1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
4 TEST_CASE("memcached_simple") {
5 pair
<string
, MemcachedCluster
> tests
[] = {
6 {"network", MemcachedCluster::network()},
7 {"socket", MemcachedCluster::socket()}
10 LOOPED_SECTION(tests
) {
11 auto memc
= &test
.memc
;
14 uint64_t id
= memcached_query_id(memc
);
15 REQUIRE_SUCCESS(memcached_flush(memc
, 0));
16 REQUIRE(id
+ 1 == memcached_query_id(memc
));
19 uint64_t buffered
= GENERATE(0, 1);
20 uint64_t binary
= GENERATE(0, 1);
22 REQUIRE_SUCCESS(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, buffered
));
23 REQUIRE_SUCCESS(memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL
, binary
));
25 DYNAMIC_SECTION("set (buffered=" << buffered
<< ",binary=" << binary
<< ")") {
26 for (auto i
= 0; i
< 10; ++i
) {
27 REQUIRE_RC(buffered
? MEMCACHED_BUFFERED
: MEMCACHED_SUCCESS
,
28 memcached_set(memc
, S(__func__
), S(__func__
), 0, 0));
32 DYNAMIC_SECTION("add (buffered=" << buffered
<< ",binary=" << binary
<< ")") {
33 memcached_return_t rc
;
35 Malloced
empty(memcached_get(memc
, S(__func__
), nullptr, nullptr, &rc
));
36 REQUIRE_FALSE(*empty
);
37 REQUIRE_RC(MEMCACHED_NOTFOUND
, rc
);
39 REQUIRE_RC(buffered
? MEMCACHED_BUFFERED
: MEMCACHED_SUCCESS
,
40 memcached_set(memc
, S(__func__
), S(__func__
), 0, 0));
42 // flush any pending requests
47 Malloced
val(memcached_get(memc
, S(__func__
), &len
, &flags
, &rc
));
50 REQUIRE(string(__func__
) == string(*val
, len
));
52 REQUIRE_RC(binary
? MEMCACHED_DATA_EXISTS
: MEMCACHED_NOTSTORED
,
53 memcached_add(memc
, S(__func__
), S("update"), 0, 0));
56 DYNAMIC_SECTION("replace (buffered=" << buffered
<< ",binary=" << binary
<< ")") {
57 REQUIRE_RC(buffered
? MEMCACHED_BUFFERED
: MEMCACHED_SUCCESS
,
58 memcached_set(memc
, S(__func__
), S(__func__
), 0, 0));
60 REQUIRE_SUCCESS(memcached_replace(memc
, S(__func__
), S("replaced"), 0, 0));
63 DYNAMIC_SECTION("not found (buffered=" << buffered
<< ",binary=" << binary
<< ")") {
64 memcached_return_t rc
;
65 Malloced
val(memcached_get(memc
, S("not-found"), nullptr, nullptr, &rc
));
66 REQUIRE_RC(MEMCACHED_NOTFOUND
, rc
);
69 val
= memcached_get_by_key(memc
, S("not-found"), S("not-found"), nullptr, nullptr, &rc
);
70 REQUIRE_RC(MEMCACHED_NOTFOUND
, rc
);
74 DYNAMIC_SECTION("verbosity (buffered=" << buffered
<< ",binary=" << binary
<< ")") {
75 REQUIRE_SUCCESS(memcached_verbosity(memc
, 0));
78 DYNAMIC_SECTION("version (buffered=" << buffered
<< ",binary=" << binary
<< ")") {
79 REQUIRE_SUCCESS(memcached_version(memc
));