use of com.alibaba.nacos.client.config.listener.impl.AbstractConfigChangeListener in project nacos by alibaba.
the class ConfigLongPollReturnChanges_CITCase method testAdd.
@Test
public void testAdd() throws InterruptedException, NacosException {
CountDownLatch latch = new CountDownLatch(1);
final String dataId = "test" + System.currentTimeMillis();
final String group = "DEFAULT_GROUP";
final String content = "config data";
configService.addListener(dataId, group, new AbstractConfigChangeListener() {
@Override
public void receiveConfigChange(ConfigChangeEvent event) {
try {
ConfigChangeItem cci = event.getChangeItem("content");
Assert.assertNull(cci.getOldValue());
Assert.assertEquals(content, cci.getNewValue());
Assert.assertEquals(PropertyChangeType.ADDED, cci.getType());
System.out.println(cci);
} finally {
latch.countDown();
}
}
});
boolean result = configService.publishConfig(dataId, group, content);
Assert.assertTrue(result);
configService.getConfig(dataId, group, 50);
latch.await(10_000L, TimeUnit.MILLISECONDS);
}
use of com.alibaba.nacos.client.config.listener.impl.AbstractConfigChangeListener in project nacos by alibaba.
the class ConfigLongPollReturnChanges_CITCase method testModify.
@Test
public void testModify() throws InterruptedException, NacosException {
CountDownLatch latch = new CountDownLatch(1);
final String dataId = "test" + System.currentTimeMillis();
final String group = "DEFAULT_GROUP";
final String oldData = "old data";
final String newData = "new data";
boolean result = configService.publishConfig(dataId, group, oldData);
Assert.assertTrue(result);
configService.addListener(dataId, group, new AbstractConfigChangeListener() {
@Override
public void receiveConfigChange(ConfigChangeEvent event) {
try {
ConfigChangeItem cci = event.getChangeItem("content");
Assert.assertEquals(oldData, cci.getOldValue());
Assert.assertEquals(newData, cci.getNewValue());
Assert.assertEquals(PropertyChangeType.MODIFIED, cci.getType());
System.out.println(cci);
} finally {
latch.countDown();
}
}
});
configService.publishConfig(dataId, group, newData);
latch.await(10_000L, TimeUnit.MILLISECONDS);
}
Aggregations