From b6e58656074e28147200c70708db6c8706d3b7ac Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Mon, 7 Oct 2024 17:21:05 +0200 Subject: [PATCH] Junit cleanup (#1119) * exclude hamcrest Signed-off-by: Gregor Zeitlinger * simplify assertj Signed-off-by: Gregor Zeitlinger * simplify assertj Signed-off-by: Gregor Zeitlinger --------- Signed-off-by: Gregor Zeitlinger --- integration-tests/it-common/pom.xml | 8 --- .../it-exporter/it-exporter-test/pom.xml | 5 -- integration-tests/it-pushgateway/pom.xml | 6 +- .../metrics/it/pushgateway/PushGatewayIT.java | 11 ++- integration-tests/pom.xml | 27 ++++--- .../metrics/core/metrics/HistogramTest.java | 4 +- .../core/metrics/StatefulMetricTest.java | 7 +- .../metrics/core/metrics/SummaryTest.java | 8 +-- .../pom.xml | 71 ++++++++++--------- .../caffeine/CacheMetricsCollectorTest.java | 3 +- .../dropwizard5/DropwizardExportsTest.java | 12 ++-- .../guava/CacheMetricsCollectorTest.java | 3 +- .../JvmMemoryPoolAllocationMetricsTest.java | 15 ++-- .../jvm/JvmThreadsMetricsTest.java | 3 +- .../ClassicHistogramBucketsTest.java | 7 +- .../model/snapshots/CounterSnapshotTest.java | 11 ++- .../metrics/model/snapshots/ExemplarTest.java | 5 +- .../model/snapshots/ExemplarsTest.java | 17 +++-- .../model/snapshots/GaugeSnapshotTest.java | 11 ++- .../snapshots/HistogramSnapshotTest.java | 11 ++- .../model/snapshots/QuantilesTest.java | 13 ++-- .../model/snapshots/SummarySnapshotTest.java | 3 +- .../model/snapshots/UnknownSnapshotTest.java | 4 +- 23 files changed, 122 insertions(+), 143 deletions(-) diff --git a/integration-tests/it-common/pom.xml b/integration-tests/it-common/pom.xml index 195a10caa..0cf030857 100644 --- a/integration-tests/it-common/pom.xml +++ b/integration-tests/it-common/pom.xml @@ -24,14 +24,6 @@ - - - org.testcontainers - testcontainers - test - - - diff --git a/integration-tests/it-exporter/it-exporter-test/pom.xml b/integration-tests/it-exporter/it-exporter-test/pom.xml index 5135e35e1..0fe5ccbdd 100644 --- a/integration-tests/it-exporter/it-exporter-test/pom.xml +++ b/integration-tests/it-exporter/it-exporter-test/pom.xml @@ -42,11 +42,6 @@ prometheus-metrics-exposition-formats ${project.version} - - org.testcontainers - testcontainers - test - commons-io commons-io diff --git a/integration-tests/it-pushgateway/pom.xml b/integration-tests/it-pushgateway/pom.xml index 1956f1dad..d10f34398 100644 --- a/integration-tests/it-pushgateway/pom.xml +++ b/integration-tests/it-pushgateway/pom.xml @@ -47,11 +47,7 @@ prometheus-metrics-exporter-pushgateway ${project.version} - - org.testcontainers - testcontainers - test - + io.prometheus it-common diff --git a/integration-tests/it-pushgateway/src/test/java/io/prometheus/metrics/it/pushgateway/PushGatewayIT.java b/integration-tests/it-pushgateway/src/test/java/io/prometheus/metrics/it/pushgateway/PushGatewayIT.java index cf11671f3..beb83d7d9 100644 --- a/integration-tests/it-pushgateway/src/test/java/io/prometheus/metrics/it/pushgateway/PushGatewayIT.java +++ b/integration-tests/it-pushgateway/src/test/java/io/prometheus/metrics/it/pushgateway/PushGatewayIT.java @@ -2,7 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.assertj.core.data.Offset.offset; import com.jayway.jsonpath.Criteria; import com.jayway.jsonpath.Filter; @@ -180,13 +179,13 @@ public void testProtobuf() throws IOException, InterruptedException { private void assertMetrics() throws IOException, InterruptedException { double value = getValue("my_batch_job_duration_seconds", "job", "pushgateway-test-app"); - assertThat(value).isCloseTo(0.5, offset(0.0)); + assertThat(value).isEqualTo(0.5); value = getValue("file_sizes_bytes_bucket", "job", "pushgateway-test-app", "le", "512"); - assertThat(value).isCloseTo(0.0, offset(0.0)); + assertThat(value).isEqualTo(0.0); value = getValue("file_sizes_bytes_bucket", "job", "pushgateway-test-app", "le", "1024"); - assertThat(value).isCloseTo(2.0, offset(0.0)); + assertThat(value).isEqualTo(2.0); value = getValue("file_sizes_bytes_bucket", "job", "pushgateway-test-app", "le", "+Inf"); - assertThat(value).isCloseTo(3.0, offset(0.0)); + assertThat(value).isEqualTo(3.0); } private double getValue(String name, String... labels) throws IOException, InterruptedException { @@ -204,7 +203,7 @@ private double getValue(String name, String... labels) throws IOException, Inter private void assertNativeHistogram() throws IOException, InterruptedException { double count = getNativeHistogramCount("file_sizes_bytes", "pushgateway-test-app"); - assertThat(count).isCloseTo(3, offset(0.0)); + assertThat(count).isEqualTo(3); } private double getNativeHistogramCount(String name, String job) diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 2ed77b95d..dfc366b07 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 @@ -49,14 +50,18 @@ - - - - org.testcontainers - testcontainers - 1.19.8 - test - - - + + + org.testcontainers + junit-jupiter + 1.20.2 + test + + + org.hamcrest + hamcrest-core + + + + diff --git a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java index 1eb1121ad..ca484bf47 100644 --- a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java +++ b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java @@ -1152,7 +1152,7 @@ private void assertExemplar(Histogram histogram, double value, String... labels) assertThat(exemplar) .as("No exemplar found in bucket [" + lowerBound + ", " + upperBound + "]") .isNotNull(); - assertThat(exemplar.getValue()).isCloseTo(value, offset(0.0)); + assertThat(exemplar.getValue()).isEqualTo(value); assertThat(exemplar.getLabels().size()) .as("" + exemplar.getLabels()) .isEqualTo(labels.length / 2); @@ -1354,7 +1354,7 @@ public void testNoLabelsDefaultZeroValue() { Histogram noLabels = Histogram.builder().name("test").build(); assertThat(getBucket(noLabels, 0.005).getCount()).isZero(); assertThat(getData(noLabels).getCount()).isZero(); - assertThat(getData(noLabels).getSum()).isCloseTo(0.0, offset(0.0)); + assertThat(getData(noLabels).getSum()).isEqualTo(0.0); } private ClassicHistogramBucket getBucket(Histogram histogram, double le, String... labels) { diff --git a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/StatefulMetricTest.java b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/StatefulMetricTest.java index d05cf145a..1120b06a3 100644 --- a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/StatefulMetricTest.java +++ b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/StatefulMetricTest.java @@ -1,7 +1,6 @@ package io.prometheus.metrics.core.metrics; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.data.Offset.offset; import java.lang.reflect.Field; import java.util.Map; @@ -55,17 +54,17 @@ public void testClearNoLabels() { Counter counter = Counter.builder().name("test").build(); counter.inc(); assertThat(counter.collect().getDataPoints()).hasSize(1); - assertThat(counter.collect().getDataPoints().get(0).getValue()).isCloseTo(1.0, offset(0.0)); + assertThat(counter.collect().getDataPoints().get(0).getValue()).isEqualTo(1.0); counter.clear(); // No labels is always present, but as no value has been observed after clear() the value should // be 0.0 assertThat(counter.collect().getDataPoints()).hasSize(1); - assertThat(counter.collect().getDataPoints().get(0).getValue()).isCloseTo(0.0, offset(0.0)); + assertThat(counter.collect().getDataPoints().get(0).getValue()).isEqualTo(0.0); // Making inc() works correctly after clear() counter.inc(); assertThat(counter.collect().getDataPoints()).hasSize(1); - assertThat(counter.collect().getDataPoints().get(0).getValue()).isCloseTo(1.0, offset(0.0)); + assertThat(counter.collect().getDataPoints().get(0).getValue()).isEqualTo(1.0); } } diff --git a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/SummaryTest.java b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/SummaryTest.java index dbabb1a93..b369ed8fb 100644 --- a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/SummaryTest.java +++ b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/SummaryTest.java @@ -123,14 +123,12 @@ public void testMaxAge() throws InterruptedException { .help("help") .register(registry); summary.observe(8.0); - assertThat(getQuantile(summary, 0.99, Labels.EMPTY)) - .isCloseTo(8.0, offset(0.0)); // From bucket 1. + assertThat(getQuantile(summary, 0.99, Labels.EMPTY)).isEqualTo(8.0); // From bucket 1. Thread.sleep(600); - assertThat(getQuantile(summary, 0.99, Labels.EMPTY)) - .isCloseTo(8.0, offset(0.0)); // From bucket 2. + assertThat(getQuantile(summary, 0.99, Labels.EMPTY)).isEqualTo(8.0); // From bucket 2. Thread.sleep(600); assertThat(getQuantile(summary, 0.99, Labels.EMPTY)) - .isCloseTo(Double.NaN, offset(0.0)); // Bucket 1 again, now it is empty. + .isEqualTo(Double.NaN); // Bucket 1 again, now it is empty. } @Test diff --git a/prometheus-metrics-exporter-opentelemetry/pom.xml b/prometheus-metrics-exporter-opentelemetry/pom.xml index 0247be420..89cc01221 100644 --- a/prometheus-metrics-exporter-opentelemetry/pom.xml +++ b/prometheus-metrics-exporter-opentelemetry/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 @@ -56,6 +57,12 @@ wiremock 3.5.4 test + + + org.hamcrest + hamcrest-core + + org.awaitility @@ -88,37 +95,37 @@ - - org.apache.maven.plugins - maven-dependency-plugin - 3.6.0 - - - copy - package - - copy - - - - - - - io.opentelemetry - opentelemetry-api - ${otel.version} - ${project.basedir}/src/main/resources/lib/ - - - io.opentelemetry - opentelemetry-context - ${otel.version} - ${project.basedir}/src/main/resources/lib/ - - - - - + + org.apache.maven.plugins + maven-dependency-plugin + 3.6.0 + + + copy + package + + copy + + + + + + + io.opentelemetry + opentelemetry-api + ${otel.version} + ${project.basedir}/src/main/resources/lib/ + + + io.opentelemetry + opentelemetry-context + ${otel.version} + ${project.basedir}/src/main/resources/lib/ + + + + +