Fixing Bugs
[iotcloud.git] / version2 / 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
11         public static final  int NUMBER_OF_TESTS = 10000;
12
13         public static void main(String[] args) {
14                 if (args[0].equals("2")) {
15                         test2();
16                 } else if (args[0].equals("3")) {
17                         test3();
18                 } else if (args[0].equals("4")) {
19                         test4();
20                 }
21         }
22
23         static void test5() {
24                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
25                 t1.rebuild();
26                 System.out.println(t1);
27
28                 // // Print the results
29                 // for (int i = 0; i < NUMBER_OF_TESTS; i++) {
30                 //      String a = "a" + i;
31                 //      String b = "b" + i;
32                 //      IoTString ia = new IoTString(a);
33                 //      IoTString ib = new IoTString(b);
34
35                 //      System.out.println(ib + " -> " + t1.getCommitted(ib));
36                 //      System.out.println(ia + " -> " + t2.getCommitted(ia));
37                 //      System.out.println();
38                 // }
39         }
40
41         // static Thread buildThreadTest4(String prefix, Table t) {
42         //      return new Thread() {
43         //              public void run() {
44         //                      for (int i = 0; i < (NUMBER_OF_TESTS * 3); i++) {
45
46         //                              int num = i % NUMBER_OF_TESTS;
47         //                              String key = prefix + num;
48         //                              String value = prefix + (num + 2000);
49         //                              IoTString iKey = new IoTString(key);
50         //                              IoTString iValue = new IoTString(value);
51
52         //                              t.startTransaction();
53         //                              t.addKV(iKey, iValue);
54         //                              t.commitTransaction();
55         //                      }
56         //              }
57         //      };
58         // }
59
60         static void test4() {
61
62                 long startTime = 0;
63                 long endTime = 0;
64
65                 // Setup the 2 clients
66                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
67                 t1.initTable();
68                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
69                 t2.update();
70
71
72                 // Make the Keys
73                 System.out.println("Setting up keys");
74                 startTime = System.currentTimeMillis();
75                 for (int i = 0; i < 4; i++) {
76                         String a = "a" + i;
77                         String b = "b" + i;
78                         String c = "c" + i;
79                         String d = "d" + i;
80                         IoTString ia = new IoTString(a);
81                         IoTString ib = new IoTString(b);
82                         IoTString ic = new IoTString(c);
83                         IoTString id = new IoTString(d);
84                         t1.createNewKey(ia, 321);
85                         t1.createNewKey(ib, 351);
86                         t2.createNewKey(ic, 321);
87                         t2.createNewKey(id, 351);
88                 }
89                 endTime = System.currentTimeMillis();
90
91
92
93                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
94                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
95                 System.out.println();
96
97
98                 // Do Updates for the keys
99                 System.out.println("Setting Key-Values...");
100                 startTime = System.currentTimeMillis();
101                 for (int t = 0; t < NUMBER_OF_TESTS; t++) {
102                         for (int i = 0; i < 4; i++) {
103                                 String keyA = "a" + i;
104                                 String keyB = "b" + i;
105                                 String keyC = "c" + i;
106                                 String keyD = "d" + i;
107                                 String valueA = "a" + i;
108                                 String valueB = "b" + i;
109                                 String valueC = "c" + i;
110                                 String valueD = "d" + i;
111
112                                 IoTString iKeyA = new IoTString(keyA);
113                                 IoTString iKeyB = new IoTString(keyB);
114                                 IoTString iKeyC = new IoTString(keyC);
115                                 IoTString iKeyD = new IoTString(keyD);
116                                 IoTString iValueA = new IoTString(valueA);
117                                 IoTString iValueB = new IoTString(valueB);
118                                 IoTString iValueC = new IoTString(valueC);
119                                 IoTString iValueD = new IoTString(valueD);
120
121                                 t1.startTransaction();
122                                 t1.addKV(iKeyA, iValueA);
123                                 t1.commitTransaction();
124
125                                 t1.startTransaction();
126                                 t1.addKV(iKeyB, iValueB);
127                                 t1.commitTransaction();
128
129                                 t2.startTransaction();
130                                 t2.addKV(iKeyC, iValueC);
131                                 t2.commitTransaction();
132
133                                 t2.startTransaction();
134                                 t2.addKV(iKeyD, iValueD);
135                                 t2.commitTransaction();
136                         }
137                 }
138                 endTime = System.currentTimeMillis();
139
140                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
141                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 8))   );
142                 System.out.println();
143
144
145                 System.out.println("Updating Clients...");
146                 t1.update();
147                 t2.update();
148                 t1.update();
149                 t2.update();
150
151                 boolean foundError = false;
152
153                 System.out.println("Checking Key-Values...");
154                 for (int i = 0; i < 4; i++) {
155
156                         String keyA = "a" + i;
157                         String keyB = "b" + i;
158                         String keyC = "c" + i;
159                         String keyD = "d" + i;
160                         String valueA = "a" + i;
161                         String valueB = "b" + i;
162                         String valueC = "c" + i;
163                         String valueD = "d" + i;
164
165                         IoTString iKeyA = new IoTString(keyA);
166                         IoTString iKeyB = new IoTString(keyB);
167                         IoTString iKeyC = new IoTString(keyC);
168                         IoTString iKeyD = new IoTString(keyD);
169                         IoTString iValueA = new IoTString(valueA);
170                         IoTString iValueB = new IoTString(valueB);
171                         IoTString iValueC = new IoTString(valueC);
172                         IoTString iValueD = new IoTString(valueD);
173
174
175                         IoTString testValA1 = t1.getCommitted(iKeyA);
176                         IoTString testValB1 = t1.getCommitted(iKeyB);
177                         IoTString testValC1 = t1.getCommitted(iKeyC);
178                         IoTString testValD1 = t1.getCommitted(iKeyD);
179
180                         IoTString testValA2 = t2.getCommitted(iKeyA);
181                         IoTString testValB2 = t2.getCommitted(iKeyB);
182                         IoTString testValC2 = t2.getCommitted(iKeyC);
183                         IoTString testValD2 = t2.getCommitted(iKeyD);
184
185                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
186                                 System.out.println("Key-Value t1 incorrect: " + keyA);
187                                 foundError = true;
188                         }
189
190                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
191                                 System.out.println("Key-Value t1 incorrect: " + keyB);
192                                 foundError = true;
193                         }
194
195                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
196                                 System.out.println("Key-Value t1 incorrect: " + keyC);
197                                 foundError = true;
198                         }
199
200                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
201                                 System.out.println("Key-Value t1 incorrect: " + keyD);
202                                 foundError = true;
203                         }
204
205
206                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
207                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
208                                 foundError = true;
209                         }
210
211                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
212                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
213                                 foundError = true;
214                         }
215
216                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
217                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
218                                 foundError = true;
219                         }
220
221                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
222                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
223                                 foundError = true;
224                         }
225                 }
226
227                 if (foundError) {
228                         System.out.println("Found Errors...");
229                 } else {
230                         System.out.println("No Errors Found...");
231                 }
232
233                 System.out.println();
234                 System.out.println();
235                 System.out.println();
236                 System.out.println();
237                 t1.printSlots();
238                 System.out.println();
239                 t2.printSlots();
240         }
241
242         static void test3() {
243
244                 long startTime = 0;
245                 long endTime = 0;
246
247                 // Setup the 2 clients
248                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
249                 t1.initTable();
250                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
251                 t2.update();
252
253
254                 // Make the Keys
255                 System.out.println("Setting up keys");
256                 startTime = System.currentTimeMillis();
257                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
258                         String a = "a" + i;
259                         String b = "b" + i;
260                         String c = "c" + i;
261                         String d = "d" + i;
262                         IoTString ia = new IoTString(a);
263                         IoTString ib = new IoTString(b);
264                         IoTString ic = new IoTString(c);
265                         IoTString id = new IoTString(d);
266                         t1.createNewKey(ia, 321);
267                         t1.createNewKey(ib, 351);
268                         t2.createNewKey(ic, 321);
269                         t2.createNewKey(id, 351);
270                 }
271                 endTime = System.currentTimeMillis();
272
273
274
275                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
276                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
277                 System.out.println();
278
279
280                 // Do Updates for the keys
281                 System.out.println("Setting Key-Values...");
282                 startTime = System.currentTimeMillis();
283                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
284                         String keyB = "b" + i;
285                         String valueB = "b" + i;
286
287                         IoTString iKeyB = new IoTString(keyB);
288                         IoTString iValueB = new IoTString(valueB);
289
290                         t1.startTransaction();
291                         t1.addKV(iKeyB, iValueB);
292                         t1.commitTransaction();
293                 }
294
295                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
296                         String keyC = "c" + i;
297                         String valueC = "c" + i;
298
299                         IoTString iKeyC = new IoTString(keyC);
300                         IoTString iValueC = new IoTString(valueC);
301
302                         t2.startTransaction();
303                         t2.addKV(iKeyC, iValueC);
304                         t2.commitTransaction();
305                 }
306
307                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
308                         String keyA = "a" + i;
309                         String keyD = "d" + i;
310                         String valueA = "a" + i;
311                         String valueD = "d" + i;
312
313                         IoTString iKeyA = new IoTString(keyA);
314                         IoTString iKeyD = new IoTString(keyD);
315                         IoTString iValueA = new IoTString(valueA);
316                         IoTString iValueD = new IoTString(valueD);
317
318                         t1.startTransaction();
319                         t1.addKV(iKeyA, iValueA);
320                         t1.commitTransaction();
321
322                         t2.startTransaction();
323                         t2.addKV(iKeyD, iValueD);
324                         t2.commitTransaction();
325                 }
326
327
328
329
330
331                 endTime = System.currentTimeMillis();
332
333                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
334                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
335                 System.out.println();
336
337
338                 System.out.println("Updating Clients...");
339                 t1.update();
340                 t2.update();
341                 t1.update();
342                 t2.update();
343
344                 boolean foundError = false;
345
346                 System.out.println("Checking Key-Values...");
347                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
348
349                         String keyA = "a" + i;
350                         String keyB = "b" + i;
351                         String keyC = "c" + i;
352                         String keyD = "d" + i;
353                         String valueA = "a" + i;
354                         String valueB = "b" + i;
355                         String valueC = "c" + i;
356                         String valueD = "d" + i;
357
358                         IoTString iKeyA = new IoTString(keyA);
359                         IoTString iKeyB = new IoTString(keyB);
360                         IoTString iKeyC = new IoTString(keyC);
361                         IoTString iKeyD = new IoTString(keyD);
362                         IoTString iValueA = new IoTString(valueA);
363                         IoTString iValueB = new IoTString(valueB);
364                         IoTString iValueC = new IoTString(valueC);
365                         IoTString iValueD = new IoTString(valueD);
366
367
368                         IoTString testValA1 = t1.getCommitted(iKeyA);
369                         IoTString testValB1 = t1.getCommitted(iKeyB);
370                         IoTString testValC1 = t1.getCommitted(iKeyC);
371                         IoTString testValD1 = t1.getCommitted(iKeyD);
372
373                         IoTString testValA2 = t2.getCommitted(iKeyA);
374                         IoTString testValB2 = t2.getCommitted(iKeyB);
375                         IoTString testValC2 = t2.getCommitted(iKeyC);
376                         IoTString testValD2 = t2.getCommitted(iKeyD);
377
378                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
379                                 System.out.println("Key-Value t1 incorrect: " + keyA);
380                                 foundError = true;
381                         }
382
383                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
384                                 System.out.println("Key-Value t1 incorrect: " + keyB);
385                                 foundError = true;
386                         }
387
388                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
389                                 System.out.println("Key-Value t1 incorrect: " + keyC);
390                                 foundError = true;
391                         }
392
393                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
394                                 System.out.println("Key-Value t1 incorrect: " + keyD);
395                                 foundError = true;
396                         }
397
398
399                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
400                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
401                                 foundError = true;
402                         }
403
404                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
405                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
406                                 foundError = true;
407                         }
408
409                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
410                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
411                                 foundError = true;
412                         }
413
414                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
415                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
416                                 foundError = true;
417                         }
418                 }
419
420                 if (foundError) {
421                         System.out.println("Found Errors...");
422                 } else {
423                         System.out.println("No Errors Found...");
424                 }
425
426                 System.out.println();
427                 System.out.println();
428                 System.out.println();
429                 System.out.println();
430                 t1.printSlots();
431                 System.out.println();
432                 t2.printSlots();
433         }
434
435         static void test2() {
436
437                 long startTime = 0;
438                 long endTime = 0;
439
440                 // Setup the 2 clients
441                 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
442                 t1.initTable();
443                 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
444                 t2.update();
445
446                 // t1.rebuild();
447                 // t2.rebuild();
448
449
450
451                 // Make the Keys
452                 System.out.println("Setting up keys");
453                 startTime = System.currentTimeMillis();
454                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
455                         String a = "a" + i;
456                         String b = "b" + i;
457                         String c = "c" + i;
458                         String d = "d" + i;
459                         IoTString ia = new IoTString(a);
460                         IoTString ib = new IoTString(b);
461                         IoTString ic = new IoTString(c);
462                         IoTString id = new IoTString(d);
463                         t1.createNewKey(ia, 321);
464                         t1.createNewKey(ib, 351);
465                         t2.createNewKey(ic, 321);
466                         t2.createNewKey(id, 351);
467                 }
468                 endTime = System.currentTimeMillis();
469
470
471
472                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
473                 System.out.println("Time Taken Per Key: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
474                 System.out.println();
475
476
477                 // Do Updates for the keys
478                 System.out.println("Setting Key-Values...");
479                 startTime = System.currentTimeMillis();
480                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
481                         String keyA = "a" + i;
482                         String keyB = "b" + i;
483                         String keyC = "c" + i;
484                         String keyD = "d" + i;
485                         String valueA = "a" + i;
486                         String valueB = "b" + i;
487                         String valueC = "c" + i;
488                         String valueD = "d" + i;
489
490                         IoTString iKeyA = new IoTString(keyA);
491                         IoTString iKeyB = new IoTString(keyB);
492                         IoTString iKeyC = new IoTString(keyC);
493                         IoTString iKeyD = new IoTString(keyD);
494                         IoTString iValueA = new IoTString(valueA);
495                         IoTString iValueB = new IoTString(valueB);
496                         IoTString iValueC = new IoTString(valueC);
497                         IoTString iValueD = new IoTString(valueD);
498
499                         t1.startTransaction();
500                         t1.addKV(iKeyA, iValueA);
501                         t1.commitTransaction();
502
503                         t1.startTransaction();
504                         t1.addKV(iKeyB, iValueB);
505                         t1.commitTransaction();
506
507                         t2.startTransaction();
508                         t2.addKV(iKeyC, iValueC);
509                         t2.commitTransaction();
510
511                         t2.startTransaction();
512                         t2.addKV(iKeyD, iValueD);
513                         t2.commitTransaction();
514                 }
515                 endTime = System.currentTimeMillis();
516
517                 System.out.println("Time Taken: " + (double)   ((endTime - startTime) / 1000.0)    );
518                 System.out.println("Time Taken Per Update: " + (double)  (((endTime - startTime) / 1000.0) / (NUMBER_OF_TESTS * 4))   );
519                 System.out.println();
520
521
522                 System.out.println("Updating Clients...");
523                 t1.update();
524                 t2.update();
525                 t1.update();
526                 t2.update();
527
528                 boolean foundError = false;
529
530                 System.out.println("Checking Key-Values...");
531                 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
532
533                         String keyA = "a" + i;
534                         String keyB = "b" + i;
535                         String keyC = "c" + i;
536                         String keyD = "d" + i;
537                         String valueA = "a" + i;
538                         String valueB = "b" + i;
539                         String valueC = "c" + i;
540                         String valueD = "d" + i;
541
542                         IoTString iKeyA = new IoTString(keyA);
543                         IoTString iKeyB = new IoTString(keyB);
544                         IoTString iKeyC = new IoTString(keyC);
545                         IoTString iKeyD = new IoTString(keyD);
546                         IoTString iValueA = new IoTString(valueA);
547                         IoTString iValueB = new IoTString(valueB);
548                         IoTString iValueC = new IoTString(valueC);
549                         IoTString iValueD = new IoTString(valueD);
550
551
552                         IoTString testValA1 = t1.getCommitted(iKeyA);
553                         IoTString testValB1 = t1.getCommitted(iKeyB);
554                         IoTString testValC1 = t1.getCommitted(iKeyC);
555                         IoTString testValD1 = t1.getCommitted(iKeyD);
556
557                         IoTString testValA2 = t2.getCommitted(iKeyA);
558                         IoTString testValB2 = t2.getCommitted(iKeyB);
559                         IoTString testValC2 = t2.getCommitted(iKeyC);
560                         IoTString testValD2 = t2.getCommitted(iKeyD);
561
562                         if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
563                                 System.out.println("Key-Value t1 incorrect: " + keyA);
564                                 foundError = true;
565                         }
566
567                         if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
568                                 System.out.println("Key-Value t1 incorrect: " + keyB);
569                                 foundError = true;
570                         }
571
572                         if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
573                                 System.out.println("Key-Value t1 incorrect: " + keyC);
574                                 foundError = true;
575                         }
576
577                         if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
578                                 System.out.println("Key-Value t1 incorrect: " + keyD);
579                                 foundError = true;
580                         }
581
582
583                         if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
584                                 System.out.println("Key-Value t2 incorrect: " + keyA + "    " + testValA2);
585                                 foundError = true;
586                         }
587
588                         if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
589                                 System.out.println("Key-Value t2 incorrect: " + keyB + "    " + testValB2);
590                                 foundError = true;
591                         }
592
593                         if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
594                                 System.out.println("Key-Value t2 incorrect: " + keyC + "    " + testValC2);
595                                 foundError = true;
596                         }
597
598                         if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
599                                 System.out.println("Key-Value t2 incorrect: " + keyD + "    " + testValD2);
600                                 foundError = true;
601                         }
602                 }
603
604                 if (foundError) {
605                         System.out.println("Found Errors...");
606                 } else {
607                         System.out.println("No Errors Found...");
608                 }
609
610                 System.out.println();
611                 System.out.println();
612                 System.out.println();
613                 System.out.println();
614                 t1.printSlots();
615                 System.out.println();
616                 t2.printSlots();
617         }
618 }