|
@@ -19,8 +19,10 @@
|
|
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.junit.Assert.fail;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.net.URI;
|
|
import java.net.URISyntaxException;
|
|
import java.net.URISyntaxException;
|
|
|
|
|
|
import javax.security.auth.login.LoginException;
|
|
import javax.security.auth.login.LoginException;
|
|
@@ -55,7 +57,8 @@ public class TestHDFSFileContextMainOperations extends
|
|
LoginException, URISyntaxException {
|
|
LoginException, URISyntaxException {
|
|
cluster = new MiniDFSCluster.Builder(CONF).numDataNodes(2).build();
|
|
cluster = new MiniDFSCluster.Builder(CONF).numDataNodes(2).build();
|
|
cluster.waitClusterUp();
|
|
cluster.waitClusterUp();
|
|
- fc = FileContext.getFileContext(cluster.getURI(0), CONF);
|
|
|
|
|
|
+ URI uri0 = cluster.getURI(0);
|
|
|
|
+ fc = FileContext.getFileContext(uri0, CONF);
|
|
defaultWorkingDirectory = fc.makeQualified( new Path("/user/" +
|
|
defaultWorkingDirectory = fc.makeQualified( new Path("/user/" +
|
|
UserGroupInformation.getCurrentUser().getShortUserName()));
|
|
UserGroupInformation.getCurrentUser().getShortUserName()));
|
|
fc.mkdir(defaultWorkingDirectory, FileContext.DEFAULT_PERM, true);
|
|
fc.mkdir(defaultWorkingDirectory, FileContext.DEFAULT_PERM, true);
|
|
@@ -77,7 +80,10 @@ public class TestHDFSFileContextMainOperations extends
|
|
|
|
|
|
@AfterClass
|
|
@AfterClass
|
|
public static void ClusterShutdownAtEnd() throws Exception {
|
|
public static void ClusterShutdownAtEnd() throws Exception {
|
|
- cluster.shutdown();
|
|
|
|
|
|
+ if (cluster != null) {
|
|
|
|
+ cluster.shutdown();
|
|
|
|
+ cluster = null;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -111,7 +117,7 @@ public class TestHDFSFileContextMainOperations extends
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testOldRenameWithQuota() throws Exception {
|
|
public void testOldRenameWithQuota() throws Exception {
|
|
- DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem();
|
|
|
|
|
|
+ DistributedFileSystem fs = cluster.getFileSystem();
|
|
Path src1 = getTestRootPath(fc, "test/testOldRenameWithQuota/srcdir/src1");
|
|
Path src1 = getTestRootPath(fc, "test/testOldRenameWithQuota/srcdir/src1");
|
|
Path src2 = getTestRootPath(fc, "test/testOldRenameWithQuota/srcdir/src2");
|
|
Path src2 = getTestRootPath(fc, "test/testOldRenameWithQuota/srcdir/src2");
|
|
Path dst1 = getTestRootPath(fc, "test/testOldRenameWithQuota/dstdir/dst1");
|
|
Path dst1 = getTestRootPath(fc, "test/testOldRenameWithQuota/dstdir/dst1");
|
|
@@ -146,7 +152,7 @@ public class TestHDFSFileContextMainOperations extends
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void testRenameWithQuota() throws Exception {
|
|
public void testRenameWithQuota() throws Exception {
|
|
- DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem();
|
|
|
|
|
|
+ DistributedFileSystem fs = cluster.getFileSystem();
|
|
Path src1 = getTestRootPath(fc, "test/testRenameWithQuota/srcdir/src1");
|
|
Path src1 = getTestRootPath(fc, "test/testRenameWithQuota/srcdir/src1");
|
|
Path src2 = getTestRootPath(fc, "test/testRenameWithQuota/srcdir/src2");
|
|
Path src2 = getTestRootPath(fc, "test/testRenameWithQuota/srcdir/src2");
|
|
Path dst1 = getTestRootPath(fc, "test/testRenameWithQuota/dstdir/dst1");
|
|
Path dst1 = getTestRootPath(fc, "test/testRenameWithQuota/dstdir/dst1");
|
|
@@ -210,7 +216,7 @@ public class TestHDFSFileContextMainOperations extends
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testEditsLogOldRename() throws Exception {
|
|
public void testEditsLogOldRename() throws Exception {
|
|
- DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem();
|
|
|
|
|
|
+ DistributedFileSystem fs = cluster.getFileSystem();
|
|
Path src1 = getTestRootPath(fc, "testEditsLogOldRename/srcdir/src1");
|
|
Path src1 = getTestRootPath(fc, "testEditsLogOldRename/srcdir/src1");
|
|
Path dst1 = getTestRootPath(fc, "testEditsLogOldRename/dstdir/dst1");
|
|
Path dst1 = getTestRootPath(fc, "testEditsLogOldRename/dstdir/dst1");
|
|
createFile(src1);
|
|
createFile(src1);
|
|
@@ -226,7 +232,7 @@ public class TestHDFSFileContextMainOperations extends
|
|
// Restart the cluster and ensure the above operations can be
|
|
// Restart the cluster and ensure the above operations can be
|
|
// loaded from the edits log
|
|
// loaded from the edits log
|
|
restartCluster();
|
|
restartCluster();
|
|
- fs = (DistributedFileSystem)cluster.getFileSystem();
|
|
|
|
|
|
+ fs = cluster.getFileSystem();
|
|
src1 = getTestRootPath(fc, "testEditsLogOldRename/srcdir/src1");
|
|
src1 = getTestRootPath(fc, "testEditsLogOldRename/srcdir/src1");
|
|
dst1 = getTestRootPath(fc, "testEditsLogOldRename/dstdir/dst1");
|
|
dst1 = getTestRootPath(fc, "testEditsLogOldRename/dstdir/dst1");
|
|
Assert.assertFalse(fs.exists(src1)); // ensure src1 is already renamed
|
|
Assert.assertFalse(fs.exists(src1)); // ensure src1 is already renamed
|
|
@@ -239,7 +245,7 @@ public class TestHDFSFileContextMainOperations extends
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testEditsLogRename() throws Exception {
|
|
public void testEditsLogRename() throws Exception {
|
|
- DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem();
|
|
|
|
|
|
+ DistributedFileSystem fs = cluster.getFileSystem();
|
|
Path src1 = getTestRootPath(fc, "testEditsLogRename/srcdir/src1");
|
|
Path src1 = getTestRootPath(fc, "testEditsLogRename/srcdir/src1");
|
|
Path dst1 = getTestRootPath(fc, "testEditsLogRename/dstdir/dst1");
|
|
Path dst1 = getTestRootPath(fc, "testEditsLogRename/dstdir/dst1");
|
|
createFile(src1);
|
|
createFile(src1);
|
|
@@ -255,7 +261,7 @@ public class TestHDFSFileContextMainOperations extends
|
|
// Restart the cluster and ensure the above operations can be
|
|
// Restart the cluster and ensure the above operations can be
|
|
// loaded from the edits log
|
|
// loaded from the edits log
|
|
restartCluster();
|
|
restartCluster();
|
|
- fs = (DistributedFileSystem)cluster.getFileSystem();
|
|
|
|
|
|
+ fs = cluster.getFileSystem();
|
|
src1 = getTestRootPath(fc, "testEditsLogRename/srcdir/src1");
|
|
src1 = getTestRootPath(fc, "testEditsLogRename/srcdir/src1");
|
|
dst1 = getTestRootPath(fc, "testEditsLogRename/dstdir/dst1");
|
|
dst1 = getTestRootPath(fc, "testEditsLogRename/dstdir/dst1");
|
|
Assert.assertFalse(fs.exists(src1)); // ensure src1 is already renamed
|
|
Assert.assertFalse(fs.exists(src1)); // ensure src1 is already renamed
|
|
@@ -279,7 +285,7 @@ public class TestHDFSFileContextMainOperations extends
|
|
|
|
|
|
private void oldRename(Path src, Path dst, boolean renameSucceeds,
|
|
private void oldRename(Path src, Path dst, boolean renameSucceeds,
|
|
boolean exception) throws Exception {
|
|
boolean exception) throws Exception {
|
|
- DistributedFileSystem fs = (DistributedFileSystem) cluster.getFileSystem();
|
|
|
|
|
|
+ DistributedFileSystem fs = cluster.getFileSystem();
|
|
try {
|
|
try {
|
|
Assert.assertEquals(renameSucceeds, fs.rename(src, dst));
|
|
Assert.assertEquals(renameSucceeds, fs.rename(src, dst));
|
|
} catch (Exception ex) {
|
|
} catch (Exception ex) {
|
|
@@ -301,4 +307,23 @@ public class TestHDFSFileContextMainOperations extends
|
|
Assert.assertEquals(renameSucceeds, !exists(fc, src));
|
|
Assert.assertEquals(renameSucceeds, !exists(fc, src));
|
|
Assert.assertEquals((dstExists||renameSucceeds), exists(fc, dst));
|
|
Assert.assertEquals((dstExists||renameSucceeds), exists(fc, dst));
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected boolean listCorruptedBlocksSupported() {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testCrossFileSystemRename() throws IOException {
|
|
|
|
+ try {
|
|
|
|
+ fc.rename(
|
|
|
|
+ new Path("hdfs://127.0.0.1/aaa/bbb/Foo"),
|
|
|
|
+ new Path("file://aaa/bbb/Moo"),
|
|
|
|
+ Options.Rename.OVERWRITE);
|
|
|
|
+ fail("IOexception expected.");
|
|
|
|
+ } catch (IOException ioe) {
|
|
|
|
+ // okay
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|