1 #include "test/lib/common.hpp"
2 #include "test/lib/MemcachedCluster.hpp"
4 static memcached_return_t
item_counter(const memcached_instance_st
*, const char *key
, size_t, const char *value
, size_t, void *context
)
6 if (key
== "curr_items"s
) {
7 auto counter
= static_cast<size_t *>(context
);
8 *counter
+= stoul(value
);
11 return MEMCACHED_SUCCESS
;
14 static memcached_return_t
stat_null(const memcached_instance_st
*, const char *, size_t, const char *, size_t, void *) {
15 return MEMCACHED_SUCCESS
;
18 TEST_CASE("memcached_stat") {
19 MemcachedCluster test
;
20 auto memc
= &test
.memc
;
22 SECTION("invalid arguments") {
24 REQUIRE_RC(MEMCACHED_INVALID_ARGUMENTS
, memcached_stat_execute(memc
, "BAD_ARG", item_counter
, &count
));
28 for (auto i
= 0; i
< 64; ++i
) {
29 auto key
= random_ascii_string(12) + to_string(i
);
30 REQUIRE_SUCCESS(memcached_set(memc
, key
.c_str(), key
.length(), nullptr, 0, 0, 0));
36 REQUIRE_SUCCESS(memcached_stat_execute(memc
, nullptr, item_counter
, &count
));
39 auto arg
= GENERATE(as
<string
>(), "slabs", "items", "sizes");
40 REQUIRE_SUCCESS(memcached_stat_execute(memc
, arg
.c_str(), stat_null
, nullptr));
43 SECTION("servername") {
44 for (auto &server
: test
.cluster
.getServers()) {
45 auto port
= server
.getSocketOrPort();
46 if (holds_alternative
<int>(port
)) {
47 memcached_stat_st stats
;
48 REQUIRE_SUCCESS(memcached_stat_servername(&stats
, nullptr, "localhost", get
<int>(port
)));
54 SECTION("get_keys/get_value") { // oh my
55 memcached_return_t rc
;
56 auto servers
= test
.cluster
.getServers();
57 Malloced
stats(memcached_stat(memc
, nullptr, &rc
));
58 Malloced
keys(memcached_stat_get_keys(memc
, nullptr, nullptr));
64 for (auto i
= 0U; i
< memcached_server_count(memc
); ++i
) {
65 auto this_stat
= &(*stats
)[i
];
67 for (auto key
= *keys
; *key
; ++key
) {
68 Malloced
val(memcached_stat_get_value(memc
, this_stat
, *key
, &rc
));
72 for (auto &server
: test
.cluster
.getServers()) {
73 if (this_stat
->pid
== server
.getPid()) {
78 FAIL("no server matches pid " << this_stat
->pid
);