Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE 2847] #2848

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ before_install:
script:
- mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true
- mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U
- mvn clean package -Pit-test
- mvn clean install -Pit-test
after_success:
- mvn clean package -Pit-test
- mvn sonar:sonar -Psonar-apache
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public String getConfig(String dataId, String group, long timeoutMs) throws Naco

@Override
public String getConfigAndSignListener(String dataId, String group, long timeoutMs, Listener listener) throws NacosException {
String content = getConfig(dataId, group, timeoutMs);
String content = getConfigInner(namespace, dataId, group, timeoutMs);
worker.addTenantListenersWithContent(dataId, group, content, Arrays.asList(listener));
return content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@ public IConfigContext getConfigContext() {
return configContext;
}

@Override
public String toString() {
return "ConfigResponse{" + "param=" + param + ", configContext=" + configContext
+ '}';
}
}
54 changes: 36 additions & 18 deletions client/src/test/java/com/alibaba/nacos/client/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,61 @@
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.AbstractListener;
import com.alibaba.nacos.common.utils.ThreadUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.util.Properties;
import java.util.concurrent.CountDownLatch;

/**
* @author <a href="mailto:[email protected]">liaochuntao</a>
*/
@Ignore
public class ConfigTest {

private ConfigService configService;
@Test
public void testServiceList() throws Exception {

@Before
public void before() throws Exception {
Properties properties = new Properties();
properties.setProperty(PropertyKeyConst.NAMESPACE, "bebf0150-e1ea-47e2-81fe-6814caf2b952");
properties.setProperty(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848");
properties.setProperty(PropertyKeyConst.USERNAME, "chuntaojun");
properties.setProperty(PropertyKeyConst.PASSWORD, "1017");
configService = NacosFactory.createConfigService(properties);
}
properties.put(PropertyKeyConst.SERVER_ADDR, "console.nacos.io:80");
properties.put(PropertyKeyConst.USERNAME, "nacos");
properties.put(PropertyKeyConst.PASSWORD, "nacos");

ConfigService configService = NacosFactory.createConfigService(properties);

final String dataId = "chuntaohjun";
final String group = "chuntaohjun";
final String content = "this.is.test=chuntaojun";

@Test
public void test() throws Exception {
final String dataId = "lessspring";
final String group = "lessspring";
final String content = "lessspring-" + System.currentTimeMillis();
boolean result = configService.publishConfig(dataId, group, content);
Assert.assertTrue(result);

ThreadUtils.sleep(10_000);
String response = configService.getConfig(dataId, group, 5000);
System.out.println(response);
configService.addListener(dataId, group, new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
System.out.println(configInfo);
}
});

for (int i = 0; i < 5; i ++) {
publish(dataId, group, content + System.currentTimeMillis(), configService);
ThreadUtils.sleep(10_000L);
}

CountDownLatch latch = new CountDownLatch(1);
latch.await();
}

private void publish(String dataId, String group, String content, ConfigService configService) {
try {
configService.publishConfig(dataId, group, content + System.currentTimeMillis());
}
catch (Throwable ex) {
ex.printStackTrace();
}
}

}
11 changes: 5 additions & 6 deletions client/src/test/java/com/alibaba/nacos/client/NamingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;

/**
* @author nkorange
Expand All @@ -38,7 +39,7 @@ public class NamingTest {
public void testServiceList() throws Exception {

Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848");
properties.put(PropertyKeyConst.SERVER_ADDR, "console.nacos.io:80");
properties.put(PropertyKeyConst.USERNAME, "nacos");
properties.put(PropertyKeyConst.PASSWORD, "nacos");

Expand All @@ -53,7 +54,7 @@ public void testServiceList() throws Exception {
map.put("version", "2.0");
instance.setMetadata(map);

namingService.registerInstance("nacos.test.1", instance);
namingService.registerInstance("nacos.test.1", "chuntaojun", instance);

ThreadUtils.sleep(5_000L);

Expand All @@ -62,10 +63,8 @@ public void testServiceList() throws Exception {
System.out.println(list);

ThreadUtils.sleep(60_000L);
// ExpressionSelector expressionSelector = new ExpressionSelector();
// expressionSelector.setExpression("INSTANCE.metadata.registerSource = 'dubbo'");
// ListView<String> serviceList = namingService.getServicesOfServer(1, 10, expressionSelector);

CountDownLatch latch = new CountDownLatch(1);
latch.await();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ private void loadSetting() {
setUseExternalDB(true);
}
}

if (isDirectRead()) {
logger.info("The current client read operation is a direct operation on the database");
} else {
logger.info("The current client read operation is to read the disk file");
}

} catch (Exception e) {
logger.error("read application.properties failed", e);
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,7 @@ public static String resolveRequiredPlaceholders(String text)
private static String localAddress = "";

public static String getLocalAddress() {
if (StringUtils.isBlank(localAddress)) {
localAddress = InetUtils.getSelfIp() + ":" + getPort();
}
return localAddress;
return InetUtils.getSelfIp() + ":" + getPort();
}

public static void setLocalAddress(String localAddress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.alibaba.nacos.core.utils;

import com.alibaba.nacos.core.cluster.ServerMemberManager;
import com.alibaba.nacos.common.executor.ExecutorFactory;
import com.alibaba.nacos.common.executor.NameThreadFactory;
import java.util.concurrent.ScheduledExecutorService;
Expand Down
15 changes: 10 additions & 5 deletions core/src/main/java/com/alibaba/nacos/core/utils/InetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.alibaba.nacos.core.notify.NotifyCenter;
import com.alibaba.nacos.core.notify.SlowEvent;
import org.apache.commons.lang3.StringUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -31,6 +31,7 @@
import java.util.Enumeration;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -50,6 +51,9 @@ public static class IPChangeEvent implements SlowEvent {
private String oldIp;
private String newIp;

public IPChangeEvent() {
}

public String getOldIp() {
return oldIp;
}
Expand Down Expand Up @@ -80,7 +84,7 @@ public String toString() {
+ "\\." + NUM + "$";
private static final Pattern IP_PATTERN = Pattern.compile(IP_REGEX);

private static String selfIp;
private volatile static String selfIp;

private static boolean useOnlySiteLocalInterface = false;

Expand Down Expand Up @@ -143,10 +147,11 @@ public void run() {
}
}

if (!Objects.equals(selfIp, tmpSelfIp) && Objects.nonNull(selfIp)) {
// If executed for the first time, selfIp is empty and no event is published
if (!Objects.equals(selfIp, tmpSelfIp) && StringUtils.isNotBlank(selfIp)) {
IPChangeEvent event = new IPChangeEvent();
event.setOldIp(selfIp);
event.setNewIp(tmpSelfIp);
event.setOldIp(Optional.ofNullable(selfIp).orElse(StringUtils.EMPTY));
event.setNewIp(Optional.ofNullable(tmpSelfIp).orElse(StringUtils.EMPTY));
NotifyCenter.publishEvent(event);
}
selfIp = tmpSelfIp;
Expand Down
Loading