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