Skip to content

Commit

Permalink
format the change
Browse files Browse the repository at this point in the history
  • Loading branch information
william feng committed Jul 18, 2020
1 parent 08a0877 commit a41c36e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 49 deletions.
4 changes: 2 additions & 2 deletions cluster/router/condition/router_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
)

import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/cluster/router"
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/yaml"
)

Expand Down Expand Up @@ -58,7 +58,7 @@ func getRule(rawRule string) (*RouterRule, error) {
return r, err
}
r.RawRule = rawRule
if len(r.Conditions) != 0 && r.Key != "" && (r.Scope == constant.RouterApplicationScope || r.Scope == constant.RouterServiceScope){
if len(r.Conditions) != 0 && r.Key != "" && (r.Scope == constant.RouterApplicationScope || r.Scope == constant.RouterServiceScope) {
r.Valid = true
}

Expand Down
6 changes: 3 additions & 3 deletions cluster/router/condition/router_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ key: test-provider
conditions:
- >
method!=sayHello =>`
rule, e = getRule(testyml)
assert.Nil(t, e)
assert.False(t, rule.Valid)
rule, e = getRule(testyml)
assert.Nil(t, e)
assert.False(t, rule.Valid)
}

func TestIsMatchGlobPattern(t *testing.T) {
Expand Down
77 changes: 37 additions & 40 deletions cluster/router/condition/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,43 @@
* limitations under the License.
*/

package condition
package condition

import (
"testing"
)

import (
"github.com/stretchr/testify/assert"
)
import (
"testing"
)

import (
import (
"github.com/dubbogo/gost/container/set"
)

func TestParseRule(t *testing.T) {
testString := ``
matchPair, err := parseRule(testString)
assert.Nil(t, err)
assert.EqualValues(t, matchPair, make(map[string]MatchPair, 16))

testString = `method!=sayHello&application=sayGoodBye`
matchPair, err = parseRule(testString)
assert.Nil(t, err)
assert.EqualValues(t, matchPair["method"].Mismatches, gxset.NewSet("sayHello"))
assert.EqualValues(t, matchPair["application"].Matches, gxset.NewSet("sayGoodBye"))

testString = `noRule`
matchPair, err = parseRule(testString)
assert.Nil(t, err)
assert.EqualValues(t, matchPair["noRule"].Mismatches, gxset.NewSet())
assert.EqualValues(t, matchPair["noRule"].Matches, gxset.NewSet())

testString = `method!=sayHello,sayGoodBye`
matchPair, err = parseRule(testString)
assert.Nil(t, err)
assert.EqualValues(t, matchPair["method"].Mismatches, gxset.NewSet(`sayHello`, `sayGoodBye`))

testString = `method!=sayHello,sayGoodDay=sayGoodBye`
matchPair, err = parseRule(testString)
assert.Nil(t, err)
assert.EqualValues(t, matchPair["method"].Mismatches, gxset.NewSet(`sayHello`, `sayGoodDay`))
assert.EqualValues(t, matchPair["method"].Matches, gxset.NewSet(`sayGoodBye`))
}
"github.com/stretchr/testify/assert"
)

func TestParseRule(t *testing.T) {
testString := ``
matchPair, err := parseRule(testString)
assert.Nil(t, err)
assert.EqualValues(t, matchPair, make(map[string]MatchPair, 16))

testString = `method!=sayHello&application=sayGoodBye`
matchPair, err = parseRule(testString)
assert.Nil(t, err)
assert.EqualValues(t, matchPair["method"].Mismatches, gxset.NewSet("sayHello"))
assert.EqualValues(t, matchPair["application"].Matches, gxset.NewSet("sayGoodBye"))

testString = `noRule`
matchPair, err = parseRule(testString)
assert.Nil(t, err)
assert.EqualValues(t, matchPair["noRule"].Mismatches, gxset.NewSet())
assert.EqualValues(t, matchPair["noRule"].Matches, gxset.NewSet())

testString = `method!=sayHello,sayGoodBye`
matchPair, err = parseRule(testString)
assert.Nil(t, err)
assert.EqualValues(t, matchPair["method"].Mismatches, gxset.NewSet(`sayHello`, `sayGoodBye`))

testString = `method!=sayHello,sayGoodDay=sayGoodBye`
matchPair, err = parseRule(testString)
assert.Nil(t, err)
assert.EqualValues(t, matchPair["method"].Mismatches, gxset.NewSet(`sayHello`, `sayGoodDay`))
assert.EqualValues(t, matchPair["method"].Matches, gxset.NewSet(`sayGoodBye`))
}
4 changes: 2 additions & 2 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ const (
// Priority Priority key in router module
RouterPriority = "priority"
// RouterScope Scope key in router module
RouterScope = "scope"
RouterScope = "scope"
// RouterApplicationScope Scope key in router module
RouterApplicationScope = "application"
// RouterServiceScope Scope key in router module
RouterServiceScope = "service"
RouterServiceScope = "service"
// RouterRuleKey defines the key of the router, service's/application's name
RouterRuleKey = "key"
// ForceUseTag is the tag in attachment
Expand Down
5 changes: 4 additions & 1 deletion config/router_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ var (
routerURLSet = gxset.NewSet()
)

// LocalRouterRules defines the local router config structure
type LocalRouterRules struct {
RouterRules []interface{} `yaml:"routerRules"`
}

// RouterInit Load config file to init router config
func RouterInit(confRouterFile string) error {
bytes, err := yaml.LoadYMLConfig(confRouterFile)
Expand All @@ -58,7 +60,7 @@ func RouterInit(confRouterFile string) error {
return err
}

func initRouterConfig (content []byte,factories map[string]router.FilePriorityRouterFactory) error {
func initRouterConfig(content []byte, factories map[string]router.FilePriorityRouterFactory) error {
logger.Warnf("get fileRouterFactories len{%+v})", len(factories))
for k, factory := range factories {
r, e := factory.NewFileRouter(content)
Expand All @@ -72,6 +74,7 @@ func initRouterConfig (content []byte,factories map[string]router.FilePriorityRo
return perrors.Errorf("no file router exists for parse %s , implement router.FIleRouterFactory please.", confRouterFile)
}

// GetRouterURLSet exposes the routerURLSet
func GetRouterURLSet() *gxset.HashSet {
return routerURLSet
}
4 changes: 3 additions & 1 deletion config/router_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
)

import (
"github.com/dubbogo/gost/container/set"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -65,8 +66,9 @@ func TestRouterInit(t *testing.T) {

assert.Equal(t, 1, routerURLSet.Size())

routerURLSet = gxset.NewSet()
errPro = RouterInit(testMultiRouterYML)
assert.NoError(t, errPro)

assert.Equal(t, 3, GetRouterURLSet().Size())
assert.Equal(t, 2, routerURLSet.Size())
}

0 comments on commit a41c36e

Please sign in to comment.