|
6 | 6 | package io.opentelemetry.exporter.prometheus;
|
7 | 7 |
|
8 | 8 | import static io.opentelemetry.api.common.AttributeKey.stringKey;
|
| 9 | +import static org.assertj.core.api.Assertions.as; |
9 | 10 | import static org.assertj.core.api.Assertions.assertThat;
|
10 | 11 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
11 | 12 |
|
|
32 | 33 | import io.opentelemetry.sdk.resources.Resource;
|
33 | 34 | import java.io.ByteArrayInputStream;
|
34 | 35 | import java.io.IOException;
|
| 36 | +import java.net.ServerSocket; |
35 | 37 | import java.nio.charset.StandardCharsets;
|
36 | 38 | import java.util.Collections;
|
37 | 39 | import java.util.List;
|
| 40 | +import java.util.concurrent.Executors; |
| 41 | +import java.util.concurrent.ScheduledExecutorService; |
| 42 | +import java.util.concurrent.ScheduledThreadPoolExecutor; |
| 43 | +import java.util.concurrent.ThreadPoolExecutor; |
38 | 44 | import java.util.concurrent.atomic.AtomicReference;
|
39 | 45 | import java.util.zip.GZIPInputStream;
|
| 46 | +import org.assertj.core.api.InstanceOfAssertFactories; |
40 | 47 | import org.junit.jupiter.api.AfterAll;
|
41 | 48 | import org.junit.jupiter.api.BeforeAll;
|
42 | 49 | import org.junit.jupiter.api.BeforeEach;
|
@@ -295,6 +302,33 @@ void stringRepresentation() {
|
295 | 302 | .isEqualTo("PrometheusHttpServer{address=" + prometheusServer.getAddress() + "}");
|
296 | 303 | }
|
297 | 304 |
|
| 305 | + @Test |
| 306 | + void defaultExecutor() { |
| 307 | + assertThat(prometheusServer) |
| 308 | + .extracting("executor", as(InstanceOfAssertFactories.type(ThreadPoolExecutor.class))) |
| 309 | + .satisfies(executor -> assertThat(executor.getCorePoolSize()).isEqualTo(5)); |
| 310 | + } |
| 311 | + |
| 312 | + @Test |
| 313 | + void customExecutor() throws IOException { |
| 314 | + ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(10); |
| 315 | + int port; |
| 316 | + try (ServerSocket socket = new ServerSocket(0)) { |
| 317 | + port = socket.getLocalPort(); |
| 318 | + } |
| 319 | + try (PrometheusHttpServer server = |
| 320 | + PrometheusHttpServer.builder() |
| 321 | + .setHost("localhost") |
| 322 | + .setPort(port) |
| 323 | + .setExecutor(scheduledExecutor) |
| 324 | + .build()) { |
| 325 | + assertThat(server) |
| 326 | + .extracting( |
| 327 | + "executor", as(InstanceOfAssertFactories.type(ScheduledThreadPoolExecutor.class))) |
| 328 | + .satisfies(executor -> assertThat(executor).isSameAs(scheduledExecutor)); |
| 329 | + } |
| 330 | + } |
| 331 | + |
298 | 332 | private static List<MetricData> generateTestData() {
|
299 | 333 | return ImmutableList.of(
|
300 | 334 | ImmutableMetricData.createLongSum(
|
|
0 commit comments