You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ch...@apache.org on 2019/05/10 13:19:26 UTC
[flink] 03/04: [hotfix][tests] Remove forced step logging in
AutoClosableProcess
This is an automated email from the ASF dual-hosted git repository.
chesnay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
commit 3ad3fbf5f10be78db530fe70c6c29c2a45cd56c0
Author: zentol <ch...@apache.org>
AuthorDate: Thu Jan 24 15:02:16 2019 +0100
[hotfix][tests] Remove forced step logging in AutoClosableProcess
---
.../flink/tests/util/AutoClosableProcess.java | 46 +++++++++++-----------
.../apache/flink/tests/util/FlinkDistribution.java | 6 ++-
.../tests/PrometheusReporterEndToEndITCase.java | 13 +++---
3 files changed, 35 insertions(+), 30 deletions(-)
diff --git a/flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/AutoClosableProcess.java b/flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/AutoClosableProcess.java
index 0235930..fbeeb1d 100644
--- a/flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/AutoClosableProcess.java
+++ b/flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/AutoClosableProcess.java
@@ -20,9 +20,6 @@ package org.apache.flink.tests.util;
import org.apache.flink.util.Preconditions;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.IOException;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
@@ -33,8 +30,6 @@ import java.util.concurrent.TimeoutException;
*/
public class AutoClosableProcess implements AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(AutoClosableProcess.class);
-
private final Process process;
public AutoClosableProcess(final Process process) {
@@ -42,35 +37,40 @@ public class AutoClosableProcess implements AutoCloseable {
this.process = process;
}
- public static AutoClosableProcess runNonBlocking(String step, String... commands) throws IOException {
- LOG.info("Step Started: " + step);
- Process process = new ProcessBuilder()
- .command(commands)
- .inheritIO()
- .start();
- return new AutoClosableProcess(process);
+ public Process getProcess() {
+ return process;
+ }
+
+ public static AutoClosableProcess runNonBlocking(String... commands) throws IOException {
+ return runNonBlocking(commands);
}
- public static void runBlocking(String step, String... commands) throws IOException {
- runBlocking(step, Duration.ofSeconds(30), commands);
+ public static Process runBlocking(String... commands) throws IOException {
+ return runBlocking(Duration.ofSeconds(30), commands);
}
- public static void runBlocking(String step, Duration timeout, String... commands) throws IOException {
- LOG.info("Step started: " + step);
- Process process = new ProcessBuilder()
- .command(commands)
- .inheritIO()
- .start();
+ public static Process runBlocking(Duration timeout, String... commands) throws IOException {
+ final Process process = createProcess(commands);
try (AutoClosableProcess autoProcess = new AutoClosableProcess(process)) {
final boolean success = process.waitFor(timeout.toMillis(), TimeUnit.MILLISECONDS);
if (!success) {
- throw new TimeoutException();
+ throw new TimeoutException("Process exceeded timeout of " + timeout.getSeconds() + "seconds.");
+ }
+ if (process.exitValue() != 0) {
+ throw new RuntimeException("Process execution failed due error.");
}
} catch (TimeoutException | InterruptedException e) {
- throw new RuntimeException(step + " failed due to timeout.");
+ throw new RuntimeException("Process failed due to timeout.");
}
- LOG.info("Step complete: " + step);
+ return process;
+ }
+
+ private static Process createProcess(String... commands) throws IOException {
+ final ProcessBuilder processBuilder = new ProcessBuilder();
+ processBuilder.command(commands);
+ processBuilder.inheritIO();
+ return processBuilder.start();
}
@Override
diff --git a/flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/FlinkDistribution.java b/flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/FlinkDistribution.java
index 8c4a39c..5192bf2 100644
--- a/flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/FlinkDistribution.java
+++ b/flink-end-to-end-tests/flink-end-to-end-tests-common/src/main/java/org/apache/flink/tests/util/FlinkDistribution.java
@@ -125,7 +125,8 @@ public final class FlinkDistribution extends ExternalResource {
}
public void startFlinkCluster() throws IOException {
- AutoClosableProcess.runBlocking("Start Flink cluster", bin.resolve("start-cluster.sh").toAbsolutePath().toString());
+ LOG.info("Starting Flink cluster.");
+ AutoClosableProcess.runBlocking(bin.resolve("start-cluster.sh").toAbsolutePath().toString());
final OkHttpClient client = new OkHttpClient();
@@ -163,7 +164,8 @@ public final class FlinkDistribution extends ExternalResource {
}
public void stopFlinkCluster() throws IOException {
- AutoClosableProcess.runBlocking("Stop Flink Cluster", bin.resolve("stop-cluster.sh").toAbsolutePath().toString());
+ LOG.info("Stopping Flink cluster.");
+ AutoClosableProcess.runBlocking(bin.resolve("stop-cluster.sh").toAbsolutePath().toString());
}
public void copyOptJarsToLib(String jarNamePrefix) throws FileNotFoundException, IOException {
diff --git a/flink-end-to-end-tests/flink-metrics-reporter-prometheus-test/src/test/java/org/apache/flink/metrics/prometheus/tests/PrometheusReporterEndToEndITCase.java b/flink-end-to-end-tests/flink-metrics-reporter-prometheus-test/src/test/java/org/apache/flink/metrics/prometheus/tests/PrometheusReporterEndToEndITCase.java
index 269754e..5d189de 100644
--- a/flink-end-to-end-tests/flink-metrics-reporter-prometheus-test/src/test/java/org/apache/flink/metrics/prometheus/tests/PrometheusReporterEndToEndITCase.java
+++ b/flink-end-to-end-tests/flink-metrics-reporter-prometheus-test/src/test/java/org/apache/flink/metrics/prometheus/tests/PrometheusReporterEndToEndITCase.java
@@ -108,15 +108,16 @@ public class PrometheusReporterEndToEndITCase extends TestLogger {
final Path prometheusBinary = prometheusBinDir.resolve("prometheus");
Files.createDirectory(tmpPrometheusDir);
+ LOG.info("Downloading Prometheus.");
runBlocking(
- "Download of Prometheus",
Duration.ofMinutes(5),
CommandLineWrapper
.wget("https://github.com/prometheus/prometheus/releases/download/v" + PROMETHEUS_VERSION + '/' + prometheusArchive.getFileName())
.targetDir(tmpPrometheusDir)
.build());
- runBlocking("Extraction of Prometheus archive",
+ LOG.info("Unpacking Prometheus.");
+ runBlocking(
CommandLineWrapper
.tar(prometheusArchive)
.extract()
@@ -124,7 +125,8 @@ public class PrometheusReporterEndToEndITCase extends TestLogger {
.targetDir(tmpPrometheusDir)
.build());
- runBlocking("Set Prometheus scrape interval",
+ LOG.info("Setting Prometheus scrape interval.");
+ runBlocking(
CommandLineWrapper
.sed("s/\\(scrape_interval:\\).*/\\1 1s/", prometheusConfig)
.inPlace()
@@ -141,14 +143,15 @@ public class PrometheusReporterEndToEndITCase extends TestLogger {
.map(port -> "'localhost:" + port + "'")
.collect(Collectors.joining(", "));
- runBlocking("Set Prometheus scrape targets to (" + scrapeTargets + ")",
+ LOG.info("Setting Prometheus scrape targets to {}.", scrapeTargets);
+ runBlocking(
CommandLineWrapper
.sed("s/\\(targets:\\).*/\\1 [" + scrapeTargets + "]/", prometheusConfig)
.inPlace()
.build());
+ LOG.info("Starting Prometheus server.");
try (AutoClosableProcess prometheus = runNonBlocking(
- "Start Prometheus server",
prometheusBinary.toAbsolutePath().toString(),
"--config.file=" + prometheusConfig.toAbsolutePath(),
"--storage.tsdb.path=" + prometheusBinDir.resolve("data").toAbsolutePath())) {