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 delete baseurl; delete password;
28 printf("Setting up keys\n");
29 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
32 sprintf(buffer, "a%d", i);
33 IoTString *ia = new IoTString(buffer);
34 sprintf(buffer, "b%d", i);
35 IoTString *ib = new IoTString(buffer);
36 sprintf(buffer, "c%d", i);
37 IoTString *ic = new IoTString(buffer);
38 sprintf(buffer, "d%d", i);
39 IoTString *id = new IoTString(buffer);
40 t1->createNewKey(ia, 321);
41 t1->createNewKey(ib, 351);
42 t2->createNewKey(ic, 321);
43 t2->createNewKey(id, 351);
50 // Do Updates for the keys
51 printf("Setting Key-Values...\n");
52 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
55 sprintf(buffer, "a%d", i);
56 IoTString * iKeyA = new IoTString(buffer);
57 IoTString * iValueA = new IoTString(buffer);
59 sprintf(buffer, "b%d", i);
60 IoTString * iKeyB = new IoTString(buffer);
61 IoTString * iValueB = new IoTString(buffer);
63 sprintf(buffer, "c%d", i);
64 IoTString * iKeyC = new IoTString(buffer);
65 IoTString * iValueC = new IoTString(buffer);
67 sprintf(buffer, "d%d", i);
68 IoTString * iKeyD = new IoTString(buffer);
69 IoTString * iValueD = new IoTString(buffer);
71 t1->startTransaction();
72 t1->put(iKeyA, iValueA);
73 transStatusList->add(t1->commitTransaction());
74 delete iKeyA; delete iValueA;
76 t1->startTransaction();
77 t1->put(iKeyB, iValueB);
78 transStatusList->add(t1->commitTransaction());
79 delete iKeyB; delete iValueB;
81 t2->startTransaction();
82 t2->put(iKeyC, iValueC);
83 transStatusList->add(t2->commitTransaction());
84 delete iKeyC; delete iValueC;
86 t2->startTransaction();
87 t2->put(iKeyD, iValueD);
88 transStatusList->add(t2->commitTransaction());
89 delete iKeyD; delete iValueD;
92 printf("Updating Clients...\n");
96 printf("Checking Key-Values...\n");
97 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
99 sprintf(buffer, "a%d", i);
100 IoTString * iKeyA = new IoTString(buffer);
101 IoTString * iValueA = new IoTString(buffer);
103 sprintf(buffer, "b%d", i);
104 IoTString * iKeyB = new IoTString(buffer);
105 IoTString * iValueB = new IoTString(buffer);
107 sprintf(buffer, "c%d", i);
108 IoTString * iKeyC = new IoTString(buffer);
109 IoTString * iValueC = new IoTString(buffer);
111 sprintf(buffer, "d%d", i);
112 IoTString * iKeyD = new IoTString(buffer);
113 IoTString * iValueD = new IoTString(buffer);
115 IoTString *testValA1 = t1->getCommitted(iKeyA);
116 IoTString *testValB1 = t1->getCommitted(iKeyB);
117 IoTString *testValC1 = t1->getCommitted(iKeyC);
118 IoTString *testValD1 = t1->getCommitted(iKeyD);
120 IoTString *testValA2 = t2->getCommitted(iKeyA);
121 IoTString *testValB2 = t2->getCommitted(iKeyB);
122 IoTString *testValC2 = t2->getCommitted(iKeyC);
123 IoTString *testValD2 = t2->getCommitted(iKeyD);
125 if ((testValA1 == NULL) || (testValA1->equals(iValueA) == false)) {
126 printf("Key-Value t1 incorrect: keyA\n");
130 if ((testValB1 == NULL) || (testValB1->equals(iValueB) == false)) {
131 printf("Key-Value t1 incorrect: keyB\n");
135 if ((testValC1 == NULL) || (testValC1->equals(iValueC) == false)) {
136 printf("Key-Value t1 incorrect: keyC\n");
140 if ((testValD1 == NULL) || (testValD1->equals(iValueD) == false)) {
141 printf("Key-Value t1 incorrect: keyD\n");
145 if ((testValA2 == NULL) || (testValA2->equals(iValueA) == false)) {
146 printf("Key-Value t2 incorrect: keyA testValA2\n");
150 if ((testValB2 == NULL) || (testValB2->equals(iValueB) == false)) {
151 printf("Key-Value t2 incorrect: keyB testValB2\n");
155 if ((testValC2 == NULL) || (testValC2->equals(iValueC) == false)) {
156 printf("Key-Value t2 incorrect: keyC testValC2\n");
160 if ((testValD2 == NULL) || (testValD2->equals(iValueD) == false)) {
161 printf("Key-Value t2 incorrect: keyD testValD2\n");
164 delete iKeyA; delete iValueA;
165 delete iKeyB; delete iValueB;
166 delete iKeyC; delete iValueC;
167 delete iKeyD; delete iValueD;
168 delete testValA1; delete testValA2;
169 delete testValB1; delete testValB2;
170 delete testValC1; delete testValC2;
171 delete testValD1; delete testValD2;
174 for (uint i = 0; i < transStatusList->size(); i++) {
175 TransactionStatus * status = transStatusList->get(i);
176 if (status->getStatus() != TransactionStatus_StatusCommitted) {
178 printf("Status error\n");
183 printf("Found Errors...\n");
185 printf("No Errors Found...\n");
188 delete transStatusList;