HADOOP-12984. Add GenericTestUtils.getTestDir method and use it for emporary directory in tests (Contributed by Steve Loughran and Vinayakumar B

This closes #91

(cherry picked from commit 8d29e2451f5ca60f864c7ece16722c0abdd1c657)
This commit is contained in:
Vinayakumar B 2016-04-07 10:12:00 +05:30
parent bccc28914b
commit c2b271fe05
76 changed files with 314 additions and 242 deletions

View File

@ -48,6 +48,8 @@
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.test.GenericTestUtils;
import static org.apache.hadoop.util.PlatformName.IBM_JAVA; import static org.apache.hadoop.util.PlatformName.IBM_JAVA;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -341,8 +343,7 @@ public void testGetLocalPath() throws IOException {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
String[] dirs = new String[]{"a", "b", "c"}; String[] dirs = new String[]{"a", "b", "c"};
for (int i = 0; i < dirs.length; i++) { for (int i = 0; i < dirs.length; i++) {
dirs[i] = new Path(System.getProperty("test.build.data"), dirs[i]) dirs[i] = new Path(GenericTestUtils.getTempPath(dirs[i])).toString();
.toString();
} }
conf.set("dirs", StringUtils.join(dirs, ",")); conf.set("dirs", StringUtils.join(dirs, ","));
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
@ -358,8 +359,7 @@ public void testGetFile() throws IOException {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
String[] dirs = new String[]{"a", "b", "c"}; String[] dirs = new String[]{"a", "b", "c"};
for (int i = 0; i < dirs.length; i++) { for (int i = 0; i < dirs.length; i++) {
dirs[i] = new Path(System.getProperty("test.build.data"), dirs[i]) dirs[i] = new Path(GenericTestUtils.getTempPath(dirs[i])).toString();
.toString();
} }
conf.set("dirs", StringUtils.join(dirs, ",")); conf.set("dirs", StringUtils.join(dirs, ","));
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {

View File

@ -30,6 +30,7 @@
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.LocalFileSystem; import org.apache.hadoop.fs.LocalFileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
@ -38,8 +39,8 @@
import org.junit.Test; import org.junit.Test;
public class TestCryptoStreamsForLocalFS extends CryptoStreamsTestBase { public class TestCryptoStreamsForLocalFS extends CryptoStreamsTestBase {
private static final String TEST_ROOT_DIR private static final String TEST_ROOT_DIR =
= System.getProperty("test.build.data","build/test/data") + "/work-dir/localfs"; GenericTestUtils.getTempPath("work-dir/testcryptostreamsforlocalfs");
private final File base = new File(TEST_ROOT_DIR); private final File base = new File(TEST_ROOT_DIR);
private final Path file = new Path(TEST_ROOT_DIR, "test-file"); private final Path file = new Path(TEST_ROOT_DIR, "test-file");

View File

@ -25,6 +25,7 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -47,8 +48,8 @@ public class TestKeyShell {
public void setup() throws Exception { public void setup() throws Exception {
outContent.reset(); outContent.reset();
errContent.reset(); errContent.reset();
final File tmpDir = new File(System.getProperty("test.build.data", "target"), final File tmpDir = GenericTestUtils.getTestDir(UUID.randomUUID()
UUID.randomUUID().toString()); .toString());
if (!tmpDir.mkdirs()) { if (!tmpDir.mkdirs()) {
throw new IOException("Unable to create " + tmpDir); throw new IOException("Unable to create " + tmpDir);
} }

View File

@ -21,6 +21,7 @@
import org.apache.commons.lang.RandomStringUtils; import org.apache.commons.lang.RandomStringUtils;
import org.apache.hadoop.fs.Options.CreateOpts; import org.apache.hadoop.fs.Options.CreateOpts;
import org.apache.hadoop.test.GenericTestUtils;
/** /**
* Abstraction of filesystem functionality with additional helper methods * Abstraction of filesystem functionality with additional helper methods
@ -43,7 +44,7 @@ public abstract class FSTestWrapper implements FSWrapper {
public FSTestWrapper(String testRootDir) { public FSTestWrapper(String testRootDir) {
// Use default test dir if not provided // Use default test dir if not provided
if (testRootDir == null || testRootDir.isEmpty()) { if (testRootDir == null || testRootDir.isEmpty()) {
testRootDir = System.getProperty("test.build.data", "build/test/data"); testRootDir = GenericTestUtils.getTestDir().getAbsolutePath();
} }
// salt test dir with some random digits for safe parallel runs // salt test dir with some random digits for safe parallel runs
this.testRootDir = testRootDir + "/" this.testRootDir = testRootDir + "/"

View File

@ -29,6 +29,7 @@
import org.apache.hadoop.fs.Options.CreateOpts; import org.apache.hadoop.fs.Options.CreateOpts;
import org.apache.hadoop.fs.Options.Rename; import org.apache.hadoop.fs.Options.Rename;
import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -99,8 +100,7 @@ public boolean accept(Path file) {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
File testBuildData = new File(System.getProperty("test.build.data", File testBuildData = GenericTestUtils.getRandomizedTestDir();
"build/test/data"), RandomStringUtils.randomAlphanumeric(10));
Path rootPath = new Path(testBuildData.getAbsolutePath(), Path rootPath = new Path(testBuildData.getAbsolutePath(),
"root-uri"); "root-uri");
localFsRootPath = rootPath.makeQualified(LocalFileSystem.NAME, null); localFsRootPath = rootPath.makeQualified(LocalFileSystem.NAME, null);

View File

@ -26,6 +26,7 @@
import org.apache.hadoop.fs.Options.CreateOpts; import org.apache.hadoop.fs.Options.CreateOpts;
import org.apache.hadoop.fs.Options.CreateOpts.BlockSize; import org.apache.hadoop.fs.Options.CreateOpts.BlockSize;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Assert; import org.junit.Assert;
/** /**
@ -39,11 +40,10 @@ public final class FileContextTestHelper {
private String absTestRootDir = null; private String absTestRootDir = null;
/** /**
* Create a context with test root relative to the <wd>/build/test/data * Create a context with test root relative to the test directory
*/ */
public FileContextTestHelper() { public FileContextTestHelper() {
this(System.getProperty("test.build.data", "target/test/data") + "/" + this(GenericTestUtils.getRandomizedTestDir().getAbsolutePath());
RandomStringUtils.randomAlphanumeric(10));
} }
/** /**

View File

@ -21,6 +21,8 @@
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Assert; import org.junit.Assert;
import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.FsPermission;
@ -51,8 +53,8 @@
* </p> * </p>
*/ */
public abstract class FileContextURIBase { public abstract class FileContextURIBase {
private static final String basePath = System.getProperty("test.build.data", private static final String basePath =
"build/test/data") + "/testContextURI"; GenericTestUtils.getTempPath("testContextURI");
private static final Path BASE = new Path(basePath); private static final Path BASE = new Path(basePath);
// Matches anything containing <, >, :, ", |, ?, *, or anything that ends with // Matches anything containing <, >, :, ", |, ?, *, or anything that ends with

View File

@ -22,9 +22,9 @@
import java.net.URI; import java.net.URI;
import java.util.Random; import java.util.Random;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.Token;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Assert; import org.junit.Assert;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -45,7 +45,7 @@ public class FileSystemTestHelper {
* Create helper with test root located at <wd>/build/test/data * Create helper with test root located at <wd>/build/test/data
*/ */
public FileSystemTestHelper() { public FileSystemTestHelper() {
this(System.getProperty("test.build.data", "target/test/data") + "/" + RandomStringUtils.randomAlphanumeric(10)); this(GenericTestUtils.getRandomizedTempPath());
} }
/** /**

View File

@ -22,6 +22,7 @@
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.GenericTestUtils;
import junit.framework.TestCase; import junit.framework.TestCase;
@ -30,15 +31,9 @@ public class TestAvroFSInput extends TestCase {
private static final String INPUT_DIR = "AvroFSInput"; private static final String INPUT_DIR = "AvroFSInput";
private Path getInputPath() { private Path getInputPath() {
String dataDir = System.getProperty("test.build.data"); return new Path(GenericTestUtils.getTempPath(INPUT_DIR));
if (null == dataDir) {
return new Path(INPUT_DIR);
} else {
return new Path(new Path(dataDir), INPUT_DIR);
}
} }
public void testAFSInput() throws Exception { public void testAFSInput() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);

View File

@ -22,12 +22,13 @@
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import static org.apache.hadoop.fs.FileSystemTestHelper.*; import static org.apache.hadoop.fs.FileSystemTestHelper.*;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.*; import org.junit.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class TestChecksumFileSystem { public class TestChecksumFileSystem {
static final String TEST_ROOT_DIR static final String TEST_ROOT_DIR =
= System.getProperty("test.build.data","build/test/data/work-dir/localfs"); GenericTestUtils.getTempPath("work-dir/localfs");
static LocalFileSystem localFs; static LocalFileSystem localFs;

View File

@ -37,7 +37,7 @@
public class TestDFVariations { public class TestDFVariations {
private static final String TEST_ROOT_DIR = private static final String TEST_ROOT_DIR =
System.getProperty("test.build.data","build/test/data") + "/TestDFVariations"; GenericTestUtils.getTestDir("testdfvariations").getAbsolutePath();
private static File test_root = null; private static File test_root = null;
@Before @Before

View File

@ -26,11 +26,11 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeys; import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.test.GenericTestUtils;
/** This test makes sure that "DU" does not get to run on each call to getUsed */ /** This test makes sure that "DU" does not get to run on each call to getUsed */
public class TestDU extends TestCase { public class TestDU extends TestCase {
final static private File DU_DIR = new File( final static private File DU_DIR = GenericTestUtils.getTestDir("dutmp");
System.getProperty("test.build.data","/tmp"), "dutmp");
@Override @Override
public void setUp() { public void setUp() {

View File

@ -23,6 +23,7 @@
import java.util.Set; import java.util.Set;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -34,9 +35,10 @@ public class TestFileContextResolveAfs {
static{ static{
FileSystem.enableSymlinks(); FileSystem.enableSymlinks();
} }
private static String TEST_ROOT_DIR_LOCAL
= System.getProperty("test.build.data","/tmp"); private static String TEST_ROOT_DIR_LOCAL =
GenericTestUtils.getTestDir().getAbsolutePath();
private FileContext fc; private FileContext fc;
private FileSystem localFs; private FileSystem localFs;

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.*; import org.junit.*;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -58,9 +59,7 @@
public class TestFileUtil { public class TestFileUtil {
private static final Log LOG = LogFactory.getLog(TestFileUtil.class); private static final Log LOG = LogFactory.getLog(TestFileUtil.class);
private static final String TEST_ROOT_DIR = System.getProperty( private static final File TEST_DIR = GenericTestUtils.getTestDir("fu");
"test.build.data", "/tmp") + "/fu";
private static final File TEST_DIR = new File(TEST_ROOT_DIR);
private static final String FILE = "x"; private static final String FILE = "x";
private static final String LINK = "y"; private static final String LINK = "y";
private static final String DIR = "dir"; private static final String DIR = "dir";
@ -1020,10 +1019,10 @@ private void doUntarAndVerify(File tarFile, File untarDir)
@Test (timeout = 30000) @Test (timeout = 30000)
public void testUntar() throws IOException { public void testUntar() throws IOException {
String tarGzFileName = System.getProperty("test.cache.data", String tarGzFileName = System.getProperty("test.cache.data",
"build/test/cache") + "/test-untar.tgz"; "target/test/cache") + "/test-untar.tgz";
String tarFileName = System.getProperty("test.cache.data", String tarFileName = System.getProperty("test.cache.data",
"build/test/cache") + "/test-untar.tar"; "build/test/cache") + "/test-untar.tar";
String dataDir = System.getProperty("test.build.data", "build/test/data"); File dataDir = GenericTestUtils.getTestDir();
File untarDir = new File(dataDir, "untarDir"); File untarDir = new File(dataDir, "untarDir");
doUntarAndVerify(new File(tarGzFileName), untarDir); doUntarAndVerify(new File(tarGzFileName), untarDir);

View File

@ -32,6 +32,7 @@
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -50,9 +51,8 @@ public static void setup() throws Exception {
conf = new Configuration(); conf = new Configuration();
shell = new FsShell(conf); shell = new FsShell(conf);
lfs = FileSystem.getLocal(conf); lfs = FileSystem.getLocal(conf);
testRootDir = lfs.makeQualified(new Path( testRootDir = lfs.makeQualified(new Path(GenericTestUtils.getTempPath(
System.getProperty("test.build.data","test/build/data"), "testFsShellCopy")));
"testFsShellCopy"));
lfs.mkdirs(testRootDir); lfs.mkdirs(testRootDir);
lfs.setWorkingDirectory(testRootDir); lfs.setWorkingDirectory(testRootDir);

View File

@ -39,6 +39,8 @@
import org.apache.hadoop.fs.shell.PathData; import org.apache.hadoop.fs.shell.PathData;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY; import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.Shell;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -61,9 +63,9 @@ public static void setup() throws IOException {
fileSys = FileSystem.get(conf); fileSys = FileSystem.get(conf);
fsShell = new FsShell(conf); fsShell = new FsShell(conf);
} }
private static String TEST_ROOT_DIR = System.getProperty("test.build.data", private static String TEST_ROOT_DIR =
"build/test/data/testCHReturnCode"); GenericTestUtils.getTempPath("testCHReturnCode");
static void writeFile(FileSystem fs, Path name) throws Exception { static void writeFile(FileSystem fs, Path name) throws Exception {
FSDataOutputStream stm = fs.create(name); FSDataOutputStream stm = fs.create(name);

View File

@ -24,6 +24,7 @@
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -41,9 +42,8 @@ public static void setup() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
shell = new FsShell(conf); shell = new FsShell(conf);
lfs = FileSystem.getLocal(conf); lfs = FileSystem.getLocal(conf);
testRootDir = lfs.makeQualified(new Path( testRootDir = lfs.makeQualified(
System.getProperty("test.build.data","test/build/data"), new Path(GenericTestUtils.getTempPath("testFsShell")));
"testFsShell"));
lfs.mkdirs(testRootDir); lfs.mkdirs(testRootDir);
lfs.setWorkingDirectory(testRootDir); lfs.setWorkingDirectory(testRootDir);

View File

@ -25,13 +25,14 @@
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.GenericTestUtils;
/** /**
* Testing the correctness of FileSystem.getFileBlockLocations. * Testing the correctness of FileSystem.getFileBlockLocations.
*/ */
public class TestGetFileBlockLocations extends TestCase { public class TestGetFileBlockLocations extends TestCase {
private static String TEST_ROOT_DIR = private static String TEST_ROOT_DIR = GenericTestUtils.getTempPath(
System.getProperty("test.build.data", "/tmp/testGetFileBlockLocations"); "testGetFileBlockLocations");
private static final int FileLength = 4 * 1024 * 1024; // 4MB private static final int FileLength = 4 * 1024 * 1024; // 4MB
private Configuration conf; private Configuration conf;
private Path path; private Path path;

View File

@ -20,6 +20,7 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.Shell;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
@ -45,8 +46,8 @@
*/ */
public class TestHarFileSystemBasics { public class TestHarFileSystemBasics {
private static final String ROOT_PATH = System.getProperty("test.build.data", private static final String ROOT_PATH =
"build/test/data"); GenericTestUtils.getTempPath("testharfilesystembasics");
private static final Path rootPath; private static final Path rootPath;
static { static {
String root = new Path(new File(ROOT_PATH).getAbsolutePath(), "localfs") String root = new Path(new File(ROOT_PATH).getAbsolutePath(), "localfs")

View File

@ -24,6 +24,7 @@
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
@ -57,9 +58,7 @@
*/ */
public class TestHardLink { public class TestHardLink {
public static final String TEST_ROOT_DIR = final static private File TEST_DIR = GenericTestUtils.getTestDir("test/hl");
System.getProperty("test.build.data", "build/test/data") + "/test";
final static private File TEST_DIR = new File(TEST_ROOT_DIR, "hl");
private static String DIR = "dir_"; private static String DIR = "dir_";
//define source and target directories //define source and target directories
private static File src = new File(TEST_DIR, DIR + "src"); private static File src = new File(TEST_DIR, DIR + "src");

View File

@ -22,11 +22,8 @@
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.log4j.Level; import org.apache.log4j.Level;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -37,8 +34,8 @@
* This class tests the FileStatus API. * This class tests the FileStatus API.
*/ */
public class TestListFiles { public class TestListFiles {
{ static {
((Log4JLogger)FileSystem.LOG).getLogger().setLevel(Level.ALL); GenericTestUtils.setLogLevel(FileSystem.LOG, Level.ALL);
} }
static final long seed = 0xDEADBEEFL; static final long seed = 0xDEADBEEFL;
@ -53,9 +50,8 @@ public class TestListFiles {
private static Path FILE3; private static Path FILE3;
static { static {
setTestPaths(new Path( setTestPaths(new Path(GenericTestUtils.getTempPath("testlistfiles"),
System.getProperty("test.build.data", "build/test/data/work-dir/localfs"), "main_"));
"main_"));
} }
protected static Path getTestDir() { protected static Path getTestDir() {

View File

@ -20,6 +20,7 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem.Statistics; import org.apache.hadoop.fs.FileSystem.Statistics;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.Shell;
import static org.apache.hadoop.fs.FileSystemTestHelper.*; import static org.apache.hadoop.fs.FileSystemTestHelper.*;
@ -44,10 +45,10 @@
* This class tests the local file system via the FileSystem abstraction. * This class tests the local file system via the FileSystem abstraction.
*/ */
public class TestLocalFileSystem { public class TestLocalFileSystem {
private static final String TEST_ROOT_DIR private static final File base =
= System.getProperty("test.build.data","build/test/data") + "/work-dir/localfs"; GenericTestUtils.getTestDir("work-dir/localfs");
private final File base = new File(TEST_ROOT_DIR); private static final String TEST_ROOT_DIR = base.getAbsolutePath();
private final Path TEST_PATH = new Path(TEST_ROOT_DIR, "test-file"); private final Path TEST_PATH = new Path(TEST_ROOT_DIR, "test-file");
private Configuration conf; private Configuration conf;
private LocalFileSystem fileSys; private LocalFileSystem fileSys;

View File

@ -19,7 +19,9 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.permission.*; import org.apache.hadoop.fs.permission.*;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.apache.log4j.Level;
import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.Shell;
import java.io.*; import java.io.*;
@ -31,19 +33,11 @@
* This class tests the local file system via the FileSystem abstraction. * This class tests the local file system via the FileSystem abstraction.
*/ */
public class TestLocalFileSystemPermission extends TestCase { public class TestLocalFileSystemPermission extends TestCase {
static final String TEST_PATH_PREFIX = new Path(System.getProperty( static final String TEST_PATH_PREFIX = GenericTestUtils.getTempPath(
"test.build.data", "/tmp")).toString().replace(' ', '_') TestLocalFileSystemPermission.class.getSimpleName());
+ "/" + TestLocalFileSystemPermission.class.getSimpleName() + "_";
{ static {
try { GenericTestUtils.setLogLevel(FileSystem.LOG, Level.DEBUG);
((org.apache.commons.logging.impl.Log4JLogger)FileSystem.LOG).getLogger()
.setLevel(org.apache.log4j.Level.DEBUG);
}
catch(Exception e) {
System.out.println("Cannot change log level\n"
+ StringUtils.stringifyException(e));
}
} }
private Path writeFile(FileSystem fs, String name) throws IOException { private Path writeFile(FileSystem fs, String name) throws IOException {

View File

@ -26,6 +26,7 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.AvroTestUtil; import org.apache.hadoop.io.AvroTestUtil;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.Shell;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
@ -402,9 +403,8 @@ public void testGlobEscapeStatus() throws Exception {
// This test is not meaningful on Windows where * is disallowed in file name. // This test is not meaningful on Windows where * is disallowed in file name.
if (Shell.WINDOWS) return; if (Shell.WINDOWS) return;
FileSystem lfs = FileSystem.getLocal(new Configuration()); FileSystem lfs = FileSystem.getLocal(new Configuration());
Path testRoot = lfs.makeQualified(new Path( Path testRoot = lfs.makeQualified(
System.getProperty("test.build.data","test/build/data"), new Path(GenericTestUtils.getTempPath("testPathGlob")));
"testPathGlob"));
lfs.delete(testRoot, true); lfs.delete(testRoot, true);
lfs.mkdirs(testRoot); lfs.mkdirs(testRoot);
assertTrue(lfs.isDirectory(testRoot)); assertTrue(lfs.isDirectory(testRoot));

View File

@ -34,6 +34,7 @@
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
/** /**
@ -41,9 +42,8 @@
*/ */
public class TestTrash extends TestCase { public class TestTrash extends TestCase {
private final static Path TEST_DIR = private final static Path TEST_DIR = new Path(GenericTestUtils.getTempPath(
new Path(new File(System.getProperty("test.build.data","/tmp") "testTrash"));
).toURI().toString().replace(' ', '+'), "testTrash");
protected static Path mkdir(FileSystem fs, Path p) throws IOException { protected static Path mkdir(FileSystem fs, Path p) throws IOException {
assertTrue(fs.mkdirs(p)); assertTrue(fs.mkdirs(p));

View File

@ -23,6 +23,7 @@
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.test.GenericTestUtils;
/** /**
* test for the input truncation bug when mark/reset is used. * test for the input truncation bug when mark/reset is used.
@ -30,8 +31,7 @@
*/ */
public class TestTruncatedInputBug extends TestCase { public class TestTruncatedInputBug extends TestCase {
private static String TEST_ROOT_DIR = private static String TEST_ROOT_DIR =
new Path(System.getProperty("test.build.data","/tmp")) GenericTestUtils.getTestDir().getAbsolutePath();
.toString().replace(' ', '+');
private void writeFile(FileSystem fileSys, private void writeFile(FileSystem fileSys,
Path name, int nBytesToWrite) Path name, int nBytesToWrite)

View File

@ -29,6 +29,7 @@
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.Shell;
import org.apache.sshd.SshServer; import org.apache.sshd.SshServer;
@ -54,7 +55,7 @@ public class TestSFTPFileSystem {
private static final String TEST_SFTP_DIR = "testsftp"; private static final String TEST_SFTP_DIR = "testsftp";
private static final String TEST_ROOT_DIR = private static final String TEST_ROOT_DIR =
System.getProperty("test.build.data", "build/test/data"); GenericTestUtils.getTestDir().getAbsolutePath();
@Rule public TestName name = new TestName(); @Rule public TestName name = new TestName();

View File

@ -29,14 +29,15 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Shell; import org.apache.hadoop.util.Shell;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class TestPathData { public class TestPathData {
private static final String TEST_ROOT_DIR = private static final String TEST_ROOT_DIR =
System.getProperty("test.build.data","build/test/data") + "/testPD"; GenericTestUtils.getTestDir("testPD").getAbsolutePath();
protected Configuration conf; protected Configuration conf;
protected FileSystem fs; protected FileSystem fs;
protected Path testDir; protected Path testDir;

View File

@ -33,6 +33,7 @@
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Test; import org.junit.Test;
/** /**
@ -41,8 +42,7 @@
*/ */
public class TestTextCommand { public class TestTextCommand {
private static final File TEST_ROOT_DIR = private static final File TEST_ROOT_DIR =
Paths.get(System.getProperty("test.build.data", "build/test/data"), GenericTestUtils.getTestDir("testText");
"testText").toFile();
private static final String AVRO_FILENAME = private static final String AVRO_FILENAME =
new File(TEST_ROOT_DIR, "weather.avro").toURI().getPath(); new File(TEST_ROOT_DIR, "weather.avro").toURI().getPath();
private static final String TEXT_FILENAME = private static final String TEXT_FILENAME =

View File

@ -30,7 +30,7 @@
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DataInputBuffer; import org.apache.hadoop.io.DataInputBuffer;
import org.apache.hadoop.io.DataOutputBuffer; import org.apache.hadoop.io.DataOutputBuffer;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
@ -44,9 +44,8 @@
*/ */
public class TestViewfsFileStatus { public class TestViewfsFileStatus {
private static final File TEST_DIR = private static final File TEST_DIR = GenericTestUtils.getTestDir(
new File(System.getProperty("test.build.data", "/tmp"), TestViewfsFileStatus.class.getSimpleName());
TestViewfsFileStatus.class.getSimpleName());
@Test @Test
public void testFileStatusSerialziation() public void testFileStatusSerialziation()

View File

@ -32,6 +32,7 @@
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import org.apache.hadoop.net.ServerSocketUtil; import org.apache.hadoop.net.ServerSocketUtil;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.apache.zookeeper.TestableZooKeeper; import org.apache.zookeeper.TestableZooKeeper;
import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.WatchedEvent;
@ -62,8 +63,7 @@ public abstract class ClientBaseWithFixes extends ZKTestCase {
protected static final Logger LOG = LoggerFactory.getLogger(ClientBaseWithFixes.class); protected static final Logger LOG = LoggerFactory.getLogger(ClientBaseWithFixes.class);
public static int CONNECTION_TIMEOUT = 30000; public static int CONNECTION_TIMEOUT = 30000;
static final File BASETEST = static final File BASETEST = GenericTestUtils.getTestDir();
new File(System.getProperty("test.build.data", "build"));
protected final String hostPort = initHostPort(); protected final String hostPort = initHostPort();
protected int maxCnxns = 0; protected int maxCnxns = 0;

View File

@ -19,6 +19,7 @@
import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.authentication.server.AuthenticationFilter; import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
import org.apache.hadoop.security.ssl.KeyStoreTestUtil; import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.mortbay.log.Log; import org.mortbay.log.Log;
@ -35,8 +36,8 @@
import java.util.List; import java.util.List;
public class TestAuthenticationSessionCookie { public class TestAuthenticationSessionCookie {
private static final String BASEDIR = System.getProperty("test.build.dir", private static final String BASEDIR =
"target/test-dir") + "/" + TestHttpCookieFlag.class.getSimpleName(); GenericTestUtils.getTempPath(TestHttpCookieFlag.class.getSimpleName());
private static boolean isCookiePersistent; private static boolean isCookiePersistent;
private static final long TOKEN_VALIDITY_SEC = 1000; private static final long TOKEN_VALIDITY_SEC = 1000;
private static long expires; private static long expires;

View File

@ -20,6 +20,7 @@
import org.apache.hadoop.security.authentication.server.AuthenticationFilter; import org.apache.hadoop.security.authentication.server.AuthenticationFilter;
import org.apache.hadoop.security.ssl.KeyStoreTestUtil; import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
import org.apache.hadoop.security.ssl.SSLFactory; import org.apache.hadoop.security.ssl.SSLFactory;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -37,8 +38,8 @@
import java.util.List; import java.util.List;
public class TestHttpCookieFlag { public class TestHttpCookieFlag {
private static final String BASEDIR = System.getProperty("test.build.dir", private static final String BASEDIR =
"target/test-dir") + "/" + TestHttpCookieFlag.class.getSimpleName(); GenericTestUtils.getTempPath(TestHttpCookieFlag.class.getSimpleName());
private static String keystoresDir; private static String keystoresDir;
private static String sslConfDir; private static String sslConfDir;
private static SSLFactory clientSslFactory; private static SSLFactory clientSslFactory;

View File

@ -17,6 +17,7 @@
*/ */
package org.apache.hadoop.http; package org.apache.hadoop.http;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.junit.Test; import org.junit.Test;
@ -76,8 +77,8 @@ public void testStartedServerIsAlive() throws Throwable {
public void testStartedServerWithRequestLog() throws Throwable { public void testStartedServerWithRequestLog() throws Throwable {
HttpRequestLogAppender requestLogAppender = new HttpRequestLogAppender(); HttpRequestLogAppender requestLogAppender = new HttpRequestLogAppender();
requestLogAppender.setName("httprequestlog"); requestLogAppender.setName("httprequestlog");
requestLogAppender.setFilename(System.getProperty("test.build.data", "/tmp/") requestLogAppender.setFilename(
+ "jetty-name-yyyy_mm_dd.log"); GenericTestUtils.getTempPath("jetty-name-yyyy_mm_dd.log"));
Logger.getLogger(HttpServer2.class.getName() + ".test").addAppender(requestLogAppender); Logger.getLogger(HttpServer2.class.getName() + ".test").addAppender(requestLogAppender);
HttpServer2 server = null; HttpServer2 server = null;
server = createTestServer(); server = createTestServer();

View File

@ -40,6 +40,7 @@
import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.ssl.KeyStoreTestUtil; import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
import org.apache.hadoop.security.ssl.SSLFactory; import org.apache.hadoop.security.ssl.SSLFactory;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -51,8 +52,8 @@
*/ */
public class TestSSLHttpServer extends HttpServerFunctionalTest { public class TestSSLHttpServer extends HttpServerFunctionalTest {
private static final String BASEDIR = System.getProperty("test.build.dir", private static final String BASEDIR =
"target/test-dir") + "/" + TestSSLHttpServer.class.getSimpleName(); GenericTestUtils.getTempPath(TestSSLHttpServer.class.getSimpleName());
private static final Log LOG = LogFactory.getLog(TestSSLHttpServer.class); private static final Log LOG = LogFactory.getLog(TestSSLHttpServer.class);
private static Configuration conf; private static Configuration conf;

View File

@ -24,6 +24,7 @@
import org.apache.commons.logging.*; import org.apache.commons.logging.*;
import org.apache.hadoop.fs.*; import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.SequenceFile.CompressionType; import org.apache.hadoop.io.SequenceFile.CompressionType;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Progressable; import org.apache.hadoop.util.Progressable;
import org.apache.hadoop.conf.*; import org.apache.hadoop.conf.*;
import org.junit.Test; import org.junit.Test;
@ -38,9 +39,8 @@
public class TestArrayFile { public class TestArrayFile {
private static final Log LOG = LogFactory.getLog(TestArrayFile.class); private static final Log LOG = LogFactory.getLog(TestArrayFile.class);
private static final Path TEST_DIR = new Path( private static final Path TEST_DIR = new Path(GenericTestUtils.getTempPath(
System.getProperty("test.build.data", "/tmp"), TestMapFile.class.getSimpleName()));
TestMapFile.class.getSimpleName());
private static String TEST_FILE = new Path(TEST_DIR, "test.array").toString(); private static String TEST_FILE = new Path(TEST_DIR, "test.array").toString();
@Test @Test

View File

@ -38,6 +38,7 @@
import org.apache.hadoop.io.compress.CompressionOutputStream; import org.apache.hadoop.io.compress.CompressionOutputStream;
import org.apache.hadoop.io.compress.Compressor; import org.apache.hadoop.io.compress.Compressor;
import org.apache.hadoop.io.compress.Decompressor; import org.apache.hadoop.io.compress.Decompressor;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Progressable; import org.apache.hadoop.util.Progressable;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -49,9 +50,8 @@
public class TestBloomMapFile { public class TestBloomMapFile {
private static Configuration conf = new Configuration(); private static Configuration conf = new Configuration();
private static final Path TEST_ROOT = new Path( private static final Path TEST_ROOT = new Path(GenericTestUtils.getTempPath(
System.getProperty("test.build.data", "/tmp"), TestMapFile.class.getSimpleName()));
TestMapFile.class.getSimpleName());
private static final Path TEST_DIR = new Path(TEST_ROOT, "testfile"); private static final Path TEST_DIR = new Path(TEST_ROOT, "testfile");
private static final Path TEST_FILE = new Path(TEST_ROOT, "testfile"); private static final Path TEST_FILE = new Path(TEST_ROOT, "testfile");

View File

@ -37,6 +37,7 @@
import org.apache.hadoop.io.compress.CompressionOutputStream; import org.apache.hadoop.io.compress.CompressionOutputStream;
import org.apache.hadoop.io.compress.Compressor; import org.apache.hadoop.io.compress.Compressor;
import org.apache.hadoop.io.compress.Decompressor; import org.apache.hadoop.io.compress.Decompressor;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Progressable; import org.apache.hadoop.util.Progressable;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -48,9 +49,8 @@
public class TestMapFile { public class TestMapFile {
private static final Path TEST_DIR = new Path( private static final Path TEST_DIR = new Path(GenericTestUtils.getTempPath(
System.getProperty("test.build.data", "/tmp"), TestMapFile.class.getSimpleName()));
TestMapFile.class.getSimpleName());
private static Configuration conf = new Configuration(); private static Configuration conf = new Configuration();

View File

@ -29,6 +29,7 @@
import org.apache.hadoop.io.compress.CompressionCodec; import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.compress.DefaultCodec; import org.apache.hadoop.io.compress.DefaultCodec;
import org.apache.hadoop.io.serializer.avro.AvroReflectSerialization; import org.apache.hadoop.io.serializer.avro.AvroReflectSerialization;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.ReflectionUtils;
import org.apache.hadoop.conf.*; import org.apache.hadoop.conf.*;
import org.junit.Test; import org.junit.Test;
@ -58,11 +59,11 @@ public void compressedSeqFileTest(CompressionCodec codec) throws Exception {
int count = 1024 * 10; int count = 1024 * 10;
int megabytes = 1; int megabytes = 1;
int factor = 5; int factor = 5;
Path file = new Path(System.getProperty("test.build.data",".")+"/test.seq"); Path file = new Path(GenericTestUtils.getTempPath("test.seq"));
Path recordCompressedFile = Path recordCompressedFile = new Path(GenericTestUtils.getTempPath(
new Path(System.getProperty("test.build.data",".")+"/test.rc.seq"); "test.rc.seq"));
Path blockCompressedFile = Path blockCompressedFile = new Path(GenericTestUtils.getTempPath(
new Path(System.getProperty("test.build.data",".")+"/test.bc.seq"); "test.bc.seq"));
int seed = new Random().nextInt(); int seed = new Random().nextInt();
LOG.info("Seed = " + seed); LOG.info("Seed = " + seed);
@ -320,13 +321,13 @@ public void testSequenceFileMetadata() throws Exception {
LOG.info("Testing SequenceFile with metadata"); LOG.info("Testing SequenceFile with metadata");
int count = 1024 * 10; int count = 1024 * 10;
CompressionCodec codec = new DefaultCodec(); CompressionCodec codec = new DefaultCodec();
Path file = new Path(System.getProperty("test.build.data",".")+"/test.seq.metadata"); Path file = new Path(GenericTestUtils.getTempPath("test.seq.metadata"));
Path sortedFile = Path sortedFile = new Path(GenericTestUtils.getTempPath(
new Path(System.getProperty("test.build.data",".")+"/test.sorted.seq.metadata"); "test.sorted.seq.metadata"));
Path recordCompressedFile = Path recordCompressedFile = new Path(GenericTestUtils.getTempPath(
new Path(System.getProperty("test.build.data",".")+"/test.rc.seq.metadata"); "test.rc.seq.metadata"));
Path blockCompressedFile = Path blockCompressedFile = new Path(GenericTestUtils.getTempPath(
new Path(System.getProperty("test.build.data",".")+"/test.bc.seq.metadata"); "test.bc.seq.metadata"));
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);
SequenceFile.Metadata theMetadata = new SequenceFile.Metadata(); SequenceFile.Metadata theMetadata = new SequenceFile.Metadata();
@ -426,14 +427,14 @@ public void testClose() throws IOException {
LocalFileSystem fs = FileSystem.getLocal(conf); LocalFileSystem fs = FileSystem.getLocal(conf);
// create a sequence file 1 // create a sequence file 1
Path path1 = new Path(System.getProperty("test.build.data",".")+"/test1.seq"); Path path1 = new Path(GenericTestUtils.getTempPath("test1.seq"));
SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, path1, SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, path1,
Text.class, NullWritable.class, CompressionType.BLOCK); Text.class, NullWritable.class, CompressionType.BLOCK);
writer.append(new Text("file1-1"), NullWritable.get()); writer.append(new Text("file1-1"), NullWritable.get());
writer.append(new Text("file1-2"), NullWritable.get()); writer.append(new Text("file1-2"), NullWritable.get());
writer.close(); writer.close();
Path path2 = new Path(System.getProperty("test.build.data",".")+"/test2.seq"); Path path2 = new Path(GenericTestUtils.getTempPath("test2.seq"));
writer = SequenceFile.createWriter(fs, conf, path2, Text.class, writer = SequenceFile.createWriter(fs, conf, path2, Text.class,
NullWritable.class, CompressionType.BLOCK); NullWritable.class, CompressionType.BLOCK);
writer.append(new Text("file2-1"), NullWritable.get()); writer.append(new Text("file2-1"), NullWritable.get());
@ -482,7 +483,7 @@ public void testClose() throws IOException {
public void testCreateUsesFsArg() throws Exception { public void testCreateUsesFsArg() throws Exception {
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);
FileSystem spyFs = Mockito.spy(fs); FileSystem spyFs = Mockito.spy(fs);
Path p = new Path(System.getProperty("test.build.data", ".")+"/testCreateUsesFSArg.seq"); Path p = new Path(GenericTestUtils.getTempPath("testCreateUsesFSArg.seq"));
SequenceFile.Writer writer = SequenceFile.createWriter( SequenceFile.Writer writer = SequenceFile.createWriter(
spyFs, conf, p, NullWritable.class, NullWritable.class); spyFs, conf, p, NullWritable.class, NullWritable.class);
writer.close(); writer.close();
@ -515,7 +516,7 @@ public void testCloseForErroneousSequenceFile()
LocalFileSystem fs = FileSystem.getLocal(conf); LocalFileSystem fs = FileSystem.getLocal(conf);
// create an empty file (which is not a valid sequence file) // create an empty file (which is not a valid sequence file)
Path path = new Path(System.getProperty("test.build.data",".")+"/broken.seq"); Path path = new Path(GenericTestUtils.getTempPath("broken.seq"));
fs.create(path).close(); fs.create(path).close();
// try to create SequenceFile.Reader // try to create SequenceFile.Reader
@ -547,8 +548,7 @@ public void testInitZeroLengthSequenceFile() throws IOException {
LocalFileSystem fs = FileSystem.getLocal(conf); LocalFileSystem fs = FileSystem.getLocal(conf);
// create an empty file (which is not a valid sequence file) // create an empty file (which is not a valid sequence file)
Path path = new Path(System.getProperty("test.build.data", ".") + Path path = new Path(GenericTestUtils.getTempPath("zerolength.seq"));
"/zerolength.seq");
fs.create(path).close(); fs.create(path).close();
try { try {
@ -569,8 +569,8 @@ public void testInitZeroLengthSequenceFile() throws IOException {
public void testCreateWriterOnExistingFile() throws IOException { public void testCreateWriterOnExistingFile() throws IOException {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);
Path name = new Path(new Path(System.getProperty("test.build.data","."), Path name = new Path(new Path(GenericTestUtils.getTempPath(
"createWriterOnExistingFile") , "file"); "createWriterOnExistingFile")), "file");
fs.create(name); fs.create(name);
SequenceFile.createWriter(fs, conf, name, RandomDatum.class, SequenceFile.createWriter(fs, conf, name, RandomDatum.class,
@ -582,8 +582,8 @@ public void testCreateWriterOnExistingFile() throws IOException {
@Test @Test
public void testRecursiveSeqFileCreate() throws IOException { public void testRecursiveSeqFileCreate() throws IOException {
FileSystem fs = FileSystem.getLocal(conf); FileSystem fs = FileSystem.getLocal(conf);
Path name = new Path(new Path(System.getProperty("test.build.data","."), Path name = new Path(new Path(GenericTestUtils.getTempPath(
"recursiveCreateDir") , "file"); "recursiveCreateDir")), "file");
boolean createParent = false; boolean createParent = false;
try { try {
@ -605,8 +605,8 @@ public void testRecursiveSeqFileCreate() throws IOException {
@Test @Test
public void testSerializationAvailability() throws IOException { public void testSerializationAvailability() throws IOException {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
Path path = new Path(System.getProperty("test.build.data", "."), Path path = new Path(GenericTestUtils.getTempPath(
"serializationAvailability"); "serializationAvailability"));
// Check if any serializers aren't found. // Check if any serializers aren't found.
try { try {
SequenceFile.createWriter( SequenceFile.createWriter(

View File

@ -43,8 +43,8 @@ public class TestSequenceFileAppend {
private static Configuration conf; private static Configuration conf;
private static FileSystem fs; private static FileSystem fs;
private static Path ROOT_PATH = new Path(System.getProperty( private static Path ROOT_PATH =
"test.build.data", "build/test/data")); new Path(GenericTestUtils.getTestDir().getAbsolutePath());
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {

View File

@ -24,6 +24,7 @@
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile.Reader; import org.apache.hadoop.io.SequenceFile.Reader;
import org.apache.hadoop.io.SequenceFile.Writer; import org.apache.hadoop.io.SequenceFile.Writer;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -50,8 +51,7 @@ public void tearDown() throws Exception {
@Test @Test
public void testJavaSerialization() throws Exception { public void testJavaSerialization() throws Exception {
Path file = new Path(System.getProperty("test.build.data",".") + Path file = new Path(GenericTestUtils.getTempPath("testseqser.seq"));
"/testseqser.seq");
fs.delete(file, true); fs.delete(file, true);
Writer writer = SequenceFile.createWriter(fs, conf, file, Long.class, Writer writer = SequenceFile.createWriter(fs, conf, file, Long.class,

View File

@ -27,6 +27,7 @@
import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Test; import org.junit.Test;
public class TestSequenceFileSync { public class TestSequenceFileSync {
@ -52,8 +53,8 @@ private static void forOffset(SequenceFile.Reader reader,
public void testLowSyncpoint() throws IOException { public void testLowSyncpoint() throws IOException {
final Configuration conf = new Configuration(); final Configuration conf = new Configuration();
final FileSystem fs = FileSystem.getLocal(conf); final FileSystem fs = FileSystem.getLocal(conf);
final Path path = new Path(System.getProperty("test.build.data", "/tmp"), final Path path = new Path(GenericTestUtils.getTempPath(
"sequencefile.sync.test"); "sequencefile.sync.test"));
final IntWritable input = new IntWritable(); final IntWritable input = new IntWritable();
final Text val = new Text(); final Text val = new Text();
SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, path, SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, path,

View File

@ -20,7 +20,6 @@
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.logging.*; import org.apache.commons.logging.*;
@ -28,6 +27,7 @@
import org.apache.hadoop.fs.*; import org.apache.hadoop.fs.*;
import org.apache.hadoop.conf.*; import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.SequenceFile.CompressionType; import org.apache.hadoop.io.SequenceFile.CompressionType;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -38,8 +38,7 @@
/** Support for flat files of binary key/value pairs. */ /** Support for flat files of binary key/value pairs. */
public class TestSetFile { public class TestSetFile {
private static final Log LOG = LogFactory.getLog(TestSetFile.class); private static final Log LOG = LogFactory.getLog(TestSetFile.class);
private static String FILE = private static String FILE = GenericTestUtils.getTempPath("test.set");
System.getProperty("test.build.data",".") + "/test.set";
private static Configuration conf = new Configuration(); private static Configuration conf = new Configuration();

View File

@ -60,6 +60,7 @@
import org.apache.hadoop.io.compress.zlib.ZlibCompressor; import org.apache.hadoop.io.compress.zlib.ZlibCompressor;
import org.apache.hadoop.io.compress.zlib.ZlibCompressor.CompressionLevel; import org.apache.hadoop.io.compress.zlib.ZlibCompressor.CompressionLevel;
import org.apache.hadoop.io.compress.zlib.ZlibCompressor.CompressionStrategy; import org.apache.hadoop.io.compress.zlib.ZlibCompressor.CompressionStrategy;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.io.compress.zlib.ZlibFactory; import org.apache.hadoop.io.compress.zlib.ZlibFactory;
import org.apache.hadoop.io.compress.bzip2.Bzip2Factory; import org.apache.hadoop.io.compress.bzip2.Bzip2Factory;
import org.apache.hadoop.util.LineReader; import org.apache.hadoop.util.LineReader;
@ -328,9 +329,9 @@ private static int readLeadingInt(Text txt) throws IOException {
private static Path writeSplitTestFile(FileSystem fs, Random rand, private static Path writeSplitTestFile(FileSystem fs, Random rand,
CompressionCodec codec, long infLen) throws IOException { CompressionCodec codec, long infLen) throws IOException {
final int REC_SIZE = 1024; final int REC_SIZE = 1024;
final Path wd = new Path(new Path( final Path wd = new Path(GenericTestUtils.getTempPath(
System.getProperty("test.build.data", "/tmp")).makeQualified(fs), codec.getClass().getSimpleName())).makeQualified(
codec.getClass().getSimpleName()); fs.getUri(), fs.getWorkingDirectory());
final Path file = new Path(wd, "test" + codec.getDefaultExtension()); final Path file = new Path(wd, "test" + codec.getDefaultExtension());
final byte[] b = new byte[REC_SIZE]; final byte[] b = new byte[REC_SIZE];
final Base64 b64 = new Base64(0, null); final Base64 b64 = new Base64(0, null);
@ -590,9 +591,8 @@ private void codecTestMapFile(Class<? extends CompressionCodec> clazz,
FileSystem fs = FileSystem.get(conf); FileSystem fs = FileSystem.get(conf);
LOG.info("Creating MapFiles with " + records + LOG.info("Creating MapFiles with " + records +
" records using codec " + clazz.getSimpleName()); " records using codec " + clazz.getSimpleName());
Path path = new Path(new Path( Path path = new Path(GenericTestUtils.getTempPath(
System.getProperty("test.build.data", "/tmp")), clazz.getSimpleName() + "-" + type + "-" + records));
clazz.getSimpleName() + "-" + type + "-" + records);
LOG.info("Writing " + path); LOG.info("Writing " + path);
createMapFile(conf, fs, path, clazz.newInstance(), type, records); createMapFile(conf, fs, path, clazz.newInstance(), type, records);
@ -749,8 +749,7 @@ public void testGzipCodecRead() throws IOException {
CodecPool.returnDecompressor(zlibDecompressor); CodecPool.returnDecompressor(zlibDecompressor);
// Now create a GZip text file. // Now create a GZip text file.
String tmpDir = System.getProperty("test.build.data", "/tmp/"); Path f = new Path(GenericTestUtils.getTempPath("testGzipCodecRead.txt.gz"));
Path f = new Path(new Path(tmpDir), "testGzipCodecRead.txt.gz");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
new GZIPOutputStream(new FileOutputStream(f.toString())))); new GZIPOutputStream(new FileOutputStream(f.toString()))));
final String msg = "This is the message in the file!"; final String msg = "This is the message in the file!";
@ -801,8 +800,7 @@ public void testGzipLongOverflow() throws IOException {
CodecPool.returnDecompressor(zlibDecompressor); CodecPool.returnDecompressor(zlibDecompressor);
// Now create a GZip text file. // Now create a GZip text file.
String tmpDir = System.getProperty("test.build.data", "/tmp/"); Path f = new Path(GenericTestUtils.getTempPath("testGzipLongOverflow.bin.gz"));
Path f = new Path(new Path(tmpDir), "testGzipLongOverflow.bin.gz");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
new GZIPOutputStream(new FileOutputStream(f.toString())))); new GZIPOutputStream(new FileOutputStream(f.toString()))));
@ -865,9 +863,8 @@ private void testGzipCodecWrite(boolean useNative) throws IOException {
codec instanceof GzipCodec); codec instanceof GzipCodec);
final String msg = "This is the message we are going to compress."; final String msg = "This is the message we are going to compress.";
final String tmpDir = System.getProperty("test.build.data", "/tmp/"); final String fileName = new Path(GenericTestUtils.getTempPath(
final String fileName = new Path(new Path(tmpDir), "testGzipCodecWrite.txt.gz")).toString();
"testGzipCodecWrite.txt.gz").toString();
BufferedWriter w = null; BufferedWriter w = null;
Compressor gzipCompressor = CodecPool.getCompressor(codec); Compressor gzipCompressor = CodecPool.getCompressor(codec);

View File

@ -30,6 +30,7 @@
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.file.tfile.TFile.Reader; 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.Writer;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner; import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
@ -43,8 +44,7 @@
* *
*/ */
public class TestTFile { public class TestTFile {
private static String ROOT = private static String ROOT = GenericTestUtils.getTempPath("tfile-test");
System.getProperty("test.build.data", "/tmp/tfile-test");
private FileSystem fs; private FileSystem fs;
private Configuration conf; private Configuration conf;
private static final int minBlockSize = 512; private static final int minBlockSize = 512;

View File

@ -35,6 +35,7 @@
import org.apache.hadoop.io.file.tfile.TFile.Writer; import org.apache.hadoop.io.file.tfile.TFile.Writer;
import org.apache.hadoop.io.file.tfile.TFile.Reader.Location; import org.apache.hadoop.io.file.tfile.TFile.Reader.Location;
import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner; import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -46,8 +47,7 @@
* *
*/ */
public class TestTFileByteArrays { public class TestTFileByteArrays {
private static String ROOT = private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath();
System.getProperty("test.build.data", "/tmp/tfile-test");
private final static int BLOCK_SIZE = 512; private final static int BLOCK_SIZE = 512;
private final static int BUF_SIZE = 64; private final static int BUF_SIZE = 64;
private final static int K = 1024; private final static int K = 1024;

View File

@ -27,13 +27,13 @@
import org.apache.hadoop.io.BytesWritable; import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.file.tfile.TFile.Writer; import org.apache.hadoop.io.file.tfile.TFile.Writer;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
public class TestTFileComparator2 { public class TestTFileComparator2 {
private static final String ROOT = System.getProperty("test.build.data", private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath();
"/tmp/tfile-test");
private static final String name = "test-tfile-comparator2"; private static final String name = "test-tfile-comparator2";
private final static int BLOCK_SIZE = 512; private final static int BLOCK_SIZE = 512;
private static final String VALUE = "value"; private static final String VALUE = "value";

View File

@ -30,6 +30,7 @@
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.file.tfile.TFile.Writer; import org.apache.hadoop.io.file.tfile.TFile.Writer;
import org.apache.hadoop.test.GenericTestUtils;
/** /**
* *
@ -38,9 +39,7 @@
* *
*/ */
public class TestTFileComparators { public class TestTFileComparators {
private static String ROOT = private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath();
System.getProperty("test.build.data", "/tmp/tfile-test");
private final static int BLOCK_SIZE = 512; private final static int BLOCK_SIZE = 512;
private FileSystem fs; private FileSystem fs;
private Configuration conf; private Configuration conf;

View File

@ -45,6 +45,7 @@
import org.apache.hadoop.io.file.tfile.TFile.Reader; 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.Writer;
import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner; import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner;
import org.apache.hadoop.test.GenericTestUtils;
/** /**
* test the performance for seek. * test the performance for seek.
@ -246,8 +247,7 @@ private static class MyOptions {
int fsOutputBufferSizeLzo = 1; int fsOutputBufferSizeLzo = 1;
int fsOutputBufferSizeGz = 1; int fsOutputBufferSizeGz = 1;
String rootDir = String rootDir = GenericTestUtils.getTestDir().getAbsolutePath();
System.getProperty("test.build.data", "/tmp/tfile-test");
String file = "TestTFileSeek"; String file = "TestTFileSeek";
String compress = "gz"; String compress = "gz";
int minKeyLen = 10; int minKeyLen = 10;

View File

@ -45,6 +45,7 @@
import org.apache.hadoop.io.SequenceFile; import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.compress.CompressionCodec; import org.apache.hadoop.io.compress.CompressionCodec;
import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner.Entry; import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner.Entry;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
public class TestTFileSeqFileComparison { public class TestTFileSeqFileComparison {
@ -516,9 +517,7 @@ private static String parameters2String(MyOptions options) {
} }
private static class MyOptions { private static class MyOptions {
String rootDir = String rootDir = GenericTestUtils.getTestDir().getAbsolutePath();;
System
.getProperty("test.build.data", "/tmp/tfile-test");
String compress = "gz"; String compress = "gz";
String format = "tfile"; String format = "tfile";
int dictSize = 1000; int dictSize = 1000;

View File

@ -32,10 +32,10 @@
import org.apache.hadoop.io.file.tfile.TFile.Reader; 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.Writer;
import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner; import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner;
import org.apache.hadoop.test.GenericTestUtils;
public class TestTFileSplit { public class TestTFileSplit {
private static String ROOT = private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath();
System.getProperty("test.build.data", "/tmp/tfile-test");
private final static int BLOCK_SIZE = 64 * 1024; private final static int BLOCK_SIZE = 64 * 1024;

View File

@ -37,6 +37,7 @@
import org.apache.hadoop.io.file.tfile.TFile.Reader; 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.Writer;
import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner; import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner;
import org.apache.hadoop.test.GenericTestUtils;
/** /**
* *
@ -46,8 +47,7 @@
*/ */
public class TestTFileStreams { public class TestTFileStreams {
private static String ROOT = private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath();
System.getProperty("test.build.data", "/tmp/tfile-test");
private final static int BLOCK_SIZE = 512; private final static int BLOCK_SIZE = 512;
private final static int K = 1024; private final static int K = 1024;

View File

@ -29,13 +29,12 @@
import org.apache.hadoop.io.file.tfile.TFile.Reader; 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.Writer;
import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner; import org.apache.hadoop.io.file.tfile.TFile.Reader.Scanner;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class TestTFileUnsortedByteArrays { public class TestTFileUnsortedByteArrays {
private static String ROOT = private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath();
System.getProperty("test.build.data", "/tmp/tfile-test");
private final static int BLOCK_SIZE = 512; private final static int BLOCK_SIZE = 512;
private final static int BUF_SIZE = 64; private final static int BUF_SIZE = 64;

View File

@ -29,12 +29,12 @@
import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class TestVLong { public class TestVLong {
private static String ROOT = private static String ROOT = GenericTestUtils.getTestDir().getAbsolutePath();
System.getProperty("test.build.data", "/tmp/tfile-test");
private Configuration conf; private Configuration conf;
private FileSystem fs; private FileSystem fs;
private Path path; private Path path;

View File

@ -61,8 +61,7 @@
public class TestNativeIO { public class TestNativeIO {
static final Log LOG = LogFactory.getLog(TestNativeIO.class); static final Log LOG = LogFactory.getLog(TestNativeIO.class);
static final File TEST_DIR = new File( static final File TEST_DIR = GenericTestUtils.getTestDir("testnativeio");
System.getProperty("test.build.data"), "testnativeio");
@Before @Before
public void checkLoaded() { public void checkLoaded() {
@ -516,8 +515,7 @@ public void testGetGroupName() throws IOException {
@Test (timeout = 30000) @Test (timeout = 30000)
public void testRenameTo() throws Exception { public void testRenameTo() throws Exception {
final File TEST_DIR = new File(new File( final File TEST_DIR = GenericTestUtils.getTestDir("renameTest") ;
System.getProperty("test.build.data","build/test/data")), "renameTest");
assumeTrue(TEST_DIR.mkdirs()); assumeTrue(TEST_DIR.mkdirs());
File nonExistentFile = new File(TEST_DIR, "nonexistent"); File nonExistentFile = new File(TEST_DIR, "nonexistent");
File targetFile = new File(TEST_DIR, "target"); File targetFile = new File(TEST_DIR, "target");
@ -566,9 +564,7 @@ public void testRenameTo() throws Exception {
@Test(timeout=10000) @Test(timeout=10000)
public void testMlock() throws Exception { public void testMlock() throws Exception {
assumeTrue(NativeIO.isAvailable()); assumeTrue(NativeIO.isAvailable());
final File TEST_FILE = new File(new File( final File TEST_FILE = GenericTestUtils.getTestDir("testMlockFile");
System.getProperty("test.build.data","build/test/data")),
"testMlockFile");
final int BUF_LEN = 12289; final int BUF_LEN = 12289;
byte buf[] = new byte[BUF_LEN]; byte buf[] = new byte[BUF_LEN];
int bufSum = 0; int bufSum = 0;

View File

@ -31,12 +31,12 @@
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.test.GenericTestUtils;
public class TestSharedFileDescriptorFactory { public class TestSharedFileDescriptorFactory {
static final Log LOG = LogFactory.getLog(TestSharedFileDescriptorFactory.class); static final Log LOG = LogFactory.getLog(TestSharedFileDescriptorFactory.class);
private static final File TEST_BASE = private static final File TEST_BASE = GenericTestUtils.getTestDir();
new File(System.getProperty("test.build.data", "/tmp"));
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {

View File

@ -53,6 +53,7 @@
import org.apache.hadoop.metrics2.impl.TestMetricsConfig; import org.apache.hadoop.metrics2.impl.TestMetricsConfig;
import org.apache.hadoop.metrics2.lib.MutableGaugeInt; import org.apache.hadoop.metrics2.lib.MutableGaugeInt;
import org.apache.hadoop.metrics2.lib.MutableGaugeLong; import org.apache.hadoop.metrics2.lib.MutableGaugeLong;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Rule; import org.junit.Rule;
import org.junit.rules.TestName; import org.junit.rules.TestName;
@ -68,9 +69,8 @@
public class RollingFileSystemSinkTestBase { public class RollingFileSystemSinkTestBase {
protected static final String SINK_PRINCIPAL_KEY = "rfssink.principal"; protected static final String SINK_PRINCIPAL_KEY = "rfssink.principal";
protected static final String SINK_KEYTAB_FILE_KEY = "rfssink.keytab"; protected static final String SINK_KEYTAB_FILE_KEY = "rfssink.keytab";
protected static final File ROOT_TEST_DIR = protected static final File ROOT_TEST_DIR = GenericTestUtils.getTestDir(
new File(System.getProperty("test.build.data", "target/test"), "RollingFileSystemSinkTest");
"RollingFileSystemSinkTest");
protected static final SimpleDateFormat DATE_FORMAT = protected static final SimpleDateFormat DATE_FORMAT =
new SimpleDateFormat("yyyyMMddHH"); new SimpleDateFormat("yyyyMMddHH");
protected static File methodDir; protected static File methodDir;

View File

@ -40,6 +40,7 @@
import org.apache.hadoop.security.Credentials; import org.apache.hadoop.security.Credentials;
import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.Token;
import org.apache.hadoop.security.token.TokenIdentifier; import org.apache.hadoop.security.token.TokenIdentifier;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -47,8 +48,7 @@
public class TestCredentials { public class TestCredentials {
private static final String DEFAULT_HMAC_ALGORITHM = "HmacSHA1"; private static final String DEFAULT_HMAC_ALGORITHM = "HmacSHA1";
private static final File tmpDir = private static final File tmpDir = GenericTestUtils.getTestDir("mapred");
new File(System.getProperty("test.build.data", "/tmp"), "mapred");
@Before @Before
public void setUp() { public void setUp() {

View File

@ -38,6 +38,7 @@
import org.apache.hadoop.security.alias.CredentialProvider; import org.apache.hadoop.security.alias.CredentialProvider;
import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.apache.hadoop.security.alias.CredentialProviderFactory;
import org.apache.hadoop.security.alias.JavaKeyStoreProvider; import org.apache.hadoop.security.alias.JavaKeyStoreProvider;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -108,8 +109,7 @@ private void doTestGetGroups(List<String> expectedGroups, int searchTimes) throw
@Test @Test
public void testExtractPassword() throws IOException { public void testExtractPassword() throws IOException {
File testDir = new File(System.getProperty("test.build.data", File testDir = GenericTestUtils.getTestDir();
"target/test-dir"));
testDir.mkdirs(); testDir.mkdirs();
File secretFile = new File(testDir, "secret.txt"); File secretFile = new File(testDir, "secret.txt");
Writer writer = new FileWriter(secretFile); Writer writer = new FileWriter(secretFile);
@ -123,8 +123,7 @@ public void testExtractPassword() throws IOException {
@Test @Test
public void testConfGetPassword() throws Exception { public void testConfGetPassword() throws Exception {
File testDir = new File(System.getProperty("test.build.data", File testDir = GenericTestUtils.getTestDir();
"target/test-dir"));
Configuration conf = new Configuration(); Configuration conf = new Configuration();
final Path jksPath = new Path(testDir.toString(), "test.jks"); final Path jksPath = new Path(testDir.toString(), "test.jks");
final String ourUrl = final String ourUrl =

View File

@ -30,14 +30,14 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class TestCredShell { public class TestCredShell {
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private static final File tmpDir = private static final File tmpDir = GenericTestUtils.getTestDir("creds");
new File(System.getProperty("test.build.data", "/tmp"), "creds");
/* The default JCEKS provider - for testing purposes */ /* The default JCEKS provider - for testing purposes */
private String jceksProvider; private String jceksProvider;

View File

@ -34,7 +34,7 @@
import org.apache.hadoop.security.Credentials; import org.apache.hadoop.security.Credentials;
import org.apache.hadoop.security.ProviderUtils; import org.apache.hadoop.security.ProviderUtils;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -61,8 +61,7 @@ public void announce() {
'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'2', '3', '4', '5', '6', '7', '8', '9',}; '2', '3', '4', '5', '6', '7', '8', '9',};
private static final File tmpDir = private static final File tmpDir = GenericTestUtils.getTestDir("creds");
new File(System.getProperty("test.build.data", "/tmp"), "creds");
@Test @Test
public void testFactory() throws Exception { public void testFactory() throws Exception {

View File

@ -23,6 +23,7 @@
import org.apache.hadoop.security.alias.CredentialProvider; import org.apache.hadoop.security.alias.CredentialProvider;
import org.apache.hadoop.security.alias.CredentialProviderFactory; import org.apache.hadoop.security.alias.CredentialProviderFactory;
import org.apache.hadoop.security.alias.JavaKeyStoreProvider; import org.apache.hadoop.security.alias.JavaKeyStoreProvider;
import org.apache.hadoop.test.GenericTestUtils;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -470,8 +471,7 @@ public static void saveConfig(File file, Configuration conf)
} }
public static void provisionPasswordsToCredentialProvider() throws Exception { public static void provisionPasswordsToCredentialProvider() throws Exception {
File testDir = new File(System.getProperty("test.build.data", File testDir = GenericTestUtils.getTestDir();
"target/test-dir"));
Configuration conf = new Configuration(); Configuration conf = new Configuration();
final Path jksPath = new Path(testDir.toString(), "test.jks"); final Path jksPath = new Path(testDir.toString(), "test.jks");

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.security.ssl; package org.apache.hadoop.security.ssl;
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -37,9 +38,8 @@
public class TestReloadingX509TrustManager { public class TestReloadingX509TrustManager {
private static final String BASEDIR = private static final String BASEDIR = GenericTestUtils.getTempPath(
System.getProperty("test.build.data", "target/test-dir") + "/" + TestReloadingX509TrustManager.class.getSimpleName());
TestReloadingX509TrustManager.class.getSimpleName();
private X509Certificate cert1; private X509Certificate cert1;
private X509Certificate cert2; private X509Certificate cert2;

View File

@ -52,8 +52,7 @@ public class TestSSLFactory {
private static final Logger LOG = LoggerFactory private static final Logger LOG = LoggerFactory
.getLogger(TestSSLFactory.class); .getLogger(TestSSLFactory.class);
private static final String BASEDIR = private static final String BASEDIR =
System.getProperty("test.build.dir", "target/test-dir") + "/" + GenericTestUtils.getTempPath(TestSSLFactory.class.getSimpleName());
TestSSLFactory.class.getSimpleName();
private static final String KEYSTORES_DIR = private static final String KEYSTORES_DIR =
new File(BASEDIR).getAbsolutePath(); new File(BASEDIR).getAbsolutePath();
private String sslConfsDir; private String sslConfsDir;
@ -433,8 +432,7 @@ private void checkSSLFactoryInitWithPasswords(SSLFactory.Mode mode,
sslConf = KeyStoreTestUtil.createServerSSLConfig(keystore, confPassword, sslConf = KeyStoreTestUtil.createServerSSLConfig(keystore, confPassword,
confKeyPassword, truststore); confKeyPassword, truststore);
if (useCredProvider) { if (useCredProvider) {
File testDir = new File(System.getProperty("test.build.data", File testDir = GenericTestUtils.getTestDir();
"target/test-dir"));
final Path jksPath = new Path(testDir.toString(), "test.jks"); final Path jksPath = new Path(testDir.toString(), "test.jks");
final String ourUrl = final String ourUrl =
JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri(); JavaKeyStoreProvider.SCHEME_NAME + "://file" + jksPath.toUri();

View File

@ -20,7 +20,6 @@
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.StringWriter; import java.io.StringWriter;
@ -37,10 +36,10 @@
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.Log4JLogger; import org.apache.commons.logging.impl.Log4JLogger;
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.util.NativeCodeLoader;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
import org.apache.log4j.Layout; import org.apache.log4j.Layout;
@ -64,6 +63,22 @@ public abstract class GenericTestUtils {
private static final AtomicInteger sequence = new AtomicInteger(); 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") @SuppressWarnings("unchecked")
public static void disableLog(Log log) { public static void disableLog(Log log) {
// We expect that commons-logging is a wrapper around Log4j. // We expect that commons-logging is a wrapper around Log4j.
@ -119,7 +134,70 @@ public static String getMethodName() {
public static int uniqueSequenceId() { public static int uniqueSequenceId() {
return sequence.incrementAndGet(); 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. * Assert that a given file exists.
*/ */

View File

@ -31,6 +31,8 @@
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; 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 * 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 * classpath, it creates a Jar on the fly with the contents of the directory
@ -152,7 +154,7 @@ else if ("file".equals(url.getProtocol())) {
klassName = klassName.replace(".", "/") + ".class"; klassName = klassName.replace(".", "/") + ".class";
path = path.substring(0, path.length() - klassName.length()); path = path.substring(0, path.length() - klassName.length());
File baseDir = new File(path); File baseDir = new File(path);
File testDir = new File(System.getProperty("test.build.dir", "target/test-dir")); File testDir = GenericTestUtils.getTestDir();
testDir = testDir.getAbsoluteFile(); testDir = testDir.getAbsoluteFile();
if (!testDir.exists()) { if (!testDir.exists()) {
testDir.mkdirs(); testDir.mkdirs();

View File

@ -37,6 +37,7 @@
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -45,8 +46,7 @@
public class TestApplicationClassLoader { public class TestApplicationClassLoader {
private static File testDir = new File(System.getProperty("test.build.data", private static File testDir = GenericTestUtils.getTestDir("appclassloader");
System.getProperty("java.io.tmpdir")), "appclassloader");
@Before @Before
public void setUp() { public void setUp() {

View File

@ -32,6 +32,7 @@
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -42,8 +43,8 @@
public class TestClasspath { public class TestClasspath {
private static final Log LOG = LogFactory.getLog(TestClasspath.class); private static final Log LOG = LogFactory.getLog(TestClasspath.class);
private static final File TEST_DIR = new File( private static final File TEST_DIR = GenericTestUtils.getTestDir(
System.getProperty("test.build.data", "/tmp"), "TestClasspath"); "TestClasspath");
private static final Charset UTF8 = Charset.forName("UTF-8"); private static final Charset UTF8 = Charset.forName("UTF-8");
static { static {

View File

@ -199,7 +199,7 @@ protected void setUp() throws Exception {
super.setUp(); super.setUp();
conf = new Configuration(); conf = new Configuration();
localFs = FileSystem.getLocal(conf); localFs = FileSystem.getLocal(conf);
testDir = new File(System.getProperty("test.build.data", "/tmp"), "generic"); testDir = GenericTestUtils.getTestDir("generic");
if(testDir.exists()) if(testDir.exists())
localFs.delete(new Path(testDir.toString()), true); localFs.delete(new Path(testDir.toString()), true);
} }

View File

@ -21,6 +21,7 @@
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileWriter; import java.io.FileWriter;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.*; import org.junit.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -31,8 +32,7 @@
public class TestHostsFileReader { public class TestHostsFileReader {
// Using /test/build/data/tmp directory to store temprory files // Using /test/build/data/tmp directory to store temprory files
final String HOSTS_TEST_DIR = new File(System.getProperty( final String HOSTS_TEST_DIR = GenericTestUtils.getTestDir().getAbsolutePath();
"test.build.data", "/tmp")).getAbsolutePath();
File EXCLUDES_FILE = new File(HOSTS_TEST_DIR, "dfs.exclude"); File EXCLUDES_FILE = new File(HOSTS_TEST_DIR, "dfs.exclude");
File INCLUDES_FILE = new File(HOSTS_TEST_DIR, "dfs.include"); File INCLUDES_FILE = new File(HOSTS_TEST_DIR, "dfs.include");
String excludesFile = HOSTS_TEST_DIR + "/dfs.exclude"; String excludesFile = HOSTS_TEST_DIR + "/dfs.exclude";

View File

@ -19,6 +19,7 @@
package org.apache.hadoop.util; package org.apache.hadoop.util;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
@ -79,8 +80,8 @@ public void testExpandedClasspath() throws Exception {
@Test @Test
public void testExistingManifest() throws Exception { public void testExistingManifest() throws Exception {
File dir = new File(System.getProperty("test.build.dir", "target/test-dir"), File dir = GenericTestUtils
TestJarFinder.class.getName() + "-testExistingManifest"); .getTestDir(TestJarFinder.class.getName() + "-testExistingManifest");
delete(dir); delete(dir);
dir.mkdirs(); dir.mkdirs();
@ -107,8 +108,8 @@ public void testExistingManifest() throws Exception {
@Test @Test
public void testNoManifest() throws Exception { public void testNoManifest() throws Exception {
File dir = new File(System.getProperty("test.build.dir", "target/test-dir"), File dir = GenericTestUtils
TestJarFinder.class.getName() + "-testNoManifest"); .getTestDir(TestJarFinder.class.getName() + "-testNoManifest");
delete(dir); delete(dir);
dir.mkdirs(); dir.mkdirs();
File propsFile = new File(dir, "props.properties"); File propsFile = new File(dir, "props.properties");

View File

@ -32,6 +32,7 @@
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -44,11 +45,8 @@ public class TestRunJar extends TestCase {
@Override @Override
@Before @Before
protected void setUp() protected void setUp() throws Exception {
throws Exception { TEST_ROOT_DIR = GenericTestUtils.getTestDir(getClass().getSimpleName());
TEST_ROOT_DIR =
new File(System.getProperty("test.build.data", "/tmp"), getClass()
.getSimpleName());
if (!TEST_ROOT_DIR.exists()) { if (!TEST_ROOT_DIR.exists()) {
TEST_ROOT_DIR.mkdirs(); TEST_ROOT_DIR.mkdirs();
} }

View File

@ -31,6 +31,8 @@
import java.lang.management.ThreadMXBean; import java.lang.management.ThreadMXBean;
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.test.GenericTestUtils;
import static org.apache.hadoop.util.Shell.*; import static org.apache.hadoop.util.Shell.*;
import org.junit.Assume; import org.junit.Assume;
import org.junit.Before; import org.junit.Before;
@ -49,7 +51,7 @@ public class TestShell extends Assert {
@Rule @Rule
public TestName methodName = new TestName(); 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 * A filename generated uniquely for each test method. The file

View File

@ -25,6 +25,7 @@
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -63,8 +64,8 @@ int readDiskBlockInformation(String diskName, int defSector) {
} }
} }
private static final FakeLinuxResourceCalculatorPlugin plugin; private static final FakeLinuxResourceCalculatorPlugin plugin;
private static String TEST_ROOT_DIR = new Path(System.getProperty( private static String TEST_ROOT_DIR = GenericTestUtils.getTestDir()
"test.build.data", "/tmp")).toString().replace(' ', '+'); .getAbsolutePath();
private static final String FAKE_MEMFILE; private static final String FAKE_MEMFILE;
private static final String FAKE_CPUFILE; private static final String FAKE_CPUFILE;
private static final String FAKE_STATFILE; private static final String FAKE_STATFILE;

View File

@ -32,6 +32,7 @@
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.test.GenericTestUtils;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -44,8 +45,8 @@
public class TestWinUtils { public class TestWinUtils {
private static final Log LOG = LogFactory.getLog(TestWinUtils.class); private static final Log LOG = LogFactory.getLog(TestWinUtils.class);
private static File TEST_DIR = new File(System.getProperty("test.build.data", private static File TEST_DIR = GenericTestUtils.getTestDir(
"target"+File.pathSeparator + "tmp"), TestWinUtils.class.getSimpleName()); TestWinUtils.class.getSimpleName());
String winutils; String winutils;

View File

@ -24,6 +24,7 @@
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.ZKUtil.BadAclFormatException; import org.apache.hadoop.util.ZKUtil.BadAclFormatException;
import org.apache.hadoop.util.ZKUtil.ZKAuthInfo; import org.apache.hadoop.util.ZKUtil.ZKAuthInfo;
import org.apache.zookeeper.ZooDefs.Perms; import org.apache.zookeeper.ZooDefs.Perms;
@ -34,8 +35,8 @@
import com.google.common.io.Files; import com.google.common.io.Files;
public class TestZKUtil { public class TestZKUtil {
private static final String TEST_ROOT_DIR = System.getProperty( private static final String TEST_ROOT_DIR = GenericTestUtils.getTempPath(
"test.build.data", "/tmp") + "/TestZKUtil"; "TestZKUtil");
private static final File TEST_FILE = new File(TEST_ROOT_DIR, private static final File TEST_FILE = new File(TEST_ROOT_DIR,
"test-file"); "test-file");