use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testUnsubscribe.
@Test
public void testUnsubscribe() throws NacosException, IllegalAccessException, NoSuchFieldException {
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";
delegate.unsubscribe(serviceName, groupName, clusters);
verify(mockGrpcClient, times(1)).unsubscribe(serviceName, groupName, clusters);
}
use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testQueryService.
@Test
public void testQueryService() 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 = delegate.queryService("a", "b");
Assert.assertNull(service);
}
use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testRegisterServiceByHttp.
@Test
public void testRegisterServiceByHttp() 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);
NamingHttpClientProxy mockHttpClient = Mockito.mock(NamingHttpClientProxy.class);
Field mockHttpClientField = NamingClientProxyDelegate.class.getDeclaredField("httpClientProxy");
mockHttpClientField.setAccessible(true);
mockHttpClientField.set(delegate, mockHttpClient);
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(false);
delegate.registerService(serviceName, groupName, instance);
verify(mockHttpClient, times(1)).registerService(serviceName, groupName, instance);
}
use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testUpdateBeatInfo.
@Test
public void testUpdateBeatInfo() 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);
NamingHttpClientProxy mockHttpClient = Mockito.mock(NamingHttpClientProxy.class);
Field mockHttpClientField = NamingClientProxyDelegate.class.getDeclaredField("httpClientProxy");
mockHttpClientField.setAccessible(true);
mockHttpClientField.set(delegate, mockHttpClient);
// HTTP ONLY
Set<Instance> set = new HashSet<>();
delegate.updateBeatInfo(set);
verify(mockHttpClient, times(1)).updateBeatInfo(set);
}
use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testServerHealthy.
@Test
public void testServerHealthy() throws IllegalAccessException, NacosException, NoSuchFieldException {
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);
Mockito.when(mockGrpcClient.serverHealthy()).thenReturn(true);
Assert.assertTrue(delegate.serverHealthy());
}
Aggregations