2018-10-04 21:23:07 +08:00
|
|
|
#include <gtest/gtest.h>
|
2017-11-14 15:47:50 +08:00
|
|
|
|
2018-10-04 21:23:07 +08:00
|
|
|
#include "storage/distributed/address.hpp"
|
|
|
|
#include "storage/distributed/gid.hpp"
|
2017-11-14 15:47:50 +08:00
|
|
|
|
|
|
|
using storage::Address;
|
|
|
|
|
|
|
|
TEST(Address, Local) {
|
|
|
|
std::string a{"bla"};
|
|
|
|
Address<std::string> address(&a);
|
|
|
|
|
|
|
|
EXPECT_TRUE(address.is_local());
|
|
|
|
EXPECT_FALSE(address.is_remote());
|
|
|
|
EXPECT_EQ(address.local(), &a);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Address, CopyCompare) {
|
|
|
|
int a = 12;
|
|
|
|
int b = 13;
|
|
|
|
Address<int> addr_a{&a};
|
|
|
|
EXPECT_EQ(Address<int>{&a}, addr_a);
|
|
|
|
EXPECT_FALSE(Address<int>{&b} == addr_a);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Address, Global) {
|
2017-12-28 17:35:12 +08:00
|
|
|
int worker_id{17};
|
2017-12-05 17:32:31 +08:00
|
|
|
uint64_t local_id{31};
|
2017-12-28 17:35:12 +08:00
|
|
|
gid::Generator generator(13);
|
2018-01-30 02:16:06 +08:00
|
|
|
auto gid = generator.Next(local_id);
|
|
|
|
Address<int> address{gid, worker_id};
|
2017-11-14 15:47:50 +08:00
|
|
|
|
|
|
|
EXPECT_TRUE(address.is_remote());
|
|
|
|
EXPECT_FALSE(address.is_local());
|
2018-01-30 02:16:06 +08:00
|
|
|
EXPECT_EQ(address.gid(), gid);
|
2017-12-28 17:35:12 +08:00
|
|
|
EXPECT_EQ(address.worker_id(), worker_id);
|
2017-11-14 15:47:50 +08:00
|
|
|
}
|