package iotcloud;
+import java.util.List;
+import java.util.ArrayList;
+
/**
* Test cases.
* @author Brian Demsky
public class Test {
- public static final int NUMBER_OF_TESTS = 20000; //66
-
- public static void main(String[] args) {
- if (args[0].equals("2")) {
- test2();
- } else if (args[0].equals("3")) {
- test3();
- } else if (args[0].equals("4")) {
- test4();
- }
- }
-
-
-
- static void test5() {
- Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
- t1.rebuild();
- System.out.println(t1);
-
- // // Print the results
- // for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- // String a = "a" + i;
- // String b = "b" + i;
- // IoTString ia = new IoTString(a);
- // IoTString ib = new IoTString(b);
-
- // System.out.println(ib + " -> " + t1.getCommitted(ib));
- // System.out.println(ia + " -> " + t2.getCommitted(ia));
- // System.out.println();
- // }
- }
-
- static Thread buildThreadTest4(String prefix, Table t) {
- return new Thread() {
- public void run() {
- for (int i = 0; i < (NUMBER_OF_TESTS * 3); i++) {
-
- int num = i % NUMBER_OF_TESTS;
- String key = prefix + num;
- String value = prefix + (num + 2000);
- IoTString iKey = new IoTString(key);
- IoTString iValue = new IoTString(value);
-
- t.startTransaction();
- t.addKV(iKey, iValue);
- t.commitTransaction();
- }
- }
- };
- }
-
- static void test4() {
- Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
- Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
- t1.rebuild();
- t2.rebuild();
-
- Thread thr1 = buildThreadTest4("b", t1);
- Thread thr2 = buildThreadTest4("a", t2);
- thr1.start();
- thr2.start();
- try {
- thr1.join();
- thr2.join();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- t1.update();
- t2.update();
- // t1.update();
-
- // Print the results
- for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- String a = "a" + i;
- String b = "b" + i;
- IoTString ia = new IoTString(a);
- IoTString ib = new IoTString(b);
-
- System.out.println(ib + " -> " + t1.getCommitted(ib));
- System.out.println(ia + " -> " + t2.getCommitted(ia));
- System.out.println();
- }
- }
-
- static void test3() {
- Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
- Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
- t1.rebuild();
- t2.rebuild();
-
-
- for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- String key = "a" + i;
- String value = "a" + (i + 1000);
- IoTString iKey = new IoTString(key);
- IoTString iValue = new IoTString(value);
-
- t1.startTransaction();
- t1.addKV(iKey, iValue);
- t1.commitTransaction();
- }
-
- for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- String key = "b" + i;
- String value = "b" + (i + 1000);
- IoTString iKey = new IoTString(key);
- IoTString iValue = new IoTString(value);
-
- t2.startTransaction();
- t2.addKV(iKey, iValue);
- t2.commitTransaction();
- }
-
- // Make sure t1 sees the new updates from t2
- t1.update();
-
- // Print the results
- for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- String a = "a" + i;
- String b = "b" + i;
- IoTString ia = new IoTString(a);
- IoTString ib = new IoTString(b);
-
- System.out.println(ib + " -> " + t1.getCommitted(ib));
- System.out.println(ia + " -> " + t2.getCommitted(ia));
- System.out.println();
- }
- }
-
- static void test2() {
- Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
- t1.initTable();
- Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
- t2.update();
-
-
- // Make the Keys
- System.out.println("Setting up keys");
- for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- String a = "a" + i;
- String b = "b" + i;
- IoTString ia = new IoTString(a);
- IoTString ib = new IoTString(b);
- t1.createNewKey(ia, 321);
- t1.createNewKey(ib, 321);
- }
-
- // System.out.println("=========t1 live" + t1.liveslotcount + " thresh: " + t1.resizethreshold);
- // System.out.println("=========t2 live" + t2.liveslotcount + " thresh: " + t2.resizethreshold);
- // System.out.println();
-
-
-
- // Do Updates for the keys
- System.out.println("Writing Keys a...");
- for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- System.out.println(i);
-
- String key = "a" + i;
- String value = "a" + (i + 10000);
- IoTString iKey = new IoTString(key);
- IoTString iValue = new IoTString(value);
-
-
- t1.startTransaction();
- t1.addKV(iKey, iValue);
- t1.commitTransaction();
- }
-
- // Do Updates for the keys
- System.out.println("Writing Keys a...");
- for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- System.out.println(i);
-
- String key = "a" + i;
- String value = "a" + (i + 10000);
- IoTString iKey = new IoTString(key);
- IoTString iValue = new IoTString(value);
-
- t1.startTransaction();
- t1.addKV(iKey, iValue);
- t1.commitTransaction();
- }
-
-
- t2.update();
- System.out.println("Writing Keys b...");
- for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- System.out.println(i);
-
- String key = "b" + i;
- String value = "b" + (i + 10000);
- IoTString iKey = new IoTString(key);
- IoTString iValue = new IoTString(value);
-
-
- t2.startTransaction();
- t2.addKV(iKey, iValue);
- t2.commitTransaction();
- }
-
-
- // Do Updates for the keys
- System.out.println("Writing Keys a...");
- for (int i = 0; i < NUMBER_OF_TESTS; i += 2) {
- System.out.println(i);
-
- String key = "a" + i;
- String value = "a" + (i + 10000);
- IoTString iKey = new IoTString(key);
- IoTString iValue = new IoTString(value);
-
- t1.startTransaction();
- t1.addKV(iKey, iValue);
- t1.commitTransaction();
- }
-
-
- t1.update();
- t2.update();
-
- System.out.println("Checking a keys...");
- for (int i = 0; i < NUMBER_OF_TESTS; i++) {
-
- String key = "a" + i;
- String value = "a" + (i + 10000);
- IoTString iKey = new IoTString(key);
- IoTString iValue = new IoTString(value);
-
- IoTString testVal = t1.getCommitted(iKey);
-
- if ((testVal == null) || (testVal.equals(iValue) == false)) {
- System.out.println("Key val incorrect: " + key);
- }
-
- key = "b" + i;
- value = "b" + (i + 10000);
- iKey = new IoTString(key);
- iValue = new IoTString(value);
-
- testVal = t1.getCommitted(iKey);
-
- if ((testVal == null) || (testVal.equals(iValue) == false)) {
- System.out.println("Key val incorrect: " + key);
- }
- }
-
- System.out.println("Checking b keys...");
- for (int i = 0; i < NUMBER_OF_TESTS; i++) {
-
- String key = "a" + i;
- String value = "a" + (i + 10000);
- IoTString iKey = new IoTString(key);
- IoTString iValue = new IoTString(value);
-
- IoTString testVal = t2.getCommitted(iKey);
-
- if ((testVal == null) || (testVal.equals(iValue) == false)) {
- System.out.println("Key val incorrect: " + key);
- }
-
- key = "b" + i;
- value = "b" + (i + 10000);
- iKey = new IoTString(key);
- iValue = new IoTString(value);
-
- testVal = t2.getCommitted(iKey);
-
- if ((testVal == null) || (testVal.equals(iValue) == false)) {
- System.out.println("Key val incorrect: " + key);
- }
- }
-
-
-
-
- System.out.println();
- System.out.println();
- System.out.println("Update");
- // Make sure t1 sees the new updates from t2
- t1.update();
- t2.update();
- t1.update();
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
- t2.update();
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
-
-
- // System.out.println("=========t1 live" + t1.liveslotcount + " thresh: " + t1.resizethreshold + " commits: " + t1.commitedTable.size() + " uncommits: " + t1.uncommittedTransactionsList.size());
- // System.out.println("=========t2 live" + t2.liveslotcount + " thresh: " + t2.resizethreshold + " commits: " + t2.commitedTable.size() + " uncommits: " + t2.uncommittedTransactionsList.size() );
- System.out.println();
-
- t1.printSlots();
- System.out.println();
- System.out.println();
- System.out.println();
- System.out.println();
- t2.printSlots();
- System.out.println();
-
-
-
- // // Do Updates for the keys
- // System.out.println("Writing Keys a (actual)");
- // for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- // String key = "a" + i;
- // String value = "a" + i;
- // IoTString iKey = new IoTString(key);
- // IoTString iValue = new IoTString(value);
-
- // t1.startTransaction();
- // t1.addKV(iKey, iValue);
- // t1.commitTransaction();
- // }
-
- // System.out.println("=========t1 live" + t1.liveslotcount + " thresh: " + t1.resizethreshold + " commits: " + t1.commitedTable.size() + " uncommits: " + t1.uncommittedTransactionsList.size());
- // System.out.println("=========t2 live" + t2.liveslotcount + " thresh: " + t2.resizethreshold + " commits: " + t2.commitedTable.size() + " uncommits: " + t2.uncommittedTransactionsList.size());
- // System.out.println();
-
-
-
- // System.out.println("Writing Keys b (actual)");
- // for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- // String key = "b" + i;
- // String value = "b" + i;
- // IoTString iKey = new IoTString(key);
- // IoTString iValue = new IoTString(value);
-
- // t2.startTransaction();
- // t2.addKV(iKey, iValue);
- // t2.commitTransaction();
- // }
-
- // System.out.println("=========t1 live" + t1.liveslotcount + " thresh: " + t1.resizethreshold + " commits: " + t1.commitedTable.size() + " uncommits: " + t1.uncommittedTransactionsList.size() );
- // System.out.println("=========t2 live" + t2.liveslotcount + " thresh: " + t2.resizethreshold + " commits: " + t2.commitedTable.size() + " uncommits: " + t2.uncommittedTransactionsList.size() );
- // System.out.println();
-
-
- // // Do Updates for the keys
- // System.out.println("Writing Keys a (actual)");
- // for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- // String key = "a" + i;
- // String value = "a" + i;
- // IoTString iKey = new IoTString(key);
- // IoTString iValue = new IoTString(value);
-
- // t1.startTransaction();
- // t1.addKV(iKey, iValue);
- // t1.commitTransaction();
- // }
-
- // System.out.println("=========t1 live" + t1.liveslotcount + " thresh: " + t1.resizethreshold + " commits: " + t1.commitedTable.size() + " uncommits: " + t1.uncommittedTransactionsList.size());
- // System.out.println("=========t2 live" + t2.liveslotcount + " thresh: " + t2.resizethreshold + " commits: " + t2.commitedTable.size() + " uncommits: " + t2.uncommittedTransactionsList.size());
- // System.out.println();
-
-
-
- // System.out.println("Writing Keys b (actual)");
- // for (int i = 0; i < NUMBER_OF_TESTS; i++) {
- // String key = "b" + i;
- // String value = "b" + i;
- // IoTString iKey = new IoTString(key);
- // IoTString iValue = new IoTString(value);
-
- // t2.startTransaction();
- // t2.addKV(iKey, iValue);
- // t2.commitTransaction();
- // }
-
- // System.out.println("=========t1 live" + t1.liveslotcount + " thresh: " + t1.resizethreshold + " commits: " + t1.commitedTable.size() + " uncommits: " + t1.uncommittedTransactionsList.size() );
- // System.out.println("=========t2 live" + t2.liveslotcount + " thresh: " + t2.resizethreshold + " commits: " + t2.commitedTable.size() + " uncommits: " + t2.uncommittedTransactionsList.size() );
- // System.out.println();
-
- // t1.printSlots();
- // System.out.println();
- // t2.printSlots();
-
-
-
- // Make sure t1 sees the new updates from t2
- // t1.update();
-
- // // Print the results
- // for (int i = NUMBER_OF_TESTS - 10; i < NUMBER_OF_TESTS; i++) {
- // String a = "a" + i;
- // String b = "b" + i;
- // IoTString ia = new IoTString(a);
- // IoTString ib = new IoTString(b);
-
- // System.out.println(ib + " -> " + t1.getCommitted(ib));
- // System.out.println(ia + " -> " + t2.getCommitted(ia));
- // System.out.println();
- // }
- }
+ public static final int NUMBER_OF_TESTS = 25;
+
+ public static void main(String[] args) throws ServerException {
+ if (args[0].equals("2")) {
+ test2();
+ } else if (args[0].equals("3")) {
+ test3();
+ } else if (args[0].equals("4")) {
+ test4();
+ } else if (args[0].equals("5")) {
+ test5();
+ } else if (args[0].equals("6")) {
+ test6();
+ } else if (args[0].equals("7")) {
+ test7();
+ } else if (args[0].equals("8")) {
+ test8();
+ } else if (args[0].equals("9")) {
+ test9();
+ } else if (args[0].equals("10")) {
+ test10();
+ } else if (args[0].equals("11")) {
+ test11();
+ } else if (args[0].equals("12")) {
+ test12();
+ } else if (args[0].equals("13")) {
+ test13();
+ }
+
+ else if (args[0].equals("14")) {
+ test14();
+ }
+ }
+
+
+ static void test14() throws ServerException {
+ TimingSingleton timer = TimingSingleton.getInstance();
+
+ boolean foundError = false;
+ long startTime = 0;
+ long endTime = 0;
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, -1);
+ t1.initTable();
+ System.out.println("T1 Ready");
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ startTime = System.nanoTime();
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ System.out.println(i);
+ String a = "a" + i;
+ IoTString ia = new IoTString(a);
+ t1.createNewKey(ia, 321);
+ }
+ endTime = System.nanoTime();
+ long keysDt = endTime - startTime;
+ long keysNet = timer.getTime();
+
+ System.out.println("Total Key Create Time: " + keysDt / 1000000);
+ System.out.println("Total Key Create Time Network: " + keysNet / 1000000);
+ System.out.println("Total Key Create Time no Network: " + (keysDt - keysNet) / 1000000);
+ System.out.println();
+ }
+
+
+ static void test13() throws ServerException {
+ TimingSingleton timer = TimingSingleton.getInstance();
+
+ boolean foundError = false;
+ long startTime = 0;
+ long endTime = 0;
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, -1);
+ t1.initTable();
+ System.out.println("T1 Ready");
+
+ Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, -1);
+ t2.update();
+ System.out.println("T2 Ready");
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ startTime = System.nanoTime();
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ System.out.println(i);
+ String a = "a" + i;
+ String b = "b" + i;
+ String c = "c" + i;
+ String d = "d" + i;
+ IoTString ia = new IoTString(a);
+ IoTString ib = new IoTString(b);
+ IoTString ic = new IoTString(c);
+ IoTString id = new IoTString(d);
+ t1.createNewKey(ia, 351);
+ t1.createNewKey(ib, 351);
+ t2.createNewKey(ic, 321);
+ t2.createNewKey(id, 321);
+ }
+ endTime = System.nanoTime();
+ long keysDt = endTime - startTime;
+ long keysNet = timer.getTime();
+
+ // Do Updates for the keys
+ System.out.println("Setting Key-Values...");
+ startTime = System.nanoTime();
+ for (int t = 0; t < 3; t++) {
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ System.out.println(i);
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueB = "b" + i;
+ String valueC = "c" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ t1.startTransaction();
+ t1.addKV(iKeyA, iValueA);
+ transStatusList.add(t1.commitTransaction());
+
+ t1.startTransaction();
+ t1.addKV(iKeyB, iValueB);
+ transStatusList.add(t1.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyC, iValueC);
+ transStatusList.add(t2.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyD, iValueD);
+ transStatusList.add(t2.commitTransaction());
+
+ }
+ }
+ endTime = System.nanoTime();
+ long writesDt = endTime - startTime;
+ long writesNet = timer.getTime() - keysNet;
+
+ System.out.println("Updating Clients...");
+ startTime = System.nanoTime();
+ t1.update();
+ t2.update();
+ endTime = System.nanoTime();
+ long updatesDt = endTime - startTime;
+ long updatesNet = timer.getTime() - keysNet - writesNet;
+
+
+ System.out.println("Total Key Create Time: " + keysDt / 1000000);
+ System.out.println("Total Key Create Time Network: " + keysNet / 1000000);
+ System.out.println("Total Key Create Time no Network: " + (keysDt - keysNet) / 1000000);
+ System.out.println();
+ System.out.println("Total write Time: " + writesDt / 1000000);
+ System.out.println("Total write Time Network: " + writesNet / 1000000);
+ System.out.println("Total write Time no Network: " + (writesDt - writesNet) / 1000000);
+ System.out.println();
+ System.out.println("Total updates Time: " + updatesDt / 1000000);
+ System.out.println("Total updates Time Network: " + updatesNet / 1000000);
+ System.out.println("Total updates Time no Network: " + (updatesDt - updatesNet) / 1000000);
+ }
+
+
+ static void test12() throws ServerException {
+ TimingSingleton timer = TimingSingleton.getInstance();
+
+ boolean foundError = false;
+ long startTime = 0;
+ long endTime = 0;
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, -1);
+ t1.initTable();
+ System.out.println("T1 Ready");
+
+ Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, -1);
+ t2.update();
+ System.out.println("T2 Ready");
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ startTime = System.nanoTime();
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ System.out.println(i);
+ String a = "a" + i;
+ String b = "b" + i;
+ String c = "c" + i;
+ String d = "d" + i;
+ IoTString ia = new IoTString(a);
+ IoTString ib = new IoTString(b);
+ IoTString ic = new IoTString(c);
+ IoTString id = new IoTString(d);
+ t1.createNewKey(ia, 321);
+ t1.createNewKey(ib, 321);
+ t2.createNewKey(ic, 351);
+ t2.createNewKey(id, 351);
+ }
+ endTime = System.nanoTime();
+ long keysDt = endTime - startTime;
+ long keysNet = timer.getTime();
+
+ // Do Updates for the keys
+ System.out.println("Setting Key-Values...");
+ startTime = System.nanoTime();
+ for (int t = 0; t < 3; t++) {
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ System.out.println(i);
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueB = "b" + i;
+ String valueC = "c" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ t1.startTransaction();
+ t1.addKV(iKeyA, iValueA);
+ transStatusList.add(t1.commitTransaction());
+
+ t1.startTransaction();
+ t1.addKV(iKeyB, iValueB);
+ transStatusList.add(t1.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyC, iValueC);
+ transStatusList.add(t2.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyD, iValueD);
+ transStatusList.add(t2.commitTransaction());
+
+ }
+ }
+ endTime = System.nanoTime();
+ long writesDt = endTime - startTime;
+ long writesNet = timer.getTime() - keysNet;
+
+ System.out.println("Updating Clients...");
+ startTime = System.nanoTime();
+ t1.update();
+ t2.update();
+ endTime = System.nanoTime();
+ long updatesDt = endTime - startTime;
+ long updatesNet = timer.getTime() - keysNet - writesNet;
+
+
+ System.out.println("Total Key Create Time: " + keysDt / 1000000);
+ System.out.println("Total Key Create Time Network: " + keysNet / 1000000);
+ System.out.println("Total Key Create Time no Network: " + (keysDt - keysNet) / 1000000);
+ System.out.println();
+ System.out.println("Total write Time: " + writesDt / 1000000);
+ System.out.println("Total write Time Network: " + writesNet / 1000000);
+ System.out.println("Total write Time no Network: " + (writesDt - writesNet) / 1000000);
+ System.out.println();
+ System.out.println("Total updates Time: " + updatesDt / 1000000);
+ System.out.println("Total updates Time Network: " + updatesNet / 1000000);
+ System.out.println("Total updates Time no Network: " + (updatesDt - updatesNet) / 1000000);
+ }
+
+
+ static void test11() {
+
+ boolean foundError = false;
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, 6000);
+
+ System.out.println("Init Table t1s");
+
+ while (true) {
+ try {
+ t1.initTable();
+ break;
+ } catch (Exception e) { }
+ }
+
+
+ System.out.println("Update Table t2");
+ Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, 6001);
+ while (t2.update() == false) {}
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ System.out.println(i);
+
+ String a = "a" + i;
+ String b = "b" + i;
+ String c = "c" + i;
+ String d = "d" + i;
+ IoTString ia = new IoTString(a);
+ IoTString ib = new IoTString(b);
+ IoTString ic = new IoTString(c);
+ IoTString id = new IoTString(d);
+
+ while (true) {
+ try {
+ t1.createNewKey(ia, 321);
+ break;
+ } catch (Exception e) { }
+ }
+
+ while (true) {
+ try {
+ t1.createNewKey(ib, 351);
+ break;
+ } catch (Exception e) { }
+ }
+
+ while (true) {
+ try {
+ t2.createNewKey(ic, 321);
+ break;
+ } catch (Exception e) { }
+ }
+
+ while (true) {
+ try {
+ t2.createNewKey(id, 351);
+ break;
+ } catch (Exception e) { }
+ }
+ }
+
+ // Do Updates for the keys
+ System.out.println("Setting Key-Values...");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ System.out.println(i);
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueB = "b" + i;
+ String valueC = "c" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ String keyAPrev = "a" + (i - 1);
+ String keyBPrev = "b" + (i - 1);
+ String keyCPrev = "c" + (i - 1);
+ String keyDPrev = "d" + (i - 1);
+ String valueAPrev = "a" + (i - 1);
+ String valueBPrev = "b" + (i - 1);
+ String valueCPrev = "c" + (i - 1);
+ String valueDPrev = "d" + (i - 1);
+
+ IoTString iKeyAPrev = new IoTString(keyAPrev);
+ IoTString iKeyBPrev = new IoTString(keyBPrev);
+ IoTString iKeyCPrev = new IoTString(keyCPrev);
+ IoTString iKeyDPrev = new IoTString(keyDPrev);
+ IoTString iValueAPrev = new IoTString(valueAPrev);
+ IoTString iValueBPrev = new IoTString(valueBPrev);
+ IoTString iValueCPrev = new IoTString(valueCPrev);
+ IoTString iValueDPrev = new IoTString(valueDPrev);
+
+
+ System.out.println("t1 A");
+ t1.startTransaction();
+ t1.addKV(iKeyA, iValueA);
+ transStatusList.add(t1.commitTransaction());
+
+ System.out.println("t1 B");
+ t1.startTransaction();
+ t1.addKV(iKeyB, iValueB);
+ transStatusList.add(t1.commitTransaction());
+
+ System.out.println("t2 C");
+ t2.startTransaction();
+ t2.addKV(iKeyC, iValueC);
+ transStatusList.add(t2.commitTransaction());
+
+ System.out.println("t2 D");
+ t2.startTransaction();
+ t2.addKV(iKeyD, iValueD);
+ transStatusList.add(t2.commitTransaction());
+ }
+
+ System.out.println("Updating...");
+ while (t1.update() == false) {}
+ while (t2.update() == false) {}
+ while (t1.update() == false) {}
+ while (t2.update() == false) {}
+
+ System.out.println("Checking Key-Values...");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueB = "b" + i;
+ String valueC = "c" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ IoTString testValA1 = t1.getCommitted(iKeyA);
+ IoTString testValB1 = t1.getCommitted(iKeyB);
+ IoTString testValC1 = t1.getCommitted(iKeyC);
+ IoTString testValD1 = t1.getCommitted(iKeyD);
+
+ IoTString testValA2 = t2.getCommitted(iKeyA);
+ IoTString testValB2 = t2.getCommitted(iKeyB);
+ IoTString testValC2 = t2.getCommitted(iKeyC);
+ IoTString testValD2 = t2.getCommitted(iKeyD);
+
+ if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1);
+ foundError = true;
+ }
+
+ if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1);
+ foundError = true;
+ }
+
+ if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1);
+ foundError = true;
+ }
+
+ if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyD + " " + testValD1);
+ foundError = true;
+ }
+
+
+ if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
+ foundError = true;
+ }
+
+ if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
+ foundError = true;
+ }
+
+ if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
+ foundError = true;
+ }
+
+ if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
+ foundError = true;
+ }
+ }
+
+ for (TransactionStatus status : transStatusList) {
+ if (status.getStatus() != TransactionStatus.StatusCommitted) {
+ foundError = true;
+ }
+ }
+
+ if (foundError) {
+ System.out.println("Found Errors...");
+ } else {
+ System.out.println("No Errors Found...");
+ }
+
+ t1.close();
+ t2.close();
+ }
+
+ static void test10() {
+
+ boolean foundError = false;
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, 6000);
+ System.out.println("Init Table t1s");
+ while (true) {
+ try {
+ t1.initTable();
+ break;
+ } catch (Exception e) { }
+ }
+ Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, 6001);
+ while (t2.update() == false) {}
+
+ t1.addLocalCommunication(351, "127.0.0.1", 6001);
+ t2.addLocalCommunication(321, "127.0.0.1", 6000);
+
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ for (int i = 0; i < 4; i++) {
+ String a = "a" + i;
+ String b = "b" + i;
+ String c = "c" + i;
+ String d = "d" + i;
+ IoTString ia = new IoTString(a);
+ IoTString ib = new IoTString(b);
+ IoTString ic = new IoTString(c);
+ IoTString id = new IoTString(d);
+ while (true) {
+ try {
+ t1.createNewKey(ia, 321);
+ break;
+ } catch (Exception e) { }
+ }
+
+ while (true) {
+ try {
+ t1.createNewKey(ib, 351);
+ break;
+ } catch (Exception e) { }
+ }
+
+ while (true) {
+ try {
+ t2.createNewKey(ic, 321);
+ break;
+ } catch (Exception e) { }
+ }
+
+ while (true) {
+ try {
+ t2.createNewKey(id, 351);
+ break;
+ } catch (Exception e) { }
+ }
+ }
+
+
+ // Do Updates for the keys
+ System.out.println("B========================");
+ for (int t = 0; t < NUMBER_OF_TESTS; t++) {
+ for (int i = 0; i < 4; i++) {
+
+ System.out.println(i);
+
+ String keyB = "b" + i;
+ String valueB = "b" + (i + t);
+
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iValueB = new IoTString(valueB);
+
+ t1.startTransaction();
+ System.out.println(t1.getSpeculativeAtomic(iKeyB));
+ t1.addKV(iKeyB, iValueB);
+ transStatusList.add(t1.commitTransaction());
+ }
+ }
+ System.out.println();
+
+
+ System.out.println("C========================");
+ for (int t = 0; t < NUMBER_OF_TESTS; t++) {
+ for (int i = 0; i < 4; i++) {
+ System.out.println(i);
+
+ String keyC = "c" + i;
+ String valueC = "c" + (i + t);
+
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iValueC = new IoTString(valueC);
+
+ t2.startTransaction();
+ System.out.println(t2.getSpeculativeAtomic(iKeyC));
+ t2.addKV(iKeyC, iValueC);
+ transStatusList.add(t2.commitTransaction());
+ }
+ }
+ System.out.println();
+
+
+ for (int t = 0; t < NUMBER_OF_TESTS; t++) {
+ for (int i = 0; i < 4; i++) {
+ String keyA = "a" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + (i + t);
+ String valueD = "d" + (i + t);
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ t1.startTransaction();
+ t1.addKV(iKeyA, iValueA);
+ transStatusList.add(t1.commitTransaction());
+
+
+ t2.startTransaction();
+ t2.addKV(iKeyD, iValueD);
+ transStatusList.add(t2.commitTransaction());
+ System.out.println();
+ }
+ }
+ System.out.println();
+
+ System.out.println("Updating...");
+ System.out.println("t1 -=-=-=-=-=-=-=-");
+ while (t1.update() == false) {}
+ System.out.println("t2 -=-=-=-=-=-=-=-");
+ while (t2.update() == false) {}
+ System.out.println("t1 -=-=-=-=-=-=-=-");
+ while (t1.update() == false) {}
+ System.out.println("t2 -=-=-=-=-=-=-=-");
+ while (t2.update() == false) {}
+
+
+ System.out.println("Checking Key-Values...");
+ for (int i = 0; i < 4; i++) {
+
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
+ String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
+ String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
+ String valueD = "d" + (i + NUMBER_OF_TESTS - 1);
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ IoTString testValA1 = t1.getCommitted(iKeyA);
+ IoTString testValB1 = t1.getCommitted(iKeyB);
+ IoTString testValC1 = t1.getCommitted(iKeyC);
+ IoTString testValD1 = t1.getCommitted(iKeyD);
+
+ IoTString testValA2 = t2.getCommitted(iKeyA);
+ IoTString testValB2 = t2.getCommitted(iKeyB);
+ IoTString testValC2 = t2.getCommitted(iKeyC);
+ IoTString testValD2 = t2.getCommitted(iKeyD);
+
+ if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1);
+ foundError = true;
+ }
+
+ if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1);
+ foundError = true;
+ }
+
+ if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1);
+ foundError = true;
+ }
+
+ if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyD + " " + testValD1);
+ foundError = true;
+ }
+
+ if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
+ foundError = true;
+ }
+
+ if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
+ foundError = true;
+ }
+
+ if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
+ foundError = true;
+ }
+
+ if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
+ foundError = true;
+ }
+ }
+
+ int counter = 0;
+ for (TransactionStatus status : transStatusList) {
+ if (status.getStatus() != TransactionStatus.StatusCommitted) {
+ foundError = true;
+ System.out.println(counter + " Status: " + status.getStatus());
+ }
+ counter++;
+ }
+
+ if (foundError) {
+ System.out.println("Found Errors...");
+ } else {
+ System.out.println("No Errors Found...");
+ }
+
+ t1.close();
+ t2.close();
+ }
+
+ static void test9() {
+
+ boolean foundError = false;
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, 6000);
+
+ System.out.println("Init Table t1s");
+ while (true) {
+ try {
+ t1.initTable();
+ break;
+ } catch (Exception e) { }
+ }
+
+
+ System.out.println("Update Table t2");
+ Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, 6001);
+ while (t2.update() == false) {}
+
+ t1.addLocalCommunication(351, "127.0.0.1", 6001);
+ t2.addLocalCommunication(321, "127.0.0.1", 6000);
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ System.out.println(i);
+
+ String a = "a" + i;
+ String b = "b" + i;
+ String c = "c" + i;
+ String d = "d" + i;
+ IoTString ia = new IoTString(a);
+ IoTString ib = new IoTString(b);
+ IoTString ic = new IoTString(c);
+ IoTString id = new IoTString(d);
+
+ while (true) {
+ try {
+ t1.createNewKey(ia, 321);
+ break;
+ } catch (Exception e) { }
+ }
+
+ while (true) {
+ try {
+ t1.createNewKey(ib, 351);
+ break;
+ } catch (Exception e) { }
+ }
+
+ while (true) {
+ try {
+ t2.createNewKey(ic, 321);
+ break;
+ } catch (Exception e) { }
+ }
+
+ while (true) {
+ try {
+ t2.createNewKey(id, 351);
+ break;
+ } catch (Exception e) { }
+ }
+ }
+
+ System.out.println("A, D...");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ String keyA = "a" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueD = new IoTString(valueD);
+
+ t1.startTransaction();
+ t1.addKV(iKeyA, iValueA);
+ transStatusList.add(t1.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyD, iValueD);
+ transStatusList.add(t2.commitTransaction());
+ }
+
+ // while (t1.updateFromLocal(351) == false) {}
+ // while (t2.updateFromLocal(321) == false) {}
+
+
+ System.out.println("Updating...");
+ System.out.println("Checking Key-Values...");
+
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+
+ String keyA = "a" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueD = "d" + i;
+
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ IoTString testValA1 = t1.getCommitted(iKeyA);
+ IoTString testValD1 = t1.getCommitted(iKeyD);
+ IoTString testValA2 = t2.getCommitted(iKeyA);
+ IoTString testValD2 = t2.getCommitted(iKeyD);
+
+
+ if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1);
+ foundError = true;
+ }
+
+ if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyD + " " + testValD1);
+ foundError = true;
+ }
+
+
+ if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
+ foundError = true;
+ }
+
+ if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
+ foundError = true;
+ }
+ }
+
+ for (TransactionStatus status : transStatusList) {
+ if (status.getStatus() != TransactionStatus.StatusCommitted) {
+ foundError = true;
+ }
+ }
+
+ if (foundError) {
+ System.out.println("Found Errors...");
+ } else {
+ System.out.println("No Errors Found...");
+ }
+
+ t1.close();
+ t2.close();
+ }
+
+ static void test8() {
+ TimingSingleton timer = TimingSingleton.getInstance();
+ long startTime = 0;
+ long endTime = 0;
+
+ boolean foundError = false;
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, 6000);
+
+ System.out.println("Init Table t1s");
+
+ while (true) {
+ try {
+ t1.initTable();
+ break;
+ } catch (Exception e) { }
+ }
+
+
+ System.out.println("Update Table t2");
+ Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, 6001);
+ while (t2.update() == false) {}
+
+ t1.addLocalCommunication(351, "127.0.0.1", 6001);
+ t2.addLocalCommunication(321, "127.0.0.1", 6000);
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ startTime = System.nanoTime();
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ System.out.println(i);
+
+ String a = "a" + i;
+ String b = "b" + i;
+ String c = "c" + i;
+ String d = "d" + i;
+ IoTString ia = new IoTString(a);
+ IoTString ib = new IoTString(b);
+ IoTString ic = new IoTString(c);
+ IoTString id = new IoTString(d);
+
+ while (true) {
+ try {
+ t1.createNewKey(ia, 321);
+ break;
+ } catch (Exception e) { }
+ }
+
+ while (true) {
+ try {
+ t1.createNewKey(ib, 351);
+ break;
+ } catch (Exception e) { }
+ }
+
+ while (true) {
+ try {
+ t2.createNewKey(ic, 321);
+ break;
+ } catch (Exception e) { }
+ }
+
+ while (true) {
+ try {
+ t2.createNewKey(id, 351);
+ break;
+ } catch (Exception e) { }
+ }
+ }
+ endTime = System.nanoTime();
+ long keysDt = endTime - startTime;
+ long keysNet = timer.getTime();
+
+
+ // Do Updates for the keys
+ startTime = System.nanoTime();
+ System.out.println("Setting Key-Values...");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ System.out.println(i);
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueB = "b" + i;
+ String valueC = "c" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ String keyAPrev = "a" + (i - 1);
+ String keyBPrev = "b" + (i - 1);
+ String keyCPrev = "c" + (i - 1);
+ String keyDPrev = "d" + (i - 1);
+ String valueAPrev = "a" + (i - 1);
+ String valueBPrev = "b" + (i - 1);
+ String valueCPrev = "c" + (i - 1);
+ String valueDPrev = "d" + (i - 1);
+
+ IoTString iKeyAPrev = new IoTString(keyAPrev);
+ IoTString iKeyBPrev = new IoTString(keyBPrev);
+ IoTString iKeyCPrev = new IoTString(keyCPrev);
+ IoTString iKeyDPrev = new IoTString(keyDPrev);
+ IoTString iValueAPrev = new IoTString(valueAPrev);
+ IoTString iValueBPrev = new IoTString(valueBPrev);
+ IoTString iValueCPrev = new IoTString(valueCPrev);
+ IoTString iValueDPrev = new IoTString(valueDPrev);
+
+ t1.startTransaction();
+ t1.addKV(iKeyA, iValueA);
+ transStatusList.add(t1.commitTransaction());
+
+ t1.startTransaction();
+ t1.addKV(iKeyB, iValueB);
+ transStatusList.add(t1.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyC, iValueC);
+ transStatusList.add(t2.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyD, iValueD);
+ transStatusList.add(t2.commitTransaction());
+ }
+ endTime = System.nanoTime();
+ long writesDt = endTime - startTime;
+ long writesNet = timer.getTime() - keysNet;
+
+
+
+ System.out.println("Updating...");
+ startTime = System.nanoTime();
+ while (t1.update() == false) {}
+ while (t2.update() == false) {}
+ while (t1.update() == false) {}
+ while (t2.update() == false) {}
+ endTime = System.nanoTime();
+ long updatesDt = endTime - startTime;
+ long updatesNet = timer.getTime() - keysNet - writesNet;
+
+
+ System.out.println("Total Key Create Time: " + keysDt / 1000000);
+ System.out.println("Total Key Create Time Network: " + keysNet / 1000000);
+ System.out.println("Total Key Create Time no Network: " + (keysDt - keysNet) / 1000000);
+ System.out.println();
+ System.out.println("Total write Time: " + writesDt / 1000000);
+ System.out.println("Total write Time Network: " + writesNet / 1000000);
+ System.out.println("Total write Time no Network: " + (writesDt - writesNet) / 1000000);
+ System.out.println();
+ System.out.println("Total updates Time: " + updatesDt / 1000000);
+ System.out.println("Total updates Time Network: " + updatesNet / 1000000);
+ System.out.println("Total updates Time no Network: " + (updatesDt - updatesNet) / 1000000);
+
+
+
+
+ // System.out.println("Checking Key-Values...");
+ // for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+
+ // String keyA = "a" + i;
+ // String keyB = "b" + i;
+ // String keyC = "c" + i;
+ // String keyD = "d" + i;
+ // String valueA = "a" + i;
+ // String valueB = "b" + i;
+ // String valueC = "c" + i;
+ // String valueD = "d" + i;
+
+ // IoTString iKeyA = new IoTString(keyA);
+ // IoTString iKeyB = new IoTString(keyB);
+ // IoTString iKeyC = new IoTString(keyC);
+ // IoTString iKeyD = new IoTString(keyD);
+ // IoTString iValueA = new IoTString(valueA);
+ // IoTString iValueB = new IoTString(valueB);
+ // IoTString iValueC = new IoTString(valueC);
+ // IoTString iValueD = new IoTString(valueD);
+
+
+ // IoTString testValA1 = t1.getCommitted(iKeyA);
+ // IoTString testValB1 = t1.getCommitted(iKeyB);
+ // IoTString testValC1 = t1.getCommitted(iKeyC);
+ // IoTString testValD1 = t1.getCommitted(iKeyD);
+
+ // IoTString testValA2 = t2.getCommitted(iKeyA);
+ // IoTString testValB2 = t2.getCommitted(iKeyB);
+ // IoTString testValC2 = t2.getCommitted(iKeyC);
+ // IoTString testValD2 = t2.getCommitted(iKeyD);
+
+ // if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
+ // System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1);
+ // foundError = true;
+ // }
+
+ // if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
+ // System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1);
+ // foundError = true;
+ // }
+
+ // if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
+ // System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1);
+ // foundError = true;
+ // }
+
+ // if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
+ // System.out.println("Key-Value t1 incorrect: " + keyD + " " + testValD1);
+ // foundError = true;
+ // }
+
+
+ // if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
+ // System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
+ // foundError = true;
+ // }
+
+ // if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
+ // System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
+ // foundError = true;
+ // }
+
+ // if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
+ // System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
+ // foundError = true;
+ // }
+
+ // if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
+ // System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
+ // foundError = true;
+ // }
+ // }
+
+ // for (TransactionStatus status : transStatusList) {
+ // if (status.getStatus() != TransactionStatus.StatusCommitted) {
+ // foundError = true;
+ // }
+ // }
+
+ // if (foundError) {
+ // System.out.println("Found Errors...");
+ // } else {
+ // System.out.println("No Errors Found...");
+ // }
+
+ t1.close();
+ t2.close();
+
+ // System.out.println();
+ // System.out.println();
+ // t1.printSlots();
+
+ // System.out.println();
+ // System.out.println();
+ // t2.printSlots();
+ }
+
+ static void test7() throws ServerException {
+
+ boolean foundError = false;
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, -1);
+ t1.initTable();
+ Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, -1);
+ t2.update();
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ for (int i = 0; i < 4; i++) {
+ String a = "a" + i;
+ String b = "b" + i;
+ String c = "c" + i;
+ String d = "d" + i;
+ IoTString ia = new IoTString(a);
+ IoTString ib = new IoTString(b);
+ IoTString ic = new IoTString(c);
+ IoTString id = new IoTString(d);
+ t1.createNewKey(ia, 321);
+ t1.createNewKey(ib, 351);
+ t2.createNewKey(ic, 321);
+ t2.createNewKey(id, 351);
+ }
+
+ // Do Updates for the keys
+ System.out.println("Setting Key-Values...");
+
+ for (int t = 0; t < NUMBER_OF_TESTS; t++) {
+ for (int i = 0; i < 4; i++) {
+ String keyB = "b" + i;
+ String valueB = "b" + (i + t);
+
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iValueB = new IoTString(valueB);
+
+ t1.startTransaction();
+ t1.getSpeculativeAtomic(iKeyB);
+ t1.addKV(iKeyB, iValueB);
+ transStatusList.add(t1.commitTransaction());
+ }
+ }
+
+ for (int i = 0; i < 4; i++) {
+
+ String keyB = "b" + i;
+ String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iValueB = new IoTString(valueB);
+
+ IoTString testValB1 = t1.getSpeculative(iKeyB);
+ IoTString testValB2 = t2.getSpeculative(iKeyB);
+
+ if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1);
+ foundError = true;
+ }
+
+ if ((testValB2 != null)) {
+ System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
+ foundError = true;
+ }
+ }
+
+ for (int t = 0; t < NUMBER_OF_TESTS; t++) {
+ for (int i = 0; i < 4; i++) {
+ String keyC = "c" + i;
+ String valueC = "c" + (i + t);
+
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iValueC = new IoTString(valueC);
+
+ t2.startTransaction();
+ t2.getSpeculativeAtomic(iKeyC);
+ t2.addKV(iKeyC, iValueC);
+ transStatusList.add(t2.commitTransaction());
+ }
+ }
+
+ for (int i = 0; i < 4; i++) {
+ String keyC = "c" + i;
+ String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iValueC = new IoTString(valueC);
+
+ IoTString testValC1 = t1.getSpeculative(iKeyC);
+ IoTString testValC2 = t2.getSpeculative(iKeyC);
+
+ if ((testValC1 != null)) {
+ System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1);
+ foundError = true;
+ }
+
+ if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
+ foundError = true;
+ }
+ }
+
+ for (int t = 0; t < NUMBER_OF_TESTS; t++) {
+ for (int i = 0; i < 4; i++) {
+ String keyA = "a" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + (i + t);
+ String valueD = "d" + (i + t);
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueD = new IoTString(valueD);
+
+ t1.startTransaction();
+ t1.addKV(iKeyA, iValueA);
+ transStatusList.add(t1.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyD, iValueD);
+ transStatusList.add(t2.commitTransaction());
+ }
+ }
+
+ System.out.println("Updating Clients...");
+ t1.update();
+ t2.update();
+ t1.update();
+ t2.update();
+
+ System.out.println("Checking Key-Values...");
+ for (int i = 0; i < 4; i++) {
+
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
+ String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
+ String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
+ String valueD = "d" + (i + NUMBER_OF_TESTS - 1);
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ IoTString testValA1 = t1.getCommitted(iKeyA);
+ IoTString testValB1 = t1.getCommitted(iKeyB);
+ IoTString testValC1 = t1.getCommitted(iKeyC);
+ IoTString testValD1 = t1.getCommitted(iKeyD);
+
+ IoTString testValA2 = t2.getCommitted(iKeyA);
+ IoTString testValB2 = t2.getCommitted(iKeyB);
+ IoTString testValC2 = t2.getCommitted(iKeyC);
+ IoTString testValD2 = t2.getCommitted(iKeyD);
+
+ if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1);
+ foundError = true;
+ }
+
+ if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1);
+ foundError = true;
+ }
+
+ if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1);
+ foundError = true;
+ }
+
+ if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyD + " " + testValD1);
+ foundError = true;
+ }
+
+ if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
+ foundError = true;
+ }
+
+ if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
+ foundError = true;
+ }
+
+ if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
+ foundError = true;
+ }
+
+ if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
+ foundError = true;
+ }
+ }
+
+ for (TransactionStatus status : transStatusList) {
+ if (status.getStatus() != TransactionStatus.StatusCommitted) {
+ foundError = true;
+ }
+ }
+
+ if (foundError) {
+ System.out.println("Found Errors...");
+ } else {
+ System.out.println("No Errors Found...");
+ }
+ }
+
+ static void test6() throws ServerException {
+
+ boolean foundError = false;
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, -1);
+ t1.initTable();
+ Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, -1);
+ t2.update();
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ String a = "a" + i;
+ String b = "b" + i;
+ String c = "c" + i;
+ String d = "d" + i;
+ IoTString ia = new IoTString(a);
+ IoTString ib = new IoTString(b);
+ IoTString ic = new IoTString(c);
+ IoTString id = new IoTString(d);
+ t1.createNewKey(ia, 321);
+ t1.createNewKey(ib, 351);
+ t2.createNewKey(ic, 321);
+ t2.createNewKey(id, 351);
+ }
+
+ // Do Updates for the keys
+ System.out.println("Setting Key-Values...");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueB = "b" + i;
+ String valueC = "c" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+ t1.startTransaction();
+ t1.getCommittedAtomic(iKeyA);
+ t1.addKV(iKeyA, iValueA);
+ transStatusList.add(t1.commitTransaction());
+
+ t1.startTransaction();
+ t1.getCommittedAtomic(iKeyB);
+ t1.addKV(iKeyB, iValueB);
+ transStatusList.add(t1.commitTransaction());
+
+ t2.startTransaction();
+ t2.getCommittedAtomic(iKeyC);
+ t2.addKV(iKeyC, iValueC);
+ transStatusList.add(t2.commitTransaction());
+
+ t2.startTransaction();
+ t2.getCommittedAtomic(iKeyD);
+ t2.addKV(iKeyD, iValueD);
+ transStatusList.add(t2.commitTransaction());
+ }
+
+ System.out.println("Updating Clients...");
+ t1.update();
+ t2.update();
+
+ System.out.println("Checking Key-Values...");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueB = "b" + i;
+ String valueC = "c" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ IoTString testValA1 = t1.getCommitted(iKeyA);
+ IoTString testValB1 = t1.getCommitted(iKeyB);
+ IoTString testValC1 = t1.getCommitted(iKeyC);
+ IoTString testValD1 = t1.getCommitted(iKeyD);
+
+ IoTString testValA2 = t2.getCommitted(iKeyA);
+ IoTString testValB2 = t2.getCommitted(iKeyB);
+ IoTString testValC2 = t2.getCommitted(iKeyC);
+ IoTString testValD2 = t2.getCommitted(iKeyD);
+
+ if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyA);
+ foundError = true;
+ }
+
+ if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyB);
+ foundError = true;
+ }
+
+ if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyC);
+ foundError = true;
+ }
+
+ if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyD);
+ foundError = true;
+ }
+
+
+ if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
+ foundError = true;
+ }
+
+ if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
+ foundError = true;
+ }
+
+ if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
+ foundError = true;
+ }
+
+ if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
+ foundError = true;
+ }
+ }
+
+ for (TransactionStatus status : transStatusList) {
+ if (status.getStatus() != TransactionStatus.StatusCommitted) {
+ foundError = true;
+ }
+ }
+
+ if (foundError) {
+ System.out.println("Found Errors...");
+ } else {
+ System.out.println("No Errors Found...");
+ }
+ }
+
+ static void test5() throws ServerException {
+
+ boolean foundError = false;
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, -1);
+ t1.initTable();
+ Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, -1);
+ t2.update();
+
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ for (int i = 0; i < 4; i++) {
+ String a = "a" + i;
+ String b = "b" + i;
+ String c = "c" + i;
+ String d = "d" + i;
+ IoTString ia = new IoTString(a);
+ IoTString ib = new IoTString(b);
+ IoTString ic = new IoTString(c);
+ IoTString id = new IoTString(d);
+ t1.createNewKey(ia, 321);
+ t1.createNewKey(ib, 351);
+ t2.createNewKey(ic, 321);
+ t2.createNewKey(id, 351);
+ }
+
+ // Do Updates for the keys
+ System.out.println("Setting Key-Values...");
+
+ for (int t = 0; t < NUMBER_OF_TESTS; t++) {
+ for (int i = 0; i < 4; i++) {
+ String keyB = "b" + i;
+ String valueB = "b" + (i + t);
+
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iValueB = new IoTString(valueB);
+
+ t1.startTransaction();
+ t1.addKV(iKeyB, iValueB);
+ transStatusList.add(t1.commitTransaction());
+ }
+ }
+
+ for (int i = 0; i < 4; i++) {
+
+ String keyB = "b" + i;
+ String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iValueB = new IoTString(valueB);
+
+ IoTString testValB1 = t1.getSpeculative(iKeyB);
+ IoTString testValB2 = t2.getSpeculative(iKeyB);
+
+ if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyB);
+ foundError = true;
+ }
+
+ if ((testValB2 != null)) {
+ System.out.println("Key-Value t2 incorrect: " + keyB);
+ foundError = true;
+ }
+ }
+
+ for (int t = 0; t < NUMBER_OF_TESTS; t++) {
+ for (int i = 0; i < 4; i++) {
+ String keyC = "c" + i;
+ String valueC = "c" + (i + t);
+
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iValueC = new IoTString(valueC);
+
+ t2.startTransaction();
+ t2.addKV(iKeyC, iValueC);
+ transStatusList.add(t2.commitTransaction());
+ }
+ }
+
+ for (int i = 0; i < 4; i++) {
+ String keyC = "c" + i;
+ String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iValueC = new IoTString(valueC);
+
+ IoTString testValC1 = t1.getSpeculative(iKeyC);
+ IoTString testValC2 = t2.getSpeculative(iKeyC);
+
+ if ((testValC1 != null)) {
+ System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1);
+ foundError = true;
+ }
+
+ if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
+ foundError = true;
+ }
+ }
+
+ for (int t = 0; t < NUMBER_OF_TESTS; t++) {
+ for (int i = 0; i < 4; i++) {
+ String keyA = "a" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + (i + t);
+ String valueD = "d" + (i + t);
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueD = new IoTString(valueD);
+
+ t1.startTransaction();
+ t1.addKV(iKeyA, iValueA);
+ transStatusList.add(t1.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyD, iValueD);
+ transStatusList.add(t2.commitTransaction());
+ }
+ }
+
+ System.out.println("Updating Clients...");
+ t1.update();
+ t2.update();
+
+
+ System.out.println("Checking Key-Values...");
+ for (int i = 0; i < 4; i++) {
+
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + (i + NUMBER_OF_TESTS - 1);
+ String valueB = "b" + (i + NUMBER_OF_TESTS - 1);
+ String valueC = "c" + (i + NUMBER_OF_TESTS - 1);
+ String valueD = "d" + (i + NUMBER_OF_TESTS - 1);
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ IoTString testValA1 = t1.getCommitted(iKeyA);
+ IoTString testValB1 = t1.getCommitted(iKeyB);
+ IoTString testValC1 = t1.getCommitted(iKeyC);
+ IoTString testValD1 = t1.getCommitted(iKeyD);
+
+ IoTString testValA2 = t2.getCommitted(iKeyA);
+ IoTString testValB2 = t2.getCommitted(iKeyB);
+ IoTString testValC2 = t2.getCommitted(iKeyC);
+ IoTString testValD2 = t2.getCommitted(iKeyD);
+
+ if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyA + " " + testValA1);
+ foundError = true;
+ }
+
+ if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyB + " " + testValB1);
+ foundError = true;
+ }
+
+ if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyC + " " + testValC1);
+ foundError = true;
+ }
+
+ if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyD + " " + testValD1);
+ foundError = true;
+ }
+
+
+ if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
+ foundError = true;
+ }
+
+ if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
+ foundError = true;
+ }
+
+ if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
+ foundError = true;
+ }
+
+ if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
+ foundError = true;
+ }
+ }
+
+ for (TransactionStatus status : transStatusList) {
+ if (status.getStatus() != TransactionStatus.StatusCommitted) {
+ foundError = true;
+ }
+ }
+
+ if (foundError) {
+ System.out.println("Found Errors...");
+ } else {
+ System.out.println("No Errors Found...");
+ }
+ }
+
+ static void test4() throws ServerException {
+
+ boolean foundError = false;
+ long startTime = 0;
+ long endTime = 0;
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, -1);
+ t1.initTable();
+ Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, -1);
+ t2.update();
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ startTime = System.currentTimeMillis();
+ for (int i = 0; i < 4; i++) {
+ String a = "a" + i;
+ String b = "b" + i;
+ String c = "c" + i;
+ String d = "d" + i;
+ IoTString ia = new IoTString(a);
+ IoTString ib = new IoTString(b);
+ IoTString ic = new IoTString(c);
+ IoTString id = new IoTString(d);
+ t1.createNewKey(ia, 321);
+ t1.createNewKey(ib, 351);
+ t2.createNewKey(ic, 321);
+ t2.createNewKey(id, 351);
+ }
+ endTime = System.currentTimeMillis();
+ System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) );
+ System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) );
+ System.out.println();
+
+
+ // Do Updates for the keys
+ System.out.println("Setting Key-Values...");
+ startTime = System.currentTimeMillis();
+ for (int t = 0; t < NUMBER_OF_TESTS; t++) {
+ for (int i = 0; i < 4; i++) {
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueB = "b" + i;
+ String valueC = "c" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+ t1.startTransaction();
+ t1.addKV(iKeyA, iValueA);
+ transStatusList.add(t1.commitTransaction());
+
+ t1.startTransaction();
+ t1.addKV(iKeyB, iValueB);
+ transStatusList.add(t1.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyC, iValueC);
+ transStatusList.add(t2.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyD, iValueD);
+ transStatusList.add(t2.commitTransaction());
+ }
+ }
+ endTime = System.currentTimeMillis();
+ System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) );
+ System.out.println("Time Taken Per Update: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 16)) );
+ System.out.println();
+
+
+ System.out.println("Updating Clients...");
+ t1.update();
+ t2.update();
+
+
+ System.out.println("Checking Key-Values...");
+ for (int i = 0; i < 4; i++) {
+
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueB = "b" + i;
+ String valueC = "c" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ IoTString testValA1 = t1.getCommitted(iKeyA);
+ IoTString testValB1 = t1.getCommitted(iKeyB);
+ IoTString testValC1 = t1.getCommitted(iKeyC);
+ IoTString testValD1 = t1.getCommitted(iKeyD);
+
+ IoTString testValA2 = t2.getCommitted(iKeyA);
+ IoTString testValB2 = t2.getCommitted(iKeyB);
+ IoTString testValC2 = t2.getCommitted(iKeyC);
+ IoTString testValD2 = t2.getCommitted(iKeyD);
+
+ if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyA);
+ foundError = true;
+ }
+
+ if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyB);
+ foundError = true;
+ }
+
+ if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyC);
+ foundError = true;
+ }
+
+ if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyD);
+ foundError = true;
+ }
+
+
+ if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
+ foundError = true;
+ }
+
+ if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
+ foundError = true;
+ }
+
+ if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
+ foundError = true;
+ }
+
+ if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
+ foundError = true;
+ }
+ }
+
+ for (TransactionStatus status : transStatusList) {
+ if (status.getStatus() != TransactionStatus.StatusCommitted) {
+ foundError = true;
+ }
+ }
+
+ if (foundError) {
+ System.out.println("Found Errors...");
+ } else {
+ System.out.println("No Errors Found...");
+ }
+ }
+
+ static void test3() throws ServerException {
+
+ long startTime = 0;
+ long endTime = 0;
+ boolean foundError = false;
+
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, -1);
+ t1.initTable();
+ Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, -1);
+ t2.update();
+
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ startTime = System.currentTimeMillis();
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ String a = "a" + i;
+ String b = "b" + i;
+ String c = "c" + i;
+ String d = "d" + i;
+ IoTString ia = new IoTString(a);
+ IoTString ib = new IoTString(b);
+ IoTString ic = new IoTString(c);
+ IoTString id = new IoTString(d);
+ t1.createNewKey(ia, 321);
+ t1.createNewKey(ib, 351);
+ t2.createNewKey(ic, 321);
+ t2.createNewKey(id, 351);
+ }
+ endTime = System.currentTimeMillis();
+ System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) );
+ System.out.println("Time Taken Per Key: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) );
+ System.out.println();
+
+
+ // Do Updates for the keys
+ System.out.println("Setting Key-Values...");
+ startTime = System.currentTimeMillis();
+
+ System.out.println("B...");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ String keyB = "b" + i;
+ String valueB = "b" + i;
+
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iValueB = new IoTString(valueB);
+
+ t1.startTransaction();
+ t1.addKV(iKeyB, iValueB);
+ transStatusList.add(t1.commitTransaction());
+ }
+
+ System.out.println("C...");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ String keyC = "c" + i;
+ String valueC = "c" + i;
+
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iValueC = new IoTString(valueC);
+
+ t2.startTransaction();
+ t2.addKV(iKeyC, iValueC);
+ transStatusList.add(t2.commitTransaction());
+ }
+
+ System.out.println("A, D...");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ String keyA = "a" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueD = new IoTString(valueD);
+
+ t1.startTransaction();
+ t1.addKV(iKeyA, iValueA);
+ transStatusList.add(t1.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyD, iValueD);
+ transStatusList.add(t2.commitTransaction());
+ }
+ endTime = System.currentTimeMillis();
+ System.out.println("Time Taken: " + (double) ((endTime - startTime) / 1000.0) );
+ System.out.println("Time Taken Per Update: " + (double) (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4)) );
+ System.out.println();
+
+
+ System.out.println("Updating Clients...");
+ t1.update();
+ t2.update();
+
+
+ System.out.println("Checking Key-Values...");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueB = "b" + i;
+ String valueC = "c" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ IoTString testValA1 = t1.getCommitted(iKeyA);
+ IoTString testValB1 = t1.getCommitted(iKeyB);
+ IoTString testValC1 = t1.getCommitted(iKeyC);
+ IoTString testValD1 = t1.getCommitted(iKeyD);
+
+ IoTString testValA2 = t2.getCommitted(iKeyA);
+ IoTString testValB2 = t2.getCommitted(iKeyB);
+ IoTString testValC2 = t2.getCommitted(iKeyC);
+ IoTString testValD2 = t2.getCommitted(iKeyD);
+
+ if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyA);
+ foundError = true;
+ }
+
+ if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyB);
+ foundError = true;
+ }
+
+ if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyC);
+ foundError = true;
+ }
+
+ if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyD);
+ foundError = true;
+ }
+
+
+ if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
+ foundError = true;
+ }
+
+ if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
+ foundError = true;
+ }
+
+ if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
+ foundError = true;
+ }
+
+ if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
+ foundError = true;
+ }
+ }
+
+ for (TransactionStatus status : transStatusList) {
+ if (status.getStatus() != TransactionStatus.StatusCommitted) {
+ foundError = true;
+ }
+ }
+
+ if (foundError) {
+ System.out.println("Found Errors...");
+ } else {
+ System.out.println("No Errors Found...");
+ }
+ }
+
+ static void test2() throws ServerException {
+ TimingSingleton timer = TimingSingleton.getInstance();
+
+ boolean foundError = false;
+ List<TransactionStatus> transStatusList = new ArrayList<TransactionStatus>();
+
+ // Setup the 2 clients
+ Table t1 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 321, -1);
+ t1.initTable();
+ System.out.println("T1 Ready");
+
+ Table t2 = new Table("http://dc-6.calit2.uci.edu/test.iotcloud/", "reallysecret", 351, -1);
+ t2.update();
+ System.out.println("T2 Ready");
+
+ // Make the Keys
+ System.out.println("Setting up keys");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ System.out.println(i);
+ String a = "a" + i;
+ String b = "b" + i;
+ String c = "c" + i;
+ String d = "d" + i;
+ IoTString ia = new IoTString(a);
+ IoTString ib = new IoTString(b);
+ IoTString ic = new IoTString(c);
+ IoTString id = new IoTString(d);
+ t1.createNewKey(ia, 321);
+ t1.createNewKey(ib, 351);
+ t2.createNewKey(ic, 321);
+ t2.createNewKey(id, 351);
+ }
+
+ // Do Updates for the keys
+ System.out.println("Setting Key-Values...");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+ System.out.println(i);
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueB = "b" + i;
+ String valueC = "c" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ t1.startTransaction();
+ t1.addKV(iKeyA, iValueA);
+ transStatusList.add(t1.commitTransaction());
+ t1.startTransaction();
+ t1.addKV(iKeyB, iValueB);
+ transStatusList.add(t1.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyC, iValueC);
+ transStatusList.add(t2.commitTransaction());
+
+ t2.startTransaction();
+ t2.addKV(iKeyD, iValueD);
+ transStatusList.add(t2.commitTransaction());
+
+ }
+
+ System.out.println("Updating Clients...");
+ t1.update();
+ t2.update();
+
+
+
+
+ System.out.println("Checking Key-Values...");
+ for (int i = 0; i < NUMBER_OF_TESTS; i++) {
+
+ String keyA = "a" + i;
+ String keyB = "b" + i;
+ String keyC = "c" + i;
+ String keyD = "d" + i;
+ String valueA = "a" + i;
+ String valueB = "b" + i;
+ String valueC = "c" + i;
+ String valueD = "d" + i;
+
+ IoTString iKeyA = new IoTString(keyA);
+ IoTString iKeyB = new IoTString(keyB);
+ IoTString iKeyC = new IoTString(keyC);
+ IoTString iKeyD = new IoTString(keyD);
+ IoTString iValueA = new IoTString(valueA);
+ IoTString iValueB = new IoTString(valueB);
+ IoTString iValueC = new IoTString(valueC);
+ IoTString iValueD = new IoTString(valueD);
+
+
+ IoTString testValA1 = t1.getCommitted(iKeyA);
+ IoTString testValB1 = t1.getCommitted(iKeyB);
+ IoTString testValC1 = t1.getCommitted(iKeyC);
+ IoTString testValD1 = t1.getCommitted(iKeyD);
+
+ IoTString testValA2 = t2.getCommitted(iKeyA);
+ IoTString testValB2 = t2.getCommitted(iKeyB);
+ IoTString testValC2 = t2.getCommitted(iKeyC);
+ IoTString testValD2 = t2.getCommitted(iKeyD);
+
+ if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyA);
+ foundError = true;
+ }
+
+ if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyB);
+ foundError = true;
+ }
+
+ if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyC);
+ foundError = true;
+ }
+
+ if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
+ System.out.println("Key-Value t1 incorrect: " + keyD);
+ foundError = true;
+ }
+
+
+ if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
+ foundError = true;
+ }
+
+ if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
+ foundError = true;
+ }
+
+ if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
+ foundError = true;
+ }
+
+ if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
+ System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
+ foundError = true;
+ }
+ }
+
+ for (TransactionStatus status : transStatusList) {
+ if (status.getStatus() != TransactionStatus.StatusCommitted) {
+ foundError = true;
+ System.out.println(status.getStatus());
+ }
+ }
+
+ if (foundError) {
+ System.out.println("Found Errors...");
+ } else {
+ System.out.println("No Errors Found...");
+ }
+
+ // System.out.println();
+ // System.out.println();
+ // t1.printSlots();
+
+ // System.out.println();
+ // System.out.println();
+ // t2.printSlots();
+ }
}