Search in sources :

Example 46 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo 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 47 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo 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)

Example 48 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class InstancesChangeNotifierTest method testRegisterListener.

@Test
public void testRegisterListener() {
    String group = "a";
    String name = "b";
    String clusters = "c";
    InstancesChangeNotifier instancesChangeNotifier = new InstancesChangeNotifier();
    EventListener listener = Mockito.mock(EventListener.class);
    instancesChangeNotifier.registerListener(group, name, clusters, listener);
    List<ServiceInfo> subscribeServices = instancesChangeNotifier.getSubscribeServices();
    Assert.assertEquals(1, subscribeServices.size());
    Assert.assertEquals(group, subscribeServices.get(0).getGroupName());
    Assert.assertEquals(name, subscribeServices.get(0).getName());
    Assert.assertEquals(clusters, subscribeServices.get(0).getClusters());
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) EventListener(com.alibaba.nacos.api.naming.listener.EventListener) Test(org.junit.Test)

Example 49 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class NamingClientProxyDelegate method subscribe.

@Override
public ServiceInfo subscribe(String serviceName, String groupName, String clusters) throws NacosException {
    NAMING_LOGGER.info("[SUBSCRIBE-SERVICE] service:{}, group:{}, clusters:{} ", serviceName, groupName, clusters);
    String serviceNameWithGroup = NamingUtils.getGroupedName(serviceName, groupName);
    String serviceKey = ServiceInfo.getKey(serviceNameWithGroup, clusters);
    serviceInfoUpdateService.scheduleUpdateIfAbsent(serviceName, groupName, clusters);
    ServiceInfo result = serviceInfoHolder.getServiceInfoMap().get(serviceKey);
    if (null == result || !isSubscribed(serviceName, groupName, clusters)) {
        result = grpcClientProxy.subscribe(serviceName, groupName, clusters);
    }
    serviceInfoHolder.processServiceInfo(result);
    return result;
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo)

Example 50 with ServiceInfo

use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.

the class FailoverReactor method getService.

public ServiceInfo getService(String key) {
    ServiceInfo serviceInfo = serviceMap.get(key);
    if (serviceInfo == null) {
        serviceInfo = new ServiceInfo();
        serviceInfo.setName(key);
    }
    return serviceInfo;
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo)

Aggregations

ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)74 Test (org.junit.Test)44 Instance (com.alibaba.nacos.api.naming.pojo.Instance)29 ArrayList (java.util.ArrayList)17 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)12 Properties (java.util.Properties)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 NacosException (com.alibaba.nacos.api.exception.NacosException)8 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)8 Before (org.junit.Before)8 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)7 Field (java.lang.reflect.Field)6 HashSet (java.util.HashSet)5 EventListener (com.alibaba.nacos.api.naming.listener.EventListener)4 SubscribeServiceResponse (com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse)4 PushDataWrapper (com.alibaba.nacos.naming.push.v2.PushDataWrapper)4 HashMap (java.util.HashMap)4 QueryServiceResponse (com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse)3 Secured (com.alibaba.nacos.auth.annotation.Secured)3 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)3