From 86f0f3c6d791ed6e7048c0aaa741957e783bb03e Mon Sep 17 00:00:00 2001 From: nkorange Date: Fri, 28 Jun 2019 17:06:06 +0800 Subject: [PATCH] #1229 Add test case --- .../test/naming/RegisterInstance_ITCase.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/RegisterInstance_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/RegisterInstance_ITCase.java index f615e43e4..e453e9d8b 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/RegisterInstance_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/RegisterInstance_ITCase.java @@ -19,6 +19,7 @@ import com.alibaba.nacos.api.PropertyKeyConst; 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.PreservedMetadataKeys; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.naming.NamingApp; import org.junit.Assert; @@ -210,4 +211,36 @@ public class RegisterInstance_ITCase { Assert.assertEquals("1.0", instances.get(0).getMetadata().get("version")); Assert.assertEquals("prod", instances.get(0).getMetadata().get("env")); } + + @Test + public void regServiceWithTTL() throws Exception { + + String serviceName = randomDomainName(); + System.out.println(serviceName); + + Instance instance = new Instance(); + instance.setIp("1.1.1.2"); + instance.setPort(9999); + Map metadata = new HashMap(); + metadata.put(PreservedMetadataKeys.HEART_BEAT_INTERVAL, "3"); + metadata.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, "6"); + metadata.put(PreservedMetadataKeys.IP_DELETE_TIMEOUT, "9"); + instance.setMetadata(metadata); + + naming.registerInstance(serviceName, instance); + + TimeUnit.SECONDS.sleep(3); + + List instances = naming.getAllInstances(serviceName); + + Assert.assertEquals(1, instances.size()); + + naming.deregisterInstance(serviceName, instance); + + TimeUnit.SECONDS.sleep(12); + + instances = naming.getAllInstances(serviceName); + + Assert.assertEquals(0, instances.size()); + } }