Commit 6ff35da8 authored by Matthieu Dorier's avatar Matthieu Dorier

put test into separate function

parent 7740c181
......@@ -18,6 +18,8 @@
static std::string gen_random_string(size_t len);
static int put_get_erase_test(sdskv::database& DB, uint32_t num_keys);
int main(int argc, char *argv[])
{
char cli_addr_prefix[64] = {0};
......@@ -68,6 +70,36 @@ int main(int argc, char *argv[])
/* open the database */
sdskv::database DB = kvcl.open(kvph, db_name);
/* Put get erase test */
put_get_erase_test(DB, num_keys);
/* 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;
}
static int put_get_erase_test(sdskv::database& DB, uint32_t num_keys) {
/* **** put keys ***** */
std::vector<std::string> keys;
std::map<std::string, std::string> reference;
......@@ -93,32 +125,15 @@ int main(int argc, char *argv[])
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;
throw std::runtime_error("DB.get() returned a value different from the reference");
}
}
/* shutdown the server */
kvcl.shutdown(svr_addr);
/**** cleanup ****/
margo_addr_free(mid, svr_addr);
/* erase keys */
for(unsigned i=0; i < num_keys; i++) {
DB.erase(keys[i]);
}
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