use of com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager in project nacos by alibaba.
the class CacheDataTest method testListener.
@Test
public void testListener() {
ConfigFilterChainManager filter = new ConfigFilterChainManager(new Properties());
final CacheData cacheData1 = new CacheData(filter, "name1", "key", "group", "tenant");
Listener listener = new Listener() {
@Override
public Executor getExecutor() {
return null;
}
@Override
public void receiveConfigInfo(String configInfo) {
}
};
cacheData1.addListener(listener);
Assert.assertEquals(1, cacheData1.getListeners().size());
Assert.assertEquals(listener, cacheData1.getListeners().get(0));
cacheData1.removeListener(listener);
Assert.assertEquals(0, cacheData1.getListeners().size());
}
use of com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager in project nacos by alibaba.
the class CacheDataTest method testGetter.
@Test
public void testGetter() {
ConfigFilterChainManager filter = new ConfigFilterChainManager(new Properties());
final CacheData cacheData1 = new CacheData(filter, "name1", "key", "group", "tenant");
Assert.assertTrue(cacheData1.isInitializing());
Assert.assertNull(cacheData1.getContent());
Assert.assertEquals(0, cacheData1.getTaskId());
Assert.assertFalse(cacheData1.isSyncWithServer());
Assert.assertFalse(cacheData1.isUseLocalConfigInfo());
Assert.assertEquals(0, cacheData1.getLastModifiedTs().intValue());
Assert.assertEquals(0, cacheData1.getLocalConfigInfoVersion());
cacheData1.setInitializing(false);
cacheData1.setContent("123");
cacheData1.setTaskId(123);
cacheData1.setSyncWithServer(true);
cacheData1.setType("123");
long timeStamp = new Date().getTime();
cacheData1.setLastModifiedTs(timeStamp);
cacheData1.setUseLocalConfigInfo(true);
cacheData1.setLocalConfigInfoVersion(timeStamp);
Assert.assertFalse(cacheData1.isInitializing());
Assert.assertEquals("123", cacheData1.getContent());
Assert.assertEquals(MD5Utils.md5Hex("123", "UTF-8"), cacheData1.getMd5());
Assert.assertEquals(123, cacheData1.getTaskId());
Assert.assertTrue(cacheData1.isSyncWithServer());
Assert.assertEquals("123", cacheData1.getType());
Assert.assertTrue(cacheData1.isUseLocalConfigInfo());
Assert.assertEquals(timeStamp, cacheData1.getLastModifiedTs().longValue());
Assert.assertEquals(timeStamp, cacheData1.getLocalConfigInfoVersion());
}
use of com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager in project nacos by alibaba.
the class ClientWorkerTest method testAddListenerWithoutTenant.
@Test
public void testAddListenerWithoutTenant() 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);
String dataId = "a";
String group = "b";
Listener listener = new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
}
};
clientWorker.addListeners(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.removeListener(dataId, group, listener);
listeners = clientWorker.getCache(dataId, group).getListeners();
Assert.assertEquals(0, listeners.size());
CacheData cacheData = clientWorker.addCacheDataIfAbsent(dataId, group);
Assert.assertEquals(cacheData, clientWorker.getCache(dataId, group));
}
use of com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager in project nacos by alibaba.
the class ClientWorkerTest method testPublishConfig.
@Test
public void testPublishConfig() 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);
ClientWorker.ConfigRpcTransportClient mockClient = Mockito.mock(ClientWorker.ConfigRpcTransportClient.class);
String dataId = "a";
String group = "b";
String tenant = "c";
String content = "d";
String appName = "app";
String tag = "tag";
String betaIps = "1.1.1.1";
String casMd5 = "1111";
String type = "properties";
boolean b = clientWorker.publishConfig(dataId, group, tenant, appName, tag, betaIps, content, null, casMd5, type);
Assert.assertFalse(b);
try {
clientWorker.removeConfig(dataId, group, tenant, tag);
Assert.fail();
} catch (NacosException e) {
Assert.assertEquals("Client not connected, current status:STARTING", e.getErrMsg());
Assert.assertEquals(-401, e.getErrCode());
}
try {
clientWorker.getServerConfig(dataId, group, tenant, 100, false);
Assert.fail();
} catch (NacosException e) {
Assert.assertEquals("Client not connected, current status:STARTING", e.getErrMsg());
Assert.assertEquals(-401, e.getErrCode());
}
}
use of com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager in project nacos by alibaba.
the class ClientWorkerTest method testConstruct.
@Test
public void testConstruct() 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);
Assert.assertNotNull(clientWorker);
}
Aggregations