Skip to content

Commit

Permalink
Merge pull request #7 from apache/develop
Browse files Browse the repository at this point in the history
Sync latest code~
  • Loading branch information
sxllwx authored Jun 1, 2020
2 parents dcb4cc2 + 4af26b9 commit 02e1ee4
Show file tree
Hide file tree
Showing 78 changed files with 470 additions and 362 deletions.
17 changes: 1 addition & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,7 @@ script:
- chmod u+x before_ut.sh && ./before_ut.sh
- go mod vendor && go test ./... -coverprofile=coverage.txt -covermode=atomic
# integrate-test
- echo 'start integrate-test'
# start zookeeper registry insecure listen in [:]:2181
- docker run -d --network host zookeeper
- ROOTDIR=$(pwd)
- cd ./test/integrate/dubbo/go-client && docker build . -t ci-consumer --build-arg PR_ORIGIN_REPO=${TRAVIS_PULL_REQUEST_SLUG} --build-arg PR_ORIGIN_COMMITID=${TRAVIS_PULL_REQUEST_SHA} && cd $ROOTDIR
- cd ./test/integrate/dubbo/go-server && docker build . -t ci-provider --build-arg PR_ORIGIN_REPO=${TRAVIS_PULL_REQUEST_SLUG} --build-arg PR_ORIGIN_COMMITID=${TRAVIS_PULL_REQUEST_SHA} && cd $ROOTDIR
- docker run -d --network host ci-provider
- docker run -it --network host ci-consumer

# another registry instance, start it by dep
# start etcd registry insecure listen in [:]:2379
#- docker run -d --network host k8s.gcr.io/etcd:3.3.10 etcd
# start consul registry insecure listen in [:]:8500
#- docker run -d --network host consul
# start nacos registry insecure listen in [:]:8848
#- docker run -d --network host nacos/nacos-server:latest
- 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
21 changes: 11 additions & 10 deletions common/config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ var (
once sync.Once
)

// GetEnvInstance ...
// GetEnvInstance gets env instance by singleton
func GetEnvInstance() *Environment {
once.Do(func() {
instance = &Environment{configCenterFirst: true}
})
return instance
}

// NewEnvInstance ...
// NewEnvInstance creates Environment instance
func NewEnvInstance() {
instance = &Environment{configCenterFirst: true}
}
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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, ""
Expand All @@ -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
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 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 {
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 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 {
Expand Down
5 changes: 3 additions & 2 deletions common/extension/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
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 ...
// 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.")
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 ...
// 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.")
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 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.")
}
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
}
12 changes: 6 additions & 6 deletions common/extension/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

const (
// DefaultKey ...
// DefaultKey for default Configurator
DefaultKey = "default"
)

Expand All @@ -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.")
Expand All @@ -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.")
Expand All @@ -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.")
Expand Down
9 changes: 5 additions & 4 deletions common/extension/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,26 @@ 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.")
}
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 {
Expand Down
2 changes: 1 addition & 1 deletion common/extension/graceful_shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func AddCustomShutdownCallback(callback func()) {
customShutdownCallbacks.PushBack(callback)
}

// GetAllCustomShutdownCallbacks ...
// GetAllCustomShutdownCallbacks gets all custom shutdown callbacks
func GetAllCustomShutdownCallbacks() *list.List {
return customShutdownCallbacks
}
Loading

0 comments on commit 02e1ee4

Please sign in to comment.