use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testShutdown.
@Test
public void testShutdown() 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);
delegate.shutdown();
verify(mockGrpcClient, times(1)).shutdown();
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testDeleteService.
@Test
public void testDeleteService() 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);
Assert.assertFalse(delegate.deleteService("service", "group1"));
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testQueryInstancesOfService.
@Test
public void testQueryInstancesOfService() 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.queryInstancesOfService(serviceName, groupName, clusters, 0, false);
verify(mockGrpcClient, times(1)).queryInstancesOfService(serviceName, groupName, clusters, 0, false);
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testRegisterServiceByGrpc.
@Test
public void testRegisterServiceByGrpc() 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 http
instance.setEphemeral(true);
delegate.registerService(serviceName, groupName, instance);
verify(mockGrpcClient, times(1)).registerService(serviceName, groupName, instance);
}
use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testCreateService.
@Test
public void testCreateService() 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.createService(service, new NoneSelector());
} catch (Exception e) {
Assert.fail();
}
}
Aggregations