Search in sources :

Example 51 with ServiceInfoHolder

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

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

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