From dbe1e4de77a5cb1bf7b658a20e28382cc33e316e Mon Sep 17 00:00:00 2001 From: Jitendra Nath Pandey Date: Fri, 28 Oct 2011 20:08:19 +0000 Subject: [PATCH] HADOOP-7770. ViewFS getFileChecksum throws FileNotFoundException for files in /tmp and /user. Contributed by Ravi Prakash. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1190532 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 +++ .../hadoop/fs/viewfs/ViewFileSystem.java | 2 +- .../org/apache/hadoop/fs/viewfs/ViewFs.java | 2 +- .../fs/viewfs/TestViewfsFileStatus.java | 24 +++++++++++++++++ .../hadoop/fs/viewfs/ViewFsBaseTest.java | 26 ++++++++++++++++++- 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index f8555f97af..471027762e 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -82,6 +82,9 @@ Trunk (unreleased changes) HADOOP-7769. TestJMXJsonServlet is failing. (tomwhite) + HADOOP-7770. ViewFS getFileChecksum throws FileNotFoundException for files in + /tmp and /user. (Ravi Prakash via jitendra) + OPTIMIZATIONS HADOOP-7761. Improve the performance of raw comparisons. (todd) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java index a08aa3d58d..b156194928 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java @@ -318,7 +318,7 @@ public FileChecksum getFileChecksum(final Path f) IOException { InodeTree.ResolveResult res = fsState.resolve(getUriPath(f), true); - return res.targetFileSystem.getFileChecksum(f); + return res.targetFileSystem.getFileChecksum(res.remainingPath); } @Override diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java index 484c041faf..232a77074f 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFs.java @@ -316,7 +316,7 @@ public FileChecksum getFileChecksum(final Path f) UnresolvedLinkException, IOException { InodeTree.ResolveResult res = fsState.resolve(getUriPath(f), true); - return res.targetFileSystem.getFileChecksum(f); + return res.targetFileSystem.getFileChecksum(res.remainingPath); } @Override diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java index 1a4d933fdb..4a576d08eb 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewfsFileStatus.java @@ -23,6 +23,7 @@ import java.net.URISyntaxException; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileChecksum; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileUtil; @@ -33,6 +34,8 @@ import org.junit.AfterClass; import org.junit.Test; +import org.mockito.Mockito; + import static org.junit.Assert.*; /** @@ -81,6 +84,27 @@ public void testFileStatusSerialziation() assertEquals(content.length, deSer.getLen()); } + // Tests that ViewFileSystem.getFileChecksum calls res.targetFileSystem + // .getFileChecksum with res.remainingPath and not with f + @Test + public void testGetFileChecksum() throws IOException { + FileSystem mockFS = Mockito.mock(FileSystem.class); + InodeTree.ResolveResult res = + new InodeTree.ResolveResult(null, mockFS , null, + new Path("someFile")); + @SuppressWarnings("unchecked") + InodeTree fsState = Mockito.mock(InodeTree.class); + Mockito.when(fsState.resolve("/tmp/someFile", true)).thenReturn(res); + ViewFileSystem vfs = Mockito.mock(ViewFileSystem.class); + vfs.fsState = fsState; + + Mockito.when(vfs.getFileChecksum(new Path("/tmp/someFile"))) + .thenCallRealMethod(); + vfs.getFileChecksum(new Path("/tmp/someFile")); + + Mockito.verify(mockFS).getFileChecksum(new Path("someFile")); + } + @AfterClass public static void cleanup() throws IOException { FileUtil.fullyDelete(TEST_DIR); diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsBaseTest.java index 1ea2a4b17e..8622f02ff6 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFsBaseTest.java @@ -29,13 +29,15 @@ import java.util.List; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.AbstractFileSystem; import org.apache.hadoop.fs.BlockLocation; import org.apache.hadoop.fs.FileContext; import org.apache.hadoop.fs.FileContextTestHelper; +import org.apache.hadoop.fs.FileContextTestHelper.fileType; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FsConstants; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.fs.FileContextTestHelper.fileType; +import org.apache.hadoop.fs.UnresolvedLinkException; import org.apache.hadoop.fs.viewfs.ViewFs.MountPoint; import org.apache.hadoop.security.AccessControlException; import org.apache.hadoop.security.token.Token; @@ -43,6 +45,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; /** @@ -408,6 +411,27 @@ public void testFileStatusOnMountLink() throws IOException { } } + @Test + public void testGetFileChecksum() throws AccessControlException + , UnresolvedLinkException, IOException { + AbstractFileSystem mockAFS = Mockito.mock(AbstractFileSystem.class); + InodeTree.ResolveResult res = + new InodeTree.ResolveResult(null, mockAFS , null, + new Path("someFile")); + @SuppressWarnings("unchecked") + InodeTree fsState = Mockito.mock(InodeTree.class); + Mockito.when(fsState.resolve(Mockito.anyString() + , Mockito.anyBoolean())).thenReturn(res); + ViewFs vfs = Mockito.mock(ViewFs.class); + vfs.fsState = fsState; + + Mockito.when(vfs.getFileChecksum(new Path("/tmp/someFile"))) + .thenCallRealMethod(); + vfs.getFileChecksum(new Path("/tmp/someFile")); + + Mockito.verify(mockAFS).getFileChecksum(new Path("someFile")); + } + @Test(expected=FileNotFoundException.class) public void testgetFSonDanglingLink() throws IOException { fcView.getFileStatus(new Path("/danglingLink"));