Skip to content

Commit

Permalink
Mod: modify inappropriate comments after review & merge develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
watermelo committed May 24, 2020
2 parents 6489acf + d2eee54 commit 51ec3df
Show file tree
Hide file tree
Showing 73 changed files with 1,274 additions and 281 deletions.
5 changes: 5 additions & 0 deletions .asf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
notifications:
commits: commits@dubbo.apache.org
issues: notifications@dubbo.apache.org
pullrequests: notifications@dubbo.apache.org
jira_options: link label link label
17 changes: 13 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
language: go
dist: trusty
sudo: required

# define the dependence env
language: go
os:
- linux

go:
- "1.13"

services:
- docker
env:
- GO111MODULE=on

install: true

# define ci-stage
script:
# license-check
- echo 'start license check'
- go fmt ./... && [[ -z `git status -s` ]]
- sh before_validate_license.sh
- chmod u+x /tmp/tools/license/license-header-checker
- /tmp/tools/license/license-header-checker -v -a -r -i vendor /tmp/tools/license/license.txt . go && [[ -z `git status -s` ]]
# unit-test
- echo 'start unit-test'
- chmod u+x before_ut.sh && ./before_ut.sh
- go mod vendor && go test ./... -coverprofile=coverage.txt -covermode=atomic
# integrate-test
- chmod +x integrate_test.sh && ./integrate_test.sh

after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
6 changes: 3 additions & 3 deletions cluster/cluster_impl/available_cluster_invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
availableUrl, _ = common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
)

