HDFS-14583. FileStatus#toString() will throw IllegalArgumentException. Contributed by xuzq.
This commit is contained in:
parent
63c295e298
commit
e04dcfdc57
@ -108,7 +108,7 @@ public void setGroup(String group) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSymlink() {
|
public boolean isSymlink() {
|
||||||
return uSymlink != null;
|
return uSymlink != null && uSymlink.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -95,7 +95,7 @@ public void setGroup(String group) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSymlink() {
|
public boolean isSymlink() {
|
||||||
return uSymlink != null;
|
return uSymlink != null && uSymlink.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
import static org.apache.hadoop.fs.permission.AclEntryType.*;
|
import static org.apache.hadoop.fs.permission.AclEntryType.*;
|
||||||
import static org.apache.hadoop.fs.permission.FsAction.*;
|
import static org.apache.hadoop.fs.permission.FsAction.*;
|
||||||
import static org.apache.hadoop.hdfs.server.namenode.AclTestHelpers.*;
|
import static org.apache.hadoop.hdfs.server.namenode.AclTestHelpers.*;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
@ -47,6 +49,7 @@
|
|||||||
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
|
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
|
||||||
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus.Flags;
|
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus.Flags;
|
||||||
import org.apache.hadoop.io.erasurecode.ECSchema;
|
import org.apache.hadoop.io.erasurecode.ECSchema;
|
||||||
|
import org.apache.hadoop.test.LambdaTestUtils;
|
||||||
import org.apache.hadoop.util.Time;
|
import org.apache.hadoop.util.Time;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -107,6 +110,48 @@ public void testHdfsFileStatusWithEcPolicy() throws IOException {
|
|||||||
Assert.assertEquals(fstatus, fs2);
|
Assert.assertEquals(fstatus, fs2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify isSymlink when symlink ie empty.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testHdfsFileStatus() throws Exception {
|
||||||
|
HdfsFileStatus hdfsFileStatus = new HdfsFileStatus.Builder()
|
||||||
|
.replication(1)
|
||||||
|
.blocksize(1024)
|
||||||
|
.perm(new FsPermission((short) 777))
|
||||||
|
.owner("owner")
|
||||||
|
.group("group")
|
||||||
|
.symlink(new byte[0])
|
||||||
|
.path(new byte[0])
|
||||||
|
.fileId(1010)
|
||||||
|
.isdir(true)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertFalse(hdfsFileStatus.isSymlink());
|
||||||
|
LambdaTestUtils.intercept(IOException.class,
|
||||||
|
"Path " + hdfsFileStatus.getPath() + " is not a symbolic link",
|
||||||
|
() -> hdfsFileStatus.getSymlink());
|
||||||
|
|
||||||
|
String expectString = new StringBuilder()
|
||||||
|
.append("HdfsLocatedFileStatus")
|
||||||
|
.append("{")
|
||||||
|
.append("path=" + null)
|
||||||
|
.append("; isDirectory=" + true)
|
||||||
|
.append("; modification_time=" + 0)
|
||||||
|
.append("; access_time=" + 0)
|
||||||
|
.append("; owner=" + "owner")
|
||||||
|
.append("; group=" + "group")
|
||||||
|
.append("; permission=" + "r----x--t")
|
||||||
|
.append("; isSymlink=" + false)
|
||||||
|
.append("; hasAcl=" + false)
|
||||||
|
.append("; isEncrypted=" + false)
|
||||||
|
.append("; isErasureCoded=" + false)
|
||||||
|
.append("}")
|
||||||
|
.toString();
|
||||||
|
|
||||||
|
assertEquals(expectString, hdfsFileStatus.toString());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHdfsFileStatusWithoutEcPolicy() throws IOException {
|
public void testHdfsFileStatusWithoutEcPolicy() throws IOException {
|
||||||
final long now = Time.now();
|
final long now = Time.now();
|
||||||
|
Loading…
Reference in New Issue
Block a user