/**
* <ul>
* Verify that logs of new notifications, when sendNotification is invoked,
* write to file. File name is value of descriptor of
* ModelMBeanNotificationInfo.
* <li>Create java class, which is not MBean. MBean has 1 getter and 1
* setter methods.
* <li>Create ModelMBeanNotificationInfo object for my type with descriptor
* with logging.
* <li>Create ModelMBeanInfoSupport object. All ModelMBeanXXXInfo except
* ModelMBeanNotificationInfo are default.
* <li>Create RequiredModelMBean object.
* <li>Instance of java class in 1st step sets managed resource for
* RequiredModelMBean using setManagedResource method.
* <li>Send my notification using sendNotification method.
* <li>Verify that logfile was created and size of file > 0.
* </ul>
*/
public Result testLogging() throws Exception {
ModelMBeanAttributeInfo attributeInfoForG = new ModelMBeanAttributeInfo(
"g", "descr", class1.getMethod("getG", null), class1.getMethod(
"setG", new Class[] { String.class }));
ModelMBeanAttributeInfo[] attributeInfos = new ModelMBeanAttributeInfo[] { attributeInfoForG };
ModelMBeanNotificationInfo notificationInfo = new ModelMBeanNotificationInfo(
new String[] { SimpleNotification.notificationType },
SimpleNotification.notificationType, "description");
File file = File.createTempFile("log", ".txt");
file.deleteOnExit();
Descriptor descriptor = notificationInfo.getDescriptor();
descriptor.setField("log", "true");
descriptor.setField("logfile", file.getAbsolutePath());
log.info("file name: " + file.getAbsolutePath());
notificationInfo.setDescriptor(descriptor);
ModelMBeanInfoSupport beanInfoSupport = new ModelMBeanInfoSupport(
class1.getName(), "description", attributeInfos, null, null,
new ModelMBeanNotificationInfo[] { notificationInfo });
beanInfoSupport.getNotification(new SimpleNotification("src", 1)
.getType());
RequiredModelMBean requiredModelMBean = new RequiredModelMBean(
beanInfoSupport);
beanInfoSupport.getDescriptor(new SimpleNotification("src", 1)
.getType(), "notification");
requiredModelMBean.sendNotification(new SimpleNotification("src", 1));
assertTrue(file.length() > 0);
file.delete();
return result();
}
NotificationLoggingTest.java 文件源码
java
阅读 18
收藏 0
点赞 0
评论 0
项目:freeVM
作者:
评论列表
文章目录