Skip to content

Commit

Permalink
upgrade nacos v2 (#2116)
Browse files Browse the repository at this point in the history
  • Loading branch information
binbin0325 authored Nov 11, 2022
1 parent 188b993 commit b534f75
Show file tree
Hide file tree
Showing 30 changed files with 171 additions and 158 deletions.
6 changes: 3 additions & 3 deletions cluster/cluster/available/cluster_invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func registerAvailable(invoker *mock.MockInvoker) protocol.Invoker {

invokers := []protocol.Invoker{}
invokers = append(invokers, invoker)
invoker.EXPECT().GetUrl().Return(availableUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(availableUrl).AnyTimes()
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()

staticDir := static.NewDirectory(invokers)
Expand All @@ -69,7 +69,7 @@ func TestAvailableClusterInvokerSuccess(t *testing.T) {

mockResult := &protocol.RPCResult{Rest: clusterpkg.Rest{Tried: 0, Success: true}}
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any()).Return(mockResult).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockResult).AnyTimes()

result := clusterInvoker.Invoke(context.Background(), &invocation.RPCInvocation{})

Expand All @@ -86,7 +86,7 @@ func TestAvailableClusterInvokerNoAvail(t *testing.T) {
invoker.EXPECT().IsAvailable().Return(false).AnyTimes()

res := &protocol.RPCResult{Err: errors.New("no provider available")}
invoker.EXPECT().Invoke(gomock.Any()).Return(res).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(res).AnyTimes()

result := clusterInvoker.Invoke(context.TODO(), &invocation.RPCInvocation{})

Expand Down
10 changes: 5 additions & 5 deletions cluster/cluster/broadcast/cluster_invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func registerBroadcast(mockInvokers ...*mock.MockInvoker) protocol.Invoker {
invokers := []protocol.Invoker{}
for _, ivk := range mockInvokers {
invokers = append(invokers, ivk)
ivk.EXPECT().GetUrl().Return(broadcastUrl).AnyTimes()
ivk.EXPECT().GetURL().Return(broadcastUrl).AnyTimes()
}
staticDir := static.NewDirectory(invokers)

Expand All @@ -70,7 +70,7 @@ func TestBroadcastInvokeSuccess(t *testing.T) {
for i := 0; i < 3; i++ {
invoker := mock.NewMockInvoker(ctrl)
invokers = append(invokers, invoker)
invoker.EXPECT().Invoke(gomock.Any()).Return(mockResult).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockResult).AnyTimes()
}

clusterInvoker := registerBroadcast(invokers...)
Expand All @@ -90,17 +90,17 @@ func TestBroadcastInvokeFailed(t *testing.T) {
for i := 0; i < 10; i++ {
invoker := mock.NewMockInvoker(ctrl)
invokers = append(invokers, invoker)
invoker.EXPECT().Invoke(gomock.Any()).Return(mockResult).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockResult).AnyTimes()
}
{
invoker := mock.NewMockInvoker(ctrl)
invokers = append(invokers, invoker)
invoker.EXPECT().Invoke(gomock.Any()).Return(mockFailedResult).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockFailedResult).AnyTimes()
}
for i := 0; i < 10; i++ {
invoker := mock.NewMockInvoker(ctrl)
invokers = append(invokers, invoker)
invoker.EXPECT().Invoke(gomock.Any()).Return(mockResult).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockResult).AnyTimes()
}

clusterInvoker := registerBroadcast(invokers...)
Expand Down
28 changes: 14 additions & 14 deletions cluster/cluster/failback/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func registerFailback(invoker *mock.MockInvoker) protocol.Invoker {
var invokers []protocol.Invoker
invokers = append(invokers, invoker)

invoker.EXPECT().GetUrl().Return(failbackUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(failbackUrl).AnyTimes()

staticDir := static.NewDirectory(invokers)
clusterInvoker := failbackCluster.Join(staticDir)
Expand All @@ -71,12 +71,12 @@ func TestFailbackSuceess(t *testing.T) {
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := registerFailback(invoker).(*failbackClusterInvoker)

invoker.EXPECT().GetUrl().Return(failbackUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(failbackUrl).AnyTimes()

invoker.EXPECT().IsAvailable().Return(true).AnyTimes()

mockResult := &protocol.RPCResult{Rest: clusterpkg.Rest{Tried: 0, Success: true}}
invoker.EXPECT().Invoke(gomock.Any()).Return(mockResult).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockResult).AnyTimes()

result := clusterInvoker.Invoke(context.Background(), &invocation.RPCInvocation{})
assert.Equal(t, mockResult, result)
Expand All @@ -90,20 +90,20 @@ func TestFailbackRetryOneSuccess(t *testing.T) {
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := registerFailback(invoker).(*failbackClusterInvoker)

invoker.EXPECT().GetUrl().Return(failbackUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(failbackUrl).AnyTimes()
invoker.EXPECT().IsAvailable().Return(true)

// failed at first
mockFailedResult := &protocol.RPCResult{Err: perrors.New("error")}
invoker.EXPECT().Invoke(gomock.Any()).Return(mockFailedResult)
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockFailedResult)

// success second
var wg sync.WaitGroup
wg.Add(1)
now := time.Now()
mockSuccResult := &protocol.RPCResult{Rest: clusterpkg.Rest{Tried: 0, Success: true}}
invoker.EXPECT().IsAvailable().Return(true)
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(func(protocol.Invocation) protocol.Result {
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).DoAndReturn(func(context.Context, protocol.Invocation) protocol.Result {
delta := time.Since(now).Nanoseconds() / int64(time.Second)
assert.True(t, delta >= 5)
wg.Done()
Expand Down Expand Up @@ -135,11 +135,11 @@ func TestFailbackRetryFailed(t *testing.T) {
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := registerFailback(invoker).(*failbackClusterInvoker)

invoker.EXPECT().GetUrl().Return(failbackUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(failbackUrl).AnyTimes()
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()

mockFailedResult := &protocol.RPCResult{Err: perrors.New("error")}
invoker.EXPECT().Invoke(gomock.Any()).Return(mockFailedResult)
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockFailedResult)

//
var wg sync.WaitGroup
Expand All @@ -150,7 +150,7 @@ func TestFailbackRetryFailed(t *testing.T) {
// add retry call that eventually failed.
for i := 0; i < retries; i++ {
j := i + 1
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(func(protocol.Invocation) protocol.Result {
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).DoAndReturn(func(context.Context, protocol.Invocation) protocol.Result {
delta := time.Since(now).Nanoseconds() / int64(time.Second)
assert.True(t, delta >= int64(5*j))
wg.Done()
Expand Down Expand Up @@ -184,17 +184,17 @@ func TestFailbackRetryFailed10Times(t *testing.T) {
clusterInvoker.maxRetries = 10

invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
invoker.EXPECT().GetUrl().Return(failbackUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(failbackUrl).AnyTimes()

// 10 task should failed firstly.
mockFailedResult := &protocol.RPCResult{Err: perrors.New("error")}
invoker.EXPECT().Invoke(gomock.Any()).Return(mockFailedResult).Times(10)
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockFailedResult).Times(10)

// 10 task should retry and failed.
var wg sync.WaitGroup
wg.Add(10)
now := time.Now()
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(func(protocol.Invocation) protocol.Result {
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).DoAndReturn(func(context.Context, protocol.Invocation) protocol.Result {
delta := time.Since(now).Nanoseconds() / int64(time.Second)
assert.True(t, delta >= 5)
wg.Done()
Expand Down Expand Up @@ -226,11 +226,11 @@ func TestFailbackOutOfLimit(t *testing.T) {
clusterInvoker := registerFailback(invoker).(*failbackClusterInvoker)
clusterInvoker.failbackTasks = 1

invoker.EXPECT().GetUrl().Return(failbackUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(failbackUrl).AnyTimes()
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()

mockFailedResult := &protocol.RPCResult{Err: perrors.New("error")}
invoker.EXPECT().Invoke(gomock.Any()).Return(mockFailedResult).Times(11)
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockFailedResult).Times(11)

// reached limit
result := clusterInvoker.Invoke(context.Background(), &invocation.RPCInvocation{})
Expand Down
10 changes: 5 additions & 5 deletions cluster/cluster/failfast/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func registerFailfast(invoker *mock.MockInvoker) protocol.Invoker {
invokers = append(invokers, invoker)

invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
invoker.EXPECT().GetUrl().Return(failfastUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(failfastUrl).AnyTimes()

staticDir := static.NewDirectory(invokers)
clusterInvoker := failfastCluster.Join(staticDir)
Expand All @@ -70,11 +70,11 @@ func TestFailfastInvokeSuccess(t *testing.T) {
clusterInvoker := registerFailfast(invoker)

invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
invoker.EXPECT().GetUrl().Return(failfastUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(failfastUrl).AnyTimes()

mockResult := &protocol.RPCResult{Rest: clusterpkg.Rest{Tried: 0, Success: true}}

invoker.EXPECT().Invoke(gomock.Any()).Return(mockResult).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockResult).AnyTimes()
result := clusterInvoker.Invoke(context.Background(), &invocation.RPCInvocation{})

assert.NoError(t, result.Error())
Expand All @@ -91,11 +91,11 @@ func TestFailfastInvokeFail(t *testing.T) {
clusterInvoker := registerFailfast(invoker)

invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
invoker.EXPECT().GetUrl().Return(failfastUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(failfastUrl).AnyTimes()

mockResult := &protocol.RPCResult{Err: perrors.New("error")}

invoker.EXPECT().Invoke(gomock.Any()).Return(mockResult).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockResult).AnyTimes()
result := clusterInvoker.Invoke(context.Background(), &invocation.RPCInvocation{})

assert.NotNil(t, result.Error())
Expand Down
10 changes: 5 additions & 5 deletions cluster/cluster/failsafe/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func registerFailsafe(invoker *mock.MockInvoker) protocol.Invoker {
invokers = append(invokers, invoker)
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()

invoker.EXPECT().GetUrl().Return(failsafeUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(failsafeUrl).AnyTimes()

staticDir := static.NewDirectory(invokers)
clusterInvoker := failsafeCluster.Join(staticDir)
Expand All @@ -71,11 +71,11 @@ func TestFailSafeInvokeSuccess(t *testing.T) {

invoker.EXPECT().IsAvailable().Return(true).AnyTimes()

invoker.EXPECT().GetUrl().Return(failsafeUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(failsafeUrl).AnyTimes()

mockResult := &protocol.RPCResult{Rest: clusterpkg.Rest{Tried: 0, Success: true}}

invoker.EXPECT().Invoke(gomock.Any()).Return(mockResult).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockResult).AnyTimes()
result := clusterInvoker.Invoke(context.Background(), &invocation.RPCInvocation{})

assert.NoError(t, result.Error())
Expand All @@ -91,11 +91,11 @@ func TestFailSafeInvokeFail(t *testing.T) {
clusterInvoker := registerFailsafe(invoker)
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()

invoker.EXPECT().GetUrl().Return(failsafeUrl).AnyTimes()
invoker.EXPECT().GetURL().Return(failsafeUrl).AnyTimes()

mockResult := &protocol.RPCResult{Err: perrors.New("error")}

invoker.EXPECT().Invoke(gomock.Any()).Return(mockResult).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).Return(mockResult).AnyTimes()
result := clusterInvoker.Invoke(context.Background(), &invocation.RPCInvocation{})

assert.NoError(t, result.Error())
Expand Down
18 changes: 9 additions & 9 deletions cluster/cluster/forking/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func registerForking(mockInvokers ...*mock.MockInvoker) protocol.Invoker {
var invokers []protocol.Invoker
for _, ivk := range mockInvokers {
invokers = append(invokers, ivk)
ivk.EXPECT().GetUrl().Return(forkingUrl).AnyTimes()
ivk.EXPECT().GetURL().Return(forkingUrl).AnyTimes()
}
staticDir := static.NewDirectory(invokers)

Expand All @@ -78,8 +78,8 @@ func TestForkingInvokeSuccess(t *testing.T) {
invoker := mock.NewMockInvoker(ctrl)
invokers = append(invokers, invoker)
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(
func(protocol.Invocation) protocol.Result {
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).DoAndReturn(
func(context.Context, protocol.Invocation) protocol.Result {
wg.Done()
return mockResult
})
Expand Down Expand Up @@ -107,8 +107,8 @@ func TestForkingInvokeTimeout(t *testing.T) {
invoker := mock.NewMockInvoker(ctrl)
invokers = append(invokers, invoker)
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(
func(protocol.Invocation) protocol.Result {
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).DoAndReturn(
func(context.Context, protocol.Invocation) protocol.Result {
time.Sleep(2 * time.Second)
wg.Done()
return mockResult
Expand Down Expand Up @@ -139,14 +139,14 @@ func TestForkingInvokeHalfTimeout(t *testing.T) {
invokers = append(invokers, invoker)
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
if i == 1 {
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(
func(protocol.Invocation) protocol.Result {
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).DoAndReturn(
func(context.Context, protocol.Invocation) protocol.Result {
wg.Done()
return mockResult
}).AnyTimes()
} else {
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(
func(protocol.Invocation) protocol.Result {
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).DoAndReturn(
func(context.Context, protocol.Invocation) protocol.Result {
time.Sleep(2 * time.Second)
wg.Done()
return mockResult
Expand Down
28 changes: 14 additions & 14 deletions cluster/cluster/zoneaware/cluster_invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ func TestZoneWareInvokerWithPreferredSuccess(t *testing.T) {
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
invoker := mock.NewMockInvoker(ctrl)
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
invoker.EXPECT().GetUrl().Return(url).AnyTimes()
invoker.EXPECT().GetURL().Return(url).AnyTimes()
if 0 == i {
url.SetParam(constant.RegistryKey+"."+constant.PreferredKey, "true")
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(
func(invocation protocol.Invocation) protocol.Result {
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).DoAndReturn(
func(ctx context.Context, invocation protocol.Invocation) protocol.Result {
return mockResult
}).AnyTimes()
} else {
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(
func(invocation protocol.Invocation) protocol.Result {
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).DoAndReturn(
func(ctx context.Context, invocation protocol.Invocation) protocol.Result {
return &protocol.RPCResult{}
}).AnyTimes()
}
Expand Down Expand Up @@ -99,21 +99,21 @@ func TestZoneWareInvokerWithWeightSuccess(t *testing.T) {
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i))
invoker := mock.NewMockInvoker(ctrl)
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
invoker.EXPECT().GetUrl().Return(url).AnyTimes()
invoker.EXPECT().GetURL().Return(url).AnyTimes()
url.SetParam(constant.RegistryKey+"."+constant.RegistryLabelKey, "true")
if 1 == i {
url.SetParam(constant.RegistryKey+"."+constant.WeightKey, w1)
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(
func(invocation protocol.Invocation) protocol.Result {
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).DoAndReturn(
func(ctx context.Context, invocation protocol.Invocation) protocol.Result {
return &protocol.RPCResult{
Attrs: map[string]interface{}{constant.WeightKey: w1},
Rest: clusterpkg.Rest{Tried: 0, Success: true},
}
}).MaxTimes(100)
} else {
url.SetParam(constant.RegistryKey+"."+constant.WeightKey, w2)
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(
func(invocation protocol.Invocation) protocol.Result {
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).DoAndReturn(
func(ctx context.Context, invocation protocol.Invocation) protocol.Result {
return &protocol.RPCResult{
Attrs: map[string]interface{}{constant.WeightKey: w2},
Rest: clusterpkg.Rest{Tried: 0, Success: true},
Expand Down Expand Up @@ -159,9 +159,9 @@ func TestZoneWareInvokerWithZoneSuccess(t *testing.T) {

invoker := mock.NewMockInvoker(ctrl)
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
invoker.EXPECT().GetUrl().Return(url).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any()).DoAndReturn(
func(invocation protocol.Invocation) protocol.Result {
invoker.EXPECT().GetURL().Return(url).AnyTimes()
invoker.EXPECT().Invoke(gomock.Any(), gomock.Any()).DoAndReturn(
func(ctx context.Context, invocation protocol.Invocation) protocol.Result {
return &protocol.RPCResult{
Attrs: map[string]interface{}{constant.RegistryZoneKey: zoneValue},
Rest: clusterpkg.Rest{Tried: 0, Success: true},
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestZoneWareInvokerWithZoneForceFail(t *testing.T) {

invoker := mock.NewMockInvoker(ctrl)
invoker.EXPECT().IsAvailable().Return(true).AnyTimes()
invoker.EXPECT().GetUrl().Return(url).AnyTimes()
invoker.EXPECT().GetURL().Return(url).AnyTimes()
invokers = append(invokers, invoker)
}

Expand Down
4 changes: 4 additions & 0 deletions common/host_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ package common
import (
"os"
"strconv"
)

import (
gxnet "github.com/dubbogo/gost/net"
)

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
)

Expand Down
6 changes: 4 additions & 2 deletions common/host_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ package common
import (
"os"
"testing"

"dubbo.apache.org/dubbo-go/v3/common/constant"
)

import (
"github.com/stretchr/testify/assert"
)

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
)

func TestGetLocalIp(t *testing.T) {
assert.NotNil(t, GetLocalIp())
}
Expand Down
Loading

0 comments on commit b534f75

Please sign in to comment.