You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/01/09 02:06:46 UTC

[GitHub] wujimin closed pull request #486: [SCB-165] Service registry not given proper instances

wujimin closed pull request #486: [SCB-165] Service registry not given proper instances
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/486
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/src/main/java/io/servicecomb/core/definition/loader/DynamicSchemaLoader.java b/core/src/main/java/io/servicecomb/core/definition/loader/DynamicSchemaLoader.java
index 332b35a1f..08a3c8de9 100644
--- a/core/src/main/java/io/servicecomb/core/definition/loader/DynamicSchemaLoader.java
+++ b/core/src/main/java/io/servicecomb/core/definition/loader/DynamicSchemaLoader.java
@@ -39,7 +39,11 @@
  *   ?????????????????????
  *   ?????????????????
  *   ?????BootListener?????????producer??????????
+ *
+ * @Deprecated This class is deprecated because when making calls to a provider, schemas will be downloaded from service enter.
+ * And at provider, schemas will register to service center when starting up.
  */
+@Deprecated
 public class DynamicSchemaLoader {
   private static final Logger LOGGER = LoggerFactory.getLogger(DynamicSchemaLoader.class);
 
diff --git a/foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/net/IpPort.java b/foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/net/IpPort.java
index 601b063c8..15dee9d80 100644
--- a/foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/net/IpPort.java
+++ b/foundations/foundation-common/src/main/java/io/servicecomb/foundation/common/net/IpPort.java
@@ -53,6 +53,28 @@ public void setPort(int port) {
     this.port = port;
   }
 
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (o == null || getClass() != o.getClass()) {
+      return false;
+    }
+
+    IpPort ipPort = (IpPort) o;
+
+    if (port != ipPort.port) {
+      return false;
+    }
+    return hostOrIp.equals(ipPort.hostOrIp);
+  }
+
+  @Override
+  public String toString() {
+    return hostOrIp + ":" + port;
+  }
+
   public InetSocketAddress getSocketAddress() {
     if (socketAddress == null) {
       synchronized (lock) {
diff --git a/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/net/TestIpPort.java b/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/net/TestIpPort.java
index 21dcda7fb..a6dbdcfab 100644
--- a/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/net/TestIpPort.java
+++ b/foundations/foundation-common/src/test/java/io/servicecomb/foundation/common/net/TestIpPort.java
@@ -30,5 +30,9 @@ public void testIpPort() {
     Assert.assertEquals(inst1.getHostOrIp(), inst2.getHostOrIp());
     Assert.assertEquals(inst1.getPort(), inst2.getPort());
     Assert.assertEquals(inst1.getSocketAddress().getHostName(), inst2.getSocketAddress().getHostName());
+    Assert.assertEquals(inst1, inst1);
+    Assert.assertEquals(inst1, inst2);
+    Assert.assertEquals(inst1.toString(), "localhost:3333");
+    Assert.assertNotEquals(inst1, new Object());
   }
 }
diff --git a/service-registry/src/main/java/io/servicecomb/serviceregistry/client/IpPortManager.java b/service-registry/src/main/java/io/servicecomb/serviceregistry/client/IpPortManager.java
index f6a681aa5..6bd4b2aed 100644
--- a/service-registry/src/main/java/io/servicecomb/serviceregistry/client/IpPortManager.java
+++ b/service-registry/src/main/java/io/servicecomb/serviceregistry/client/IpPortManager.java
@@ -19,6 +19,7 @@
 
 import static io.servicecomb.serviceregistry.api.Const.REGISTRY_APP_ID;
 import static io.servicecomb.serviceregistry.api.Const.REGISTRY_SERVICE_NAME;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Random;
@@ -46,10 +47,10 @@
 
   private ArrayList<IpPort> defaultIpPort;
 
-  private InstanceCache instanceCache = null;
-
   private AtomicInteger currentAvailableIndex;
 
+  private boolean autoDiscoveryInited = false;
+
   public IpPortManager(ServiceRegistryConfig serviceRegistryConfig, InstanceCacheManager instanceCacheManager) {
     this.serviceRegistryConfig = serviceRegistryConfig;
     this.instanceCacheManager = instanceCacheManager;
@@ -65,45 +66,48 @@ public IpPortManager(ServiceRegistryConfig serviceRegistryConfig, InstanceCacheM
 
   // we have to do this operation after the first time setup has already done
   public void initAutoDiscovery() {
-    if (this.serviceRegistryConfig.isRegistryAutoDiscovery()) {
-      instanceCache = instanceCacheManager.getOrCreate(REGISTRY_APP_ID,
+    if (!autoDiscoveryInited && this.serviceRegistryConfig.isRegistryAutoDiscovery()) {
+      instanceCacheManager.getOrCreate(REGISTRY_APP_ID,
           REGISTRY_SERVICE_NAME,
           DefinitionConst.VERSION_RULE_LATEST);
+      autoDiscoveryInited = true;
     }
   }
 
-  public IpPort getAvailableAddress(boolean invalidate) {
-    int index;
-    if (invalidate) {
-      index = currentAvailableIndex.incrementAndGet();
-    } else {
-      index = currentAvailableIndex.get();
+  public IpPort getNextAvailableAddress(IpPort failedIpPort) {
+    int currentIndex = currentAvailableIndex.get();
+    IpPort current = getAvailableAddress(currentIndex);
+    if (current.equals(failedIpPort)) {
+      currentAvailableIndex.compareAndSet(currentIndex, currentIndex + 1);
+      current = getAvailableAddress();
     }
 
+    LOGGER.info("Change service center address from {} to {}", failedIpPort.toString(), current.toString());
+    return current;
+  }
+
+  public IpPort getAvailableAddress() {
+    return getAvailableAddress(currentAvailableIndex.get());
+  }
+
+  private IpPort getAvailableAddress(int index) {
     if (index < defaultIpPort.size()) {
-      return returnWithLog(invalidate, defaultIpPort.get(index));
+      return defaultIpPort.get(index);
     }
     List<CacheEndpoint> endpoints = getDiscoveredIpPort();
     if (endpoints == null || (index >= defaultIpPort.size() + endpoints.size())) {
       currentAvailableIndex.set(0);
-      return returnWithLog(invalidate, defaultIpPort.get(0));
+      return defaultIpPort.get(0);
     }
     CacheEndpoint nextEndpoint = endpoints.get(index - defaultIpPort.size());
-    return returnWithLog(invalidate, new URIEndpointObject(nextEndpoint.getEndpoint()));
-  }
-
-  private IpPort returnWithLog(boolean needLog, IpPort result) {
-    if (needLog) {
-      LOGGER.info("Using next service center address {}:{}.", result.getHostOrIp(), result.getPort());
-    }
-    return result;
+    return new URIEndpointObject(nextEndpoint.getEndpoint());
   }
 
   private List<CacheEndpoint> getDiscoveredIpPort() {
-    if (instanceCache == null) {
-      return new ArrayList<>(0);
+    if (!autoDiscoveryInited || !this.serviceRegistryConfig.isRegistryAutoDiscovery()) {
+      return null;
     }
-    instanceCache = instanceCacheManager.getOrCreate(REGISTRY_APP_ID,
+    InstanceCache instanceCache = instanceCacheManager.getOrCreate(REGISTRY_APP_ID,
         REGISTRY_SERVICE_NAME,
         DefinitionConst.VERSION_RULE_LATEST);
     return instanceCache.getOrCreateTransportMap().get(defaultTransport);
diff --git a/service-registry/src/main/java/io/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java b/service-registry/src/main/java/io/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
index 53ffe5c10..3a5e84f91 100644
--- a/service-registry/src/main/java/io/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
+++ b/service-registry/src/main/java/io/servicecomb/serviceregistry/client/http/ServiceRegistryClientImpl.java
@@ -50,8 +50,8 @@
 import io.servicecomb.serviceregistry.api.response.GetSchemaResponse;
 import io.servicecomb.serviceregistry.api.response.GetServiceResponse;
 import io.servicecomb.serviceregistry.api.response.HeartbeatResponse;
-import io.servicecomb.serviceregistry.api.response.MicroserviceInstanceResponse;
 import io.servicecomb.serviceregistry.api.response.MicroserviceInstanceChangedEvent;
+import io.servicecomb.serviceregistry.api.response.MicroserviceInstanceResponse;
 import io.servicecomb.serviceregistry.api.response.RegisterInstanceResponse;
 import io.servicecomb.serviceregistry.client.ClientException;
 import io.servicecomb.serviceregistry.client.IpPortManager;
@@ -80,7 +80,7 @@ public void init() {
 
   private void retry(RequestContext requestContext, Handler<RestResponse> responseHandler) {
     LOGGER.warn("invoke service [{}] failed, retry.", requestContext.getUri());
-    requestContext.setIpPort(ipPortManager.getAvailableAddress(true));
+    requestContext.setIpPort(ipPortManager.getNextAvailableAddress(requestContext.getIpPort()));
     requestContext.setRetry(true);
     RestUtils.httpDo(requestContext, responseHandler);
   }
@@ -111,7 +111,8 @@ private void retry(RequestContext requestContext, Handler<RestResponse> response
               holder.value =
                   JsonUtils.readValue(bodyBuffer.getBytes(), cls);
             } catch (Exception e) {
-              LOGGER.warn(bodyBuffer.toString());
+              LOGGER.warn("read value failed and response message is {}",
+                  bodyBuffer.toString());
             }
             countDownLatch.countDown();
           });
@@ -137,7 +138,7 @@ private void retry(RequestContext requestContext, Handler<RestResponse> response
         } else {
           countDownLatch.countDown();
         }
-        
+
         return;
       }
 
@@ -154,7 +155,7 @@ private void retry(RequestContext requestContext, Handler<RestResponse> response
   @Override
   public List<Microservice> getAllMicroservices() {
     Holder<GetAllServicesResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     CountDownLatch countDownLatch = new CountDownLatch(1);
     RestUtils.get(ipPort,
@@ -175,7 +176,7 @@ private void retry(RequestContext requestContext, Handler<RestResponse> response
   @Override
   public String getMicroserviceId(String appId, String microserviceName, String versionRule) {
     Holder<GetExistenceResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     CountDownLatch countDownLatch = new CountDownLatch(1);
     RestUtils.get(ipPort,
@@ -203,7 +204,7 @@ public String getMicroserviceId(String appId, String microserviceName, String ve
   @Override
   public boolean isSchemaExist(String microserviceId, String schemaId) {
     Holder<GetExistenceResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     CountDownLatch countDownLatch = new CountDownLatch(1);
     RestUtils.get(ipPort,
@@ -226,7 +227,7 @@ public boolean isSchemaExist(String microserviceId, String schemaId) {
   @Override
   public boolean registerSchema(String microserviceId, String schemaId, String schemaContent) {
     Holder<ResponseWrapper> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     try {
       CreateSchemaRequest request = new CreateSchemaRequest();
@@ -271,7 +272,7 @@ public boolean registerSchema(String microserviceId, String schemaId, String sch
   @Override
   public String getSchema(String microserviceId, String schemaId) {
     Holder<GetSchemaResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     CountDownLatch countDownLatch = new CountDownLatch(1);
     RestUtils.get(ipPort,
@@ -296,7 +297,7 @@ public String getSchema(String microserviceId, String schemaId) {
   @Override
   public String registerMicroservice(Microservice microservice) {
     Holder<CreateServiceResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
     try {
       CreateServiceRequest request = new CreateServiceRequest();
       request.setService(microservice);
@@ -328,7 +329,7 @@ public String registerMicroservice(Microservice microservice) {
   @Override
   public Microservice getMicroservice(String microserviceId) {
     Holder<GetServiceResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     CountDownLatch countDownLatch = new CountDownLatch(1);
     RestUtils.get(ipPort,
@@ -349,7 +350,7 @@ public Microservice getMicroservice(String microserviceId) {
   @Override
   public String registerMicroserviceInstance(MicroserviceInstance instance) {
     Holder<RegisterInstanceResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     try {
       RegisterInstanceRequest request = new RegisterInstanceRequest();
@@ -378,7 +379,7 @@ public String registerMicroserviceInstance(MicroserviceInstance instance) {
   @Override
   public List<MicroserviceInstance> getMicroserviceInstance(String consumerId, String providerId) {
     Holder<GetInstancesResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     CountDownLatch countDownLatch = new CountDownLatch(1);
     RestUtils.get(ipPort,
@@ -399,7 +400,7 @@ public String registerMicroserviceInstance(MicroserviceInstance instance) {
   @Override
   public boolean unregisterMicroserviceInstance(String microserviceId, String microserviceInstanceId) {
     Holder<HttpClientResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     CountDownLatch countDownLatch = new CountDownLatch(1);
     RestUtils.delete(ipPort,
@@ -426,7 +427,7 @@ public boolean unregisterMicroserviceInstance(String microserviceId, String micr
   @Override
   public HeartbeatResponse heartbeat(String microserviceId, String microserviceInstanceId) {
     Holder<HttpClientResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     CountDownLatch countDownLatch = new CountDownLatch(1);
     RestUtils.put(ipPort,
@@ -472,7 +473,7 @@ public void watch(String selfMicroserviceId, AsyncResultCallback<MicroserviceIns
 
           String url = String.format(Const.REGISTRY_API.MICROSERVICE_WATCH, selfMicroserviceId);
 
-          IpPort ipPort = ipPortManager.getAvailableAddress(false);
+          IpPort ipPort = ipPortManager.getAvailableAddress();
           WebsocketUtils.open(ipPort, url, o -> {
             onOpen.success(o);
             LOGGER.info(
@@ -519,7 +520,7 @@ public void watch(String selfMicroserviceId, AsyncResultCallback<MicroserviceIns
   public List<MicroserviceInstance> findServiceInstance(String consumerId, String appId, String serviceName,
       String versionRule) {
     Holder<FindInstancesResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     CountDownLatch countDownLatch = new CountDownLatch(1);
     RestUtils.get(ipPort,
@@ -562,7 +563,7 @@ private void watchErrorHandler(Throwable e, String selfMicroserviceId,
   @Override
   public boolean updateMicroserviceProperties(String microserviceId, Map<String, String> serviceProperties) {
     Holder<HttpClientResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     try {
       UpdatePropertiesRequest request = new UpdatePropertiesRequest();
@@ -598,7 +599,7 @@ public boolean updateMicroserviceProperties(String microserviceId, Map<String, S
   public boolean updateInstanceProperties(String microserviceId, String microserviceInstanceId,
       Map<String, String> instanceProperties) {
     Holder<HttpClientResponse> holder = new Holder<>();
-    IpPort ipPort = ipPortManager.getAvailableAddress(false);
+    IpPort ipPort = ipPortManager.getAvailableAddress();
 
     try {
       UpdatePropertiesRequest request = new UpdatePropertiesRequest();
@@ -636,7 +637,7 @@ public boolean updateInstanceProperties(String microserviceId, String microservi
   public MicroserviceInstance findServiceInstance(String serviceId, String instanceId) {
     try {
       Holder<MicroserviceInstanceResponse> holder = new Holder<>();
-      IpPort ipPort = ipPortManager.getAvailableAddress(false);
+      IpPort ipPort = ipPortManager.getAvailableAddress();
       CountDownLatch countDownLatch = new CountDownLatch(1);
       RestUtils.get(ipPort,
           String.format(Const.REGISTRY_API.MICROSERVICE_INSTANCE_OPERATION_ONE, serviceId, instanceId),
@@ -651,8 +652,5 @@ public MicroserviceInstance findServiceInstance(String serviceId, String instanc
       LOGGER.error("get instance from sc failed");
       return null;
     }
-
   }
-  
-  
 }
diff --git a/service-registry/src/main/java/io/servicecomb/serviceregistry/consumer/MicroserviceVersions.java b/service-registry/src/main/java/io/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
index 48bcfaa31..1dadb89da 100644
--- a/service-registry/src/main/java/io/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
+++ b/service-registry/src/main/java/io/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
@@ -104,6 +104,9 @@ public void pullInstances() {
         microserviceName,
         DefinitionConst.VERSION_RULE_ALL);
     if (pulledInstances == null) {
+      // exception happens and try pull again later.
+      pendingPullCount.incrementAndGet();
+      appManager.getEventBus().post(new PullMicroserviceVersionsInstancesEvent(this, TimeUnit.SECONDS.toMillis(1)));
       return;
     }
 
diff --git a/service-registry/src/main/java/io/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java b/service-registry/src/main/java/io/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
index 27e4d4dd7..c91a20b26 100644
--- a/service-registry/src/main/java/io/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
+++ b/service-registry/src/main/java/io/servicecomb/serviceregistry/registry/AbstractServiceRegistry.java
@@ -207,7 +207,7 @@ public boolean unregisterInstance() {
         serviceName,
         versionRule);
     if (instances == null) {
-      LOGGER.error("find empty instances from service center. service={}/{}/{}", appId, serviceName, versionRule);
+      LOGGER.error("Can not find any instances from service center due to previous errors. service={}/{}/{}", appId, serviceName, versionRule);
       return null;
     }
 
diff --git a/service-registry/src/main/java/io/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java b/service-registry/src/main/java/io/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
index 5b0a3b0a8..5d6be5a94 100644
--- a/service-registry/src/main/java/io/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
+++ b/service-registry/src/main/java/io/servicecomb/serviceregistry/registry/RemoteServiceRegistry.java
@@ -32,6 +32,7 @@
 import io.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl;
 import io.servicecomb.serviceregistry.config.ServiceRegistryConfig;
 import io.servicecomb.serviceregistry.definition.MicroserviceDefinition;
+import io.servicecomb.serviceregistry.task.MicroserviceRegisterTask;
 import io.servicecomb.serviceregistry.task.event.PeriodicPullEvent;
 import io.servicecomb.serviceregistry.task.event.PullMicroserviceVersionsInstancesEvent;
 import io.servicecomb.serviceregistry.task.event.ShutdownEvent;
@@ -77,8 +78,6 @@ public void onShutdown(ShutdownEvent event) {
   public void run() {
     super.run();
 
-    ipPortManager.initAutoDiscovery();
-
     taskPool.scheduleAtFixedRate(serviceCenterTask,
         serviceRegistryConfig.getHeartbeatInterval(),
         serviceRegistryConfig.getHeartbeatInterval(),
@@ -101,6 +100,12 @@ public void onPullMicroserviceVersionsInstancesEvent(PullMicroserviceVersionsIns
     taskPool.schedule(event.getMicroserviceVersions()::pullInstances, event.getMsDelay(), TimeUnit.MILLISECONDS);
   }
 
+  @Subscribe
+  public void onMicroserviceRegistryTask(MicroserviceRegisterTask event) {
+    if (event.isRegistered()) {
+      ipPortManager.initAutoDiscovery();
+    }
+  }
   // for testing
   ScheduledThreadPoolExecutor getTaskPool() {
     return this.taskPool;
diff --git a/service-registry/src/test/java/io/servicecomb/serviceregistry/client/TestIpPortManager.java b/service-registry/src/test/java/io/servicecomb/serviceregistry/client/TestIpPortManager.java
index bdd877a3b..016be3566 100644
--- a/service-registry/src/test/java/io/servicecomb/serviceregistry/client/TestIpPortManager.java
+++ b/service-registry/src/test/java/io/servicecomb/serviceregistry/client/TestIpPortManager.java
@@ -80,9 +80,9 @@ public void testGetAvailableAddress(@Injectable ServiceRegistryConfig config,
     };
 
     IpPortManager manager = new IpPortManager(config, cacheManager);
-    IpPort address1 = manager.getAvailableAddress(false);
+    IpPort address1 = manager.getAvailableAddress();
 
-    if(address1.getPort() == 9980) {
+    if (address1.getPort() == 9980) {
       Assert.assertEquals("127.0.0.1", address1.getHostOrIp());
       Assert.assertEquals(9980, address1.getPort());
     } else {
@@ -90,8 +90,8 @@ public void testGetAvailableAddress(@Injectable ServiceRegistryConfig config,
       Assert.assertEquals(9981, address1.getPort());
     }
 
-    IpPort address2 = manager.getAvailableAddress(true);
-    if(address1.getPort() == 9980) {
+    IpPort address2 = manager.getNextAvailableAddress(address1);
+    if (address1.getPort() == 9980) {
       Assert.assertEquals("127.0.0.1", address2.getHostOrIp());
       Assert.assertEquals(9981, address2.getPort());
     } else {
@@ -99,8 +99,8 @@ public void testGetAvailableAddress(@Injectable ServiceRegistryConfig config,
       Assert.assertEquals(9980, address2.getPort());
     }
 
-    IpPort address3 = manager.getAvailableAddress(false);
-    if(address1.getPort() == 9980) {
+    IpPort address3 = manager.getAvailableAddress();
+    if (address1.getPort() == 9980) {
       Assert.assertEquals("127.0.0.1", address3.getHostOrIp());
       Assert.assertEquals(9981, address3.getPort());
     } else {
@@ -120,19 +120,19 @@ public void testGetAvailableAddress(@Injectable ServiceRegistryConfig config,
         result = addresses;
       }
     };
-    
+
     manager.initAutoDiscovery();
-    IpPort address4 = manager.getAvailableAddress(true);
-    if(address1.getPort() == 9980) {
+    IpPort address4 = manager.getNextAvailableAddress(address3);
+    if (address1.getPort() == 9980) {
       Assert.assertEquals("127.0.0.1", address4.getHostOrIp());
       Assert.assertEquals(9982, address4.getPort());
     } else {
-      address4 = manager.getAvailableAddress(true);
+      address4 = manager.getNextAvailableAddress(address1);
       Assert.assertEquals("127.0.0.1", address4.getHostOrIp());
       Assert.assertEquals(9982, address4.getPort());
     }
 
-    IpPort address5 = manager.getAvailableAddress(true);
+    IpPort address5 = manager.getNextAvailableAddress(address4);
     Assert.assertEquals("127.0.0.1", address5.getHostOrIp());
     Assert.assertEquals(9980, address5.getPort());
   }
@@ -153,5 +153,4 @@ public void testCreateServiceRegistryCacheWithInstanceCache() {
       }
     };
   }
-
 }
diff --git a/service-registry/src/test/java/io/servicecomb/serviceregistry/client/http/TestClientHttp.java b/service-registry/src/test/java/io/servicecomb/serviceregistry/client/http/TestClientHttp.java
index 29f2c989c..283b0df89 100644
--- a/service-registry/src/test/java/io/servicecomb/serviceregistry/client/http/TestClientHttp.java
+++ b/service-registry/src/test/java/io/servicecomb/serviceregistry/client/http/TestClientHttp.java
@@ -45,7 +45,7 @@ public void testServiceRegistryClientImpl(@Mocked IpPortManager manager) {
     IpPort ipPort = new IpPort("127.0.0.1", 8853);
     new Expectations() {
       {
-        manager.getAvailableAddress(false);
+        manager.getAvailableAddress();
         result = ipPort;
       }
     };
@@ -143,7 +143,7 @@ public void testRequestParam() {
   @Test
   public void testIpPortManager(@Mocked InstanceCacheManager instanceCacheManager) throws Exception {
     IpPortManager oManager = new IpPortManager(ServiceRegistryConfig.INSTANCE, instanceCacheManager);
-    IpPort oIPPort = oManager.getAvailableAddress(true);
-    Assert.assertEquals(oIPPort.getHostOrIp(), oManager.getAvailableAddress(false).getHostOrIp());
+    IpPort oIPPort = oManager.getNextAvailableAddress(new IpPort("", 33));
+    Assert.assertEquals(oIPPort.getHostOrIp(), oManager.getAvailableAddress().getHostOrIp());
   }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services