Search in sources :

Example 21 with ServiceInfoHolder

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();
}
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 22 with ServiceInfoHolder

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"));
}
Also used : ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) InstancesChangeNotifier(com.alibaba.nacos.client.naming.event.InstancesChangeNotifier) Properties(java.util.Properties) Test(org.junit.Test)

Example 23 with ServiceInfoHolder

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);
}
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 24 with ServiceInfoHolder

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);
}
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 25 with ServiceInfoHolder

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();
    }
}
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)

Aggregations

ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)52 Test (org.junit.Test)51 Properties (java.util.Properties)41 Field (java.lang.reflect.Field)34 ServerListManager (com.alibaba.nacos.client.naming.core.ServerListManager)23 SecurityProxy (com.alibaba.nacos.client.security.SecurityProxy)23 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)19 HttpRestResult (com.alibaba.nacos.common.http.HttpRestResult)18 NacosRestTemplate (com.alibaba.nacos.common.http.client.NacosRestTemplate)18 Instance (com.alibaba.nacos.api.naming.pojo.Instance)10 NamingGrpcClientProxy (com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy)8 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)7 Service (com.alibaba.nacos.api.naming.pojo.Service)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 HashMap (java.util.HashMap)5 NoneSelector (com.alibaba.nacos.api.selector.NoneSelector)4 NacosException (com.alibaba.nacos.api.exception.NacosException)3 BeatReactor (com.alibaba.nacos.client.naming.beat.BeatReactor)3 NamingHttpClientProxy (com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy)3 ExecutorService (java.util.concurrent.ExecutorService)3