24af2f8cbf3ecc745e6856ac17f40b12d61b8b5e
[iotcloud.git] / version2 / src / java / iotcloud / Test.java
1 package iotcloud;
2
3 /**
4  * Test cases.
5  * @author Brian Demsky
6  * @version 1.0
7  */
8
9 public class Test {
10
11         public static final  int NUMBER_OF_TESTS = 20000; //66
12
13         public static void main(String[] args) {
14                 if (args[0].equals("2")) {
15                         test2();
16                 } else if (args[0].equals("3")) {
17                         test3();
18                 } else if (args[0].equals("4")) {
19                         test4();
20                 }
21         }
22
23
24
25         static void test5() {
26                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
27                 t1.rebuild();
28                 System.out.println(t1);
29
30                 // // Print the results
31                 // for (int i = 0; i < NUMBER_OF_TESTS; i++) {
32                 //      String a = "a" + i;
33                 //      String b = "b" + i;
34                 //      IoTString ia = new IoTString(a);
35                 //      IoTString ib = new IoTString(b);
36
37                 //      System.out.println(ib + " -> " + t1.getCommitted(ib));
38                 //      System.out.println(ia + " -> " + t2.getCommitted(ia));
39                 //      System.out.println();
40                 // }
41         }
42
43         static Thread buildThreadTest4(String prefix, Table t) {
44                 return new Thread() {
45                         public void run() {
46                                 for (int i = 0; i < (NUMBER_OF_TESTS * 3); i++) {
47
48                                         int num = i % NUMBER_OF_TESTS;
49                                         String key = prefix + num;
50                                         String value = prefix + (num + 2000);
51                                         IoTString iKey = new IoTString(key);
52                                         IoTString iValue = new IoTString(value);
53
54                                         t.startTransaction();
55                                         t.addKV(iKey, iValue);
56                                         t.commitTransaction();
57                                 }
58                         }
59                 };
60         }
61
62         static void test4() {
63                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
64                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
65                 t1.rebuild();
66                 t2.rebuild();
67
68                 Thread thr1 = buildThreadTest4("b", t1);
69                 Thread thr2 = buildThreadTest4("a", t2);
70                 thr1.start();
71                 thr2.start();
72                 try {
73                         thr1.join();
74                         thr2.join();
75                 } catch (Exception e) {
76                         e.printStackTrace();
77                 }
78
79                 t1.update();
80                 t2.update();
81                 // t1.update();
82
83                 // Print the results
84                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
85                         String a = "a" + i;
86                         String b = "b" + i;
87                         IoTString ia = new IoTString(a);
88                         IoTString ib = new IoTString(b);
89
90                         System.out.println(ib + " -> " + t1.getCommitted(ib));
91                         System.out.println(ia + " -> " + t2.getCommitted(ia));
92                         System.out.println();
93                 }
94         }
95
96         static void test3() {
97                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
98                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
99                 t1.rebuild();
100                 t2.rebuild();
101
102
103                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
104                         String key = "a" + i;
105                         String value = "a" + (i + 1000);
106                         IoTString iKey = new IoTString(key);
107                         IoTString iValue = new IoTString(value);
108
109                         t1.startTransaction();
110                         t1.addKV(iKey, iValue);
111                         t1.commitTransaction();
112                 }
113
114                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
115                         String key = "b" + i;
116                         String value = "b" + (i + 1000);
117                         IoTString iKey = new IoTString(key);
118                         IoTString iValue = new IoTString(value);
119
120                         t2.startTransaction();
121                         t2.addKV(iKey, iValue);
122                         t2.commitTransaction();
123                 }
124
125                 // Make sure t1 sees the new updates from t2
126                 t1.update();
127
128                 // Print the results
129                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
130                         String a = "a" + i;
131                         String b = "b" + i;
132                         IoTString ia = new IoTString(a);
133                         IoTString ib = new IoTString(b);
134
135                         System.out.println(ib + " -> " + t1.getCommitted(ib));
136                         System.out.println(ia + " -> " + t2.getCommitted(ia));
137                         System.out.println();
138                 }
139         }
140
141         static void test2() {
142                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
143                 t1.initTable();
144                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
145                 t2.update();
146
147
148                 // Make the Keys
149                 System.out.println("Setting up keys");
150                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
151                         String a = "a" + i;
152                         String b = "b" + i;
153                         IoTString ia = new IoTString(a);
154                         IoTString ib = new IoTString(b);
155                         t1.createNewKey(ia, 321);
156                         t1.createNewKey(ib, 321);
157                 }
158
159                 // System.out.println("=========t1 live" + t1.liveslotcount + "     thresh: " + t1.resizethreshold);
160                 // System.out.println("=========t2 live" + t2.liveslotcount + "     thresh: " + t2.resizethreshold);
161                 // System.out.println();
162
163
164
165                 // Do Updates for the keys
166                 System.out.println("Writing Keys a...");
167                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
168                         System.out.println(i);
169
170                         String key = "a" + i;
171                         String value = "a" + (i + 10000);
172                         IoTString iKey = new IoTString(key);
173                         IoTString iValue = new IoTString(value);
174
175
176                         t1.startTransaction();
177                         t1.addKV(iKey, iValue);
178                         t1.commitTransaction();
179                 }
180
181                 // Do Updates for the keys
182                 System.out.println("Writing Keys a...");
183                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
184                         System.out.println(i);
185
186                         String key = "a" + i;
187                         String value = "a" + (i + 10000);
188                         IoTString iKey = new IoTString(key);
189                         IoTString iValue = new IoTString(value);
190
191                         t1.startTransaction();
192                         t1.addKV(iKey, iValue);
193                         t1.commitTransaction();
194                 }
195
196
197                 t2.update();
198                 System.out.println("Writing Keys b...");
199                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
200                         System.out.println(i);
201
202                         String key = "b" + i;
203                         String value = "b" + (i + 10000);
204                         IoTString iKey = new IoTString(key);
205                         IoTString iValue = new IoTString(value);
206
207
208                         t2.startTransaction();
209                         t2.addKV(iKey, iValue);
210                         t2.commitTransaction();
211                 }
212
213
214                 // Do Updates for the keys
215                 System.out.println("Writing Keys a...");
216                 for (int i = 0; i < NUMBER_OF_TESTS; i += 2) {
217                         System.out.println(i);
218
219                         String key = "a" + i;
220                         String value = "a" + (i + 10000);
221                         IoTString iKey = new IoTString(key);
222                         IoTString iValue = new IoTString(value);
223
224                         t1.startTransaction();
225                         t1.addKV(iKey, iValue);
226                         t1.commitTransaction();
227                 }
228
229
230                 t1.update();
231                 t2.update();
232
233                 System.out.println("Checking a keys...");
234                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
235
236                         String key = "a" + i;
237                         String value = "a" + (i + 10000);
238                         IoTString iKey = new IoTString(key);
239                         IoTString iValue = new IoTString(value);
240
241                         IoTString testVal = t1.getCommitted(iKey);
242
243                         if ((testVal == null) || (testVal.equals(iValue) == false)) {
244                                 System.out.println("Key val incorrect: " + key);
245                         }
246
247                         key = "b" + i;
248                         value = "b" + (i + 10000);
249                         iKey = new IoTString(key);
250                         iValue = new IoTString(value);
251
252                         testVal = t1.getCommitted(iKey);
253
254                         if ((testVal == null) || (testVal.equals(iValue) == false)) {
255                                 System.out.println("Key val incorrect: " + key);
256                         }
257                 }
258
259                 System.out.println("Checking b keys...");
260                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
261
262                         String key = "a" + i;
263                         String value = "a" + (i + 10000);
264                         IoTString iKey = new IoTString(key);
265                         IoTString iValue = new IoTString(value);
266
267                         IoTString testVal = t2.getCommitted(iKey);
268
269                         if ((testVal == null) || (testVal.equals(iValue) == false)) {
270                                 System.out.println("Key val incorrect: " + key);
271                         }
272
273                         key = "b" + i;
274                         value = "b" + (i + 10000);
275                         iKey = new IoTString(key);
276                         iValue = new IoTString(value);
277
278                         testVal = t2.getCommitted(iKey);
279
280                         if ((testVal == null) || (testVal.equals(iValue) == false)) {
281                                 System.out.println("Key val incorrect: " + key);
282                         }
283                 }
284
285
286
287
288                 System.out.println();
289                 System.out.println();
290                 System.out.println("Update");
291                 // Make sure t1 sees the new updates from t2
292                 t1.update();
293                 t2.update();
294                 t1.update();
295                 System.out.println();
296                 System.out.println();
297                 System.out.println();
298                 System.out.println();
299                 System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
300                 System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
301                 System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
302                 t2.update();
303                 System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
304                 System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
305                 System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
306
307
308                 // System.out.println("=========t1 live" + t1.liveslotcount + "     thresh: " + t1.resizethreshold + "   commits: " + t1.commitedTable.size() + "   uncommits: " + t1.uncommittedTransactionsList.size());
309                 // System.out.println("=========t2 live" + t2.liveslotcount + "     thresh: " + t2.resizethreshold + "   commits: " + t2.commitedTable.size() + "   uncommits: " + t2.uncommittedTransactionsList.size() );
310                 System.out.println();
311
312                 t1.printSlots();
313                 System.out.println();
314                 System.out.println();
315                 System.out.println();
316                 System.out.println();
317                 t2.printSlots();
318                 System.out.println();
319
320
321
322                 // // Do Updates for the keys
323                 // System.out.println("Writing Keys a (actual)");
324                 // for (int i = 0; i < NUMBER_OF_TESTS; i++) {
325                 //      String key = "a" + i;
326                 //      String value = "a" + i;
327                 //      IoTString iKey = new IoTString(key);
328                 //      IoTString iValue = new IoTString(value);
329
330                 //      t1.startTransaction();
331                 //      t1.addKV(iKey, iValue);
332                 //      t1.commitTransaction();
333                 // }
334
335                 // System.out.println("=========t1 live" + t1.liveslotcount + "     thresh: " + t1.resizethreshold + "   commits: " + t1.commitedTable.size() + "   uncommits: " + t1.uncommittedTransactionsList.size());
336                 // System.out.println("=========t2 live" + t2.liveslotcount + "     thresh: " + t2.resizethreshold + "   commits: " + t2.commitedTable.size() + "   uncommits: " + t2.uncommittedTransactionsList.size());
337                 // System.out.println();
338
339
340
341                 // System.out.println("Writing Keys b (actual)");
342                 // for (int i = 0; i < NUMBER_OF_TESTS; i++) {
343                 //      String key = "b" + i;
344                 //      String value = "b" + i;
345                 //      IoTString iKey = new IoTString(key);
346                 //      IoTString iValue = new IoTString(value);
347
348                 //      t2.startTransaction();
349                 //      t2.addKV(iKey, iValue);
350                 //      t2.commitTransaction();
351                 // }
352
353                 // System.out.println("=========t1 live" + t1.liveslotcount + "     thresh: " + t1.resizethreshold + "   commits: " + t1.commitedTable.size() + "   uncommits: " + t1.uncommittedTransactionsList.size() );
354                 // System.out.println("=========t2 live" + t2.liveslotcount + "     thresh: " + t2.resizethreshold + "   commits: " + t2.commitedTable.size() + "   uncommits: " + t2.uncommittedTransactionsList.size() );
355                 // System.out.println();
356
357
358                 // // Do Updates for the keys
359                 // System.out.println("Writing Keys a (actual)");
360                 // for (int i = 0; i < NUMBER_OF_TESTS; i++) {
361                 //      String key = "a" + i;
362                 //      String value = "a" + i;
363                 //      IoTString iKey = new IoTString(key);
364                 //      IoTString iValue = new IoTString(value);
365
366                 //      t1.startTransaction();
367                 //      t1.addKV(iKey, iValue);
368                 //      t1.commitTransaction();
369                 // }
370
371                 // System.out.println("=========t1 live" + t1.liveslotcount + "     thresh: " + t1.resizethreshold + "   commits: " + t1.commitedTable.size() + "   uncommits: " + t1.uncommittedTransactionsList.size());
372                 // System.out.println("=========t2 live" + t2.liveslotcount + "     thresh: " + t2.resizethreshold + "   commits: " + t2.commitedTable.size() + "   uncommits: " + t2.uncommittedTransactionsList.size());
373                 // System.out.println();
374
375
376
377                 // System.out.println("Writing Keys b (actual)");
378                 // for (int i = 0; i < NUMBER_OF_TESTS; i++) {
379                 //      String key = "b" + i;
380                 //      String value = "b" + i;
381                 //      IoTString iKey = new IoTString(key);
382                 //      IoTString iValue = new IoTString(value);
383
384                 //      t2.startTransaction();
385                 //      t2.addKV(iKey, iValue);
386                 //      t2.commitTransaction();
387                 // }
388
389                 // System.out.println("=========t1 live" + t1.liveslotcount + "     thresh: " + t1.resizethreshold + "   commits: " + t1.commitedTable.size() + "   uncommits: " + t1.uncommittedTransactionsList.size() );
390                 // System.out.println("=========t2 live" + t2.liveslotcount + "     thresh: " + t2.resizethreshold + "   commits: " + t2.commitedTable.size() + "   uncommits: " + t2.uncommittedTransactionsList.size() );
391                 // System.out.println();
392
393                 // t1.printSlots();
394                 // System.out.println();
395                 // t2.printSlots();
396
397
398
399                 // Make sure t1 sees the new updates from t2
400                 // t1.update();
401
402                 // // Print the results
403                 // for (int i = NUMBER_OF_TESTS - 10; i < NUMBER_OF_TESTS; i++) {
404                 // String a = "a" + i;
405                 // String b = "b" + i;
406                 // IoTString ia = new IoTString(a);
407                 //      IoTString ib = new IoTString(b);
408
409                 //      System.out.println(ib + " -> " + t1.getCommitted(ib));
410                 //      System.out.println(ia + " -> " + t2.getCommitted(ia));
411                 //      System.out.println();
412                 // }
413         }
414 }