Search in sources :

Example 1 with NamingClientProxy

use of com.alibaba.nacos.client.naming.remote.NamingClientProxy in project nacos by alibaba.

the class NamingTestUtils method getBeatReactorByReflection.

public static BeatReactor getBeatReactorByReflection(NamingService namingService) throws NoSuchFieldException, IllegalAccessException {
    Field clientProxyField = namingService.getClass().getDeclaredField("clientProxy");
    clientProxyField.setAccessible(true);
    NamingClientProxy namingClientProxy = (NamingClientProxy) clientProxyField.get(namingService);
    Field httpClientProxyField = namingClientProxy.getClass().getDeclaredField("httpClientProxy");
    httpClientProxyField.setAccessible(true);
    NamingHttpClientProxy httpClientProxy = (NamingHttpClientProxy) httpClientProxyField.get(namingClientProxy);
    return httpClientProxy.getBeatReactor();
}
Also used : NamingHttpClientProxy(com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy) Field(java.lang.reflect.Field) NamingClientProxy(com.alibaba.nacos.client.naming.remote.NamingClientProxy)

Example 2 with NamingClientProxy

use of com.alibaba.nacos.client.naming.remote.NamingClientProxy in project nacos by alibaba.

the class ServiceInfoUpdateServiceTest method testScheduleUpdateIfAbsent.

@Test
public void testScheduleUpdateIfAbsent() throws InterruptedException, NacosException {
    String serviceName = "aa";
    String group = "bb";
    String clusters = "cc";
    ServiceInfo info = new ServiceInfo();
    info.setName(serviceName);
    info.setGroupName(group);
    info.setClusters(clusters);
    info.setLastRefTime(System.currentTimeMillis());
    ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
    NamingClientProxy proxy = Mockito.mock(NamingClientProxy.class);
    Mockito.when(proxy.queryInstancesOfService(serviceName, group, clusters, 0, false)).thenReturn(info);
    InstancesChangeNotifier notifyer = Mockito.mock(InstancesChangeNotifier.class);
    Properties prop = new Properties();
    final ServiceInfoUpdateService serviceInfoUpdateService = new ServiceInfoUpdateService(prop, holder, proxy, notifyer);
    serviceInfoUpdateService.scheduleUpdateIfAbsent("aa", "bb", "cc");
    TimeUnit.SECONDS.sleep(2);
    Mockito.verify(proxy).queryInstancesOfService(serviceName, group, clusters, 0, false);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) InstancesChangeNotifier(com.alibaba.nacos.client.naming.event.InstancesChangeNotifier) NamingClientProxy(com.alibaba.nacos.client.naming.remote.NamingClientProxy) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with NamingClientProxy

use of com.alibaba.nacos.client.naming.remote.NamingClientProxy in project nacos by alibaba.

the class ServiceInfoUpdateServiceTest method testStopUpdateIfContain.

@Test
public void testStopUpdateIfContain() throws NacosException {
    String serviceName = "aa";
    String group = "bb";
    String clusters = "cc";
    ServiceInfo info = new ServiceInfo();
    info.setName(serviceName);
    info.setGroupName(group);
    info.setClusters(clusters);
    info.setLastRefTime(System.currentTimeMillis());
    NamingClientProxy proxy = Mockito.mock(NamingClientProxy.class);
    Mockito.when(proxy.queryInstancesOfService(serviceName, group, clusters, 0, false)).thenReturn(info);
    InstancesChangeNotifier notifyer = Mockito.mock(InstancesChangeNotifier.class);
    Properties prop = new Properties();
    ServiceInfoHolder holder = Mockito.mock(ServiceInfoHolder.class);
    final ServiceInfoUpdateService serviceInfoUpdateService = new ServiceInfoUpdateService(prop, holder, proxy, notifyer);
    serviceInfoUpdateService.scheduleUpdateIfAbsent(serviceName, group, clusters);
    serviceInfoUpdateService.stopUpdateIfContain(serviceName, group, clusters);
    serviceInfoUpdateService.shutdown();
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) InstancesChangeNotifier(com.alibaba.nacos.client.naming.event.InstancesChangeNotifier) NamingClientProxy(com.alibaba.nacos.client.naming.remote.NamingClientProxy) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

NamingClientProxy (com.alibaba.nacos.client.naming.remote.NamingClientProxy)3 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)2 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)2 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 NamingHttpClientProxy (com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy)1 Field (java.lang.reflect.Field)1