Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions integration-tests/application-server-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,27 +129,11 @@
<version>1.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>5.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
<version>${version.json-schema-validator}</version>
<scope>test</scope>
<exclusions>
<!--
mockserver-client does not work with the latest jackson version
see https://github.com/jamesdbloom/mockserver/issues/440
-->
<exclusion>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
import okhttp3.logging.HttpLoggingInterceptor;
import org.junit.After;
import org.junit.Test;
import org.mockserver.model.ClearType;
import org.mockserver.model.HttpRequest;
import org.mockserver.model.HttpResponse;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.MountableFile;
Expand All @@ -59,9 +56,7 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import static co.elastic.apm.agent.report.IntakeV2ReportingEventHandler.INTAKE_V2_URL;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockserver.model.HttpRequest.request;

/**
* When you want to execute the test in the IDE, execute {@code mvn clean package} before.
Expand All @@ -84,18 +79,17 @@ public abstract class AbstractServletContainerIntegrationTest {
@Nullable
private static final String AGENT_VERSION_TO_DOWNLOAD_FROM_MAVEN = null;

private static final MockServerContainer mockServerContainer;
private static final MockApmServerContainer mockServerContainer;

private static final OkHttpClient httpClient;

static {
mockServerContainer = new MockServerContainer()
mockServerContainer = new MockApmServerContainer()
.withNetworkAliases("apm-server")
.waitingFor(Wait.forHttp(MockServerContainer.HEALTH_ENDPOINT).forStatusCode(200))
.withNetwork(Network.SHARED);

if (JavaExecutable.isDebugging()) {
mockServerContainer.withLogConsumer(TestContainersUtils.createSlf4jLogConsumer(MockServerContainer.class));
mockServerContainer.withLogConsumer(TestContainersUtils.createSlf4jLogConsumer(MockApmServerContainer.class));
}

final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(logger::info);
Expand All @@ -106,8 +100,6 @@ public abstract class AbstractServletContainerIntegrationTest {
.build();

mockServerContainer.start();
mockServerContainer.getClient().when(request(INTAKE_V2_URL)).respond(HttpResponse.response().withStatusCode(200));
mockServerContainer.getClient().when(request("/")).respond(HttpResponse.response().withStatusCode(200));
}

private final MockReporter mockReporter = new MockReporter();
Expand Down Expand Up @@ -150,7 +142,7 @@ protected AbstractServletContainerIntegrationTest(AgentTestContainer.AppServer c

container
.withNetwork(Network.SHARED)
.withEnv("ELASTIC_APM_SERVER_URL", "http://apm-server:1080")
.withEnv("ELASTIC_APM_SERVER_URL", "http://apm-server:8080")
.withEnv("ELASTIC_APM_IGNORE_URLS", ignoreUrlConfig)
.withEnv("ELASTIC_APM_REPORT_SYNC", "true")
.withEnv("ELASTIC_APM_LOG_LEVEL", "DEBUG")
Expand Down Expand Up @@ -247,7 +239,7 @@ public void testAllScenarios() throws Exception {
}

public void clearMockServerLog() {
mockServerContainer.getClient().clear(HttpRequest.request(), ClearType.LOG);
mockServerContainer.clearRecorded();
}

public JsonNode assertTransactionReported(String pathToTest, int expectedResponseCode) {
Expand Down Expand Up @@ -423,8 +415,7 @@ public List<JsonNode> getEvents(String eventType) {
try {
final List<JsonNode> events = new ArrayList<>();
final ObjectMapper objectMapper = new ObjectMapper();
for (HttpRequest httpRequest : mockServerContainer.getClient().retrieveRecordedRequests(request(INTAKE_V2_URL))) {
final String bodyAsString = httpRequest.getBodyAsString();
for (String bodyAsString : mockServerContainer.getRecordedRequestBodies()) {
for (String ndJsonLine : bodyAsString.split("\n")) {
final JsonNode ndJson = objectMapper.readTree(ndJsonLine);
if (ndJson.get(eventType) != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.apm.servlet;

import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.tomakehurst.wiremock.client.WireMock;
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder;
import com.github.tomakehurst.wiremock.matching.UrlPattern;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;

import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.stream.Collectors;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

import static com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder.responseDefinition;
import static com.github.tomakehurst.wiremock.client.WireMock.any;

public class MockApmServerContainer extends GenericContainer<MockApmServerContainer> {

private WireMock wireMock;

public MockApmServerContainer() {
super("wiremock/wiremock:3.13.2");
addExposedPorts(8080);
waitStrategy = Wait.forHealthcheck();
}

@Override
protected void containerIsStarted(InspectContainerResponse containerInfo) {
super.containerIsStarted(containerInfo);
wireMock = WireMock.create()
.host(getHost())
.port(getMappedPort(8080))
.build();

wireMock.register(any(UrlPattern.ANY).willReturn(responseDefinition().withStatus(200)));
}

public List<String> getRecordedRequestBodies() {
return wireMock.find(RequestPatternBuilder.newRequestPattern())
.stream()
// wiremock provides the raw request body without any decompression so we have to do it explicitly ourselves
.map(action -> decompressZlib(action.getBody()))
.collect(Collectors.toList());
}

private static String decompressZlib(byte[] input) {
Inflater inflater = new Inflater();
inflater.setInput(input);
try {
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
while (!inflater.finished()) {
int count = inflater.inflate(buffer);
output.write(buffer, 0, count);
}
inflater.end();
return output.toString(StandardCharsets.UTF_8);
} catch (DataFormatException e) {
throw new IllegalStateException(e);
}
}

public void clearRecorded() {
wireMock.resetRequests();
}

}

This file was deleted.

13 changes: 0 additions & 13 deletions integration-tests/quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<scope>import</scope>
</dependency>
<dependency>
<!-- mock-server requires a fixed jackson version -->
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.14.1</version>
Expand Down Expand Up @@ -70,18 +69,6 @@
<version>1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mockserver</artifactId>
<version>${version.testcontainers}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-client-java</artifactId>
<version>5.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
Expand Down
Loading
Loading