Search in sources :

Example 26 with ServiceDTO

use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.

the class BaseIntegrationTest method mockMetaServerHandler.

protected ContextHandler mockMetaServerHandler(final boolean failedAtFirstTime) {
    final ServiceDTO someServiceDTO = new ServiceDTO();
    someServiceDTO.setAppName(someAppName);
    someServiceDTO.setInstanceId(someInstanceId);
    someServiceDTO.setHomepageUrl(configServiceURL);
    final AtomicInteger counter = new AtomicInteger(0);
    ContextHandler context = new ContextHandler("/services/config");
    context.setHandler(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            if (failedAtFirstTime && counter.incrementAndGet() == 1) {
                response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
                baseRequest.setHandled(true);
                return;
            }
            response.setContentType("application/json;charset=UTF-8");
            response.setStatus(HttpServletResponse.SC_OK);
            response.getWriter().println(gson.toJson(Lists.newArrayList(someServiceDTO)));
            baseRequest.setHandled(true);
        }
    });
    return context;
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler)

Example 27 with ServiceDTO

use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.

the class RemoteConfigLongPollServiceTest method setUp.

@Before
public void setUp() throws Exception {
    MockInjector.setInstance(HttpClient.class, httpClient);
    someServerUrl = "http://someServer";
    ServiceDTO serviceDTO = mock(ServiceDTO.class);
    when(serviceDTO.getHomepageUrl()).thenReturn(someServerUrl);
    when(configServiceLocator.getConfigServices()).thenReturn(Lists.newArrayList(serviceDTO));
    MockInjector.setInstance(ConfigServiceLocator.class, configServiceLocator);
    MockInjector.setInstance(ConfigUtil.class, new MockConfigUtil());
    remoteConfigLongPollService = new RemoteConfigLongPollService();
    responseType = (Type) ReflectionTestUtils.getField(remoteConfigLongPollService, "m_responseType");
    someAppId = "someAppId";
    someCluster = "someCluster";
}
Also used : ServiceDTO(com.ctrip.framework.apollo.core.dto.ServiceDTO) Before(org.junit.Before)

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