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