Skip to content

Commit

Permalink
Junit cleanup (#1119)
Browse files Browse the repository at this point in the history
* exclude hamcrest

Signed-off-by: Gregor Zeitlinger <[email protected]>

* simplify assertj

Signed-off-by: Gregor Zeitlinger <[email protected]>

* simplify assertj

Signed-off-by: Gregor Zeitlinger <[email protected]>

---------

Signed-off-by: Gregor Zeitlinger <[email protected]>
  • Loading branch information
zeitlinger authored Oct 7, 2024
1 parent 2c3e258 commit b6e5865
Show file tree
Hide file tree
Showing 23 changed files with 122 additions and 143 deletions.
8 changes: 0 additions & 8 deletions integration-tests/it-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@
</license>
</licenses>

<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<testResources>
<testResource>
Expand Down
5 changes: 0 additions & 5 deletions integration-tests/it-exporter/it-exporter-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
<artifactId>prometheus-metrics-exposition-formats</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
Expand Down
6 changes: 1 addition & 5 deletions integration-tests/it-pushgateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@
<artifactId>prometheus-metrics-exporter-pushgateway</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.prometheus</groupId>
<artifactId>it-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
27 changes: 16 additions & 11 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -49,14 +50,18 @@
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.19.8</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.20.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 39 additions & 32 deletions prometheus-metrics-exporter-opentelemetry/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -56,6 +57,12 @@
<artifactId>wiremock</artifactId>
<version>3.5.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
Expand Down Expand Up @@ -88,37 +95,37 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<version>${otel.version}</version>
<outputDirectory>${project.basedir}/src/main/resources/lib/</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-context</artifactId>
<version>${otel.version}</version>
<outputDirectory>${project.basedir}/src/main/resources/lib/</outputDirectory>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<version>${otel.version}</version>
<outputDirectory>${project.basedir}/src/main/resources/lib/</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-context</artifactId>
<version>${otel.version}</version>
<outputDirectory>${project.basedir}/src/main/resources/lib/</outputDirectory>
</artifactItem>
</artifactItems>
<!-- other configurations here -->
</configuration>
</plugin>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.prometheus.metrics.instrumentation.caffeine;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.Offset.offset;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -120,7 +119,7 @@ private void assertCounterMetric(
final CounterSnapshot.CounterDataPointSnapshot dataPointSnapshot =
(CounterSnapshot.CounterDataPointSnapshot) getDataPointSnapshot(registry, name, cacheName);

assertThat(dataPointSnapshot.getValue()).isCloseTo(value, offset(0.0));
assertThat(dataPointSnapshot.getValue()).isEqualTo(value);
}

private DataPointSnapshot getDataPointSnapshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,17 @@ public void testHistogram() {
assertThat(dataPoint.hasSum()).isFalse();
Quantiles quantiles = dataPoint.getQuantiles();
assertThat(quantiles.size()).isEqualTo(6);
assertThat(quantiles.get(0).getQuantile()).isCloseTo(0.5, offset(0.0));
assertThat(quantiles.get(0).getQuantile()).isEqualTo(0.5);
assertThat(quantiles.get(0).getValue()).isCloseTo(49.0, offset(1.0));
assertThat(quantiles.get(1).getQuantile()).isCloseTo(0.75, offset(0.0));
assertThat(quantiles.get(1).getQuantile()).isEqualTo(0.75);
assertThat(quantiles.get(1).getValue()).isCloseTo(74.0, offset(1.0));
assertThat(quantiles.get(2).getQuantile()).isCloseTo(0.95, offset(0.0));
assertThat(quantiles.get(2).getQuantile()).isEqualTo(0.95);
assertThat(quantiles.get(2).getValue()).isCloseTo(94.0, offset(1.0));
assertThat(quantiles.get(3).getQuantile()).isCloseTo(0.98, offset(0.0));
assertThat(quantiles.get(3).getQuantile()).isEqualTo(0.98);
assertThat(quantiles.get(3).getValue()).isCloseTo(97.0, offset(1.0));
assertThat(quantiles.get(4).getQuantile()).isCloseTo(0.99, offset(0.0));
assertThat(quantiles.get(4).getQuantile()).isEqualTo(0.99);
assertThat(quantiles.get(4).getValue()).isCloseTo(98.0, offset(1.0));
assertThat(quantiles.get(5).getQuantile()).isCloseTo(0.999, offset(0.0));
assertThat(quantiles.get(5).getQuantile()).isEqualTo(0.999);
assertThat(quantiles.get(5).getValue()).isCloseTo(99.0, offset(1.0));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.prometheus.metrics.instrumentation.guava;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.Offset.offset;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -116,7 +115,7 @@ private void assertCounterMetric(
final CounterSnapshot.CounterDataPointSnapshot dataPointSnapshot =
(CounterSnapshot.CounterDataPointSnapshot) getDataPointSnapshot(registry, name, cacheName);

assertThat(dataPointSnapshot.getValue()).isCloseTo(value, offset(0.0));
assertThat(dataPointSnapshot.getValue()).isEqualTo(value);
}

private DataPointSnapshot getDataPointSnapshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 io.prometheus.metrics.core.metrics.Counter;
import io.prometheus.metrics.instrumentation.jvm.JvmMemoryPoolAllocationMetrics.AllocationCountingNotificationListener;
Expand All @@ -23,31 +22,31 @@ public void testListenerLogic() {

// Increase by 123
listener.handleMemoryPool("TestPool", 0, 123);
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isCloseTo(123, offset(0.0));
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isEqualTo(123);

// No increase
listener.handleMemoryPool("TestPool", 123, 123);
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isCloseTo(123, offset(0.0));
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isEqualTo(123);

// No increase, then decrease to 0
listener.handleMemoryPool("TestPool", 123, 0);
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isCloseTo(123, offset(0.0));
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isEqualTo(123);

// No increase, then increase by 7
listener.handleMemoryPool("TestPool", 0, 7);
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isCloseTo(130, offset(0.0));
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isEqualTo(130);

// Increase by 10, then decrease to 10
listener.handleMemoryPool("TestPool", 17, 10);
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isCloseTo(140, offset(0.0));
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isEqualTo(140);

// Increase by 7, then increase by 3
listener.handleMemoryPool("TestPool", 17, 20);
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isCloseTo(150, offset(0.0));
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isEqualTo(150);

// Decrease to 17, then increase by 3
listener.handleMemoryPool("TestPool", 17, 20);
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isCloseTo(153, offset(0.0));
assertThat(getCountByPool("test", "TestPool", registry.scrape())).isEqualTo(153);
}

private double getCountByPool(String metricName, String poolName, MetricSnapshots snapshots) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static io.prometheus.metrics.instrumentation.jvm.TestUtil.convertToOpenMetricsFormat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.Offset.offset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -135,7 +134,7 @@ public void testInvalidThreadIds() {

assertThat(actual).hasSameSizeAs(expected);
for (String threadState : expected.keySet()) {
assertThat(actual.get(threadState)).isCloseTo(expected.get(threadState), offset(0.0));
assertThat(actual.get(threadState)).isEqualTo(expected.get(threadState));
}
} finally {
for (int i = 0; i < numberOfInvalidThreadIds; i++) {
Expand Down
Loading

0 comments on commit b6e5865

Please sign in to comment.