Skip to content

Commit

Permalink
fix mock
Browse files Browse the repository at this point in the history
  • Loading branch information
xujianhai666 committed Jul 28, 2019
1 parent be07149 commit 0653977
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
13 changes: 7 additions & 6 deletions cluster/cluster_impl/failback_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ import (
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/protocol"
"github.com/apache/dubbo-go/protocol/invocation"
"github.com/apache/dubbo-go/protocol/mock"
)

var (
failbackUrl, _ = common.NewURL(context.TODO(), "dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
)

// register_failback register failbackCluster to cluster extension.
func register_failback(t *testing.T, invoker *protocol.MockInvoker) protocol.Invoker {
func register_failback(t *testing.T, invoker *mock.MockInvoker) protocol.Invoker {
extension.SetLoadbalance("random", loadbalance.NewRandomLoadBalance)
failbackCluster := NewFailbackCluster()

Expand All @@ -63,7 +64,7 @@ func Test_FailbackSuceess(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

invoker := protocol.NewMockInvoker(ctrl)
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := register_failback(t, invoker).(*failbackClusterInvoker)

invoker.EXPECT().GetUrl().Return(failbackUrl).Times(1)
Expand All @@ -80,7 +81,7 @@ func Test_FailbackRetryOneSuccess(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

invoker := protocol.NewMockInvoker(ctrl)
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := register_failback(t, invoker).(*failbackClusterInvoker)

invoker.EXPECT().GetUrl().Return(failbackUrl).AnyTimes()
Expand Down Expand Up @@ -123,7 +124,7 @@ func Test_FailbackRetryFailed(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

invoker := protocol.NewMockInvoker(ctrl)
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := register_failback(t, invoker).(*failbackClusterInvoker)

invoker.EXPECT().GetUrl().Return(failbackUrl).AnyTimes()
Expand Down Expand Up @@ -169,7 +170,7 @@ func Test_FailbackRetryFailed10Times(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

invoker := protocol.NewMockInvoker(ctrl)
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := register_failback(t, invoker).(*failbackClusterInvoker)
clusterInvoker.maxRetries = 10

Expand Down Expand Up @@ -211,7 +212,7 @@ func Test_FailbackOutOfLimit(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

invoker := protocol.NewMockInvoker(ctrl)
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := register_failback(t, invoker).(*failbackClusterInvoker)
clusterInvoker.failbackTasks = 1

Expand Down
7 changes: 4 additions & 3 deletions cluster/cluster_impl/failsafe_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ import (
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/protocol"
"github.com/apache/dubbo-go/protocol/invocation"
"github.com/apache/dubbo-go/protocol/mock"
)

var (
failsafeUrl, _ = common.NewURL(context.TODO(), "dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
)

// register_failsafe register failsafeCluster to cluster extension.
func register_failsafe(t *testing.T, invoker *protocol.MockInvoker) protocol.Invoker {
func register_failsafe(t *testing.T, invoker *mock.MockInvoker) protocol.Invoker {
extension.SetLoadbalance("random", loadbalance.NewRandomLoadBalance)
failsafeCluster := NewFailsafeCluster()

Expand All @@ -60,7 +61,7 @@ func Test_FailSafeInvokeSuccess(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

invoker := protocol.NewMockInvoker(ctrl)
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := register_failsafe(t, invoker)

invoker.EXPECT().GetUrl().Return(failsafeUrl)
Expand All @@ -79,7 +80,7 @@ func Test_FailSafeInvokeFail(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

invoker := protocol.NewMockInvoker(ctrl)
invoker := mock.NewMockInvoker(ctrl)
clusterInvoker := register_failsafe(t, invoker)

invoker.EXPECT().GetUrl().Return(failsafeUrl)
Expand Down
2 changes: 1 addition & 1 deletion protocol/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/apache/dubbo-go/common/logger"
)

//go:generate mockgen -source invoker.go -destination mock_invoker.go -self_package github.com/apache/dubbo-go/protocol --package protocol Invoker
//go:generate mockgen -source invoker.go -destination mock/mock_invoker.go -self_package github.com/apache/dubbo-go/protocol --package mock Invoker
// Extension - Invoker
type Invoker interface {
common.Node
Expand Down
16 changes: 11 additions & 5 deletions protocol/mock_invoker.go → protocol/mock/mock_invoker.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0653977

Please sign in to comment.