#include "Table.h"
+#include "IoTString.h"
+#include "TimingSingleton.h"
+#include "TransactionStatus.h"
+
+#define NUMBER_OF_TESTS 2
int main(int numargs, char ** args) {
- Table * t = new Table(NULL, NULL, 0, 0);
- delete t;
+ TimingSingleton * timer = TimingSingleton_getInstance();
+
+ bool foundError = false;
+ Vector<TransactionStatus *> * transStatusList = new Vector<TransactionStatus *>();
+
+ // Setup the 2 clients
+ Table * t1 = new Table(new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/"), new IoTString("reallysecret"), 321, -1);
+ t1->initTable();
+ printf("T1 Ready\n");
+
+ Table * t2 = new Table(new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/"), new IoTString("reallysecret"), 351, -1);
+ t2->update();
+ printf("T2 Ready\n");
+
+ // 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);
+ }
+
+ // 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->addKV(iKeyA, iValueA);
+ transStatusList->add(t1->commitTransaction());
+ t1->startTransaction();
+ t1->addKV(iKeyB, iValueB);
+ transStatusList->add(t1->commitTransaction());
+
+ t2->startTransaction();
+ t2->addKV(iKeyC, iValueC);
+ transStatusList->add(t2->commitTransaction());
+
+ t2->startTransaction();
+ t2->addKV(iKeyD, iValueD);
+ transStatusList->add(t2->commitTransaction());
+ }
+ 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;
+ }
+ }
+
+ for (uint i = 0; i < transStatusList->size(); i++) {
+ TransactionStatus * status = transStatusList->get(i);
+ if (status->getStatus() != TransactionStatus_StatusCommitted) {
+ foundError = true;
+ printf("Status error\n");
+ }
+ }
+
+ if (foundError) {
+ printf("Found Errors...\n");
+ } else {
+ printf("No Errors Found...\n");
+ }
}
+