diff --git a/common/constant/key.go b/common/constant/key.go index 3a4f1d05601109637016588a7c1d41d65f47d23c..33dfeba3fe814aee3c085ae487ee3b9a047db4d4 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -38,5 +38,5 @@ const ( ) const ( - //EXPORT_KEY = "export" +//EXPORT_KEY = "export" ) diff --git a/common/proxy/proxy.go b/common/proxy/proxy.go index 13b95607fbf9521028b40c56a0051c0801186a5a..b157b360ba000367e0fc2c0382689e1862095ed4 100644 --- a/common/proxy/proxy.go +++ b/common/proxy/proxy.go @@ -9,12 +9,13 @@ import ( ) import ( + "github.com/dubbo/dubbo-go/config" "github.com/dubbo/dubbo-go/protocol" ) // Proxy struct type Proxy struct { - v interface{} + v config.RPCService invoke protocol.Invoker callBack interface{} attachments map[string]string @@ -31,7 +32,7 @@ func NewProxy(invoke protocol.Invoker, callBack interface{}, attachments map[str } // proxy implement -func (p *Proxy) Implement(v interface{}) error { +func (p *Proxy) Implement(v config.RPCService) error { // check parameters, incoming interface must be a elem's pointer. valueOf := reflect.ValueOf(v) diff --git a/config/support/reference_config.go b/config/support/reference_config.go index 9dc04789b22b8ec9b766e542e7d32d6be34ed734..88d934a4325b581bf3c7f97dc28a9e39f3fb2a2e 100644 --- a/config/support/reference_config.go +++ b/config/support/reference_config.go @@ -63,7 +63,7 @@ func (refconfig *ReferenceConfig) Refer() { } // @v is service provider implemented RPCService -func (refconfig *ReferenceConfig) Implement(v interface{}) error { +func (refconfig *ReferenceConfig) Implement(v config.RPCService) error { return refconfig.pxy.Implement(v) } diff --git a/filter/imp/echo_filter.go b/filter/imp/echo_filter.go index 74e2ed913d3a4bde27127d8b938e9f3a2b5569da..b4803e03ffdec820681a9f82d5efe0eec3ca6320 100644 --- a/filter/imp/echo_filter.go +++ b/filter/imp/echo_filter.go @@ -17,6 +17,7 @@ type EchoFilter struct { } func (ef *EchoFilter) Invoke(invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { + if invocation.MethodName() == constant.ECHO && len(invocation.Arguments()) == 1 { return &protocol.RPCResult{ Rest: invocation.Arguments()[0], diff --git a/go.mod b/go.mod index aa565e80bf028b554e99665b97ad788d031e13b6..b1eed2445c38506c0e3550848bd7c0f57d47024b 100644 --- a/go.mod +++ b/go.mod @@ -9,5 +9,6 @@ require ( github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec github.com/stretchr/testify v1.3.0 github.com/tevino/abool v0.0.0-20170917061928-9b9efcf221b5 + go.uber.org/atomic v1.3.2 gopkg.in/yaml.v2 v2.2.2 ) diff --git a/protocol/dubbo/dubbo_protocol.go b/protocol/dubbo/dubbo_protocol.go index eb6807b6978744a3076577dee818d2bb4ff5087d..23041611076fd4a63ab41b3a24bdd4dcea06f49f 100644 --- a/protocol/dubbo/dubbo_protocol.go +++ b/protocol/dubbo/dubbo_protocol.go @@ -35,7 +35,7 @@ func (dp *DubboProtocol) Export(invoker protocol.Invoker) protocol.Exporter { serviceKey := url.Key() exporter := NewDubboExporter(serviceKey, invoker, dp.ExporterMap()) dp.SetExporterMap(serviceKey, exporter) - log.Info("Export service: ", url.String()) + log.Info("Export service: %s", url.String()) // start server dp.openServer(*url) @@ -45,7 +45,7 @@ func (dp *DubboProtocol) Export(invoker protocol.Invoker) protocol.Exporter { func (dp *DubboProtocol) Refer(url config.IURL) protocol.Invoker { invoker := NewDubboInvoker(url, NewClient()) dp.SetInvokers(invoker) - log.Info("Refer service: ", url.(*config.URL).String()) + log.Info("Refer service: %s", url.(*config.URL).String()) return invoker } diff --git a/protocol/invoker.go b/protocol/invoker.go index 03a39efa26c90e99d0cccf14aed8cb6de901bbfa..3e02805dca70a4b6612666b908bef54e168a436c 100644 --- a/protocol/invoker.go +++ b/protocol/invoker.go @@ -46,7 +46,7 @@ func (bi *BaseInvoker) IsDestroyed() bool { } func (bi *BaseInvoker) Invoke(invocation Invocation) Result { - return nil + return &RPCResult{} } func (bi *BaseInvoker) Destroy() { diff --git a/protocol/jsonrpc/jsonrpc_protocol.go b/protocol/jsonrpc/jsonrpc_protocol.go index 343e03ef389ab82e3292c808913a049d9d166584..259f969149c48e4c75222585dbd1b4d50d243038 100644 --- a/protocol/jsonrpc/jsonrpc_protocol.go +++ b/protocol/jsonrpc/jsonrpc_protocol.go @@ -36,7 +36,7 @@ func (jp *JsonrpcProtocol) Export(invoker protocol.Invoker) protocol.Exporter { serviceKey := url.Key() exporter := NewJsonrpcExporter(serviceKey, invoker, jp.ExporterMap()) jp.SetExporterMap(serviceKey, exporter) - log.Info("Export service: ", url.String()) + log.Info("Export service: %s", url.String()) // start server jp.openServer(*url) @@ -50,7 +50,7 @@ func (jp *JsonrpcProtocol) Refer(url config.IURL) protocol.Invoker { HTTPTimeout: support.GetConsumerConfig().RequestTimeout, })) jp.SetInvokers(invoker) - log.Info("Refer service: ", url.(*config.URL).String()) + log.Info("Refer service: %s", url.(*config.URL).String()) return invoker } diff --git a/protocol/jsonrpc/jsonrpc_protocol_test.go b/protocol/jsonrpc/jsonrpc_protocol_test.go new file mode 100644 index 0000000000000000000000000000000000000000..e9a867b944816a1ae34b5d1a67987a0a07ad4fc9 --- /dev/null +++ b/protocol/jsonrpc/jsonrpc_protocol_test.go @@ -0,0 +1,75 @@ +package jsonrpc + +import ( + "context" + "testing" + "time" +) + +import ( + "github.com/stretchr/testify/assert" +) + +import ( + "github.com/dubbo/dubbo-go/config" + "github.com/dubbo/dubbo-go/config/support" + "github.com/dubbo/dubbo-go/protocol" +) + +func TestJsonrpcProtocol_Export(t *testing.T) { + // Export + proto := GetProtocol() + url, err := config.NewURL(context.Background(), "dubbo://192.168.56.1:20000/com.ikurento.user.UserProvider?anyhost=true&"+ + "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&"+ + "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&"+ + "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&"+ + "side=provider&timeout=3000×tamp=1556509797245") + assert.NoError(t, err) + exporter := proto.Export(protocol.NewBaseInvoker(url)) + + // make sure url + eq := exporter.GetInvoker().GetUrl().URLEqual(url) + assert.True(t, eq) + + // make sure exporterMap after 'Unexport' + _, ok := proto.(*JsonrpcProtocol).ExporterMap().Load(url.Key()) + assert.True(t, ok) + exporter.Unexport() + _, ok = proto.(*JsonrpcProtocol).ExporterMap().Load(url.Key()) + assert.False(t, ok) + + // make sure serverMap after 'Destroy' + _, ok = proto.(*JsonrpcProtocol).serverMap[url.Location] + assert.True(t, ok) + proto.Destroy() + _, ok = proto.(*JsonrpcProtocol).serverMap[url.Location] + assert.False(t, ok) +} + +func TestJsonrpcProtocol_Refer(t *testing.T) { + // Refer + proto := GetProtocol() + url, err := config.NewURL(context.Background(), "dubbo://192.168.56.1:20000/com.ikurento.user.UserProvider?anyhost=true&"+ + "application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&"+ + "environment=dev&interface=com.ikurento.user.UserProvider&ip=192.168.56.1&methods=GetUser%2C&"+ + "module=dubbogo+user-info+server&org=ikurento.com&owner=ZX&pid=1447&revision=0.0.1&"+ + "side=provider&timeout=3000×tamp=1556509797245") + assert.NoError(t, err) + con := support.ConsumerConfig{ + ConnectTimeout: 5 * time.Second, + RequestTimeout: 5 * time.Second, + } + support.SetConsumerConfig(con) + invoker := proto.Refer(url) + + // make sure url + eq := invoker.GetUrl().URLEqual(url) + assert.True(t, eq) + + // make sure invokers after 'Destroy' + invokersLen := len(proto.(*JsonrpcProtocol).Invokers()) + assert.Equal(t, 1, invokersLen) + proto.Destroy() + invokersLen = len(proto.(*JsonrpcProtocol).Invokers()) + assert.Equal(t, 0, invokersLen) +}