From 4f2731aa9b2a5c8d69e2999e1ab6393d3ecb14d6 Mon Sep 17 00:00:00 2001 From: Joe Zou <yixian.zou@gmail.com> Date: Sat, 8 Feb 2020 22:08:10 +0800 Subject: [PATCH] fix test case and add some comment --- cluster/directory/base_directory.go | 14 +++++++------- cluster/directory/static_directory.go | 4 +++- cluster/router/condition/listenable_router.go | 4 +++- cluster/router/match/match_utils_test.go | 1 - 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cluster/directory/base_directory.go b/cluster/directory/base_directory.go index 353e10a68..5ad9c0f64 100644 --- a/cluster/directory/base_directory.go +++ b/cluster/directory/base_directory.go @@ -18,7 +18,6 @@ package directory import ( - "github.com/apache/dubbo-go/common/logger" "sync" ) @@ -32,12 +31,13 @@ import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/common/extension" + "github.com/apache/dubbo-go/common/logger" "github.com/dubbogo/gost/container/set" ) var routerURLSet = gxset.NewSet() -// BaseDirectory ... +// BaseDirectory Abstract implementation of Directory: Invoker list returned from this Directory's list method have been filtered by Routers type BaseDirectory struct { url *common.URL destroyed *atomic.Bool @@ -57,7 +57,7 @@ func (dir *BaseDirectory) SetRouterChain(routerChain router.Chain) { dir.routerChain = routerChain } -// NewBaseDirectory ... +// NewBaseDirectory Create BaseDirectory with URL func NewBaseDirectory(url *common.URL) BaseDirectory { return BaseDirectory{ url: url, @@ -66,12 +66,12 @@ func NewBaseDirectory(url *common.URL) BaseDirectory { } } -// GetUrl ... +// GetUrl Get URL func (dir *BaseDirectory) GetUrl() common.URL { return *dir.url } -// GetDirectoryUrl ... +// GetDirectoryUrl Get URL instance func (dir *BaseDirectory) GetDirectoryUrl() *common.URL { return dir.url } @@ -106,7 +106,7 @@ func (dir *BaseDirectory) SetRouters(urls []*common.URL) { rc.AddRouters(routers) } -// Destroy ... +// Destroy Destroy func (dir *BaseDirectory) Destroy(doDestroy func()) { if dir.destroyed.CAS(false, true) { dir.mutex.Lock() @@ -115,7 +115,7 @@ func (dir *BaseDirectory) Destroy(doDestroy func()) { } } -// IsAvailable ... +// IsAvailable Once directory init finish, it will change to true func (dir *BaseDirectory) IsAvailable() bool { return !dir.destroyed.Load() } diff --git a/cluster/directory/static_directory.go b/cluster/directory/static_directory.go index abe03db90..032859a27 100644 --- a/cluster/directory/static_directory.go +++ b/cluster/directory/static_directory.go @@ -27,7 +27,7 @@ type staticDirectory struct { invokers []protocol.Invoker } -// NewStaticDirectory ... +// NewStaticDirectory Create a new staticDirectory with invokers func NewStaticDirectory(invokers []protocol.Invoker) *staticDirectory { var url common.URL @@ -53,6 +53,7 @@ func (dir *staticDirectory) IsAvailable() bool { return true } +// List List invokers func (dir *staticDirectory) List(invocation protocol.Invocation) []protocol.Invoker { l := len(dir.invokers) invokers := make([]protocol.Invoker, l, l) @@ -66,6 +67,7 @@ func (dir *staticDirectory) List(invocation protocol.Invocation) []protocol.Invo return routerChain.Route(invokers, &dirUrl, invocation) } +// Destroy Destroy func (dir *staticDirectory) Destroy() { dir.BaseDirectory.Destroy(func() { for _, ivk := range dir.invokers { diff --git a/cluster/router/condition/listenable_router.go b/cluster/router/condition/listenable_router.go index 4b7b56ff9..933dc5f32 100644 --- a/cluster/router/condition/listenable_router.go +++ b/cluster/router/condition/listenable_router.go @@ -40,7 +40,7 @@ const ( listenableRouterDefaultPriority = ^int64(0) ) -//ListenableRouter Abstract router which listens to dynamic configuration +// listenableRouter Abstract router which listens to dynamic configuration type listenableRouter struct { conditionRouters []*ConditionRouter routerRule *RouterRule @@ -49,6 +49,7 @@ type listenableRouter struct { priority int64 } +// RouterRule Get RouterRule instance from listenableRouter func (l *listenableRouter) RouterRule() *RouterRule { return l.routerRule } @@ -84,6 +85,7 @@ func newListenableRouter(url *common.URL, ruleKey string) (*AppRouter, error) { return l, nil } +// Process Process config change event , generate routers and set them to the listenableRouter instance func (l *listenableRouter) Process(event *config_center.ConfigChangeEvent) { logger.Infof("Notification of condition rule, change type is:[%s] , raw rule is:[%v]", event.ConfigType, event.Value) if remoting.EventTypeDel == event.ConfigType { diff --git a/cluster/router/match/match_utils_test.go b/cluster/router/match/match_utils_test.go index e36d68fa9..f16480f1d 100644 --- a/cluster/router/match/match_utils_test.go +++ b/cluster/router/match/match_utils_test.go @@ -18,7 +18,6 @@ package match import ( - "context" "testing" ) -- GitLab