Skip to content
Snippets Groups Projects
Unverified Commit 34775e54 authored by lzp0412's avatar lzp0412 Committed by GitHub
Browse files

Merge pull request #9 from flycash/2.7.5-bk

2.7.5 bk
parents bfb89b50 f9938033
No related branches found
No related tags found
No related merge requests found
Showing
with 80 additions and 75 deletions
notifications:
commits: commits@dubbo.apache.org
issues: notifications@dubbo.apache.org
pullrequests: notifications@dubbo.apache.org
jira_options: link label link label
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)
......
......@@ -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()
......@@ -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)
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -89,7 +89,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)
......
......@@ -19,7 +19,6 @@ package directory
import (
"encoding/base64"
"fmt"
"testing"
)
......@@ -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)
......@@ -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)
......
......@@ -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()
......
......@@ -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"
......@@ -40,7 +42,7 @@ const (
ConsistentHash = "consistenthash"
// HashNodes ...
HashNodes = "hash.nodes"
// HashArguments ...
// HashArguments key of hash arguments in url
HashArguments = "hash.arguments"
)
......@@ -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
......@@ -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
}
......@@ -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))
......
......@@ -46,7 +46,7 @@ var (
once sync.Once
)
// GetEnvInstance ...
// GetEnvInstance gets env instance by singleton
func GetEnvInstance() *Environment {
once.Do(func() {
instance = &Environment{configCenterFirst: true}
......@@ -54,7 +54,7 @@ func GetEnvInstance() *Environment {
return instance
}
// NewEnvInstance ...
// NewEnvInstance creates Environment instance
func NewEnvInstance() {
instance = &Environment{configCenterFirst: true}
}
......@@ -67,21 +67,22 @@ func NewEnvInstance() {
// return env.configCenterFirst
//}
// UpdateExternalConfigMap ...
// UpdateExternalConfigMap updates env externalConfigMap field
func (env *Environment) UpdateExternalConfigMap(externalMap map[string]string) {
for k, v := range externalMap {
env.externalConfigMap.Store(k, v)
}
}
// UpdateAppExternalConfigMap ...
// UpdateAppExternalConfigMap updates env appExternalConfigMap field
func (env *Environment) UpdateAppExternalConfigMap(externalMap map[string]string) {
for k, v := range externalMap {
env.appExternalConfigMap.Store(k, v)
}
}
// Configuration ...
// Configuration puts externalConfigMap and appExternalConfigMap into list
// List represents a doubly linked list.
func (env *Environment) Configuration() *list.List {
cfgList := list.New()
// The sequence would be: SystemConfiguration -> ExternalConfiguration -> AppExternalConfiguration -> AbstractConfig -> PropertiesConfiguration
......@@ -90,17 +91,17 @@ func (env *Environment) Configuration() *list.List {
return cfgList
}
// SetDynamicConfiguration ...
// SetDynamicConfiguration sets value for dynamicConfiguration
func (env *Environment) SetDynamicConfiguration(dc config_center.DynamicConfiguration) {
env.dynamicConfiguration = dc
}
// GetDynamicConfiguration ...
// GetDynamicConfiguration gets dynamicConfiguration
func (env *Environment) GetDynamicConfiguration() config_center.DynamicConfiguration {
return env.dynamicConfiguration
}
// InmemoryConfiguration ...
// InmemoryConfiguration stores config in memory
type InmemoryConfiguration struct {
store *sync.Map
}
......@@ -109,7 +110,7 @@ func newInmemoryConfiguration(p *sync.Map) *InmemoryConfiguration {
return &InmemoryConfiguration{store: p}
}
// GetProperty ...
// GetProperty gets value from InmemoryConfiguration instance by @key
func (conf *InmemoryConfiguration) GetProperty(key string) (bool, string) {
if conf.store == nil {
return false, ""
......@@ -123,7 +124,7 @@ func (conf *InmemoryConfiguration) GetProperty(key string) (bool, string) {
return false, ""
}
// GetSubProperty ...
// GetSubProperty gets sub property from InmemoryConfiguration instance by @subkey
func (conf *InmemoryConfiguration) GetSubProperty(subKey string) map[string]struct{} {
if conf.store == nil {
return nil
......
......@@ -187,6 +187,9 @@ const (
// ForceUseTag is the tag in attachment
ForceUseTag = "dubbo.force.tag"
Tagkey = "dubbo.tag"
// Attachment key in context in invoker
AttachmentKey = "attachment"
)
const (
......
......@@ -26,12 +26,12 @@ var (
accesskeyStorages = make(map[string]func() filter.AccessKeyStorage)
)
// SetAuthenticator put 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 find 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 {
......@@ -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 find 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 {
......
......@@ -25,12 +25,13 @@ var (
clusters = make(map[string]func() cluster.Cluster)
)
// SetCluster ...
// 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 ...
// 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.")
......
......@@ -26,12 +26,12 @@ var (
configCenters = make(map[string]func(config *common.URL) (config_center.DynamicConfiguration, error))
)
// SetConfigCenter ...
// SetConfigCenter sets the DynamicConfiguration with @name
func SetConfigCenter(name string, v func(config *common.URL) (config_center.DynamicConfiguration, error)) {
configCenters[name] = v
}
// GetConfigCenter ...
// 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.")
......
......@@ -25,12 +25,12 @@ var (
configCenterFactories = make(map[string]func() config_center.DynamicConfigurationFactory)
)
// SetConfigCenterFactory ...
// SetConfigCenterFactory sets the DynamicConfigurationFactory with @name
func SetConfigCenterFactory(name string, v func() config_center.DynamicConfigurationFactory) {
configCenterFactories[name] = v
}
// GetConfigCenterFactory ...
// 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.")
......
......@@ -26,12 +26,12 @@ var (
defaults = make(map[string]string)
)
// SetConfigReaders set 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 get 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.")
......@@ -39,12 +39,12 @@ func GetConfigReaders(name string) interfaces.ConfigReader {
return configReaders[name]()
}
// SetDefaultConfigReader set {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
}
......@@ -23,7 +23,7 @@ import (
)
const (
// DefaultKey ...
// DefaultKey for default Configurator
DefaultKey = "default"
)
......@@ -33,12 +33,12 @@ var (
configurator = make(map[string]getConfiguratorFunc)
)
// SetConfigurator ...
// SetConfigurator sets the getConfiguratorFunc with @name
func SetConfigurator(name string, v getConfiguratorFunc) {
configurator[name] = v
}
// GetConfigurator ...
// 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.")
......@@ -47,12 +47,12 @@ func GetConfigurator(name string, url *common.URL) config_center.Configurator {
}
// SetDefaultConfigurator ...
// SetDefaultConfigurator sets the default Configurator
func SetDefaultConfigurator(v getConfiguratorFunc) {
configurator[DefaultKey] = v
}
// GetDefaultConfigurator ...
// 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.")
......@@ -61,7 +61,7 @@ func GetDefaultConfigurator(url *common.URL) config_center.Configurator {
}
// GetDefaultConfiguratorFunc ...
// GetDefaultConfiguratorFunc gets default configurator function
func GetDefaultConfiguratorFunc() getConfiguratorFunc {
if configurator[DefaultKey] == nil {
panic("configurator for default is not existing, make sure you have import the package.")
......
......@@ -26,12 +26,13 @@ var (
rejectedExecutionHandler = make(map[string]func() filter.RejectedExecutionHandler)
)
// SetFilter ...
// SetFilter sets the filter extension with @name
// For example: hystrix/metrics/token/tracing/limit/...
func SetFilter(name string, v func() filter.Filter) {
filters[name] = v
}
// GetFilter ...
// GetFilter finds the filter extension with @name
func GetFilter(name string) filter.Filter {
if filters[name] == nil {
panic("filter for " + name + " is not existing, make sure you have imported the package.")
......@@ -39,12 +40,12 @@ func GetFilter(name string) filter.Filter {
return filters[name]()
}
// SetRejectedExecutionHandler ...
// SetRejectedExecutionHandler sets the RejectedExecutionHandler with @name
func SetRejectedExecutionHandler(name string, creator func() filter.RejectedExecutionHandler) {
rejectedExecutionHandler[name] = creator
}
// GetRejectedExecutionHandler ...
// GetRejectedExecutionHandler finds the RejectedExecutionHandler with @name
func GetRejectedExecutionHandler(name string) filter.RejectedExecutionHandler {
creator, ok := rejectedExecutionHandler[name]
if !ok {
......
......@@ -49,7 +49,7 @@ func AddCustomShutdownCallback(callback func()) {
customShutdownCallbacks.PushBack(callback)
}
// GetAllCustomShutdownCallbacks ...
// GetAllCustomShutdownCallbacks gets all custom shutdown callbacks
func GetAllCustomShutdownCallbacks() *list.List {
return customShutdownCallbacks
}
......@@ -26,12 +26,12 @@ var (
healthCheckers = make(map[string]func(url *common.URL) router.HealthChecker)
)
// SethealthChecker set the HealthChecker with name
// SethealthChecker sets the HealthChecker with @name
func SethealthChecker(name string, fcn func(url *common.URL) router.HealthChecker) {
healthCheckers[name] = fcn
}
// GetHealthChecker get the HealthChecker with name
// GetHealthChecker gets the HealthChecker with @name
func GetHealthChecker(name string, url *common.URL) router.HealthChecker {
if healthCheckers[name] == nil {
panic("healthCheckers for " + name + " is not existing, make sure you have import the package.")
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment