1bbc9d22325568a7c64369b068b1e64175377c26
[m6w6/libmemcached] / testing / lib / Cluster.hpp
1 #pragma once
2
3 #include "common.hpp"
4 #include "Server.hpp"
5
6 class Cluster {
7 public:
8 explicit
9 Cluster(Server serv, uint16_t cnt = 0);
10
11 ~Cluster();
12
13 Cluster(const Cluster &c) = delete;
14 Cluster &operator = (const Cluster &c) = delete;
15
16 Cluster(Cluster &&c)
17 : proto{}
18 {
19 *this = move(c);
20 };
21 Cluster &operator = (Cluster &&c) {
22 count = exchange(c.count, 0);
23 proto = exchange(c.proto, Server{});
24 cluster = exchange(c.cluster, {});
25 pids = exchange(c.pids, {});
26 return *this;
27 }
28
29 const vector<Server> &getServers() const;
30
31 bool start();
32 void stop();
33 void reset();
34 bool isStopped();
35 bool isListening();
36 void wait();
37
38 private:
39 uint16_t count;
40 Server proto;
41 vector<Server> cluster;
42 map<pid_t, Server *> pids;
43
44 bool startServer(Server &server);
45 };