From 6ab1f545fb1a2fc64154484fc605e74fc2f34c6a Mon Sep 17 00:00:00 2001 From: Vinayakumar B Date: Thu, 16 Jun 2016 16:47:06 +0530 Subject: [PATCH] HDFS-10256. Use GenericTestUtils.getTestDir method in tests for temporary directories (Contributed by Vinayakumar B) (cherry picked from commit cc6c265171aace1e57653e777a4a73a747221086) --- .../java/org/apache/hadoop/fs/FileUtil.java | 14 ++++ .../apache/hadoop/fs/TestGetSpaceUsed.java | 5 +- .../shortcircuit/TestShortCircuitShm.java | 4 +- .../TestHttpFSFWithSWebhdfsFileSystem.java | 5 +- .../TestHttpFSFileSystemLocalFileSystem.java | 5 +- .../hdfs/nfs/nfs3/TestNfs3HttpServer.java | 5 +- .../apache/hadoop/cli/TestCryptoAdminCLI.java | 4 +- .../fs/TestEnhancedByteBufferAccess.java | 12 ++-- ...TestSWebHdfsFileContextMainOperations.java | 6 +- .../TestWebHdfsFileContextMainOperations.java | 7 +- .../apache/hadoop/hdfs/MiniDFSCluster.java | 17 +++-- .../hdfs/TestAppendSnapshotTruncate.java | 4 +- .../org/apache/hadoop/hdfs/TestDFSShell.java | 4 +- .../hadoop/hdfs/TestDFSUpgradeFromImage.java | 18 ++--- .../org/apache/hadoop/hdfs/TestDFSUtil.java | 3 +- .../hdfs/TestDatanodeLayoutUpgrade.java | 21 +++--- ...tDatanodeStartupFixesLegacyStorageIDs.java | 12 ++-- .../apache/hadoop/hdfs/TestFetchImage.java | 5 +- .../org/apache/hadoop/hdfs/TestPread.java | 2 +- .../org/apache/hadoop/hdfs/TestSeekBug.java | 3 +- .../sasl/SaslDataTransferTestCase.java | 5 +- .../hdfs/qjournal/TestSecureNNWithQJM.java | 5 +- .../server/datanode/TestDataNodeUUID.java | 3 +- .../hdfs/server/datanode/TestDataStorage.java | 3 +- .../server/namenode/TestCreateEditsLog.java | 6 +- .../namenode/TestDecommissioningStatus.java | 65 +++++-------------- .../namenode/TestEditLogFileInputStream.java | 3 +- .../namenode/TestFSImageWithSnapshot.java | 4 +- .../hadoop/hdfs/server/namenode/TestFsck.java | 11 ++-- .../namenode/TestNameNodeHttpServer.java | 5 +- .../server/namenode/TestNameNodeRecovery.java | 5 +- .../TestNameNodeRespectsBindHostKeys.java | 5 +- .../snapshot/TestRenameWithSnapshots.java | 2 +- .../namenode/snapshot/TestSnapshot.java | 4 +- .../apache/hadoop/hdfs/tools/TestGetConf.java | 62 ++++-------------- .../hadoop/hdfs/util/HostsFileWriter.java | 32 +++++++-- .../util/TestCombinedHostsFileReader.java | 5 +- .../hadoop/hdfs/web/TestHttpsFileSystem.java | 5 +- .../hadoop/hdfs/web/TestWebHdfsTokens.java | 9 +-- .../org/apache/hadoop/test/PathUtils.java | 7 +- 40 files changed, 186 insertions(+), 216 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java index 8ad2cc8eadc..aecf23b0bfa 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java @@ -99,6 +99,20 @@ public class FileUtil { return stat2Paths(stats); } + /** + * Register all files recursively to be deleted on exit. + * @param file File/directory to be deleted + */ + public static void fullyDeleteOnExit(final File file) { + file.deleteOnExit(); + if (file.isDirectory()) { + File[] files = file.listFiles(); + for (File child : files) { + fullyDeleteOnExit(child); + } + } + } + /** * Delete a directory and all its contents. If * we return false, the directory may be partially-deleted. diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGetSpaceUsed.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGetSpaceUsed.java index f436713ea66..d696dbfe40f 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGetSpaceUsed.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestGetSpaceUsed.java @@ -18,6 +18,7 @@ package org.apache.hadoop.fs; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -28,8 +29,8 @@ import java.io.IOException; import static org.junit.Assert.*; public class TestGetSpaceUsed { - final static private File DIR = new File( - System.getProperty("test.build.data", "/tmp"), "TestGetSpaceUsed"); + final static private File DIR = + GenericTestUtils.getTestDir("TestGetSpaceUsed"); @Before public void setUp() { diff --git a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/shortcircuit/TestShortCircuitShm.java b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/shortcircuit/TestShortCircuitShm.java index 9d484447984..0c202edac6d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/shortcircuit/TestShortCircuitShm.java +++ b/hadoop-hdfs-project/hadoop-hdfs-client/src/test/java/org/apache/hadoop/hdfs/shortcircuit/TestShortCircuitShm.java @@ -22,6 +22,7 @@ import org.apache.hadoop.hdfs.ExtendedBlockId; import org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.ShmId; import org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.Slot; import org.apache.hadoop.io.nativeio.SharedFileDescriptorFactory; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Assert; import org.junit.Assume; import org.junit.Before; @@ -38,8 +39,7 @@ public class TestShortCircuitShm { public static final Logger LOG = LoggerFactory.getLogger( TestShortCircuitShm.class); - private static final File TEST_BASE = - new File(System.getProperty("test.build.data", "/tmp")); + private static final File TEST_BASE = GenericTestUtils.getTestDir(); @Before public void before() { diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/TestHttpFSFWithSWebhdfsFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/TestHttpFSFWithSWebhdfsFileSystem.java index 9c3d7001038..d8f860a94dd 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/TestHttpFSFWithSWebhdfsFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/TestHttpFSFWithSWebhdfsFileSystem.java @@ -23,6 +23,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.hdfs.web.SWebHdfsFileSystem; import org.apache.hadoop.security.ssl.KeyStoreTestUtil; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.TestJettyHelper; import org.junit.AfterClass; import org.junit.runner.RunWith; @@ -37,8 +38,8 @@ import java.util.UUID; public class TestHttpFSFWithSWebhdfsFileSystem extends TestHttpFSWithHttpFSFileSystem { private static String classpathDir; - private static final String BASEDIR = System.getProperty("test.build.dir", - "target/test-dir") + "/" + UUID.randomUUID(); + private static final String BASEDIR = + GenericTestUtils.getTempPath(UUID.randomUUID().toString()); private static Configuration sslConf; diff --git a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/TestHttpFSFileSystemLocalFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/TestHttpFSFileSystemLocalFileSystem.java index e9a80e34658..83bcb2efacc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/TestHttpFSFileSystemLocalFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/test/java/org/apache/hadoop/fs/http/client/TestHttpFSFileSystemLocalFileSystem.java @@ -25,6 +25,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.TestDirHelper; import org.junit.Assert; import org.junit.runner.RunWith; @@ -41,9 +42,7 @@ public class TestHttpFSFileSystemLocalFileSystem extends BaseTestHttpFSWith { static { new TestDirHelper(); - String prefix = - System.getProperty("test.build.dir", "target/test-dir") + "/local"; - File file = new File(prefix); + File file = GenericTestUtils.getTestDir("local"); file.mkdirs(); PATH_PREFIX = file.getAbsolutePath(); } diff --git a/hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/nfs3/TestNfs3HttpServer.java b/hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/nfs3/TestNfs3HttpServer.java index 46dbd42f4c9..952aae2b584 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/nfs3/TestNfs3HttpServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs-nfs/src/test/java/org/apache/hadoop/hdfs/nfs/nfs3/TestNfs3HttpServer.java @@ -30,13 +30,14 @@ import org.apache.hadoop.hdfs.nfs.conf.NfsConfigKeys; import org.apache.hadoop.hdfs.nfs.conf.NfsConfiguration; import org.apache.hadoop.http.HttpConfig; import org.apache.hadoop.security.ssl.KeyStoreTestUtil; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; public class TestNfs3HttpServer { - private static final String BASEDIR = System.getProperty("test.build.dir", - "target/test-dir") + "/" + TestNfs3HttpServer.class.getSimpleName(); + private static final String BASEDIR = + GenericTestUtils.getTempPath(TestNfs3HttpServer.class.getSimpleName()); private static NfsConfiguration conf = new NfsConfiguration(); private static MiniDFSCluster cluster; private static String keystoresDir; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestCryptoAdminCLI.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestCryptoAdminCLI.java index bd5349d82d6..7c6aaeb9edc 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestCryptoAdminCLI.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/cli/TestCryptoAdminCLI.java @@ -44,6 +44,7 @@ import org.apache.hadoop.hdfs.HDFSPolicyProvider; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.tools.CryptoAdmin; import org.apache.hadoop.security.authorize.PolicyProvider; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -63,8 +64,7 @@ public class TestCryptoAdminCLI extends CLITestHelperDFS { HDFSPolicyProvider.class, PolicyProvider.class); conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, 1); - tmpDir = new File(System.getProperty("test.build.data", "target"), - UUID.randomUUID().toString()).getAbsoluteFile(); + tmpDir = GenericTestUtils.getTestDir(UUID.randomUUID().toString()); final Path jksPath = new Path(tmpDir.toString(), "test.jks"); conf.set(DFSConfigKeys.DFS_ENCRYPTION_KEY_PROVIDER_URI, JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri()); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestEnhancedByteBufferAccess.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestEnhancedByteBufferAccess.java index 32a34e8a685..0ccc07a833d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestEnhancedByteBufferAccess.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestEnhancedByteBufferAccess.java @@ -557,27 +557,25 @@ public class TestEnhancedByteBufferAccess { */ @Test public void testIndirectFallbackReads() throws Exception { - final File TEST_DIR = new File( - System.getProperty("test.build.data","build/test/data")); - final String TEST_PATH = TEST_DIR + File.separator + - "indirectFallbackTestFile"; + final String testPath = GenericTestUtils + .getTestDir("indirectFallbackTestFile").getAbsolutePath(); final int TEST_FILE_LENGTH = 16385; final int RANDOM_SEED = 23453; FileOutputStream fos = null; FileInputStream fis = null; try { - fos = new FileOutputStream(TEST_PATH); + fos = new FileOutputStream(testPath); Random random = new Random(RANDOM_SEED); byte original[] = new byte[TEST_FILE_LENGTH]; random.nextBytes(original); fos.write(original); fos.close(); fos = null; - fis = new FileInputStream(TEST_PATH); + fis = new FileInputStream(testPath); testFallbackImpl(fis, original); } finally { IOUtils.cleanup(LOG, fos, fis); - new File(TEST_PATH).delete(); + new File(testPath).delete(); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSWebHdfsFileContextMainOperations.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSWebHdfsFileContextMainOperations.java index 02110ac7031..84bd98bf67c 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSWebHdfsFileContextMainOperations.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestSWebHdfsFileContextMainOperations.java @@ -24,6 +24,7 @@ import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.ssl.KeyStoreTestUtil; import org.apache.hadoop.security.ssl.SSLFactory; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -50,9 +51,8 @@ public class TestSWebHdfsFileContextMainOperations private static final HdfsConfiguration CONF = new HdfsConfiguration(); - private static final String BASEDIR = - System.getProperty("test.build.dir", "target/test-dir") + "/" - + TestSWebHdfsFileContextMainOperations.class.getSimpleName(); + private static final String BASEDIR = GenericTestUtils + .getTempPath(TestSWebHdfsFileContextMainOperations.class.getSimpleName()); protected static int numBlocks = 2; protected static final byte[] data = getFileData(numBlocks, getDefaultBlockSize()); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestWebHdfsFileContextMainOperations.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestWebHdfsFileContextMainOperations.java index ec91cd16679..72fc6e6274b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestWebHdfsFileContextMainOperations.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/fs/TestWebHdfsFileContextMainOperations.java @@ -23,6 +23,7 @@ import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -63,7 +64,7 @@ public class TestWebHdfsFileContextMainOperations @Override protected FileContextTestHelper createFileContextHelper() { - return new FileContextTestHelper("/tmp/TestWebHdfsFileContextMainOperations"); + return new FileContextTestHelper(); } public URI getWebhdfsUrl() { @@ -88,8 +89,8 @@ public class TestWebHdfsFileContextMainOperations public void setUp() throws Exception { URI webhdfsUrlReal = getWebhdfsUrl(); Path testBuildData = new Path( - webhdfsUrlReal + "/build/test/data/" + RandomStringUtils - .randomAlphanumeric(10)); + webhdfsUrlReal + "/" + GenericTestUtils.DEFAULT_TEST_DATA_PATH + + RandomStringUtils.randomAlphanumeric(10)); Path rootPath = new Path(testBuildData, "root-uri"); localFsRootPath = rootPath.makeQualified(webhdfsUrlReal, null); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java index bec0af8addc..8215b70b250 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/MiniDFSCluster.java @@ -102,7 +102,6 @@ import org.apache.hadoop.hdfs.server.datanode.SecureDataNodeStarter.SecureResour import org.apache.hadoop.hdfs.server.datanode.SimulatedFSDataset; import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsDatasetSpi; import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeSpi; -import org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsDatasetUtil; import org.apache.hadoop.hdfs.server.datanode.fsdataset.impl.FsVolumeImpl; import org.apache.hadoop.hdfs.server.namenode.EditLogFileOutputStream; import org.apache.hadoop.hdfs.server.namenode.FSNamesystem; @@ -142,7 +141,8 @@ public class MiniDFSCluster { private static final String NAMESERVICE_ID_PREFIX = "nameserviceId"; private static final Log LOG = LogFactory.getLog(MiniDFSCluster.class); /** System property to set the data dir: {@value} */ - public static final String PROP_TEST_BUILD_DATA = "test.build.data"; + public static final String PROP_TEST_BUILD_DATA = + GenericTestUtils.SYSPROP_TEST_DATA_DIR; /** Configuration option to set the data dir: {@value} */ public static final String HDFS_MINIDFS_BASEDIR = "hdfs.minidfs.basedir"; public static final String DFS_NAMENODE_SAFEMODE_EXTENSION_TESTING_KEY @@ -1828,12 +1828,11 @@ public class MiniDFSCluster { ShutdownHookManager.get().clearShutdownHooks(); if (base_dir != null) { if (deleteDfsDir) { - base_dir.delete(); + FileUtil.fullyDelete(base_dir); } else { - base_dir.deleteOnExit(); + FileUtil.fullyDeleteOnExit(base_dir); } } - } /** @@ -2650,13 +2649,13 @@ public class MiniDFSCluster { /** * Get the base directory for any DFS cluster whose configuration does - * not explicitly set it. This is done by retrieving the system property - * {@link #PROP_TEST_BUILD_DATA} (defaulting to "build/test/data" ), - * and returning that directory with a subdir of /dfs. + * not explicitly set it. This is done via + * {@link GenericTestUtils#getTestDir()}. * @return a directory for use as a miniDFS filesystem. */ public static String getBaseDirectory() { - return System.getProperty(PROP_TEST_BUILD_DATA, "build/test/data") + "/dfs/"; + return GenericTestUtils.getTestDir("dfs").getAbsolutePath() + + File.separator; } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestAppendSnapshotTruncate.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestAppendSnapshotTruncate.java index a1169c3cfda..e73da2904c5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestAppendSnapshotTruncate.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestAppendSnapshotTruncate.java @@ -115,9 +115,7 @@ public class TestAppendSnapshotTruncate { dfs.mkdirs(dir); dfs.allowSnapshot(dir); - final File localDir = new File( - System.getProperty("test.build.data", "target/test/data") - + dirPathString); + final File localDir = GenericTestUtils.getTestDir(dirPathString); if (localDir.exists()) { FileUtil.fullyDelete(localDir); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java index 77b04c332e1..f97d28466a9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSShell.java @@ -3152,8 +3152,8 @@ public class TestDFSShell { assertTrue(e.getMessage().contains("Invalid path name /.reserved")); } - final String testdir = System.getProperty("test.build.data") - + "/TestDFSShell-testCopyReserved"; + final String testdir = GenericTestUtils.getTempPath( + "TestDFSShell-testCopyReserved"); final Path hdfsTestDir = new Path(testdir); writeFile(fs, new Path(testdir, "testFileForPut")); final Path src = new Path(hdfsTestDir, "srcfile"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUpgradeFromImage.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUpgradeFromImage.java index c7d25c0d5a6..4ae24a6802e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUpgradeFromImage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUpgradeFromImage.java @@ -89,8 +89,10 @@ public class TestDFSUpgradeFromImage { static { upgradeConf = new HdfsConfiguration(); upgradeConf.setInt(DFSConfigKeys.DFS_DATANODE_SCAN_PERIOD_HOURS_KEY, -1); // block scanning off - if (System.getProperty("test.build.data") == null) { // to allow test to be run outside of Maven - System.setProperty("test.build.data", "build/test/data"); + if (System.getProperty(GenericTestUtils.SYSPROP_TEST_DATA_DIR) == null) { + // to allow test to be run outside of Maven + System.setProperty(GenericTestUtils.SYSPROP_TEST_DATA_DIR, + GenericTestUtils.DEFAULT_TEST_DATA_DIR); } } @@ -105,19 +107,19 @@ public class TestDFSUpgradeFromImage { void unpackStorage(String tarFileName, String referenceName) throws IOException { - String tarFile = System.getProperty("test.cache.data", "build/test/cache") + String tarFile = System.getProperty("test.cache.data", "target/test/cache") + "/" + tarFileName; - String dataDir = System.getProperty("test.build.data", "build/test/data"); + File dataDir = GenericTestUtils.getTestDir(); File dfsDir = new File(dataDir, "dfs"); if ( dfsDir.exists() && !FileUtil.fullyDelete(dfsDir) ) { throw new IOException("Could not delete dfs directory '" + dfsDir + "'"); } LOG.info("Unpacking " + tarFile); - FileUtil.unTar(new File(tarFile), new File(dataDir)); + FileUtil.unTar(new File(tarFile), dataDir); //Now read the reference info BufferedReader reader = new BufferedReader(new FileReader( - System.getProperty("test.cache.data", "build/test/cache") + System.getProperty("test.cache.data", "target/test/cache") + "/" + referenceName)); String line; while ( (line = reader.readLine()) != null ) { @@ -631,10 +633,10 @@ public class TestDFSUpgradeFromImage { unpackStorage(HADOOP1_BBW_IMAGE, HADOOP_DFS_DIR_TXT); Configuration conf = new Configuration(upgradeConf); conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, - System.getProperty("test.build.data") + File.separator + + GenericTestUtils.getTempPath( "dfs" + File.separator + "data" + File.separator + - "data1"); + "data1")); upgradeAndVerify(new MiniDFSCluster.Builder(conf). numDataNodes(1).enableManagedDfsDirsRedundancy(false). manageDataDfsDirs(false), null); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java index 62bbca73892..78344a3301e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDFSUtil.java @@ -874,8 +874,7 @@ public class TestDFSUtil { @Test public void testGetPassword() throws Exception { - File testDir = new File(System.getProperty("test.build.data", - "target/test-dir")); + File testDir = GenericTestUtils.getTestDir(); Configuration conf = new Configuration(); final Path jksPath = new Path(testDir.toString(), "test.jks"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDatanodeLayoutUpgrade.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDatanodeLayoutUpgrade.java index 6b60b2bcb9e..0e2f4e4ee09 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDatanodeLayoutUpgrade.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDatanodeLayoutUpgrade.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hdfs; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Test; import java.io.File; @@ -42,11 +43,11 @@ public class TestDatanodeLayoutUpgrade { TestDFSUpgradeFromImage upgrade = new TestDFSUpgradeFromImage(); upgrade.unpackStorage(HADOOP24_DATANODE, HADOOP_DATANODE_DIR_TXT); Configuration conf = new Configuration(TestDFSUpgradeFromImage.upgradeConf); - conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, - new File(System.getProperty("test.build.data"), + conf.set( + DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, GenericTestUtils.getTestDir( "dfs" + File.separator + "data").toURI().toString()); - conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, - new File(System.getProperty("test.build.data"), + conf.set( + DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, GenericTestUtils.getTestDir( "dfs" + File.separator + "name").toURI().toString()); upgrade.upgradeAndVerify(new MiniDFSCluster.Builder(conf).numDataNodes(1) .manageDataDfsDirs(false).manageNameDfsDirs(false), null); @@ -61,12 +62,12 @@ public class TestDatanodeLayoutUpgrade { TestDFSUpgradeFromImage upgrade = new TestDFSUpgradeFromImage(); upgrade.unpackStorage(HADOOP_56_DN_LAYOUT, HADOOP_56_DN_LAYOUT_TXT); Configuration conf = new Configuration(TestDFSUpgradeFromImage.upgradeConf); - conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, - new File(System.getProperty("test.build.data"), "dfs" + File.separator - + "data").toURI().toString()); - conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, - new File(System.getProperty("test.build.data"), "dfs" + File.separator - + "name").toURI().toString()); + conf.set( + DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, GenericTestUtils.getTestDir( + "dfs" + File.separator + "data").toURI().toString()); + conf.set( + DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, GenericTestUtils.getTestDir( + "dfs" + File.separator + "name").toURI().toString()); upgrade.upgradeAndVerify(new MiniDFSCluster.Builder(conf).numDataNodes(1) .manageDataDfsDirs(false).manageNameDfsDirs(false), null); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDatanodeStartupFixesLegacyStorageIDs.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDatanodeStartupFixesLegacyStorageIDs.java index e262abcb6a8..659a8c162b1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDatanodeStartupFixesLegacyStorageIDs.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestDatanodeStartupFixesLegacyStorageIDs.java @@ -87,12 +87,12 @@ public class TestDatanodeStartupFixesLegacyStorageIDs { private static void initStorageDirs(final Configuration conf, final String testName) { - conf.set(DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, - System.getProperty("test.build.data") + File.separator + - testName + File.separator + "dfs" + File.separator + "data"); - conf.set(DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, - System.getProperty("test.build.data") + File.separator + - testName + File.separator + "dfs" + File.separator + "name"); + conf.set( + DFSConfigKeys.DFS_DATANODE_DATA_DIR_KEY, GenericTestUtils.getTempPath( + testName + File.separator + "dfs" + File.separator + "data")); + conf.set( + DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY, GenericTestUtils.getTempPath( + testName + File.separator + "dfs" + File.separator + "name")); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFetchImage.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFetchImage.java index 0d4435779aa..51034c8a825 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFetchImage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestFetchImage.java @@ -32,13 +32,14 @@ import org.apache.hadoop.hdfs.protocol.HdfsConstants.SafeModeAction; import org.apache.hadoop.hdfs.tools.DFSAdmin; import org.apache.hadoop.hdfs.util.MD5FileUtils; import org.apache.hadoop.io.MD5Hash; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.Test; public class TestFetchImage { - private static final File FETCHED_IMAGE_FILE = new File( - System.getProperty("test.build.dir"), "target/fetched-image-dir"); + private static final File FETCHED_IMAGE_FILE = + GenericTestUtils.getTestDir("target/fetched-image-dir"); // Shamelessly stolen from NNStorage. private static final Pattern IMAGE_REGEX = Pattern.compile("fsimage_(\\d+)"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestPread.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestPread.java index cc0fb926c3b..c69f06095c0 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestPread.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestPread.java @@ -485,7 +485,7 @@ public class TestPread { Configuration conf = new HdfsConfiguration(); FileSystem fileSys = FileSystem.getLocal(conf); try { - Path file1 = new Path("build/test/data", "preadtest.dat"); + Path file1 = new Path(GenericTestUtils.getTempPath("preadtest.dat")); writeFile(fileSys, file1); pReadFile(fileSys, file1); cleanupFile(fileSys, file1); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSeekBug.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSeekBug.java index 31365dbfe2d..804cf046d5d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSeekBug.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestSeekBug.java @@ -30,6 +30,7 @@ import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IOUtils; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Test; /** @@ -208,7 +209,7 @@ public class TestSeekBug { Configuration conf = new HdfsConfiguration(); FileSystem fileSys = FileSystem.getLocal(conf); try { - Path file1 = new Path("build/test/data", "seektest.dat"); + Path file1 = new Path(GenericTestUtils.getTempPath("seektest.dat")); writeFile(fileSys, file1); seekReadFile(fileSys, file1); cleanupFile(fileSys, file1); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/datatransfer/sasl/SaslDataTransferTestCase.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/datatransfer/sasl/SaslDataTransferTestCase.java index 37b2a2c0606..4eade6ad5e6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/datatransfer/sasl/SaslDataTransferTestCase.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/datatransfer/sasl/SaslDataTransferTestCase.java @@ -43,6 +43,7 @@ import org.apache.hadoop.minikdc.MiniKdc; import org.apache.hadoop.security.SecurityUtil; import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod; import org.apache.hadoop.security.ssl.KeyStoreTestUtil; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -74,8 +75,8 @@ public abstract class SaslDataTransferTestCase { @BeforeClass public static void initKdc() throws Exception { - baseDir = new File(System.getProperty("test.build.dir", "target/test-dir"), - SaslDataTransferTestCase.class.getSimpleName()); + baseDir = GenericTestUtils + .getTestDir(SaslDataTransferTestCase.class.getSimpleName()); FileUtil.fullyDelete(baseDir); assertTrue(baseDir.mkdirs()); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/TestSecureNNWithQJM.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/TestSecureNNWithQJM.java index 197759edf58..9abfb9cfbad 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/TestSecureNNWithQJM.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/qjournal/TestSecureNNWithQJM.java @@ -55,6 +55,7 @@ import org.apache.hadoop.security.SecurityUtil; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod; import org.apache.hadoop.security.ssl.KeyStoreTestUtil; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -82,8 +83,8 @@ public class TestSecureNNWithQJM { @BeforeClass public static void init() throws Exception { - baseDir = new File(System.getProperty("test.build.dir", "target/test-dir"), - TestSecureNNWithQJM.class.getSimpleName()); + baseDir = + GenericTestUtils.getTestDir(TestSecureNNWithQJM.class.getSimpleName()); FileUtil.fullyDelete(baseDir); assertTrue(baseDir.mkdirs()); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeUUID.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeUUID.java index ebf7c35841e..0d40fc72af5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeUUID.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataNodeUUID.java @@ -25,6 +25,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.MiniDFSCluster; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Test; import java.io.File; @@ -69,7 +70,7 @@ public class TestDataNodeUUID { @Test(timeout = 10000) public void testUUIDRegeneration() throws Exception { - File baseDir = new File(System.getProperty("test.build.data")); + File baseDir = GenericTestUtils.getTestDir(); File disk1 = new File(baseDir, "disk1"); File disk2 = new File(baseDir, "disk2"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataStorage.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataStorage.java index 405d2e967ff..446a77b2552 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataStorage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/TestDataStorage.java @@ -47,8 +47,7 @@ public class TestDataStorage { private final static String BUILD_VERSION = "2.0"; private final static String SOFTWARE_VERSION = "2.0"; private final static long CTIME = 1; - private final static File TEST_DIR = - new File(System.getProperty("test.build.data") + "/dstest"); + private final static File TEST_DIR = GenericTestUtils.getTestDir("dstest"); private final static StartupOption START_OPT = StartupOption.REGULAR; private DataNode mockDN = Mockito.mock(DataNode.class); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCreateEditsLog.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCreateEditsLog.java index 67e5e330da8..d3527f5ce3b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCreateEditsLog.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestCreateEditsLog.java @@ -22,6 +22,7 @@ import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_NAME_DIR_KEY; import java.io.File; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -42,9 +43,8 @@ public class TestCreateEditsLog { private static final File HDFS_DIR = new File( MiniDFSCluster.getBaseDirectory()).getAbsoluteFile(); - private static final File TEST_DIR = new File( - System.getProperty("test.build.data", "build/test/data"), - "TestCreateEditsLog").getAbsoluteFile(); + private static final File TEST_DIR = + GenericTestUtils.getTestDir("TestCreateEditsLog"); private MiniDFSCluster cluster; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDecommissioningStatus.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDecommissioningStatus.java index 02b5ebbdd62..dd8968790cf 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDecommissioningStatus.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestDecommissioningStatus.java @@ -25,7 +25,6 @@ import java.io.PrintStream; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; import java.util.List; import java.util.Random; @@ -55,6 +54,7 @@ import org.apache.hadoop.hdfs.server.blockmanagement.DecommissionManager; import org.apache.hadoop.hdfs.server.datanode.DataNode; import org.apache.hadoop.hdfs.server.datanode.DataNodeTestUtils; import org.apache.hadoop.hdfs.tools.DFSAdmin; +import org.apache.hadoop.hdfs.util.HostsFileWriter; import org.apache.log4j.Level; import org.apache.log4j.Logger; import org.junit.After; @@ -71,10 +71,8 @@ public class TestDecommissioningStatus { private static final int numDatanodes = 2; private static MiniDFSCluster cluster; private static FileSystem fileSys; - private static Path excludeFile; - private static FileSystem localFileSys; + private static HostsFileWriter hostsFileWriter; private static Configuration conf; - private static Path dir; final ArrayList decommissionedNodes = new ArrayList(numDatanodes); @@ -85,14 +83,8 @@ public class TestDecommissioningStatus { false); // Set up the hosts/exclude files. - localFileSys = FileSystem.getLocal(conf); - Path workingDir = localFileSys.getWorkingDirectory(); - dir = new Path(workingDir, "build/test/data/work-dir/decommission"); - assertTrue(localFileSys.mkdirs(dir)); - excludeFile = new Path(dir, "exclude"); - conf.set(DFSConfigKeys.DFS_HOSTS_EXCLUDE, excludeFile.toUri().getPath()); - Path includeFile = new Path(dir, "include"); - conf.set(DFSConfigKeys.DFS_HOSTS, includeFile.toUri().getPath()); + hostsFileWriter = new HostsFileWriter(); + hostsFileWriter.initialize(conf, "work-dir/decommission"); conf.setInt(DFSConfigKeys.DFS_NAMENODE_HEARTBEAT_RECHECK_INTERVAL_KEY, 1000); conf.setInt(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, 1); @@ -102,9 +94,6 @@ public class TestDecommissioningStatus { conf.setInt(DFSConfigKeys.DFS_NAMENODE_DECOMMISSION_INTERVAL_KEY, 1); conf.setLong(DFSConfigKeys.DFS_DATANODE_BALANCE_BANDWIDTHPERSEC_KEY, 1); - writeConfigFile(localFileSys, excludeFile, null); - writeConfigFile(localFileSys, includeFile, null); - cluster = new MiniDFSCluster.Builder(conf).numDataNodes(numDatanodes).build(); cluster.waitActive(); fileSys = cluster.getFileSystem(); @@ -115,31 +104,13 @@ public class TestDecommissioningStatus { @After public void tearDown() throws Exception { - if (localFileSys != null ) cleanupFile(localFileSys, dir); + if (hostsFileWriter != null) { + hostsFileWriter.cleanup(); + } if(fileSys != null) fileSys.close(); if(cluster != null) cluster.shutdown(); } - private static void writeConfigFile(FileSystem fs, Path name, - ArrayList nodes) throws IOException { - - // delete if it already exists - if (fs.exists(name)) { - fs.delete(name, true); - } - - FSDataOutputStream stm = fs.create(name); - - if (nodes != null) { - for (Iterator it = nodes.iterator(); it.hasNext();) { - String node = it.next(); - stm.writeBytes(node); - stm.writeBytes("\n"); - } - } - stm.close(); - } - private void writeFile(FileSystem fileSys, Path name, short repl) throws IOException { // create and write a file that contains three blocks of data @@ -182,25 +153,25 @@ public class TestDecommissioningStatus { * Decommissions the node at the given index */ private String decommissionNode(FSNamesystem namesystem, DFSClient client, - FileSystem localFileSys, int nodeIndex) throws IOException { + int nodeIndex) throws IOException { DatanodeInfo[] info = client.datanodeReport(DatanodeReportType.LIVE); String nodename = info[nodeIndex].getXferAddr(); - decommissionNode(namesystem, localFileSys, nodename); + decommissionNode(namesystem, nodename); return nodename; } /* * Decommissions the node by name */ - private void decommissionNode(FSNamesystem namesystem, - FileSystem localFileSys, String dnName) throws IOException { + private void decommissionNode(FSNamesystem namesystem, String dnName) + throws IOException { System.out.println("Decommissioning node: " + dnName); // write nodename into the exclude file. ArrayList nodes = new ArrayList(decommissionedNodes); nodes.add(dnName); - writeConfigFile(localFileSys, excludeFile, nodes); + hostsFileWriter.initExcludeHosts(nodes.toArray(new String[0])); } private void checkDecommissionStatus(DatanodeDescriptor decommNode, @@ -292,7 +263,7 @@ public class TestDecommissioningStatus { FSNamesystem fsn = cluster.getNamesystem(); final DatanodeManager dm = fsn.getBlockManager().getDatanodeManager(); for (int iteration = 0; iteration < numDatanodes; iteration++) { - String downnode = decommissionNode(fsn, client, localFileSys, iteration); + String downnode = decommissionNode(fsn, client, iteration); dm.refreshNodes(conf); decommissionedNodes.add(downnode); BlockManagerTestUtil.recheckDecommissionState(dm); @@ -319,7 +290,7 @@ public class TestDecommissioningStatus { // Call refreshNodes on FSNamesystem with empty exclude file. // This will remove the datanodes from decommissioning list and // make them available again. - writeConfigFile(localFileSys, excludeFile, null); + hostsFileWriter.initExcludeHost(""); dm.refreshNodes(conf); st1.close(); cleanupFile(fileSys, file1); @@ -349,7 +320,7 @@ public class TestDecommissioningStatus { // Decommission the DN. FSNamesystem fsn = cluster.getNamesystem(); final DatanodeManager dm = fsn.getBlockManager().getDatanodeManager(); - decommissionNode(fsn, localFileSys, dnName); + decommissionNode(fsn, dnName); dm.refreshNodes(conf); // Stop the DN when decommission is in progress. @@ -396,7 +367,7 @@ public class TestDecommissioningStatus { // Call refreshNodes on FSNamesystem with empty exclude file. // This will remove the datanodes from decommissioning list and // make them available again. - writeConfigFile(localFileSys, excludeFile, null); + hostsFileWriter.initExcludeHost(""); dm.refreshNodes(conf); } @@ -417,7 +388,7 @@ public class TestDecommissioningStatus { FSNamesystem fsn = cluster.getNamesystem(); final DatanodeManager dm = fsn.getBlockManager().getDatanodeManager(); DatanodeDescriptor dnDescriptor = dm.getDatanode(dnID); - decommissionNode(fsn, localFileSys, dnName); + decommissionNode(fsn, dnName); dm.refreshNodes(conf); BlockManagerTestUtil.recheckDecommissionState(dm); assertTrue(dnDescriptor.isDecommissioned()); @@ -428,7 +399,7 @@ public class TestDecommissioningStatus { // Call refreshNodes on FSNamesystem with empty exclude file to remove the // datanode from decommissioning list and make it available again. - writeConfigFile(localFileSys, excludeFile, null); + hostsFileWriter.initExcludeHost(""); dm.refreshNodes(conf); } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileInputStream.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileInputStream.java index cb28b60c956..3c8336ff8ea 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileInputStream.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileInputStream.java @@ -86,8 +86,7 @@ public class TestEditLogFileInputStream { @Test(timeout=60000) public void testScanCorruptEditLog() throws Exception { Configuration conf = new Configuration(); - File editLog = new File(System.getProperty( - "test.build.data", "/tmp"), "testCorruptEditLog"); + File editLog = new File(GenericTestUtils.getTempPath("testCorruptEditLog")); LOG.debug("Creating test edit log file: " + editLog); EditLogFileOutputStream elos = new EditLogFileOutputStream(conf, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java index 6be39509c9a..82f5cfb1699 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFSImageWithSnapshot.java @@ -69,8 +69,8 @@ public class TestFSImageWithSnapshot { private final Path dir = new Path("/TestSnapshot"); private static final String testDir = - System.getProperty("test.build.data", "build/test/data"); - + GenericTestUtils.getTestDir().getAbsolutePath(); + Configuration conf; MiniDFSCluster cluster; FSNamesystem fsn; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java index a4d06672691..a3e2a97da4d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java @@ -116,8 +116,8 @@ import com.google.common.collect.Sets; * A JUnit test for doing fsck */ public class TestFsck { - static final String auditLogFile = System.getProperty("test.build.dir", - "build/test") + "/TestFsck-audit.log"; + static final String AUDITLOG_FILE = + GenericTestUtils.getTempPath("TestFsck-audit.log"); // Pattern for: // allowed=true ugi=name ip=/address cmd=FSCK src=/ dst=null perm=null @@ -206,14 +206,15 @@ public class TestFsck { /** Sets up log4j logger for auditlogs */ private void setupAuditLogs() throws IOException { - File file = new File(auditLogFile); + File file = new File(AUDITLOG_FILE); if (file.exists()) { file.delete(); } Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger(); logger.setLevel(Level.INFO); PatternLayout layout = new PatternLayout("%m%n"); - RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile); + RollingFileAppender appender = + new RollingFileAppender(layout, AUDITLOG_FILE); logger.addAppender(appender); } @@ -225,7 +226,7 @@ public class TestFsck { BufferedReader reader = null; try { // Audit log should contain one getfileinfo and one fsck - reader = new BufferedReader(new FileReader(auditLogFile)); + reader = new BufferedReader(new FileReader(AUDITLOG_FILE)); String line; // one extra getfileinfo stems from resolving the path diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeHttpServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeHttpServer.java index 7dc719e564a..27efea6d8b2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeHttpServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeHttpServer.java @@ -32,6 +32,7 @@ import org.apache.hadoop.http.HttpConfig; import org.apache.hadoop.http.HttpConfig.Policy; import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.security.ssl.KeyStoreTestUtil; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -42,8 +43,8 @@ import org.junit.runners.Parameterized.Parameters; @RunWith(value = Parameterized.class) public class TestNameNodeHttpServer { - private static final String BASEDIR = System.getProperty("test.build.dir", - "target/test-dir") + "/" + TestNameNodeHttpServer.class.getSimpleName(); + private static final String BASEDIR = GenericTestUtils + .getTempPath(TestNameNodeHttpServer.class.getSimpleName()); private static String keystoresDir; private static String sslConfDir; private static Configuration conf; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRecovery.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRecovery.java index cb6a09dd1c8..9800f2ee0b1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRecovery.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRecovery.java @@ -49,6 +49,7 @@ import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.DeleteOp; import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp.OpInstanceCache; import org.apache.hadoop.hdfs.server.namenode.NNStorage.NameNodeDirType; import org.apache.hadoop.io.IOUtils; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.PathUtils; import org.apache.hadoop.util.StringUtils; import org.junit.Test; @@ -515,8 +516,8 @@ public class TestNameNodeRecovery { conf.set(DFSConfigKeys.DFS_HA_NAMENODE_ID_KEY, "nn1"); conf.set(DFSUtil.addKeySuffixes(DFSConfigKeys.DFS_HA_NAMENODES_KEY_PREFIX, "ns1"), "nn1,nn2"); - String baseDir = System.getProperty( - MiniDFSCluster.PROP_TEST_BUILD_DATA, "build/test/data") + "/dfs/"; + String baseDir = GenericTestUtils.getTestDir("setupRecoveryTestConf") + .getAbsolutePath(); File nameDir = new File(baseDir, "nameR"); File secondaryDir = new File(baseDir, "namesecondaryR"); conf.set(DFSUtil.addKeySuffixes(DFSConfigKeys. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRespectsBindHostKeys.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRespectsBindHostKeys.java index b0fa93d837c..4353e6186b3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRespectsBindHostKeys.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestNameNodeRespectsBindHostKeys.java @@ -29,6 +29,7 @@ import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.http.HttpConfig; import org.apache.hadoop.security.ssl.KeyStoreTestUtil; +import org.apache.hadoop.test.GenericTestUtils; import java.io.File; import java.io.IOException; @@ -238,8 +239,8 @@ public class TestNameNodeRespectsBindHostKeys { } } - private static final String BASEDIR = System.getProperty("test.build.dir", - "target/test-dir") + "/" + TestNameNodeRespectsBindHostKeys.class.getSimpleName(); + private static final String BASEDIR = GenericTestUtils + .getTempPath(TestNameNodeRespectsBindHostKeys.class.getSimpleName()); private static void setupSsl() throws Exception { Configuration conf = new Configuration(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java index 827feb6a2a8..ad3a5a19678 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java @@ -95,7 +95,7 @@ public class TestRenameWithSnapshots { private static FSDirectory fsdir; private static DistributedFileSystem hdfs; private static final String testDir = - System.getProperty("test.build.data", "build/test/data"); + GenericTestUtils.getTestDir().getAbsolutePath(); static private final Path dir = new Path("/testRenameWithSnapshots"); static private final Path sub1 = new Path(dir, "sub1"); static private final Path file1 = new Path(sub1, "file1"); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshot.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshot.java index 150d294f449..65b988b3aaa 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshot.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshot.java @@ -98,8 +98,8 @@ public class TestSnapshot { protected DistributedFileSystem hdfs; private static final String testDir = - System.getProperty("test.build.data", "build/test/data"); - + GenericTestUtils.getTestDir().getAbsolutePath(); + @Rule public ExpectedException exception = ExpectedException.none(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestGetConf.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestGetConf.java index 94ce6b22fc7..942719e1fc8 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestGetConf.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/TestGetConf.java @@ -35,20 +35,18 @@ import java.io.PrintStream; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.StringTokenizer; -import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSUtil; import org.apache.hadoop.hdfs.DFSUtil.ConfiguredNNAddress; import org.apache.hadoop.hdfs.HdfsConfiguration; import org.apache.hadoop.hdfs.tools.GetConf.Command; import org.apache.hadoop.hdfs.tools.GetConf.CommandHandler; +import org.apache.hadoop.hdfs.util.HostsFileWriter; import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.util.ToolRunner; import org.junit.Test; @@ -390,42 +388,29 @@ public class TestGetConf { public void TestGetConfExcludeCommand() throws Exception{ HdfsConfiguration conf = new HdfsConfiguration(); // Set up the hosts/exclude files. - localFileSys = FileSystem.getLocal(conf); - Path workingDir = localFileSys.getWorkingDirectory(); - Path dir = new Path(workingDir, System.getProperty("test.build.data", "target/test/data") + "/Getconf/"); - Path hostsFile = new Path(dir, "hosts"); - Path excludeFile = new Path(dir, "exclude"); - - // Setup conf - conf.set(DFSConfigKeys.DFS_HOSTS, hostsFile.toUri().getPath()); - conf.set(DFSConfigKeys.DFS_HOSTS_EXCLUDE, excludeFile.toUri().getPath()); - writeConfigFile(hostsFile, null); - writeConfigFile(excludeFile, null); + HostsFileWriter hostsFileWriter = new HostsFileWriter(); + hostsFileWriter.initialize(conf, "GetConf"); + Path excludeFile = hostsFileWriter.getExcludeFile(); + String[] args = {"-excludeFile"}; String ret = runTool(conf, args, true); assertEquals(excludeFile.toUri().getPath(),ret.trim()); - cleanupFile(localFileSys, excludeFile.getParent()); + hostsFileWriter.cleanup(); } @Test public void TestGetConfIncludeCommand() throws Exception{ HdfsConfiguration conf = new HdfsConfiguration(); // Set up the hosts/exclude files. - localFileSys = FileSystem.getLocal(conf); - Path workingDir = localFileSys.getWorkingDirectory(); - Path dir = new Path(workingDir, System.getProperty("test.build.data", "target/test/data") + "/Getconf/"); - Path hostsFile = new Path(dir, "hosts"); - Path excludeFile = new Path(dir, "exclude"); - + HostsFileWriter hostsFileWriter = new HostsFileWriter(); + hostsFileWriter.initialize(conf, "GetConf"); + Path hostsFile = hostsFileWriter.getIncludeFile(); + // Setup conf - conf.set(DFSConfigKeys.DFS_HOSTS, hostsFile.toUri().getPath()); - conf.set(DFSConfigKeys.DFS_HOSTS_EXCLUDE, excludeFile.toUri().getPath()); - writeConfigFile(hostsFile, null); - writeConfigFile(excludeFile, null); String[] args = {"-includeFile"}; String ret = runTool(conf, args, true); assertEquals(hostsFile.toUri().getPath(),ret.trim()); - cleanupFile(localFileSys, excludeFile.getParent()); + hostsFileWriter.cleanup(); } @Test @@ -443,29 +428,4 @@ public class TestGetConf { verifyAddresses(conf, TestType.NAMENODE, false, includedNN); verifyAddresses(conf, TestType.NNRPCADDRESSES, true, includedNN); } - - private void writeConfigFile(Path name, ArrayList nodes) - throws IOException { - // delete if it already exists - if (localFileSys.exists(name)) { - localFileSys.delete(name, true); - } - - FSDataOutputStream stm = localFileSys.create(name); - - if (nodes != null) { - for (Iterator it = nodes.iterator(); it.hasNext();) { - String node = it.next(); - stm.writeBytes(node); - stm.writeBytes("\n"); - } - } - stm.close(); - } - - private void cleanupFile(FileSystem fileSys, Path name) throws IOException { - assertTrue(fileSys.exists(name)); - fileSys.delete(name, true); - assertTrue(!fileSys.exists(name)); - } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/HostsFileWriter.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/HostsFileWriter.java index cd5ae954971..2ef0b8f2bc3 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/HostsFileWriter.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/HostsFileWriter.java @@ -73,16 +73,26 @@ public class HostsFileWriter { } public void initExcludeHost(String hostNameAndPort) throws IOException { + initExcludeHosts(hostNameAndPort); + } + + public void initExcludeHosts(String... hostNameAndPorts) throws IOException { + StringBuilder excludeHosts = new StringBuilder(); if (isLegacyHostsFile) { - DFSTestUtil.writeFile(localFileSys, excludeFile, hostNameAndPort); + for (String hostNameAndPort : hostNameAndPorts) { + excludeHosts.append(hostNameAndPort).append("\n"); + } + DFSTestUtil.writeFile(localFileSys, excludeFile, excludeHosts.toString()); } else { - DatanodeAdminProperties dn = new DatanodeAdminProperties(); - String [] hostAndPort = hostNameAndPort.split(":"); - dn.setHostName(hostAndPort[0]); - dn.setPort(Integer.parseInt(hostAndPort[1])); - dn.setAdminState(AdminStates.DECOMMISSIONED); HashSet allDNs = new HashSet<>(); - allDNs.add(dn); + for (String hostNameAndPort : hostNameAndPorts) { + DatanodeAdminProperties dn = new DatanodeAdminProperties(); + String[] hostAndPort = hostNameAndPort.split(":"); + dn.setHostName(hostAndPort[0]); + dn.setPort(Integer.parseInt(hostAndPort[1])); + dn.setAdminState(AdminStates.DECOMMISSIONED); + allDNs.add(dn); + } CombinedHostsFileWriter.writeFile(combinedFile.toString(), allDNs); } } @@ -119,4 +129,12 @@ public class HostsFileWriter { FileUtils.deleteQuietly(new File(fullDir.toUri().getPath())); } } + + public Path getIncludeFile() { + return includeFile; + } + + public Path getExcludeFile() { + return excludeFile; + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestCombinedHostsFileReader.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestCombinedHostsFileReader.java index c3946e412b2..923cf66feaa 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestCombinedHostsFileReader.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/util/TestCombinedHostsFileReader.java @@ -23,6 +23,7 @@ import java.io.FileWriter; import java.util.Set; import org.apache.hadoop.hdfs.protocol.DatanodeAdminProperties; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Before; import org.junit.After; import org.junit.Test; @@ -35,8 +36,8 @@ import static org.junit.Assert.assertEquals; public class TestCombinedHostsFileReader { // Using /test/build/data/tmp directory to store temporary files - static final String HOSTS_TEST_DIR = new File(System.getProperty( - "test.build.data", "/tmp")).getAbsolutePath(); + static final String HOSTS_TEST_DIR = GenericTestUtils.getTestDir() + .getAbsolutePath(); File NEW_FILE = new File(HOSTS_TEST_DIR, "dfs.hosts.new.json"); static final String TEST_CACHE_DATA_DIR = diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestHttpsFileSystem.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestHttpsFileSystem.java index 04c1e0241bc..d8b29bb2af1 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestHttpsFileSystem.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestHttpsFileSystem.java @@ -34,14 +34,15 @@ import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys; import org.apache.hadoop.http.HttpConfig; import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.security.ssl.KeyStoreTestUtil; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; public class TestHttpsFileSystem { - private static final String BASEDIR = System.getProperty("test.build.dir", - "target/test-dir") + "/" + TestHttpsFileSystem.class.getSimpleName(); + private static final String BASEDIR = + GenericTestUtils.getTempPath(TestHttpsFileSystem.class.getSimpleName()); private static MiniDFSCluster cluster; private static Configuration conf; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTokens.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTokens.java index 44a6b379799..16f20a87950 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTokens.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/web/TestWebHdfsTokens.java @@ -56,6 +56,7 @@ import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.authentication.client.ConnectionConfigurator; import org.apache.hadoop.security.ssl.KeyStoreTestUtil; import org.apache.hadoop.security.token.SecretManager.InvalidToken; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.security.token.Token; import org.junit.Assert; import org.junit.BeforeClass; @@ -200,8 +201,8 @@ public class TestWebHdfsTokens { SecurityUtil.setAuthenticationMethod(SIMPLE, clusterConf); clusterConf.setBoolean(DFSConfigKeys .DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY, true); - String BASEDIR = System.getProperty("test.build.dir", - "target/test-dir") + "/" + TestWebHdfsTokens.class.getSimpleName(); + String baseDir = + GenericTestUtils.getTempPath(TestWebHdfsTokens.class.getSimpleName()); String keystoresDir; String sslConfDir; @@ -210,10 +211,10 @@ public class TestWebHdfsTokens { clusterConf.set(DFSConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_KEY, "localhost:0"); clusterConf.set(DFSConfigKeys.DFS_DATANODE_HTTPS_ADDRESS_KEY, "localhost:0"); - File base = new File(BASEDIR); + File base = new File(baseDir); FileUtil.fullyDelete(base); base.mkdirs(); - keystoresDir = new File(BASEDIR).getAbsolutePath(); + keystoresDir = new File(baseDir).getAbsolutePath(); sslConfDir = KeyStoreTestUtil.getClasspathDir(TestWebHdfsTokens.class); KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, clusterConf, false); clusterConf.set(DFSConfigKeys.DFS_CLIENT_HTTPS_KEYSTORE_RESOURCE_KEY, diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/test/PathUtils.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/test/PathUtils.java index ac0f632145b..d54ea651ef7 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/test/PathUtils.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/test/PathUtils.java @@ -19,7 +19,6 @@ package org.apache.hadoop.test; import java.io.File; -import org.apache.commons.lang.RandomStringUtils; import org.apache.hadoop.fs.Path; public class PathUtils { @@ -37,10 +36,8 @@ public class PathUtils { } public static File getTestDir(Class caller, boolean create) { - File dir = - new File(System.getProperty("test.build.data", "target/test/data") - + "/" + RandomStringUtils.randomAlphanumeric(10), - caller.getSimpleName()); + File dir = new File(GenericTestUtils.getRandomizedTestDir(), + caller.getSimpleName()); if (create) { dir.mkdirs(); }