Commit c5dceabe authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

finished testing the list-keys feature

parent 7ebaa3ea
......@@ -9,7 +9,8 @@ bin_PROGRAMS = bin/sdskv-server-daemon \
bin/sdskv-shutdown \
test/sdskv-open-test \
test/sdskv-put-test \
test/sdskv-get-test
test/sdskv-get-test \
test/sdskv-list-keys-test
bin_sdskv_server_daemon_SOURCES = src/sdskv-server-daemon.c
bin_sdskv_server_daemon_DEPENDENCIES = lib/libsdskv-server.la
......@@ -83,7 +84,8 @@ check_PROGRAMS = test/sdskv-open-test
TESTS = test/basic.sh \
test/open-test.sh \
test/put-test.sh \
test/get-test.sh
test/get-test.sh \
test/list-keys-test.sh
TESTS_ENVIRONMENT = TIMEOUT="$(TIMEOUT)" \
MKTEMP="$(MKTEMP)"
......@@ -100,6 +102,10 @@ test_sdskv_get_test_SOURCES = test/sdskv-get-test.cc
test_sdskv_get_test_DEPENDENCIES = lib/libsdskv-client.la
test_sdskv_get_test_LDFLAGS = -Llib -lsdskv-client
test_sdskv_list_keys_test_SOURCES = test/sdskv-list-keys-test.cc
test_sdskv_list_keys_test_DEPENDENCIES = lib/libsdskv-client.la
test_sdskv_list_keys_test_LDFLAGS = -Llib -lsdskv-client
#############################################################
## tests bellow correspond to old tests (see old-test folder)
#############################################################
......
......@@ -531,8 +531,8 @@ int sdskv_list_keys(sdskv_provider_handle_t provider,
ksizes[i] = out.ksizes[i];
memcpy(keys[i], out.keys[i], out.ksizes[i]);
}
margo_free_output(handle, &out);
margo_free_output(handle, &out);
margo_destroy(handle);
return ret;
......
......@@ -248,6 +248,7 @@ static inline hg_return_t hg_proc_list_out_t(hg_proc_t proc, void *data)
for (i=0; i<out->nkeys; i++) {
ret = hg_proc_raw(proc, &(out->ksizes[i]),
sizeof(*(out->ksizes)) );
if(ret != HG_SUCCESS) return ret;
}
for (i=0; i<out->nkeys; i++) {
ret = hg_proc_raw(proc, out->keys[i], out->ksizes[i]);
......@@ -260,7 +261,7 @@ static inline hg_return_t hg_proc_list_out_t(hg_proc_t proc, void *data)
for (i=0; i<out->nkeys; i++) {
ret = hg_proc_raw(proc, &(out->ksizes[i]),
sizeof(*out->ksizes));
if(ret != HG_SUCCESS) return ret;
}
out->keys = (kv_data_t *)malloc(out->nkeys*sizeof(kv_data_t));
for (i=0; i<out->nkeys; i++) {
......
......@@ -566,7 +566,10 @@ static void sdskv_list_ult(hg_handle_t handle)
(sdskv_provider_t)margo_registered_data_mplex(mid, info->id, info->target_id);
if(!svr_ctx) {
fprintf(stderr, "Error: SDSKV could not find provider\n");
out.ret = -1;
out.ret = -1;
out.nkeys = 0;
out.keys = nullptr;
out.ksizes = nullptr;
margo_respond(handle, &out);
margo_destroy(handle);
return;
......@@ -600,21 +603,17 @@ static void sdskv_list_ult(hg_handle_t handle)
out.nkeys = keys.size();
/* create the array of sizes */
std::vector<hg_size_t> sizes(out.nkeys);
hg_size_t total_size = 0;
for(unsigned i = 0; i < out.nkeys; i++) {
sizes[i] = keys[i].size();
total_size += sizes[i];
}
out.ksizes = sizes.data();
/* create the packed data */
std::vector<kv_data_t> packed_keys(total_size);
hg_size_t offset = 0;
std::vector<kv_data_t> packed_keys(keys.size());
for(unsigned i = 0; i < out.nkeys; i++) {
std::memcpy((void*)(packed_keys.data()+offset),
(void*)(keys[i].data()), keys[i].size());
offset += keys[i].size();
packed_keys[i] = (char*)(keys[i].data());
}
out.keys = packed_keys.data();
out.ret = 0;
margo_respond(handle, &out);
margo_free_input(handle, &in);
......
#!/bin/bash -x
if [ -z $srcdir ]; then
echo srcdir variable not set.
exit 1
fi
source $srcdir/test/test-util.sh
# start a server with 2 second wait,
# 20s timeout, and my_test_db as database
test_start_server 2 20 my_test_db
sleep 1
#####################
run_to 20 test/sdskv-list-keys-test $svr_addr 1 my_test_db 10
if [ $? -ne 0 ]; then
wait
exit 1
fi
wait
echo cleaning up $TMPBASE
rm -rf $TMPBASE
exit 0
/*
* (C) 2015 The University of Chicago
*
* See COPYRIGHT in top-level directory.
*/
#include <stdio.h>
#include <assert.h>
#include <unistd.h>
#include <margo.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include "sdskv-client.h"
static std::string gen_random_string(size_t len);
int main(int argc, char *argv[])
{
char cli_addr_prefix[64] = {0};
char *sdskv_svr_addr_str;
char *db_name;
margo_instance_id mid;
hg_addr_t svr_addr;
uint8_t mplex_id;
uint32_t num_keys;
sdskv_client_t kvcl;
sdskv_provider_handle_t kvph;
hg_return_t hret;
int ret;
if(argc != 5)
{
fprintf(stderr, "Usage: %s <sdskv_server_addr> <mplex_id> <db_name> <num_keys>\n", argv[0]);
fprintf(stderr, " Example: %s tcp://localhost:1234 1 foo 1000\n", argv[0]);
return(-1);
}
sdskv_svr_addr_str = argv[1];
mplex_id = atoi(argv[2]);
db_name = argv[3];
num_keys = atoi(argv[4]);
/* initialize Margo using the transport portion of the server
* address (i.e., the part before the first : character if present)
*/
for(unsigned i=0; (i<63 && sdskv_svr_addr_str[i] != '\0' && sdskv_svr_addr_str[i] != ':'); i++)
cli_addr_prefix[i] = sdskv_svr_addr_str[i];
/* start margo */
mid = margo_init(cli_addr_prefix, MARGO_SERVER_MODE, 0, 0);
if(mid == MARGO_INSTANCE_NULL)
{
fprintf(stderr, "Error: margo_init()\n");
return(-1);
}
ret = sdskv_client_init(mid, &kvcl);
if(ret != 0)
{
fprintf(stderr, "Error: sdskv_client_init()\n");
margo_finalize(mid);
return -1;
}
/* look up the SDSKV server address */
hret = margo_addr_lookup(mid, sdskv_svr_addr_str, &svr_addr);
if(hret != HG_SUCCESS)
{
fprintf(stderr, "Error: margo_addr_lookup()\n");
sdskv_client_finalize(kvcl);
margo_finalize(mid);
return(-1);
}
/* create a SDSKV provider handle */
ret = sdskv_provider_handle_create(kvcl, svr_addr, mplex_id, &kvph);
if(ret != 0)
{
fprintf(stderr, "Error: sdskv_provider_handle_create()\n");
margo_addr_free(mid, svr_addr);
sdskv_client_finalize(kvcl);
margo_finalize(mid);
return(-1);
}
/* open the database */
sdskv_database_id_t db_id;
ret = sdskv_open(kvph, db_name, &db_id);
if(ret == 0) {
printf("Successfuly open database %s, id is %ld\n", db_name, db_id);
} else {
fprintf(stderr, "Error: could not open database %s\n", db_name);
sdskv_provider_handle_release(kvph);
margo_addr_free(mid, svr_addr);
sdskv_client_finalize(kvcl);
margo_finalize(mid);
return(-1);
}
/* **** put keys ***** */
std::vector<std::string> keys;
size_t max_value_size = 8000;
for(unsigned i=0; i < num_keys; i++) {
auto k = gen_random_string(16);
// half of the entries will be put using bulk
auto v = gen_random_string(i*max_value_size/num_keys);
ret = sdskv_put(kvph, db_id,
(const void *)k.data(), k.size()+1,
(const void *)v.data(), v.size()+1);
if(ret != 0) {
fprintf(stderr, "Error: sdskv_put() failed (iteration %d)\n", i);
sdskv_shutdown_service(kvcl, svr_addr);
sdskv_provider_handle_release(kvph);
margo_addr_free(mid, svr_addr);
sdskv_client_finalize(kvcl);
margo_finalize(mid);
return -1;
}
keys.push_back(k);
}
printf("Successfuly inserted %d keys\n", num_keys);
/* **** list keys **** */
std::sort(keys.begin(), keys.end());
auto i1 = keys.size()/3;
auto i2 = 2*keys.size()/3;
auto keys_after = keys[i1];
std::vector<std::vector<char>> result_strings(i2-i1, std::vector<char>(16+1));
std::vector<void*> list_result(i2-i1);
std::vector<hg_size_t> ksizes(i2-i1, 16+1);
hg_size_t max_keys = i2-i1;
for(unsigned i=0; i<i2-i1; i++) {
list_result[i] = (void*)result_strings[i].data();
}
ret = sdskv_list_keys(kvph, db_id,
(const void*)keys_after.c_str(), keys_after.size()+1,
list_result.data(), ksizes.data(), &max_keys);
if(ret != 0) {
fprintf(stderr, "Error: sdskv_list_keys() failed\n");
sdskv_shutdown_service(kvcl, svr_addr);
sdskv_provider_handle_release(kvph);
margo_addr_free(mid, svr_addr);
sdskv_client_finalize(kvcl);
margo_finalize(mid);
return -1;
}
/* shutdown the server */
ret = sdskv_shutdown_service(kvcl, svr_addr);
/**** cleanup ****/
sdskv_provider_handle_release(kvph);
margo_addr_free(mid, svr_addr);
sdskv_client_finalize(kvcl);
margo_finalize(mid);
return(ret);
}
static std::string gen_random_string(size_t len) {
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
std::string s(len, ' ');
for (unsigned i = 0; i < len; ++i) {
s[i] = alphanum[rand() % (sizeof(alphanum) - 1)];
}
return s;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment