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());
}
}
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());
}
}
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());
}
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());
}
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());
}
Aggregations