bin: consolidate clients
[awesomized/libmemcached] / test / tests / memcached / udp.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
3
4 TEST_CASE("memcached_udp") {
5 auto test = MemcachedCluster::udp();
6 auto memc = &test.memc;
7 MemcachedPtr check;
8
9 for (const auto &server : test.cluster.getServers()) {
10 memcached_server_add(*check, "localhost", get<int>(server.getSocketOrPort()));
11 }
12
13 SECTION("compat") {
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);
23 }
24
25 SECTION("io") {
26 const auto max = 1025; // request id rolls over at 1024
27 auto binary = GENERATE(0, 1);
28
29 test.enableBinaryProto(binary);
30
31 DYNAMIC_SECTION("binary=" << binary) {
32 SECTION("set") {
33 for (auto i = 0; i < max; ++i) {
34 auto s = to_string(i);
35 INFO("i=" << i);
36 REQUIRE_SUCCESS(memcached_set(memc, s.c_str(), s.length(), s.c_str(), s.length(), 0, 0));
37 }
38 memcached_quit(memc);
39 REQUIRE_SUCCESS(memcached_last_error(memc));
40
41 for (auto i = 0; i < max; ++i) {
42 auto s = to_string(i);
43 memcached_return_t rc;
44 INFO("i=" << i);
45 Malloced val(memcached_get(*check, s.c_str(), s.length(), nullptr, nullptr, &rc));
46 CHECK(*val);
47 CHECK(MEMCACHED_SUCCESS == rc);
48 }
49 }
50
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));
55 memcached_quit(memc);
56 REQUIRE_SUCCESS(memcached_last_error(memc));
57 }
58
59 SECTION("delete") {
60 for (auto i = 0; i < max; ++i) {
61 auto s = to_string(i);
62 INFO("i=" << i);
63 REQUIRE_SUCCESS(memcached_delete(memc, s.c_str(), s.length(), 0));
64 }
65 memcached_quit(memc);
66 REQUIRE_SUCCESS(memcached_last_error(memc));
67 }
68
69 SECTION("verbosity") {
70 for (auto i = 0; i < max; ++i) {
71 INFO("i=" << i);
72 REQUIRE_SUCCESS(memcached_verbosity(memc, 0));
73 }
74 memcached_quit(memc);
75 REQUIRE_SUCCESS(memcached_last_error(memc));
76 }
77
78 SECTION("flush") {
79 for (auto i = 0; i < max; ++i) {
80 INFO("i=" << i);
81 REQUIRE_SUCCESS(memcached_flush(memc, 0));
82 }
83 memcached_quit(memc);
84 REQUIRE_SUCCESS(memcached_last_error(memc));
85 }
86
87 SECTION("incremend/decrement") {
88 uint64_t newval = 0;
89 REQUIRE_SUCCESS(memcached_set(memc, S("udp-incr"), S("1"), 0, 0));
90 memcached_quit(memc);
91 this_thread::sleep_for(1s);
92 REQUIRE_SUCCESS(memcached_increment(memc, S("udp-incr"), 1, &newval));
93 memcached_quit(memc);
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));
98 REQUIRE_SUCCESS(rc);
99 REQUIRE(*val);
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);
106 REQUIRE_SUCCESS(rc);
107 REQUIRE(*val);
108 CHECK(string(*val) == "1");
109 }
110 }
111 }
112 }