use of com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager in project nacos by alibaba.
the class CacheDataTest method testConstructorAndEquals.
@Test
public void testConstructorAndEquals() {
ConfigFilterChainManager filter = new ConfigFilterChainManager(new Properties());
final CacheData cacheData1 = new CacheData(filter, "name1", "key", "group", "tenant");
Assert.assertEquals("CacheData [key, group]", cacheData1.toString());
final CacheData cacheData2 = new CacheData(filter, "name2", "key", "group");
Assert.assertEquals(cacheData1, cacheData2);
Assert.assertEquals(cacheData1.hashCode(), cacheData2.hashCode());
final CacheData cacheData3 = new CacheData(filter, "name2", "key3", "group", "tenant");
Assert.assertNotEquals(cacheData1, cacheData3);
}
use of com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager in project nacos by alibaba.
the class CacheDataTest method testCheckListenerMd5.
@Test
public void testCheckListenerMd5() {
ConfigFilterChainManager filter = new ConfigFilterChainManager(new Properties());
final CacheData data = new CacheData(filter, "name1", "key", "group", "tenant");
final List<String> list = new ArrayList<>();
Listener listener = new Listener() {
@Override
public Executor getExecutor() {
return Runnable::run;
}
@Override
public void receiveConfigInfo(String configInfo) {
list.add(configInfo);
}
};
data.addListener(listener);
data.checkListenerMd5();
Assert.assertTrue(data.checkListenersMd5Consistent());
Assert.assertEquals(0, list.size());
data.setContent("new");
Assert.assertFalse(data.checkListenersMd5Consistent());
data.checkListenerMd5();
Assert.assertEquals(1, list.size());
Assert.assertEquals("new", list.get(0));
}
use of com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager in project nacos by alibaba.
the class ClientWorkerTest method testShutdown.
@Test
public void testShutdown() throws NacosException, NoSuchFieldException, IllegalAccessException {
Properties prop = new Properties();
ConfigFilterChainManager filter = new ConfigFilterChainManager(new Properties());
ServerListManager agent = Mockito.mock(ServerListManager.class);
ClientWorker clientWorker = new ClientWorker(filter, agent, prop);
String dataId = "a";
String group = "b";
String tenant = "c";
String content = "d";
clientWorker.shutdown();
Field agent1 = ClientWorker.class.getDeclaredField("agent");
agent1.setAccessible(true);
ConfigTransportClient o = (ConfigTransportClient) agent1.get(clientWorker);
Assert.assertTrue(o.executor.isShutdown());
agent1.setAccessible(false);
Assert.assertTrue(clientWorker.isHealthServer());
Assert.assertEquals(null, clientWorker.getAgentName());
}
use of com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager 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));
}
Aggregations