use of com.alibaba.nacos.api.config.listener.Listener in project nacos by alibaba.
the class ClientWorkerTest method testListenerWithTenant.
@Test
public void testListenerWithTenant() throws NacosException {
Properties prop = new Properties();
ConfigFilterChainManager filter = new ConfigFilterChainManager(new Properties());
ServerListManager agent = Mockito.mock(ServerListManager.class);
ClientWorker clientWorker = new ClientWorker(filter, agent, prop);
Listener listener = new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
}
};
String dataId = "a";
String group = "b";
clientWorker.addTenantListeners(dataId, group, Arrays.asList(listener));
List<Listener> listeners = clientWorker.getCache(dataId, group).getListeners();
Assert.assertEquals(1, listeners.size());
Assert.assertEquals(listener, listeners.get(0));
clientWorker.removeTenantListener(dataId, group, listener);
listeners = clientWorker.getCache(dataId, group).getListeners();
Assert.assertEquals(0, listeners.size());
String content = "d";
clientWorker.addTenantListenersWithContent(dataId, group, content, Arrays.asList(listener));
listeners = clientWorker.getCache(dataId, group).getListeners();
Assert.assertEquals(1, listeners.size());
Assert.assertEquals(listener, listeners.get(0));
clientWorker.removeTenantListener(dataId, group, listener);
listeners = clientWorker.getCache(dataId, group).getListeners();
Assert.assertEquals(0, listeners.size());
String tenant = "c";
CacheData cacheData = clientWorker.addCacheDataIfAbsent(dataId, group, tenant);
Assert.assertEquals(cacheData, clientWorker.getCache(dataId, group, tenant));
clientWorker.removeCache(dataId, group, tenant);
Assert.assertNull(clientWorker.getCache(dataId, group, tenant));
}
use of com.alibaba.nacos.api.config.listener.Listener in project nacos by alibaba.
the class NacosConfigServiceTest method testRemoveListener.
@Test
public void testRemoveListener() {
String dataId = "1";
String group = "2";
Listener listener = new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
}
};
nacosConfigService.removeListener(dataId, group, listener);
Mockito.verify(mockWoker, Mockito.times(1)).removeTenantListener(dataId, group, listener);
}
use of com.alibaba.nacos.api.config.listener.Listener in project nacos by alibaba.
the class ClientWorker method addTenantListenersWithContent.
/**
* Add listeners for tenant with content.
*
* @param dataId dataId of data
* @param group group of data
* @param content content
* @param listeners listeners
* @throws NacosException nacos exception
*/
public void addTenantListenersWithContent(String dataId, String group, String content, List<? extends Listener> listeners) throws NacosException {
group = blank2defaultGroup(group);
String tenant = agent.getTenant();
CacheData cache = addCacheDataIfAbsent(dataId, group, tenant);
synchronized (cache) {
cache.setContent(content);
for (Listener listener : listeners) {
cache.addListener(listener);
}
cache.setSyncWithServer(false);
agent.notifyListenConfig();
}
}
use of com.alibaba.nacos.api.config.listener.Listener in project nacos by alibaba.
the class ClientWorker method addTenantListeners.
/**
* Add listeners for tenant.
*
* @param dataId dataId of data
* @param group group of data
* @param listeners listeners
* @throws NacosException nacos exception
*/
public void addTenantListeners(String dataId, String group, List<? extends Listener> listeners) throws NacosException {
group = blank2defaultGroup(group);
String tenant = agent.getTenant();
CacheData cache = addCacheDataIfAbsent(dataId, group, tenant);
synchronized (cache) {
for (Listener listener : listeners) {
cache.addListener(listener);
}
cache.setSyncWithServer(false);
agent.notifyListenConfig();
}
}
use of com.alibaba.nacos.api.config.listener.Listener in project nacos by alibaba.
the class ConfigLongPoll_CITCase method test.
@Test
public void test() throws InterruptedException, NacosException {
configService.addListener("test", "DEFAULT_GROUP", new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
System.out.println(configInfo);
}
});
configService.addListener("test-1", "DEFAULT_GROUP", new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
System.out.println(configInfo);
}
});
TimeUnit.SECONDS.sleep(10);
}
Aggregations