void test_KineticClient_Delete_should_execute_DELETE_operation(void) { ByteArray key = ByteArray_CreateWithCString("some_key"); ByteArray tag = ByteArray_CreateWithCString("SomeTagValue"); KineticEntry entry = { .key = ByteBuffer_CreateWithArray(key), .tag = ByteBuffer_CreateWithArray(tag), }; KineticConnection_FromHandle_ExpectAndReturn(DummyHandle, &Connection); KineticAllocator_NewPDU_ExpectAndReturn(&Connection.pdus, &Request); KineticAllocator_NewPDU_ExpectAndReturn(&Connection.pdus, &Response); KineticPDU_Init_Expect(&Request, &Connection); KineticPDU_Init_Expect(&Response, &Connection); KineticConnection_IncrementSequence_Expect(&Connection); KineticMessage_ConfigureKeyValue_Expect(&Request.protoData.message, &entry); KineticPDU_Send_ExpectAndReturn(&Request, KINETIC_STATUS_SUCCESS); KineticPDU_Receive_ExpectAndReturn(&Response, KINETIC_STATUS_SUCCESS); KineticPDU_GetStatus_ExpectAndReturn(&Response, KINETIC_STATUS_SUCCESS); KineticAllocator_FreePDU_Expect(&Connection.pdus, &Request); KineticAllocator_FreePDU_Expect(&Connection.pdus, &Response); KineticStatus status = KineticClient_Delete(DummyHandle, &entry); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); }
void test_put_get_delete_one_entry_by_one_entry(void) { uint8_t version_data[DEFAULT_BUFFER_SIZE], tag_data[DEFAULT_BUFFER_SIZE], value_data[DEFAULT_BUFFER_SIZE]; ByteBuffer version_buffer, tag_buffer, value_buffer; version_buffer = ByteBuffer_CreateAndAppendCString(version_data, sizeof(version_data), "v1.0"); ExpectedVersionBuffer = ByteBuffer_CreateAndAppendCString(version_data, sizeof(version_data), "v1.0"); tag_buffer = ByteBuffer_CreateAndAppendCString(tag_data, sizeof(tag_data), "SomeTagValue"); ExpectedTagBuffer = ByteBuffer_CreateAndAppendCString(tag_data, sizeof(tag_data), "SomeTagValue"); value_buffer = ByteBuffer_Create(value_data, DEFAULT_BUFFER_SIZE, 0); unsigned int i; for (i=0; i<KV_PAIRS_PER_GROUP; i++) { // put object KineticEntry putEntry = { .key = generate_entry_key_by_index(i), .tag = tag_buffer, .newVersion = version_buffer, .algorithm = KINETIC_ALGORITHM_SHA1, .value = generate_entry_value_by_index(i), .force = true, .synchronization = KINETIC_SYNCHRONIZATION_WRITETHROUGH, }; KineticStatus status = KineticClient_Put(Fixture.session, &putEntry, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); ByteBuffer_Reset(&value_buffer); // get object value_buffer = ByteBuffer_Create(value_data, DEFAULT_BUFFER_SIZE, 0); KineticEntry getEntry = { .key = generate_entry_key_by_index(i), .dbVersion = version_buffer, .tag = tag_buffer, .value = value_buffer, }; status = KineticClient_Get(Fixture.session, &getEntry, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); TEST_ASSERT_EQUAL_ByteBuffer(ExpectedVersionBuffer, getEntry.dbVersion); TEST_ASSERT_ByteBuffer_NULL(getEntry.newVersion); TEST_ASSERT_EQUAL_ByteBuffer(generate_entry_key_by_index(i), getEntry.key); TEST_ASSERT_EQUAL_ByteBuffer(ExpectedTagBuffer, getEntry.tag); TEST_ASSERT_EQUAL(KINETIC_ALGORITHM_SHA1, getEntry.algorithm); TEST_ASSERT_EQUAL_ByteBuffer(generate_entry_value_by_index(i), getEntry.value); TEST_ASSERT_EQUAL_ByteBuffer(ExpectedVersionBuffer, version_buffer); // delete object KineticEntry deleteEntry = { .key = generate_entry_key_by_index(i), .dbVersion = version_buffer, }; TEST_ASSERT_EQUAL_ByteBuffer(ExpectedVersionBuffer, version_buffer); status = KineticClient_Delete(Fixture.session, &deleteEntry, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); TEST_ASSERT_EQUAL(0, deleteEntry.value.bytesUsed); // get object again status = KineticClient_Get(Fixture.session, &getEntry, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_NOT_FOUND, status); } } void test_put_get_delete_one_group_by_one_group(void) { uint8_t version_data[DEFAULT_BUFFER_SIZE], tag_data[DEFAULT_BUFFER_SIZE], value_data[DEFAULT_BUFFER_SIZE]; ByteBuffer version_buffer, tag_buffer, value_buffer; version_buffer = ByteBuffer_CreateAndAppendCString(version_data, sizeof(version_data), "v1.0"); ExpectedVersionBuffer = ByteBuffer_CreateAndAppendCString(version_data, sizeof(version_data), "v1.0"); tag_buffer = ByteBuffer_CreateAndAppendCString(tag_data, sizeof(tag_data), "SomeTagValue"); ExpectedTagBuffer = ByteBuffer_CreateAndAppendCString(tag_data, sizeof(tag_data), "SomeTagValue"); value_buffer = ByteBuffer_Create(value_data, DEFAULT_BUFFER_SIZE, 0); unsigned int i, j; for (i =0; i<TOTAL_GROUPS; i++) { KineticStatus status; // put a group of entries for (j=0; j<KV_PAIRS_PER_GROUP; j++) { KineticEntry putEntry = { .key = generate_entry_key_by_index(i*KV_PAIRS_PER_GROUP + j), .tag = tag_buffer, .newVersion = version_buffer, .algorithm = KINETIC_ALGORITHM_SHA1, .value = generate_entry_value_by_index(i*KV_PAIRS_PER_GROUP + j), .force = true, .synchronization = KINETIC_SYNCHRONIZATION_WRITETHROUGH, }; status = KineticClient_Put(Fixture.session, &putEntry, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); } // get key_range KineticKeyRange range = { .startKey = generate_entry_key_by_index(i*KV_PAIRS_PER_GROUP), .endKey = generate_entry_key_by_index(i*KV_PAIRS_PER_GROUP + KV_PAIRS_PER_GROUP -1), .startKeyInclusive = true, .endKeyInclusive = true, .maxReturned = KV_PAIRS_PER_GROUP, }; ByteBuffer keyBuff[KV_PAIRS_PER_GROUP]; uint8_t keysData[KV_PAIRS_PER_GROUP][DEFAULT_BUFFER_SIZE]; for (j = 0; j < KV_PAIRS_PER_GROUP; j++) { memset(&keysData[j], 0, DEFAULT_BUFFER_SIZE); keyBuff[j] = ByteBuffer_Create(&keysData[j], DEFAULT_BUFFER_SIZE, 0); } ByteBufferArray keys = {.buffers = keyBuff, .count = KV_PAIRS_PER_GROUP, .used = 0}; status = KineticClient_GetKeyRange(Fixture.session, &range, &keys, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); TEST_ASSERT_EQUAL(KV_PAIRS_PER_GROUP, keys.used); for (j = 0; j < KV_PAIRS_PER_GROUP; j++) { TEST_ASSERT_EQUAL_ByteBuffer(generate_entry_key_by_index(i*KV_PAIRS_PER_GROUP + j), keys.buffers[j]); } // delete a group of entries for (j=0; j<KV_PAIRS_PER_GROUP; j++) { ByteBuffer_Reset(&value_buffer); // get object value_buffer = ByteBuffer_Create(value_data, DEFAULT_BUFFER_SIZE, 0); KineticEntry getEntry = { .key = generate_entry_key_by_index(i*KV_PAIRS_PER_GROUP + j), .dbVersion = version_buffer, .tag = tag_buffer, .value = value_buffer, }; status = KineticClient_Get(Fixture.session, &getEntry, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); TEST_ASSERT_EQUAL_ByteBuffer(ExpectedVersionBuffer, getEntry.dbVersion); TEST_ASSERT_ByteBuffer_NULL(getEntry.newVersion); TEST_ASSERT_EQUAL_ByteBuffer(generate_entry_key_by_index(i*KV_PAIRS_PER_GROUP + j), getEntry.key); TEST_ASSERT_EQUAL_ByteBuffer(ExpectedTagBuffer, getEntry.tag); TEST_ASSERT_EQUAL(KINETIC_ALGORITHM_SHA1, getEntry.algorithm); TEST_ASSERT_EQUAL_ByteBuffer(generate_entry_value_by_index(i*KV_PAIRS_PER_GROUP + j), getEntry.value); TEST_ASSERT_EQUAL_ByteBuffer(ExpectedVersionBuffer, version_buffer); } // delete a group of entries for (j=0; j<KV_PAIRS_PER_GROUP; j++) { // delete object KineticEntry deleteEntry = { .key = generate_entry_key_by_index(i*KV_PAIRS_PER_GROUP + j), .dbVersion = version_buffer, }; TEST_ASSERT_EQUAL_ByteBuffer(ExpectedVersionBuffer, version_buffer); status = KineticClient_Delete(Fixture.session, &deleteEntry, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); TEST_ASSERT_EQUAL(0, deleteEntry.value.bytesUsed); // get object again ByteBuffer_Reset(&value_buffer); // get object value_buffer = ByteBuffer_Create(value_data, DEFAULT_BUFFER_SIZE, 0); KineticEntry getEntry = { .key = generate_entry_key_by_index(i*KV_PAIRS_PER_GROUP + j), .dbVersion = version_buffer, .tag = tag_buffer, .value = value_buffer, }; status = KineticClient_Get(Fixture.session, &getEntry, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_NOT_FOUND, status); } } }
void test_Flush_should_flush_pending_PUTs_and_DELETEs(void) { // Arguments shared between entries uint8_t TagData[1024]; ByteBuffer tagBuffer = ByteBuffer_CreateAndAppendCString(TagData, sizeof(TagData), "tag_val"); uint8_t key1[10]; ByteBuffer keyBuffer1 = ByteBuffer_CreateAndAppendCString(key1, sizeof(key1), "key1"); uint8_t value1[10]; ByteBuffer valueBuffer1 = ByteBuffer_CreateAndAppendCString(value1, sizeof(value1), "value1"); uint8_t key2[10]; ByteBuffer keyBuffer2 = ByteBuffer_CreateAndAppendCString(key2, sizeof(key2), "key2"); uint8_t value2[10]; ByteBuffer valueBuffer2 = ByteBuffer_CreateAndAppendCString(value2, sizeof(value2), "value2"); // Do a blocking PUT ("key1" => "value1") so we can delete it later KineticEntry Entry = (KineticEntry) { .key = keyBuffer1, .tag = tagBuffer, .algorithm = KINETIC_ALGORITHM_SHA1, .value = valueBuffer1, .synchronization = KINETIC_SYNCHRONIZATION_WRITEBACK, .force = true, }; KineticStatus status = KineticClient_Put(Fixture.session, &Entry, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); Entry = (KineticEntry) { .key = keyBuffer2, .tag = tagBuffer, .algorithm = KINETIC_ALGORITHM_SHA1, .value = valueBuffer2, .synchronization = KINETIC_SYNCHRONIZATION_WRITEBACK, .force = true, }; status = KineticClient_Put(Fixture.session, &Entry, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); // Do an async DELETE so we can flush to complete it KineticEntry deleteEntry = { .key = keyBuffer1, .synchronization = KINETIC_SYNCHRONIZATION_WRITETHROUGH, }; KineticCompletionClosure no_op_closure = { .callback = &no_op_callback, }; status = KineticClient_Delete(Fixture.session, &deleteEntry, &no_op_closure); /* Now do a blocking flush and confirm that (key1,value1) has been * DELETEd and (key2,value2) have been PUT. */ status = KineticClient_Flush(Fixture.session, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); // GET key1 --> expect NOT FOUND KineticEntry getEntry1 = { .key = keyBuffer1, .tag = tagBuffer, .value = valueBuffer1, }; status = KineticClient_Get(Fixture.session, &getEntry1, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_NOT_FOUND, status); // GET key2 --> present KineticEntry getEntry2 = { .key = keyBuffer2, .tag = tagBuffer, .value = valueBuffer2, }; status = KineticClient_Get(Fixture.session, &getEntry2, NULL); TEST_ASSERT_EQUAL_KineticStatus(KINETIC_STATUS_SUCCESS, status); }
KineticStatus ExecuteOperation( struct UtilConfig * cfg) { KineticStatus status = KINETIC_STATUS_INVALID; KineticLogInfo * logInfo; ByteArray tmpArray; switch (cfg->opID) { case OPT_NOOP: status = KineticClient_NoOp(cfg->session); if (status == KINETIC_STATUS_SUCCESS) { printf("NoOp operation completed successfully." " Kinetic Device is alive and well!\n"); } break; case OPT_PUT: status = KineticClient_Put(cfg->session, &cfg->entry, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("Put operation completed successfully." " Your data has been stored!\n"); PrintEntry(&cfg->entry); } break; case OPT_GET: status = KineticClient_Get(cfg->session, &cfg->entry, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("Get executed successfully.\n"); PrintEntry(&cfg->entry); } break; case OPT_GETNEXT: status = KineticClient_GetNext(cfg->session, &cfg->entry, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("GetNext executed successfully.\n"); PrintEntry(&cfg->entry); } break; case OPT_GETPREVIOUS: status = KineticClient_GetPrevious(cfg->session, &cfg->entry, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("GetPrevious executed successfully.\n"); PrintEntry(&cfg->entry); } break; case OPT_DELETE: status = KineticClient_Delete(cfg->session, &cfg->entry, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("Delete executed successfully. The entry has been destroyed!\n"); PrintEntry(&cfg->entry); } break; case OPT_GETLOG: status = KineticAdminClient_GetLog(cfg->adminSession, cfg->logType, &logInfo, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("GetLog executed successfully.\n" "The device log info has been retrieved!\n"); PrintLogInfo(cfg->logType, logInfo); } break; case OPT_GETDEVICESPECIFICLOG: if (strlen(cfg->deviceLogName) == 0) { fprintf(stderr, "Device-specific log type requires '--devicelogname' to be set!\n"); exit(1); } tmpArray.data = (uint8_t*)cfg->deviceLogName; tmpArray.len = strlen(cfg->deviceLogName); status = KineticAdminClient_GetDeviceSpecificLog(cfg->adminSession, tmpArray, &logInfo, NULL); if (status == KINETIC_STATUS_SUCCESS) { printf("GetDeviceSpecificLog executed successfully." "The device-specific device log info has been retrieved!\n"); printf("Device-Specific Log Info:\n"); char* dev = calloc(1, logInfo->device->name.len + 1); memcpy(dev, logInfo->device->name.data, logInfo->device->name.len); printf(" %s\n", dev); free(dev); } else if (status == KINETIC_STATUS_NOT_FOUND) { fprintf(stderr, "The specified device-specific log '%s' was not found on the device!\n", cfg->deviceLogName); status = KINETIC_STATUS_SUCCESS; } break; case OPT_SETERASEPIN: status = KineticAdminClient_SetErasePin(cfg->adminSession, ByteArray_Create(cfg->pin, strlen(cfg->pin)), ByteArray_Create(cfg->newPin, strlen(cfg->newPin))); if (status == KINETIC_STATUS_SUCCESS) { printf("SetErasePin executed successfully.\n" "The kinetic device erase pin has been changed!\n"); } break; case OPT_INSTANTERASE: status = KineticAdminClient_InstantErase(cfg->adminSession, ByteArray_Create(cfg->pin, strlen(cfg->pin))); if (status == KINETIC_STATUS_SUCCESS) { printf("InstantErase executed successfully.\n" "The kinetic device has been erased!\n"); } break; case OPT_SECUREERASE: status = KineticAdminClient_SecureErase(cfg->adminSession, ByteArray_Create(cfg->pin, strlen(cfg->pin))); if (status == KINETIC_STATUS_SUCCESS) { printf("SecureErase executed successfully.\n" "The kinetic device has been erased!\n"); } break; case OPT_SETLOCKPIN: status = KineticAdminClient_SetLockPin(cfg->adminSession, ByteArray_Create(cfg->pin, strlen(cfg->pin)), ByteArray_Create(cfg->newPin, strlen(cfg->newPin))); if (status == KINETIC_STATUS_SUCCESS) { printf("SetLockPin executed successfully.\n" "The kinetic device lock/unlock pin has been changed!\n"); } break; case OPT_LOCKDEVICE: status = KineticAdminClient_LockDevice(cfg->adminSession, ByteArray_Create(cfg->pin, strlen(cfg->pin))); if (status == KINETIC_STATUS_SUCCESS) { printf("LockDevice executed successfully.\n" "The kinetic device is now locked!\n"); } break; case OPT_UNLOCKDEVICE: status = KineticAdminClient_UnlockDevice(cfg->adminSession, ByteArray_Create(cfg->pin, strlen(cfg->pin))); if (status == KINETIC_STATUS_SUCCESS) { printf("UnlockDevice executed successfully.\n" "The kinetic device is now unlocked!\n"); } break; case OPT_SETCLUSTERVERSION: status = KineticAdminClient_SetClusterVersion(cfg->adminSession, cfg->newClusterVersion); if (status == KINETIC_STATUS_SUCCESS) { printf("SetClusterVersion executed successfully.\n" "The kinetic device's cluster version has been updated!\n"); } break; case OPT_SETACL: status = KineticAdminClient_SetACL(cfg->adminSession, cfg->file); if (status == KINETIC_STATUS_SUCCESS) { printf("SetACL executed successfully.\n" "The kinetic device ACLs have been replaced!\n"); } break; case OPT_UPDATEFIRMWARE: status = KineticAdminClient_UpdateFirmware(cfg->session, cfg->file); if (status == KINETIC_STATUS_SUCCESS) { printf("SecureErase executed successfully.\n" "The kinetic device has been restored to empty status!\n"); } break; default: fprintf(stderr, "Specified operation '%d' is invalid!\n", (int)cfg->opID); exit(-1); }; // Print out status code description if operation was not successful if (status != KINETIC_STATUS_SUCCESS) { fprintf(stderr, "\nERROR: Operation '%s' failed with status '%s'\n", GetOptString(cfg->opID), Kinetic_GetStatusDescription(status)); } return status; }