*: implement Endpoint Watch and new Resolver

This commit is contained in:
limeng01
2021-02-05 16:48:11 +08:00
parent dae29bb719
commit 8feb55f65c
7 changed files with 197 additions and 95 deletions

View File

@@ -27,8 +27,6 @@ import (
)
func TestEndpointManager(t *testing.T) {
t.Skip("Not implemented yet")
defer testutil.AfterTest(t)
clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
@@ -54,10 +52,10 @@ func TestEndpointManager(t *testing.T) {
us := <-w
if us == nil {
t.Fatal("failed to get update", err)
t.Fatal("failed to get update")
}
wu := endpoints.Update{
wu := &endpoints.Update{
Op: endpoints.Add,
Key: "foo/a1",
Endpoint: e1,
@@ -73,16 +71,16 @@ func TestEndpointManager(t *testing.T) {
}
us = <-w
if err != nil {
t.Fatalf("failed to get udpate %v", err)
if us == nil {
t.Fatal("failed to get udpate")
}
wu = endpoints.Update{
wu = &endpoints.Update{
Op: endpoints.Delete,
Key: "foo/a1",
}
if !reflect.DeepEqual(us, wu) {
if !reflect.DeepEqual(us[0], wu) {
t.Fatalf("up = %#v, want %#v", us[1], wu)
}
}
@@ -91,8 +89,6 @@ func TestEndpointManager(t *testing.T) {
// correctly with multiple hosts and correctly receive multiple
// updates in a single revision.
func TestEndpointManagerAtomicity(t *testing.T) {
t.Skip("Not implemented yet")
defer testutil.AfterTest(t)
clus := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})

View File

@@ -20,8 +20,8 @@ import (
"testing"
"time"
etcdnaming "go.etcd.io/etcd/client/v3/naming"
"go.etcd.io/etcd/client/v3/naming/endpoints"
"go.etcd.io/etcd/client/v3/naming/resolver"
grpctest "go.etcd.io/etcd/pkg/v3/grpc_testing"
"go.etcd.io/etcd/pkg/v3/testutil"
"go.etcd.io/etcd/tests/v3/integration"
@@ -65,10 +65,12 @@ func TestEtcdGrpcResolver(t *testing.T) {
t.Fatal("failed to add foo", err)
}
r := &etcdnaming.GRPCResolver{Client: clus.Client(1)}
b := grpc.RoundRobin(r)
b, err := resolver.NewBuilder(clus.Client(1))
if err != nil {
t.Fatal("failed to new resolver builder", err)
}
conn, err := grpc.Dial("foo", grpc.WithInsecure(), grpc.WithBalancer(b))
conn, err := grpc.Dial("etcd:///foo", grpc.WithInsecure(), grpc.WithResolvers(b))
if err != nil {
t.Fatal("failed to connect to foo", err)
}
@@ -108,7 +110,6 @@ func TestEtcdGrpcResolver(t *testing.T) {
}
t.Fatalf("unexpected response from foo (e2): %s", resp.GetPayload().GetBody())
}
break
}
}