use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class ConsulDiscoveryServiceTest method testGetServiceInstances.
@Test
public void testGetServiceInstances() {
String someIp = "1.2.3.4";
int somePort = 8080;
String someInstanceId = "someInstanceId";
ServiceInstance someServiceInstance = mockServiceInstance(someInstanceId, someIp, somePort);
when(consulDiscoveryClient.getInstances(someServiceId)).thenReturn(Lists.newArrayList(someServiceInstance));
List<ServiceDTO> serviceDTOList = consulDiscoveryService.getServiceInstances(someServiceId);
ServiceDTO serviceDTO = serviceDTOList.get(0);
assertEquals(1, serviceDTOList.size());
assertEquals(someServiceId, serviceDTO.getAppName());
assertEquals("http://1.2.3.4:8080/", serviceDTO.getHomepageUrl());
}
use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class KubernetesDiscoveryServiceTest method testGetAdminServiceInstances.
@Test
public void testGetAdminServiceInstances() {
String someUrl = "http://some-host/some-path";
String anotherUrl = "http://another-host/another-path";
when(bizConfig.getValue(adminServiceConfigName)).thenReturn(String.format("%s,%s", someUrl, anotherUrl));
List<ServiceDTO> serviceDTOList = kubernetesDiscoveryService.getServiceInstances(ServiceNameConsts.APOLLO_ADMINSERVICE);
assertEquals(2, serviceDTOList.size());
ServiceDTO serviceDTO = serviceDTOList.get(0);
assertEquals(ServiceNameConsts.APOLLO_ADMINSERVICE, serviceDTO.getAppName());
assertEquals(String.format("%s:%s", ServiceNameConsts.APOLLO_ADMINSERVICE, someUrl), serviceDTO.getInstanceId());
assertEquals(someUrl, serviceDTO.getHomepageUrl());
ServiceDTO anotherServiceDTO = serviceDTOList.get(1);
assertEquals(ServiceNameConsts.APOLLO_ADMINSERVICE, anotherServiceDTO.getAppName());
assertEquals(String.format("%s:%s", ServiceNameConsts.APOLLO_ADMINSERVICE, anotherUrl), anotherServiceDTO.getInstanceId());
assertEquals(anotherUrl, anotherServiceDTO.getHomepageUrl());
}
use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class DefaultDiscoveryServiceTest method testGetServiceInstances.
@Test
public void testGetServiceInstances() throws URISyntaxException {
String someUri = "http://1.2.3.4:8080/some-path/";
String someInstanceId = "someInstanceId";
InstanceInfo someServiceInstance = mockServiceInstance(someServiceId, someInstanceId, someUri);
String anotherUri = "http://2.3.4.5:9090/anotherPath";
String anotherInstanceId = "anotherInstanceId";
InstanceInfo anotherServiceInstance = mockServiceInstance(someServiceId, anotherInstanceId, anotherUri);
when(eurekaClient.getApplication(someServiceId)).thenReturn(someApplication);
when(someApplication.getInstances()).thenReturn(Lists.newArrayList(someServiceInstance, anotherServiceInstance));
List<ServiceDTO> serviceDTOList = defaultDiscoveryService.getServiceInstances(someServiceId);
assertEquals(2, serviceDTOList.size());
check(someServiceInstance, serviceDTOList.get(0));
check(anotherServiceInstance, serviceDTOList.get(1));
}
use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class NacosDiscoveryServiceTest method testGetServiceInstances.
@Test
public void testGetServiceInstances() throws Exception {
String someIp = "1.2.3.4";
int somePort = 8080;
String someInstanceId = "someInstanceId";
Instance someServiceInstance = mockServiceInstance(someInstanceId, someIp, somePort);
when(nacosNamingService.selectInstances(someServiceId, true)).thenReturn(Lists.newArrayList(someServiceInstance));
List<ServiceDTO> serviceDTOList = nacosDiscoveryService.getServiceInstances(someServiceId);
ServiceDTO serviceDTO = serviceDTOList.get(0);
assertEquals(1, serviceDTOList.size());
assertEquals(someServiceId, serviceDTO.getAppName());
assertEquals("http://1.2.3.4:8080/", serviceDTO.getHomepageUrl());
}
use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class RetryableRestTemplateTest method mockService.
private ServiceDTO mockService(String homeUrl) {
ServiceDTO serviceDTO = new ServiceDTO();
serviceDTO.setHomepageUrl(homeUrl);
return serviceDTO;
}
Aggregations