Search in sources :

Example 16 with InstancesChangeNotifier

use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier in project nacos by alibaba.

the class NamingClientProxyDelegateTest method testUpdateInstance.

@Test
public void testUpdateInstance() 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);
    String serviceName = "service1";
    String groupName = "group1";
    Instance instance = new Instance();
    try {
        delegate.updateInstance(serviceName, groupName, instance);
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : 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) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 17 with InstancesChangeNotifier

use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier in project nacos by alibaba.

the class NamingClientProxyDelegateTest method testUpdateService.

@Test
public void testUpdateService() 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.updateService(service, new ExpressionSelector());
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) InstancesChangeNotifier(com.alibaba.nacos.client.naming.event.InstancesChangeNotifier) ExpressionSelector(com.alibaba.nacos.api.selector.ExpressionSelector) Service(com.alibaba.nacos.api.naming.pojo.Service) Properties(java.util.Properties) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 18 with InstancesChangeNotifier

use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier 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 19 with InstancesChangeNotifier

use of com.alibaba.nacos.client.naming.event.InstancesChangeNotifier 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)19 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)19 Properties (java.util.Properties)18 Test (org.junit.Test)18 Field (java.lang.reflect.Field)11 NamingGrpcClientProxy (com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy)8 Instance (com.alibaba.nacos.api.naming.pojo.Instance)6 NacosException (com.alibaba.nacos.api.exception.NacosException)3 Service (com.alibaba.nacos.api.naming.pojo.Service)3 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)3 NamingHttpClientProxy (com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy)3 ExpressionSelector (com.alibaba.nacos.api.selector.ExpressionSelector)2 NamingClientProxy (com.alibaba.nacos.client.naming.remote.NamingClientProxy)2 AbstractSelector (com.alibaba.nacos.api.selector.AbstractSelector)1 NoneSelector (com.alibaba.nacos.api.selector.NoneSelector)1 NamingClientProxyDelegate (com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate)1 HashSet (java.util.HashSet)1