3 #include "TimingSingleton.h"
4 #include "TransactionStatus.h"
6 #define NUMBER_OF_TESTS 2
8 int main(int numargs, char ** args) {
9 TimingSingleton * timer = TimingSingleton_getInstance();
11 bool foundError = false;
12 Vector<TransactionStatus *> * transStatusList = new Vector<TransactionStatus *>();
14 // Setup the 2 clients
15 IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/");
16 IoTString * password = new IoTString("reallysecret");
17 Table * t1 = new Table(baseurl, password, 321, -1);
21 Table * t2 = new Table(baseurl, password, 351, -1);
25 baseurl->releaseRef();
26 password->releaseRef();
29 printf("Setting up keys\n");
30 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
33 sprintf(buffer, "a%d", i);
34 IoTString *ia = new IoTString(buffer);
35 sprintf(buffer, "b%d", i);
36 IoTString *ib = new IoTString(buffer);
37 sprintf(buffer, "c%d", i);
38 IoTString *ic = new IoTString(buffer);
39 sprintf(buffer, "d%d", i);
40 IoTString *id = new IoTString(buffer);
41 t1->createNewKey(ia, 321);
42 t1->createNewKey(ib, 351);
43 t2->createNewKey(ic, 321);
44 t2->createNewKey(id, 351);
51 // Do Updates for the keys
52 printf("Setting Key-Values...\n");
53 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
56 sprintf(buffer, "a%d", i);
57 IoTString * iKeyA = new IoTString(buffer);
58 IoTString * iValueA = new IoTString(buffer);
60 sprintf(buffer, "b%d", i);
61 IoTString * iKeyB = new IoTString(buffer);
62 IoTString * iValueB = new IoTString(buffer);
64 sprintf(buffer, "c%d", i);
65 IoTString * iKeyC = new IoTString(buffer);
66 IoTString * iValueC = new IoTString(buffer);
68 sprintf(buffer, "d%d", i);
69 IoTString * iKeyD = new IoTString(buffer);
70 IoTString * iValueD = new IoTString(buffer);
72 t1->startTransaction();
73 t1->put(iKeyA, iValueA);
74 transStatusList->add(t1->commitTransaction());
76 iValueA->releaseRef();
78 t1->startTransaction();
79 t1->put(iKeyB, iValueB);
80 transStatusList->add(t1->commitTransaction());
82 iValueB->releaseRef();
84 t2->startTransaction();
85 t2->put(iKeyC, iValueC);
86 transStatusList->add(t2->commitTransaction());
88 iValueC->releaseRef();
90 t2->startTransaction();
91 t2->put(iKeyD, iValueD);
92 transStatusList->add(t2->commitTransaction());
94 iValueD->releaseRef();
97 printf("Updating Clients...\n");
101 printf("Checking Key-Values...\n");
102 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
104 sprintf(buffer, "a%d", i);
105 IoTString * iKeyA = new IoTString(buffer);
106 IoTString * iValueA = new IoTString(buffer);
108 sprintf(buffer, "b%d", i);
109 IoTString * iKeyB = new IoTString(buffer);
110 IoTString * iValueB = new IoTString(buffer);
112 sprintf(buffer, "c%d", i);
113 IoTString * iKeyC = new IoTString(buffer);
114 IoTString * iValueC = new IoTString(buffer);
116 sprintf(buffer, "d%d", i);
117 IoTString * iKeyD = new IoTString(buffer);
118 IoTString * iValueD = new IoTString(buffer);
120 IoTString *testValA1 = t1->getCommitted(iKeyA);
121 IoTString *testValB1 = t1->getCommitted(iKeyB);
122 IoTString *testValC1 = t1->getCommitted(iKeyC);
123 IoTString *testValD1 = t1->getCommitted(iKeyD);
125 IoTString *testValA2 = t2->getCommitted(iKeyA);
126 IoTString *testValB2 = t2->getCommitted(iKeyB);
127 IoTString *testValC2 = t2->getCommitted(iKeyC);
128 IoTString *testValD2 = t2->getCommitted(iKeyD);
130 if ((testValA1 == NULL) || (testValA1->equals(iValueA) == false)) {
131 printf("Key-Value t1 incorrect: keyA\n");
135 if ((testValB1 == NULL) || (testValB1->equals(iValueB) == false)) {
136 printf("Key-Value t1 incorrect: keyB\n");
140 if ((testValC1 == NULL) || (testValC1->equals(iValueC) == false)) {
141 printf("Key-Value t1 incorrect: keyC\n");
145 if ((testValD1 == NULL) || (testValD1->equals(iValueD) == false)) {
146 printf("Key-Value t1 incorrect: keyD\n");
150 if ((testValA2 == NULL) || (testValA2->equals(iValueA) == false)) {
151 printf("Key-Value t2 incorrect: keyA testValA2\n");
155 if ((testValB2 == NULL) || (testValB2->equals(iValueB) == false)) {
156 printf("Key-Value t2 incorrect: keyB testValB2\n");
160 if ((testValC2 == NULL) || (testValC2->equals(iValueC) == false)) {
161 printf("Key-Value t2 incorrect: keyC testValC2\n");
165 if ((testValD2 == NULL) || (testValD2->equals(iValueD) == false)) {
166 printf("Key-Value t2 incorrect: keyD testValD2\n");
170 iValueA->releaseRef();
172 iValueB->releaseRef();
174 iValueC->releaseRef();
176 iValueD->releaseRef();
177 testValA1->releaseRef();
178 testValA2->releaseRef();
179 testValB1->releaseRef();
180 testValB2->releaseRef();
181 testValC1->releaseRef();
182 testValC2->releaseRef();
183 testValD1->releaseRef();
184 testValD2->releaseRef();
187 for (uint i = 0; i < transStatusList->size(); i++) {
188 TransactionStatus * status = transStatusList->get(i);
189 if (status->getStatus() != TransactionStatus_StatusCommitted) {
191 printf("Status error\n");
197 printf("Found Errors...\n");
199 printf("No Errors Found...\n");
202 delete transStatusList;