### Question:
JMXPollUtil { public static Map<String, Map<String, String>> getAllMBeans() { Map<String, Map<String, String>> mbeanMap = Maps.newHashMap(); Set<ObjectInstance> queryMBeans = null; try { queryMBeans = mbeanServer.queryMBeans(null, null); } catch (Exception ex) { LOG.error("Could not get Mbeans for monitoring", ex); Throwables.propagate(ex); } for (ObjectInstance obj : queryMBeans) { try { if (!obj.getObjectName().toString().startsWith("org.apache.flume")) { continue; } MBeanAttributeInfo[] attrs = mbeanServer. getMBeanInfo(obj.getObjectName()).getAttributes(); String strAtts[] = new String[attrs.length]; for (int i = 0; i < strAtts.length; i++) { strAtts[i] = attrs[i].getName(); } AttributeList attrList = mbeanServer.getAttributes( obj.getObjectName(), strAtts); String component = obj.getObjectName().toString().substring( obj.getObjectName().toString().indexOf('=') + 1); Map<String, String> attrMap = Maps.newHashMap(); for (Object attr : attrList) { Attribute localAttr = (Attribute) attr; if(localAttr.getName().equalsIgnoreCase("type")){ component = localAttr.getValue()+ "." + component; } attrMap.put(localAttr.getName(), localAttr.getValue().toString()); } mbeanMap.put(component, attrMap); } catch (Exception e) { LOG.error("Unable to poll JMX for metrics.", e); } } return mbeanMap; }  static Map<String, Map<String, String>> getAllMBeans();  }### Answer:
@Test public void testJMXPoll() { memChannel.setName("memChannel"); pmemChannel.setName("pmemChannel"); Context c = new Context(); Configurables.configure(memChannel, c); Configurables.configure(pmemChannel, c); memChannel.start(); pmemChannel.start(); Transaction txn = memChannel.getTransaction(); txn.begin(); memChannel.put(EventBuilder.withBody("blah".getBytes())); memChannel.put(EventBuilder.withBody("blah".getBytes())); txn.commit(); txn.close(); txn = memChannel.getTransaction(); txn.begin(); memChannel.take(); txn.commit(); txn.close(); Transaction txn2 = pmemChannel.getTransaction(); txn2.begin(); pmemChannel.put(EventBuilder.withBody("blah".getBytes())); pmemChannel.put(EventBuilder.withBody("blah".getBytes())); txn2.commit(); txn2.close(); txn2 = pmemChannel.getTransaction(); txn2.begin(); pmemChannel.take(); txn2.commit(); txn2.close(); Map<String, Map<String, String>> mbeans = JMXPollUtil.getAllMBeans(); Assert.assertNotNull(mbeans); Map<String, String> memBean = mbeans.get("CHANNEL.memChannel"); Assert.assertNotNull(memBean); JMXTestUtils.checkChannelCounterParams(memBean); Map<String, String> pmemBean = mbeans.get("CHANNEL.pmemChannel"); Assert.assertNotNull(pmemBean); JMXTestUtils.checkChannelCounterParams(pmemBean); memChannel.stop(); pmemChannel.stop(); }