Skip to content

Commit

Permalink
[ISSUE-#4346] Fix import code (#4347)
Browse files Browse the repository at this point in the history
* remove import.*

* transfer first_pre to final static variable

* use NamingBase.Xxx to replace constant
  • Loading branch information
horizonzy authored Nov 30, 2020
1 parent 149ba91 commit 6ac6a6c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}

/**
Expand All @@ -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);

Expand All @@ -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<Instance> instances2 = naming.getAllInstances(serviceName, Arrays.asList(TEST_NEW_CLUSTER_4_DOM_1));
List<Instance> 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);
}

Expand All @@ -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);
Expand All @@ -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)));

}

Expand All @@ -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);

Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 6ac6a6c

Please sign in to comment.