#include "Table.h" #include "IoTString.h" #include "TimingSingleton.h" #include "TransactionStatus.h" #define NUMBER_OF_TESTS 2 TimingSingleton *timer; bool foundError; MyVector * transStatusList; Table *t1; void setup() { // TODO: This test uses the Serial library // Please install "screen" on your machine and run // it on the serial port right after flashing the // firmware onto the Particle board. // e.g. sudo screen /dev/ttyACM0 Serial.begin(); timer = TimingSingleton_getInstance(); foundError = false; transStatusList = new MyVector(); IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/"); IoTString * password = new IoTString("reallysecret"); t1 = new Table(baseurl, password, 321, -1); t1->initTable(); Serial.println("Finished table init..."); baseurl->releaseRef(); password->releaseRef(); // Make the Keys for (int i = 0; i < NUMBER_OF_TESTS; i++) { char buffer[80]; sprintf(buffer, "a%d", i); IoTString *ia = new IoTString(buffer); sprintf(buffer, "b%d", i); IoTString *ib = new IoTString(buffer); t1->createNewKey(ia, 321); t1->createNewKey(ib, 321); ia->releaseRef(); ib->releaseRef(); } Serial.println("Finished key generation..."); } void loop() { // Do Updates for the keys 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); 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(); Serial.println("Added new transaction: "); Serial.print("a"); Serial.println(i); Serial.print("b"); Serial.println(i); } t1->update(); Serial.println("Updated table..."); 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); IoTString *testValA1 = t1->getCommitted(iKeyA); IoTString *testValB1 = t1->getCommitted(iKeyB); if ((testValA1 == NULL) || (testValA1->equals(iValueA) == false)) { Serial.println("Key-Value t1 incorrect: keyA"); foundError = true; } if ((testValB1 == NULL) || (testValB1->equals(iValueB) == false)) { Serial.println("Key-Value t1 incorrect: keyB"); foundError = true; } iKeyA->releaseRef(); iValueA->releaseRef(); iKeyB->releaseRef(); iValueB->releaseRef(); testValA1->releaseRef(); testValB1->releaseRef(); } for (uint i = 0; i < transStatusList->size(); i++) { TransactionStatus * status = transStatusList->get(i); if (status->getStatus() != TransactionStatus_StatusCommitted) { foundError = true; Serial.println("Status error"); } delete status; } if (foundError) { Serial.println("Found Errors..."); } delete transStatusList; delete t1; Serial.println("Process done... now waiting..."); while(true) { } }