X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=test%2Ftests%2Fmemcached%2Futil.cpp;h=35a76b7eadb6e5a666a7f65eba3def1e3283afdd;hb=ca5b36c524c7b4ecdb436c2e20a8a0b089be127a;hp=9612b1d08b5d61f10d24f09cf5424f1d0e0e3062;hpb=9f262c9ea92d4869715ca6f534c80075a8310ac1;p=m6w6%2Flibmemcached diff --git a/test/tests/memcached/util.cpp b/test/tests/memcached/util.cpp index 9612b1d0..35a76b7e 100644 --- a/test/tests/memcached/util.cpp +++ b/test/tests/memcached/util.cpp @@ -53,7 +53,7 @@ TEST_CASE("memcached_util") { } REQUIRE(-1 == libmemcached_util_getpid("localhost", 1, &rc)); - REQUIRE_RC(MEMCACHED_CONNECTION_FAILURE, rc); + REQUIRE(memcached_fatal(rc)); } SECTION("ping") { @@ -73,4 +73,109 @@ TEST_CASE("memcached_util") { REQUIRE_SUCCESS(rc); } } + + SECTION("pool") { + SECTION("deprecated") { + auto conf = "--SERVER=host10.example.com --SERVER=host11.example.com --SERVER=host10.example.com --POOL-MIN=10 --POOL-MAX=32"; + auto pool = memcached_pool(S(conf)); + REQUIRE(pool); + + memcached_return_t rc; + auto memc = memcached_pool_pop(pool, false, &rc); + REQUIRE(memc); + REQUIRE(MEMCACHED_SUCCESS == rc); + + REQUIRE(MEMCACHED_SUCCESS == memcached_pool_push(pool, memc)); + REQUIRE(nullptr == memcached_pool_destroy(pool)); + } + + SECTION("basic") { + auto test = MemcachedCluster::mixed(); + auto memc = &test.memc; + memcached_return_t rc; + + constexpr auto POOL_MIN = 5; + constexpr auto POOL_MAX = 10; + + auto pool = memcached_pool_create(memc, POOL_MIN, POOL_MAX); + REQUIRE(pool); + + array hold{}; + for (auto &h : hold) { + h = memcached_pool_fetch(pool, nullptr, &rc); + REQUIRE_SUCCESS(rc); + REQUIRE(h); + } + + SECTION("depleted") { + REQUIRE(nullptr == memcached_pool_fetch(pool, nullptr, &rc)); + REQUIRE_RC(MEMCACHED_NOTFOUND, rc); + } + + SECTION("usable") { + for (auto h : hold) { + auto s = to_string(reinterpret_cast(h)); + REQUIRE_SUCCESS(memcached_set(h, s.c_str(), s.length(), s.c_str(), s.length(), 0, 0)); + } + for (auto h : hold) { + auto s = to_string(reinterpret_cast(h)); + Malloced val(memcached_get(h, s.c_str(), s.length(), nullptr, nullptr, &rc)); + REQUIRE_SUCCESS(rc); + REQUIRE(*val); + REQUIRE(h == reinterpret_cast(stoul(*val))); + } + + REQUIRE_SUCCESS(memcached_set(hold[0], S(__func__), "0", 1, 0, 0)); + uint64_t inc = 0; + for (auto h : hold) { + uint64_t val; + REQUIRE_SUCCESS(memcached_increment(h, S(__func__), 1, &val)); + CHECK(++inc == val); + } + } + + SECTION("behaviors") { + uint64_t val; + REQUIRE_SUCCESS(memcached_pool_behavior_get(pool, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, &val)); + REQUIRE_FALSE(val == 9999); + REQUIRE_SUCCESS(memcached_pool_behavior_set(pool, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, 9999)); + REQUIRE_SUCCESS(memcached_pool_behavior_get(pool, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, &val)); + REQUIRE(val == 9999); + + for (auto &h : hold) { + REQUIRE_FALSE(9999 == memcached_behavior_get(h, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK)); + REQUIRE_SUCCESS(memcached_pool_release(pool, h)); + h = memcached_pool_fetch(pool, nullptr, &rc); + REQUIRE_SUCCESS(rc); + REQUIRE(h); + REQUIRE(9999 == memcached_behavior_get(h, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK)); + REQUIRE_FALSE(9999 == memcached_behavior_get(h, MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK)); + REQUIRE_SUCCESS(memcached_pool_release(pool, h)); + } + + REQUIRE_SUCCESS(memcached_pool_behavior_get(pool, MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK, &val)); + REQUIRE_FALSE(val == 9999); + REQUIRE_SUCCESS(memcached_pool_behavior_set(pool, MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK, 9999)); + REQUIRE_SUCCESS(memcached_pool_behavior_get(pool, MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK, &val)); + REQUIRE(val == 9999); + + for (auto &h : hold) { + h = memcached_pool_fetch(pool, nullptr, &rc); + REQUIRE_SUCCESS(rc); + REQUIRE(h); + REQUIRE(9999 == memcached_behavior_get(h, MEMCACHED_BEHAVIOR_IO_BYTES_WATERMARK)); + } + } + + for (auto h : hold) { + REQUIRE_SUCCESS(memcached_pool_release(pool, h)); + auto again = memcached_pool_fetch(pool, nullptr, &rc); + REQUIRE_SUCCESS(rc); + REQUIRE(again); + REQUIRE_SUCCESS(memcached_pool_release(pool, again)); + } + + REQUIRE(memc == memcached_pool_destroy(pool)); + } + } }