other cluster codes

This commit is contained in:
finley
2025-02-03 18:37:07 +08:00
parent b699918223
commit 0bf068f51c
38 changed files with 175 additions and 4479 deletions

View File

@@ -6,6 +6,9 @@ import (
"time"
"github.com/hdt3213/godis/cluster/raft"
"github.com/hdt3213/godis/lib/utils"
"github.com/hdt3213/godis/redis/connection"
"github.com/hdt3213/godis/redis/protocol"
)
func TestClusterBootstrap(t *testing.T) {
@@ -16,6 +19,9 @@ func TestClusterBootstrap(t *testing.T) {
defer func() {
os.RemoveAll(leaderDir)
}()
RegisterDefaultCmd("get")
RegisterDefaultCmd("set")
// connection stub
connections := NewInMemConnectionFactory()
leaderCfg := &Config{
@@ -35,6 +41,20 @@ func TestClusterBootstrap(t *testing.T) {
}
connections.nodes[leaderCfg.RedisAdvertiseAddr] = leader
// set key-values for test
testEntries := make(map[string]string)
c := connection.NewFakeConn()
for i := 0; i < 1000; i++ {
key := utils.RandString(10)
value := utils.RandString(10)
testEntries[key] = value
result := leader.Exec(c, utils.ToCmdLine("set", key, value))
if !protocol.IsOKReply(result) {
t.Errorf("command [set] failed: %s", string(result.ToBytes()))
return
}
}
// start follower
followerDir := "test/1"
os.RemoveAll(followerDir)
@@ -100,4 +120,15 @@ func TestClusterBootstrap(t *testing.T) {
time.Sleep(time.Second)
}
}
// set key-values for test
for key, value := range testEntries {
c := connection.NewFakeConn()
result := leader.Exec(c, utils.ToCmdLine("get", key))
result2 := result.(*protocol.BulkReply)
if string(result2.Arg) != value {
t.Errorf("command [get] failed: %s", string(result.ToBytes()))
return
}
}
}