Skip to content

Commit c75bfec

Browse files
authored
Fixed integration tests startup timing issue (#1216)
Signed-off-by: dhoard <doug.hoard@gmail.com>
1 parent 305add5 commit c75bfec

File tree

8 files changed

+66
-26
lines changed

8 files changed

+66
-26
lines changed

integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/JavaDockerImages.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ private JavaDockerImages() {
5353
}
5454

5555
/**
56-
* Method to get List of Docker image names filtered by a Predicate
56+
* Method to get collection of Docker image names filtered by a Predicate
5757
*
58-
* @return the List of Docker image names
58+
* @return the collection of Docker image names
5959
*/
6060
public static Collection<String> names() {
6161
String configurationValues =
@@ -77,6 +77,15 @@ public static Collection<String> names() {
7777
return Collections.unmodifiableList(toList(configurationValues));
7878
}
7979

80+
/**
81+
* Method to get a collection of all Docker image names
82+
*
83+
* @return a collection of all Docker image names
84+
*/
85+
public static Collection<String> allNames() {
86+
return ALL_DOCKER_IMAGE_NAMES;
87+
}
88+
8089
/**
8190
* Method to load the list of Docker image names from a resource
8291
*

integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/PrometheusDockerImages.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ private PrometheusDockerImages() {
5353
}
5454

5555
/**
56-
* Method to get List of Docker image names filtered by a Predicate
56+
* Method to get a collection of Docker image names filter by configuration
5757
*
58-
* @return the List of Docker image names
58+
* @return the collection of Docker image names
5959
*/
6060
public static Collection<String> names() {
6161
String configurationValue =
@@ -77,6 +77,15 @@ public static Collection<String> names() {
7777
return Collections.unmodifiableList(toList(configurationValue));
7878
}
7979

80+
/**
81+
* Method to get a collection of all Docker image names
82+
*
83+
* @return a collection of all Docker image names
84+
*/
85+
public static Collection<String> allNames() {
86+
return ALL_DOCKER_IMAGE_NAMES;
87+
}
88+
8089
/**
8190
* Method to load the list of Docker image names from a resource
8291
*

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.prometheus.jmx.TabularData;
3232
import io.prometheus.jmx.common.HTTPServerFactory;
3333
import io.prometheus.jmx.common.util.ResourceSupport;
34+
import io.prometheus.jmx.test.support.ExporterPath;
3435
import io.prometheus.jmx.test.support.Repeater;
3536
import io.prometheus.jmx.test.support.http.HttpClient;
3637
import io.prometheus.jmx.test.support.http.HttpHeader;
@@ -140,7 +141,7 @@ public static void prepare(ClassContext classContext) throws Throwable {
140141
@Verifyica.Test
141142
@Verifyica.Order(1)
142143
public void testHealthy(ArgumentContext argumentContext) throws Throwable {
143-
String url = argumentContext.classContext().map().getAs(URL) + "/-/healthy";
144+
String url = argumentContext.classContext().map().getAs(URL) + ExporterPath.HEALTHY;
144145

145146
HttpResponse httpResponse = HttpClient.sendRequest(url);
146147

@@ -149,7 +150,7 @@ public void testHealthy(ArgumentContext argumentContext) throws Throwable {
149150

150151
@Verifyica.Test
151152
public void testDefaultTextMetrics(ArgumentContext argumentContext) throws Throwable {
152-
String url = argumentContext.classContext().map().getAs(URL) + "/metrics";
153+
String url = argumentContext.classContext().map().getAs(URL) + ExporterPath.METRICS;
153154

154155
// Run the test code multiple times
155156
new Repeater(ITERATIONS)
@@ -165,7 +166,7 @@ public void testDefaultTextMetrics(ArgumentContext argumentContext) throws Throw
165166

166167
@Verifyica.Test
167168
public void testOpenMetricsTextMetrics(ArgumentContext argumentContext) throws Throwable {
168-
String url = argumentContext.classContext().map().getAs(URL) + "/metrics";
169+
String url = argumentContext.classContext().map().getAs(URL) + ExporterPath.METRICS;
169170

170171
// Run the test code multiple times
171172
new Repeater(ITERATIONS)
@@ -187,7 +188,7 @@ public void testOpenMetricsTextMetrics(ArgumentContext argumentContext) throws T
187188

188189
@Verifyica.Test
189190
public void testPrometheusTextMetrics(ArgumentContext argumentContext) throws Throwable {
190-
String url = argumentContext.classContext().map().getAs(URL) + "/metrics";
191+
String url = argumentContext.classContext().map().getAs(URL) + ExporterPath.METRICS;
191192

192193
// Run the test code multiple times
193194
new Repeater(ITERATIONS)
@@ -208,7 +209,7 @@ public void testPrometheusTextMetrics(ArgumentContext argumentContext) throws Th
208209

209210
@Verifyica.Test
210211
public void testPrometheusProtobufMetrics(ArgumentContext argumentContext) throws Throwable {
211-
String url = argumentContext.classContext().map().getAs(URL) + "/metrics";
212+
String url = argumentContext.classContext().map().getAs(URL) + ExporterPath.METRICS;
212213

213214
// Run the test code multiple times
214215
new Repeater(ITERATIONS)
@@ -313,5 +314,19 @@ private void assertMetricsResponse(
313314
"io_prometheus_jmx_test_PerformanceMetricsMBean_PerformanceMetrics_BootstrapsDeferred")
314315
.withValue(6.0d)
315316
.isPresent();
317+
318+
assertMetric(metrics)
319+
.ofType(Metric.Type.UNTYPED)
320+
.withName("org_exist_management_exist_ProcessReport_RunningQueries_id")
321+
.withLabel("key_id", "1")
322+
.withLabel("key_path", "/db/query1.xq")
323+
.isPresent();
324+
325+
assertMetric(metrics)
326+
.ofType(Metric.Type.UNTYPED)
327+
.withName("org_exist_management_exist_ProcessReport_RunningQueries_id")
328+
.withLabel("key_id", "2")
329+
.withLabel("key_path", "/db/query2.xq")
330+
.isPresent();
316331
}
317332
}

integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/support/ExporterTestEnvironment.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.testcontainers.containers.BindMode;
2424
import org.testcontainers.containers.GenericContainer;
2525
import org.testcontainers.containers.Network;
26-
import org.testcontainers.containers.startupcheck.IsRunningStartupCheckStrategy;
2726
import org.testcontainers.containers.wait.strategy.Wait;
2827
import org.verifyica.api.Argument;
2928

@@ -194,8 +193,8 @@ private GenericContainer<?> createJavaAgentApplicationContainer() {
194193
.withLogConsumer(TestContainerLogger.getInstance())
195194
.withNetwork(network)
196195
.withNetworkAliases("application")
197-
.withStartupCheckStrategy(new IsRunningStartupCheckStrategy())
198-
.withStartupTimeout(Duration.ofMillis(60000))
196+
.waitingFor(Wait.forLogMessage(".*JmxExampleApplication \\| Running.*", 1))
197+
.withStartupTimeout(Duration.ofSeconds(60))
199198
.withWorkingDirectory("/temp");
200199
}
201200

@@ -218,7 +217,7 @@ private GenericContainer<?> createStandaloneApplicationContainer() {
218217
.withLogConsumer(TestContainerLogger.getInstance())
219218
.withNetwork(network)
220219
.withNetworkAliases("application")
221-
.withStartupCheckStrategy(new IsRunningStartupCheckStrategy())
220+
.waitingFor(Wait.forLogMessage(".*JmxExampleApplication \\| Running.*", 1))
222221
.withStartupTimeout(Duration.ofMillis(60000))
223222
.withWorkingDirectory("/temp");
224223
}
@@ -242,8 +241,7 @@ private GenericContainer<?> createStandaloneExporterContainer() {
242241
.withLogConsumer(TestContainerLogger.getInstance())
243242
.withNetwork(network)
244243
.withNetworkAliases("exporter")
245-
.withStartupCheckStrategy(new IsRunningStartupCheckStrategy())
246-
.withStartupTimeout(Duration.ofMillis(60000))
244+
.waitingFor(Wait.forLogMessage(".*Standalone \\| Running.*", 1))
247245
.withWorkingDirectory("/temp");
248246
}
249247

integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/support/OpenTelemetryTestEnvironment.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.testcontainers.containers.BindMode;
3030
import org.testcontainers.containers.GenericContainer;
3131
import org.testcontainers.containers.Network;
32-
import org.testcontainers.containers.startupcheck.IsRunningStartupCheckStrategy;
3332
import org.testcontainers.containers.wait.strategy.Wait;
3433
import org.verifyica.api.Argument;
3534

@@ -294,7 +293,6 @@ private GenericContainer<?> createPrometheusContainer() {
294293
})
295294
.withNetwork(network)
296295
.withNetworkAliases("prometheus")
297-
.withStartupCheckStrategy(new IsRunningStartupCheckStrategy())
298296
.withStartupTimeout(Duration.ofMillis(60000))
299297
.waitingFor(
300298
Wait.forLogMessage(
@@ -327,7 +325,7 @@ private GenericContainer<?> createJavaAgentApplicationContainer() {
327325
.withLogConsumer(TestContainerLogger.getInstance())
328326
.withNetwork(network)
329327
.withNetworkAliases("application")
330-
.withStartupCheckStrategy(new IsRunningStartupCheckStrategy())
328+
.waitingFor(Wait.forLogMessage(".*JmxExampleApplication \\| Running.*", 1))
331329
.withStartupTimeout(Duration.ofMillis(60000))
332330
.withWorkingDirectory("/temp");
333331
}
@@ -351,10 +349,9 @@ private GenericContainer<?> createStandaloneApplicationContainer() {
351349
.withLogConsumer(TestContainerLogger.getInstance())
352350
.withNetwork(network)
353351
.withNetworkAliases("application")
354-
.withStartupCheckStrategy(new IsRunningStartupCheckStrategy())
352+
.waitingFor(Wait.forLogMessage(".*JmxExampleApplication \\| Running.*", 1))
355353
.withStartupTimeout(Duration.ofMillis(60000))
356-
.withWorkingDirectory("/temp")
357-
.waitingFor(Wait.forLogMessage(".*Running.*", 1));
354+
.withWorkingDirectory("/temp");
358355
}
359356

360357
/**
@@ -376,7 +373,7 @@ private GenericContainer<?> createStandaloneExporterContainer() {
376373
.withLogConsumer(TestContainerLogger.getInstance())
377374
.withNetwork(network)
378375
.withNetworkAliases("exporter")
379-
.withStartupCheckStrategy(new IsRunningStartupCheckStrategy())
376+
.waitingFor(Wait.forLogMessage(".*Standalone \\| Running.*", 1))
380377
.withStartupTimeout(Duration.ofMillis(60000))
381378
.withWorkingDirectory("/temp")
382379
.waitingFor(Wait.forLogMessage(".*Running.*", 1));

integration_test_suite/jmx_example_application/src/main/java/io/prometheus/jmx/ExistDb.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,24 @@
2525
/** Class to implement ExitDb */
2626
public class ExistDb implements ExistDbMXBean {
2727

28+
private final Map<QueryKey, RunningQuery> queries;
29+
30+
public ExistDb() {
31+
queries = build();
32+
}
33+
2834
@Override
2935
public Map<QueryKey, RunningQuery> getRunningQueries() {
30-
final Map<QueryKey, RunningQuery> queries = new TreeMap<>();
36+
return queries;
37+
}
38+
39+
private Map<QueryKey, RunningQuery> build() {
40+
Map<QueryKey, RunningQuery> queries = new TreeMap<>();
3141

32-
final RunningQuery runningQuery1 =
42+
RunningQuery runningQuery1 =
3343
new RunningQuery(1, "/db/query1.xq", System.currentTimeMillis());
34-
final RunningQuery runningQuery2 =
44+
45+
RunningQuery runningQuery2 =
3546
new RunningQuery(2, "/db/query2.xq", System.currentTimeMillis());
3647

3748
queries.put(new QueryKey(runningQuery1.getId(), runningQuery1.getPath()), runningQuery1);

integration_test_suite/jmx_example_application/src/main/java/io/prometheus/jmx/ExistDbMXBean.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public interface ExistDbMXBean {
3030

3131
/** Class to implement QueryKey */
3232
class QueryKey implements Comparable<QueryKey> {
33+
3334
private final int id;
3435
private final String path;
3536

integration_test_suite/jmx_example_application/src/main/java/io/prometheus/jmx/JmxExampleApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void main(String[] args) throws Exception {
4949
LocalDateTime.now().format(DATE_TIME_FORMATTER),
5050
Thread.currentThread().getName(),
5151
JmxExampleApplication.class.getName(),
52-
"Running");
52+
"Running ...");
5353

5454
Thread.currentThread().join();
5555
}

0 commit comments

Comments
 (0)