diff --git a/cluster/router/condition/router_rule.go b/cluster/router/condition/router_rule.go index f8c2c3ed0d8e4763e7c3d414be89f02c4d745023..576dea87f91b01cda330b99f128669fe6fd56f8f 100644 --- a/cluster/router/condition/router_rule.go +++ b/cluster/router/condition/router_rule.go @@ -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" ) @@ -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 } diff --git a/cluster/router/condition/router_rule_test.go b/cluster/router/condition/router_rule_test.go index 1376058ed3f7d9fba7a53a72c3d3b2f5f9de9d18..369b14f08a6a650b36fe63a2d890c04fe7b892a5 100644 --- a/cluster/router/condition/router_rule_test.go +++ b/cluster/router/condition/router_rule_test.go @@ -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) { diff --git a/cluster/router/condition/router_test.go b/cluster/router/condition/router_test.go index 151f6ccfca571c0873cc35c9297f93218f4a4f03..35b8656b5f820b6949da3d8c8e852e4b6db51d46 100644 --- a/cluster/router/condition/router_test.go +++ b/cluster/router/condition/router_test.go @@ -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`)) - } \ No newline at end of file + "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`)) +} diff --git a/common/constant/key.go b/common/constant/key.go index 48d7a6dd10e05ac615dc055bc3ec4fdbea2d6173..f22debd58c575c41f146b879fb576135e2bb35cc 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -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 diff --git a/config/router_config.go b/config/router_config.go index e9cd5dc749d3a1e4ec58b40c189331aec61a4bb6..ed42577ed3cce2e5a1ab0da290f0d5450553d8fb 100644 --- a/config/router_config.go +++ b/config/router_config.go @@ -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) @@ -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) @@ -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 } diff --git a/config/router_config_test.go b/config/router_config_test.go index e4b09ef57d20319cce6025722423a0d6d9786a22..13af7056d5280ef4cca3c0f9ede9397407df7478 100644 --- a/config/router_config_test.go +++ b/config/router_config_test.go @@ -23,6 +23,7 @@ import ( ) import ( + "github.com/dubbogo/gost/container/set" "github.com/stretchr/testify/assert" ) @@ -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()) }