bin: consolidate clients
[awesomized/libmemcached] / test / tests / memcached / behavior.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
3 #include "test/fixtures/callbacks.hpp"
4
5 TEST_CASE("memcached_behavior") {
6 auto test = MemcachedCluster::network();
7 auto memc = &test.memc;
8
9 SECTION("IO_KEY_PREFETCH") {
10 test.enableBinaryProto();
11 constexpr int NUM_KEYS = 2048;
12
13 // use batches of 64 keys
14 REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH, 64));
15
16 array<string, NUM_KEYS> str;
17 array<char *, NUM_KEYS> chr;
18 array<size_t, NUM_KEYS> len;
19
20 for (auto i = 0; i < NUM_KEYS; ++i) {
21 str[i] = to_string(i);
22 chr[i] = str[i].data();
23 len[i] = str[i].length();
24 REQUIRE_SUCCESS(memcached_set(memc, chr[i], len[i], chr[i], len[i], 0, 0));
25 }
26
27 memcached_quit(memc);
28
29 size_t counter = 0;
30 memcached_execute_fn cb[] = {&callback_counter};
31 REQUIRE_SUCCESS(memcached_mget_execute(memc, chr.data(), len.data(), NUM_KEYS, cb, &counter, 1));
32 auto q_id = memcached_query_id(memc);
33 REQUIRE_SUCCESS(memcached_fetch_execute(memc, cb, &counter, 1));
34 REQUIRE(counter == NUM_KEYS);
35 REQUIRE(q_id == memcached_query_id(memc));
36 }
37 }