-
Notifications
You must be signed in to change notification settings - Fork 876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(server): SetConfig() for ClusterConfig. #1202
Changes from all commits
85184b2
0916eb8
768e83e
5f4da9b
530cbba
1be7e42
0740767
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,28 @@ | |
|
||
#include "server/cluster/cluster_config.h" | ||
|
||
#include <gmock/gmock-matchers.h> | ||
|
||
#include "base/gtest.h" | ||
#include "base/logging.h" | ||
|
||
using namespace std; | ||
using Node = dfly::ClusterConfig::Node; | ||
|
||
namespace dfly { | ||
|
||
class ClusterConfigTest : public ::testing::Test {}; | ||
MATCHER_P(NodeMatches, expected, "") { | ||
return arg.id == expected.id && arg.ip == expected.ip && arg.port == expected.port; | ||
} | ||
|
||
class ClusterConfigTest : public ::testing::Test { | ||
protected: | ||
const string kMyId = "my-id"; | ||
ClusterConfig config_{kMyId}; | ||
}; | ||
|
||
TEST_F(ClusterConfigTest, KeyTagTest) { | ||
std::string key = "{user1000}.following"; | ||
string key = "{user1000}.following"; | ||
ASSERT_EQ("user1000", ClusterConfig::KeyTag(key)); | ||
|
||
key = " foo{}{bar}"; | ||
|
@@ -27,4 +41,81 @@ TEST_F(ClusterConfigTest, KeyTagTest) { | |
ASSERT_EQ(key, ClusterConfig::KeyTag(key)); | ||
} | ||
|
||
TEST_F(ClusterConfigTest, ConfigEmpty) { | ||
// Test that empty-initialization causes none of the slots to be owned locally. | ||
for (SlotId i : {0, 1, 10, 100, 1'000, 10'000, 16'000, 0x3FFF}) { | ||
EXPECT_FALSE(config_.IsMySlot(i)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a test where you check that IsMySlot is true and for some false There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good idea! |
||
} | ||
} | ||
|
||
TEST_F(ClusterConfigTest, ConfigSetInvalidEmpty) { | ||
EXPECT_FALSE(config_.SetConfig({})); | ||
} | ||
|
||
TEST_F(ClusterConfigTest, ConfigSetInvalidMissingSlots) { | ||
EXPECT_FALSE(config_.SetConfig({{.slot_ranges = {{.start = 0, .end = 16000}}, | ||
.master = {.id = "other", .ip = "192.168.0.100", .port = 7000}, | ||
.replicas = {}}})); | ||
} | ||
|
||
TEST_F(ClusterConfigTest, ConfigSetInvalidDoubleBookedSlot) { | ||
EXPECT_FALSE(config_.SetConfig({{.slot_ranges = {{.start = 0, .end = 0x3FFF}}, | ||
.master = {.id = "other", .ip = "192.168.0.100", .port = 7000}, | ||
.replicas = {}}, | ||
{.slot_ranges = {{.start = 0, .end = 0}}, | ||
.master = {.id = "other2", .ip = "192.168.0.101", .port = 7001}, | ||
.replicas = {}}})); | ||
} | ||
|
||
TEST_F(ClusterConfigTest, ConfigSetOk) { | ||
EXPECT_TRUE(config_.SetConfig({{.slot_ranges = {{.start = 0, .end = 0x3FFF}}, | ||
.master = {.id = "other", .ip = "192.168.0.100", .port = 7000}, | ||
.replicas = {}}})); | ||
EXPECT_THAT(config_.GetMasterNodeForSlot(0), | ||
NodeMatches(Node{.id = "other", .ip = "192.168.0.100", .port = 7000})); | ||
} | ||
|
||
TEST_F(ClusterConfigTest, ConfigSetOkWithReplicas) { | ||
EXPECT_TRUE(config_.SetConfig( | ||
{{.slot_ranges = {{.start = 0, .end = 0x3FFF}}, | ||
.master = {.id = "other-master", .ip = "192.168.0.100", .port = 7000}, | ||
.replicas = {{.id = "other-replica", .ip = "192.168.0.101", .port = 7001}}}})); | ||
EXPECT_THAT(config_.GetMasterNodeForSlot(0), | ||
NodeMatches(Node{.id = "other-master", .ip = "192.168.0.100", .port = 7000})); | ||
} | ||
|
||
TEST_F(ClusterConfigTest, ConfigSetMultipleInstances) { | ||
EXPECT_TRUE(config_.SetConfig( | ||
{{.slot_ranges = {{.start = 0, .end = 5'000}}, | ||
.master = {.id = "other-master", .ip = "192.168.0.100", .port = 7000}, | ||
.replicas = {{.id = "other-replica", .ip = "192.168.0.101", .port = 7001}}}, | ||
{.slot_ranges = {{.start = 5'001, .end = 10'000}}, | ||
.master = {.id = kMyId, .ip = "192.168.0.102", .port = 7002}, | ||
.replicas = {{.id = "other-replica2", .ip = "192.168.0.103", .port = 7003}}}, | ||
{.slot_ranges = {{.start = 10'001, .end = 0x3FFF}}, | ||
.master = {.id = "other-master3", .ip = "192.168.0.104", .port = 7004}, | ||
.replicas = {{.id = "other-replica3", .ip = "192.168.0.105", .port = 7005}}}})); | ||
{ | ||
for (int i = 0; i <= 5'000; ++i) { | ||
EXPECT_THAT(config_.GetMasterNodeForSlot(i), | ||
NodeMatches(Node{.id = "other-master", .ip = "192.168.0.100", .port = 7000})); | ||
EXPECT_FALSE(config_.IsMySlot(i)); | ||
} | ||
} | ||
{ | ||
for (int i = 5'001; i <= 10'000; ++i) { | ||
EXPECT_THAT(config_.GetMasterNodeForSlot(i), | ||
NodeMatches(Node{.id = kMyId, .ip = "192.168.0.102", .port = 7002})); | ||
EXPECT_TRUE(config_.IsMySlot(i)); | ||
} | ||
} | ||
{ | ||
for (int i = 10'001; i <= 0x3FFF; ++i) { | ||
EXPECT_THAT(config_.GetMasterNodeForSlot(i), | ||
NodeMatches(Node{.id = "other-master3", .ip = "192.168.0.104", .port = 7004})); | ||
EXPECT_FALSE(config_.IsMySlot(i)); | ||
} | ||
} | ||
} | ||
|
||
} // namespace dfly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add log prints so it will be easier to understand if we have a problem with the config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's a great idea!