use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testDeregisterServiceHttp.
@Test
public void testDeregisterServiceHttp() 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 http
instance.setEphemeral(false);
delegate.deregisterService(serviceName, groupName, instance);
verify(mockHttpClient, times(1)).deregisterService(serviceName, groupName, instance);
}
use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier in project nacos by alibaba.
the class NacosNamingService method init.
private void init(Properties properties) throws NacosException {
ValidatorUtils.checkInitParam(properties);
this.namespace = InitUtils.initNamespaceForNaming(properties);
InitUtils.initSerialization();
InitUtils.initWebRootContext(properties);
initLogName(properties);
this.changeNotifier = new InstancesChangeNotifier();
NotifyCenter.registerToPublisher(InstancesChangeEvent.class, 16384);
NotifyCenter.registerSubscriber(changeNotifier);
this.serviceInfoHolder = new ServiceInfoHolder(namespace, properties);
this.clientProxy = new NamingClientProxyDelegate(this.namespace, serviceInfoHolder, properties, changeNotifier);
}
use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier in project nacos by alibaba.
the class NamingClientProxyDelegateTest method testGetServiceList.
@Test
public void testGetServiceList() 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);
AbstractSelector selector = new ExpressionSelector();
int pageNo = 1;
int pageSize = 10;
String groupName = "group2";
delegate.getServiceList(pageNo, pageSize, groupName, selector);
verify(mockGrpcClient, times(1)).getServiceList(pageNo, pageSize, groupName, selector);
}
use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier 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.event.InstancesChangeNotifier 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"));
}
Aggregations