|
@@ -21,15 +21,31 @@ import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
+import org.apache.hadoop.fs.azurebfs.enums.Trilean;
|
|
import org.junit.Assume;
|
|
import org.junit.Assume;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
+import org.assertj.core.api.Assertions;
|
|
|
|
|
|
|
|
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
|
|
+import org.apache.hadoop.fs.FileSystem;
|
|
|
|
+import org.apache.hadoop.fs.azurebfs.services.AbfsClient;
|
|
|
|
+import org.apache.hadoop.fs.azurebfs.services.AbfsRestOperation;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException;
|
|
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException;
|
|
import org.apache.hadoop.fs.azurebfs.services.AuthType;
|
|
import org.apache.hadoop.fs.azurebfs.services.AuthType;
|
|
|
|
|
|
|
|
+import static org.mockito.ArgumentMatchers.anyString;
|
|
|
|
+import static org.mockito.Mockito.doReturn;
|
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
|
+import static org.mockito.Mockito.never;
|
|
|
|
+import static org.mockito.Mockito.times;
|
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
|
+
|
|
|
|
+import static org.apache.hadoop.fs.azurebfs.constants.FileSystemConfigurations.DEFAULT_FS_AZURE_ACCOUNT_IS_HNS_ENABLED;
|
|
|
|
+import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.TEST_CONFIGURATION_FILE_NAME;
|
|
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_CREATE_REMOTE_FILESYSTEM_DURING_INITIALIZATION;
|
|
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_CREATE_REMOTE_FILESYSTEM_DURING_INITIALIZATION;
|
|
|
|
+import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ACCOUNT_IS_HNS_ENABLED;
|
|
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ACCOUNT_KEY_PROPERTY_NAME;
|
|
import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ACCOUNT_KEY_PROPERTY_NAME;
|
|
import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT;
|
|
import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT;
|
|
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
|
|
import static org.apache.hadoop.test.LambdaTestUtils.intercept;
|
|
@@ -39,6 +55,9 @@ import static org.apache.hadoop.test.LambdaTestUtils.intercept;
|
|
*/
|
|
*/
|
|
public class ITestGetNameSpaceEnabled extends AbstractAbfsIntegrationTest {
|
|
public class ITestGetNameSpaceEnabled extends AbstractAbfsIntegrationTest {
|
|
|
|
|
|
|
|
+ private static final String TRUE_STR = "true";
|
|
|
|
+ private static final String FALSE_STR = "false";
|
|
|
|
+
|
|
private boolean isUsingXNSAccount;
|
|
private boolean isUsingXNSAccount;
|
|
public ITestGetNameSpaceEnabled() throws Exception {
|
|
public ITestGetNameSpaceEnabled() throws Exception {
|
|
isUsingXNSAccount = getConfiguration().getBoolean(FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT, false);
|
|
isUsingXNSAccount = getConfiguration().getBoolean(FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT, false);
|
|
@@ -57,7 +76,57 @@ public class ITestGetNameSpaceEnabled extends AbstractAbfsIntegrationTest {
|
|
Assume.assumeFalse("Skip this test because the account being used for test is a XNS account",
|
|
Assume.assumeFalse("Skip this test because the account being used for test is a XNS account",
|
|
isUsingXNSAccount);
|
|
isUsingXNSAccount);
|
|
assertFalse("Expecting getIsNamespaceEnabled() return false",
|
|
assertFalse("Expecting getIsNamespaceEnabled() return false",
|
|
- getFileSystem().getIsNamespaceEnabled());
|
|
|
|
|
|
+ getFileSystem().getIsNamespaceEnabled());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testGetIsNamespaceEnabledWhenConfigIsTrue() throws Exception {
|
|
|
|
+ AzureBlobFileSystem fs = getNewFSWithHnsConf(TRUE_STR);
|
|
|
|
+ Assertions.assertThat(fs.getIsNamespaceEnabled()).describedAs(
|
|
|
|
+ "getIsNamespaceEnabled should return true when the "
|
|
|
|
+ + "config is set as true").isTrue();
|
|
|
|
+ fs.getAbfsStore().deleteFilesystem();
|
|
|
|
+ unsetAndAssert();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testGetIsNamespaceEnabledWhenConfigIsFalse() throws Exception {
|
|
|
|
+ AzureBlobFileSystem fs = getNewFSWithHnsConf(FALSE_STR);
|
|
|
|
+ Assertions.assertThat(fs.getIsNamespaceEnabled()).describedAs(
|
|
|
|
+ "getIsNamespaceEnabled should return false when the "
|
|
|
|
+ + "config is set as false").isFalse();
|
|
|
|
+ fs.getAbfsStore().deleteFilesystem();
|
|
|
|
+ unsetAndAssert();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void unsetAndAssert() throws Exception {
|
|
|
|
+ AzureBlobFileSystem fs = getNewFSWithHnsConf(
|
|
|
|
+ DEFAULT_FS_AZURE_ACCOUNT_IS_HNS_ENABLED);
|
|
|
|
+ boolean expectedValue = this.getConfiguration()
|
|
|
|
+ .getBoolean(FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT, false);
|
|
|
|
+ Assertions.assertThat(fs.getIsNamespaceEnabled()).describedAs(
|
|
|
|
+ "getIsNamespaceEnabled should return the value "
|
|
|
|
+ + "configured for fs.azure.test.namespace.enabled")
|
|
|
|
+ .isEqualTo(expectedValue);
|
|
|
|
+ fs.getAbfsStore().deleteFilesystem();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private AzureBlobFileSystem getNewFSWithHnsConf(
|
|
|
|
+ String isNamespaceEnabledAccount) throws Exception {
|
|
|
|
+ Configuration rawConfig = new Configuration();
|
|
|
|
+ rawConfig.addResource(TEST_CONFIGURATION_FILE_NAME);
|
|
|
|
+ rawConfig.set(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, isNamespaceEnabledAccount);
|
|
|
|
+ rawConfig
|
|
|
|
+ .setBoolean(AZURE_CREATE_REMOTE_FILESYSTEM_DURING_INITIALIZATION, true);
|
|
|
|
+ rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY,
|
|
|
|
+ getNonExistingUrl());
|
|
|
|
+ return (AzureBlobFileSystem) FileSystem.get(rawConfig);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getNonExistingUrl() {
|
|
|
|
+ String testUri = this.getTestUrl();
|
|
|
|
+ return getAbfsScheme() + "://" + UUID.randomUUID() + testUri
|
|
|
|
+ .substring(testUri.indexOf("@"));
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -95,4 +164,72 @@ public class ITestGetNameSpaceEnabled extends AbstractAbfsIntegrationTest {
|
|
fs.getIsNamespaceEnabled();
|
|
fs.getIsNamespaceEnabled();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testEnsureGetAclCallIsMadeOnceWhenConfigIsInvalid()
|
|
|
|
+ throws Exception {
|
|
|
|
+ unsetConfAndEnsureGetAclCallIsMadeOnce();
|
|
|
|
+ ensureGetAclCallIsMadeOnceForInvalidConf(" ");
|
|
|
|
+ unsetConfAndEnsureGetAclCallIsMadeOnce();
|
|
|
|
+ ensureGetAclCallIsMadeOnceForInvalidConf("Invalid conf");
|
|
|
|
+ unsetConfAndEnsureGetAclCallIsMadeOnce();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testEnsureGetAclCallIsNeverMadeWhenConfigIsValid()
|
|
|
|
+ throws Exception {
|
|
|
|
+ unsetConfAndEnsureGetAclCallIsMadeOnce();
|
|
|
|
+ ensureGetAclCallIsNeverMadeForValidConf(FALSE_STR.toLowerCase());
|
|
|
|
+ unsetConfAndEnsureGetAclCallIsMadeOnce();
|
|
|
|
+ ensureGetAclCallIsNeverMadeForValidConf(FALSE_STR.toUpperCase());
|
|
|
|
+ unsetConfAndEnsureGetAclCallIsMadeOnce();
|
|
|
|
+ ensureGetAclCallIsNeverMadeForValidConf(TRUE_STR.toLowerCase());
|
|
|
|
+ unsetConfAndEnsureGetAclCallIsMadeOnce();
|
|
|
|
+ ensureGetAclCallIsNeverMadeForValidConf(TRUE_STR.toUpperCase());
|
|
|
|
+ unsetConfAndEnsureGetAclCallIsMadeOnce();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testEnsureGetAclCallIsMadeOnceWhenConfigIsNotPresent()
|
|
|
|
+ throws IOException {
|
|
|
|
+ unsetConfAndEnsureGetAclCallIsMadeOnce();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void ensureGetAclCallIsMadeOnceForInvalidConf(String invalidConf)
|
|
|
|
+ throws Exception {
|
|
|
|
+ this.getFileSystem().getAbfsStore()
|
|
|
|
+ .setNamespaceEnabled(Trilean.getTrilean(invalidConf));
|
|
|
|
+ AbfsClient mockClient =
|
|
|
|
+ callAbfsGetIsNamespaceEnabledAndReturnMockAbfsClient();
|
|
|
|
+ verify(mockClient, times(1)).getAclStatus(anyString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void ensureGetAclCallIsNeverMadeForValidConf(String validConf)
|
|
|
|
+ throws Exception {
|
|
|
|
+ this.getFileSystem().getAbfsStore()
|
|
|
|
+ .setNamespaceEnabled(Trilean.getTrilean(validConf));
|
|
|
|
+ AbfsClient mockClient =
|
|
|
|
+ callAbfsGetIsNamespaceEnabledAndReturnMockAbfsClient();
|
|
|
|
+ verify(mockClient, never()).getAclStatus(anyString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void unsetConfAndEnsureGetAclCallIsMadeOnce() throws IOException {
|
|
|
|
+ this.getFileSystem().getAbfsStore().setNamespaceEnabled(Trilean.UNKNOWN);
|
|
|
|
+ AbfsClient mockClient =
|
|
|
|
+ callAbfsGetIsNamespaceEnabledAndReturnMockAbfsClient();
|
|
|
|
+ verify(mockClient, times(1)).getAclStatus(anyString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private AbfsClient callAbfsGetIsNamespaceEnabledAndReturnMockAbfsClient()
|
|
|
|
+ throws IOException {
|
|
|
|
+ final AzureBlobFileSystem abfs = this.getFileSystem();
|
|
|
|
+ final AzureBlobFileSystemStore abfsStore = abfs.getAbfsStore();
|
|
|
|
+ final AbfsClient mockClient = mock(AbfsClient.class);
|
|
|
|
+ doReturn(mock(AbfsRestOperation.class)).when(mockClient)
|
|
|
|
+ .getAclStatus(anyString());
|
|
|
|
+ abfsStore.setClient(mockClient);
|
|
|
|
+ abfs.getIsNamespaceEnabled();
|
|
|
|
+ return mockClient;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|