objName = new ObjectName("org.apache.flume.source"
+ ":type=" + source.getName());
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
String strAtts[] = {"Type", "EventReceivedCount", "EventAcceptedCount"};
AttributeList attrList = mbeanServer.getAttributes(objName, strAtts);
Assert.assertNotNull(attrList.get(0));
Assert.assertEquals("Expected Value: Type", "Type",
((Attribute) attrList.get(0)).getName());
Assert.assertEquals("Expected Value: SOURCE", "SOURCE",
((Attribute) attrList.get(0)).getValue());
Assert.assertNotNull(attrList.get(1));
Assert.assertEquals("Expected Value: EventReceivedCount", "EventReceivedCount",
((Attribute) attrList.get(1)).getName());
Assert.assertEquals("Expected Value: 5", "5",
((Attribute) attrList.get(1)).getValue().toString());
Assert.assertNotNull(attrList.get(2));
Assert.assertEquals("Expected Value: EventAcceptedCount", "EventAcceptedCount",
((Attribute) attrList.get(2)).getName());
Assert.assertEquals("Expected Value: 5", "5",
((Attribute) attrList.get(2)).getValue().toString());
} catch (Exception ex) {
System.out.println("Unable to retreive the monitored counter: "
+ objName + ex.getMessage());
}