diff options
author | Ola Aunrønning <olaa@verizonmedia.com> | 2019-12-18 12:28:49 +0100 |
---|---|---|
committer | Ola Aunrønning <olaa@verizonmedia.com> | 2019-12-18 12:31:32 +0100 |
commit | 6976e9a7b8288284ed9e13145b72f3e46c2420a6 (patch) | |
tree | 1f2d9c8a8d2af070cf6cfe38999bffb18cfd3635 /configserver | |
parent | a6f89a895b0d825b93ce08b1a194175d7d293eef (diff) |
Stabilize testGetLogs
Diffstat (limited to 'configserver')
3 files changed, 44 insertions, 40 deletions
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java index 0802db23ea7..f25b41bd121 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/ApplicationRepositoryTest.java @@ -353,27 +353,4 @@ public class ApplicationRepositoryTest { return applicationRepository.getMetadataFromSession(tenant, sessionId); } - private static class MockLogRetriever extends LogRetriever { - - @Override - public HttpResponse getLogs(String logServerHostname) { - return new MockHttpResponse(); - } - - private static class MockHttpResponse extends HttpResponse { - - private MockHttpResponse() { - super(200); - } - - @Override - public void render(OutputStream outputStream) throws IOException { - outputStream.write("log line".getBytes(StandardCharsets.UTF_8)); - } - - } - - - } - } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/MockLogRetriever.java b/configserver/src/test/java/com/yahoo/vespa/config/server/MockLogRetriever.java new file mode 100644 index 00000000000..06c07773e27 --- /dev/null +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/MockLogRetriever.java @@ -0,0 +1,34 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.config.server; + +import com.yahoo.container.jdisc.HttpResponse; +import com.yahoo.vespa.config.server.http.LogRetriever; + +import java.io.IOException; +import java.io.OutputStream; +import java.nio.charset.StandardCharsets; + +/** + * @author olaa + */ +public class MockLogRetriever extends LogRetriever { + + @Override + public HttpResponse getLogs(String logServerHostname) { + return new MockHttpResponse(); + } + + private static class MockHttpResponse extends HttpResponse { + + private MockHttpResponse() { + super(200); + } + + @Override + public void render(OutputStream outputStream) throws IOException { + outputStream.write("log line".getBytes(StandardCharsets.UTF_8)); + } + + } + +}
\ No newline at end of file diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java index 0acce9ed2c7..22ce0db89e2 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java @@ -2,8 +2,6 @@ package com.yahoo.vespa.config.server.http.v2; import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.tomakehurst.wiremock.WireMockServer; -import com.github.tomakehurst.wiremock.client.WireMock; import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.ApplicationName; @@ -13,6 +11,7 @@ import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.jdisc.Response; import com.yahoo.vespa.config.server.ApplicationRepository; +import com.yahoo.vespa.config.server.MockLogRetriever; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.ConfigConvergenceChecker; import com.yahoo.vespa.config.server.application.HttpProxy; @@ -31,16 +30,12 @@ import org.junit.Before; import org.junit.Test; import javax.ws.rs.client.Client; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.net.URI; import java.time.Clock; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static com.yahoo.config.model.api.container.ContainerServiceType.CLUSTERCONTROLLER_CONTAINER; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -80,6 +75,7 @@ public class ApplicationHandlerTest { applicationRepository = new ApplicationRepository(tenantRepository, provisioner, orchestrator, + new MockLogRetriever(), Clock.systemUTC()); listApplicationsHandler = new ListApplicationsHandler(ListApplicationsHandler.testOnlyContext(), tenantRepository, @@ -202,20 +198,17 @@ public class ApplicationHandlerTest { } @Test - public void testGetLogs() { - String path = "/logs?from=100&to=200"; + public void testGetLogs() throws IOException { applicationRepository.deploy(new File("src/test/apps/app-logserver-with-container"), prepareParams(applicationId)); - WireMockServer wireMock = new WireMockServer(wireMockConfig().port(8080)); - wireMock.start(); - WireMock.configureFor("localhost", wireMock.port()); - stubFor(get(urlEqualTo(path)) - .willReturn(aResponse() - .withStatus(200))); - String url = toUrlPath(applicationId, Zone.defaultZone(), true) + path; + String url = toUrlPath(applicationId, Zone.defaultZone(), true) + "/logs?from=100&to=200"; ApplicationHandler mockHandler = createApplicationHandler(); + HttpResponse response = mockHandler.handle(HttpRequest.createTestRequest(url, com.yahoo.jdisc.http.HttpRequest.Method.GET)); assertEquals(200, response.getStatus()); - wireMock.stop(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + response.render(baos); + assertEquals("log line", baos.toString()); } private void assertNotAllowed(com.yahoo.jdisc.http.HttpRequest.Method method) throws IOException { |