11 public static final int NUMBER_OF_TESTS = 10000;
13 public static void main(String[] args) {
14 if (args[0].equals("2")) {
16 } else if (args[0].equals("3")) {
18 } else if (args[0].equals("4")) {
24 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
26 System.out.println(t1);
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);
35 // System.out.println(ib + " -> " + t1.getCommitted(ib));
36 // System.out.println(ia + " -> " + t2.getCommitted(ia));
37 // System.out.println();
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++) {
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);
52 // t.startTransaction();
53 // t.addKV(iKey, iValue);
54 // t.commitTransaction();
65 // Setup the 2 clients
66 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
68 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
73 System.out.println("Setting up keys");
74 startTime = System.currentTimeMillis();
75 for (int i = 0; i < 4; 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);
89 endTime = System.currentTimeMillis();
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)) );
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;
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);
121 t1.startTransaction();
122 t1.addKV(iKeyA, iValueA);
123 t1.commitTransaction();
125 t1.startTransaction();
126 t1.addKV(iKeyB, iValueB);
127 t1.commitTransaction();
129 t2.startTransaction();
130 t2.addKV(iKeyC, iValueC);
131 t2.commitTransaction();
133 t2.startTransaction();
134 t2.addKV(iKeyD, iValueD);
135 t2.commitTransaction();
138 endTime = System.currentTimeMillis();
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();
145 System.out.println("Updating Clients...");
151 boolean foundError = false;
153 System.out.println("Checking Key-Values...");
154 for (int i = 0; i < 4; i++) {
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;
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);
175 IoTString testValA1 = t1.getCommitted(iKeyA);
176 IoTString testValB1 = t1.getCommitted(iKeyB);
177 IoTString testValC1 = t1.getCommitted(iKeyC);
178 IoTString testValD1 = t1.getCommitted(iKeyD);
180 IoTString testValA2 = t2.getCommitted(iKeyA);
181 IoTString testValB2 = t2.getCommitted(iKeyB);
182 IoTString testValC2 = t2.getCommitted(iKeyC);
183 IoTString testValD2 = t2.getCommitted(iKeyD);
185 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
186 System.out.println("Key-Value t1 incorrect: " + keyA);
190 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
191 System.out.println("Key-Value t1 incorrect: " + keyB);
195 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
196 System.out.println("Key-Value t1 incorrect: " + keyC);
200 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
201 System.out.println("Key-Value t1 incorrect: " + keyD);
206 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
207 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
211 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
212 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
216 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
217 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
221 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
222 System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
228 System.out.println("Found Errors...");
230 System.out.println("No Errors Found...");
233 System.out.println();
234 System.out.println();
235 System.out.println();
236 System.out.println();
238 System.out.println();
242 static void test3() {
247 // Setup the 2 clients
248 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
250 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
255 System.out.println("Setting up keys");
256 startTime = System.currentTimeMillis();
257 for (int i = 0; i < NUMBER_OF_TESTS; 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);
271 endTime = System.currentTimeMillis();
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();
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;
287 IoTString iKeyB = new IoTString(keyB);
288 IoTString iValueB = new IoTString(valueB);
290 t1.startTransaction();
291 t1.addKV(iKeyB, iValueB);
292 t1.commitTransaction();
295 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
296 String keyC = "c" + i;
297 String valueC = "c" + i;
299 IoTString iKeyC = new IoTString(keyC);
300 IoTString iValueC = new IoTString(valueC);
302 t2.startTransaction();
303 t2.addKV(iKeyC, iValueC);
304 t2.commitTransaction();
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;
313 IoTString iKeyA = new IoTString(keyA);
314 IoTString iKeyD = new IoTString(keyD);
315 IoTString iValueA = new IoTString(valueA);
316 IoTString iValueD = new IoTString(valueD);
318 t1.startTransaction();
319 t1.addKV(iKeyA, iValueA);
320 t1.commitTransaction();
322 t2.startTransaction();
323 t2.addKV(iKeyD, iValueD);
324 t2.commitTransaction();
331 endTime = System.currentTimeMillis();
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();
338 System.out.println("Updating Clients...");
344 boolean foundError = false;
346 System.out.println("Checking Key-Values...");
347 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
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;
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);
368 IoTString testValA1 = t1.getCommitted(iKeyA);
369 IoTString testValB1 = t1.getCommitted(iKeyB);
370 IoTString testValC1 = t1.getCommitted(iKeyC);
371 IoTString testValD1 = t1.getCommitted(iKeyD);
373 IoTString testValA2 = t2.getCommitted(iKeyA);
374 IoTString testValB2 = t2.getCommitted(iKeyB);
375 IoTString testValC2 = t2.getCommitted(iKeyC);
376 IoTString testValD2 = t2.getCommitted(iKeyD);
378 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
379 System.out.println("Key-Value t1 incorrect: " + keyA);
383 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
384 System.out.println("Key-Value t1 incorrect: " + keyB);
388 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
389 System.out.println("Key-Value t1 incorrect: " + keyC);
393 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
394 System.out.println("Key-Value t1 incorrect: " + keyD);
399 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
400 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
404 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
405 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
409 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
410 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
414 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
415 System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
421 System.out.println("Found Errors...");
423 System.out.println("No Errors Found...");
426 System.out.println();
427 System.out.println();
428 System.out.println();
429 System.out.println();
431 System.out.println();
435 static void test2() {
440 // Setup the 2 clients
441 Table t1 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 321);
443 Table t2 = new Table("http://127.0.0.1/test.iotcloud/", "reallysecret", 351);
452 System.out.println("Setting up keys");
453 startTime = System.currentTimeMillis();
454 for (int i = 0; i < NUMBER_OF_TESTS; 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);
468 endTime = System.currentTimeMillis();
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();
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;
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);
499 t1.startTransaction();
500 t1.addKV(iKeyA, iValueA);
501 t1.commitTransaction();
503 t1.startTransaction();
504 t1.addKV(iKeyB, iValueB);
505 t1.commitTransaction();
507 t2.startTransaction();
508 t2.addKV(iKeyC, iValueC);
509 t2.commitTransaction();
511 t2.startTransaction();
512 t2.addKV(iKeyD, iValueD);
513 t2.commitTransaction();
515 endTime = System.currentTimeMillis();
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();
522 System.out.println("Updating Clients...");
528 boolean foundError = false;
530 System.out.println("Checking Key-Values...");
531 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
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;
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);
552 IoTString testValA1 = t1.getCommitted(iKeyA);
553 IoTString testValB1 = t1.getCommitted(iKeyB);
554 IoTString testValC1 = t1.getCommitted(iKeyC);
555 IoTString testValD1 = t1.getCommitted(iKeyD);
557 IoTString testValA2 = t2.getCommitted(iKeyA);
558 IoTString testValB2 = t2.getCommitted(iKeyB);
559 IoTString testValC2 = t2.getCommitted(iKeyC);
560 IoTString testValD2 = t2.getCommitted(iKeyD);
562 if ((testValA1 == null) || (testValA1.equals(iValueA) == false)) {
563 System.out.println("Key-Value t1 incorrect: " + keyA);
567 if ((testValB1 == null) || (testValB1.equals(iValueB) == false)) {
568 System.out.println("Key-Value t1 incorrect: " + keyB);
572 if ((testValC1 == null) || (testValC1.equals(iValueC) == false)) {
573 System.out.println("Key-Value t1 incorrect: " + keyC);
577 if ((testValD1 == null) || (testValD1.equals(iValueD) == false)) {
578 System.out.println("Key-Value t1 incorrect: " + keyD);
583 if ((testValA2 == null) || (testValA2.equals(iValueA) == false)) {
584 System.out.println("Key-Value t2 incorrect: " + keyA + " " + testValA2);
588 if ((testValB2 == null) || (testValB2.equals(iValueB) == false)) {
589 System.out.println("Key-Value t2 incorrect: " + keyB + " " + testValB2);
593 if ((testValC2 == null) || (testValC2.equals(iValueC) == false)) {
594 System.out.println("Key-Value t2 incorrect: " + keyC + " " + testValC2);
598 if ((testValD2 == null) || (testValD2.equals(iValueD) == false)) {
599 System.out.println("Key-Value t2 incorrect: " + keyD + " " + testValD2);
605 System.out.println("Found Errors...");
607 System.out.println("No Errors Found...");
610 System.out.println();
611 System.out.println();
612 System.out.println();
613 System.out.println();
615 System.out.println();