Skip to content

Commit

Permalink
Updated AntuBLUE test engine (#975)
Browse files Browse the repository at this point in the history
Signed-off-by: dhoard <[email protected]>
  • Loading branch information
dhoard authored Jun 16, 2024
1 parent 77bd2a4 commit 7c02d2c
Show file tree
Hide file tree
Showing 39 changed files with 467 additions and 425 deletions.
2 changes: 1 addition & 1 deletion integration_test_suite/integration_tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<antublue.test.engine.version>6.3.0</antublue.test.engine.version>
<antublue.test.engine.version>7.0.0-BETA</antublue.test.engine.version>
<!-- smoke test containers -->
<docker.image.names/>
<!-- all test containers -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.prometheus.jmx.test.support;

/** Enum of the two operational modes */
public enum Mode {
public enum JmxExporterMode {
JavaAgent,
Standalone
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,45 @@

import org.antublue.test.engine.api.Argument;

public class TestArgument implements Argument {
public class TestArguments implements Argument<TestArguments> {

private final String name;
private final String dockerImageName;
private final Mode mode;
private final JmxExporterMode jmxExporterMode;

private TestArgument(String name, String dockerImageName, Mode mode) {
private TestArguments(String name, String dockerImageName, JmxExporterMode jmxExporterMode) {
this.name = name;
this.dockerImageName = dockerImageName;
this.mode = mode;
this.jmxExporterMode = jmxExporterMode;
}

@Override
public String name() {
public String getName() {
return name;
}

public String dockerImageName() {
@Override
public TestArguments getPayload() {
return this;
}

public String getDockerImageName() {
return dockerImageName;
}

public Mode mode() {
return mode;
public JmxExporterMode getJmxExporterMode() {
return jmxExporterMode;
}

@Override
public String toString() {
return String.format(
"TestArgument{name=[%s],dockerImageName=[%s],mode=[%s]}",
name, dockerImageName, mode);
name, dockerImageName, jmxExporterMode);
}

public static TestArgument of(String name, String dockerImageName, Mode mode) {
return new TestArgument(name, dockerImageName, mode);
public static TestArguments of(
String name, String dockerImageName, JmxExporterMode jmxExporterMode) {
return new TestArguments(name, dockerImageName, jmxExporterMode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.testcontainers.containers.Network;

/** Class to a TestContext */
public class TestContext {
public class TestEnvironment {

private Network network;
private GenericContainer<?> applicationContainer;
Expand All @@ -30,7 +30,7 @@ public class TestContext {
private HttpClient httpClient;

/** Constructor */
public TestContext() {
public TestEnvironment() {
// DO NOTHING
}

Expand All @@ -40,7 +40,7 @@ public TestContext() {
* @param network network
* @return this
*/
public TestContext network(Network network) {
public TestEnvironment setNetwork(Network network) {
this.network = network;
return this;
}
Expand All @@ -50,7 +50,7 @@ public TestContext network(Network network) {
*
* @return the Network
*/
public Network network() {
public Network getNetwork() {
return network;
}

Expand All @@ -60,7 +60,7 @@ public Network network() {
* @param applicationContainer application container
* @return this
*/
public TestContext applicationContainer(GenericContainer<?> applicationContainer) {
public TestEnvironment setApplicationContainer(GenericContainer<?> applicationContainer) {
this.applicationContainer = applicationContainer;
return this;
}
Expand All @@ -70,7 +70,7 @@ public TestContext applicationContainer(GenericContainer<?> applicationContainer
*
* @return the application container
*/
public GenericContainer<?> applicationContainer() {
public GenericContainer<?> getApplicationContainer() {
return applicationContainer;
}

Expand All @@ -80,7 +80,7 @@ public GenericContainer<?> applicationContainer() {
* @param exporterContainer exporter container
* @return this
*/
public TestContext exporterContainer(GenericContainer<?> exporterContainer) {
public TestEnvironment setExporterContainer(GenericContainer<?> exporterContainer) {
this.exporterContainer = exporterContainer;
return this;
}
Expand All @@ -90,7 +90,7 @@ public TestContext exporterContainer(GenericContainer<?> exporterContainer) {
*
* @return the exporter container
*/
public GenericContainer<?> exporterContainer() {
public GenericContainer<?> getExporterContainer() {
return exporterContainer;
}

Expand All @@ -100,7 +100,7 @@ public GenericContainer<?> exporterContainer() {
* @param baseUrl baseURL
* @return this
*/
public TestContext baseUrl(String baseUrl) {
public TestEnvironment setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl;
return this;
}
Expand All @@ -110,7 +110,7 @@ public TestContext baseUrl(String baseUrl) {
*
* @return the base URL
*/
public String baseUrl() {
public String getBaseUrl() {
return baseUrl;
}

Expand All @@ -120,7 +120,7 @@ public String baseUrl() {
* @param httpClient httpClient
* @return this
*/
public TestContext httpClient(HttpClient httpClient) {
public TestEnvironment setHttpClient(HttpClient httpClient) {
this.httpClient = httpClient;
return this;
}
Expand All @@ -130,7 +130,7 @@ public TestContext httpClient(HttpClient httpClient) {
*
* @return the HttpClient
*/
public HttpClient httpClient() {
public HttpClient getHttpClient() {
return httpClient;
}

Expand All @@ -144,13 +144,13 @@ public void reset() {
applicationContainer.close();
}

applicationContainer(null);
exporterContainer(null);
httpClient(null);
setApplicationContainer(null);
setExporterContainer(null);
setHttpClient(null);
}

/** Method to dispose the test state (containers and network) */
public void dispose() {
public void destroy() {
if (exporterContainer != null) {
exporterContainer.close();
exporterContainer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@

import com.github.dockerjava.api.model.Ulimit;
import io.prometheus.jmx.test.support.DockerImageNames;
import io.prometheus.jmx.test.support.Mode;
import io.prometheus.jmx.test.support.TestArgument;
import io.prometheus.jmx.test.support.TestContext;
import io.prometheus.jmx.test.support.JmxExporterMode;
import io.prometheus.jmx.test.support.TestArguments;
import io.prometheus.jmx.test.support.TestEnvironment;
import io.prometheus.jmx.test.support.http.HttpClient;
import io.prometheus.jmx.test.support.http.HttpContentType;
import io.prometheus.jmx.test.support.http.HttpHeader;
import io.prometheus.jmx.test.support.http.HttpResponse;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import org.antublue.test.engine.api.TestEngine;
import org.testcontainers.containers.BindMode;
Expand All @@ -43,65 +39,64 @@ public abstract class AbstractTest {
private static final long MEMORY_BYTES = 1073741824; // 1GB
private static final long MEMORY_SWAP_BYTES = 2 * MEMORY_BYTES;

protected TestContext testContext;
@TestEngine.Argument public TestArguments testArguments;

@TestEngine.Argument protected TestArgument testArgument;
protected TestEnvironment testEnvironment;

/**
* Method to get the list of TestArguments
*
* @return the return value
*/
@TestEngine.ArgumentSupplier
protected static Stream<TestArgument> arguments() {
List<TestArgument> testArguments = new ArrayList<>();
public static Stream<TestArguments> arguments() {
List<TestArguments> testArguments = new ArrayList<>();

DockerImageNames.names()
.forEach(
dockerImageName -> {
for (Mode mode : Mode.values()) {
for (JmxExporterMode jmxExporterMode : JmxExporterMode.values()) {
testArguments.add(
TestArgument.of(
dockerImageName + " / " + mode,
TestArguments.of(
dockerImageName + " / " + jmxExporterMode,
dockerImageName,
mode));
jmxExporterMode));
}
});

return testArguments.stream();
}

@TestEngine.Prepare
protected final void prepare() {
testContext = new TestContext();

public final void prepare() {
// Get the Network and get the id to force the network creation
Network network = Network.newNetwork();
network.getId();

testContext.network(network);
testContext.baseUrl(BASE_URL);
testEnvironment = new TestEnvironment();
testEnvironment.setNetwork(network);
testEnvironment.setBaseUrl(BASE_URL);
}

@TestEngine.BeforeAll
protected final void beforeAll() {
testContext.reset();
public final void beforeAll() {
testEnvironment.reset();

Network network = testContext.network();
String dockerImageName = testArgument.dockerImageName();
Network network = testEnvironment.getNetwork();
String dockerImageName = testArguments.getDockerImageName();
String testName = this.getClass().getName();
String baseUrl = testContext.baseUrl();
String baseUrl = testEnvironment.getBaseUrl();

switch (testArgument.mode()) {
switch (testArguments.getJmxExporterMode()) {
case JavaAgent:
{
GenericContainer<?> applicationContainer =
createJavaAgentApplicationContainer(network, dockerImageName, testName);
applicationContainer.start();
testContext.applicationContainer(applicationContainer);
testEnvironment.setApplicationContainer(applicationContainer);

HttpClient httpClient = createHttpClient(applicationContainer, baseUrl);
testContext.httpClient(httpClient);
testEnvironment.setHttpClient(httpClient);

break;
}
Expand All @@ -111,30 +106,30 @@ protected final void beforeAll() {
createStandaloneApplicationContainer(
network, dockerImageName, testName);
applicationContainer.start();
testContext.applicationContainer(applicationContainer);
testEnvironment.setApplicationContainer(applicationContainer);

GenericContainer<?> exporterContainer =
createStandaloneExporterContainer(network, dockerImageName, testName);
exporterContainer.start();
testContext.exporterContainer(exporterContainer);
testEnvironment.setExporterContainer(exporterContainer);

HttpClient httpClient = createHttpClient(exporterContainer, baseUrl);
testContext.httpClient(httpClient);
testEnvironment.setHttpClient(httpClient);

break;
}
}
}

@TestEngine.AfterAll
protected final void afterAll() {
testContext.reset();
public final void afterAll() {
testEnvironment.reset();
}

@TestEngine.Conclude
protected final void conclude() {
testContext.dispose();
testContext = null;
public final void conclude() {
testEnvironment.destroy();
testEnvironment = null;
}

/**
Expand Down Expand Up @@ -277,9 +272,4 @@ private static HttpClient createHttpClient(
GenericContainer<?> genericContainer, String baseUrl) {
return new HttpClient(baseUrl + ":" + genericContainer.getMappedPort(8888));
}

protected static boolean isProtoBufFormat(HttpResponse httpResponse) {
return Objects.requireNonNull(httpResponse.headers().get(HttpHeader.CONTENT_TYPE))
.contains(HttpContentType.PROTOBUF);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AutoIncrementingMBeanTest extends AbstractTest {
@TestEngine.Test
public void testHealthy() {
new HttpHealthyRequest()
.send(testContext.httpClient())
.send(testEnvironment.getHttpClient())
.accept(HttpResponseAssertions::assertHttpHealthyResponse);
}

Expand All @@ -55,7 +55,7 @@ private double collect() {
final AtomicDouble value = new AtomicDouble();

HttpResponse httpResponse =
new HttpPrometheusMetricsRequest().send(testContext.httpClient());
new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient());

assertHttpMetricsResponse(httpResponse);

Expand Down
Loading

0 comments on commit 7c02d2c

Please sign in to comment.