flush [ci skip]
[awesomized/libmemcached] / testing / memcached / dump.cpp
1 #include "../lib/common.hpp"
2 #include "../lib/MemcachedCluster.hpp"
3
4 memcached_return_t dump_cb(const memcached_st *, const char *, size_t, void *ctx) {
5 size_t *c = reinterpret_cast<size_t *>(ctx);
6 ++(*c);
7 return MEMCACHED_SUCCESS;
8 }
9
10 TEST_CASE("memcached dump") {
11 MemcachedCluster tests[]{
12 MemcachedCluster::mixed(),
13 MemcachedCluster::net(),
14 MemcachedCluster::socket()
15 };
16
17 LOOPED_SECTION(tests) {
18 auto memc = &test.memc;
19
20 SECTION("prepared with 64 KVs") {
21 for (int i = 0; i < 64; ++i) {
22 char key[8];
23 int len = snprintf(key, sizeof(key) - 1, "k_%d", i);
24
25 CHECKED_IF(len) {
26 auto rc = memcached_set(memc, key, len, key, len, 0, 0);
27 INFO("last error: " << memcached_last_error(memc));
28 REQUIRE(MEMCACHED_SUCCESS == rc);
29 }
30 }
31
32 memcached_quit(memc);
33
34 // let memcached sort itself
35 using namespace chrono_literals;
36 this_thread::sleep_for(3s);
37
38 SECTION("dumps 64 KVs") {
39 size_t counter = 0;
40 memcached_dump_fn fn[] = {dump_cb};
41
42 REQUIRE(MEMCACHED_SUCCESS == memcached_dump(memc, fn, &counter, 1));
43 REQUIRE(counter == 64);
44 }
45 }
46 }
47 }