Skip to content

Commit

Permalink
Add directory permission tests for HDFS
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Oct 24, 2023
1 parent e67bd6a commit 9799746
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand All @@ -42,6 +43,7 @@ public class TestHdfsFileSystemHdfs
extends AbstractTestTrinoFileSystem
{
private Hadoop hadoop;
private HdfsConfiguration hdfsConfiguration;
private HdfsEnvironment hdfsEnvironment;
private HdfsContext hdfsContext;
private TrinoFileSystem fileSystem;
Expand All @@ -53,7 +55,7 @@ void beforeAll()
hadoop.start();

HdfsConfig hdfsConfig = new HdfsConfig();
HdfsConfiguration hdfsConfiguration = new DynamicHdfsConfiguration(new HdfsConfigurationInitializer(hdfsConfig), emptySet());
hdfsConfiguration = new DynamicHdfsConfiguration(new HdfsConfigurationInitializer(hdfsConfig), emptySet());
hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hdfsConfig, new NoHdfsAuthentication());
hdfsContext = new HdfsContext(ConnectorIdentity.ofUser("test"));

Expand Down Expand Up @@ -107,4 +109,33 @@ protected void verifyFileSystemIsEmpty()
throw new UncheckedIOException(e);
}
}

@Test
void testCreateDirectoryPermission()
throws IOException
{
assertCreateDirectoryPermission(fileSystem, hdfsEnvironment, (short) 777);
}

@Test
void testCreateDirectoryPermissionWithSkip()
throws IOException
{
HdfsConfig configWithSkip = new HdfsConfig()
.setNewDirectoryPermissions(HdfsConfig.SKIP_DIR_PERMISSIONS);
HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, configWithSkip, new NoHdfsAuthentication());
TrinoFileSystem fileSystem = new HdfsFileSystem(hdfsEnvironment, hdfsContext, new TrinoHdfsFileSystemStats());

assertCreateDirectoryPermission(fileSystem, hdfsEnvironment, (short) 755);
}

private void assertCreateDirectoryPermission(TrinoFileSystem fileSystem, HdfsEnvironment hdfsEnvironment, short permission)
throws IOException
{
Location location = getRootLocation().appendPath("test");
fileSystem.createDirectory(location);
Path path = new Path(location.toString());
FileStatus status = hdfsEnvironment.getFileSystem(hdfsContext, path).getFileStatus(path);
assertThat(status.getPermission().toOctal()).isEqualTo(permission);
}
}

0 comments on commit 9799746

Please sign in to comment.