2018-08-31 16:32:53 +08:00
|
|
|
#include <gtest/gtest.h>
|
2018-01-10 19:18:03 +08:00
|
|
|
|
2018-08-31 16:32:53 +08:00
|
|
|
#include "communication/rpc/client_pool.hpp"
|
2018-01-24 19:16:14 +08:00
|
|
|
#include "communication/rpc/server.hpp"
|
2018-10-05 18:37:23 +08:00
|
|
|
#include "database/distributed/distributed_counters.hpp"
|
2018-01-10 19:18:03 +08:00
|
|
|
|
2018-10-16 15:12:19 +08:00
|
|
|
#include "test_coordination.hpp"
|
2018-01-10 19:18:03 +08:00
|
|
|
|
|
|
|
TEST(CountersDistributed, All) {
|
2018-10-16 15:12:19 +08:00
|
|
|
TestMasterCoordination coordination;
|
|
|
|
database::MasterCounters master(&coordination);
|
2018-10-16 16:58:41 +08:00
|
|
|
coordination.Start();
|
|
|
|
|
2018-10-16 15:12:19 +08:00
|
|
|
communication::rpc::ClientPool master_client_pool(
|
|
|
|
coordination.GetServerEndpoint());
|
2018-01-10 19:18:03 +08:00
|
|
|
|
2018-08-31 16:32:53 +08:00
|
|
|
database::WorkerCounters w1(&master_client_pool);
|
|
|
|
database::WorkerCounters w2(&master_client_pool);
|
2018-01-10 19:18:03 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(w1.Get("a"), 0);
|
|
|
|
EXPECT_EQ(w1.Get("a"), 1);
|
|
|
|
EXPECT_EQ(w2.Get("a"), 2);
|
|
|
|
EXPECT_EQ(w1.Get("a"), 3);
|
|
|
|
EXPECT_EQ(master.Get("a"), 4);
|
|
|
|
|
|
|
|
EXPECT_EQ(master.Get("b"), 0);
|
|
|
|
EXPECT_EQ(w2.Get("b"), 1);
|
|
|
|
w1.Set("b", 42);
|
|
|
|
EXPECT_EQ(w2.Get("b"), 42);
|
2018-09-27 21:07:46 +08:00
|
|
|
|
2018-10-16 15:12:19 +08:00
|
|
|
coordination.Stop();
|
2018-01-10 19:18:03 +08:00
|
|
|
}
|