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