Search in sources :

Example 21 with ServiceInfo

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

the class CatalogServiceV2ImplTest method testListInstances.

@Test
public void testListInstances() {
    try {
        Mockito.when(serviceStorage.getClusters(Mockito.any())).thenReturn(Collections.singleton("D"));
        ServiceInfo serviceInfo = new ServiceInfo();
        serviceInfo.setGroupName("B");
        serviceInfo.setName("C");
        Instance instance = new Instance();
        instance.setClusterName("D");
        instance.setIp("1.1.1.1");
        serviceInfo.setHosts(Collections.singletonList(instance));
        Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
        List<? extends Instance> instances = catalogServiceV2Impl.listInstances("A", "B", "C", "D");
        Assert.assertEquals(1, instances.size());
    } catch (NacosException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Instance(com.alibaba.nacos.api.naming.pojo.Instance) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 22 with ServiceInfo

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

the class CatalogServiceV2ImplTest method testPageListServiceDetail.

@Test
public void testPageListServiceDetail() {
    try {
        ServiceMetadata metadata = new ServiceMetadata();
        Mockito.when(metadataManager.getServiceMetadata(Mockito.any())).thenReturn(Optional.of(metadata));
        Instance instance = new Instance();
        instance.setServiceName("C");
        instance.setClusterName("D");
        List<Instance> instances = Collections.singletonList(instance);
        ServiceInfo serviceInfo = new ServiceInfo();
        serviceInfo.setHosts(instances);
        Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
        List<ServiceDetailInfo> result = (List<ServiceDetailInfo>) catalogServiceV2Impl.pageListServiceDetail("A", "B", "C", 1, 10);
        Assert.assertEquals(1, result.size());
    } catch (NacosException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Instance(com.alibaba.nacos.api.naming.pojo.Instance) ServiceDetailInfo(com.alibaba.nacos.naming.pojo.ServiceDetailInfo) List(java.util.List) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) NacosException(com.alibaba.nacos.api.exception.NacosException) Test(org.junit.Test)

Example 23 with ServiceInfo

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

the class InstanceOperatorClientImplTest method testPatchInstance.

@Test
public void testPatchInstance() throws NacosException {
    Instance instance = new Instance();
    instance.setIp("1.1.1.1");
    instance.setPort(8848);
    instance.setClusterName("C");
    List<Instance> instances = Collections.singletonList(instance);
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setHosts(instances);
    Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
    instanceOperatorClient.patchInstance("A", "B", new InstancePatchObject("C", "1.1.1.1", 8848));
    Mockito.verify(metadataOperateService).updateInstanceMetadata(Mockito.any(), Mockito.anyString(), Mockito.any());
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Instance(com.alibaba.nacos.api.naming.pojo.Instance) Test(org.junit.Test)

Example 24 with ServiceInfo

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

the class InstanceOperatorClientImplTest method testBatchUpdateMetadata.

@Test
public void testBatchUpdateMetadata() throws NacosException {
    Instance instance = new Instance();
    instance.setServiceName("C");
    instance.setIp("1.1.1.1");
    instance.setPort(8848);
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setHosts(Collections.singletonList(instance));
    Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
    InstanceOperationInfo instanceOperationInfo = new InstanceOperationInfo();
    List<String> res = instanceOperatorClient.batchUpdateMetadata("A", instanceOperationInfo, new HashMap<>());
    Assert.assertEquals(1, res.size());
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Instance(com.alibaba.nacos.api.naming.pojo.Instance) InstanceOperationInfo(com.alibaba.nacos.naming.pojo.InstanceOperationInfo) Test(org.junit.Test)

Example 25 with ServiceInfo

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

the class InstanceOperatorClientImplTest method testListAllInstances.

@Test
public void testListAllInstances() throws NacosException {
    ServiceInfo serviceInfo = new ServiceInfo();
    serviceInfo.setHosts(Collections.emptyList());
    Mockito.when(serviceStorage.getData(Mockito.any())).thenReturn(serviceInfo);
    List<? extends Instance> instances = instanceOperatorClient.listAllInstances("A", "C");
    Assert.assertEquals(0, instances.size());
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Test(org.junit.Test)

Aggregations

ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)74 Test (org.junit.Test)44 Instance (com.alibaba.nacos.api.naming.pojo.Instance)29 ArrayList (java.util.ArrayList)17 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)12 Properties (java.util.Properties)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 NacosException (com.alibaba.nacos.api.exception.NacosException)8 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)8 Before (org.junit.Before)8 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)7 Field (java.lang.reflect.Field)6 HashSet (java.util.HashSet)5 EventListener (com.alibaba.nacos.api.naming.listener.EventListener)4 SubscribeServiceResponse (com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse)4 PushDataWrapper (com.alibaba.nacos.naming.push.v2.PushDataWrapper)4 HashMap (java.util.HashMap)4 QueryServiceResponse (com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse)3 Secured (com.alibaba.nacos.auth.annotation.Secured)3 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)3