use of javax.management.ObjectInstance in project lucene-solr by apache.
the class SolrJmxReporterTest method testEnabled.
@Test
public void testEnabled() throws Exception {
String root1 = TestUtil.randomSimpleString(random(), 5, 10);
PluginInfo pluginInfo1 = createReporterPluginInfo(root1, true);
metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo1, coreMetricManager.getTag());
String root2 = TestUtil.randomSimpleString(random(), 5, 10);
assertFalse(root2.equals(root1));
PluginInfo pluginInfo2 = createReporterPluginInfo(root2, false);
metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo2, coreMetricManager.getTag());
Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
assertTrue(reporters.containsKey(pluginInfo1.name + "@" + coreMetricManager.getTag()));
assertTrue(reporters.containsKey(pluginInfo2.name + "@" + coreMetricManager.getTag()));
String scope = SolrMetricTestUtils.getRandomScope(random(), true);
SolrInfoBean.Category category = SolrMetricTestUtils.getRandomCategory(random(), true);
Map<String, Counter> metrics = SolrMetricTestUtils.getRandomMetrics(random(), true);
SolrMetricProducer producer = SolrMetricTestUtils.getProducerOf(metricManager, category, scope, metrics);
coreMetricManager.registerMetricProducer(scope, producer);
Set<ObjectInstance> objects = mBeanServer.queryMBeans(null, null);
assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && root1.equals(o.getObjectName().getDomain())).count());
assertEquals(0, objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && root2.equals(o.getObjectName().getDomain())).count());
}
use of javax.management.ObjectInstance in project lucene-solr by apache.
the class SolrJmxReporterTest method testReloadCore.
@Test
public void testReloadCore() throws Exception {
Random random = random();
String scope = SolrMetricTestUtils.getRandomScope(random, true);
SolrInfoBean.Category category = SolrMetricTestUtils.getRandomCategory(random, true);
Map<String, Counter> metrics = SolrMetricTestUtils.getRandomMetrics(random, true);
SolrMetricProducer producer = SolrMetricTestUtils.getProducerOf(metricManager, category, scope, metrics);
coreMetricManager.registerMetricProducer(scope, producer);
Set<ObjectInstance> objects = mBeanServer.queryMBeans(null, null);
assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && o.getObjectName().getDomain().equals(rootName)).count());
h.getCoreContainer().reload(h.getCore().getName());
PluginInfo pluginInfo = createReporterPluginInfo(rootName, true);
metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo, String.valueOf(coreMetricManager.getCore().hashCode()));
coreMetricManager.registerMetricProducer(scope, producer);
objects = mBeanServer.queryMBeans(null, null);
assertEquals(metrics.size(), objects.stream().filter(o -> scope.equals(o.getObjectName().getKeyProperty("scope")) && rootName.equals(o.getObjectName().getDomain())).count());
}
use of javax.management.ObjectInstance in project lucene-solr by apache.
the class TestJmxIntegration method testJmxRegistration.
@Test
public void testJmxRegistration() throws Exception {
assertTrue("No MBeans found in server", mbeanServer.getMBeanCount() > 0);
Set<ObjectInstance> objects = mbeanServer.queryMBeans(null, null);
assertFalse("No objects found in mbean server", objects.isEmpty());
int numDynamicMbeans = 0;
for (ObjectInstance o : objects) {
ObjectName name = o.getObjectName();
assertNotNull("Null name on: " + o.toString(), name);
MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(name);
if (name.getDomain().equals("solr")) {
numDynamicMbeans++;
MBeanAttributeInfo[] attrs = mbeanInfo.getAttributes();
if (name.getKeyProperty("name").equals("fetcher")) {
// no attributes without active replication
continue;
}
assertTrue("No Attributes found for mbean: " + o.getObjectName() + ", " + mbeanInfo, 0 < attrs.length);
for (MBeanAttributeInfo attr : attrs) {
// ensure every advertised attribute is gettable
try {
Object trash = mbeanServer.getAttribute(o.getObjectName(), attr.getName());
} catch (javax.management.AttributeNotFoundException e) {
throw new RuntimeException("Unable to featch attribute for " + o.getObjectName() + ": " + attr.getName(), e);
}
}
}
}
assertTrue("No MBeans found", 0 < numDynamicMbeans);
}
use of javax.management.ObjectInstance in project lucene-solr by apache.
the class TestJmxIntegration method testJmxOnCoreReload.
@Test
@Ignore("timing problem? https://issues.apache.org/jira/browse/SOLR-2715")
public void testJmxOnCoreReload() throws Exception {
String coreName = h.getCore().getName();
Set<ObjectInstance> oldBeans = mbeanServer.queryMBeans(null, null);
int oldNumberOfObjects = 0;
for (ObjectInstance bean : oldBeans) {
try {
if (String.valueOf(h.getCore().hashCode()).equals(mbeanServer.getAttribute(bean.getObjectName(), "coreHashCode"))) {
oldNumberOfObjects++;
}
} catch (AttributeNotFoundException e) {
// expected
}
}
log.info("Before Reload: Size of infoRegistry: " + h.getCore().getInfoRegistry().size() + " MBeans: " + oldNumberOfObjects);
assertEquals("Number of registered MBeans is not the same as info registry size", h.getCore().getInfoRegistry().size(), oldNumberOfObjects);
h.getCoreContainer().reload(coreName);
Set<ObjectInstance> newBeans = mbeanServer.queryMBeans(null, null);
int newNumberOfObjects = 0;
int registrySize = 0;
try (SolrCore core = h.getCoreContainer().getCore(coreName)) {
registrySize = core.getInfoRegistry().size();
for (ObjectInstance bean : newBeans) {
try {
if (String.valueOf(core.hashCode()).equals(mbeanServer.getAttribute(bean.getObjectName(), "coreHashCode"))) {
newNumberOfObjects++;
}
} catch (AttributeNotFoundException e) {
// expected
}
}
}
log.info("After Reload: Size of infoRegistry: " + registrySize + " MBeans: " + newNumberOfObjects);
assertEquals("Number of registered MBeans is not the same as info registry size", registrySize, newNumberOfObjects);
}
use of javax.management.ObjectInstance in project tomee by apache.
the class CxfUtilTest method checkMonitoring.
@Test
public void checkMonitoring() throws IOException, MalformedObjectNameException {
// need a call to get something
IO.slurp(new URL(root.toExternalForm() + "test/monitoring/cxf"));
final Set<ObjectInstance> mbeans = ManagementFactory.getPlatformMBeanServer().queryMBeans(new ObjectName("*:*,type=Performance.Counter.Server"), null);
assertNotNull(mbeans);
assertEquals(2, mbeans.size());
}
Aggregations