From 971c854dde079b7deef6e10199fbea11d4801791 Mon Sep 17 00:00:00 2001 From: AlexStocks <alexstocks@foxmail.com> Date: Sun, 3 Jan 2021 03:00:40 +0800 Subject: [PATCH] fix registry error --- registry/base_configuration_listener.go | 12 +++++++++--- registry/directory/directory.go | 4 +++- registry/zookeeper/registry_test.go | 12 ++++++++---- registry/zookeeper/service_discovery_test.go | 10 ++++++++-- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/registry/base_configuration_listener.go b/registry/base_configuration_listener.go index 3b3651030..31e859eec 100644 --- a/registry/base_configuration_listener.go +++ b/registry/base_configuration_listener.go @@ -20,6 +20,7 @@ package registry import ( perrors "github.com/pkg/errors" ) + import ( "github.com/apache/dubbo-go/common" "github.com/apache/dubbo-go/common/config" @@ -42,7 +43,9 @@ func (bcl *BaseConfigurationListener) Configurators() []config_center.Configurat } // InitWith will init BaseConfigurationListener by @key+@Listener+@f -func (bcl *BaseConfigurationListener) InitWith(key string, listener config_center.ConfigurationListener, f func(url *common.URL) config_center.Configurator) { +func (bcl *BaseConfigurationListener) InitWith(key string, listener config_center.ConfigurationListener, + f func(url *common.URL) config_center.Configurator) { + bcl.dynamicConfiguration = config.GetEnvInstance().GetDynamicConfiguration() if bcl.dynamicConfiguration == nil { //set configurators to empty @@ -51,12 +54,15 @@ func (bcl *BaseConfigurationListener) InitWith(key string, listener config_cente } bcl.defaultConfiguratorFunc = f bcl.dynamicConfiguration.AddListener(key, listener) - if rawConfig, err := bcl.dynamicConfiguration.GetInternalProperty(key, config_center.WithGroup(constant.DUBBO)); err != nil { + if rawConfig, err := bcl.dynamicConfiguration.GetInternalProperty(key, + config_center.WithGroup(constant.DUBBO)); err != nil { //set configurators to empty bcl.configurators = []config_center.Configurator{} return } else if len(rawConfig) > 0 { - bcl.genConfiguratorFromRawRule(rawConfig) + if err := bcl.genConfiguratorFromRawRule(rawConfig); err != nil { + logger.Error("bcl.genConfiguratorFromRawRule(rawConfig:%v) = error:%v", rawConfig, err) + } } } diff --git a/registry/directory/directory.go b/registry/directory/directory.go index ed1d8fb3c..f55bd4abf 100644 --- a/registry/directory/directory.go +++ b/registry/directory/directory.go @@ -102,7 +102,9 @@ func (dir *RegistryDirectory) subscribe(url *common.URL) { logger.Debugf("subscribe service :%s for RegistryDirectory.", url.Key()) dir.consumerConfigurationListener.addNotifyListener(dir) dir.referenceConfigurationListener = newReferenceConfigurationListener(dir, url) - dir.registry.Subscribe(url, dir) + if err := dir.registry.Subscribe(url, dir); err != nil { + logger.Error("registry.Subscribe(url:%v, dir:%v) = error:%v", url, dir, err) + } } // Notify monitor changes from registry,and update the cacheServices diff --git a/registry/zookeeper/registry_test.go b/registry/zookeeper/registry_test.go index e630db7e4..d7a011ec4 100644 --- a/registry/zookeeper/registry_test.go +++ b/registry/zookeeper/registry_test.go @@ -87,7 +87,8 @@ func Test_Subscribe(t *testing.T) { regurl.SetParam(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER)) _, reg2, _ := newMockZkRegistry(regurl, zookeeper.WithTestCluster(ts)) - reg2.Register(url) + err = reg2.Register(url) + assert.Nil(t, err) listener, _ := reg2.DoSubscribe(url) serviceEvent, _ := listener.Next() @@ -116,7 +117,8 @@ func Test_UnSubscribe(t *testing.T) { regurl.SetParam(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER)) _, reg2, _ := newMockZkRegistry(regurl, zookeeper.WithTestCluster(ts)) - reg2.Register(url) + err = reg2.Register(url) + assert.Nil(t, err) listener, _ := reg2.DoSubscribe(url) serviceEvent, _ := listener.Next() @@ -126,7 +128,8 @@ func Test_UnSubscribe(t *testing.T) { } assert.Regexp(t, ".*ServiceEvent{Action{add}.*", serviceEvent.String()) - reg2.UnSubscribe(url, nil) + err = reg2.UnSubscribe(url, nil) + assert.Nil(t, err) assert.Nil(t, reg2.listener) defer ts.Stop() @@ -160,7 +163,8 @@ func Test_ProviderDestory(t *testing.T) { defer ts.Stop() assert.NoError(t, err) - reg.Register(url) + err = reg.Register(url) + assert.Nil(t, err) //listener.Close() time.Sleep(1e9) diff --git a/registry/zookeeper/service_discovery_test.go b/registry/zookeeper/service_discovery_test.go index ea3c7ddd4..60b3d1375 100644 --- a/registry/zookeeper/service_discovery_test.go +++ b/registry/zookeeper/service_discovery_test.go @@ -78,7 +78,10 @@ func TestCURDZookeeperServiceDiscovery(t *testing.T) { defer ts.Stop() sd, err := newZookeeperServiceDiscovery(testName) assert.Nil(t, err) - defer sd.Destroy() + defer func() { + err := sd.Destroy() + assert.Nil(t, err) + }() md := make(map[string]string) md["t1"] = "test1" err = sd.Register(®istry.DefaultServiceInstance{ @@ -143,7 +146,10 @@ func TestAddListenerZookeeperServiceDiscovery(t *testing.T) { defer ts.Stop() sd, err := newZookeeperServiceDiscovery(testName) assert.Nil(t, err) - defer sd.Destroy() + defer func() { + err := sd.Destroy() + assert.Nil(t, err) + }() err = sd.Register(®istry.DefaultServiceInstance{ Id: "testId", -- GitLab