加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
discovery_test.go 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
Gogo 提交于 2021-09-28 19:43 . feat: 实现cache客户端
package client
import (
"gitee.com/Gogo-gitee/registry"
"strconv"
"testing"
"time"
)
func TestDiscoveryNode(t *testing.T) {
hash := New(3, func(key []byte) uint32 {
i, _ := strconv.Atoi(string(key))
return uint32(i)
})
exit := make(chan struct{})
zooKeeperRegistry := registry.ZooKeeperRegistry{
Host: []string{"118.25.250.196"},
}
DiscoveryNode("118.25.250.196", "/test", exit, hash)
zooKeeperRegistry.Register("/test", "6", nil)
zooKeeperRegistry.Register("/test", "2", nil)
zooKeeperRegistry.Register("/test", "4", nil)
time.Sleep(time.Millisecond * 1000)
testCases := map[string]string{
"2": "2",
"11": "2",
"23": "4",
"27": "2",
}
for k, v := range testCases {
if hash.Get(k) != v {
t.Errorf("Asking for %s, should have yielded %s,but got %v", k, v, hash.Get(k))
}
}
zooKeeperRegistry.Register("/test", "8", nil)
time.Sleep(time.Millisecond * 1000)
// 27 should now map to 8.
testCases["27"] = "8"
for k, v := range testCases {
if hash.Get(k) != v {
t.Errorf("Asking for %s, should have yielded %s", k, v)
}
}
exit <- struct{}{}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化