hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject hadoop git commit: HADOOP-13380. TestBasicDiskValidator should not write data to /tmp (Yufei Gu via lei)
Date Mon, 08 Aug 2016 22:06:14 GMT
Repository: hadoop
Updated Branches:
  refs/heads/trunk 83a2ffec4 -> 6418edd6f


HADOOP-13380. TestBasicDiskValidator should not write data to /tmp (Yufei Gu via lei)


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

Branch: refs/heads/trunk
Commit: 6418edd6feeafc0204536e1860942eeb1cb1a9ce
Parents: 83a2ffe
Author: Lei Xu <lei@apache.org>
Authored: Mon Aug 8 15:04:11 2016 -0700
Committer: Lei Xu <lei@apache.org>
Committed: Mon Aug 8 15:06:03 2016 -0700

----------------------------------------------------------------------
 .../hadoop/util/TestBasicDiskValidator.java     |  8 +----
 .../org/apache/hadoop/util/TestDiskChecker.java | 35 +++++++++++++-------
 2 files changed, 24 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/6418edd6/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestBasicDiskValidator.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestBasicDiskValidator.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestBasicDiskValidator.java
index c961ee8..d6964a4 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestBasicDiskValidator.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestBasicDiskValidator.java
@@ -30,14 +30,8 @@ public class TestBasicDiskValidator extends TestDiskChecker {
   @Override
   protected void checkDirs(boolean isDir, String perm, boolean success)
       throws Throwable {
-    File localDir = File.createTempFile("test", "tmp");
+    File localDir = isDir ? createTempDir() : createTempFile();
     try {
-      if (isDir) {
-        // reuse the file path generated by File#createTempFile to create a dir
-        localDir.delete();
-        localDir.mkdir();
-      }
-
       Shell.execCommand(Shell.getSetPermissionCommand(perm, false,
           localDir.getAbsolutePath()));
 

http://git-wip-us.apache.org/repos/asf/hadoop/blob/6418edd6/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestDiskChecker.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestDiskChecker.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestDiskChecker.java
index b484940..0d55d7e 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestDiskChecker.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestDiskChecker.java
@@ -18,6 +18,7 @@
 package org.apache.hadoop.util;
 
 import java.io.*;
+import java.nio.file.Files;
 
 import org.junit.Test;
 import static org.junit.Assert.*;
@@ -25,7 +26,6 @@ import static org.junit.Assert.*;
 import static org.mockito.Mockito.*;
 
 import static org.apache.hadoop.test.MockitoMaker.*;
-import static org.apache.hadoop.fs.permission.FsAction.*;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -34,7 +34,6 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.permission.FsPermission;
 import org.apache.hadoop.test.GenericTestUtils;
 import org.apache.hadoop.util.DiskChecker.DiskErrorException;
-import org.apache.hadoop.util.Shell;
 
 public class TestDiskChecker {
   final FsPermission defaultPerm = new FsPermission("755");
@@ -112,13 +111,29 @@ public class TestDiskChecker {
     _checkDirs(true, new FsPermission("666"), false);   // not listable
   }
 
+  /**
+   * Create an empty file with a random name under test directory.
+   * @return the created file
+   * @throws java.io.IOException if any
+   */
+  protected File createTempFile() throws java.io.IOException {
+    File testDir = new File(System.getProperty("test.build.data"));
+    return Files.createTempFile(testDir.toPath(), "test", "tmp").toFile();
+  }
+
+  /**
+   * Create an empty directory with a random name under test directory.
+   * @return the created directory
+   * @throws java.io.IOException if any
+   */
+  protected File createTempDir() throws java.io.IOException {
+    File testDir = new File(System.getProperty("test.build.data"));
+    return Files.createTempDirectory(testDir.toPath(), "test").toFile();
+  }
+
   private void _checkDirs(boolean isDir, FsPermission perm, boolean success)
       throws Throwable {
-    File localDir = File.createTempFile("test", "tmp");
-    if (isDir) {
-      localDir.delete();
-      localDir.mkdir();
-    }
+    File localDir = isDir ? createTempDir() : createTempFile();
     Shell.execCommand(Shell.getSetPermissionCommand(String.format("%04o",
       perm.toShort()), false, localDir.getAbsolutePath()));
     try {
@@ -163,11 +178,7 @@ public class TestDiskChecker {
 
   protected void checkDirs(boolean isDir, String perm, boolean success)
       throws Throwable {
-    File localDir = File.createTempFile("test", "tmp");
-    if (isDir) {
-      localDir.delete();
-      localDir.mkdir();
-    }
+    File localDir = isDir ? createTempDir() : createTempFile();
     Shell.execCommand(Shell.getSetPermissionCommand(perm, false,
                                                     localDir.getAbsolutePath()));
     try {


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message