Skip to content

Commit

Permalink
prometheus#907 JUnit5 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
0x006EA1E5 committed Dec 12, 2023
1 parent 60f72b6 commit 1960dec
Show file tree
Hide file tree
Showing 67 changed files with 1,524 additions and 1,444 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.Random;
*/

public class ManualCompleteMetricsTest {
class ManualCompleteMetricsTest {

// This contains a complete set of all metric types, and target_info and otel_scope_info.
// I used this to expose in Prometheus format and OTLP format at the same time and compare the results.
Expand Down
5 changes: 5 additions & 0 deletions integration-tests/it-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.prometheus.client.it.common;

import org.junit.Assert;
import org.junit.jupiter.api.Assertions;

import java.io.File;
import java.io.IOException;
Expand All @@ -24,7 +24,7 @@ private Volume(Path tmpDir) {

public static Volume create(String prefix) throws IOException, URISyntaxException {
Path targetDir = Paths.get(Volume.class.getResource("/").toURI()).getParent();
Assert.assertEquals("failed to locate target/ directory", "target", targetDir.getFileName().toString());
Assertions.assertEquals("target", targetDir.getFileName().toString(), "failed to locate target/ directory");
return new Volume(Files.createTempDirectory(targetDir, prefix + "-"));
}

Expand Down Expand Up @@ -56,7 +56,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
}
});
} else {
Assert.fail(src + ": No such file or directory");
Assertions.fail(src + ": No such file or directory");
}
return this;
}
Expand Down
12 changes: 9 additions & 3 deletions integration-tests/it-exporter/it-exporter-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@
<artifactId>prometheus-metrics-exposition-formats</artifactId>
<version>${project.version}</version>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<id>integration-test</id>
Expand All @@ -50,6 +51,7 @@
</plugins>
</pluginManagement>
</build>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down
52 changes: 32 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,75 +80,87 @@
</repository>
</distributionManagement>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<pluginManagement>
<plugins>
<!-- Add plugin versions for reproducible builds. Versions for default bindings are taken from -->
<!-- https://github.com/apache/maven/tree/maven-3.8.1/maven-core/src/main/resources/META-INF/plexus -->
<!-- https://github.com/apache/maven/blob/maven-3.9.6/maven-core/src/main/resources/META-INF/plexus -->
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<version>3.1.1</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.11.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<version>3.1.1</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<version>3.12.1</version>
</plugin>
<!-- Plugins with groupId org.apache.maven.plugins that are not part of default bindings. -->
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.5.0</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<version>3.0.1</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<version>3.6.0</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<version>3.5.0</version>
</plugin>
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<version>3.3.0</version>
</plugin>
</plugins>
</pluginManagement>
Expand Down Expand Up @@ -191,7 +203,7 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<version>3.5.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
Expand Down Expand Up @@ -225,7 +237,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.10.0</version>
<version>2.16.0</version>
<configuration>
<rulesUri>file://${project.basedir}/version-rules.xml</rulesUri>
</configuration>
Expand All @@ -238,7 +250,7 @@
<plugin>
<!-- maven-site-plugin 3.3 requires maven-project-info-reports-plugin < 3.0 -->
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.9</version>
<version>3.1.1</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
Expand Down
5 changes: 2 additions & 3 deletions prometheus-metrics-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
<dependencies>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package io.prometheus.metrics.config;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PrometheusPropertiesTest {
class PrometheusPropertiesTest {

@Test
public void testPrometheusConfig() {
void testPrometheusConfig() {
PrometheusProperties result = PrometheusProperties.get();
Assert.assertEquals(11, result.getDefaultMetricProperties().getHistogramClassicUpperBounds().size());
Assert.assertEquals(4, result.getMetricProperties("http_duration_seconds").getHistogramClassicUpperBounds().size());
Assertions.assertEquals(11, result.getDefaultMetricProperties().getHistogramClassicUpperBounds().size());
Assertions.assertEquals(4, result.getMetricProperties("http_duration_seconds").getHistogramClassicUpperBounds().size());
}

@Test
public void testEmptyUpperBounds() throws IOException {
void testEmptyUpperBounds() throws IOException {
Properties properties = new Properties();
try (InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("emptyUpperBounds.properties")) {
properties.load(stream);
}
Assert.assertEquals(1, properties.size());
Assertions.assertEquals(1, properties.size());
MetricsProperties.load("io.prometheus.metrics", properties);
Assert.assertEquals(0, properties.size());
Assertions.assertEquals(0, properties.size());
}
}
5 changes: 2 additions & 3 deletions prometheus-metrics-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.prometheus.metrics.core.datapoints;

public class TimerApiTest {
class TimerApiTest {

// TODO: Port this from the simpleclient SimpleTimerTest
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import io.prometheus.metrics.model.snapshots.Exemplars;
import io.prometheus.metrics.model.snapshots.Label;
import io.prometheus.metrics.core.util.Scheduler;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class ExemplarSamplerTest {
class ExemplarSamplerTest {

private final int tick = 10; // Time step in milliseconds. Make this larger if the test is flaky.
private final int sampleInterval = 10 * tick; // do not change this
Expand Down Expand Up @@ -56,24 +56,24 @@ public void markCurrentSpanAsExemplar() {
}

@Test
public void testCustomExemplarsBuckets() throws Exception {
void testCustomExemplarsBuckets() throws Exception {
// TODO
}

private io.prometheus.metrics.tracer.common.SpanContext origContext;

@Before
public void setUp() {
@BeforeEach
void setUp() {
origContext = SpanContextSupplier.getSpanContext();
}

@After
public void tearDown() {
@AfterEach
void tearDown() {
SpanContextSupplier.setSpanContext(origContext);
}

@Test
public void testIsSampled() throws Exception {
void testIsSampled() throws Exception {
SpanContext context = new SpanContext();
context.isSampled = false;
SpanContextSupplier.setSpanContext(context);
Expand All @@ -84,7 +84,7 @@ public void testIsSampled() throws Exception {
}

@Test
public void testDefaultConfigHasFourExemplars() throws Exception {
void testDefaultConfigHasFourExemplars() throws Exception {
SpanContext context = new SpanContext();
SpanContextSupplier.setSpanContext(context);
ExemplarSampler sampler = new ExemplarSampler(makeConfig());
Expand All @@ -103,7 +103,7 @@ public void testDefaultConfigHasFourExemplars() throws Exception {
}

@Test
public void testEmptyBuckets() throws Exception {
void testEmptyBuckets() throws Exception {
SpanContext context = new SpanContext();
SpanContextSupplier.setSpanContext(context);
ExemplarSampler sampler = new ExemplarSampler(makeConfig(Double.POSITIVE_INFINITY));
Expand All @@ -116,7 +116,7 @@ public void testEmptyBuckets() throws Exception {
}

@Test
public void testDefaultExemplarsBuckets() throws Exception {
void testDefaultExemplarsBuckets() throws Exception {
SpanContext context = new SpanContext();
SpanContextSupplier.setSpanContext(context);
ExemplarSampler sampler = new ExemplarSampler(makeConfig(0.2, 0.4, 0.6, 0.8, 1.0, Double.POSITIVE_INFINITY));
Expand Down Expand Up @@ -144,12 +144,12 @@ public void testDefaultExemplarsBuckets() throws Exception {
}

@Test
public void testCustomExemplarsNoBuckets() throws Exception {
void testCustomExemplarsNoBuckets() throws Exception {
// TODO
}

@Test
public void testDefaultExemplarsNoBuckets() throws Exception {
void testDefaultExemplarsNoBuckets() throws Exception {
SpanContext context = new SpanContext();
SpanContextSupplier.setSpanContext(context);
ExemplarSampler sampler = new ExemplarSampler(makeConfig());
Expand Down Expand Up @@ -193,7 +193,7 @@ public void testDefaultExemplarsNoBuckets() throws Exception {

private void assertExemplars(ExemplarSampler sampler, double... values) {
Exemplars exemplars = sampler.collect();
Assert.assertEquals(values.length, exemplars.size());
Assertions.assertEquals(values.length, exemplars.size());
for (double value : values) {
boolean found = false;
for (Exemplar exemplar : exemplars) {
Expand All @@ -202,7 +202,7 @@ private void assertExemplars(ExemplarSampler sampler, double... values) {
break;
}
}
Assert.assertTrue(value + " not found", found);
Assertions.assertTrue(found, value + " not found");
}
}

Expand Down

0 comments on commit 1960dec

Please sign in to comment.