HDFS-13816. dfs.getQuotaUsage() throws NPE on non-existent dir instead of FileNotFoundException. Contributed by Vinayakumar B.
(cherry picked from commit b098281454
)
This commit is contained in:
parent
1b937d701d
commit
538757ed49
|
@ -565,6 +565,10 @@ class FSDirStatAndListingOp {
|
||||||
fsd.readLock();
|
fsd.readLock();
|
||||||
try {
|
try {
|
||||||
INode targetNode = iip.getLastINode();
|
INode targetNode = iip.getLastINode();
|
||||||
|
if (targetNode == null) {
|
||||||
|
throw new FileNotFoundException(
|
||||||
|
"File/Directory does not exist: " + iip.getPath());
|
||||||
|
}
|
||||||
QuotaUsage usage = null;
|
QuotaUsage usage = null;
|
||||||
if (targetNode.isDirectory()) {
|
if (targetNode.isDirectory()) {
|
||||||
DirectoryWithQuotaFeature feature =
|
DirectoryWithQuotaFeature feature =
|
||||||
|
|
|
@ -28,6 +28,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
@ -332,6 +333,13 @@ public class TestQuota {
|
||||||
// 14a: set quota on a non-existent directory
|
// 14a: set quota on a non-existent directory
|
||||||
Path nonExistentPath = new Path(dir, "test1");
|
Path nonExistentPath = new Path(dir, "test1");
|
||||||
assertFalse(dfs.exists(nonExistentPath));
|
assertFalse(dfs.exists(nonExistentPath));
|
||||||
|
try {
|
||||||
|
compareQuotaUsage(null, dfs, nonExistentPath);
|
||||||
|
fail("Expected FileNotFoundException");
|
||||||
|
} catch (FileNotFoundException fnfe) {
|
||||||
|
GenericTestUtils.assertExceptionContains(
|
||||||
|
"File/Directory does not exist: " + nonExistentPath, fnfe);
|
||||||
|
}
|
||||||
args = new String[]{"-setQuota", "1", nonExistentPath.toString()};
|
args = new String[]{"-setQuota", "1", nonExistentPath.toString()};
|
||||||
runCommand(admin, args, true);
|
runCommand(admin, args, true);
|
||||||
runCommand(admin, true, "-setSpaceQuota", "1g", // for space quota
|
runCommand(admin, true, "-setSpaceQuota", "1g", // for space quota
|
||||||
|
|
Loading…
Reference in New Issue