Commits working, Transactions Working, Arbitrations working, Still needs a lot of...
[iotcloud.git] / version2 / src / java / iotcloud / Test.java
index 00d4c7c946c535af7e80fdeb4f962f1e9fade7ea..24af2f8cbf3ecc745e6856ac17f40b12d61b8b5e 100644 (file)
@@ -7,69 +7,408 @@ package iotcloud;
  */
 
 public class Test {
  */
 
 public class Test {
+
+       public static final  int NUMBER_OF_TESTS = 20000; //66
+
        public static void main(String[] args) {
                if (args[0].equals("2")) {
                        test2();
        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 test2() {
+
+
+       static void test5() {
                Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
                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();
+               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();
+               // }
+       }
 
 
-               final int NUMBER_OF_TESTS = 200;
+       static Thread buildThreadTest4(String prefix, Table t) {
+               return new Thread() {
+                       public void run() {
+                               for (int i = 0; i < (NUMBER_OF_TESTS * 3); i++) {
 
 
-               for (int i = 0; i < NUMBER_OF_TESTS; 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);
 
 
-                       System.out.println("Doing: " + i);
+                                       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);
 
                        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();
+
 
 
-                       t1.createNewKey(ia, 351);
-                       t2.createNewKey(ib, 321);
+               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.startTransaction();
-                       t1.addKV(ia, ia);
+                       t1.addKV(iKey, iValue);
                        t1.commitTransaction();
                }
 
                for (int i = 0; i < NUMBER_OF_TESTS; i++) {
                        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);
 
 
-                       System.out.println("Doing: " + i);
+                       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);
 
                        String a = "a" + i;
                        String b = "b" + i;
                        IoTString ia = new IoTString(a);
                        IoTString ib = new IoTString(b);
 
-                       t2.startTransaction();
-                       t2.addKV(ib, ib);
-                       t2.commitTransaction();
+                       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();
 
 
 
 
-               t1.update();
-               // t2.update();
-               // t1.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);
                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(ib + " -> " + t1.getCommitted(ib));
-                       System.out.println(ia + " -> " + t2.getCommitted(ia));
-                       System.out.println();
+               // 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();
+               // }
        }
 }
        }
 }