Skip to content
Snippets Groups Projects
Commit 5f90f484 authored by flycash's avatar flycash
Browse files

Merge develop

parents bc64aedc 6b26d4b0
No related branches found
No related tags found
No related merge requests found
Showing
with 154 additions and 82 deletions
......@@ -2,6 +2,7 @@
[![Build Status](https://travis-ci.org/apache/dubbo-go.svg?branch=master)](https://travis-ci.org/apache/dubbo-go)
[![codecov](https://codecov.io/gh/apache/dubbo-go/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-go)
[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/apache/dubbo-go?tab=doc)
---
Apache Dubbo Go Implementation.
......
......@@ -39,7 +39,7 @@ import (
)
var (
availableUrl, _ = common.NewURL(context.Background(), "dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
availableUrl, _ = common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
)
func registerAvailable(t *testing.T, invoker *mock.MockInvoker) protocol.Invoker {
......
......@@ -18,7 +18,6 @@
package cluster_impl
import (
"context"
"fmt"
"testing"
)
......@@ -37,7 +36,7 @@ import (
func Test_StickyNormal(t *testing.T) {
invokers := []protocol.Invoker{}
for i := 0; i < 10; i++ {
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url.SetParam("sticky", "true")
invokers = append(invokers, NewMockInvoker(url, 1))
}
......@@ -51,7 +50,7 @@ func Test_StickyNormal(t *testing.T) {
func Test_StickyNormalWhenError(t *testing.T) {
invokers := []protocol.Invoker{}
for i := 0; i < 10; i++ {
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url.SetParam("sticky", "true")
invokers = append(invokers, NewMockInvoker(url, 1))
}
......
......@@ -39,7 +39,7 @@ import (
)
var (
broadcastUrl, _ = common.NewURL(context.TODO(), "dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
broadcastUrl, _ = common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
)
func registerBroadcast(t *testing.T, mockInvokers ...*mock.MockInvoker) protocol.Invoker {
......
......@@ -41,7 +41,7 @@ import (
)
var (
failbackUrl, _ = common.NewURL(context.TODO(), "dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
failbackUrl, _ = common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
)
// registerFailback register failbackCluster to cluster extension.
......
......@@ -39,7 +39,7 @@ import (
)
var (
failfastUrl, _ = common.NewURL(context.TODO(), "dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
failfastUrl, _ = common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
)
// registerFailfast register failfastCluster to cluster extension.
......
......@@ -39,9 +39,9 @@ import (
"github.com/apache/dubbo-go/protocol/invocation"
)
/////////////////////////////
// ///////////////////////////
// mock invoker
/////////////////////////////
// ///////////////////////////
type MockInvoker struct {
url common.URL
......@@ -107,7 +107,7 @@ func normalInvoke(t *testing.T, successCount int, urlParam url.Values, invocatio
invokers := []protocol.Invoker{}
for i := 0; i < 10; i++ {
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i), common.WithParams(urlParam))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i), common.WithParams(urlParam))
invokers = append(invokers, NewMockInvoker(url, successCount))
}
......@@ -157,7 +157,7 @@ func Test_FailoverDestroy(t *testing.T) {
invokers := []protocol.Invoker{}
for i := 0; i < 10; i++ {
url, _ := common.NewURL(context.Background(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
invokers = append(invokers, NewMockInvoker(url, 1))
}
......
......@@ -39,7 +39,7 @@ import (
)
var (
failsafeUrl, _ = common.NewURL(context.TODO(), "dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
failsafeUrl, _ = common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
)
// registerFailsafe register failsafeCluster to cluster extension.
......
......@@ -42,7 +42,7 @@ import (
)
var (
forkingUrl, _ = common.NewURL(context.TODO(), "dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
forkingUrl, _ = common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
)
func registerForking(t *testing.T, mockInvokers ...*mock.MockInvoker) protocol.Invoker {
......
......@@ -39,7 +39,7 @@ func Test_RegAwareInvokeSuccess(t *testing.T) {
invokers := []protocol.Invoker{}
for i := 0; i < 10; i++ {
url, _ := common.NewURL(context.Background(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
invokers = append(invokers, NewMockInvoker(url, 1))
}
......@@ -55,7 +55,7 @@ func TestDestroy(t *testing.T) {
invokers := []protocol.Invoker{}
for i := 0; i < 10; i++ {
url, _ := common.NewURL(context.Background(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
invokers = append(invokers, NewMockInvoker(url, 1))
}
......
......@@ -18,7 +18,6 @@
package directory
import (
"context"
"fmt"
"testing"
)
......@@ -36,7 +35,7 @@ import (
func Test_StaticDirList(t *testing.T) {
invokers := []protocol.Invoker{}
for i := 0; i < 10; i++ {
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
invokers = append(invokers, protocol.NewBaseInvoker(url))
}
......@@ -47,7 +46,7 @@ func Test_StaticDirList(t *testing.T) {
func Test_StaticDirDestroy(t *testing.T) {
invokers := []protocol.Invoker{}
for i := 0; i < 10; i++ {
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
invokers = append(invokers, protocol.NewBaseInvoker(url))
}
......
......@@ -18,7 +18,6 @@
package loadbalance
import (
"context"
"testing"
)
......@@ -44,7 +43,7 @@ type consistentHashSelectorSuite struct {
func (s *consistentHashSelectorSuite) SetupTest() {
var invokers []protocol.Invoker
url, _ := common.NewURL(context.TODO(),
url, _ := common.NewURL(
"dubbo://192.168.1.0:20000/org.apache.demo.HelloService?methods.echo.hash.arguments=0,1")
invokers = append(invokers, protocol.NewBaseInvoker(url))
s.selector = newConsistentHashSelector(invokers, "echo", 999944)
......@@ -56,8 +55,8 @@ func (s *consistentHashSelectorSuite) TestToKey() {
}
func (s *consistentHashSelectorSuite) TestSelectForKey() {
url1, _ := common.NewURL(context.TODO(), "dubbo://192.168.1.0:8080")
url2, _ := common.NewURL(context.TODO(), "dubbo://192.168.1.0:8081")
url1, _ := common.NewURL("dubbo://192.168.1.0:8080")
url2, _ := common.NewURL("dubbo://192.168.1.0:8081")
s.selector.virtualInvokers = make(map[uint32]protocol.Invoker)
s.selector.virtualInvokers[99874] = protocol.NewBaseInvoker(url1)
s.selector.virtualInvokers[9999945] = protocol.NewBaseInvoker(url2)
......@@ -84,11 +83,11 @@ type consistentHashLoadBalanceSuite struct {
func (s *consistentHashLoadBalanceSuite) SetupTest() {
var err error
s.url1, err = common.NewURL(context.TODO(), "dubbo://192.168.1.0:8080/org.apache.demo.HelloService?methods.echo.hash.arguments=0,1")
s.url1, err = common.NewURL("dubbo://192.168.1.0:8080/org.apache.demo.HelloService?methods.echo.hash.arguments=0,1")
s.NoError(err)
s.url2, err = common.NewURL(context.TODO(), "dubbo://192.168.1.0:8081/org.apache.demo.HelloService?methods.echo.hash.arguments=0,1")
s.url2, err = common.NewURL("dubbo://192.168.1.0:8081/org.apache.demo.HelloService?methods.echo.hash.arguments=0,1")
s.NoError(err)
s.url3, err = common.NewURL(context.TODO(), "dubbo://192.168.1.0:8082/org.apache.demo.HelloService?methods.echo.hash.arguments=0,1")
s.url3, err = common.NewURL("dubbo://192.168.1.0:8082/org.apache.demo.HelloService?methods.echo.hash.arguments=0,1")
s.NoError(err)
s.invoker1 = protocol.NewBaseInvoker(s.url1)
......
......@@ -18,7 +18,6 @@
package loadbalance
import (
"context"
"fmt"
"testing"
)
......@@ -38,13 +37,13 @@ func TestLeastActiveSelect(t *testing.T) {
var invokers []protocol.Invoker
url, _ := common.NewURL(context.TODO(), "dubbo://192.168.1.0:20000/org.apache.demo.HelloService")
url, _ := common.NewURL("dubbo://192.168.1.0:20000/org.apache.demo.HelloService")
invokers = append(invokers, protocol.NewBaseInvoker(url))
i := loadBalance.Select(invokers, &invocation.RPCInvocation{})
assert.True(t, i.GetUrl().URLEqual(url))
for i := 1; i < 10; i++ {
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/org.apache.demo.HelloService", i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/org.apache.demo.HelloService", i))
invokers = append(invokers, protocol.NewBaseInvoker(url))
}
loadBalance.Select(invokers, &invocation.RPCInvocation{})
......@@ -56,7 +55,7 @@ func TestLeastActiveByWeight(t *testing.T) {
var invokers []protocol.Invoker
loop := 3
for i := 1; i <= loop; i++ {
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("test%v://192.168.1.%v:20000/org.apache.demo.HelloService?weight=%v", i, i, i))
url, _ := common.NewURL(fmt.Sprintf("test%v://192.168.1.%v:20000/org.apache.demo.HelloService?weight=%v", i, i, i))
invokers = append(invokers, protocol.NewBaseInvoker(url))
}
......
......@@ -18,7 +18,6 @@
package loadbalance
import (
"context"
"fmt"
"net/url"
"strconv"
......@@ -42,13 +41,13 @@ func Test_RandomlbSelect(t *testing.T) {
invokers := []protocol.Invoker{}
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", 0))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", 0))
invokers = append(invokers, protocol.NewBaseInvoker(url))
i := randomlb.Select(invokers, &invocation.RPCInvocation{})
assert.True(t, i.GetUrl().URLEqual(url))
for i := 1; i < 10; i++ {
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
invokers = append(invokers, protocol.NewBaseInvoker(url))
}
randomlb.Select(invokers, &invocation.RPCInvocation{})
......@@ -59,13 +58,13 @@ func Test_RandomlbSelectWeight(t *testing.T) {
invokers := []protocol.Invoker{}
for i := 0; i < 10; i++ {
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
invokers = append(invokers, protocol.NewBaseInvoker(url))
}
urlParams := url.Values{}
urlParams.Set("methods.test."+constant.WEIGHT_KEY, "10000000000000")
urll, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.100:20000/com.ikurento.user.UserProvider"), common.WithParams(urlParams))
urll, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.100:20000/com.ikurento.user.UserProvider"), common.WithParams(urlParams))
invokers = append(invokers, protocol.NewBaseInvoker(urll))
ivc := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("test"))
......@@ -80,7 +79,7 @@ func Test_RandomlbSelectWeight(t *testing.T) {
}
assert.Condition(t, func() bool {
//really is 0.9999999999999
// really is 0.9999999999999
return selected/10000 > 0.9
})
}
......@@ -90,13 +89,13 @@ func Test_RandomlbSelectWarmup(t *testing.T) {
invokers := []protocol.Invoker{}
for i := 0; i < 10; i++ {
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
invokers = append(invokers, protocol.NewBaseInvoker(url))
}
urlParams := url.Values{}
urlParams.Set(constant.REMOTE_TIMESTAMP_KEY, strconv.FormatInt(time.Now().Add(time.Minute*(-9)).Unix(), 10))
urll, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.100:20000/com.ikurento.user.UserProvider"), common.WithParams(urlParams))
urll, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.100:20000/com.ikurento.user.UserProvider"), common.WithParams(urlParams))
invokers = append(invokers, protocol.NewBaseInvoker(urll))
ivc := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("test"))
......
......@@ -18,7 +18,6 @@
package loadbalance
import (
"context"
"fmt"
"strconv"
"testing"
......@@ -39,13 +38,13 @@ func TestRoundRobinSelect(t *testing.T) {
var invokers []protocol.Invoker
url, _ := common.NewURL(context.TODO(), "dubbo://192.168.1.0:20000/org.apache.demo.HelloService")
url, _ := common.NewURL("dubbo://192.168.1.0:20000/org.apache.demo.HelloService")
invokers = append(invokers, protocol.NewBaseInvoker(url))
i := loadBalance.Select(invokers, &invocation.RPCInvocation{})
assert.True(t, i.GetUrl().URLEqual(url))
for i := 1; i < 10; i++ {
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/org.apache.demo.HelloService", i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/org.apache.demo.HelloService", i))
invokers = append(invokers, protocol.NewBaseInvoker(url))
}
loadBalance.Select(invokers, &invocation.RPCInvocation{})
......@@ -57,7 +56,7 @@ func TestRoundRobinByWeight(t *testing.T) {
var invokers []protocol.Invoker
loop := 10
for i := 1; i <= loop; i++ {
url, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://192.168.1.%v:20000/org.apache.demo.HelloService?weight=%v", i, i))
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/org.apache.demo.HelloService?weight=%v", i, i))
invokers = append(invokers, protocol.NewBaseInvoker(url))
}
......
......@@ -59,21 +59,21 @@ func (bi *MockInvoker) GetUrl() common.URL {
}
func getRouteUrl(rule string) *common.URL {
url, _ := common.NewURL(context.TODO(), "condition://0.0.0.0/com.foo.BarService")
url, _ := common.NewURL("condition://0.0.0.0/com.foo.BarService")
url.AddParam("rule", rule)
url.AddParam("force", "true")
return &url
}
func getRouteUrlWithForce(rule, force string) *common.URL {
url, _ := common.NewURL(context.TODO(), "condition://0.0.0.0/com.foo.BarService")
url, _ := common.NewURL("condition://0.0.0.0/com.foo.BarService")
url.AddParam("rule", rule)
url.AddParam("force", force)
return &url
}
func getRouteUrlWithNoForce(rule string) *common.URL {
url, _ := common.NewURL(context.TODO(), "condition://0.0.0.0/com.foo.BarService")
url, _ := common.NewURL("condition://0.0.0.0/com.foo.BarService")
url.AddParam("rule", rule)
return &url
}
......@@ -120,7 +120,7 @@ func TestRoute_matchWhen(t *testing.T) {
inv := &invocation.RPCInvocation{}
rule := base64.URLEncoding.EncodeToString([]byte("=> host = 1.2.3.4"))
router, _ := NewConditionRouterFactory().Router(getRouteUrl(rule))
cUrl, _ := common.NewURL(context.TODO(), "consumer://1.1.1.1/com.foo.BarService")
cUrl, _ := common.NewURL("consumer://1.1.1.1/com.foo.BarService")
matchWhen, _ := router.(*ConditionRouter).MatchWhen(cUrl, inv)
assert.Equal(t, true, matchWhen)
rule1 := base64.URLEncoding.EncodeToString([]byte("host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4"))
......@@ -152,9 +152,9 @@ func TestRoute_matchWhen(t *testing.T) {
func TestRoute_matchFilter(t *testing.T) {
localIP, _ := gxnet.GetLocalIP()
t.Logf("The local ip is %s", localIP)
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService?default.serialization=fastjson")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url1, _ := common.NewURL("dubbo://10.20.3.3:20880/com.foo.BarService?default.serialization=fastjson")
url2, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
invokers := []protocol.Invoker{NewMockInvoker(url1, 1), NewMockInvoker(url2, 2), NewMockInvoker(url3, 3)}
rule1 := base64.URLEncoding.EncodeToString([]byte("host = " + localIP + " => " + " host = 10.20.3.3"))
rule2 := base64.URLEncoding.EncodeToString([]byte("host = " + localIP + " => " + " host = 10.20.3.* & host != 10.20.3.3"))
......@@ -168,7 +168,7 @@ func TestRoute_matchFilter(t *testing.T) {
router4, _ := NewConditionRouterFactory().Router(getRouteUrl(rule4))
router5, _ := NewConditionRouterFactory().Router(getRouteUrl(rule5))
router6, _ := NewConditionRouterFactory().Router(getRouteUrl(rule6))
cUrl, _ := common.NewURL(context.TODO(), "consumer://"+localIP+"/com.foo.BarService")
cUrl, _ := common.NewURL("consumer://" + localIP + "/com.foo.BarService")
fileredInvokers1 := router1.Route(invokers, cUrl, &invocation.RPCInvocation{})
fileredInvokers2 := router2.Route(invokers, cUrl, &invocation.RPCInvocation{})
fileredInvokers3 := router3.Route(invokers, cUrl, &invocation.RPCInvocation{})
......@@ -188,18 +188,18 @@ func TestRoute_methodRoute(t *testing.T) {
inv := invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("getFoo"), invocation.WithParameterTypes([]reflect.Type{}), invocation.WithArguments([]interface{}{}))
rule := base64.URLEncoding.EncodeToString([]byte("host !=4.4.4.* & host = 2.2.2.2,1.1.1.1,3.3.3.3 => host = 1.2.3.4"))
router, _ := NewConditionRouterFactory().Router(getRouteUrl(rule))
url, _ := common.NewURL(context.TODO(), "consumer://1.1.1.1/com.foo.BarService?methods=setFoo,getFoo,findFoo")
url, _ := common.NewURL("consumer://1.1.1.1/com.foo.BarService?methods=setFoo,getFoo,findFoo")
matchWhen, _ := router.(*ConditionRouter).MatchWhen(url, inv)
assert.Equal(t, true, matchWhen)
url1, _ := common.NewURL(context.TODO(), "consumer://1.1.1.1/com.foo.BarService?methods=getFoo")
url1, _ := common.NewURL("consumer://1.1.1.1/com.foo.BarService?methods=getFoo")
matchWhen, _ = router.(*ConditionRouter).MatchWhen(url1, inv)
assert.Equal(t, true, matchWhen)
url2, _ := common.NewURL(context.TODO(), "consumer://1.1.1.1/com.foo.BarService?methods=getFoo")
url2, _ := common.NewURL("consumer://1.1.1.1/com.foo.BarService?methods=getFoo")
rule2 := base64.URLEncoding.EncodeToString([]byte("methods=getFoo & host!=1.1.1.1 => host = 1.2.3.4"))
router2, _ := NewConditionRouterFactory().Router(getRouteUrl(rule2))
matchWhen, _ = router2.(*ConditionRouter).MatchWhen(url2, inv)
assert.Equal(t, false, matchWhen)
url3, _ := common.NewURL(context.TODO(), "consumer://1.1.1.1/com.foo.BarService?methods=getFoo")
url3, _ := common.NewURL("consumer://1.1.1.1/com.foo.BarService?methods=getFoo")
rule3 := base64.URLEncoding.EncodeToString([]byte("methods=getFoo & host=1.1.1.1 => host = 1.2.3.4"))
router3, _ := NewConditionRouterFactory().Router(getRouteUrl(rule3))
matchWhen, _ = router3.(*ConditionRouter).MatchWhen(url3, inv)
......@@ -208,12 +208,12 @@ func TestRoute_methodRoute(t *testing.T) {
}
func TestRoute_ReturnFalse(t *testing.T) {
url, _ := common.NewURL(context.TODO(), "")
url, _ := common.NewURL("")
localIP, _ := gxnet.GetLocalIP()
invokers := []protocol.Invoker{NewMockInvoker(url, 1), NewMockInvoker(url, 2), NewMockInvoker(url, 3)}
inv := &invocation.RPCInvocation{}
rule := base64.URLEncoding.EncodeToString([]byte("host = " + localIP + " => false"))
curl, _ := common.NewURL(context.TODO(), "consumer://"+localIP+"/com.foo.BarService")
curl, _ := common.NewURL("consumer://" + localIP + "/com.foo.BarService")
router, _ := NewConditionRouterFactory().Router(getRouteUrl(rule))
fileredInvokers := router.(*ConditionRouter).Route(invokers, curl, inv)
assert.Equal(t, 0, len(fileredInvokers))
......@@ -221,11 +221,11 @@ func TestRoute_ReturnFalse(t *testing.T) {
func TestRoute_ReturnEmpty(t *testing.T) {
localIP, _ := gxnet.GetLocalIP()
url, _ := common.NewURL(context.TODO(), "")
url, _ := common.NewURL("")
invokers := []protocol.Invoker{NewMockInvoker(url, 1), NewMockInvoker(url, 2), NewMockInvoker(url, 3)}
inv := &invocation.RPCInvocation{}
rule := base64.URLEncoding.EncodeToString([]byte("host = " + localIP + " => "))
curl, _ := common.NewURL(context.TODO(), "consumer://"+localIP+"/com.foo.BarService")
curl, _ := common.NewURL("consumer://" + localIP + "/com.foo.BarService")
router, _ := NewConditionRouterFactory().Router(getRouteUrl(rule))
fileredInvokers := router.(*ConditionRouter).Route(invokers, curl, inv)
assert.Equal(t, 0, len(fileredInvokers))
......@@ -236,7 +236,7 @@ func TestRoute_ReturnAll(t *testing.T) {
invokers := []protocol.Invoker{&MockInvoker{}, &MockInvoker{}, &MockInvoker{}}
inv := &invocation.RPCInvocation{}
rule := base64.URLEncoding.EncodeToString([]byte("host = " + localIP + " => " + " host = " + localIP))
curl, _ := common.NewURL(context.TODO(), "consumer://"+localIP+"/com.foo.BarService")
curl, _ := common.NewURL("consumer://" + localIP + "/com.foo.BarService")
router, _ := NewConditionRouterFactory().Router(getRouteUrl(rule))
fileredInvokers := router.(*ConditionRouter).Route(invokers, curl, inv)
assert.Equal(t, invokers, fileredInvokers)
......@@ -244,16 +244,16 @@ func TestRoute_ReturnAll(t *testing.T) {
func TestRoute_HostFilter(t *testing.T) {
localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url1, _ := common.NewURL("dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
invoker1 := NewMockInvoker(url1, 1)
invoker2 := NewMockInvoker(url2, 2)
invoker3 := NewMockInvoker(url3, 3)
invokers := []protocol.Invoker{invoker1, invoker2, invoker3}
inv := &invocation.RPCInvocation{}
rule := base64.URLEncoding.EncodeToString([]byte("host = " + localIP + " => " + " host = " + localIP))
curl, _ := common.NewURL(context.TODO(), "consumer://"+localIP+"/com.foo.BarService")
curl, _ := common.NewURL("consumer://" + localIP + "/com.foo.BarService")
router, _ := NewConditionRouterFactory().Router(getRouteUrl(rule))
fileredInvokers := router.(*ConditionRouter).Route(invokers, curl, inv)
assert.Equal(t, 2, len(fileredInvokers))
......@@ -263,16 +263,16 @@ func TestRoute_HostFilter(t *testing.T) {
func TestRoute_Empty_HostFilter(t *testing.T) {
localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url1, _ := common.NewURL("dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
invoker1 := NewMockInvoker(url1, 1)
invoker2 := NewMockInvoker(url2, 2)
invoker3 := NewMockInvoker(url3, 3)
invokers := []protocol.Invoker{invoker1, invoker2, invoker3}
inv := &invocation.RPCInvocation{}
rule := base64.URLEncoding.EncodeToString([]byte(" => " + " host = " + localIP))
curl, _ := common.NewURL(context.TODO(), "consumer://"+localIP+"/com.foo.BarService")
curl, _ := common.NewURL("consumer://" + localIP + "/com.foo.BarService")
router, _ := NewConditionRouterFactory().Router(getRouteUrl(rule))
fileredInvokers := router.(*ConditionRouter).Route(invokers, curl, inv)
assert.Equal(t, 2, len(fileredInvokers))
......@@ -282,16 +282,16 @@ func TestRoute_Empty_HostFilter(t *testing.T) {
func TestRoute_False_HostFilter(t *testing.T) {
localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url1, _ := common.NewURL("dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
invoker1 := NewMockInvoker(url1, 1)
invoker2 := NewMockInvoker(url2, 2)
invoker3 := NewMockInvoker(url3, 3)
invokers := []protocol.Invoker{invoker1, invoker2, invoker3}
inv := &invocation.RPCInvocation{}
rule := base64.URLEncoding.EncodeToString([]byte("true => " + " host = " + localIP))
curl, _ := common.NewURL(context.TODO(), "consumer://"+localIP+"/com.foo.BarService")
curl, _ := common.NewURL("consumer://" + localIP + "/com.foo.BarService")
router, _ := NewConditionRouterFactory().Router(getRouteUrl(rule))
fileredInvokers := router.(*ConditionRouter).Route(invokers, curl, inv)
assert.Equal(t, 2, len(fileredInvokers))
......@@ -301,16 +301,16 @@ func TestRoute_False_HostFilter(t *testing.T) {
func TestRoute_Placeholder(t *testing.T) {
localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url1, _ := common.NewURL("dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
invoker1 := NewMockInvoker(url1, 1)
invoker2 := NewMockInvoker(url2, 2)
invoker3 := NewMockInvoker(url3, 3)
invokers := []protocol.Invoker{invoker1, invoker2, invoker3}
inv := &invocation.RPCInvocation{}
rule := base64.URLEncoding.EncodeToString([]byte("host = " + localIP + " => " + " host = $host"))
curl, _ := common.NewURL(context.TODO(), "consumer://"+localIP+"/com.foo.BarService")
curl, _ := common.NewURL("consumer://" + localIP + "/com.foo.BarService")
router, _ := NewConditionRouterFactory().Router(getRouteUrl(rule))
fileredInvokers := router.(*ConditionRouter).Route(invokers, curl, inv)
assert.Equal(t, 2, len(fileredInvokers))
......@@ -320,16 +320,16 @@ func TestRoute_Placeholder(t *testing.T) {
func TestRoute_NoForce(t *testing.T) {
localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url1, _ := common.NewURL("dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
invoker1 := NewMockInvoker(url1, 1)
invoker2 := NewMockInvoker(url2, 2)
invoker3 := NewMockInvoker(url3, 3)
invokers := []protocol.Invoker{invoker1, invoker2, invoker3}
inv := &invocation.RPCInvocation{}
rule := base64.URLEncoding.EncodeToString([]byte("host = " + localIP + " => " + " host = 1.2.3.4"))
curl, _ := common.NewURL(context.TODO(), "consumer://"+localIP+"/com.foo.BarService")
curl, _ := common.NewURL("consumer://" + localIP + "/com.foo.BarService")
router, _ := NewConditionRouterFactory().Router(getRouteUrlWithNoForce(rule))
fileredInvokers := router.(*ConditionRouter).Route(invokers, curl, inv)
assert.Equal(t, invokers, fileredInvokers)
......@@ -337,16 +337,16 @@ func TestRoute_NoForce(t *testing.T) {
func TestRoute_Force(t *testing.T) {
localIP, _ := gxnet.GetLocalIP()
url1, _ := common.NewURL(context.TODO(), "dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(context.TODO(), fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url1, _ := common.NewURL("dubbo://10.20.3.3:20880/com.foo.BarService")
url2, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
url3, _ := common.NewURL(fmt.Sprintf("dubbo://%s:20880/com.foo.BarService", localIP))
invoker1 := NewMockInvoker(url1, 1)
invoker2 := NewMockInvoker(url2, 2)
invoker3 := NewMockInvoker(url3, 3)
invokers := []protocol.Invoker{invoker1, invoker2, invoker3}
inv := &invocation.RPCInvocation{}
rule := base64.URLEncoding.EncodeToString([]byte("host = " + localIP + " => " + " host = 1.2.3.4"))
curl, _ := common.NewURL(context.TODO(), "consumer://"+localIP+"/com.foo.BarService")
curl, _ := common.NewURL("consumer://" + localIP + "/com.foo.BarService")
router, _ := NewConditionRouterFactory().Router(getRouteUrlWithForce(rule, "true"))
fileredInvokers := router.(*ConditionRouter).Route(invokers, curl, inv)
assert.Equal(t, 0, len(fileredInvokers))
......
......@@ -68,6 +68,7 @@ const (
DYNAMIC_CONFIGURATORS_CATEGORY = "dynamicconfigurators"
APP_DYNAMIC_CONFIGURATORS_CATEGORY = "appdynamicconfigurators"
PROVIDER_CATEGORY = "providers"
CONSUMER_CATEGORY = "consumers"
)
const (
......
......@@ -141,3 +141,21 @@ const (
const (
TRACING_REMOTE_SPAN_CTX = "tracing.remote.span.ctx"
)
const (
CONSUMER_SIGN_FILTER = "sign"
PROVIDER_AUTH_FILTER = "auth"
SERVICE_AUTH_KEY = "auth"
AUTHENTICATOR_KEY = "authenticator"
DEFAULT_AUTHENTICATOR = "accesskeys"
DEFAULT_ACCESS_KEY_STORAGE = "urlstorage"
ACCESS_KEY_STORAGE_KEY = "accessKey.storage"
REQUEST_TIMESTAMP_KEY = "timestamp"
REQUEST_SIGNATURE_KEY = "signature"
AK_KEY = "ak"
SIGNATURE_STRING_FORMAT = "%s#%s#%s#%s"
PARAMTER_SIGNATURE_ENABLE_KEY = "param.sign"
CONSUMER = "consumer"
ACCESS_KEY_ID_KEY = "accessKeyId"
SECRET_ACCESS_KEY_KEY = "secretAccessKey"
)
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package constant
import (
"time"
)
var (
MsToNanoRate = int64(time.Millisecond / time.Nanosecond)
)
package extension
import (
"github.com/apache/dubbo-go/filter"
)
var (
authenticators = make(map[string]func() filter.Authenticator)
accesskeyStorages = make(map[string]func() filter.AccessKeyStorage)
)
func SetAuthenticator(name string, fcn func() filter.Authenticator) {
authenticators[name] = fcn
}
func GetAuthenticator(name string) filter.Authenticator {
if authenticators[name] == nil {
panic("authenticator for " + name + " is not existing, make sure you have import the package.")
}
return authenticators[name]()
}
func SetAccesskeyStorages(name string, fcn func() filter.AccessKeyStorage) {
accesskeyStorages[name] = fcn
}
func GetAccesskeyStorages(name string) filter.AccessKeyStorage {
if accesskeyStorages[name] == nil {
panic("accesskeyStorages for " + name + " is not existing, make sure you have import the package.")
}
return accesskeyStorages[name]()
}
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