Skip to content

Commit 7c02d2c

Browse files
authored
Updated AntuBLUE test engine (#975)
Signed-off-by: dhoard <doug.hoard@gmail.com>
1 parent 77bd2a4 commit 7c02d2c

File tree

39 files changed

+467
-425
lines changed

39 files changed

+467
-425
lines changed

integration_test_suite/integration_tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<maven.compiler.target>11</maven.compiler.target>
2929
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3030
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
31-
<antublue.test.engine.version>6.3.0</antublue.test.engine.version>
31+
<antublue.test.engine.version>7.0.0-BETA</antublue.test.engine.version>
3232
<!-- smoke test containers -->
3333
<docker.image.names/>
3434
<!-- all test containers -->

integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/Mode.java renamed to integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/JmxExporterMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package io.prometheus.jmx.test.support;
1818

1919
/** Enum of the two operational modes */
20-
public enum Mode {
20+
public enum JmxExporterMode {
2121
JavaAgent,
2222
Standalone
2323
}
Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,45 @@
1818

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

21-
public class TestArgument implements Argument {
21+
public class TestArguments implements Argument<TestArguments> {
2222

2323
private final String name;
2424
private final String dockerImageName;
25-
private final Mode mode;
25+
private final JmxExporterMode jmxExporterMode;
2626

27-
private TestArgument(String name, String dockerImageName, Mode mode) {
27+
private TestArguments(String name, String dockerImageName, JmxExporterMode jmxExporterMode) {
2828
this.name = name;
2929
this.dockerImageName = dockerImageName;
30-
this.mode = mode;
30+
this.jmxExporterMode = jmxExporterMode;
3131
}
3232

3333
@Override
34-
public String name() {
34+
public String getName() {
3535
return name;
3636
}
3737

38-
public String dockerImageName() {
38+
@Override
39+
public TestArguments getPayload() {
40+
return this;
41+
}
42+
43+
public String getDockerImageName() {
3944
return dockerImageName;
4045
}
4146

42-
public Mode mode() {
43-
return mode;
47+
public JmxExporterMode getJmxExporterMode() {
48+
return jmxExporterMode;
4449
}
4550

4651
@Override
4752
public String toString() {
4853
return String.format(
4954
"TestArgument{name=[%s],dockerImageName=[%s],mode=[%s]}",
50-
name, dockerImageName, mode);
55+
name, dockerImageName, jmxExporterMode);
5156
}
5257

53-
public static TestArgument of(String name, String dockerImageName, Mode mode) {
54-
return new TestArgument(name, dockerImageName, mode);
58+
public static TestArguments of(
59+
String name, String dockerImageName, JmxExporterMode jmxExporterMode) {
60+
return new TestArguments(name, dockerImageName, jmxExporterMode);
5561
}
5662
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.testcontainers.containers.Network;
2222

2323
/** Class to a TestContext */
24-
public class TestContext {
24+
public class TestEnvironment {
2525

2626
private Network network;
2727
private GenericContainer<?> applicationContainer;
@@ -30,7 +30,7 @@ public class TestContext {
3030
private HttpClient httpClient;
3131

3232
/** Constructor */
33-
public TestContext() {
33+
public TestEnvironment() {
3434
// DO NOTHING
3535
}
3636

@@ -40,7 +40,7 @@ public TestContext() {
4040
* @param network network
4141
* @return this
4242
*/
43-
public TestContext network(Network network) {
43+
public TestEnvironment setNetwork(Network network) {
4444
this.network = network;
4545
return this;
4646
}
@@ -50,7 +50,7 @@ public TestContext network(Network network) {
5050
*
5151
* @return the Network
5252
*/
53-
public Network network() {
53+
public Network getNetwork() {
5454
return network;
5555
}
5656

@@ -60,7 +60,7 @@ public Network network() {
6060
* @param applicationContainer application container
6161
* @return this
6262
*/
63-
public TestContext applicationContainer(GenericContainer<?> applicationContainer) {
63+
public TestEnvironment setApplicationContainer(GenericContainer<?> applicationContainer) {
6464
this.applicationContainer = applicationContainer;
6565
return this;
6666
}
@@ -70,7 +70,7 @@ public TestContext applicationContainer(GenericContainer<?> applicationContainer
7070
*
7171
* @return the application container
7272
*/
73-
public GenericContainer<?> applicationContainer() {
73+
public GenericContainer<?> getApplicationContainer() {
7474
return applicationContainer;
7575
}
7676

@@ -80,7 +80,7 @@ public GenericContainer<?> applicationContainer() {
8080
* @param exporterContainer exporter container
8181
* @return this
8282
*/
83-
public TestContext exporterContainer(GenericContainer<?> exporterContainer) {
83+
public TestEnvironment setExporterContainer(GenericContainer<?> exporterContainer) {
8484
this.exporterContainer = exporterContainer;
8585
return this;
8686
}
@@ -90,7 +90,7 @@ public TestContext exporterContainer(GenericContainer<?> exporterContainer) {
9090
*
9191
* @return the exporter container
9292
*/
93-
public GenericContainer<?> exporterContainer() {
93+
public GenericContainer<?> getExporterContainer() {
9494
return exporterContainer;
9595
}
9696

@@ -100,7 +100,7 @@ public GenericContainer<?> exporterContainer() {
100100
* @param baseUrl baseURL
101101
* @return this
102102
*/
103-
public TestContext baseUrl(String baseUrl) {
103+
public TestEnvironment setBaseUrl(String baseUrl) {
104104
this.baseUrl = baseUrl;
105105
return this;
106106
}
@@ -110,7 +110,7 @@ public TestContext baseUrl(String baseUrl) {
110110
*
111111
* @return the base URL
112112
*/
113-
public String baseUrl() {
113+
public String getBaseUrl() {
114114
return baseUrl;
115115
}
116116

@@ -120,7 +120,7 @@ public String baseUrl() {
120120
* @param httpClient httpClient
121121
* @return this
122122
*/
123-
public TestContext httpClient(HttpClient httpClient) {
123+
public TestEnvironment setHttpClient(HttpClient httpClient) {
124124
this.httpClient = httpClient;
125125
return this;
126126
}
@@ -130,7 +130,7 @@ public TestContext httpClient(HttpClient httpClient) {
130130
*
131131
* @return the HttpClient
132132
*/
133-
public HttpClient httpClient() {
133+
public HttpClient getHttpClient() {
134134
return httpClient;
135135
}
136136

@@ -144,13 +144,13 @@ public void reset() {
144144
applicationContainer.close();
145145
}
146146

147-
applicationContainer(null);
148-
exporterContainer(null);
149-
httpClient(null);
147+
setApplicationContainer(null);
148+
setExporterContainer(null);
149+
setHttpClient(null);
150150
}
151151

152152
/** Method to dispose the test state (containers and network) */
153-
public void dispose() {
153+
public void destroy() {
154154
if (exporterContainer != null) {
155155
exporterContainer.close();
156156
exporterContainer = null;

integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/AbstractTest.java

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@
1818

1919
import com.github.dockerjava.api.model.Ulimit;
2020
import io.prometheus.jmx.test.support.DockerImageNames;
21-
import io.prometheus.jmx.test.support.Mode;
22-
import io.prometheus.jmx.test.support.TestArgument;
23-
import io.prometheus.jmx.test.support.TestContext;
21+
import io.prometheus.jmx.test.support.JmxExporterMode;
22+
import io.prometheus.jmx.test.support.TestArguments;
23+
import io.prometheus.jmx.test.support.TestEnvironment;
2424
import io.prometheus.jmx.test.support.http.HttpClient;
25-
import io.prometheus.jmx.test.support.http.HttpContentType;
26-
import io.prometheus.jmx.test.support.http.HttpHeader;
27-
import io.prometheus.jmx.test.support.http.HttpResponse;
2825
import java.time.Duration;
2926
import java.util.ArrayList;
3027
import java.util.List;
31-
import java.util.Objects;
3228
import java.util.stream.Stream;
3329
import org.antublue.test.engine.api.TestEngine;
3430
import org.testcontainers.containers.BindMode;
@@ -43,65 +39,64 @@ public abstract class AbstractTest {
4339
private static final long MEMORY_BYTES = 1073741824; // 1GB
4440
private static final long MEMORY_SWAP_BYTES = 2 * MEMORY_BYTES;
4541

46-
protected TestContext testContext;
42+
@TestEngine.Argument public TestArguments testArguments;
4743

48-
@TestEngine.Argument protected TestArgument testArgument;
44+
protected TestEnvironment testEnvironment;
4945

5046
/**
5147
* Method to get the list of TestArguments
5248
*
5349
* @return the return value
5450
*/
5551
@TestEngine.ArgumentSupplier
56-
protected static Stream<TestArgument> arguments() {
57-
List<TestArgument> testArguments = new ArrayList<>();
52+
public static Stream<TestArguments> arguments() {
53+
List<TestArguments> testArguments = new ArrayList<>();
5854

5955
DockerImageNames.names()
6056
.forEach(
6157
dockerImageName -> {
62-
for (Mode mode : Mode.values()) {
58+
for (JmxExporterMode jmxExporterMode : JmxExporterMode.values()) {
6359
testArguments.add(
64-
TestArgument.of(
65-
dockerImageName + " / " + mode,
60+
TestArguments.of(
61+
dockerImageName + " / " + jmxExporterMode,
6662
dockerImageName,
67-
mode));
63+
jmxExporterMode));
6864
}
6965
});
7066

7167
return testArguments.stream();
7268
}
7369

7470
@TestEngine.Prepare
75-
protected final void prepare() {
76-
testContext = new TestContext();
77-
71+
public final void prepare() {
7872
// Get the Network and get the id to force the network creation
7973
Network network = Network.newNetwork();
8074
network.getId();
8175

82-
testContext.network(network);
83-
testContext.baseUrl(BASE_URL);
76+
testEnvironment = new TestEnvironment();
77+
testEnvironment.setNetwork(network);
78+
testEnvironment.setBaseUrl(BASE_URL);
8479
}
8580

8681
@TestEngine.BeforeAll
87-
protected final void beforeAll() {
88-
testContext.reset();
82+
public final void beforeAll() {
83+
testEnvironment.reset();
8984

90-
Network network = testContext.network();
91-
String dockerImageName = testArgument.dockerImageName();
85+
Network network = testEnvironment.getNetwork();
86+
String dockerImageName = testArguments.getDockerImageName();
9287
String testName = this.getClass().getName();
93-
String baseUrl = testContext.baseUrl();
88+
String baseUrl = testEnvironment.getBaseUrl();
9489

95-
switch (testArgument.mode()) {
90+
switch (testArguments.getJmxExporterMode()) {
9691
case JavaAgent:
9792
{
9893
GenericContainer<?> applicationContainer =
9994
createJavaAgentApplicationContainer(network, dockerImageName, testName);
10095
applicationContainer.start();
101-
testContext.applicationContainer(applicationContainer);
96+
testEnvironment.setApplicationContainer(applicationContainer);
10297

10398
HttpClient httpClient = createHttpClient(applicationContainer, baseUrl);
104-
testContext.httpClient(httpClient);
99+
testEnvironment.setHttpClient(httpClient);
105100

106101
break;
107102
}
@@ -111,30 +106,30 @@ protected final void beforeAll() {
111106
createStandaloneApplicationContainer(
112107
network, dockerImageName, testName);
113108
applicationContainer.start();
114-
testContext.applicationContainer(applicationContainer);
109+
testEnvironment.setApplicationContainer(applicationContainer);
115110

116111
GenericContainer<?> exporterContainer =
117112
createStandaloneExporterContainer(network, dockerImageName, testName);
118113
exporterContainer.start();
119-
testContext.exporterContainer(exporterContainer);
114+
testEnvironment.setExporterContainer(exporterContainer);
120115

121116
HttpClient httpClient = createHttpClient(exporterContainer, baseUrl);
122-
testContext.httpClient(httpClient);
117+
testEnvironment.setHttpClient(httpClient);
123118

124119
break;
125120
}
126121
}
127122
}
128123

129124
@TestEngine.AfterAll
130-
protected final void afterAll() {
131-
testContext.reset();
125+
public final void afterAll() {
126+
testEnvironment.reset();
132127
}
133128

134129
@TestEngine.Conclude
135-
protected final void conclude() {
136-
testContext.dispose();
137-
testContext = null;
130+
public final void conclude() {
131+
testEnvironment.destroy();
132+
testEnvironment = null;
138133
}
139134

140135
/**
@@ -277,9 +272,4 @@ private static HttpClient createHttpClient(
277272
GenericContainer<?> genericContainer, String baseUrl) {
278273
return new HttpClient(baseUrl + ":" + genericContainer.getMappedPort(8888));
279274
}
280-
281-
protected static boolean isProtoBufFormat(HttpResponse httpResponse) {
282-
return Objects.requireNonNull(httpResponse.headers().get(HttpHeader.CONTENT_TYPE))
283-
.contains(HttpContentType.PROTOBUF);
284-
}
285275
}

integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/AutoIncrementingMBeanTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class AutoIncrementingMBeanTest extends AbstractTest {
3434
@TestEngine.Test
3535
public void testHealthy() {
3636
new HttpHealthyRequest()
37-
.send(testContext.httpClient())
37+
.send(testEnvironment.getHttpClient())
3838
.accept(HttpResponseAssertions::assertHttpHealthyResponse);
3939
}
4040

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

5757
HttpResponse httpResponse =
58-
new HttpPrometheusMetricsRequest().send(testContext.httpClient());
58+
new HttpPrometheusMetricsRequest().send(testEnvironment.getHttpClient());
5959

6060
assertHttpMetricsResponse(httpResponse);
6161

0 commit comments

Comments
 (0)