From fe34212a289b64c5fd933ff550511964cb45e871 Mon Sep 17 00:00:00 2001 From: Andrzej Bialecki Date: Tue, 15 Aug 2017 03:23:28 +0200 Subject: [PATCH] Make this test more robust to the presence of MBeanServer created in other tests. --- .../reporters/solr/SolrCloudReportersTest.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrCloudReportersTest.java b/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrCloudReportersTest.java index 224778d7951..605daa7b209 100644 --- a/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrCloudReportersTest.java +++ b/solr/core/src/test/org/apache/solr/metrics/reporters/solr/SolrCloudReportersTest.java @@ -28,7 +28,7 @@ import org.apache.solr.core.SolrCore; import org.apache.solr.metrics.AggregateMetric; import org.apache.solr.metrics.SolrMetricManager; import org.apache.solr.metrics.SolrMetricReporter; -import org.apache.solr.util.JmxUtil; +import org.apache.solr.metrics.reporters.SolrJmxReporter; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -42,6 +42,7 @@ public class SolrCloudReportersTest extends SolrCloudTestCase { int jmxReporter; + @BeforeClass public static void configureDummyCluster() throws Exception { configureCluster(0).configure(); @@ -52,7 +53,6 @@ public class SolrCloudReportersTest extends SolrCloudTestCase { shutdownCluster(); leaderRegistries = 0; clusterRegistries = 0; - jmxReporter = JmxUtil.findFirstMBeanServer() != null ? 1 : 0; } @Test @@ -99,6 +99,12 @@ public class SolrCloudReportersTest extends SolrCloudTestCase { assertEquals(5, sor.getPeriod()); for (String registryName : metricManager.registryNames(".*\\.shard[0-9]\\.replica.*")) { reporters = metricManager.getReporters(registryName); + jmxReporter = 0; + reporters.forEach((k, v) -> { + if (v instanceof SolrJmxReporter) { + jmxReporter++; + } + }); assertEquals(reporters.toString(), 1 + jmxReporter, reporters.size()); reporter = null; for (String name : reporters.keySet()) { @@ -158,6 +164,12 @@ public class SolrCloudReportersTest extends SolrCloudTestCase { assertEquals(reporters.toString(), 0, reporters.size()); for (String registryName : metricManager.registryNames(".*\\.shard[0-9]\\.replica.*")) { reporters = metricManager.getReporters(registryName); + jmxReporter = 0; + reporters.forEach((k, v) -> { + if (v instanceof SolrJmxReporter) { + jmxReporter++; + } + }); assertEquals(reporters.toString(), 0 + jmxReporter, reporters.size()); } });