|
24 | 24 | import org.junit.Assume; |
25 | 25 | import org.junit.Test; |
26 | 26 | import org.assertj.core.api.Assertions; |
| 27 | +import org.mockito.Mockito; |
27 | 28 |
|
28 | 29 | import org.apache.hadoop.fs.CommonConfigurationKeysPublic; |
29 | 30 | import org.apache.hadoop.fs.FileSystem; |
| 31 | +import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException; |
30 | 32 | import org.apache.hadoop.fs.azurebfs.services.AbfsClient; |
31 | 33 | import org.apache.hadoop.fs.azurebfs.services.AbfsRestOperation; |
32 | 34 | import org.apache.hadoop.conf.Configuration; |
33 | 35 | import org.apache.hadoop.fs.Path; |
34 | 36 | import org.apache.hadoop.fs.azurebfs.enums.Trilean; |
35 | 37 | import org.apache.hadoop.fs.azurebfs.utils.TracingContext; |
| 38 | +import org.apache.kerby.config.Conf; |
36 | 39 |
|
37 | 40 | import static org.mockito.ArgumentMatchers.any; |
38 | 41 | import static org.mockito.ArgumentMatchers.anyString; |
39 | 42 | import static org.mockito.Mockito.doReturn; |
| 43 | +import static org.mockito.Mockito.doThrow; |
40 | 44 | import static org.mockito.Mockito.mock; |
41 | 45 | import static org.mockito.Mockito.never; |
42 | 46 | import static org.mockito.Mockito.times; |
|
48 | 52 | import static org.apache.hadoop.fs.azurebfs.constants.ConfigurationKeys.FS_AZURE_ACCOUNT_IS_HNS_ENABLED; |
49 | 53 | import static org.apache.hadoop.fs.azurebfs.constants.TestConfigurationKeys.FS_AZURE_TEST_NAMESPACE_ENABLED_ACCOUNT; |
50 | 54 | import static org.apache.hadoop.test.LambdaTestUtils.intercept; |
| 55 | +import static org.mockito.Mockito.when; |
51 | 56 |
|
52 | 57 | /** |
53 | 58 | * Test getIsNamespaceEnabled call. |
@@ -217,4 +222,31 @@ private AbfsClient callAbfsGetIsNamespaceEnabledAndReturnMockAbfsClient() |
217 | 222 | return mockClient; |
218 | 223 | } |
219 | 224 |
|
| 225 | + @Test |
| 226 | + public void ensureGetAclDetermineHnsStatusAccurately() throws Exception { |
| 227 | + ensureGetAclDetermineHnsStatusAccuratelyInternal(400, false); |
| 228 | + ensureGetAclDetermineHnsStatusAccuratelyInternal(404, true); |
| 229 | + ensureGetAclDetermineHnsStatusAccuratelyInternal(500, false); |
| 230 | + ensureGetAclDetermineHnsStatusAccuratelyInternal(503, false); |
| 231 | + } |
| 232 | + |
| 233 | + private void ensureGetAclDetermineHnsStatusAccuratelyInternal(int statusCode, |
| 234 | + boolean expected) throws Exception { |
| 235 | + AzureBlobFileSystemStore store = Mockito.spy(getFileSystem().getAbfsStore()); |
| 236 | + AbfsClient mockClient = mock(AbfsClient.class); |
| 237 | + store.setNamespaceEnabled(Trilean.UNKNOWN); |
| 238 | + doReturn(mockClient).when(store).getClient(); |
| 239 | + AbfsRestOperationException ex = new AbfsRestOperationException( |
| 240 | + statusCode, null, Integer.toString(statusCode), null); |
| 241 | + doThrow(ex).when(mockClient).getAclStatus(anyString(), any(TracingContext.class)); |
| 242 | + |
| 243 | + try { |
| 244 | + boolean isHnsEnabled = store.getIsNamespaceEnabled( |
| 245 | + getTestTracingContext(getFileSystem(), false)); |
| 246 | + Assertions.assertThat(isHnsEnabled).isEqualTo(expected); |
| 247 | + } catch (AbfsRestOperationException caughtEx) { |
| 248 | + Assertions.assertThat(caughtEx.getStatusCode()).isEqualTo(statusCode); |
| 249 | + Assertions.assertThat(caughtEx.getErrorMessage()).isEqualTo(ex.getErrorMessage()); |
| 250 | + } |
| 251 | + } |
220 | 252 | } |
0 commit comments