Skip to content
Snippets Groups Projects
Commit b824d500 authored by 邹毅贤's avatar 邹毅贤
Browse files

add test case

parent 235a2810
No related branches found
No related tags found
No related merge requests found
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
:: limitations under the License. :: limitations under the License.
set zkJar=zookeeper-3.4.9-fatjar.jar set zkJar=zookeeper-3.4.9-fatjar.jar
md remoting\zookeeper\zookeeper-4unittest\contrib\fatjar config_center\zookeeper\zookeeper-4unittest\contrib\fatjar registry\zookeeper\zookeeper-4unittest\contrib\fatjar md remoting\zookeeper\zookeeper-4unittest\contrib\fatjar config_center\zookeeper\zookeeper-4unittest\contrib\fatjar registry\zookeeper\zookeeper-4unittest\contrib\fatjar cluster\router\chain\zookeeper-4unittest\contrib\fatjar
curl -L https://github.com/dubbogo/resources/raw/master/zookeeper-4unitest/contrib/fatjar/%zkJar% -o remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/%zkJar% curl -L https://github.com/dubbogo/resources/raw/master/zookeeper-4unitest/contrib/fatjar/%zkJar% -o remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/%zkJar%
xcopy /f "remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/%zkJar%" "config_center/zookeeper/zookeeper-4unittest/contrib/fatjar/" xcopy /f "remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/%zkJar%" "config_center/zookeeper/zookeeper-4unittest/contrib/fatjar/"
xcopy /f "remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/%zkJar%" "registry/zookeeper/zookeeper-4unittest/contrib/fatjar/" xcopy /f "remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/%zkJar%" "registry/zookeeper/zookeeper-4unittest/contrib/fatjar/"
\ No newline at end of file xcopy /f "remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/%zkJar%" "cluster/router/chain/zookeeper-4unittest/contrib/fatjar/"
\ No newline at end of file
before_ut.sh 100644 → 100755
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
# limitations under the License. # limitations under the License.
mkdir -p remoting/zookeeper/zookeeper-4unittest/contrib/fatjar config_center/zookeeper/zookeeper-4unittest/contrib/fatjar registry/zookeeper/zookeeper-4unittest/contrib/fatjar mkdir -p remoting/zookeeper/zookeeper-4unittest/contrib/fatjar config_center/zookeeper/zookeeper-4unittest/contrib/fatjar registry/zookeeper/zookeeper-4unittest/contrib/fatjar cluster/router/chain/zookeeper-4unittest/contrib/fatjar
wget -P "remoting/zookeeper/zookeeper-4unittest/contrib/fatjar" https://github.com/dubbogo/resources/raw/master/zookeeper-4unitest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar wget -P "remoting/zookeeper/zookeeper-4unittest/contrib/fatjar" https://github.com/dubbogo/resources/raw/master/zookeeper-4unitest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar
cp remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar config_center/zookeeper/zookeeper-4unittest/contrib/fatjar/ cp remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar config_center/zookeeper/zookeeper-4unittest/contrib/fatjar/
cp remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar registry/zookeeper/zookeeper-4unittest/contrib/fatjar/ cp remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar registry/zookeeper/zookeeper-4unittest/contrib/fatjar/
\ No newline at end of file cp remoting/zookeeper/zookeeper-4unittest/contrib/fatjar/zookeeper-3.4.9-fatjar.jar cluster/router/chain/zookeeper-4unittest/contrib/fatjar
\ No newline at end of file
...@@ -52,16 +52,16 @@ func (c Chain) AddRouters(routers []router.Router) { ...@@ -52,16 +52,16 @@ func (c Chain) AddRouters(routers []router.Router) {
c.routers = newRouters c.routers = newRouters
} }
func NewRouterChain(url common.URL) *Chain { func NewRouterChain(url *common.URL) *Chain {
routerFactories := extension.GetRouters() routerFactories := extension.GetRouters()
if len(routerFactories) == 0 { if len(routerFactories) == 0 {
return nil return nil
} }
routers := make([]router.Router, 0) routers := make([]router.Router, 0)
for _, routerFactory := range routerFactories { for _, routerFactory := range routerFactories {
r, err := routerFactory().Router(&url) r, err := routerFactory().Router(url)
if err != nil { if r == nil || err != nil {
logger.Errorf("router chain build router fail! error:%v", err) logger.Errorf("router chain build router fail! error:%s", err.Error())
continue continue
} }
routers = append(routers, r) routers = append(routers, r)
......
...@@ -16,3 +16,42 @@ ...@@ -16,3 +16,42 @@
*/ */
package chain package chain
import (
"context"
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/extension"
_ "github.com/apache/dubbo-go/config_center/zookeeper"
"github.com/apache/dubbo-go/remoting/zookeeper"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
import (
_ "github.com/apache/dubbo-go/cluster/router/condition"
)
func TestNewRouterChain(t *testing.T) {
ts, z, _, err := zookeeper.NewMockZookeeperClient("test", 15*time.Second)
assert.NoError(t, err)
defer ts.Stop()
defer z.Close()
t.Log(z.ZkAddrs)
zkUrl, _ := common.NewURL(context.TODO(), "zookeeper://127.0.0.1:2181")
configuration, err := extension.GetConfigCenterFactory("zookeeper").GetDynamicConfiguration(&zkUrl)
assert.Nil(t, err)
assert.NotNil(t, configuration)
chain := NewRouterChain(getRouteUrl("test"))
t.Log(chain.routers)
}
func getRouteUrl(applicationKey string) *common.URL {
url, _ := common.NewURL(context.TODO(), "condition://0.0.0.0/com.foo.BarService")
url.AddParam("application", applicationKey)
url.AddParam("force", "true")
return &url
}
...@@ -31,8 +31,7 @@ type AppRouter struct { ...@@ -31,8 +31,7 @@ type AppRouter struct {
} }
func NewAppRouter(url *common.URL) (*AppRouter, error) { func NewAppRouter(url *common.URL) (*AppRouter, error) {
appRouter := &AppRouter{} appRouter, err := newListenableRouter(url, url.GetParam(constant.APPLICATION_KEY, ""))
err := appRouter.newListenableRouter(url, url.GetParam(constant.APPLICATION_KEY, ""))
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -49,28 +49,34 @@ type listenableRouter struct { ...@@ -49,28 +49,34 @@ type listenableRouter struct {
priority int64 priority int64
} }
func (l *listenableRouter) newListenableRouter(url *common.URL, ruleKey string) error { func newListenableRouter(url *common.URL, ruleKey string) (*AppRouter, error) {
l.url = url
l.priority = DEFAULT_PRIORITY
if ruleKey == "" { if ruleKey == "" {
return nil return nil, perrors.Errorf("newListenableRouter ruleKey is nil, can't create Listenable router")
} }
l := &AppRouter{}
l.url = url
l.priority = DEFAULT_PRIORITY
routerKey := ruleKey + RULE_SUFFIX routerKey := ruleKey + RULE_SUFFIX
//add listener //add listener
dynamicConfiguration := config.GetEnvInstance().GetDynamicConfiguration() dynamicConfiguration := config.GetEnvInstance().GetDynamicConfiguration()
if dynamicConfiguration == nil {
return nil, perrors.Errorf("get dynamicConfiguration fail, dynamicConfiguration is nil, init config center plugin please")
}
dynamicConfiguration.AddListener(routerKey, l) dynamicConfiguration.AddListener(routerKey, l)
//get rule //get rule
rule, err := dynamicConfiguration.GetRule(routerKey, config_center.WithGroup(config_center.DEFAULT_GROUP)) rule, err := dynamicConfiguration.GetRule(routerKey, config_center.WithGroup(config_center.DEFAULT_GROUP))
if len(rule) == 0 || err != nil { if len(rule) == 0 || err != nil {
return perrors.Errorf("get rule fail, config rule{%s}, error{%v}", rule, err) return nil, perrors.Errorf("get rule fail, config rule{%s}, error{%v}", rule, err)
} }
l.Process(&config_center.ConfigChangeEvent{ l.Process(&config_center.ConfigChangeEvent{
Key: routerKey, Key: routerKey,
Value: rule, Value: rule,
ConfigType: remoting.EventTypeUpdate}) ConfigType: remoting.EventTypeUpdate})
return nil return l, nil
} }
func (l *listenableRouter) Process(event *config_center.ConfigChangeEvent) { func (l *listenableRouter) Process(event *config_center.ConfigChangeEvent) {
......
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