Search in sources :

Example 6 with ServiceDTO

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());
}
Also used : ServiceInstance(org.springframework.cloud.client.ServiceInstance) ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO) Test(org.junit.Test)

Example 7 with ServiceDTO

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());
}
Also used : ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO) Test(org.junit.Test)

Example 8 with ServiceDTO

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));
}
Also used : ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 9 with ServiceDTO

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());
}
Also used : Instance(com.alibaba.nacos.api.naming.pojo.Instance) ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO) Test(org.junit.Test)

Example 10 with ServiceDTO

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;
}
Also used : ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO)

Aggregations

ServiceDTO (com.ctrip.framework.apollo.core.dto.ServiceDTO)27 Test (org.junit.Test)7 Transaction (com.ctrip.framework.apollo.tracer.spi.Transaction)5 InstanceInfo (com.netflix.appinfo.InstanceInfo)4 ServiceException (com.ctrip.framework.apollo.common.exception.ServiceException)3 HttpRequest (com.ctrip.framework.apollo.util.http.HttpRequest)3 List (java.util.List)3 Function (java.util.function.Function)3 ServiceInstance (org.springframework.cloud.client.ServiceInstance)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Instance (com.alibaba.nacos.api.naming.pojo.Instance)2 ApolloConfigException (com.ctrip.framework.apollo.exceptions.ApolloConfigException)2 Before (org.junit.Before)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)1 ApolloConfigStatusCodeException (com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException)1 EnvironmentInfo (com.ctrip.framework.apollo.portal.entity.vo.EnvironmentInfo)1 Env (com.ctrip.framework.apollo.portal.environment.Env)1 OrderedProperties (com.ctrip.framework.apollo.util.OrderedProperties)1 HttpResponse (com.ctrip.framework.apollo.util.http.HttpResponse)1