This is an automated email from the ASF dual-hosted git repository. liubao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit 3dbfb87eb6249f3ad41ea7514d1a73ec6e193bfe Author: weichao666 <[email protected]> AuthorDate: Thu Mar 15 22:03:42 2018 +0800 fix ut --- .../client/http/ServiceRegistryClientImpl.java | 2 +- .../registry/AbstractServiceRegistry.java | 24 ++++++++++++++++------ .../registry/TestServiceRegistryFactory.java | 13 ++---------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java index e916338..ab7f597 100644 --- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java +++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java @@ -65,7 +65,7 @@ import io.vertx.core.Handler; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpClientResponse; -public class ServiceRegistryClientImpl implements ServiceRegistryClient { +public final class ServiceRegistryClientImpl implements ServiceRegistryClient { private static final Logger LOGGER = LoggerFactory.getLogger(ServiceRegistryClientImpl.class); private IpPortManager ipPortManager; diff --git a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java index b524e2b..e30bf6f 100644 --- a/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java +++ b/service-registry/src/main/java/org/apache/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java @@ -104,9 +104,6 @@ public abstract class AbstractServiceRegistry implements ServiceRegistry { } serviceCenterInfo = srClient.getServiceCenterInfo(); - if (serviceCenterInfo == null) { - throw new IllegalStateException("Failed to load servicecenter info"); - } createServiceCenterTask(); @@ -184,17 +181,32 @@ public abstract class AbstractServiceRegistry implements ServiceRegistry { } private void loadFrameworkVersions() { - Version scVersion = VersionUtils.getOrCreate(serviceCenterInfo.getVersion()); - Version frameworkVersion = VersionUtils.getOrCreate(Const.SERVICECENTER_FRAMEWORK_VERSION); Framework framework = new Framework(); framework.setName(CONFIG_FRAMEWORK_DEFAULT_NAME); - if (scVersion.compareTo(frameworkVersion) >= 0) { + + if (needSetFrameworkVersion()) { framework.setVersion(FrameworkVersions.allVersions()); } microservice.setFramework(framework); microservice.setRegisterBy(CONFIG_DEFAULT_REGISTER_BY); } + private boolean needSetFrameworkVersion() { + if (serviceCenterInfo == null) { + LOGGER.warn("Server startup when service center not started and cannot retrieve version info, assume latest."); + return true; + } else { + Version scVersion = VersionUtils.getOrCreate(serviceCenterInfo.getVersion()); + Version frameworkVersion = VersionUtils.getOrCreate(Const.SERVICECENTER_FRAMEWORK_VERSION); + + if (scVersion.compareTo(frameworkVersion) >= 0) { + return true; + } else { + return false; + } + } + } + private void loadStaticConfiguration() { // TODO 如果yaml定义了paths规则属性,替换默认值,现需要DynamicPropertyFactory支持数组获取 List<BasePath> paths = microservice.getPaths(); diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestServiceRegistryFactory.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestServiceRegistryFactory.java index d6357a0..1e62441 100644 --- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestServiceRegistryFactory.java +++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/registry/TestServiceRegistryFactory.java @@ -20,7 +20,6 @@ package org.apache.servicecomb.serviceregistry.registry; import java.util.Collections; import org.apache.servicecomb.serviceregistry.ServiceRegistry; -import org.apache.servicecomb.serviceregistry.api.registry.ServiceCenterInfo; import org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl; import org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient; import org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl; @@ -43,16 +42,8 @@ public class TestServiceRegistryFactory { ServiceRegistryConfig serviceRegistryConfig = ServiceRegistryConfig.INSTANCE; MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(Collections.emptyList()); - ServiceRegistry serviceRegistry = new RemoteServiceRegistry(eventBus, serviceRegistryConfig, microserviceDefinition) { - @Override - protected ServiceRegistryClient createServiceRegistryClient() { - return new ServiceRegistryClientImpl(ipPortManager) { - public ServiceCenterInfo getServiceCenterInfo() { - return new ServiceCenterInfo(); - } - }; - } - }; + ServiceRegistry serviceRegistry = + ServiceRegistryFactory.create(eventBus, serviceRegistryConfig, microserviceDefinition); serviceRegistry.init(); ServiceRegistryClient client = serviceRegistry.getServiceRegistryClient(); Assert.assertTrue(client instanceof ServiceRegistryClientImpl); -- To stop receiving notification emails like this one, please contact [email protected].
