From 9e8c37f1e904a7da2a51e0c5b12e505faba201ff Mon Sep 17 00:00:00 2001 From: tydhot <583125614@qq.com> Date: Sat, 31 Jul 2021 15:11:35 +0800 Subject: [PATCH] remove zk test --- config_center/zookeeper/impl_test.go | 232 --------------- config_center/zookeeper/listener_test.go | 101 ------- metadata/report/zookeeper/report_test.go | 203 -------------- registry/zookeeper/listener_test.go | 46 --- registry/zookeeper/registry_test.go | 185 ------------ registry/zookeeper/service_discovery_test.go | 279 ------------------- remoting/zookeeper/facade_test.go | 125 --------- remoting/zookeeper/listener_test.go | 104 ------- 8 files changed, 1275 deletions(-) delete mode 100644 config_center/zookeeper/impl_test.go delete mode 100644 config_center/zookeeper/listener_test.go delete mode 100644 metadata/report/zookeeper/report_test.go delete mode 100644 registry/zookeeper/listener_test.go delete mode 100644 registry/zookeeper/registry_test.go delete mode 100644 registry/zookeeper/service_discovery_test.go delete mode 100644 remoting/zookeeper/facade_test.go diff --git a/config_center/zookeeper/impl_test.go b/config_center/zookeeper/impl_test.go deleted file mode 100644 index 6d33c5a821..0000000000 --- a/config_center/zookeeper/impl_test.go +++ /dev/null @@ -1,232 +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 ( - "dubbo.apache.org/dubbo-go/v3/common" - "dubbo.apache.org/dubbo-go/v3/common/constant" - "dubbo.apache.org/dubbo-go/v3/config_center" - "dubbo.apache.org/dubbo-go/v3/config_center/parser" -) - -const ( - dubboPropertyFileName = "dubbo.properties" -) - -func initZkData(group string, t *testing.T) (*zk.TestCluster, *zookeeperDynamicConfiguration) { - ts, err := zk.StartTestCluster(1, nil, nil, zk.WithRetryTimes(20)) - 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 56c2e1ee2d..0000000000 --- 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 ( - "dubbo.apache.org/dubbo-go/v3/common" - "dubbo.apache.org/dubbo-go/v3/common/constant" - "dubbo.apache.org/dubbo-go/v3/config_center/parser" -) - -func initZkDynamicConfiguration(t *testing.T) (*zk.TestCluster, *zookeeperDynamicConfiguration) { - ts, err := zk.StartTestCluster(1, nil, nil, zk.WithRetryTimes(20)) - 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 8d718db214..0000000000 --- a/metadata/report/zookeeper/report_test.go +++ /dev/null @@ -1,203 +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 ( - "dubbo.apache.org/dubbo-go/v3/common" - "dubbo.apache.org/dubbo-go/v3/common/constant" - "dubbo.apache.org/dubbo-go/v3/common/extension" - "dubbo.apache.org/dubbo-go/v3/metadata/identifier" - "dubbo.apache.org/dubbo-go/v3/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() *identifier.SubscriberMetadataIdentifier { - return &identifier.SubscriberMetadataIdentifier{ - Revision: "1.0", - BaseApplicationMetadataIdentifier: identifier.BaseApplicationMetadataIdentifier{Application: "provider"}, - } -} - -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() - 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() - 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 (suite *zookeeperMetadataReportTestSuite) testPublishAppMetadata() { - subscribeMi := newSubscribeMetadataIdentifier() - info := common.NewMetadataInfWithApp(subscribeMi.Application) - err := suite.m.PublishAppMetadata(subscribeMi, info) - assert.NoError(suite.t, err) -} - -func (suite *zookeeperMetadataReportTestSuite) testGetAppMetadata() { - subscribeMi := newSubscribeMetadataIdentifier() - info, err := suite.m.GetAppMetadata(subscribeMi) - assert.NoError(suite.t, err) - assert.Equal(suite.t, "provider", info.App) -} - -func testInterfaceMetadata(t *testing.T) { - testCluster, err := zk.StartTestCluster(1, nil, nil, zk.WithRetryTimes(20)) - assert.NoError(t, err) - defer func() { - err := testCluster.Stop() - assert.Nil(t, err) - }() - - providerRegistryUrl := newProviderRegistryUrl("127.0.0.1", testCluster.Servers[0].Port) - mf := extension.GetMetadataReportFactory("zookeeper") - m := mf.CreateMetadataReport(providerRegistryUrl) - - suite := newZookeeperMetadataReportTestSuite(t, m) - suite.testStoreProviderMetadata() - suite.testStoreConsumerMetadata() - suite.testSaveServiceMetadata(providerRegistryUrl) - suite.testGetExportedURLs() - suite.testRemoveServiceMetadata() - suite.testSaveSubscribedData(providerRegistryUrl) - suite.testGetSubscribedURLs() - suite.testGetServiceDefinition() -} - -func testAppMetadata(t *testing.T) { - testCluster, err := zk.StartTestCluster(1, nil, nil, zk.WithRetryTimes(20)) - assert.NoError(t, err) - defer func() { - err := testCluster.Stop() - assert.Nil(t, err) - }() - - providerRegistryUrl := newProviderRegistryUrl("127.0.0.1", testCluster.Servers[0].Port) - mf := extension.GetMetadataReportFactory("zookeeper") - m := mf.CreateMetadataReport(providerRegistryUrl) - - suite := newZookeeperMetadataReportTestSuite(t, m) - suite.testPublishAppMetadata() - suite.testGetAppMetadata() -} - -// TestZookeeperMetadataReport is dependent on zookeeper-*-fatjar.jar, -// please execute `make -f ../../../Makefile prepare` before running unittest. -func TestZookeeperMetadataReport(t *testing.T) { - t.Run("testInterfaceMetadata", testInterfaceMetadata) - t.Run("testAppMetadata", testAppMetadata) -} diff --git a/registry/zookeeper/listener_test.go b/registry/zookeeper/listener_test.go deleted file mode 100644 index 43862e059a..0000000000 --- a/registry/zookeeper/listener_test.go +++ /dev/null @@ -1,46 +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 ( - "testing" -) - -import ( - "github.com/stretchr/testify/assert" -) - -import ( - "dubbo.apache.org/dubbo-go/v3/common" - "dubbo.apache.org/dubbo-go/v3/config_center" - "dubbo.apache.org/dubbo-go/v3/remoting" -) - -// Test_DataChange test data change event of zk listenerg -func Test_DataChange(t *testing.T) { - listener := NewRegistryDataListener() - url, _ := common.NewURL("jsonrpc%3A%2F%2F127.0.0.1%3A20001%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26app.version%3D0.0.1%26application%3DBDTService%26category%3Dproviders%26cluster%3Dfailover%26dubbo%3Ddubbo-provider-golang-1.3.0%26environment%3Ddev%26group%3D%26interface%3Dcom.ikurento.user.UserProvider%26ip%3D10.32.20.124%26loadbalance%3Drandom%26methods.GetUser.loadbalance%3Drandom%26methods.GetUser.retries%3D1%26methods.GetUser.weight%3D0%26module%3Ddubbogo%2Buser-info%2Bserver%26name%3DBDTService%26organization%3Dikurento.com%26owner%3DZX%26pid%3D74500%26retries%3D0%26service.filter%3Decho%26side%3Dprovider%26timestamp%3D1560155407%26version%3D%26warmup%3D100") - listener.SubscribeURL(url, &MockConfigurationListener{}) - int := listener.DataChange(remoting.Event{Path: "/dubbo/com.ikurento.user.UserProvider/providers/jsonrpc%3A%2F%2F127.0.0.1%3A20001%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26app.version%3D0.0.1%26application%3DBDTService%26category%3Dproviders%26cluster%3Dfailover%26dubbo%3Ddubbo-provider-golang-1.3.0%26environment%3Ddev%26group%3D%26interface%3Dcom.ikurento.user.UserProvider%26ip%3D10.32.20.124%26loadbalance%3Drandom%26methods.GetUser.loadbalance%3Drandom%26methods.GetUser.retries%3D1%26methods.GetUser.weight%3D0%26module%3Ddubbogo%2Buser-info%2Bserver%26name%3DBDTService%26organization%3Dikurento.com%26owner%3DZX%26pid%3D74500%26retries%3D0%26service.filter%3Decho%26side%3Dprovider%26timestamp%3D1560155407%26version%3D%26warmup%3D100"}) - assert.Equal(t, true, int) -} - -type MockConfigurationListener struct{} - -func (*MockConfigurationListener) Process(configType *config_center.ConfigChangeEvent) { -} diff --git a/registry/zookeeper/registry_test.go b/registry/zookeeper/registry_test.go deleted file mode 100644 index 4e1c1986e8..0000000000 --- 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 ( - "dubbo.apache.org/dubbo-go/v3/common" - "dubbo.apache.org/dubbo-go/v3/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 512031bd4b..0000000000 --- a/registry/zookeeper/service_discovery_test.go +++ /dev/null @@ -1,279 +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 ( - "context" - "strconv" - "sync" - "testing" -) - -import ( - "github.com/dubbogo/go-zookeeper/zk" - gxset "github.com/dubbogo/gost/container/set" - "github.com/stretchr/testify/assert" -) - -import ( - "dubbo.apache.org/dubbo-go/v3/common" - "dubbo.apache.org/dubbo-go/v3/common/constant" - "dubbo.apache.org/dubbo-go/v3/common/extension" - "dubbo.apache.org/dubbo-go/v3/common/observer" - "dubbo.apache.org/dubbo-go/v3/common/observer/dispatcher" - "dubbo.apache.org/dubbo-go/v3/config" - "dubbo.apache.org/dubbo-go/v3/metadata/mapping" - "dubbo.apache.org/dubbo-go/v3/protocol" - "dubbo.apache.org/dubbo-go/v3/registry" - "dubbo.apache.org/dubbo-go/v3/registry/event" -) - -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) { - prepareData(t) - extension.SetEventDispatcher("mock", func() observer.EventDispatcher { - return dispatcher.NewMockEventDispatcher() - }) - extension.SetGlobalServiceNameMapping(func() mapping.ServiceNameMapping { - return mapping.NewMockServiceNameMapping() - }) - - extension.SetProtocol("mock", func() protocol.Protocol { - return &mockProtocol{} - }) - - sd, err := newZookeeperServiceDiscovery(testName) - assert.Nil(t, err) - defer func() { - _ = sd.Destroy() - }() - ins := ®istry.DefaultServiceInstance{ - ID: "testID", - ServiceName: testName, - Host: "127.0.0.1", - Port: 2233, - Enable: true, - Healthy: true, - Metadata: nil, - } - ins.Metadata = map[string]string{"t1": "test1", constant.METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME: `{"protocol":"mock","timeout":"10000","version":"1.0.0","dubbo":"2.0.2","release":"2.7.6","port":"2233"}`} - err = sd.Register(ins) - - 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"]) - - ins = ®istry.DefaultServiceInstance{ - ID: "testID", - ServiceName: testName, - Host: "127.0.0.1", - Port: 2233, - Enable: true, - Healthy: true, - } - ins.Metadata = map[string]string{"t1": "test12", constant.METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME: `{"protocol":"mock","timeout":"10000","version":"1.0.0","dubbo":"2.0.2","release":"2.7.6","port":"2233"}`} - - err = sd.Update(ins) - - 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() - }() - - ins := ®istry.DefaultServiceInstance{ - ID: "testID", - ServiceName: testName, - Host: "127.0.0.1", - Port: 2233, - Enable: true, - Healthy: true, - Metadata: nil, - } - ins.Metadata = map[string]string{"t1": "test12", constant.METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME: `{"protocol":"mock","timeout":"10000","version":"1.0.0","dubbo":"2.0.2","release":"2.7.6","port":"2233"}`} - err = sd.Register(ins) - - assert.Nil(t, err) - wg := &sync.WaitGroup{} - wg.Add(1) - tn := &testNotify{ - wg: wg, - t: t, - } - hs := gxset.NewSet() - hs.Add(testName) - - sicl := event.NewServiceInstancesChangedListener(hs) - sicl.AddListenerAndNotify(testName, tn) - extension.SetAndInitGlobalDispatcher("direct") - extension.GetGlobalDispatcher().AddEventListener(sicl) - err = sd.AddListener(sicl) - assert.NoError(t, err) - - ins = ®istry.DefaultServiceInstance{ - ID: "testID", - ServiceName: testName, - Host: "127.0.0.1", - Port: 2233, - Enable: true, - Healthy: true, - Metadata: nil, - } - ins.Metadata = map[string]string{"t1": "test12", constant.METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME: `{"protocol":"mock","timeout":"10000","version":"1.0.0","dubbo":"2.0.2","release":"2.7.6","port":"2233"}`} - err = sd.Update(ins) - assert.NoError(t, err) - tn.wg.Wait() -} - -type testNotify struct { - wg *sync.WaitGroup - t *testing.T -} - -func (tn *testNotify) Notify(e *registry.ServiceEvent) { - assert.Equal(tn.t, "2233", e.Service.Port) - tn.wg.Done() -} -func (tn *testNotify) NotifyAll([]*registry.ServiceEvent, func()) { - -} - -type mockProtocol struct{} - -func (m mockProtocol) Export(protocol.Invoker) protocol.Exporter { - panic("implement me") -} - -func (m mockProtocol) Refer(*common.URL) protocol.Invoker { - return &mockInvoker{} -} - -func (m mockProtocol) Destroy() { - panic("implement me") -} - -type mockInvoker struct{} - -func (m *mockInvoker) GetURL() *common.URL { - panic("implement me") -} - -func (m *mockInvoker) IsAvailable() bool { - panic("implement me") -} - -func (m *mockInvoker) Destroy() { - panic("implement me") -} - -func (m *mockInvoker) Invoke(context.Context, protocol.Invocation) protocol.Result { - // for getMetadataInfo and ServiceInstancesChangedListenerImpl onEvent - serviceInfo := &common.ServiceInfo{ServiceKey: "test", MatchKey: "test"} - services := make(map[string]*common.ServiceInfo) - services["test"] = serviceInfo - return &protocol.RPCResult{ - Rest: &common.MetadataInfo{ - Services: services, - }, - } -} diff --git a/remoting/zookeeper/facade_test.go b/remoting/zookeeper/facade_test.go deleted file mode 100644 index 84e7e14dae..0000000000 --- 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 ( - "dubbo.apache.org/dubbo-go/v3/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 6e185eee4e..9e30846dcd 100644 --- a/remoting/zookeeper/listener_test.go +++ b/remoting/zookeeper/listener_test.go @@ -19,117 +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 ( - "dubbo.apache.org/dubbo-go/v3/common/logger" - "dubbo.apache.org/dubbo-go/v3/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)