Search in sources :

Example 6 with ConfigFilterChainManager

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);
}
Also used : ConfigFilterChainManager(com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with ConfigFilterChainManager

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));
}
Also used : Listener(com.alibaba.nacos.api.config.listener.Listener) ConfigFilterChainManager(com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Test(org.junit.Test)

Example 8 with ConfigFilterChainManager

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());
}
Also used : Field(java.lang.reflect.Field) ConfigFilterChainManager(com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager) Properties(java.util.Properties) Test(org.junit.Test)

Example 9 with ConfigFilterChainManager

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));
}
Also used : AbstractListener(com.alibaba.nacos.api.config.listener.AbstractListener) Listener(com.alibaba.nacos.api.config.listener.Listener) ConfigFilterChainManager(com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager) AbstractListener(com.alibaba.nacos.api.config.listener.AbstractListener) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

ConfigFilterChainManager (com.alibaba.nacos.client.config.filter.impl.ConfigFilterChainManager)9 Properties (java.util.Properties)9 Test (org.junit.Test)9 Listener (com.alibaba.nacos.api.config.listener.Listener)4 AbstractListener (com.alibaba.nacos.api.config.listener.AbstractListener)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1