@Test
public void testHistogramReporting() throws Exception {

	MetricRegistryImpl registry = null;
	String histogramName = "histogram";
	try {
		Configuration config = new Configuration();
		config.setString(MetricOptions.REPORTERS_LIST, "jmx_test");
		config.setString(ConfigConstants.METRICS_REPORTER_PREFIX + "jmx_test." + ConfigConstants.METRICS_REPORTER_CLASS_SUFFIX, JMXReporter.class.getName());
		registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(config));
		TaskManagerMetricGroup metricGroup = new TaskManagerMetricGroup(registry, "localhost", "tmId");
		TestingHistogram histogram = new TestingHistogram();
		metricGroup.histogram(histogramName, histogram);
		MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
		ObjectName objectName = new ObjectName(JMX_DOMAIN_PREFIX + "taskmanager." + histogramName, JMXReporter.generateJmxTable(metricGroup.getAllVariables()));
		MBeanInfo info = mBeanServer.getMBeanInfo(objectName);
		MBeanAttributeInfo[] attributeInfos = info.getAttributes();
		assertEquals(11, attributeInfos.length);
		assertEquals(histogram.getCount(), mBeanServer.getAttribute(objectName, "Count"));
		assertEquals(histogram.getStatistics().getMean(), mBeanServer.getAttribute(objectName, "Mean"));
		assertEquals(histogram.getStatistics().getStdDev(), mBeanServer.getAttribute(objectName, "StdDev"));
		assertEquals(histogram.getStatistics().getMax(), mBeanServer.getAttribute(objectName, "Max"));
		assertEquals(histogram.getStatistics().getMin(), mBeanServer.getAttribute(objectName, "Min"));
		assertEquals(histogram.getStatistics().getQuantile(0.5), mBeanServer.getAttribute(objectName, "Median"));
		assertEquals(histogram.getStatistics().getQuantile(0.75), mBeanServer.getAttribute(objectName, "75thPercentile"));
		assertEquals(histogram.getStatistics().getQuantile(0.95), mBeanServer.getAttribute(objectName, "95thPercentile"));
		assertEquals(histogram.getStatistics().getQuantile(0.98), mBeanServer.getAttribute(objectName, "98thPercentile"));
		assertEquals(histogram.getStatistics().getQuantile(0.99), mBeanServer.getAttribute(objectName, "99thPercentile"));
		assertEquals(histogram.getStatistics().getQuantile(0.999), mBeanServer.getAttribute(objectName, "999thPercentile"));
	} finally {
		if (registry != null) {
			registry.shutdown();
		}
	}
}