Search in sources :

Example 1 with ConfigFilterChainManager

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

Example 2 with ConfigFilterChainManager

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

Example 3 with ConfigFilterChainManager

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));
}
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)

Example 4 with ConfigFilterChainManager

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

Example 5 with ConfigFilterChainManager

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