Search in sources :

Example 46 with ServiceInfoHolder

use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.

the class PushReceiverTest method testTestRunWithUnknown.

@Test
public void testTestRunWithUnknown() throws InterruptedException, IOException {
    ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
    final PushReceiver pushReceiver = new PushReceiver(holder);
    final ExecutorService executorService = Executors.newFixedThreadPool(1);
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            pushReceiver.run();
        }
    });
    TimeUnit.MILLISECONDS.sleep(10);
    PushReceiver.PushPacket pack1 = new PushReceiver.PushPacket();
    pack1.type = "unknown";
    pack1.data = "pack1";
    pack1.lastRefTime = 1;
    final String res1 = udpClientRun(pack1, pushReceiver);
    Assert.assertEquals("{\"type\": \"unknown-ack\", \"lastRefTime\":\"1\", \"data\":\"\"}", res1);
}
Also used : ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 47 with ServiceInfoHolder

use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.

the class PushReceiverTest method testTestRunDomAndService.

@Test
public void testTestRunDomAndService() throws InterruptedException, IOException {
    ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
    final PushReceiver pushReceiver = new PushReceiver(holder);
    final ExecutorService executorService = Executors.newFixedThreadPool(1);
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            pushReceiver.run();
        }
    });
    TimeUnit.MILLISECONDS.sleep(10);
    PushReceiver.PushPacket pack1 = new PushReceiver.PushPacket();
    pack1.type = "dom";
    pack1.data = "pack1";
    pack1.lastRefTime = 1;
    final String res1 = udpClientRun(pack1, pushReceiver);
    Assert.assertEquals("{\"type\": \"push-ack\", \"lastRefTime\":\"1\", \"data\":\"\"}", res1);
    verify(holder, times(1)).processServiceInfo(pack1.data);
    PushReceiver.PushPacket pack2 = new PushReceiver.PushPacket();
    pack2.type = "service";
    pack2.data = "pack2";
    pack2.lastRefTime = 2;
    final String res2 = udpClientRun(pack2, pushReceiver);
    Assert.assertEquals("{\"type\": \"push-ack\", \"lastRefTime\":\"2\", \"data\":\"\"}", res2);
    verify(holder, times(1)).processServiceInfo(pack2.data);
}
Also used : ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 48 with ServiceInfoHolder

use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.

the class PushReceiverTest method testShutdown.

@Test
public void testShutdown() throws NacosException, NoSuchFieldException, IllegalAccessException {
    ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
    final PushReceiver pushReceiver = new PushReceiver(holder);
    pushReceiver.shutdown();
    final Field closed = PushReceiver.class.getDeclaredField("closed");
    closed.setAccessible(true);
    final boolean o = (boolean) closed.get(pushReceiver);
    Assert.assertTrue(o);
}
Also used : Field(java.lang.reflect.Field) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) Test(org.junit.Test)

Example 49 with ServiceInfoHolder

use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.

the class PushReceiverTest method testTestRunWithDump.

@Test
public void testTestRunWithDump() throws InterruptedException, IOException {
    ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
    final PushReceiver pushReceiver = new PushReceiver(holder);
    final ExecutorService executorService = Executors.newFixedThreadPool(1);
    executorService.submit(new Runnable() {

        @Override
        public void run() {
            pushReceiver.run();
        }
    });
    TimeUnit.MILLISECONDS.sleep(10);
    PushReceiver.PushPacket pack1 = new PushReceiver.PushPacket();
    pack1.type = "dump";
    pack1.data = "pack1";
    pack1.lastRefTime = 1;
    final String res1 = udpClientRun(pack1, pushReceiver);
    Assert.assertEquals("{\"type\": \"dump-ack\", \"lastRefTime\": \"1\", \"data\":\"{}\"}", res1);
    verify(holder, times(1)).getServiceInfoMap();
}
Also used : ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 50 with ServiceInfoHolder

use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.

the class PushReceiverTest method testGetUdpPort.

@Test
public void testGetUdpPort() {
    ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
    final PushReceiver pushReceiver = new PushReceiver(holder);
    final int udpPort = pushReceiver.getUdpPort();
    System.out.println("udpPort = " + udpPort);
    Assert.assertTrue(udpPort > 0);
}
Also used : ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) Test(org.junit.Test)

Aggregations

ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)52 Test (org.junit.Test)51 Properties (java.util.Properties)41 Field (java.lang.reflect.Field)34 ServerListManager (com.alibaba.nacos.client.naming.core.ServerListManager)23 SecurityProxy (com.alibaba.nacos.client.security.SecurityProxy)23 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)19 HttpRestResult (com.alibaba.nacos.common.http.HttpRestResult)18 NacosRestTemplate (com.alibaba.nacos.common.http.client.NacosRestTemplate)18 Instance (com.alibaba.nacos.api.naming.pojo.Instance)10 NamingGrpcClientProxy (com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy)8 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)7 Service (com.alibaba.nacos.api.naming.pojo.Service)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 HashMap (java.util.HashMap)5 NoneSelector (com.alibaba.nacos.api.selector.NoneSelector)4 NacosException (com.alibaba.nacos.api.exception.NacosException)3 BeatReactor (com.alibaba.nacos.client.naming.beat.BeatReactor)3 NamingHttpClientProxy (com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy)3 ExecutorService (java.util.concurrent.ExecutorService)3