[ https://issues.apache.org/jira/browse/FLINK-3951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15336178#comment-15336178 ]
ASF GitHub Bot commented on FLINK-3951: --------------------------------------- Github user zentol commented on a diff in the pull request: https://github.com/apache/flink/pull/2112#discussion_r67515825 --- Diff: flink-core/src/test/java/org/apache/flink/metrics/reporter/JMXReporterTest.java --- @@ -51,4 +69,106 @@ public void testGenerateName() { assertEquals("org.apache.flink.metrics:key0=value0,key1=value1,key2=value2_(test)------,name=TestMetric", jmxName); } + + /** + * Tests that histograms are properly reported via the JMXReporter. + */ + @Test + public void testHistogramReporting() throws MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, ReflectionException, AttributeNotFoundException, MBeanException { + MetricRegistry registry = null; + String histogramName = "histogram"; + + try { + Configuration config = new Configuration(); + + registry = new MetricRegistry(config); + + TaskManagerMetricGroup metricGroup = new TaskManagerMetricGroup(registry, "localhost", "tmId"); + + TestingHistogram histogram = new TestingHistogram(); + + registry.register(histogram, histogramName, metricGroup); + + MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); + + ObjectName objectName = new ObjectName(JMXReporter.generateJmxName(histogramName, metricGroup.getScopeComponents())); + + MBeanInfo info = mBeanServer.getMBeanInfo(objectName); + + MBeanAttributeInfo[] attributeInfos = info.getAttributes(); + + assertEquals(11, attributeInfos.length); + + for (MBeanAttributeInfo attributeInfo : attributeInfos) { + Object attribute = mBeanServer.getAttribute(objectName, attributeInfo.getName()); + + assertNotNull(attribute); + + if (attributeInfo.getType().equals("long")) { + assertEquals(42L, attribute); + } else if (attributeInfo.getType().equals("double")) { + assertEquals(42.0, attribute); + } else { + fail("Could not convert into type " + attributeInfo.getType()); + } + } + } finally { + if (registry != null) { + registry.shutdown(); + } + } + } + + static class TestingHistogram implements Histogram { + + @Override + public void update(long value) { + + } + + @Override + public long getCount() { + return 42; + } + + @Override + public HistogramStatistics getStatistics() { + return new HistogramStatistics() { + @Override + public double getValue(double quantile) { + return 42; + } + + @Override + public long[] getValues() { + return new long[0]; + } + + @Override + public int size() { + return 42; --- End diff -- every method should return a different value to make sure a certain value is not reporter as something else. > Add Histogram Metric Type > ------------------------- > > Key: FLINK-3951 > URL: https://issues.apache.org/jira/browse/FLINK-3951 > Project: Flink > Issue Type: Sub-task > Components: Core > Reporter: Stephan Ewen > Assignee: Till Rohrmann > Fix For: 1.1.0 > > -- This message was sent by Atlassian JIRA (v6.3.4#6332)