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 Table * t1 = new Table(new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/"), new IoTString("reallysecret"), 321, -1);
19 Table * t2 = new Table(new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/"), new IoTString("reallysecret"), 351, -1);
24 printf("Setting up keys\n");
25 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
28 sprintf(buffer, "a%d", i);
29 IoTString *ia = new IoTString(buffer);
30 sprintf(buffer, "b%d", i);
31 IoTString *ib = new IoTString(buffer);
32 sprintf(buffer, "c%d", i);
33 IoTString *ic = new IoTString(buffer);
34 sprintf(buffer, "d%d", i);
35 IoTString *id = new IoTString(buffer);
36 t1->createNewKey(ia, 321);
37 t1->createNewKey(ib, 351);
38 t2->createNewKey(ic, 321);
39 t2->createNewKey(id, 351);
46 // Do Updates for the keys
47 printf("Setting Key-Values...\n");
48 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 sprintf(buffer, "c%d", i);
60 IoTString * iKeyC = new IoTString(buffer);
61 IoTString * iValueC = new IoTString(buffer);
63 sprintf(buffer, "d%d", i);
64 IoTString * iKeyD = new IoTString(buffer);
65 IoTString * iValueD = new IoTString(buffer);
67 t1->startTransaction();
68 t1->put(iKeyA, iValueA);
69 transStatusList->add(t1->commitTransaction());
70 delete iKeyA; delete iValueA;
72 t1->startTransaction();
73 t1->put(iKeyB, iValueB);
74 transStatusList->add(t1->commitTransaction());
75 delete iKeyB; delete iValueB;
77 t2->startTransaction();
78 t2->put(iKeyC, iValueC);
79 transStatusList->add(t2->commitTransaction());
80 delete iKeyC; delete iValueC;
82 t2->startTransaction();
83 t2->put(iKeyD, iValueD);
84 transStatusList->add(t2->commitTransaction());
85 delete iKeyD; delete iValueD;
88 printf("Updating Clients...\n");
92 printf("Checking Key-Values...\n");
93 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
95 sprintf(buffer, "a%d", i);
96 IoTString * iKeyA = new IoTString(buffer);
97 IoTString * iValueA = new IoTString(buffer);
99 sprintf(buffer, "b%d", i);
100 IoTString * iKeyB = new IoTString(buffer);
101 IoTString * iValueB = new IoTString(buffer);
103 sprintf(buffer, "c%d", i);
104 IoTString * iKeyC = new IoTString(buffer);
105 IoTString * iValueC = new IoTString(buffer);
107 sprintf(buffer, "d%d", i);
108 IoTString * iKeyD = new IoTString(buffer);
109 IoTString * iValueD = new IoTString(buffer);
111 IoTString *testValA1 = t1->getCommitted(iKeyA);
112 IoTString *testValB1 = t1->getCommitted(iKeyB);
113 IoTString *testValC1 = t1->getCommitted(iKeyC);
114 IoTString *testValD1 = t1->getCommitted(iKeyD);
116 IoTString *testValA2 = t2->getCommitted(iKeyA);
117 IoTString *testValB2 = t2->getCommitted(iKeyB);
118 IoTString *testValC2 = t2->getCommitted(iKeyC);
119 IoTString *testValD2 = t2->getCommitted(iKeyD);
121 if ((testValA1 == NULL) || (testValA1->equals(iValueA) == false)) {
122 printf("Key-Value t1 incorrect: keyA\n");
126 if ((testValB1 == NULL) || (testValB1->equals(iValueB) == false)) {
127 printf("Key-Value t1 incorrect: keyB\n");
131 if ((testValC1 == NULL) || (testValC1->equals(iValueC) == false)) {
132 printf("Key-Value t1 incorrect: keyC\n");
136 if ((testValD1 == NULL) || (testValD1->equals(iValueD) == false)) {
137 printf("Key-Value t1 incorrect: keyD\n");
141 if ((testValA2 == NULL) || (testValA2->equals(iValueA) == false)) {
142 printf("Key-Value t2 incorrect: keyA testValA2\n");
146 if ((testValB2 == NULL) || (testValB2->equals(iValueB) == false)) {
147 printf("Key-Value t2 incorrect: keyB testValB2\n");
151 if ((testValC2 == NULL) || (testValC2->equals(iValueC) == false)) {
152 printf("Key-Value t2 incorrect: keyC testValC2\n");
156 if ((testValD2 == NULL) || (testValD2->equals(iValueD) == false)) {
157 printf("Key-Value t2 incorrect: keyD testValD2\n");
160 delete iKeyA; delete iValueA;
161 delete iKeyB; delete iValueB;
162 delete iKeyC; delete iValueC;
163 delete iKeyD; delete iValueD;
164 delete testValA1; delete testValA2;
165 delete testValB1; delete testValB2;
166 delete testValC1; delete testValC2;
167 delete testValD1; delete testValD2;
170 for (uint i = 0; i < transStatusList->size(); i++) {
171 TransactionStatus * status = transStatusList->get(i);
172 if (status->getStatus() != TransactionStatus_StatusCommitted) {
174 printf("Status error\n");
179 printf("Found Errors...\n");
181 printf("No Errors Found...\n");
184 delete transStatusList;