func registerAvailable(t *testing.T, invoker *mock.MockInvoker) protocol.Invoker {
func registerAvailable(invoker *mock.MockInvoker) protocol.Invoker {
extension.SetLoadbalance("random", loadbalance.NewRandomLoadBalance)
availableCluster := NewAvailableCluster()

Expand All @@ -60,7 +60,7 @@ func TestAvailableClusterInvokerSuccess(t *testing.T) {
defer ctrl.Finish()

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

mockResult := &protocol.RPCResult{Rest: rest{tried: 0, success: true}}
invoker.EXPECT().IsAvailable().Return(true)
Expand All @@ -76,7 +76,7 @@ func TestAvailableClusterInvokerNoAvail(t *testing.T) {
defer ctrl.Finish()

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

invoker.EXPECT().IsAvailable().Return(false)

Expand Down
1 change: 0 additions & 1 deletion cluster/cluster_impl/base_cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func (invoker *baseClusterInvoker) checkWhetherDestroyed() error {
}

func (invoker *baseClusterInvoker) doSelect(lb cluster.LoadBalance, invocation protocol.Invocation, invokers []protocol.Invoker, invoked []protocol.Invoker) protocol.Invoker {

var selectedInvoker protocol.Invoker
url := invokers[0].GetUrl()
sticky := url.GetParamBool(constant.STICKY_KEY, false)
Expand Down
4 changes: 2 additions & 2 deletions cluster/cluster_impl/failover_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ func normalInvoke(t *testing.T, successCount int, urlParam url.Values, invocatio

invokers := []protocol.Invoker{}
for i := 0; i < 10; i++ {
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))
newUrl, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.%v:20000/com.ikurento.user.UserProvider", i), common.WithParams(urlParam))
invokers = append(invokers, NewMockInvoker(newUrl, successCount))
}

staticDir := directory.NewStaticDirectory(invokers)
Expand Down
2 changes: 1 addition & 1 deletion cluster/directory/base_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (dir *BaseDirectory) SetRouters(urls []*common.URL) {
factory := extension.GetRouterFactory(url.Protocol)
r, err := factory.NewRouter(url)
if err != nil {
logger.Errorf("Create router fail. router key: %s, error: %v", routerKey, url.Service(), err)
logger.Errorf("Create router fail. router key: %s, url:%s, error: %+v", routerKey, url.Service(), err)
return
}
routers = append(routers, r)
Expand Down
5 changes: 2 additions & 3 deletions cluster/directory/base_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package directory

import (
"encoding/base64"
"fmt"
"testing"
)

Expand All @@ -35,7 +34,7 @@ import (
)

func TestNewBaseDirectory(t *testing.T) {
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider"))
url, _ := common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
directory := NewBaseDirectory(&url)

assert.NotNil(t, directory)
Expand All @@ -46,7 +45,7 @@ func TestNewBaseDirectory(t *testing.T) {
}

func TestBuildRouterChain(t *testing.T) {
url, _ := common.NewURL(fmt.Sprintf("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider"))
url, _ := common.NewURL("dubbo://192.168.1.1:20000/com.ikurento.user.UserProvider")
directory := NewBaseDirectory(&url)

assert.NotNil(t, directory)
Expand Down
2 changes: 1 addition & 1 deletion cluster/directory/static_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (dir *staticDirectory) IsAvailable() bool {
// List List invokers
func (dir *staticDirectory) List(invocation protocol.Invocation) []protocol.Invoker {
l := len(dir.invokers)
invokers := make([]protocol.Invoker, l, l)
invokers := make([]protocol.Invoker, l)
copy(invokers, dir.invokers)
routerChain := dir.RouterChain()

Expand Down
33 changes: 10 additions & 23 deletions cluster/loadbalance/consistent_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import (
"strconv"
"strings"
)

import (
gxsort "github.com/dubbogo/gost/sort"
)
import (
"github.com/apache/dubbo-go/cluster"
"github.com/apache/dubbo-go/common/constant"
Expand All @@ -40,7 +42,7 @@ const (
ConsistentHash = "consistenthash"
// HashNodes ...
HashNodes = "hash.nodes"
// HashArguments ...
// HashArguments key of hash arguments in url
HashArguments = "hash.arguments"
)

Expand All @@ -53,16 +55,16 @@ func init() {
extension.SetLoadbalance(ConsistentHash, NewConsistentHashLoadBalance)
}

// ConsistentHashLoadBalance ...
// ConsistentHashLoadBalance implementation of load balancing: using consistent hashing
type ConsistentHashLoadBalance struct {
}

// NewConsistentHashLoadBalance ...
// NewConsistentHashLoadBalance creates NewConsistentHashLoadBalance
func NewConsistentHashLoadBalance() cluster.LoadBalance {
return &ConsistentHashLoadBalance{}
}

// Select ...
// Select gets invoker based on load balancing strategy
func (lb *ConsistentHashLoadBalance) Select(invokers []protocol.Invoker, invocation protocol.Invocation) protocol.Invoker {
methodName := invocation.MethodName()
key := invokers[0].GetUrl().ServiceKey() + "." + methodName
Expand All @@ -85,27 +87,12 @@ func (lb *ConsistentHashLoadBalance) Select(invokers []protocol.Invoker, invocat
return selector.Select(invocation)
}

// Uint32Slice ...
type Uint32Slice []uint32

func (s Uint32Slice) Len() int {
return len(s)
}

func (s Uint32Slice) Less(i, j int) bool {
return s[i] < s[j]
}

func (s Uint32Slice) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

// ConsistentHashSelector ...
// ConsistentHashSelector implementation of Selector:get invoker based on load balancing strategy
type ConsistentHashSelector struct {
hashCode uint32
replicaNum int
virtualInvokers map[uint32]protocol.Invoker
keys Uint32Slice
keys gxsort.Uint32Slice
argumentIndex []int
}

Expand Down Expand Up @@ -141,7 +128,7 @@ func newConsistentHashSelector(invokers []protocol.Invoker, methodName string,
return selector
}

// Select ...
// Select gets invoker based on load balancing strategy
func (c *ConsistentHashSelector) Select(invocation protocol.Invocation) protocol.Invoker {
key := c.toKey(invocation.Arguments())
digest := md5.Sum([]byte(key))
Expand Down
10 changes: 5 additions & 5 deletions common/config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ func (env *Environment) Configuration() *list.List {
return cfgList
}

// SetDynamicConfiguration is used to set value for dynamicConfiguration
// SetDynamicConfiguration sets value for dynamicConfiguration
func (env *Environment) SetDynamicConfiguration(dc config_center.DynamicConfiguration) {
env.dynamicConfiguration = dc
}

// GetDynamicConfiguration is used to get dynamicConfiguration
// GetDynamicConfiguration gets dynamicConfiguration
func (env *Environment) GetDynamicConfiguration() config_center.DynamicConfiguration {
return env.dynamicConfiguration
}

// InmemoryConfiguration is used to store config in memory
// InmemoryConfiguration stores config in memory
type InmemoryConfiguration struct {
store *sync.Map
}
Expand All @@ -110,7 +110,7 @@ func newInmemoryConfiguration(p *sync.Map) *InmemoryConfiguration {
return &InmemoryConfiguration{store: p}
}

// GetProperty is used the key to get value from InmemoryConfiguration instance
// GetProperty gets value from InmemoryConfiguration instance by @key
func (conf *InmemoryConfiguration) GetProperty(key string) (bool, string) {
if conf.store == nil {
return false, ""
Expand All @@ -124,7 +124,7 @@ func (conf *InmemoryConfiguration) GetProperty(key string) (bool, string) {
return false, ""
}

// GetSubProperty is used the subkey to get sub property from InmemoryConfiguration instance
// GetSubProperty gets sub property from InmemoryConfiguration instance by @subkey
func (conf *InmemoryConfiguration) GetSubProperty(subKey string) map[string]struct{} {
if conf.store == nil {
return nil
Expand Down
8 changes: 4 additions & 4 deletions common/extension/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ var (
accesskeyStorages = make(map[string]func() filter.AccessKeyStorage)
)

// SetAuthenticator puts the fcn into map with name
// SetAuthenticator puts the @fcn into map with name
func SetAuthenticator(name string, fcn func() filter.Authenticator) {
authenticators[name] = fcn
}

// GetAuthenticator finds the Authenticator with name
// GetAuthenticator finds the Authenticator with @name
// if not found, it will panic
func GetAuthenticator(name string) filter.Authenticator {
if authenticators[name] == nil {
Expand All @@ -40,12 +40,12 @@ func GetAuthenticator(name string) filter.Authenticator {
return authenticators[name]()
}

// SetAccesskeyStorages will set the fcn into map with this name
// SetAccesskeyStorages will set the @fcn into map with this name
func SetAccesskeyStorages(name string, fcn func() filter.AccessKeyStorage) {
accesskeyStorages[name] = fcn
}

// GetAccesskeyStorages finds the storage with the name.
// GetAccesskeyStorages finds the storage with the @name.
// If not found, it will panic.
func GetAccesskeyStorages(name string) filter.AccessKeyStorage {
if accesskeyStorages[name] == nil {
Expand Down
4 changes: 2 additions & 2 deletions common/extension/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ var (
clusters = make(map[string]func() cluster.Cluster)
)

// SetCluster sets the cluster fault-tolerant mode with name
// SetCluster sets the cluster fault-tolerant mode with @name
// For example: available/failfast/broadcast/failfast/failsafe/...
func SetCluster(name string, fcn func() cluster.Cluster) {
clusters[name] = fcn
}

// GetCluster finds the cluster fault-tolerant mode with name
// GetCluster finds the cluster fault-tolerant mode with @name
func GetCluster(name string) cluster.Cluster {
if clusters[name] == nil {
panic("cluster for " + name + " is not existing, make sure you have import the package.")
Expand Down
4 changes: 2 additions & 2 deletions common/extension/config_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ var (
configCenters = make(map[string]func(config *common.URL) (config_center.DynamicConfiguration, error))
)

// SetConfigCenter sets the DynamicConfiguration with name
// SetConfigCenter sets the DynamicConfiguration with @name
func SetConfigCenter(name string, v func(config *common.URL) (config_center.DynamicConfiguration, error)) {
configCenters[name] = v
}

// GetConfigCenter finds the DynamicConfiguration with name
// GetConfigCenter finds the DynamicConfiguration with @name
func GetConfigCenter(name string, config *common.URL) (config_center.DynamicConfiguration, error) {
if configCenters[name] == nil {
panic("config center for " + name + " is not existing, make sure you have import the package.")
Expand Down
4 changes: 2 additions & 2 deletions common/extension/config_center_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ var (
configCenterFactories = make(map[string]func() config_center.DynamicConfigurationFactory)
)

// SetConfigCenterFactory sets the DynamicConfigurationFactory with name
// SetConfigCenterFactory sets the DynamicConfigurationFactory with @name
func SetConfigCenterFactory(name string, v func() config_center.DynamicConfigurationFactory) {
configCenterFactories[name] = v
}

// GetConfigCenterFactory finds the DynamicConfigurationFactory with name
// GetConfigCenterFactory finds the DynamicConfigurationFactory with @name
func GetConfigCenterFactory(name string) config_center.DynamicConfigurationFactory {
if configCenterFactories[name] == nil {
panic("config center for " + name + " is not existing, make sure you have import the package.")
Expand Down
8 changes: 4 additions & 4 deletions common/extension/config_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ var (
defaults = make(map[string]string)
)

// SetConfigReaders sets a creator of config reader.
// SetConfigReaders sets a creator of config reader with @name
func SetConfigReaders(name string, v func() interfaces.ConfigReader) {
configReaders[name] = v
}

// GetConfigReaders gets a config reader by name.
// GetConfigReaders gets a config reader with @name
func GetConfigReaders(name string) interfaces.ConfigReader {
if configReaders[name] == nil {
panic("config reader for " + name + " is not existing, make sure you have imported the package.")
}
return configReaders[name]()
}

// SetDefaultConfigReader sets {name} to default config reader for {module}
// SetDefaultConfigReader sets @name for @module in default config reader
func SetDefaultConfigReader(module, name string) {
defaults[module] = name
}

// GetDefaultConfigReader
// GetDefaultConfigReader gets default config reader
func GetDefaultConfigReader() map[string]string {
return defaults
}
6 changes: 3 additions & 3 deletions common/extension/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ var (
configurator = make(map[string]getConfiguratorFunc)
)

// SetConfigurator sets the getConfiguratorFunc with name
// SetConfigurator sets the getConfiguratorFunc with @name
func SetConfigurator(name string, v getConfiguratorFunc) {
configurator[name] = v
}

// GetConfigurator finds the Configurator with name
// GetConfigurator finds the Configurator with @name
func GetConfigurator(name string, url *common.URL) config_center.Configurator {
if configurator[name] == nil {
panic("configurator for " + name + " is not existing, make sure you have import the package.")
Expand All @@ -52,7 +52,7 @@ func SetDefaultConfigurator(v getConfiguratorFunc) {
configurator[DefaultKey] = v
}

// GetDefaultConfigurator get default configurator
// GetDefaultConfigurator gets default configurator
func GetDefaultConfigurator(url *common.URL) config_center.Configurator {
if configurator[DefaultKey] == nil {
panic("configurator for default is not existing, make sure you have import the package.")
Expand Down
Loading

0 comments on commit 51ec3df

Please sign in to comment.