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