From 2d33ec0d71c928d88bf936cf334da10f329077fd Mon Sep 17 00:00:00 2001 From: Colin Surprenant Date: Fri, 1 Sep 2017 12:59:19 -0400 Subject: [PATCH] use 6.0 versions of LsMetricsMonitorTest.java --- .../benchmark/cli/LsMetricsMonitorTest.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tools/benchmark-cli/src/test/java/org/logstash/benchmark/cli/LsMetricsMonitorTest.java b/tools/benchmark-cli/src/test/java/org/logstash/benchmark/cli/LsMetricsMonitorTest.java index 693c8899d0a..4af3ce4dd7b 100644 --- a/tools/benchmark-cli/src/test/java/org/logstash/benchmark/cli/LsMetricsMonitorTest.java +++ b/tools/benchmark-cli/src/test/java/org/logstash/benchmark/cli/LsMetricsMonitorTest.java @@ -2,14 +2,16 @@ import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.junit.WireMockRule; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.EnumMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import org.apache.commons.io.IOUtils; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; import org.junit.Rule; @@ -30,11 +32,7 @@ public final class LsMetricsMonitorTest { public void parsesFilteredCount() throws Exception { final String path = "/_node/stats/?pretty"; http.stubFor(WireMock.get(WireMock.urlEqualTo(path)).willReturn(WireMock.okJson( - new String( - Files.readAllBytes( - Paths.get(LsMetricsMonitorTest.class.getResource("metrics.json").getPath() - )) - , StandardCharsets.UTF_8) + metricsFixture() ))); final ExecutorService executor = Executors.newSingleThreadExecutor(); try { @@ -54,11 +52,7 @@ public void parsesFilteredCount() throws Exception { public void parsesCpuUsage() throws Exception { final String path = "/_node/stats/?pretty"; http.stubFor(WireMock.get(WireMock.urlEqualTo(path)).willReturn(WireMock.okJson( - new String( - Files.readAllBytes( - Paths.get(LsMetricsMonitorTest.class.getResource("metrics.json").getPath() - )) - , StandardCharsets.UTF_8) + metricsFixture() ))); final ExecutorService executor = Executors.newSingleThreadExecutor(); try { @@ -73,4 +67,13 @@ public void parsesCpuUsage() throws Exception { executor.shutdownNow(); } } + + private static String metricsFixture() throws IOException { + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (final InputStream input = LsMetricsMonitorTest.class + .getResourceAsStream("metrics.json")) { + IOUtils.copy(input, baos); + } + return baos.toString(StandardCharsets.UTF_8.name()); + } }