3 #include "TimingSingleton.h"
4 #include "TransactionStatus.h"
6 #define NUMBER_OF_TESTS 2
8 TimingSingleton *timer;
10 MyVector<TransactionStatus *> * transStatusList;
14 // TODO: This test uses the Serial library
15 // Please install "screen" on your machine and run
16 // it on the serial port right after flashing the
17 // firmware onto the Particle board.
18 // e.g. sudo screen /dev/ttyACM0
20 timer = TimingSingleton_getInstance();
22 transStatusList = new MyVector<TransactionStatus *>();
23 IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/");
24 IoTString * password = new IoTString("reallysecret");
25 t1 = new Table(baseurl, password, 321, -1);
27 Serial.println("Finished table init...");
28 baseurl->releaseRef();
29 password->releaseRef();
32 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
34 sprintf(buffer, "a%d", i);
35 IoTString *ia = new IoTString(buffer);
36 sprintf(buffer, "b%d", i);
37 IoTString *ib = new IoTString(buffer);
38 t1->createNewKey(ia, 321);
39 t1->createNewKey(ib, 321);
43 Serial.println("Finished key generation...");
48 // Do Updates for the keys
49 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
51 sprintf(buffer, "a%d", i);
52 IoTString * iKeyA = new IoTString(buffer);
53 IoTString * iValueA = new IoTString(buffer);
55 sprintf(buffer, "b%d", i);
56 IoTString * iKeyB = new IoTString(buffer);
57 IoTString * iValueB = new IoTString(buffer);
59 t1->startTransaction();
60 t1->put(iKeyA, iValueA);
61 transStatusList->add(t1->commitTransaction());
63 iValueA->releaseRef();
65 t1->startTransaction();
66 t1->put(iKeyB, iValueB);
67 transStatusList->add(t1->commitTransaction());
69 iValueB->releaseRef();
71 Serial.println("Added new transaction: ");
79 Serial.println("Updated table...");
81 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
83 sprintf(buffer, "a%d", i);
84 IoTString * iKeyA = new IoTString(buffer);
85 IoTString * iValueA = new IoTString(buffer);
87 sprintf(buffer, "b%d", i);
88 IoTString * iKeyB = new IoTString(buffer);
89 IoTString * iValueB = new IoTString(buffer);
91 IoTString *testValA1 = t1->getCommitted(iKeyA);
92 IoTString *testValB1 = t1->getCommitted(iKeyB);
94 if ((testValA1 == NULL) || (testValA1->equals(iValueA) == false)) {
95 Serial.println("Key-Value t1 incorrect: keyA");
99 if ((testValB1 == NULL) || (testValB1->equals(iValueB) == false)) {
100 Serial.println("Key-Value t1 incorrect: keyB");
105 iValueA->releaseRef();
107 iValueB->releaseRef();
108 testValA1->releaseRef();
109 testValB1->releaseRef();
112 for (uint i = 0; i < transStatusList->size(); i++) {
113 TransactionStatus * status = transStatusList->get(i);
114 if (status->getStatus() != TransactionStatus_StatusCommitted) {
116 Serial.println("Status error");
122 Serial.println("Found Errors...");
125 delete transStatusList;
128 Serial.println("Process done... now waiting...");