Fixing initialization to just create a table on the cloud side.
[iotcloud.git] / version2 / src / C / Read.C
1 #include "Table.h"
2 #include "IoTString.h"
3 #include "TimingSingleton.h"
4 #include "TransactionStatus.h"
5
6 #define NUMBER_OF_TESTS 1
7 #define MACHINE_ID 371
8
9 int main(int numargs, char ** args) {
10         TimingSingleton * timer = TimingSingleton_getInstance();
11
12         bool foundError = false;
13         Vector<TransactionStatus *> * transStatusList = new Vector<TransactionStatus *>();
14
15         // Setup the 2 clients
16         IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/");
17         IoTString * password = new IoTString("reallysecret");
18         Table * t1 = new Table(baseurl, password, MACHINE_ID, -1);
19         //t1->initTable();
20         t1->rebuild();
21         printf("T1 Ready\n");
22
23         baseurl->releaseRef();
24         password->releaseRef();
25
26         printf("Checking Key-Values...\n");
27         char buffer[80];
28         sprintf(buffer, "humid0");
29         IoTString * iKeyA = new IoTString(buffer);
30         IoTString *testValA1 = t1->getCommitted(iKeyA);
31         
32         if (testValA1 == NULL) {
33                 printf("\n\nKEY-VALUE A is NULL!\n\n");
34                 foundError = true;
35         } else {
36                 printf("Printing value... ");
37                 testValA1->print();
38                 printf("\n\n");
39         }
40         sprintf(buffer, "tempF0");
41         IoTString * iKeyB = new IoTString(buffer);
42         IoTString * testValB1 = t1->getCommitted(iKeyB);
43         
44         if (testValA1 == NULL) {
45                 printf("\n\nKEY-VALUE B is NULL!\n\n");
46                 foundError = true;
47         } else {
48                 printf("Printing value... ");
49                 testValB1->print();
50                 printf("\n\n");
51         }
52
53         iKeyA->releaseRef();
54         testValA1->releaseRef();
55         iKeyB->releaseRef();
56         testValB1->releaseRef();
57
58         for (uint i = 0; i < transStatusList->size(); i++) {
59                 TransactionStatus * status = transStatusList->get(i);
60                 if (status->getStatus() != TransactionStatus_StatusCommitted) {
61                         foundError = true;
62                         printf("Status error\n");
63                 }
64                 delete status;
65         }
66         
67         if (foundError) {
68                 printf("Found Errors...\n");
69         } else {
70                 printf("No Errors Found...\n");
71         }
72
73         delete transStatusList;
74         delete t1;
75 }
76