HADOOP-9287. Parallel-testing hadoop-common. Contributed by Andrey Klochkov

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1489250 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason Darrell Lowe 2013-06-04 00:29:37 +00:00
parent 198cb3ebdd
commit eb7af141e4
57 changed files with 562 additions and 363 deletions

View File

@ -95,6 +95,8 @@ Release 2.1.0-beta - UNRELEASED
HADOOP-7391 Document Interface Classification from HADOOP-5073 (sanjay Radia) HADOOP-7391 Document Interface Classification from HADOOP-5073 (sanjay Radia)
HADOOP-9287. Parallel-testing hadoop-common (Andrey Klochkov via jlowe)
OPTIMIZATIONS OPTIMIZATIONS
HADOOP-9150. Avoid unnecessary DNS resolution attempts for logical URIs HADOOP-9150. Avoid unnecessary DNS resolution attempts for logical URIs

View File

@ -653,5 +653,22 @@
</plugins> </plugins>
</build> </build>
</profile> </profile>
<profile>
<id>parallel-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>perthread</forkMode>
<threadCount>${testsThreadCount}</threadCount>
<parallel>classes</parallel>
<argLine>-Xmx1024m -XX:+HeapDumpOnOutOfMemoryError -DminiClusterDedicatedDirs=true</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles> </profiles>
</project> </project>

View File

