Skip to content

Commit a2d3b20

Browse files
authored
add tests (#1163)
* allow java 17 in tests Signed-off-by: Gregor Zeitlinger <[email protected]> * allow java 17 in tests Signed-off-by: Gregor Zeitlinger <[email protected]> * add coverage Signed-off-by: Gregor Zeitlinger <[email protected]> --------- Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 28b4048 commit a2d3b20

File tree

15 files changed

+197
-88
lines changed

15 files changed

+197
-88
lines changed

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
java temurin-17.0.7+7

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
<skip>${coverage.skip}</skip>
233233
<excludes>
234234
<exclude>**/generated/**</exclude>
235+
<exclude>**/*BlockingRejectedExecutionHandler*</exclude>
235236
</excludes>
236237
</configuration>
237238
<executions>
@@ -310,6 +311,9 @@
310311
<release>${java.version}</release>
311312
<source>${java.version}</source>
312313
<target>${java.version}</target>
314+
<testRelease>17</testRelease>
315+
<testSource>17</testSource>
316+
<testTarget>17</testTarget>
313317
<showWarnings>true</showWarnings>
314318
<compilerArgs>
315319
<arg>-Xlint:all,-serial,-processing,-options</arg>

prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExemplarsPropertiesTest.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
55

6-
import com.google.common.collect.ImmutableMap;
76
import java.util.HashMap;
87
import java.util.Map;
98
import org.junit.jupiter.api.Test;
@@ -14,7 +13,7 @@ class ExemplarsPropertiesTest {
1413
void load() {
1514
ExemplarsProperties properties =
1615
load(
17-
ImmutableMap.of(
16+
Map.of(
1817
"io.prometheus.exemplars.minRetentionPeriodSeconds", "1",
1918
"io.prometheus.exemplars.maxRetentionPeriodSeconds", "2",
2019
"io.prometheus.exemplars.sampleIntervalMilliseconds", "3"));
@@ -23,20 +22,17 @@ void load() {
2322
assertThat(properties.getSampleIntervalMilliseconds()).isEqualTo(3);
2423

2524
assertThatExceptionOfType(PrometheusPropertiesException.class)
26-
.isThrownBy(
27-
() -> load(ImmutableMap.of("io.prometheus.exemplars.minRetentionPeriodSeconds", "-1")))
25+
.isThrownBy(() -> load(Map.of("io.prometheus.exemplars.minRetentionPeriodSeconds", "-1")))
2826
.withMessage(
2927
"io.prometheus.exemplars.minRetentionPeriodSeconds: Expecting value > 0. Found: -1");
3028

3129
assertThatExceptionOfType(PrometheusPropertiesException.class)
32-
.isThrownBy(
33-
() -> load(ImmutableMap.of("io.prometheus.exemplars.maxRetentionPeriodSeconds", "0")))
30+
.isThrownBy(() -> load(Map.of("io.prometheus.exemplars.maxRetentionPeriodSeconds", "0")))
3431
.withMessage(
3532
"io.prometheus.exemplars.maxRetentionPeriodSeconds: Expecting value > 0. Found: 0");
3633

3734
assertThatExceptionOfType(PrometheusPropertiesException.class)
38-
.isThrownBy(
39-
() -> load(ImmutableMap.of("io.prometheus.exemplars.sampleIntervalMilliseconds", "-1")))
35+
.isThrownBy(() -> load(Map.of("io.prometheus.exemplars.sampleIntervalMilliseconds", "-1")))
4036
.withMessage(
4137
"io.prometheus.exemplars.sampleIntervalMilliseconds: Expecting value > 0. Found: -1");
4238
}

prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterFilterPropertiesTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5-
import com.google.common.collect.ImmutableMap;
65
import java.util.HashMap;
76
import java.util.Map;
87
import org.junit.jupiter.api.Test;
@@ -13,7 +12,7 @@ class ExporterFilterPropertiesTest {
1312
void load() {
1413
ExporterFilterProperties properties =
1514
load(
16-
ImmutableMap.of(
15+
Map.of(
1716
"io.prometheus.exporter.filter.metricNameMustBeEqualTo", "a,b,c",
1817
"io.prometheus.exporter.filter.metricNameMustNotBeEqualTo", "d,e,f",
1918
"io.prometheus.exporter.filter.metricNameMustStartWith", "g,h,i",

prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterHttpServerPropertiesTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
55

6-
import com.google.common.collect.ImmutableMap;
76
import java.util.HashMap;
87
import java.util.Map;
98
import org.junit.jupiter.api.Test;
@@ -12,11 +11,11 @@ class ExporterHttpServerPropertiesTest {
1211
@Test
1312
void load() {
1413
ExporterHttpServerProperties properties =
15-
load(ImmutableMap.of("io.prometheus.exporter.httpServer.port", "1"));
14+
load(Map.of("io.prometheus.exporter.httpServer.port", "1"));
1615
assertThat(properties.getPort()).isOne();
1716

1817
assertThatExceptionOfType(PrometheusPropertiesException.class)
19-
.isThrownBy(() -> load(ImmutableMap.of("io.prometheus.exporter.httpServer.port", "0")))
18+
.isThrownBy(() -> load(Map.of("io.prometheus.exporter.httpServer.port", "0")))
2019
.withMessage("io.prometheus.exporter.httpServer.port: Expecting value > 0. Found: 0");
2120
}
2221

prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterOpenTelemetryPropertiesTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5-
import com.google.common.collect.ImmutableMap;
65
import java.util.HashMap;
76
import java.util.Map;
87
import org.junit.jupiter.api.Test;
@@ -13,7 +12,7 @@ class ExporterOpenTelemetryPropertiesTest {
1312
void load() {
1413
ExporterOpenTelemetryProperties properties =
1514
load(
16-
ImmutableMap.of(
15+
Map.of(
1716
"io.prometheus.exporter.opentelemetry.protocol", "grpc",
1817
"io.prometheus.exporter.opentelemetry.endpoint", "http://localhost:8080",
1918
"io.prometheus.exporter.opentelemetry.headers", "key1=value1,key2=value2",
@@ -33,15 +32,15 @@ private static void assertValues(ExporterOpenTelemetryProperties properties) {
3332
assertThat(properties.getProtocol()).isEqualTo("grpc");
3433
assertThat(properties.getEndpoint()).isEqualTo("http://localhost:8080");
3534
assertThat(properties.getHeaders())
36-
.containsExactlyInAnyOrderEntriesOf(ImmutableMap.of("key1", "value1", "key2", "value2"));
35+
.containsExactlyInAnyOrderEntriesOf(Map.of("key1", "value1", "key2", "value2"));
3736
assertThat(properties.getInterval()).isEqualTo("10s");
3837
assertThat(properties.getTimeout()).isEqualTo("5s");
3938
assertThat(properties.getServiceName()).isEqualTo("serviceName");
4039
assertThat(properties.getServiceNamespace()).isEqualTo("serviceNamespace");
4140
assertThat(properties.getServiceInstanceId()).isEqualTo("serviceInstanceId");
4241
assertThat(properties.getServiceVersion()).isEqualTo("serviceVersion");
4342
assertThat(properties.getResourceAttributes())
44-
.containsExactlyInAnyOrderEntriesOf(ImmutableMap.of("key1", "value1", "key2", "value2"));
43+
.containsExactlyInAnyOrderEntriesOf(Map.of("key1", "value1", "key2", "value2"));
4544
}
4645

4746
private static ExporterOpenTelemetryProperties load(Map<String, String> map) {

prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPropertiesTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
55

6-
import com.google.common.collect.ImmutableMap;
76
import java.util.HashMap;
87
import java.util.Map;
98
import org.junit.jupiter.api.Test;
@@ -15,7 +14,7 @@ void load() {
1514
ExporterProperties properties =
1615
load(
1716
new HashMap<>(
18-
ImmutableMap.of(
17+
Map.of(
1918
"io.prometheus.exporter.includeCreatedTimestamps", "true",
2019
"io.prometheus.exporter.exemplarsOnAllMetricTypes", "true")));
2120
assertThat(properties.getIncludeCreatedTimestamps()).isTrue();
@@ -26,17 +25,15 @@ void load() {
2625
() ->
2726
load(
2827
new HashMap<>(
29-
ImmutableMap.of(
30-
"io.prometheus.exporter.includeCreatedTimestamps", "invalid"))))
28+
Map.of("io.prometheus.exporter.includeCreatedTimestamps", "invalid"))))
3129
.withMessage(
3230
"io.prometheus.exporter.includeCreatedTimestamps: Expecting 'true' or 'false'. Found: invalid");
3331
assertThatExceptionOfType(PrometheusPropertiesException.class)
3432
.isThrownBy(
3533
() ->
3634
load(
3735
new HashMap<>(
38-
ImmutableMap.of(
39-
"io.prometheus.exporter.exemplarsOnAllMetricTypes", "invalid"))))
36+
Map.of("io.prometheus.exporter.exemplarsOnAllMetricTypes", "invalid"))))
4037
.withMessage(
4138
"io.prometheus.exporter.exemplarsOnAllMetricTypes: Expecting 'true' or 'false'. Found: invalid");
4239
}

prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/ExporterPushgatewayPropertiesTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
55

6-
import com.google.common.collect.ImmutableMap;
76
import java.util.HashMap;
87
import java.util.Map;
98
import org.junit.jupiter.api.Test;
@@ -14,7 +13,7 @@ class ExporterPushgatewayPropertiesTest {
1413
void load() {
1514
ExporterPushgatewayProperties properties =
1615
load(
17-
ImmutableMap.of(
16+
Map.of(
1817
"io.prometheus.exporter.pushgateway.address", "http://localhost",
1918
"io.prometheus.exporter.pushgateway.job", "job",
2019
"io.prometheus.exporter.pushgateway.scheme", "http"));
@@ -24,7 +23,7 @@ void load() {
2423
assertThat(properties.getScheme()).isEqualTo("http");
2524

2625
assertThatExceptionOfType(PrometheusPropertiesException.class)
27-
.isThrownBy(() -> load(ImmutableMap.of("io.prometheus.exporter.pushgateway.scheme", "foo")))
26+
.isThrownBy(() -> load(Map.of("io.prometheus.exporter.pushgateway.scheme", "foo")))
2827
.withMessage(
2928
"io.prometheus.exporter.pushgateway.scheme: Illegal value. Expecting 'http' or 'https'. Found: foo");
3029
}

prometheus-metrics-exporter-httpserver/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
<properties>
2020
<automatic.module.name>io.prometheus.metrics.exporter.httpserver</automatic.module.name>
21-
<!-- we have to set the line coverage to 0.0 because the module is tested with integration tests-->
22-
<jacoco.line-coverage>0.0</jacoco.line-coverage>
21+
<jacoco.line-coverage>0.45</jacoco.line-coverage>
2322
</properties>
2423

2524
<dependencies>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.prometheus.metrics.exporter.httpserver;
2+
3+
import java.util.concurrent.RejectedExecutionHandler;
4+
import java.util.concurrent.ThreadPoolExecutor;
5+
6+
class BlockingRejectedExecutionHandler implements RejectedExecutionHandler {
7+
8+
@Override
9+
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor threadPoolExecutor) {
10+
if (!threadPoolExecutor.isShutdown()) {
11+
try {
12+
threadPoolExecutor.getQueue().put(runnable);
13+
} catch (InterruptedException ignored) {
14+
// ignore
15+
}
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)