use of com.alibaba.nacos.api.config.ConfigChangeItem 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.api.config.ConfigChangeItem 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);
}
use of com.alibaba.nacos.api.config.ConfigChangeItem in project nacos by alibaba.
the class TextChangeParser method doParse.
@Override
public Map<String, ConfigChangeItem> doParse(String oldContent, String newContent, String type) throws IOException {
Map<String, ConfigChangeItem> map = new HashMap<>(4);
final String key = "content";
ConfigChangeItem cci = new ConfigChangeItem(key, oldContent, newContent);
if (null == oldContent && null != newContent) {
cci.setType(PropertyChangeType.ADDED);
} else if (null != oldContent && null != newContent && !oldContent.equals(newContent)) {
cci.setType(PropertyChangeType.MODIFIED);
} else if (null != oldContent && null == newContent) {
cci.setType(PropertyChangeType.DELETED);
}
map.put(key, cci);
return map;
}
use of com.alibaba.nacos.api.config.ConfigChangeItem in project nacos by alibaba.
the class TextChangeParser method doParse.
@Override
public Map<String, ConfigChangeItem> doParse(String oldContent, String newContent, String type) throws IOException {
Map<String, ConfigChangeItem> map = new HashMap<>(4);
final String key = "content";
ConfigChangeItem cci = new ConfigChangeItem(key, oldContent, newContent);
if (null == oldContent && null != newContent) {
cci.setType(PropertyChangeType.ADDED);
} else if (null != oldContent && null != newContent && !oldContent.equals(newContent)) {
cci.setType(PropertyChangeType.MODIFIED);
} else if (null != oldContent && null == newContent) {
cci.setType(PropertyChangeType.DELETED);
}
map.put(key, cci);
return map;
}
Aggregations