Commit 7740c181 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added put/get test using C++ API

parent da5277a5
......@@ -20,6 +20,7 @@ check_PROGRAMS = test/sdskv-open-test \
test/sdskv-custom-cmp-test \
test/sdskv-migrate-test \
test/sdskv-multi-test \
test/sdskv-cxx-test \
test/sdskv-custom-server-daemon
bin_sdskv_server_daemon_SOURCES = src/sdskv-server-daemon.c
......@@ -78,7 +79,10 @@ lib_libsdskv_server_la_LIBADD = ${SERVER_LIBS}
include_HEADERS = include/sdskv-client.h \
include/sdskv-server.h \
include/sdskv-common.h
include/sdskv-common.h \
include/sdskv-client.hpp \
include/sdskv-server.hpp \
include/sdskv-common.hpp
noinst_HEADERS = src/bulk.h \
src/sds-keyval.h \
......@@ -111,7 +115,8 @@ TESTS = test/basic.sh \
test/list-keys-prefix-test.sh \
test/migrate-test.sh \
test/custom-cmp-test.sh \
test/multi-test.sh
test/multi-test.sh \
test/cxx-test.sh
TESTS_ENVIRONMENT = TIMEOUT="$(TIMEOUT)" \
MKTEMP="$(MKTEMP)"
......@@ -169,6 +174,10 @@ test_sdskv_multi_test_SOURCES = test/sdskv-multi-test.cc
test_sdskv_multi_test_DEPENDENCIES = lib/libsdskv-client.la
test_sdskv_multi_test_LDFLAGS = -Llib -lsdskv-client
test_sdskv_cxx_test_SOURCES = test/sdskv-cxx-test.cc
test_sdskv_cxx_test_DEPENDENCIES = lib/libsdskv-client.la
test_sdskv_cxx_test_LDFLAGS = -Llib -lsdskv-client
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = maint/sdskv-server.pc \
maint/sdskv-client.pc
......
#!/bin/bash -x
if [ -z $srcdir ]; then
echo srcdir variable not set.
exit 1
fi
source $srcdir/test/test-util.sh
find_db_name
# start a server with 2 second wait,
# 20s timeout, and my_test_db as database
test_start_server 2 20 $test_db_full
sleep 1
#####################
run_to 20 test/sdskv-cxx-test $svr_addr 1 $test_db_name 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 <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include "sdskv-client.hpp"
static std::string gen_random_string(size_t len);
int main(int argc, char *argv[])
{
char cli_addr_prefix[64] = {0};
std::string sdskv_svr_addr;
std::string db_name;
margo_instance_id mid;
hg_addr_t svr_addr;
uint16_t provider_id;
uint32_t num_keys;
hg_return_t hret;
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 = argv[1];
provider_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[i] != '\0' && sdskv_svr_addr[i] != ':'); i++)
cli_addr_prefix[i] = sdskv_svr_addr[i];
/* start margo */
mid = margo_init(cli_addr_prefix, MARGO_SERVER_MODE, 0, 0);
if(mid == MARGO_INSTANCE_NULL)
throw std::runtime_error("margo_init failed");
{
sdskv::client kvcl(mid);
sdskv::provider_handle kvph;
/* look up the SDSKV server address */
hret = margo_addr_lookup(mid, sdskv_svr_addr.c_str(), &svr_addr);
if(hret != HG_SUCCESS)
throw std::runtime_error("margo_addr_lookup failed");
/* create a SDSKV provider handle */
kvph = sdskv::provider_handle(kvcl, svr_addr, provider_id);
/* open the database */
sdskv::database DB = kvcl.open(kvph, db_name);
/* **** put keys ***** */
std::vector<std::string> keys;
std::map<std::string, std::string> reference;
size_t max_value_size = 24;
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(3+i*(max_value_size-3)/num_keys);
DB.put(k, v);
std::cout << "Inserted " << k << "\t ===> " << v << std::endl;
reference[k] = v;
keys.push_back(k);
}
std::cout << "Successfuly inserted " << num_keys << " keys" << std::endl;
/* **** get keys **** */
for(unsigned i=0; i < num_keys; i++) {
auto k = keys[rand() % keys.size()];
size_t value_size = max_value_size;
std::vector<char> v(max_value_size);
DB.get(k,v);
std::string vstring((char*)(v.data()));
std::cout << "Got " << k << " ===> " << vstring << std::endl;
if(vstring != reference[k]) {
std::cerr << "DB.get() returned a value different from the reference" << std::endl;
return -1;
}
}
/* shutdown the server */
kvcl.shutdown(svr_addr);
/**** cleanup ****/
margo_addr_free(mid, svr_addr);
}
margo_finalize(mid);
return 0;
}
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