You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
888 B
51 lines
888 B
5 years ago
|
package zookeeper
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"testing"
|
||
|
"time"
|
||
|
|
||
|
"github.com/bilibili/kratos/pkg/naming"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
_testAppid = "test_appid"
|
||
|
|
||
|
_testConf = &Config{
|
||
|
Root: "/test",
|
||
|
Endpoints: []string{"127.0.0.1:2181"},
|
||
|
}
|
||
|
_testIns = &naming.Instance{
|
||
|
AppID: _testAppid,
|
||
|
Addrs: []string{"grpc://127.0.0.1:9000"},
|
||
|
Metadata: map[string]string{
|
||
|
"test_key": "test_value",
|
||
|
},
|
||
|
}
|
||
|
)
|
||
|
|
||
|
func TestZookeeper(t *testing.T) {
|
||
|
zk, err := New(_testConf)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
res := zk.Build(_testAppid)
|
||
|
go func() {
|
||
|
for event := range res.Watch() {
|
||
|
t.Log(event)
|
||
|
}
|
||
|
}()
|
||
|
_, err = zk.Register(context.TODO(), _testIns)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
time.Sleep(time.Second)
|
||
|
in, ok := res.Fetch(context.TODO())
|
||
|
if !ok {
|
||
|
t.Fatal("failed to resolver fetch")
|
||
|
}
|
||
|
if len(in.Instances) != 1 {
|
||
|
t.Fatalf("Instances not match, got:%d want:1", len(in.Instances))
|
||
|
}
|
||
|
}
|