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 2827]: hotfix config dump #2828

Merged
merged 5 commits into from
May 21, 2020
Merged
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 install -Pit-test
- mvn clean package -Pit-test
after_success:
- mvn clean package -Pit-test
- mvn sonar:sonar -Psonar-apache
35 changes: 31 additions & 4 deletions client/src/test/java/com/alibaba/nacos/client/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,46 @@

package com.alibaba.nacos.client;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
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;

/**
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
@Ignore
public class ConfigTest {

private ConfigService config7;
private ConfigService config8;
private ConfigService config9;
private ConfigService configService;

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

public void test() {
@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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.common.utils;

import java.util.Objects;
import java.util.Set;

/**
Expand All @@ -25,6 +26,8 @@ public class Observable {

private transient boolean changed = false;
private transient Set<Observer> obs = new ConcurrentHashSet<>();
private volatile int observerCnt = 0;
private boolean alreadyAddObserver = false;

/**
* Adds an observer to the set of observers for this object, provided
Expand All @@ -35,20 +38,24 @@ public class Observable {
* @param o an observer to be added.
* @throws NullPointerException if the parameter o is null.
*/
public void addObserver(Observer o) {
if (o == null) {
throw new NullPointerException();
}
public synchronized void addObserver(Observer o) {
Objects.requireNonNull(o, "Observer");
obs.add(o);
observerCnt ++;
if (!alreadyAddObserver) {
notifyAll();
}
alreadyAddObserver = true;
}

/**
* Deletes an observer from the set of observers of this object.
* Passing {@code null} to this method will have no effect.
* @param o the observer to be deleted.
*/
public void deleteObserver(Observer o) {
public synchronized void deleteObserver(Observer o) {
obs.remove(o);
observerCnt --;
}

/**
Expand Down Expand Up @@ -96,6 +103,9 @@ public void notifyObservers(Object arg) {
return;
}
clearChanged();
if (!alreadyAddObserver) {
ThreadUtils.objectWait(this);
}
}

for (Observer observer : obs) {
Expand Down Expand Up @@ -150,8 +160,8 @@ public synchronized boolean hasChanged() {
* @return the number of observers of this object.
*/
public int countObservers() {
return obs.size();
return observerCnt;
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
*/
public final class ThreadUtils {

public static void objectWait(Object object) {
try {
object.wait();
} catch (InterruptedException ignore) {
Thread.interrupted();
}
}

public static void sleep(long millis) {
try {
Thread.sleep(millis);
Expand All @@ -49,7 +57,8 @@ public static void latchAwait(CountDownLatch latch, long time, TimeUnit unit) {
}

/**
* 通过内核数,算出合适的线程数;1.5-2倍cpu内核数
* Through the number of cores, calculate the appropriate number of threads;
* 1.5-2 times the number of CPU cores
*
* @return thread count
*/
Expand Down
Loading