Loading test/support/system_test_kv_generate.c +2 −2 Original line number Diff line number Diff line Loading @@ -30,13 +30,13 @@ static const char VALUE_PREFIX[] = "my_value"; ByteBuffer generate_entry_key_by_index(uint32_t index) { char* key = malloc(MAX_SIZE); return ByteBuffer_CreateAndAppendFormattedCString(key, MAX_SIZE, "%s%d",KEY_PREFIX, index); return ByteBuffer_CreateAndAppendFormattedCString(key, MAX_SIZE, "%s%10d",KEY_PREFIX, index); } ByteBuffer generate_entry_value_by_index(uint32_t index) { char* value = malloc(MAX_SIZE); return ByteBuffer_CreateAndAppendFormattedCString(value, MAX_SIZE, "%s%d",VALUE_PREFIX, index); return ByteBuffer_CreateAndAppendFormattedCString(value, MAX_SIZE, "%s%10d",VALUE_PREFIX, index); } ByteBuffer get_generated_value_by_key(ByteBuffer* key) Loading test/system/test_system_put_get_delete_mix.c 0 → 100644 +218 −0 Original line number Diff line number Diff line /* * kinetic-c * Copyright (C) 2015 Seagate Technology. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include "system_test_fixture.h" #include "kinetic_client.h" #include "system_test_kv_generate.h" static const unsigned int KV_PAIRS_PER_GROUP = 9; static const unsigned int TOTAL_GROUPS = 10; static const int DEFAULT_BUFFER_SIZE = 1024; static ByteBuffer ExpectedTagBuffer; static ByteBuffer ExpectedVersionBuffer; void setUp(void) { SystemTestSetup(1, true); } void tearDown(void) { SystemTestShutDown(); } 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); } } } Loading
test/support/system_test_kv_generate.c +2 −2 Original line number Diff line number Diff line Loading @@ -30,13 +30,13 @@ static const char VALUE_PREFIX[] = "my_value"; ByteBuffer generate_entry_key_by_index(uint32_t index) { char* key = malloc(MAX_SIZE); return ByteBuffer_CreateAndAppendFormattedCString(key, MAX_SIZE, "%s%d",KEY_PREFIX, index); return ByteBuffer_CreateAndAppendFormattedCString(key, MAX_SIZE, "%s%10d",KEY_PREFIX, index); } ByteBuffer generate_entry_value_by_index(uint32_t index) { char* value = malloc(MAX_SIZE); return ByteBuffer_CreateAndAppendFormattedCString(value, MAX_SIZE, "%s%d",VALUE_PREFIX, index); return ByteBuffer_CreateAndAppendFormattedCString(value, MAX_SIZE, "%s%10d",VALUE_PREFIX, index); } ByteBuffer get_generated_value_by_key(ByteBuffer* key) Loading
test/system/test_system_put_get_delete_mix.c 0 → 100644 +218 −0 Original line number Diff line number Diff line /* * kinetic-c * Copyright (C) 2015 Seagate Technology. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #include "system_test_fixture.h" #include "kinetic_client.h" #include "system_test_kv_generate.h" static const unsigned int KV_PAIRS_PER_GROUP = 9; static const unsigned int TOTAL_GROUPS = 10; static const int DEFAULT_BUFFER_SIZE = 1024; static ByteBuffer ExpectedTagBuffer; static ByteBuffer ExpectedVersionBuffer; void setUp(void) { SystemTestSetup(1, true); } void tearDown(void) { SystemTestShutDown(); } 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); } } }