1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
4 static memcached_return_t
callback_counter(const memcached_st
*, memcached_result_st
*, void *context
) {
5 auto *counter
= reinterpret_cast<size_t *>(context
);
6 *counter
= *counter
+ 1;
8 return MEMCACHED_SUCCESS
;
11 TEST_CASE("memcached_behavior") {
12 auto test
= MemcachedCluster::network();
13 auto memc
= &test
.memc
;
15 SECTION("IO_KEY_PREFETCH") {
16 test
.enableBinaryProto();
17 constexpr int NUM_KEYS
= 2048;
19 // use batches of 64 keys
20 REQUIRE_SUCCESS(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH
, 64));
22 array
<string
, NUM_KEYS
> str
;
23 array
<char *, NUM_KEYS
> chr
;
24 array
<size_t, NUM_KEYS
> len
;
26 for (auto i
= 0; i
< NUM_KEYS
; ++i
) {
27 str
[i
] = to_string(i
);
28 chr
[i
] = str
[i
].data();
29 len
[i
] = str
[i
].length();
30 REQUIRE_SUCCESS(memcached_set(memc
, chr
[i
], len
[i
], chr
[i
], len
[i
], 0, 0));
36 memcached_execute_fn cb
[] = {&callback_counter
};
37 REQUIRE_SUCCESS(memcached_mget_execute(memc
, chr
.data(), len
.data(), NUM_KEYS
, cb
, &counter
, 1));
38 auto q_id
= memcached_query_id(memc
);
39 REQUIRE_SUCCESS(memcached_fetch_execute(memc
, cb
, &counter
, 1));
40 REQUIRE(counter
== NUM_KEYS
);
41 REQUIRE(q_id
== memcached_query_id(memc
));