Search in sources :

Example 1 with AbstractSelector

use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.

the class NacosNamingMaintainServiceTest method testUpdateService3.

@Test
public void testUpdateService3() throws NacosException {
    // given
    Service service = new Service();
    AbstractSelector selector = new NoneSelector();
    // when
    nacosNamingMaintainService.updateService(service, selector);
    // then
    verify(serverProxy, times(1)).updateService(service, selector);
}
Also used : AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) Service(com.alibaba.nacos.api.naming.pojo.Service) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector) Test(org.junit.Test)

Example 2 with AbstractSelector

use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.

the class NacosNamingServiceTest method testGetServicesOfServer3.

@Test
public void testGetServicesOfServer3() throws NacosException {
    // given
    int pageNo = 1;
    int pageSize = 10;
    AbstractSelector selector = new AbstractSelector("aaa") {

        @Override
        public String getType() {
            return super.getType();
        }
    };
    // when
    client.getServicesOfServer(pageNo, pageSize, selector);
    // then
    verify(proxy, times(1)).getServiceList(pageNo, pageSize, Constants.DEFAULT_GROUP, selector);
}
Also used : AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) Test(org.junit.Test)

Example 3 with AbstractSelector

use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.

the class NamingGrpcClientProxyTest method testGetServiceList.

@Test
public void testGetServiceList() throws Exception {
    ServiceListResponse res = new ServiceListResponse();
    List<String> services = Arrays.asList("service1", "service2");
    res.setServiceNames(services);
    res.setCount(5);
    when(this.rpcClient.request(any())).thenReturn(res);
    AbstractSelector selector = new NoneSelector();
    ListView<String> serviceList = client.getServiceList(1, 10, GROUP_NAME, selector);
    Assert.assertEquals(5, serviceList.getCount());
    Assert.assertEquals(services, serviceList.getData());
}
Also used : AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) ServiceListResponse(com.alibaba.nacos.api.naming.remote.response.ServiceListResponse) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector) Test(org.junit.Test)

Example 4 with AbstractSelector

use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.

the class NamingGrpcClientProxyTest method testCreateService.

@Test
public void testCreateService() throws Exception {
    // TODO thrown.expect(UnsupportedOperationException.class);
    Service service = new Service();
    AbstractSelector selector = new NoneSelector();
    client.createService(service, selector);
}
Also used : AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) Service(com.alibaba.nacos.api.naming.pojo.Service) NamingGrpcRedoService(com.alibaba.nacos.client.naming.remote.gprc.redo.NamingGrpcRedoService) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector) Test(org.junit.Test)

Example 5 with AbstractSelector

use of com.alibaba.nacos.api.selector.AbstractSelector in project nacos by alibaba.

the class NamingClientProxyDelegateTest method testGetServiceList.

@Test
public void testGetServiceList() 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);
    AbstractSelector selector = new ExpressionSelector();
    int pageNo = 1;
    int pageSize = 10;
    String groupName = "group2";
    delegate.getServiceList(pageNo, pageSize, groupName, selector);
    verify(mockGrpcClient, times(1)).getServiceList(pageNo, pageSize, groupName, selector);
}
Also used : Field(java.lang.reflect.Field) ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) AbstractSelector(com.alibaba.nacos.api.selector.AbstractSelector) InstancesChangeNotifier(com.alibaba.nacos.client.naming.event.InstancesChangeNotifier) NamingGrpcClientProxy(com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy) ExpressionSelector(com.alibaba.nacos.api.selector.ExpressionSelector) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

AbstractSelector (com.alibaba.nacos.api.selector.AbstractSelector)10 Test (org.junit.Test)10 Service (com.alibaba.nacos.api.naming.pojo.Service)6 NoneSelector (com.alibaba.nacos.api.selector.NoneSelector)5 Properties (java.util.Properties)3 Instance (com.alibaba.nacos.api.naming.pojo.Instance)2 ServerListChangedEvent (com.alibaba.nacos.client.naming.event.ServerListChangedEvent)2 NamingGrpcRedoService (com.alibaba.nacos.client.naming.remote.gprc.redo.NamingGrpcRedoService)2 SecurityProxy (com.alibaba.nacos.client.security.SecurityProxy)2 Set (java.util.Set)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 ServiceListResponse (com.alibaba.nacos.api.naming.remote.response.ServiceListResponse)1 ExpressionSelector (com.alibaba.nacos.api.selector.ExpressionSelector)1 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)1 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)1 NamingGrpcClientProxy (com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy)1 Field (java.lang.reflect.Field)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1