Merge pull request #2 from saxenapranav/dfsHasCapablity-saxenapranav

HDFS-16963: added asserts on the conditions used in FileSystem.hasPathCapablity
This commit is contained in:
Tsz-Wo Nicholas Sze 2023-03-24 15:38:22 +08:00 committed by GitHub
commit 0ec6f5c374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 3 deletions

View File

@ -23,6 +23,7 @@ import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import static org.apache.hadoop.fs.CommonPathCapabilities.FS_SYMLINKS;
@ -37,16 +38,28 @@ public class TestDfsPathCapabilities {
conf.set(FileSystem.FS_DEFAULT_NAME_KEY, "hdfs://localhost/");
final FileSystem fs = FileSystem.get(conf);
Assert.assertTrue(fs instanceof DistributedFileSystem);
final DistributedFileSystem dfs = (DistributedFileSystem) fs;
final DistributedFileSystem dfs = Mockito.spy((DistributedFileSystem) fs);
final Path path = new Path("/");
Assert.assertTrue(dfs.supportsSymlinks());
// Symlinks disabled
// Symlinks support disabled
Mockito.doReturn(false).when(dfs).supportsSymlinks();
Assert.assertFalse(FileSystem.areSymlinksEnabled());
Assert.assertFalse(dfs.hasPathCapability(path, FS_SYMLINKS));
// Symlinks support enabled
Mockito.doReturn(true).when(dfs).supportsSymlinks();
Assert.assertFalse(FileSystem.areSymlinksEnabled());
Assert.assertFalse(dfs.hasPathCapability(path, FS_SYMLINKS));
// Symlinks enabled
FileSystem.enableSymlinks();
Mockito.doReturn(true).when(dfs).supportsSymlinks();
Assert.assertTrue(FileSystem.areSymlinksEnabled());
Assert.assertTrue(dfs.hasPathCapability(path, FS_SYMLINKS));
// Symlinks enabled but symlink-support is disabled
FileSystem.enableSymlinks();
Mockito.doReturn(false).when(dfs).supportsSymlinks();
Assert.assertTrue(FileSystem.areSymlinksEnabled());
Assert.assertTrue(dfs.hasPathCapability(path, FS_SYMLINKS));
}