Skip to content
Snippets Groups Projects
Commit ebedbf2b authored by vito.he's avatar vito.he
Browse files

Merge branch 'develop-2.6.0' of https://github.com/dubbogo/dubbo-go into develop-2.6.0

parents 28a9f8c4 3f151c1c
No related branches found
No related tags found
No related merge requests found
......@@ -38,5 +38,5 @@ const (
)
const (
//EXPORT_KEY = "export"
//EXPORT_KEY = "export"
)
......@@ -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)
......
......@@ -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)
}
......
......@@ -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],
......
......@@ -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
)
......@@ -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
}
......
......@@ -46,7 +46,7 @@ func (bi *BaseInvoker) IsDestroyed() bool {
}
func (bi *BaseInvoker) Invoke(invocation Invocation) Result {
return nil
return &RPCResult{}
}
func (bi *BaseInvoker) Destroy() {
......
......@@ -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
}
......
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&timestamp=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&timestamp=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)
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment