parent
758b8b3942
commit
30304f0b3a
@ -78,7 +78,7 @@ public class MultiTenant_InstanceAPI_ITCase {
|
||||
|
||||
private URL base;
|
||||
|
||||
private volatile List<Instance> instances = Collections.emptyList();
|
||||
private final List<Instance> instances = Collections.emptyList();
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
@ -415,7 +415,7 @@ public class MultiTenant_InstanceAPI_ITCase {
|
||||
.appendParam("ip", "22.22.22.22").appendParam("port", "80")
|
||||
.appendParam("namespaceId", "namespace-2").done(), String.class, HttpMethod.PATCH);
|
||||
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
|
||||
|
||||
|
||||
TimeUnit.SECONDS.sleep(3L);
|
||||
|
||||
response = request("/nacos/v1/ns/instance/list",
|
||||
@ -449,7 +449,7 @@ public class MultiTenant_InstanceAPI_ITCase {
|
||||
.appendParam("port", "8888").appendParam("namespaceId", "namespace-1") //新增
|
||||
.done(), String.class, HttpMethod.POST);
|
||||
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
|
||||
|
||||
|
||||
TimeUnit.SECONDS.sleep(5L);
|
||||
response = request("/nacos/v1/ns/instance/list",
|
||||
Params.newParams().appendParam("serviceName", serviceName) //获取naming中的实例
|
||||
|
@ -22,9 +22,10 @@ import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.api.naming.pojo.ListView;
|
||||
import com.alibaba.nacos.api.selector.ExpressionSelector;
|
||||
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@ -50,7 +51,9 @@ import static com.alibaba.nacos.test.naming.NamingBase.*;
|
||||
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
public class SelectInstances_ITCase {
|
||||
|
||||
private NamingService naming;
|
||||
private static NamingService naming;
|
||||
|
||||
private static NamingService naming1;
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@ -60,6 +63,7 @@ public class SelectInstances_ITCase {
|
||||
if (naming == null) {
|
||||
//TimeUnit.SECONDS.sleep(10);
|
||||
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
|
||||
naming1 = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
|
||||
}
|
||||
int i = 5;
|
||||
while (i >= 0) {
|
||||
@ -71,6 +75,16 @@ public class SelectInstances_ITCase {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws NacosException {
|
||||
if (null != naming) {
|
||||
naming.shutDown();
|
||||
}
|
||||
if (null != naming1) {
|
||||
naming1.shutDown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有健康的Instance
|
||||
@ -81,7 +95,7 @@ public class SelectInstances_ITCase {
|
||||
public void selectHealthyInstances() throws Exception {
|
||||
String serviceName = randomDomainName();
|
||||
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT);
|
||||
naming.registerInstance(serviceName, "1.1.1.1", 9090);
|
||||
naming1.registerInstance(serviceName, "1.1.1.1", 9090);
|
||||
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
|
||||
@ -111,7 +125,7 @@ public class SelectInstances_ITCase {
|
||||
public void selectUnhealthyInstances() throws Exception {
|
||||
String serviceName = randomDomainName();
|
||||
naming.registerInstance(serviceName, "1.1.1.1", TEST_PORT);
|
||||
naming.registerInstance(serviceName, "1.1.1.2", TEST_PORT);
|
||||
naming1.registerInstance(serviceName, "1.1.1.2", TEST_PORT);
|
||||
|
||||
TimeUnit.SECONDS.sleep(8);
|
||||
List<Instance> instances = naming.selectInstances(serviceName, false);
|
||||
@ -133,7 +147,7 @@ public class SelectInstances_ITCase {
|
||||
public void selectHealthyInstancesClusters() throws Exception {
|
||||
String serviceName = randomDomainName();
|
||||
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
|
||||
naming.registerInstance(serviceName, "127.0.0.2", 9090, "c2");
|
||||
naming1.registerInstance(serviceName, "127.0.0.2", 9090, "c2");
|
||||
|
||||
TimeUnit.SECONDS.sleep(8);
|
||||
List<Instance> instances = naming.selectInstances(serviceName, Arrays.asList("c1", "c2"), true);
|
||||
@ -154,7 +168,7 @@ public class SelectInstances_ITCase {
|
||||
public void selectUnhealthyInstancesClusters() throws Exception {
|
||||
String serviceName = randomDomainName();
|
||||
naming.registerInstance(serviceName, "1.1.1.1", TEST_PORT, "c1");
|
||||
naming.registerInstance(serviceName, "1.1.1.2", TEST_PORT, "c2");
|
||||
naming1.registerInstance(serviceName, "1.1.1.2", TEST_PORT, "c2");
|
||||
|
||||
TimeUnit.SECONDS.sleep(8);
|
||||
List<Instance> instances = naming.selectInstances(serviceName, Arrays.asList("c1", "c2"), false);
|
||||
@ -171,7 +185,7 @@ public class SelectInstances_ITCase {
|
||||
|
||||
String serviceName = randomDomainName();
|
||||
naming.registerInstance(serviceName, "1.1.1.1", TEST_PORT, "c1");
|
||||
naming.registerInstance(serviceName, "1.1.1.2", TEST_PORT, "c2");
|
||||
naming1.registerInstance(serviceName, "1.1.1.2", TEST_PORT, "c2");
|
||||
|
||||
TimeUnit.SECONDS.sleep(8);
|
||||
|
||||
@ -199,7 +213,7 @@ public class SelectInstances_ITCase {
|
||||
public void selectAllWeightedInstances() throws Exception {
|
||||
String serviceName = randomDomainName();
|
||||
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT);
|
||||
naming.registerInstance(serviceName, "1.1.1.1", 9090);
|
||||
naming1.registerInstance(serviceName, "1.1.1.1", 9090);
|
||||
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
|
||||
@ -242,7 +256,7 @@ public class SelectInstances_ITCase {
|
||||
public void selectAllWeightedInstancesClusters() throws Exception {
|
||||
String serviceName = randomDomainName();
|
||||
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
|
||||
naming.registerInstance(serviceName, "1.1.1.1", 9090, "c2");
|
||||
naming1.registerInstance(serviceName, "1.1.1.1", 9090, "c2");
|
||||
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
|
||||
@ -285,7 +299,7 @@ public class SelectInstances_ITCase {
|
||||
public void selectAllEnabledInstances() throws Exception {
|
||||
String serviceName = randomDomainName();
|
||||
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT);
|
||||
naming.registerInstance(serviceName, "1.1.1.1", 9090);
|
||||
naming1.registerInstance(serviceName, "1.1.1.1", 9090);
|
||||
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
|
||||
@ -329,7 +343,7 @@ public class SelectInstances_ITCase {
|
||||
String serviceName = randomDomainName();
|
||||
System.out.println(serviceName);
|
||||
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
|
||||
naming.registerInstance(serviceName, "1.1.1.1", 9090, "c2");
|
||||
naming1.registerInstance(serviceName, "1.1.1.1", 9090, "c2");
|
||||
|
||||
TimeUnit.SECONDS.sleep(5);
|
||||
|
||||
@ -365,6 +379,7 @@ public class SelectInstances_ITCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("TODO nacos 2.0 can't support selector for now")
|
||||
public void getServiceListWithSelector() throws NacosException, InterruptedException {
|
||||
|
||||
String serviceName = randomDomainName();
|
||||
|
@ -16,10 +16,11 @@
|
||||
package com.alibaba.nacos.test.naming;
|
||||
|
||||
import com.alibaba.nacos.Nacos;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.NamingFactory;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||
import com.alibaba.nacos.sys.utils.ApplicationUtils;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@ -45,7 +46,11 @@ import static com.alibaba.nacos.test.naming.NamingBase.*;
|
||||
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
public class SelectOneHealthyInstance_ITCase {
|
||||
|
||||
private NamingService naming;
|
||||
private static NamingService naming;
|
||||
private static NamingService naming1;
|
||||
private static NamingService naming2;
|
||||
private static NamingService naming3;
|
||||
private static NamingService naming4;
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
@Before
|
||||
@ -53,9 +58,31 @@ public class SelectOneHealthyInstance_ITCase {
|
||||
if (naming == null) {
|
||||
//TimeUnit.SECONDS.sleep(10);
|
||||
naming = NamingFactory.createNamingService("127.0.0.1"+":"+port);
|
||||
naming1 = NamingFactory.createNamingService("127.0.0.1"+":"+port);
|
||||
naming2 = NamingFactory.createNamingService("127.0.0.1"+":"+port);
|
||||
naming3 = NamingFactory.createNamingService("127.0.0.1"+":"+port);
|
||||
naming4 = NamingFactory.createNamingService("127.0.0.1"+":"+port);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws NacosException {
|
||||
if (null != naming) {
|
||||
naming.shutDown();
|
||||
}
|
||||
if (null != naming1) {
|
||||
naming1.shutDown();
|
||||
}
|
||||
if (null != naming2) {
|
||||
naming2.shutDown();
|
||||
}
|
||||
if (null != naming3) {
|
||||
naming3.shutDown();
|
||||
}
|
||||
if (null != naming4) {
|
||||
naming4.shutDown();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取一个健康的Instance
|
||||
@ -65,7 +92,7 @@ public class SelectOneHealthyInstance_ITCase {
|
||||
public void selectOneHealthyInstances() throws Exception {
|
||||
String serviceName = randomDomainName();
|
||||
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT);
|
||||
naming.registerInstance(serviceName, "127.0.0.1", 60000);
|
||||
naming1.registerInstance(serviceName, "127.0.0.1", 60000);
|
||||
|
||||
TimeUnit.SECONDS.sleep(2);
|
||||
Instance instance = naming.selectOneHealthyInstance(serviceName);
|
||||
@ -92,10 +119,10 @@ public class SelectOneHealthyInstance_ITCase {
|
||||
public void selectOneHealthyInstancesCluster() throws Exception {
|
||||
String serviceName = randomDomainName();
|
||||
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
|
||||
naming.registerInstance(serviceName, "127.0.0.1", 60000, "c1");
|
||||
naming.registerInstance(serviceName, "1.1.1.1", TEST_PORT, "c1");
|
||||
naming.registerInstance(serviceName, "127.0.0.1", 60001, "c1");
|
||||
naming.registerInstance(serviceName, "127.0.0.1", 60002, "c2");
|
||||
naming1.registerInstance(serviceName, "127.0.0.1", 60000, "c1");
|
||||
naming2.registerInstance(serviceName, "1.1.1.1", TEST_PORT, "c1");
|
||||
naming3.registerInstance(serviceName, "127.0.0.1", 60001, "c1");
|
||||
naming4.registerInstance(serviceName, "127.0.0.1", 60002, "c2");
|
||||
|
||||
TimeUnit.SECONDS.sleep(2);
|
||||
Instance instance = naming.selectOneHealthyInstance(serviceName, Arrays.asList("c1"));
|
||||
@ -125,9 +152,9 @@ public class SelectOneHealthyInstance_ITCase {
|
||||
public void selectOneHealthyInstancesClusters() throws Exception {
|
||||
String serviceName = randomDomainName();
|
||||
naming.registerInstance(serviceName, "1.1.1.1", TEST_PORT, "c1");
|
||||
naming.registerInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
|
||||
naming.registerInstance(serviceName, "127.0.0.1", 60000, "c1");
|
||||
naming.registerInstance(serviceName, "127.0.0.1", 60001, "c2");
|
||||
naming1.registerInstance(serviceName, "127.0.0.1", TEST_PORT, "c1");
|
||||
naming2.registerInstance(serviceName, "127.0.0.1", 60000, "c1");
|
||||
naming3.registerInstance(serviceName, "127.0.0.1", 60001, "c2");
|
||||
|
||||
TimeUnit.SECONDS.sleep(2);
|
||||
Instance instance = naming.selectOneHealthyInstance(serviceName, Arrays.asList("c1", "c2"));
|
||||
|
Loading…
Reference in New Issue
Block a user