Skip to content

Commit

Permalink
Clear metrics before test start (#18883)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbartok committed Jun 11, 2021
1 parent 1e1a816 commit 1009c1c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void tearDown() {

@Test
public void testNoMBeanLeak() {
helper.assertNoMBeans();
helper.clearMBeans();

ClientConfig clientConfig = new ClientConfig();
clientConfig.getMetricsConfig()
Expand All @@ -62,11 +62,6 @@ public void testNoMBeanLeak() {
assertTrueEventually(() -> helper.assertMBeanContains(expectedObjectName));

client.shutdown();
// if failing, grep for "test-jvm"
// there should be a Metric[com.hazelcast:type=Metrics,instance=$CLIENT_NAME,prefix=test-jvm-$JVM_NAME] metric if the
// client was created with TestHazelcastFactory
// $JVM_NAME contains the PID, so $CLIENT_NAME + $JVM_NAME together helps identifying the test left the given metric
// around
helper.assertNoMBeans();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.hazelcast.internal.metrics.jmx.MetricsMBean.Type;
import com.hazelcast.internal.util.BiTuple;
import com.hazelcast.internal.util.ExceptionUtil;
import com.hazelcast.internal.util.TriTuple;
import com.hazelcast.logging.ILogger;
import com.hazelcast.logging.Logger;
Expand Down Expand Up @@ -51,6 +52,20 @@ public JmxPublisherTestHelper(String domainPrefix) throws Exception {
platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
}

public void clearMBeans() {
queryOurInstances().forEach(this::clearMBean);
assertNoMBeans();
}

private void clearMBean(ObjectInstance instance) {
try {
ObjectName name = instance.getObjectName();
platformMBeanServer.unregisterMBean(name);
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}

public void assertNoMBeans() {
Set<ObjectInstance> instances = queryOurInstances();
if (instances.size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void tearDown() {

@Test
public void testNoMBeanLeak() {
helper.assertNoMBeans();
helper.clearMBeans();

Config config = smallInstanceConfig();
config.getMetricsConfig()
Expand Down

0 comments on commit 1009c1c

Please sign in to comment.