-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed incorrect test container logic that allowed tests to start befo…
…re the container was fully started (#799) Signed-off-by: dhoard <[email protected]> Signed-off-by: Petr Dušák <[email protected]>
- Loading branch information
1 parent
e01e3d0
commit c7254a7
Showing
29 changed files
with
397 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
...est_suite/integration_tests/src/test/java/io/prometheus/jmx/test/AutoIncrementing_IT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/* | ||
* Copyright (C) 2022-2023 The Prometheus jmx_exporter Authors | ||
* | ||
* Licensed 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 io.prometheus.jmx.test; | ||
|
||
import io.prometheus.jmx.test.support.ContentConsumer; | ||
import io.prometheus.jmx.test.support.HealthyRequest; | ||
import io.prometheus.jmx.test.support.HealthyResponse; | ||
import io.prometheus.jmx.test.support.MetricsRequest; | ||
import io.prometheus.jmx.test.support.MetricsResponse; | ||
import org.antublue.test.engine.api.Parameter; | ||
import org.antublue.test.engine.api.ParameterMap; | ||
import org.antublue.test.engine.api.TestEngine; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.shaded.com.google.common.util.concurrent.AtomicDouble; | ||
|
||
import java.util.Collection; | ||
|
||
import static io.prometheus.jmx.test.support.RequestResponseAssertions.assertThatResponseForRequest; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class AutoIncrementing_IT extends Abstract_IT { | ||
|
||
private static final String BASE_URL = "http://localhost"; | ||
|
||
private static Network network; | ||
|
||
private String testName; | ||
private String dockerImageName; | ||
private boolean isJava6; | ||
private Mode mode; | ||
|
||
private GenericContainer<?> applicationContainer; | ||
private GenericContainer<?> exporterContainer; | ||
private HttpClient httpClient; | ||
|
||
@TestEngine.Parameter | ||
public void parameter(Parameter parameter) { | ||
ParameterMap parameterMap = parameter.value(); | ||
testName = getClass().getName(); | ||
dockerImageName = parameterMap.get(DOCKER_IMAGE_NAME); | ||
isJava6 = parameterMap.get(IS_JAVA_6); | ||
mode = parameterMap.get(MODE); | ||
} | ||
|
||
@TestEngine.BeforeClass | ||
public static void beforeClass() { | ||
network = createNetwork(); | ||
} | ||
|
||
@TestEngine.BeforeAll | ||
public void beforeAll() { | ||
switch (mode) { | ||
case JavaAgent: { | ||
applicationContainer = createJavaAgentApplicationContainer(network, dockerImageName, testName); | ||
applicationContainer.start(); | ||
httpClient = createHttpClient(applicationContainer, BASE_URL); | ||
break; | ||
} | ||
case Standalone: { | ||
applicationContainer = createStandaloneApplicationContainer(network, dockerImageName, testName); | ||
applicationContainer.start(); | ||
exporterContainer = createStandaloneExporterContainer(network, dockerImageName, testName); | ||
exporterContainer.start(); | ||
httpClient = createHttpClient(exporterContainer, BASE_URL); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
@TestEngine.Test | ||
public void testHealthy() { | ||
assertThatResponseForRequest(new HealthyRequest(httpClient)) | ||
.isSuperset(HealthyResponse.RESULT_200); | ||
} | ||
|
||
@TestEngine.Test | ||
public void testMetrics() { | ||
AtomicDouble value1 = new AtomicDouble(); | ||
AtomicDouble value2 = new AtomicDouble(); | ||
AtomicDouble value3 = new AtomicDouble(); | ||
|
||
assertThatResponseForRequest(new MetricsRequest(httpClient)) | ||
.isSuperset(MetricsResponse.RESULT_200) | ||
.dispatch((ContentConsumer) content -> { | ||
Collection<Metric> metrics = MetricsParser.parse(content); | ||
metrics | ||
.forEach(metric -> { | ||
if (metric.getName().startsWith("io_prometheus_jmx_autoIncrementing")) { | ||
assertThat(metric.getValue()).isGreaterThanOrEqualTo(1); | ||
value1.set(metric.getValue()); | ||
} | ||
}); | ||
}); | ||
|
||
assertThatResponseForRequest(new MetricsRequest(httpClient)) | ||
.isSuperset(MetricsResponse.RESULT_200) | ||
.dispatch((ContentConsumer) content -> { | ||
Collection<Metric> metrics = MetricsParser.parse(content); | ||
metrics | ||
.forEach(metric -> { | ||
if (metric.getName().startsWith("io_prometheus_jmx_autoIncrementing")) { | ||
value2.set(metric.getValue()); | ||
} | ||
}); | ||
}); | ||
|
||
assertThatResponseForRequest(new MetricsRequest(httpClient)) | ||
.isSuperset(MetricsResponse.RESULT_200) | ||
.dispatch((ContentConsumer) content -> { | ||
Collection<Metric> metrics = MetricsParser.parse(content); | ||
metrics | ||
.forEach(metric -> { | ||
if (metric.getName().startsWith("io_prometheus_jmx_autoIncrementing")) { | ||
value3.set(metric.getValue()); | ||
} | ||
}); | ||
}); | ||
|
||
// Use value1 as a baseline value | ||
assertThat(value2.get()).isEqualTo(value1.get() + 1); | ||
assertThat(value3.get()).isEqualTo(value2.get() + 1); | ||
} | ||
|
||
@TestEngine.AfterAll | ||
public void afterAll() { | ||
destroy(applicationContainer); | ||
destroy(exporterContainer); | ||
httpClient = null; | ||
} | ||
|
||
@TestEngine.AfterClass | ||
public static void afterClass() { | ||
destroy(network); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.