Offline support added
[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 = 15;
12
13         public static void main(String[] args)  throws ServerException {
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                 } else if (args[0].equals("5")) {
21                         test5();
22                 } else if (args[0].equals("6")) {
23                         test6();
24                 } else if (args[0].equals("7")) {
25                         test7();
26                 } else if (args[0].equals("8")) {
27                         test8();
28                 } else if (args[0].equals("9")) {
29                         test9();
30                 }
31         }
32
33         // static void test9()  throws ServerException {
34         //      // Setup the 2 clients
35         //      Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
36         //      t1.initTable();
37         //      Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
38         //      t2.update();
39
40
41         //      // Make the Keys
42         //      System.out.println("Setting up keys");
43         //      for (int i = 0; i < NUMBER_OF_TESTS; i++) {
44         //              String a = "a" + i;
45         //              String b = "b" + i;
46         //              String c = "c" + i;
47         //              String d = "d" + i;
48         //              IoTString ia = new IoTString(a);
49         //              IoTString ib = new IoTString(b);
50         //              IoTString ic = new IoTString(c);
51         //              IoTString id = new IoTString(d);
52         //              t1.createNewKey(ia, 321);
53         //              t1.createNewKey(ib, 351);
54         //              t2.createNewKey(ic, 321);
55         //              t2.createNewKey(id, 351);
56         //      }
57
58         //      for (int i = 0; i < NUMBER_OF_TESTS; i++) {
59         //              String a = "a" + i;
60         //              String b = "b" + i;
61         //              String c = "c" + i;
62         //              String d = "d" + i;
63         //              IoTString ia = new IoTString(a);
64         //              IoTString ib = new IoTString(b);
65         //              IoTString ic = new IoTString(c);
66         //              IoTString id = new IoTString(d);
67         //              t1.createNewKey(ia, 1000);
68         //              t1.createNewKey(ib, 1000);
69         //              t2.createNewKey(ic, 1000);
70         //              t2.createNewKey(id, 1000);
71         //      }
72
73         //      System.out.println("Updating Clients...");
74         //      t1.update();
75         //      t2.update();
76         //      t1.update();
77         //      t2.update();
78
79         //      boolean foundError = false;
80
81         //      System.out.println("Checking Key-Values...");
82         //      for (int i = 0; i < NUMBER_OF_TESTS; i++) {
83
84         //              String keyA = "a" + i;
85         //              String keyB = "b" + i;
86         //              String keyC = "c" + i;
87         //              String keyD = "d" + i;
88
89         //              IoTString iKeyA = new IoTString(keyA);
90         //              IoTString iKeyB = new IoTString(keyB);
91         //              IoTString iKeyC = new IoTString(keyC);
92         //              IoTString iKeyD = new IoTString(keyD);
93
94
95         //              Long testValA1 = t1.getArbitrator(iKeyA);
96         //              Long testValB1 = t1.getArbitrator(iKeyB);
97         //              Long testValC1 = t1.getArbitrator(iKeyC);
98         //              Long testValD1 = t1.getArbitrator(iKeyD);
99
100         //              Long testValA2 = t2.getArbitrator(iKeyA);
101         //              Long testValB2 = t2.getArbitrator(iKeyB);
102         //              Long testValC2 = t2.getArbitrator(iKeyC);
103         //              Long testValD2 = t2.getArbitrator(iKeyD);
104
105         //              if ((testValA1 == null) || (testValA1 != 321)) {
106         //                      System.out.println("Key-Value t1 incorrect: " + keyA + "    " + testValA1);
107         //                      foundError = true;
108         //              }
109
110         //              if ((testValB1 == null) || (testValB1 != 351)) {
111         //                      System.out.println("Key-Value t1 incorrect: " + keyB + "    " + testValB1);
112         //                      foundError = true;
113         //              }
114
115         //              if ((testValC1 == null) || (testValC1 != 321)) {
116         //                      System.out.println("Key-Value t1 incorrect: " + keyC + "    " + testValC1);
117         //                      foundError = true;
118         //              }
119
120         //              if ((testValD1 == null) || (testValD1 != 351)) {
121         //                      System.out.println("Key-Value t1 incorrect: " + keyD + "    " + testValD1);
122         //                      foundError = true;
123         //              }
124
125         //              if ((testValA2 == null) || (testValA2 != 321)) {
126         //                      System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
127         //                      foundError = true;
128         //              }
129
130         //              if ((testValB2 == null) || (testValB2 != 351)) {
131         //                      System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
132         //                      foundError = true;
133         //              }
134
135         //              if ((testValC2 == null) || (testValC2 != 321)) {
136         //                      System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
137         //                      foundError = true;
138         //              }
139
140         //              if ((testValD2 == null) || (testValD2 != 351)) {
141         //                      System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
142         //                      foundError = true;
143         //              }
144         //      }
145
146         //      if (foundError) {
147         //              System.out.println("Found Errors...");
148         //      } else {
149         //              System.out.println("No Errors Found...");
150         //      }
151         // }
152
153         // static void test8()  throws ServerException {
154
155         //      boolean foundError = false;
156
157         //      // Setup the 2 clients
158         //      Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
159         //      t1.initTable();
160         //      Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
161         //      t2.update();
162
163         //      // t1.rebuild();
164         //      // t2.rebuild();
165
166         //      // Make the Keys
167         //      System.out.println("Setting up keys");
168         //      for (int i = 0; i < NUMBER_OF_TESTS; i++) {
169         //              String a = "a" + i;
170         //              String b = "b" + i;
171         //              String c = "c" + i;
172         //              String d = "d" + i;
173         //              IoTString ia = new IoTString(a);
174         //              IoTString ib = new IoTString(b);
175         //              IoTString ic = new IoTString(c);
176         //              IoTString id = new IoTString(d);
177         //              t1.createNewKey(ia, 321);
178         //              t1.createNewKey(ib, 351);
179         //              t2.createNewKey(ic, 321);
180         //              t2.createNewKey(id, 351);
181         //      }
182
183
184         //      // Do Updates for the keys
185         //      System.out.println("Setting Key-Values...");
186
187
188         //      String keyA0 = "a0";
189         //      String keyB0 = "b0";
190         //      String keyC0 = "c0";
191         //      String keyD0 = "d0";
192         //      String valueA0 = "a0";
193         //      String valueB0 = "b0";
194         //      String valueC0 = "c0";
195         //      String valueD0 = "d0";
196
197         //      IoTString iKeyA0 = new IoTString(keyA0);
198         //      IoTString iKeyB0 = new IoTString(keyB0);
199         //      IoTString iKeyC0 = new IoTString(keyC0);
200         //      IoTString iKeyD0 = new IoTString(keyD0);
201         //      IoTString iValueA0 = new IoTString(valueA0);
202         //      IoTString iValueB0 = new IoTString(valueB0);
203         //      IoTString iValueC0 = new IoTString(valueC0);
204         //      IoTString iValueD0 = new IoTString(valueD0);
205
206         //      t1.startTransaction();
207         //      t1.addKV( iKeyA0, iValueA0);
208         //      t1.commitTransaction();
209
210         //      t1.startTransaction();
211         //      t1.addKV(iKeyB0, iValueB0);
212         //      t1.commitTransaction();
213
214         //      t2.startTransaction();
215         //      t2.addKV(iKeyC0, iValueC0);
216         //      t2.commitTransaction();
217
218         //      t2.startTransaction();
219         //      t2.addKV(iKeyD0, iValueD0);
220         //      t2.commitTransaction();
221
222         //      for (int i = 1; i < NUMBER_OF_TESTS; i++) {
223         //              String keyB = "b" + i;
224         //              String valueB = "b" + i;
225         //              IoTString iKeyB = new IoTString(keyB);
226         //              IoTString iValueB = new IoTString(valueB);
227
228         //              String keyBOld = "b" + (i - 1);
229         //              String valueBOld = "b" + (i - 1);
230         //              IoTString iKeyBOld = new IoTString(keyBOld);
231         //              IoTString iValueBOld = new IoTString(valueBOld);
232
233
234         //              t1.startTransaction();
235         //              t1.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyBOld, iValueBOld, Guard.Equal))));
236         //              t1.addKV(iKeyB, iValueB);
237         //              t1.commitTransaction();
238         //      }
239
240         //      System.out.println("Checking Key-Values...");
241         //      for (int i = 0; i < NUMBER_OF_TESTS; i++) {
242
243         //              String keyB = "b" + i;
244         //              String valueB = "b" + i;
245
246         //              IoTString iKeyB = new IoTString(keyB);
247         //              IoTString iValueB = new IoTString(valueB);
248
249         //              IoTString testValB1 = t1.getSpeculative(iKeyB);
250
251         //              if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
252         //                      System.out.println("Key-Value t1 incorrect: " + keyB);
253         //                      foundError = true;
254
255         //              }
256         //      }
257
258
259         //      System.out.println("Updating Clients...");
260         //      t1.update();
261         //      t2.update();
262         //      t1.update();
263         //      t2.update();
264
265         //      System.out.println("Checking Key-Values...");
266         //      for (int i = 0; i < NUMBER_OF_TESTS; i++) {
267
268         //              String keyA = "a" + i;
269         //              String keyB = "b" + i;
270         //              String keyC = "c" + i;
271         //              String keyD = "d" + i;
272         //              String valueA = "a" + i;
273         //              String valueB = "b" + i;
274         //              String valueC = "c" + i;
275         //              String valueD = "d" + i;
276
277         //              IoTString iKeyA = new IoTString(keyA);
278         //              IoTString iKeyB = new IoTString(keyB);
279         //              IoTString iKeyC = new IoTString(keyC);
280         //              IoTString iKeyD = new IoTString(keyD);
281         //              IoTString iValueA = new IoTString(valueA);
282         //              IoTString iValueB = new IoTString(valueB);
283         //              IoTString iValueC = new IoTString(valueC);
284         //              IoTString iValueD = new IoTString(valueD);
285
286
287         //              IoTString testValA1 = t1.getCommitted(iKeyA);
288         //              IoTString testValB1 = t1.getCommitted(iKeyB);
289         //              IoTString testValC1 = t1.getCommitted(iKeyC);
290         //              IoTString testValD1 = t1.getCommitted(iKeyD);
291
292         //              IoTString testValA2 = t2.getCommitted(iKeyA);
293         //              IoTString testValB2 = t2.getCommitted(iKeyB);
294         //              IoTString testValC2 = t2.getCommitted(iKeyC);
295         //              IoTString testValD2 = t2.getCommitted(iKeyD);
296
297
298         //              if (i == 0) {
299         //                      if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
300         //                              System.out.println("Key-Value t1 incorrect: " + keyA);
301         //                              foundError = true;
302         //                      }
303
304         //                      if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
305         //                              System.out.println("Key-Value t1 incorrect: " + keyB);
306         //                              foundError = true;
307         //                      }
308
309         //                      if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
310         //                              System.out.println("Key-Value t1 incorrect: " + keyC);
311         //                              foundError = true;
312         //                      }
313
314         //                      if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
315         //                              System.out.println("Key-Value t1 incorrect: " + keyD);
316         //                              foundError = true;
317         //                      }
318
319
320         //                      if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
321         //                              System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
322         //                              foundError = true;
323         //                      }
324
325         //                      if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
326         //                              System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
327         //                              foundError = true;
328         //                      }
329
330         //                      if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
331         //                              System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
332         //                              foundError = true;
333         //                      }
334
335         //                      if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
336         //                              System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
337         //                              foundError = true;
338         //                      }
339         //              } else {
340         //                      if (testValA1 != null) {
341         //                              System.out.println("Key-Value t1 incorrect: " + keyA);
342         //                              foundError = true;
343         //                      }
344
345         //                      if (testValB1 != null) {
346         //                              System.out.println("Key-Value t1 incorrect: " + keyB);
347         //                              foundError = true;
348         //                      }
349
350         //                      if (testValC1 != null) {
351         //                              System.out.println("Key-Value t1 incorrect: " + keyC);
352         //                              foundError = true;
353         //                      }
354
355         //                      if (testValD1 != null) {
356         //                              System.out.println("Key-Value t1 incorrect: " + keyD);
357         //                              foundError = true;
358         //                      }
359
360         //                      if (testValA2 != null) {
361         //                              System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
362         //                              foundError = true;
363         //                      }
364
365         //                      if (testValB2 != null) {
366         //                              System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
367         //                              foundError = true;
368         //                      }
369
370         //                      if (testValC2 != null) {
371         //                              System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
372         //                              foundError = true;
373         //                      }
374
375         //                      if (testValD2 != null) {
376         //                              System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
377         //                              foundError = true;
378         //                      }
379         //              }
380         //      }
381
382         //      if (foundError) {
383         //              System.out.println("Found Errors...");
384         //      } else {
385         //              System.out.println("No Errors Found...");
386         //      }
387         // }
388
389         // static void test7()  throws ServerException {
390
391         //      long startTime = 0;
392         //      long endTime = 0;
393
394         //      // Setup the 2 clients
395         //      Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
396         //      t1.initTable();
397         //      Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
398         //      t2.update();
399
400         //      // t1.rebuild();
401         //      // t2.rebuild();
402
403         //      // Make the Keys
404         //      System.out.println("Setting up keys");
405         //      startTime = System.currentTimeMillis();
406         //      for (int i = 0; i < NUMBER_OF_TESTS; i++) {
407         //              String a = "a" + i;
408         //              String b = "b" + i;
409         //              String c = "c" + i;
410         //              String d = "d" + i;
411         //              IoTString ia = new IoTString(a);
412         //              IoTString ib = new IoTString(b);
413         //              IoTString ic = new IoTString(c);
414         //              IoTString id = new IoTString(d);
415         //              t1.createNewKey(ia, 321);
416         //              t1.createNewKey(ib, 351);
417         //              t2.createNewKey(ic, 321);
418         //              t2.createNewKey(id, 351);
419         //      }
420         //      endTime = System.currentTimeMillis();
421
422         //      System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
423         //      System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
424         //      System.out.println();
425
426
427         //      // Do Updates for the keys
428         //      System.out.println("Setting Key-Values...");
429         //      startTime = System.currentTimeMillis();
430
431
432
433         //      String keyA0 = "a0";
434         //      String keyB0 = "b0";
435         //      String keyC0 = "c0";
436         //      String keyD0 = "d0";
437         //      String valueA0 = "a0";
438         //      String valueB0 = "b0";
439         //      String valueC0 = "c0";
440         //      String valueD0 = "d0";
441
442         //      IoTString iKeyA0 = new IoTString(keyA0);
443         //      IoTString iKeyB0 = new IoTString(keyB0);
444         //      IoTString iKeyC0 = new IoTString(keyC0);
445         //      IoTString iKeyD0 = new IoTString(keyD0);
446         //      IoTString iValueA0 = new IoTString(valueA0);
447         //      IoTString iValueB0 = new IoTString(valueB0);
448         //      IoTString iValueC0 = new IoTString(valueC0);
449         //      IoTString iValueD0 = new IoTString(valueD0);
450
451         //      t1.startTransaction();
452         //      t1.addKV( iKeyA0, iValueA0);
453         //      t1.commitTransaction();
454
455         //      t1.startTransaction();
456         //      t1.addKV(iKeyB0, iValueB0);
457         //      t1.commitTransaction();
458
459         //      t2.startTransaction();
460         //      t2.addKV(iKeyC0, iValueC0);
461         //      t2.commitTransaction();
462
463         //      t2.startTransaction();
464         //      t2.addKV(iKeyD0, iValueD0);
465         //      t2.commitTransaction();
466
467         //      for (int i = 1; i < NUMBER_OF_TESTS; i++) {
468         //              String keyB = "b" + i;
469         //              String valueB = "b" + i;
470         //              IoTString iKeyB = new IoTString(keyB);
471         //              IoTString iValueB = new IoTString(valueB);
472
473         //              String keyBOld = "b" + (i - 1);
474         //              String valueBOld = "b" + (i - 2);
475         //              IoTString iKeyBOld = new IoTString(keyBOld);
476         //              IoTString iValueBOld = new IoTString(valueBOld);
477
478
479         //              t1.startTransaction();
480         //              t1.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyBOld, iValueBOld, Guard.Equal))));
481         //              t1.addKV(iKeyB, iValueB);
482         //              t1.commitTransaction();
483         //      }
484
485         //      for (int i = 1; i < NUMBER_OF_TESTS; i++) {
486         //              String keyC = "c" + i;
487         //              String valueC = "c" + i;
488         //              IoTString iKeyC = new IoTString(keyC);
489         //              IoTString iValueC = new IoTString(valueC);
490
491         //              String keyCOld = "c" + (i - 1);
492         //              String valueCOld = "c" + (i - 2);
493         //              IoTString iKeyCOld = new IoTString(keyCOld);
494         //              IoTString iValueCOld = new IoTString(valueCOld);
495
496
497         //              t2.startTransaction();
498         //              t2.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyCOld, iValueCOld, Guard.Equal))));
499         //              t2.addKV(iKeyC, iValueC);
500         //              t2.commitTransaction();
501         //      }
502
503         //      for (int i = 1; i < NUMBER_OF_TESTS; i++) {
504         //              String keyA = "a" + i;
505         //              String keyD = "d" + i;
506         //              String valueA = "a" + i;
507         //              String valueD = "d" + i;
508
509         //              IoTString iKeyA = new IoTString(keyA);
510         //              IoTString iKeyD = new IoTString(keyD);
511         //              IoTString iValueA = new IoTString(valueA);
512         //              IoTString iValueD = new IoTString(valueD);
513
514
515         //              String keyAOld = "a" + (i - 1);
516         //              String keyDOld = "d" + (i - 1);
517         //              String valueAOld = "a" + (i - 2);
518         //              String valueDOld = "d" + (i - 2);
519         //              IoTString iKeyAOld = new IoTString(keyAOld);
520         //              IoTString iKeyDOld = new IoTString(keyDOld);
521         //              IoTString iValueAOld = new IoTString(valueAOld);
522         //              IoTString iValueDOld = new IoTString(valueDOld);
523
524
525         //              t1.startTransaction();
526         //              t1.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyAOld, iValueAOld, Guard.Equal))));
527         //              t1.addKV(iKeyA, iValueA);
528         //              t1.commitTransaction();
529
530         //              t2.startTransaction();
531         //              t2.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyDOld, iValueDOld, Guard.Equal))));
532         //              t2.addKV(iKeyD, iValueD);
533         //              t2.commitTransaction();
534         //      }
535
536         //      endTime = System.currentTimeMillis();
537
538         //      System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
539         //      System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
540         //      System.out.println();
541
542
543         //      System.out.println("Updating Clients...");
544         //      t1.update();
545         //      t2.update();
546         //      t1.update();
547         //      t2.update();
548
549         //      boolean foundError = false;
550
551         //      System.out.println("Checking Key-Values...");
552         //      for (int i = 0; i < NUMBER_OF_TESTS; i++) {
553
554         //              String keyA = "a" + i;
555         //              String keyB = "b" + i;
556         //              String keyC = "c" + i;
557         //              String keyD = "d" + i;
558         //              String valueA = "a" + i;
559         //              String valueB = "b" + i;
560         //              String valueC = "c" + i;
561         //              String valueD = "d" + i;
562
563         //              IoTString iKeyA = new IoTString(keyA);
564         //              IoTString iKeyB = new IoTString(keyB);
565         //              IoTString iKeyC = new IoTString(keyC);
566         //              IoTString iKeyD = new IoTString(keyD);
567         //              IoTString iValueA = new IoTString(valueA);
568         //              IoTString iValueB = new IoTString(valueB);
569         //              IoTString iValueC = new IoTString(valueC);
570         //              IoTString iValueD = new IoTString(valueD);
571
572
573         //              IoTString testValA1 = t1.getCommitted(iKeyA);
574         //              IoTString testValB1 = t1.getCommitted(iKeyB);
575         //              IoTString testValC1 = t1.getCommitted(iKeyC);
576         //              IoTString testValD1 = t1.getCommitted(iKeyD);
577
578         //              IoTString testValA2 = t2.getCommitted(iKeyA);
579         //              IoTString testValB2 = t2.getCommitted(iKeyB);
580         //              IoTString testValC2 = t2.getCommitted(iKeyC);
581         //              IoTString testValD2 = t2.getCommitted(iKeyD);
582
583
584         //              if (i == 0) {
585         //                      if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
586         //                              System.out.println("Key-Value t1 incorrect: " + keyA);
587         //                              foundError = true;
588         //                      }
589
590         //                      if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
591         //                              System.out.println("Key-Value t1 incorrect: " + keyB);
592         //                              foundError = true;
593         //                      }
594
595         //                      if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
596         //                              System.out.println("Key-Value t1 incorrect: " + keyC);
597         //                              foundError = true;
598         //                      }
599
600         //                      if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
601         //                              System.out.println("Key-Value t1 incorrect: " + keyD);
602         //                              foundError = true;
603         //                      }
604
605
606         //                      if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
607         //                              System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
608         //                              foundError = true;
609         //                      }
610
611         //                      if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
612         //                              System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
613         //                              foundError = true;
614         //                      }
615
616         //                      if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
617         //                              System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
618         //                              foundError = true;
619         //                      }
620
621         //                      if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
622         //                              System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
623         //                              foundError = true;
624         //                      }
625         //              } else {
626         //                      if (testValA1 != null) {
627         //                              System.out.println("Key-Value t1 incorrect: " + keyA);
628         //                              foundError = true;
629         //                      }
630
631         //                      if (testValB1 != null) {
632         //                              System.out.println("Key-Value t1 incorrect: " + keyB);
633         //                              foundError = true;
634         //                      }
635
636         //                      if (testValC1 != null) {
637         //                              System.out.println("Key-Value t1 incorrect: " + keyC);
638         //                              foundError = true;
639         //                      }
640
641         //                      if (testValD1 != null) {
642         //                              System.out.println("Key-Value t1 incorrect: " + keyD);
643         //                              foundError = true;
644         //                      }
645
646         //                      if (testValA2 != null) {
647         //                              System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
648         //                              foundError = true;
649         //                      }
650
651         //                      if (testValB2 != null) {
652         //                              System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
653         //                              foundError = true;
654         //                      }
655
656         //                      if (testValC2 != null) {
657         //                              System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
658         //                              foundError = true;
659         //                      }
660
661         //                      if (testValD2 != null) {
662         //                              System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
663         //                              foundError = true;
664         //                      }
665         //              }
666         //      }
667
668         //      if (foundError) {
669         //              System.out.println("Found Errors...");
670         //      } else {
671         //              System.out.println("No Errors Found...");
672         //      }
673         // }
674
675         static void test9()  {
676
677                 boolean foundError = false;
678
679                 // Setup the 2 clients
680                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
681
682                 while (true) {
683                         try {
684                                 t1.initTable();
685                                 break;
686                         } catch (Exception e) {}
687                 }
688
689                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
690
691                 while (true) {
692                         try {
693                                 t2.update();
694                                 break;
695                         } catch (Exception e) {}
696                 }
697
698                 // Make the Keys
699                 System.out.println("Setting up keys");
700                 for (int i = 0; i < 4; i++) {
701                         String a = "a" + i;
702                         String b = "b" + i;
703                         String c = "c" + i;
704                         String d = "d" + i;
705                         IoTString ia = new IoTString(a);
706                         IoTString ib = new IoTString(b);
707                         IoTString ic = new IoTString(c);
708                         IoTString id = new IoTString(d);
709                         while (true) {
710                                 try {
711                                         t1.createNewKey(ia, 321);
712                                         break;
713                                 } catch (Exception e) {}
714                         }
715
716                         while (true) {
717                                 try {
718                                         t1.createNewKey(ib, 351);
719                                         break;
720                                 } catch (Exception e) {}
721                         }
722
723                         while (true) {
724                                 try {
725                                         t2.createNewKey(ic, 321);
726                                         break;
727                                 } catch (Exception e) {}
728                         }
729
730                         while (true) {
731                                 try {
732                                         t2.createNewKey(id, 351);
733                                         break;
734                                 } catch (Exception e) {}
735                         }
736                 }
737
738                 // Do Updates for the keys
739                 System.out.println("Setting Key-Values...");
740
741                 System.out.println("Setting b...");
742                 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
743                         for (int i = 0; i < 4; i++) {
744                                 String keyB = "b" + i;
745                                 String valueB = "b" + (i + t);
746
747                                 IoTString iKeyB = new IoTString(keyB);
748                                 IoTString iValueB = new IoTString(valueB);
749
750                                 try {
751                                         t1.startTransaction();
752                                         t1.getSpeculativeAtomic(iKeyB);
753                                         t1.addKV(iKeyB, iValueB);
754                                         t1.commitTransaction();
755                                         System.out.println("Server Success");
756                                 } catch (Exception e) {
757                                         System.out.println("Server Fail");
758                                 }
759
760                         }
761                 }
762
763                 System.out.println("Checking b");
764                 for (int i = 0; i < 4; i++) {
765
766                         String keyB = "b" + i;
767                         String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
768                         IoTString iKeyB = new IoTString(keyB);
769                         IoTString iValueB = new IoTString(valueB);
770
771                         IoTString testValB1 = t1.getSpeculative(iKeyB);
772                         IoTString testValB2 = t2.getSpeculative(iKeyB);
773
774                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
775                                 System.out.println("Key-Value t1 incorrect: " + keyB + "    " + testValB1);
776                                 foundError = true;
777                         }
778
779                         if ((testValB2 != null)) {
780                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
781                                 foundError = true;
782                         }
783                 }
784
785                 System.out.println("Setting c...");
786                 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
787                         for (int i = 0; i < 4; i++) {
788                                 String keyC = "c" + i;
789                                 String valueC = "c" + (i + t);
790
791                                 IoTString iKeyC = new IoTString(keyC);
792                                 IoTString iValueC = new IoTString(valueC);
793
794                                 try {
795                                         t2.startTransaction();
796                                         t2.getSpeculativeAtomic(iKeyC);
797                                         t2.addKV(iKeyC, iValueC);
798                                         t2.commitTransaction();
799                                         System.out.println("Server Success");
800                                 } catch (Exception e) {
801                                         System.out.println("Server Fail");
802                                 }
803
804                         }
805                 }
806
807                 System.out.println("Checking c");
808                 for (int i = 0; i < 4; i++) {
809                         String keyC = "c" + i;
810                         String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
811                         IoTString iKeyC = new IoTString(keyC);
812                         IoTString iValueC = new IoTString(valueC);
813
814                         IoTString testValC1 = t1.getSpeculative(iKeyC);
815                         IoTString testValC2 = t2.getSpeculative(iKeyC);
816
817                         if ((testValC1 != null)) {
818                                 System.out.println("Key-Value t1 incorrect: " + keyC + "   " + testValC1);
819                                 foundError = true;
820                         }
821
822                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
823                                 System.out.println("Key-Value t2 incorrect: " + keyC + "   " + testValC2);
824                                 foundError = true;
825                         }
826                 }
827
828                 System.out.println("Setting a and b...");
829                 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
830                         for (int i = 0; i < 4; i++) {
831                                 String keyA = "a" + i;
832                                 String keyD = "d" + i;
833                                 String valueA = "a" + (i + t);
834                                 String valueD = "d" + (i + t);
835
836                                 IoTString iKeyA = new IoTString(keyA);
837                                 IoTString iKeyD = new IoTString(keyD);
838                                 IoTString iValueA = new IoTString(valueA);
839                                 IoTString iValueD = new IoTString(valueD);
840
841                                 try {
842                                         t1.startTransaction();
843                                         t1.addKV(iKeyA, iValueA);
844                                         t1.commitTransaction();
845                                         System.out.println("Server Success");
846
847                                 } catch (Exception e) {
848                                         System.out.println("Server Fail");
849                                 }
850
851                                 try {
852                                         t2.startTransaction();
853                                         t2.addKV(iKeyD, iValueD);
854                                         t2.commitTransaction();
855                                         System.out.println("Server Success");
856
857                                 } catch (Exception e) {
858                                         System.out.println("Server Fail");
859                                 }
860
861                         }
862                 }
863
864                 System.out.println("Updating Clients...");
865                 System.out.println("Updating Clients...");
866                 System.out.println("Updating Clients...");
867                 System.out.println("Updating Clients...");
868                 System.out.println("Updating Clients...");
869                 System.out.println("Updating Clients...");
870                 System.out.println("Updating Clients...");
871                 System.out.println("Updating Clients...");
872                 System.out.println("Updating Clients...");
873                 System.out.println("Updating Clients...");
874                 System.out.println("Updating Clients...");
875                 System.out.println("Updating Clients...");
876                 System.out.println("Updating Clients...");
877                 System.out.println("Updating Clients...");
878                 System.out.println("Updating Clients...");
879                 System.out.println("Updating Clients...");
880                 System.out.println("Updating Clients...");
881                 System.out.println("Updating Clients...");
882                 System.out.println("Updating Clients...");
883                 System.out.println("Updating Clients...");
884                 System.out.println("Updating Clients...");
885                 System.out.println("Updating Clients...");
886                 System.out.println("Updating Clients...");
887                 System.out.println("Updating Clients...");
888                 System.out.println("Updating Clients...");
889
890                 try {
891                         Thread.sleep(3000);
892                 } catch (Exception e) {
893
894                 }
895
896                 System.out.println("Updating Clients... T1   first");
897                 while (true) {
898                         try {
899                                 t1.update();
900                                 break;
901                         } catch (Exception e) {
902                                 e.printStackTrace();
903                                 System.out.println("Fail");
904                         }
905                 }
906
907                 System.out.println("Updating Clients... T2   first");
908                 while (true) {
909                         try {
910                                 t2.update();
911                                 break;
912                         } catch (Exception e) {
913                                 System.out.println("Fail");
914                         }
915                 }
916
917                 System.out.println("Updating Clients... T1   second");
918                 while (true) {
919                         try {
920                                 t1.update();
921                                 break;
922                         } catch (Exception e) {
923                                 System.out.println("Fail");
924                         }
925                 }
926
927                 System.out.println("Updating Clients... T2  second");
928                 while (true) {
929                         try {
930                                 t2.update();
931                                 break;
932                         } catch (Exception e) {
933                                 System.out.println("Fail");
934                         }
935                 }
936
937                 System.out.println("Checking Key-Values...");
938                 for (int i = 0; i < 4; i++) {
939
940                         String keyA = "a" + i;
941                         String keyB = "b" + i;
942                         String keyC = "c" + i;
943                         String keyD = "d" + i;
944                         String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
945                         String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
946                         String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
947                         String valueD = "d" + (i + NUMBER_OF_TESTS - 1);
948
949                         IoTString iKeyA = new IoTString(keyA);
950                         IoTString iKeyB = new IoTString(keyB);
951                         IoTString iKeyC = new IoTString(keyC);
952                         IoTString iKeyD = new IoTString(keyD);
953                         IoTString iValueA = new IoTString(valueA);
954                         IoTString iValueB = new IoTString(valueB);
955                         IoTString iValueC = new IoTString(valueC);
956                         IoTString iValueD = new IoTString(valueD);
957
958
959                         IoTString testValA1 = t1.getCommitted(iKeyA);
960                         IoTString testValB1 = t1.getCommitted(iKeyB);
961                         IoTString testValC1 = t1.getCommitted(iKeyC);
962                         IoTString testValD1 = t1.getCommitted(iKeyD);
963
964                         IoTString testValA2 = t2.getCommitted(iKeyA);
965                         IoTString testValB2 = t2.getCommitted(iKeyB);
966                         IoTString testValC2 = t2.getCommitted(iKeyC);
967                         IoTString testValD2 = t2.getCommitted(iKeyD);
968
969                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
970                                 System.out.println("Key-Value t1 incorrect: " + keyA + "    " + testValA1 + "    " + iValueA);
971                                 foundError = true;
972                         }
973
974                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
975                                 System.out.println("Key-Value t1 incorrect: " + keyB + "    " + testValB1 + "    " + iValueB);
976                                 foundError = true;
977                         }
978
979                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
980                                 System.out.println("Key-Value t1 incorrect: " + keyC + "    " + testValC1 + "    " + iValueC);
981                                 foundError = true;
982                         }
983
984                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
985                                 System.out.println("Key-Value t1 incorrect: " + keyD + "    " + testValD1 + "    " + iValueD);
986                                 foundError = true;
987                         }
988
989                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
990                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2 + "    " + iValueA);
991                                 foundError = true;
992                         }
993
994                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
995                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2 + "    " + iValueB);
996                                 foundError = true;
997                         }
998
999                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1000                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2 + "    " + iValueC);
1001                                 foundError = true;
1002                         }
1003
1004                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1005                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2 + "    " + iValueD);
1006                                 foundError = true;
1007                         }
1008                 }
1009
1010                 if (foundError) {
1011                         System.out.println("Found Errors...");
1012                 } else {
1013                         System.out.println("No Errors Found...");
1014                 }
1015         }
1016
1017         static void test8() {
1018                 boolean foundError = false;
1019
1020
1021                 // Setup the 2 clients
1022                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
1023                 while (true) {
1024                         try {
1025                                 t1.initTable();
1026                                 break;
1027                         } catch (Exception e) {}
1028                 }
1029
1030                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
1031                 while (true) {
1032                         try {
1033                                 t2.update();
1034                                 break;
1035                         } catch (Exception e) {}
1036                 }
1037
1038                 // Make the Keys
1039                 System.out.println("Setting up keys");
1040                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1041                         System.out.println(i);
1042
1043                         String a = "a" + i;
1044                         String b = "b" + i;
1045                         String c = "c" + i;
1046                         String d = "d" + i;
1047                         IoTString ia = new IoTString(a);
1048                         IoTString ib = new IoTString(b);
1049                         IoTString ic = new IoTString(c);
1050                         IoTString id = new IoTString(d);
1051
1052                         while (true) {
1053                                 try {
1054                                         t1.createNewKey(ia, 321);
1055                                         break;
1056                                 } catch (Exception e) {}
1057                         }
1058
1059                         while (true) {
1060                                 try {
1061                                         t1.createNewKey(ib, 351);
1062                                         break;
1063                                 } catch (Exception e) {}
1064                         }
1065
1066                         while (true) {
1067                                 try {
1068                                         t2.createNewKey(ic, 321);
1069                                         break;
1070                                 } catch (Exception e) {}
1071                         }
1072
1073                         while (true) {
1074                                 try {
1075                                         t2.createNewKey(id, 351);
1076                                         break;
1077                                 } catch (Exception e) {}
1078                         }
1079                 }
1080
1081                 // Do Updates for the keys
1082                 System.out.println("Setting Key-Values...");
1083                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1084                         System.out.println(i);
1085                         String keyA = "a" + i;
1086                         String keyB = "b" + i;
1087                         String keyC = "c" + i;
1088                         String keyD = "d" + i;
1089                         String valueA = "a" + i;
1090                         String valueB = "b" + i;
1091                         String valueC = "c" + i;
1092                         String valueD = "d" + i;
1093
1094                         IoTString iKeyA = new IoTString(keyA);
1095                         IoTString iKeyB = new IoTString(keyB);
1096                         IoTString iKeyC = new IoTString(keyC);
1097                         IoTString iKeyD = new IoTString(keyD);
1098                         IoTString iValueA = new IoTString(valueA);
1099                         IoTString iValueB = new IoTString(valueB);
1100                         IoTString iValueC = new IoTString(valueC);
1101                         IoTString iValueD = new IoTString(valueD);
1102
1103
1104                         String keyAPrev = "a" + (i - 1);
1105                         String keyBPrev = "b" + (i - 1);
1106                         String keyCPrev = "c" + (i - 1);
1107                         String keyDPrev = "d" + (i - 1);
1108                         String valueAPrev = "a" + (i - 1);
1109                         String valueBPrev = "b" + (i - 1);
1110                         String valueCPrev = "c" + (i - 1);
1111                         String valueDPrev = "d" + (i - 1);
1112
1113                         IoTString iKeyAPrev = new IoTString(keyAPrev);
1114                         IoTString iKeyBPrev = new IoTString(keyBPrev);
1115                         IoTString iKeyCPrev = new IoTString(keyCPrev);
1116                         IoTString iKeyDPrev = new IoTString(keyDPrev);
1117                         IoTString iValueAPrev = new IoTString(valueAPrev);
1118                         IoTString iValueBPrev = new IoTString(valueBPrev);
1119                         IoTString iValueCPrev = new IoTString(valueCPrev);
1120                         IoTString iValueDPrev = new IoTString(valueDPrev);
1121
1122                         try {
1123                                 t1.startTransaction();
1124                                 if (i != 0) {
1125                                         IoTString tmp = t1.getSpeculative(iKeyAPrev);
1126                                         if ((tmp == null) || !tmp.equals(iValueAPrev)) {
1127                                                 System.out.println("Key a Error: " + i);
1128                                                 foundError = true;
1129                                         }
1130                                 }
1131                                 t1.addKV(iKeyA, iValueA);
1132                                 t1.commitTransaction();
1133                         } catch (Exception e) {
1134                                 System.out.println("Connection Failure!");
1135                         }
1136
1137                         try {
1138                                 t1.startTransaction();
1139                                 if (i != 0) {
1140                                         IoTString tmp = t1.getSpeculative(iKeyBPrev);
1141                                         if ((tmp == null) || !tmp.equals(iValueBPrev)) {
1142                                                 System.out.println("Key b Error: " + i);
1143                                                 foundError = true;
1144                                         }
1145                                 }
1146                                 t1.addKV(iKeyB, iValueB);
1147                                 t1.commitTransaction();
1148                         } catch (Exception e) {
1149                                 System.out.println("Connection Failure!");
1150                         }
1151
1152                         try {
1153                                 t2.startTransaction();
1154                                 if (i != 0) {
1155                                         IoTString tmp = t2.getSpeculative(iKeyCPrev);
1156                                         if ((tmp == null) || !tmp.equals(iValueCPrev)) {
1157                                                 System.out.println("Key c Error: " + i);
1158                                                 foundError = true;
1159                                         }
1160                                 }
1161                                 t2.addKV(iKeyC, iValueC);
1162                                 t2.commitTransaction();
1163                         } catch (Exception e) {
1164                                 System.out.println("Connection Failure!");
1165                         }
1166
1167                         try {
1168                                 t2.startTransaction();
1169                                 if (i != 0) {
1170                                         IoTString tmp = t2.getSpeculative(iKeyDPrev);
1171                                         if ((tmp == null) || !tmp.equals(iValueDPrev)) {
1172                                                 System.out.println("Key d Error: " + i);
1173                                                 foundError = true;
1174                                         }
1175                                 }
1176                                 t2.addKV(iKeyD, iValueD);
1177                                 t2.commitTransaction();
1178                         } catch (Exception e) {
1179                                 System.out.println("Connection Failure!");
1180                         }
1181                 }
1182
1183                 while (true) {
1184                         try {
1185                                 t1.update();
1186                                 break;
1187                         } catch (Exception e) {
1188
1189                         }
1190                 }
1191
1192                 while (true) {
1193                         try {
1194                                 t2.update();
1195                                 break;
1196                         } catch (Exception e) {
1197
1198                         }
1199                 }
1200
1201                 while (true) {
1202                         try {
1203                                 t1.update();
1204                                 break;
1205                         } catch (Exception e) {
1206
1207                         }
1208                 }
1209
1210                 while (true) {
1211                         try {
1212                                 t2.update();
1213                                 break;
1214                         } catch (Exception e) {
1215
1216                         }
1217                 }
1218
1219
1220                 System.out.println("Checking Key-Values...");
1221                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1222
1223                         String keyA = "a" + i;
1224                         String keyB = "b" + i;
1225                         String keyC = "c" + i;
1226                         String keyD = "d" + i;
1227                         String valueA = "a" + i;
1228                         String valueB = "b" + i;
1229                         String valueC = "c" + i;
1230                         String valueD = "d" + i;
1231
1232                         IoTString iKeyA = new IoTString(keyA);
1233                         IoTString iKeyB = new IoTString(keyB);
1234                         IoTString iKeyC = new IoTString(keyC);
1235                         IoTString iKeyD = new IoTString(keyD);
1236                         IoTString iValueA = new IoTString(valueA);
1237                         IoTString iValueB = new IoTString(valueB);
1238                         IoTString iValueC = new IoTString(valueC);
1239                         IoTString iValueD = new IoTString(valueD);
1240
1241
1242                         IoTString testValA1 = t1.getCommitted(iKeyA);
1243                         IoTString testValB1 = t1.getCommitted(iKeyB);
1244                         IoTString testValC1 = t1.getCommitted(iKeyC);
1245                         IoTString testValD1 = t1.getCommitted(iKeyD);
1246
1247                         IoTString testValA2 = t2.getCommitted(iKeyA);
1248                         IoTString testValB2 = t2.getCommitted(iKeyB);
1249                         IoTString testValC2 = t2.getCommitted(iKeyC);
1250                         IoTString testValD2 = t2.getCommitted(iKeyD);
1251
1252                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1253                                 System.out.println("Key-Value t1 incorrect: " + keyA);
1254                                 foundError = true;
1255                         }
1256
1257                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1258                                 System.out.println("Key-Value t1 incorrect: " + keyB);
1259                                 foundError = true;
1260                         }
1261
1262                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1263                                 System.out.println("Key-Value t1 incorrect: " + keyC);
1264                                 foundError = true;
1265                         }
1266
1267                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1268                                 System.out.println("Key-Value t1 incorrect: " + keyD);
1269                                 foundError = true;
1270                         }
1271
1272
1273                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1274                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
1275                                 foundError = true;
1276                         }
1277
1278                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1279                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
1280                                 foundError = true;
1281                         }
1282
1283                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1284                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
1285                                 foundError = true;
1286                         }
1287
1288                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1289                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
1290                                 foundError = true;
1291                         }
1292                 }
1293
1294                 if (foundError) {
1295                         System.out.println("Found Errors...");
1296                 } else {
1297                         System.out.println("No Errors Found...");
1298                 }
1299         }
1300
1301         static void test7() throws ServerException {
1302
1303                 long startTime = 0;
1304                 long endTime = 0;
1305                 boolean foundError = false;
1306
1307                 // Setup the 2 clients
1308                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
1309                 t1.initTable();
1310                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
1311                 t2.update();
1312
1313                 startTime = System.currentTimeMillis();
1314                 // Make the Keys
1315                 System.out.println("Setting up keys");
1316                 for (int i = 0; i < 4; i++) {
1317                         String a = "a" + i;
1318                         String b = "b" + i;
1319                         String c = "c" + i;
1320                         String d = "d" + i;
1321                         IoTString ia = new IoTString(a);
1322                         IoTString ib = new IoTString(b);
1323                         IoTString ic = new IoTString(c);
1324                         IoTString id = new IoTString(d);
1325                         t1.createNewKey(ia, 321);
1326                         t1.createNewKey(ib, 351);
1327                         t2.createNewKey(ic, 321);
1328                         t2.createNewKey(id, 351);
1329                 }
1330                 endTime = System.currentTimeMillis();
1331                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1332                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (4))   );
1333                 System.out.println();
1334
1335                 // Do Updates for the keys
1336                 System.out.println("Setting Key-Values...");
1337
1338                 startTime = System.currentTimeMillis();
1339                 System.out.println("Setting b...");
1340                 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
1341                         for (int i = 0; i < 4; i++) {
1342                                 String keyB = "b" + i;
1343                                 String valueB = "b" + (i + t);
1344
1345                                 IoTString iKeyB = new IoTString(keyB);
1346                                 IoTString iValueB = new IoTString(valueB);
1347
1348                                 t1.startTransaction();
1349                                 t1.getSpeculativeAtomic(iKeyB);
1350                                 t1.addKV(iKeyB, iValueB);
1351                                 t1.commitTransaction();
1352                         }
1353                 }
1354                 endTime = System.currentTimeMillis();
1355                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1356                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (4 * NUMBER_OF_TESTS))   );
1357                 System.out.println();
1358
1359
1360
1361                 System.out.println("Checking b");
1362                 for (int i = 0; i < 4; i++) {
1363
1364                         String keyB = "b" + i;
1365                         String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
1366                         IoTString iKeyB = new IoTString(keyB);
1367                         IoTString iValueB = new IoTString(valueB);
1368
1369                         IoTString testValB1 = t1.getSpeculative(iKeyB);
1370                         IoTString testValB2 = t2.getSpeculative(iKeyB);
1371
1372                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1373                                 System.out.println("Key-Value t1 incorrect: " + keyB + "    " + testValB1);
1374                                 foundError = true;
1375                         }
1376
1377                         if ((testValB2 != null)) {
1378                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
1379                                 foundError = true;
1380                         }
1381                 }
1382
1383                 startTime = System.currentTimeMillis();
1384                 System.out.println("Setting c...");
1385                 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
1386                         for (int i = 0; i < 4; i++) {
1387                                 String keyC = "c" + i;
1388                                 String valueC = "c" + (i + t);
1389
1390                                 IoTString iKeyC = new IoTString(keyC);
1391                                 IoTString iValueC = new IoTString(valueC);
1392
1393                                 t2.startTransaction();
1394                                 t2.getSpeculativeAtomic(iKeyC);
1395                                 t2.addKV(iKeyC, iValueC);
1396                                 t2.commitTransaction();
1397                         }
1398                 }
1399                 endTime = System.currentTimeMillis();
1400                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1401                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (4 * NUMBER_OF_TESTS))   );
1402                 System.out.println();
1403
1404
1405                 System.out.println("Checking c");
1406                 for (int i = 0; i < 4; i++) {
1407                         String keyC = "c" + i;
1408                         String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
1409                         IoTString iKeyC = new IoTString(keyC);
1410                         IoTString iValueC = new IoTString(valueC);
1411
1412                         IoTString testValC1 = t1.getSpeculative(iKeyC);
1413                         IoTString testValC2 = t2.getSpeculative(iKeyC);
1414
1415                         if ((testValC1 != null)) {
1416                                 System.out.println("Key-Value t1 incorrect: " + keyC + "   " + testValC1);
1417                                 foundError = true;
1418                         }
1419
1420                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1421                                 System.out.println("Key-Value t2 incorrect: " + keyC + "   " + testValC2);
1422                                 foundError = true;
1423                         }
1424                 }
1425
1426                 System.out.println("Setting a and b...");
1427                 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
1428                         for (int i = 0; i < 4; i++) {
1429                                 String keyA = "a" + i;
1430                                 String keyD = "d" + i;
1431                                 String valueA = "a" + (i + t);
1432                                 String valueD = "d" + (i + t);
1433
1434                                 IoTString iKeyA = new IoTString(keyA);
1435                                 IoTString iKeyD = new IoTString(keyD);
1436                                 IoTString iValueA = new IoTString(valueA);
1437                                 IoTString iValueD = new IoTString(valueD);
1438
1439                                 t1.startTransaction();
1440                                 t1.addKV(iKeyA, iValueA);
1441                                 t1.commitTransaction();
1442
1443                                 t2.startTransaction();
1444                                 t2.addKV(iKeyD, iValueD);
1445                                 t2.commitTransaction();
1446                         }
1447                 }
1448
1449                 System.out.println("Updating Clients...");
1450                 t1.update();
1451                 t2.update();
1452                 t1.update();
1453                 t2.update();
1454
1455                 System.out.println("Checking Key-Values...");
1456                 for (int i = 0; i < 4; i++) {
1457
1458                         String keyA = "a" + i;
1459                         String keyB = "b" + i;
1460                         String keyC = "c" + i;
1461                         String keyD = "d" + i;
1462                         String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
1463                         String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
1464                         String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
1465                         String valueD = "d" + (i + NUMBER_OF_TESTS - 1);
1466
1467                         IoTString iKeyA = new IoTString(keyA);
1468                         IoTString iKeyB = new IoTString(keyB);
1469                         IoTString iKeyC = new IoTString(keyC);
1470                         IoTString iKeyD = new IoTString(keyD);
1471                         IoTString iValueA = new IoTString(valueA);
1472                         IoTString iValueB = new IoTString(valueB);
1473                         IoTString iValueC = new IoTString(valueC);
1474                         IoTString iValueD = new IoTString(valueD);
1475
1476
1477                         IoTString testValA1 = t1.getCommitted(iKeyA);
1478                         IoTString testValB1 = t1.getCommitted(iKeyB);
1479                         IoTString testValC1 = t1.getCommitted(iKeyC);
1480                         IoTString testValD1 = t1.getCommitted(iKeyD);
1481
1482                         IoTString testValA2 = t2.getCommitted(iKeyA);
1483                         IoTString testValB2 = t2.getCommitted(iKeyB);
1484                         IoTString testValC2 = t2.getCommitted(iKeyC);
1485                         IoTString testValD2 = t2.getCommitted(iKeyD);
1486
1487                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1488                                 System.out.println("Key-Value t1 incorrect: " + keyA + "    " + testValA1);
1489                                 foundError = true;
1490                         }
1491
1492                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1493                                 System.out.println("Key-Value t1 incorrect: " + keyB + "    " + testValB1);
1494                                 foundError = true;
1495                         }
1496
1497                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1498                                 System.out.println("Key-Value t1 incorrect: " + keyC + "    " + testValC1);
1499                                 foundError = true;
1500                         }
1501
1502                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1503                                 System.out.println("Key-Value t1 incorrect: " + keyD + "    " + testValD1);
1504                                 foundError = true;
1505                         }
1506
1507                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1508                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
1509                                 foundError = true;
1510                         }
1511
1512                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1513                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
1514                                 foundError = true;
1515                         }
1516
1517                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1518                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
1519                                 foundError = true;
1520                         }
1521
1522                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1523                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
1524                                 foundError = true;
1525                         }
1526                 }
1527
1528                 if (foundError) {
1529                         System.out.println("Found Errors...");
1530                 } else {
1531                         System.out.println("No Errors Found...");
1532                 }
1533         }
1534
1535         static void test6()  throws ServerException {
1536                 long startTime = 0;
1537                 long endTime = 0;
1538
1539                 // Setup the 2 clients
1540                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
1541                 t1.initTable();
1542                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
1543                 t2.update();
1544
1545
1546                 // Make the Keys
1547                 System.out.println("Setting up keys");
1548                 startTime = System.currentTimeMillis();
1549                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1550                         String a = "a" + i;
1551                         String b = "b" + i;
1552                         String c = "c" + i;
1553                         String d = "d" + i;
1554                         IoTString ia = new IoTString(a);
1555                         IoTString ib = new IoTString(b);
1556                         IoTString ic = new IoTString(c);
1557                         IoTString id = new IoTString(d);
1558                         t1.createNewKey(ia, 321);
1559                         t1.createNewKey(ib, 351);
1560                         t2.createNewKey(ic, 321);
1561                         t2.createNewKey(id, 351);
1562                 }
1563                 endTime = System.currentTimeMillis();
1564
1565
1566
1567                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1568                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
1569                 System.out.println();
1570
1571
1572                 // Do Updates for the keys
1573                 System.out.println("Setting Key-Values...");
1574                 startTime = System.currentTimeMillis();
1575                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1576                         String keyA = "a" + i;
1577                         String keyB = "b" + i;
1578                         String keyC = "c" + i;
1579                         String keyD = "d" + i;
1580                         String valueA = "a" + i;
1581                         String valueB = "b" + i;
1582                         String valueC = "c" + i;
1583                         String valueD = "d" + i;
1584
1585                         IoTString iKeyA = new IoTString(keyA);
1586                         IoTString iKeyB = new IoTString(keyB);
1587                         IoTString iKeyC = new IoTString(keyC);
1588                         IoTString iKeyD = new IoTString(keyD);
1589                         IoTString iValueA = new IoTString(valueA);
1590                         IoTString iValueB = new IoTString(valueB);
1591                         IoTString iValueC = new IoTString(valueC);
1592                         IoTString iValueD = new IoTString(valueD);
1593
1594                         t1.startTransaction();
1595                         t1.getCommittedAtomic(iKeyA);
1596                         t1.addKV(iKeyA, iValueA);
1597                         t1.commitTransaction();
1598
1599                         t1.startTransaction();
1600                         t1.getCommittedAtomic(iKeyB);
1601                         t1.addKV(iKeyB, iValueB);
1602                         t1.commitTransaction();
1603
1604                         t2.startTransaction();
1605                         t2.getCommittedAtomic(iKeyC);
1606                         t2.addKV(iKeyC, iValueC);
1607                         t2.commitTransaction();
1608
1609                         t2.startTransaction();
1610                         t2.getCommittedAtomic(iKeyD);
1611                         t2.addKV(iKeyD, iValueD);
1612                         t2.commitTransaction();
1613                 }
1614                 endTime = System.currentTimeMillis();
1615
1616                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1617                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
1618                 System.out.println();
1619
1620
1621                 System.out.println("Updating Clients...");
1622                 t1.update();
1623                 t2.update();
1624                 t1.update();
1625                 t2.update();
1626
1627                 boolean foundError = false;
1628
1629                 System.out.println("Checking Key-Values...");
1630                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1631
1632                         String keyA = "a" + i;
1633                         String keyB = "b" + i;
1634                         String keyC = "c" + i;
1635                         String keyD = "d" + i;
1636                         String valueA = "a" + i;
1637                         String valueB = "b" + i;
1638                         String valueC = "c" + i;
1639                         String valueD = "d" + i;
1640
1641                         IoTString iKeyA = new IoTString(keyA);
1642                         IoTString iKeyB = new IoTString(keyB);
1643                         IoTString iKeyC = new IoTString(keyC);
1644                         IoTString iKeyD = new IoTString(keyD);
1645                         IoTString iValueA = new IoTString(valueA);
1646                         IoTString iValueB = new IoTString(valueB);
1647                         IoTString iValueC = new IoTString(valueC);
1648                         IoTString iValueD = new IoTString(valueD);
1649
1650
1651                         IoTString testValA1 = t1.getCommitted(iKeyA);
1652                         IoTString testValB1 = t1.getCommitted(iKeyB);
1653                         IoTString testValC1 = t1.getCommitted(iKeyC);
1654                         IoTString testValD1 = t1.getCommitted(iKeyD);
1655
1656                         IoTString testValA2 = t2.getCommitted(iKeyA);
1657                         IoTString testValB2 = t2.getCommitted(iKeyB);
1658                         IoTString testValC2 = t2.getCommitted(iKeyC);
1659                         IoTString testValD2 = t2.getCommitted(iKeyD);
1660
1661                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1662                                 System.out.println("Key-Value t1 incorrect: " + keyA);
1663                                 foundError = true;
1664                         }
1665
1666                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1667                                 System.out.println("Key-Value t1 incorrect: " + keyB);
1668                                 foundError = true;
1669                         }
1670
1671                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1672                                 System.out.println("Key-Value t1 incorrect: " + keyC);
1673                                 foundError = true;
1674                         }
1675
1676                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1677                                 System.out.println("Key-Value t1 incorrect: " + keyD);
1678                                 foundError = true;
1679                         }
1680
1681
1682                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1683                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
1684                                 foundError = true;
1685                         }
1686
1687                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1688                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
1689                                 foundError = true;
1690                         }
1691
1692                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1693                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
1694                                 foundError = true;
1695                         }
1696
1697                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1698                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
1699                                 foundError = true;
1700                         }
1701                 }
1702
1703                 if (foundError) {
1704                         System.out.println("Found Errors...");
1705                 } else {
1706                         System.out.println("No Errors Found...");
1707                 }
1708
1709                 // System.out.println();
1710                 // System.out.println();
1711                 // System.out.println();
1712                 // t1.printSlots();
1713                 // System.out.println();
1714                 // System.out.println();
1715                 // System.out.println();
1716                 // t2.printSlots();
1717         }
1718
1719         static void test5() throws ServerException {
1720
1721                 long startTime = 0;
1722                 long endTime = 0;
1723                 boolean foundError = false;
1724
1725                 // Setup the 2 clients
1726                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
1727                 t1.initTable();
1728                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
1729                 t2.update();
1730
1731
1732                 // Make the Keys
1733                 System.out.println("Setting up keys");
1734                 for (int i = 0; i < 4; i++) {
1735                         String a = "a" + i;
1736                         String b = "b" + i;
1737                         String c = "c" + i;
1738                         String d = "d" + i;
1739                         IoTString ia = new IoTString(a);
1740                         IoTString ib = new IoTString(b);
1741                         IoTString ic = new IoTString(c);
1742                         IoTString id = new IoTString(d);
1743                         t1.createNewKey(ia, 321);
1744                         t1.createNewKey(ib, 351);
1745                         t2.createNewKey(ic, 321);
1746                         t2.createNewKey(id, 351);
1747                 }
1748                 endTime = System.currentTimeMillis();
1749
1750
1751
1752                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1753                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (4))   );
1754                 System.out.println();
1755
1756
1757                 // Do Updates for the keys
1758                 System.out.println("Setting Key-Values...");
1759
1760                 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
1761                         for (int i = 0; i < 4; i++) {
1762                                 String keyB = "b" + i;
1763                                 String valueB = "b" + (i + t);
1764
1765                                 IoTString iKeyB = new IoTString(keyB);
1766                                 IoTString iValueB = new IoTString(valueB);
1767
1768                                 t1.startTransaction();
1769                                 t1.addKV(iKeyB, iValueB);
1770                                 t1.commitTransaction();
1771                         }
1772                 }
1773
1774                 for (int i = 0; i < 4; i++) {
1775
1776                         String keyB = "b" + i;
1777                         String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
1778                         IoTString iKeyB = new IoTString(keyB);
1779                         IoTString iValueB = new IoTString(valueB);
1780
1781                         IoTString testValB1 = t1.getSpeculative(iKeyB);
1782                         IoTString testValB2 = t2.getSpeculative(iKeyB);
1783
1784                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1785                                 System.out.println("Key-Value t1 incorrect: " + keyB);
1786                                 foundError = true;
1787                         }
1788
1789                         if ((testValB2 != null)) {
1790                                 System.out.println("Key-Value t2 incorrect: " + keyB);
1791                                 foundError = true;
1792                         }
1793                 }
1794
1795                 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
1796                         for (int i = 0; i < 4; i++) {
1797                                 String keyC = "c" + i;
1798                                 String valueC = "c" + (i + t);
1799
1800                                 IoTString iKeyC = new IoTString(keyC);
1801                                 IoTString iValueC = new IoTString(valueC);
1802
1803                                 t2.startTransaction();
1804                                 t2.addKV(iKeyC, iValueC);
1805                                 t2.commitTransaction();
1806                         }
1807                 }
1808
1809                 for (int i = 0; i < 4; i++) {
1810                         String keyC = "c" + i;
1811                         String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
1812                         IoTString iKeyC = new IoTString(keyC);
1813                         IoTString iValueC = new IoTString(valueC);
1814
1815                         IoTString testValC1 = t1.getSpeculative(iKeyC);
1816                         IoTString testValC2 = t2.getSpeculative(iKeyC);
1817
1818                         if ((testValC1 != null)) {
1819                                 System.out.println("Key-Value t1 incorrect: " + keyC + "   " + testValC1);
1820                                 foundError = true;
1821                         }
1822
1823                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1824                                 System.out.println("Key-Value t2 incorrect: " + keyC + "   " + testValC2);
1825                                 foundError = true;
1826                         }
1827                 }
1828
1829                 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
1830                         for (int i = 0; i < 4; i++) {
1831                                 String keyA = "a" + i;
1832                                 String keyD = "d" + i;
1833                                 String valueA = "a" + (i + t);
1834                                 String valueD = "d" + (i + t);
1835
1836                                 IoTString iKeyA = new IoTString(keyA);
1837                                 IoTString iKeyD = new IoTString(keyD);
1838                                 IoTString iValueA = new IoTString(valueA);
1839                                 IoTString iValueD = new IoTString(valueD);
1840
1841                                 t1.startTransaction();
1842                                 t1.addKV(iKeyA, iValueA);
1843                                 t1.commitTransaction();
1844
1845                                 t2.startTransaction();
1846                                 t2.addKV(iKeyD, iValueD);
1847                                 t2.commitTransaction();
1848                         }
1849                 }
1850
1851                 System.out.println("Updating Clients...");
1852                 t1.update();
1853                 t2.update();
1854                 t1.update();
1855                 t2.update();
1856
1857
1858                 System.out.println("Checking Key-Values...");
1859                 for (int i = 0; i < 4; i++) {
1860
1861                         String keyA = "a" + i;
1862                         String keyB = "b" + i;
1863                         String keyC = "c" + i;
1864                         String keyD = "d" + i;
1865                         String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
1866                         String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
1867                         String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
1868                         String valueD = "d" + (i + NUMBER_OF_TESTS - 1);
1869
1870                         IoTString iKeyA = new IoTString(keyA);
1871                         IoTString iKeyB = new IoTString(keyB);
1872                         IoTString iKeyC = new IoTString(keyC);
1873                         IoTString iKeyD = new IoTString(keyD);
1874                         IoTString iValueA = new IoTString(valueA);
1875                         IoTString iValueB = new IoTString(valueB);
1876                         IoTString iValueC = new IoTString(valueC);
1877                         IoTString iValueD = new IoTString(valueD);
1878
1879
1880                         IoTString testValA1 = t1.getCommitted(iKeyA);
1881                         IoTString testValB1 = t1.getCommitted(iKeyB);
1882                         IoTString testValC1 = t1.getCommitted(iKeyC);
1883                         IoTString testValD1 = t1.getCommitted(iKeyD);
1884
1885                         IoTString testValA2 = t2.getCommitted(iKeyA);
1886                         IoTString testValB2 = t2.getCommitted(iKeyB);
1887                         IoTString testValC2 = t2.getCommitted(iKeyC);
1888                         IoTString testValD2 = t2.getCommitted(iKeyD);
1889
1890                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1891                                 System.out.println("Key-Value t1 incorrect: " + keyA + "    " + testValA1);
1892                                 foundError = true;
1893                         }
1894
1895                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1896                                 System.out.println("Key-Value t1 incorrect: " + keyB + "    " + testValB1);
1897                                 foundError = true;
1898                         }
1899
1900                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1901                                 System.out.println("Key-Value t1 incorrect: " + keyC + "    " + testValC1);
1902                                 foundError = true;
1903                         }
1904
1905                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1906                                 System.out.println("Key-Value t1 incorrect: " + keyD + "    " + testValD1);
1907                                 foundError = true;
1908                         }
1909
1910
1911                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1912                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
1913                                 foundError = true;
1914                         }
1915
1916                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1917                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
1918                                 foundError = true;
1919                         }
1920
1921                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1922                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
1923                                 foundError = true;
1924                         }
1925
1926                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1927                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
1928                                 foundError = true;
1929                         }
1930                 }
1931
1932                 if (foundError) {
1933                         System.out.println("Found Errors...");
1934                 } else {
1935                         System.out.println("No Errors Found...");
1936                 }
1937         }
1938
1939         static void test4() throws ServerException {
1940
1941                 long startTime = 0;
1942                 long endTime = 0;
1943
1944                 // Setup the 2 clients
1945                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
1946                 t1.initTable();
1947                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
1948                 t2.update();
1949
1950
1951                 // Make the Keys
1952                 System.out.println("Setting up keys");
1953                 startTime = System.currentTimeMillis();
1954                 for (int i = 0; i < 4; i++) {
1955                         String a = "a" + i;
1956                         String b = "b" + i;
1957                         String c = "c" + i;
1958                         String d = "d" + i;
1959                         IoTString ia = new IoTString(a);
1960                         IoTString ib = new IoTString(b);
1961                         IoTString ic = new IoTString(c);
1962                         IoTString id = new IoTString(d);
1963                         t1.createNewKey(ia, 321);
1964                         t1.createNewKey(ib, 351);
1965                         t2.createNewKey(ic, 321);
1966                         t2.createNewKey(id, 351);
1967                 }
1968                 endTime = System.currentTimeMillis();
1969
1970
1971
1972                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1973                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
1974                 System.out.println();
1975
1976
1977                 // Do Updates for the keys
1978                 System.out.println("Setting Key-Values...");
1979                 startTime = System.currentTimeMillis();
1980                 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
1981                         for (int i = 0; i < 4; i++) {
1982                                 String keyA = "a" + i;
1983                                 String keyB = "b" + i;
1984                                 String keyC = "c" + i;
1985                                 String keyD = "d" + i;
1986                                 String valueA = "a" + i;
1987                                 String valueB = "b" + i;
1988                                 String valueC = "c" + i;
1989                                 String valueD = "d" + i;
1990
1991                                 IoTString iKeyA = new IoTString(keyA);
1992                                 IoTString iKeyB = new IoTString(keyB);
1993                                 IoTString iKeyC = new IoTString(keyC);
1994                                 IoTString iKeyD = new IoTString(keyD);
1995                                 IoTString iValueA = new IoTString(valueA);
1996                                 IoTString iValueB = new IoTString(valueB);
1997                                 IoTString iValueC = new IoTString(valueC);
1998                                 IoTString iValueD = new IoTString(valueD);
1999
2000                                 t1.startTransaction();
2001                                 t1.addKV(iKeyA, iValueA);
2002                                 t1.commitTransaction();
2003
2004                                 t1.startTransaction();
2005                                 t1.addKV(iKeyB, iValueB);
2006                                 t1.commitTransaction();
2007
2008                                 t2.startTransaction();
2009                                 t2.addKV(iKeyC, iValueC);
2010                                 t2.commitTransaction();
2011
2012                                 t2.startTransaction();
2013                                 t2.addKV(iKeyD, iValueD);
2014                                 t2.commitTransaction();
2015                         }
2016                 }
2017                 endTime = System.currentTimeMillis();
2018
2019                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
2020                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 16))   );
2021                 System.out.println();
2022
2023
2024                 System.out.println("Updating Clients...");
2025                 t1.update();
2026                 t2.update();
2027                 t1.update();
2028                 t2.update();
2029
2030                 boolean foundError = false;
2031
2032                 System.out.println("Checking Key-Values...");
2033                 for (int i = 0; i < 4; i++) {
2034
2035                         String keyA = "a" + i;
2036                         String keyB = "b" + i;
2037                         String keyC = "c" + i;
2038                         String keyD = "d" + i;
2039                         String valueA = "a" + i;
2040                         String valueB = "b" + i;
2041                         String valueC = "c" + i;
2042                         String valueD = "d" + i;
2043
2044                         IoTString iKeyA = new IoTString(keyA);
2045                         IoTString iKeyB = new IoTString(keyB);
2046                         IoTString iKeyC = new IoTString(keyC);
2047                         IoTString iKeyD = new IoTString(keyD);
2048                         IoTString iValueA = new IoTString(valueA);
2049                         IoTString iValueB = new IoTString(valueB);
2050                         IoTString iValueC = new IoTString(valueC);
2051                         IoTString iValueD = new IoTString(valueD);
2052
2053
2054                         IoTString testValA1 = t1.getCommitted(iKeyA);
2055                         IoTString testValB1 = t1.getCommitted(iKeyB);
2056                         IoTString testValC1 = t1.getCommitted(iKeyC);
2057                         IoTString testValD1 = t1.getCommitted(iKeyD);
2058
2059                         IoTString testValA2 = t2.getCommitted(iKeyA);
2060                         IoTString testValB2 = t2.getCommitted(iKeyB);
2061                         IoTString testValC2 = t2.getCommitted(iKeyC);
2062                         IoTString testValD2 = t2.getCommitted(iKeyD);
2063
2064                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
2065                                 System.out.println("Key-Value t1 incorrect: " + keyA);
2066                                 foundError = true;
2067                         }
2068
2069                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
2070                                 System.out.println("Key-Value t1 incorrect: " + keyB);
2071                                 foundError = true;
2072                         }
2073
2074                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
2075                                 System.out.println("Key-Value t1 incorrect: " + keyC);
2076                                 foundError = true;
2077                         }
2078
2079                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
2080                                 System.out.println("Key-Value t1 incorrect: " + keyD);
2081                                 foundError = true;
2082                         }
2083
2084
2085                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
2086                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
2087                                 foundError = true;
2088                         }
2089
2090                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
2091                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
2092                                 foundError = true;
2093                         }
2094
2095                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
2096                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
2097                                 foundError = true;
2098                         }
2099
2100                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
2101                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
2102                                 foundError = true;
2103                         }
2104                 }
2105
2106                 if (foundError) {
2107                         System.out.println("Found Errors...");
2108                 } else {
2109                         System.out.println("No Errors Found...");
2110                 }
2111         }
2112
2113         static void test3() throws ServerException {
2114
2115                 long startTime = 0;
2116                 long endTime = 0;
2117                 boolean foundError = false;
2118
2119                 // Setup the 2 clients
2120                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
2121                 t1.initTable();
2122                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
2123                 t2.update();
2124
2125
2126                 // Make the Keys
2127                 System.out.println("Setting up keys");
2128                 startTime = System.currentTimeMillis();
2129                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
2130                         String a = "a" + i;
2131                         String b = "b" + i;
2132                         String c = "c" + i;
2133                         String d = "d" + i;
2134                         IoTString ia = new IoTString(a);
2135                         IoTString ib = new IoTString(b);
2136                         IoTString ic = new IoTString(c);
2137                         IoTString id = new IoTString(d);
2138                         t1.createNewKey(ia, 321);
2139                         t1.createNewKey(ib, 351);
2140                         t2.createNewKey(ic, 321);
2141                         t2.createNewKey(id, 351);
2142                 }
2143                 endTime = System.currentTimeMillis();
2144
2145
2146
2147                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
2148                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
2149                 System.out.println();
2150
2151
2152                 // Do Updates for the keys
2153                 System.out.println("Setting Key-Values...");
2154                 startTime = System.currentTimeMillis();
2155                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
2156                         String keyB = "b" + i;
2157                         String valueB = "b" + i;
2158
2159                         IoTString iKeyB = new IoTString(keyB);
2160                         IoTString iValueB = new IoTString(valueB);
2161
2162                         t1.startTransaction();
2163                         t1.addKV(iKeyB, iValueB);
2164                         t1.commitTransaction();
2165                 }
2166
2167                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
2168                         String keyC = "c" + i;
2169                         String valueC = "c" + i;
2170
2171                         IoTString iKeyC = new IoTString(keyC);
2172                         IoTString iValueC = new IoTString(valueC);
2173
2174                         t2.startTransaction();
2175                         t2.addKV(iKeyC, iValueC);
2176                         t2.commitTransaction();
2177                 }
2178
2179                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
2180                         String keyA = "a" + i;
2181                         String keyD = "d" + i;
2182                         String valueA = "a" + i;
2183                         String valueD = "d" + i;
2184
2185                         IoTString iKeyA = new IoTString(keyA);
2186                         IoTString iKeyD = new IoTString(keyD);
2187                         IoTString iValueA = new IoTString(valueA);
2188                         IoTString iValueD = new IoTString(valueD);
2189
2190                         t1.startTransaction();
2191                         t1.addKV(iKeyA, iValueA);
2192                         t1.commitTransaction();
2193
2194                         t2.startTransaction();
2195                         t2.addKV(iKeyD, iValueD);
2196                         t2.commitTransaction();
2197                 }
2198                 endTime = System.currentTimeMillis();
2199
2200                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
2201                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
2202                 System.out.println();
2203
2204
2205                 System.out.println("Updating Clients...");
2206                 t1.update();
2207                 t2.update();
2208                 t1.update();
2209                 t2.update();
2210
2211
2212                 System.out.println("Checking Key-Values...");
2213                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
2214
2215                         String keyA = "a" + i;
2216                         String keyB = "b" + i;
2217                         String keyC = "c" + i;
2218                         String keyD = "d" + i;
2219                         String valueA = "a" + i;
2220                         String valueB = "b" + i;
2221                         String valueC = "c" + i;
2222                         String valueD = "d" + i;
2223
2224                         IoTString iKeyA = new IoTString(keyA);
2225                         IoTString iKeyB = new IoTString(keyB);
2226                         IoTString iKeyC = new IoTString(keyC);
2227                         IoTString iKeyD = new IoTString(keyD);
2228                         IoTString iValueA = new IoTString(valueA);
2229                         IoTString iValueB = new IoTString(valueB);
2230                         IoTString iValueC = new IoTString(valueC);
2231                         IoTString iValueD = new IoTString(valueD);
2232
2233
2234                         IoTString testValA1 = t1.getCommitted(iKeyA);
2235                         IoTString testValB1 = t1.getCommitted(iKeyB);
2236                         IoTString testValC1 = t1.getCommitted(iKeyC);
2237                         IoTString testValD1 = t1.getCommitted(iKeyD);
2238
2239                         IoTString testValA2 = t2.getCommitted(iKeyA);
2240                         IoTString testValB2 = t2.getCommitted(iKeyB);
2241                         IoTString testValC2 = t2.getCommitted(iKeyC);
2242                         IoTString testValD2 = t2.getCommitted(iKeyD);
2243
2244                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
2245                                 System.out.println("Key-Value t1 incorrect: " + keyA);
2246                                 foundError = true;
2247                         }
2248
2249                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
2250                                 System.out.println("Key-Value t1 incorrect: " + keyB);
2251                                 foundError = true;
2252                         }
2253
2254                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
2255                                 System.out.println("Key-Value t1 incorrect: " + keyC);
2256                                 foundError = true;
2257                         }
2258
2259                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
2260                                 System.out.println("Key-Value t1 incorrect: " + keyD);
2261                                 foundError = true;
2262                         }
2263
2264
2265                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
2266                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
2267                                 foundError = true;
2268                         }
2269
2270                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
2271                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
2272                                 foundError = true;
2273                         }
2274
2275                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
2276                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
2277                                 foundError = true;
2278                         }
2279
2280                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
2281                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
2282                                 foundError = true;
2283                         }
2284                 }
2285
2286                 if (foundError) {
2287                         System.out.println("Found Errors...");
2288                 } else {
2289                         System.out.println("No Errors Found...");
2290                 }
2291         }
2292
2293         static void test2() throws ServerException {
2294
2295                 long startTime = 0;
2296                 long endTime = 0;
2297
2298                 // Setup the 2 clients
2299                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
2300                 t1.initTable();
2301                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
2302                 t2.update();
2303
2304                 // Make the Keys
2305                 System.out.println("Setting up keys");
2306                 startTime = System.currentTimeMillis();
2307                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
2308                         String a = "a" + i;
2309                         String b = "b" + i;
2310                         String c = "c" + i;
2311                         String d = "d" + i;
2312                         IoTString ia = new IoTString(a);
2313                         IoTString ib = new IoTString(b);
2314                         IoTString ic = new IoTString(c);
2315                         IoTString id = new IoTString(d);
2316                         t1.createNewKey(ia, 321);
2317                         t1.createNewKey(ib, 351);
2318                         t2.createNewKey(ic, 321);
2319                         t2.createNewKey(id, 351);
2320                 }
2321                 endTime = System.currentTimeMillis();
2322
2323
2324
2325                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
2326                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
2327                 System.out.println();
2328
2329
2330                 // Do Updates for the keys
2331                 System.out.println("Setting Key-Values...");
2332                 startTime = System.currentTimeMillis();
2333                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
2334                         String keyA = "a" + i;
2335                         String keyB = "b" + i;
2336                         String keyC = "c" + i;
2337                         String keyD = "d" + i;
2338                         String valueA = "a" + i;
2339                         String valueB = "b" + i;
2340                         String valueC = "c" + i;
2341                         String valueD = "d" + i;
2342
2343                         IoTString iKeyA = new IoTString(keyA);
2344                         IoTString iKeyB = new IoTString(keyB);
2345                         IoTString iKeyC = new IoTString(keyC);
2346                         IoTString iKeyD = new IoTString(keyD);
2347                         IoTString iValueA = new IoTString(valueA);
2348                         IoTString iValueB = new IoTString(valueB);
2349                         IoTString iValueC = new IoTString(valueC);
2350                         IoTString iValueD = new IoTString(valueD);
2351
2352                         t1.startTransaction();
2353                         t1.addKV(iKeyA, iValueA);
2354                         t1.commitTransaction();
2355
2356                         t1.startTransaction();
2357                         t1.addKV(iKeyB, iValueB);
2358                         t1.commitTransaction();
2359
2360                         t2.startTransaction();
2361                         t2.addKV(iKeyC, iValueC);
2362                         t2.commitTransaction();
2363
2364                         t2.startTransaction();
2365                         t2.addKV(iKeyD, iValueD);
2366                         t2.commitTransaction();
2367                 }
2368                 endTime = System.currentTimeMillis();
2369
2370                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
2371                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
2372                 System.out.println();
2373
2374
2375                 System.out.println("Updating Clients...");
2376                 t1.update();
2377                 t2.update();
2378                 t1.update();
2379                 t2.update();
2380
2381                 boolean foundError = false;
2382
2383                 System.out.println("Checking Key-Values...");
2384                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
2385
2386                         String keyA = "a" + i;
2387                         String keyB = "b" + i;
2388                         String keyC = "c" + i;
2389                         String keyD = "d" + i;
2390                         String valueA = "a" + i;
2391                         String valueB = "b" + i;
2392                         String valueC = "c" + i;
2393                         String valueD = "d" + i;
2394
2395                         IoTString iKeyA = new IoTString(keyA);
2396                         IoTString iKeyB = new IoTString(keyB);
2397                         IoTString iKeyC = new IoTString(keyC);
2398                         IoTString iKeyD = new IoTString(keyD);
2399                         IoTString iValueA = new IoTString(valueA);
2400                         IoTString iValueB = new IoTString(valueB);
2401                         IoTString iValueC = new IoTString(valueC);
2402                         IoTString iValueD = new IoTString(valueD);
2403
2404
2405                         IoTString testValA1 = t1.getCommitted(iKeyA);
2406                         IoTString testValB1 = t1.getCommitted(iKeyB);
2407                         IoTString testValC1 = t1.getCommitted(iKeyC);
2408                         IoTString testValD1 = t1.getCommitted(iKeyD);
2409
2410                         IoTString testValA2 = t2.getCommitted(iKeyA);
2411                         IoTString testValB2 = t2.getCommitted(iKeyB);
2412                         IoTString testValC2 = t2.getCommitted(iKeyC);
2413                         IoTString testValD2 = t2.getCommitted(iKeyD);
2414
2415                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
2416                                 System.out.println("Key-Value t1 incorrect: " + keyA);
2417                                 foundError = true;
2418                         }
2419
2420                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
2421                                 System.out.println("Key-Value t1 incorrect: " + keyB);
2422                                 foundError = true;
2423                         }
2424
2425                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
2426                                 System.out.println("Key-Value t1 incorrect: " + keyC);
2427                                 foundError = true;
2428                         }
2429
2430                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
2431                                 System.out.println("Key-Value t1 incorrect: " + keyD);
2432                                 foundError = true;
2433                         }
2434
2435
2436                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
2437                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
2438                                 foundError = true;
2439                         }
2440
2441                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
2442                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
2443                                 foundError = true;
2444                         }
2445
2446                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
2447                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
2448                                 foundError = true;
2449                         }
2450
2451                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
2452                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
2453                                 foundError = true;
2454                         }
2455                 }
2456
2457                 if (foundError) {
2458                         System.out.println("Found Errors...");
2459                 } else {
2460                         System.out.println("No Errors Found...");
2461                 }
2462         }
2463 }