This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-metrics.git
commit 49825c09eef5242c9d6ffa3f65004c229a66af48 Author: Chetan Mehrotra <[email protected]> AuthorDate: Mon Aug 21 05:05:02 2017 +0000 SLING-7062 - Commons metrics inventory closes zip Instead of closing just flush the internal writer git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1805597 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/metrics/internal/JSONReporter.java | 2 +- .../internal/MetricWebConsolePluginTest.java | 39 +++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java index d501fb2..1b24b3e 100644 --- a/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java +++ b/src/main/java/org/apache/sling/commons/metrics/internal/JSONReporter.java @@ -155,7 +155,7 @@ class JSONReporter implements Reporter, Closeable { @Override public void close(){ - pw.close(); + pw.flush(); } private void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, diff --git a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java index 6b73d91..8f0c3ce 100644 --- a/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java +++ b/src/test/java/org/apache/sling/commons/metrics/internal/MetricWebConsolePluginTest.java @@ -21,6 +21,7 @@ package org.apache.sling.commons.metrics.internal; import java.io.PrintWriter; import java.io.StringWriter; +import java.io.Writer; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -37,6 +38,7 @@ import com.gargoylesoftware.htmlunit.html.HTMLParser; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlTable; import org.apache.felix.inventory.Format; +import org.apache.felix.utils.json.JSONParser; import org.apache.sling.testing.mock.osgi.MockOsgi; import org.apache.sling.testing.mock.osgi.junit.OsgiContext; import org.junit.Rule; @@ -49,6 +51,9 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; public class MetricWebConsolePluginTest { @@ -111,11 +116,30 @@ public class MetricWebConsolePluginTest { activatePlugin(); StringWriter sw = new StringWriter(); - plugin.print(new PrintWriter(sw), Format.TEXT, false); + PrintWriter pw = spy(new PrintWriter(sw)); + plugin.print(pw, Format.TEXT, false); String out = sw.toString(); assertThat(out, containsString("foo:test1")); assertThat(out, containsString("Meters")); + verify(pw, never()).close(); + } + + @Test + public void inventory_json() throws Exception{ + MetricRegistry reg1 = new MetricRegistry(); + reg1.meter("test1").mark(5); + context.registerService(MetricRegistry.class, reg1, regProps("foo")); + + activatePlugin(); + + StringWriter sw = new StringWriter(); + PrintWriter pw = spy(new PrintWriter(sw)); + plugin.print(pw, Format.JSON, false); + + Map<String, Object> json = new JSONParser(sw.toString()).getParsed(); + assertTrue(json.containsKey("meters")); + verify(pw, never()).close(); } @Test @@ -160,4 +184,17 @@ public class MetricWebConsolePluginTest { private void activatePlugin() { MockOsgi.activate(plugin, context.bundleContext(), Collections.<String, Object>emptyMap()); } + + private static class CloseRecordingWriter extends PrintWriter { + + + public CloseRecordingWriter(Writer out) { + super(out); + } + + @Override + public void close() { + super.close(); + } + } } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
