Add metadata test case
This commit is contained in:
parent
eb43978f86
commit
504edb141b
@ -29,7 +29,9 @@ import org.springframework.boot.web.server.LocalServerPort;
|
|||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static com.alibaba.nacos.test.naming.NamingBase.*;
|
import static com.alibaba.nacos.test.naming.NamingBase.*;
|
||||||
@ -42,31 +44,35 @@ import static com.alibaba.nacos.test.naming.NamingBase.*;
|
|||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
|
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
|
||||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
public class RegisterInstance_ITCase {
|
public class RegisterInstance_ITCase {
|
||||||
|
|
||||||
private NamingService naming;
|
private NamingService naming;
|
||||||
private NamingService naming2;
|
private NamingService naming2;
|
||||||
@LocalServerPort
|
@LocalServerPort
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() throws Exception{
|
public void init() throws Exception {
|
||||||
if (naming == null) {
|
if (naming == null) {
|
||||||
TimeUnit.SECONDS.sleep(10);
|
TimeUnit.SECONDS.sleep(10);
|
||||||
naming = NamingFactory.createNamingService("127.0.0.1"+":"+port);
|
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册一个默认cluster的Instance,并验证
|
* 注册一个默认cluster的Instance,并验证
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void regDomTest() throws Exception{
|
public void regDomTest() throws Exception {
|
||||||
String serviceName = randomDomainName();
|
String serviceName = randomDomainName();
|
||||||
|
|
||||||
naming.registerInstance(serviceName, TEST_IP_4_DOM_1, TEST_PORT);
|
naming.registerInstance(serviceName, TEST_IP_4_DOM_1, TEST_PORT);
|
||||||
|
|
||||||
|
System.out.println(serviceName);
|
||||||
|
|
||||||
TimeUnit.SECONDS.sleep(3);
|
TimeUnit.SECONDS.sleep(3);
|
||||||
|
|
||||||
List<Instance> instances = naming.getAllInstances(serviceName);
|
List<Instance> instances = naming.getAllInstances(serviceName);
|
||||||
@ -80,10 +86,11 @@ public class RegisterInstance_ITCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册一个自定义cluster的Instance,并验证
|
* 注册一个自定义cluster的Instance,并验证
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void regDomClusterTest() throws Exception{
|
public void regDomClusterTest() throws Exception {
|
||||||
String serviceName = randomDomainName();
|
String serviceName = randomDomainName();
|
||||||
|
|
||||||
naming.registerInstance(serviceName, TEST_IP_4_DOM_1, TEST_PORT, TEST_NEW_CLUSTER_4_DOM_1);
|
naming.registerInstance(serviceName, TEST_IP_4_DOM_1, TEST_PORT, TEST_NEW_CLUSTER_4_DOM_1);
|
||||||
@ -111,6 +118,7 @@ public class RegisterInstance_ITCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册一个自定义的Instance,并验证
|
* 注册一个自定义的Instance,并验证
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@ -132,6 +140,7 @@ public class RegisterInstance_ITCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册一个不健康的Instance,并验证
|
* 注册一个不健康的Instance,并验证
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@ -145,9 +154,34 @@ public class RegisterInstance_ITCase {
|
|||||||
|
|
||||||
TimeUnit.SECONDS.sleep(3);
|
TimeUnit.SECONDS.sleep(3);
|
||||||
|
|
||||||
List<Instance> instances = naming.selectInstances(serviceName,false);
|
List<Instance> instances = naming.selectInstances(serviceName, false);
|
||||||
|
|
||||||
Assert.assertEquals(instances.size(), 1);
|
Assert.assertEquals(instances.size(), 1);
|
||||||
Assert.assertEquals(instances.get(0).isHealthy(), false);
|
Assert.assertEquals(instances.get(0).isHealthy(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void regServiceWithMetadata() throws Exception {
|
||||||
|
|
||||||
|
String serviceName = randomDomainName();
|
||||||
|
System.out.println(serviceName);
|
||||||
|
|
||||||
|
Instance instance = new Instance();
|
||||||
|
instance.setIp("1.1.1.2");
|
||||||
|
instance.setPort(9999);
|
||||||
|
Map<String, String> metadata = new HashMap<String, String>();
|
||||||
|
metadata.put("version", "1.0");
|
||||||
|
metadata.put("env", "prod");
|
||||||
|
instance.setMetadata(metadata);
|
||||||
|
|
||||||
|
naming.registerInstance(serviceName, instance);
|
||||||
|
|
||||||
|
TimeUnit.SECONDS.sleep(3);
|
||||||
|
|
||||||
|
List<Instance> instances = naming.getAllInstances(serviceName);
|
||||||
|
|
||||||
|
Assert.assertEquals(1, instances.size());
|
||||||
|
Assert.assertEquals("1.0", instances.get(0).getMetadata().get("version"));
|
||||||
|
Assert.assertEquals("prod", instances.get(0).getMetadata().get("env"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user