jmx metrics: Add test timeouts and mbean server status assertions (#218)
This commit is contained in:
parent
818a1e2d63
commit
ba515bffaa
|
|
@ -8,6 +8,7 @@ package io.opentelemetry.contrib.jmxmetrics;
|
|||
import static io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat;
|
||||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry;
|
||||
import static java.lang.management.ManagementFactory.getPlatformMBeanServer;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
||||
import groovy.lang.Closure;
|
||||
import groovy.util.Eval;
|
||||
|
|
@ -38,10 +39,12 @@ import org.junit.jupiter.api.BeforeEach;
|
|||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
@Timeout(value = 10, unit = SECONDS)
|
||||
class InstrumenterHelperTest {
|
||||
|
||||
private static final MBeanServer mbeanServer = getPlatformMBeanServer();
|
||||
|
|
@ -78,6 +81,11 @@ class InstrumenterHelperTest {
|
|||
jmxServer.stop();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void confirmServerIsActive() {
|
||||
assertThat(jmxServer.isActive()).isTrue();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void setupOtel() {
|
||||
metricReader = InMemoryMetricReader.create();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
package io.opentelemetry.contrib.jmxmetrics;
|
||||
|
||||
import static java.lang.management.ManagementFactory.getPlatformMBeanServer;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -24,8 +25,11 @@ import javax.management.remote.JMXServiceURL;
|
|||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
@Timeout(value = 10, unit = SECONDS)
|
||||
class MBeanHelperTest {
|
||||
|
||||
private static final MBeanServer mbeanServer = getPlatformMBeanServer();
|
||||
|
|
@ -56,6 +60,11 @@ class MBeanHelperTest {
|
|||
jmxServer.stop();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void confirmServerIsActive() {
|
||||
assertThat(jmxServer.isActive()).isTrue();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void unregisterBeans() throws Exception {
|
||||
for (ObjectInstance bean : registeredBeans) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
package io.opentelemetry.contrib.jmxmetrics;
|
||||
|
||||
import static java.lang.management.ManagementFactory.getPlatformMBeanServer;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
|
@ -28,7 +29,9 @@ import org.junit.jupiter.api.AfterAll;
|
|||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
||||
@Timeout(value = 10, unit = SECONDS)
|
||||
class OtelHelperJmxTest {
|
||||
|
||||
private static final String thingName =
|
||||
|
|
@ -48,10 +51,15 @@ class OtelHelperJmxTest {
|
|||
|
||||
@AfterAll
|
||||
static void tearDown() throws Exception {
|
||||
jmxServer.stop();
|
||||
mbeanServer.unregisterMBean(new ObjectName(thingName));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void stopServer() throws Exception {
|
||||
// each test stands up its own server
|
||||
jmxServer.stop();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void unregisterBeans() throws Exception {
|
||||
for (ObjectInstance bean : registeredBeans) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue