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 TEST_CASE("memcached_stat") {
15 MemcachedCluster test
;
16 auto memc
= &test
.memc
;
18 SECTION("invalid arguments") {
20 REQUIRE_RC(MEMCACHED_INVALID_ARGUMENTS
, memcached_stat_execute(memc
, "BAD_ARG", item_counter
, &count
));
24 for (auto i
= 0; i
< 64; ++i
) {
25 auto key
= random_ascii_string(12) + to_string(i
);
26 REQUIRE_SUCCESS(memcached_set(memc
, key
.c_str(), key
.length(), nullptr, 0, 0, 0));
32 REQUIRE_SUCCESS(memcached_stat_execute(memc
, nullptr, item_counter
, &count
));
36 SECTION("servername") {
37 for (auto &server
: test
.cluster
.getServers()) {
38 auto port
= server
.getSocketOrPort();
39 if (holds_alternative
<int>(port
)) {
40 memcached_stat_st stats
;
41 REQUIRE_SUCCESS(memcached_stat_servername(&stats
, nullptr, "localhost", get
<int>(port
)));
47 SECTION("get_keys/get_value") { // oh my
48 memcached_return_t rc
;
49 auto servers
= test
.cluster
.getServers();
50 Malloced
stats(memcached_stat(memc
, nullptr, &rc
));
51 Malloced
keys(memcached_stat_get_keys(memc
, nullptr, nullptr));
57 for (auto i
= 0U; i
< memcached_server_count(memc
); ++i
) {
58 auto this_stat
= &(*stats
)[i
];
60 for (auto key
= *keys
; *key
; ++key
) {
61 Malloced
val(memcached_stat_get_value(memc
, this_stat
, *key
, &rc
));
65 for (auto &server
: test
.cluster
.getServers()) {
66 if (this_stat
->pid
== server
.getPid()) {
71 FAIL("no server matches pid " << this_stat
->pid
);