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