Make this test more robust to the presence of MBeanServer created in other tests.

This commit is contained in:
Andrzej Bialecki 2017-08-15 03:23:28 +02:00
parent 3cbbecca02
commit fe34212a28
1 changed files with 14 additions and 2 deletions

View File

@ -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());
}
});