remove ambigous Cluster ctor
[awesomized/libmemcached] / test / lib / Cluster.cpp
index e1375bfde90ed50c65fcb52a3f0cff54c3be35fa..3ecc6e9abea2d629009e3a54cf05e610bdef2e7c 100644 (file)
@@ -7,13 +7,12 @@ Cluster::Cluster(Server serv, uint16_t cnt)
 : count{cnt}
 , proto{move(serv)}
 {
-  if (count < 4) {
-      count = stoi(getenv_else("MEMCACHED_CLUSTER", "4"));
-  }
   if (!count) {
     count = 1;
   }
-  reset();
+  for (int i = 0; i < count; ++i) {
+    cluster.push_back(proto);
+  }
 }
 
 Cluster::~Cluster() {
@@ -25,14 +24,6 @@ const vector<Server> &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;
 
@@ -45,11 +36,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);
+    }
   }
 }
 
@@ -111,3 +106,9 @@ void Cluster::wait() {
     }
   }
 }
+
+bool Cluster::restart() {
+  stop();
+  wait();
+  return start();
+}