MCPcopy Create free account
hub / github.com/apache/kvrocks-controller / TestCluster_AddRemovePeer

Function TestCluster_AddRemovePeer

store/engine/raft/node_test.go:220–260  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

218}
219
220func TestCluster_AddRemovePeer(t *testing.T) {
221 cluster := NewTestCluster(3)
222 defer cluster.Close()
223
224 ctx := context.Background()
225 require.Eventually(t, func() bool {
226 return cluster.IsReady(ctx)
227 }, 10*time.Second, 100*time.Millisecond)
228
229 n1 := cluster.GetNode(0)
230 require.NoError(t, n1.Set(ctx, "foo", []byte("bar")))
231 require.Eventually(t, func() bool {
232 got, _ := n1.Get(ctx, "foo")
233 return string(got) == "bar"
234 }, 1*time.Second, 100*time.Millisecond)
235
236 t.Run("add a new peer node", func(t *testing.T) {
237 n4, err := cluster.createNode(n1.config.Peers)
238 require.NoError(t, err)
239 require.NotNil(t, n4)
240
241 require.NoError(t, cluster.AddNode(ctx, n4.config.ID, n4.Addr()))
242 require.Eventually(t, func() bool {
243 return n4.IsReady(ctx)
244 }, 10*time.Second, 100*time.Millisecond)
245
246 require.NoError(t, n4.Set(ctx, "foo", []byte("bar-1")))
247 require.Eventually(t, func() bool {
248 got, _ := n1.Get(ctx, "foo")
249 return string(got) == "bar-1"
250 }, 1*time.Second, 100*time.Millisecond)
251 require.Len(t, n1.ListPeers(), 4)
252 })
253
254 t.Run("remove a peer node", func(t *testing.T) {
255 cluster.RemoveNode(ctx, 4)
256 require.Eventually(t, func() bool {
257 return len(n1.ListPeers()) == 3
258 }, 10*time.Second, 100*time.Millisecond)
259 })
260}
261
262func TestTriggerSnapshot(t *testing.T) {
263 cluster := NewTestCluster(3)

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
IsReadyMethod · 0.95
GetNodeMethod · 0.95
createNodeMethod · 0.95
AddNodeMethod · 0.95
RemoveNodeMethod · 0.95
NewTestClusterFunction · 0.85
LenMethod · 0.80
SetMethod · 0.65
GetMethod · 0.65
AddrMethod · 0.65
IsReadyMethod · 0.65

Tested by

no test coverage detected