|
40 | 40 | import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR; |
41 | 41 | import static java.net.HttpURLConnection.HTTP_NOT_FOUND; |
42 | 42 | import static java.net.HttpURLConnection.HTTP_UNAVAILABLE; |
| 43 | +import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.AZURE_MAX_IO_RETRIES; |
| 44 | +import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.accountProperty; |
43 | 45 | import static org.mockito.ArgumentMatchers.any; |
44 | 46 | import static org.mockito.ArgumentMatchers.anyString; |
45 | 47 | import static org.mockito.Mockito.doReturn; |
@@ -125,6 +127,8 @@ private AzureBlobFileSystem getNewFSWithHnsConf( |
125 | 127 | Configuration rawConfig = new Configuration(); |
126 | 128 | rawConfig.addResource(TEST_CONFIGURATION_FILE_NAME); |
127 | 129 | rawConfig.set(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, isNamespaceEnabledAccount); |
| 130 | + rawConfig.set(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, |
| 131 | + this.getAccountName()), isNamespaceEnabledAccount); |
128 | 132 | rawConfig |
129 | 133 | .setBoolean(AZURE_CREATE_REMOTE_FILESYSTEM_DURING_INITIALIZATION, true); |
130 | 134 | rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, |
@@ -265,4 +269,65 @@ private void ensureGetAclDetermineHnsStatusAccuratelyInternal(int statusCode, |
265 | 269 | Mockito.verify(mockClient, times(1)) |
266 | 270 | .getAclStatus(anyString(), any(TracingContext.class)); |
267 | 271 | } |
| 272 | + |
| 273 | + @Test |
| 274 | + public void testAccountSpecificConfig() throws Exception { |
| 275 | + Configuration rawConfig = new Configuration(); |
| 276 | + rawConfig.addResource(TEST_CONFIGURATION_FILE_NAME); |
| 277 | + rawConfig.unset(FS_AZURE_ACCOUNT_IS_HNS_ENABLED); |
| 278 | + rawConfig.unset(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, |
| 279 | + this.getAccountName())); |
| 280 | + String testAccountName = "testAccount.dfs.core.windows.net"; |
| 281 | + String otherAccountName = "otherAccount.dfs.core.windows.net"; |
| 282 | + String defaultUri = this.getTestUrl().replace(this.getAccountName(), testAccountName); |
| 283 | + String otherUri = this.getTestUrl().replace(this.getAccountName(), otherAccountName); |
| 284 | + |
| 285 | + // Set both account specific and account agnostic config for test account |
| 286 | + rawConfig.set(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, testAccountName), FALSE_STR); |
| 287 | + rawConfig.set(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, TRUE_STR); |
| 288 | + // Assert that account specific config takes precedence |
| 289 | + rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, defaultUri); |
| 290 | + assertFileSystemInitWithExpectedHNSSettings(rawConfig, false); |
| 291 | + // Assert that other account still uses account agnostic config |
| 292 | + rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, otherUri); |
| 293 | + assertFileSystemInitWithExpectedHNSSettings(rawConfig, true); |
| 294 | + |
| 295 | + // Set only the account specific config for test account |
| 296 | + rawConfig.set(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, testAccountName), FALSE_STR); |
| 297 | + rawConfig.unset(FS_AZURE_ACCOUNT_IS_HNS_ENABLED); |
| 298 | + // Assert that only account specific config is enough for test account |
| 299 | + rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, defaultUri); |
| 300 | + assertFileSystemInitWithExpectedHNSSettings(rawConfig, false); |
| 301 | + |
| 302 | + // Set only account agnostic config |
| 303 | + rawConfig.set(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, FALSE_STR); |
| 304 | + rawConfig.unset(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, testAccountName)); |
| 305 | + rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, defaultUri); |
| 306 | + assertFileSystemInitWithExpectedHNSSettings(rawConfig, false); |
| 307 | + |
| 308 | + // Unset both account specific and account agnostic config |
| 309 | + rawConfig.unset(FS_AZURE_ACCOUNT_IS_HNS_ENABLED); |
| 310 | + rawConfig.unset(accountProperty(FS_AZURE_ACCOUNT_IS_HNS_ENABLED, testAccountName)); |
| 311 | + rawConfig.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, defaultUri); |
| 312 | + rawConfig.set(AZURE_MAX_IO_RETRIES, "0"); |
| 313 | + // Assert that file system init fails with UnknownHost exception as getAcl() is needed. |
| 314 | + try { |
| 315 | + assertFileSystemInitWithExpectedHNSSettings(rawConfig, false); |
| 316 | + } catch (Exception e) { |
| 317 | + Assertions.assertThat(e.getCause().getMessage()) |
| 318 | + .describedAs("getAcl() to determine HNS Nature of account should" |
| 319 | + + "fail with Unknown Host Exception").contains("UnknownHostException"); |
| 320 | + } |
| 321 | + } |
| 322 | + |
| 323 | + private void assertFileSystemInitWithExpectedHNSSettings( |
| 324 | + Configuration configuration, boolean expectedIsHnsEnabledValue) throws IOException { |
| 325 | + try (AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(configuration)) { |
| 326 | + Assertions.assertThat(getIsNamespaceEnabled(fs)).describedAs( |
| 327 | + "getIsNamespaceEnabled should return true when the " |
| 328 | + + "account specific config is not set").isEqualTo(expectedIsHnsEnabledValue); |
| 329 | + } catch (Exception e) { |
| 330 | + throw e; |
| 331 | + } |
| 332 | + } |
268 | 333 | } |
0 commit comments