From a485240c332beba45ee67454432fcc55ef9669b9 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 2 Nov 2019 11:59:56 -0400 Subject: nserver: protocol: Define ssdump. * nserver/src/protocol.c (ssdump): New function. * nserver/tests/protocol_tests.c (test_ssdump): New test. (all_tests): Add test_ssdump. --- nserver/src/protocol.c | 19 +++++++++++++++++++ nserver/tests/protocol_tests.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) (limited to 'nserver') diff --git a/nserver/src/protocol.c b/nserver/src/protocol.c index adcfc21..bb23b92 100644 --- a/nserver/src/protocol.c +++ b/nserver/src/protocol.c @@ -103,3 +103,22 @@ double ssmean(char *key) return -1; } +char *ssdump(char *key) +{ + check(hash != NULL, "hash not initialized"); + + // 1. create bstring from 'key'. + bstring k = bfromcstr(key); + + // 2. try to get Stats for key. + Stats *st = (Stats *) Hashmap_get(hash, k); + check(st != NULL, "stats not found for key"); + + // 3. get dump. + char *dstr = Stats_dump(st); + check(dstr != NULL, "dump failed for key"); + + return dstr; + error: + return NULL; +} diff --git a/nserver/tests/protocol_tests.c b/nserver/tests/protocol_tests.c index bc8a3db..96450be 100644 --- a/nserver/tests/protocol_tests.c +++ b/nserver/tests/protocol_tests.c @@ -58,6 +58,34 @@ char *test_ssmean() return NULL; } +char *test_ssdump() +{ + char *dstr = NULL; + + dstr = ssdump("crimson"); + mu_assert(dstr != NULL, "ssdump failed 0"); + debug("DUMP: %s", dstr); + + // clean up. + free(dstr); + + dstr = ssdump("/vermilion"); + mu_assert(dstr != NULL, "ssdump failed 1"); + debug("DUMP: %s", dstr); + + // clean up. + free(dstr); + + dstr = ssdump("/ruby"); + mu_assert(dstr == NULL, "ssdump failed 2"); + debug("DUMP: %s", dstr); + + // clean up. + free(dstr); + + return NULL; +} + char *test_ssdelete() { int rc = 0; @@ -81,6 +109,7 @@ char *all_tests() mu_run_test(test_sscreate); mu_run_test(test_sssample); mu_run_test(test_ssmean); + mu_run_test(test_ssdump); mu_run_test(test_ssdelete); return NULL; -- cgit v1.2.3