Block Chain Transactions, Commits multiple parts version
[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 = 100;
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         }
30     }
31
32     static void test7() throws ServerException {
33
34         boolean foundError = false;
35         List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
36
37         // Setup the 2 clients
38         Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
39         t1.initTable();
40         Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
41         t2.update();
42
43         // Make the Keys
44         System.out.println("Setting up keys");
45         for (int i = 0; i < 4; i++) {
46             String a = "a" + i;
47             String b = "b" + i;
48             String c = "c" + i;
49             String d = "d" + i;
50             IoTString ia = new IoTString(a);
51             IoTString ib = new IoTString(b);
52             IoTString ic = new IoTString(c);
53             IoTString id = new IoTString(d);
54             t1.createNewKey(ia, 321);
55             t1.createNewKey(ib, 351);
56             t2.createNewKey(ic, 321);
57             t2.createNewKey(id, 351);
58         }
59
60         // Do Updates for the keys
61         System.out.println("Setting Key-Values...");
62
63         for (int t = 0; t < NUMBER_OF_TESTS; t++) {
64             for (int i = 0; i < 4; i++) {
65                 String keyB = "b" + i;
66                 String valueB = "b" + (i + t);
67
68                 IoTString iKeyB = new IoTString(keyB);
69                 IoTString iValueB = new IoTString(valueB);
70
71                 t1.startTransaction();
72                 t1.getSpeculativeAtomic(iKeyB);
73                 t1.addKV(iKeyB, iValueB);
74                 transStatusList.add(t1.commitTransaction());
75             }
76         }
77
78         for (int i = 0; i < 4; i++) {
79
80             String keyB = "b" + i;
81             String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
82             IoTString iKeyB = new IoTString(keyB);
83             IoTString iValueB = new IoTString(valueB);
84
85             IoTString testValB1 = t1.getSpeculative(iKeyB);
86             IoTString testValB2 = t2.getSpeculative(iKeyB);
87
88             if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
89                 System.out.println("Key-Value t1 incorrect: " + keyB + "    " + testValB1);
90                 foundError = true;
91             }
92
93             if ((testValB2 != null)) {
94                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
95                 foundError = true;
96             }
97         }
98
99         for (int t = 0; t < NUMBER_OF_TESTS; t++) {
100             for (int i = 0; i < 4; i++) {
101                 String keyC = "c" + i;
102                 String valueC = "c" + (i + t);
103
104                 IoTString iKeyC = new IoTString(keyC);
105                 IoTString iValueC = new IoTString(valueC);
106
107                 t2.startTransaction();
108                 t2.getSpeculativeAtomic(iKeyC);
109                 t2.addKV(iKeyC, iValueC);
110                 transStatusList.add(t2.commitTransaction());
111             }
112         }
113
114         for (int i = 0; i < 4; i++) {
115             String keyC = "c" + i;
116             String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
117             IoTString iKeyC = new IoTString(keyC);
118             IoTString iValueC = new IoTString(valueC);
119
120             IoTString testValC1 = t1.getSpeculative(iKeyC);
121             IoTString testValC2 = t2.getSpeculative(iKeyC);
122
123             if ((testValC1 != null)) {
124                 System.out.println("Key-Value t1 incorrect: " + keyC + "   " + testValC1);
125                 foundError = true;
126             }
127
128             if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
129                 System.out.println("Key-Value t2 incorrect: " + keyC + "   " + testValC2);
130                 foundError = true;
131             }
132         }
133
134         for (int t = 0; t < NUMBER_OF_TESTS; t++) {
135             for (int i = 0; i < 4; i++) {
136                 String keyA = "a" + i;
137                 String keyD = "d" + i;
138                 String valueA = "a" + (i + t);
139                 String valueD = "d" + (i + t);
140
141                 IoTString iKeyA = new IoTString(keyA);
142                 IoTString iKeyD = new IoTString(keyD);
143                 IoTString iValueA = new IoTString(valueA);
144                 IoTString iValueD = new IoTString(valueD);
145
146                 t1.startTransaction();
147                 t1.addKV(iKeyA, iValueA);
148                 transStatusList.add(t1.commitTransaction());
149
150                 t2.startTransaction();
151                 t2.addKV(iKeyD, iValueD);
152                 transStatusList.add(t2.commitTransaction());
153             }
154         }
155
156         System.out.println("Updating Clients...");
157         t1.update();
158         t2.update();
159         t1.update();
160         t2.update();
161
162         System.out.println("Checking Key-Values...");
163         for (int i = 0; i < 4; i++) {
164
165             String keyA = "a" + i;
166             String keyB = "b" + i;
167             String keyC = "c" + i;
168             String keyD = "d" + i;
169             String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
170             String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
171             String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
172             String valueD = "d" + (i + NUMBER_OF_TESTS - 1);
173
174             IoTString iKeyA = new IoTString(keyA);
175             IoTString iKeyB = new IoTString(keyB);
176             IoTString iKeyC = new IoTString(keyC);
177             IoTString iKeyD = new IoTString(keyD);
178             IoTString iValueA = new IoTString(valueA);
179             IoTString iValueB = new IoTString(valueB);
180             IoTString iValueC = new IoTString(valueC);
181             IoTString iValueD = new IoTString(valueD);
182
183
184             IoTString testValA1 = t1.getCommitted(iKeyA);
185             IoTString testValB1 = t1.getCommitted(iKeyB);
186             IoTString testValC1 = t1.getCommitted(iKeyC);
187             IoTString testValD1 = t1.getCommitted(iKeyD);
188
189             IoTString testValA2 = t2.getCommitted(iKeyA);
190             IoTString testValB2 = t2.getCommitted(iKeyB);
191             IoTString testValC2 = t2.getCommitted(iKeyC);
192             IoTString testValD2 = t2.getCommitted(iKeyD);
193
194             if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
195                 System.out.println("Key-Value t1 incorrect: " + keyA + "    " + testValA1);
196                 foundError = true;
197             }
198
199             if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
200                 System.out.println("Key-Value t1 incorrect: " + keyB + "    " + testValB1);
201                 foundError = true;
202             }
203
204             if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
205                 System.out.println("Key-Value t1 incorrect: " + keyC + "    " + testValC1);
206                 foundError = true;
207             }
208
209             if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
210                 System.out.println("Key-Value t1 incorrect: " + keyD + "    " + testValD1);
211                 foundError = true;
212             }
213
214             if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
215                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
216                 foundError = true;
217             }
218
219             if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
220                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
221                 foundError = true;
222             }
223
224             if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
225                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
226                 foundError = true;
227             }
228
229             if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
230                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
231                 foundError = true;
232             }
233         }
234
235         for (TransactionStatus status : transStatusList) {
236             if (status.getStatus() != TransactionStatus.StatusCommitted) {
237                 foundError = true;
238             }
239         }
240
241         if (foundError) {
242             System.out.println("Found Errors...");
243         } else {
244             System.out.println("No Errors Found...");
245         }
246     }
247
248     static void test6() throws ServerException {
249
250         boolean foundError = false;
251         List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
252
253         // Setup the 2 clients
254         Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
255         t1.initTable();
256         Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
257         t2.update();
258
259         // Make the Keys
260         System.out.println("Setting up keys");
261         for (int i = 0; i < NUMBER_OF_TESTS; i++) {
262             String a = "a" + i;
263             String b = "b" + i;
264             String c = "c" + i;
265             String d = "d" + i;
266             IoTString ia = new IoTString(a);
267             IoTString ib = new IoTString(b);
268             IoTString ic = new IoTString(c);
269             IoTString id = new IoTString(d);
270             t1.createNewKey(ia, 321);
271             t1.createNewKey(ib, 351);
272             t2.createNewKey(ic, 321);
273             t2.createNewKey(id, 351);
274         }
275
276         // Do Updates for the keys
277         System.out.println("Setting Key-Values...");
278         for (int i = 0; i < NUMBER_OF_TESTS; i++) {
279             String keyA = "a" + i;
280             String keyB = "b" + i;
281             String keyC = "c" + i;
282             String keyD = "d" + i;
283             String valueA = "a" + i;
284             String valueB = "b" + i;
285             String valueC = "c" + i;
286             String valueD = "d" + i;
287
288             IoTString iKeyA = new IoTString(keyA);
289             IoTString iKeyB = new IoTString(keyB);
290             IoTString iKeyC = new IoTString(keyC);
291             IoTString iKeyD = new IoTString(keyD);
292             IoTString iValueA = new IoTString(valueA);
293             IoTString iValueB = new IoTString(valueB);
294             IoTString iValueC = new IoTString(valueC);
295             IoTString iValueD = new IoTString(valueD);
296
297             t1.startTransaction();
298             t1.getCommittedAtomic(iKeyA);
299             t1.addKV(iKeyA, iValueA);
300             transStatusList.add(t1.commitTransaction());
301
302             t1.startTransaction();
303             t1.getCommittedAtomic(iKeyB);
304             t1.addKV(iKeyB, iValueB);
305             transStatusList.add(t1.commitTransaction());
306
307             t2.startTransaction();
308             t2.getCommittedAtomic(iKeyC);
309             t2.addKV(iKeyC, iValueC);
310             transStatusList.add(t2.commitTransaction());
311
312             t2.startTransaction();
313             t2.getCommittedAtomic(iKeyD);
314             t2.addKV(iKeyD, iValueD);
315             transStatusList.add(t2.commitTransaction());
316         }
317
318         System.out.println("Updating Clients...");
319         t1.update();
320         t2.update();
321
322         System.out.println("Checking Key-Values...");
323         for (int i = 0; i < NUMBER_OF_TESTS; i++) {
324
325             String keyA = "a" + i;
326             String keyB = "b" + i;
327             String keyC = "c" + i;
328             String keyD = "d" + i;
329             String valueA = "a" + i;
330             String valueB = "b" + i;
331             String valueC = "c" + i;
332             String valueD = "d" + i;
333
334             IoTString iKeyA = new IoTString(keyA);
335             IoTString iKeyB = new IoTString(keyB);
336             IoTString iKeyC = new IoTString(keyC);
337             IoTString iKeyD = new IoTString(keyD);
338             IoTString iValueA = new IoTString(valueA);
339             IoTString iValueB = new IoTString(valueB);
340             IoTString iValueC = new IoTString(valueC);
341             IoTString iValueD = new IoTString(valueD);
342
343
344             IoTString testValA1 = t1.getCommitted(iKeyA);
345             IoTString testValB1 = t1.getCommitted(iKeyB);
346             IoTString testValC1 = t1.getCommitted(iKeyC);
347             IoTString testValD1 = t1.getCommitted(iKeyD);
348
349             IoTString testValA2 = t2.getCommitted(iKeyA);
350             IoTString testValB2 = t2.getCommitted(iKeyB);
351             IoTString testValC2 = t2.getCommitted(iKeyC);
352             IoTString testValD2 = t2.getCommitted(iKeyD);
353
354             if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
355                 System.out.println("Key-Value t1 incorrect: " + keyA);
356                 foundError = true;
357             }
358
359             if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
360                 System.out.println("Key-Value t1 incorrect: " + keyB);
361                 foundError = true;
362             }
363
364             if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
365                 System.out.println("Key-Value t1 incorrect: " + keyC);
366                 foundError = true;
367             }
368
369             if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
370                 System.out.println("Key-Value t1 incorrect: " + keyD);
371                 foundError = true;
372             }
373
374
375             if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
376                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
377                 foundError = true;
378             }
379
380             if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
381                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
382                 foundError = true;
383             }
384
385             if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
386                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
387                 foundError = true;
388             }
389
390             if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
391                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
392                 foundError = true;
393             }
394         }
395
396         for (TransactionStatus status : transStatusList) {
397             if (status.getStatus() != TransactionStatus.StatusCommitted) {
398                 foundError = true;
399             }
400         }
401
402         if (foundError) {
403             System.out.println("Found Errors...");
404         } else {
405             System.out.println("No Errors Found...");
406         }
407     }
408
409     static void test5() throws ServerException {
410
411         boolean foundError = false;
412         List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
413
414         // Setup the 2 clients
415         Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
416         t1.initTable();
417         Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
418         t2.update();
419
420
421         // Make the Keys
422         System.out.println("Setting up keys");
423         for (int i = 0; i < 4; i++) {
424             String a = "a" + i;
425             String b = "b" + i;
426             String c = "c" + i;
427             String d = "d" + i;
428             IoTString ia = new IoTString(a);
429             IoTString ib = new IoTString(b);
430             IoTString ic = new IoTString(c);
431             IoTString id = new IoTString(d);
432             t1.createNewKey(ia, 321);
433             t1.createNewKey(ib, 351);
434             t2.createNewKey(ic, 321);
435             t2.createNewKey(id, 351);
436         }
437
438         // Do Updates for the keys
439         System.out.println("Setting Key-Values...");
440
441         for (int t = 0; t < NUMBER_OF_TESTS; t++) {
442             for (int i = 0; i < 4; i++) {
443                 String keyB = "b" + i;
444                 String valueB = "b" + (i + t);
445
446                 IoTString iKeyB = new IoTString(keyB);
447                 IoTString iValueB = new IoTString(valueB);
448
449                 t1.startTransaction();
450                 t1.addKV(iKeyB, iValueB);
451                 transStatusList.add(t1.commitTransaction());
452             }
453         }
454
455         for (int i = 0; i < 4; i++) {
456
457             String keyB = "b" + i;
458             String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
459             IoTString iKeyB = new IoTString(keyB);
460             IoTString iValueB = new IoTString(valueB);
461
462             IoTString testValB1 = t1.getSpeculative(iKeyB);
463             IoTString testValB2 = t2.getSpeculative(iKeyB);
464
465             if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
466                 System.out.println("Key-Value t1 incorrect: " + keyB);
467                 foundError = true;
468             }
469
470             if ((testValB2 != null)) {
471                 System.out.println("Key-Value t2 incorrect: " + keyB);
472                 foundError = true;
473             }
474         }
475
476         for (int t = 0; t < NUMBER_OF_TESTS; t++) {
477             for (int i = 0; i < 4; i++) {
478                 String keyC = "c" + i;
479                 String valueC = "c" + (i + t);
480
481                 IoTString iKeyC = new IoTString(keyC);
482                 IoTString iValueC = new IoTString(valueC);
483
484                 t2.startTransaction();
485                 t2.addKV(iKeyC, iValueC);
486                 transStatusList.add(t2.commitTransaction());
487             }
488         }
489
490         for (int i = 0; i < 4; i++) {
491             String keyC = "c" + i;
492             String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
493             IoTString iKeyC = new IoTString(keyC);
494             IoTString iValueC = new IoTString(valueC);
495
496             IoTString testValC1 = t1.getSpeculative(iKeyC);
497             IoTString testValC2 = t2.getSpeculative(iKeyC);
498
499             if ((testValC1 != null)) {
500                 System.out.println("Key-Value t1 incorrect: " + keyC + "   " + testValC1);
501                 foundError = true;
502             }
503
504             if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
505                 System.out.println("Key-Value t2 incorrect: " + keyC + "   " + testValC2);
506                 foundError = true;
507             }
508         }
509
510         for (int t = 0; t < NUMBER_OF_TESTS; t++) {
511             for (int i = 0; i < 4; i++) {
512                 String keyA = "a" + i;
513                 String keyD = "d" + i;
514                 String valueA = "a" + (i + t);
515                 String valueD = "d" + (i + t);
516
517                 IoTString iKeyA = new IoTString(keyA);
518                 IoTString iKeyD = new IoTString(keyD);
519                 IoTString iValueA = new IoTString(valueA);
520                 IoTString iValueD = new IoTString(valueD);
521
522                 t1.startTransaction();
523                 t1.addKV(iKeyA, iValueA);
524                 transStatusList.add(t1.commitTransaction());
525
526                 t2.startTransaction();
527                 t2.addKV(iKeyD, iValueD);
528                 transStatusList.add(t2.commitTransaction());
529             }
530         }
531
532         System.out.println("Updating Clients...");
533         t1.update();
534         t2.update();
535
536
537         System.out.println("Checking Key-Values...");
538         for (int i = 0; i < 4; i++) {
539
540             String keyA = "a" + i;
541             String keyB = "b" + i;
542             String keyC = "c" + i;
543             String keyD = "d" + i;
544             String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
545             String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
546             String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
547             String valueD = "d" + (i + NUMBER_OF_TESTS - 1);
548
549             IoTString iKeyA = new IoTString(keyA);
550             IoTString iKeyB = new IoTString(keyB);
551             IoTString iKeyC = new IoTString(keyC);
552             IoTString iKeyD = new IoTString(keyD);
553             IoTString iValueA = new IoTString(valueA);
554             IoTString iValueB = new IoTString(valueB);
555             IoTString iValueC = new IoTString(valueC);
556             IoTString iValueD = new IoTString(valueD);
557
558
559             IoTString testValA1 = t1.getCommitted(iKeyA);
560             IoTString testValB1 = t1.getCommitted(iKeyB);
561             IoTString testValC1 = t1.getCommitted(iKeyC);
562             IoTString testValD1 = t1.getCommitted(iKeyD);
563
564             IoTString testValA2 = t2.getCommitted(iKeyA);
565             IoTString testValB2 = t2.getCommitted(iKeyB);
566             IoTString testValC2 = t2.getCommitted(iKeyC);
567             IoTString testValD2 = t2.getCommitted(iKeyD);
568
569             if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
570                 System.out.println("Key-Value t1 incorrect: " + keyA + "    " + testValA1);
571                 foundError = true;
572             }
573
574             if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
575                 System.out.println("Key-Value t1 incorrect: " + keyB + "    " + testValB1);
576                 foundError = true;
577             }
578
579             if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
580                 System.out.println("Key-Value t1 incorrect: " + keyC + "    " + testValC1);
581                 foundError = true;
582             }
583
584             if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
585                 System.out.println("Key-Value t1 incorrect: " + keyD + "    " + testValD1);
586                 foundError = true;
587             }
588
589
590             if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
591                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
592                 foundError = true;
593             }
594
595             if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
596                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
597                 foundError = true;
598             }
599
600             if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
601                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
602                 foundError = true;
603             }
604
605             if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
606                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
607                 foundError = true;
608             }
609         }
610
611         for (TransactionStatus status : transStatusList) {
612             if (status.getStatus() != TransactionStatus.StatusCommitted) {
613                 foundError = true;
614             }
615         }
616
617         if (foundError) {
618             System.out.println("Found Errors...");
619         } else {
620             System.out.println("No Errors Found...");
621         }
622     }
623
624     static void test4() throws ServerException {
625
626         boolean foundError = false;
627         long startTime = 0;
628         long endTime = 0;
629         List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
630
631         // Setup the 2 clients
632         Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
633         t1.initTable();
634         Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
635         t2.update();
636
637         // Make the Keys
638         System.out.println("Setting up keys");
639         startTime = System.currentTimeMillis();
640         for (int i = 0; i < 4; i++) {
641             String a = "a" + i;
642             String b = "b" + i;
643             String c = "c" + i;
644             String d = "d" + i;
645             IoTString ia = new IoTString(a);
646             IoTString ib = new IoTString(b);
647             IoTString ic = new IoTString(c);
648             IoTString id = new IoTString(d);
649             t1.createNewKey(ia, 321);
650             t1.createNewKey(ib, 351);
651             t2.createNewKey(ic, 321);
652             t2.createNewKey(id, 351);
653         }
654         endTime = System.currentTimeMillis();
655         System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
656         System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
657         System.out.println();
658
659
660         // Do Updates for the keys
661         System.out.println("Setting Key-Values...");
662         startTime = System.currentTimeMillis();
663         for (int t = 0; t < NUMBER_OF_TESTS; t++) {
664             for (int i = 0; i < 4; i++) {
665                 String keyA = "a" + i;
666                 String keyB = "b" + i;
667                 String keyC = "c" + i;
668                 String keyD = "d" + i;
669                 String valueA = "a" + i;
670                 String valueB = "b" + i;
671                 String valueC = "c" + i;
672                 String valueD = "d" + i;
673
674                 IoTString iKeyA = new IoTString(keyA);
675                 IoTString iKeyB = new IoTString(keyB);
676                 IoTString iKeyC = new IoTString(keyC);
677                 IoTString iKeyD = new IoTString(keyD);
678                 IoTString iValueA = new IoTString(valueA);
679                 IoTString iValueB = new IoTString(valueB);
680                 IoTString iValueC = new IoTString(valueC);
681                 IoTString iValueD = new IoTString(valueD);
682
683                 t1.startTransaction();
684                 t1.addKV(iKeyA, iValueA);
685                 transStatusList.add(t1.commitTransaction());
686
687                 t1.startTransaction();
688                 t1.addKV(iKeyB, iValueB);
689                 transStatusList.add(t1.commitTransaction());
690
691                 t2.startTransaction();
692                 t2.addKV(iKeyC, iValueC);
693                 transStatusList.add(t2.commitTransaction());
694
695                 t2.startTransaction();
696                 t2.addKV(iKeyD, iValueD);
697                 transStatusList.add(t2.commitTransaction());
698             }
699         }
700         endTime = System.currentTimeMillis();
701         System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
702         System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 16))   );
703         System.out.println();
704
705
706         System.out.println("Updating Clients...");
707         t1.update();
708         t2.update();
709
710
711         System.out.println("Checking Key-Values...");
712         for (int i = 0; i < 4; i++) {
713
714             String keyA = "a" + i;
715             String keyB = "b" + i;
716             String keyC = "c" + i;
717             String keyD = "d" + i;
718             String valueA = "a" + i;
719             String valueB = "b" + i;
720             String valueC = "c" + i;
721             String valueD = "d" + i;
722
723             IoTString iKeyA = new IoTString(keyA);
724             IoTString iKeyB = new IoTString(keyB);
725             IoTString iKeyC = new IoTString(keyC);
726             IoTString iKeyD = new IoTString(keyD);
727             IoTString iValueA = new IoTString(valueA);
728             IoTString iValueB = new IoTString(valueB);
729             IoTString iValueC = new IoTString(valueC);
730             IoTString iValueD = new IoTString(valueD);
731
732
733             IoTString testValA1 = t1.getCommitted(iKeyA);
734             IoTString testValB1 = t1.getCommitted(iKeyB);
735             IoTString testValC1 = t1.getCommitted(iKeyC);
736             IoTString testValD1 = t1.getCommitted(iKeyD);
737
738             IoTString testValA2 = t2.getCommitted(iKeyA);
739             IoTString testValB2 = t2.getCommitted(iKeyB);
740             IoTString testValC2 = t2.getCommitted(iKeyC);
741             IoTString testValD2 = t2.getCommitted(iKeyD);
742
743             if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
744                 System.out.println("Key-Value t1 incorrect: " + keyA);
745                 foundError = true;
746             }
747
748             if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
749                 System.out.println("Key-Value t1 incorrect: " + keyB);
750                 foundError = true;
751             }
752
753             if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
754                 System.out.println("Key-Value t1 incorrect: " + keyC);
755                 foundError = true;
756             }
757
758             if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
759                 System.out.println("Key-Value t1 incorrect: " + keyD);
760                 foundError = true;
761             }
762
763
764             if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
765                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
766                 foundError = true;
767             }
768
769             if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
770                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
771                 foundError = true;
772             }
773
774             if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
775                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
776                 foundError = true;
777             }
778
779             if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
780                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
781                 foundError = true;
782             }
783         }
784
785         for (TransactionStatus status : transStatusList) {
786             if (status.getStatus() != TransactionStatus.StatusCommitted) {
787                 foundError = true;
788             }
789         }
790
791         if (foundError) {
792             System.out.println("Found Errors...");
793         } else {
794             System.out.println("No Errors Found...");
795         }
796     }
797
798     static void test3() throws ServerException {
799
800         long startTime = 0;
801         long endTime = 0;
802         boolean foundError = false;
803
804         List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
805
806         // Setup the 2 clients
807         Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
808         t1.initTable();
809         Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
810         t2.update();
811
812
813         // Make the Keys
814         System.out.println("Setting up keys");
815         startTime = System.currentTimeMillis();
816         for (int i = 0; i < NUMBER_OF_TESTS; i++) {
817             String a = "a" + i;
818             String b = "b" + i;
819             String c = "c" + i;
820             String d = "d" + i;
821             IoTString ia = new IoTString(a);
822             IoTString ib = new IoTString(b);
823             IoTString ic = new IoTString(c);
824             IoTString id = new IoTString(d);
825             t1.createNewKey(ia, 321);
826             t1.createNewKey(ib, 351);
827             t2.createNewKey(ic, 321);
828             t2.createNewKey(id, 351);
829         }
830         endTime = System.currentTimeMillis();
831         System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
832         System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
833         System.out.println();
834
835
836         // Do Updates for the keys
837         System.out.println("Setting Key-Values...");
838         startTime = System.currentTimeMillis();
839
840         System.out.println("B...");
841         for (int i = 0; i < NUMBER_OF_TESTS; i++) {
842             String keyB = "b" + i;
843             String valueB = "b" + i;
844
845             IoTString iKeyB = new IoTString(keyB);
846             IoTString iValueB = new IoTString(valueB);
847
848             t1.startTransaction();
849             t1.addKV(iKeyB, iValueB);
850             transStatusList.add(t1.commitTransaction());
851         }
852
853         System.out.println("C...");
854         for (int i = 0; i < NUMBER_OF_TESTS; i++) {
855             String keyC = "c" + i;
856             String valueC = "c" + i;
857
858             IoTString iKeyC = new IoTString(keyC);
859             IoTString iValueC = new IoTString(valueC);
860
861             t2.startTransaction();
862             t2.addKV(iKeyC, iValueC);
863             transStatusList.add(t2.commitTransaction());
864         }
865
866         System.out.println("A, D...");
867         for (int i = 0; i < NUMBER_OF_TESTS; i++) {
868             String keyA = "a" + i;
869             String keyD = "d" + i;
870             String valueA = "a" + i;
871             String valueD = "d" + i;
872
873             IoTString iKeyA = new IoTString(keyA);
874             IoTString iKeyD = new IoTString(keyD);
875             IoTString iValueA = new IoTString(valueA);
876             IoTString iValueD = new IoTString(valueD);
877
878             t1.startTransaction();
879             t1.addKV(iKeyA, iValueA);
880             transStatusList.add(t1.commitTransaction());
881
882             t2.startTransaction();
883             t2.addKV(iKeyD, iValueD);
884             transStatusList.add(t2.commitTransaction());
885         }
886         endTime = System.currentTimeMillis();
887         System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
888         System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
889         System.out.println();
890
891
892         System.out.println("Updating Clients...");
893         t1.update();
894         t2.update();
895
896
897         System.out.println("Checking Key-Values...");
898         for (int i = 0; i < NUMBER_OF_TESTS; i++) {
899
900             String keyA = "a" + i;
901             String keyB = "b" + i;
902             String keyC = "c" + i;
903             String keyD = "d" + i;
904             String valueA = "a" + i;
905             String valueB = "b" + i;
906             String valueC = "c" + i;
907             String valueD = "d" + i;
908
909             IoTString iKeyA = new IoTString(keyA);
910             IoTString iKeyB = new IoTString(keyB);
911             IoTString iKeyC = new IoTString(keyC);
912             IoTString iKeyD = new IoTString(keyD);
913             IoTString iValueA = new IoTString(valueA);
914             IoTString iValueB = new IoTString(valueB);
915             IoTString iValueC = new IoTString(valueC);
916             IoTString iValueD = new IoTString(valueD);
917
918
919             IoTString testValA1 = t1.getCommitted(iKeyA);
920             IoTString testValB1 = t1.getCommitted(iKeyB);
921             IoTString testValC1 = t1.getCommitted(iKeyC);
922             IoTString testValD1 = t1.getCommitted(iKeyD);
923
924             IoTString testValA2 = t2.getCommitted(iKeyA);
925             IoTString testValB2 = t2.getCommitted(iKeyB);
926             IoTString testValC2 = t2.getCommitted(iKeyC);
927             IoTString testValD2 = t2.getCommitted(iKeyD);
928
929             if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
930                 System.out.println("Key-Value t1 incorrect: " + keyA);
931                 foundError = true;
932             }
933
934             if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
935                 System.out.println("Key-Value t1 incorrect: " + keyB);
936                 foundError = true;
937             }
938
939             if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
940                 System.out.println("Key-Value t1 incorrect: " + keyC);
941                 foundError = true;
942             }
943
944             if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
945                 System.out.println("Key-Value t1 incorrect: " + keyD);
946                 foundError = true;
947             }
948
949
950             if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
951                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
952                 foundError = true;
953             }
954
955             if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
956                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
957                 foundError = true;
958             }
959
960             if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
961                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
962                 foundError = true;
963             }
964
965             if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
966                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
967                 foundError = true;
968             }
969         }
970
971         for (TransactionStatus status : transStatusList) {
972             if (status.getStatus() != TransactionStatus.StatusCommitted) {
973                 foundError = true;
974             }
975         }
976
977         if (foundError) {
978             System.out.println("Found Errors...");
979         } else {
980             System.out.println("No Errors Found...");
981         }
982     }
983
984     static void test2() throws ServerException {
985
986         boolean foundError = false;
987         long startTime = 0;
988         long endTime = 0;
989         List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
990
991         // Setup the 2 clients
992         Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
993         t1.initTable();
994         System.out.println("T1 Ready");
995
996         Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
997         t2.update();
998         System.out.println("T2 Ready");
999
1000         // Make the Keys
1001         System.out.println("Setting up keys");
1002         startTime = System.currentTimeMillis();
1003         for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1004             String a = "a" + i;
1005             String b = "b" + i;
1006             String c = "c" + i;
1007             String d = "d" + i;
1008             IoTString ia = new IoTString(a);
1009             IoTString ib = new IoTString(b);
1010             IoTString ic = new IoTString(c);
1011             IoTString id = new IoTString(d);
1012             t1.createNewKey(ia, 321);
1013             t1.createNewKey(ib, 351);
1014             t2.createNewKey(ic, 321);
1015             t2.createNewKey(id, 351);
1016         }
1017         endTime = System.currentTimeMillis();
1018         System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1019         System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
1020         System.out.println();
1021
1022         // Do Updates for the keys
1023         System.out.println("Setting Key-Values...");
1024         startTime = System.currentTimeMillis();
1025         for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1026             String keyA = "a" + i;
1027             String keyB = "b" + i;
1028             String keyC = "c" + i;
1029             String keyD = "d" + i;
1030             String valueA = "a" + i;
1031             String valueB = "b" + i;
1032             String valueC = "c" + i;
1033             String valueD = "d" + i;
1034
1035             IoTString iKeyA = new IoTString(keyA);
1036             IoTString iKeyB = new IoTString(keyB);
1037             IoTString iKeyC = new IoTString(keyC);
1038             IoTString iKeyD = new IoTString(keyD);
1039             IoTString iValueA = new IoTString(valueA);
1040             IoTString iValueB = new IoTString(valueB);
1041             IoTString iValueC = new IoTString(valueC);
1042             IoTString iValueD = new IoTString(valueD);
1043
1044             t1.startTransaction();
1045             t1.addKV(iKeyA, iValueA);
1046             transStatusList.add(t1.commitTransaction());
1047
1048
1049             t1.startTransaction();
1050             t1.addKV(iKeyB, iValueB);
1051             transStatusList.add(t1.commitTransaction());
1052
1053
1054             t2.startTransaction();
1055             t2.addKV(iKeyC, iValueC);
1056             transStatusList.add(t2.commitTransaction());
1057
1058
1059             t2.startTransaction();
1060             t2.addKV(iKeyD, iValueD);
1061             transStatusList.add(t2.commitTransaction());
1062         }
1063         endTime = System.currentTimeMillis();
1064         System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1065         System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
1066         System.out.println();
1067
1068
1069         System.out.println("Updating Clients...");
1070         t1.update();
1071         t2.update();
1072
1073
1074         System.out.println("Checking Key-Values...");
1075         for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1076
1077             String keyA = "a" + i;
1078             String keyB = "b" + i;
1079             String keyC = "c" + i;
1080             String keyD = "d" + i;
1081             String valueA = "a" + i;
1082             String valueB = "b" + i;
1083             String valueC = "c" + i;
1084             String valueD = "d" + i;
1085
1086             IoTString iKeyA = new IoTString(keyA);
1087             IoTString iKeyB = new IoTString(keyB);
1088             IoTString iKeyC = new IoTString(keyC);
1089             IoTString iKeyD = new IoTString(keyD);
1090             IoTString iValueA = new IoTString(valueA);
1091             IoTString iValueB = new IoTString(valueB);
1092             IoTString iValueC = new IoTString(valueC);
1093             IoTString iValueD = new IoTString(valueD);
1094
1095
1096             IoTString testValA1 = t1.getCommitted(iKeyA);
1097             IoTString testValB1 = t1.getCommitted(iKeyB);
1098             IoTString testValC1 = t1.getCommitted(iKeyC);
1099             IoTString testValD1 = t1.getCommitted(iKeyD);
1100
1101             IoTString testValA2 = t2.getCommitted(iKeyA);
1102             IoTString testValB2 = t2.getCommitted(iKeyB);
1103             IoTString testValC2 = t2.getCommitted(iKeyC);
1104             IoTString testValD2 = t2.getCommitted(iKeyD);
1105
1106             if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1107                 System.out.println("Key-Value t1 incorrect: " + keyA);
1108                 foundError = true;
1109             }
1110
1111             if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1112                 System.out.println("Key-Value t1 incorrect: " + keyB);
1113                 foundError = true;
1114             }
1115
1116             if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1117                 System.out.println("Key-Value t1 incorrect: " + keyC);
1118                 foundError = true;
1119             }
1120
1121             if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1122                 System.out.println("Key-Value t1 incorrect: " + keyD);
1123                 foundError = true;
1124             }
1125
1126
1127             if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1128                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
1129                 foundError = true;
1130             }
1131
1132             if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1133                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
1134                 foundError = true;
1135             }
1136
1137             if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1138                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
1139                 foundError = true;
1140             }
1141
1142             if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1143                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
1144                 foundError = true;
1145             }
1146         }
1147
1148         for (TransactionStatus status : transStatusList) {
1149             if (status.getStatus() != TransactionStatus.StatusCommitted) {
1150                 foundError = true;
1151                 System.out.println(status.getStatus());
1152             }
1153         }
1154
1155         if (foundError) {
1156             System.out.println("Found Errors...");
1157         } else {
1158             System.out.println("No Errors Found...");
1159         }
1160     }
1161 }