|
| 1 | +package io.quarkus.agroal.test; |
| 2 | + |
| 3 | +import jakarta.inject.Inject; |
| 4 | + |
| 5 | +import org.eclipse.microprofile.metrics.*; |
| 6 | +import org.eclipse.microprofile.metrics.annotation.RegistryType; |
| 7 | +import org.junit.jupiter.api.Assertions; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 10 | + |
| 11 | +import io.quarkus.test.QuarkusUnitTest; |
| 12 | + |
| 13 | +/** |
| 14 | + * Test to verify that Agroal metrics are exposed when only quarkus.datasource.metrics.enabled=true is set |
| 15 | + */ |
| 16 | +public class AgroalMetricsOnlyTestCase { |
| 17 | + |
| 18 | + @RegisterExtension |
| 19 | + static final QuarkusUnitTest config = new QuarkusUnitTest() |
| 20 | + .withConfigurationResource("base.properties") |
| 21 | + .overrideConfigKey("quarkus.datasource.metrics.enabled", "true"); |
| 22 | + |
| 23 | + @Inject |
| 24 | + @RegistryType(type = MetricRegistry.Type.VENDOR) |
| 25 | + MetricRegistry registry; |
| 26 | + |
| 27 | + @Test |
| 28 | + public void testMetricsAreExposed() { |
| 29 | + Counter acquireCount = registry.getCounters() |
| 30 | + .get(new MetricID("agroal.acquire.count", new Tag("datasource", "default"))); |
| 31 | + Gauge<?> maxUsed = registry.getGauges() |
| 32 | + .get(new MetricID("agroal.max.used.count", new Tag("datasource", "default"))); |
| 33 | + |
| 34 | + Assertions.assertNotNull(acquireCount, "Agroal metrics should be registered eagerly"); |
| 35 | + Assertions.assertNotNull(maxUsed, "Agroal metrics should be registered eagerly"); |
| 36 | + } |
| 37 | + |
| 38 | +} |
0 commit comments