Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt: opt err handling #536

Merged
merged 4 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/metadata_report_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func startMetadataReport(metadataType string, metadataReportConfig *MetadataRepo
if url, err := metadataReportConfig.ToUrl(); err == nil {
instance.GetMetadataReportInstance(url)
} else {
return perrors.New("MetadataConfig is invalid!")
return perrors.Wrap(err, "Start MetadataReport failed.")
AlexStocks marked this conversation as resolved.
Show resolved Hide resolved
}

return nil
Expand Down
17 changes: 12 additions & 5 deletions registry/directory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ func (dir *RegistryDirectory) refreshInvokers(res *registry.ServiceEvent) {
}

func (dir *RegistryDirectory) toGroupInvokers() []protocol.Invoker {
newInvokersList := []protocol.Invoker{}
var (
err error
newInvokersList []protocol.Invoker
)
groupInvokersMap := make(map[string][]protocol.Invoker)
groupInvokersList := []protocol.Invoker{}

dir.cacheInvokersMap.Range(func(key, value interface{}) bool {
newInvokersList = append(newInvokersList, value.(protocol.Invoker))
Expand All @@ -170,6 +172,7 @@ func (dir *RegistryDirectory) toGroupInvokers() []protocol.Invoker {
groupInvokersMap[group] = []protocol.Invoker{invoker}
}
}
groupInvokersList := make([]protocol.Invoker, 0, len(groupInvokersMap))
if len(groupInvokersMap) == 1 {
//len is 1 it means no group setting ,so do not need cluster again
for _, invokers := range groupInvokersMap {
Expand All @@ -178,9 +181,13 @@ func (dir *RegistryDirectory) toGroupInvokers() []protocol.Invoker {
} else {
for _, invokers := range groupInvokersMap {
staticDir := directory.NewStaticDirectory(invokers)
cluster := extension.GetCluster(dir.GetUrl().SubURL.GetParam(constant.CLUSTER_KEY, constant.DEFAULT_CLUSTER))
staticDir.BuildRouterChain(invokers)
groupInvokersList = append(groupInvokersList, cluster.Join(staticDir))
cst := extension.GetCluster(dir.GetUrl().SubURL.GetParam(constant.CLUSTER_KEY, constant.DEFAULT_CLUSTER))
err = staticDir.BuildRouterChain(invokers)
if err != nil {
logger.Error(err)
continue
}
Comment on lines +185 to +189
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this

Suggested change
err = staticDir.BuildRouterChain(invokers)
if err != nil {
logger.Error(err)
continue
}
if err = staticDir.BuildRouterChain(invokers); err != nil {
logger.Error(err)
continue
}

groupInvokersList = append(groupInvokersList, cst.Join(staticDir))
}
}

Expand Down
16 changes: 16 additions & 0 deletions registry/directory/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)

Expand All @@ -37,6 +38,7 @@ import (
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/config"
"github.com/apache/dubbo-go/protocol/invocation"
"github.com/apache/dubbo-go/protocol/mock"
"github.com/apache/dubbo-go/protocol/protocolwrapper"
"github.com/apache/dubbo-go/registry"
"github.com/apache/dubbo-go/remoting"
Expand Down Expand Up @@ -169,7 +171,21 @@ Loop1:
break Loop1
}
}
}

func Test_toGroupInvokers(t *testing.T) {
registryDirectory, _ := normalRegistryDir()
ctrl := gomock.NewController(t)
defer ctrl.Finish()
invoker := mock.NewMockInvoker(ctrl)
newUrl, _ := common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
invoker.EXPECT().GetUrl().Return(newUrl).AnyTimes()

registryDirectory.cacheInvokersMap.Store("group1", invoker)
registryDirectory.cacheInvokersMap.Store("group2", invoker)
registryDirectory.cacheInvokersMap.Store("group1", invoker)
groupInvokers := registryDirectory.toGroupInvokers()
assert.Len(t, groupInvokers, 2)
}

func normalRegistryDir(noMockEvent ...bool) (*RegistryDirectory, *registry.MockRegistry) {
Expand Down