Search in sources :

Example 1 with NamingGrpcClientProxy

use of com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy 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);
}
Also used : Field(java.lang.reflect.Field) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) InstancesChangeNotifier(com.alibaba.nacos.client.naming.event.InstancesChangeNotifier) NamingGrpcClientProxy(com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with NamingGrpcClientProxy

use of com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy 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());
}
Also used : Field(java.lang.reflect.Field) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) InstancesChangeNotifier(com.alibaba.nacos.client.naming.event.InstancesChangeNotifier) NamingGrpcClientProxy(com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with NamingGrpcClientProxy

use of com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy 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);
}
Also used : Field(java.lang.reflect.Field) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) InstancesChangeNotifier(com.alibaba.nacos.client.naming.event.InstancesChangeNotifier) NamingGrpcClientProxy(com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy) ExpressionSelector(com.alibaba.nacos.api.selector.ExpressionSelector) Properties(java.util.Properties) Test(org.junit.Test)

Example 4 with NamingGrpcClientProxy

use of com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy 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();
}
Also used : Field(java.lang.reflect.Field) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) InstancesChangeNotifier(com.alibaba.nacos.client.naming.event.InstancesChangeNotifier) NamingGrpcClientProxy(com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with NamingGrpcClientProxy

use of com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy 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);
}
Also used : Field(java.lang.reflect.Field) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) InstancesChangeNotifier(com.alibaba.nacos.client.naming.event.InstancesChangeNotifier) NamingGrpcClientProxy(com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)8 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)8 NamingGrpcClientProxy (com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy)8 Field (java.lang.reflect.Field)8 Properties (java.util.Properties)8 Test (org.junit.Test)8 Instance (com.alibaba.nacos.api.naming.pojo.Instance)2 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)1 AbstractSelector (com.alibaba.nacos.api.selector.AbstractSelector)1 ExpressionSelector (com.alibaba.nacos.api.selector.ExpressionSelector)1