diff --git a/pom.xml b/pom.xml index c7fc99f..c53b2c1 100644 --- a/pom.xml +++ b/pom.xml @@ -103,7 +103,7 @@ com.google.guava guava - 30.1.1-jre + 31.1-jre compile @@ -115,13 +115,13 @@ com.fasterxml.jackson.core jackson-core - 2.13.1 + 2.13.4 compile com.fasterxml.jackson.core jackson-databind - 2.13.1 + 2.13.4 compile @@ -132,43 +132,43 @@ io.netty netty-all - 4.1.42.Final + 4.1.81.Final test junit junit - 4.13.1 + 4.13.2 test org.testcontainers testcontainers - 1.16.2 + 1.17.3 test io.rest-assured rest-assured - 4.3.1 + 5.2.0 test org.assertj assertj-core - 3.14.0 + 3.23.1 test org.apache.logging.log4j log4j-slf4j-impl - 2.17.2 + 2.18.0 org.apache.logging.log4j log4j-core - 2.17.1 + 2.18.0 com.jayway.awaitility diff --git a/src/test/java/io/logz/jmx2graphite/GraphiteITest.java b/src/test/java/io/logz/jmx2graphite/GraphiteITest.java index 6d9de02..86f664a 100644 --- a/src/test/java/io/logz/jmx2graphite/GraphiteITest.java +++ b/src/test/java/io/logz/jmx2graphite/GraphiteITest.java @@ -40,20 +40,20 @@ public class GraphiteITest { private static Stopwatch beforeClassStopwatch; public static final String TEST_SERVICE_HOST = "testhost"; public static final String TEST_SERVICE_NAME = "testservice"; - private static File tempDir; + @SuppressWarnings({"resource", "unchecked"}) @BeforeClass public static void beforeClass() throws IOException { beforeClassStopwatch = Stopwatch.createStarted(); - tempDir = createTempDir(); + File tempDir = createTempDir(); - graphiteContainer = new GenericContainer("sitespeedio/graphite:0.9.14").withExposedPorts(2003, 80) + graphiteContainer = new GenericContainer<>("sitespeedio/graphite:1.0.2-2").withExposedPorts(2003, 80) .withFileSystemBind(tempDir.getAbsolutePath(), "/var/log/carbon", BindMode.READ_WRITE) .withClasspathResourceMapping("carbon.conf", "/opt/graphite/conf/carbon.conf", BindMode.READ_ONLY) .withClasspathResourceMapping("blacklist.conf", "/opt/graphite/conf/blacklist.conf", BindMode.READ_ONLY) .withClasspathResourceMapping("storage-schemas.conf", "/opt/graphite/conf/storage-schemas.conf", BindMode.READ_ONLY) - .waitingFor(new HostPortWaitStrategy().withStartupTimeout(Duration.ofSeconds(10))) + .waitingFor(new HostPortWaitStrategy().withStartupTimeout(Duration.ofSeconds(30))) .withLogConsumer(new Slf4jLogConsumer(logger).withPrefix("graphite")); graphiteContainer.setPortBindings(Lists.newArrayList("2003:2003", "1180:80")); @@ -69,46 +69,46 @@ public static void afterClass() { } @Test - public void testResilienceToGraphiteRestart() { - GraphiteClient graphite = createGraphiteClient(); + public void testResilienceToGraphiteRestart() throws IOException { + try (GraphiteClient graphite = createGraphiteClient()) { + ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")).truncatedTo(MINUTES); + String metricName = "numOfLogz"; + float value = 100.0f; + graphite.sendMetrics(metricsListOf(metricName, value, now.toEpochSecond())); + assertThat(graphite.getFailedAtLastWrite()).isEqualTo(0); + + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String fullMetricPath = String.format("%s.%s.%s", TEST_SERVICE_NAME, TEST_SERVICE_HOST, metricName); + + await().atMost(10, TimeUnit.SECONDS).until(() -> { + String result = queryGraphiteAsCsv(fullMetricPath); + assertThat(result).contains(fullMetricPath + "," + dateTimeFormatter.format(now) + "," + value); + }); - ZonedDateTime now = ZonedDateTime.now(ZoneId.of("UTC")).truncatedTo(MINUTES); - String metricName = "numOfLogz"; - float value = 100.0f; - graphite.sendMetrics(metricsListOf(metricName, value, now.toEpochSecond())); - assertThat(graphite.getFailedAtLastWrite()).isEqualTo(0); - - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - String fullMetricPath = String.format("%s.%s.%s", TEST_SERVICE_NAME, TEST_SERVICE_HOST, metricName); - - await().atMost(10, TimeUnit.SECONDS).until(() -> { - String result = queryGraphiteAsCsv(fullMetricPath); - assertThat(result).contains(fullMetricPath + "," + dateTimeFormatter.format(now) + "," + value); - }); - - graphiteContainer.stop(); + graphiteContainer.stop(); - await().atMost(10, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS) - .until(() -> assertThatThrownBy( - () -> graphite.sendMetrics(metricsListOf(metricName, value, now.toEpochSecond()))) - .isInstanceOf(GraphiteClient.GraphiteWriteFailed.class) - .hasMessageContaining("Connection refused")); + await().atMost(10, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS) + .until(() -> assertThatThrownBy( + () -> graphite.sendMetrics(metricsListOf(metricName, value, now.toEpochSecond()))) + .isInstanceOf(GraphiteClient.GraphiteWriteFailed.class) + .hasMessageContaining("Connection refused")); - graphiteContainer.start(); + graphiteContainer.start(); - await().atMost(10, TimeUnit.SECONDS).ignoreExceptionsInstanceOf(ConnectException.class) - .until(() -> queryGraphiteAsCsv(fullMetricPath) != null); + await().atMost(10, TimeUnit.SECONDS).ignoreExceptionsInstanceOf(ConnectException.class) + .until(() -> queryGraphiteAsCsv(fullMetricPath) != null); - String metricName2 = "numOfLogz2"; + String metricName2 = "numOfLogz2"; - graphite.sendMetrics(metricsListOf(metricName2, value, now.toEpochSecond())); - assertThat(graphite.getFailedAtLastWrite()).isEqualTo(0); + graphite.sendMetrics(metricsListOf(metricName2, value, now.toEpochSecond())); + assertThat(graphite.getFailedAtLastWrite()).isEqualTo(0); - String fullMetricPath2 = String.format("%s.%s.%s", TEST_SERVICE_NAME, TEST_SERVICE_HOST, metricName2); - await().atMost(10, TimeUnit.SECONDS).until(() -> { - String result2 = queryGraphiteAsCsv(fullMetricPath2); - assertThat(result2).contains(fullMetricPath2 + "," + dateTimeFormatter.format(now) + "," + value); - }); + String fullMetricPath2 = String.format("%s.%s.%s", TEST_SERVICE_NAME, TEST_SERVICE_HOST, metricName2); + await().atMost(10, TimeUnit.SECONDS).until(() -> { + String result2 = queryGraphiteAsCsv(fullMetricPath2); + assertThat(result2).contains(fullMetricPath2 + "," + dateTimeFormatter.format(now) + "," + value); + }); + } } private String queryGraphiteAsCsv(String fullMetricPath) { @@ -132,7 +132,7 @@ private static List metricsListOf(String metricName, Number value, } private static File createTempDir() throws IOException { - final File tempFile = Files.createTempDirectory("mytest").toFile();; + final File tempFile = Files.createTempDirectory("mytest").toFile(); logger.info("Logging to {}", tempFile.getAbsolutePath()); return tempFile; }