Skip to content

Commit

Permalink
use 6.0 versions of LsMetricsMonitorTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
colinsurprenant committed Sep 20, 2017
1 parent fd9b729 commit 2eff1fd
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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());
}
}

0 comments on commit 2eff1fd

Please sign in to comment.