update TODO
[awesomized/libmemcached] / test / tests / memcached / vbucket.cpp
1 #include "test/lib/common.hpp"
2 #include "test/lib/ReturnMatcher.hpp"
3
4
5 TEST_CASE("memcached_vbucket") {
6 MemcachedPtr memc;
7 LoneReturnMatcher test{*memc};
8 uint32_t server_map[] = {0, 1, 2, 1};
9
10 REQUIRE_SUCCESS(memcached_bucket_set(*memc, server_map, nullptr, 4, 2));
11 REQUIRE(MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET == memcached_behavior_get_distribution(*memc));
12 REQUIRE_SUCCESS(memcached_behavior_set_key_hash(*memc, MEMCACHED_HASH_CRC));
13
14 auto servers = memcached_servers_parse("localhost:11211, localhost1:11210, localhost2:11211");
15 REQUIRE(servers);
16 REQUIRE_SUCCESS(memcached_server_push(*memc, servers));
17 REQUIRE(3 == memcached_server_count(*memc));
18
19 tuple<const char *, uint32_t, uint32_t> keys[] = {
20 {"hello", 0, 0},
21 {"doctor", 0, 0},
22 {"name", 1, 3},
23 {"continue", 1, 3},
24 {"yesterday", 0, 0},
25 {"tomorrow", 1, 1},
26 {"another key", 2, 2}
27 };
28
29 for (const auto &k : keys) {
30 auto [key, server, bucket] = k;
31
32 REQUIRE(bucket == (memcached_generate_hash_value(S(key), memcached_behavior_get_key_hash(*memc)) % 4));
33 REQUIRE(server == memcached_generate_hash(*memc, S(key)));
34 }
35
36 memcached_server_list_free(servers);
37 }