1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
4 TEST_CASE("memcached_udp") {
5 auto test
= MemcachedCluster::udp();
6 auto memc
= &test
.memc
;
9 for (const auto &server
: test
.cluster
.getServers()) {
10 memcached_server_add(*check
, "localhost", get
<int>(server
.getSocketOrPort()));
14 memcached_return_t rc
;
15 REQUIRE_RC(MEMCACHED_INVALID_ARGUMENTS
, memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS
, true));
16 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED
, memcached_version(memc
));
17 REQUIRE_SUCCESS(memcached_verbosity(memc
, 0));
18 REQUIRE(nullptr == memcached_get(memc
, S(__func__
), 0, 0, &rc
));
19 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED
, rc
);
20 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED
, memcached_mget_execute_by_key(memc
, S(__func__
), nullptr, nullptr, 0, nullptr, nullptr, 0));
21 REQUIRE(nullptr == memcached_stat(memc
, nullptr, &rc
));
22 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED
, rc
);
26 const auto max
= 1025; // request id rolls over at 1024
27 auto binary
= GENERATE(0, 1);
29 test
.enableBinaryProto(binary
);
31 DYNAMIC_SECTION("binary=" << binary
) {
33 for (auto i
= 0; i
< max
; ++i
) {
34 auto s
= to_string(i
);
36 REQUIRE_SUCCESS(memcached_set(memc
, s
.c_str(), s
.length(), s
.c_str(), s
.length(), 0, 0));
39 REQUIRE_SUCCESS(memcached_last_error(memc
));
41 for (auto i
= 0; i
< max
; ++i
) {
42 auto s
= to_string(i
);
43 memcached_return_t rc
;
45 Malloced
val(memcached_get(*check
, s
.c_str(), s
.length(), nullptr, nullptr, &rc
));
47 CHECK(MEMCACHED_SUCCESS
== rc
);
51 SECTION("set too big") {
52 const auto len
= 1'234'567;
53 auto blob
= make_unique
<char>(len
);
54 REQUIRE_RC(MEMCACHED_WRITE_FAILURE
, memcached_set(memc
, S(__func__
), blob
.get(), len
, 0, 0));
56 REQUIRE_SUCCESS(memcached_last_error(memc
));
60 for (auto i
= 0; i
< max
; ++i
) {
61 auto s
= to_string(i
);
63 REQUIRE_SUCCESS(memcached_delete(memc
, s
.c_str(), s
.length(), 0));
66 REQUIRE_SUCCESS(memcached_last_error(memc
));
69 SECTION("verbosity") {
70 for (auto i
= 0; i
< max
; ++i
) {
72 REQUIRE_SUCCESS(memcached_verbosity(memc
, 0));
75 REQUIRE_SUCCESS(memcached_last_error(memc
));
79 for (auto i
= 0; i
< max
; ++i
) {
81 REQUIRE_SUCCESS(memcached_flush(memc
, 0));
84 REQUIRE_SUCCESS(memcached_last_error(memc
));
87 SECTION("incremend/decrement") {
89 REQUIRE_SUCCESS(memcached_set(memc
, S("udp-incr"), S("1"), 0, 0));
91 this_thread::sleep_for(1s
);
92 REQUIRE_SUCCESS(memcached_increment(memc
, S("udp-incr"), 1, &newval
));
94 this_thread::sleep_for(1s
);
95 REQUIRE(newval
== UINT64_MAX
);
96 memcached_return_t rc
;
97 Malloced
val(memcached_get(*check
, S("udp-incr"), nullptr, nullptr, &rc
));
100 CHECK(string(*val
) == "2");
101 REQUIRE_SUCCESS(memcached_decrement(memc
, S("udp-incr"), 1, &newval
));
102 memcached_quit(memc
);
103 this_thread::sleep_for(1s
);
104 REQUIRE(newval
== UINT64_MAX
);
105 val
= memcached_get(*check
, S("udp-incr"), nullptr, nullptr, &rc
);
108 CHECK(string(*val
) == "1");