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:21:30 UTC

[flink] branch master updated (a810255 -> c4cb904)

This is an automated email from the ASF dual-hosted git repository.

chesnay pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git.


    from a810255  [hotfix][tests] Rework Process IO handling
     new c2ed44d  [hotfix][tests] Add modified ExternalResource class
     new c4cb904  [hotfix][tests] Backup logs for failed tests

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../flink-end-to-end-tests-common/pom.xml          |  6 +++
 .../apache/flink/tests/util/FlinkDistribution.java | 30 +++++++++--
 .../org/apache/flink/util/ExternalResource.java    | 61 ++++++++++++++++++++++
 3 files changed, 93 insertions(+), 4 deletions(-)
 create mode 100644 flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/util/ExternalResource.java


[flink] 01/02: [hotfix][tests] Add modified ExternalResource class

Posted by ch...@apache.org.
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 c2ed44d07b8ac70b548dfeb1a181be8909443b75
Author: zentol <ch...@apache.org>
AuthorDate: Tue Jan 29 13:19:33 2019 +0100

    [hotfix][tests] Add modified ExternalResource class
---
 .../org/apache/flink/util/ExternalResource.java    | 61 ++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/util/ExternalResource.java b/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/util/ExternalResource.java
new file mode 100644
index 0000000..c894e3b
--- /dev/null
+++ b/flink-test-utils-parent/flink-test-utils-junit/src/main/java/org/apache/flink/util/ExternalResource.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.util;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/**
+ * Modified version of the jUnit {@link org.junit.rules.ExternalResource}.
+ *
+ *<p>This version is an interface instead of an abstract class and allows resources to differentiate between successful
+ * and failed tests in their {@code After} methods.
+ */
+public interface ExternalResource extends TestRule {
+
+	void before() throws Exception;
+
+	void afterTestSuccess();
+
+	default void afterTestFailure() {
+		afterTestSuccess();
+	}
+
+	@Override
+	default Statement apply(final Statement base, final Description description) {
+		return new Statement() {
+			@Override
+			public void evaluate() throws Throwable {
+				before();
+				try {
+					base.evaluate();
+				} catch (final Throwable testThrowable) {
+					try {
+						afterTestFailure();
+					} catch (final Throwable afterFailureThrowable) {
+						testThrowable.addSuppressed(afterFailureThrowable);
+					}
+					throw testThrowable;
+				}
+				afterTestSuccess();
+			}
+		};
+	}
+}


[flink] 02/02: [hotfix][tests] Backup logs for failed tests

Posted by ch...@apache.org.
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 c4cb904c90e64bde945117048c5af4cb93e0dddf
Author: zentol <ch...@apache.org>
AuthorDate: Tue Jan 29 13:24:11 2019 +0100

    [hotfix][tests] Backup logs for failed tests
---
 .../flink-end-to-end-tests-common/pom.xml          |  6 +++++
 .../apache/flink/tests/util/FlinkDistribution.java | 30 +++++++++++++++++++---
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/flink-end-to-end-tests/flink-end-to-end-tests-common/pom.xml b/flink-end-to-end-tests/flink-end-to-end-tests-common/pom.xml
index c94400e..791f806 100644
--- a/flink-end-to-end-tests/flink-end-to-end-tests-common/pom.xml
+++ b/flink-end-to-end-tests/flink-end-to-end-tests-common/pom.xml
@@ -51,6 +51,12 @@ under the License.
 			<scope>compile</scope>
 		</dependency>
 		<dependency>
+			<groupId>org.apache.flink</groupId>
+			<artifactId>flink-test-utils-junit</artifactId>
+			<version>${project.version}</version>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
 			<!-- To ensure that flink-dist is built beforehand -->
 			<groupId>org.apache.flink</groupId>
 			<artifactId>flink-dist_${scala.binary.version}</artifactId>
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 5192bf2..8236f4b 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
@@ -22,6 +22,7 @@ import org.apache.flink.configuration.Configuration;
 import org.apache.flink.configuration.GlobalConfiguration;
 import org.apache.flink.configuration.UnmodifiableConfiguration;
 import org.apache.flink.util.ExceptionUtils;
+import org.apache.flink.util.ExternalResource;
 
 import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode;
 import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
@@ -29,8 +30,8 @@ import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMap
 import okhttp3.OkHttpClient;
 import okhttp3.Request;
 import okhttp3.Response;
+import org.apache.commons.io.FileUtils;
 import org.junit.Assert;
-import org.junit.rules.ExternalResource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -57,7 +58,7 @@ import java.util.stream.Stream;
 /**
  * A wrapper around a Flink distribution.
  */
-public final class FlinkDistribution extends ExternalResource {
+public final class FlinkDistribution implements ExternalResource {
 
 	private static final Logger LOG = LoggerFactory.getLogger(FlinkDistribution.class);
 
@@ -68,6 +69,8 @@ public final class FlinkDistribution extends ExternalResource {
 
 	private final List<AutoClosablePath> filesToDelete = new ArrayList<>(4);
 
+	private final Optional<Path> logBackupDir;
+
 	private final Path opt;
 	private final Path lib;
 	private final Path conf;
@@ -81,6 +84,10 @@ public final class FlinkDistribution extends ExternalResource {
 		if (distDirProperty == null) {
 			Assert.fail("The distDir property was not set. You can set it when running maven via -DdistDir=<path> .");
 		}
+		final String backupDirProperty = System.getProperty("logBackupDir");
+		logBackupDir = backupDirProperty == null
+			? Optional.empty()
+			: Optional.of(Paths.get(backupDirProperty));
 		final Path flinkDir = Paths.get(distDirProperty);
 		bin = flinkDir.resolve("bin");
 		opt = flinkDir.resolve("opt");
@@ -90,7 +97,7 @@ public final class FlinkDistribution extends ExternalResource {
 	}
 
 	@Override
-	protected void before() throws IOException {
+	public void before() throws IOException {
 		defaultConfig = new UnmodifiableConfiguration(GlobalConfiguration.loadConfiguration(conf.toAbsolutePath().toString()));
 		final Path originalConfig = conf.resolve(FLINK_CONF_YAML);
 		final Path backupConfig = conf.resolve(FLINK_CONF_YAML_BACKUP);
@@ -99,7 +106,7 @@ public final class FlinkDistribution extends ExternalResource {
 	}
 
 	@Override
-	protected void after() {
+	public void afterTestSuccess() {
 		try {
 			stopFlinkCluster();
 		} catch (IOException e) {
@@ -124,6 +131,21 @@ public final class FlinkDistribution extends ExternalResource {
 		}
 	}
 
+	@Override
+	public void afterTestFailure() {
+		logBackupDir.ifPresent(backupLocation -> {
+			LOG.info("Backing up logs to {}.", backupLocation);
+			try {
+				Files.createDirectories(backupLocation);
+				FileUtils.copyDirectory(log.toFile(), backupLocation.toFile());
+			} catch (IOException e) {
+				LOG.warn("An error occurred while backing up logs.", e);
+			}
+		});
+
+		afterTestSuccess();
+	}
+
 	public void startFlinkCluster() throws IOException {
 		LOG.info("Starting Flink cluster.");
 		AutoClosableProcess.runBlocking(bin.resolve("start-cluster.sh").toAbsolutePath().toString());