Skip to content
Snippets Groups Projects
Commit 94d11ef9 authored by Xin.Zh's avatar Xin.Zh Committed by GitHub
Browse files

Merge pull request #350 from flycash/remove-context

Refactor: remove context from URL.
parents e072df18 eca8c677
No related branches found
No related tags found
No related merge requests found
Showing
with 102 additions and 115 deletions
......@@ -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))
......
......@@ -19,7 +19,6 @@ package common
import (
"bytes"
"context"
"encoding/base64"
"fmt"
"math"
......@@ -85,7 +84,6 @@ type baseUrl struct {
paramsLock sync.RWMutex
params url.Values
PrimitiveURL string
ctx context.Context
}
// URL ...
......@@ -194,14 +192,15 @@ func NewURLWithOptions(opts ...option) *URL {
return url
}
// NewURL ...
func NewURL(ctx context.Context, urlString string, opts ...option) (URL, error) {
// NewURL will create a new url
// the urlString should not be empty
func NewURL(urlString string, opts ...option) (URL, error) {
var (
err error
rawUrlString string
serviceUrl *url.URL
s = URL{baseUrl: baseUrl{ctx: ctx}}
s = URL{baseUrl: baseUrl{}}
)
// new a null instance
......@@ -216,7 +215,7 @@ func NewURL(ctx context.Context, urlString string, opts ...option) (URL, error)
//rawUrlString = "//" + rawUrlString
if strings.Index(rawUrlString, "//") < 0 {
t := URL{baseUrl: baseUrl{ctx: ctx}}
t := URL{baseUrl: baseUrl{}}
for _, opt := range opts {
opt(&t)
}
......@@ -367,11 +366,6 @@ func (c *URL) EncodedServiceKey() string {
return strings.Replace(serviceKey, "/", "*", 1)
}
// Context ...
func (c URL) Context() context.Context {
return c.ctx
}
// Service ...
func (c URL) Service() string {
service := c.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/"))
......
......@@ -18,7 +18,6 @@
package common
import (
"context"
"encoding/base64"
"net/url"
"testing"
......@@ -56,10 +55,10 @@ func TestNewURLWithOptions(t *testing.T) {
}
func TestURL(t *testing.T) {
u, err := NewURL(context.TODO(), "dubbo://127.0.0.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&"+
u, err := NewURL("dubbo://127.0.0.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)
......@@ -83,7 +82,7 @@ func TestURL(t *testing.T) {
}
func TestURLWithoutSchema(t *testing.T) {
u, err := NewURL(context.TODO(), "127.0.0.1:20000/com.ikurento.user.UserProvider?anyhost=true&"+
u, err := NewURL("127.0.0.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&"+
......@@ -110,13 +109,13 @@ func TestURLWithoutSchema(t *testing.T) {
}
func TestURL_URLEqual(t *testing.T) {
u1, err := NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0")
u1, err := NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0")
assert.NoError(t, err)
u2, err := NewURL(context.TODO(), "dubbo://127.0.0.2:20001/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0")
u2, err := NewURL("dubbo://127.0.0.2:20001/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0")
assert.NoError(t, err)
assert.True(t, u1.URLEqual(u2))
u3, err := NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=gg&version=2.6.0")
u3, err := NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=gg&version=2.6.0")
assert.NoError(t, err)
assert.False(t, u1.URLEqual(u3))
}
......@@ -166,7 +165,7 @@ func TestURL_GetParamAndDecoded(t *testing.T) {
assert.Equal(t, rule, v)
}
func TestURL_GetRawParam(t *testing.T) {
u, _ := NewURL(context.TODO(), "condition://0.0.0.0:8080/com.foo.BarService?serialization=fastjson")
u, _ := NewURL("condition://0.0.0.0:8080/com.foo.BarService?serialization=fastjson")
u.Username = "test"
u.Password = "test"
assert.Equal(t, "condition", u.GetRawParam("protocol"))
......@@ -178,7 +177,7 @@ func TestURL_GetRawParam(t *testing.T) {
assert.Equal(t, "fastjson", u.GetRawParam("serialization"))
}
func TestURL_ToMap(t *testing.T) {
u, _ := NewURL(context.TODO(), "condition://0.0.0.0:8080/com.foo.BarService?serialization=fastjson")
u, _ := NewURL("condition://0.0.0.0:8080/com.foo.BarService?serialization=fastjson")
u.Username = "test"
u.Password = "test"
......@@ -240,8 +239,8 @@ func TestMergeUrl(t *testing.T) {
serviceUrlParams.Set(constant.CLUSTER_KEY, "roundrobin")
serviceUrlParams.Set(constant.RETRIES_KEY, "2")
serviceUrlParams.Set(constant.METHOD_KEYS+".testMethod."+constant.RETRIES_KEY, "2")
referenceUrl, _ := NewURL(context.TODO(), "mock1://127.0.0.1:1111", WithParams(referenceUrlParams), WithMethods([]string{"testMethod"}))
serviceUrl, _ := NewURL(context.TODO(), "mock2://127.0.0.1:20000", WithParams(serviceUrlParams))
referenceUrl, _ := NewURL("mock1://127.0.0.1:1111", WithParams(referenceUrlParams), WithMethods([]string{"testMethod"}))
serviceUrl, _ := NewURL("mock2://127.0.0.1:20000", WithParams(serviceUrlParams))
mergedUrl := MergeUrl(&serviceUrl, &referenceUrl)
assert.Equal(t, "random", mergedUrl.GetParam(constant.CLUSTER_KEY, ""))
......@@ -252,7 +251,7 @@ func TestMergeUrl(t *testing.T) {
}
func TestURL_SetParams(t *testing.T) {
u1, err := NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0&configVersion=1.0")
u1, err := NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0&configVersion=1.0")
assert.NoError(t, err)
params := url.Values{}
params.Set("key", "3")
......@@ -262,7 +261,7 @@ func TestURL_SetParams(t *testing.T) {
}
func TestClone(t *testing.T) {
u1, err := NewURL(context.TODO(), "dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0&configVersion=1.0")
u1, err := NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider?interface=com.ikurento.user.UserProvider&group=&version=2.6.0&configVersion=1.0")
assert.NoError(t, err)
u2 := u1.Clone()
assert.Equal(t, u2.Protocol, "dubbo")
......
......@@ -18,7 +18,6 @@
package config
import (
"context"
"reflect"
"strconv"
"strings"
......@@ -50,8 +49,11 @@ type BaseConfig struct {
MetricConfig *MetricConfig `yaml:"metrics" json:"metrics,omitempty"`
}
func (c *BaseConfig) startConfigCenter(ctx context.Context) error {
url, err := common.NewURL(ctx, c.ConfigCenterConfig.Address, common.WithProtocol(c.ConfigCenterConfig.Protocol), common.WithParams(c.ConfigCenterConfig.GetUrlMap()))
// startConfigCenter will start the config center.
// it will prepare the environment
func (c *BaseConfig) startConfigCenter() error {
url, err := common.NewURL(c.ConfigCenterConfig.Address,
common.WithProtocol(c.ConfigCenterConfig.Protocol), common.WithParams(c.ConfigCenterConfig.GetUrlMap()))
if err != nil {
return err
}
......
......@@ -17,7 +17,6 @@
package config
import (
"context"
"fmt"
"reflect"
"testing"
......@@ -492,7 +491,7 @@ func Test_startConfigCenter(t *testing.T) {
Group: "dubbo",
ConfigFile: "mockDubbo.properties",
}}
err := c.startConfigCenter(context.Background())
err := c.startConfigCenter()
assert.NoError(t, err)
b, v := config.GetEnvInstance().Configuration().Back().Value.(*config.InmemoryConfiguration).GetProperty("dubbo.application.organization")
assert.True(t, b)
......
......@@ -18,7 +18,6 @@
package config
import (
"context"
"io/ioutil"
"path"
"time"
......@@ -136,7 +135,7 @@ func configCenterRefreshConsumer() error {
var err error
if consumerConfig.ConfigCenterConfig != nil {
consumerConfig.SetFatherConfig(consumerConfig)
if err := consumerConfig.startConfigCenter(context.Background()); err != nil {
if err := consumerConfig.startConfigCenter(); err != nil {
return perrors.Errorf("start config center error , error message is {%v}", perrors.WithStack(err))
}
consumerConfig.fresh()
......
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