4 import java.util.ArrayList;
14 public static final int NUMBER_OF_TESTS = 100;
16 public static void main(String[] args) throws ServerException, InterruptedException {
17 if (args[0].equals("2")) {
19 } else if (args[0].equals("3")) {
21 } else if (args[0].equals("4")) {
23 } else if (args[0].equals("5")) {
25 } else if (args[0].equals("6")) {
27 } else if (args[0].equals("7")) {
29 } else if (args[0].equals("8")) {
31 } else if (args[0].equals("9")) {
33 } else if (args[0].equals("10")) {
35 } else if (args[0].equals("11")) {
41 static void test11() throws InterruptedException {
43 boolean foundError = false;
45 // Setup the 2 clients
46 Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
51 } catch (Exception e) {}
54 Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
55 while (t2.update().getFirst() == false) {}
57 LocalComm lc = new LocalComm(t1, t2);
58 t1.addLocalComm(t2.getId(), lc);
59 t2.addLocalComm(t1.getId(), lc);
62 System.out.println("Setting up keys");
63 for (int i = 0; i < 4; 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);
74 t1.createNewKey(ia, 321);
76 } catch (Exception e) {}
81 t1.createNewKey(ib, 351);
83 } catch (Exception e) {}
88 t2.createNewKey(ic, 321);
90 } catch (Exception e) {}
95 t2.createNewKey(id, 351);
97 } catch (Exception e) {}
101 // Do Updates for the keys
102 System.out.println("Setting Key-Values...");
103 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
104 for (int i = 0; i < 4; i++) {
105 String keyA = "a" + i;
106 String valueA = "a" + (i + t);
108 IoTString iKeyA = new IoTString(keyA);
109 IoTString iValueA = new IoTString(valueA);
111 t1.startTransaction();
112 t1.addKV(iKeyA, iValueA);
113 t1.commitTransaction();
117 t2.updateFromLocal(321);
119 System.out.println("Checking Key-Values...");
120 for (int i = 0; i < 4; i++) {
122 String keyA = "a" + i;
123 String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
125 IoTString iKeyA = new IoTString(keyA);
126 IoTString iValueA = new IoTString(valueA);
128 IoTString testValA1 = t1.getCommitted(iKeyA);
129 IoTString testValA2 = t2.getCommitted(iKeyA);
131 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
132 System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1 + " " + iValueA);
136 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
137 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2 + " " + iValueA);
143 System.out.println("Found Errors...");
145 System.out.println("No Errors Found...");
149 static void test10() throws InterruptedException {
151 boolean foundError = false;
153 // Setup the 2 clients
154 Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
159 } catch (Exception e) {}
162 Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
167 } catch (Exception e) {}
170 LocalComm lc = new LocalComm(t1, t2);
171 t1.addLocalComm(t2.getId(), lc);
172 t2.addLocalComm(t1.getId(), lc);
175 System.out.println("Checking Key-Values...");
176 for (int i = 0; i < 4; i++) {
178 String keyA = "a" + i;
179 String keyB = "b" + i;
180 String keyC = "c" + i;
181 String keyD = "d" + i;
182 String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
183 String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
184 String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
185 String valueD = "d" + (i + NUMBER_OF_TESTS - 1);
187 IoTString iKeyA = new IoTString(keyA);
188 IoTString iKeyB = new IoTString(keyB);
189 IoTString iKeyC = new IoTString(keyC);
190 IoTString iKeyD = new IoTString(keyD);
191 IoTString iValueA = new IoTString(valueA);
192 IoTString iValueB = new IoTString(valueB);
193 IoTString iValueC = new IoTString(valueC);
194 IoTString iValueD = new IoTString(valueD);
197 IoTString testValA1 = t1.getCommitted(iKeyA);
198 IoTString testValB1 = t1.getCommitted(iKeyB);
199 IoTString testValC1 = t1.getCommitted(iKeyC);
200 IoTString testValD1 = t1.getCommitted(iKeyD);
202 IoTString testValA2 = t2.getCommitted(iKeyA);
203 IoTString testValB2 = t2.getCommitted(iKeyB);
204 IoTString testValC2 = t2.getCommitted(iKeyC);
205 IoTString testValD2 = t2.getCommitted(iKeyD);
207 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
208 System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1 + " " + iValueA);
212 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
213 System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1 + " " + iValueB);
217 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
218 System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1 + " " + iValueC);
222 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
223 System.out.println("Key-Value t1 incorrect: " + keyD + " " + testValD1 + " " + iValueD);
227 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
228 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2 + " " + iValueA);
232 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
233 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2 + " " + iValueB);
237 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
238 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2 + " " + iValueC);
242 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
243 System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2 + " " + iValueD);
249 System.out.println("Found Errors...");
251 System.out.println("No Errors Found...");
255 static void test9() throws InterruptedException {
257 boolean foundError = false;
258 List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
260 // Setup the 2 clients
261 Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
266 } catch (Exception e) {}
269 Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
270 while (t2.update().getFirst() == false) {}
272 // LocalComm lc = new LocalComm(t1, t2);
273 // t1.addLocalComm(t2.getId(), lc);
274 // t2.addLocalComm(t1.getId(), lc);
279 System.out.println("Setting up keys");
280 for (int i = 0; i < 4; i++) {
285 IoTString ia = new IoTString(a);
286 IoTString ib = new IoTString(b);
287 IoTString ic = new IoTString(c);
288 IoTString id = new IoTString(d);
291 t1.createNewKey(ia, 321);
293 } catch (Exception e) {}
298 t1.createNewKey(ib, 351);
300 } catch (Exception e) {}
305 t2.createNewKey(ic, 321);
307 } catch (Exception e) {}
312 t2.createNewKey(id, 351);
314 } catch (Exception e) {}
318 // Do Updates for the keys
319 System.out.println("Setting Key-Values...");
321 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
322 for (int i = 0; i < 4; i++) {
323 String keyB = "b" + i;
324 String valueB = "b" + (i + t);
326 IoTString iKeyB = new IoTString(keyB);
327 IoTString iValueB = new IoTString(valueB);
330 t1.startTransaction();
331 t1.getSpeculativeAtomic(iKeyB);
332 t1.addKV(iKeyB, iValueB);
333 transStatusList.add(t1.commitTransaction());
337 while (t1.update().getFirst() == false) {}
340 for (int i = 0; i < 4; i++) {
342 String keyB = "b" + i;
343 String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
344 IoTString iKeyB = new IoTString(keyB);
345 IoTString iValueB = new IoTString(valueB);
347 IoTString testValB1 = t1.getSpeculative(iKeyB);
348 IoTString testValB2 = t2.getSpeculative(iKeyB);
350 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
351 System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1);
355 if ((testValB2 != null)) {
356 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
361 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
362 for (int i = 0; i < 4; i++) {
363 String keyC = "c" + i;
364 String valueC = "c" + (i + t);
366 IoTString iKeyC = new IoTString(keyC);
367 IoTString iValueC = new IoTString(valueC);
369 t2.startTransaction();
370 t2.getSpeculativeAtomic(iKeyC);
371 t2.addKV(iKeyC, iValueC);
372 transStatusList.add(t2.commitTransaction());
376 while (t2.update().getFirst() == false) {}
378 for (int i = 0; i < 4; i++) {
379 String keyC = "c" + i;
380 String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
381 IoTString iKeyC = new IoTString(keyC);
382 IoTString iValueC = new IoTString(valueC);
384 IoTString testValC1 = t1.getSpeculative(iKeyC);
385 IoTString testValC2 = t2.getSpeculative(iKeyC);
387 if ((testValC1 != null)) {
388 System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1);
392 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
393 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
398 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
399 for (int i = 0; i < 4; i++) {
400 String keyA = "a" + i;
401 String keyD = "d" + i;
402 String valueA = "a" + (i + t);
403 String valueD = "d" + (i + t);
405 IoTString iKeyA = new IoTString(keyA);
406 IoTString iKeyD = new IoTString(keyD);
407 IoTString iValueA = new IoTString(valueA);
408 IoTString iValueD = new IoTString(valueD);
411 t1.startTransaction();
412 t1.addKV(iKeyA, iValueA);
413 transStatusList.add(t1.commitTransaction());
415 t2.startTransaction();
416 t2.addKV(iKeyD, iValueD);
417 transStatusList.add(t2.commitTransaction());
421 System.out.println("Updating Clients...");
422 while (t1.update().getFirst() == false) {}
423 while (t2.update().getFirst() == false) {}
425 System.out.println("Checking Key-Values...");
426 for (int i = 0; i < 4; i++) {
428 String keyA = "a" + i;
429 String keyB = "b" + i;
430 String keyC = "c" + i;
431 String keyD = "d" + i;
432 String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
433 String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
434 String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
435 String valueD = "d" + (i + NUMBER_OF_TESTS - 1);
437 IoTString iKeyA = new IoTString(keyA);
438 IoTString iKeyB = new IoTString(keyB);
439 IoTString iKeyC = new IoTString(keyC);
440 IoTString iKeyD = new IoTString(keyD);
441 IoTString iValueA = new IoTString(valueA);
442 IoTString iValueB = new IoTString(valueB);
443 IoTString iValueC = new IoTString(valueC);
444 IoTString iValueD = new IoTString(valueD);
447 IoTString testValA1 = t1.getCommitted(iKeyA);
448 IoTString testValB1 = t1.getCommitted(iKeyB);
449 IoTString testValC1 = t1.getCommitted(iKeyC);
450 IoTString testValD1 = t1.getCommitted(iKeyD);
452 IoTString testValA2 = t2.getCommitted(iKeyA);
453 IoTString testValB2 = t2.getCommitted(iKeyB);
454 IoTString testValC2 = t2.getCommitted(iKeyC);
455 IoTString testValD2 = t2.getCommitted(iKeyD);
457 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
458 System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1 + " " + iValueA);
462 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
463 System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1 + " " + iValueB);
467 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
468 System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1 + " " + iValueC);
472 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
473 System.out.println("Key-Value t1 incorrect: " + keyD + " " + testValD1 + " " + iValueD);
477 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
478 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2 + " " + iValueA);
482 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
483 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2 + " " + iValueB);
487 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
488 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2 + " " + iValueC);
492 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
493 System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2 + " " + iValueD);
498 for (TransactionStatus status : transStatusList) {
499 if (status.getStatus() != TransactionStatus.StatusCommitted) {
501 System.out.println(status.getStatus());
506 System.out.println("Found Errors...");
508 System.out.println("No Errors Found...");
512 static void test8() throws InterruptedException {
514 boolean foundError = false;
515 List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
517 // Setup the 2 clients
518 Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
523 } catch (Exception e) {}
526 Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
527 while (t2.update().getFirst() == false) {}
529 LocalComm lc = new LocalComm(t1, t2);
530 t1.addLocalComm(t2.getId(), lc);
531 t2.addLocalComm(t1.getId(), lc);
534 System.out.println("Setting up keys");
535 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
536 System.out.println(i);
542 IoTString ia = new IoTString(a);
543 IoTString ib = new IoTString(b);
544 IoTString ic = new IoTString(c);
545 IoTString id = new IoTString(d);
549 t1.createNewKey(ia, 321);
551 } catch (Exception e) {}
556 t1.createNewKey(ib, 351);
558 } catch (Exception e) {}
563 t2.createNewKey(ic, 321);
565 } catch (Exception e) {}
570 t2.createNewKey(id, 351);
572 } catch (Exception e) {}
576 // Do Updates for the keys
577 System.out.println("Setting Key-Values...");
578 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
579 System.out.println(i);
580 String keyA = "a" + i;
581 String keyB = "b" + i;
582 String keyC = "c" + i;
583 String keyD = "d" + i;
584 String valueA = "a" + i;
585 String valueB = "b" + i;
586 String valueC = "c" + i;
587 String valueD = "d" + i;
589 IoTString iKeyA = new IoTString(keyA);
590 IoTString iKeyB = new IoTString(keyB);
591 IoTString iKeyC = new IoTString(keyC);
592 IoTString iKeyD = new IoTString(keyD);
593 IoTString iValueA = new IoTString(valueA);
594 IoTString iValueB = new IoTString(valueB);
595 IoTString iValueC = new IoTString(valueC);
596 IoTString iValueD = new IoTString(valueD);
599 String keyAPrev = "a" + (i - 1);
600 String keyBPrev = "b" + (i - 1);
601 String keyCPrev = "c" + (i - 1);
602 String keyDPrev = "d" + (i - 1);
603 String valueAPrev = "a" + (i - 1);
604 String valueBPrev = "b" + (i - 1);
605 String valueCPrev = "c" + (i - 1);
606 String valueDPrev = "d" + (i - 1);
608 IoTString iKeyAPrev = new IoTString(keyAPrev);
609 IoTString iKeyBPrev = new IoTString(keyBPrev);
610 IoTString iKeyCPrev = new IoTString(keyCPrev);
611 IoTString iKeyDPrev = new IoTString(keyDPrev);
612 IoTString iValueAPrev = new IoTString(valueAPrev);
613 IoTString iValueBPrev = new IoTString(valueBPrev);
614 IoTString iValueCPrev = new IoTString(valueCPrev);
615 IoTString iValueDPrev = new IoTString(valueDPrev);
617 t1.startTransaction();
619 IoTString tmp = t1.getSpeculative(iKeyAPrev);
620 if ((tmp == null) || !tmp.equals(iValueAPrev)) {
621 System.out.println("Key a Error: " + i);
625 t1.addKV(iKeyA, iValueA);
626 transStatusList.add(t1.commitTransaction());
630 t1.startTransaction();
632 IoTString tmp = t1.getSpeculative(iKeyBPrev);
633 if ((tmp == null) || !tmp.equals(iValueBPrev)) {
634 System.out.println("Key b Error: " + i);
638 t1.addKV(iKeyB, iValueB);
639 transStatusList.add(t1.commitTransaction());
642 t2.startTransaction();
644 IoTString tmp = t2.getSpeculative(iKeyCPrev);
645 if ((tmp == null) || !tmp.equals(iValueCPrev)) {
646 System.out.println("Key c Error: " + i);
650 t2.addKV(iKeyC, iValueC);
651 transStatusList.add(t2.commitTransaction());
653 t2.startTransaction();
655 IoTString tmp = t2.getSpeculative(iKeyDPrev);
656 if ((tmp == null) || !tmp.equals(iValueDPrev)) {
657 System.out.println("Key d Error: " + i);
661 t2.addKV(iKeyD, iValueD);
662 transStatusList.add(t2.commitTransaction());
666 System.out.println("Updating...");
667 while (t1.update().getFirst() == false) {}
668 while (t2.update().getFirst() == false) {}
671 System.out.println("Checking Key-Values...");
672 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
674 String keyA = "a" + i;
675 String keyB = "b" + i;
676 String keyC = "c" + i;
677 String keyD = "d" + i;
678 String valueA = "a" + i;
679 String valueB = "b" + i;
680 String valueC = "c" + i;
681 String valueD = "d" + i;
683 IoTString iKeyA = new IoTString(keyA);
684 IoTString iKeyB = new IoTString(keyB);
685 IoTString iKeyC = new IoTString(keyC);
686 IoTString iKeyD = new IoTString(keyD);
687 IoTString iValueA = new IoTString(valueA);
688 IoTString iValueB = new IoTString(valueB);
689 IoTString iValueC = new IoTString(valueC);
690 IoTString iValueD = new IoTString(valueD);
693 IoTString testValA1 = t1.getCommitted(iKeyA);
694 IoTString testValB1 = t1.getCommitted(iKeyB);
695 IoTString testValC1 = t1.getCommitted(iKeyC);
696 IoTString testValD1 = t1.getCommitted(iKeyD);
698 IoTString testValA2 = t2.getCommitted(iKeyA);
699 IoTString testValB2 = t2.getCommitted(iKeyB);
700 IoTString testValC2 = t2.getCommitted(iKeyC);
701 IoTString testValD2 = t2.getCommitted(iKeyD);
703 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
704 System.out.println("Key-Value t1 incorrect: " + keyA);
708 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
709 System.out.println("Key-Value t1 incorrect: " + keyB);
713 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
714 System.out.println("Key-Value t1 incorrect: " + keyC);
718 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
719 System.out.println("Key-Value t1 incorrect: " + keyD);
724 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
725 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
729 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
730 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
734 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
735 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
739 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
740 System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
745 for (TransactionStatus status : transStatusList) {
746 if (status.getStatus() != TransactionStatus.StatusCommitted) {
751 System.out.println("Found Errors...");
753 System.out.println("No Errors Found...");
757 static void test7() throws ServerException, InterruptedException {
759 boolean foundError = false;
760 List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
762 // Setup the 2 clients
763 Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
765 Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
769 System.out.println("Setting up keys");
770 for (int i = 0; i < 4; i++) {
775 IoTString ia = new IoTString(a);
776 IoTString ib = new IoTString(b);
777 IoTString ic = new IoTString(c);
778 IoTString id = new IoTString(d);
779 t1.createNewKey(ia, 321);
780 t1.createNewKey(ib, 351);
781 t2.createNewKey(ic, 321);
782 t2.createNewKey(id, 351);
785 // Do Updates for the keys
786 System.out.println("Setting Key-Values...");
788 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
789 for (int i = 0; i < 4; i++) {
790 String keyB = "b" + i;
791 String valueB = "b" + (i + t);
793 IoTString iKeyB = new IoTString(keyB);
794 IoTString iValueB = new IoTString(valueB);
796 t1.startTransaction();
797 t1.getSpeculativeAtomic(iKeyB);
798 t1.addKV(iKeyB, iValueB);
799 transStatusList.add(t1.commitTransaction());
803 for (int i = 0; i < 4; i++) {
805 String keyB = "b" + i;
806 String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
807 IoTString iKeyB = new IoTString(keyB);
808 IoTString iValueB = new IoTString(valueB);
810 IoTString testValB1 = t1.getSpeculative(iKeyB);
811 IoTString testValB2 = t2.getSpeculative(iKeyB);
813 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
814 System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1);
818 if ((testValB2 != null)) {
819 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
824 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
825 for (int i = 0; i < 4; i++) {
826 String keyC = "c" + i;
827 String valueC = "c" + (i + t);
829 IoTString iKeyC = new IoTString(keyC);
830 IoTString iValueC = new IoTString(valueC);
832 t2.startTransaction();
833 t2.getSpeculativeAtomic(iKeyC);
834 t2.addKV(iKeyC, iValueC);
835 transStatusList.add(t2.commitTransaction());
839 for (int i = 0; i < 4; i++) {
840 String keyC = "c" + i;
841 String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
842 IoTString iKeyC = new IoTString(keyC);
843 IoTString iValueC = new IoTString(valueC);
845 IoTString testValC1 = t1.getSpeculative(iKeyC);
846 IoTString testValC2 = t2.getSpeculative(iKeyC);
848 if ((testValC1 != null)) {
849 System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1);
853 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
854 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
859 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
860 for (int i = 0; i < 4; i++) {
861 String keyA = "a" + i;
862 String keyD = "d" + i;
863 String valueA = "a" + (i + t);
864 String valueD = "d" + (i + t);
866 IoTString iKeyA = new IoTString(keyA);
867 IoTString iKeyD = new IoTString(keyD);
868 IoTString iValueA = new IoTString(valueA);
869 IoTString iValueD = new IoTString(valueD);
871 t1.startTransaction();
872 t1.addKV(iKeyA, iValueA);
873 transStatusList.add(t1.commitTransaction());
875 t2.startTransaction();
876 t2.addKV(iKeyD, iValueD);
877 transStatusList.add(t2.commitTransaction());
881 System.out.println("Updating Clients...");
887 System.out.println("Checking Key-Values...");
888 for (int i = 0; i < 4; i++) {
890 String keyA = "a" + i;
891 String keyB = "b" + i;
892 String keyC = "c" + i;
893 String keyD = "d" + i;
894 String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
895 String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
896 String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
897 String valueD = "d" + (i + NUMBER_OF_TESTS - 1);
899 IoTString iKeyA = new IoTString(keyA);
900 IoTString iKeyB = new IoTString(keyB);
901 IoTString iKeyC = new IoTString(keyC);
902 IoTString iKeyD = new IoTString(keyD);
903 IoTString iValueA = new IoTString(valueA);
904 IoTString iValueB = new IoTString(valueB);
905 IoTString iValueC = new IoTString(valueC);
906 IoTString iValueD = new IoTString(valueD);
909 IoTString testValA1 = t1.getCommitted(iKeyA);
910 IoTString testValB1 = t1.getCommitted(iKeyB);
911 IoTString testValC1 = t1.getCommitted(iKeyC);
912 IoTString testValD1 = t1.getCommitted(iKeyD);
914 IoTString testValA2 = t2.getCommitted(iKeyA);
915 IoTString testValB2 = t2.getCommitted(iKeyB);
916 IoTString testValC2 = t2.getCommitted(iKeyC);
917 IoTString testValD2 = t2.getCommitted(iKeyD);
919 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
920 System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1);
924 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
925 System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1);
929 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
930 System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1);
934 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
935 System.out.println("Key-Value t1 incorrect: " + keyD + " " + testValD1);
939 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
940 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
944 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
945 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
949 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
950 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
954 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
955 System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
960 for (TransactionStatus status : transStatusList) {
961 if (status.getStatus() != TransactionStatus.StatusCommitted) {
967 System.out.println("Found Errors...");
969 System.out.println("No Errors Found...");
973 static void test6() throws ServerException, InterruptedException {
975 boolean foundError = false;
976 List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
978 // Setup the 2 clients
979 Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
981 Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
985 System.out.println("Setting up keys");
986 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
991 IoTString ia = new IoTString(a);
992 IoTString ib = new IoTString(b);
993 IoTString ic = new IoTString(c);
994 IoTString id = new IoTString(d);
995 t1.createNewKey(ia, 321);
996 t1.createNewKey(ib, 351);
997 t2.createNewKey(ic, 321);
998 t2.createNewKey(id, 351);
1001 // Do Updates for the keys
1002 System.out.println("Setting Key-Values...");
1003 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1004 String keyA = "a" + i;
1005 String keyB = "b" + i;
1006 String keyC = "c" + i;
1007 String keyD = "d" + i;
1008 String valueA = "a" + i;
1009 String valueB = "b" + i;
1010 String valueC = "c" + i;
1011 String valueD = "d" + i;
1013 IoTString iKeyA = new IoTString(keyA);
1014 IoTString iKeyB = new IoTString(keyB);
1015 IoTString iKeyC = new IoTString(keyC);
1016 IoTString iKeyD = new IoTString(keyD);
1017 IoTString iValueA = new IoTString(valueA);
1018 IoTString iValueB = new IoTString(valueB);
1019 IoTString iValueC = new IoTString(valueC);
1020 IoTString iValueD = new IoTString(valueD);
1022 t1.startTransaction();
1023 t1.getCommittedAtomic(iKeyA);
1024 t1.addKV(iKeyA, iValueA);
1025 transStatusList.add(t1.commitTransaction());
1027 t1.startTransaction();
1028 t1.getCommittedAtomic(iKeyB);
1029 t1.addKV(iKeyB, iValueB);
1030 transStatusList.add(t1.commitTransaction());
1032 t2.startTransaction();
1033 t2.getCommittedAtomic(iKeyC);
1034 t2.addKV(iKeyC, iValueC);
1035 transStatusList.add(t2.commitTransaction());
1037 t2.startTransaction();
1038 t2.getCommittedAtomic(iKeyD);
1039 t2.addKV(iKeyD, iValueD);
1040 transStatusList.add(t2.commitTransaction());
1043 System.out.println("Updating Clients...");
1047 System.out.println("Checking Key-Values...");
1048 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1050 String keyA = "a" + i;
1051 String keyB = "b" + i;
1052 String keyC = "c" + i;
1053 String keyD = "d" + i;
1054 String valueA = "a" + i;
1055 String valueB = "b" + i;
1056 String valueC = "c" + i;
1057 String valueD = "d" + i;
1059 IoTString iKeyA = new IoTString(keyA);
1060 IoTString iKeyB = new IoTString(keyB);
1061 IoTString iKeyC = new IoTString(keyC);
1062 IoTString iKeyD = new IoTString(keyD);
1063 IoTString iValueA = new IoTString(valueA);
1064 IoTString iValueB = new IoTString(valueB);
1065 IoTString iValueC = new IoTString(valueC);
1066 IoTString iValueD = new IoTString(valueD);
1069 IoTString testValA1 = t1.getCommitted(iKeyA);
1070 IoTString testValB1 = t1.getCommitted(iKeyB);
1071 IoTString testValC1 = t1.getCommitted(iKeyC);
1072 IoTString testValD1 = t1.getCommitted(iKeyD);
1074 IoTString testValA2 = t2.getCommitted(iKeyA);
1075 IoTString testValB2 = t2.getCommitted(iKeyB);
1076 IoTString testValC2 = t2.getCommitted(iKeyC);
1077 IoTString testValD2 = t2.getCommitted(iKeyD);
1079 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1080 System.out.println("Key-Value t1 incorrect: " + keyA);
1084 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1085 System.out.println("Key-Value t1 incorrect: " + keyB);
1089 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1090 System.out.println("Key-Value t1 incorrect: " + keyC);
1094 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1095 System.out.println("Key-Value t1 incorrect: " + keyD);
1100 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1101 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
1105 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1106 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
1110 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1111 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
1115 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1116 System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
1121 for (TransactionStatus status : transStatusList) {
1122 if (status.getStatus() != TransactionStatus.StatusCommitted) {
1128 System.out.println("Found Errors...");
1130 System.out.println("No Errors Found...");
1134 static void test5() throws ServerException, InterruptedException {
1136 boolean foundError = false;
1137 List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
1139 // Setup the 2 clients
1140 Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
1142 Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
1147 System.out.println("Setting up keys");
1148 for (int i = 0; i < 4; i++) {
1153 IoTString ia = new IoTString(a);
1154 IoTString ib = new IoTString(b);
1155 IoTString ic = new IoTString(c);
1156 IoTString id = new IoTString(d);
1157 t1.createNewKey(ia, 321);
1158 t1.createNewKey(ib, 351);
1159 t2.createNewKey(ic, 321);
1160 t2.createNewKey(id, 351);
1163 // Do Updates for the keys
1164 System.out.println("Setting Key-Values...");
1166 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
1167 for (int i = 0; i < 4; i++) {
1168 String keyB = "b" + i;
1169 String valueB = "b" + (i + t);
1171 IoTString iKeyB = new IoTString(keyB);
1172 IoTString iValueB = new IoTString(valueB);
1174 t1.startTransaction();
1175 t1.addKV(iKeyB, iValueB);
1176 transStatusList.add(t1.commitTransaction());
1180 for (int i = 0; i < 4; i++) {
1182 String keyB = "b" + i;
1183 String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
1184 IoTString iKeyB = new IoTString(keyB);
1185 IoTString iValueB = new IoTString(valueB);
1187 IoTString testValB1 = t1.getSpeculative(iKeyB);
1188 IoTString testValB2 = t2.getSpeculative(iKeyB);
1190 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1191 System.out.println("Key-Value t1 incorrect: " + keyB);
1195 if ((testValB2 != null)) {
1196 System.out.println("Key-Value t2 incorrect: " + keyB);
1201 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
1202 for (int i = 0; i < 4; i++) {
1203 String keyC = "c" + i;
1204 String valueC = "c" + (i + t);
1206 IoTString iKeyC = new IoTString(keyC);
1207 IoTString iValueC = new IoTString(valueC);
1209 t2.startTransaction();
1210 t2.addKV(iKeyC, iValueC);
1211 transStatusList.add(t2.commitTransaction());
1215 for (int i = 0; i < 4; i++) {
1216 String keyC = "c" + i;
1217 String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
1218 IoTString iKeyC = new IoTString(keyC);
1219 IoTString iValueC = new IoTString(valueC);
1221 IoTString testValC1 = t1.getSpeculative(iKeyC);
1222 IoTString testValC2 = t2.getSpeculative(iKeyC);
1224 if ((testValC1 != null)) {
1225 System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1);
1229 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1230 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
1235 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
1236 for (int i = 0; i < 4; i++) {
1237 String keyA = "a" + i;
1238 String keyD = "d" + i;
1239 String valueA = "a" + (i + t);
1240 String valueD = "d" + (i + t);
1242 IoTString iKeyA = new IoTString(keyA);
1243 IoTString iKeyD = new IoTString(keyD);
1244 IoTString iValueA = new IoTString(valueA);
1245 IoTString iValueD = new IoTString(valueD);
1247 t1.startTransaction();
1248 t1.addKV(iKeyA, iValueA);
1249 transStatusList.add(t1.commitTransaction());
1251 t2.startTransaction();
1252 t2.addKV(iKeyD, iValueD);
1253 transStatusList.add(t2.commitTransaction());
1257 System.out.println("Updating Clients...");
1262 System.out.println("Checking Key-Values...");
1263 for (int i = 0; i < 4; i++) {
1265 String keyA = "a" + i;
1266 String keyB = "b" + i;
1267 String keyC = "c" + i;
1268 String keyD = "d" + i;
1269 String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
1270 String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
1271 String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
1272 String valueD = "d" + (i + NUMBER_OF_TESTS - 1);
1274 IoTString iKeyA = new IoTString(keyA);
1275 IoTString iKeyB = new IoTString(keyB);
1276 IoTString iKeyC = new IoTString(keyC);
1277 IoTString iKeyD = new IoTString(keyD);
1278 IoTString iValueA = new IoTString(valueA);
1279 IoTString iValueB = new IoTString(valueB);
1280 IoTString iValueC = new IoTString(valueC);
1281 IoTString iValueD = new IoTString(valueD);
1284 IoTString testValA1 = t1.getCommitted(iKeyA);
1285 IoTString testValB1 = t1.getCommitted(iKeyB);
1286 IoTString testValC1 = t1.getCommitted(iKeyC);
1287 IoTString testValD1 = t1.getCommitted(iKeyD);
1289 IoTString testValA2 = t2.getCommitted(iKeyA);
1290 IoTString testValB2 = t2.getCommitted(iKeyB);
1291 IoTString testValC2 = t2.getCommitted(iKeyC);
1292 IoTString testValD2 = t2.getCommitted(iKeyD);
1294 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1295 System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1);
1299 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1300 System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1);
1304 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1305 System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1);
1309 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1310 System.out.println("Key-Value t1 incorrect: " + keyD + " " + testValD1);
1315 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1316 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
1320 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1321 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
1325 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1326 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
1330 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1331 System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
1336 for (TransactionStatus status : transStatusList) {
1337 if (status.getStatus() != TransactionStatus.StatusCommitted) {
1343 System.out.println("Found Errors...");
1345 System.out.println("No Errors Found...");
1349 static void test4() throws ServerException, InterruptedException {
1351 boolean foundError = false;
1354 List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
1356 // Setup the 2 clients
1357 Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
1359 Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
1363 System.out.println("Setting up keys");
1364 startTime = System.currentTimeMillis();
1365 for (int i = 0; i < 4; i++) {
1370 IoTString ia = new IoTString(a);
1371 IoTString ib = new IoTString(b);
1372 IoTString ic = new IoTString(c);
1373 IoTString id = new IoTString(d);
1374 t1.createNewKey(ia, 321);
1375 t1.createNewKey(ib, 351);
1376 t2.createNewKey(ic, 321);
1377 t2.createNewKey(id, 351);
1379 endTime = System.currentTimeMillis();
1380 System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) );
1381 System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) );
1382 System.out.println();
1385 // Do Updates for the keys
1386 System.out.println("Setting Key-Values...");
1387 startTime = System.currentTimeMillis();
1388 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
1389 for (int i = 0; i < 4; i++) {
1390 String keyA = "a" + i;
1391 String keyB = "b" + i;
1392 String keyC = "c" + i;
1393 String keyD = "d" + i;
1394 String valueA = "a" + i;
1395 String valueB = "b" + i;
1396 String valueC = "c" + i;
1397 String valueD = "d" + i;
1399 IoTString iKeyA = new IoTString(keyA);
1400 IoTString iKeyB = new IoTString(keyB);
1401 IoTString iKeyC = new IoTString(keyC);
1402 IoTString iKeyD = new IoTString(keyD);
1403 IoTString iValueA = new IoTString(valueA);
1404 IoTString iValueB = new IoTString(valueB);
1405 IoTString iValueC = new IoTString(valueC);
1406 IoTString iValueD = new IoTString(valueD);
1408 t1.startTransaction();
1409 t1.addKV(iKeyA, iValueA);
1410 transStatusList.add(t1.commitTransaction());
1412 t1.startTransaction();
1413 t1.addKV(iKeyB, iValueB);
1414 transStatusList.add(t1.commitTransaction());
1416 t2.startTransaction();
1417 t2.addKV(iKeyC, iValueC);
1418 transStatusList.add(t2.commitTransaction());
1420 t2.startTransaction();
1421 t2.addKV(iKeyD, iValueD);
1422 transStatusList.add(t2.commitTransaction());
1425 endTime = System.currentTimeMillis();
1426 System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) );
1427 System.out.println("Time Taken Per Update: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 16)) );
1428 System.out.println();
1431 System.out.println("Updating Clients...");
1436 System.out.println("Checking Key-Values...");
1437 for (int i = 0; i < 4; i++) {
1439 String keyA = "a" + i;
1440 String keyB = "b" + i;
1441 String keyC = "c" + i;
1442 String keyD = "d" + i;
1443 String valueA = "a" + i;
1444 String valueB = "b" + i;
1445 String valueC = "c" + i;
1446 String valueD = "d" + i;
1448 IoTString iKeyA = new IoTString(keyA);
1449 IoTString iKeyB = new IoTString(keyB);
1450 IoTString iKeyC = new IoTString(keyC);
1451 IoTString iKeyD = new IoTString(keyD);
1452 IoTString iValueA = new IoTString(valueA);
1453 IoTString iValueB = new IoTString(valueB);
1454 IoTString iValueC = new IoTString(valueC);
1455 IoTString iValueD = new IoTString(valueD);
1458 IoTString testValA1 = t1.getCommitted(iKeyA);
1459 IoTString testValB1 = t1.getCommitted(iKeyB);
1460 IoTString testValC1 = t1.getCommitted(iKeyC);
1461 IoTString testValD1 = t1.getCommitted(iKeyD);
1463 IoTString testValA2 = t2.getCommitted(iKeyA);
1464 IoTString testValB2 = t2.getCommitted(iKeyB);
1465 IoTString testValC2 = t2.getCommitted(iKeyC);
1466 IoTString testValD2 = t2.getCommitted(iKeyD);
1468 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1469 System.out.println("Key-Value t1 incorrect: " + keyA);
1473 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1474 System.out.println("Key-Value t1 incorrect: " + keyB);
1478 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1479 System.out.println("Key-Value t1 incorrect: " + keyC);
1483 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1484 System.out.println("Key-Value t1 incorrect: " + keyD);
1489 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1490 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
1494 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1495 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
1499 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1500 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
1504 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1505 System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
1510 for (TransactionStatus status : transStatusList) {
1511 if (status.getStatus() != TransactionStatus.StatusCommitted) {
1517 System.out.println("Found Errors...");
1519 System.out.println("No Errors Found...");
1523 static void test3() throws ServerException, InterruptedException {
1527 boolean foundError = false;
1529 List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
1531 // Setup the 2 clients
1532 Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
1534 Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
1539 System.out.println("Setting up keys");
1540 startTime = System.currentTimeMillis();
1541 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1546 IoTString ia = new IoTString(a);
1547 IoTString ib = new IoTString(b);
1548 IoTString ic = new IoTString(c);
1549 IoTString id = new IoTString(d);
1550 t1.createNewKey(ia, 321);
1551 t1.createNewKey(ib, 351);
1552 t2.createNewKey(ic, 321);
1553 t2.createNewKey(id, 351);
1555 endTime = System.currentTimeMillis();
1556 System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) );
1557 System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) );
1558 System.out.println();
1561 // Do Updates for the keys
1562 System.out.println("Setting Key-Values...");
1563 startTime = System.currentTimeMillis();
1564 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1565 String keyB = "b" + i;
1566 String valueB = "b" + i;
1568 IoTString iKeyB = new IoTString(keyB);
1569 IoTString iValueB = new IoTString(valueB);
1571 t1.startTransaction();
1572 t1.addKV(iKeyB, iValueB);
1573 transStatusList.add(t1.commitTransaction());
1576 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1577 String keyC = "c" + i;
1578 String valueC = "c" + i;
1580 IoTString iKeyC = new IoTString(keyC);
1581 IoTString iValueC = new IoTString(valueC);
1583 t2.startTransaction();
1584 t2.addKV(iKeyC, iValueC);
1585 transStatusList.add(t2.commitTransaction());
1588 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1589 String keyA = "a" + i;
1590 String keyD = "d" + i;
1591 String valueA = "a" + i;
1592 String valueD = "d" + i;
1594 IoTString iKeyA = new IoTString(keyA);
1595 IoTString iKeyD = new IoTString(keyD);
1596 IoTString iValueA = new IoTString(valueA);
1597 IoTString iValueD = new IoTString(valueD);
1599 t1.startTransaction();
1600 t1.addKV(iKeyA, iValueA);
1601 transStatusList.add(t1.commitTransaction());
1603 t2.startTransaction();
1604 t2.addKV(iKeyD, iValueD);
1605 transStatusList.add(t2.commitTransaction());
1607 endTime = System.currentTimeMillis();
1608 System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) );
1609 System.out.println("Time Taken Per Update: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) );
1610 System.out.println();
1613 System.out.println("Updating Clients...");
1618 System.out.println("Checking Key-Values...");
1619 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1621 String keyA = "a" + i;
1622 String keyB = "b" + i;
1623 String keyC = "c" + i;
1624 String keyD = "d" + i;
1625 String valueA = "a" + i;
1626 String valueB = "b" + i;
1627 String valueC = "c" + i;
1628 String valueD = "d" + i;
1630 IoTString iKeyA = new IoTString(keyA);
1631 IoTString iKeyB = new IoTString(keyB);
1632 IoTString iKeyC = new IoTString(keyC);
1633 IoTString iKeyD = new IoTString(keyD);
1634 IoTString iValueA = new IoTString(valueA);
1635 IoTString iValueB = new IoTString(valueB);
1636 IoTString iValueC = new IoTString(valueC);
1637 IoTString iValueD = new IoTString(valueD);
1640 IoTString testValA1 = t1.getCommitted(iKeyA);
1641 IoTString testValB1 = t1.getCommitted(iKeyB);
1642 IoTString testValC1 = t1.getCommitted(iKeyC);
1643 IoTString testValD1 = t1.getCommitted(iKeyD);
1645 IoTString testValA2 = t2.getCommitted(iKeyA);
1646 IoTString testValB2 = t2.getCommitted(iKeyB);
1647 IoTString testValC2 = t2.getCommitted(iKeyC);
1648 IoTString testValD2 = t2.getCommitted(iKeyD);
1650 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1651 System.out.println("Key-Value t1 incorrect: " + keyA);
1655 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1656 System.out.println("Key-Value t1 incorrect: " + keyB);
1660 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1661 System.out.println("Key-Value t1 incorrect: " + keyC);
1665 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1666 System.out.println("Key-Value t1 incorrect: " + keyD);
1671 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1672 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
1676 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1677 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
1681 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1682 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
1686 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1687 System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
1692 for (TransactionStatus status : transStatusList) {
1693 if (status.getStatus() != TransactionStatus.StatusCommitted) {
1699 System.out.println("Found Errors...");
1701 System.out.println("No Errors Found...");
1705 static void test2() throws ServerException, InterruptedException {
1707 boolean foundError = false;
1710 List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
1712 // Setup the 2 clients
1713 Table t1 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
1715 System.out.println("T1 Ready");
1717 Table t2 = new Table("127.0.0.1", "http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
1719 System.out.println("T2 Ready");
1722 System.out.println("Setting up keys");
1723 startTime = System.currentTimeMillis();
1724 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1729 IoTString ia = new IoTString(a);
1730 IoTString ib = new IoTString(b);
1731 IoTString ic = new IoTString(c);
1732 IoTString id = new IoTString(d);
1733 t1.createNewKey(ia, 321);
1734 t1.createNewKey(ib, 351);
1735 t2.createNewKey(ic, 321);
1736 t2.createNewKey(id, 351);
1738 endTime = System.currentTimeMillis();
1739 System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) );
1740 System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) );
1741 System.out.println();
1743 // Do Updates for the keys
1744 System.out.println("Setting Key-Values...");
1745 startTime = System.currentTimeMillis();
1746 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1747 String keyA = "a" + i;
1748 String keyB = "b" + i;
1749 String keyC = "c" + i;
1750 String keyD = "d" + i;
1751 String valueA = "a" + i;
1752 String valueB = "b" + i;
1753 String valueC = "c" + i;
1754 String valueD = "d" + i;
1756 IoTString iKeyA = new IoTString(keyA);
1757 IoTString iKeyB = new IoTString(keyB);
1758 IoTString iKeyC = new IoTString(keyC);
1759 IoTString iKeyD = new IoTString(keyD);
1760 IoTString iValueA = new IoTString(valueA);
1761 IoTString iValueB = new IoTString(valueB);
1762 IoTString iValueC = new IoTString(valueC);
1763 IoTString iValueD = new IoTString(valueD);
1765 t1.startTransaction();
1766 t1.addKV(iKeyA, iValueA);
1767 transStatusList.add(t1.commitTransaction());
1769 t1.startTransaction();
1770 t1.addKV(iKeyB, iValueB);
1771 transStatusList.add(t1.commitTransaction());
1773 t2.startTransaction();
1774 t2.addKV(iKeyC, iValueC);
1775 transStatusList.add(t2.commitTransaction());
1777 t2.startTransaction();
1778 t2.addKV(iKeyD, iValueD);
1779 transStatusList.add(t2.commitTransaction());
1781 endTime = System.currentTimeMillis();
1782 System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) );
1783 System.out.println("Time Taken Per Update: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) );
1784 System.out.println();
1787 System.out.println("Updating Clients...");
1792 System.out.println("Checking Key-Values...");
1793 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
1795 String keyA = "a" + i;
1796 String keyB = "b" + i;
1797 String keyC = "c" + i;
1798 String keyD = "d" + i;
1799 String valueA = "a" + i;
1800 String valueB = "b" + i;
1801 String valueC = "c" + i;
1802 String valueD = "d" + i;
1804 IoTString iKeyA = new IoTString(keyA);
1805 IoTString iKeyB = new IoTString(keyB);
1806 IoTString iKeyC = new IoTString(keyC);
1807 IoTString iKeyD = new IoTString(keyD);
1808 IoTString iValueA = new IoTString(valueA);
1809 IoTString iValueB = new IoTString(valueB);
1810 IoTString iValueC = new IoTString(valueC);
1811 IoTString iValueD = new IoTString(valueD);
1814 IoTString testValA1 = t1.getCommitted(iKeyA);
1815 IoTString testValB1 = t1.getCommitted(iKeyB);
1816 IoTString testValC1 = t1.getCommitted(iKeyC);
1817 IoTString testValD1 = t1.getCommitted(iKeyD);
1819 IoTString testValA2 = t2.getCommitted(iKeyA);
1820 IoTString testValB2 = t2.getCommitted(iKeyB);
1821 IoTString testValC2 = t2.getCommitted(iKeyC);
1822 IoTString testValD2 = t2.getCommitted(iKeyD);
1824 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
1825 System.out.println("Key-Value t1 incorrect: " + keyA);
1829 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
1830 System.out.println("Key-Value t1 incorrect: " + keyB);
1834 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
1835 System.out.println("Key-Value t1 incorrect: " + keyC);
1839 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
1840 System.out.println("Key-Value t1 incorrect: " + keyD);
1845 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
1846 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
1850 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
1851 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
1855 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
1856 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
1860 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
1861 System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
1866 for (TransactionStatus status : transStatusList) {
1867 if (status.getStatus() != TransactionStatus.StatusCommitted) {
1873 System.out.println("Found Errors...");
1875 System.out.println("No Errors Found...");