@@ -95,41 +95,47 @@ TEST_F(ClusterConfigTest, ConfigSetInvalidEmpty) {
95
95
}
96
96
97
97
TEST_F (ClusterConfigTest, ConfigSetInvalidMissingSlots) {
98
- EXPECT_EQ (ClusterConfig::CreateFromConfig (
99
- kMyId , {{.slot_ranges = SlotRanges ({{.start = 0 , .end = 16000 }}),
100
- .master = {.id = " other" , .ip = " 192.168.0.100" , .port = 7000 },
101
- .replicas = {},
102
- .migrations = {}}}),
103
- nullptr );
98
+ EXPECT_EQ (
99
+ ClusterConfig::CreateFromConfig (
100
+ kMyId ,
101
+ {{.slot_ranges = SlotRanges ({{.start = 0 , .end = 16000 }}),
102
+ .master = {{.id = " other" , .ip = " 192.168.0.100" , .port = 7000 }, NodeHealth::ONLINE},
103
+ .replicas = {},
104
+ .migrations = {}}}),
105
+ nullptr );
104
106
}
105
107
106
108
TEST_F (ClusterConfigTest, ConfigSetInvalidDoubleBookedSlot) {
107
109
EXPECT_EQ (ClusterConfig::CreateFromConfig (
108
- kMyId ,
109
- ClusterShardInfos ({{.slot_ranges = SlotRanges ({{.start = 0 , .end = 0x3FFF }}),
110
- .master = {.id = " other" , .ip = " 192.168.0.100" , .port = 7000 },
111
- .replicas = {},
112
- .migrations = {}},
113
- {.slot_ranges = SlotRanges ({{.start = 0 , .end = 0 }}),
114
- .master = {.id = " other2" , .ip = " 192.168.0.101" , .port = 7001 },
115
- .replicas = {},
116
- .migrations = {}}})),
110
+ kMyId , ClusterShardInfos (
111
+ {{.slot_ranges = SlotRanges ({{.start = 0 , .end = 0x3FFF }}),
112
+ .master = {{.id = " other" , .ip = " 192.168.0.100" , .port = 7000 },
113
+ NodeHealth::ONLINE},
114
+ .replicas = {},
115
+ .migrations = {}},
116
+ {.slot_ranges = SlotRanges ({{.start = 0 , .end = 0 }}),
117
+ .master = {{.id = " other2" , .ip = " 192.168.0.101" , .port = 7001 },
118
+ NodeHealth::ONLINE},
119
+ .replicas = {},
120
+ .migrations = {}}})),
117
121
nullptr );
118
122
}
119
123
120
124
TEST_F (ClusterConfigTest, ConfigSetInvalidSlotId) {
121
- EXPECT_EQ (ClusterConfig::CreateFromConfig (
122
- kMyId , {{.slot_ranges = SlotRanges ({{.start = 0 , .end = 0x3FFF + 1 }}),
123
- .master = {.id = " other" , .ip = " 192.168.0.100" , .port = 7000 },
124
- .replicas = {},
125
- .migrations = {}}}),
126
- nullptr );
125
+ EXPECT_EQ (
126
+ ClusterConfig::CreateFromConfig (
127
+ kMyId ,
128
+ {{.slot_ranges = SlotRanges ({{.start = 0 , .end = 0x3FFF + 1 }}),
129
+ .master = {{.id = " other" , .ip = " 192.168.0.100" , .port = 7000 }, NodeHealth::ONLINE},
130
+ .replicas = {},
131
+ .migrations = {}}}),
132
+ nullptr );
127
133
}
128
134
129
135
TEST_F (ClusterConfigTest, ConfigSetOk) {
130
136
auto config = ClusterConfig::CreateFromConfig (
131
137
kMyId , {{.slot_ranges = SlotRanges ({{.start = 0 , .end = 0x3FFF }}),
132
- .master = {.id = " other" , .ip = " 192.168.0.100" , .port = 7000 },
138
+ .master = {{ .id = " other" , .ip = " 192.168.0.100" , .port = 7000 }, NodeHealth::ONLINE },
133
139
.replicas = {},
134
140
.migrations = {}}});
135
141
EXPECT_NE (config, nullptr );
@@ -140,30 +146,38 @@ TEST_F(ClusterConfigTest, ConfigSetOk) {
140
146
141
147
TEST_F (ClusterConfigTest, ConfigSetOkWithReplica) {
142
148
auto config = ClusterConfig::CreateFromConfig (
143
- kMyId , {{.slot_ranges = SlotRanges ({{.start = 0 , .end = 0x3FFF }}),
144
- .master = {.id = " other-master" , .ip = " 192.168.0.100" , .port = 7000 },
145
- .replicas = {{.id = " other-replica" , .ip = " 192.168.0.101" , .port = 7001 }},
146
- .migrations = {}}});
149
+ kMyId ,
150
+ {{.slot_ranges = SlotRanges ({{.start = 0 , .end = 0x3FFF }}),
151
+ .master = {{.id = " other-master" , .ip = " 192.168.0.100" , .port = 7000 }, NodeHealth::ONLINE},
152
+ .replicas = {{{.id = " other-replica" , .ip = " 192.168.0.101" , .port = 7001 },
153
+ NodeHealth::ONLINE}},
154
+ .migrations = {}}});
147
155
EXPECT_NE (config, nullptr );
148
156
EXPECT_THAT (config->GetMasterNodeForSlot (0 ),
149
157
NodeMatches (Node{.id = " other-master" , .ip = " 192.168.0.100" , .port = 7000 }));
150
158
}
151
159
152
160
TEST_F (ClusterConfigTest, ConfigSetMultipleInstances) {
153
161
auto config = ClusterConfig::CreateFromConfig (
154
- kMyId , ClusterShardInfos (
155
- {{.slot_ranges = SlotRanges ({{.start = 0 , .end = 5'000 }}),
156
- .master = {.id = " other-master" , .ip = " 192.168.0.100" , .port = 7000 },
157
- .replicas = {{.id = " other-replica" , .ip = " 192.168.0.101" , .port = 7001 }},
158
- .migrations = {}},
159
- {.slot_ranges = SlotRanges ({{.start = 5'001 , .end = 10'000 }}),
160
- .master = {.id = kMyId , .ip = " 192.168.0.102" , .port = 7002 },
161
- .replicas = {{.id = " other-replica2" , .ip = " 192.168.0.103" , .port = 7003 }},
162
- .migrations = {}},
163
- {.slot_ranges = SlotRanges ({{.start = 10'001 , .end = 0x3FFF }}),
164
- .master = {.id = " other-master3" , .ip = " 192.168.0.104" , .port = 7004 },
165
- .replicas = {{.id = " other-replica3" , .ip = " 192.168.0.105" , .port = 7005 }},
166
- .migrations = {}}}));
162
+ kMyId ,
163
+ ClusterShardInfos (
164
+ {{.slot_ranges = SlotRanges ({{.start = 0 , .end = 5'000 }}),
165
+ .master = {{.id = " other-master" , .ip = " 192.168.0.100" , .port = 7000 },
166
+ NodeHealth::ONLINE},
167
+ .replicas = {{{.id = " other-replica" , .ip = " 192.168.0.101" , .port = 7001 },
168
+ NodeHealth::ONLINE}},
169
+ .migrations = {}},
170
+ {.slot_ranges = SlotRanges ({{.start = 5'001 , .end = 10'000 }}),
171
+ .master = {{.id = kMyId , .ip = " 192.168.0.102" , .port = 7002 }, NodeHealth::ONLINE},
172
+ .replicas = {{{.id = " other-replica2" , .ip = " 192.168.0.103" , .port = 7003 },
173
+ NodeHealth::ONLINE}},
174
+ .migrations = {}},
175
+ {.slot_ranges = SlotRanges ({{.start = 10'001 , .end = 0x3FFF }}),
176
+ .master = {{.id = " other-master3" , .ip = " 192.168.0.104" , .port = 7004 },
177
+ NodeHealth::ONLINE},
178
+ .replicas = {{{.id = " other-replica3" , .ip = " 192.168.0.105" , .port = 7005 },
179
+ NodeHealth::ONLINE}},
180
+ .migrations = {}}}));
167
181
EXPECT_NE (config, nullptr );
168
182
SlotSet owned_slots = config->GetOwnedSlots ();
169
183
EXPECT_EQ (owned_slots.ToSlotRanges ().Size (), 1 );
@@ -705,4 +719,23 @@ TEST_F(ClusterConfigTest, ConfigComparison) {
705
719
EXPECT_EQ (config5->GetConfig (), config5->GetConfig ());
706
720
}
707
721
722
+ TEST_F (ClusterConfigTest, NodesHealth) {
723
+ auto config1 = ClusterConfig::CreateFromConfig (" id0" , R"json(
724
+ [
725
+ {
726
+ "slot_ranges": [ { "start": 0, "end": 16383 } ],
727
+ "master": { "id": "id0", "ip": "localhost", "port": 3000, "health" : "online" },
728
+ "replicas": [{ "id": "id1", "ip": "localhost", "port": 3001, "health" : "loading" },
729
+ { "id": "id2", "ip": "localhost", "port": 3002, "health" : "fail" }],
730
+ "migrations": [{ "slot_ranges": [ { "start": 7000, "end": 8000 } ]
731
+ , "ip": "127.0.0.1", "port" : 9001, "node_id": "id1" }]
732
+ }
733
+
734
+ ])json" );
735
+
736
+ EXPECT_EQ (config1->GetConfig ().begin ()->master .health , NodeHealth::ONLINE);
737
+ EXPECT_EQ (config1->GetConfig ().begin ()->replicas .front ().health , NodeHealth::LOADING);
738
+ EXPECT_EQ (config1->GetConfig ().begin ()->replicas .back ().health , NodeHealth::FAIL);
739
+ }
740
+
708
741
} // namespace dfly::cluster
0 commit comments