use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testSubscribe.
@Test
public void testSubscribe() throws NacosException, NoSuchFieldException, IllegalAccessException {
String ns = "ns1";
ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
Properties props = new Properties();
props.setProperty("serverAddr", "localhost");
InstancesChangeNotifier notifier = new InstancesChangeNotifier();
NamingClientProxyDelegate delegate = new NamingClientProxyDelegate(ns, holder, props, notifier);
NamingGrpcClientProxy mockGrpcClient = Mockito.mock(NamingGrpcClientProxy.class);
Field grpcClientProxyField = NamingClientProxyDelegate.class.getDeclaredField("grpcClientProxy");
grpcClientProxyField.setAccessible(true);
grpcClientProxyField.set(delegate, mockGrpcClient);
String serviceName = "service1";
String groupName = "group1";
String clusters = "cluster1";
ServiceInfo info = new ServiceInfo();
info.setName(serviceName);
info.setGroupName(groupName);
info.setClusters(clusters);
when(mockGrpcClient.subscribe(serviceName, groupName, clusters)).thenReturn(info);
ServiceInfo actual = delegate.subscribe(serviceName, groupName, clusters);
Assert.assertEquals(info, actual);
verify(mockGrpcClient, times(1)).subscribe(serviceName, groupName, clusters);
verify(holder, times(1)).processServiceInfo(info);
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testDeregisterServiceGrpc.
@Test
public void testDeregisterServiceGrpc() throws NacosException, NoSuchFieldException, IllegalAccessException {
String ns = "ns1";
ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
Properties props = new Properties();
props.setProperty("serverAddr", "localhost");
InstancesChangeNotifier notifier = new InstancesChangeNotifier();
NamingClientProxyDelegate delegate = new NamingClientProxyDelegate(ns, holder, props, notifier);
NamingGrpcClientProxy mockGrpcClient = Mockito.mock(NamingGrpcClientProxy.class);
Field grpcClientProxyField = NamingClientProxyDelegate.class.getDeclaredField("grpcClientProxy");
grpcClientProxyField.setAccessible(true);
grpcClientProxyField.set(delegate, mockGrpcClient);
String serviceName = "service1";
String groupName = "group1";
Instance instance = new Instance();
instance.setServiceName(serviceName);
instance.setClusterName(groupName);
instance.setIp("1.1.1.1");
instance.setPort(1);
// use grpc
instance.setEphemeral(true);
delegate.deregisterService(serviceName, groupName, instance);
verify(mockGrpcClient, times(1)).deregisterService(serviceName, groupName, instance);
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testUpdateInstance.
@Test
public void testUpdateInstance() throws NacosException {
String ns = "ns1";
ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
Properties props = new Properties();
props.setProperty("serverAddr", "localhost");
InstancesChangeNotifier notifier = new InstancesChangeNotifier();
NamingClientProxyDelegate delegate = new NamingClientProxyDelegate(ns, holder, props, notifier);
String serviceName = "service1";
String groupName = "group1";
Instance instance = new Instance();
try {
delegate.updateInstance(serviceName, groupName, instance);
} catch (Exception e) {
Assert.fail();
}
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testUpdateService.
@Test
public void testUpdateService() throws NacosException {
String ns = "ns1";
ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
Properties props = new Properties();
props.setProperty("serverAddr", "localhost");
InstancesChangeNotifier notifier = new InstancesChangeNotifier();
NamingClientProxyDelegate delegate = new NamingClientProxyDelegate(ns, holder, props, notifier);
Service service = new Service();
try {
delegate.updateService(service, new ExpressionSelector());
} catch (Exception e) {
Assert.fail();
}
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingPushRequestHandlerTest method testRequestReply.
@Test
public void testRequestReply() {
// given
ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
NamingPushRequestHandler handler = new NamingPushRequestHandler(holder);
ServiceInfo info = new ServiceInfo("name", "cluster1");
Request req = NotifySubscriberRequest.buildNotifySubscriberRequest(info);
// when
Response response = handler.requestReply(req);
// then
Assert.assertTrue(response instanceof NotifySubscriberResponse);
verify(holder, times(1)).processServiceInfo(info);
}
Aggregations