use of javax.management.MBeanServerConnection in project samza by apache.
the class TestJmxAppender method testJmxAppender.
@Test
public void testJmxAppender() throws Exception {
MBeanServerConnection mbserver = JMXConnectorFactory.connect(URL).getMBeanServerConnection();
ObjectName objectName = new ObjectName(JmxAppender.JMX_OBJECT_DOMAIN + ":type=" + JmxAppender.JMX_OBJECT_TYPE + ",name=" + JmxAppender.JMX_OBJECT_NAME);
String level = null;
MockAppender mockAppender = new MockAppender();
Logger.getRootLogger().addAppender(mockAppender);
// Check INFO is set (from log4j.xml).
level = (String) mbserver.getAttribute(objectName, "Level");
assertEquals("INFO", level);
log.info("info1");
log.debug("debug1");
// Set to debug.
mbserver.setAttribute(objectName, new Attribute("Level", "debug"));
// Check DEBUG is set.
level = (String) mbserver.getAttribute(objectName, "Level");
assertEquals("DEBUG", level);
log.info("info2");
log.debug("debug2");
List<LoggingEvent> logLines = mockAppender.getLogLines();
// Should not have debug1 because log level is info at first.
Iterator<LoggingEvent> logLineIterator = logLines.iterator();
assertEquals(3, logLines.size());
assertEquals("info1", logLineIterator.next().getMessage());
assertEquals("info2", logLineIterator.next().getMessage());
assertEquals("debug2", logLineIterator.next().getMessage());
}
use of javax.management.MBeanServerConnection in project wildfly by wildfly.
the class ServiceMBeanSupportTestCase method testSarWithServiceMBeanSupport.
/**
* Tests that invocation on a service deployed within a .sar, inside a .ear without an application.xml, is successful.
*
* @throws Exception
*/
@Test
public void testSarWithServiceMBeanSupport() throws Exception {
// get mbean server
final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials());
final MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection();
try {
// deploy the unmanaged sar
deployer.deploy(ServiceMBeanSupportTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME);
// check the unmanaged mbean state
int state = (Integer) mBeanServerConnection.getAttribute(new ObjectName("jboss:name=service-mbean-support-test"), "State");
Assert.assertEquals("Unexpected return state from Test MBean: " + state, ServiceMBean.STARTED, state);
} finally {
// undeploy it
deployer.undeploy(ServiceMBeanSupportTestCase.UNMANAGED_SAR_DEPLOYMENT_NAME);
}
// check the result of life-cycle methods invocation, using result mbean
// also check that the result mbean received lifecycle notifications
String[] expectedAttributes = new String[] { "CreateServiceInvoked", "StartServiceInvoked", "StopServiceInvoked", "DestroyServiceInvoked", "StartingNotificationReceived", "StartedNotificationReceived", "StoppingNotificationReceived", "StoppedNotificationReceived" };
// each of these attributes should be 'true'
for (String attribute : expectedAttributes) {
Boolean result = (Boolean) mBeanServerConnection.getAttribute(new ObjectName("jboss:name=service-mbean-support-test-result"), attribute);
Assert.assertTrue("Unexpected result for " + attribute + ": " + result, result);
}
}
use of javax.management.MBeanServerConnection in project wildfly by wildfly.
the class JNDIBindingMBeanTestCase method testMBeanStartup.
/**
* Makes sure that the MBeans that are expected to be up and running are accessible.
*
* @throws Exception
* @see https://developer.jboss.org/thread/251092
*/
@Test
public void testMBeanStartup() throws Exception {
// get mbean server
final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials());
try {
final MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection();
// check the deployed MBeans
for (int i = 1; i <= 9; i++) {
final String mbeanName = "jboss:name=mbean-startup-jndi-bind-" + i;
final Object instance = mBeanServerConnection.getObjectInstance(new ObjectName(mbeanName));
Assert.assertNotNull("No instance returned for MBean: " + mbeanName, instance);
}
} finally {
connector.close();
}
}
use of javax.management.MBeanServerConnection in project wildfly by wildfly.
the class SarWithinEarTestCase method testSarWithinEar.
private void testSarWithinEar(final String serviceName) throws Exception {
final MBeanServerConnection mBeanServerConnection = this.getMBeanServerConnection();
final ObjectName mbeanObjectName = new ObjectName(serviceName);
final int num1 = 3;
final int num2 = 4;
// invoke the operation on MBean
Integer sum = (Integer) mBeanServerConnection.invoke(mbeanObjectName, "add", new Object[] { num1, num2 }, new String[] { Integer.TYPE.getName(), Integer.TYPE.getName() });
Assert.assertEquals("Unexpected return value from MBean: " + mbeanObjectName, num1 + num2, (int) sum);
}
use of javax.management.MBeanServerConnection in project wildfly by wildfly.
the class SarInjectionTestCase method testMBean.
@Test
public void testMBean() throws Exception {
final JMXConnector connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL());
try {
final MBeanServerConnection mbeanServer = connector.getMBeanServerConnection();
final ObjectName objectName = new ObjectName("jboss:name=POJOService");
Assert.assertTrue(2 == (Integer) mbeanServer.getAttribute(objectName, "Count"));
Assert.assertTrue(2 == (Integer) mbeanServer.getAttribute(objectName, "InjectedCount"));
Assert.assertTrue((Boolean) mbeanServer.getAttribute(objectName, "CreateCalled"));
Assert.assertTrue((Boolean) mbeanServer.getAttribute(objectName, "StartCalled"));
Assert.assertFalse((Boolean) mbeanServer.getAttribute(objectName, "StopCalled"));
Assert.assertFalse((Boolean) mbeanServer.getAttribute(objectName, "DestroyCalled"));
} finally {
IoUtils.safeClose(connector);
}
}
Aggregations