update TODO
[awesomized/libmemcached] / test / tests / memcached / dump.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
3
4 memcached_return_t dump_cb(const memcached_st *, const char *, size_t, void *ctx) {
5 auto *c = reinterpret_cast<size_t *>(ctx);
6 ++(*c);
7 return MEMCACHED_SUCCESS;
8 }
9
10 TEST_CASE("memcached_dump") {
11 pair<string, MemcachedCluster> tests[]{
12 {"mixed", MemcachedCluster::mixed()},
13 {"network", MemcachedCluster::network()},
14 {"socket", 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 REQUIRE_SUCCESS(memcached_set(memc, key, len, key, len, 0, 0));
27 }
28 }
29
30 memcached_quit(memc);
31
32 // let memcached sort itself
33 using namespace chrono_literals;
34 this_thread::sleep_for(3s);
35
36 SECTION("dumps 64 KVs") {
37 size_t counter = 0;
38 memcached_dump_fn fn[] = {dump_cb};
39
40 REQUIRE_SUCCESS(memcached_dump(memc, fn, &counter, 1));
41 REQUIRE(counter == 64);
42 }
43 }
44 }
45 }