Search in sources :

Example 1 with NoneSelector

use of com.alibaba.nacos.api.selector.NoneSelector 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 NoneSelector

use of com.alibaba.nacos.api.selector.NoneSelector 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 3 with NoneSelector

use of com.alibaba.nacos.api.selector.NoneSelector 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 4 with NoneSelector

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

the class NamingHttpClientProxyTest method testUpdateService.

@Test
public void testUpdateService() throws Exception {
    // given
    NacosRestTemplate nacosRestTemplate = mock(NacosRestTemplate.class);
    HttpRestResult<Object> a = new HttpRestResult<Object>();
    a.setData("");
    a.setCode(200);
    when(nacosRestTemplate.exchangeForm(any(), any(), any(), any(), any(), any())).thenReturn(a);
    SecurityProxy proxy = mock(SecurityProxy.class);
    ServerListManager mgr = mock(ServerListManager.class);
    when(mgr.getServerList()).thenReturn(Arrays.asList("localhost"));
    Properties props = new Properties();
    ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
    NamingHttpClientProxy clientProxy = new NamingHttpClientProxy("namespaceId", proxy, mgr, props, holder);
    final Field nacosRestTemplateField = NamingHttpClientProxy.class.getDeclaredField("nacosRestTemplate");
    nacosRestTemplateField.setAccessible(true);
    nacosRestTemplateField.set(clientProxy, nacosRestTemplate);
    String serviceName = "service1";
    String groupName = "group1";
    // when
    clientProxy.updateService(new Service(), new NoneSelector());
    // then
    verify(nacosRestTemplate, times(1)).exchangeForm(endsWith(UtilAndComs.nacosUrlService), any(), any(), any(), eq(HttpMethod.PUT), any());
}
Also used : ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) ServerListManager(com.alibaba.nacos.client.naming.core.ServerListManager) HttpRestResult(com.alibaba.nacos.common.http.HttpRestResult) Service(com.alibaba.nacos.api.naming.pojo.Service) Properties(java.util.Properties) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector) Field(java.lang.reflect.Field) SecurityProxy(com.alibaba.nacos.client.security.SecurityProxy) NacosRestTemplate(com.alibaba.nacos.common.http.client.NacosRestTemplate) Test(org.junit.Test)

Example 5 with NoneSelector

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

the class NamingHttpClientProxyTest method testGetServiceList.

@Test
public void testGetServiceList() throws Exception {
    // given
    NacosRestTemplate nacosRestTemplate = mock(NacosRestTemplate.class);
    HttpRestResult<Object> a = new HttpRestResult<Object>();
    a.setData("{\"count\":2,\"doms\":[\"aaa\",\"bbb\"]}");
    a.setCode(200);
    when(nacosRestTemplate.exchangeForm(any(), any(), any(), any(), any(), any())).thenReturn(a);
    SecurityProxy proxy = mock(SecurityProxy.class);
    ServerListManager mgr = mock(ServerListManager.class);
    when(mgr.getServerList()).thenReturn(Arrays.asList("localhost"));
    Properties props = new Properties();
    ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
    NamingHttpClientProxy clientProxy = new NamingHttpClientProxy("namespaceId", proxy, mgr, props, holder);
    final Field nacosRestTemplateField = NamingHttpClientProxy.class.getDeclaredField("nacosRestTemplate");
    nacosRestTemplateField.setAccessible(true);
    nacosRestTemplateField.set(clientProxy, nacosRestTemplate);
    String groupName = "group1";
    // when
    ListView<String> serviceList = clientProxy.getServiceList(1, 10, groupName, new NoneSelector());
    // then
    verify(nacosRestTemplate, times(1)).exchangeForm(endsWith("/service/list"), any(), any(), any(), eq(HttpMethod.GET), any());
    Assert.assertEquals(2, serviceList.getCount());
    Assert.assertEquals("aaa", serviceList.getData().get(0));
    Assert.assertEquals("bbb", serviceList.getData().get(1));
}
Also used : ServiceInfoHolder(com.alibaba.nacos.client.naming.cache.ServiceInfoHolder) ServerListManager(com.alibaba.nacos.client.naming.core.ServerListManager) HttpRestResult(com.alibaba.nacos.common.http.HttpRestResult) Properties(java.util.Properties) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector) Field(java.lang.reflect.Field) SecurityProxy(com.alibaba.nacos.client.security.SecurityProxy) NacosRestTemplate(com.alibaba.nacos.common.http.client.NacosRestTemplate) Test(org.junit.Test)

Aggregations

NoneSelector (com.alibaba.nacos.api.selector.NoneSelector)13 Service (com.alibaba.nacos.api.naming.pojo.Service)11 Test (org.junit.Test)11 AbstractSelector (com.alibaba.nacos.api.selector.AbstractSelector)5 NamingMaintainService (com.alibaba.nacos.api.naming.NamingMaintainService)4 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)4 Properties (java.util.Properties)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 ServerListManager (com.alibaba.nacos.client.naming.core.ServerListManager)3 SecurityProxy (com.alibaba.nacos.client.security.SecurityProxy)3 HttpRestResult (com.alibaba.nacos.common.http.HttpRestResult)3 NacosRestTemplate (com.alibaba.nacos.common.http.client.NacosRestTemplate)3 Field (java.lang.reflect.Field)3 NamingService (com.alibaba.nacos.api.naming.NamingService)2 NamingGrpcRedoService (com.alibaba.nacos.client.naming.remote.gprc.redo.NamingGrpcRedoService)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 ServiceListResponse (com.alibaba.nacos.api.naming.remote.response.ServiceListResponse)1 ExpressionSelector (com.alibaba.nacos.api.selector.ExpressionSelector)1 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)1