Search in sources :

Example 11 with Service

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

the class NamingHttpClientProxyTest method testQueryService.

@Test
public void testQueryService() throws Exception {
    // given
    NacosRestTemplate nacosRestTemplate = mock(NacosRestTemplate.class);
    HttpRestResult<Object> a = new HttpRestResult<Object>();
    a.setData("{\"name\":\"service1\",\"groupName\":\"group1\"}");
    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
    Service service = clientProxy.queryService(serviceName, groupName);
    // then
    verify(nacosRestTemplate, times(1)).exchangeForm(endsWith(UtilAndComs.nacosUrlService), any(), any(), any(), eq(HttpMethod.GET), any());
    Assert.assertEquals(serviceName, service.getName());
    Assert.assertEquals(groupName, service.getGroupName());
}
Also used : Field(java.lang.reflect.Field) 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) SecurityProxy(com.alibaba.nacos.client.security.SecurityProxy) Properties(java.util.Properties) NacosRestTemplate(com.alibaba.nacos.common.http.client.NacosRestTemplate) Test(org.junit.Test)

Example 12 with Service

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

the class NamingHttpClientProxyTest method testCreateService.

@Test
public void testCreateService() 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);
    // when
    clientProxy.createService(new Service(), new NoneSelector());
    // then
    verify(nacosRestTemplate, times(1)).exchangeForm(endsWith(UtilAndComs.nacosUrlService), any(), any(), any(), eq(HttpMethod.POST), any());
}
Also used : Field(java.lang.reflect.Field) 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) SecurityProxy(com.alibaba.nacos.client.security.SecurityProxy) Properties(java.util.Properties) NacosRestTemplate(com.alibaba.nacos.common.http.client.NacosRestTemplate) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector) Test(org.junit.Test)

Example 13 with Service

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

the class NacosNamingMaintainServiceTest method testCreateService4.

@Test
public void testCreateService4() throws NacosException {
    // given
    Service service = new Service();
    AbstractSelector selector = new NoneSelector();
    // when
    nacosNamingMaintainService.createService(service, selector);
    // then
    verify(serverProxy, times(1)).createService(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 14 with Service

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

the class NacosNamingMaintainService method createService.

@Override
public void createService(String serviceName, String groupName, float protectThreshold, String expression) throws NacosException {
    Service service = new Service();
    service.setName(serviceName);
    service.setGroupName(groupName);
    service.setProtectThreshold(protectThreshold);
    ExpressionSelector selector = new ExpressionSelector();
    selector.setExpression(expression);
    createService(service, selector);
}
Also used : ExpressionSelector(com.alibaba.nacos.api.selector.ExpressionSelector) NamingMaintainService(com.alibaba.nacos.api.naming.NamingMaintainService) Service(com.alibaba.nacos.api.naming.pojo.Service) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService)

Example 15 with Service

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

the class NacosNamingMaintainService method updateService.

@Override
public void updateService(String serviceName, String groupName, float protectThreshold, Map<String, String> metadata) throws NacosException {
    Service service = new Service();
    service.setName(serviceName);
    service.setGroupName(groupName);
    service.setProtectThreshold(protectThreshold);
    service.setMetadata(metadata);
    updateService(service, new NoneSelector());
}
Also used : NamingMaintainService(com.alibaba.nacos.api.naming.NamingMaintainService) Service(com.alibaba.nacos.api.naming.pojo.Service) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector)

Aggregations

Service (com.alibaba.nacos.api.naming.pojo.Service)18 Test (org.junit.Test)15 NoneSelector (com.alibaba.nacos.api.selector.NoneSelector)11 Properties (java.util.Properties)8 AbstractSelector (com.alibaba.nacos.api.selector.AbstractSelector)6 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)6 NamingMaintainService (com.alibaba.nacos.api.naming.NamingMaintainService)5 SecurityProxy (com.alibaba.nacos.client.security.SecurityProxy)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 ExpressionSelector (com.alibaba.nacos.api.selector.ExpressionSelector)3 ServerListManager (com.alibaba.nacos.client.naming.core.ServerListManager)3 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)3 NamingGrpcRedoService (com.alibaba.nacos.client.naming.remote.gprc.redo.NamingGrpcRedoService)3 HttpRestResult (com.alibaba.nacos.common.http.HttpRestResult)3 NacosRestTemplate (com.alibaba.nacos.common.http.client.NacosRestTemplate)3 Field (java.lang.reflect.Field)3 NacosException (com.alibaba.nacos.api.exception.NacosException)2 NamingService (com.alibaba.nacos.api.naming.NamingService)2 Instance (com.alibaba.nacos.api.naming.pojo.Instance)2 ServerListChangedEvent (com.alibaba.nacos.client.naming.event.ServerListChangedEvent)2