#include "Table.h" #include "IoTString.h" #include "TimingSingleton.h" #include "TransactionStatus.h" #define NUMBER_OF_TESTS 2 int main(int numargs, char ** args) { TimingSingleton * timer = TimingSingleton_getInstance(); bool foundError = false; Vector * transStatusList = new Vector(); // Setup the 2 clients IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/"); IoTString * password = new IoTString("reallysecret"); Table * t1 = new Table(baseurl, password, 321, -1); t1->initTable(); printf("T1 Ready\n"); Table * t2 = new Table(baseurl, password, 351, -1); t2->update(); printf("T2 Ready\n"); baseurl->releaseRef(); password->releaseRef(); // Make the Keys printf("Setting up keys\n"); for (int i = 0; i < NUMBER_OF_TESTS; i++) { printf("%d\n",i); char buffer[80]; sprintf(buffer, "a%d", i); IoTString *ia = new IoTString(buffer); sprintf(buffer, "b%d", i); IoTString *ib = new IoTString(buffer); sprintf(buffer, "c%d", i); IoTString *ic = new IoTString(buffer); sprintf(buffer, "d%d", i); IoTString *id = new IoTString(buffer); t1->createNewKey(ia, 321); t1->createNewKey(ib, 351); t2->createNewKey(ic, 321); t2->createNewKey(id, 351); ia->releaseRef(); ib->releaseRef(); ic->releaseRef(); id->releaseRef(); } // Do Updates for the keys printf("Setting Key-Values...\n"); for (int i = 0; i < NUMBER_OF_TESTS; i++) { printf("%d\n", i); char buffer[80]; sprintf(buffer, "a%d", i); IoTString * iKeyA = new IoTString(buffer); IoTString * iValueA = new IoTString(buffer); sprintf(buffer, "b%d", i); IoTString * iKeyB = new IoTString(buffer); IoTString * iValueB = new IoTString(buffer); sprintf(buffer, "c%d", i); IoTString * iKeyC = new IoTString(buffer); IoTString * iValueC = new IoTString(buffer); sprintf(buffer, "d%d", i); IoTString * iKeyD = new IoTString(buffer); IoTString * iValueD = new IoTString(buffer); t1->startTransaction(); t1->put(iKeyA, iValueA); transStatusList->add(t1->commitTransaction()); iKeyA->releaseRef(); iValueA->releaseRef(); t1->startTransaction(); t1->put(iKeyB, iValueB); transStatusList->add(t1->commitTransaction()); iKeyB->releaseRef(); iValueB->releaseRef(); t2->startTransaction(); t2->put(iKeyC, iValueC); transStatusList->add(t2->commitTransaction()); iKeyC->releaseRef(); iValueC->releaseRef(); t2->startTransaction(); t2->put(iKeyD, iValueD); transStatusList->add(t2->commitTransaction()); iKeyD->releaseRef(); iValueD->releaseRef(); } printf("Updating Clients...\n"); t1->update(); t2->update(); printf("Checking Key-Values...\n"); for (int i = 0; i < NUMBER_OF_TESTS; i++) { char buffer[80]; sprintf(buffer, "a%d", i); IoTString * iKeyA = new IoTString(buffer); IoTString * iValueA = new IoTString(buffer); sprintf(buffer, "b%d", i); IoTString * iKeyB = new IoTString(buffer); IoTString * iValueB = new IoTString(buffer); sprintf(buffer, "c%d", i); IoTString * iKeyC = new IoTString(buffer); IoTString * iValueC = new IoTString(buffer); sprintf(buffer, "d%d", i); IoTString * iKeyD = new IoTString(buffer); IoTString * iValueD = new IoTString(buffer); IoTString *testValA1 = t1->getCommitted(iKeyA); IoTString *testValB1 = t1->getCommitted(iKeyB); IoTString *testValC1 = t1->getCommitted(iKeyC); IoTString *testValD1 = t1->getCommitted(iKeyD); IoTString *testValA2 = t2->getCommitted(iKeyA); IoTString *testValB2 = t2->getCommitted(iKeyB); IoTString *testValC2 = t2->getCommitted(iKeyC); IoTString *testValD2 = t2->getCommitted(iKeyD); if ((testValA1 == NULL) || (testValA1->equals(iValueA) == false)) { printf("Key-Value t1 incorrect: keyA\n"); foundError = true; } if ((testValB1 == NULL) || (testValB1->equals(iValueB) == false)) { printf("Key-Value t1 incorrect: keyB\n"); foundError = true; } if ((testValC1 == NULL) || (testValC1->equals(iValueC) == false)) { printf("Key-Value t1 incorrect: keyC\n"); foundError = true; } if ((testValD1 == NULL) || (testValD1->equals(iValueD) == false)) { printf("Key-Value t1 incorrect: keyD\n"); foundError = true; } if ((testValA2 == NULL) || (testValA2->equals(iValueA) == false)) { printf("Key-Value t2 incorrect: keyA testValA2\n"); foundError = true; } if ((testValB2 == NULL) || (testValB2->equals(iValueB) == false)) { printf("Key-Value t2 incorrect: keyB testValB2\n"); foundError = true; } if ((testValC2 == NULL) || (testValC2->equals(iValueC) == false)) { printf("Key-Value t2 incorrect: keyC testValC2\n"); foundError = true; } if ((testValD2 == NULL) || (testValD2->equals(iValueD) == false)) { printf("Key-Value t2 incorrect: keyD testValD2\n"); foundError = true; } iKeyA->releaseRef(); iValueA->releaseRef(); iKeyB->releaseRef(); iValueB->releaseRef(); iKeyC->releaseRef(); iValueC->releaseRef(); iKeyD->releaseRef(); iValueD->releaseRef(); testValA1->releaseRef(); testValA2->releaseRef(); testValB1->releaseRef(); testValB2->releaseRef(); testValC1->releaseRef(); testValC2->releaseRef(); testValD1->releaseRef(); testValD2->releaseRef(); } for (uint i = 0; i < transStatusList->size(); i++) { TransactionStatus * status = transStatusList->get(i); if (status->getStatus() != TransactionStatus_StatusCommitted) { foundError = true; printf("Status error\n"); } delete status; } if (foundError) { printf("Found Errors...\n"); } else { printf("No Errors Found...\n"); } delete transStatusList; delete t1; }