Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexStocks authored Jan 6, 2021
2 parents b4accad + 34fa1da commit 85a21e8
Show file tree
Hide file tree
Showing 115 changed files with 669 additions and 549 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,26 @@ jobs:
else
go get -v -t -d ./...
fi
- name: Verify
run: |
make verify
- name: Integrate Test
- name: gofmt
run: |
chmod +x integrate_test.sh && ./integrate_test.sh
go fmt ./... && git checkout -- go.mod && git status && [[ -z `git status -s` ]]
# diff -u <(echo -n) <(gofmt -d -s .)
- name: Install go ci lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0

- name: Run Linter
run: golangci-lint run --timeout=10m -v

- name: Verify
run: |
make verify
- name: Integrate Test
run: |
chmod +x integrate_test.sh && ./integrate_test.sh
- name: Post Coverage
run: bash <(curl -s https://codecov.io/bash)

Expand Down
63 changes: 63 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
linters-settings:
govet:
check-shadowing: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 10
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
misspell:
locale: US
lll:
line-length: 140
goimports:
local-prefixes: github.com/golangci/golangci-lint
gocritic:
enabled-tags:
- performance
- style
- experimental
disabled-checks:
- wrapperFunc

linters:
disable-all: true
enable:
- govet
- staticcheck
- ineffassign
- misspell

run:
skip-dirs:
- test/testdata_etc
- pkg/golinters/goanalysis/(checker|passes)

issues:
exclude-rules:
- text: "weak cryptographic primitive"
linters:
- gosec
- linters:
- staticcheck
text: "SA1019:"

# golangci.com configuration
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.15.x # use the fixed version to not introduce new linters unexpectedly
prepare:
- echo "here I can run custom commands, but no preparation needed for this repo"

28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

3 changes: 1 addition & 2 deletions cluster/cluster_impl/failback_cluster_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ func (invoker *failbackClusterInvoker) tryTimerTaskProc(ctx context.Context, ret
invoked = append(invoked, retryTask.lastInvoker)

retryInvoker := invoker.doSelect(retryTask.loadbalance, retryTask.invocation, retryTask.invokers, invoked)
var result protocol.Result
result = retryInvoker.Invoke(ctx, retryTask.invocation)
result := retryInvoker.Invoke(ctx, retryTask.invocation)
if result.Error() != nil {
retryTask.lastInvoker = retryInvoker
invoker.checkRetry(retryTask, result.Error())
Expand Down
2 changes: 1 addition & 1 deletion cluster/router/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (c *RouterChain) copyInvokerIfNecessary(cache *InvokerCache) []protocol.Inv
func (c *RouterChain) buildCache() {
origin := c.loadCache()
invokers := c.copyInvokerIfNecessary(origin)
if invokers == nil || len(invokers) == 0 {
if len(invokers) == 0 {
return
}

Expand Down
39 changes: 29 additions & 10 deletions cluster/router/chain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ conditions:

_, err = z.Conn.Set(path, []byte(testyml), 0)
assert.NoError(t, err)
defer ts.Stop()
defer z.Close()
defer func() {
_ = ts.Stop()
z.Close()
}()

zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, localIP, ts.Servers[0].Port))
configuration, err := extension.GetConfigCenterFactory(zk).GetDynamicConfiguration(zkUrl)
Expand Down Expand Up @@ -128,11 +130,15 @@ conditions:

_, err = z.Conn.Set(path, []byte(testyml), 0)
assert.NoError(t, err)
defer ts.Stop()
defer z.Close()
defer func() {
_ = ts.Stop()
assert.NoError(t, err)
z.Close()
}()

zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, localIP, ts.Servers[0].Port))
configuration, err := extension.GetConfigCenterFactory(zk).GetDynamicConfiguration(zkUrl)
assert.NoError(t, err)
config.GetEnvInstance().SetDynamicConfiguration(configuration)

chain, err := NewRouterChain(getConditionRouteUrl(applicationKey))
Expand All @@ -154,11 +160,15 @@ conditions:

func TestRouterChainRoute(t *testing.T) {
ts, z, _, err := zookeeper.NewMockZookeeperClient("test", 15*time.Second)
defer ts.Stop()
defer z.Close()
defer func() {
err = ts.Stop()
assert.NoError(t, err)
z.Close()
}()

zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, localIP, ts.Servers[0].Port))
configuration, err := extension.GetConfigCenterFactory(zk).GetDynamicConfiguration(zkUrl)
assert.NoError(t, err)
config.GetEnvInstance().SetDynamicConfiguration(configuration)

