flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [5/9] flink git commit: [FLINK-5817] [tests] Use TemporaryFold to create temp files and folds for test
Date Mon, 20 Feb 2017 11:07:01 GMT
[FLINK-5817] [tests] Use TemporaryFold to create temp files and folds for test


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

Branch: refs/heads/release-1.2
Commit: d1b148cf30ebd10815912bca2f2b94b2b56a2388
Parents: fee020c
Author: wenlong.lwl <wenlong.lwl@alibaba-inc.com>
Authored: Fri Feb 17 17:14:54 2017 +0800
Committer: Stephan Ewen <sewen@apache.org>
Committed: Mon Feb 20 02:07:54 2017 +0100

----------------------------------------------------------------------
 .../io/disk/iomanager/IOManagerTest.java        | 11 ++--
 .../flink/test/util/AbstractTestBase.java       | 53 ++++++--------------
 2 files changed, 22 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flink/blob/d1b148cf/flink-runtime/src/test/java/org/apache/flink/runtime/io/disk/iomanager/IOManagerTest.java
----------------------------------------------------------------------
diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/io/disk/iomanager/IOManagerTest.java
b/flink-runtime/src/test/java/org/apache/flink/runtime/io/disk/iomanager/IOManagerTest.java
index 39cb8ee..156098e 100644
--- a/flink-runtime/src/test/java/org/apache/flink/runtime/io/disk/iomanager/IOManagerTest.java
+++ b/flink-runtime/src/test/java/org/apache/flink/runtime/io/disk/iomanager/IOManagerTest.java
@@ -21,7 +21,9 @@ package org.apache.flink.runtime.io.disk.iomanager;
 import org.apache.flink.core.memory.MemorySegment;
 import org.apache.flink.runtime.io.disk.iomanager.FileIOChannel.ID;
 import org.apache.flink.runtime.io.network.buffer.Buffer;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 
 import java.io.File;
 import java.io.IOException;
@@ -34,12 +36,15 @@ import static org.junit.Assert.assertTrue;
 
 public class IOManagerTest {
 
+	@Rule
+	public final TemporaryFolder  temporaryFolder = new TemporaryFolder();
+
 	@Test
-	public void channelEnumerator() {
+	public void channelEnumerator() throws IOException {
 		IOManager ioMan = null;
 
 		try {
-			File tempPath = new File(System.getProperty("java.io.tmpdir"));
+			File tempPath = temporaryFolder.newFolder();
 
 			String[] tempDirs = new String[]{
 					new File(tempPath, "a").getAbsolutePath(),
@@ -126,4 +131,4 @@ public class IOManagerTest {
 			throw new UnsupportedOperationException();
 		}
 	}
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/flink/blob/d1b148cf/flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/AbstractTestBase.java
----------------------------------------------------------------------
diff --git a/flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/AbstractTestBase.java
b/flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/AbstractTestBase.java
index 316fd21..544d473 100644
--- a/flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/AbstractTestBase.java
+++ b/flink-test-utils-parent/flink-test-utils/src/main/java/org/apache/flink/test/util/AbstractTestBase.java
@@ -20,14 +20,17 @@ package org.apache.flink.test.util;
 
 import com.google.common.base.Charsets;
 import com.google.common.io.Files;
+
 import org.apache.flink.configuration.Configuration;
 import org.apache.flink.runtime.minicluster.LocalFlinkMiniCluster;
+
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
+
 import scala.concurrent.duration.FiniteDuration;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Objects;
 
 import org.apache.flink.runtime.akka.AkkaUtils;
@@ -39,22 +42,23 @@ public abstract class AbstractTestBase extends TestBaseUtils {
 	
 	/** Configuration to start the testing cluster with */
 	protected final Configuration config;
-	
-	private final List<File> tempFiles;
-	
+
 	private final FiniteDuration timeout;
 
 	protected int taskManagerNumSlots = 1;
 
 	protected int numTaskManagers = 1;
-	
+
+	@Rule
+	public final TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+
 	/** The mini cluster that runs the test programs */
 	protected LocalFlinkMiniCluster executor;
 	
 
 	public AbstractTestBase(Configuration config) {
 		this.config = Objects.requireNonNull(config);
-		this.tempFiles = new ArrayList<File>();
 
 		timeout = AkkaUtils.getTimeout(config);
 	}
@@ -74,7 +78,6 @@ public abstract class AbstractTestBase extends TestBaseUtils {
 
 	public void stopCluster() throws Exception {
 		stopCluster(executor, timeout);
-		deleteAllTempFiles();
 	}
 
 	//------------------
@@ -103,12 +106,12 @@ public abstract class AbstractTestBase extends TestBaseUtils {
 	// --------------------------------------------------------------------------------------------
 
 	public String getTempDirPath(String dirName) throws IOException {
-		File f = createAndRegisterTempFile(dirName);
+		File f = temporaryFolder.newFolder(dirName);
 		return f.toURI().toString();
 	}
 
 	public String getTempFilePath(String fileName) throws IOException {
-		File f = createAndRegisterTempFile(fileName);
+		File f = temporaryFolder.newFile(fileName);
 		return f.toURI().toString();
 	}
 
@@ -119,35 +122,7 @@ public abstract class AbstractTestBase extends TestBaseUtils {
 	}
 
 	public File createAndRegisterTempFile(String fileName) throws IOException {
-		File baseDir = new File(System.getProperty("java.io.tmpdir"));
-		File f = new File(baseDir, this.getClass().getName() + "-" + fileName);
-
-		if (f.exists()) {
-			deleteRecursively(f);
-		}
-
-		File parentToDelete = f;
-		while (true) {
-			File parent = parentToDelete.getParentFile();
-			if (parent == null) {
-				throw new IOException("Missed temp dir while traversing parents of a temp file.");
-			}
-			if (parent.equals(baseDir)) {
-				break;
-			}
-			parentToDelete = parent;
-		}
-
-		Files.createParentDirs(f);
-		this.tempFiles.add(parentToDelete);
-		return f;
+		return temporaryFolder.newFile(fileName);
 	}
 
-	private void deleteAllTempFiles() throws IOException {
-		for (File f : this.tempFiles) {
-			if (f.exists()) {
-				deleteRecursively(f);
-			}
-		}
-	}
 }


Mime
View raw message