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);
42 // Do Updates for the keys
43 printf("Setting Key-Values...\n");
44 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
47 sprintf(buffer, "a%d", i);
48 IoTString * iKeyA = new IoTString(buffer);
49 IoTString * iValueA = new IoTString(buffer);
51 sprintf(buffer, "b%d", i);
52 IoTString * iKeyB = new IoTString(buffer);
53 IoTString * iValueB = new IoTString(buffer);
55 sprintf(buffer, "c%d", i);
56 IoTString * iKeyC = new IoTString(buffer);
57 IoTString * iValueC = new IoTString(buffer);
59 sprintf(buffer, "d%d", i);
60 IoTString * iKeyD = new IoTString(buffer);
61 IoTString * iValueD = new IoTString(buffer);
63 t1->startTransaction();
64 t1->addKV(iKeyA, iValueA);
65 transStatusList->add(t1->commitTransaction());
66 t1->startTransaction();
67 t1->addKV(iKeyB, iValueB);
68 transStatusList->add(t1->commitTransaction());
70 t2->startTransaction();
71 t2->addKV(iKeyC, iValueC);
72 transStatusList->add(t2->commitTransaction());
74 t2->startTransaction();
75 t2->addKV(iKeyD, iValueD);
76 transStatusList->add(t2->commitTransaction());
78 printf("Updating Clients...\n");
82 printf("Checking Key-Values...\n");
83 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
85 sprintf(buffer, "a%d", i);
86 IoTString * iKeyA = new IoTString(buffer);
87 IoTString * iValueA = new IoTString(buffer);
89 sprintf(buffer, "b%d", i);
90 IoTString * iKeyB = new IoTString(buffer);
91 IoTString * iValueB = new IoTString(buffer);
93 sprintf(buffer, "c%d", i);
94 IoTString * iKeyC = new IoTString(buffer);
95 IoTString * iValueC = new IoTString(buffer);
97 sprintf(buffer, "d%d", i);
98 IoTString * iKeyD = new IoTString(buffer);
99 IoTString * iValueD = new IoTString(buffer);
101 IoTString *testValA1 = t1->getCommitted(iKeyA);
102 IoTString *testValB1 = t1->getCommitted(iKeyB);
103 IoTString *testValC1 = t1->getCommitted(iKeyC);
104 IoTString *testValD1 = t1->getCommitted(iKeyD);
106 IoTString *testValA2 = t2->getCommitted(iKeyA);
107 IoTString *testValB2 = t2->getCommitted(iKeyB);
108 IoTString *testValC2 = t2->getCommitted(iKeyC);
109 IoTString *testValD2 = t2->getCommitted(iKeyD);
111 if ((testValA1 == NULL) || (testValA1->equals(iValueA) == false)) {
112 printf("Key-Value t1 incorrect: keyA\n");
116 if ((testValB1 == NULL) || (testValB1->equals(iValueB) == false)) {
117 printf("Key-Value t1 incorrect: keyB\n");
121 if ((testValC1 == NULL) || (testValC1->equals(iValueC) == false)) {
122 printf("Key-Value t1 incorrect: keyC\n");
126 if ((testValD1 == NULL) || (testValD1->equals(iValueD) == false)) {
127 printf("Key-Value t1 incorrect: keyD\n");
131 if ((testValA2 == NULL) || (testValA2->equals(iValueA) == false)) {
132 printf("Key-Value t2 incorrect: keyA testValA2\n");
136 if ((testValB2 == NULL) || (testValB2->equals(iValueB) == false)) {
137 printf("Key-Value t2 incorrect: keyB testValB2\n");
141 if ((testValC2 == NULL) || (testValC2->equals(iValueC) == false)) {
142 printf("Key-Value t2 incorrect: keyC testValC2\n");
146 if ((testValD2 == NULL) || (testValD2->equals(iValueD) == false)) {
147 printf("Key-Value t2 incorrect: keyD testValD2\n");
152 for (uint i = 0; i < transStatusList->size(); i++) {
153 TransactionStatus * status = transStatusList->get(i);
154 if (status->getStatus() != TransactionStatus_StatusCommitted) {
156 printf("Status error\n");
161 printf("Found Errors...\n");
163 printf("No Errors Found...\n");