mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-16 05:40:49 +08:00
support mset in cluster
This commit is contained in:
43
cluster/core/tests.go
Normal file
43
cluster/core/tests.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
dbimpl "github.com/hdt3213/godis/database"
|
||||
)
|
||||
|
||||
// MakeTestCluster creates a cluster for test, which communications are done through local function calls.
|
||||
func MakeTestCluster(ids []string) map[string]*Cluster {
|
||||
nodes := make(map[string]*Cluster)
|
||||
connections := NewInMemConnectionFactory()
|
||||
connections.nodes = nodes
|
||||
for _, id := range ids {
|
||||
db := dbimpl.NewStandaloneServer()
|
||||
cluster := &Cluster{
|
||||
db: db,
|
||||
config: &Config{},
|
||||
connections: connections,
|
||||
rebalanceManger: newRebalanceManager(),
|
||||
slotsManager: newSlotsManager(),
|
||||
transactions: newTransactionManager(),
|
||||
id_: id,
|
||||
}
|
||||
cluster.pickNodeImpl = func(slotID uint32) string {
|
||||
// skip raft for test
|
||||
index := int(slotID) % len(ids)
|
||||
return ids[index]
|
||||
}
|
||||
cluster.getSlotImpl = func(key string) uint32 {
|
||||
// backdoor for test
|
||||
i, err := strconv.Atoi(key)
|
||||
if err == nil && i < SlotCount {
|
||||
return uint32(i)
|
||||
}
|
||||
return defaultGetSlotImpl(cluster, key)
|
||||
}
|
||||
cluster.injectInsertCallback()
|
||||
cluster.injectDeleteCallback()
|
||||
nodes[id] = cluster
|
||||
}
|
||||
return nodes
|
||||
}
|
Reference in New Issue
Block a user