http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileUnsortedByteArrays.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileUnsortedByteArrays.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileUnsortedByteArrays.java index 235e5e4..f243b2a 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileUnsortedByteArrays.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestTFileUnsortedByteArrays.java @@ -29,13 +29,12 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.file.tfile.TFile.Reader; import org.apache.hadoop.io.file.tfile.TFile.Writer; import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Before; import org.junit.Test; public class TestTFileUnsortedByteArrays { - private static String ROOT = - System.getProperty("test.build.data", "/tmp/tfile-test"); - + private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath(); private final static int BLOCK_SIZE = 512; private final static int BUF_SIZE = 64;
http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestVLong.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestVLong.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestVLong.java index 9efd271..69e6eb8 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestVLong.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/file/tfile/TestVLong.java @@ -29,12 +29,12 @@ import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Before; import org.junit.Test; public class TestVLong { - private static String ROOT = - System.getProperty("test.build.data", "/tmp/tfile-test"); + private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath(); private Configuration conf; private FileSystem fs; private Path path; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/nativeio/TestNativeIO.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/nativeio/TestNativeIO.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/nativeio/TestNativeIO.java index 13fdbc1..e6f25dc 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/nativeio/TestNativeIO.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/nativeio/TestNativeIO.java @@ -61,8 +61,7 @@ import static org.apache.hadoop.io.nativeio.NativeIO.POSIX.Stat.*; public class TestNativeIO { static final Log LOG = LogFactory.getLog(TestNativeIO.class); - static final File TEST_DIR = new File( - System.getProperty("test.build.data"), "testnativeio"); + static final File TEST_DIR = GenericTestUtils.getTestDir("testnativeio"); @Before public void checkLoaded() { @@ -516,8 +515,7 @@ public class TestNativeIO { @Test (timeout = 30000) public void testRenameTo() throws Exception { - final File TEST_DIR = new File(new File( - System.getProperty("test.build.data","build/test/data")), "renameTest"); + final File TEST_DIR = GenericTestUtils.getTestDir("renameTest") ; assumeTrue(TEST_DIR.mkdirs()); File nonExistentFile = new File(TEST_DIR, "nonexistent"); File targetFile = new File(TEST_DIR, "target"); @@ -566,9 +564,7 @@ public class TestNativeIO { @Test(timeout=10000) public void testMlock() throws Exception { assumeTrue(NativeIO.isAvailable()); - final File TEST_FILE = new File(new File( - System.getProperty("test.build.data","build/test/data")), - "testMlockFile"); + final File TEST_FILE = GenericTestUtils.getTestDir("testMlockFile"); final int BUF_LEN = 12289; byte buf[] = new byte[BUF_LEN]; int bufSum = 0; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/nativeio/TestSharedFileDescriptorFactory.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/nativeio/TestSharedFileDescriptorFactory.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/nativeio/TestSharedFileDescriptorFactory.java index 899ba4b..64abecd 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/nativeio/TestSharedFileDescriptorFactory.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/nativeio/TestSharedFileDescriptorFactory.java @@ -31,12 +31,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.test.GenericTestUtils; public class TestSharedFileDescriptorFactory { static final Log LOG = LogFactory.getLog(TestSharedFileDescriptorFactory.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 setup() throws Exception { http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/sink/RollingFileSystemSinkTestBase.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/sink/RollingFileSystemSinkTestBase.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/sink/RollingFileSystemSinkTestBase.java index 9914c5e..b65a759 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/sink/RollingFileSystemSinkTestBase.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/sink/RollingFileSystemSinkTestBase.java @@ -53,6 +53,7 @@ import org.apache.hadoop.metrics2.impl.MetricsSystemImpl; import org.apache.hadoop.metrics2.impl.TestMetricsConfig; import org.apache.hadoop.metrics2.lib.MutableGaugeInt; import org.apache.hadoop.metrics2.lib.MutableGaugeLong; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.AfterClass; import org.junit.Rule; import org.junit.rules.TestName; @@ -68,9 +69,8 @@ import static org.junit.Assert.assertTrue; public class RollingFileSystemSinkTestBase { protected static final String SINK_PRINCIPAL_KEY = "rfssink.principal"; protected static final String SINK_KEYTAB_FILE_KEY = "rfssink.keytab"; - protected static final File ROOT_TEST_DIR = - new File(System.getProperty("test.build.data", "target/test"), - "RollingFileSystemSinkTest"); + protected static final File ROOT_TEST_DIR = GenericTestUtils.getTestDir( + "RollingFileSystemSinkTest"); protected static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMddHH"); protected static File methodDir; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestCredentials.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestCredentials.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestCredentials.java index cad0262..e1e7d1d 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestCredentials.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestCredentials.java @@ -40,6 +40,7 @@ import org.apache.hadoop.io.WritableComparator; import org.apache.hadoop.security.Credentials; import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.TokenIdentifier; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -47,8 +48,7 @@ import static org.junit.Assert.*; public class TestCredentials { private static final String DEFAULT_HMAC_ALGORITHM = "HmacSHA1"; - private static final File tmpDir = - new File(System.getProperty("test.build.data", "/tmp"), "mapred"); + private static final File tmpDir = GenericTestUtils.getTestDir("mapred"); @Before public void setUp() { http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java index 17a14d1..da46970 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/TestLdapGroupsMapping.java @@ -38,6 +38,7 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.security.alias.CredentialProvider; import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.apache.hadoop.security.alias.JavaKeyStoreProvider; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -108,8 +109,7 @@ public class TestLdapGroupsMapping extends TestLdapGroupsMappingBase { @Test public void testExtractPassword() throws IOException { - File testDir = new File(System.getProperty("test.build.data", - "target/test-dir")); + File testDir = GenericTestUtils.getTestDir(); testDir.mkdirs(); File secretFile = new File(testDir, "secret.txt"); Writer writer = new FileWriter(secretFile); @@ -123,8 +123,7 @@ public class TestLdapGroupsMapping extends TestLdapGroupsMappingBase { @Test public void testConfGetPassword() 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"); final String ourUrl = http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredShell.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredShell.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredShell.java index 7551df6..f4541fc 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredShell.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredShell.java @@ -30,14 +30,14 @@ import java.util.List; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Before; import org.junit.Test; public class TestCredShell { private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); - private static final File tmpDir = - new File(System.getProperty("test.build.data", "/tmp"), "creds"); + private static final File tmpDir = GenericTestUtils.getTestDir("creds"); /* The default JCEKS provider - for testing purposes */ private String jceksProvider; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredentialProviderFactory.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredentialProviderFactory.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredentialProviderFactory.java index 73cf3f4..567adbb 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredentialProviderFactory.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/alias/TestCredentialProviderFactory.java @@ -34,7 +34,7 @@ import org.apache.hadoop.io.Text; import org.apache.hadoop.security.Credentials; import org.apache.hadoop.security.ProviderUtils; import org.apache.hadoop.security.UserGroupInformation; - +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -61,8 +61,7 @@ public class TestCredentialProviderFactory { 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9',}; - private static final File tmpDir = - new File(System.getProperty("test.build.data", "/tmp"), "creds"); + private static final File tmpDir = GenericTestUtils.getTestDir("creds"); @Test public void testFactory() throws Exception { http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/KeyStoreTestUtil.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/KeyStoreTestUtil.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/KeyStoreTestUtil.java index 00cd1cb..898c94e 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/KeyStoreTestUtil.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/KeyStoreTestUtil.java @@ -23,6 +23,7 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.security.alias.CredentialProvider; import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.apache.hadoop.security.alias.JavaKeyStoreProvider; +import org.apache.hadoop.test.GenericTestUtils; import java.io.File; import java.io.FileOutputStream; @@ -470,8 +471,7 @@ public class KeyStoreTestUtil { } public static void provisionPasswordsToCredentialProvider() 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"); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestReloadingX509TrustManager.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestReloadingX509TrustManager.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestReloadingX509TrustManager.java index 75e5a8e..9375da8 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestReloadingX509TrustManager.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestReloadingX509TrustManager.java @@ -18,6 +18,7 @@ package org.apache.hadoop.security.ssl; import org.apache.hadoop.fs.FileUtil; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.BeforeClass; import org.junit.Test; @@ -37,9 +38,8 @@ import static org.apache.hadoop.security.ssl.KeyStoreTestUtil.generateKeyPair; public class TestReloadingX509TrustManager { - private static final String BASEDIR = - System.getProperty("test.build.data", "target/test-dir") + "/" + - TestReloadingX509TrustManager.class.getSimpleName(); + private static final String BASEDIR = GenericTestUtils.getTempPath( + TestReloadingX509TrustManager.class.getSimpleName()); private X509Certificate cert1; private X509Certificate cert2; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestSSLFactory.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestSSLFactory.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestSSLFactory.java index b8a09ed..f0c502e 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestSSLFactory.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/security/ssl/TestSSLFactory.java @@ -52,8 +52,7 @@ public class TestSSLFactory { private static final Logger LOG = LoggerFactory .getLogger(TestSSLFactory.class); private static final String BASEDIR = - System.getProperty("test.build.dir", "target/test-dir") + "/" + - TestSSLFactory.class.getSimpleName(); + GenericTestUtils.getTempPath(TestSSLFactory.class.getSimpleName()); private static final String KEYSTORES_DIR = new File(BASEDIR).getAbsolutePath(); private String sslConfsDir; @@ -433,8 +432,7 @@ public class TestSSLFactory { sslConf = KeyStoreTestUtil.createServerSSLConfig(keystore, confPassword, confKeyPassword, truststore); if (useCredProvider) { - File testDir = new File(System.getProperty("test.build.data", - "target/test-dir")); + File testDir = GenericTestUtils.getTestDir(); final Path jksPath = new Path(testDir.toString(), "test.jks"); final String ourUrl = JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java index 1907094..116a111 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/test/GenericTestUtils.java @@ -20,7 +20,6 @@ package org.apache.hadoop.test; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; -import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringWriter; @@ -37,10 +36,10 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Pattern; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.impl.Log4JLogger; import org.apache.hadoop.fs.FileUtil; -import org.apache.hadoop.util.NativeCodeLoader; import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.Time; import org.apache.log4j.Layout; @@ -64,6 +63,22 @@ public abstract class GenericTestUtils { private static final AtomicInteger sequence = new AtomicInteger(); + /** + * system property for test data: {@value} + */ + public static final String SYSPROP_TEST_DATA_DIR = "test.build.data"; + + /** + * Default path for test data: {@value} + */ + public static final String DEFAULT_TEST_DATA_DIR = + "target" + File.separator + "test" + File.separator + "data"; + + /** + * The default path for using in Hadoop path references: {@value} + */ + public static final String DEFAULT_TEST_DATA_PATH = "target/test/data/"; + @SuppressWarnings("unchecked") public static void disableLog(Log log) { // We expect that commons-logging is a wrapper around Log4j. @@ -119,7 +134,70 @@ public abstract class GenericTestUtils { public static int uniqueSequenceId() { return sequence.incrementAndGet(); } - + + /** + * Get the (created) base directory for tests. + * @return the absolute directory + */ + public static File getTestDir() { + String prop = System.getProperty(SYSPROP_TEST_DATA_DIR, DEFAULT_TEST_DATA_DIR); + if (prop.isEmpty()) { + // corner case: property is there but empty + prop = DEFAULT_TEST_DATA_DIR; + } + File dir = new File(prop).getAbsoluteFile(); + dir.mkdirs(); + assertExists(dir); + return dir; + } + + /** + * Get an uncreated directory for tests. + * @return the absolute directory for tests. Caller is expected to create it. + */ + public static File getTestDir(String subdir) { + return new File(getTestDir(), subdir).getAbsoluteFile(); + } + + /** + * Get an uncreated directory for tests with a randomized alphanumeric + * name. This is likely to provide a unique path for tests run in parallel + * @return the absolute directory for tests. Caller is expected to create it. + */ + public static File getRandomizedTestDir() { + return new File(getRandomizedTempPath()).getAbsoluteFile(); + } + + /** + * Get a temp path. This may or may not be relative; it depends on what the + * {@link #SYSPROP_TEST_DATA_DIR} is set to. If unset, it returns a path + * under the relative path {@link #DEFAULT_TEST_DATA_PATH} + * @param subpath sub path, with no leading "/" character + * @return a string to use in paths + */ + public static String getTempPath(String subpath) { + String prop = System.getProperty(SYSPROP_TEST_DATA_DIR, DEFAULT_TEST_DATA_PATH); + if (prop.isEmpty()) { + // corner case: property is there but empty + prop = DEFAULT_TEST_DATA_PATH; + } + if (!prop.endsWith("/")) { + prop = prop + "/"; + } + return prop + subpath; + } + + /** + * Get a temp path. This may or may not be relative; it depends on what the + * {@link #SYSPROP_TEST_DATA_DIR} is set to. If unset, it returns a path + * under the relative path {@link #DEFAULT_TEST_DATA_PATH} + * @param subpath sub path, with no leading "/" character + * @return a string to use in paths + */ + public static String getRandomizedTempPath() { + return getTempPath(RandomStringUtils.randomAlphanumeric(10)); + } + /** * Assert that a given file exists. */ http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/JarFinder.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/JarFinder.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/JarFinder.java index 98acd16..33aa025 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/JarFinder.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/JarFinder.java @@ -31,6 +31,8 @@ import java.util.jar.Manifest; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +import org.apache.hadoop.test.GenericTestUtils; + /** * Finds the Jar for a class. If the class is in a directory in the * classpath, it creates a Jar on the fly with the contents of the directory @@ -152,7 +154,7 @@ public class JarFinder { klassName = klassName.replace(".", "/") + ".class"; path = path.substring(0, path.length() - klassName.length()); File baseDir = new File(path); - File testDir = new File(System.getProperty("test.build.dir", "target/test-dir")); + File testDir = GenericTestUtils.getTestDir(); testDir = testDir.getAbsoluteFile(); if (!testDir.exists()) { testDir.mkdirs(); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestApplicationClassLoader.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestApplicationClassLoader.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestApplicationClassLoader.java index be8e61e..570e542 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestApplicationClassLoader.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestApplicationClassLoader.java @@ -37,6 +37,7 @@ import java.util.zip.ZipEntry; import org.apache.commons.io.IOUtils; import org.apache.hadoop.fs.FileUtil; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Before; import org.junit.Test; @@ -45,8 +46,7 @@ import com.google.common.collect.Lists; public class TestApplicationClassLoader { - private static File testDir = new File(System.getProperty("test.build.data", - System.getProperty("java.io.tmpdir")), "appclassloader"); + private static File testDir = GenericTestUtils.getTestDir("appclassloader"); @Before public void setUp() { http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestClasspath.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestClasspath.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestClasspath.java index 9ffde90..a38c3d7 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestClasspath.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestClasspath.java @@ -32,6 +32,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.io.IOUtils; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -42,8 +43,8 @@ import org.junit.Test; public class TestClasspath { private static final Log LOG = LogFactory.getLog(TestClasspath.class); - private static final File TEST_DIR = new File( - System.getProperty("test.build.data", "/tmp"), "TestClasspath"); + private static final File TEST_DIR = GenericTestUtils.getTestDir( + "TestClasspath"); private static final Charset UTF8 = Charset.forName("UTF-8"); static { http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericOptionsParser.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericOptionsParser.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericOptionsParser.java index 2bc1915..d575586 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericOptionsParser.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericOptionsParser.java @@ -199,7 +199,7 @@ public class TestGenericOptionsParser extends TestCase { super.setUp(); conf = new Configuration(); localFs = FileSystem.getLocal(conf); - testDir = new File(System.getProperty("test.build.data", "/tmp"), "generic"); + testDir = GenericTestUtils.getTestDir("generic"); if(testDir.exists()) localFs.delete(new Path(testDir.toString()), true); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestHostsFileReader.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestHostsFileReader.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestHostsFileReader.java index 7de0be8..3000069 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestHostsFileReader.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestHostsFileReader.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.*; import static org.junit.Assert.*; @@ -31,8 +32,7 @@ import static org.junit.Assert.*; public class TestHostsFileReader { // Using /test/build/data/tmp directory to store temprory files - final String HOSTS_TEST_DIR = new File(System.getProperty( - "test.build.data", "/tmp")).getAbsolutePath(); + final String HOSTS_TEST_DIR = GenericTestUtils.getTestDir().getAbsolutePath(); File EXCLUDES_FILE = new File(HOSTS_TEST_DIR, "dfs.exclude"); File INCLUDES_FILE = new File(HOSTS_TEST_DIR, "dfs.include"); String excludesFile = HOSTS_TEST_DIR + "/dfs.exclude"; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestJarFinder.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestJarFinder.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestJarFinder.java index 4997b7a..e58fb3b 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestJarFinder.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestJarFinder.java @@ -19,6 +19,7 @@ package org.apache.hadoop.util; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Assert; import org.junit.Test; @@ -79,8 +80,8 @@ public class TestJarFinder { @Test public void testExistingManifest() throws Exception { - File dir = new File(System.getProperty("test.build.dir", "target/test-dir"), - TestJarFinder.class.getName() + "-testExistingManifest"); + File dir = GenericTestUtils + .getTestDir(TestJarFinder.class.getName() + "-testExistingManifest"); delete(dir); dir.mkdirs(); @@ -107,8 +108,8 @@ public class TestJarFinder { @Test public void testNoManifest() throws Exception { - File dir = new File(System.getProperty("test.build.dir", "target/test-dir"), - TestJarFinder.class.getName() + "-testNoManifest"); + File dir = GenericTestUtils + .getTestDir(TestJarFinder.class.getName() + "-testNoManifest"); delete(dir); dir.mkdirs(); File propsFile = new File(dir, "props.properties"); http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java index f592d04..5b751e2 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestRunJar.java @@ -32,6 +32,7 @@ import java.util.zip.ZipEntry; import junit.framework.TestCase; import org.apache.hadoop.fs.FileUtil; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -44,11 +45,8 @@ public class TestRunJar extends TestCase { @Override @Before - protected void setUp() - throws Exception { - TEST_ROOT_DIR = - new File(System.getProperty("test.build.data", "/tmp"), getClass() - .getSimpleName()); + protected void setUp() throws Exception { + TEST_ROOT_DIR = GenericTestUtils.getTestDir(getClass().getSimpleName()); if (!TEST_ROOT_DIR.exists()) { TEST_ROOT_DIR.mkdirs(); } http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java index a9f7f6d..f20c140 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestShell.java @@ -31,6 +31,8 @@ import java.lang.management.ThreadInfo; import java.lang.management.ThreadMXBean; import org.apache.hadoop.fs.FileUtil; +import org.apache.hadoop.test.GenericTestUtils; + import static org.apache.hadoop.util.Shell.*; import org.junit.Assume; import org.junit.Before; @@ -49,7 +51,7 @@ public class TestShell extends Assert { @Rule public TestName methodName = new TestName(); - private File rootTestDir = new File(System.getProperty("test.build.data", "target/")); + private File rootTestDir = GenericTestUtils.getTestDir(); /** * A filename generated uniquely for each test method. The file http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestSysInfoLinux.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestSysInfoLinux.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestSysInfoLinux.java index 47fef33..8a6df0c 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestSysInfoLinux.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestSysInfoLinux.java @@ -25,6 +25,7 @@ import java.util.Random; import org.apache.commons.io.IOUtils; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -63,8 +64,8 @@ public class TestSysInfoLinux { } } private static final FakeLinuxResourceCalculatorPlugin plugin; - private static String TEST_ROOT_DIR = new Path(System.getProperty( - "test.build.data", "/tmp")).toString().replace(' ', '+'); + private static String TEST_ROOT_DIR = GenericTestUtils.getTestDir() + .getAbsolutePath(); private static final String FAKE_MEMFILE; private static final String FAKE_CPUFILE; private static final String FAKE_STATFILE; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java index fde2822..cfa97f4 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestWinUtils.java @@ -32,6 +32,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.fs.FileUtil; +import org.apache.hadoop.test.GenericTestUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -44,8 +45,8 @@ import static org.hamcrest.CoreMatchers.*; public class TestWinUtils { private static final Log LOG = LogFactory.getLog(TestWinUtils.class); - private static File TEST_DIR = new File(System.getProperty("test.build.data", - "target"+File.pathSeparator + "tmp"), TestWinUtils.class.getSimpleName()); + private static File TEST_DIR = GenericTestUtils.getTestDir( + TestWinUtils.class.getSimpleName()); String winutils; http://git-wip-us.apache.org/repos/asf/hadoop/blob/8d29e245/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestZKUtil.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestZKUtil.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestZKUtil.java index 52d10ca..0e39ca9 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestZKUtil.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestZKUtil.java @@ -24,6 +24,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; +import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.util.ZKUtil.BadAclFormatException; import org.apache.hadoop.util.ZKUtil.ZKAuthInfo; import org.apache.zookeeper.ZooDefs.Perms; @@ -34,8 +35,8 @@ import com.google.common.base.Charsets; import com.google.common.io.Files; public class TestZKUtil { - private static final String TEST_ROOT_DIR = System.getProperty( - "test.build.data", "/tmp") + "/TestZKUtil"; + private static final String TEST_ROOT_DIR = GenericTestUtils.getTempPath( + "TestZKUtil"); private static final File TEST_FILE = new File(TEST_ROOT_DIR, "test-file");