DefaultRequiredModelMBeanTest.java 文件源码

java
阅读 19 收藏 0 点赞 0 评论 0

项目:freeVM 作者:
/**
 * Verify that RequiredModelMBean generates correct generic notification.
 * <ul>
 * Step by step:
 * <li>Create RequiredModelMBean object using RequiredModelMBean()
 * constructor.
 * <li>Set Integer class as managed resource for RequiredModelMBean object.
 * <li>Create ObjectName object.
 * <li>Register RequiredModelMBean object in MBeanServer with above
 * objectName.
 * <li> Create notification listener and add this listener in server.
 * <li>Send notification using sendNotification(msg) method of
 * RequiredModelMBean.
 * <li> Verify that handleNotification method of listener was invoked.
 * <li>Verify notification in parameter of handleNotification method: its
 * type=jmx.modelmbean.generic, its message=msg in 4 step and sequence
 * number=1.
 * </ul>
 */
public Result testSendNotification() throws Exception {
    RequiredModelMBean requiredModelMBean = new RequiredModelMBean();
    requiredModelMBean
        .setManagedResource(new Integer(7), "ObjectReference");
    ObjectName objectName = new ObjectName("modelmbean:type=Operation");
    MBeanServer server = MBeanServerFactory.createMBeanServer();
    server.registerMBean(requiredModelMBean, objectName);
    final String message = "message";
    NotificationListener notificationListener = new NotificationListener() {
        public void handleNotification(Notification arg0, Object arg1) {
            ishandleNotificationInvoked = true;
            assertEquals(arg0.getType(), "jmx.modelmbean.generic");
            assertEquals(arg0.getMessage(), message);
            assertEquals(arg0.getSequenceNumber(), 1);
        }

    };
    server.addNotificationListener(objectName, notificationListener, null,
        null);
    requiredModelMBean.sendNotification(message);
    assertTrue(ishandleNotificationInvoked);
    server.unregisterMBean(objectName);
    return result();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号