From ac47753083baaf147e9e1351811640ff2d2d4b56 Mon Sep 17 00:00:00 2001 From: xujianhai666 <zero.xu@bytedance.com> Date: Sat, 21 Dec 2019 20:38:44 +0800 Subject: [PATCH] add new client test --- protocol/grpc/client_test.go | 15 ++++++++++++++- protocol/grpc/common_test.go | 4 ++-- protocol/grpc/grpc_protocol.go | 1 - 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/protocol/grpc/client_test.go b/protocol/grpc/client_test.go index b63ceefae..308511ee6 100644 --- a/protocol/grpc/client_test.go +++ b/protocol/grpc/client_test.go @@ -18,16 +18,18 @@ limitations under the License. package grpc import ( + "context" "reflect" "testing" ) import ( - "github.com/bmizerany/assert" + "github.com/stretchr/testify/assert" "google.golang.org/grpc" ) import ( + "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/protocol/grpc/internal" ) @@ -40,3 +42,14 @@ func TestGetInvoker(t *testing.T) { expected := reflect.TypeOf(internal.NewGreeterClient(nil)) assert.Equal(t, i, expected) } + +func TestNewClient(t *testing.T) { + go internal.InitGrpcServer() + defer internal.ShutdownGrpcServer() + + var impl *internal.GrpcGreeterImpl + url, err := common.NewURL(context.Background(), "grpc://127.0.0.1:20000/GrpcGreeterImpl?accesslog=&anyhost=true&app.version=0.0.1&application=BDTService&async=false&bean.name=GrpcGreeterImpl&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&execute.limit=&execute.limit.rejected.handler=&generic=false&group=&interface=io.grpc.examples.helloworld.GreeterGrpc%24IGreeter&ip=192.168.1.106&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=1&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps.limit.strategy=&methods.SayHello.weight=0&module=dubbogo+say-hello+client&name=BDTService&organization=ikurento.com&owner=ZX&pid=49427&reference.filter=cshutdown®istry.role=3&remote.timestamp=1576923717&retries=&service.filter=echo%2Ctoken%2Caccesslog%2Ctps%2Cexecute%2Cpshutdown&side=provider×tamp=1576923740&tps.limit.interval=&tps.limit.rate=&tps.limit.rejected.handler=&tps.limit.strategy=&tps.limiter=&version=&warmup=100!") + assert.Nil(t, err) + cli := NewClient(impl, url) + assert.NotNil(t, cli) +} diff --git a/protocol/grpc/common_test.go b/protocol/grpc/common_test.go index 2110f538d..7f78bdc40 100644 --- a/protocol/grpc/common_test.go +++ b/protocol/grpc/common_test.go @@ -35,14 +35,14 @@ import ( // userd grpc-dubbo biz service func addService() { - config.SetProviderService(NewGreeterProvider()) + config.SetProviderService(newGreeterProvider()) } type greeterProvider struct { *greeterProviderBase } -func NewGreeterProvider() *greeterProvider { +func newGreeterProvider() *greeterProvider { return &greeterProvider{ greeterProviderBase: &greeterProviderBase{}, } diff --git a/protocol/grpc/grpc_protocol.go b/protocol/grpc/grpc_protocol.go index 95b25373b..fb2df33bd 100644 --- a/protocol/grpc/grpc_protocol.go +++ b/protocol/grpc/grpc_protocol.go @@ -49,7 +49,6 @@ func NewGRPCProtocol() *GrpcProtocol { } } -// 缂哄皯涓€涓� type 淇℃伅, 鏃犳硶杩涜binding func (gp *GrpcProtocol) Export(invoker protocol.Invoker) protocol.Exporter { url := invoker.GetUrl() serviceKey := url.ServiceKey() -- GitLab