Search in sources :

Example 26 with ServiceInfoHolder

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

the class NamingClientProxyDelegateTest method testSubscribe.

@Test
public void testSubscribe() 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);
    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";
    ServiceInfo info = new ServiceInfo();
    info.setName(serviceName);
    info.setGroupName(groupName);
    info.setClusters(clusters);
    when(mockGrpcClient.subscribe(serviceName, groupName, clusters)).thenReturn(info);
    ServiceInfo actual = delegate.subscribe(serviceName, groupName, clusters);
    Assert.assertEquals(info, actual);
    verify(mockGrpcClient, times(1)).subscribe(serviceName, groupName, clusters);
    verify(holder, times(1)).processServiceInfo(info);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) 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 27 with ServiceInfoHolder

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

the class NamingClientProxyDelegateTest method testDeregisterServiceGrpc.

@Test
public void testDeregisterServiceGrpc() 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);
    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";
    Instance instance = new Instance();
    instance.setServiceName(serviceName);
    instance.setClusterName(groupName);
    instance.setIp("1.1.1.1");
    instance.setPort(1);
    // use grpc
    instance.setEphemeral(true);
    delegate.deregisterService(serviceName, groupName, instance);
    verify(mockGrpcClient, times(1)).deregisterService(serviceName, groupName, instance);
}
Also used : 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) NamingGrpcClientProxy(com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy) Properties(java.util.Properties) Test(org.junit.Test)

Example 28 with ServiceInfoHolder

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

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

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

the class NamingPushRequestHandlerTest method testRequestReply.

@Test
public void testRequestReply() {
    // given
    ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
    NamingPushRequestHandler handler = new NamingPushRequestHandler(holder);
    ServiceInfo info = new ServiceInfo("name", "cluster1");
    Request req = NotifySubscriberRequest.buildNotifySubscriberRequest(info);
    // when
    Response response = handler.requestReply(req);
    // then
    Assert.assertTrue(response instanceof NotifySubscriberResponse);
    verify(holder, times(1)).processServiceInfo(info);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Response(com.alibaba.nacos.api.remote.response.Response) NotifySubscriberResponse(com.alibaba.nacos.api.naming.remote.response.NotifySubscriberResponse) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) NotifySubscriberResponse(com.alibaba.nacos.api.naming.remote.response.NotifySubscriberResponse) NotifySubscriberRequest(com.alibaba.nacos.api.naming.remote.request.NotifySubscriberRequest) Request(com.alibaba.nacos.api.remote.request.Request) 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