fix bug for review

This commit is contained in:
mingyixu 2018-10-10 23:02:29 +08:00
parent 0857a7f406
commit 13845f7a7e

View File

@ -20,6 +20,7 @@ import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst; import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.config.ConfigService; import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.AbstractListener;
import com.alibaba.nacos.api.config.listener.Listener; import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult; import com.alibaba.nacos.client.config.impl.HttpSimpleClient.HttpResult;
@ -380,17 +381,12 @@ public class ConfigAPI_ITCase {
boolean result = iconfig.publishConfig(dataId, group, content); boolean result = iconfig.publishConfig(dataId, group, content);
Assert.assertTrue(result); Assert.assertTrue(result);
Listener ml = new Listener() { Listener ml = new AbstractListener() {
@Override @Override
public void receiveConfigInfo(String configInfo) { public void receiveConfigInfo(String configInfo) {
count.incrementAndGet(); count.incrementAndGet();
Assert.assertEquals(content, configInfo); Assert.assertEquals(content, configInfo);
} }
@Override
public Executor getExecutor() {
return null;
}
}; };
iconfig.addListener(dataId, group, ml); iconfig.addListener(dataId, group, ml);
while (count.get() == 0) { while (count.get() == 0) {
@ -414,16 +410,11 @@ public class ConfigAPI_ITCase {
iconfig.removeConfig(dataId, group); iconfig.removeConfig(dataId, group);
Thread.sleep(TIME_OUT); Thread.sleep(TIME_OUT);
Listener ml = new Listener() { Listener ml = new AbstractListener() {
@Override @Override
public void receiveConfigInfo(String configInfo) { public void receiveConfigInfo(String configInfo) {
count.incrementAndGet(); count.incrementAndGet();
} }
@Override
public Executor getExecutor() {
return null;
}
}; };
iconfig.addListener(dataId, group, ml); iconfig.addListener(dataId, group, ml);
Thread.sleep(TIME_OUT); Thread.sleep(TIME_OUT);
@ -447,29 +438,19 @@ public class ConfigAPI_ITCase {
*/ */
@Test(timeout = 5*TIME_OUT) @Test(timeout = 5*TIME_OUT)
public void nacos_removeListener_1() throws Exception { public void nacos_removeListener_1() throws Exception {
iconfig.addListener(dataId, group, new Listener() { iconfig.addListener(dataId, group, new AbstractListener() {
@Override @Override
public void receiveConfigInfo(String configInfo) { public void receiveConfigInfo(String configInfo) {
Assert.assertTrue(false); Assert.assertTrue(false);
} }
@Override
public Executor getExecutor() {
return null;
}
}); });
Thread.sleep(TIME_OUT); Thread.sleep(TIME_OUT);
try { try {
iconfig.removeListener(dataId, group, new Listener() { iconfig.removeListener(dataId, group, new AbstractListener() {
@Override @Override
public void receiveConfigInfo(String configInfo) { public void receiveConfigInfo(String configInfo) {
System.out.println("remove recieve:" + configInfo); System.out.println("remove recieve:" + configInfo);
} }
@Override
public Executor getExecutor() {
return null;
}
}); });
} catch (Exception e) { } catch (Exception e) {
@ -487,16 +468,11 @@ public class ConfigAPI_ITCase {
public void nacos_removeListener_2() { public void nacos_removeListener_2() {
group += "test.nacos"; group += "test.nacos";
try { try {
iconfig.removeListener(dataId, group, new Listener() { iconfig.removeListener(dataId, group, new AbstractListener() {
@Override @Override
public void receiveConfigInfo(String configInfo) { public void receiveConfigInfo(String configInfo) {
} }
@Override
public Executor getExecutor() {
return null;
}
}); });
} catch (Exception e) { } catch (Exception e) {
Assert.assertTrue(false); Assert.assertTrue(false);
@ -515,23 +491,13 @@ public class ConfigAPI_ITCase {
final String contentRemove = "test-abc-two"; final String contentRemove = "test-abc-two";
final AtomicInteger count = new AtomicInteger(0); final AtomicInteger count = new AtomicInteger(0);
Listener ml = new Listener() { Listener ml = new AbstractListener() {
@Override
public Executor getExecutor() {
return null;
}
@Override @Override
public void receiveConfigInfo(String configInfo) { public void receiveConfigInfo(String configInfo) {
count.incrementAndGet(); count.incrementAndGet();
} }
}; };
Listener ml1 = new Listener() { Listener ml1 = new AbstractListener() {
@Override
public Executor getExecutor() {
return null;
}
@Override @Override
public void receiveConfigInfo(String configInfo) { public void receiveConfigInfo(String configInfo) {
//System.out.println("ml1 remove listener recieve:" + configInfo); //System.out.println("ml1 remove listener recieve:" + configInfo);
@ -649,7 +615,6 @@ public class ConfigAPI_ITCase {
Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code); Assert.assertEquals(HttpURLConnection.HTTP_OK, result.code);
Assert.assertEquals(content, JSON.parseObject(result.content).getJSONObject("data").getString("content")); Assert.assertEquals(content, JSON.parseObject(result.content).getJSONObject("data").getString("content"));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
Assert.assertTrue(false); Assert.assertTrue(false);
} }
} }