This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch 1.5
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/1.5 by this push:
new 76b78e5 remove zk test (#1363)
76b78e5 is described below
commit 76b78e5efb1275ebbc763923e9336cabbeacb0d0
Author: YuDong Tang <[email protected]>
AuthorDate: Sat Aug 7 12:40:49 2021 +0800
remove zk test (#1363)
---
cluster/router/chain/chain_test.go | 298 ---------------------------
cluster/router/condition/app_router_test.go | 220 --------------------
cluster/router/tag/tag_router_test.go | 76 -------
config_center/zookeeper/impl_test.go | 233 ---------------------
config_center/zookeeper/listener_test.go | 101 ---------
metadata/report/zookeeper/report_test.go | 169 ---------------
registry/zookeeper/registry_test.go | 185 -----------------
registry/zookeeper/service_discovery_test.go | 209 -------------------
remoting/zookeeper/facade_test.go | 125 -----------
remoting/zookeeper/listener_test.go | 106 ----------
10 files changed, 1722 deletions(-)
diff --git a/cluster/router/chain/chain_test.go
b/cluster/router/chain/chain_test.go
deleted file mode 100644
index d38b3be..0000000
--- a/cluster/router/chain/chain_test.go
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package chain
-
-import (
- "encoding/base64"
- "fmt"
- "testing"
- "time"
-)
-
-import (
- zk "github.com/dubbogo/go-zookeeper/zk"
- gxzookeeper "github.com/dubbogo/gost/database/kv/zk"
- "github.com/stretchr/testify/assert"
-)
-
-import (
- "github.com/apache/dubbo-go/cluster/router"
- "github.com/apache/dubbo-go/cluster/router/condition"
- "github.com/apache/dubbo-go/common"
- "github.com/apache/dubbo-go/common/config"
- "github.com/apache/dubbo-go/common/constant"
- "github.com/apache/dubbo-go/common/extension"
- _ "github.com/apache/dubbo-go/config_center/zookeeper"
- "github.com/apache/dubbo-go/protocol"
- "github.com/apache/dubbo-go/protocol/invocation"
-)
-
-const (
- localIP = "127.0.0.1"
- test1234IP = "1.2.3.4"
- test1111IP = "1.1.1.1"
- test0000IP = "0.0.0.0"
- port20000 = 20000
-
- path = "/dubbo/config/dubbo/test-condition.condition-router"
- zkFormat = "zookeeper://%s:%d"
- consumerFormat = "consumer://%s/com.foo.BarService"
- dubboForamt = "dubbo://%s:%d/com.foo.BarService"
- anyUrlFormat = "condition://%s/com.foo.BarService"
- zkName = "zookeeper"
- applicationKey = "test-condition"
- applicationField = "application"
- forceField = "force"
- forceValue = "true"
-)
-
-var zkCluster *zk.TestCluster
-
-func TestNewRouterChain(t *testing.T) {
- ts, z, _, err := gxzookeeper.NewMockZookeeperClient("test",
15*time.Second)
- assert.NoError(t, err)
- zkCluster = ts
- err = z.Create(path)
- assert.NoError(t, err)
- testyml := `scope: application
-key: mock-app
-enabled: true
-force: true
-runtime: false
-conditions:
- - => host != 172.22.3.91
-`
-
- _, err = z.Conn.Set(path, []byte(testyml), 0)
- assert.NoError(t, err)
- defer func() {
- z.Delete(path)
- z.Close()
- }()
-
- zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, localIP,
ts.Servers[0].Port))
- configuration, err :=
extension.GetConfigCenterFactory(zkName).GetDynamicConfiguration(zkUrl)
- config.GetEnvInstance().SetDynamicConfiguration(configuration)
-
- assert.Nil(t, err)
- assert.NotNil(t, configuration)
-
- chain, err := NewRouterChain(getRouteUrl(applicationKey))
- assert.Nil(t, err)
- assert.Equal(t, 1, len(chain.routers))
- appRouter := chain.routers[0].(*condition.AppRouter)
-
- assert.NotNil(t, appRouter)
- assert.NotNil(t, appRouter.RouterRule())
- rule := appRouter.RouterRule()
- assert.Equal(t, "application", rule.Scope)
- assert.True(t, rule.Force)
- assert.True(t, rule.Enabled)
- assert.True(t, rule.Valid)
-
- assert.Equal(t, testyml, rule.RawRule)
- assert.Equal(t, false, rule.Runtime)
- assert.Equal(t, false, rule.Dynamic)
- assert.Equal(t, "mock-app", rule.Key)
-}
-
-func TestNewRouterChainURLNil(t *testing.T) {
- chain, err := NewRouterChain(nil)
- assert.NoError(t, err)
- assert.NotNil(t, chain)
-}
-
-func TestRouterChainAddRouters(t *testing.T) {
- _, z, _, err := gxzookeeper.NewMockZookeeperClient("test",
15*time.Second, gxzookeeper.WithTestCluster(zkCluster))
- assert.NoError(t, err)
- err = z.Create(path)
- assert.NoError(t, err)
-
- testyml := `scope: application
-key: mock-app
-enabled: true
-force: true
-runtime: false
-conditions:
- - => host != 172.22.3.91
-`
-
- _, err = z.Conn.Set(path, []byte(testyml), 0)
- assert.NoError(t, err)
- defer func() {
- z.Delete(path)
- z.Close()
- }()
-
- zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, localIP,
zkCluster.Servers[0].Port))
- configuration, err :=
extension.GetConfigCenterFactory(zkName).GetDynamicConfiguration(zkUrl)
- assert.NoError(t, err)
- config.GetEnvInstance().SetDynamicConfiguration(configuration)
-
- chain, err := NewRouterChain(getConditionRouteUrl(applicationKey))
- assert.Nil(t, err)
- assert.Equal(t, 2, len(chain.routers))
-
- url := getConditionRouteUrl(applicationKey)
- assert.NotNil(t, url)
- factory := extension.GetRouterFactory(url.Protocol)
- notify := make(chan struct{})
- go func() {
- for range notify {
- }
- }()
- r, err := factory.NewPriorityRouter(url, notify)
- assert.Nil(t, err)
- assert.NotNil(t, r)
-
- routers := make([]router.PriorityRouter, 0)
- routers = append(routers, r)
- chain.AddRouters(routers)
- assert.Equal(t, 3, len(chain.routers))
-}
-
-func TestRouterChainRoute(t *testing.T) {
- ts, _, _, err := gxzookeeper.NewMockZookeeperClient("test",
15*time.Second, gxzookeeper.WithTestCluster(zkCluster))
- assert.Nil(t, err)
- zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, localIP,
ts.Servers[0].Port))
- configuration, err :=
extension.GetConfigCenterFactory(zkName).GetDynamicConfiguration(zkUrl)
- assert.NoError(t, err)
- config.GetEnvInstance().SetDynamicConfiguration(configuration)
-
- chain, err := NewRouterChain(getConditionRouteUrl(applicationKey))
- assert.Nil(t, err)
- assert.Equal(t, 1, len(chain.routers))
-
- url := getConditionRouteUrl(applicationKey)
- assert.NotNil(t, url)
-
- var invokers []protocol.Invoker
- dubboURL, _ := common.NewURL(fmt.Sprintf(dubboForamt, test1234IP,
port20000))
- invokers = append(invokers, protocol.NewBaseInvoker(dubboURL))
- chain.SetInvokers(invokers)
- chain.buildCache()
-
- targetURL, _ := common.NewURL(fmt.Sprintf(consumerFormat, test1111IP))
- inv := &invocation.RPCInvocation{}
- finalInvokers := chain.Route(targetURL, inv)
-
- assert.Equal(t, 1, len(finalInvokers))
-}
-
-func TestRouterChainRouteAppRouter(t *testing.T) {
- ts, z, _, err := gxzookeeper.NewMockZookeeperClient("test",
15*time.Second, gxzookeeper.WithTestCluster(zkCluster))
- assert.NoError(t, err)
- err = z.Create(path)
- assert.NoError(t, err)
-
- testyml := `scope: application
-key: mock-app
-enabled: true
-force: true
-runtime: false
-conditions:
- - => host = 1.1.1.1 => host != 1.2.3.4
-`
-
- _, err = z.Conn.Set(path, []byte(testyml), 0)
- assert.NoError(t, err)
- defer func() {
- z.Delete(path)
- z.Close()
- }()
-
- zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, localIP,
ts.Servers[0].Port))
- configuration, err :=
extension.GetConfigCenterFactory(zkName).GetDynamicConfiguration(zkUrl)
- assert.NoError(t, err)
- config.GetEnvInstance().SetDynamicConfiguration(configuration)
-
- chain, err := NewRouterChain(getConditionRouteUrl(applicationKey))
- assert.Nil(t, err)
- assert.Equal(t, 2, len(chain.routers))
-
- var invokers []protocol.Invoker
- dubboURL, _ := common.NewURL(fmt.Sprintf(dubboForamt, test1234IP,
port20000))
- invokers = append(invokers, protocol.NewBaseInvoker(dubboURL))
- chain.SetInvokers(invokers)
- chain.buildCache()
-
- targetURL, _ := common.NewURL(fmt.Sprintf(consumerFormat, test1111IP))
- inv := &invocation.RPCInvocation{}
- finalInvokers := chain.Route(targetURL, inv)
-
- assert.Equal(t, 0, len(finalInvokers))
-}
-
-func TestRouterChainRouteNoRoute(t *testing.T) {
- ts, z, _, err := gxzookeeper.NewMockZookeeperClient("test",
15*time.Second, gxzookeeper.WithTestCluster(zkCluster))
- 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(zkName).GetDynamicConfiguration(zkUrl)
- config.GetEnvInstance().SetDynamicConfiguration(configuration)
- assert.Nil(t, err)
-
- chain, err := NewRouterChain(getConditionNoRouteUrl(applicationKey))
- assert.Nil(t, err)
- assert.Equal(t, 1, len(chain.routers))
-
- url := getConditionRouteUrl(applicationKey)
- assert.NotNil(t, url)
-
- var invokers []protocol.Invoker
- dubboURL, _ := common.NewURL(fmt.Sprintf(dubboForamt, test1234IP,
port20000))
- invokers = append(invokers, protocol.NewBaseInvoker(dubboURL))
- chain.SetInvokers(invokers)
- chain.buildCache()
-
- targetURL, _ := common.NewURL(fmt.Sprintf(consumerFormat, test1111IP))
- inv := &invocation.RPCInvocation{}
- finalInvokers := chain.Route(targetURL, inv)
-
- assert.Equal(t, 0, len(finalInvokers))
-}
-
-func getConditionNoRouteUrl(applicationKey string) *common.URL {
- url, _ := common.NewURL(fmt.Sprintf(anyUrlFormat, test0000IP))
- url.AddParam(applicationField, applicationKey)
- url.AddParam(forceField, forceValue)
- rule := base64.URLEncoding.EncodeToString([]byte("host = 1.1.1.1 =>
host != 1.2.3.4"))
- url.AddParam(constant.RULE_KEY, rule)
- return url
-}
-
-func getConditionRouteUrl(applicationKey string) *common.URL {
- url, _ := common.NewURL(fmt.Sprintf(anyUrlFormat, test0000IP))
- url.AddParam(applicationField, applicationKey)
- url.AddParam(forceField, forceValue)
- rule := base64.URLEncoding.EncodeToString([]byte("host = 1.1.1.1 =>
host = 1.2.3.4"))
- url.AddParam(constant.RULE_KEY, rule)
- return url
-}
-
-func getRouteUrl(applicationKey string) *common.URL {
- url, _ := common.NewURL(fmt.Sprintf(anyUrlFormat, test0000IP))
- url.AddParam(applicationField, applicationKey)
- url.AddParam(forceField, forceValue)
- return url
-}
diff --git a/cluster/router/condition/app_router_test.go
b/cluster/router/condition/app_router_test.go
deleted file mode 100644
index 86fdede..0000000
--- a/cluster/router/condition/app_router_test.go
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package condition
-
-import (
- "fmt"
- "testing"
- "time"
-)
-
-import (
- gxzookeeper "github.com/dubbogo/gost/database/kv/zk"
- "github.com/stretchr/testify/assert"
-)
-
-import (
- "github.com/apache/dubbo-go/common"
- "github.com/apache/dubbo-go/common/config"
- "github.com/apache/dubbo-go/common/constant"
- "github.com/apache/dubbo-go/common/extension"
- "github.com/apache/dubbo-go/config_center"
- _ "github.com/apache/dubbo-go/config_center/zookeeper"
- "github.com/apache/dubbo-go/remoting"
-)
-
-const (
- routerPath = "/dubbo/config/dubbo/test-condition.condition-router"
- routerLocalIP = "127.0.0.1"
- routerZk = "zookeeper"
- routerKey = "test-condition"
-)
-
-var (
- zkFormat = "zookeeper://%s:%d"
- conditionFormat = "condition://%s/com.foo.BarService"
-)
-
-func TestNewAppRouter(t *testing.T) {
-
- testYML := `scope: application
-key: mock-app
-enabled: true
-force: true
-runtime: false
-conditions:
- - => host != 172.22.3.91
-`
- ts, z, _, err := gxzookeeper.NewMockZookeeperClient("test",
15*time.Second)
- assert.NoError(t, err)
- err = z.Create(routerPath)
- assert.NoError(t, err)
-
- _, err = z.Conn.Set(routerPath, []byte(testYML), 0)
- assert.NoError(t, err)
- defer func() {
- assert.NoError(t, err)
- z.Close()
- }()
-
- zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, routerLocalIP,
ts.Servers[0].Port))
- configuration, err :=
extension.GetConfigCenterFactory(routerZk).GetDynamicConfiguration(zkUrl)
- config.GetEnvInstance().SetDynamicConfiguration(configuration)
-
- assert.Nil(t, err)
- assert.NotNil(t, configuration)
-
- appRouteURL := getAppRouteURL(routerKey)
- notify := make(chan struct{})
- go func() {
- for range notify {
- }
- }()
- appRouter, err := NewAppRouter(appRouteURL, notify)
- assert.Nil(t, err)
- assert.NotNil(t, appRouter)
-
- assert.NotNil(t, appRouter)
- assert.NotNil(t, appRouter.RouterRule())
- rule := appRouter.RouterRule()
- assert.Equal(t, "application", rule.Scope)
- assert.True(t, rule.Force)
- assert.True(t, rule.Enabled)
- assert.True(t, rule.Valid)
-
- assert.Equal(t, testYML, rule.RawRule)
- assert.Equal(t, false, rule.Runtime)
- assert.Equal(t, false, rule.Dynamic)
- assert.Equal(t, "mock-app", rule.Key)
- assert.Equal(t, 0, rule.Priority)
-}
-
-func TestGenerateConditions(t *testing.T) {
-
- testYML := `scope: application
-key: mock-app
-enabled: true
-force: true
-runtime: false
-conditions:
- - => host != 172.22.3.91
- - host = 192.168.199.208 => host = 192.168.199.208
-`
- ts, z, _, err := gxzookeeper.NewMockZookeeperClient("test",
15*time.Second)
- assert.NoError(t, err)
- err = z.Create(routerPath)
- assert.NoError(t, err)
-
- _, err = z.Conn.Set(routerPath, []byte(testYML), 0)
- assert.NoError(t, err)
- defer func() {
- assert.NoError(t, err)
- z.Close()
- }()
-
- zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, routerLocalIP,
ts.Servers[0].Port))
- configuration, err :=
extension.GetConfigCenterFactory(routerZk).GetDynamicConfiguration(zkUrl)
- config.GetEnvInstance().SetDynamicConfiguration(configuration)
-
- assert.Nil(t, err)
- assert.NotNil(t, configuration)
-
- appRouteURL := getAppRouteURL(routerKey)
- notify := make(chan struct{})
- go func() {
- for range notify {
- }
- }()
- appRouter, err := NewAppRouter(appRouteURL, notify)
- assert.Nil(t, err)
- assert.NotNil(t, appRouter)
-
- rule, err := getRule(testYML)
- assert.Nil(t, err)
- appRouter.generateConditions(rule)
-
- assert.Equal(t, 2, len(appRouter.conditionRouters))
-}
-
-func TestProcess(t *testing.T) {
-
- testYML := `scope: application
-key: mock-app
-enabled: true
-force: true
-runtime: false
-conditions:
- - => host != 172.22.3.91
-`
- ts, z, _, err := gxzookeeper.NewMockZookeeperClient("test",
15*time.Second)
- assert.NoError(t, err)
- err = z.Create(routerPath)
- assert.NoError(t, err)
-
- _, err = z.Conn.Set(routerPath, []byte(testYML), 0)
- assert.NoError(t, err)
- 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)
- config.GetEnvInstance().SetDynamicConfiguration(configuration)
-
- assert.Nil(t, err)
- assert.NotNil(t, configuration)
-
- appRouteURL := getAppRouteURL(routerKey)
- notify := make(chan struct{})
- go func() {
- for range notify {
- }
- }()
- appRouter, err := NewAppRouter(appRouteURL, notify)
- assert.Nil(t, err)
- assert.NotNil(t, appRouter)
-
- assert.Equal(t, 1, len(appRouter.conditionRouters))
-
- testNewYML := `scope: application
-key: mock-app
-enabled: true
-force: true
-runtime: false
-conditions:
- - => host != 172.22.3.91
- - host = 192.168.199.208 => host = 192.168.199.208
-`
-
- appRouter.Process(&config_center.ConfigChangeEvent{ConfigType:
remoting.EventTypeDel})
-
- assert.Equal(t, 0, len(appRouter.conditionRouters))
-
- appRouter.Process(&config_center.ConfigChangeEvent{Value: testNewYML,
ConfigType: remoting.EventTypeAdd})
-
- assert.Equal(t, 2, len(appRouter.conditionRouters))
-}
-
-func getAppRouteURL(applicationKey string) *common.URL {
- url, _ := common.NewURL(fmt.Sprintf(conditionFormat,
constant.ANYHOST_VALUE))
- url.AddParam("application", applicationKey)
- url.AddParam("force", "true")
- return url
-}
diff --git a/cluster/router/tag/tag_router_test.go
b/cluster/router/tag/tag_router_test.go
index 1606240..097a8cc 100644
--- a/cluster/router/tag/tag_router_test.go
+++ b/cluster/router/tag/tag_router_test.go
@@ -19,9 +19,7 @@ package tag
import (
"context"
- "fmt"
"testing"
- "time"
)
import (
@@ -37,8 +35,6 @@ import (
"github.com/apache/dubbo-go/cluster/router/chain"
"github.com/apache/dubbo-go/cluster/router/utils"
"github.com/apache/dubbo-go/common"
- "github.com/apache/dubbo-go/common/config"
- "github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/config_center"
_ "github.com/apache/dubbo-go/config_center/zookeeper"
"github.com/apache/dubbo-go/protocol"
@@ -54,12 +50,6 @@ const (
tagRouterTestUserConsumer =
"dubbo://127.0.0.1:20005/com.ikurento.user.UserConsumer?interface=com.ikurento.user.UserConsumer&group=&version=2.6.0&enabled=true&remote.application=test-tag"
tagRouterTestUserConsumerTag =
"dubbo://127.0.0.1:20000/com.ikurento.user.UserConsumer?interface=com.ikurento.user.UserConsumer&group=&version=2.6.0&enabled=true&dubbo.force.tag=true&remote.application=test-tag"
- tagRouterTestDynamicIpv4Provider1 =
"dubbo://127.0.0.1:20001/com.ikurento.user.UserConsumer?interface=com.ikurento.user.UserConsumer&group=&version=2.6.0&enabled=true&remote.application=test-tag"
- tagRouterTestDynamicIpv4Provider2 =
"dubbo://127.0.0.1:20002/com.ikurento.user.UserConsumer?interface=com.ikurento.user.UserConsumer&group=&version=2.6.0&enabled=true&remote.application=test-tag"
- tagRouterTestDynamicIpv4Provider3 =
"dubbo://127.0.0.1:20003/com.ikurento.user.UserConsumer?interface=com.ikurento.user.UserConsumer&group=&version=2.6.0&enabled=true&remote.application=test-tag"
- tagRouterTestDynamicIpv4Provider4 =
"dubbo://127.0.0.1:20004/com.ikurento.user.UserConsumer?interface=com.ikurento.user.UserConsumer&group=&version=2.6.0&enabled=true&remote.application=test-tag&dubbo.tag=tag4"
- tagRouterTestDynamicIpv4Provider5 =
"dubbo://127.0.0.1:20005/com.ikurento.user.UserConsumer?interface=com.ikurento.user.UserConsumer&group=&version=2.6.0&enabled=true&remote.application=test-tag&dubbo.tag=tag5"
-
tagRouterTestDubboTag = "dubbo.tag"
tagRouterTestDubboForceTag = "dubbo.force.tag"
tagRouterTestHangZhou = "hangzhou"
@@ -266,72 +256,6 @@ type DynamicTagRouter struct {
url *common.URL
}
-func TestDynamicTagRouter(t *testing.T) {
- dtg := &DynamicTagRouter{}
- u1, _ := common.NewURL(tagRouterTestDynamicIpv4Provider1)
- u2, _ := common.NewURL(tagRouterTestDynamicIpv4Provider2)
- u3, _ := common.NewURL(tagRouterTestDynamicIpv4Provider3)
- u4, _ := common.NewURL(tagRouterTestDynamicIpv4Provider4)
- u5, _ := common.NewURL(tagRouterTestDynamicIpv4Provider5)
- inv1 := NewMockInvoker(u1)
- inv2 := NewMockInvoker(u2)
- inv3 := NewMockInvoker(u3)
- inv4 := NewMockInvoker(u4)
- inv5 := NewMockInvoker(u5)
- dtg.invokers = append(dtg.invokers, inv1, inv2, inv3, inv4, inv5)
- suite.Run(t, dtg)
-}
-
-func (suite *DynamicTagRouter) SetupTest() {
- var err error
- testYML := `enabled: true
-scope: application
-force: true
-runtime: false
-valid: true
-priority: 1
-key: demo-provider
-tags:
- - name: tag1
- addresses: ["127.0.0.1:20001"]
- - name: tag2
- addresses: ["127.0.0.1:20002"]
- - name: tag3
- addresses: ["127.0.0.1:20003", "127.0.0.1:20004"]
-`
- ts, z, _, err := gxzookeeper.NewMockZookeeperClient("test",
15*time.Second)
- suite.NoError(err)
- err = z.Create(routerPath)
- suite.NoError(err)
-
- suite.zkClient = z
- suite.testCluster = ts
-
- _, err = z.Conn.Set(routerPath, []byte(testYML), 0)
- suite.NoError(err)
-
- zkUrl, _ := common.NewURL(fmt.Sprintf(zkFormat, routerLocalIP,
suite.testCluster.Servers[0].Port))
- configuration, err :=
extension.GetConfigCenterFactory(routerZk).GetDynamicConfiguration(zkUrl)
- config.GetEnvInstance().SetDynamicConfiguration(configuration)
-
- suite.Nil(err)
- suite.NotNil(configuration)
-
- url, e1 := common.NewURL(tagRouterTestUserConsumerTag)
- suite.Nil(e1)
-
- notify := make(chan struct{})
- go func() {
- for range notify {
- }
- }()
- tagRouter, err := NewTagRouter(url, notify)
- suite.Nil(err)
- suite.NotNil(tagRouter)
- suite.route = tagRouter
- suite.url = url
-}
-
func (suite *DynamicTagRouter) TearDownTest() {
suite.zkClient.Close()
}
diff --git a/config_center/zookeeper/impl_test.go
b/config_center/zookeeper/impl_test.go
deleted file mode 100644
index 54007e8..0000000
--- a/config_center/zookeeper/impl_test.go
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package zookeeper
-
-import (
- "fmt"
- "path"
- "strconv"
- "sync"
- "testing"
-)
-
-import (
- "github.com/dubbogo/go-zookeeper/zk"
- gxset "github.com/dubbogo/gost/container/set"
- "github.com/stretchr/testify/assert"
-)
-
-import (
- "github.com/apache/dubbo-go/common"
- "github.com/apache/dubbo-go/common/constant"
- "github.com/apache/dubbo-go/config_center"
- "github.com/apache/dubbo-go/config_center/parser"
-)
-
-const (
- dubboPropertyFileName = "dubbo.properties"
-)
-
-func initZkData(group string, t *testing.T) (*zk.TestCluster,
*zookeeperDynamicConfiguration) {
- ts, err := zk.StartTestCluster(1, nil, nil)
- assert.NoError(t, err)
- assert.NotNil(t, ts.Servers[0])
- urlString := "registry://127.0.0.1:" + strconv.Itoa(ts.Servers[0].Port)
- regurl, err := common.NewURL(urlString)
- assert.NoError(t, err)
- regurl.AddParam(constant.REGISTRY_TIMEOUT_KEY, "15s")
- zkFactory := &zookeeperDynamicConfigurationFactory{}
- reg, err := zkFactory.GetDynamicConfiguration(regurl)
- zreg, ok := reg.(*zookeeperDynamicConfiguration)
- assert.True(t, ok)
- assert.NoError(t, err)
- assert.True(t, zreg.IsAvailable())
- assert.Equal(t, zreg.GetURL(), regurl)
- assert.True(t, zreg.RestartCallBack())
- zreg.SetParser(&parser.DefaultConfigurationParser{})
-
- data := `
- dubbo.consumer.request_timeout=5s
- dubbo.consumer.connect_timeout=5s
- dubbo.application.organization=ikurento.com
- dubbo.application.name=BDTService
- dubbo.application.module=dubbogo user-info server
- dubbo.application.version=0.0.1
- dubbo.application.owner=ZX
- dubbo.application.environment=dev
- dubbo.registries.hangzhouzk.protocol=zookeeper
- dubbo.registries.hangzhouzk.timeout=3s
- dubbo.registries.hangzhouzk.address=127.0.0.1:2181
- dubbo.registries.shanghaizk.protocol=zookeeper
- dubbo.registries.shanghaizk.timeout=3s
- dubbo.registries.shanghaizk.address=127.0.0.1:2182
- dubbo.service.com.ikurento.user.UserProvider.protocol=dubbo
-
dubbo.service.com.ikurento.user.UserProvider.interface=com.ikurento.user.UserProvider
- dubbo.service.com.ikurento.user.UserProvider.loadbalance=random
- dubbo.service.com.ikurento.user.UserProvider.warmup=100
- dubbo.service.com.ikurento.user.UserProvider.cluster=failover
-`
- if group != "" {
- err = zreg.client.Create(path.Join(zreg.rootPath, group,
dubboPropertyFileName))
- assert.NoError(t, err)
-
- _, err = zreg.client.Conn.Set(path.Join(zreg.rootPath, group,
dubboPropertyFileName), []byte(data), 0)
- assert.NoError(t, err)
- } else {
- err = zreg.client.Create(path.Join(zreg.rootPath,
dubboPropertyFileName))
- assert.NoError(t, err)
-
- _, err = zreg.client.Conn.Set(path.Join(zreg.rootPath,
dubboPropertyFileName), []byte(data), 0)
- assert.NoError(t, err)
- }
-
- return ts, zreg
-}
-
-func TestGetConfig(t *testing.T) {
- ts, reg := initZkData("dubbo", t)
- defer func() {
- reg.client.Close()
- err := ts.Stop()
- assert.NoError(t, err)
- }()
- configs, err := reg.GetProperties(dubboPropertyFileName,
config_center.WithGroup("dubbo"))
- assert.NoError(t, err)
- m, err := reg.Parser().Parse(configs)
- assert.NoError(t, err)
- assert.Equal(t, "5s", m["dubbo.consumer.request_timeout"])
- configs, err = reg.GetProperties(dubboPropertyFileName)
- assert.Error(t, err)
- assert.Equal(t, "", configs)
- configs, err = reg.GetInternalProperty(dubboPropertyFileName)
- assert.Error(t, err)
- assert.Equal(t, "", configs)
- configs, err = reg.GetRule(dubboPropertyFileName)
- assert.Error(t, err)
- assert.Equal(t, "", configs)
-}
-
-func TestAddListener(t *testing.T) {
- ts, reg := initZkData("", t)
- defer func() {
- reg.client.Close()
- err := ts.Stop()
- assert.NoError(t, err)
- }()
- listener := &mockDataListener{}
- reg.AddListener(dubboPropertyFileName, listener)
-
- listener.wg.Add(1)
- data := `
- dubbo.consumer.request_timeout=3s
- dubbo.consumer.connect_timeout=5s
- dubbo.application.organization=ikurento.com
- dubbo.application.name=BDTService
- dubbo.application.module=dubbogo user-info server
- dubbo.application.version=0.0.1
- dubbo.application.owner=ZX
- dubbo.application.environment=dev
- dubbo.registries.hangzhouzk.protocol=zookeeper
- dubbo.registries.hangzhouzk.timeout=3s
- dubbo.registries.hangzhouzk.address=127.0.0.1:2181
- dubbo.registries.shanghaizk.protocol=zookeeper
- dubbo.registries.shanghaizk.timeout=3s
- dubbo.registries.shanghaizk.address=127.0.0.1:2182
- dubbo.service.com.ikurento.user.UserProvider.protocol=dubbo
-
dubbo.service.com.ikurento.user.UserProvider.interface=com.ikurento.user.UserProvider
- dubbo.service.com.ikurento.user.UserProvider.loadbalance=random
- dubbo.service.com.ikurento.user.UserProvider.warmup=100
- dubbo.service.com.ikurento.user.UserProvider.cluster=failover
-`
- _, err := reg.client.Conn.Set(path.Join(reg.rootPath,
dubboPropertyFileName), []byte(data), 1)
- assert.NoError(t, err)
- listener.wg.Wait()
- assert.Equal(t, dubboPropertyFileName, listener.event)
-}
-
-func TestRemoveListener(t *testing.T) {
- ts, reg := initZkData("", t)
- defer func() {
- reg.client.Close()
- err := ts.Stop()
- assert.NoError(t, err)
- }()
- listener := &mockDataListener{}
- reg.AddListener(dubboPropertyFileName, listener)
- listener.wg.Add(1)
- data := `
- dubbo.consumer.request_timeout=3s
- dubbo.consumer.connect_timeout=5s
- dubbo.application.organization=ikurento.com
- dubbo.application.name=BDTService
- dubbo.application.module=dubbogo user-info server
- dubbo.application.version=0.0.1
- dubbo.application.owner=ZX
- dubbo.application.environment=dev
- dubbo.registries.hangzhouzk.protocol=zookeeper
- dubbo.registries.hangzhouzk.timeout=3s
- dubbo.registries.hangzhouzk.address=127.0.0.1:2181
- dubbo.registries.shanghaizk.protocol=zookeeper
- dubbo.registries.shanghaizk.timeout=3s
- dubbo.registries.shanghaizk.address=127.0.0.1:2182
- dubbo.service.com.ikurento.user.UserProvider.protocol=dubbo
-
dubbo.service.com.ikurento.user.UserProvider.interface=com.ikurento.user.UserProvider
- dubbo.service.com.ikurento.user.UserProvider.loadbalance=random
- dubbo.service.com.ikurento.user.UserProvider.warmup=100
- dubbo.service.com.ikurento.user.UserProvider.cluster=failover
-`
- reg.RemoveListener(dubboPropertyFileName, listener)
- listener.wg.Done()
- _, err := reg.client.Conn.Set(path.Join(reg.rootPath,
dubboPropertyFileName), []byte(data), 1)
- assert.NoError(t, err)
- listener.wg.Wait()
- assert.Equal(t, "", listener.event)
-}
-
-func TestZookeeperDynamicConfigurationPublishConfig(t *testing.T) {
- value := "Test Data"
- customGroup := "Custom Group"
- key := "myKey"
- ts, reg := initZkData(config_center.DEFAULT_GROUP, t)
- defer func() {
- reg.client.Close()
- err := ts.Stop()
- assert.NoError(t, err)
- }()
- err := reg.PublishConfig(key, customGroup, value)
- assert.Nil(t, err)
- result, err := reg.GetInternalProperty("myKey",
config_center.WithGroup(customGroup))
- assert.Nil(t, err)
- assert.Equal(t, value, result)
-
- var keys *gxset.HashSet
- keys, err = reg.GetConfigKeysByGroup(customGroup)
- assert.Nil(t, err)
- assert.Equal(t, 1, keys.Size())
- assert.True(t, keys.Contains(key))
-
-}
-
-type mockDataListener struct {
- wg sync.WaitGroup
- event string
-}
-
-func (l *mockDataListener) Process(configType
*config_center.ConfigChangeEvent) {
- fmt.Println("process!!!!!")
- l.wg.Done()
- l.event = configType.Key
-}
diff --git a/config_center/zookeeper/listener_test.go
b/config_center/zookeeper/listener_test.go
deleted file mode 100644
index 07c7179..0000000
--- a/config_center/zookeeper/listener_test.go
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package zookeeper
-
-import (
- "path"
- "strconv"
- "testing"
-)
-
-import (
- "github.com/dubbogo/go-zookeeper/zk"
- "github.com/stretchr/testify/assert"
-)
-
-import (
- "github.com/apache/dubbo-go/common"
- "github.com/apache/dubbo-go/common/constant"
- "github.com/apache/dubbo-go/config_center/parser"
-)
-
-func initZkDynamicConfiguration(t *testing.T) (*zk.TestCluster,
*zookeeperDynamicConfiguration) {
- ts, err := zk.StartTestCluster(1, nil, nil)
- assert.NoError(t, err)
- assert.NotNil(t, ts.Servers[0])
- urlString := "registry://127.0.0.1:" + strconv.Itoa(ts.Servers[0].Port)
- regurl, err := common.NewURL(urlString)
- assert.NoError(t, err)
- regurl.AddParam(constant.REGISTRY_TIMEOUT_KEY, "15s")
- zkFactory := &zookeeperDynamicConfigurationFactory{}
- reg, err := zkFactory.GetDynamicConfiguration(regurl)
- zreg, ok := reg.(*zookeeperDynamicConfiguration)
- assert.True(t, ok)
- assert.NoError(t, err)
- assert.True(t, zreg.IsAvailable())
- assert.Equal(t, zreg.GetURL(), regurl)
- assert.True(t, zreg.RestartCallBack())
- zreg.SetParser(&parser.DefaultConfigurationParser{})
-
- data := `
- dubbo.application.name=dubbogo
-`
- err = zreg.client.Create(path.Join(zreg.rootPath,
dubboPropertyFileName))
- assert.NoError(t, err)
- _, err = zreg.client.Conn.Set(path.Join(zreg.rootPath,
dubboPropertyFileName), []byte(data), 0)
- assert.NoError(t, err)
-
- return ts, zreg
-}
-
-func TestZookeeperDynamicConfigurationPathToKey(t *testing.T) {
- ts, reg := initZkDynamicConfiguration(t)
- defer func() {
- err := ts.Stop()
- assert.NoError(t, err)
- }()
- listener := &mockDataListener{}
- key := path.Join("dubbogoDemo" + constant.CONFIGURATORS_SUFFIX)
- reg.AddListener(key, listener)
- listener.wg.Add(1)
-
- data := `
-scope: application
-key: dubbogoDemo
-enabled: true
-configs:
- - addresses: [0.0.0.0:20880]
- side: provider
- parameters:
- weight: 60
- - addresses: [0.0.0.0:20881]
- side: provider
- parameters:
- weight: 40
-`
- zkPath := path.Join(reg.rootPath, "dubbo", key)
- exists, _, err := reg.client.Conn.Exists(zkPath)
- assert.NoError(t, err)
- if !exists {
- err = reg.client.Create(zkPath)
- assert.NoError(t, err)
- }
- _, err = reg.client.SetContent(zkPath, []byte(data), 0)
- assert.NoError(t, err)
- listener.wg.Wait()
- assert.Equal(t, key, listener.event)
-}
diff --git a/metadata/report/zookeeper/report_test.go
b/metadata/report/zookeeper/report_test.go
deleted file mode 100644
index 3f927b1..0000000
--- a/metadata/report/zookeeper/report_test.go
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package zookeeper
-
-import (
- "encoding/json"
- "net/url"
- "strconv"
- "testing"
-)
-
-import (
- "github.com/dubbogo/go-zookeeper/zk"
- "github.com/stretchr/testify/assert"
-)
-
-import (
- "github.com/apache/dubbo-go/common"
- "github.com/apache/dubbo-go/common/constant"
- "github.com/apache/dubbo-go/common/extension"
- "github.com/apache/dubbo-go/metadata/identifier"
- "github.com/apache/dubbo-go/metadata/report"
-)
-
-func newProviderRegistryUrl(host string, port int) *common.URL {
- return common.NewURLWithOptions(
- common.WithIp(host),
- common.WithPort(strconv.Itoa(port)),
- common.WithParams(url.Values{}),
- common.WithParamsValue(constant.ROLE_KEY,
strconv.Itoa(common.PROVIDER)),
- )
-}
-
-func newBaseMetadataIdentifier(side string) *identifier.BaseMetadataIdentifier
{
- return &identifier.BaseMetadataIdentifier{
- ServiceInterface: "org.apache.HelloWorld",
- Version: "1.0.0",
- Group: "group",
- Side: side,
- }
-}
-
-func newMetadataIdentifier(side string) *identifier.MetadataIdentifier {
- return &identifier.MetadataIdentifier{
- Application: "application",
- BaseMetadataIdentifier: *newBaseMetadataIdentifier(side),
- }
-}
-
-func newServiceMetadataIdentifier(side string)
*identifier.ServiceMetadataIdentifier {
- return &identifier.ServiceMetadataIdentifier{
- Revision: "1.0",
- Protocol: "dubbo",
- BaseMetadataIdentifier: *newBaseMetadataIdentifier(side),
- }
-}
-
-func newSubscribeMetadataIdentifier(side string)
*identifier.SubscriberMetadataIdentifier {
- return &identifier.SubscriberMetadataIdentifier{
- Revision: "1.0",
- MetadataIdentifier: *newMetadataIdentifier(side),
- }
-}
-
-type zookeeperMetadataReportTestSuite struct {
- t *testing.T
- m report.MetadataReport
-}
-
-func newZookeeperMetadataReportTestSuite(t *testing.T, m
report.MetadataReport) *zookeeperMetadataReportTestSuite {
- return &zookeeperMetadataReportTestSuite{t: t, m: m}
-}
-
-func (suite *zookeeperMetadataReportTestSuite) testStoreProviderMetadata() {
- providerMi := newMetadataIdentifier("provider")
- providerMeta := "provider"
- err := suite.m.StoreProviderMetadata(providerMi, providerMeta)
- assert.NoError(suite.t, err)
-}
-
-func (suite *zookeeperMetadataReportTestSuite) testStoreConsumerMetadata() {
- consumerMi := newMetadataIdentifier("consumer")
- consumerMeta := "consumer"
- err := suite.m.StoreProviderMetadata(consumerMi, consumerMeta)
- assert.NoError(suite.t, err)
-}
-
-func (suite *zookeeperMetadataReportTestSuite) testSaveServiceMetadata(url
*common.URL) {
- serviceMi := newServiceMetadataIdentifier("provider")
- err := suite.m.SaveServiceMetadata(serviceMi, url)
- assert.NoError(suite.t, err)
-}
-
-func (suite *zookeeperMetadataReportTestSuite) testRemoveServiceMetadata() {
- serviceMi := newServiceMetadataIdentifier("provider")
- err := suite.m.RemoveServiceMetadata(serviceMi)
- assert.NoError(suite.t, err)
-}
-
-func (suite *zookeeperMetadataReportTestSuite) testGetExportedURLs() {
- serviceMi := newServiceMetadataIdentifier("provider")
- urls, err := suite.m.GetExportedURLs(serviceMi)
- assert.Equal(suite.t, 1, len(urls))
- assert.NoError(suite.t, err)
-}
-
-func (suite *zookeeperMetadataReportTestSuite) testSaveSubscribedData(url
*common.URL) {
- subscribeMi := newSubscribeMetadataIdentifier("provider")
- urls := []string{url.String()}
- bytes, _ := json.Marshal(urls)
- err := suite.m.SaveSubscribedData(subscribeMi, string(bytes))
- assert.Nil(suite.t, err)
-}
-
-func (suite *zookeeperMetadataReportTestSuite) testGetSubscribedURLs() {
- subscribeMi := newSubscribeMetadataIdentifier("provider")
- urls, err := suite.m.GetSubscribedURLs(subscribeMi)
- assert.Equal(suite.t, 1, len(urls))
- assert.NoError(suite.t, err)
-}
-
-func (suite *zookeeperMetadataReportTestSuite) testGetServiceDefinition() {
- providerMi := newMetadataIdentifier("provider")
- providerMeta, err := suite.m.GetServiceDefinition(providerMi)
- assert.Equal(suite.t, "provider", providerMeta)
- assert.NoError(suite.t, err)
-}
-
-func test1(t *testing.T) {
- testCluster, err := zk.StartTestCluster(1, nil, nil)
- assert.NoError(t, err)
- defer func() {
- err := testCluster.Stop()
- assert.Nil(t, err)
- }()
-
- url := newProviderRegistryUrl("127.0.0.1", testCluster.Servers[0].Port)
- mf := extension.GetMetadataReportFactory("zookeeper")
- m := mf.CreateMetadataReport(url)
-
- suite := newZookeeperMetadataReportTestSuite(t, m)
- suite.testStoreProviderMetadata()
- suite.testStoreConsumerMetadata()
- suite.testSaveServiceMetadata(url)
- suite.testGetExportedURLs()
- suite.testRemoveServiceMetadata()
- suite.testSaveSubscribedData(url)
- suite.testGetSubscribedURLs()
- suite.testGetServiceDefinition()
-}
-
-func TestZookeeperMetadataReport(t *testing.T) {
- t.Run("test1", test1)
-}
diff --git a/registry/zookeeper/registry_test.go
b/registry/zookeeper/registry_test.go
deleted file mode 100644
index 9e52dd7..0000000
--- a/registry/zookeeper/registry_test.go
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package zookeeper
-
-import (
- "strconv"
- "testing"
- "time"
-)
-
-import (
- gxzookeeper "github.com/dubbogo/gost/database/kv/zk"
- "github.com/stretchr/testify/assert"
-)
-
-import (
- "github.com/apache/dubbo-go/common"
- "github.com/apache/dubbo-go/common/constant"
-)
-
-func Test_Register(t *testing.T) {
- regURL, _ := common.NewURL("registry://127.0.0.1:1111",
common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
- url, _ :=
common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider",
common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
common.WithParamsValue("serviceid", "soa.mock"),
common.WithMethods([]string{"GetUser", "AddUser"}))
-
- ts, reg, err := newMockZkRegistry(regURL)
- assert.NoError(t, err)
- defer func() {
- _ = ts.Stop()
- }()
- err = reg.Register(url)
- children, _ :=
reg.client.GetChildren("/dubbo/com.ikurento.user.UserProvider/providers")
- assert.Regexp(t,
".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26cluster%3Dmock%26.*.serviceid%3Dsoa.mock",
children)
- assert.NoError(t, err)
-}
-
-func Test_UnRegister(t *testing.T) {
- // register
- regURL, _ := common.NewURL("registry://127.0.0.1:1111",
common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
- url, _ :=
common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider",
common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
common.WithParamsValue("serviceid", "soa.mock"),
common.WithMethods([]string{"GetUser", "AddUser"}))
-
- ts, reg, _ := newMockZkRegistry(regURL)
- defer func() {
- _ = ts.Stop()
- }()
- err := reg.Register(url)
- assert.NoError(t, err)
- children, _ :=
reg.client.GetChildren("/dubbo/com.ikurento.user.UserProvider/providers")
- assert.Regexp(t,
".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26cluster%3Dmock%26.*.serviceid%3Dsoa.mock",
children)
- assert.NoError(t, err)
-
- err = reg.UnRegister(url)
- assert.NoError(t, err)
- children, err =
reg.client.GetChildren("/dubbo/com.ikurento.user.UserProvider/providers")
- assert.Equal(t, 0, len(children))
- assert.Error(t, err)
- assert.True(t, reg.IsAvailable())
-
- err = reg.Register(url)
- children, _ =
reg.client.GetChildren("/dubbo/com.ikurento.user.UserProvider/providers")
- assert.Regexp(t,
".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26cluster%3Dmock%26.*.serviceid%3Dsoa.mock",
children)
- assert.NoError(t, err)
-}
-
-func Test_Subscribe(t *testing.T) {
- regURL, _ := common.NewURL("registry://127.0.0.1:1111",
common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
- url, _ :=
common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider",
common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
common.WithMethods([]string{"GetUser", "AddUser"}))
- ts, reg, _ := newMockZkRegistry(regURL)
-
- //provider register
- err := reg.Register(url)
- assert.NoError(t, err)
-
- if err != nil {
- return
- }
-
- //consumer register
- regURL.SetParam(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))
- _, reg2, _ := newMockZkRegistry(regURL, gxzookeeper.WithTestCluster(ts))
-
- err = reg2.Register(url)
- assert.Nil(t, err)
- listener, _ := reg2.DoSubscribe(url)
-
- serviceEvent, _ := listener.Next()
- assert.NoError(t, err)
- if err != nil {
- return
- }
- assert.Regexp(t, ".*ServiceEvent{Action{add}.*", serviceEvent.String())
- defer func() {
- _ = ts.Stop()
- }()
-}
-
-func Test_UnSubscribe(t *testing.T) {
- regURL, _ := common.NewURL("registry://127.0.0.1:1111",
common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
- url, _ :=
common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider",
common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
common.WithMethods([]string{"GetUser", "AddUser"}))
- ts, reg, _ := newMockZkRegistry(regURL)
-
- //provider register
- err := reg.Register(url)
- assert.NoError(t, err)
-
- if err != nil {
- return
- }
-
- //consumer register
- regURL.SetParam(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))
- _, reg2, _ := newMockZkRegistry(regURL, gxzookeeper.WithTestCluster(ts))
-
- err = reg2.Register(url)
- assert.Nil(t, err)
- listener, _ := reg2.DoSubscribe(url)
-
- serviceEvent, _ := listener.Next()
- assert.NoError(t, err)
- if err != nil {
- return
- }
- assert.Regexp(t, ".*ServiceEvent{Action{add}.*", serviceEvent.String())
-
- err = reg2.UnSubscribe(url, nil)
- assert.Nil(t, err)
- assert.Nil(t, reg2.listener)
- defer func() {
- _ = ts.Stop()
- }()
-}
-
-func Test_ConsumerDestroy(t *testing.T) {
- regURL, _ := common.NewURL("registry://127.0.0.1:1111",
common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER)))
- url, _ :=
common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider",
common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
common.WithMethods([]string{"GetUser", "AddUser"}))
-
- ts, reg, err := newMockZkRegistry(regURL)
- defer func() {
- _ = ts.Stop()
- }()
-
- assert.NoError(t, err)
- err = reg.Register(url)
- assert.NoError(t, err)
- _, err = reg.DoSubscribe(url)
- assert.NoError(t, err)
-
- //listener.Close()
- time.Sleep(1e9)
- reg.Destroy()
- assert.Equal(t, false, reg.IsAvailable())
-}
-
-func Test_ProviderDestroy(t *testing.T) {
- regURL, _ := common.NewURL("registry://127.0.0.1:1111",
common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)))
- url, _ :=
common.NewURL("dubbo://127.0.0.1:20000/com.ikurento.user.UserProvider",
common.WithParamsValue(constant.CLUSTER_KEY, "mock"),
common.WithMethods([]string{"GetUser", "AddUser"}))
-
- ts, reg, err := newMockZkRegistry(regURL)
- defer func() {
- _ = ts.Stop()
- }()
-
- assert.NoError(t, err)
- err = reg.Register(url)
- assert.Nil(t, err)
-
- //listener.Close()
- time.Sleep(1e9)
- reg.Destroy()
- assert.Equal(t, false, reg.IsAvailable())
-}
diff --git a/registry/zookeeper/service_discovery_test.go
b/registry/zookeeper/service_discovery_test.go
deleted file mode 100644
index d53b798..0000000
--- a/registry/zookeeper/service_discovery_test.go
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package zookeeper
-
-import (
- "strconv"
- "sync"
- "testing"
-)
-
-import (
- "github.com/dubbogo/go-zookeeper/zk"
- "github.com/stretchr/testify/assert"
-)
-
-import (
- "github.com/apache/dubbo-go/common/extension"
- "github.com/apache/dubbo-go/common/observer"
- "github.com/apache/dubbo-go/config"
- "github.com/apache/dubbo-go/registry"
-)
-
-const testName = "test"
-
-func prepareData(t *testing.T) *zk.TestCluster {
- var err error
- tc, err := zk.StartTestCluster(1, nil, nil)
- assert.NoError(t, err)
- assert.NotNil(t, tc.Servers[0])
- address := "127.0.0.1:" + strconv.Itoa(tc.Servers[0].Port)
- //address := "127.0.0.1:2181"
-
- config.GetBaseConfig().ServiceDiscoveries[testName] =
&config.ServiceDiscoveryConfig{
- Protocol: "zookeeper",
- RemoteRef: "test",
- }
-
- config.GetBaseConfig().Remotes[testName] = &config.RemoteConfig{
- Address: address,
- TimeoutStr: "10s",
- }
- return tc
-}
-
-func TestNewZookeeperServiceDiscovery(t *testing.T) {
- name := "zookeeper1"
- _, err := newZookeeperServiceDiscovery(name)
-
- // the ServiceDiscoveryConfig not found
- // err: could not init the instance because the config is invalid
- assert.NotNil(t, err)
-
- sdc := &config.ServiceDiscoveryConfig{
- Protocol: "zookeeper",
- RemoteRef: "mock",
- }
- config.GetBaseConfig().ServiceDiscoveries[name] = sdc
- _, err = newZookeeperServiceDiscovery(name)
-
- // RemoteConfig not found
- // err: could not find the remote config for name: mock
- assert.NotNil(t, err)
-}
-
-func TestZookeeperServiceDiscovery_CURDAndListener(t *testing.T) {
- tc := prepareData(t)
- defer func() {
- _ = tc.Stop()
- }()
- t.Run("testCURDZookeeperServiceDiscovery",
testCURDZookeeperServiceDiscovery)
- t.Run("testAddListenerZookeeperServiceDiscovery",
testAddListenerZookeeperServiceDiscovery)
-}
-
-func testCURDZookeeperServiceDiscovery(t *testing.T) {
- sd, err := newZookeeperServiceDiscovery(testName)
- assert.Nil(t, err)
- defer func() {
- _ = sd.Destroy()
- }()
- md := make(map[string]string)
- md["t1"] = "test1"
- err = sd.Register(®istry.DefaultServiceInstance{
- Id: "testId",
- ServiceName: testName,
- Host: "127.0.0.1",
- Port: 2233,
- Enable: true,
- Healthy: true,
- Metadata: md,
- })
- assert.Nil(t, err)
-
- testsPager := sd.GetHealthyInstancesByPage(testName, 0, 1, true)
- assert.Equal(t, 1, testsPager.GetDataSize())
- assert.Equal(t, 1, testsPager.GetTotalPages())
- test := testsPager.GetData()[0].(registry.ServiceInstance)
- assert.Equal(t, "127.0.0.1:2233", test.GetId())
- assert.Equal(t, "test1", test.GetMetadata()["t1"])
-
- md["t1"] = "test12"
- err = sd.Update(®istry.DefaultServiceInstance{
- Id: "testId",
- ServiceName: testName,
- Host: "127.0.0.1",
- Port: 2233,
- Enable: true,
- Healthy: true,
- Metadata: md,
- })
- assert.Nil(t, err)
-
- testsPager = sd.GetInstancesByPage(testName, 0, 1)
- assert.Equal(t, 1, testsPager.GetDataSize())
- test = testsPager.GetData()[0].(registry.ServiceInstance)
- assert.Equal(t, "test12", test.GetMetadata()["t1"])
-
- testsMap := sd.GetRequestInstances([]string{testName}, 0, 1)
- assert.Equal(t, 1, len(testsMap))
- assert.Equal(t, 1, testsMap[testName].GetDataSize())
- test = testsMap[testName].GetData()[0].(registry.ServiceInstance)
- assert.Equal(t, "test12", test.GetMetadata()["t1"])
-
- names := sd.GetServices()
- assert.Equal(t, 1, names.Size())
- assert.Equal(t, testName, names.Values()[0])
-
- err = sd.Unregister(®istry.DefaultServiceInstance{
- Id: "testId",
- ServiceName: testName,
- Host: "127.0.0.1",
- Port: 2233,
- Enable: true,
- Healthy: true,
- Metadata: nil,
- })
- assert.Nil(t, err)
-}
-
-func testAddListenerZookeeperServiceDiscovery(t *testing.T) {
- sd, err := newZookeeperServiceDiscovery(testName)
- assert.Nil(t, err)
- defer func() {
- _ = sd.Destroy()
- }()
-
- err = sd.Register(®istry.DefaultServiceInstance{
- Id: "testId",
- ServiceName: testName,
- Host: "127.0.0.1",
- Port: 2233,
- Enable: true,
- Healthy: true,
- Metadata: nil,
- })
- assert.Nil(t, err)
- wg := &sync.WaitGroup{}
- wg.Add(1)
- tn := &testNotify{
- wg: wg,
- t: t,
- }
- sicl := ®istry.ServiceInstancesChangedListener{
- ServiceName: testName,
- ChangedNotify: tn,
- }
- extension.SetAndInitGlobalDispatcher("direct")
- extension.GetGlobalDispatcher().AddEventListener(sicl)
- err = sd.AddListener(sicl)
- assert.NoError(t, err)
-
- err = sd.Update(®istry.DefaultServiceInstance{
- Id: "testId",
- ServiceName: testName,
- Host: "127.0.0.1",
- Port: 2233,
- Enable: true,
- Healthy: true,
- Metadata: nil,
- })
- assert.NoError(t, err)
- tn.wg.Wait()
-}
-
-type testNotify struct {
- wg *sync.WaitGroup
- t *testing.T
-}
-
-func (tn *testNotify) Notify(e observer.Event) {
- ice := e.(*registry.ServiceInstancesChangedEvent)
- assert.Equal(tn.t, 1, len(ice.Instances))
- assert.Equal(tn.t, "127.0.0.1:2233", ice.Instances[0].GetId())
- tn.wg.Done()
-}
diff --git a/remoting/zookeeper/facade_test.go
b/remoting/zookeeper/facade_test.go
deleted file mode 100644
index af8f887..0000000
--- a/remoting/zookeeper/facade_test.go
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package zookeeper
-
-import (
- "sync"
- "testing"
- "time"
-)
-
-import (
- "github.com/dubbogo/go-zookeeper/zk"
- gxzookeeper "github.com/dubbogo/gost/database/kv/zk"
- "github.com/stretchr/testify/assert"
-)
-
-import (
- "github.com/apache/dubbo-go/common"
-)
-
-type mockFacade struct {
- client *gxzookeeper.ZookeeperClient
- cltLock sync.Mutex
- wg sync.WaitGroup
- URL *common.URL
- done chan struct{}
-}
-
-func verifyEventStateOrder(t *testing.T, c <-chan zk.Event, expectedStates
[]zk.State, source string) {
- for _, state := range expectedStates {
- for {
- event, ok := <-c
- if !ok {
- t.Fatalf("unexpected channel close for %s",
source)
- }
- if event.Type != zk.EventSession {
- continue
- }
-
- if event.State != state {
- t.Fatalf("mismatched state order from %s,
expected %v, received %v", source, state, event.State)
- }
- break
- }
- }
-}
-
-func newMockFacade(client *gxzookeeper.ZookeeperClient, url *common.URL)
ZkClientFacade {
- mock := &mockFacade{
- client: client,
- URL: url,
- }
-
- mock.wg.Add(1)
- return mock
-}
-
-func (r *mockFacade) ZkClient() *gxzookeeper.ZookeeperClient {
- return r.client
-}
-
-func (r *mockFacade) SetZkClient(client *gxzookeeper.ZookeeperClient) {
- r.client = client
-}
-
-func (r *mockFacade) ZkClientLock() *sync.Mutex {
- return &r.cltLock
-}
-
-func (r *mockFacade) WaitGroup() *sync.WaitGroup {
- return &r.wg
-}
-
-func (r *mockFacade) Done() chan struct{} {
- return r.done
-}
-
-func (r *mockFacade) GetURL() *common.URL {
- return r.URL
-}
-
-func (r *mockFacade) Destroy() {
- close(r.done)
- r.wg.Wait()
-}
-
-func (r *mockFacade) RestartCallBack() bool {
- return true
-}
-
-func (r *mockFacade) IsAvailable() bool {
- return true
-}
-
-func Test_Facade(t *testing.T) {
- ts, z, event, err := gxzookeeper.NewMockZookeeperClient("test",
15*time.Second)
- assert.NoError(t, err)
- defer func() {
- if err := ts.Stop(); err != nil {
- t.Errorf("tc.Stop() = error: %v", err)
- }
- }()
- url, _ := common.NewURL("mock://127.0.0.1")
- mock := newMockFacade(z, url)
- go HandleClientRestart(mock)
- states := []zk.State{zk.StateConnecting, zk.StateConnected,
zk.StateHasSession}
- verifyEventStateOrder(t, event, states, "event channel")
- z.Close()
- verifyEventStateOrder(t, event, []zk.State{zk.StateDisconnected},
"event channel")
-}
diff --git a/remoting/zookeeper/listener_test.go
b/remoting/zookeeper/listener_test.go
index 1278665..9e30846 100644
--- a/remoting/zookeeper/listener_test.go
+++ b/remoting/zookeeper/listener_test.go
@@ -19,119 +19,13 @@ package zookeeper
import (
"net/url"
- "sync"
"testing"
- "time"
)
import (
- "github.com/dubbogo/go-zookeeper/zk"
- gxzookeeper "github.com/dubbogo/gost/database/kv/zk"
"github.com/stretchr/testify/assert"
)
-import (
- "github.com/apache/dubbo-go/common/logger"
- "github.com/apache/dubbo-go/remoting"
-)
-
-var (
- dubboPropertiesPath = "/dubbo/dubbo.properties"
-)
-
-func initZkData(t *testing.T) (*zk.TestCluster, *gxzookeeper.ZookeeperClient,
<-chan zk.Event) {
- ts, client, event, err := gxzookeeper.NewMockZookeeperClient("test",
15*time.Second)
- assert.NoError(t, err)
-
- data := `
- dubbo.consumer.request_timeout=5s
- dubbo.consumer.connect_timeout=5s
- dubbo.application.organization=ikurento.com
- dubbo.application.name=BDTService
- dubbo.application.module=dubbogo user-info server
- dubbo.application.version=0.0.1
- dubbo.application.owner=ZX
- dubbo.application.environment=dev
- dubbo.registries.hangzhouzk.protocol=zookeeper
- dubbo.registries.hangzhouzk.timeout=3s
- dubbo.registries.hangzhouzk.address=127.0.0.1:2181
- dubbo.registries.shanghaizk.protocol=zookeeper
- dubbo.registries.shanghaizk.timeout=3s
- dubbo.registries.shanghaizk.address=127.0.0.1:2182
- dubbo.service.com.ikurento.user.UserProvider.protocol=dubbo
-
dubbo.service.com.ikurento.user.UserProvider.interface=com.ikurento.user.UserProvider
- dubbo.service.com.ikurento.user.UserProvider.loadbalance=random
- dubbo.service.com.ikurento.user.UserProvider.warmup=100
- dubbo.service.com.ikurento.user.UserProvider.cluster=failover
-`
-
- err = client.Create(dubboPropertiesPath)
- assert.NoError(t, err)
-
- _, err = client.Conn.Set(dubboPropertiesPath, []byte(data), 0)
- assert.NoError(t, err)
-
- return ts, client, event
-}
-
-func TestListener(t *testing.T) {
- changedData := `
- dubbo.consumer.request_timeout=3s
- dubbo.consumer.connect_timeout=5s
- dubbo.application.organization=ikurento.com
- dubbo.application.name=BDTService
- dubbo.application.module=dubbogo user-info server
- dubbo.application.version=0.0.1
- dubbo.application.owner=ZX
- dubbo.application.environment=dev
- dubbo.registries.hangzhouzk.protocol=zookeeper
- dubbo.registries.hangzhouzk.timeout=3s
- dubbo.registries.hangzhouzk.address=127.0.0.1:2181
- dubbo.registries.shanghaizk.protocol=zookeeper
- dubbo.registries.shanghaizk.timeout=3s
- dubbo.registries.shanghaizk.address=127.0.0.1:2182
- dubbo.service.com.ikurento.user.UserProvider.protocol=dubbo
-
dubbo.service.com.ikurento.user.UserProvider.interface=com.ikurento.user.UserProvider
- dubbo.service.com.ikurento.user.UserProvider.loadbalance=random
- dubbo.service.com.ikurento.user.UserProvider.warmup=100
- dubbo.service.com.ikurento.user.UserProvider.cluster=failover
-`
- var wait sync.WaitGroup
- ts, client, _ := initZkData(t)
- defer func() {
- if err := ts.Stop(); err != nil {
- t.Errorf("ts.Stop() = error: %v", err)
- }
- }()
- client.Wait.Add(1)
- wait.Add(1)
- go client.GetEventHandler().HandleZkEvent(client)
- listener := NewZkEventListener(client)
- dataListener := &mockDataListener{client: client, changedData:
changedData, wait: &wait}
- listener.ListenServiceEvent(nil, "/dubbo", dataListener)
- time.Sleep(1 * time.Second)
- _, err := client.Conn.Set(dubboPropertiesPath, []byte(changedData), 1)
- assert.NoError(t, err)
- wait.Wait()
- assert.Equal(t, changedData, dataListener.eventList[1].Content)
-}
-
-type mockDataListener struct {
- eventList []remoting.Event
- client *gxzookeeper.ZookeeperClient
- changedData string
- wait *sync.WaitGroup
-}
-
-func (m *mockDataListener) DataChange(eventType remoting.Event) bool {
- logger.Info(eventType)
- m.eventList = append(m.eventList, eventType)
- if eventType.Content == m.changedData {
- m.wait.Done()
- }
- return true
-}
-
func TestZkPath(t *testing.T) {
zkPath := "io.grpc.examples.helloworld.GreeterGrpc$IGreeter"
zkPath = url.QueryEscape(zkPath)