add some comments
[iotcloud.git] / src / java / iotcloud / Test.java
1 package iotcloud;
2
3 /**
4  * Test cases.
5  * @author Brian Demsky
6  * @version 1.0
7  */
8
9 public class Test {
10         public static void main(String[] args) {
11                 if (args[0].equals("1"))
12                         test1();
13                 else if(args[0].equals("2"))
14                         test2();
15                 else if(args[0].equals("3"))
16                         test3();
17                 else if(args[0].equals("4"))
18                         test4();
19
20         }
21
22         static Thread buildThread(String prefix, Table t) {
23                 return new Thread() {
24                                                  public void run() {
25                                                          for(int i=0; i<600; i++) {
26                                                                  String a=prefix+i;
27                                                                  IoTString ia=new IoTString(a);
28                                                                  t.put(ia, ia);
29                                                                  System.out.println(ia+"->"+t.get(ia));
30                                                          }
31                                                  }
32                 };
33         }
34
35         static void test4() {
36                 Table t1=new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
37                 Table t2=new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
38                 t1.rebuild();
39                 t2.rebuild();
40                 Thread thr1=buildThread("p1", t1);
41                 Thread thr2=buildThread("p2", t2);
42                 thr1.start();
43                 thr2.start();
44                 try {
45                         thr1.join();
46                         thr2.join();
47                 } catch (Exception e) {
48                         e.printStackTrace();
49                 }
50         }
51
52         static void test3() {
53                 Table t1=new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
54                 Table t2=new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
55                 t1.rebuild();
56                 t2.rebuild();
57                 for(int i=0; i<600; i++) {
58                         String a="STR"+i;
59                         String b="ABR"+i;
60                         IoTString ia=new IoTString(a);
61                         IoTString ib=new IoTString(b);
62                         t1.put(ia, ia);
63                         t2.put(ib, ib);
64                         t1.update();
65                         System.out.println(ib+"->"+t1.get(ib));
66                         System.out.println(ia+"->"+t2.get(ia));
67                 }
68         }
69
70         static void test2() {
71                 Table t1=new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
72                 t1.initTable();
73                 Table t2=new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
74                 t2.update();
75                 for(int i=0; i<600; i++) {
76                         String a="STR"+i;
77                         String b="ABR"+i;
78                         IoTString ia=new IoTString(a);
79                         IoTString ib=new IoTString(b);
80                         t1.put(ia, ia);
81                         t2.put(ib, ib);
82                         t1.update();
83                         System.out.println(ib+"->"+t1.get(ib));
84                         System.out.println(ia+"->"+t2.get(ia));
85                 }
86         }
87
88         static void test1() {
89                 TestCloudComm cc=new TestCloudComm();
90                 Table t1=new Table(cc, 6513);
91                 t1.initTable();
92                 Table t2=new Table(cc, 6512);
93                 t2.update();
94                 for(int i=0; i<600; i++) {
95                         String a="STR"+i;
96                         String b="ABR"+i;
97                         IoTString ia=new IoTString(a);
98                         IoTString ib=new IoTString(b);
99                         t1.put(ia, ia);
100                         t2.put(ib, ib);
101                         t1.update();
102                         System.out.println(ib+"->"+t1.get(ib));
103                         System.out.println(ia+"->"+t2.get(ia));
104                 }
105                 for(int i=0; i<600; i++) {
106                         String a="STR"+i;
107                         String b="ABR"+i;
108                         IoTString ia=new IoTString(a);
109                         IoTString ib=new IoTString(b);
110                         System.out.println(ib+"->"+t1.get(ib));
111                         System.out.println(ia+"->"+t2.get(ia));
112                         System.out.println(ib+"->"+t2.get(ib));
113                         System.out.println(ia+"->"+t1.get(ia));
114                 }
115
116         }
117 }