diff --git a/core/src/main/java/com/alibaba/nacos/core/listener/StartingApplicationListener.java b/core/src/main/java/com/alibaba/nacos/core/listener/StartingApplicationListener.java index 7ab149564ae..938f1d0fc65 100644 --- a/core/src/main/java/com/alibaba/nacos/core/listener/StartingApplicationListener.java +++ b/core/src/main/java/com/alibaba/nacos/core/listener/StartingApplicationListener.java @@ -55,6 +55,8 @@ public class StartingApplicationListener implements NacosApplicationListener { private static final String LOCAL_IP_PROPERTY_KEY = "nacos.local.ip"; + private static final String FIRST_PRE_PROPERTIES = "first_pre"; + private ScheduledExecutorService scheduledExecutorService; private volatile boolean starting; @@ -126,7 +128,7 @@ private void injectEnvironment(ConfigurableEnvironment environment) { private void loadPreProperties(ConfigurableEnvironment environment) { try { - environment.getPropertySources().addLast(new OriginTrackedMapPropertySource("first_pre", + environment.getPropertySources().addLast(new OriginTrackedMapPropertySource(FIRST_PRE_PROPERTIES, EnvUtil.loadProperties(EnvUtil.getApplicationConfFileResource()))); } catch (IOException e) { throw new NacosRuntimeException(NacosException.SERVER_ERROR, e); @@ -151,7 +153,7 @@ private void initSystemProperty() { } private void removePreProperties(ConfigurableEnvironment environment) { - environment.getPropertySources().remove("first_pre"); + environment.getPropertySources().remove(FIRST_PRE_PROPERTIES); } private void logClusterConf() { diff --git a/test/src/test/java/com/alibaba/nacos/test/config/ConfigExportAndImportAPI_CITCase.java b/test/src/test/java/com/alibaba/nacos/test/config/ConfigExportAndImportAPI_CITCase.java index 4e808b0b9ad..c1ec86af888 100644 --- a/test/src/test/java/com/alibaba/nacos/test/config/ConfigExportAndImportAPI_CITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/config/ConfigExportAndImportAPI_CITCase.java @@ -27,14 +27,24 @@ import com.github.keran213539.commonOkHttp.CommonOkHttpClient; import com.github.keran213539.commonOkHttp.CommonOkHttpClientBuilder; import com.github.keran213539.commonOkHttp.UploadByteFile; -import org.junit.*; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.test.context.junit4.SpringRunner; import java.net.HttpURLConnection; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; /** * @author klw 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 249e7891598..f5a67245600 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 @@ -31,11 +31,13 @@ import org.springframework.boot.web.server.LocalServerPort; import org.springframework.test.context.junit4.SpringRunner; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; import java.util.concurrent.TimeUnit; -import static com.alibaba.nacos.test.naming.NamingBase.*; - /** * Created by wangtong.wt on 2018/6/20. * @@ -103,9 +105,9 @@ public void regService() throws NacosException, InterruptedException { */ @Test public void regDomTest() throws Exception { - String serviceName = randomDomainName(); + String serviceName = NamingBase.randomDomainName(); System.out.println(serviceName); - naming.registerInstance(serviceName, TEST_IP_4_DOM_1, TEST_PORT); + naming.registerInstance(serviceName, NamingBase.TEST_IP_4_DOM_1, NamingBase.TEST_PORT); TimeUnit.SECONDS.sleep(3); @@ -114,8 +116,8 @@ public void regDomTest() throws Exception { Assert.assertEquals(1, instances.size()); Assert.assertTrue(instances.get(0).getInstanceId().contains(serviceName)); //Assert.assertEquals(instances.get(0).getService().getName(), serviceName); - Assert.assertEquals(instances.get(0).getIp(), TEST_IP_4_DOM_1); - Assert.assertEquals(instances.get(0).getPort(), TEST_PORT); + Assert.assertEquals(instances.get(0).getIp(), NamingBase.TEST_IP_4_DOM_1); + Assert.assertEquals(instances.get(0).getPort(), NamingBase.TEST_PORT); } /** @@ -126,11 +128,11 @@ public void regDomTest() throws Exception { @Test public void regDomClusterTest() throws Exception { - String serviceName = randomDomainName(); + String serviceName = NamingBase.randomDomainName(); System.out.println(serviceName); - naming.registerInstance(serviceName, TEST_IP_4_DOM_1, TEST_PORT, TEST_NEW_CLUSTER_4_DOM_1); + naming.registerInstance(serviceName, NamingBase.TEST_IP_4_DOM_1, NamingBase.TEST_PORT, NamingBase.TEST_NEW_CLUSTER_4_DOM_1); TimeUnit.SECONDS.sleep(3); @@ -139,17 +141,17 @@ public void regDomClusterTest() throws Exception { Assert.assertEquals(1, instances.size()); Assert.assertTrue(instances.get(0).getInstanceId().contains(serviceName)); //Assert.assertEquals(instances2.get(0).getService().getName(), serviceName); - Assert.assertEquals(instances.get(0).getIp(), TEST_IP_4_DOM_1); - Assert.assertEquals(instances.get(0).getPort(), TEST_PORT); + Assert.assertEquals(instances.get(0).getIp(), NamingBase.TEST_IP_4_DOM_1); + Assert.assertEquals(instances.get(0).getPort(), NamingBase.TEST_PORT); //Assert.assertEquals(instances.get(0).getCluster().getName(), TEST_NEW_CLUSTER_4_DOM_1); - List instances2 = naming.getAllInstances(serviceName, Arrays.asList(TEST_NEW_CLUSTER_4_DOM_1)); + List instances2 = naming.getAllInstances(serviceName, Arrays.asList(NamingBase.TEST_NEW_CLUSTER_4_DOM_1)); Assert.assertEquals(instances2.size(), 1); Assert.assertTrue(instances2.get(0).getInstanceId().contains(serviceName)); //Assert.assertEquals(instances2.get(0).getService().getName(), serviceName); - Assert.assertEquals(instances2.get(0).getIp(), TEST_IP_4_DOM_1); - Assert.assertEquals(instances2.get(0).getPort(), TEST_PORT); + Assert.assertEquals(instances2.get(0).getIp(), NamingBase.TEST_IP_4_DOM_1); + Assert.assertEquals(instances2.get(0).getPort(), NamingBase.TEST_PORT); //Assert.assertEquals(instances2.get(0).getCluster().getName(), TEST_NEW_CLUSTER_4_DOM_1); } @@ -160,9 +162,9 @@ public void regDomClusterTest() throws Exception { */ @Test public void regDomWithInstance() throws Exception { - String serviceName = randomDomainName(); + String serviceName = NamingBase.randomDomainName(); - Instance i1 = getInstance(serviceName); + Instance i1 = NamingBase.getInstance(serviceName); naming.registerInstance(serviceName, i1); TimeUnit.SECONDS.sleep(3); @@ -171,7 +173,7 @@ public void regDomWithInstance() throws Exception { Assert.assertEquals(instances.size(), 1); - Assert.assertTrue(verifyInstance(i1, instances.get(0))); + Assert.assertTrue(NamingBase.verifyInstance(i1, instances.get(0))); } @@ -182,11 +184,11 @@ public void regDomWithInstance() throws Exception { */ @Test public void regDomNotHealth() throws Exception { - String serviceName = randomDomainName(); + String serviceName = NamingBase.randomDomainName(); System.out.println(serviceName); naming.registerInstance(serviceName, "1.1.1.1", 2000); - naming.registerInstance(serviceName, TEST_IP_4_DOM_1, TEST_PORT); + naming.registerInstance(serviceName, NamingBase.TEST_IP_4_DOM_1, NamingBase.TEST_PORT); TimeUnit.SECONDS.sleep(3); @@ -198,7 +200,7 @@ public void regDomNotHealth() throws Exception { @Test public void regServiceWithMetadata() throws Exception { - String serviceName = randomDomainName(); + String serviceName = NamingBase.randomDomainName(); System.out.println(serviceName); Instance instance = new Instance(); @@ -223,7 +225,7 @@ public void regServiceWithMetadata() throws Exception { @Test public void regServiceWithTTL() throws Exception { - String serviceName = randomDomainName(); + String serviceName = NamingBase.randomDomainName(); System.out.println(serviceName); Instance instance = new Instance();