@ -39,6 +39,7 @@
import junit.framework.TestCase; import junit.framework.TestCase;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration.IntegerRanges; import org.apache.hadoop.conf.Configuration.IntegerRanges;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
@ -49,8 +50,8 @@
public class TestConfiguration extends TestCase { public class TestConfiguration extends TestCase {
private Configuration conf; private Configuration conf;
final static String CONFIG = new File("./test-config.xml").getAbsolutePath(); final static String CONFIG = new File("./test-config-TestConfiguration.xml").getAbsolutePath();
final static String CONFIG2 = new File("./test-config2.xml").getAbsolutePath(); final static String CONFIG2 = new File("./test-config2-TestConfiguration.xml").getAbsolutePath();
final static Random RAN = new Random(); final static Random RAN = new Random();
final static String XMLHEADER = final static String XMLHEADER =
IBM_JAVA?"<?xml version=\"1.0\" encoding=\"UTF-8\"?><configuration>": IBM_JAVA?"<?xml version=\"1.0\" encoding=\"UTF-8\"?><configuration>":

View File

@ -36,11 +36,9 @@
public class TestConfigurationDeprecation { public class TestConfigurationDeprecation {
private Configuration conf; private Configuration conf;
final static String CONFIG = new File("./test-config.xml").getAbsolutePath(); final static String CONFIG = new File("./test-config-TestConfigurationDeprecation.xml").getAbsolutePath();
final static String CONFIG2 = final static String CONFIG2 = new File("./test-config2-TestConfigurationDeprecation.xml").getAbsolutePath();
new File("./test-config2.xml").getAbsolutePath(); final static String CONFIG3 = new File("./test-config3-TestConfigurationDeprecation.xml").getAbsolutePath();
final static String CONFIG3 =
new File("./test-config3.xml").getAbsolutePath();
BufferedWriter out; BufferedWriter out;
static { static {

View File

@ -39,6 +39,8 @@ public abstract class FCStatisticsBaseTest {
static protected int blockSize = 512; static protected int blockSize = 512;
static protected int numBlocks = 1; static protected int numBlocks = 1;
protected final FileContextTestHelper fileContextTestHelper = new FileContextTestHelper();
//fc should be set appropriately by the deriving test. //fc should be set appropriately by the deriving test.
protected static FileContext fc = null; protected static FileContext fc = null;
@ -47,7 +49,7 @@ public void testStatistics() throws IOException, URISyntaxException {
URI fsUri = getFsUri(); URI fsUri = getFsUri();
Statistics stats = FileContext.getStatistics(fsUri); Statistics stats = FileContext.getStatistics(fsUri);
Assert.assertEquals(0, stats.getBytesRead()); Assert.assertEquals(0, stats.getBytesRead());
Path filePath = getTestRootPath(fc, "file1"); Path filePath = fileContextTestHelper .getTestRootPath(fc, "file1");
createFile(fc, filePath, numBlocks, blockSize); createFile(fc, filePath, numBlocks, blockSize);
Assert.assertEquals(0, stats.getBytesRead()); Assert.assertEquals(0, stats.getBytesRead());

View File

@ -34,8 +34,6 @@
import org.junit.Test; import org.junit.Test;
import org.mortbay.log.Log; import org.mortbay.log.Log;
import static org.apache.hadoop.fs.FileSystemTestHelper.*;
/** /**
* <p> * <p>
* A collection of tests for the {@link FileSystem}. * A collection of tests for the {@link FileSystem}.
@ -55,7 +53,7 @@
* @AfterClass public static void ClusterShutdownAtEnd() * @AfterClass public static void ClusterShutdownAtEnd()
* </p> * </p>
*/ */
public abstract class FSMainOperationsBaseTest { public abstract class FSMainOperationsBaseTest extends FileSystemTestHelper {
private static String TEST_DIR_AAA2 = "test/hadoop2/aaa"; private static String TEST_DIR_AAA2 = "test/hadoop2/aaa";
private static String TEST_DIR_AAA = "test/hadoop/aaa"; private static String TEST_DIR_AAA = "test/hadoop/aaa";
@ -64,7 +62,7 @@ public abstract class FSMainOperationsBaseTest {
private static int numBlocks = 2; private static int numBlocks = 2;
protected static FileSystem fSys; protected FileSystem fSys;
final private static PathFilter DEFAULT_FILTER = new PathFilter() { final private static PathFilter DEFAULT_FILTER = new PathFilter() {
@Override @Override
@ -87,8 +85,18 @@ public boolean accept(Path file) {
protected static final byte[] data = getFileData(numBlocks, protected static final byte[] data = getFileData(numBlocks,
getDefaultBlockSize()); getDefaultBlockSize());
abstract protected FileSystem createFileSystem() throws Exception;
public FSMainOperationsBaseTest() {
}
public FSMainOperationsBaseTest(String testRootDir) {
super(testRootDir);
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
fSys = createFileSystem();
fSys.mkdirs(getTestRootPath(fSys, "test")); fSys.mkdirs(getTestRootPath(fSys, "test"));
} }
@ -157,7 +165,7 @@ public void testWorkingDirectory() throws Exception {
// Now open a file relative to the wd we just set above. // Now open a file relative to the wd we just set above.
Path absolutePath = new Path(absoluteDir, "foo"); Path absolutePath = new Path(absoluteDir, "foo");
FileSystemTestHelper.createFile(fSys, absolutePath); createFile(fSys, absolutePath);
fSys.open(new Path("foo")).close(); fSys.open(new Path("foo")).close();
@ -308,11 +316,11 @@ public void testListStatus() throws Exception {
paths = fSys.listStatus(getTestRootPath(fSys, "test/hadoop")); paths = fSys.listStatus(getTestRootPath(fSys, "test/hadoop"));
Assert.assertEquals(3, paths.length); Assert.assertEquals(3, paths.length);
Assert.assertTrue(containsPath(getTestRootPath(fSys, "test/hadoop/a"), Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, "test/hadoop/a"),
paths)); paths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, "test/hadoop/b"), Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, "test/hadoop/b"),
paths)); paths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, "test/hadoop/c"), Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, "test/hadoop/c"),
paths)); paths));
paths = fSys.listStatus(getTestRootPath(fSys, "test/hadoop/a")); paths = fSys.listStatus(getTestRootPath(fSys, "test/hadoop/a"));
@ -359,9 +367,9 @@ public void testListStatusFilterWithSomeMatches() throws Exception {
FileStatus[] filteredPaths = fSys.listStatus( FileStatus[] filteredPaths = fSys.listStatus(
getTestRootPath(fSys, "test/hadoop"), TEST_X_FILTER); getTestRootPath(fSys, "test/hadoop"), TEST_X_FILTER);
Assert.assertEquals(2,filteredPaths.length); Assert.assertEquals(2,filteredPaths.length);
Assert.assertTrue(containsPath(getTestRootPath(fSys, Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys,
TEST_DIR_AXA), filteredPaths)); TEST_DIR_AXA), filteredPaths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys,
TEST_DIR_AXX), filteredPaths)); TEST_DIR_AXX), filteredPaths));
} }
@ -417,9 +425,9 @@ public void testGlobStatusSomeMatchesInDirectories() throws Exception {
FileStatus[] paths = fSys.globStatus( FileStatus[] paths = fSys.globStatus(
getTestRootPath(fSys, "test/hadoop*")); getTestRootPath(fSys, "test/hadoop*"));
Assert.assertEquals(2, paths.length); Assert.assertEquals(2, paths.length);
Assert.assertTrue(containsPath(getTestRootPath(fSys, Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys,
"test/hadoop"), paths)); "test/hadoop"), paths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys,
"test/hadoop2"), paths)); "test/hadoop2"), paths));
} }
@ -442,10 +450,10 @@ public void testGlobStatusWithMultipleWildCardMatches() throws Exception {
FileStatus[] paths = fSys.globStatus( FileStatus[] paths = fSys.globStatus(
getTestRootPath(fSys, "test/hadoop*/*")); getTestRootPath(fSys, "test/hadoop*/*"));
Assert.assertEquals(4, paths.length); Assert.assertEquals(4, paths.length);
Assert.assertTrue(containsPath(getTestRootPath(fSys, TEST_DIR_AAA), paths)); Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AAA), paths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, TEST_DIR_AXA), paths)); Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA), paths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, TEST_DIR_AXX), paths)); Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX), paths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, TEST_DIR_AAA2), paths)); Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AAA2), paths));
} }
@Test @Test
@ -466,9 +474,9 @@ public void testGlobStatusWithMultipleMatchesOfSingleChar() throws Exception {
FileStatus[] paths = fSys.globStatus( FileStatus[] paths = fSys.globStatus(
getTestRootPath(fSys, "test/hadoop/ax?")); getTestRootPath(fSys, "test/hadoop/ax?"));
Assert.assertEquals(2, paths.length); Assert.assertEquals(2, paths.length);
Assert.assertTrue(containsPath(getTestRootPath(fSys, Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys,
TEST_DIR_AXA), paths)); TEST_DIR_AXA), paths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys,
TEST_DIR_AXX), paths)); TEST_DIR_AXX), paths));
} }
@ -513,11 +521,11 @@ public void testGlobStatusFilterWithSomePathMatchesAndTrivialFilter()
getTestRootPath(fSys, "test/hadoop/*"), getTestRootPath(fSys, "test/hadoop/*"),
DEFAULT_FILTER); DEFAULT_FILTER);
Assert.assertEquals(3, filteredPaths.length); Assert.assertEquals(3, filteredPaths.length);
Assert.assertTrue(containsPath(getTestRootPath(fSys, Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys,
TEST_DIR_AAA), filteredPaths)); TEST_DIR_AAA), filteredPaths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys,
TEST_DIR_AXA), filteredPaths)); TEST_DIR_AXA), filteredPaths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys,
TEST_DIR_AXX), filteredPaths)); TEST_DIR_AXX), filteredPaths));
} }
@ -541,11 +549,11 @@ public void testGlobStatusFilterWithMultipleWildCardMatchesAndTrivialFilter()
getTestRootPath(fSys, "test/hadoop/a??"), getTestRootPath(fSys, "test/hadoop/a??"),
DEFAULT_FILTER); DEFAULT_FILTER);
Assert.assertEquals(3, filteredPaths.length); Assert.assertEquals(3, filteredPaths.length);
Assert.assertTrue(containsPath(getTestRootPath(fSys, TEST_DIR_AAA), Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AAA),
filteredPaths)); filteredPaths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, TEST_DIR_AXA), Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA),
filteredPaths)); filteredPaths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, TEST_DIR_AXX), Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX),
filteredPaths)); filteredPaths));
} }
@ -569,9 +577,9 @@ public void testGlobStatusFilterWithMultiplePathMatchesAndNonTrivialFilter()
getTestRootPath(fSys, "test/hadoop/*"), getTestRootPath(fSys, "test/hadoop/*"),
TEST_X_FILTER); TEST_X_FILTER);
Assert.assertEquals(2, filteredPaths.length); Assert.assertEquals(2, filteredPaths.length);
Assert.assertTrue(containsPath(getTestRootPath(fSys, Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys,
TEST_DIR_AXA), filteredPaths)); TEST_DIR_AXA), filteredPaths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys,
TEST_DIR_AXX), filteredPaths)); TEST_DIR_AXX), filteredPaths));
} }
@ -617,9 +625,9 @@ public void testGlobStatusFilterWithMultiplePathWildcardsAndNonTrivialFilter()
getTestRootPath(fSys, "test/hadoop/a??"), getTestRootPath(fSys, "test/hadoop/a??"),
TEST_X_FILTER); TEST_X_FILTER);
Assert.assertEquals(2, filteredPaths.length); Assert.assertEquals(2, filteredPaths.length);
Assert.assertTrue(containsPath(getTestRootPath(fSys, TEST_DIR_AXA), Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXA),
filteredPaths)); filteredPaths));
Assert.assertTrue(containsPath(getTestRootPath(fSys, TEST_DIR_AXX), Assert.assertTrue(containsTestRootPath(getTestRootPath(fSys, TEST_DIR_AXX),
filteredPaths)); filteredPaths));
} }
@ -1090,9 +1098,9 @@ public void testGetWrappedInputStream() throws IOException {
public void testCopyToLocalWithUseRawLocalFileSystemOption() throws Exception { public void testCopyToLocalWithUseRawLocalFileSystemOption() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
FileSystem fSys = new RawLocalFileSystem(); FileSystem fSys = new RawLocalFileSystem();
Path fileToFS = new Path(TEST_ROOT_DIR, "fs.txt"); Path fileToFS = new Path(getTestRootDir(), "fs.txt");
Path fileToLFS = new Path(TEST_ROOT_DIR, "test.txt"); Path fileToLFS = new Path(getTestRootDir(), "test.txt");
Path crcFileAtLFS = new Path(TEST_ROOT_DIR, ".test.txt.crc"); Path crcFileAtLFS = new Path(getTestRootDir(), ".test.txt.crc");
fSys.initialize(new URI("file:///"), conf); fSys.initialize(new URI("file:///"), conf);
writeFile(fSys, fileToFS); writeFile(fSys, fileToFS);
if (fSys.exists(crcFileAtLFS)) if (fSys.exists(crcFileAtLFS))
@ -1112,7 +1120,7 @@ private void writeFile(FileSystem fs, Path name) throws IOException {
} }
protected void createFile(Path path) throws IOException { protected void createFile(Path path) throws IOException {
FileSystemTestHelper.createFile(fSys, path); createFile(fSys, path);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -1125,10 +1133,11 @@ private void rename(Path src, Path dst, boolean renameShouldSucceed,
Assert.assertEquals("Source exists", srcExists, exists(fSys, src)); Assert.assertEquals("Source exists", srcExists, exists(fSys, src));
Assert.assertEquals("Destination exists", dstExists, exists(fSys, dst)); Assert.assertEquals("Destination exists", dstExists, exists(fSys, dst));
} }
private boolean containsPath(Path path, FileStatus[] filteredPaths) private boolean containsTestRootPath(Path path, FileStatus[] filteredPaths)
throws IOException { throws IOException {
Path testRootPath = getTestRootPath(fSys, path.toString());
for(int i = 0; i < filteredPaths.length; i ++) { for(int i = 0; i < filteredPaths.length; i ++) {
if (getTestRootPath(fSys, path.toString()).equals( if (testRootPath.equals(
filteredPaths[i].getPath())) filteredPaths[i].getPath()))
return true; return true;
} }

View File

@ -51,6 +51,7 @@
public abstract class FileContextCreateMkdirBaseTest { public abstract class FileContextCreateMkdirBaseTest {
protected final FileContextTestHelper fileContextTestHelper;
protected static FileContext fc; protected static FileContext fc;
{ {
@ -63,6 +64,13 @@ public abstract class FileContextCreateMkdirBaseTest {
} }
} }
public FileContextCreateMkdirBaseTest() {
fileContextTestHelper = createFileContextHelper();
}
protected FileContextTestHelper createFileContextHelper() {
return new FileContextTestHelper();
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -149,4 +157,13 @@ public void testCreateRecursiveWithNonExistingDir() throws IOException {
createFile(fc, f); createFile(fc, f);
Assert.assertTrue(isFile(fc, f)); Assert.assertTrue(isFile(fc, f));
} }
private Path getTestRootPath(FileContext fc) {
return fileContextTestHelper.getTestRootPath(fc);
}
private Path getTestRootPath(FileContext fc, String pathString) {
return fileContextTestHelper.getTestRootPath(fc, pathString);
}
} }

View File

@ -23,6 +23,7 @@
import java.io.IOException; import java.io.IOException;
import java.util.EnumSet; import java.util.EnumSet;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.hadoop.HadoopIllegalArgumentException; import org.apache.hadoop.HadoopIllegalArgumentException;
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;
@ -62,16 +63,9 @@ public abstract class FileContextMainOperationsBaseTest {
private static String TEST_DIR_AXX = "test/hadoop/axx"; private static String TEST_DIR_AXX = "test/hadoop/axx";
private static int numBlocks = 2; private static int numBlocks = 2;
public static final Path LOCAL_FS_ROOT_PATH; public Path localFsRootPath;
static {
File testBuildData = new File(System.getProperty("test.build.data",
"build/test/data"));
Path localFsRootPath = new Path(testBuildData.getAbsolutePath(),
"root-uri");
LOCAL_FS_ROOT_PATH = localFsRootPath.makeQualified(LocalFileSystem.NAME, null);
}
protected final FileContextTestHelper fileContextTestHelper = new FileContextTestHelper();
protected static FileContext fc; protected static FileContext fc;
final private static PathFilter DEFAULT_FILTER = new PathFilter() { final private static PathFilter DEFAULT_FILTER = new PathFilter() {
@ -97,13 +91,18 @@ 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",
"build/test/data"), RandomStringUtils.randomAlphanumeric(10));
Path rootPath = new Path(testBuildData.getAbsolutePath(),
"root-uri");
localFsRootPath = rootPath.makeQualified(LocalFileSystem.NAME, null);
fc.mkdir(getTestRootPath(fc, "test"), FileContext.DEFAULT_PERM, true); fc.mkdir(getTestRootPath(fc, "test"), FileContext.DEFAULT_PERM, true);
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
fc.delete(new Path(getAbsoluteTestRootPath(fc), new Path("test")), true); fc.delete(new Path(fileContextTestHelper.getAbsoluteTestRootPath(fc), new Path("test")), true);
fc.delete(LOCAL_FS_ROOT_PATH, true); fc.delete(localFsRootPath, true);
} }
@ -136,7 +135,7 @@ public void testFsStatus() throws Exception {
public void testWorkingDirectory() throws Exception { public void testWorkingDirectory() throws Exception {
// First we cd to our test root // First we cd to our test root
Path workDir = new Path(getAbsoluteTestRootPath(fc), new Path("test")); Path workDir = new Path(fileContextTestHelper.getAbsoluteTestRootPath(fc), new Path("test"));
fc.setWorkingDirectory(workDir); fc.setWorkingDirectory(workDir);
Assert.assertEquals(workDir, fc.getWorkingDirectory()); Assert.assertEquals(workDir, fc.getWorkingDirectory());
@ -149,7 +148,7 @@ public void testWorkingDirectory() throws Exception {
// cd using a relative path // cd using a relative path
// Go back to our test root // Go back to our test root
workDir = new Path(getAbsoluteTestRootPath(fc), new Path("test")); workDir = new Path(fileContextTestHelper.getAbsoluteTestRootPath(fc), new Path("test"));
fc.setWorkingDirectory(workDir); fc.setWorkingDirectory(workDir);
Assert.assertEquals(workDir, fc.getWorkingDirectory()); Assert.assertEquals(workDir, fc.getWorkingDirectory());
@ -184,7 +183,7 @@ public void testWorkingDirectory() throws Exception {
// Try a URI // Try a URI
absoluteDir = new Path(LOCAL_FS_ROOT_PATH, "existingDir"); absoluteDir = new Path(localFsRootPath, "existingDir");
fc.mkdir(absoluteDir, FileContext.DEFAULT_PERM, true); fc.mkdir(absoluteDir, FileContext.DEFAULT_PERM, true);
fc.setWorkingDirectory(absoluteDir); fc.setWorkingDirectory(absoluteDir);
Assert.assertEquals(absoluteDir, fc.getWorkingDirectory()); Assert.assertEquals(absoluteDir, fc.getWorkingDirectory());
@ -1181,6 +1180,7 @@ private void rename(Path src, Path dst, boolean renameShouldSucceed,
Assert.assertEquals("Source exists", srcExists, exists(fc, src)); Assert.assertEquals("Source exists", srcExists, exists(fc, src));
Assert.assertEquals("Destination exists", dstExists, exists(fc, dst)); Assert.assertEquals("Destination exists", dstExists, exists(fc, dst));
} }
private boolean containsPath(Path path, FileStatus[] filteredPaths) private boolean containsPath(Path path, FileStatus[] filteredPaths)
throws IOException { throws IOException {
for(int i = 0; i < filteredPaths.length; i ++) { for(int i = 0; i < filteredPaths.length; i ++) {
@ -1190,4 +1190,8 @@ private boolean containsPath(Path path, FileStatus[] filteredPaths)
} }
return false; return false;
} }
private Path getTestRootPath(FileContext fc, String pathString) {
return fileContextTestHelper.getTestRootPath(fc, pathString);
}
} }

View File

@ -68,16 +68,25 @@ public abstract class FileContextPermissionBase {
} }
} }
protected static FileContext fc; protected FileContextTestHelper fileContextTestHelper;
protected FileContext fc;
protected FileContextTestHelper getFileContextHelper() {
return new FileContextTestHelper();
}
protected abstract FileContext getFileContext() throws Exception;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
fc.mkdir(getTestRootPath(fc), FileContext.DEFAULT_PERM, true); fileContextTestHelper = getFileContextHelper();
fc = getFileContext();
fc.mkdir(fileContextTestHelper.getTestRootPath(fc), FileContext.DEFAULT_PERM, true);
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
fc.delete(getTestRootPath(fc), true); fc.delete(fileContextTestHelper.getTestRootPath(fc), true);
} }
private void cleanupFile(FileContext fc, Path name) throws IOException { private void cleanupFile(FileContext fc, Path name) throws IOException {
@ -93,8 +102,8 @@ public void testCreatePermission() throws IOException {
return; return;
} }
String filename = "foo"; String filename = "foo";
Path f = getTestRootPath(fc, filename); Path f = fileContextTestHelper.getTestRootPath(fc, filename);
createFile(fc, filename); fileContextTestHelper.createFile(fc, filename);
doFilePermissionCheck(FileContext.FILE_DEFAULT_PERM.applyUMask(fc.getUMask()), doFilePermissionCheck(FileContext.FILE_DEFAULT_PERM.applyUMask(fc.getUMask()),
fc.getFileStatus(f).getPermission()); fc.getFileStatus(f).getPermission());
} }
@ -108,7 +117,7 @@ public void testSetPermission() throws IOException {
} }
String filename = "foo"; String filename = "foo";
Path f = getTestRootPath(fc, filename); Path f = fileContextTestHelper.getTestRootPath(fc, filename);
createFile(fc, f); createFile(fc, f);
try { try {
@ -133,7 +142,7 @@ public void testSetOwner() throws IOException {
} }
String filename = "bar"; String filename = "bar";
Path f = getTestRootPath(fc, filename); Path f = fileContextTestHelper.getTestRootPath(fc, filename);
createFile(fc, f); createFile(fc, f);
List<String> groups = null; List<String> groups = null;
try { try {

View File

@ -43,6 +43,7 @@ public abstract class FileContextSymlinkBaseTest {
static final int blockSize = 8192; static final int blockSize = 8192;
static final int fileSize = 16384; static final int fileSize = 16384;
protected final FileContextTestHelper fileContextTestHelper = new FileContextTestHelper();
protected static FileContext fc; protected static FileContext fc;
abstract protected String getScheme(); abstract protected String getScheme();

View File

@ -22,6 +22,7 @@
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.EnumSet; import java.util.EnumSet;
import org.apache.commons.lang.RandomStringUtils;
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;
@ -31,15 +32,18 @@
* Helper class for unit tests. * Helper class for unit tests.
*/ */
public final class FileContextTestHelper { public final class FileContextTestHelper {
// The test root is relative to the <wd>/build/test/data by default
public static final String TEST_ROOT_DIR =
System.getProperty("test.build.data", "build/test/data") + "/test";
private static final int DEFAULT_BLOCK_SIZE = 1024; private static final int DEFAULT_BLOCK_SIZE = 1024;
private static final int DEFAULT_NUM_BLOCKS = 2; private static final int DEFAULT_NUM_BLOCKS = 2;
private static String absTestRootDir = null;
/** Hidden constructor */ private final String testRootDir;
private FileContextTestHelper() {} private String absTestRootDir = null;
/**
* Create a context with test root relative to the <wd>/build/test/data
*/
public FileContextTestHelper() {
testRootDir = System.getProperty("test.build.data", "target/test/data") + "/" + RandomStringUtils.randomAlphanumeric(10);
}
public static int getDefaultBlockSize() { public static int getDefaultBlockSize() {
return DEFAULT_BLOCK_SIZE; return DEFAULT_BLOCK_SIZE;
@ -53,36 +57,36 @@ public static byte[] getFileData(int numOfBlocks, long blockSize) {
return data; return data;
} }
public static Path getTestRootPath(FileContext fc) { public Path getTestRootPath(FileContext fc) {
return fc.makeQualified(new Path(TEST_ROOT_DIR)); return fc.makeQualified(new Path(testRootDir));
} }
public static Path getTestRootPath(FileContext fc, String pathString) { public Path getTestRootPath(FileContext fc, String pathString) {
return fc.makeQualified(new Path(TEST_ROOT_DIR, pathString)); return fc.makeQualified(new Path(testRootDir, pathString));
} }
// the getAbsolutexxx method is needed because the root test dir // the getAbsolutexxx method is needed because the root test dir
// can be messed up by changing the working dir. // can be messed up by changing the working dir.
public static String getAbsoluteTestRootDir(FileContext fc) public String getAbsoluteTestRootDir(FileContext fc)
throws IOException { throws IOException {
if (absTestRootDir == null) { if (absTestRootDir == null) {
if (new Path(TEST_ROOT_DIR).isAbsolute()) { if (new Path(testRootDir).isAbsolute()) {
absTestRootDir = TEST_ROOT_DIR; absTestRootDir = testRootDir;
} else { } else {
absTestRootDir = fc.getWorkingDirectory().toString() + "/" absTestRootDir = fc.getWorkingDirectory().toString() + "/"
+ TEST_ROOT_DIR; + testRootDir;
} }
} }
return absTestRootDir; return absTestRootDir;
} }
public static Path getAbsoluteTestRootPath(FileContext fc) throws IOException { public Path getAbsoluteTestRootPath(FileContext fc) throws IOException {
return fc.makeQualified(new Path(getAbsoluteTestRootDir(fc))); return fc.makeQualified(new Path(getAbsoluteTestRootDir(fc)));
} }
public static Path getDefaultWorkingDirectory(FileContext fc) public Path getDefaultWorkingDirectory(FileContext fc)
throws IOException { throws IOException {
return getTestRootPath(fc, "/user/" + System.getProperty("user.name")) return getTestRootPath(fc, "/user/" + System.getProperty("user.name"))
.makeQualified(fc.getDefaultFileSystem().getUri(), .makeQualified(fc.getDefaultFileSystem().getUri(),
@ -116,12 +120,12 @@ public static long createFile(FileContext fc, Path path) throws IOException {
return createFile(fc, path, DEFAULT_NUM_BLOCKS, CreateOpts.createParent()); return createFile(fc, path, DEFAULT_NUM_BLOCKS, CreateOpts.createParent());
} }
public static long createFile(FileContext fc, String name) throws IOException { public long createFile(FileContext fc, String name) throws IOException {
Path path = getTestRootPath(fc, name); Path path = getTestRootPath(fc, name);
return createFile(fc, path); return createFile(fc, path);
} }
public static long createFileNonRecursive(FileContext fc, String name) public long createFileNonRecursive(FileContext fc, String name)
throws IOException { throws IOException {
Path path = getTestRootPath(fc, name); Path path = getTestRootPath(fc, name);
return createFileNonRecursive(fc, path); return createFileNonRecursive(fc, path);
@ -190,7 +194,7 @@ public static byte[] readFile(FileContext fc, Path path, int len)
return buffer; return buffer;
} }
public static FileStatus containsPath(FileContext fc, Path path, public FileStatus containsPath(FileContext fc, Path path,
FileStatus[] dirList) FileStatus[] dirList)
throws IOException { throws IOException {
return containsPath(getTestRootPath(fc, path.toString()), dirList); return containsPath(getTestRootPath(fc, path.toString()), dirList);
@ -206,7 +210,7 @@ public static FileStatus containsPath(Path path,
return null; return null;
} }
public static FileStatus containsPath(FileContext fc, String path, public FileStatus containsPath(FileContext fc, String path,
FileStatus[] dirList) FileStatus[] dirList)
throws IOException { throws IOException {
return containsPath(fc, new Path(path), dirList); return containsPath(fc, new Path(path), dirList);

View File

@ -17,7 +17,6 @@
*/ */
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import static org.apache.hadoop.fs.FileContextTestHelper.getTestRootPath;
import static org.apache.hadoop.fs.FileContextTestHelper.readFile; import static org.apache.hadoop.fs.FileContextTestHelper.readFile;
import static org.apache.hadoop.fs.FileContextTestHelper.writeFile; import static org.apache.hadoop.fs.FileContextTestHelper.writeFile;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -44,6 +43,7 @@
* </p> * </p>
*/ */
public abstract class FileContextUtilBase { public abstract class FileContextUtilBase {
protected final FileContextTestHelper fileContextTestHelper = new FileContextTestHelper();
protected FileContext fc; protected FileContext fc;
{ {
@ -58,19 +58,19 @@ public abstract class FileContextUtilBase {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
fc.mkdir(getTestRootPath(fc), FileContext.DEFAULT_PERM, true); fc.mkdir(fileContextTestHelper.getTestRootPath(fc), FileContext.DEFAULT_PERM, true);
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
fc.delete(getTestRootPath(fc), true); fc.delete(fileContextTestHelper.getTestRootPath(fc), true);
} }
@Test @Test
public void testFcCopy() throws Exception{ public void testFcCopy() throws Exception{
final String ts = "some random text"; final String ts = "some random text";
Path file1 = getTestRootPath(fc, "file1"); Path file1 = fileContextTestHelper.getTestRootPath(fc, "file1");
Path file2 = getTestRootPath(fc, "file2"); Path file2 = fileContextTestHelper.getTestRootPath(fc, "file2");
writeFile(fc, file1, ts.getBytes()); writeFile(fc, file1, ts.getBytes());
assertTrue(fc.util().exists(file1)); assertTrue(fc.util().exists(file1));
@ -87,8 +87,8 @@ public void testFcCopy() throws Exception{
public void testRecursiveFcCopy() throws Exception { public void testRecursiveFcCopy() throws Exception {
final String ts = "some random text"; final String ts = "some random text";
Path dir1 = getTestRootPath(fc, "dir1"); Path dir1 = fileContextTestHelper.getTestRootPath(fc, "dir1");
Path dir2 = getTestRootPath(fc, "dir2"); Path dir2 = fileContextTestHelper.getTestRootPath(fc, "dir2");
Path file1 = new Path(dir1, "file1"); Path file1 = new Path(dir1, "file1");
fc.mkdir(dir1, null, false); fc.mkdir(dir1, null, false);

View File

@ -23,26 +23,38 @@
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.junit.Assert; import org.junit.Assert;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
/** /**
* Helper class for unit tests. * Helper class for unit tests.
*/ */
public final class FileSystemTestHelper { public class FileSystemTestHelper {
// The test root is relative to the <wd>/build/test/data by default
public static final String TEST_ROOT_DIR =
System.getProperty("test.build.data", "target/test/data") + "/test";
private static final int DEFAULT_BLOCK_SIZE = 1024; private static final int DEFAULT_BLOCK_SIZE = 1024;
private static final int DEFAULT_NUM_BLOCKS = 2; private static final int DEFAULT_NUM_BLOCKS = 2;
private static final short DEFAULT_NUM_REPL = 1; private static final short DEFAULT_NUM_REPL = 1;
private static String absTestRootDir = null;
/** Hidden constructor */ protected final String testRootDir;
private FileSystemTestHelper() {} private String absTestRootDir = null;
/**
* Create helper with test root located at <wd>/build/test/data
*/
public FileSystemTestHelper() {
this(System.getProperty("test.build.data", "target/test/data") + "/" + RandomStringUtils.randomAlphanumeric(10));
}
/**
* Create helper with the specified test root dir
*/
public FileSystemTestHelper(String testRootDir) {
this.testRootDir = testRootDir;
}
public static void addFileSystemForTesting(URI uri, Configuration conf, public static void addFileSystemForTesting(URI uri, Configuration conf,
FileSystem fs) throws IOException { FileSystem fs) throws IOException {
@ -61,19 +73,22 @@ public static byte[] getFileData(int numOfBlocks, long blockSize) {
return data; return data;
} }
public String getTestRootDir() {
return testRootDir;
}
/* /*
* get testRootPath qualified for fSys * get testRootPath qualified for fSys
*/ */
public static Path getTestRootPath(FileSystem fSys) { public Path getTestRootPath(FileSystem fSys) {
return fSys.makeQualified(new Path(TEST_ROOT_DIR)); return fSys.makeQualified(new Path(testRootDir));
} }
/* /*
* get testRootPath + pathString qualified for fSys * get testRootPath + pathString qualified for fSys
*/ */
public static Path getTestRootPath(FileSystem fSys, String pathString) { public Path getTestRootPath(FileSystem fSys, String pathString) {
return fSys.makeQualified(new Path(TEST_ROOT_DIR, pathString)); return fSys.makeQualified(new Path(testRootDir, pathString));
} }
@ -82,25 +97,25 @@ public static Path getTestRootPath(FileSystem fSys, String pathString) {
// is often relative to the working directory of process // is often relative to the working directory of process
// running the unit tests. // running the unit tests.
static String getAbsoluteTestRootDir(FileSystem fSys) String getAbsoluteTestRootDir(FileSystem fSys)
throws IOException { throws IOException {
// NOTE: can't cache because of different filesystems! // NOTE: can't cache because of different filesystems!
//if (absTestRootDir == null) //if (absTestRootDir == null)
if (new Path(TEST_ROOT_DIR).isAbsolute()) { if (new Path(testRootDir).isAbsolute()) {
absTestRootDir = TEST_ROOT_DIR; absTestRootDir = testRootDir;
} else { } else {
absTestRootDir = fSys.getWorkingDirectory().toString() + "/" absTestRootDir = fSys.getWorkingDirectory().toString() + "/"
+ TEST_ROOT_DIR; + testRootDir;
} }
//} //}
return absTestRootDir; return absTestRootDir;
} }
public static Path getAbsoluteTestRootPath(FileSystem fSys) throws IOException { public Path getAbsoluteTestRootPath(FileSystem fSys) throws IOException {
return fSys.makeQualified(new Path(getAbsoluteTestRootDir(fSys))); return fSys.makeQualified(new Path(getAbsoluteTestRootDir(fSys)));
} }
public static Path getDefaultWorkingDirectory(FileSystem fSys) public Path getDefaultWorkingDirectory(FileSystem fSys)
throws IOException { throws IOException {
return getTestRootPath(fSys, "/user/" + System.getProperty("user.name")) return getTestRootPath(fSys, "/user/" + System.getProperty("user.name"))
.makeQualified(fSys.getUri(), .makeQualified(fSys.getUri(),
@ -136,7 +151,7 @@ public static long createFile(FileSystem fSys, Path path) throws IOException {
return createFile(fSys, path, DEFAULT_NUM_BLOCKS, DEFAULT_BLOCK_SIZE, DEFAULT_NUM_REPL, true); return createFile(fSys, path, DEFAULT_NUM_BLOCKS, DEFAULT_BLOCK_SIZE, DEFAULT_NUM_REPL, true);
} }
public static long createFile(FileSystem fSys, String name) throws IOException { public long createFile(FileSystem fSys, String name) throws IOException {
Path path = getTestRootPath(fSys, name); Path path = getTestRootPath(fSys, name);
return createFile(fSys, path); return createFile(fSys, path);
} }
@ -188,7 +203,7 @@ static String readFile(FileSystem fs, Path name, int buflen)
return s; return s;
} }
public static FileStatus containsPath(FileSystem fSys, Path path, public FileStatus containsPath(FileSystem fSys, Path path,
FileStatus[] dirList) FileStatus[] dirList)
throws IOException { throws IOException {
for(int i = 0; i < dirList.length; i ++) { for(int i = 0; i < dirList.length; i ++) {
@ -210,7 +225,7 @@ public static FileStatus containsPath(Path path,
} }
public static FileStatus containsPath(FileSystem fSys, String path, FileStatus[] dirList) public FileStatus containsPath(FileSystem fSys, String path, FileStatus[] dirList)
throws IOException { throws IOException {
return containsPath(fSys, new Path(path), dirList); return containsPath(fSys, new Path(path), dirList);
} }

View File

@ -28,10 +28,14 @@
public class TestFSMainOperationsLocalFileSystem extends FSMainOperationsBaseTest { public class TestFSMainOperationsLocalFileSystem extends FSMainOperationsBaseTest {
@Override
protected FileSystem createFileSystem() throws IOException {
return FileSystem.getLocal(new Configuration());
}
@Override @Override
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
fSys = FileSystem.getLocal(new Configuration());
super.setUp(); super.setUp();
} }
@ -52,8 +56,7 @@ public void tearDown() throws Exception {
@Test @Test
@Override @Override
public void testWDAbsolute() throws IOException { public void testWDAbsolute() throws IOException {
Path absoluteDir = FileSystemTestHelper.getTestRootPath(fSys, Path absoluteDir = getTestRootPath(fSys, "test/existingDir");
"test/existingDir");
fSys.mkdirs(absoluteDir); fSys.mkdirs(absoluteDir);
fSys.setWorkingDirectory(absoluteDir); fSys.setWorkingDirectory(absoluteDir);
Assert.assertEquals(absoluteDir, fSys.getWorkingDirectory()); Assert.assertEquals(absoluteDir, fSys.getWorkingDirectory());

View File

@ -29,7 +29,6 @@ public class TestFcLocalFsPermission extends
@Override @Override
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
fc = FileContext.getLocalFSFileContext();
super.setUp(); super.setUp();
} }
@ -39,4 +38,9 @@ public void tearDown() throws Exception {
super.tearDown(); super.tearDown();
} }
@Override
protected FileContext getFileContext() throws UnsupportedFileSystemException {
return FileContext.getLocalFSFileContext();
}
} }

View File

@ -35,6 +35,7 @@ public class TestFileContextDeleteOnExit {
private static int blockSize = 1024; private static int blockSize = 1024;
private static int numBlocks = 2; private static int numBlocks = 2;
private final FileContextTestHelper helper = new FileContextTestHelper();
private FileContext fc; private FileContext fc;
@Before @Before
@ -44,7 +45,7 @@ public void setup() throws IOException {
@After @After
public void tearDown() throws IOException { public void tearDown() throws IOException {
fc.delete(getTestRootPath(fc), true); fc.delete(helper.getTestRootPath(fc), true);
} }
@ -60,7 +61,7 @@ private void checkDeleteOnExitData(int size, FileContext fc, Path... paths) {
@Test @Test
public void testDeleteOnExit() throws Exception { public void testDeleteOnExit() throws Exception {
// Create deleteOnExit entries // Create deleteOnExit entries
Path file1 = getTestRootPath(fc, "file1"); Path file1 = helper.getTestRootPath(fc, "file1");
createFile(fc, file1, numBlocks, blockSize); createFile(fc, file1, numBlocks, blockSize);
fc.deleteOnExit(file1); fc.deleteOnExit(file1);
checkDeleteOnExitData(1, fc, file1); checkDeleteOnExitData(1, fc, file1);
@ -68,12 +69,12 @@ public void testDeleteOnExit() throws Exception {
// Ensure shutdown hook is added // Ensure shutdown hook is added
Assert.assertTrue(ShutdownHookManager.get().hasShutdownHook(FileContext.FINALIZER)); Assert.assertTrue(ShutdownHookManager.get().hasShutdownHook(FileContext.FINALIZER));
Path file2 = getTestRootPath(fc, "dir1/file2"); Path file2 = helper.getTestRootPath(fc, "dir1/file2");
createFile(fc, file2, numBlocks, blockSize); createFile(fc, file2, numBlocks, blockSize);
fc.deleteOnExit(file2); fc.deleteOnExit(file2);
checkDeleteOnExitData(1, fc, file1, file2); checkDeleteOnExitData(1, fc, file1, file2);
Path dir = getTestRootPath(fc, "dir3/dir4/dir5/dir6"); Path dir = helper.getTestRootPath(fc, "dir3/dir4/dir5/dir6");
createFile(fc, dir, numBlocks, blockSize); createFile(fc, dir, numBlocks, blockSize);
fc.deleteOnExit(dir); fc.deleteOnExit(dir);
checkDeleteOnExitData(1, fc, file1, file2, dir); checkDeleteOnExitData(1, fc, file1, file2, dir);

View File

@ -52,7 +52,7 @@ public void testFileContextNoCache() throws UnsupportedFileSystemException {
@Test @Test
public void testDefaultFilePermission() throws IOException { public void testDefaultFilePermission() throws IOException {
Path file = FileContextTestHelper.getTestRootPath(fc, Path file = fileContextTestHelper.getTestRootPath(fc,
"testDefaultFilePermission"); "testDefaultFilePermission");
FileContextTestHelper.createFile(fc, file); FileContextTestHelper.createFile(fc, file);
FsPermission expect = FileContext.FILE_DEFAULT_PERM.applyUMask(fc.getUMask()); FsPermission expect = FileContext.FILE_DEFAULT_PERM.applyUMask(fc.getUMask());

View File

@ -25,7 +25,6 @@
import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.FileUtil; import org.apache.hadoop.fs.FileUtil;
import static org.apache.hadoop.fs.FileContextTestHelper.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import org.junit.Test; import org.junit.Test;
@ -43,12 +42,12 @@ protected String getScheme() {
@Override @Override
protected String testBaseDir1() throws IOException { protected String testBaseDir1() throws IOException {
return getAbsoluteTestRootDir(fc)+"/test1"; return fileContextTestHelper.getAbsoluteTestRootDir(fc)+"/test1";
} }
@Override @Override
protected String testBaseDir2() throws IOException { protected String testBaseDir2() throws IOException {
return getAbsoluteTestRootDir(fc)+"/test2"; return fileContextTestHelper.getAbsoluteTestRootDir(fc)+"/test2";
} }
@Override @Override

View File

@ -69,7 +69,7 @@ public void after() throws IOException {
/** /**
* Test the capability of setting the working directory. * Test the capability of setting the working directory.
*/ */
@Test(timeout = 1000) @Test(timeout = 10000)
public void testWorkingDirectory() throws IOException { public void testWorkingDirectory() throws IOException {
Path origDir = fileSys.getWorkingDirectory(); Path origDir = fileSys.getWorkingDirectory();
Path subdir = new Path(TEST_ROOT_DIR, "new"); Path subdir = new Path(TEST_ROOT_DIR, "new");
@ -156,7 +156,7 @@ private void verifyFile(FileSystem fs, Path file, int bytesToVerify,
} }
} }
@Test(timeout = 1000) @Test(timeout = 10000)
public void testCopy() throws IOException { public void testCopy() throws IOException {
Path src = new Path(TEST_ROOT_DIR, "dingo"); Path src = new Path(TEST_ROOT_DIR, "dingo");
Path dst = new Path(TEST_ROOT_DIR, "yak"); Path dst = new Path(TEST_ROOT_DIR, "yak");
@ -271,7 +271,7 @@ public void testListStatusWithColons() throws IOException {
stats[0].getPath().toUri().getPath()); stats[0].getPath().toUri().getPath());
} }
@Test(timeout = 1000) @Test(timeout = 10000)
public void testReportChecksumFailure() throws IOException { public void testReportChecksumFailure() throws IOException {
base.mkdirs(); base.mkdirs();
assertTrue(base.exists() && base.isDirectory()); assertTrue(base.exists() && base.isDirectory());

View File

@ -25,8 +25,6 @@
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import static org.apache.hadoop.fs.FileContextTestHelper.*;
/** /**
* <p> * <p>
* Tests the File Context Statistics for {@link LocalFileSystem} * Tests the File Context Statistics for {@link LocalFileSystem}
@ -39,12 +37,12 @@ public class TestLocalFsFCStatistics extends FCStatisticsBaseTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
fc = FileContext.getLocalFSFileContext(); fc = FileContext.getLocalFSFileContext();
fc.mkdir(getTestRootPath(fc, "test"), FileContext.DEFAULT_PERM, true); fc.mkdir(fileContextTestHelper.getTestRootPath(fc, "test"), FileContext.DEFAULT_PERM, true);
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
fc.delete(getTestRootPath(fc, "test"), true); fc.delete(fileContextTestHelper.getTestRootPath(fc, "test"), true);
} }
@Override @Override

View File

@ -97,37 +97,37 @@ private void run(CommandWithDestination cmd, String... args) {
assertEquals(0, cmd.run(args)); assertEquals(0, cmd.run(args));
} }
@Test(timeout = 1000) @Test(timeout = 10000)
public void testPutWithP() throws Exception { public void testPutWithP() throws Exception {
run(new Put(), "-p", FROM.toString(), TO.toString()); run(new Put(), "-p", FROM.toString(), TO.toString());
assertAttributesPreserved(); assertAttributesPreserved();
} }
@Test(timeout = 1000) @Test(timeout = 10000)
public void testPutWithoutP() throws Exception { public void testPutWithoutP() throws Exception {
run(new Put(), FROM.toString(), TO.toString()); run(new Put(), FROM.toString(), TO.toString());
assertAttributesChanged(); assertAttributesChanged();
} }
@Test(timeout = 1000) @Test(timeout = 10000)
public void testGetWithP() throws Exception { public void testGetWithP() throws Exception {
run(new Get(), "-p", FROM.toString(), TO.toString()); run(new Get(), "-p", FROM.toString(), TO.toString());
assertAttributesPreserved(); assertAttributesPreserved();
} }
@Test(timeout = 1000) @Test(timeout = 10000)
public void testGetWithoutP() throws Exception { public void testGetWithoutP() throws Exception {
run(new Get(), FROM.toString(), TO.toString()); run(new Get(), FROM.toString(), TO.toString());
assertAttributesChanged(); assertAttributesChanged();
} }
@Test(timeout = 1000) @Test(timeout = 10000)
public void testCpWithP() throws Exception { public void testCpWithP() throws Exception {
run(new Cp(), "-p", FROM.toString(), TO.toString()); run(new Cp(), "-p", FROM.toString(), TO.toString());
assertAttributesPreserved(); assertAttributesPreserved();
} }
@Test(timeout = 1000) @Test(timeout = 10000)
public void testCpWithoutP() throws Exception { public void testCpWithoutP() throws Exception {
run(new Cp(), FROM.toString(), TO.toString()); run(new Cp(), FROM.toString(), TO.toString());
assertAttributesChanged(); assertAttributesChanged();

View File

@ -40,13 +40,15 @@ public class TestChRootedFileSystem {
FileSystem fSys; // The ChRoootedFs FileSystem fSys; // The ChRoootedFs
FileSystem fSysTarget; // FileSystem fSysTarget; //
Path chrootedTo; Path chrootedTo;
FileSystemTestHelper fileSystemTestHelper;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
// create the test root on local_fs // create the test root on local_fs
Configuration conf = new Configuration(); Configuration conf = new Configuration();
fSysTarget = FileSystem.getLocal(conf); fSysTarget = FileSystem.getLocal(conf);
chrootedTo = FileSystemTestHelper.getAbsoluteTestRootPath(fSysTarget); fileSystemTestHelper = new FileSystemTestHelper();
chrootedTo = fileSystemTestHelper.getAbsoluteTestRootPath(fSysTarget);
// In case previous test was killed before cleanup // In case previous test was killed before cleanup
fSysTarget.delete(chrootedTo, true); fSysTarget.delete(chrootedTo, true);
@ -107,12 +109,12 @@ public void testCreateDelete() throws IOException {
// Create file // Create file
FileSystemTestHelper.createFile(fSys, "/foo"); fileSystemTestHelper.createFile(fSys, "/foo");
Assert.assertTrue(fSys.isFile(new Path("/foo"))); Assert.assertTrue(fSys.isFile(new Path("/foo")));
Assert.assertTrue(fSysTarget.isFile(new Path(chrootedTo, "foo"))); Assert.assertTrue(fSysTarget.isFile(new Path(chrootedTo, "foo")));
// Create file with recursive dir // Create file with recursive dir
FileSystemTestHelper.createFile(fSys, "/newDir/foo"); fileSystemTestHelper.createFile(fSys, "/newDir/foo");
Assert.assertTrue(fSys.isFile(new Path("/newDir/foo"))); Assert.assertTrue(fSys.isFile(new Path("/newDir/foo")));
Assert.assertTrue(fSysTarget.isFile(new Path(chrootedTo,"newDir/foo"))); Assert.assertTrue(fSysTarget.isFile(new Path(chrootedTo,"newDir/foo")));
@ -122,7 +124,7 @@ public void testCreateDelete() throws IOException {
Assert.assertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/foo"))); Assert.assertFalse(fSysTarget.exists(new Path(chrootedTo, "newDir/foo")));
// Create file with a 2 component dirs recursively // Create file with a 2 component dirs recursively
FileSystemTestHelper.createFile(fSys, "/newDir/newDir2/foo"); fileSystemTestHelper.createFile(fSys, "/newDir/newDir2/foo");
Assert.assertTrue(fSys.isFile(new Path("/newDir/newDir2/foo"))); Assert.assertTrue(fSys.isFile(new Path("/newDir/newDir2/foo")));
Assert.assertTrue(fSysTarget.isFile(new Path(chrootedTo,"newDir/newDir2/foo"))); Assert.assertTrue(fSysTarget.isFile(new Path(chrootedTo,"newDir/newDir2/foo")));
@ -135,11 +137,11 @@ public void testCreateDelete() throws IOException {
@Test @Test
public void testMkdirDelete() throws IOException { public void testMkdirDelete() throws IOException {
fSys.mkdirs(FileSystemTestHelper.getTestRootPath(fSys, "/dirX")); fSys.mkdirs(fileSystemTestHelper.getTestRootPath(fSys, "/dirX"));
Assert.assertTrue(fSys.isDirectory(new Path("/dirX"))); Assert.assertTrue(fSys.isDirectory(new Path("/dirX")));
Assert.assertTrue(fSysTarget.isDirectory(new Path(chrootedTo,"dirX"))); Assert.assertTrue(fSysTarget.isDirectory(new Path(chrootedTo,"dirX")));
fSys.mkdirs(FileSystemTestHelper.getTestRootPath(fSys, "/dirX/dirY")); fSys.mkdirs(fileSystemTestHelper.getTestRootPath(fSys, "/dirX/dirY"));
Assert.assertTrue(fSys.isDirectory(new Path("/dirX/dirY"))); Assert.assertTrue(fSys.isDirectory(new Path("/dirX/dirY")));
Assert.assertTrue(fSysTarget.isDirectory(new Path(chrootedTo,"dirX/dirY"))); Assert.assertTrue(fSysTarget.isDirectory(new Path(chrootedTo,"dirX/dirY")));
@ -157,11 +159,11 @@ public void testMkdirDelete() throws IOException {
@Test @Test
public void testRename() throws IOException { public void testRename() throws IOException {
// Rename a file // Rename a file
FileSystemTestHelper.createFile(fSys, "/newDir/foo"); fileSystemTestHelper.createFile(fSys, "/newDir/foo");
fSys.rename(new Path("/newDir/foo"), new Path("/newDir/fooBar")); fSys.rename(new Path("/newDir/foo"), new Path("/newDir/fooBar"));
Assert.assertFalse(fSys.exists(new Path("/newDir/foo"))); Assert.assertFalse(fSys.exists(new Path("/newDir/foo")));
Assert.assertFalse(fSysTarget.exists(new Path(chrootedTo,"newDir/foo"))); Assert.assertFalse(fSysTarget.exists(new Path(chrootedTo,"newDir/foo")));
Assert.assertTrue(fSys.isFile(FileSystemTestHelper.getTestRootPath(fSys,"/newDir/fooBar"))); Assert.assertTrue(fSys.isFile(fileSystemTestHelper.getTestRootPath(fSys,"/newDir/fooBar")));
Assert.assertTrue(fSysTarget.isFile(new Path(chrootedTo,"newDir/fooBar"))); Assert.assertTrue(fSysTarget.isFile(new Path(chrootedTo,"newDir/fooBar")));
@ -170,7 +172,7 @@ public void testRename() throws IOException {
fSys.rename(new Path("/newDir/dirFoo"), new Path("/newDir/dirFooBar")); fSys.rename(new Path("/newDir/dirFoo"), new Path("/newDir/dirFooBar"));
Assert.assertFalse(fSys.exists(new Path("/newDir/dirFoo"))); Assert.assertFalse(fSys.exists(new Path("/newDir/dirFoo")));
Assert.assertFalse(fSysTarget.exists(new Path(chrootedTo,"newDir/dirFoo"))); Assert.assertFalse(fSysTarget.exists(new Path(chrootedTo,"newDir/dirFoo")));
Assert.assertTrue(fSys.isDirectory(FileSystemTestHelper.getTestRootPath(fSys,"/newDir/dirFooBar"))); Assert.assertTrue(fSys.isDirectory(fileSystemTestHelper.getTestRootPath(fSys,"/newDir/dirFooBar")));
Assert.assertTrue(fSysTarget.isDirectory(new Path(chrootedTo,"newDir/dirFooBar"))); Assert.assertTrue(fSysTarget.isDirectory(new Path(chrootedTo,"newDir/dirFooBar")));
} }
@ -214,10 +216,10 @@ public void testList() throws IOException {
FileSystemTestHelper.createFile(fSys, "/foo"); fileSystemTestHelper.createFile(fSys, "/foo");
FileSystemTestHelper.createFile(fSys, "/bar"); fileSystemTestHelper.createFile(fSys, "/bar");
fSys.mkdirs(new Path("/dirX")); fSys.mkdirs(new Path("/dirX"));
fSys.mkdirs(FileSystemTestHelper.getTestRootPath(fSys, "/dirY")); fSys.mkdirs(fileSystemTestHelper.getTestRootPath(fSys, "/dirY"));
fSys.mkdirs(new Path("/dirX/dirXX")); fSys.mkdirs(new Path("/dirX/dirXX"));
dirPaths = fSys.listStatus(new Path("/")); dirPaths = fSys.listStatus(new Path("/"));
@ -307,7 +309,7 @@ public void testWorkingDirectory() throws Exception {
@Test @Test
public void testResolvePath() throws IOException { public void testResolvePath() throws IOException {
Assert.assertEquals(chrootedTo, fSys.resolvePath(new Path("/"))); Assert.assertEquals(chrootedTo, fSys.resolvePath(new Path("/")));
FileSystemTestHelper.createFile(fSys, "/foo"); fileSystemTestHelper.createFile(fSys, "/foo");
Assert.assertEquals(new Path(chrootedTo, "foo"), Assert.assertEquals(new Path(chrootedTo, "foo"),
fSys.resolvePath(new Path("/foo"))); fSys.resolvePath(new Path("/foo")));
} }

View File

@ -38,6 +38,7 @@
import org.junit.Test; import org.junit.Test;
public class TestChRootedFs { public class TestChRootedFs {
FileContextTestHelper fileContextTestHelper = new FileContextTestHelper();
FileContext fc; // The ChRoootedFs FileContext fc; // The ChRoootedFs
FileContext fcTarget; // FileContext fcTarget; //
Path chrootedTo; Path chrootedTo;
@ -46,7 +47,7 @@ public class TestChRootedFs {
public void setUp() throws Exception { public void setUp() throws Exception {
// create the test root on local_fs // create the test root on local_fs
fcTarget = FileContext.getLocalFSFileContext(); fcTarget = FileContext.getLocalFSFileContext();
chrootedTo = FileContextTestHelper.getAbsoluteTestRootPath(fcTarget); chrootedTo = fileContextTestHelper.getAbsoluteTestRootPath(fcTarget);
// In case previous test was killed before cleanup // In case previous test was killed before cleanup
fcTarget.delete(chrootedTo, true); fcTarget.delete(chrootedTo, true);
@ -105,12 +106,12 @@ public void testCreateDelete() throws IOException {
// Create file // Create file
FileContextTestHelper.createFileNonRecursive(fc, "/foo"); fileContextTestHelper.createFileNonRecursive(fc, "/foo");
Assert.assertTrue(isFile(fc, new Path("/foo"))); Assert.assertTrue(isFile(fc, new Path("/foo")));
Assert.assertTrue(isFile(fcTarget, new Path(chrootedTo, "foo"))); Assert.assertTrue(isFile(fcTarget, new Path(chrootedTo, "foo")));
// Create file with recursive dir // Create file with recursive dir
FileContextTestHelper.createFile(fc, "/newDir/foo"); fileContextTestHelper.createFile(fc, "/newDir/foo");
Assert.assertTrue(isFile(fc, new Path("/newDir/foo"))); Assert.assertTrue(isFile(fc, new Path("/newDir/foo")));
Assert.assertTrue(isFile(fcTarget, new Path(chrootedTo,"newDir/foo"))); Assert.assertTrue(isFile(fcTarget, new Path(chrootedTo,"newDir/foo")));
@ -120,7 +121,7 @@ public void testCreateDelete() throws IOException {
Assert.assertFalse(exists(fcTarget, new Path(chrootedTo,"newDir/foo"))); Assert.assertFalse(exists(fcTarget, new Path(chrootedTo,"newDir/foo")));
// Create file with a 2 component dirs recursively // Create file with a 2 component dirs recursively
FileContextTestHelper.createFile(fc, "/newDir/newDir2/foo"); fileContextTestHelper.createFile(fc, "/newDir/newDir2/foo");
Assert.assertTrue(isFile(fc, new Path("/newDir/newDir2/foo"))); Assert.assertTrue(isFile(fc, new Path("/newDir/newDir2/foo")));
Assert.assertTrue(isFile(fcTarget, new Path(chrootedTo,"newDir/newDir2/foo"))); Assert.assertTrue(isFile(fcTarget, new Path(chrootedTo,"newDir/newDir2/foo")));
@ -133,11 +134,11 @@ public void testCreateDelete() throws IOException {
@Test @Test
public void testMkdirDelete() throws IOException { public void testMkdirDelete() throws IOException {
fc.mkdir(FileContextTestHelper.getTestRootPath(fc, "/dirX"), FileContext.DEFAULT_PERM, false); fc.mkdir(fileContextTestHelper.getTestRootPath(fc, "/dirX"), FileContext.DEFAULT_PERM, false);
Assert.assertTrue(isDir(fc, new Path("/dirX"))); Assert.assertTrue(isDir(fc, new Path("/dirX")));
Assert.assertTrue(isDir(fcTarget, new Path(chrootedTo,"dirX"))); Assert.assertTrue(isDir(fcTarget, new Path(chrootedTo,"dirX")));
fc.mkdir(FileContextTestHelper.getTestRootPath(fc, "/dirX/dirY"), FileContext.DEFAULT_PERM, false); fc.mkdir(fileContextTestHelper.getTestRootPath(fc, "/dirX/dirY"), FileContext.DEFAULT_PERM, false);
Assert.assertTrue(isDir(fc, new Path("/dirX/dirY"))); Assert.assertTrue(isDir(fc, new Path("/dirX/dirY")));
Assert.assertTrue(isDir(fcTarget, new Path(chrootedTo,"dirX/dirY"))); Assert.assertTrue(isDir(fcTarget, new Path(chrootedTo,"dirX/dirY")));
@ -155,11 +156,11 @@ public void testMkdirDelete() throws IOException {
@Test @Test
public void testRename() throws IOException { public void testRename() throws IOException {
// Rename a file // Rename a file
FileContextTestHelper.createFile(fc, "/newDir/foo"); fileContextTestHelper.createFile(fc, "/newDir/foo");
fc.rename(new Path("/newDir/foo"), new Path("/newDir/fooBar")); fc.rename(new Path("/newDir/foo"), new Path("/newDir/fooBar"));
Assert.assertFalse(exists(fc, new Path("/newDir/foo"))); Assert.assertFalse(exists(fc, new Path("/newDir/foo")));
Assert.assertFalse(exists(fcTarget, new Path(chrootedTo,"newDir/foo"))); Assert.assertFalse(exists(fcTarget, new Path(chrootedTo,"newDir/foo")));
Assert.assertTrue(isFile(fc, FileContextTestHelper.getTestRootPath(fc,"/newDir/fooBar"))); Assert.assertTrue(isFile(fc, fileContextTestHelper.getTestRootPath(fc,"/newDir/fooBar")));
Assert.assertTrue(isFile(fcTarget, new Path(chrootedTo,"newDir/fooBar"))); Assert.assertTrue(isFile(fcTarget, new Path(chrootedTo,"newDir/fooBar")));
@ -168,7 +169,7 @@ public void testRename() throws IOException {
fc.rename(new Path("/newDir/dirFoo"), new Path("/newDir/dirFooBar")); fc.rename(new Path("/newDir/dirFoo"), new Path("/newDir/dirFooBar"));
Assert.assertFalse(exists(fc, new Path("/newDir/dirFoo"))); Assert.assertFalse(exists(fc, new Path("/newDir/dirFoo")));
Assert.assertFalse(exists(fcTarget, new Path(chrootedTo,"newDir/dirFoo"))); Assert.assertFalse(exists(fcTarget, new Path(chrootedTo,"newDir/dirFoo")));
Assert.assertTrue(isDir(fc, FileContextTestHelper.getTestRootPath(fc,"/newDir/dirFooBar"))); Assert.assertTrue(isDir(fc, fileContextTestHelper.getTestRootPath(fc,"/newDir/dirFooBar")));
Assert.assertTrue(isDir(fcTarget, new Path(chrootedTo,"newDir/dirFooBar"))); Assert.assertTrue(isDir(fcTarget, new Path(chrootedTo,"newDir/dirFooBar")));
} }
@ -202,10 +203,10 @@ public void testList() throws IOException {
FileContextTestHelper.createFileNonRecursive(fc, "/foo"); fileContextTestHelper.createFileNonRecursive(fc, "/foo");
FileContextTestHelper.createFileNonRecursive(fc, "/bar"); fileContextTestHelper.createFileNonRecursive(fc, "/bar");
fc.mkdir(new Path("/dirX"), FileContext.DEFAULT_PERM, false); fc.mkdir(new Path("/dirX"), FileContext.DEFAULT_PERM, false);
fc.mkdir(FileContextTestHelper.getTestRootPath(fc, "/dirY"), fc.mkdir(fileContextTestHelper.getTestRootPath(fc, "/dirY"),
FileContext.DEFAULT_PERM, false); FileContext.DEFAULT_PERM, false);
fc.mkdir(new Path("/dirX/dirXX"), FileContext.DEFAULT_PERM, false); fc.mkdir(new Path("/dirX/dirXX"), FileContext.DEFAULT_PERM, false);
@ -213,16 +214,16 @@ public void testList() throws IOException {
Assert.assertEquals(4, dirPaths.length); Assert.assertEquals(4, dirPaths.length);
// Note the the file status paths are the full paths on target // Note the the file status paths are the full paths on target
fs = FileContextTestHelper.containsPath(fcTarget, "foo", dirPaths); fs = fileContextTestHelper.containsPath(fcTarget, "foo", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue(fs.isFile()); Assert.assertTrue(fs.isFile());
fs = FileContextTestHelper.containsPath(fcTarget, "bar", dirPaths); fs = fileContextTestHelper.containsPath(fcTarget, "bar", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue(fs.isFile()); Assert.assertTrue(fs.isFile());
fs = FileContextTestHelper.containsPath(fcTarget, "dirX", dirPaths); fs = fileContextTestHelper.containsPath(fcTarget, "dirX", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue(fs.isDirectory()); Assert.assertTrue(fs.isDirectory());
fs = FileContextTestHelper.containsPath(fcTarget, "dirY", dirPaths); fs = fileContextTestHelper.containsPath(fcTarget, "dirY", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue(fs.isDirectory()); Assert.assertTrue(fs.isDirectory());
} }
@ -273,7 +274,7 @@ public void testWorkingDirectory() throws Exception {
fc.mkdir(new Path("newDir"), FileContext.DEFAULT_PERM, true); fc.mkdir(new Path("newDir"), FileContext.DEFAULT_PERM, true);
Assert.assertTrue(isDir(fc, new Path(absoluteDir, "newDir"))); Assert.assertTrue(isDir(fc, new Path(absoluteDir, "newDir")));
absoluteDir = getTestRootPath(fc, "nonexistingPath"); absoluteDir = fileContextTestHelper.getTestRootPath(fc, "nonexistingPath");
try { try {
fc.setWorkingDirectory(absoluteDir); fc.setWorkingDirectory(absoluteDir);
Assert.fail("cd to non existing dir should have failed"); Assert.fail("cd to non existing dir should have failed");
@ -297,7 +298,7 @@ public void testWorkingDirectory() throws Exception {
@Test @Test
public void testResolvePath() throws IOException { public void testResolvePath() throws IOException {
Assert.assertEquals(chrootedTo, fc.getDefaultFileSystem().resolvePath(new Path("/"))); Assert.assertEquals(chrootedTo, fc.getDefaultFileSystem().resolvePath(new Path("/")));
FileContextTestHelper.createFile(fc, "/foo"); fileContextTestHelper.createFile(fc, "/foo");
Assert.assertEquals(new Path(chrootedTo, "foo"), Assert.assertEquals(new Path(chrootedTo, "foo"),
fc.getDefaultFileSystem().resolvePath(new Path("/foo"))); fc.getDefaultFileSystem().resolvePath(new Path("/foo")));
} }

View File

@ -23,7 +23,6 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSMainOperationsBaseTest; import org.apache.hadoop.fs.FSMainOperationsBaseTest;
import org.apache.hadoop.fs.FileSystemTestHelper;
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.junit.After; import org.junit.After;
@ -32,14 +31,19 @@
import org.junit.Test; import org.junit.Test;
public class TestFSMainOperationsLocalFileSystem extends FSMainOperationsBaseTest { public class TestFSMainOperationsLocalFileSystem extends FSMainOperationsBaseTest {
static FileSystem fcTarget; FileSystem fcTarget;
@Override
protected FileSystem createFileSystem() throws Exception {
return ViewFileSystemTestSetup.setupForViewFileSystem(
ViewFileSystemTestSetup.createConfig(), this, fcTarget);
}
@Override @Override
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
fcTarget = FileSystem.getLocal(conf); fcTarget = FileSystem.getLocal(conf);
fSys = ViewFileSystemTestSetup.setupForViewFileSystem(
ViewFileSystemTestSetup.createConfig(), fcTarget);
super.setUp(); super.setUp();
} }
@ -47,14 +51,13 @@ public void setUp() throws Exception {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
super.tearDown(); super.tearDown();
ViewFileSystemTestSetup.tearDown(fcTarget); ViewFileSystemTestSetup.tearDown(this, fcTarget);
} }
@Test @Test
@Override @Override
public void testWDAbsolute() throws IOException { public void testWDAbsolute() throws IOException {
Path absoluteDir = FileSystemTestHelper.getTestRootPath(fSys, Path absoluteDir = getTestRootPath(fSys, "test/existingDir");
"test/existingDir");
fSys.mkdirs(absoluteDir); fSys.mkdirs(absoluteDir);
fSys.setWorkingDirectory(absoluteDir); fSys.setWorkingDirectory(absoluteDir);
Assert.assertEquals(absoluteDir, fSys.getWorkingDirectory()); Assert.assertEquals(absoluteDir, fSys.getWorkingDirectory());

View File

@ -31,7 +31,7 @@ public class TestFcCreateMkdirLocalFs extends
@Override @Override
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
fc = ViewFsTestSetup.setupForViewFsLocalFs(); fc = ViewFsTestSetup.setupForViewFsLocalFs(fileContextTestHelper);
super.setUp(); super.setUp();
} }
@ -39,6 +39,6 @@ public void setUp() throws Exception {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
super.tearDown(); super.tearDown();
ViewFsTestSetup.tearDownForViewFsLocalFs(); ViewFsTestSetup.tearDownForViewFsLocalFs(fileContextTestHelper);
} }
} }

View File

@ -39,7 +39,7 @@ public class TestFcMainOperationsLocalFs extends
@Override @Override
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
fc = ViewFsTestSetup.setupForViewFsLocalFs(); fc = ViewFsTestSetup.setupForViewFsLocalFs(fileContextTestHelper);
super.setUp(); super.setUp();
} }
@ -47,6 +47,6 @@ public void setUp() throws Exception {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
super.tearDown(); super.tearDown();
ViewFsTestSetup.tearDownForViewFsLocalFs(); ViewFsTestSetup.tearDownForViewFsLocalFs(fileContextTestHelper);
} }
} }

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.fs.viewfs; package org.apache.hadoop.fs.viewfs;
import org.apache.hadoop.fs.FileContext;
import org.apache.hadoop.fs.FileContextPermissionBase; import org.apache.hadoop.fs.FileContextPermissionBase;
import org.junit.After; import org.junit.After;
@ -26,11 +27,9 @@
public class TestFcPermissionsLocalFs extends FileContextPermissionBase { public class TestFcPermissionsLocalFs extends FileContextPermissionBase {
@Override @Override
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
fc = ViewFsTestSetup.setupForViewFsLocalFs();
super.setUp(); super.setUp();
} }
@ -38,6 +37,11 @@ public void setUp() throws Exception {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
super.tearDown(); super.tearDown();
ViewFsTestSetup.tearDownForViewFsLocalFs(); ViewFsTestSetup.tearDownForViewFsLocalFs(fileContextTestHelper);
}
@Override
protected FileContext getFileContext() throws Exception {
return ViewFsTestSetup.setupForViewFsLocalFs(fileContextTestHelper);
} }
} }

View File

@ -52,7 +52,7 @@ static FakeFileSystem setupFileSystem(URI uri, Class clazz)
conf.set("fs."+scheme+".impl", clazz.getName()); conf.set("fs."+scheme+".impl", clazz.getName());
FakeFileSystem fs = (FakeFileSystem)FileSystem.get(uri, conf); FakeFileSystem fs = (FakeFileSystem)FileSystem.get(uri, conf);
assertEquals(uri, fs.getUri()); assertEquals(uri, fs.getUri());
Path targetPath = FileSystemTestHelper.getAbsoluteTestRootPath(fs); Path targetPath = new FileSystemTestHelper().getAbsoluteTestRootPath(fs);
ConfigUtil.addLink(conf, "/mounts/"+scheme, targetPath.toUri()); ConfigUtil.addLink(conf, "/mounts/"+scheme, targetPath.toUri());
return fs; return fs;
} }

View File

@ -38,7 +38,6 @@
public class TestViewFileSystemLocalFileSystem extends ViewFileSystemBaseTest { public class TestViewFileSystemLocalFileSystem extends ViewFileSystemBaseTest {
@Override @Override
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -51,7 +50,7 @@ public void setUp() throws Exception {
@Override @Override
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
fsTarget.delete(FileSystemTestHelper.getTestRootPath(fsTarget), true); fsTarget.delete(fileSystemTestHelper.getTestRootPath(fsTarget), true);
super.tearDown(); super.tearDown();
} }
} }

View File

@ -59,7 +59,7 @@ public void setUp() throws Exception {
@Override @Override
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
fsTarget.delete(FileSystemTestHelper.getTestRootPath(fsTarget), true); fsTarget.delete(fileSystemTestHelper.getTestRootPath(fsTarget), true);
super.tearDown(); super.tearDown();
} }

View File

@ -35,11 +35,12 @@ public class TestViewFsTrash {
FileSystem fsTarget; // the target file system - the mount will point here FileSystem fsTarget; // the target file system - the mount will point here
FileSystem fsView; FileSystem fsView;
Configuration conf; Configuration conf;
FileSystemTestHelper fileSystemTestHelper = new FileSystemTestHelper();
static class TestLFS extends LocalFileSystem { class TestLFS extends LocalFileSystem {
Path home; Path home;
TestLFS() throws IOException { TestLFS() throws IOException {
this(new Path(FileSystemTestHelper.TEST_ROOT_DIR)); this(new Path(fileSystemTestHelper.getTestRootDir()));
} }
TestLFS(Path home) throws IOException { TestLFS(Path home) throws IOException {
super(); super();
@ -54,23 +55,23 @@ public Path getHomeDirectory() {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
fsTarget = FileSystem.getLocal(new Configuration()); fsTarget = FileSystem.getLocal(new Configuration());
fsTarget.mkdirs(new Path(FileSystemTestHelper. fsTarget.mkdirs(new Path(fileSystemTestHelper.
getTestRootPath(fsTarget), "dir1")); getTestRootPath(fsTarget), "dir1"));
conf = ViewFileSystemTestSetup.createConfig(); conf = ViewFileSystemTestSetup.createConfig();
fsView = ViewFileSystemTestSetup.setupForViewFileSystem(conf, fsTarget); fsView = ViewFileSystemTestSetup.setupForViewFileSystem(conf, fileSystemTestHelper, fsTarget);
conf.set("fs.defaultFS", FsConstants.VIEWFS_URI.toString()); conf.set("fs.defaultFS", FsConstants.VIEWFS_URI.toString());
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
ViewFileSystemTestSetup.tearDown(fsTarget); ViewFileSystemTestSetup.tearDown(fileSystemTestHelper, fsTarget);
fsTarget.delete(new Path(fsTarget.getHomeDirectory(), ".Trash/Current"), fsTarget.delete(new Path(fsTarget.getHomeDirectory(), ".Trash/Current"),
true); true);
} }
@Test @Test
public void testTrash() throws IOException { public void testTrash() throws IOException {
TestTrash.trashShell(conf, FileSystemTestHelper.getTestRootPath(fsView), TestTrash.trashShell(conf, fileSystemTestHelper.getTestRootPath(fsView),
fsTarget, new Path(fsTarget.getHomeDirectory(), ".Trash/Current")); fsTarget, new Path(fsTarget.getHomeDirectory(), ".Trash/Current"));
} }

View File

@ -68,7 +68,15 @@ public class ViewFileSystemBaseTest {
FileSystem fsTarget; // the target file system - the mount will point here FileSystem fsTarget; // the target file system - the mount will point here
Path targetTestRoot; Path targetTestRoot;
Configuration conf; Configuration conf;
final FileSystemTestHelper fileSystemTestHelper;
public ViewFileSystemBaseTest() {
this.fileSystemTestHelper = createFileSystemHelper();
}
protected FileSystemTestHelper createFileSystemHelper() {
return new FileSystemTestHelper();
}
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -94,11 +102,11 @@ public void setUp() throws Exception {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
fsTarget.delete(FileSystemTestHelper.getTestRootPath(fsTarget), true); fsTarget.delete(fileSystemTestHelper.getTestRootPath(fsTarget), true);
} }
void initializeTargetTestRoot() throws IOException { void initializeTargetTestRoot() throws IOException {
targetTestRoot = FileSystemTestHelper.getAbsoluteTestRootPath(fsTarget); targetTestRoot = fileSystemTestHelper.getAbsoluteTestRootPath(fsTarget);
// In case previous test was killed before cleanup // In case previous test was killed before cleanup
fsTarget.delete(targetTestRoot, true); fsTarget.delete(targetTestRoot, true);
@ -199,7 +207,7 @@ public void testBasicPaths() {
@Test @Test
public void testOperationsThroughMountLinks() throws IOException { public void testOperationsThroughMountLinks() throws IOException {
// Create file // Create file
FileSystemTestHelper.createFile(fsView, "/user/foo"); fileSystemTestHelper.createFile(fsView, "/user/foo");
Assert.assertTrue("Created file should be type file", Assert.assertTrue("Created file should be type file",
fsView.isFile(new Path("/user/foo"))); fsView.isFile(new Path("/user/foo")));
Assert.assertTrue("Target of created file should be type file", Assert.assertTrue("Target of created file should be type file",
@ -214,7 +222,7 @@ public void testOperationsThroughMountLinks() throws IOException {
fsTarget.exists(new Path(targetTestRoot,"user/foo"))); fsTarget.exists(new Path(targetTestRoot,"user/foo")));
// Create file with a 2 component dirs // Create file with a 2 component dirs
FileSystemTestHelper.createFile(fsView, "/internalDir/linkToDir2/foo"); fileSystemTestHelper.createFile(fsView, "/internalDir/linkToDir2/foo");
Assert.assertTrue("Created file should be type file", Assert.assertTrue("Created file should be type file",
fsView.isFile(new Path("/internalDir/linkToDir2/foo"))); fsView.isFile(new Path("/internalDir/linkToDir2/foo")));
Assert.assertTrue("Target of created file should be type file", Assert.assertTrue("Target of created file should be type file",
@ -230,14 +238,14 @@ public void testOperationsThroughMountLinks() throws IOException {
// Create file with a 3 component dirs // Create file with a 3 component dirs
FileSystemTestHelper.createFile(fsView, "/internalDir/internalDir2/linkToDir3/foo"); fileSystemTestHelper.createFile(fsView, "/internalDir/internalDir2/linkToDir3/foo");
Assert.assertTrue("Created file should be type file", Assert.assertTrue("Created file should be type file",
fsView.isFile(new Path("/internalDir/internalDir2/linkToDir3/foo"))); fsView.isFile(new Path("/internalDir/internalDir2/linkToDir3/foo")));
Assert.assertTrue("Target of created file should be type file", Assert.assertTrue("Target of created file should be type file",
fsTarget.isFile(new Path(targetTestRoot,"dir3/foo"))); fsTarget.isFile(new Path(targetTestRoot,"dir3/foo")));
// Recursive Create file with missing dirs // Recursive Create file with missing dirs
FileSystemTestHelper.createFile(fsView, fileSystemTestHelper.createFile(fsView,
"/internalDir/linkToDir2/missingDir/miss2/foo"); "/internalDir/linkToDir2/missingDir/miss2/foo");
Assert.assertTrue("Created file should be type file", Assert.assertTrue("Created file should be type file",
fsView.isFile(new Path("/internalDir/linkToDir2/missingDir/miss2/foo"))); fsView.isFile(new Path("/internalDir/linkToDir2/missingDir/miss2/foo")));
@ -256,14 +264,14 @@ public void testOperationsThroughMountLinks() throws IOException {
// mkdir // mkdir
fsView.mkdirs(FileSystemTestHelper.getTestRootPath(fsView, "/user/dirX")); fsView.mkdirs(fileSystemTestHelper.getTestRootPath(fsView, "/user/dirX"));
Assert.assertTrue("New dir should be type dir", Assert.assertTrue("New dir should be type dir",
fsView.isDirectory(new Path("/user/dirX"))); fsView.isDirectory(new Path("/user/dirX")));
Assert.assertTrue("Target of new dir should be of type dir", Assert.assertTrue("Target of new dir should be of type dir",
fsTarget.isDirectory(new Path(targetTestRoot,"user/dirX"))); fsTarget.isDirectory(new Path(targetTestRoot,"user/dirX")));
fsView.mkdirs( fsView.mkdirs(
FileSystemTestHelper.getTestRootPath(fsView, "/user/dirX/dirY")); fileSystemTestHelper.getTestRootPath(fsView, "/user/dirX/dirY"));
Assert.assertTrue("New dir should be type dir", Assert.assertTrue("New dir should be type dir",
fsView.isDirectory(new Path("/user/dirX/dirY"))); fsView.isDirectory(new Path("/user/dirX/dirY")));
Assert.assertTrue("Target of new dir should be of type dir", Assert.assertTrue("Target of new dir should be of type dir",
@ -285,14 +293,14 @@ public void testOperationsThroughMountLinks() throws IOException {
Assert.assertFalse(fsTarget.exists(new Path(targetTestRoot,"user/dirX"))); Assert.assertFalse(fsTarget.exists(new Path(targetTestRoot,"user/dirX")));
// Rename a file // Rename a file
FileSystemTestHelper.createFile(fsView, "/user/foo"); fileSystemTestHelper.createFile(fsView, "/user/foo");
fsView.rename(new Path("/user/foo"), new Path("/user/fooBar")); fsView.rename(new Path("/user/foo"), new Path("/user/fooBar"));
Assert.assertFalse("Renamed src should not exist", Assert.assertFalse("Renamed src should not exist",
fsView.exists(new Path("/user/foo"))); fsView.exists(new Path("/user/foo")));
Assert.assertFalse("Renamed src should not exist in target", Assert.assertFalse("Renamed src should not exist in target",
fsTarget.exists(new Path(targetTestRoot,"user/foo"))); fsTarget.exists(new Path(targetTestRoot,"user/foo")));
Assert.assertTrue("Renamed dest should exist as file", Assert.assertTrue("Renamed dest should exist as file",
fsView.isFile(FileSystemTestHelper.getTestRootPath(fsView,"/user/fooBar"))); fsView.isFile(fileSystemTestHelper.getTestRootPath(fsView,"/user/fooBar")));
Assert.assertTrue("Renamed dest should exist as file in target", Assert.assertTrue("Renamed dest should exist as file in target",
fsTarget.isFile(new Path(targetTestRoot,"user/fooBar"))); fsTarget.isFile(new Path(targetTestRoot,"user/fooBar")));
@ -303,7 +311,7 @@ public void testOperationsThroughMountLinks() throws IOException {
Assert.assertFalse("Renamed src should not exist in target", Assert.assertFalse("Renamed src should not exist in target",
fsTarget.exists(new Path(targetTestRoot,"user/dirFoo"))); fsTarget.exists(new Path(targetTestRoot,"user/dirFoo")));
Assert.assertTrue("Renamed dest should exist as dir", Assert.assertTrue("Renamed dest should exist as dir",
fsView.isDirectory(FileSystemTestHelper.getTestRootPath(fsView,"/user/dirFooBar"))); fsView.isDirectory(fileSystemTestHelper.getTestRootPath(fsView,"/user/dirFooBar")));
Assert.assertTrue("Renamed dest should exist as dir in target", Assert.assertTrue("Renamed dest should exist as dir in target",
fsTarget.isDirectory(new Path(targetTestRoot,"user/dirFooBar"))); fsTarget.isDirectory(new Path(targetTestRoot,"user/dirFooBar")));
@ -322,7 +330,7 @@ public void testOperationsThroughMountLinks() throws IOException {
// rename across mount points that point to same target also fail // rename across mount points that point to same target also fail
@Test(expected=IOException.class) @Test(expected=IOException.class)
public void testRenameAcrossMounts1() throws IOException { public void testRenameAcrossMounts1() throws IOException {
FileSystemTestHelper.createFile(fsView, "/user/foo"); fileSystemTestHelper.createFile(fsView, "/user/foo");
fsView.rename(new Path("/user/foo"), new Path("/user2/fooBarBar")); fsView.rename(new Path("/user/foo"), new Path("/user2/fooBarBar"));
/* - code if we had wanted this to suceed /* - code if we had wanted this to suceed
Assert.assertFalse(fSys.exists(new Path("/user/foo"))); Assert.assertFalse(fSys.exists(new Path("/user/foo")));
@ -338,7 +346,7 @@ public void testRenameAcrossMounts1() throws IOException {
@Test(expected=IOException.class) @Test(expected=IOException.class)
public void testRenameAcrossMounts2() throws IOException { public void testRenameAcrossMounts2() throws IOException {
FileSystemTestHelper.createFile(fsView, "/user/foo"); fileSystemTestHelper.createFile(fsView, "/user/foo");
fsView.rename(new Path("/user/foo"), new Path("/data/fooBar")); fsView.rename(new Path("/user/foo"), new Path("/data/fooBar"));
} }
@ -394,19 +402,19 @@ public void testListOnInternalDirsOfMountTable() throws IOException {
FileStatus[] dirPaths = fsView.listStatus(new Path("/")); FileStatus[] dirPaths = fsView.listStatus(new Path("/"));
FileStatus fs; FileStatus fs;
Assert.assertEquals(getExpectedDirPaths(), dirPaths.length); Assert.assertEquals(getExpectedDirPaths(), dirPaths.length);
fs = FileSystemTestHelper.containsPath(fsView, "/user", dirPaths); fs = fileSystemTestHelper.containsPath(fsView, "/user", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
fs = FileSystemTestHelper.containsPath(fsView, "/data", dirPaths); fs = fileSystemTestHelper.containsPath(fsView, "/data", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
fs = FileSystemTestHelper.containsPath(fsView, "/internalDir", dirPaths); fs = fileSystemTestHelper.containsPath(fsView, "/internalDir", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("A mount should appear as symlink", fs.isDirectory()); Assert.assertTrue("A mount should appear as symlink", fs.isDirectory());
fs = FileSystemTestHelper.containsPath(fsView, "/danglingLink", dirPaths); fs = fileSystemTestHelper.containsPath(fsView, "/danglingLink", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
fs = FileSystemTestHelper.containsPath(fsView, "/linkToAFile", dirPaths); fs = fileSystemTestHelper.containsPath(fsView, "/linkToAFile", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
@ -416,10 +424,10 @@ public void testListOnInternalDirsOfMountTable() throws IOException {
dirPaths = fsView.listStatus(new Path("/internalDir")); dirPaths = fsView.listStatus(new Path("/internalDir"));
Assert.assertEquals(2, dirPaths.length); Assert.assertEquals(2, dirPaths.length);
fs = FileSystemTestHelper.containsPath(fsView, "/internalDir/internalDir2", dirPaths); fs = fileSystemTestHelper.containsPath(fsView, "/internalDir/internalDir2", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("A mount should appear as symlink", fs.isDirectory()); Assert.assertTrue("A mount should appear as symlink", fs.isDirectory());
fs = FileSystemTestHelper.containsPath(fsView, "/internalDir/linkToDir2", fs = fileSystemTestHelper.containsPath(fsView, "/internalDir/linkToDir2",
dirPaths); dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
@ -436,22 +444,22 @@ public void testListOnMountTargetDirs() throws IOException {
Assert.assertEquals(0, dirPaths.length); Assert.assertEquals(0, dirPaths.length);
// add a file // add a file
long len = FileSystemTestHelper.createFile(fsView, "/data/foo"); long len = fileSystemTestHelper.createFile(fsView, "/data/foo");
dirPaths = fsView.listStatus(new Path("/data")); dirPaths = fsView.listStatus(new Path("/data"));
Assert.assertEquals(1, dirPaths.length); Assert.assertEquals(1, dirPaths.length);
fs = FileSystemTestHelper.containsPath(fsView, "/data/foo", dirPaths); fs = fileSystemTestHelper.containsPath(fsView, "/data/foo", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("Created file shoudl appear as a file", fs.isFile()); Assert.assertTrue("Created file shoudl appear as a file", fs.isFile());
Assert.assertEquals(len, fs.getLen()); Assert.assertEquals(len, fs.getLen());
// add a dir // add a dir
fsView.mkdirs(FileSystemTestHelper.getTestRootPath(fsView, "/data/dirX")); fsView.mkdirs(fileSystemTestHelper.getTestRootPath(fsView, "/data/dirX"));
dirPaths = fsView.listStatus(new Path("/data")); dirPaths = fsView.listStatus(new Path("/data"));
Assert.assertEquals(2, dirPaths.length); Assert.assertEquals(2, dirPaths.length);
fs = FileSystemTestHelper.containsPath(fsView, "/data/foo", dirPaths); fs = fileSystemTestHelper.containsPath(fsView, "/data/foo", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("Created file shoudl appear as a file", fs.isFile()); Assert.assertTrue("Created file shoudl appear as a file", fs.isFile());
fs = FileSystemTestHelper.containsPath(fsView, "/data/dirX", dirPaths); fs = fileSystemTestHelper.containsPath(fsView, "/data/dirX", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("Created dir should appear as a dir", fs.isDirectory()); Assert.assertTrue("Created dir should appear as a dir", fs.isDirectory());
} }
@ -504,18 +512,18 @@ public void testResolvePathMountPoints() throws IOException {
@Test @Test
public void testResolvePathThroughMountPoints() throws IOException { public void testResolvePathThroughMountPoints() throws IOException {
FileSystemTestHelper.createFile(fsView, "/user/foo"); fileSystemTestHelper.createFile(fsView, "/user/foo");
Assert.assertEquals(new Path(targetTestRoot,"user/foo"), Assert.assertEquals(new Path(targetTestRoot,"user/foo"),
fsView.resolvePath(new Path("/user/foo"))); fsView.resolvePath(new Path("/user/foo")));
fsView.mkdirs( fsView.mkdirs(
FileSystemTestHelper.getTestRootPath(fsView, "/user/dirX")); fileSystemTestHelper.getTestRootPath(fsView, "/user/dirX"));
Assert.assertEquals(new Path(targetTestRoot,"user/dirX"), Assert.assertEquals(new Path(targetTestRoot,"user/dirX"),
fsView.resolvePath(new Path("/user/dirX"))); fsView.resolvePath(new Path("/user/dirX")));
fsView.mkdirs( fsView.mkdirs(
FileSystemTestHelper.getTestRootPath(fsView, "/user/dirX/dirY")); fileSystemTestHelper.getTestRootPath(fsView, "/user/dirX/dirY"));
Assert.assertEquals(new Path(targetTestRoot,"user/dirX/dirY"), Assert.assertEquals(new Path(targetTestRoot,"user/dirX/dirY"),
fsView.resolvePath(new Path("/user/dirX/dirY"))); fsView.resolvePath(new Path("/user/dirX/dirY")));
} }
@ -534,7 +542,7 @@ public void testResolvePathMissingThroughMountPoints() throws IOException {
@Test(expected=FileNotFoundException.class) @Test(expected=FileNotFoundException.class)
public void testResolvePathMissingThroughMountPoints2() throws IOException { public void testResolvePathMissingThroughMountPoints2() throws IOException {
fsView.mkdirs( fsView.mkdirs(
FileSystemTestHelper.getTestRootPath(fsView, "/user/dirX")); fileSystemTestHelper.getTestRootPath(fsView, "/user/dirX"));
fsView.resolvePath(new Path("/user/dirX/nonExisting")); fsView.resolvePath(new Path("/user/dirX/nonExisting"));
} }
@ -550,57 +558,57 @@ public void testResolvePathMissingThroughMountPoints2() throws IOException {
// Mkdir on existing internal mount table succeed except for / // Mkdir on existing internal mount table succeed except for /
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalMkdirSlash() throws IOException { public void testInternalMkdirSlash() throws IOException {
fsView.mkdirs(FileSystemTestHelper.getTestRootPath(fsView, "/")); fsView.mkdirs(fileSystemTestHelper.getTestRootPath(fsView, "/"));
} }
public void testInternalMkdirExisting1() throws IOException { public void testInternalMkdirExisting1() throws IOException {
Assert.assertTrue("mkdir of existing dir should succeed", Assert.assertTrue("mkdir of existing dir should succeed",
fsView.mkdirs(FileSystemTestHelper.getTestRootPath(fsView, fsView.mkdirs(fileSystemTestHelper.getTestRootPath(fsView,
"/internalDir"))); "/internalDir")));
} }
public void testInternalMkdirExisting2() throws IOException { public void testInternalMkdirExisting2() throws IOException {
Assert.assertTrue("mkdir of existing dir should succeed", Assert.assertTrue("mkdir of existing dir should succeed",
fsView.mkdirs(FileSystemTestHelper.getTestRootPath(fsView, fsView.mkdirs(fileSystemTestHelper.getTestRootPath(fsView,
"/internalDir/linkToDir2"))); "/internalDir/linkToDir2")));
} }
// Mkdir for new internal mount table should fail // Mkdir for new internal mount table should fail
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalMkdirNew() throws IOException { public void testInternalMkdirNew() throws IOException {
fsView.mkdirs(FileSystemTestHelper.getTestRootPath(fsView, "/dirNew")); fsView.mkdirs(fileSystemTestHelper.getTestRootPath(fsView, "/dirNew"));
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalMkdirNew2() throws IOException { public void testInternalMkdirNew2() throws IOException {
fsView.mkdirs(FileSystemTestHelper.getTestRootPath(fsView, "/internalDir/dirNew")); fsView.mkdirs(fileSystemTestHelper.getTestRootPath(fsView, "/internalDir/dirNew"));
} }
// Create File on internal mount table should fail // Create File on internal mount table should fail
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalCreate1() throws IOException { public void testInternalCreate1() throws IOException {
FileSystemTestHelper.createFile(fsView, "/foo"); // 1 component fileSystemTestHelper.createFile(fsView, "/foo"); // 1 component
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalCreate2() throws IOException { // 2 component public void testInternalCreate2() throws IOException { // 2 component
FileSystemTestHelper.createFile(fsView, "/internalDir/foo"); fileSystemTestHelper.createFile(fsView, "/internalDir/foo");
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalCreateMissingDir() throws IOException { public void testInternalCreateMissingDir() throws IOException {
FileSystemTestHelper.createFile(fsView, "/missingDir/foo"); fileSystemTestHelper.createFile(fsView, "/missingDir/foo");
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalCreateMissingDir2() throws IOException { public void testInternalCreateMissingDir2() throws IOException {
FileSystemTestHelper.createFile(fsView, "/missingDir/miss2/foo"); fileSystemTestHelper.createFile(fsView, "/missingDir/miss2/foo");
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalCreateMissingDir3() throws IOException { public void testInternalCreateMissingDir3() throws IOException {
FileSystemTestHelper.createFile(fsView, "/internalDir/miss2/foo"); fileSystemTestHelper.createFile(fsView, "/internalDir/miss2/foo");
} }
// Delete on internal mount table should fail // Delete on internal mount table should fail
@ -665,7 +673,7 @@ public void testInternalSetOwner() throws IOException {
@Test @Test
public void testCreateNonRecursive() throws IOException { public void testCreateNonRecursive() throws IOException {
Path path = FileSystemTestHelper.getTestRootPath(fsView, "/user/foo"); Path path = fileSystemTestHelper.getTestRootPath(fsView, "/user/foo");
fsView.createNonRecursive(path, false, 1024, (short)1, 1024L, null); fsView.createNonRecursive(path, false, 1024, (short)1, 1024L, null);
FileStatus status = fsView.getFileStatus(new Path("/user/foo")); FileStatus status = fsView.getFileStatus(new Path("/user/foo"));
Assert.assertTrue("Created file should be type file", Assert.assertTrue("Created file should be type file",

View File

@ -55,18 +55,18 @@ public class ViewFileSystemTestSetup {
* @return return the ViewFS File context to be used for tests * @return return the ViewFS File context to be used for tests
* @throws Exception * @throws Exception
*/ */
static public FileSystem setupForViewFileSystem(Configuration conf, FileSystem fsTarget) throws Exception { static public FileSystem setupForViewFileSystem(Configuration conf, FileSystemTestHelper fileSystemTestHelper, FileSystem fsTarget) throws Exception {
/** /**
* create the test root on local_fs - the mount table will point here * create the test root on local_fs - the mount table will point here
*/ */
Path targetOfTests = FileSystemTestHelper.getTestRootPath(fsTarget); Path targetOfTests = fileSystemTestHelper.getTestRootPath(fsTarget);
// In case previous test was killed before cleanup // In case previous test was killed before cleanup
fsTarget.delete(targetOfTests, true); fsTarget.delete(targetOfTests, true);
fsTarget.mkdirs(targetOfTests); fsTarget.mkdirs(targetOfTests);
// Set up viewfs link for test dir as described above // Set up viewfs link for test dir as described above
String testDir = FileSystemTestHelper.getTestRootPath(fsTarget).toUri() String testDir = fileSystemTestHelper.getTestRootPath(fsTarget).toUri()
.getPath(); .getPath();
linkUpFirstComponents(conf, testDir, fsTarget, "test dir"); linkUpFirstComponents(conf, testDir, fsTarget, "test dir");
@ -91,14 +91,21 @@ static public FileSystem setupForViewFileSystem(Configuration conf, FileSystem f
* *
* delete the test directory in the target fs * delete the test directory in the target fs
*/ */
static public void tearDown(FileSystem fsTarget) throws Exception { static public void tearDown(FileSystemTestHelper fileSystemTestHelper, FileSystem fsTarget) throws Exception {
Path targetOfTests = FileSystemTestHelper.getTestRootPath(fsTarget); Path targetOfTests = fileSystemTestHelper.getTestRootPath(fsTarget);
fsTarget.delete(targetOfTests, true); fsTarget.delete(targetOfTests, true);
} }
public static Configuration createConfig() { public static Configuration createConfig() {
return createConfig(true);
}
public static Configuration createConfig(boolean disableCache) {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
conf.set("fs.viewfs.impl", ViewFileSystem.class.getName()); conf.set("fs.viewfs.impl", ViewFileSystem.class.getName());
if (disableCache) {
conf.set("fs.viewfs.impl.disable.cache", "true");
}
return conf; return conf;
} }

View File

@ -75,6 +75,7 @@ public class ViewFsBaseTest {
Configuration conf; Configuration conf;
FileContext xfcViewWithAuthority; // same as fsView but with authority FileContext xfcViewWithAuthority; // same as fsView but with authority
URI schemeWithAuthority; URI schemeWithAuthority;
final FileContextTestHelper fileContextTestHelper = new FileContextTestHelper();
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -118,7 +119,7 @@ public void setUp() throws Exception {
} }
void initializeTargetTestRoot() throws IOException { void initializeTargetTestRoot() throws IOException {
targetTestRoot = FileContextTestHelper.getAbsoluteTestRootPath(fcTarget); targetTestRoot = fileContextTestHelper.getAbsoluteTestRootPath(fcTarget);
// In case previous test was killed before cleanup // In case previous test was killed before cleanup
fcTarget.delete(targetTestRoot, true); fcTarget.delete(targetTestRoot, true);
@ -127,7 +128,7 @@ void initializeTargetTestRoot() throws IOException {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
fcTarget.delete(FileContextTestHelper.getTestRootPath(fcTarget), true); fcTarget.delete(fileContextTestHelper.getTestRootPath(fcTarget), true);
} }
@Test @Test
@ -181,7 +182,7 @@ public void testBasicPaths() {
@Test @Test
public void testOperationsThroughMountLinks() throws IOException { public void testOperationsThroughMountLinks() throws IOException {
// Create file // Create file
FileContextTestHelper.createFileNonRecursive(fcView, "/user/foo"); fileContextTestHelper.createFileNonRecursive(fcView, "/user/foo");
Assert.assertTrue("Create file should be file", Assert.assertTrue("Create file should be file",
isFile(fcView, new Path("/user/foo"))); isFile(fcView, new Path("/user/foo")));
Assert.assertTrue("Target of created file should be type file", Assert.assertTrue("Target of created file should be type file",
@ -196,7 +197,7 @@ public void testOperationsThroughMountLinks() throws IOException {
exists(fcTarget, new Path(targetTestRoot,"user/foo"))); exists(fcTarget, new Path(targetTestRoot,"user/foo")));
// Create file with a 2 component dirs // Create file with a 2 component dirs
FileContextTestHelper.createFileNonRecursive(fcView, fileContextTestHelper.createFileNonRecursive(fcView,
"/internalDir/linkToDir2/foo"); "/internalDir/linkToDir2/foo");
Assert.assertTrue("Created file should be type file", Assert.assertTrue("Created file should be type file",
isFile(fcView, new Path("/internalDir/linkToDir2/foo"))); isFile(fcView, new Path("/internalDir/linkToDir2/foo")));
@ -213,7 +214,7 @@ public void testOperationsThroughMountLinks() throws IOException {
// Create file with a 3 component dirs // Create file with a 3 component dirs
FileContextTestHelper.createFileNonRecursive(fcView, fileContextTestHelper.createFileNonRecursive(fcView,
"/internalDir/internalDir2/linkToDir3/foo"); "/internalDir/internalDir2/linkToDir3/foo");
Assert.assertTrue("Created file should be of type file", Assert.assertTrue("Created file should be of type file",
isFile(fcView, new Path("/internalDir/internalDir2/linkToDir3/foo"))); isFile(fcView, new Path("/internalDir/internalDir2/linkToDir3/foo")));
@ -221,7 +222,7 @@ public void testOperationsThroughMountLinks() throws IOException {
isFile(fcTarget, new Path(targetTestRoot,"dir3/foo"))); isFile(fcTarget, new Path(targetTestRoot,"dir3/foo")));
// Recursive Create file with missing dirs // Recursive Create file with missing dirs
FileContextTestHelper.createFile(fcView, fileContextTestHelper.createFile(fcView,
"/internalDir/linkToDir2/missingDir/miss2/foo"); "/internalDir/linkToDir2/missingDir/miss2/foo");
Assert.assertTrue("Created file should be of type file", Assert.assertTrue("Created file should be of type file",
isFile(fcView, new Path("/internalDir/linkToDir2/missingDir/miss2/foo"))); isFile(fcView, new Path("/internalDir/linkToDir2/missingDir/miss2/foo")));
@ -239,14 +240,14 @@ public void testOperationsThroughMountLinks() throws IOException {
// mkdir // mkdir
fcView.mkdir(FileContextTestHelper.getTestRootPath(fcView, "/user/dirX"), fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/user/dirX"),
FileContext.DEFAULT_PERM, false); FileContext.DEFAULT_PERM, false);
Assert.assertTrue("New dir should be type dir", Assert.assertTrue("New dir should be type dir",
isDir(fcView, new Path("/user/dirX"))); isDir(fcView, new Path("/user/dirX")));
Assert.assertTrue("Target of new dir should be of type dir", Assert.assertTrue("Target of new dir should be of type dir",
isDir(fcTarget, new Path(targetTestRoot,"user/dirX"))); isDir(fcTarget, new Path(targetTestRoot,"user/dirX")));
fcView.mkdir(FileContextTestHelper.getTestRootPath(fcView, "/user/dirX/dirY"), fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/user/dirX/dirY"),
FileContext.DEFAULT_PERM, false); FileContext.DEFAULT_PERM, false);
Assert.assertTrue("New dir should be type dir", Assert.assertTrue("New dir should be type dir",
isDir(fcView, new Path("/user/dirX/dirY"))); isDir(fcView, new Path("/user/dirX/dirY")));
@ -270,13 +271,13 @@ public void testOperationsThroughMountLinks() throws IOException {
exists(fcTarget, new Path(targetTestRoot,"user/dirX"))); exists(fcTarget, new Path(targetTestRoot,"user/dirX")));
// Rename a file // Rename a file
FileContextTestHelper.createFile(fcView, "/user/foo"); fileContextTestHelper.createFile(fcView, "/user/foo");
fcView.rename(new Path("/user/foo"), new Path("/user/fooBar")); fcView.rename(new Path("/user/foo"), new Path("/user/fooBar"));
Assert.assertFalse("Renamed src should not exist", Assert.assertFalse("Renamed src should not exist",
exists(fcView, new Path("/user/foo"))); exists(fcView, new Path("/user/foo")));
Assert.assertFalse(exists(fcTarget, new Path(targetTestRoot,"user/foo"))); Assert.assertFalse(exists(fcTarget, new Path(targetTestRoot,"user/foo")));
Assert.assertTrue(isFile(fcView, Assert.assertTrue(isFile(fcView,
FileContextTestHelper.getTestRootPath(fcView,"/user/fooBar"))); fileContextTestHelper.getTestRootPath(fcView,"/user/fooBar")));
Assert.assertTrue(isFile(fcTarget, new Path(targetTestRoot,"user/fooBar"))); Assert.assertTrue(isFile(fcTarget, new Path(targetTestRoot,"user/fooBar")));
fcView.mkdir(new Path("/user/dirFoo"), FileContext.DEFAULT_PERM, false); fcView.mkdir(new Path("/user/dirFoo"), FileContext.DEFAULT_PERM, false);
@ -287,7 +288,7 @@ public void testOperationsThroughMountLinks() throws IOException {
exists(fcTarget, new Path(targetTestRoot,"user/dirFoo"))); exists(fcTarget, new Path(targetTestRoot,"user/dirFoo")));
Assert.assertTrue("Renamed dest should exist as dir", Assert.assertTrue("Renamed dest should exist as dir",
isDir(fcView, isDir(fcView,
FileContextTestHelper.getTestRootPath(fcView,"/user/dirFooBar"))); fileContextTestHelper.getTestRootPath(fcView,"/user/dirFooBar")));
Assert.assertTrue("Renamed dest should exist as dir in target", Assert.assertTrue("Renamed dest should exist as dir in target",
isDir(fcTarget,new Path(targetTestRoot,"user/dirFooBar"))); isDir(fcTarget,new Path(targetTestRoot,"user/dirFooBar")));
@ -309,7 +310,7 @@ public void testOperationsThroughMountLinks() throws IOException {
// rename across mount points that point to same target also fail // rename across mount points that point to same target also fail
@Test(expected=IOException.class) @Test(expected=IOException.class)
public void testRenameAcrossMounts1() throws IOException { public void testRenameAcrossMounts1() throws IOException {
FileContextTestHelper.createFile(fcView, "/user/foo"); fileContextTestHelper.createFile(fcView, "/user/foo");
fcView.rename(new Path("/user/foo"), new Path("/user2/fooBarBar")); fcView.rename(new Path("/user/foo"), new Path("/user2/fooBarBar"));
/* - code if we had wanted this to succeed /* - code if we had wanted this to succeed
Assert.assertFalse(exists(fc, new Path("/user/foo"))); Assert.assertFalse(exists(fc, new Path("/user/foo")));
@ -327,7 +328,7 @@ public void testRenameAcrossMounts1() throws IOException {
@Test(expected=IOException.class) @Test(expected=IOException.class)
public void testRenameAcrossMounts2() throws IOException { public void testRenameAcrossMounts2() throws IOException {
FileContextTestHelper.createFile(fcView, "/user/foo"); fileContextTestHelper.createFile(fcView, "/user/foo");
fcView.rename(new Path("/user/foo"), new Path("/data/fooBar")); fcView.rename(new Path("/user/foo"), new Path("/data/fooBar"));
} }
@ -382,19 +383,19 @@ public void testListOnInternalDirsOfMountTable() throws IOException {
FileStatus[] dirPaths = fcView.util().listStatus(new Path("/")); FileStatus[] dirPaths = fcView.util().listStatus(new Path("/"));
FileStatus fs; FileStatus fs;
Assert.assertEquals(7, dirPaths.length); Assert.assertEquals(7, dirPaths.length);
fs = FileContextTestHelper.containsPath(fcView, "/user", dirPaths); fs = fileContextTestHelper.containsPath(fcView, "/user", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
fs = FileContextTestHelper.containsPath(fcView, "/data", dirPaths); fs = fileContextTestHelper.containsPath(fcView, "/data", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
fs = FileContextTestHelper.containsPath(fcView, "/internalDir", dirPaths); fs = fileContextTestHelper.containsPath(fcView, "/internalDir", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("InternalDirs should appear as dir", fs.isDirectory()); Assert.assertTrue("InternalDirs should appear as dir", fs.isDirectory());
fs = FileContextTestHelper.containsPath(fcView, "/danglingLink", dirPaths); fs = fileContextTestHelper.containsPath(fcView, "/danglingLink", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
fs = FileContextTestHelper.containsPath(fcView, "/linkToAFile", dirPaths); fs = fileContextTestHelper.containsPath(fcView, "/linkToAFile", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
@ -404,11 +405,11 @@ public void testListOnInternalDirsOfMountTable() throws IOException {
dirPaths = fcView.util().listStatus(new Path("/internalDir")); dirPaths = fcView.util().listStatus(new Path("/internalDir"));
Assert.assertEquals(2, dirPaths.length); Assert.assertEquals(2, dirPaths.length);
fs = FileContextTestHelper.containsPath(fcView, fs = fileContextTestHelper.containsPath(fcView,
"/internalDir/internalDir2", dirPaths); "/internalDir/internalDir2", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("InternalDirs should appear as dir",fs.isDirectory()); Assert.assertTrue("InternalDirs should appear as dir",fs.isDirectory());
fs = FileContextTestHelper.containsPath(fcView, fs = fileContextTestHelper.containsPath(fcView,
"/internalDir/linkToDir2", dirPaths); "/internalDir/linkToDir2", dirPaths);
Assert.assertNotNull(fs); Assert.assertNotNull(fs);
Assert.assertTrue("A mount should appear as symlink", fs.isSymlink()); Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
@ -534,19 +535,19 @@ public void testResolvePathMountPoints() throws IOException {
@Test @Test
public void testResolvePathThroughMountPoints() throws IOException { public void testResolvePathThroughMountPoints() throws IOException {
FileContextTestHelper.createFile(fcView, "/user/foo"); fileContextTestHelper.createFile(fcView, "/user/foo");
Assert.assertEquals(new Path(targetTestRoot,"user/foo"), Assert.assertEquals(new Path(targetTestRoot,"user/foo"),
fcView.resolvePath(new Path("/user/foo"))); fcView.resolvePath(new Path("/user/foo")));
fcView.mkdir( fcView.mkdir(
FileContextTestHelper.getTestRootPath(fcView, "/user/dirX"), fileContextTestHelper.getTestRootPath(fcView, "/user/dirX"),
FileContext.DEFAULT_PERM, false); FileContext.DEFAULT_PERM, false);
Assert.assertEquals(new Path(targetTestRoot,"user/dirX"), Assert.assertEquals(new Path(targetTestRoot,"user/dirX"),
fcView.resolvePath(new Path("/user/dirX"))); fcView.resolvePath(new Path("/user/dirX")));
fcView.mkdir( fcView.mkdir(
FileContextTestHelper.getTestRootPath(fcView, "/user/dirX/dirY"), fileContextTestHelper.getTestRootPath(fcView, "/user/dirX/dirY"),
FileContext.DEFAULT_PERM, false); FileContext.DEFAULT_PERM, false);
Assert.assertEquals(new Path(targetTestRoot,"user/dirX/dirY"), Assert.assertEquals(new Path(targetTestRoot,"user/dirX/dirY"),
fcView.resolvePath(new Path("/user/dirX/dirY"))); fcView.resolvePath(new Path("/user/dirX/dirY")));
@ -566,7 +567,7 @@ public void testResolvePathMissingThroughMountPoints() throws IOException {
@Test(expected=FileNotFoundException.class) @Test(expected=FileNotFoundException.class)
public void testResolvePathMissingThroughMountPoints2() throws IOException { public void testResolvePathMissingThroughMountPoints2() throws IOException {
fcView.mkdir( fcView.mkdir(
FileContextTestHelper.getTestRootPath(fcView, "/user/dirX"), fileContextTestHelper.getTestRootPath(fcView, "/user/dirX"),
FileContext.DEFAULT_PERM, false); FileContext.DEFAULT_PERM, false);
fcView.resolvePath(new Path("/user/dirX/nonExisting")); fcView.resolvePath(new Path("/user/dirX/nonExisting"));
} }
@ -584,29 +585,29 @@ public void testResolvePathMissingThroughMountPoints2() throws IOException {
// Mkdir on internal mount table should fail // Mkdir on internal mount table should fail
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalMkdirSlash() throws IOException { public void testInternalMkdirSlash() throws IOException {
fcView.mkdir(FileContextTestHelper.getTestRootPath(fcView, "/"), fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/"),
FileContext.DEFAULT_PERM, false); FileContext.DEFAULT_PERM, false);
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalMkdirExisting1() throws IOException { public void testInternalMkdirExisting1() throws IOException {
fcView.mkdir(FileContextTestHelper.getTestRootPath(fcView, "/internalDir"), fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/internalDir"),
FileContext.DEFAULT_PERM, false); FileContext.DEFAULT_PERM, false);
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalMkdirExisting2() throws IOException { public void testInternalMkdirExisting2() throws IOException {
fcView.mkdir(FileContextTestHelper.getTestRootPath(fcView, fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView,
"/internalDir/linkToDir2"), "/internalDir/linkToDir2"),
FileContext.DEFAULT_PERM, false); FileContext.DEFAULT_PERM, false);
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalMkdirNew() throws IOException { public void testInternalMkdirNew() throws IOException {
fcView.mkdir(FileContextTestHelper.getTestRootPath(fcView, "/dirNew"), fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/dirNew"),
FileContext.DEFAULT_PERM, false); FileContext.DEFAULT_PERM, false);
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalMkdirNew2() throws IOException { public void testInternalMkdirNew2() throws IOException {
fcView.mkdir(FileContextTestHelper.getTestRootPath(fcView, "/internalDir/dirNew"), fcView.mkdir(fileContextTestHelper.getTestRootPath(fcView, "/internalDir/dirNew"),
FileContext.DEFAULT_PERM, false); FileContext.DEFAULT_PERM, false);
} }
@ -614,28 +615,28 @@ public void testInternalMkdirNew2() throws IOException {
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalCreate1() throws IOException { public void testInternalCreate1() throws IOException {
FileContextTestHelper.createFileNonRecursive(fcView, "/foo"); // 1 component fileContextTestHelper.createFileNonRecursive(fcView, "/foo"); // 1 component
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalCreate2() throws IOException { // 2 component public void testInternalCreate2() throws IOException { // 2 component
FileContextTestHelper.createFileNonRecursive(fcView, "/internalDir/foo"); fileContextTestHelper.createFileNonRecursive(fcView, "/internalDir/foo");
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalCreateMissingDir() throws IOException { public void testInternalCreateMissingDir() throws IOException {
FileContextTestHelper.createFile(fcView, "/missingDir/foo"); fileContextTestHelper.createFile(fcView, "/missingDir/foo");
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalCreateMissingDir2() throws IOException { public void testInternalCreateMissingDir2() throws IOException {
FileContextTestHelper.createFile(fcView, "/missingDir/miss2/foo"); fileContextTestHelper.createFile(fcView, "/missingDir/miss2/foo");
} }
@Test(expected=AccessControlException.class) @Test(expected=AccessControlException.class)
public void testInternalCreateMissingDir3() throws IOException { public void testInternalCreateMissingDir3() throws IOException {
FileContextTestHelper.createFile(fcView, "/internalDir/miss2/foo"); fileContextTestHelper.createFile(fcView, "/internalDir/miss2/foo");
} }
// Delete on internal mount table should fail // Delete on internal mount table should fail

View File

@ -53,12 +53,12 @@ public class ViewFsTestSetup {
/* /*
* return the ViewFS File context to be used for tests * return the ViewFS File context to be used for tests
*/ */
static public FileContext setupForViewFsLocalFs() throws Exception { static public FileContext setupForViewFsLocalFs(FileContextTestHelper helper) throws Exception {
/** /**
* create the test root on local_fs - the mount table will point here * create the test root on local_fs - the mount table will point here
*/ */
FileContext fsTarget = FileContext.getLocalFSFileContext(); FileContext fsTarget = FileContext.getLocalFSFileContext();
Path targetOfTests = FileContextTestHelper.getTestRootPath(fsTarget); Path targetOfTests = helper.getTestRootPath(fsTarget);
// In case previous test was killed before cleanup // In case previous test was killed before cleanup
fsTarget.delete(targetOfTests, true); fsTarget.delete(targetOfTests, true);
@ -66,7 +66,7 @@ static public FileContext setupForViewFsLocalFs() throws Exception {
Configuration conf = new Configuration(); Configuration conf = new Configuration();
// Set up viewfs link for test dir as described above // Set up viewfs link for test dir as described above
String testDir = FileContextTestHelper.getTestRootPath(fsTarget).toUri() String testDir = helper.getTestRootPath(fsTarget).toUri()
.getPath(); .getPath();
linkUpFirstComponents(conf, testDir, fsTarget, "test dir"); linkUpFirstComponents(conf, testDir, fsTarget, "test dir");
@ -91,9 +91,9 @@ static public FileContext setupForViewFsLocalFs() throws Exception {
* *
* delete the test directory in the target local fs * delete the test directory in the target local fs
*/ */
static public void tearDownForViewFsLocalFs() throws Exception { static public void tearDownForViewFsLocalFs(FileContextTestHelper helper) throws Exception {
FileContext fclocal = FileContext.getLocalFSFileContext(); FileContext fclocal = FileContext.getLocalFSFileContext();
Path targetOfTests = FileContextTestHelper.getTestRootPath(fclocal); Path targetOfTests = helper.getTestRootPath(fclocal);
fclocal.delete(targetOfTests, true); fclocal.delete(targetOfTests, true);
} }

View File

@ -23,7 +23,10 @@
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.Socket; import java.net.Socket;
import java.nio.channels.FileLock;
import java.nio.channels.OverlappingFileLockException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -63,17 +66,13 @@ public abstract class ClientBaseWithFixes extends ZKTestCase {
static final File BASETEST = static final File BASETEST =
new File(System.getProperty("build.test.dir", "build")); new File(System.getProperty("build.test.dir", "build"));
protected String hostPort = "127.0.0.1:" + PortAssignment.unique(); protected final String hostPort = initHostPort();
protected int maxCnxns = 0; protected int maxCnxns = 0;
protected ServerCnxnFactory serverFactory = null; protected ServerCnxnFactory serverFactory = null;
protected File tmpDir = null; protected File tmpDir = null;
long initialFdCount; long initialFdCount;
public ClientBaseWithFixes() {
super();
}
/** /**
* In general don't use this. Only use in the special case that you * In general don't use this. Only use in the special case that you
* want to ignore results (for whatever reason) in your test. Don't * want to ignore results (for whatever reason) in your test. Don't
@ -154,6 +153,10 @@ protected TestableZooKeeper createClient(String hp)
private LinkedList<ZooKeeper> allClients; private LinkedList<ZooKeeper> allClients;
private boolean allClientsSetup = false; private boolean allClientsSetup = false;
private RandomAccessFile portNumLockFile;
private File portNumFile;
protected TestableZooKeeper createClient(CountdownWatcher watcher, String hp) protected TestableZooKeeper createClient(CountdownWatcher watcher, String hp)
throws IOException, InterruptedException throws IOException, InterruptedException
{ {
@ -311,6 +314,7 @@ static File createTmpDir(File parentDir) throws IOException {
return tmpDir; return tmpDir;
} }
private static int getPort(String hostPort) { private static int getPort(String hostPort) {
String[] split = hostPort.split(":"); String[] split = hostPort.split(":");
String portstr = split[split.length-1]; String portstr = split[split.length-1];
@ -394,6 +398,35 @@ public void setUp() throws Exception {
LOG.info("Client test setup finished"); LOG.info("Client test setup finished");
} }
private String initHostPort() {
BASETEST.mkdirs();
int port;
for (;;) {
port = PortAssignment.unique();
FileLock lock = null;
portNumLockFile = null;
try {
try {
portNumFile = new File(BASETEST, port + ".lock");
portNumLockFile = new RandomAccessFile(portNumFile, "rw");
try {
lock = portNumLockFile.getChannel().tryLock();
} catch (OverlappingFileLockException e) {
continue;
}
} finally {
if (lock != null)
break;
if (portNumLockFile != null)
portNumLockFile.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return "127.0.0.1:" + port;
}
protected void startServer() throws Exception { protected void startServer() throws Exception {
LOG.info("STARTING server"); LOG.info("STARTING server");
serverFactory = createNewServerInstance(tmpDir, serverFactory, hostPort, maxCnxns); serverFactory = createNewServerInstance(tmpDir, serverFactory, hostPort, maxCnxns);
@ -434,6 +467,9 @@ public void tearDown() throws Exception {
stopServer(); stopServer();
portNumLockFile.close();
portNumFile.delete();
if (tmpDir != null) { if (tmpDir != null) {
Assert.assertTrue("delete " + tmpDir.toString(), recursiveDelete(tmpDir)); Assert.assertTrue("delete " + tmpDir.toString(), recursiveDelete(tmpDir));
} }

View File

@ -39,7 +39,9 @@
public class TestSequenceFile extends TestCase { public class TestSequenceFile extends TestCase {
private static final Log LOG = LogFactory.getLog(TestSequenceFile.class); private static final Log LOG = LogFactory.getLog(TestSequenceFile.class);
private static Configuration conf = new Configuration(); private Configuration conf = new Configuration();
public TestSequenceFile() { }
public TestSequenceFile(String name) { super(name); } public TestSequenceFile(String name) { super(name); }
@ -126,7 +128,7 @@ public void compressedSeqFileTest(CompressionCodec codec) throws Exception {
} }
} }
private static void writeTest(FileSystem fs, int count, int seed, Path file, private void writeTest(FileSystem fs, int count, int seed, Path file,
CompressionType compressionType, CompressionCodec codec) CompressionType compressionType, CompressionCodec codec)
throws IOException { throws IOException {
fs.delete(file, true); fs.delete(file, true);
@ -146,7 +148,7 @@ private static void writeTest(FileSystem fs, int count, int seed, Path file,
writer.close(); writer.close();
} }
private static void readTest(FileSystem fs, int count, int seed, Path file) private void readTest(FileSystem fs, int count, int seed, Path file)
throws IOException { throws IOException {
LOG.debug("reading " + count + " records"); LOG.debug("reading " + count + " records");
SequenceFile.Reader reader = new SequenceFile.Reader(fs, file, conf); SequenceFile.Reader reader = new SequenceFile.Reader(fs, file, conf);
@ -202,7 +204,7 @@ private static void readTest(FileSystem fs, int count, int seed, Path file)
} }
private static void sortTest(FileSystem fs, int count, int megabytes, private void sortTest(FileSystem fs, int count, int megabytes,
int factor, boolean fast, Path file) int factor, boolean fast, Path file)
throws IOException { throws IOException {
fs.delete(new Path(file+".sorted"), true); fs.delete(new Path(file+".sorted"), true);
@ -212,7 +214,7 @@ private static void sortTest(FileSystem fs, int count, int megabytes,
LOG.info("done sorting " + count + " debug"); LOG.info("done sorting " + count + " debug");
} }
private static void checkSort(FileSystem fs, int count, int seed, Path file) private void checkSort(FileSystem fs, int count, int seed, Path file)
throws IOException { throws IOException {
LOG.info("sorting " + count + " records in memory for debug"); LOG.info("sorting " + count + " records in memory for debug");
RandomDatum.Generator generator = new RandomDatum.Generator(seed); RandomDatum.Generator generator = new RandomDatum.Generator(seed);
@ -249,7 +251,7 @@ private static void checkSort(FileSystem fs, int count, int seed, Path file)
LOG.debug("sucessfully checked " + count + " records"); LOG.debug("sucessfully checked " + count + " records");
} }
private static void mergeTest(FileSystem fs, int count, int seed, Path file, private void mergeTest(FileSystem fs, int count, int seed, Path file,
CompressionType compressionType, CompressionType compressionType,
boolean fast, int factor, int megabytes) boolean fast, int factor, int megabytes)
throws IOException { throws IOException {
@ -293,7 +295,7 @@ private static void mergeTest(FileSystem fs, int count, int seed, Path file,
.merge(sortedNames, file.suffix(".sorted")); .merge(sortedNames, file.suffix(".sorted"));
} }
private static SequenceFile.Sorter newSorter(FileSystem fs, private SequenceFile.Sorter newSorter(FileSystem fs,
boolean fast, boolean fast,
int megabytes, int factor) { int megabytes, int factor) {
SequenceFile.Sorter sorter = SequenceFile.Sorter sorter =
@ -370,7 +372,7 @@ public void testSequenceFileMetadata() throws Exception {
} }
private static SequenceFile.Metadata readMetadata(FileSystem fs, Path file) private SequenceFile.Metadata readMetadata(FileSystem fs, Path file)
throws IOException { throws IOException {
LOG.info("reading file: " + file.toString()); LOG.info("reading file: " + file.toString());
SequenceFile.Reader reader = new SequenceFile.Reader(fs, file, conf); SequenceFile.Reader reader = new SequenceFile.Reader(fs, file, conf);
@ -379,7 +381,7 @@ private static SequenceFile.Metadata readMetadata(FileSystem fs, Path file)
return meta; return meta;
} }
private static void writeMetadataTest(FileSystem fs, int count, int seed, Path file, private void writeMetadataTest(FileSystem fs, int count, int seed, Path file,
CompressionType compressionType, CompressionCodec codec, SequenceFile.Metadata metadata) CompressionType compressionType, CompressionCodec codec, SequenceFile.Metadata metadata)
throws IOException { throws IOException {
fs.delete(file, true); fs.delete(file, true);
@ -399,7 +401,7 @@ private static void writeMetadataTest(FileSystem fs, int count, int seed, Path f
writer.close(); writer.close();
} }
private static void sortMetadataTest(FileSystem fs, Path unsortedFile, Path sortedFile, SequenceFile.Metadata metadata) private void sortMetadataTest(FileSystem fs, Path unsortedFile, Path sortedFile, SequenceFile.Metadata metadata)
throws IOException { throws IOException {
fs.delete(sortedFile, true); fs.delete(sortedFile, true);
LOG.info("sorting: " + unsortedFile + " to: " + sortedFile); LOG.info("sorting: " + unsortedFile + " to: " + sortedFile);
@ -538,7 +540,6 @@ public void testCreateWriterOnExistingFile() throws IOException {
} }
public void testRecursiveSeqFileCreate() throws IOException { public void testRecursiveSeqFileCreate() throws IOException {
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(System.getProperty("test.build.data","."),
"recursiveCreateDir") , "file"); "recursiveCreateDir") , "file");
@ -673,7 +674,9 @@ public static void main(String[] args) throws Exception {
} }
} }
fs = file.getFileSystem(conf); TestSequenceFile test = new TestSequenceFile();
fs = file.getFileSystem(test.conf);
LOG.info("count = " + count); LOG.info("count = " + count);
LOG.info("megabytes = " + megabytes); LOG.info("megabytes = " + megabytes);
@ -696,25 +699,25 @@ public static void main(String[] args) throws Exception {
CompressionType compressionType = CompressionType compressionType =
CompressionType.valueOf(compressType); CompressionType.valueOf(compressType);
CompressionCodec codec = (CompressionCodec)ReflectionUtils.newInstance( CompressionCodec codec = (CompressionCodec)ReflectionUtils.newInstance(
conf.getClassByName(compressionCodec), test.conf.getClassByName(compressionCodec),
conf); test.conf);
if (rwonly || (create && !merge)) { if (rwonly || (create && !merge)) {
writeTest(fs, count, seed, file, compressionType, codec); test.writeTest(fs, count, seed, file, compressionType, codec);
readTest(fs, count, seed, file); test.readTest(fs, count, seed, file);
} }
if (!rwonly) { if (!rwonly) {
if (merge) { if (merge) {
mergeTest(fs, count, seed, file, compressionType, test.mergeTest(fs, count, seed, file, compressionType,
fast, factor, megabytes); fast, factor, megabytes);
} else { } else {
sortTest(fs, count, megabytes, factor, fast, file); test.sortTest(fs, count, megabytes, factor, fast, file);
} }
} }
if (check) { if (check) {
checkSort(fs, count, seed, file); test.checkSort(fs, count, seed, file);
} }
} finally { } finally {
fs.close(); fs.close();

View File

@ -46,7 +46,7 @@ protected void tearDown() throws Exception {
public void testJavaSerialization() throws Exception { public void testJavaSerialization() throws Exception {
Path file = new Path(System.getProperty("test.build.data",".") + Path file = new Path(System.getProperty("test.build.data",".") +
"/test.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

@ -64,7 +64,7 @@ public class TestTFileByteArrays {
private String compression = Compression.Algorithm.GZ.getName(); private String compression = Compression.Algorithm.GZ.getName();
private String comparator = "memcmp"; private String comparator = "memcmp";
private String outputFile = "TFileTestByteArrays"; private final String outputFile = getClass().getSimpleName();
/* /*
* pre-sampled numbers of records in one block, based on the given the * pre-sampled numbers of records in one block, based on the given the
@ -75,17 +75,16 @@ public class TestTFileByteArrays {
private int records1stBlock = usingNative ? 5674 : 4480; private int records1stBlock = usingNative ? 5674 : 4480;
private int records2ndBlock = usingNative ? 5574 : 4263; private int records2ndBlock = usingNative ? 5574 : 4263;
public void init(String compression, String comparator, String outputFile, public void init(String compression, String comparator,
int numRecords1stBlock, int numRecords2ndBlock) { int numRecords1stBlock, int numRecords2ndBlock) {
init(compression, comparator, outputFile); init(compression, comparator);
this.records1stBlock = numRecords1stBlock; this.records1stBlock = numRecords1stBlock;
this.records2ndBlock = numRecords2ndBlock; this.records2ndBlock = numRecords2ndBlock;
} }
public void init(String compression, String comparator, String outputFile) { public void init(String compression, String comparator) {
this.compression = compression; this.compression = compression;
this.comparator = comparator; this.comparator = comparator;
this.outputFile = outputFile;
} }
@Before @Before

View File

@ -37,8 +37,7 @@ public class TestTFileJClassComparatorByteArrays extends TestTFileByteArrays {
@Override @Override
public void setUp() throws IOException { public void setUp() throws IOException {
init(Compression.Algorithm.GZ.getName(), init(Compression.Algorithm.GZ.getName(),
"jclass: org.apache.hadoop.io.file.tfile.MyComparator", "jclass: org.apache.hadoop.io.file.tfile.MyComparator");
"TFileTestJClassComparator");
super.setUp(); super.setUp();
} }
} }

View File

@ -34,8 +34,7 @@ public void setUp() throws IOException {
} }
// TODO: sample the generated key/value records, and put the numbers below // TODO: sample the generated key/value records, and put the numbers below
init(Compression.Algorithm.LZO.getName(), "memcmp", "TFileTestCodecsLzo", init(Compression.Algorithm.LZO.getName(), "memcmp", 2605, 2558);
2605, 2558);
if (!skip) if (!skip)
super.setUp(); super.setUp();
} }

View File

@ -32,7 +32,7 @@ public void setUp() throws IOException {
if (skip) { if (skip) {
System.out.println("Skipped"); System.out.println("Skipped");
} }
init(Compression.Algorithm.LZO.getName(), "memcmp", "TFileTestCodecsLzo"); init(Compression.Algorithm.LZO.getName(), "memcmp");
if (!skip) if (!skip)
super.setUp(); super.setUp();
} }

View File

@ -25,8 +25,7 @@ public class TestTFileNoneCodecsByteArrays extends TestTFileByteArrays {
*/ */
@Override @Override
public void setUp() throws IOException { public void setUp() throws IOException {
init(Compression.Algorithm.NONE.getName(), "memcmp", "TFileTestCodecsNone", init(Compression.Algorithm.NONE.getName(), "memcmp", 24, 24);
24, 24);
super.setUp(); super.setUp();
} }
} }

View File

@ -33,8 +33,7 @@ public class TestTFileNoneCodecsJClassComparatorByteArrays extends TestTFileByte
@Override @Override
public void setUp() throws IOException { public void setUp() throws IOException {
init(Compression.Algorithm.NONE.getName(), init(Compression.Algorithm.NONE.getName(),
"jclass: org.apache.hadoop.io.file.tfile.MyComparator", "jclass: org.apache.hadoop.io.file.tfile.MyComparator", 24, 24);
"TestTFileNoneCodecsJClassComparatorByteArrays", 24, 24);
super.setUp(); super.setUp();
} }
} }

View File

@ -26,7 +26,7 @@ public class TestTFileNoneCodecsStreams extends TestTFileStreams {
*/ */
@Override @Override
public void setUp() throws IOException { public void setUp() throws IOException {
init(Compression.Algorithm.NONE.getName(), "memcmp", "TFileTestCodecsNone"); init(Compression.Algorithm.NONE.getName(), "memcmp");
super.setUp(); super.setUp();
} }
} }

View File

@ -57,12 +57,11 @@ public class TestTFileStreams extends TestCase {
private String compression = Compression.Algorithm.GZ.getName(); private String compression = Compression.Algorithm.GZ.getName();
private String comparator = "memcmp"; private String comparator = "memcmp";
private String outputFile = "TFileTestStreams"; private final String outputFile = getClass().getSimpleName();
public void init(String compression, String comparator, String outputFile) { public void init(String compression, String comparator) {
this.compression = compression; this.compression = compression;
this.comparator = comparator; this.comparator = comparator;
this.outputFile = outputFile;
} }
@Override @Override

View File

@ -64,6 +64,9 @@
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class TestMetricsSystemImpl { public class TestMetricsSystemImpl {
private static final Log LOG = LogFactory.getLog(TestMetricsSystemImpl.class); private static final Log LOG = LogFactory.getLog(TestMetricsSystemImpl.class);
static { DefaultMetricsSystem.setMiniClusterMode(true); }
@Captor private ArgumentCaptor<MetricsRecord> r1; @Captor private ArgumentCaptor<MetricsRecord> r1;
@Captor private ArgumentCaptor<MetricsRecord> r2; @Captor private ArgumentCaptor<MetricsRecord> r2;
private static String hostname = MetricsSystemImpl.getHostname(); private static String hostname = MetricsSystemImpl.getHostname();

View File

@ -35,9 +35,22 @@
public class TestFcHdfsPermission extends FileContextPermissionBase { public class TestFcHdfsPermission extends FileContextPermissionBase {
private static final FileContextTestHelper fileContextTestHelper = new FileContextTestHelper();
private static FileContext fc;
private static MiniDFSCluster cluster; private static MiniDFSCluster cluster;
private static Path defaultWorkingDirectory; private static Path defaultWorkingDirectory;
@Override
protected FileContextTestHelper getFileContextHelper() {
return fileContextTestHelper;
}
@Override
protected FileContext getFileContext() {
return fc;
}
@BeforeClass @BeforeClass
public static void clusterSetupAtBegining() public static void clusterSetupAtBegining()
throws IOException, LoginException, URISyntaxException { throws IOException, LoginException, URISyntaxException {

View File

@ -42,6 +42,7 @@
public class TestFcHdfsSetUMask { public class TestFcHdfsSetUMask {
private static FileContextTestHelper fileContextTestHelper = new FileContextTestHelper();
private static MiniDFSCluster cluster; private static MiniDFSCluster cluster;
private static Path defaultWorkingDirectory; private static Path defaultWorkingDirectory;
private static FileContext fc; private static FileContext fc;
@ -110,12 +111,12 @@ public static void ClusterShutdownAtEnd() throws Exception {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
fc.setUMask(WIDE_OPEN_TEST_UMASK); fc.setUMask(WIDE_OPEN_TEST_UMASK);
fc.mkdir(getTestRootPath(fc), FileContext.DEFAULT_PERM, true); fc.mkdir(fileContextTestHelper.getTestRootPath(fc), FileContext.DEFAULT_PERM, true);
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
fc.delete(getTestRootPath(fc), true); fc.delete(fileContextTestHelper.getTestRootPath(fc), true);
} }
@Test @Test
@ -199,7 +200,7 @@ public void testCreateRecursiveWithNonExistingDirMiddle() throws IOException {
public void testMkdirWithExistingDir(FsPermission umask, public void testMkdirWithExistingDir(FsPermission umask,
FsPermission expectedPerms) throws IOException { FsPermission expectedPerms) throws IOException {
Path f = getTestRootPath(fc, "aDir"); Path f = fileContextTestHelper.getTestRootPath(fc, "aDir");
fc.setUMask(umask); fc.setUMask(umask);
fc.mkdir(f, FileContext.DEFAULT_PERM, true); fc.mkdir(f, FileContext.DEFAULT_PERM, true);
Assert.assertTrue(isDir(fc, f)); Assert.assertTrue(isDir(fc, f));
@ -210,13 +211,13 @@ public void testMkdirWithExistingDir(FsPermission umask,
public void testMkdirRecursiveWithNonExistingDir(FsPermission umask, public void testMkdirRecursiveWithNonExistingDir(FsPermission umask,
FsPermission expectedPerms, FsPermission expectedParentPerms) FsPermission expectedPerms, FsPermission expectedParentPerms)
throws IOException { throws IOException {
Path f = getTestRootPath(fc, "NonExistant2/aDir"); Path f = fileContextTestHelper.getTestRootPath(fc, "NonExistant2/aDir");
fc.setUMask(umask); fc.setUMask(umask);
fc.mkdir(f, FileContext.DEFAULT_PERM, true); fc.mkdir(f, FileContext.DEFAULT_PERM, true);
Assert.assertTrue(isDir(fc, f)); Assert.assertTrue(isDir(fc, f));
Assert.assertEquals("permissions on directory are wrong", Assert.assertEquals("permissions on directory are wrong",
expectedPerms, fc.getFileStatus(f).getPermission()); expectedPerms, fc.getFileStatus(f).getPermission());
Path fParent = getTestRootPath(fc, "NonExistant2"); Path fParent = fileContextTestHelper.getTestRootPath(fc, "NonExistant2");
Assert.assertEquals("permissions on parent directory are wrong", Assert.assertEquals("permissions on parent directory are wrong",
expectedParentPerms, fc.getFileStatus(fParent).getPermission()); expectedParentPerms, fc.getFileStatus(fParent).getPermission());
} }
@ -224,7 +225,7 @@ public void testMkdirRecursiveWithNonExistingDir(FsPermission umask,
public void testCreateRecursiveWithExistingDir(FsPermission umask, public void testCreateRecursiveWithExistingDir(FsPermission umask,
FsPermission expectedPerms) throws IOException { FsPermission expectedPerms) throws IOException {
Path f = getTestRootPath(fc,"foo"); Path f = fileContextTestHelper.getTestRootPath(fc,"foo");
fc.setUMask(umask); fc.setUMask(umask);
createFile(fc, f); createFile(fc, f);
Assert.assertTrue(isFile(fc, f)); Assert.assertTrue(isFile(fc, f));
@ -236,8 +237,8 @@ public void testCreateRecursiveWithExistingDir(FsPermission umask,
public void testCreateRecursiveWithNonExistingDir(FsPermission umask, public void testCreateRecursiveWithNonExistingDir(FsPermission umask,
FsPermission expectedDirPerms, FsPermission expectedFilePerms) FsPermission expectedDirPerms, FsPermission expectedFilePerms)
throws IOException { throws IOException {
Path f = getTestRootPath(fc,"NonExisting/foo"); Path f = fileContextTestHelper.getTestRootPath(fc,"NonExisting/foo");
Path fParent = getTestRootPath(fc, "NonExisting"); Path fParent = fileContextTestHelper.getTestRootPath(fc, "NonExisting");
Assert.assertFalse(exists(fc, fParent)); Assert.assertFalse(exists(fc, fParent));
fc.setUMask(umask); fc.setUMask(umask);
createFile(fc, f); createFile(fc, f);

View File

@ -17,7 +17,6 @@
*/ */
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import static org.apache.hadoop.fs.FileContextTestHelper.getAbsoluteTestRootDir;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -51,11 +50,11 @@ public class TestFcHdfsSymlink extends FileContextSymlinkBaseTest {
((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ALL); ((Log4JLogger)NameNode.stateChangeLog).getLogger().setLevel(Level.ALL);
} }
private static FileContextTestHelper fileContextTestHelper = new FileContextTestHelper();
private static MiniDFSCluster cluster; private static MiniDFSCluster cluster;
private static WebHdfsFileSystem webhdfs; private static WebHdfsFileSystem webhdfs;
private static DistributedFileSystem dfs; private static DistributedFileSystem dfs;
@Override @Override
protected String getScheme() { protected String getScheme() {
return "hdfs"; return "hdfs";
@ -103,10 +102,10 @@ public static void testTearDown() throws Exception {
@Test @Test
/** Access a file using a link that spans Hdfs to LocalFs */ /** Access a file using a link that spans Hdfs to LocalFs */
public void testLinkAcrossFileSystems() throws IOException { public void testLinkAcrossFileSystems() throws IOException {
Path localDir = new Path("file://"+getAbsoluteTestRootDir(fc)+"/test");
Path localFile = new Path("file://"+getAbsoluteTestRootDir(fc)+"/test/file");
Path link = new Path(testBaseDir1(), "linkToFile");
FileContext localFc = FileContext.getLocalFSFileContext(); FileContext localFc = FileContext.getLocalFSFileContext();
Path localDir = new Path("file://"+fileContextTestHelper.getAbsoluteTestRootDir(localFc)+"/test");
Path localFile = new Path("file://"+fileContextTestHelper.getAbsoluteTestRootDir(localFc)+"/test/file");
Path link = new Path(testBaseDir1(), "linkToFile");
localFc.delete(localDir, true); localFc.delete(localDir, true);
localFc.mkdir(localDir, FileContext.DEFAULT_PERM, true); localFc.mkdir(localDir, FileContext.DEFAULT_PERM, true);
localFc.setWorkingDirectory(localDir); localFc.setWorkingDirectory(localDir);
@ -120,12 +119,12 @@ public void testLinkAcrossFileSystems() throws IOException {
@Test @Test
/** Test renaming a file across two file systems using a link */ /** Test renaming a file across two file systems using a link */
public void testRenameAcrossFileSystemsViaLink() throws IOException { public void testRenameAcrossFileSystemsViaLink() throws IOException {
Path localDir = new Path("file://"+getAbsoluteTestRootDir(fc)+"/test"); FileContext localFc = FileContext.getLocalFSFileContext();
Path localDir = new Path("file://"+fileContextTestHelper.getAbsoluteTestRootDir(localFc)+"/test");
Path hdfsFile = new Path(testBaseDir1(), "file"); Path hdfsFile = new Path(testBaseDir1(), "file");
Path link = new Path(testBaseDir1(), "link"); Path link = new Path(testBaseDir1(), "link");
Path hdfsFileNew = new Path(testBaseDir1(), "fileNew"); Path hdfsFileNew = new Path(testBaseDir1(), "fileNew");
Path hdfsFileNewViaLink = new Path(link, "fileNew"); Path hdfsFileNewViaLink = new Path(link, "fileNew");
FileContext localFc = FileContext.getLocalFSFileContext();
localFc.delete(localDir, true); localFc.delete(localDir, true);
localFc.mkdir(localDir, FileContext.DEFAULT_PERM, true); localFc.mkdir(localDir, FileContext.DEFAULT_PERM, true);
localFc.setWorkingDirectory(localDir); localFc.setWorkingDirectory(localDir);

View File

@ -19,7 +19,6 @@
package org.apache.hadoop.fs; package org.apache.hadoop.fs;
import static org.apache.hadoop.fs.FileContextTestHelper.exists; import static org.apache.hadoop.fs.FileContextTestHelper.exists;
import static org.apache.hadoop.fs.FileContextTestHelper.getTestRootPath;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -42,6 +41,7 @@
public class TestHDFSFileContextMainOperations extends public class TestHDFSFileContextMainOperations extends
FileContextMainOperationsBaseTest { FileContextMainOperationsBaseTest {
private static FileContextTestHelper fileContextTestHelper = new FileContextTestHelper();
private static MiniDFSCluster cluster; private static MiniDFSCluster cluster;
private static Path defaultWorkingDirectory; private static Path defaultWorkingDirectory;
private static HdfsConfiguration CONF = new HdfsConfiguration(); private static HdfsConfiguration CONF = new HdfsConfiguration();
@ -101,6 +101,10 @@ protected IOException unwrapException(IOException e) {
return e; return e;
} }
private Path getTestRootPath(FileContext fc, String path) {
return fileContextTestHelper.getTestRootPath(fc, path);
}
@Test @Test
public void testOldRenameWithQuota() throws Exception { public void testOldRenameWithQuota() throws Exception {
DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem(); DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem();

View File

@ -25,6 +25,7 @@
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
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.FileSystemTestHelper;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.MiniDFSCluster; import org.apache.hadoop.hdfs.MiniDFSCluster;
@ -42,6 +43,11 @@ public class TestViewFileSystemAtHdfsRoot extends ViewFileSystemBaseTest {
private static Configuration CONF = new Configuration(); private static Configuration CONF = new Configuration();
private static FileSystem fHdfs; private static FileSystem fHdfs;
@Override
protected FileSystemTestHelper createFileSystemHelper() {
return new FileSystemTestHelper("/tmp/TestViewFileSystemAtHdfsRoot");
}
@BeforeClass @BeforeClass
public static void clusterSetupAtBegining() throws IOException, public static void clusterSetupAtBegining() throws IOException,
LoginException, URISyntaxException { LoginException, URISyntaxException {

View File

@ -48,6 +48,11 @@ public class TestViewFileSystemHdfs extends ViewFileSystemBaseTest {
private FileSystem fsTarget2; private FileSystem fsTarget2;
Path targetTestRoot2; Path targetTestRoot2;
@Override
protected FileSystemTestHelper createFileSystemHelper() {
return new FileSystemTestHelper("/tmp/TestViewFileSystemHdfs");
}
@BeforeClass @BeforeClass
public static void clusterSetupAtBegining() throws IOException, public static void clusterSetupAtBegining() throws IOException,
LoginException, URISyntaxException { LoginException, URISyntaxException {
@ -86,7 +91,7 @@ public void setUp() throws Exception {
// create the test root on local_fs // create the test root on local_fs
fsTarget = fHdfs; fsTarget = fHdfs;
fsTarget2 = fHdfs2; fsTarget2 = fHdfs2;
targetTestRoot2 = FileSystemTestHelper.getAbsoluteTestRootPath(fsTarget2); targetTestRoot2 = new FileSystemTestHelper().getAbsoluteTestRootPath(fsTarget2);
super.setUp(); super.setUp();
} }

View File

@ -52,6 +52,7 @@ public class TestViewFsFileStatusHdfs {
static final String testfilename = "/tmp/testFileStatusSerialziation"; static final String testfilename = "/tmp/testFileStatusSerialziation";
static final String someFile = "/hdfstmp/someFileForTestGetFileChecksum"; static final String someFile = "/hdfstmp/someFileForTestGetFileChecksum";
private static final FileSystemTestHelper fileSystemTestHelper = new FileSystemTestHelper();
private static MiniDFSCluster cluster; private static MiniDFSCluster cluster;
private static Path defaultWorkingDirectory; private static Path defaultWorkingDirectory;
private static Configuration CONF = new Configuration(); private static Configuration CONF = new Configuration();
@ -79,7 +80,7 @@ public static void clusterSetupAtBegining() throws IOException,
@Test @Test
public void testFileStatusSerialziation() public void testFileStatusSerialziation()
throws IOException, URISyntaxException { throws IOException, URISyntaxException {
long len = FileSystemTestHelper.createFile(fHdfs, testfilename); long len = fileSystemTestHelper.createFile(fHdfs, testfilename);
FileStatus stat = vfs.getFileStatus(new Path(testfilename)); FileStatus stat = vfs.getFileStatus(new Path(testfilename));
assertEquals(len, stat.getLen()); assertEquals(len, stat.getLen());
// check serialization/deserialization // check serialization/deserialization
@ -95,8 +96,8 @@ public void testFileStatusSerialziation()
@Test @Test
public void testGetFileChecksum() throws IOException, URISyntaxException { public void testGetFileChecksum() throws IOException, URISyntaxException {
// Create two different files in HDFS // Create two different files in HDFS
FileSystemTestHelper.createFile(fHdfs, someFile); fileSystemTestHelper.createFile(fHdfs, someFile);
FileSystemTestHelper.createFile(fHdfs, FileSystemTestHelper fileSystemTestHelper.createFile(fHdfs, fileSystemTestHelper
.getTestRootPath(fHdfs, someFile + "other"), 1, 512); .getTestRootPath(fHdfs, someFile + "other"), 1, 512);
// Get checksum through ViewFS // Get checksum through ViewFS
FileChecksum viewFSCheckSum = vfs.getFileChecksum( FileChecksum viewFSCheckSum = vfs.getFileChecksum(

View File

@ -17,9 +17,6 @@
*/ */
package org.apache.hadoop.hdfs.web; package org.apache.hadoop.hdfs.web;
import static org.apache.hadoop.fs.FileSystemTestHelper.exists;
import static org.apache.hadoop.fs.FileSystemTestHelper.getTestRootPath;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
@ -52,6 +49,12 @@ public class TestFSMainOperationsWebHdfs extends FSMainOperationsBaseTest {
private static MiniDFSCluster cluster = null; private static MiniDFSCluster cluster = null;
private static Path defaultWorkingDirectory; private static Path defaultWorkingDirectory;
private static FileSystem fileSystem;
@Override
protected FileSystem createFileSystem() throws Exception {
return fileSystem;
}
@BeforeClass @BeforeClass
public static void setupCluster() { public static void setupCluster() {
@ -73,14 +76,14 @@ public static void setupCluster() {
final UserGroupInformation current = UserGroupInformation.getCurrentUser(); final UserGroupInformation current = UserGroupInformation.getCurrentUser();
final UserGroupInformation ugi = UserGroupInformation.createUserForTesting( final UserGroupInformation ugi = UserGroupInformation.createUserForTesting(
current.getShortUserName() + "x", new String[]{"user"}); current.getShortUserName() + "x", new String[]{"user"});
fSys = ugi.doAs(new PrivilegedExceptionAction<FileSystem>() { fileSystem = ugi.doAs(new PrivilegedExceptionAction<FileSystem>() {
@Override @Override
public FileSystem run() throws Exception { public FileSystem run() throws Exception {
return FileSystem.get(new URI(uri), conf); return FileSystem.get(new URI(uri), conf);
} }
}); });
defaultWorkingDirectory = fSys.getWorkingDirectory(); defaultWorkingDirectory = fileSystem.getWorkingDirectory();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -36,6 +36,9 @@
<test.exclude>_</test.exclude> <test.exclude>_</test.exclude>
<test.exclude.pattern>_</test.exclude.pattern> <test.exclude.pattern>_</test.exclude.pattern>
<!-- number of threads/forks to use when running tests in parallel, see parallel-tests profile -->
<testsThreadCount>4</testsThreadCount>
<!-- platform encoding override --> <!-- platform encoding override -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@ -1004,5 +1007,23 @@
</plugins> </plugins>
</build> </build>
</profile> </profile>
<!-- Copied into specific modules supporting parallel testing. Will be uncommented as soon as all modules support this.
<profile>
<id>parallel-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>perthread</forkMode>
<threadCount>${testsThreadCount}</threadCount>
<parallel>classes</parallel>
</configuration>
</plugin>
</plugins>
</build>
</profile>
-->
</profiles> </profiles>
</project> </project>

View File

@ -56,7 +56,7 @@ private static Configuration getConf() throws URISyntaxException {
public static void setup() throws URISyntaxException{ public static void setup() throws URISyntaxException{
try { try {
Path fswd = FileSystem.get(getConf()).getWorkingDirectory(); Path fswd = FileSystem.get(getConf()).getWorkingDirectory();
Configuration vConf = ViewFileSystemTestSetup.createConfig(); Configuration vConf = ViewFileSystemTestSetup.createConfig(false);
ConfigUtil.addLink(vConf, "/usr", new URI(fswd.toString())); ConfigUtil.addLink(vConf, "/usr", new URI(fswd.toString()));
fs = FileSystem.get(FsConstants.VIEWFS_URI, vConf); fs = FileSystem.get(FsConstants.VIEWFS_URI, vConf);
fs.setWorkingDirectory(new Path("/usr")); fs.setWorkingDirectory(new Path("/usr"));