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