1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
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);
9 constexpr static const int keys
= 5000;
11 TEST_CASE("memcached_noreply") {
12 auto test
{MemcachedCluster::mixed()};
13 auto memc
= &test
.memc
;
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));
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
;
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;
33 if (rc
!= MEMCACHED_BUFFERED
) {
38 REQUIRE_SUCCESS(memcached_flush_buffers(memc
));
40 for (auto i
= 0; i
< keys
; ++i
) {
41 auto key
= to_string(i
);
44 memcached_return_t rc
;
46 Malloced
val(memcached_get(memc
, key
.c_str(), key
.length(), &len
, &flags
, &rc
));
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;