From b687de99dbbbae04564b9fe4aad3e159782b8a26 Mon Sep 17 00:00:00 2001 From: rtrimana Date: Mon, 16 Apr 2018 09:23:40 -0700 Subject: [PATCH] Adding files to initialize, update, and read key-value (to be used together with the PHOTON core version); SlotBuffer size is reduced to 4 slots per table for PHOTON. --- version2/src/C/Init.C | 58 ++++++++++++++++++++++++++++++++++ version2/src/C/Makefile | 4 +++ version2/src/C/Read.C | 62 +++++++++++++++++++++++++++++++++++++ version2/src/C/SlotBuffer.h | 2 +- version2/src/C/Update.C | 58 ++++++++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 version2/src/C/Init.C create mode 100644 version2/src/C/Read.C create mode 100644 version2/src/C/Update.C diff --git a/version2/src/C/Init.C b/version2/src/C/Init.C new file mode 100644 index 0000000..55cd2c6 --- /dev/null +++ b/version2/src/C/Init.C @@ -0,0 +1,58 @@ +#include "Table.h" +#include "IoTString.h" +#include "TimingSingleton.h" +#include "TransactionStatus.h" + +#define NUMBER_OF_SENSORS 1 +#define MACHINE_ID 260 + +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, MACHINE_ID, -1); + t1->initTable(); + //t1->rebuild(); + printf("T1 Ready\n"); + + baseurl->releaseRef(); + password->releaseRef(); + + // Make the Keys + printf("Setting up keys\n"); + for (int i = 0; i < NUMBER_OF_SENSORS; i++) { + printf("%d\n",i); + char buffer[80]; + sprintf(buffer, "sensor%d", i); + IoTString *ia = new IoTString(buffer); + t1->createNewKey(ia, MACHINE_ID); + ia->releaseRef(); + } + + t1->update(); + printf("Updating table\n"); + + 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; +} + diff --git a/version2/src/C/Makefile b/version2/src/C/Makefile index 199196e..5d4be5a 100644 --- a/version2/src/C/Makefile +++ b/version2/src/C/Makefile @@ -29,6 +29,10 @@ directories: ${OBJ_DIR} test: bin/lib_iotcloud.so g++ -g -O3 Test.C -L./bin/ -l_iotcloud -lpthread -lbsd -o bin/Test + g++ -g -O3 Init.C -L./bin/ -l_iotcloud -lpthread -lbsd -o bin/init + g++ -g -O3 Update.C -L./bin/ -l_iotcloud -lpthread -lbsd -o bin/update + g++ -g -O3 Read.C -L./bin/ -l_iotcloud -lpthread -lbsd -o bin/read + sudo cp ./bin/*.so /usr/lib/ ${OBJ_DIR}: ${MKDIR_P} ${OBJ_DIR} diff --git a/version2/src/C/Read.C b/version2/src/C/Read.C new file mode 100644 index 0000000..eff53aa --- /dev/null +++ b/version2/src/C/Read.C @@ -0,0 +1,62 @@ +#include "Table.h" +#include "IoTString.h" +#include "TimingSingleton.h" +#include "TransactionStatus.h" + +#define NUMBER_OF_TESTS 1 +#define MACHINE_ID 371 + +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, MACHINE_ID, -1); + //t1->initTable(); + t1->rebuild(); + printf("T1 Ready\n"); + + baseurl->releaseRef(); + password->releaseRef(); + + printf("Checking Key-Values...\n"); + char buffer[80]; + sprintf(buffer, "sensor0"); + IoTString * iKeyA = new IoTString(buffer); + IoTString *testValA1 = t1->getCommitted(iKeyA); + + if (testValA1 == NULL) { + printf("\n\nKEY-VALUE A is NULL!\n\n"); + foundError = true; + } else { + printf("Printing value... "); + testValA1->print(); + printf("\n\n"); + } + + iKeyA->releaseRef(); + testValA1->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; +} + diff --git a/version2/src/C/SlotBuffer.h b/version2/src/C/SlotBuffer.h index 0f6d625..6bb369d 100644 --- a/version2/src/C/SlotBuffer.h +++ b/version2/src/C/SlotBuffer.h @@ -9,7 +9,7 @@ * @version 1.0 */ -#define SlotBuffer_DEFAULT_SIZE 32 +#define SlotBuffer_DEFAULT_SIZE 4 class SlotBuffer { private: diff --git a/version2/src/C/Update.C b/version2/src/C/Update.C new file mode 100644 index 0000000..805cc8b --- /dev/null +++ b/version2/src/C/Update.C @@ -0,0 +1,58 @@ +#include "Table.h" +#include "IoTString.h" +#include "TimingSingleton.h" +#include "TransactionStatus.h" + +#define NUMBER_OF_SENSORS 1 +#define MACHINE_ID 260 + +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, MACHINE_ID, -1); + t1->rebuild(); + printf("T1 Ready\n"); + + baseurl->releaseRef(); + password->releaseRef(); + + /*char keyBuffer[80]; + char dataBuffer[80]; + + sprintf(keyBuffer, "sensor0"); + IoTString * iKeyA = new IoTString(keyBuffer); + sprintf(dataBuffer, "data1"); + IoTString * iValueA = new IoTString(dataBuffer); + t1->startTransaction(); + t1->put(iKeyA, iValueA); + transStatusList->add(t1->commitTransaction());*/ + t1->update(); + + //iKeyA->releaseRef(); + //iValueA->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; +} + -- 2.34.1