Search in sources :

Example 11 with InstancesChangeNotifier

use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier 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)

Example 12 with InstancesChangeNotifier

use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier 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);
}
Also used : Field(java.lang.reflect.Field) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) Instance(com.alibaba.nacos.api.naming.pojo.Instance) 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 13 with InstancesChangeNotifier

use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier 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();
    }
}
Also used : ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) InstancesChangeNotifier(com.alibaba.nacos.client.naming.event.InstancesChangeNotifier) Service(com.alibaba.nacos.api.naming.pojo.Service) Properties(java.util.Properties) NacosException(com.alibaba.nacos.api.exception.NacosException) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector) Test(org.junit.Test)

Example 14 with InstancesChangeNotifier

use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier 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);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) 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 15 with InstancesChangeNotifier

use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier 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);
}
Also used : Field(java.lang.reflect.Field) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) Instance(com.alibaba.nacos.api.naming.pojo.Instance) 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)19 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)19 Properties (java.util.Properties)18 Test (org.junit.Test)18 Field (java.lang.reflect.Field)11 NamingGrpcClientProxy (com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy)8 Instance (com.alibaba.nacos.api.naming.pojo.Instance)6 NacosException (com.alibaba.nacos.api.exception.NacosException)3 Service (com.alibaba.nacos.api.naming.pojo.Service)3 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)3 NamingHttpClientProxy (com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy)3 ExpressionSelector (com.alibaba.nacos.api.selector.ExpressionSelector)2 NamingClientProxy (com.alibaba.nacos.client.naming.remote.NamingClientProxy)2 AbstractSelector (com.alibaba.nacos.api.selector.AbstractSelector)1 NoneSelector (com.alibaba.nacos.api.selector.NoneSelector)1 NamingClientProxyDelegate (com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate)1 HashSet (java.util.HashSet)1