You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by le...@apache.org on 2016/07/08 21:30:15 UTC
[08/21] hadoop git commit: Add negative test for
LocalMetadataStore.listStatus()
Add negative test for LocalMetadataStore.listStatus()
Also fix failure semantics in other places. It throws
FileNotFoundException. I think we should change that
to return null, but for now, keeping the interface.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/44fd2d36
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/44fd2d36
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/44fd2d36
Branch: refs/heads/s3_create
Commit: 44fd2d362b19859cf29c41305b7e43f9525e32fa
Parents: 0e20b3a
Author: Aaron Fabbri <fa...@cloudera.com>
Authored: Wed Jun 29 17:56:30 2016 -0700
Committer: Aaron Fabbri <fa...@cloudera.com>
Committed: Wed Jun 29 17:56:30 2016 -0700
----------------------------------------------------------------------
.../hadoop/fs/s3a/LocalMetadataStore.java | 9 +++++-
.../hadoop/fs/s3a/TestLocalMetadataStore.java | 29 +++++++++++++-------
2 files changed, 27 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/44fd2d36/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/LocalMetadataStore.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/LocalMetadataStore.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/LocalMetadataStore.java
index 94df47a..38c74a0 100644
--- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/LocalMetadataStore.java
+++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/LocalMetadataStore.java
@@ -115,9 +115,16 @@ public class LocalMetadataStore implements MetadataStore {
@Override
public CachedDirectory listStatus(Path f) throws FileNotFoundException, IOException {
// TODO validate/normalize path here and other public functions.
+ CachedDirectory cd;
synchronized (this) {
- return dirHash.get(f);
+ cd = dirHash.get(f);
}
+ if (cd == null) {
+ /* I think this should return null instead, this is not exceptional
+ * condition. */
+ throw new FileNotFoundException("LocalMetadataStore: \"" + f.toString() + "\"");
+ }
+ return cd;
}
@Override
http://git-wip-us.apache.org/repos/asf/hadoop/blob/44fd2d36/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestLocalMetadataStore.java
----------------------------------------------------------------------
diff --git a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestLocalMetadataStore.java b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestLocalMetadataStore.java
index 08a5c97..e4b2ef4 100644
--- a/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestLocalMetadataStore.java
+++ b/hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestLocalMetadataStore.java
@@ -11,6 +11,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
@@ -138,18 +139,19 @@ public class TestLocalMetadataStore extends Assert {
@Test
public void testListStatus() throws Exception {
- createNewDirs("/a1","/a2", "/a1/b1", "/a1/b2", "/a1/b1/c1", "/a1/b1/c1/d1");
- lms.putNew(new CachedFileStatus(makeFileStatus("/a1/b1/file1", 100)));
- lms.putNew(new CachedFileStatus(makeFileStatus("/a1/b1/file2", 100)));
+ setupListStatus();
- CachedDirectory cd = lms.listStatus(new Path("/"));
- if (cd != null) {
+ CachedDirectory cd;
+ try {
+ cd = lms.listStatus(new Path("/"));
+ if (cd != null) {
/* Cache has no way of knowing it has all entries for root unless we
* specifically tell it via putListStatus() with
* CachedDirectory.isFullyCached = true */
- assertFalse("Root dir is not cached, or partially cached", cd.isFullyCached());
- assertFileStatusesEqual(cd.getFileStatuses(), "/a1", "/a2");
- }
+ assertFalse("Root dir is not cached, or partially cached", cd.isFullyCached());
+ assertFileStatusesEqual(cd.getFileStatuses(), "/a1", "/a2");
+ }
+ } catch (FileNotFoundException f) { }
cd = lms.listStatus(new Path("/a1"));
assertFileStatusesEqual(cd.getFileStatuses(), "/a1/b1", "/a1/b2");
@@ -164,9 +166,10 @@ public class TestLocalMetadataStore extends Assert {
"/a1/b1/file2", "/a1/b1/c1");
}
- @Test
+ @Test(expected=FileNotFoundException.class)
public void testInvalidListStatus() throws Exception {
-
+ setupListStatus();
+ lms.listStatus(new Path("/a1/b1x"));
}
/** Additional internal test for fiddly part of code. */
@@ -186,6 +189,12 @@ public class TestLocalMetadataStore extends Assert {
assertNull("e1 deleted", testMap.get("/a1/b1/c1/d1/e1"));
}
+ private void setupListStatus() throws IOException {
+ createNewDirs("/a1","/a2", "/a1/b1", "/a1/b2", "/a1/b1/c1", "/a1/b1/c1/d1");
+ lms.putNew(new CachedFileStatus(makeFileStatus("/a1/b1/file1", 100)));
+ lms.putNew(new CachedFileStatus(makeFileStatus("/a1/b1/file2", 100)));
+ }
+
private void assertFileStatusesEqual(FileStatus[] statuses, String ...pathStrs) {
Set<Path> a = new HashSet<>();
for (FileStatus fs : statuses) {
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org