From ac36a41d8683ae2f51de85a2450afc499e00e718 Mon Sep 17 00:00:00 2001 From: chuntaojun Date: Thu, 9 May 2019 10:07:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor(api=E3=80=81client):=20modify=20Mainta?= =?UTF-8?q?inService=20to=20NamingMaintainService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/alibaba/nacos/api/NacosFactory.java | 16 ++++++------- ...actory.java => NamingMaintainFactory.java} | 10 ++++---- ...ervice.java => NamingMaintainService.java} | 2 +- ...e.java => NacosNamingMaintainService.java} | 8 +++---- ...va => NacosNamingMaintainServiceTest.java} | 17 +++++++------ ...java => NamingMaintainService_ITCase.java} | 24 +++++++++---------- 6 files changed, 38 insertions(+), 39 deletions(-) rename api/src/main/java/com/alibaba/nacos/api/naming/{MaintainFactory.java => NamingMaintainFactory.java} (76%) rename api/src/main/java/com/alibaba/nacos/api/naming/{MaintainService.java => NamingMaintainService.java} (99%) rename client/src/main/java/com/alibaba/nacos/client/naming/{NacosMaintainService.java => NacosNamingMaintainService.java} (95%) rename client/src/test/java/com/alibaba/nacos/client/naming/{NacosMaintainServiceTest.java => NacosNamingMaintainServiceTest.java} (82%) rename test/src/test/java/com/alibaba/nacos/test/naming/{MaintainService_ITCase.java => NamingMaintainService_ITCase.java} (85%) diff --git a/api/src/main/java/com/alibaba/nacos/api/NacosFactory.java b/api/src/main/java/com/alibaba/nacos/api/NacosFactory.java index 165965e49..82228c027 100644 --- a/api/src/main/java/com/alibaba/nacos/api/NacosFactory.java +++ b/api/src/main/java/com/alibaba/nacos/api/NacosFactory.java @@ -20,8 +20,8 @@ import java.util.Properties; import com.alibaba.nacos.api.config.ConfigFactory; import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.naming.MaintainFactory; -import com.alibaba.nacos.api.naming.MaintainService; +import com.alibaba.nacos.api.naming.NamingMaintainFactory; +import com.alibaba.nacos.api.naming.NamingMaintainService; import com.alibaba.nacos.api.naming.NamingFactory; import com.alibaba.nacos.api.naming.NamingService; @@ -80,22 +80,22 @@ public class NacosFactory { * Create maintain service * * @param serverAddr - * @return MaintainService + * @return NamingMaintainService * @throws NacosException Exception */ - public static MaintainService createMaintainService(String serverAddr) throws NacosException { - return MaintainFactory.createMaintainService(serverAddr); + public static NamingMaintainService createMaintainService(String serverAddr) throws NacosException { + return NamingMaintainFactory.createMaintainService(serverAddr); } /** * Create maintain service * * @param properties - * @return MaintainService + * @return NamingMaintainService * @throws NacosException Exception */ - public static MaintainService createMaintainService(Properties properties) throws NacosException { - return MaintainFactory.createMaintainService(properties); + public static NamingMaintainService createMaintainService(Properties properties) throws NacosException { + return NamingMaintainFactory.createMaintainService(properties); } } diff --git a/api/src/main/java/com/alibaba/nacos/api/naming/MaintainFactory.java b/api/src/main/java/com/alibaba/nacos/api/naming/NamingMaintainFactory.java similarity index 76% rename from api/src/main/java/com/alibaba/nacos/api/naming/MaintainFactory.java rename to api/src/main/java/com/alibaba/nacos/api/naming/NamingMaintainFactory.java index 423814646..5cf93a382 100644 --- a/api/src/main/java/com/alibaba/nacos/api/naming/MaintainFactory.java +++ b/api/src/main/java/com/alibaba/nacos/api/naming/NamingMaintainFactory.java @@ -25,24 +25,24 @@ import java.util.Properties; * @author liaochuntao * @since 1.0.1 */ -public class MaintainFactory { +public class NamingMaintainFactory { - public static MaintainService createMaintainService(String serverList) throws NacosException { + public static NamingMaintainService createMaintainService(String serverList) throws NacosException { try { Class driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosMaintainService"); Constructor constructor = driverImplClass.getConstructor(String.class); - MaintainService vendorImpl = (MaintainService)constructor.newInstance(serverList); + NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(serverList); return vendorImpl; } catch (Throwable e) { throw new NacosException(-400, e.getMessage()); } } - public static MaintainService createMaintainService(Properties properties) throws NacosException { + public static NamingMaintainService createMaintainService(Properties properties) throws NacosException { try { Class driverImplClass = Class.forName("com.alibaba.nacos.client.naming.NacosMaintainService"); Constructor constructor = driverImplClass.getConstructor(Properties.class); - MaintainService vendorImpl = (MaintainService)constructor.newInstance(properties); + NamingMaintainService vendorImpl = (NamingMaintainService)constructor.newInstance(properties); return vendorImpl; } catch (Throwable e) { throw new NacosException(-400, e.getMessage()); diff --git a/api/src/main/java/com/alibaba/nacos/api/naming/MaintainService.java b/api/src/main/java/com/alibaba/nacos/api/naming/NamingMaintainService.java similarity index 99% rename from api/src/main/java/com/alibaba/nacos/api/naming/MaintainService.java rename to api/src/main/java/com/alibaba/nacos/api/naming/NamingMaintainService.java index bfddc8a38..069e39582 100644 --- a/api/src/main/java/com/alibaba/nacos/api/naming/MaintainService.java +++ b/api/src/main/java/com/alibaba/nacos/api/naming/NamingMaintainService.java @@ -29,7 +29,7 @@ import java.util.Map; * @author liaochuntao * @since 1.0.1 */ -public interface MaintainService { +public interface NamingMaintainService { /** * update instance info diff --git a/client/src/main/java/com/alibaba/nacos/client/naming/NacosMaintainService.java b/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingMaintainService.java similarity index 95% rename from client/src/main/java/com/alibaba/nacos/client/naming/NacosMaintainService.java rename to client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingMaintainService.java index 93eda8dfa..a13638d2e 100644 --- a/client/src/main/java/com/alibaba/nacos/client/naming/NacosMaintainService.java +++ b/client/src/main/java/com/alibaba/nacos/client/naming/NacosNamingMaintainService.java @@ -19,7 +19,7 @@ package com.alibaba.nacos.client.naming; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.naming.MaintainService; +import com.alibaba.nacos.api.naming.NamingMaintainService; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.Service; import com.alibaba.nacos.api.selector.AbstractSelector; @@ -37,7 +37,7 @@ import java.util.Properties; * @since 1.0.1 */ @SuppressWarnings("PMD.ServiceOrDaoClassShouldEndWithImplRule") -public class NacosMaintainService implements MaintainService { +public class NacosNamingMaintainService implements NamingMaintainService { private String namespace; @@ -47,14 +47,14 @@ public class NacosMaintainService implements MaintainService { private NamingProxy serverProxy; - public NacosMaintainService(String serverList) { + public NacosNamingMaintainService(String serverList) { Properties properties = new Properties(); properties.setProperty(PropertyKeyConst.SERVER_ADDR, serverList); init(properties); } - public NacosMaintainService(Properties properties) { + public NacosNamingMaintainService(Properties properties) { init(properties); } diff --git a/client/src/test/java/com/alibaba/nacos/client/naming/NacosMaintainServiceTest.java b/client/src/test/java/com/alibaba/nacos/client/naming/NacosNamingMaintainServiceTest.java similarity index 82% rename from client/src/test/java/com/alibaba/nacos/client/naming/NacosMaintainServiceTest.java rename to client/src/test/java/com/alibaba/nacos/client/naming/NacosNamingMaintainServiceTest.java index bb3dd71fa..0157e22a3 100644 --- a/client/src/test/java/com/alibaba/nacos/client/naming/NacosMaintainServiceTest.java +++ b/client/src/test/java/com/alibaba/nacos/client/naming/NacosNamingMaintainServiceTest.java @@ -4,7 +4,7 @@ import com.alibaba.nacos.api.NacosFactory; import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.naming.MaintainService; +import com.alibaba.nacos.api.naming.NamingMaintainService; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Service; import com.alibaba.nacos.api.selector.ExpressionSelector; @@ -20,12 +20,11 @@ import java.util.Map; import java.util.Properties; import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER; -import static org.junit.Assert.*; @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class NacosMaintainServiceTest { +public class NacosNamingMaintainServiceTest { - private MaintainService maintainService; + private NamingMaintainService namingMaintainService; private NamingService namingService; @Before @@ -33,7 +32,7 @@ public class NacosMaintainServiceTest { Properties properties = new Properties(); properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848"); - maintainService = NacosFactory.createMaintainService(properties); + namingMaintainService = NacosFactory.createMaintainService(properties); } @Test @@ -50,7 +49,7 @@ public class NacosMaintainServiceTest { selector.setExpression("CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B"); try { - maintainService.createService(service, new NoneSelector()); + namingMaintainService.createService(service, new NoneSelector()); } catch (NacosException e) { NAMING_LOGGER.error(e.getErrMsg()); } @@ -67,7 +66,7 @@ public class NacosMaintainServiceTest { service.setMetadata(metadata); try { - maintainService.updateService(service, new NoneSelector()); + namingMaintainService.updateService(service, new NoneSelector()); } catch (NacosException e) { NAMING_LOGGER.error(e.getErrMsg()); } @@ -76,7 +75,7 @@ public class NacosMaintainServiceTest { @Test public void test3selectOneService() { try { - Service service = maintainService.queryService("nacos-api"); + Service service = namingMaintainService.queryService("nacos-api"); System.out.println("service : " + service.toString()); } catch (NacosException e) { NAMING_LOGGER.error(e.getErrMsg()); @@ -86,7 +85,7 @@ public class NacosMaintainServiceTest { @Test public void test4deleteService() { try { - Assert.assertTrue(maintainService.deleteService("nacos-api")); + Assert.assertTrue(namingMaintainService.deleteService("nacos-api")); } catch (NacosException e) { NAMING_LOGGER.error(e.getErrMsg()); } diff --git a/test/src/test/java/com/alibaba/nacos/test/naming/MaintainService_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java similarity index 85% rename from test/src/test/java/com/alibaba/nacos/test/naming/MaintainService_ITCase.java rename to test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java index d4a144dee..773848761 100644 --- a/test/src/test/java/com/alibaba/nacos/test/naming/MaintainService_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/naming/NamingMaintainService_ITCase.java @@ -18,8 +18,8 @@ package com.alibaba.nacos.test.naming; import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.naming.MaintainFactory; -import com.alibaba.nacos.api.naming.MaintainService; +import com.alibaba.nacos.api.naming.NamingMaintainFactory; +import com.alibaba.nacos.api.naming.NamingMaintainService; import com.alibaba.nacos.api.naming.NamingFactory; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; @@ -47,9 +47,9 @@ import java.util.concurrent.TimeUnit; @RunWith(SpringRunner.class) @SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class MaintainService_ITCase { +public class NamingMaintainService_ITCase { - private MaintainService maintainService; + private NamingMaintainService namingMaintainService; private NamingService namingService; private Instance instance; private Service service; @@ -62,9 +62,9 @@ public class MaintainService_ITCase { NamingBase.prepareServer(port); - if (maintainService == null) { + if (namingMaintainService == null) { TimeUnit.SECONDS.sleep(10); - maintainService = MaintainFactory.createMaintainService("127.0.0.1" + ":" + port); + namingMaintainService = NamingMaintainFactory.createMaintainService("127.0.0.1" + ":" + port); } if (namingService == null) { @@ -98,7 +98,7 @@ public class MaintainService_ITCase { map.put("version", "2.0"); instance.setMetadata(map); namingService.registerInstance("nacos-api", instance); - maintainService.updateInstance("nacos-api", instance); + namingMaintainService.updateInstance("nacos-api", instance); List instances = namingService.getAllInstances("nacos-api", true); Assert.assertEquals(instances.size(), 1); @@ -112,8 +112,8 @@ public class MaintainService_ITCase { selector.setExpression("CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B"); System.out.println("service info : " + service); - maintainService.createService(service, selector); - Service remoteService = maintainService.queryService("nacos-api"); + namingMaintainService.createService(service, selector); + Service remoteService = namingMaintainService.queryService("nacos-api"); System.out.println("remote service info : " + remoteService); Assert.assertEquals(service.toString(), remoteService.toString()); } @@ -128,15 +128,15 @@ public class MaintainService_ITCase { metadata.put("nacos-1", "nacos-3-update"); service.setMetadata(metadata); - maintainService.updateService(service, new NoneSelector()); - Service remoteService = maintainService.queryService("nacos-api"); + namingMaintainService.updateService(service, new NoneSelector()); + Service remoteService = namingMaintainService.queryService("nacos-api"); System.out.println("remote service info : " + remoteService); Assert.assertEquals(service.toString(), remoteService.toString()); } @Test public void deleteService() throws NacosException { - Assert.assertTrue(maintainService.deleteService("nacos-api")); + Assert.assertTrue(namingMaintainService.deleteService("nacos-api")); } @Test