X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=testing%2Flib%2FCluster.hpp;h=1bbc9d22325568a7c64369b068b1e64175377c26;hb=d1c9b695e9b3fbfcc94230a242b0290b43f27006;hp=d6a11a7ee79ea65e397d3fa0dfab03b997d88891;hpb=5e54d17fc535a901f384fcbf2cfd420f3a2e7a81;p=awesomized%2Flibmemcached diff --git a/testing/lib/Cluster.hpp b/testing/lib/Cluster.hpp index d6a11a7e..1bbc9d22 100644 --- a/testing/lib/Cluster.hpp +++ b/testing/lib/Cluster.hpp @@ -1,34 +1,45 @@ #pragma once +#include "common.hpp" #include "Server.hpp" -#include -#include - class Cluster { -private: - uint16_t count; - Server proto; - vector cluster; - - map pids; - public: explicit - Cluster(Server &&serv, uint16_t cnt = 0) - : count{cnt} - , proto{serv} + Cluster(Server serv, uint16_t cnt = 0); + + ~Cluster(); + + Cluster(const Cluster &c) = delete; + Cluster &operator = (const Cluster &c) = delete; + + Cluster(Cluster &&c) + : proto{} { - if (!cnt) { - count = thread::hardware_concurrency() ?: 4; - } - reset(); + *this = move(c); + }; + Cluster &operator = (Cluster &&c) { + count = exchange(c.count, 0); + proto = exchange(c.proto, Server{}); + cluster = exchange(c.cluster, {}); + pids = exchange(c.pids, {}); + return *this; } + const vector &getServers() const; + bool start(); void stop(); void reset(); bool isStopped(); - bool isListening(int max_timeout = 1000); + bool isListening(); void wait(); + +private: + uint16_t count; + Server proto; + vector cluster; + map pids; + + bool startServer(Server &server); };