update TODO
[awesomized/libmemcached] / test / tests / memcached / noreply.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
3
4 enum action_t {ADD, REPLACE, SET, APPEND, PREPEND};
5 inline action_t operator ++ (action_t &a) {
6 return a = static_cast<action_t>(underlying_type<action_t>::type(a) + 1);
7 }
8
9 constexpr static const int keys = 5000;
10
11 TEST_CASE("memcached_noreply") {
12 auto test{MemcachedCluster::mixed()};
13 auto memc = &test.memc;
14
15 REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, true));
16 REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, true));
17 REQUIRE_SUCCESS(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true));
18
19 for (auto action = ADD; action <= PREPEND; ++action) {
20 for (auto i = 0; i < keys; ++i) {
21 auto key = to_string(i);
22 memcached_return_t rc;
23
24 switch (action) {
25 case ADD: rc = memcached_add(memc, key.c_str(), key.length(), key.c_str(), key.length(), 0, 0); break;
26 case REPLACE: rc = memcached_replace(memc, key.c_str(), key.length(), key.c_str(), key.length(), 0, 0); break;
27 case SET: rc = memcached_set(memc, key.c_str(), key.length(), key.c_str(), key.length(), 0, 0); break;
28 case APPEND: rc = memcached_append(memc, key.c_str(), key.length(), key.c_str(), key.length(), 0, 0); break;
29 case PREPEND: rc = memcached_prepend(memc, key.c_str(), key.length(), key.c_str(), key.length(), 0, 0); break;
30 default: FAIL();
31 }
32
33 if (rc != MEMCACHED_BUFFERED) {
34 REQUIRE_SUCCESS(rc);
35 }
36 }
37
38 REQUIRE_SUCCESS(memcached_flush_buffers(memc));
39
40 for (auto i = 0; i < keys; ++i) {
41 auto key = to_string(i);
42
43 size_t len;
44 memcached_return_t rc;
45 uint32_t flags;
46 Malloced val(memcached_get(memc, key.c_str(), key.length(), &len, &flags, &rc));
47
48 REQUIRE_SUCCESS(rc);
49 REQUIRE(*val);
50
51 switch (action) {
52 case ADD: [[fallthrough]];
53 case REPLACE: [[fallthrough]];
54 case SET: REQUIRE(key == *val); break;
55 case APPEND: REQUIRE(key + key == *val); break;
56 case PREPEND: REQUIRE(key + key + key == *val); break;
57 default: FAIL();
58 }
59 }
60 }
61 }