This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit adc3367364d57968bb6475cba49474fa9a2f612f Author: wujimin <[email protected]> AuthorDate: Mon Jan 22 12:45:25 2018 +0800 SCB-272 do findServiceInstances after registered self to SC. --- .../client/http/ServiceRegistryClientImpl.java | 9 +++++++++ .../client/http/TestServiceRegistryClientImpl.java | 13 +++++++++++++ 2 files changed, 22 insertions(+) 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 64f9a93..d48d0bc 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 @@ -583,6 +583,15 @@ public final class ServiceRegistryClientImpl implements ServiceRegistryClient { @Override public MicroserviceInstances findServiceInstances(String consumerId, String appId, String serviceName, String versionRule, String revision) { + // must register self first, and then invoke findServiceInstances + if (consumerId == null) { + LOGGER.error("find microservice instance {}/{}/{} failed, not registered to serviceCenter.", + appId, + serviceName, + versionRule); + return null; + } + MicroserviceInstances microserviceInstances = new MicroserviceInstances(); IpPort ipPort = ipPortManager.getAvailableAddress(); diff --git a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java index a171531..56af6d2 100644 --- a/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java +++ b/service-registry/src/test/java/org/apache/servicecomb/serviceregistry/client/http/TestServiceRegistryClientImpl.java @@ -29,6 +29,7 @@ import javax.xml.ws.Holder; import org.apache.log4j.Appender; import org.apache.log4j.Logger; import org.apache.log4j.spi.LoggingEvent; +import org.apache.servicecomb.foundation.common.net.IpPort; import org.apache.servicecomb.serviceregistry.api.registry.Microservice; import org.apache.servicecomb.serviceregistry.api.registry.MicroserviceFactory; import org.apache.servicecomb.serviceregistry.api.response.GetExistenceResponse; @@ -308,4 +309,16 @@ public class TestServiceRegistryClientImpl { public void testFindServiceInstance() { Assert.assertNull(oClient.findServiceInstance("aaa", "bbb")); } + + @Test + public void findServiceInstance_consumerId_null() { + new MockUp<IpPortManager>(ipPortManager) { + @Mock + IpPort getAvailableAddress() { + throw new Error("must not invoke this."); + } + }; + + Assert.assertNull(oClient.findServiceInstance(null, "appId", "serviceName", "1.0.0+")); + } } -- To stop receiving notification emails like this one, please contact [email protected].
