Search in sources :

Example 6 with Service

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

the class NamingMaintainService_ITCase method createAndUpdateService.

@Test
public void createAndUpdateService() throws NacosException {
    String serviceName = randomDomainName();
    // register service
    Service preService = new Service();
    preService.setName(serviceName);
    preService.setGroupName(Constants.DEFAULT_GROUP);
    preService.setProtectThreshold(1.0f);
    Map<String, String> metadata = new HashMap<String, String>();
    metadata.put(serviceName, "this is a register metadata");
    preService.setMetadata(metadata);
    ExpressionSelector selector = new ExpressionSelector();
    selector.setExpression("CONSUMER.label.A=PROVIDER.label.A &CONSUMER.label.B=PROVIDER.label.B");
    System.out.println("service info : " + preService);
    namingMaintainService.createService(preService, selector);
    Service remoteService = namingMaintainService.queryService(serviceName);
    System.out.println("remote service info : " + remoteService);
    Assert.assertEquals(preService.toString(), remoteService.toString());
    // update service
    Service nowService = new Service();
    nowService.setName(serviceName);
    nowService.setGroupName(Constants.DEFAULT_GROUP);
    nowService.setProtectThreshold(1.0f);
    metadata.clear();
    metadata.put(serviceName, "this is a update metadata");
    nowService.setMetadata(metadata);
    namingMaintainService.updateService(nowService, new NoneSelector());
    remoteService = namingMaintainService.queryService(serviceName);
    System.out.println("remote service info : " + remoteService);
    Assert.assertEquals(nowService.toString(), remoteService.toString());
}
Also used : HashMap(java.util.HashMap) ExpressionSelector(com.alibaba.nacos.api.selector.ExpressionSelector) NamingMaintainService(com.alibaba.nacos.api.naming.NamingMaintainService) Service(com.alibaba.nacos.api.naming.pojo.Service) NamingService(com.alibaba.nacos.api.naming.NamingService) NoneSelector(com.alibaba.nacos.api.selector.NoneSelector) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with Service

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

the class NamingClientProxyDelegateTest method testCreateService.

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

Example 8 with Service

use of com.alibaba.nacos.api.naming.pojo.Service 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 9 with Service

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

the class NamingGrpcClientProxyTest method testUpdateService.

@Test
public void testUpdateService() throws NacosException {
    // TODO thrown.expect(UnsupportedOperationException.class);
    Service service = new Service();
    AbstractSelector selector = new NoneSelector();
    client.updateService(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 10 with Service

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

the class NamingGrpcClientProxyTest method testQueryService.

@Test
public void testQueryService() throws Exception {
    Service service = client.queryService(SERVICE_NAME, GROUP_NAME);
    Assert.assertNull(service);
}
Also used : Service(com.alibaba.nacos.api.naming.pojo.Service) NamingGrpcRedoService(com.alibaba.nacos.client.naming.remote.gprc.redo.NamingGrpcRedoService) Test(org.junit.Test)

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