Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jmx metrics: Add test timeouts and mbean server status assertions #218

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -38,10 +39,12 @@
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();
Expand Down Expand Up @@ -78,6 +81,11 @@ static void tearDown() throws Exception {
jmxServer.stop();
}

@BeforeEach
void confirmServerIsActive() {
assertThat(jmxServer.isActive()).isTrue();
}

@BeforeEach
void setupOtel() {
metricReader = InMemoryMetricReader.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,8 +25,11 @@
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();
Expand Down Expand Up @@ -56,6 +60,11 @@ static void tearDown() throws Exception {
jmxServer.stop();
}

@BeforeEach
void confirmServerIsActive() {
assertThat(jmxServer.isActive()).isTrue();
}

@AfterEach
void unregisterBeans() throws Exception {
for (ObjectInstance bean : registeredBeans) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +29,9 @@
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 =
Expand All @@ -48,10 +51,15 @@ static void setUp() throws Exception {

@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) {
Expand Down