85e44126c7ae742becda21bddf4bc6470408960c
[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 #ifdef __APPLE__
6 WARN("skip: memcached crashes");
7 SUCCEED();
8 #else
9 auto test = MemcachedCluster::udp();
10 auto memc = &test.memc;
11
12 SECTION("sets reply flag") {
13 // FIXME: bad internals test
14 REQUIRE(memc->flags.reply);
15 REQUIRE_FALSE(memc->flags.use_udp);
16 REQUIRE_FALSE(memc->flags.use_udp == memc->flags.reply);
17 test.enableUdp();
18 REQUIRE_FALSE(memc->flags.reply);
19 REQUIRE(memc->flags.use_udp);
20 REQUIRE_FALSE(memc->flags.use_udp == memc->flags.reply);
21 test.enableUdp(false);
22 REQUIRE(memc->flags.reply);
23 REQUIRE_FALSE(memc->flags.use_udp);
24 REQUIRE_FALSE(memc->flags.use_udp == memc->flags.reply);
25 }
26
27 test.enableUdp();
28
29 SECTION("compat") {
30 memcached_return_t rc;
31 REQUIRE_RC(MEMCACHED_INVALID_ARGUMENTS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, true));
32 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED, memcached_version(memc));
33 REQUIRE_SUCCESS(memcached_verbosity(memc, 0));
34 REQUIRE(nullptr == memcached_get(memc, S(__func__), 0, 0, &rc));
35 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED, rc);
36 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED, memcached_mget_execute_by_key(memc, S(__func__), nullptr, nullptr, 0, nullptr, nullptr, 0));
37 REQUIRE(nullptr == memcached_stat(memc, nullptr, &rc));
38 REQUIRE_RC(MEMCACHED_NOT_SUPPORTED, rc);
39 }
40
41 SECTION("io") {
42 const auto max = 1025; // request id rolls over at 1024
43 auto binary = GENERATE(0,1);
44
45 test.enableBinaryProto(binary);
46
47 DYNAMIC_SECTION("binary=" << binary) {
48 SECTION("set") {
49 for (auto i = 0; i < max; ++i) {
50 auto s = to_string(i);
51 INFO("i=" << i);
52 REQUIRE_SUCCESS(memcached_set(memc, s.c_str(), s.length(), s.c_str(), s.length(), 0, 0));
53 }
54 // FIXME: check request id
55 memcached_quit(memc);
56 REQUIRE_SUCCESS(memcached_last_error(memc));
57 }
58
59 SECTION("set too big") {
60 const auto len = 1'234'567;
61 auto blob = make_unique<char>(len);
62 REQUIRE_RC(MEMCACHED_WRITE_FAILURE, memcached_set(memc, S(__func__), blob.get(), len, 0, 0));
63 memcached_quit(memc);
64 REQUIRE_SUCCESS(memcached_last_error(memc));
65 }
66
67 SECTION("delete") {
68 for (auto i = 0; i < max; ++i) {
69 auto s = to_string(i);
70 INFO("i=" << i);
71 REQUIRE_SUCCESS(memcached_delete(memc, s.c_str(), s.length(), 0));
72 }
73 memcached_quit(memc);
74 REQUIRE_SUCCESS(memcached_last_error(memc));
75 }
76
77 SECTION("verbosity") {
78 for (auto i = 0; i < max; ++i) {
79 INFO("i=" << i);
80 REQUIRE_SUCCESS(memcached_verbosity(memc, 0));
81 }
82 memcached_quit(memc);
83 REQUIRE_SUCCESS(memcached_last_error(memc));
84 }
85
86 SECTION("flush") {
87 for (auto i = 0; i < max; ++i) {
88 INFO("i=" << i);
89 REQUIRE_SUCCESS(memcached_flush(memc, 0));
90 }
91 memcached_quit(memc);
92 REQUIRE_SUCCESS(memcached_last_error(memc));
93 }
94 }
95 }
96 #endif
97 }