flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ches...@apache.org
Subject [10/12] flink git commit: [hotfix] [tests] minor test improvements in TaskManagerConfigurationTest
Date Mon, 31 Jul 2017 11:59:17 GMT
[hotfix] [tests] minor test improvements in TaskManagerConfigurationTest

* use a proper JUnit temporary folder that ensures uniqueness
* do not catch an exception just to fail with its message - if we let it throw,
we do get more information out of the failure
* also re-set the default file system scheme (a static member!) after finishing
the test

This closes #4401.


Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/d4b7ff35
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/d4b7ff35
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/d4b7ff35

Branch: refs/heads/master
Commit: d4b7ff35ddd2514945e83b84a597fa0654456516
Parents: 8bd537f
Author: Nico Kruber <nico@data-artisans.com>
Authored: Wed Jul 26 12:02:59 2017 +0200
Committer: zentol <chesnay@apache.org>
Committed: Mon Jul 31 12:12:09 2017 +0200

----------------------------------------------------------------------
 .../TaskManagerConfigurationTest.java           | 39 +++++++++++---------
 1 file changed, 21 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/d4b7ff35/flink-runtime/src/test/java/org/apache/flink/runtime/taskmanager/TaskManagerConfigurationTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/taskmanager/TaskManagerConfigurationTest.java
b/flink-runtime/src/test/java/org/apache/flink/runtime/taskmanager/TaskManagerConfigurationTest.java
index 96d1455..e73c684 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/taskmanager/TaskManagerConfigurationTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/taskmanager/TaskManagerConfigurationTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.flink.runtime.taskmanager;
 
+import net.jcip.annotations.NotThreadSafe;
 import org.apache.flink.configuration.ConfigConstants;
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.configuration.GlobalConfiguration;
@@ -25,12 +26,13 @@ import org.apache.flink.configuration.IllegalConfigurationException;
 import org.apache.flink.configuration.JobManagerOptions;
 import org.apache.flink.configuration.TaskManagerOptions;
 import org.apache.flink.core.fs.FileSystem;
-import org.apache.flink.core.testutils.CommonTestUtils;
 import org.apache.flink.runtime.concurrent.Executors;
 import org.apache.flink.runtime.highavailability.HighAvailabilityServices;
 import org.apache.flink.runtime.highavailability.HighAvailabilityServicesUtils;
+import org.junit.Rule;
 import org.junit.Test;
 
+import org.junit.rules.TemporaryFolder;
 import scala.Tuple2;
 
 import java.io.File;
@@ -39,16 +41,23 @@ import java.io.PrintWriter;
 import java.lang.reflect.Field;
 import java.net.*;
 import java.util.Iterator;
-import java.util.UUID;
 
 import static org.junit.Assert.*;
 
 /**
  * Validates that the TaskManager startup properly obeys the configuration
  * values.
+ *
+ * NOTE: at least {@link #testDefaultFsParameterLoading()} should not be run in parallel
to other
+ * tests in the same JVM as it modifies a static (private) member of the {@link FileSystem}
class
+ * and verifies its content.
  */
+@NotThreadSafe
 public class TaskManagerConfigurationTest {
 
+	@Rule
+	public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
 	@Test
 	public void testUsePreconfiguredNetworkInterface() throws Exception {
 		final String TEST_HOST_NAME = "testhostname";
@@ -141,18 +150,18 @@ public class TaskManagerConfigurationTest {
 	}
 
 	@Test
-	public void testDefaultFsParameterLoading() {
-		final File tmpDir = getTmpDir();
-		final File confFile =  new File(tmpDir, GlobalConfiguration.FLINK_CONF_FILENAME);
-
+	public void testDefaultFsParameterLoading() throws Exception {
 		try {
+			final File tmpDir = temporaryFolder.newFolder();
+			final File confFile = new File(tmpDir, GlobalConfiguration.FLINK_CONF_FILENAME);
+
 			final URI defaultFS = new URI("otherFS", null, "localhost", 1234, null, null, null);
 
 			final PrintWriter pw1 = new PrintWriter(confFile);
-			pw1.println("fs.default-scheme: "+ defaultFS);
+			pw1.println("fs.default-scheme: " + defaultFS);
 			pw1.close();
 
-			String[] args = new String[]{"--configDir:" + tmpDir};
+			String[] args = new String[] {"--configDir:" + tmpDir};
 			TaskManager.parseArgsAndLoadConfig(args);
 
 			Field f = FileSystem.class.getDeclaredField("defaultScheme");
@@ -160,11 +169,11 @@ public class TaskManagerConfigurationTest {
 			URI scheme = (URI) f.get(null);
 
 			assertEquals("Default Filesystem Scheme not configured.", scheme, defaultFS);
-		} catch (Exception e) {
-			fail(e.getMessage());
 		} finally {
-			confFile.delete();
-			tmpDir.delete();
+			// reset default FS scheme:
+			Field f = FileSystem.class.getDeclaredField("defaultScheme");
+			f.setAccessible(true);
+			f.set(null, null);
 		}
 	}
 
@@ -210,10 +219,4 @@ public class TaskManagerConfigurationTest {
 			}
 		}
 	}
-
-	private File getTmpDir() {
-		File tmpDir = new File(CommonTestUtils.getTempDir(), UUID.randomUUID().toString());
-		assertTrue("could not create temp directory", tmpDir.mkdirs());
-		return tmpDir;
-	}
 }


Mime
View raw message