X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=test%2Flib%2FCluster.cpp;h=54de9398564e25c5cba32f328fe56299448b7bcd;hb=fd66e60622e8e139753f62454cfdd5be662e39a0;hp=c3c625cf04eb225069a08d4b5f732ea68132eade;hpb=9f262c9ea92d4869715ca6f534c80075a8310ac1;p=m6w6%2Flibmemcached diff --git a/test/lib/Cluster.cpp b/test/lib/Cluster.cpp index c3c625cf..54de9398 100644 --- a/test/lib/Cluster.cpp +++ b/test/lib/Cluster.cpp @@ -7,10 +7,22 @@ Cluster::Cluster(Server serv, uint16_t cnt) : count{cnt} , proto{move(serv)} { - if (!cnt) { - count = thread::hardware_concurrency()/2 ?: 4; + if (count < 4) { + count = stoi(getenv_else("MEMCACHED_CLUSTER", "4")); + } + if (!count) { + count = 1; + } + for (int i = 0; i < count; ++i) { + cluster.push_back(proto); } - reset(); +} + +Cluster::Cluster(vector servers) +: count{servers.size()} +, cluster{move(servers)} +{ + } Cluster::~Cluster() { @@ -22,14 +34,6 @@ const vector &Cluster::getServers() const { return cluster; } -void Cluster::reset() { - pids.clear(); - cluster.clear(); - for (int i = 0; i < count; ++i) { - cluster.push_back(proto); - } -} - bool Cluster::start() { bool started = true; @@ -42,11 +46,15 @@ bool Cluster::start() { return started; } -void Cluster::stop() { +void Cluster::stop(bool graceful) { for (auto &server : cluster) { server.drain(); - // no cookies for memcached; TERM is just too slow - server.signal(SIGKILL); + if (graceful) { + server.stop(); + } else { + // no cookies for memcached; TERM is just too slow + server.signal(SIGKILL); + } } } @@ -108,3 +116,9 @@ void Cluster::wait() { } } } + +bool Cluster::restart() { + stop(); + wait(); + return start(); +}