}
REQUIRE(memcached_create(&memc));
+
+ for (const auto &[behavior, value] : to_set) {
+ REQUIRE(MEMCACHED_SUCCESS == memcached_behavior_set(&memc, behavior, value));
+ }
+
for (const auto &server : cluster.getServers()) {
auto target = server.getSocketOrPort();
if (holds_alternative<string>(target)) {
init();
}
-MemcachedCluster::MemcachedCluster(Cluster &&cluster_)
+MemcachedCluster::MemcachedCluster(Cluster &&cluster_, behaviors_t to_set_)
: cluster{move(cluster_)}
+, to_set{move(to_set_)}
{
init();
}
Server::arg_pair_t{"-U", random_socket_or_port_string},
Server::arg_t{"-v"}
}
- }}};
+ }}, {
+ {MEMCACHED_BEHAVIOR_USE_UDP, 1}
+ }};
}
#if LIBMEMCACHED_WITH_SASL_SUPPORT
Server::arg_pair_t{"-p", random_socket_or_port_string},
Server::arg_t{"-S"}
}
- }}};
- mc.enableBinaryProto();
+ }}, {
+ {MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1},
+ }};
REQUIRE(MEMCACHED_SUCCESS == memcached_set_sasl_auth_data(&mc.memc,
"memcached", "memcached"));
return mc;
MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, memcached_server_count(&memc) - 1));
}
-void MemcachedCluster::enableUdp(bool enable) {
- REQUIRE(MEMCACHED_SUCCESS == memcached_behavior_set(&memc,
- MEMCACHED_BEHAVIOR_USE_UDP, enable));
-}
-
void MemcachedCluster::killOneServer() {
const auto &servers = cluster.getServers();
const auto &victim = servers[random_num(0UL, servers.size() - 1)];
class MemcachedCluster {
public:
+ using behavior_t = pair<memcached_behavior_t, uint64_t>;
+ using behaviors_t = vector<behavior_t>;
+
Cluster cluster;
memcached_st memc{empty_memc};
ReturnMatcher returns{&memc};
MemcachedCluster();
- explicit
- MemcachedCluster(Cluster &&cluster);
+ explicit MemcachedCluster(Cluster &&cluster, behaviors_t to_set = {});
~MemcachedCluster();
MemcachedCluster(const MemcachedCluster &) = delete;
MemcachedCluster &operator=(const MemcachedCluster &) = delete;
- MemcachedCluster(MemcachedCluster &&mc);;
+ MemcachedCluster(MemcachedCluster &&mc);
MemcachedCluster &operator=(MemcachedCluster &&mc);
void enableBinaryProto(bool enable = true);
void killOneServer();
private:
+ behaviors_t to_set;
static const memcached_st empty_memc;
void init();
auto test = MemcachedCluster::udp();
auto memc = &test.memc;
- SECTION("sets reply flag") {
- // FIXME: bad internals test
- REQUIRE(memc->flags.reply);
- REQUIRE_FALSE(memc->flags.use_udp);
- REQUIRE_FALSE(memc->flags.use_udp == memc->flags.reply);
- test.enableUdp();
- REQUIRE_FALSE(memc->flags.reply);
- REQUIRE(memc->flags.use_udp);
- REQUIRE_FALSE(memc->flags.use_udp == memc->flags.reply);
- test.enableUdp(false);
- REQUIRE(memc->flags.reply);
- REQUIRE_FALSE(memc->flags.use_udp);
- REQUIRE_FALSE(memc->flags.use_udp == memc->flags.reply);
- }
-
- test.enableUdp();
-
SECTION("compat") {
memcached_return_t rc;
REQUIRE_RC(MEMCACHED_INVALID_ARGUMENTS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, true));