chain, err := NewRouterChain(getConditionRouteUrl(applicationKey))
Expand Down Expand Up @@ -198,11 +208,15 @@ conditions:

_, err = z.Conn.Set(path, []byte(testyml), 0)
assert.NoError(t, err)
defer ts.Stop()
defer z.Close()
defer func() {
_ = ts.Stop()
assert.NoError(t, err)
z.Close()
}()

zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, localIP, ts.Servers[0].Port))
configuration, err := extension.GetConfigCenterFactory(zk).GetDynamicConfiguration(zkUrl)
assert.NoError(t, err)
config.GetEnvInstance().SetDynamicConfiguration(configuration)

chain, err := NewRouterChain(getConditionRouteUrl(applicationKey))
Expand All @@ -224,12 +238,17 @@ conditions:

func TestRouterChainRouteNoRoute(t *testing.T) {
ts, z, _, err := zookeeper.NewMockZookeeperClient("test", 15*time.Second)
defer ts.Stop()
defer z.Close()
assert.Nil(t, err)
defer func() {
_ = ts.Stop()
assert.NoError(t, err)
z.Close()
}()

zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, localIP, ts.Servers[0].Port))
configuration, err := extension.GetConfigCenterFactory(zk).GetDynamicConfiguration(zkUrl)
config.GetEnvInstance().SetDynamicConfiguration(configuration)
assert.Nil(t, err)

chain, err := NewRouterChain(getConditionNoRouteUrl(applicationKey))
assert.Nil(t, err)
Expand Down
21 changes: 15 additions & 6 deletions cluster/router/condition/app_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ conditions:

_, err = z.Conn.Set(routerPath, []byte(testYML), 0)
assert.NoError(t, err)
defer ts.Stop()
defer z.Close()
defer func() {
err = ts.Stop()
assert.NoError(t, err)
z.Close()
}()

zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, routerLocalIP, ts.Servers[0].Port))
configuration, err := extension.GetConfigCenterFactory(routerZk).GetDynamicConfiguration(zkUrl)
Expand Down Expand Up @@ -115,8 +118,11 @@ conditions:

_, err = z.Conn.Set(routerPath, []byte(testYML), 0)
assert.NoError(t, err)
defer ts.Stop()
defer z.Close()
defer func() {
err = ts.Stop()
assert.NoError(t, err)
z.Close()
}()

zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, routerLocalIP, ts.Servers[0].Port))
configuration, err := extension.GetConfigCenterFactory(routerZk).GetDynamicConfiguration(zkUrl)
Expand Down Expand Up @@ -154,8 +160,11 @@ conditions:

_, err = z.Conn.Set(routerPath, []byte(testYML), 0)
assert.NoError(t, err)
defer ts.Stop()
defer z.Close()
defer func() {
err = ts.Stop()
assert.NoError(t, err)
z.Close()
}()

zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, routerLocalIP, ts.Servers[0].Port))
configuration, err := extension.GetConfigCenterFactory(routerZk).GetDynamicConfiguration(zkUrl)
Expand Down
3 changes: 3 additions & 0 deletions cluster/router/condition/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ func TestParseServiceRouterKey(t *testing.T) {
assert.Equal(t, "", grp)
assert.Equal(t, "mock-service", srv)
assert.Equal(t, "", ver)
assert.NoError(t, err)

testString = "/mock-service:"
grp, srv, ver, err = parseServiceRouterKey(testString)
assert.Equal(t, "", grp)
assert.Equal(t, "mock-service", srv)
assert.Equal(t, "", ver)
assert.NoError(t, err)

testString = "grp:mock-service:123"
grp, srv, ver, err = parseServiceRouterKey(testString)
Expand All @@ -129,4 +131,5 @@ func TestParseServiceRouterKey(t *testing.T) {
assert.Equal(t, "", grp)
assert.Equal(t, "", srv)
assert.Equal(t, "", ver)
assert.NoError(t, err)
}
4 changes: 2 additions & 2 deletions cluster/router/condition/listenable_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ type listenableRouter struct {
conditionRouters []*ConditionRouter
routerRule *RouterRule
url *common.URL
force bool
priority int64
//force bool
priority int64
}

// RouterRule Get RouterRule instance from listenableRouter
Expand Down
2 changes: 1 addition & 1 deletion cluster/router/tag/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type FileTagRouter struct {
router *tagRouter
routerRule *RouterRule
url *common.URL
force bool
//force bool
}

// NewFileTagRouter Create file tag router instance with content (from config file)
Expand Down
18 changes: 9 additions & 9 deletions cluster/router/tag/router_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ func (t *RouterRule) getTagNames() []string {
return result
}

func (t *RouterRule) hasTag(tag string) bool {
return len(t.TagNameToAddresses[tag]) > 0
}
//func (t *RouterRule) hasTag(tag string) bool {
// return len(t.TagNameToAddresses[tag]) > 0
//}

func (t *RouterRule) getAddressToTagNames() map[string][]string {
return t.AddressToTagNames
Expand All @@ -96,10 +96,10 @@ func (t *RouterRule) getTagNameToAddresses() map[string][]string {
return t.TagNameToAddresses
}

func (t *RouterRule) getTags() []Tag {
return t.Tags
}
//func (t *RouterRule) getTags() []Tag {
// return t.Tags
//}

func (t *RouterRule) setTags(tags []Tag) {
t.Tags = tags
}
//func (t *RouterRule) setTags(tags []Tag) {
// t.Tags = tags
//}
4 changes: 2 additions & 2 deletions cluster/router/tag/tag_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type addrMetadata struct {
// application name
application string
// is rule a runtime rule
ruleRuntime bool
//ruleRuntime bool
// is rule a force rule
ruleForce bool
// is rule a valid rule
Expand Down Expand Up @@ -227,7 +227,7 @@ func (c *tagRouter) Pool(invokers []protocol.Invoker) (router.AddrPool, router.A

// fetchRuleIfNecessary fetches, parses rule and register listener for the further change
func (c *tagRouter) fetchRuleIfNecessary(invokers []protocol.Invoker) {
if invokers == nil || len(invokers) == 0 {
if len(invokers) == 0 {
return
}

Expand Down
2 changes: 1 addition & 1 deletion cluster/router/tag/tag_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func TestRouteBeijingInvoker(t *testing.T) {

type DynamicTagRouter struct {
suite.Suite
rule *RouterRule
//rule *RouterRule

route *tagRouter
zkClient *zookeeper.ZookeeperClient
Expand Down
4 changes: 2 additions & 2 deletions common/config/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import (
// We just have config center configuration which can override configuration in consumer.yaml & provider.yaml.
// But for add these features in future ,I finish the environment struct following Environment class in java.
type Environment struct {
configCenterFirst bool
externalConfigs sync.Map
configCenterFirst bool
//externalConfigs sync.Map
externalConfigMap sync.Map
appExternalConfigMap sync.Map
dynamicConfiguration config_center.DynamicConfiguration
Expand Down
Loading

0 comments on commit 85a21e8

Please sign in to comment.