Search in sources :

Example 1 with ServiceInfoHolder

use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.

the class FailoverReactorTest method testInit.

@Test
public void testInit() throws NacosException, NoSuchFieldException, IllegalAccessException {
    ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
    Mockito.when(holder.getServiceInfoMap()).thenReturn(new HashMap<>());
    FailoverReactor failoverReactor = new FailoverReactor(holder, "/tmp");
    Field executorService = FailoverReactor.class.getDeclaredField("executorService");
    executorService.setAccessible(true);
    ScheduledExecutorService o = (ScheduledExecutorService) executorService.get(failoverReactor);
    Assert.assertFalse(o.isShutdown());
    failoverReactor.shutdown();
    Assert.assertTrue(o.isShutdown());
}
Also used : Field(java.lang.reflect.Field) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) Test(org.junit.Test)

Example 2 with ServiceInfoHolder

use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder 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 3 with ServiceInfoHolder

use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.

the class NamingClientProxyDelegateTest method testQueryService.

@Test
public void testQueryService() 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 = delegate.queryService("a", "b");
    Assert.assertNull(service);
}
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) Test(org.junit.Test)

Example 4 with ServiceInfoHolder

use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.

the class NamingClientProxyDelegateTest method testRegisterServiceByHttp.

@Test
public void testRegisterServiceByHttp() 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 grpc
    instance.setEphemeral(false);
    delegate.registerService(serviceName, groupName, instance);
    verify(mockHttpClient, times(1)).registerService(serviceName, groupName, instance);
}
Also used : NamingHttpClientProxy(com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy) 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) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with ServiceInfoHolder

use of com.alibaba.nacos.client.naming.cache.ServiceInfoHolder in project nacos by alibaba.

the class NamingClientProxyDelegateTest method testUpdateBeatInfo.

@Test
public void testUpdateBeatInfo() 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);
    // HTTP ONLY
    Set<Instance> set = new HashSet<>();
    delegate.updateBeatInfo(set);
    verify(mockHttpClient, times(1)).updateBeatInfo(set);
}
Also used : NamingHttpClientProxy(com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy) 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) Properties(java.util.Properties) HashSet(java.util.HashSet) 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