From 4c5c2a66e86dc99ee7b86648b51250f841a62bcb Mon Sep 17 00:00:00 2001 From: chuntaojun Date: Thu, 16 May 2019 12:08:28 +0800 Subject: [PATCH 1/3] fix(test): fix NamingMaintainService_ITCase mistake --- .../naming/NamingMaintainService_ITCase.java | 69 ++++++++++--------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java index 7738487611c..c84d51f9a6a 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java @@ -40,6 +40,8 @@ import java.util.Map; import java.util.concurrent.TimeUnit; +import static com.alibaba.nacos.test.naming.NamingBase.randomDomainName; + /** * @author liaochuntao * @date 2019-05-07 10:13 @@ -52,7 +54,7 @@ public class NamingMaintainService_ITCase { private NamingMaintainService namingMaintainService; private NamingService namingService; private Instance instance; - private Service service; + private String serviceName; @LocalServerPort private int port; @@ -82,13 +84,8 @@ public void init() throws Exception { map.put("version", "1.0"); instance.setMetadata(map); - service = new Service(); - service.setName("nacos-api"); - service.setGroupName(Constants.DEFAULT_GROUP); - service.setProtectThreshold(1.0f); - Map metadata = new HashMap(); - metadata.put("nacos-1", "this is a test metadata"); - service.setMetadata(metadata); + serviceName = randomDomainName(); + } @Test @@ -96,52 +93,58 @@ public void updateInstance() throws NacosException { Map map = new HashMap(); map.put("netType", "external-update"); map.put("version", "2.0"); + namingService.registerInstance(serviceName, instance); instance.setMetadata(map); - namingService.registerInstance("nacos-api", instance); - namingMaintainService.updateInstance("nacos-api", instance); - List instances = namingService.getAllInstances("nacos-api", true); + namingMaintainService.updateInstance(serviceName, instance); + List instances = namingService.getAllInstances(serviceName, true); Assert.assertEquals(instances.size(), 1); System.out.println(instances.get(0)); } @Test - public void createService() throws NacosException { + public void createAndUpdateService() throws NacosException { + // register service + Service preService = new Service(); + preService.setName(serviceName); + preService.setGroupName(Constants.DEFAULT_GROUP); + preService.setProtectThreshold(1.0f); + Map metadata = new HashMap(); + metadata.put(serviceName, "this is a register metadata"); + preService.setMetadata(metadata); ExpressionSelector selector = new ExpressionSelector(); selector.setExpression("CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B"); - System.out.println("service info : " + service); - namingMaintainService.createService(service, selector); - Service remoteService = namingMaintainService.queryService("nacos-api"); + System.out.println("service info : " + preService); + namingMaintainService.createService(preService, selector); + Service remoteService = namingMaintainService.queryService(serviceName); System.out.println("remote service info : " + remoteService); - Assert.assertEquals(service.toString(), remoteService.toString()); - } - - @Test - public void updateService() throws NacosException { - Service service = new Service(); - service.setName("nacos-api"); - service.setGroupName(Constants.DEFAULT_GROUP); - service.setProtectThreshold(1.0f); - Map metadata = new HashMap(); - metadata.put("nacos-1", "nacos-3-update"); - service.setMetadata(metadata); - - namingMaintainService.updateService(service, new NoneSelector()); - Service remoteService = namingMaintainService.queryService("nacos-api"); + Assert.assertEquals(preService.toString(), remoteService.toString()); + + // update service + Service nowService = new Service(); + nowService.setName(serviceName); + nowService.setGroupName(Constants.DEFAULT_GROUP); + nowService.setProtectThreshold(1.0f); + metadata.clear(); + metadata.put(serviceName, "this is a update metadata"); + nowService.setMetadata(metadata); + + namingMaintainService.updateService(nowService, new NoneSelector()); + remoteService = namingMaintainService.queryService(serviceName); System.out.println("remote service info : " + remoteService); - Assert.assertEquals(service.toString(), remoteService.toString()); + Assert.assertEquals(nowService.toString(), remoteService.toString()); } @Test public void deleteService() throws NacosException { - Assert.assertTrue(namingMaintainService.deleteService("nacos-api")); + Assert.assertTrue(namingMaintainService.deleteService(serviceName)); } @Test public void dregInstance() throws NacosException { - namingService.deregisterInstance("nacos-api", "127.0.0.1", 8081); + namingService.deregisterInstance(serviceName, "127.0.0.1", 8081); } } From 51ded2c8579a2b8607dd3459ed9cc9569eea25fc Mon Sep 17 00:00:00 2001 From: chuntaojun Date: Thu, 16 May 2019 12:25:00 +0800 Subject: [PATCH 2/3] fix(fix NamingMaintainService_ITCase mistake): --- .../nacos/test/naming/NamingMaintainService_ITCase.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java index c84d51f9a6a..4fc3448de86 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java @@ -139,6 +139,12 @@ public void createAndUpdateService() throws NacosException { @Test public void deleteService() throws NacosException { + + Service preService = new Service(); + preService.setName(serviceName); + System.out.println("service info : " + preService); + namingMaintainService.createService(preService, new NoneSelector()); + Assert.assertTrue(namingMaintainService.deleteService(serviceName)); } From f21db943272b3383188c4dbe1b192d98464abd7c Mon Sep 17 00:00:00 2001 From: chuntaojun Date: Thu, 16 May 2019 16:57:02 +0800 Subject: [PATCH 3/3] fix(test): --- .../nacos/test/naming/NamingMaintainService_ITCase.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java index 4fc3448de86..a5158ce0129 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java @@ -148,9 +148,4 @@ public void deleteService() throws NacosException { Assert.assertTrue(namingMaintainService.deleteService(serviceName)); } - @Test - public void dregInstance() throws NacosException { - namingService.deregisterInstance(serviceName, "127.0.0.1", 8081); - } - }