Adding files to initialize, update, and read key-value (to be used together with...
[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, "sensor0");
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
41         iKeyA->releaseRef();
42         testValA1->releaseRef();
43
44         for (uint i = 0; i < transStatusList->size(); i++) {
45                 TransactionStatus * status = transStatusList->get(i);
46                 if (status->getStatus() != TransactionStatus_StatusCommitted) {
47                         foundError = true;
48                         printf("Status error\n");
49                 }
50                 delete status;
51         }
52         
53         if (foundError) {
54                 printf("Found Errors...\n");
55         } else {
56                 printf("No Errors Found...\n");
57         }
58
59         delete transStatusList;
60         delete t1;
61 }
62