Squashed Last bugs
[iotcloud.git] / version2 / src / java / iotcloud / Test.java
1 package iotcloud;
2
3 /**
4  * Test cases.
5  * @author Brian Demsky
6  * @version 1.0
7  */
8
9 public class Test {
10
11         public static final  int NUMBER_OF_TESTS = 1000;
12
13         public static void main(String[] args) {
14                 if (args[0].equals("2")) {
15                         test2();
16                 } else if (args[0].equals("3")) {
17                         test3();
18                 } else if (args[0].equals("4")) {
19                         test4();
20                 } else if (args[0].equals("5")) {
21                         test5();
22                 } else if (args[0].equals("6")) {
23                         test6();
24                 } else if (args[0].equals("7")) {
25                         test7();
26                 } else if (args[0].equals("8")) {
27                         test8();
28                 } else if (args[0].equals("9")) {
29                         test9();
30                 }
31         }
32
33         static void test9() {
34
35                 // Setup the 2 clients
36                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
37                 t1.initTable();
38                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
39                 t2.update();
40
41
42                 // Make the Keys
43                 System.out.println("Setting up keys");
44                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
45                         String a = "a" + i;
46                         String b = "b" + i;
47                         String c = "c" + i;
48                         String d = "d" + i;
49                         IoTString ia = new IoTString(a);
50                         IoTString ib = new IoTString(b);
51                         IoTString ic = new IoTString(c);
52                         IoTString id = new IoTString(d);
53                         t1.createNewKey(ia, 321);
54                         t1.createNewKey(ib, 351);
55                         t2.createNewKey(ic, 321);
56                         t2.createNewKey(id, 351);
57                 }
58
59                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
60                         String a = "a" + i;
61                         String b = "b" + i;
62                         String c = "c" + i;
63                         String d = "d" + i;
64                         IoTString ia = new IoTString(a);
65                         IoTString ib = new IoTString(b);
66                         IoTString ic = new IoTString(c);
67                         IoTString id = new IoTString(d);
68                         t1.createNewKey(ia, 1000);
69                         t1.createNewKey(ib, 1000);
70                         t2.createNewKey(ic, 1000);
71                         t2.createNewKey(id, 1000);
72                 }
73
74                 System.out.println("Updating Clients...");
75                 t1.update();
76                 t2.update();
77                 t1.update();
78                 t2.update();
79
80                 boolean foundError = false;
81
82                 System.out.println("Checking Key-Values...");
83                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
84
85                         String keyA = "a" + i;
86                         String keyB = "b" + i;
87                         String keyC = "c" + i;
88                         String keyD = "d" + i;
89
90                         IoTString iKeyA = new IoTString(keyA);
91                         IoTString iKeyB = new IoTString(keyB);
92                         IoTString iKeyC = new IoTString(keyC);
93                         IoTString iKeyD = new IoTString(keyD);
94
95
96                         Long testValA1 = t1.getArbitrator(iKeyA);
97                         Long testValB1 = t1.getArbitrator(iKeyB);
98                         Long testValC1 = t1.getArbitrator(iKeyC);
99                         Long testValD1 = t1.getArbitrator(iKeyD);
100
101                         Long testValA2 = t2.getArbitrator(iKeyA);
102                         Long testValB2 = t2.getArbitrator(iKeyB);
103                         Long testValC2 = t2.getArbitrator(iKeyC);
104                         Long testValD2 = t2.getArbitrator(iKeyD);
105
106                         if ((testValA1 == null) || (testValA1 != 321)) {
107                                 System.out.println("Key-Value t1 incorrect: " + keyA + "    " + testValA1);
108                                 foundError = true;
109                         }
110
111                         if ((testValB1 == null) || (testValB1 != 351)) {
112                                 System.out.println("Key-Value t1 incorrect: " + keyB + "    " + testValB1);
113                                 foundError = true;
114                         }
115
116                         if ((testValC1 == null) || (testValC1 != 321)) {
117                                 System.out.println("Key-Value t1 incorrect: " + keyC + "    " + testValC1);
118                                 foundError = true;
119                         }
120
121                         if ((testValD1 == null) || (testValD1 != 351)) {
122                                 System.out.println("Key-Value t1 incorrect: " + keyD + "    " + testValD1);
123                                 foundError = true;
124                         }
125
126                         if ((testValA2 == null) || (testValA2 != 321)) {
127                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
128                                 foundError = true;
129                         }
130
131                         if ((testValB2 == null) || (testValB2 != 351)) {
132                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
133                                 foundError = true;
134                         }
135
136                         if ((testValC2 == null) || (testValC2 != 321)) {
137                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
138                                 foundError = true;
139                         }
140
141                         if ((testValD2 == null) || (testValD2 != 351)) {
142                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
143                                 foundError = true;
144                         }
145                 }
146
147                 if (foundError) {
148                         System.out.println("Found Errors...");
149                 } else {
150                         System.out.println("No Errors Found...");
151                 }
152         }
153
154         static void test8() {
155
156                 boolean foundError = false;
157
158                 // Setup the 2 clients
159                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
160                 t1.initTable();
161                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
162                 t2.update();
163
164                 // t1.rebuild();
165                 // t2.rebuild();
166
167                 // Make the Keys
168                 System.out.println("Setting up keys");
169                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
170                         String a = "a" + i;
171                         String b = "b" + i;
172                         String c = "c" + i;
173                         String d = "d" + i;
174                         IoTString ia = new IoTString(a);
175                         IoTString ib = new IoTString(b);
176                         IoTString ic = new IoTString(c);
177                         IoTString id = new IoTString(d);
178                         t1.createNewKey(ia, 321);
179                         t1.createNewKey(ib, 351);
180                         t2.createNewKey(ic, 321);
181                         t2.createNewKey(id, 351);
182                 }
183
184
185                 // Do Updates for the keys
186                 System.out.println("Setting Key-Values...");
187
188
189                 String keyA0 = "a0";
190                 String keyB0 = "b0";
191                 String keyC0 = "c0";
192                 String keyD0 = "d0";
193                 String valueA0 = "a0";
194                 String valueB0 = "b0";
195                 String valueC0 = "c0";
196                 String valueD0 = "d0";
197
198                 IoTString iKeyA0 = new IoTString(keyA0);
199                 IoTString iKeyB0 = new IoTString(keyB0);
200                 IoTString iKeyC0 = new IoTString(keyC0);
201                 IoTString iKeyD0 = new IoTString(keyD0);
202                 IoTString iValueA0 = new IoTString(valueA0);
203                 IoTString iValueB0 = new IoTString(valueB0);
204                 IoTString iValueC0 = new IoTString(valueC0);
205                 IoTString iValueD0 = new IoTString(valueD0);
206
207                 t1.startTransaction();
208                 t1.addKV( iKeyA0, iValueA0);
209                 t1.commitTransaction();
210
211                 t1.startTransaction();
212                 t1.addKV(iKeyB0, iValueB0);
213                 t1.commitTransaction();
214
215                 t2.startTransaction();
216                 t2.addKV(iKeyC0, iValueC0);
217                 t2.commitTransaction();
218
219                 t2.startTransaction();
220                 t2.addKV(iKeyD0, iValueD0);
221                 t2.commitTransaction();
222
223                 for (int i = 1; i < NUMBER_OF_TESTS; i++) {
224                         String keyB = "b" + i;
225                         String valueB = "b" + i;
226                         IoTString iKeyB = new IoTString(keyB);
227                         IoTString iValueB = new IoTString(valueB);
228
229                         String keyBOld = "b" + (i - 1);
230                         String valueBOld = "b" + (i - 1);
231                         IoTString iKeyBOld = new IoTString(keyBOld);
232                         IoTString iValueBOld = new IoTString(valueBOld);
233
234
235                         t1.startTransaction();
236                         t1.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyBOld, iValueBOld, Guard.Equal))));
237                         t1.addKV(iKeyB, iValueB);
238                         t1.commitTransaction();
239                 }
240
241                 System.out.println("Checking Key-Values...");
242                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
243
244                         String keyB = "b" + i;
245                         String valueB = "b" + i;
246
247                         IoTString iKeyB = new IoTString(keyB);
248                         IoTString iValueB = new IoTString(valueB);
249
250                         IoTString testValB1 = t1.getSpeculative(iKeyB);
251
252                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
253                                 System.out.println("Key-Value t1 incorrect: " + keyB);
254                                 foundError = true;
255
256                         }
257                 }
258
259
260                 System.out.println("Updating Clients...");
261                 t1.update();
262                 t2.update();
263                 t1.update();
264                 t2.update();
265
266                 System.out.println("Checking Key-Values...");
267                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
268
269                         String keyA = "a" + i;
270                         String keyB = "b" + i;
271                         String keyC = "c" + i;
272                         String keyD = "d" + i;
273                         String valueA = "a" + i;
274                         String valueB = "b" + i;
275                         String valueC = "c" + i;
276                         String valueD = "d" + i;
277
278                         IoTString iKeyA = new IoTString(keyA);
279                         IoTString iKeyB = new IoTString(keyB);
280                         IoTString iKeyC = new IoTString(keyC);
281                         IoTString iKeyD = new IoTString(keyD);
282                         IoTString iValueA = new IoTString(valueA);
283                         IoTString iValueB = new IoTString(valueB);
284                         IoTString iValueC = new IoTString(valueC);
285                         IoTString iValueD = new IoTString(valueD);
286
287
288                         IoTString testValA1 = t1.getCommitted(iKeyA);
289                         IoTString testValB1 = t1.getCommitted(iKeyB);
290                         IoTString testValC1 = t1.getCommitted(iKeyC);
291                         IoTString testValD1 = t1.getCommitted(iKeyD);
292
293                         IoTString testValA2 = t2.getCommitted(iKeyA);
294                         IoTString testValB2 = t2.getCommitted(iKeyB);
295                         IoTString testValC2 = t2.getCommitted(iKeyC);
296                         IoTString testValD2 = t2.getCommitted(iKeyD);
297
298
299                         if (i == 0) {
300                                 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
301                                         System.out.println("Key-Value t1 incorrect: " + keyA);
302                                         foundError = true;
303                                 }
304
305                                 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
306                                         System.out.println("Key-Value t1 incorrect: " + keyB);
307                                         foundError = true;
308                                 }
309
310                                 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
311                                         System.out.println("Key-Value t1 incorrect: " + keyC);
312                                         foundError = true;
313                                 }
314
315                                 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
316                                         System.out.println("Key-Value t1 incorrect: " + keyD);
317                                         foundError = true;
318                                 }
319
320
321                                 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
322                                         System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
323                                         foundError = true;
324                                 }
325
326                                 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
327                                         System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
328                                         foundError = true;
329                                 }
330
331                                 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
332                                         System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
333                                         foundError = true;
334                                 }
335
336                                 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
337                                         System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
338                                         foundError = true;
339                                 }
340                         } else {
341                                 if (testValA1 != null) {
342                                         System.out.println("Key-Value t1 incorrect: " + keyA);
343                                         foundError = true;
344                                 }
345
346                                 if (testValB1 != null) {
347                                         System.out.println("Key-Value t1 incorrect: " + keyB);
348                                         foundError = true;
349                                 }
350
351                                 if (testValC1 != null) {
352                                         System.out.println("Key-Value t1 incorrect: " + keyC);
353                                         foundError = true;
354                                 }
355
356                                 if (testValD1 != null) {
357                                         System.out.println("Key-Value t1 incorrect: " + keyD);
358                                         foundError = true;
359                                 }
360
361                                 if (testValA2 != null) {
362                                         System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
363                                         foundError = true;
364                                 }
365
366                                 if (testValB2 != null) {
367                                         System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
368                                         foundError = true;
369                                 }
370
371                                 if (testValC2 != null) {
372                                         System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
373                                         foundError = true;
374                                 }
375
376                                 if (testValD2 != null) {
377                                         System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
378                                         foundError = true;
379                                 }
380                         }
381                 }
382
383                 if (foundError) {
384                         System.out.println("Found Errors...");
385                 } else {
386                         System.out.println("No Errors Found...");
387                 }
388         }
389
390         static void test7() {
391
392                 long startTime = 0;
393                 long endTime = 0;
394
395                 // Setup the 2 clients
396                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
397                 t1.initTable();
398                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
399                 t2.update();
400
401                 // t1.rebuild();
402                 // t2.rebuild();
403
404                 // Make the Keys
405                 System.out.println("Setting up keys");
406                 startTime = System.currentTimeMillis();
407                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
408                         String a = "a" + i;
409                         String b = "b" + i;
410                         String c = "c" + i;
411                         String d = "d" + i;
412                         IoTString ia = new IoTString(a);
413                         IoTString ib = new IoTString(b);
414                         IoTString ic = new IoTString(c);
415                         IoTString id = new IoTString(d);
416                         t1.createNewKey(ia, 321);
417                         t1.createNewKey(ib, 351);
418                         t2.createNewKey(ic, 321);
419                         t2.createNewKey(id, 351);
420                 }
421                 endTime = System.currentTimeMillis();
422
423                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
424                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
425                 System.out.println();
426
427
428                 // Do Updates for the keys
429                 System.out.println("Setting Key-Values...");
430                 startTime = System.currentTimeMillis();
431
432
433
434                 String keyA0 = "a0";
435                 String keyB0 = "b0";
436                 String keyC0 = "c0";
437                 String keyD0 = "d0";
438                 String valueA0 = "a0";
439                 String valueB0 = "b0";
440                 String valueC0 = "c0";
441                 String valueD0 = "d0";
442
443                 IoTString iKeyA0 = new IoTString(keyA0);
444                 IoTString iKeyB0 = new IoTString(keyB0);
445                 IoTString iKeyC0 = new IoTString(keyC0);
446                 IoTString iKeyD0 = new IoTString(keyD0);
447                 IoTString iValueA0 = new IoTString(valueA0);
448                 IoTString iValueB0 = new IoTString(valueB0);
449                 IoTString iValueC0 = new IoTString(valueC0);
450                 IoTString iValueD0 = new IoTString(valueD0);
451
452                 t1.startTransaction();
453                 t1.addKV( iKeyA0, iValueA0);
454                 t1.commitTransaction();
455
456                 t1.startTransaction();
457                 t1.addKV(iKeyB0, iValueB0);
458                 t1.commitTransaction();
459
460                 t2.startTransaction();
461                 t2.addKV(iKeyC0, iValueC0);
462                 t2.commitTransaction();
463
464                 t2.startTransaction();
465                 t2.addKV(iKeyD0, iValueD0);
466                 t2.commitTransaction();
467
468                 for (int i = 1; i < NUMBER_OF_TESTS; i++) {
469                         String keyB = "b" + i;
470                         String valueB = "b" + i;
471                         IoTString iKeyB = new IoTString(keyB);
472                         IoTString iValueB = new IoTString(valueB);
473
474                         String keyBOld = "b" + (i - 1);
475                         String valueBOld = "b" + (i - 2);
476                         IoTString iKeyBOld = new IoTString(keyBOld);
477                         IoTString iValueBOld = new IoTString(valueBOld);
478
479
480                         t1.startTransaction();
481                         t1.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyBOld, iValueBOld, Guard.Equal))));
482                         t1.addKV(iKeyB, iValueB);
483                         t1.commitTransaction();
484                 }
485
486                 for (int i = 1; i < NUMBER_OF_TESTS; i++) {
487                         String keyC = "c" + i;
488                         String valueC = "c" + i;
489                         IoTString iKeyC = new IoTString(keyC);
490                         IoTString iValueC = new IoTString(valueC);
491
492                         String keyCOld = "c" + (i - 1);
493                         String valueCOld = "c" + (i - 2);
494                         IoTString iKeyCOld = new IoTString(keyCOld);
495                         IoTString iValueCOld = new IoTString(valueCOld);
496
497
498                         t2.startTransaction();
499                         t2.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyCOld, iValueCOld, Guard.Equal))));
500                         t2.addKV(iKeyC, iValueC);
501                         t2.commitTransaction();
502                 }
503
504                 for (int i = 1; i < NUMBER_OF_TESTS; i++) {
505                         String keyA = "a" + i;
506                         String keyD = "d" + i;
507                         String valueA = "a" + i;
508                         String valueD = "d" + i;
509
510                         IoTString iKeyA = new IoTString(keyA);
511                         IoTString iKeyD = new IoTString(keyD);
512                         IoTString iValueA = new IoTString(valueA);
513                         IoTString iValueD = new IoTString(valueD);
514
515
516                         String keyAOld = "a" + (i - 1);
517                         String keyDOld = "d" + (i - 1);
518                         String valueAOld = "a" + (i - 2);
519                         String valueDOld = "d" + (i - 2);
520                         IoTString iKeyAOld = new IoTString(keyAOld);
521                         IoTString iKeyDOld = new IoTString(keyDOld);
522                         IoTString iValueAOld = new IoTString(valueAOld);
523                         IoTString iValueDOld = new IoTString(valueDOld);
524
525
526                         t1.startTransaction();
527                         t1.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyAOld, iValueAOld, Guard.Equal))));
528                         t1.addKV(iKeyA, iValueA);
529                         t1.commitTransaction();
530
531                         t2.startTransaction();
532                         t2.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyDOld, iValueDOld, Guard.Equal))));
533                         t2.addKV(iKeyD, iValueD);
534                         t2.commitTransaction();
535                 }
536
537                 endTime = System.currentTimeMillis();
538
539                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
540                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
541                 System.out.println();
542
543
544                 System.out.println("Updating Clients...");
545                 t1.update();
546                 t2.update();
547                 t1.update();
548                 t2.update();
549
550                 boolean foundError = false;
551
552                 System.out.println("Checking Key-Values...");
553                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
554
555                         String keyA = "a" + i;
556                         String keyB = "b" + i;
557                         String keyC = "c" + i;
558                         String keyD = "d" + i;
559                         String valueA = "a" + i;
560                         String valueB = "b" + i;
561                         String valueC = "c" + i;
562                         String valueD = "d" + i;
563
564                         IoTString iKeyA = new IoTString(keyA);
565                         IoTString iKeyB = new IoTString(keyB);
566                         IoTString iKeyC = new IoTString(keyC);
567                         IoTString iKeyD = new IoTString(keyD);
568                         IoTString iValueA = new IoTString(valueA);
569                         IoTString iValueB = new IoTString(valueB);
570                         IoTString iValueC = new IoTString(valueC);
571                         IoTString iValueD = new IoTString(valueD);
572
573
574                         IoTString testValA1 = t1.getCommitted(iKeyA);
575                         IoTString testValB1 = t1.getCommitted(iKeyB);
576                         IoTString testValC1 = t1.getCommitted(iKeyC);
577                         IoTString testValD1 = t1.getCommitted(iKeyD);
578
579                         IoTString testValA2 = t2.getCommitted(iKeyA);
580                         IoTString testValB2 = t2.getCommitted(iKeyB);
581                         IoTString testValC2 = t2.getCommitted(iKeyC);
582                         IoTString testValD2 = t2.getCommitted(iKeyD);
583
584
585                         if (i == 0) {
586                                 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
587                                         System.out.println("Key-Value t1 incorrect: " + keyA);
588                                         foundError = true;
589                                 }
590
591                                 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
592                                         System.out.println("Key-Value t1 incorrect: " + keyB);
593                                         foundError = true;
594                                 }
595
596                                 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
597                                         System.out.println("Key-Value t1 incorrect: " + keyC);
598                                         foundError = true;
599                                 }
600
601                                 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
602                                         System.out.println("Key-Value t1 incorrect: " + keyD);
603                                         foundError = true;
604                                 }
605
606
607                                 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
608                                         System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
609                                         foundError = true;
610                                 }
611
612                                 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
613                                         System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
614                                         foundError = true;
615                                 }
616
617                                 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
618                                         System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
619                                         foundError = true;
620                                 }
621
622                                 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
623                                         System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
624                                         foundError = true;
625                                 }
626                         } else {
627                                 if (testValA1 != null) {
628                                         System.out.println("Key-Value t1 incorrect: " + keyA);
629                                         foundError = true;
630                                 }
631
632                                 if (testValB1 != null) {
633                                         System.out.println("Key-Value t1 incorrect: " + keyB);
634                                         foundError = true;
635                                 }
636
637                                 if (testValC1 != null) {
638                                         System.out.println("Key-Value t1 incorrect: " + keyC);
639                                         foundError = true;
640                                 }
641
642                                 if (testValD1 != null) {
643                                         System.out.println("Key-Value t1 incorrect: " + keyD);
644                                         foundError = true;
645                                 }
646
647                                 if (testValA2 != null) {
648                                         System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
649                                         foundError = true;
650                                 }
651
652                                 if (testValB2 != null) {
653                                         System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
654                                         foundError = true;
655                                 }
656
657                                 if (testValC2 != null) {
658                                         System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
659                                         foundError = true;
660                                 }
661
662                                 if (testValD2 != null) {
663                                         System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
664                                         foundError = true;
665                                 }
666                         }
667                 }
668
669                 if (foundError) {
670                         System.out.println("Found Errors...");
671                 } else {
672                         System.out.println("No Errors Found...");
673                 }
674         }
675
676         static void test6() {
677
678                 long startTime = 0;
679                 long endTime = 0;
680
681                 // Setup the 2 clients
682                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
683                 t1.initTable();
684                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
685                 t2.update();
686
687                 // t1.rebuild();
688                 // t2.rebuild();
689
690                 // Make the Keys
691                 System.out.println("Setting up keys");
692                 startTime = System.currentTimeMillis();
693                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
694                         String a = "a" + i;
695                         String b = "b" + i;
696                         String c = "c" + i;
697                         String d = "d" + i;
698                         IoTString ia = new IoTString(a);
699                         IoTString ib = new IoTString(b);
700                         IoTString ic = new IoTString(c);
701                         IoTString id = new IoTString(d);
702                         t1.createNewKey(ia, 321);
703                         t1.createNewKey(ib, 351);
704                         t2.createNewKey(ic, 321);
705                         t2.createNewKey(id, 351);
706                 }
707                 endTime = System.currentTimeMillis();
708
709                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
710                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
711                 System.out.println();
712
713
714                 // Do Updates for the keys
715                 System.out.println("Setting Key-Values...");
716                 startTime = System.currentTimeMillis();
717
718
719                 t1.startTransaction();
720                 t1.addKV( new IoTString("a0"), new IoTString("a0"));
721                 t1.commitTransaction();
722
723                 t1.startTransaction();
724                 t1.addKV(new IoTString("b0"), new IoTString("b0"));
725                 t1.commitTransaction();
726
727                 t2.startTransaction();
728                 t2.addKV(new IoTString("c0"), new IoTString("c0"));
729                 t2.commitTransaction();
730
731                 t2.startTransaction();
732                 t2.addKV(new IoTString("d0"), new IoTString("d0"));
733                 t2.commitTransaction();
734
735                 for (int i = 1; i < NUMBER_OF_TESTS; i++) {
736                         String keyB = "b" + i;
737                         String valueB = "b" + i;
738                         IoTString iKeyB = new IoTString(keyB);
739                         IoTString iValueB = new IoTString(valueB);
740
741                         String keyBOld = "b" + (i - 1);
742                         String valueBOld = "b" + (i - 1);
743                         IoTString iKeyBOld = new IoTString(keyBOld);
744                         IoTString iValueBOld = new IoTString(valueBOld);
745
746
747                         t1.startTransaction();
748                         t1.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyBOld, iValueBOld, Guard.Equal))));
749                         t1.addKV(iKeyB, iValueB);
750                         t1.commitTransaction();
751                 }
752
753                 for (int i = 1; i < NUMBER_OF_TESTS; i++) {
754                         String keyC = "c" + i;
755                         String valueC = "c" + i;
756                         IoTString iKeyC = new IoTString(keyC);
757                         IoTString iValueC = new IoTString(valueC);
758
759                         String keyCOld = "c" + (i - 1);
760                         String valueCOld = "c" + (i - 1);
761                         IoTString iKeyCOld = new IoTString(keyCOld);
762                         IoTString iValueCOld = new IoTString(valueCOld);
763
764
765                         t2.startTransaction();
766                         t2.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyCOld, iValueCOld, Guard.Equal))));
767                         t2.addKV(iKeyC, iValueC);
768                         t2.commitTransaction();
769                 }
770
771                 for (int i = 1; i < NUMBER_OF_TESTS; i++) {
772                         String keyA = "a" + i;
773                         String keyD = "d" + i;
774                         String valueA = "a" + i;
775                         String valueD = "d" + i;
776
777                         IoTString iKeyA = new IoTString(keyA);
778                         IoTString iKeyD = new IoTString(keyD);
779                         IoTString iValueA = new IoTString(valueA);
780                         IoTString iValueD = new IoTString(valueD);
781
782
783                         String keyAOld = "a" + (i - 1);
784                         String keyDOld = "d" + (i - 1);
785                         String valueAOld = "a" + (i - 1);
786                         String valueDOld = "d" + (i - 1);
787                         IoTString iKeyAOld = new IoTString(keyAOld);
788                         IoTString iKeyDOld = new IoTString(keyDOld);
789                         IoTString iValueAOld = new IoTString(valueAOld);
790                         IoTString iValueDOld = new IoTString(valueDOld);
791
792
793                         t1.startTransaction();
794                         t1.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyAOld, iValueAOld, Guard.Equal))));
795                         t1.addKV(iKeyA, iValueA);
796                         t1.commitTransaction();
797
798                         t2.startTransaction();
799                         t2.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyDOld, iValueDOld, Guard.Equal))));
800                         t2.addKV(iKeyD, iValueD);
801                         t2.commitTransaction();
802                 }
803
804                 endTime = System.currentTimeMillis();
805
806                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
807                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
808                 System.out.println();
809
810
811                 System.out.println("Updating Clients...");
812                 t1.update();
813                 t2.update();
814                 t1.update();
815                 t2.update();
816
817                 boolean foundError = false;
818
819                 System.out.println("Checking Key-Values...");
820                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
821
822                         String keyA = "a" + i;
823                         String keyB = "b" + i;
824                         String keyC = "c" + i;
825                         String keyD = "d" + i;
826                         String valueA = "a" + i;
827                         String valueB = "b" + i;
828                         String valueC = "c" + i;
829                         String valueD = "d" + i;
830
831                         IoTString iKeyA = new IoTString(keyA);
832                         IoTString iKeyB = new IoTString(keyB);
833                         IoTString iKeyC = new IoTString(keyC);
834                         IoTString iKeyD = new IoTString(keyD);
835                         IoTString iValueA = new IoTString(valueA);
836                         IoTString iValueB = new IoTString(valueB);
837                         IoTString iValueC = new IoTString(valueC);
838                         IoTString iValueD = new IoTString(valueD);
839
840
841                         IoTString testValA1 = t1.getCommitted(iKeyA);
842                         IoTString testValB1 = t1.getCommitted(iKeyB);
843                         IoTString testValC1 = t1.getCommitted(iKeyC);
844                         IoTString testValD1 = t1.getCommitted(iKeyD);
845
846                         IoTString testValA2 = t2.getCommitted(iKeyA);
847                         IoTString testValB2 = t2.getCommitted(iKeyB);
848                         IoTString testValC2 = t2.getCommitted(iKeyC);
849                         IoTString testValD2 = t2.getCommitted(iKeyD);
850
851                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
852                                 System.out.println("Key-Value t1 incorrect: " + keyA);
853                                 foundError = true;
854                         }
855
856                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
857                                 System.out.println("Key-Value t1 incorrect: " + keyB);
858                                 foundError = true;
859                         }
860
861                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
862                                 System.out.println("Key-Value t1 incorrect: " + keyC);
863                                 foundError = true;
864                         }
865
866                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
867                                 System.out.println("Key-Value t1 incorrect: " + keyD);
868                                 foundError = true;
869                         }
870
871
872                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
873                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
874                                 foundError = true;
875                         }
876
877                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
878                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
879                                 foundError = true;
880                         }
881
882                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
883                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
884                                 foundError = true;
885                         }
886
887                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
888                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
889                                 foundError = true;
890                         }
891                 }
892
893                 if (foundError) {
894                         System.out.println("Found Errors...");
895                 } else {
896                         System.out.println("No Errors Found...");
897                 }
898         }
899
900         static void test5() {
901
902                 long startTime = 0;
903                 long endTime = 0;
904
905                 // Setup the 2 clients
906                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
907                 t1.initTable();
908                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
909                 t2.update();
910
911                 // t1.rebuild();
912                 // t2.rebuild();
913
914
915
916                 // Make the Keys
917                 System.out.println("Setting up keys");
918                 startTime = System.currentTimeMillis();
919                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
920                         String a = "a" + i;
921                         String b = "b" + i;
922                         String c = "c" + i;
923                         String d = "d" + i;
924                         IoTString ia = new IoTString(a);
925                         IoTString ib = new IoTString(b);
926                         IoTString ic = new IoTString(c);
927                         IoTString id = new IoTString(d);
928                         t1.createNewKey(ia, 321);
929                         t1.createNewKey(ib, 351);
930                         t2.createNewKey(ic, 321);
931                         t2.createNewKey(id, 351);
932                 }
933                 endTime = System.currentTimeMillis();
934
935
936
937                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
938                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
939                 System.out.println();
940
941
942                 // Do Updates for the keys
943                 System.out.println("Setting Key-Values...");
944                 startTime = System.currentTimeMillis();
945                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
946                         String keyA = "a" + i;
947                         String keyB = "b" + i;
948                         String keyC = "c" + i;
949                         String keyD = "d" + i;
950                         String valueA = "a" + i;
951                         String valueB = "b" + i;
952                         String valueC = "c" + i;
953                         String valueD = "d" + i;
954
955                         IoTString iKeyA = new IoTString(keyA);
956                         IoTString iKeyB = new IoTString(keyB);
957                         IoTString iKeyC = new IoTString(keyC);
958                         IoTString iKeyD = new IoTString(keyD);
959                         IoTString iValueA = new IoTString(valueA);
960                         IoTString iValueB = new IoTString(valueB);
961                         IoTString iValueC = new IoTString(valueC);
962                         IoTString iValueD = new IoTString(valueD);
963
964
965
966                         if (i != 0) {
967                                 String keyAOld = "a" + (i - 1);
968                                 String keyBOld = "b" + (i - 1);
969                                 String keyCOld = "c" + (i - 1);
970                                 String keyDOld = "d" + (i - 1);
971                                 String valueAOld = "a" + (i - 1);
972                                 String valueBOld = "b" + (i - 1);
973                                 String valueCOld = "c" + (i - 1);
974                                 String valueDOld = "d" + (i - 1);
975
976                                 IoTString iKeyAOld = new IoTString(keyAOld);
977                                 IoTString iKeyBOld = new IoTString(keyBOld);
978                                 IoTString iKeyCOld = new IoTString(keyCOld);
979                                 IoTString iKeyDOld = new IoTString(keyDOld);
980                                 IoTString iValueAOld = new IoTString(valueAOld);
981                                 IoTString iValueBOld = new IoTString(valueBOld);
982                                 IoTString iValueCOld = new IoTString(valueCOld);
983                                 IoTString iValueDOld = new IoTString(valueDOld);
984
985                                 t1.startTransaction();
986                                 t1.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyAOld, iValueAOld, Guard.Equal))));
987                                 t1.addKV(iKeyA, iValueA);
988                                 t1.commitTransaction();
989
990                                 t1.startTransaction();
991                                 t1.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyBOld, iValueBOld, Guard.Equal))));
992                                 t1.addKV(iKeyB, iValueB);
993                                 t1.commitTransaction();
994
995                                 t2.startTransaction();
996                                 t2.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyCOld, iValueCOld, Guard.Equal))));
997                                 t2.addKV(iKeyC, iValueC);
998                                 t2.commitTransaction();
999
1000                                 t2.startTransaction();
1001                                 t2.addGuard(new Guard(new IoTString(Guard.createExpression(iKeyDOld, iValueDOld, Guard.Equal))));
1002                                 t2.addKV(iKeyD, iValueD);
1003                                 t2.commitTransaction();
1004
1005
1006                         } else {
1007                                 t1.startTransaction();
1008                                 t1.addKV(iKeyA, iValueA);
1009                                 t1.commitTransaction();
1010
1011                                 t1.startTransaction();
1012                                 t1.addKV(iKeyB, iValueB);
1013                                 t1.commitTransaction();
1014
1015                                 t2.startTransaction();
1016                                 t2.addKV(iKeyC, iValueC);
1017                                 t2.commitTransaction();
1018
1019                                 t2.startTransaction();
1020                                 t2.addKV(iKeyD, iValueD);
1021                                 t2.commitTransaction();
1022                         }
1023                 }
1024                 endTime = System.currentTimeMillis();
1025
1026                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1027                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
1028                 System.out.println();
1029
1030
1031                 System.out.println("Updating Clients...");
1032                 t1.update();
1033                 t2.update();
1034                 t1.update();
1035                 t2.update();
1036
1037                 boolean foundError = false;
1038
1039                 System.out.println("Checking Key-Values...");
1040                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1041
1042                         String keyA = "a" + i;
1043                         String keyB = "b" + i;
1044                         String keyC = "c" + i;
1045                         String keyD = "d" + i;
1046                         String valueA = "a" + i;
1047                         String valueB = "b" + i;
1048                         String valueC = "c" + i;
1049                         String valueD = "d" + i;
1050
1051                         IoTString iKeyA = new IoTString(keyA);
1052                         IoTString iKeyB = new IoTString(keyB);
1053                         IoTString iKeyC = new IoTString(keyC);
1054                         IoTString iKeyD = new IoTString(keyD);
1055                         IoTString iValueA = new IoTString(valueA);
1056                         IoTString iValueB = new IoTString(valueB);
1057                         IoTString iValueC = new IoTString(valueC);
1058                         IoTString iValueD = new IoTString(valueD);
1059
1060
1061                         IoTString testValA1 = t1.getCommitted(iKeyA);
1062                         IoTString testValB1 = t1.getCommitted(iKeyB);
1063                         IoTString testValC1 = t1.getCommitted(iKeyC);
1064                         IoTString testValD1 = t1.getCommitted(iKeyD);
1065
1066                         IoTString testValA2 = t2.getCommitted(iKeyA);
1067                         IoTString testValB2 = t2.getCommitted(iKeyB);
1068                         IoTString testValC2 = t2.getCommitted(iKeyC);
1069                         IoTString testValD2 = t2.getCommitted(iKeyD);
1070
1071                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1072                                 System.out.println("Key-Value t1 incorrect: " + keyA);
1073                                 foundError = true;
1074                         }
1075
1076                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1077                                 System.out.println("Key-Value t1 incorrect: " + keyB);
1078                                 foundError = true;
1079                         }
1080
1081                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1082                                 System.out.println("Key-Value t1 incorrect: " + keyC);
1083                                 foundError = true;
1084                         }
1085
1086                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1087                                 System.out.println("Key-Value t1 incorrect: " + keyD);
1088                                 foundError = true;
1089                         }
1090
1091
1092                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1093                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
1094                                 foundError = true;
1095                         }
1096
1097                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1098                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
1099                                 foundError = true;
1100                         }
1101
1102                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1103                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
1104                                 foundError = true;
1105                         }
1106
1107                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1108                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
1109                                 foundError = true;
1110                         }
1111                 }
1112
1113                 if (foundError) {
1114                         System.out.println("Found Errors...");
1115                 } else {
1116                         System.out.println("No Errors Found...");
1117                 }
1118         }
1119
1120         static void test4() {
1121
1122                 long startTime = 0;
1123                 long endTime = 0;
1124
1125                 // Setup the 2 clients
1126                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
1127                 t1.initTable();
1128                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
1129                 t2.update();
1130
1131
1132                 // Make the Keys
1133                 System.out.println("Setting up keys");
1134                 startTime = System.currentTimeMillis();
1135                 for (int i = 0; i < 4; i++) {
1136                         String a = "a" + i;
1137                         String b = "b" + i;
1138                         String c = "c" + i;
1139                         String d = "d" + i;
1140                         IoTString ia = new IoTString(a);
1141                         IoTString ib = new IoTString(b);
1142                         IoTString ic = new IoTString(c);
1143                         IoTString id = new IoTString(d);
1144                         t1.createNewKey(ia, 321);
1145                         t1.createNewKey(ib, 351);
1146                         t2.createNewKey(ic, 321);
1147                         t2.createNewKey(id, 351);
1148                 }
1149                 endTime = System.currentTimeMillis();
1150
1151
1152
1153                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1154                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
1155                 System.out.println();
1156
1157
1158                 // Do Updates for the keys
1159                 System.out.println("Setting Key-Values...");
1160                 startTime = System.currentTimeMillis();
1161                 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
1162                         for (int i = 0; i < 4; i++) {
1163                                 String keyA = "a" + i;
1164                                 String keyB = "b" + i;
1165                                 String keyC = "c" + i;
1166                                 String keyD = "d" + i;
1167                                 String valueA = "a" + i;
1168                                 String valueB = "b" + i;
1169                                 String valueC = "c" + i;
1170                                 String valueD = "d" + i;
1171
1172                                 IoTString iKeyA = new IoTString(keyA);
1173                                 IoTString iKeyB = new IoTString(keyB);
1174                                 IoTString iKeyC = new IoTString(keyC);
1175                                 IoTString iKeyD = new IoTString(keyD);
1176                                 IoTString iValueA = new IoTString(valueA);
1177                                 IoTString iValueB = new IoTString(valueB);
1178                                 IoTString iValueC = new IoTString(valueC);
1179                                 IoTString iValueD = new IoTString(valueD);
1180
1181                                 t1.startTransaction();
1182                                 t1.addKV(iKeyA, iValueA);
1183                                 t1.commitTransaction();
1184
1185                                 t1.startTransaction();
1186                                 t1.addKV(iKeyB, iValueB);
1187                                 t1.commitTransaction();
1188
1189                                 t2.startTransaction();
1190                                 t2.addKV(iKeyC, iValueC);
1191                                 t2.commitTransaction();
1192
1193                                 t2.startTransaction();
1194                                 t2.addKV(iKeyD, iValueD);
1195                                 t2.commitTransaction();
1196                         }
1197                 }
1198                 endTime = System.currentTimeMillis();
1199
1200                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1201                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 8))   );
1202                 System.out.println();
1203
1204
1205                 System.out.println("Updating Clients...");
1206                 t1.update();
1207                 t2.update();
1208                 t1.update();
1209                 t2.update();
1210
1211                 boolean foundError = false;
1212
1213                 System.out.println("Checking Key-Values...");
1214                 for (int i = 0; i < 4; i++) {
1215
1216                         String keyA = "a" + i;
1217                         String keyB = "b" + i;
1218                         String keyC = "c" + i;
1219                         String keyD = "d" + i;
1220                         String valueA = "a" + i;
1221                         String valueB = "b" + i;
1222                         String valueC = "c" + i;
1223                         String valueD = "d" + i;
1224
1225                         IoTString iKeyA = new IoTString(keyA);
1226                         IoTString iKeyB = new IoTString(keyB);
1227                         IoTString iKeyC = new IoTString(keyC);
1228                         IoTString iKeyD = new IoTString(keyD);
1229                         IoTString iValueA = new IoTString(valueA);
1230                         IoTString iValueB = new IoTString(valueB);
1231                         IoTString iValueC = new IoTString(valueC);
1232                         IoTString iValueD = new IoTString(valueD);
1233
1234
1235                         IoTString testValA1 = t1.getCommitted(iKeyA);
1236                         IoTString testValB1 = t1.getCommitted(iKeyB);
1237                         IoTString testValC1 = t1.getCommitted(iKeyC);
1238                         IoTString testValD1 = t1.getCommitted(iKeyD);
1239
1240                         IoTString testValA2 = t2.getCommitted(iKeyA);
1241                         IoTString testValB2 = t2.getCommitted(iKeyB);
1242                         IoTString testValC2 = t2.getCommitted(iKeyC);
1243                         IoTString testValD2 = t2.getCommitted(iKeyD);
1244
1245                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1246                                 System.out.println("Key-Value t1 incorrect: " + keyA);
1247                                 foundError = true;
1248                         }
1249
1250                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1251                                 System.out.println("Key-Value t1 incorrect: " + keyB);
1252                                 foundError = true;
1253                         }
1254
1255                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1256                                 System.out.println("Key-Value t1 incorrect: " + keyC);
1257                                 foundError = true;
1258                         }
1259
1260                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1261                                 System.out.println("Key-Value t1 incorrect: " + keyD);
1262                                 foundError = true;
1263                         }
1264
1265
1266                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1267                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
1268                                 foundError = true;
1269                         }
1270
1271                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1272                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
1273                                 foundError = true;
1274                         }
1275
1276                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1277                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
1278                                 foundError = true;
1279                         }
1280
1281                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1282                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
1283                                 foundError = true;
1284                         }
1285                 }
1286
1287                 if (foundError) {
1288                         System.out.println("Found Errors...");
1289                 } else {
1290                         System.out.println("No Errors Found...");
1291                 }
1292         }
1293
1294         static void test3() {
1295
1296                 long startTime = 0;
1297                 long endTime = 0;
1298
1299                 // Setup the 2 clients
1300                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
1301                 t1.initTable();
1302                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
1303                 t2.update();
1304
1305
1306                 // Make the Keys
1307                 System.out.println("Setting up keys");
1308                 startTime = System.currentTimeMillis();
1309                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1310                         String a = "a" + i;
1311                         String b = "b" + i;
1312                         String c = "c" + i;
1313                         String d = "d" + i;
1314                         IoTString ia = new IoTString(a);
1315                         IoTString ib = new IoTString(b);
1316                         IoTString ic = new IoTString(c);
1317                         IoTString id = new IoTString(d);
1318                         t1.createNewKey(ia, 321);
1319                         t1.createNewKey(ib, 351);
1320                         t2.createNewKey(ic, 321);
1321                         t2.createNewKey(id, 351);
1322                 }
1323                 endTime = System.currentTimeMillis();
1324
1325
1326
1327                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1328                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
1329                 System.out.println();
1330
1331
1332                 // Do Updates for the keys
1333                 System.out.println("Setting Key-Values...");
1334                 startTime = System.currentTimeMillis();
1335                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1336                         String keyB = "b" + i;
1337                         String valueB = "b" + i;
1338
1339                         IoTString iKeyB = new IoTString(keyB);
1340                         IoTString iValueB = new IoTString(valueB);
1341
1342                         t1.startTransaction();
1343                         t1.addKV(iKeyB, iValueB);
1344                         t1.commitTransaction();
1345                 }
1346
1347                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1348                         String keyC = "c" + i;
1349                         String valueC = "c" + i;
1350
1351                         IoTString iKeyC = new IoTString(keyC);
1352                         IoTString iValueC = new IoTString(valueC);
1353
1354                         t2.startTransaction();
1355                         t2.addKV(iKeyC, iValueC);
1356                         t2.commitTransaction();
1357                 }
1358
1359                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1360                         String keyA = "a" + i;
1361                         String keyD = "d" + i;
1362                         String valueA = "a" + i;
1363                         String valueD = "d" + i;
1364
1365                         IoTString iKeyA = new IoTString(keyA);
1366                         IoTString iKeyD = new IoTString(keyD);
1367                         IoTString iValueA = new IoTString(valueA);
1368                         IoTString iValueD = new IoTString(valueD);
1369
1370                         t1.startTransaction();
1371                         t1.addKV(iKeyA, iValueA);
1372                         t1.commitTransaction();
1373
1374                         t2.startTransaction();
1375                         t2.addKV(iKeyD, iValueD);
1376                         t2.commitTransaction();
1377                 }
1378                 endTime = System.currentTimeMillis();
1379
1380                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1381                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
1382                 System.out.println();
1383
1384
1385                 System.out.println("Updating Clients...");
1386                 t1.update();
1387                 t2.update();
1388                 t1.update();
1389                 t2.update();
1390
1391                 boolean foundError = false;
1392
1393                 System.out.println("Checking Key-Values...");
1394                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1395
1396                         String keyA = "a" + i;
1397                         String keyB = "b" + i;
1398                         String keyC = "c" + i;
1399                         String keyD = "d" + i;
1400                         String valueA = "a" + i;
1401                         String valueB = "b" + i;
1402                         String valueC = "c" + i;
1403                         String valueD = "d" + i;
1404
1405                         IoTString iKeyA = new IoTString(keyA);
1406                         IoTString iKeyB = new IoTString(keyB);
1407                         IoTString iKeyC = new IoTString(keyC);
1408                         IoTString iKeyD = new IoTString(keyD);
1409                         IoTString iValueA = new IoTString(valueA);
1410                         IoTString iValueB = new IoTString(valueB);
1411                         IoTString iValueC = new IoTString(valueC);
1412                         IoTString iValueD = new IoTString(valueD);
1413
1414
1415                         IoTString testValA1 = t1.getCommitted(iKeyA);
1416                         IoTString testValB1 = t1.getCommitted(iKeyB);
1417                         IoTString testValC1 = t1.getCommitted(iKeyC);
1418                         IoTString testValD1 = t1.getCommitted(iKeyD);
1419
1420                         IoTString testValA2 = t2.getCommitted(iKeyA);
1421                         IoTString testValB2 = t2.getCommitted(iKeyB);
1422                         IoTString testValC2 = t2.getCommitted(iKeyC);
1423                         IoTString testValD2 = t2.getCommitted(iKeyD);
1424
1425                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1426                                 System.out.println("Key-Value t1 incorrect: " + keyA);
1427                                 foundError = true;
1428                         }
1429
1430                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1431                                 System.out.println("Key-Value t1 incorrect: " + keyB);
1432                                 foundError = true;
1433                         }
1434
1435                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1436                                 System.out.println("Key-Value t1 incorrect: " + keyC);
1437                                 foundError = true;
1438                         }
1439
1440                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1441                                 System.out.println("Key-Value t1 incorrect: " + keyD);
1442                                 foundError = true;
1443                         }
1444
1445
1446                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1447                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
1448                                 foundError = true;
1449                         }
1450
1451                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1452                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
1453                                 foundError = true;
1454                         }
1455
1456                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1457                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
1458                                 foundError = true;
1459                         }
1460
1461                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1462                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
1463                                 foundError = true;
1464                         }
1465                 }
1466
1467                 if (foundError) {
1468                         System.out.println("Found Errors...");
1469                 } else {
1470                         System.out.println("No Errors Found...");
1471                 }
1472         }
1473
1474         static void test2() {
1475
1476                 long startTime = 0;
1477                 long endTime = 0;
1478
1479                 // Setup the 2 clients
1480                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
1481                 t1.initTable();
1482                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
1483                 t2.update();
1484
1485                 // t1.rebuild();
1486                 // t2.rebuild();
1487
1488
1489
1490                 // Make the Keys
1491                 System.out.println("Setting up keys");
1492                 startTime = System.currentTimeMillis();
1493                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1494                         String a = "a" + i;
1495                         String b = "b" + i;
1496                         String c = "c" + i;
1497                         String d = "d" + i;
1498                         IoTString ia = new IoTString(a);
1499                         IoTString ib = new IoTString(b);
1500                         IoTString ic = new IoTString(c);
1501                         IoTString id = new IoTString(d);
1502                         t1.createNewKey(ia, 321);
1503                         t1.createNewKey(ib, 351);
1504                         t2.createNewKey(ic, 321);
1505                         t2.createNewKey(id, 351);
1506                 }
1507                 endTime = System.currentTimeMillis();
1508
1509
1510
1511                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1512                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
1513                 System.out.println();
1514
1515
1516                 // Do Updates for the keys
1517                 System.out.println("Setting Key-Values...");
1518                 startTime = System.currentTimeMillis();
1519                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1520                         String keyA = "a" + i;
1521                         String keyB = "b" + i;
1522                         String keyC = "c" + i;
1523                         String keyD = "d" + i;
1524                         String valueA = "a" + i;
1525                         String valueB = "b" + i;
1526                         String valueC = "c" + i;
1527                         String valueD = "d" + i;
1528
1529                         IoTString iKeyA = new IoTString(keyA);
1530                         IoTString iKeyB = new IoTString(keyB);
1531                         IoTString iKeyC = new IoTString(keyC);
1532                         IoTString iKeyD = new IoTString(keyD);
1533                         IoTString iValueA = new IoTString(valueA);
1534                         IoTString iValueB = new IoTString(valueB);
1535                         IoTString iValueC = new IoTString(valueC);
1536                         IoTString iValueD = new IoTString(valueD);
1537
1538                         t1.startTransaction();
1539                         t1.addKV(iKeyA, iValueA);
1540                         t1.commitTransaction();
1541
1542                         t1.startTransaction();
1543                         t1.addKV(iKeyB, iValueB);
1544                         t1.commitTransaction();
1545
1546                         t2.startTransaction();
1547                         t2.addKV(iKeyC, iValueC);
1548                         t2.commitTransaction();
1549
1550                         t2.startTransaction();
1551                         t2.addKV(iKeyD, iValueD);
1552                         t2.commitTransaction();
1553                 }
1554                 endTime = System.currentTimeMillis();
1555
1556                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
1557                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
1558                 System.out.println();
1559
1560
1561                 System.out.println("Updating Clients...");
1562                 t1.update();
1563                 t2.update();
1564                 t1.update();
1565                 t2.update();
1566
1567                 boolean foundError = false;
1568
1569                 System.out.println("Checking Key-Values...");
1570                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1571
1572                         String keyA = "a" + i;
1573                         String keyB = "b" + i;
1574                         String keyC = "c" + i;
1575                         String keyD = "d" + i;
1576                         String valueA = "a" + i;
1577                         String valueB = "b" + i;
1578                         String valueC = "c" + i;
1579                         String valueD = "d" + i;
1580
1581                         IoTString iKeyA = new IoTString(keyA);
1582                         IoTString iKeyB = new IoTString(keyB);
1583                         IoTString iKeyC = new IoTString(keyC);
1584                         IoTString iKeyD = new IoTString(keyD);
1585                         IoTString iValueA = new IoTString(valueA);
1586                         IoTString iValueB = new IoTString(valueB);
1587                         IoTString iValueC = new IoTString(valueC);
1588                         IoTString iValueD = new IoTString(valueD);
1589
1590
1591                         IoTString testValA1 = t1.getCommitted(iKeyA);
1592                         IoTString testValB1 = t1.getCommitted(iKeyB);
1593                         IoTString testValC1 = t1.getCommitted(iKeyC);
1594                         IoTString testValD1 = t1.getCommitted(iKeyD);
1595
1596                         IoTString testValA2 = t2.getCommitted(iKeyA);
1597                         IoTString testValB2 = t2.getCommitted(iKeyB);
1598                         IoTString testValC2 = t2.getCommitted(iKeyC);
1599                         IoTString testValD2 = t2.getCommitted(iKeyD);
1600
1601                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1602                                 System.out.println("Key-Value t1 incorrect: " + keyA);
1603                                 foundError = true;
1604                         }
1605
1606                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1607                                 System.out.println("Key-Value t1 incorrect: " + keyB);
1608                                 foundError = true;
1609                         }
1610
1611                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1612                                 System.out.println("Key-Value t1 incorrect: " + keyC);
1613                                 foundError = true;
1614                         }
1615
1616                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1617                                 System.out.println("Key-Value t1 incorrect: " + keyD);
1618                                 foundError = true;
1619                         }
1620
1621
1622                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1623                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
1624                                 foundError = true;
1625                         }
1626
1627                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1628                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
1629                                 foundError = true;
1630                         }
1631
1632                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1633                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
1634                                 foundError = true;
1635                         }
1636
1637                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1638                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
1639                                 foundError = true;
1640                         }
1641                 }
1642
1643                 if (foundError) {
1644                         System.out.println("Found Errors...");
1645                 } else {
1646                         System.out.println("No Errors Found...");
1647                 }
1648         }
1649 }