From 0b700a7626c01c9e1646bd9e398a0d4ab1d6074a Mon Sep 17 00:00:00 2001 From: "ken.lj" Date: Thu, 27 Dec 2018 17:10:33 +0800 Subject: [PATCH 01/11] Remove assert check to continue with execute. --- .../router/condition/config/ListenableRouter.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java index 71c5fcec60e..84419a7ea30 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/condition/config/ListenableRouter.java @@ -20,8 +20,8 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.common.utils.Assert; import org.apache.dubbo.common.utils.CollectionUtils; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.configcenter.ConfigChangeEvent; import org.apache.dubbo.configcenter.ConfigChangeType; import org.apache.dubbo.configcenter.ConfigurationListener; @@ -125,12 +125,14 @@ private void generateConditions(ConditionRouterRule rule, List } private synchronized void init(String ruleKey) { - Assert.notEmptyString(ruleKey, "router rule's key cannot be null"); - String router = ruleKey + Constants.ROUTERS_SUFFIX; - configuration.addListener(router, this); - String rule = configuration.getConfig(router); + if (StringUtils.isEmpty(ruleKey)) { + return; + } + String routerKey = ruleKey + Constants.ROUTERS_SUFFIX; + configuration.addListener(routerKey, this); + String rule = configuration.getConfig(routerKey); if (rule != null) { - this.process(new ConfigChangeEvent(router, rule)); + this.process(new ConfigChangeEvent(routerKey, rule)); } } } From 9c0e3efd1ec1a6ebea2f2ca5650c47a813602d97 Mon Sep 17 00:00:00 2001 From: "ken.lj" Date: Thu, 27 Dec 2018 17:15:25 +0800 Subject: [PATCH 02/11] solve compile error --- .../apache/dubbo/test/provider/DefaultDemoService.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/dubbo-test/dubbo-test-compatibility/dubbo-test-spring3/src/main/java/org/apache/dubbo/test/provider/DefaultDemoService.java b/dubbo-test/dubbo-test-compatibility/dubbo-test-spring3/src/main/java/org/apache/dubbo/test/provider/DefaultDemoService.java index d208a43ee27..7c747717ef9 100644 --- a/dubbo-test/dubbo-test-compatibility/dubbo-test-spring3/src/main/java/org/apache/dubbo/test/provider/DefaultDemoService.java +++ b/dubbo-test/dubbo-test-compatibility/dubbo-test-spring3/src/main/java/org/apache/dubbo/test/provider/DefaultDemoService.java @@ -37,14 +37,4 @@ public String sayHello(String name) { return "DefaultDemoService - sayHell() : " + name; } - @Override - public String routeMethod1() { - return null; - } - - @Override - public String routeMethod2() { - return null; - } - } From c255ad696fc400562c9691c93d4245fae0f53a79 Mon Sep 17 00:00:00 2001 From: Ian Luo Date: Thu, 27 Dec 2018 18:48:03 +0800 Subject: [PATCH 03/11] Merge pull request #3077, Code review around AbstractConfiguratorListener. * refactor ScriptRouter * refactor TagRouter * refactor AbstractConfiguratorListener * make sure parameter should not be null * correct comments * make ReferenceConfigurationListener private static * avoid dup code in init * add fixme for potential useless code --- .../router/file/FileRouterFactory.java | 5 +- .../cluster/router/script/ScriptRouter.java | 12 ++--- .../rpc/cluster/router/tag/TagRouter.java | 14 ++---- .../AbstractConfiguratorListener.java | 26 +++++++--- .../integration/RegistryDirectory.java | 49 +++++++------------ .../integration/RegistryProtocol.java | 27 +--------- 6 files changed, 53 insertions(+), 80 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterFactory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterFactory.java index 6b8b3245559..2d509422d12 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterFactory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/file/FileRouterFactory.java @@ -53,8 +53,11 @@ public Router getRouter(URL url) { } String rule = IOUtils.read(new FileReader(new File(url.getAbsolutePath()))); + // FIXME: this code looks useless boolean runtime = url.getParameter(Constants.RUNTIME_KEY, false); - URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type).addParameter(Constants.RUNTIME_KEY, runtime).addParameterAndEncoded(Constants.RULE_KEY, rule); + URL script = url.setProtocol(protocol).addParameter(Constants.TYPE_KEY, type) + .addParameter(Constants.RUNTIME_KEY, runtime) + .addParameterAndEncoded(Constants.RULE_KEY, rule); return routerFactory.getRouter(script); } catch (IOException e) { diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java index 1776ce69738..496a0dce122 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/script/ScriptRouter.java @@ -45,7 +45,7 @@ public class ScriptRouter extends AbstractRouter { public static final String NAME = "SCRIPT_ROUTER"; private static final Logger logger = LoggerFactory.getLogger(ScriptRouter.class); - private static final Map engines = new ConcurrentHashMap(); + private static final Map engines = new ConcurrentHashMap<>(); private final ScriptEngine engine; @@ -62,13 +62,13 @@ public ScriptRouter(URL url) { type = Constants.DEFAULT_SCRIPT_TYPE_KEY; } if (rule == null || rule.length() == 0) { - throw new IllegalStateException(new IllegalStateException("route rule can not be empty. rule:" + rule)); + throw new IllegalStateException("route rule can not be empty. rule:" + rule); } ScriptEngine engine = engines.get(type); if (engine == null) { engine = new ScriptEngineManager().getEngineByName(type); if (engine == null) { - throw new IllegalStateException(new IllegalStateException("Unsupported route rule type: " + type + ", rule: " + rule)); + throw new IllegalStateException("unsupported route rule type: " + type + ", rule: " + rule); } engines.put(type, engine); } @@ -85,7 +85,7 @@ public URL getUrl() { @SuppressWarnings("unchecked") public List> route(List> invokers, URL url, Invocation invocation) throws RpcException { try { - List> invokersCopy = new ArrayList>(invokers); + List> invokersCopy = new ArrayList<>(invokers); Compilable compilable = (Compilable) engine; Bindings bindings = engine.createBindings(); bindings.put("invokers", invokersCopy); @@ -105,8 +105,8 @@ public List> route(List> invokers, URL url, Invocation } return invokersCopy; } catch (ScriptException e) { - //fail then ignore rule .invokers. - logger.error("route error , rule has been ignored. rule: " + rule + ", method:" + invocation.getMethodName() + ", url: " + RpcContext.getContext().getUrl(), e); + logger.error("route error, rule has been ignored. rule: " + rule + ", method:" + + invocation.getMethodName() + ", url: " + RpcContext.getContext().getUrl(), e); return invokers; } } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java index 4edffacd9f2..21fe390ee61 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/tag/TagRouter.java @@ -42,7 +42,7 @@ import static org.apache.dubbo.common.Constants.TAG_KEY; /** - * + * TagRouter */ public class TagRouter extends AbstractRouter implements Comparable, ConfigurationListener { public static final String NAME = "TAG_ROUTER"; @@ -117,10 +117,9 @@ public List> route(List> invokers, URL url, Invocation } // FAILOVER: return all Providers without any tags. else { - List> tmp = filterInvoker(invokers, invoker -> addressNotMatches(invoker.getUrl(), tagRouterRule - .getAddresses())); - return filterInvoker(tmp, invoker -> StringUtils.isEmpty(invoker.getUrl() - .getParameter(TAG_KEY))); + List> tmp = filterInvoker(invokers, invoker -> addressNotMatches(invoker.getUrl(), + tagRouterRule.getAddresses())); + return filterInvoker(tmp, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(TAG_KEY))); } } else { // List addresses = tagRouterRule.filter(providerApp); @@ -137,10 +136,7 @@ public List> route(List> invokers, URL url, Invocation } return filterInvoker(result, invoker -> { String localTag = invoker.getUrl().getParameter(TAG_KEY); - if (StringUtils.isEmpty(localTag) || !tagRouterRule.getTagNames().contains(localTag)) { - return true; - } - return false; + return StringUtils.isEmpty(localTag) || !tagRouterRule.getTagNames().contains(localTag); }); } } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java index 1193798cf24..8b0b43fad9d 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java @@ -18,28 +18,40 @@ import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.configcenter.ConfigChangeEvent; import org.apache.dubbo.configcenter.ConfigChangeType; import org.apache.dubbo.configcenter.ConfigurationListener; +import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.rpc.cluster.Configurator; import org.apache.dubbo.rpc.cluster.configurator.parser.ConfigParser; -import java.util.LinkedList; +import java.util.Collections; import java.util.List; /** - * + * AbstractConfiguratorListener */ public abstract class AbstractConfiguratorListener implements ConfigurationListener { private static final Logger logger = LoggerFactory.getLogger(AbstractConfiguratorListener.class); - protected List configurators = new LinkedList<>(); + protected List configurators = Collections.emptyList(); + + + protected final void initWith(String key) { + DynamicConfiguration dynamicConfiguration = DynamicConfiguration.getDynamicConfiguration(); + dynamicConfiguration.addListener(key, this); + String rawConfig = dynamicConfiguration.getConfig(key); + if (!StringUtils.isEmpty(rawConfig)) { + process(new ConfigChangeEvent(key, rawConfig)); + } + } @Override public void process(ConfigChangeEvent event) { if (logger.isInfoEnabled()) { - logger.info("Notification of overriding rule, change type is: " + event.getChangeType() + ", raw config content is:\n " + event - .getValue()); + logger.info("Notification of overriding rule, change type is: " + event.getChangeType() + + ", raw config content is:\n " + event.getValue()); } if (event.getChangeType().equals(ConfigChangeType.DELETED)) { @@ -50,8 +62,8 @@ public void process(ConfigChangeEvent event) { configurators = Configurator.toConfigurators(ConfigParser.parseConfigurators(event.getValue())) .orElse(configurators); } catch (Exception e) { - logger.error("Failed to parse raw dynamic config and it will not take effect, the raw config is: " + event - .getValue(), e); + logger.error("Failed to parse raw dynamic config and it will not take effect, the raw config is: " + + event.getValue(), e); return; } } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java index e886d139274..48f727e5175 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryDirectory.java @@ -22,9 +22,9 @@ import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.Assert; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.common.utils.StringUtils; -import org.apache.dubbo.configcenter.ConfigChangeEvent; import org.apache.dubbo.configcenter.DynamicConfiguration; import org.apache.dubbo.registry.NotifyListener; import org.apache.dubbo.registry.Registry; @@ -157,7 +157,7 @@ public void setRegistry(Registry registry) { public void subscribe(URL url) { setConsumerUrl(url); consumerConfigurationListener.addNotifyListener(this); - serviceConfigurationListener = new ReferenceConfigurationListener(url); + serviceConfigurationListener = new ReferenceConfigurationListener(this, url); registry.subscribe(url, this); } @@ -223,7 +223,9 @@ public void refreshOverrideAndInvoker(List urls) { */ // TODO: 2017/8/31 FIXME The thread pool should be used to refresh the address, otherwise the task may be accumulated. private void refreshInvoker(List invokerUrls) { - if (invokerUrls != null && invokerUrls.size() == 1 && invokerUrls.get(0) != null && Constants.EMPTY_PROTOCOL.equals(invokerUrls + Assert.notNull(invokerUrls, "invokerUrls should not be null"); + + if (invokerUrls.size() == 1 && invokerUrls.get(0) != null && Constants.EMPTY_PROTOCOL.equals(invokerUrls .get(0) .getProtocol())) { this.forbidden = true; // Forbid to access @@ -233,7 +235,7 @@ private void refreshInvoker(List invokerUrls) { } else { this.forbidden = false; // Allow to access Map> oldUrlInvokerMap = this.urlInvokerMap; // local reference - if (invokerUrls == null) { + if (invokerUrls == Collections.emptyList()) { invokerUrls = new ArrayList<>(); } if (invokerUrls.isEmpty() && this.cachedInvokerUrls != null) { @@ -718,54 +720,37 @@ public URL getProviderUrl() { } } - public class ReferenceConfigurationListener extends AbstractConfiguratorListener { + private static class ReferenceConfigurationListener extends AbstractConfiguratorListener { + private RegistryDirectory directory; private URL url; - ReferenceConfigurationListener(URL url) { + ReferenceConfigurationListener(RegistryDirectory directory, URL url) { + this.directory = directory; this.url = url; - this.init(); - } - - private synchronized void init() { - String key = url.getEncodedServiceKey() + Constants.CONFIGURATORS_SUFFIX; - DynamicConfiguration.getDynamicConfiguration().addListener(key, this); - String rawConfig = DynamicConfiguration.getDynamicConfiguration().getConfig(key); - if (rawConfig != null) { - this.process(new ConfigChangeEvent(key, rawConfig)); - } + this.initWith(url.getEncodedServiceKey() + Constants.CONFIGURATORS_SUFFIX); } @Override protected void notifyOverrides() { - // 'null' means notification of configurators or routers. - RegistryDirectory.this.refreshInvoker(null); + // to notify configurator/router changes + directory.refreshInvoker(Collections.emptyList()); } } private static class ConsumerConfigurationListener extends AbstractConfiguratorListener { List listeners = new ArrayList<>(); - - void addNotifyListener(RegistryDirectory listener) { - this.listeners.add(listener); - } - ConsumerConfigurationListener() { - this.init(); + this.initWith(ApplicationModel.getApplication() + Constants.CONFIGURATORS_SUFFIX); } - private synchronized void init() { - String appKey = ApplicationModel.getApplication() + Constants.CONFIGURATORS_SUFFIX; - DynamicConfiguration.getDynamicConfiguration().addListener(appKey, this); - String appRawConfig = DynamicConfiguration.getDynamicConfiguration().getConfig(appKey); - if (appRawConfig != null) { - process(new ConfigChangeEvent(appKey, appRawConfig)); - } + void addNotifyListener(RegistryDirectory listener) { + this.listeners.add(listener); } @Override protected void notifyOverrides() { - listeners.forEach(listener -> listener.refreshInvoker(null)); + listeners.forEach(listener -> listener.refreshInvoker(Collections.emptyList())); } } diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java index 438d319a45c..ebf5842690f 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java @@ -39,7 +39,6 @@ import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.cluster.Cluster; import org.apache.dubbo.rpc.cluster.Configurator; -import org.apache.dubbo.rpc.cluster.configurator.parser.ConfigParser; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.protocol.InvokerWrapper; @@ -537,18 +536,7 @@ private class ServiceConfigurationListener extends AbstractConfiguratorListener public ServiceConfigurationListener(URL providerUrl, OverrideListener notifyListener) { this.providerUrl = providerUrl; this.notifyListener = notifyListener; - this.init(); - } - - private synchronized void init() { - DynamicConfiguration dynamicConfiguration = DynamicConfiguration.getDynamicConfiguration(); - String key = providerUrl.getEncodedServiceKey() + Constants.CONFIGURATORS_SUFFIX; - dynamicConfiguration.addListener(key, this); - String rawConfig = dynamicConfiguration.getConfig(key); - if (!StringUtils.isEmpty(rawConfig)) { - configurators = Configurator.toConfigurators(ConfigParser.parseConfigurators(rawConfig)) - .orElse(configurators); - } + this.initWith(providerUrl.getEncodedServiceKey() + Constants.CONFIGURATORS_SUFFIX); } private URL overrideUrl(URL providerUrl) { @@ -564,18 +552,7 @@ protected void notifyOverrides() { private class ProviderConfigurationListener extends AbstractConfiguratorListener { public ProviderConfigurationListener() { - this.init(); - } - - private synchronized void init() { - DynamicConfiguration dynamicConfiguration = DynamicConfiguration.getDynamicConfiguration(); - String appKey = ApplicationModel.getApplication() + Constants.CONFIGURATORS_SUFFIX; - dynamicConfiguration.addListener(appKey, this); - String appRawConfig = dynamicConfiguration.getConfig(appKey); - if (!StringUtils.isEmpty(appRawConfig)) { - configurators = Configurator.toConfigurators(ConfigParser.parseConfigurators(appRawConfig)) - .orElse(configurators); - } + this.initWith(ApplicationModel.getApplication() + Constants.CONFIGURATORS_SUFFIX); } /** From 7aa0717124704db8aede882d815eb39c421dbdf5 Mon Sep 17 00:00:00 2001 From: "ken.lj" Date: Thu, 27 Dec 2018 19:55:25 +0800 Subject: [PATCH 04/11] add Apache license --- .../store/redis/RedisMetadata4TstService.java | 16 ++++++++++++++ .../store/redis/RedisMetadataReportTest.java | 16 ++++++++++++++ .../ZookeeperMetadataReport4TstService.java | 16 ++++++++++++++ .../ZookeeperMetadataReportTest.java | 21 +++++++++++++++++-- 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadata4TstService.java b/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadata4TstService.java index a08849d2a40..0a8d51ba6a3 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadata4TstService.java +++ b/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadata4TstService.java @@ -1,3 +1,19 @@ +/* + * 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 org.apache.dubbo.metadata.store.redis; /** diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java index 85966b215e7..deb08de1c18 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java @@ -1,3 +1,19 @@ +/* + * 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 org.apache.dubbo.metadata.store.redis; import org.apache.dubbo.common.Constants; diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport4TstService.java b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport4TstService.java index 0b9f2a0d674..cea8b272379 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport4TstService.java +++ b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport4TstService.java @@ -1,3 +1,19 @@ +/* + * 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 org.apache.dubbo.metadata.store.zookeeper; /** diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java index 380e10708ce..583e90b73ae 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java @@ -1,7 +1,21 @@ +/* + * 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 org.apache.dubbo.metadata.store.zookeeper; -import com.google.gson.Gson; -import org.apache.curator.test.TestingServer; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; @@ -9,6 +23,9 @@ import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; import org.apache.dubbo.metadata.identifier.MetadataIdentifier; import org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter; + +import com.google.gson.Gson; +import org.apache.curator.test.TestingServer; import org.junit.After; import org.junit.Assert; import org.junit.Before; From 5cfb963ca6fa972c7965686dc4919e0783b5bcd8 Mon Sep 17 00:00:00 2001 From: cvictory Date: Thu, 27 Dec 2018 20:03:06 +0800 Subject: [PATCH 05/11] edit comments , edit metadata identify path --- .../apache/dubbo/metadata/identifier/MetadataIdentifier.java | 2 +- .../apache/dubbo/metadata/store/redis/RedisMetadataReport.java | 2 +- .../dubbo/metadata/store/redis/RedisMetadataReportFactory.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java index 85135a011c5..81c3d45bad8 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java +++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/identifier/MetadataIdentifier.java @@ -68,7 +68,7 @@ private String getFilePathKey() { public String getFilePathKey(String pathTag) { return toServicePath() + Constants.PATH_SEPARATOR + pathTag + Constants.PATH_SEPARATOR + (version == null ? "" : (version + Constants.PATH_SEPARATOR)) - + (group == null ? "" : (group + Constants.PATH_SEPARATOR)) + side + getApplication(); + + (group == null ? "" : (group + Constants.PATH_SEPARATOR)) + side + Constants.PATH_SEPARATOR + getApplication(); } private String toServicePath() { diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java index f86e337b45a..19ee7a7e3eb 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java +++ b/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReport.java @@ -27,7 +27,7 @@ import redis.clients.jedis.JedisPoolConfig; /** - * ZookeeperRegistry + * RedisMetadataReport */ public class RedisMetadataReport extends AbstractMetadataReport { diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java b/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java index f3f633eb548..b507dbec21d 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java +++ b/dubbo-metadata-report/dubbo-metadata-report-redis/src/main/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportFactory.java @@ -21,7 +21,7 @@ import org.apache.dubbo.metadata.support.AbstractMetadataReportFactory; /** - * ZookeeperRegistryFactory. + * RedisMetadataReportFactory. */ public class RedisMetadataReportFactory extends AbstractMetadataReportFactory { From 70b8d0cdaf804925d39cf265642b6b656c09161b Mon Sep 17 00:00:00 2001 From: "ken.lj" Date: Thu, 27 Dec 2018 20:32:53 +0800 Subject: [PATCH 06/11] temporarily ignore UT ZookeeperMetadataReportTest --- .../metadata/store/zookeeper/ZookeeperMetadataReportTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java index 583e90b73ae..2d79d1f1404 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java @@ -29,6 +29,7 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import java.util.HashMap; @@ -37,6 +38,7 @@ /** * 2018/10/9 */ +@Ignore("Keeps fail on Travis") public class ZookeeperMetadataReportTest { private TestingServer zkServer; private ZookeeperMetadataReport zookeeperMetadataReport; From ca7d64173c6d63dd4cbd82ca208bdb036a0e167e Mon Sep 17 00:00:00 2001 From: "ken.lj" Date: Thu, 27 Dec 2018 21:05:55 +0800 Subject: [PATCH 07/11] temporarily ignore UT RegistryDataConfigTest --- .../java/org/apache/dubbo/config/RegistryDataConfigTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryDataConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryDataConfigTest.java index 881a7ed4098..445b150b711 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryDataConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryDataConfigTest.java @@ -1,13 +1,12 @@ package org.apache.dubbo.config; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import java.util.Map; -/** - * @author cvictory ON 2018/11/14 - */ +@Ignore("Waiting for cvictory to fix") public class RegistryDataConfigTest { @Test From 5ea4fa531f9ec5ae446d4cb1ef2417b53712bd46 Mon Sep 17 00:00:00 2001 From: "ken.lj" Date: Thu, 27 Dec 2018 21:32:34 +0800 Subject: [PATCH 08/11] add license and reformat --- ...leReferenceAnnotationBeanPostProcessor.java | 1 + .../CompatibleReferenceBeanBuilder.java | 1 + ...ibleServiceAnnotationBeanPostProcessor.java | 1 + .../java/org/apache/dubbo/cache/CacheTest.java | 3 ++- .../dubbo/config/ApplicationConfigTest.java | 1 + .../dubbo/config/ArgumentConfigTest.java | 4 ++-- .../org/apache/dubbo/config/ConfigTest.java | 1 + .../dubbo/config/ConsumerConfigTest.java | 4 ++-- .../apache/dubbo/config/MethodConfigTest.java | 7 ++++--- .../dubbo/config/ProtocolConfigTest.java | 3 +-- .../dubbo/config/ReferenceConfigTest.java | 4 ++-- .../dubbo/config/RegistryConfigTest.java | 1 + .../dubbo/config/RegistryDataConfigTest.java | 16 ++++++++++++++++ .../org/apache/dubbo/echo/EchoServiceTest.java | 8 ++++---- .../org/apache/dubbo/filter/FilterTest.java | 2 +- .../org/apache/dubbo/filter/MyInvoker.java | 2 +- .../dubbo/generic/GenericServiceTest.java | 4 +++- .../dubbo/serialization/SerializationTest.java | 1 + .../apache/dubbo/service/ComplexObject.java | 18 ++++++++++++++++-- 19 files changed, 61 insertions(+), 21 deletions(-) diff --git a/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceAnnotationBeanPostProcessor.java b/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceAnnotationBeanPostProcessor.java index 544b1cb0bdc..d6826a5f819 100644 --- a/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceAnnotationBeanPostProcessor.java +++ b/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceAnnotationBeanPostProcessor.java @@ -19,6 +19,7 @@ import org.apache.dubbo.config.spring.ReferenceBean; import com.alibaba.dubbo.config.annotation.Reference; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeanUtils; diff --git a/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceBeanBuilder.java b/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceBeanBuilder.java index cb2ba68a51a..e9276a96cfe 100644 --- a/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceBeanBuilder.java +++ b/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleReferenceBeanBuilder.java @@ -22,6 +22,7 @@ import org.apache.dubbo.config.spring.convert.converter.StringArrayToStringConverter; import com.alibaba.dubbo.config.annotation.Reference; + import org.springframework.context.ApplicationContext; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.support.DefaultConversionService; diff --git a/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleServiceAnnotationBeanPostProcessor.java b/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleServiceAnnotationBeanPostProcessor.java index 7c87087dc9a..b71adfdbd77 100644 --- a/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleServiceAnnotationBeanPostProcessor.java +++ b/dubbo-compatible/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/CompatibleServiceAnnotationBeanPostProcessor.java @@ -22,6 +22,7 @@ import org.apache.dubbo.config.spring.context.annotation.DubboClassPathBeanDefinitionScanner; import com.alibaba.dubbo.config.annotation.Service; + import org.springframework.beans.BeansException; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.BeanClassLoaderAware; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/cache/CacheTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/cache/CacheTest.java index 6ff4d8b4ae2..7084bd2181e 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/cache/CacheTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/cache/CacheTest.java @@ -17,13 +17,14 @@ package org.apache.dubbo.cache; +import org.apache.dubbo.rpc.RpcInvocation; + import com.alibaba.dubbo.cache.Cache; import com.alibaba.dubbo.cache.CacheFactory; import com.alibaba.dubbo.common.URL; import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Invoker; -import org.apache.dubbo.rpc.RpcInvocation; import org.junit.Assert; import org.junit.Test; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java index fe4c2ff537e..ef4cd390c00 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ApplicationConfigTest.java @@ -21,6 +21,7 @@ import com.alibaba.dubbo.config.ApplicationConfig; import com.alibaba.dubbo.config.MonitorConfig; import com.alibaba.dubbo.config.RegistryConfig; + import org.junit.Test; import java.util.Collections; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ArgumentConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ArgumentConfigTest.java index 2f73c515910..18e149b4858 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ArgumentConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ArgumentConfigTest.java @@ -17,13 +17,13 @@ package org.apache.dubbo.config; +import com.alibaba.dubbo.config.ArgumentConfig; + import org.junit.Test; import java.util.HashMap; import java.util.Map; -import com.alibaba.dubbo.config.ArgumentConfig; - import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.is; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConfigTest.java index 2e57fec1804..9300032f760 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConfigTest.java @@ -24,6 +24,7 @@ import com.alibaba.dubbo.config.ReferenceConfig; import com.alibaba.dubbo.config.RegistryConfig; import com.alibaba.dubbo.config.ServiceConfig; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java index 2b08c79d78a..386f218378f 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ConsumerConfigTest.java @@ -17,10 +17,10 @@ package org.apache.dubbo.config; -import org.junit.Test; - import com.alibaba.dubbo.config.ConsumerConfig; +import org.junit.Test; + import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java index e7e0601e2b3..033688612b4 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/MethodConfigTest.java @@ -17,12 +17,13 @@ package org.apache.dubbo.config; +import org.apache.dubbo.rpc.model.ConsumerMethodModel; +import org.apache.dubbo.service.Person; + import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.config.MethodConfig; import com.alibaba.dubbo.config.ArgumentConfig; +import com.alibaba.dubbo.config.MethodConfig; -import org.apache.dubbo.rpc.model.ConsumerMethodModel; -import org.apache.dubbo.service.Person; import org.hamcrest.Matchers; import org.junit.Test; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ProtocolConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ProtocolConfigTest.java index 48de8a1e6ee..f9e9ecd32f6 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ProtocolConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ProtocolConfigTest.java @@ -17,10 +17,9 @@ package org.apache.dubbo.config; -import com.alibaba.dubbo.rpc.Protocol; import com.alibaba.dubbo.config.ProtocolConfig; + import org.junit.Test; -import org.mockito.Mockito; import java.util.Collections; import java.util.HashMap; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java index 7f331e60aea..0bda70e437d 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java @@ -21,10 +21,10 @@ import org.apache.dubbo.service.DemoServiceImpl; import com.alibaba.dubbo.config.ApplicationConfig; -import com.alibaba.dubbo.config.RegistryConfig; import com.alibaba.dubbo.config.ProtocolConfig; -import com.alibaba.dubbo.config.ServiceConfig; import com.alibaba.dubbo.config.ReferenceConfig; +import com.alibaba.dubbo.config.RegistryConfig; +import com.alibaba.dubbo.config.ServiceConfig; import org.junit.Test; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryConfigTest.java index 1511f42a667..00efb783615 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryConfigTest.java @@ -19,6 +19,7 @@ import com.alibaba.dubbo.common.Constants; import com.alibaba.dubbo.config.RegistryConfig; + import org.junit.Test; import java.util.Collections; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryDataConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryDataConfigTest.java index 445b150b711..930ed3f1ece 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryDataConfigTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryDataConfigTest.java @@ -1,3 +1,19 @@ +/* + * 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 org.apache.dubbo.config; import org.junit.Assert; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/echo/EchoServiceTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/echo/EchoServiceTest.java index b9d1cf761d8..2cba721f216 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/echo/EchoServiceTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/echo/EchoServiceTest.java @@ -17,16 +17,16 @@ package org.apache.dubbo.echo; -import com.alibaba.dubbo.rpc.service.EchoService; - import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; -import org.apache.dubbo.service.DemoService; -import org.apache.dubbo.service.DemoServiceImpl; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Protocol; import org.apache.dubbo.rpc.ProxyFactory; +import org.apache.dubbo.service.DemoService; +import org.apache.dubbo.service.DemoServiceImpl; + +import com.alibaba.dubbo.rpc.service.EchoService; import org.junit.Assert; import org.junit.Test; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/filter/FilterTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/filter/FilterTest.java index 53a2db320ca..14c20cf46c5 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/filter/FilterTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/filter/FilterTest.java @@ -17,12 +17,12 @@ package org.apache.dubbo.filter; -import org.apache.dubbo.service.MockInvocation; import org.apache.dubbo.rpc.Filter; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; +import org.apache.dubbo.service.MockInvocation; import org.junit.AfterClass; import org.junit.Assert; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/filter/MyInvoker.java b/dubbo-compatible/src/test/java/org/apache/dubbo/filter/MyInvoker.java index 5d69754c931..7ba9995f6dc 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/filter/MyInvoker.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/filter/MyInvoker.java @@ -17,12 +17,12 @@ package org.apache.dubbo.filter; import org.apache.dubbo.common.URL; -import org.apache.dubbo.service.DemoService; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Invoker; import org.apache.dubbo.rpc.Result; import org.apache.dubbo.rpc.RpcException; import org.apache.dubbo.rpc.RpcResult; +import org.apache.dubbo.service.DemoService; public class MyInvoker implements Invoker { diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/generic/GenericServiceTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/generic/GenericServiceTest.java index c18334af4b1..3d753b58b8b 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/generic/GenericServiceTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/generic/GenericServiceTest.java @@ -18,7 +18,6 @@ package org.apache.dubbo.generic; -import com.alibaba.fastjson.JSON; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.metadata.definition.ServiceDefinitionBuilder; @@ -33,6 +32,9 @@ import org.apache.dubbo.service.ComplexObject; import org.apache.dubbo.service.DemoService; import org.apache.dubbo.service.DemoServiceImpl; + +import com.alibaba.fastjson.JSON; + import org.junit.Assert; import org.junit.Test; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/serialization/SerializationTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/serialization/SerializationTest.java index b2adac43556..10706370e37 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/serialization/SerializationTest.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/serialization/SerializationTest.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.serialize.ObjectInput; import org.apache.dubbo.common.serialize.ObjectOutput; + import org.hamcrest.CoreMatchers; import org.hamcrest.Matchers; import org.junit.Before; diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/service/ComplexObject.java b/dubbo-compatible/src/test/java/org/apache/dubbo/service/ComplexObject.java index 5bcc9f6acab..5c895380302 100644 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/service/ComplexObject.java +++ b/dubbo-compatible/src/test/java/org/apache/dubbo/service/ComplexObject.java @@ -1,7 +1,21 @@ +/* + * 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 org.apache.dubbo.service; -import net.sf.cglib.beans.BeanMap; - import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; From cd560698d24aa521ba1b0b45a0ce725308da5af5 Mon Sep 17 00:00:00 2001 From: XiaoJie Li Date: Fri, 28 Dec 2018 13:02:42 +0800 Subject: [PATCH 09/11] add unit test to dubbo-registry/dubbo-registry-api and dubbo-registry/dubbo-registry-default (#3053) * add FailedRetryTaskTest.java --- .../registry/dubbo/DubboRegistryTest.java | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/DubboRegistryTest.java diff --git a/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/DubboRegistryTest.java b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/DubboRegistryTest.java new file mode 100644 index 00000000000..d6390ff5de8 --- /dev/null +++ b/dubbo-registry/dubbo-registry-default/src/test/java/org/apache/dubbo/registry/dubbo/DubboRegistryTest.java @@ -0,0 +1,155 @@ +/* + * 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 org.apache.dubbo.registry.dubbo; + +import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.registry.NotifyListener; +import org.apache.dubbo.registry.RegistryService; +import org.apache.dubbo.registry.support.FailbackRegistry; +import org.apache.dubbo.rpc.Invoker; +import org.apache.dubbo.rpc.RpcInvocation; +import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.mock; + +public class DubboRegistryTest { + + private static final Logger logger = LoggerFactory.getLogger(DubboRegistryTest.class); + + private DubboRegistry dubboRegistry; + + private URL registryURL; + + private URL serviceURL; + + private NotifyListener notifyListener; + + private Invoker invoker; + + private RegistryService registryService; + + @Before + public void setUp() { + registryURL = new URL(Constants.REGISTRY_PROTOCOL, NetUtils.getLocalHost(), NetUtils.getAvailablePort()) + .addParameter(Constants.CHECK_KEY, false) + .setServiceInterface(RegistryService.class.getName()); + serviceURL = new URL(DubboProtocol.NAME, NetUtils.getLocalHost(), NetUtils.getAvailablePort()) + .addParameter(Constants.CHECK_KEY, false) + .setServiceInterface(RegistryService.class.getName()); + + registryService = new MockDubboRegistry(registryURL); + + invoker = mock(Invoker.class); + given(invoker.getUrl()).willReturn(serviceURL); + given(invoker.getInterface()).willReturn(RegistryService.class); + given(invoker.invoke(new RpcInvocation())).willReturn(null); + + dubboRegistry = new DubboRegistry(invoker, registryService); + notifyListener = mock(NotifyListener.class); + } + + @Test + public void testRegister() { + dubboRegistry.register(serviceURL); + assertEquals(1, getRegistereds()); + } + + @Test + public void testUnRegister() { + assertEquals(0, getRegistereds()); + dubboRegistry.register(serviceURL); + assertEquals(1, getRegistereds()); + dubboRegistry.unregister(serviceURL); + assertEquals(0, getRegistereds()); + } + + @Test + public void testSubscribe() { + dubboRegistry.register(serviceURL); + assertEquals(1, getRegistereds()); + dubboRegistry.subscribe(serviceURL, notifyListener); + assertEquals(1, getSubscribeds()); + assertEquals(1, getNotifiedListeners()); + } + + @Test + public void testUnsubscribe() { + dubboRegistry.subscribe(serviceURL, notifyListener); + assertEquals(1, getSubscribeds()); + assertEquals(1, getNotifiedListeners()); + dubboRegistry.unsubscribe(serviceURL, notifyListener); + assertEquals(0, getNotifiedListeners()); + } + + private class MockDubboRegistry extends FailbackRegistry { + + private volatile boolean isAvaliable = false; + + public MockDubboRegistry(URL url) { + super(url); + } + + @Override + public void doRegister(URL url) { + logger.info("Begin to register: " + url); + isAvaliable = true; + } + + @Override + public void doUnregister(URL url) { + logger.info("Begin to ungister: " + url); + isAvaliable = false; + } + + @Override + public void doSubscribe(URL url, NotifyListener listener) { + logger.info("Begin to subscribe: " + url); + } + + @Override + public void doUnsubscribe(URL url, NotifyListener listener) { + logger.info("Begin to unSubscribe: " + url); + } + + @Override + public boolean isAvailable() { + return isAvaliable; + } + } + + private int getNotifiedListeners() { + return dubboRegistry.getSubscribed().get(serviceURL).size(); + } + + private int getRegistereds() { + return dubboRegistry.getRegistered().size(); + } + + private int getSubscribeds() { + return dubboRegistry.getSubscribed().size(); + } +} From 2fbdecf823fcd6b05d43a12e6fee585cd599b640 Mon Sep 17 00:00:00 2001 From: cvictory Date: Fri, 28 Dec 2018 19:48:41 +0800 Subject: [PATCH 10/11] fix async store test fail issue --- .../dubbo/config/RegistryDataConfigTest.java | 102 ------------------ .../dubbo/config/RegistryDataConfig.java | 24 ----- .../store/redis/RedisMetadataReportTest.java | 30 +++++- .../ZookeeperMetadataReportTest.java | 4 +- 4 files changed, 28 insertions(+), 132 deletions(-) delete mode 100644 dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryDataConfigTest.java diff --git a/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryDataConfigTest.java b/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryDataConfigTest.java deleted file mode 100644 index 930ed3f1ece..00000000000 --- a/dubbo-compatible/src/test/java/org/apache/dubbo/config/RegistryDataConfigTest.java +++ /dev/null @@ -1,102 +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 org.apache.dubbo.config; - -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -import java.util.Map; - -@Ignore("Waiting for cvictory to fix") -public class RegistryDataConfigTest { - - @Test - public void testProviderNoValue(){ - RegistryDataConfig registryDataConfig = new RegistryDataConfig(); - registryDataConfig.setSimpleProviderConfig(false); - registryDataConfig.setExtraProviderKeys("xxx,sss"); - Map result = registryDataConfig.transferToMap(); - Assert.assertTrue(result.isEmpty()); - } - - @Test - public void testProviderNoParamKey(){ - RegistryDataConfig registryDataConfig = new RegistryDataConfig(); - registryDataConfig.setSimpleProviderConfig(true); - Map result = registryDataConfig.transferToMap(); - Assert.assertFalse(result.isEmpty()); - Assert.assertEquals(result.get("simpleProviderConfig"), "true"); - Assert.assertNull(result.get("extraProviderKeys")); - } - - @Test - public void testProviderHasParamKey(){ - RegistryDataConfig registryDataConfig = new RegistryDataConfig(); - registryDataConfig.setSimpleProviderConfig(true); - registryDataConfig.setExtraProviderKeys("xxx,sss"); - Map result = registryDataConfig.transferToMap(); - Assert.assertFalse(result.isEmpty()); - Assert.assertEquals(result.get("simpleProviderConfig"), "true"); - Assert.assertEquals(result.get("extraProviderKeys"), "xxx,sss"); - } - - @Test - public void testConsumerNoValue(){ - RegistryDataConfig registryDataConfig = new RegistryDataConfig(); - registryDataConfig.setSimpleConsumerConfig(false); - registryDataConfig.setExtraConsumerKeys("xxx,sss"); - Map result = registryDataConfig.transferToMap(); - Assert.assertTrue(result.isEmpty()); - } - - @Test - public void testConsumerNoParamKey(){ - RegistryDataConfig registryDataConfig = new RegistryDataConfig(); - registryDataConfig.setSimpleConsumerConfig(true); - Map result = registryDataConfig.transferToMap(); - Assert.assertFalse(result.isEmpty()); - Assert.assertEquals(result.get("simpleConsumerConfig"), "true"); - Assert.assertNull(result.get("extraConsumerKeys")); - } - - @Test - public void testConsumerHasParamKey(){ - RegistryDataConfig registryDataConfig = new RegistryDataConfig(); - registryDataConfig.setSimpleConsumerConfig(true); - registryDataConfig.setExtraConsumerKeys("xxx,sss"); - Map result = registryDataConfig.transferToMap(); - Assert.assertFalse(result.isEmpty()); - Assert.assertEquals(result.get("simpleConsumerConfig"), "true"); - Assert.assertEquals(result.get("extraConsumerKeys"), "xxx,sss"); - } - - @Test - public void testMixHasParamKey(){ - RegistryDataConfig registryDataConfig = new RegistryDataConfig(); - registryDataConfig.setSimpleConsumerConfig(true); - registryDataConfig.setExtraConsumerKeys("xxx,sss"); - registryDataConfig.setSimpleProviderConfig(true); - registryDataConfig.setExtraProviderKeys("yyy,xxx"); - Map result = registryDataConfig.transferToMap(); - Assert.assertTrue(result.size() == 4); - Assert.assertEquals(result.get("simpleProviderConfig"), "true"); - Assert.assertEquals(result.get("extraProviderKeys"), "yyy,xxx"); - Assert.assertEquals(result.get("simpleConsumerConfig"), "true"); - Assert.assertEquals(result.get("extraConsumerKeys"), "xxx,sss"); - } -} diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryDataConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryDataConfig.java index 1b41e2eb8f4..f96044dd991 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryDataConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryDataConfig.java @@ -16,12 +16,6 @@ */ package org.apache.dubbo.config; -import org.apache.dubbo.common.Constants; -import org.apache.dubbo.common.utils.StringUtils; - -import java.util.HashMap; -import java.util.Map; - /** * 2018/10/31 */ @@ -33,24 +27,6 @@ public class RegistryDataConfig extends AbstractConfig { private Boolean simpleConsumerConfig; private String extraConsumerKeys; - Map transferToMap() { - Map map = new HashMap(4); - if (simpleProviderConfig != null && simpleProviderConfig) { - map.put(Constants.SIMPLE_PROVIDER_CONFIG_KEY, Boolean.TRUE.toString()); - if (StringUtils.isNotEmpty(extraProviderKeys)) { - map.put(Constants.EXTRA_PROVIDER_CONFIG_KEYS_KEY, extraProviderKeys.trim()); - } - } - if (simpleConsumerConfig != null && simpleConsumerConfig) { - map.put(Constants.SIMPLE_CONSUMER_CONFIG_KEY, Boolean.TRUE.toString()); - if (StringUtils.isNotEmpty(extraConsumerKeys)) { - map.put(Constants.EXTRA_CONSUMER_CONFIG_KEYS_KEY, extraConsumerKeys.trim()); - } - } - - return map; - } - public Boolean getSimpleProviderConfig() { return simpleProviderConfig; } diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java index deb08de1c18..8c6e32dca09 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java @@ -36,6 +36,7 @@ import java.util.HashMap; import java.util.Map; +import static org.apache.dubbo.common.Constants.SYNC_REPORT_KEY; import static org.apache.dubbo.metadata.store.MetadataReport.META_DATA_SOTRE_TAG; /** @@ -43,6 +44,7 @@ */ public class RedisMetadataReportTest { RedisMetadataReport redisMetadataReport; + RedisMetadataReport syncRedisMetadataReport; RedisServer redisServer; @Before @@ -52,6 +54,8 @@ public void constructor() throws IOException { this.redisServer.start(); URL registryUrl = URL.valueOf("redis://localhost:" + redisPort); redisMetadataReport = (RedisMetadataReport) new RedisMetadataReportFactory().createMetadataReport(registryUrl); + URL asyncRegistryUrl = URL.valueOf("redis://localhost:" + redisPort + "?" + SYNC_REPORT_KEY + "=true"); + syncRedisMetadataReport = (RedisMetadataReport) new RedisMetadataReportFactory().createMetadataReport(registryUrl); } @After @@ -61,14 +65,23 @@ public void tearDown() throws Exception { @Test - public void testStoreProvider() throws ClassNotFoundException { + public void testAsyncStoreProvider() throws ClassNotFoundException { + testStoreProvider(redisMetadataReport, "1.0.0.redis.md.p1", 3000); + } + + @Test + public void testSyncStoreProvider() throws ClassNotFoundException { + testStoreProvider(syncRedisMetadataReport, "1.0.0.redis.md.p2", 3); + } + + private void testStoreProvider(RedisMetadataReport redisMetadataReport, String version, long moreTime) throws ClassNotFoundException { String interfaceName = "org.apache.dubbo.metadata.store.redis.RedisMetadata4TstService"; - String version = "1.0.0.redis.md"; String group = null; String application = "vic.redis.md"; MetadataIdentifier providerMetadataIdentifier = storePrivider(redisMetadataReport, interfaceName, version, group, application); Jedis jedis = null; try { + Thread.sleep(moreTime); jedis = redisMetadataReport.pool.getResource(); String value = jedis.get(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY) + META_DATA_SOTRE_TAG); Assert.assertNotNull(value); @@ -87,14 +100,23 @@ public void testStoreProvider() throws ClassNotFoundException { } @Test - public void testStoreConsumer() throws ClassNotFoundException { + public void testAsyncStoreConsumer() throws ClassNotFoundException { + testStoreProvider(redisMetadataReport, "1.0.0.redis.md.c1", 3000); + } + + @Test + public void testSyncStoreConsumer() throws ClassNotFoundException { + testStoreProvider(syncRedisMetadataReport, "1.0.0.redis.md.c2", 3); + } + + private void testStoreConsumer(RedisMetadataReport redisMetadataReport, String version, long moreTime) throws ClassNotFoundException { String interfaceName = "org.apache.dubbo.metadata.store.redis.RedisMetadata4TstService"; - String version = "1.0.0.redis.md"; String group = null; String application = "vic.redis.md"; MetadataIdentifier consumerMetadataIdentifier = storeConsumer(redisMetadataReport, interfaceName, version, group, application); Jedis jedis = null; try { + Thread.sleep(moreTime); jedis = redisMetadataReport.pool.getResource(); String value = jedis.get(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY) + META_DATA_SOTRE_TAG); Assert.assertEquals(value, "{\"paramConsumerTest\":\"redisCm\"}"); diff --git a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java index 2d79d1f1404..d3a4e7a445e 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-zookeeper/src/test/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReportTest.java @@ -123,7 +123,7 @@ private MetadataIdentifier storePrivider(ZookeeperMetadataReport zookeeperMetada FullServiceDefinition fullServiceDefinition = ServiceDefinitionBuilder.buildFullDefinition(interfaceClass, url.getParameters()); zookeeperMetadataReport.storeProviderMetadata(providerMetadataIdentifier, fullServiceDefinition); - Thread.sleep(300); + Thread.sleep(2000); return providerMetadataIdentifier; } @@ -137,7 +137,7 @@ private MetadataIdentifier storeConsumer(ZookeeperMetadataReport zookeeperMetada Map tmp = new HashMap<>(); tmp.put("paramConsumerTest", "zkCm"); zookeeperMetadataReport.storeConsumerMetadata(consumerMetadataIdentifier, tmp); - Thread.sleep(300); + Thread.sleep(2000); return consumerMetadataIdentifier; } From 09cbf8f616876b205b11aee942d90cc43f55c904 Mon Sep 17 00:00:00 2001 From: cvictory Date: Fri, 28 Dec 2018 20:05:19 +0800 Subject: [PATCH 11/11] fix async store test fail issue --- .../support/AbstractMetadataReportTest.java | 2 +- .../store/redis/RedisMetadataReportTest.java | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportTest.java index 75b4465925c..d9a8e2d99cf 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/test/java/org/apache/dubbo/metadata/support/AbstractMetadataReportTest.java @@ -66,7 +66,7 @@ public void testStoreProviderUsual() throws ClassNotFoundException, InterruptedE String group = null; String application = "vic"; MetadataIdentifier providerMetadataIdentifier = storePrivider(abstractMetadataReport, interfaceName, version, group, application); - Thread.sleep(1000); + Thread.sleep(1500); Assert.assertNotNull(abstractMetadataReport.store.get(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY))); } diff --git a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java b/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java index 8c6e32dca09..82fc12b945f 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java +++ b/dubbo-metadata-report/dubbo-metadata-report-redis/src/test/java/org/apache/dubbo/metadata/store/redis/RedisMetadataReportTest.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.metadata.store.redis; +import com.google.gson.Gson; import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.utils.NetUtils; @@ -23,8 +24,6 @@ import org.apache.dubbo.metadata.definition.model.FullServiceDefinition; import org.apache.dubbo.metadata.identifier.MetadataIdentifier; import org.apache.dubbo.rpc.RpcException; - -import com.google.gson.Gson; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -81,9 +80,14 @@ private void testStoreProvider(RedisMetadataReport redisMetadataReport, String v MetadataIdentifier providerMetadataIdentifier = storePrivider(redisMetadataReport, interfaceName, version, group, application); Jedis jedis = null; try { - Thread.sleep(moreTime); jedis = redisMetadataReport.pool.getResource(); - String value = jedis.get(providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY) + META_DATA_SOTRE_TAG); + String keyTmp = providerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY) + META_DATA_SOTRE_TAG; + String value = jedis.get(keyTmp); + if (value == null) { + Thread.sleep(moreTime); + value = jedis.get(keyTmp); + } + Assert.assertNotNull(value); Gson gson = new Gson(); @@ -101,12 +105,12 @@ private void testStoreProvider(RedisMetadataReport redisMetadataReport, String v @Test public void testAsyncStoreConsumer() throws ClassNotFoundException { - testStoreProvider(redisMetadataReport, "1.0.0.redis.md.c1", 3000); + testStoreConsumer(redisMetadataReport, "1.0.0.redis.md.c1", 3000); } @Test public void testSyncStoreConsumer() throws ClassNotFoundException { - testStoreProvider(syncRedisMetadataReport, "1.0.0.redis.md.c2", 3); + testStoreConsumer(syncRedisMetadataReport, "1.0.0.redis.md.c2", 3); } private void testStoreConsumer(RedisMetadataReport redisMetadataReport, String version, long moreTime) throws ClassNotFoundException { @@ -116,9 +120,13 @@ private void testStoreConsumer(RedisMetadataReport redisMetadataReport, String v MetadataIdentifier consumerMetadataIdentifier = storeConsumer(redisMetadataReport, interfaceName, version, group, application); Jedis jedis = null; try { - Thread.sleep(moreTime); jedis = redisMetadataReport.pool.getResource(); - String value = jedis.get(consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY) + META_DATA_SOTRE_TAG); + String keyTmp = consumerMetadataIdentifier.getUniqueKey(MetadataIdentifier.KeyTypeEnum.UNIQUE_KEY) + META_DATA_SOTRE_TAG; + String value = jedis.get(keyTmp); + if (value == null) { + Thread.sleep(moreTime); + value = jedis.get(keyTmp); + } Assert.assertEquals(value, "{\"paramConsumerTest\":\"redisCm\"}"); } catch (Throwable e) { throw new RpcException("Failed to put to redis . cause: " + e.getMessage(), e);