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