diff --git a/sdk/storage/azure-storage-file-datalake/assets.json b/sdk/storage/azure-storage-file-datalake/assets.json index 76dfcdb641cc2..3a453d7be8038 100644 --- a/sdk/storage/azure-storage-file-datalake/assets.json +++ b/sdk/storage/azure-storage-file-datalake/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/storage/azure-storage-file-datalake", - "Tag": "java/storage/azure-storage-file-datalake_7647723dc8" + "Tag": "java/storage/azure-storage-file-datalake_8f2462b720" } diff --git a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakeFileSystemAsyncClient.java b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakeFileSystemAsyncClient.java index 38af1d18afab0..6fabbe58eb371 100644 --- a/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakeFileSystemAsyncClient.java +++ b/sdk/storage/azure-storage-file-datalake/src/main/java/com/azure/storage/file/datalake/DataLakeFileSystemAsyncClient.java @@ -1079,12 +1079,11 @@ public Mono createFileIfNotExists(String fileName) { @ServiceMethod(returns = ReturnType.SINGLE) public Mono> createFileIfNotExistsWithResponse(String fileName, DataLakePathCreateOptions options) { - DataLakeRequestConditions requestConditions = new DataLakeRequestConditions() - .setIfNoneMatch(Constants.HeaderConstants.ETAG_WILDCARD); options = options == null ? new DataLakePathCreateOptions() : options; + options.setRequestConditions(new DataLakeRequestConditions() + .setIfNoneMatch(Constants.HeaderConstants.ETAG_WILDCARD)); try { - return createFileWithResponse(fileName, options.getPermissions(), options.getUmask(), - options.getPathHttpHeaders(), options.getMetadata(), requestConditions) + return createFileWithResponse(fileName, options) .onErrorResume(t -> t instanceof DataLakeStorageException && ((DataLakeStorageException) t) .getStatusCode() == 409, t -> { @@ -1444,11 +1443,11 @@ public Mono createDirectoryIfNotExists(String dire @ServiceMethod(returns = ReturnType.SINGLE) public Mono> createDirectoryIfNotExistsWithResponse(String directoryName, DataLakePathCreateOptions options) { + options = options == null ? new DataLakePathCreateOptions() : options; + options.setRequestConditions(new DataLakeRequestConditions() + .setIfNoneMatch(Constants.HeaderConstants.ETAG_WILDCARD)); try { - options = options == null ? new DataLakePathCreateOptions() : options; - return createDirectoryWithResponse(directoryName, options.getPermissions(), options.getUmask(), - options.getPathHttpHeaders(), options.getMetadata(), - new DataLakeRequestConditions().setIfNoneMatch(Constants.HeaderConstants.ETAG_WILDCARD)) + return createDirectoryWithResponse(directoryName, options) .onErrorResume(t -> t instanceof DataLakeStorageException && ((DataLakeStorageException) t) .getStatusCode() == 409, t -> { diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DataLakeTestBase.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DataLakeTestBase.java index d8296de79ad77..f292cc0e6fd4c 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DataLakeTestBase.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DataLakeTestBase.java @@ -553,6 +553,10 @@ protected String setupFileSystemLeaseCondition(DataLakeFileSystemClient fsc, Str return Objects.equals(RECEIVED_LEASE_ID, leaseID) ? createLeaseClient(fsc).acquireLease(-1) : leaseID; } + protected String setupFileSystemLeaseCondition(DataLakeFileSystemAsyncClient fsc, String leaseID) { + return Objects.equals(RECEIVED_LEASE_ID, leaseID) ? createLeaseAsyncClient(fsc).acquireLease(-1).block() : leaseID; + } + /** * This will retrieve the etag to be used in testing match conditions. The result will typically be assigned to * the ifMatch condition when testing success and the ifNoneMatch condition when testing failure. @@ -593,15 +597,14 @@ protected String setupPathLeaseCondition(DataLakePathClient pc, String leaseID) return Objects.equals(RECEIVED_LEASE_ID, leaseID) ? responseLeaseId : leaseID; } - protected String setupPathLeaseCondition(DataLakePathAsyncClient pc, String leaseID) { + protected String setupPathLeaseCondition(DataLakePathAsyncClient pac, String leaseID) { String responseLeaseId = null; if (Objects.equals(RECEIVED_LEASE_ID, leaseID) || Objects.equals(GARBAGE_LEASE_ID, leaseID)) { - responseLeaseId = (pc instanceof DataLakeFileAsyncClient) - ? createLeaseAsyncClient((DataLakeFileAsyncClient) pc).acquireLease(-1).block() - : createLeaseAsyncClient((DataLakeDirectoryAsyncClient) pc).acquireLease(-1).block(); + responseLeaseId = (pac instanceof DataLakeFileAsyncClient) + ? createLeaseAsyncClient((DataLakeFileAsyncClient) pac).acquireLease(-1).block() + : createLeaseAsyncClient((DataLakeDirectoryAsyncClient) pac).acquireLease(-1).block(); } - return Objects.equals(RECEIVED_LEASE_ID, leaseID) ? responseLeaseId : leaseID; } @@ -891,4 +894,40 @@ public static void waitUntilPredicate(long delayMillis, int numberOfDelays, Supp public static boolean isLiveMode() { return ENVIRONMENT.getTestMode() == TestMode.LIVE; } + + private static boolean olderThan20200210ServiceVersion() { + return olderThan(DataLakeServiceVersion.V2020_02_10); + } + + private static boolean olderThan20201206ServiceVersion() { + return olderThan(DataLakeServiceVersion.V2020_12_06); + } + + private static boolean olderThan20200612ServiceVersion() { + return olderThan(DataLakeServiceVersion.V2020_06_12); + } + + private static boolean olderThan20210608ServiceVersion() { + return olderThan(DataLakeServiceVersion.V2021_06_08); + } + + private static boolean olderThan20230803ServiceVersion() { + return olderThan(DataLakeServiceVersion.V2023_08_03); + } + + private static boolean olderThan20200804ServiceVersion() { + return olderThan(DataLakeServiceVersion.V2020_08_04); + } + + private static boolean olderThan20191212ServiceVersion() { + return olderThan(DataLakeServiceVersion.V2019_12_12); + } + + private static boolean olderThan20201002ServiceVersion() { + return olderThan(DataLakeServiceVersion.V2020_10_02); + } + + private static boolean olderThan20210410ServiceVersion() { + return olderThan(DataLakeServiceVersion.V2021_04_10); + } } diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DirectoryApiTests.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DirectoryApiTests.java index de57f8ef91a4b..d3c853fb3cfb7 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DirectoryApiTests.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DirectoryApiTests.java @@ -130,7 +130,7 @@ public void createDefaults() { validateBasicHeaders(createResponse.getHeaders()); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createDefaultsWithOptions() { DataLakePathCreateOptions options = new DataLakePathCreateOptions() @@ -312,7 +312,7 @@ public void createEncryptionScope() { assertEquals(ENCRYPTION_SCOPE_STRING, properties.getEncryptionScope()); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createEncryptionScopeSas() { PathSasPermission permissions = new PathSasPermission() @@ -333,7 +333,7 @@ public void createEncryptionScopeSas() { assertEquals(ENCRYPTION_SCOPE_STRING, client.getProperties().getEncryptionScope()); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createEncryptionScopeAccountSas() { AccountSasService service = new AccountSasService().setBlobAccess(true); @@ -359,7 +359,7 @@ public void createEncryptionScopeAccountSas() { assertEquals(ENCRYPTION_SCOPE_STRING, client.getProperties().getEncryptionScope()); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createEncryptionScopeIdentitySas() { UserDelegationKey key = getOAuthServiceClient() @@ -386,7 +386,7 @@ public void createEncryptionScopeIdentitySas() { assertEquals(ENCRYPTION_SCOPE_STRING, client.getProperties().getEncryptionScope()); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createOptionsWithAcl() { dc = dataLakeFileSystemClient.getDirectoryClient(generatePathName()); @@ -398,7 +398,7 @@ public void createOptionsWithAcl() { assertEquals(PATH_ACCESS_CONTROL_ENTRIES.get(1), acl.get(1)); // testing if group is set the same } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createOptionsWithOwnerAndGroup() { dc = dataLakeFileSystemClient.getDirectoryClient(generatePathName()); @@ -625,7 +625,7 @@ public void deleteDirDoesNotExistAnymore() { } @Disabled("Requires manual OAuth setup and creates 5000+ files") - @DisabledIf("olderThan20230803ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20230803ServiceVersion") @Test public void deletePaginatedDirectory() { String entityId = "68bff720-253b-428c-b124-603700654ea9"; @@ -864,7 +864,7 @@ public void setACLError() { () -> dc.setAccessControlList(PATH_ACCESS_CONTROL_ENTRIES, GROUP, OWNER)); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveMin() { setupStandardRecursiveAclTest(); @@ -877,7 +877,7 @@ public void setACLRecursiveMin() { assertNull(result.getBatchFailures()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveBatches() { setupStandardRecursiveAclTest(); @@ -892,7 +892,7 @@ public void setACLRecursiveBatches() { assertNull(result.getBatchFailures()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveBatchesResume() { setupStandardRecursiveAclTest(); @@ -912,7 +912,7 @@ public void setACLRecursiveBatchesResume() { assertNull(result.getBatchFailures()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveBatchesProgress() { setupStandardRecursiveAclTest(); @@ -939,7 +939,7 @@ public void setACLRecursiveBatchesProgress() { assertEquals(7, progress.cumulativeCounters.get(3).getChangedFilesCount() + progress.cumulativeCounters.get(3).getChangedDirectoriesCount()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveBatchesFollowToken() { setupStandardRecursiveAclTest(); @@ -979,7 +979,7 @@ private DataLakeDirectoryClient getSasDirectoryClient(DataLakeDirectoryClient di return getDirectoryClient(sas, directoryClient.getDirectoryUrl(), directoryClient.getDirectoryPath()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveProgressWithFailure() { dataLakeFileSystemClient.getRootDirectoryClient() @@ -1030,7 +1030,7 @@ public void setACLRecursiveProgressWithFailure() { assertNotNull(progress.failures.get(0).getErrorMessage()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveContinueOnFailure() { dataLakeFileSystemClient.getRootDirectoryClient() @@ -1094,7 +1094,7 @@ public void setACLRecursiveContinueOnFailure() { assertTrue(batchFailures.contains(subdir3.getObjectPath())); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveContinueOnFailureBatchFailures() { dataLakeFileSystemClient.getRootDirectoryClient() @@ -1153,7 +1153,7 @@ public void setACLRecursiveContinueOnFailureBatchFailures() { assertNull(result.getContinuationToken()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveContinueOnFailureBatchesResume() { dataLakeFileSystemClient.getRootDirectoryClient() @@ -1241,7 +1241,7 @@ public void setACLRecursiveError() { assertInstanceOf(DataLakeStorageException.class, e.getCause()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @ParameterizedTest @MethodSource("setACLRecursiveErrorSupplier") public void setACLRecursiveErrorMiddleOfBatches(Throwable error) { @@ -1267,7 +1267,7 @@ private static Stream setACLRecursiveErrorSupplier() { getStubResponse(500, new HttpRequest(HttpMethod.PUT, "https://www.fake.com")), null)); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursive() { setupStandardRecursiveAclTest(); @@ -1279,7 +1279,7 @@ public void updateACLRecursive() { assertNull(result.getBatchFailures()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveBatches() { setupStandardRecursiveAclTest(); @@ -1295,7 +1295,7 @@ public void updateACLRecursiveBatches() { assertNull(result.getBatchFailures()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveBatchesResume() { setupStandardRecursiveAclTest(); @@ -1314,7 +1314,7 @@ public void updateACLRecursiveBatchesResume() { assertNull(result.getBatchFailures()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveBatchesProgress() { setupStandardRecursiveAclTest(); @@ -1341,7 +1341,7 @@ public void updateACLRecursiveBatchesProgress() { assertEquals(7, progress.cumulativeCounters.get(3).getChangedFilesCount() + progress.cumulativeCounters.get(3).getChangedDirectoriesCount()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveBatchesFollowToken() { setupStandardRecursiveAclTest(); @@ -1372,7 +1372,7 @@ public void updateACLRecursiveBatchesFollowToken() { assertEquals(2, iterations); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveProgressWithFailure() { dataLakeFileSystemClient.getRootDirectoryClient() @@ -1422,7 +1422,7 @@ public void updateACLRecursiveProgressWithFailure() { assertNotNull(progress.failures.get(0).getErrorMessage()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveContinueOnFailure() { dataLakeFileSystemClient.getRootDirectoryClient() @@ -1486,7 +1486,7 @@ public void updateACLRecursiveContinueOnFailure() { assertTrue(batchFailures.contains(subdir3.getObjectPath())); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveContinueOnFailureBatchFailures() { dataLakeFileSystemClient.getRootDirectoryClient() @@ -1546,7 +1546,7 @@ public void updateACLRecursiveContinueOnFailureBatchFailures() { assertNull(result.getContinuationToken()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveContinueOnFailureBatchesResume() { dataLakeFileSystemClient.getRootDirectoryClient() @@ -1631,7 +1631,7 @@ public void updateACLRecursiveError() { assertInstanceOf(DataLakeStorageException.class, e.getCause()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @ParameterizedTest @MethodSource("setACLRecursiveErrorSupplier") public void updateACLRecursiveErrorMiddleOfBatches(Throwable error) { @@ -1649,7 +1649,7 @@ public void updateACLRecursiveErrorMiddleOfBatches(Throwable error) { assertEquals(error.getClass(), e.getCause().getClass()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursive() { setupStandardRecursiveAclTest(); @@ -1660,7 +1660,7 @@ public void removeACLRecursive() { assertEquals(0L, result.getCounters().getFailedChangesCount()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveBatches() { setupStandardRecursiveAclTest(); @@ -1676,7 +1676,7 @@ public void removeACLRecursiveBatches() { assertNull(result.getBatchFailures()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveBatchesResume() { setupStandardRecursiveAclTest(); @@ -1695,7 +1695,7 @@ public void removeACLRecursiveBatchesResume() { assertNull(result.getBatchFailures()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveBatchesProgress() { setupStandardRecursiveAclTest(); @@ -1722,7 +1722,7 @@ public void removeACLRecursiveBatchesProgress() { assertEquals(7, progress.cumulativeCounters.get(3).getChangedFilesCount() + progress.cumulativeCounters.get(3).getChangedDirectoriesCount()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveBatchesFollowToken() { setupStandardRecursiveAclTest(); @@ -1753,7 +1753,7 @@ public void removeACLRecursiveBatchesFollowToken() { assertEquals(2, iterations); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveProgressWithFailure() { dataLakeFileSystemClient.getRootDirectoryClient() @@ -1802,7 +1802,7 @@ public void removeACLRecursiveProgressWithFailure() { assertNotNull(progress.failures.get(0).getErrorMessage()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveContinueOnFailure() { dataLakeFileSystemClient.getRootDirectoryClient() @@ -1861,7 +1861,7 @@ public void removeACLRecursiveContinueOnFailure() { assertTrue(batchFailures.contains(subdir3.getObjectPath())); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveContinueOnFailureBatchFailures() { dataLakeFileSystemClient.getRootDirectoryClient() @@ -1922,7 +1922,7 @@ public void removeACLRecursiveContinueOnFailureBatchFailures() { assertNull(result.getContinuationToken()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveContinueOnFailureBatchesResume() { dataLakeFileSystemClient.getRootDirectoryClient() @@ -2011,7 +2011,7 @@ public void removeACLRecursiveError() { assertInstanceOf(DataLakeStorageException.class, e.getCause()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @ParameterizedTest @MethodSource("setACLRecursiveErrorSupplier") public void removeACLRecursiveErrorMiddleOfBatches(Throwable error) { @@ -2266,7 +2266,7 @@ public void getPropertiesMin() { assertEquals(200, dc.getPropertiesWithResponse(null, null, null).getStatusCode()); } - @DisabledIf("olderThan20200612ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200612ServiceVersion") @Test public void getPropertiesOwnerGroupPermissions() { PathProperties properties = dc.getPropertiesWithResponse(null, null, null).getValue(); @@ -3391,23 +3391,4 @@ public void createFileSystemWithSmallTimeoutsFailForServiceClient() { fail("Expected a request to time out."); } - private static boolean olderThan20200210ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_02_10); - } - - private static boolean olderThan20201206ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_12_06); - } - - private static boolean olderThan20200612ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_06_12); - } - - private static boolean olderThan20210608ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2021_06_08); - } - - private static boolean olderThan20230803ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2023_08_03); - } } diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DirectoryAsyncApiTests.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DirectoryAsyncApiTests.java index c2be04ae8b656..3b5cb4b98e9ad 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DirectoryAsyncApiTests.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/DirectoryAsyncApiTests.java @@ -119,7 +119,7 @@ public void createDefaults() { .verifyComplete(); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createDefaultsWithOptions() { DataLakePathCreateOptions options = new DataLakePathCreateOptions() @@ -320,7 +320,7 @@ public void createEncryptionScope() { .verifyComplete(); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createEncryptionScopeSas() { PathSasPermission permissions = new PathSasPermission() @@ -343,7 +343,7 @@ public void createEncryptionScopeSas() { .verifyComplete(); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createEncryptionScopeAccountSas() { AccountSasService service = new AccountSasService().setBlobAccess(true); @@ -371,7 +371,7 @@ public void createEncryptionScopeAccountSas() { .verifyComplete(); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createEncryptionScopeIdentitySas() { UserDelegationKey key = getOAuthServiceClient() @@ -400,7 +400,7 @@ public void createEncryptionScopeIdentitySas() { .verifyComplete(); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createOptionsWithAcl() { dc = dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(generatePathName()); @@ -415,7 +415,7 @@ public void createOptionsWithAcl() { .verifyComplete(); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createOptionsWithOwnerAndGroup() { dc = dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(generatePathName()); @@ -878,7 +878,7 @@ public void setACLError() { .verifyError(DataLakeStorageException.class); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveMin() { setupStandardRecursiveAclTest(); @@ -893,7 +893,7 @@ public void setACLRecursiveMin() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveBatches() { setupStandardRecursiveAclTest(); @@ -910,7 +910,7 @@ public void setACLRecursiveBatches() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveBatchesResume() { setupStandardRecursiveAclTest(); @@ -934,7 +934,7 @@ public void setACLRecursiveBatchesResume() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveBatchesProgress() { setupStandardRecursiveAclTest(); @@ -973,7 +973,7 @@ public void setACLRecursiveBatchesProgress() { + progress.cumulativeCounters.get(3).getChangedDirectoriesCount()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveBatchesFollowToken() { setupStandardRecursiveAclTest(); @@ -1013,7 +1013,7 @@ private DataLakeDirectoryAsyncClient getSasDirectoryClient(DataLakeDirectoryAsyn return getDirectoryAsyncClient(sas, directoryClient.getDirectoryUrl(), directoryClient.getDirectoryPath()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveProgressWithFailure() { dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient() @@ -1068,7 +1068,7 @@ public void setACLRecursiveProgressWithFailure() { } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveContinueOnFailure() { dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient() @@ -1134,7 +1134,7 @@ public void setACLRecursiveContinueOnFailure() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveContinueOnFailureBatchFailures() { dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient() @@ -1196,7 +1196,7 @@ public void setACLRecursiveContinueOnFailureBatchFailures() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursiveContinueOnFailureBatchesResume() { dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient() @@ -1289,7 +1289,7 @@ public void setACLRecursiveError() { }); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @ParameterizedTest @MethodSource("setACLRecursiveErrorSupplier") public void setACLRecursiveErrorMiddleOfBatches(Throwable error) { @@ -1316,7 +1316,7 @@ private static Stream setACLRecursiveErrorSupplier() { getStubResponse(500, new HttpRequest(HttpMethod.PUT, "https://www.fake.com")), null)); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursive() { setupStandardRecursiveAclTest(); @@ -1330,7 +1330,7 @@ public void updateACLRecursive() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveBatches() { setupStandardRecursiveAclTest(); @@ -1349,7 +1349,7 @@ public void updateACLRecursiveBatches() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveBatchesResume() { setupStandardRecursiveAclTest(); @@ -1373,7 +1373,7 @@ public void updateACLRecursiveBatchesResume() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveBatchesProgress() { setupStandardRecursiveAclTest(); @@ -1411,7 +1411,7 @@ public void updateACLRecursiveBatchesProgress() { + progress.cumulativeCounters.get(3).getChangedDirectoriesCount()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveBatchesFollowToken() { setupStandardRecursiveAclTest(); @@ -1442,7 +1442,7 @@ public void updateACLRecursiveBatchesFollowToken() { assertEquals(2, iterations); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveProgressWithFailure() { dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient() @@ -1495,7 +1495,7 @@ public void updateACLRecursiveProgressWithFailure() { assertNotNull(progress.failures.get(0).getErrorMessage()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveContinueOnFailure() { dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient() @@ -1560,7 +1560,7 @@ public void updateACLRecursiveContinueOnFailure() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveContinueOnFailureBatchFailures() { dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient() @@ -1622,7 +1622,7 @@ public void updateACLRecursiveContinueOnFailureBatchFailures() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursiveContinueOnFailureBatchesResume() { dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient() @@ -1713,7 +1713,7 @@ public void updateACLRecursiveError() { }); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @ParameterizedTest @MethodSource("setACLRecursiveErrorSupplier") public void updateACLRecursiveErrorMiddleOfBatches(Throwable error) { @@ -1733,7 +1733,7 @@ public void updateACLRecursiveErrorMiddleOfBatches(Throwable error) { }); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursive() { setupStandardRecursiveAclTest(); @@ -1746,7 +1746,7 @@ public void removeACLRecursive() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveBatches() { setupStandardRecursiveAclTest(); @@ -1764,7 +1764,7 @@ public void removeACLRecursiveBatches() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveBatchesResume() { setupStandardRecursiveAclTest(); @@ -1788,7 +1788,7 @@ public void removeACLRecursiveBatchesResume() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveBatchesProgress() { setupStandardRecursiveAclTest(); @@ -1826,7 +1826,7 @@ public void removeACLRecursiveBatchesProgress() { + progress.cumulativeCounters.get(3).getChangedDirectoriesCount()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveBatchesFollowToken() { setupStandardRecursiveAclTest(); @@ -1857,7 +1857,7 @@ public void removeACLRecursiveBatchesFollowToken() { assertEquals(2, iterations); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveProgressWithFailure() { dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient() @@ -1911,7 +1911,7 @@ public void removeACLRecursiveProgressWithFailure() { assertNotNull(progress.failures.get(0).getErrorMessage()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveContinueOnFailure() { dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient() @@ -1975,7 +1975,7 @@ public void removeACLRecursiveContinueOnFailure() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveContinueOnFailureBatchFailures() { dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient() @@ -2038,7 +2038,7 @@ public void removeACLRecursiveContinueOnFailureBatchFailures() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursiveContinueOnFailureBatchesResume() { dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient() @@ -2132,7 +2132,7 @@ public void removeACLRecursiveError() { }); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @ParameterizedTest @MethodSource("setACLRecursiveErrorSupplier") public void removeACLRecursiveErrorMiddleOfBatches(Throwable error) { @@ -2397,7 +2397,7 @@ public void getPropertiesMin() { 200); } - @DisabledIf("olderThan20200612ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200612ServiceVersion") @Test public void getPropertiesOwnerGroupPermissions() { StepVerifier.create(dc.getPropertiesWithResponse(null)) @@ -3615,27 +3615,4 @@ public void createFileSystemWithSmallTimeoutsFailForServiceClient() { fail("Expected a request to time out."); } - - - - private static boolean olderThan20200210ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_02_10); - } - - private static boolean olderThan20201206ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_12_06); - } - - private static boolean olderThan20200612ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_06_12); - } - - private static boolean olderThan20210608ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2021_06_08); - } - - private static boolean olderThan20230803ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2023_08_03); - } - } diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileApiTest.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileApiTest.java index dea61d7381d11..0e5c87389157d 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileApiTest.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileApiTest.java @@ -221,11 +221,7 @@ public void createMetadata(String key1, String value1, String key2, String value assertEquals(metadata, fc.getProperties().getMetadata()); } - private static boolean olderThan20210410ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2021_04_10); - } - - @DisabledIf("olderThan20210410ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210410ServiceVersion") @Test public void createEncryptionContext() { dataLakeFileSystemClient = primaryDataLakeServiceClient.getFileSystemClient(generateFileSystemName()); @@ -312,11 +308,7 @@ public void createPermissionsAndUmask() { assertEquals(201, fc.createWithResponse("0777", "0057", null, null, null, null, Context.NONE).getStatusCode()); } - private static boolean olderThan20201206ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_12_06); - } - - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createOptionsWithACL() { List pathAccessControlEntries = PathAccessControlEntry.parseList("user::rwx,group::r--,other::---,mask::rwx"); @@ -328,7 +320,7 @@ public void createOptionsWithACL() { assertEquals(pathAccessControlEntries.get(1), acl.get(1)); // testing if group is set the same } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createOptionsWithOwnerAndGroup() { String ownerName = testResourceNamer.randomUuid(); @@ -399,7 +391,7 @@ public void createOptionsWithPermissionsAndUmask() { assertEquals(PathPermissions.parseSymbolic("rwx-w----").toString(), acl.getPermissions().toString()); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createOptionsWithLeaseId() { String leaseId = CoreUtils.randomUuid().toString(); @@ -417,7 +409,7 @@ public void createOptionsWithLeaseIdError() { assertThrows(DataLakeStorageException.class, () -> fc.createWithResponse(options, null, null)); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createOptionsWithLeaseDuration() { String leaseId = CoreUtils.randomUuid().toString(); @@ -432,7 +424,7 @@ public void createOptionsWithLeaseDuration() { assertEquals(LeaseDurationType.FIXED, fileProps.getLeaseDuration()); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @ParameterizedTest @MethodSource("timeExpiresOnOptionsSupplier") public void createOptionsWithTimeExpiresOn(DataLakePathScheduleDeletionOptions deletionOptions) { @@ -445,7 +437,7 @@ private static Stream timeExpiresOnOptionsS return Stream.of(new DataLakePathScheduleDeletionOptions(OffsetDateTime.now().plusDays(1)), null); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createOptionsWithTimeToExpireRelativeToNow() { DataLakePathScheduleDeletionOptions deletionOptions = new DataLakePathScheduleDeletionOptions(Duration.ofDays(6)); @@ -541,7 +533,7 @@ public void createIfNotExistsPermissionsAndUmask() { .setPermissions("0777").setUmask("0057"), null, Context.NONE).getStatusCode()); } - @DisabledIf("olderThan20210410ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210410ServiceVersion") @Test public void createIfNotExistsEncryptionContext() { dataLakeFileSystemClient = primaryDataLakeServiceClient.createFileSystem(generateFileSystemName()); @@ -555,7 +547,7 @@ public void createIfNotExistsEncryptionContext() { assertEquals(encryptionContext, fc.getProperties().getEncryptionContext()); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createIfNotExistsOptionsWithACL() { fc = dataLakeFileSystemClient.getFileClient(generatePathName()); @@ -568,7 +560,7 @@ public void createIfNotExistsOptionsWithACL() { assertEquals(pathAccessControlEntries.get(1), acl.get(1)); // testing if group is set the same } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createIfNotExistsOptionsWithOwnerAndGroup() { fc = dataLakeFileSystemClient.getFileClient(generatePathName()); @@ -645,7 +637,7 @@ public void createIfNotExistsOptionsWithPermissionsAndUmask() { assertEquals(PathPermissions.parseSymbolic("rwx-w----").toString(), acl.getPermissions().toString()); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createIfNotExistsOptionsWithLeaseId() { fc = dataLakeFileSystemClient.getFileClient(generatePathName()); @@ -665,7 +657,7 @@ public void createIfNotExistsOptionsWithLeaseIdError() { assertThrows(DataLakeStorageException.class, () -> fc.createIfNotExistsWithResponse(options, null, null)); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createIfNotExistsOptionsWithLeaseDuration() { fc = dataLakeFileSystemClient.getFileClient(generatePathName()); @@ -681,7 +673,7 @@ public void createIfNotExistsOptionsWithLeaseDuration() { assertEquals(LeaseDurationType.FIXED, fileProps.getLeaseDuration()); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @ParameterizedTest @MethodSource("timeExpiresOnOptionsSupplier") public void createIfNotExistsOptionsWithTimeExpiresOn(DataLakePathScheduleDeletionOptions deletionOptions) { @@ -692,7 +684,7 @@ public void createIfNotExistsOptionsWithTimeExpiresOn(DataLakePathScheduleDeleti assertEquals(201, fc.createIfNotExistsWithResponse(options, null, null).getStatusCode()); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createIfNotExistsOptionsWithTimeToExpireRelativeToNow() { fc = dataLakeFileSystemClient.getFileClient(generatePathName()); @@ -906,11 +898,7 @@ public void setACLError() { () -> fc.setAccessControlList(PATH_ACCESS_CONTROL_ENTRIES, GROUP, OWNER)); } - private static boolean olderThan20200210ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_02_10); - } - - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursive() { AccessControlChangeResult response = fc.setAccessControlRecursive(PATH_ACCESS_CONTROL_ENTRIES); @@ -920,7 +908,7 @@ public void setACLRecursive() { assertEquals(0L, response.getCounters().getFailedChangesCount()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursive() { AccessControlChangeResult response = fc.updateAccessControlRecursive(PATH_ACCESS_CONTROL_ENTRIES); @@ -930,7 +918,7 @@ public void updateACLRecursive() { assertEquals(0L, response.getCounters().getFailedChangesCount()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursive() { List removeAccessControlEntries = PathRemoveAccessControlEntry.parseList( @@ -2021,11 +2009,7 @@ public void appendDataLeaseFail() { assertEquals(412, e.getResponse().getStatusCode()); } - private static boolean olderThan20200804ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_08_04); - } - - @DisabledIf("olderThan20200804ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200804ServiceVersion") @Test public void appendDataLeaseAcquire() { fc = dataLakeFileSystemClient.createFileIfNotExists(generatePathName()); @@ -2043,7 +2027,7 @@ public void appendDataLeaseAcquire() { assertEquals(LeaseDurationType.FIXED, fileProperties.getLeaseDuration()); } - @DisabledIf("olderThan20200804ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200804ServiceVersion") @Test public void appendDataLeaseAutoRenew() { fc = dataLakeFileSystemClient.createFileIfNotExists(generatePathName()); @@ -2064,7 +2048,7 @@ public void appendDataLeaseAutoRenew() { assertEquals(LeaseDurationType.FIXED, fileProperties.getLeaseDuration()); } - @DisabledIf("olderThan20200804ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200804ServiceVersion") @Test public void appendDataLeaseRelease() { fc = dataLakeFileSystemClient.createFileIfNotExists(generatePathName()); @@ -2086,7 +2070,7 @@ public void appendDataLeaseRelease() { assertEquals(LeaseStateType.AVAILABLE, fileProperties.getLeaseState()); } - @DisabledIf("olderThan20200804ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200804ServiceVersion") @Test public void appendDataLeaseAcquireRelease() { fc = dataLakeFileSystemClient.createFileIfNotExists(generatePathName()); @@ -2127,7 +2111,7 @@ public void appendDataRetryOnTransientFailure() { TestUtils.assertArraysEqual(DATA.getDefaultBytes(), os.toByteArray()); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void appendDataFlush() { DataLakeFileAppendOptions appendOptions = new DataLakeFileAppendOptions().setFlush(true); @@ -2165,7 +2149,7 @@ public void appendBinaryData() { - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void appendBinaryDataFlush() { DataLakeFileAppendOptions appendOptions = new DataLakeFileAppendOptions().setFlush(true); @@ -2518,7 +2502,7 @@ public void uploadBinaryDataOverwrite() { TestUtils.assertArraysEqual(DATA.getDefaultBytes(), os.toByteArray()); } - @DisabledIf("olderThan20210410ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210410ServiceVersion") @Test public void uploadEncryptionContext() { String encryptionContext = "encryptionContext"; @@ -2595,7 +2579,7 @@ private static byte[] readFromInputStream(InputStream stream, int numBytesToRead return queryData; } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @ValueSource(ints = { 1, // 32 bytes @@ -2632,7 +2616,7 @@ public void queryMin(int numCopies) { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @MethodSource("queryCsvSerializationSeparatorSupplier") public void queryCsvSerializationSeparator(char recordSeparator, char columnSeparator, boolean headersPresentIn, @@ -2713,7 +2697,7 @@ private static Stream queryCsvSerializationSeparatorSupplier() { ); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryCsvSerializationEscapeAndFieldQuote() { FileQueryDelimitedSerialization ser = new FileQueryDelimitedSerialization() @@ -2744,7 +2728,7 @@ public void queryCsvSerializationEscapeAndFieldQuote() { } /* Note: Input delimited tested everywhere else. */ - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @MethodSource("queryInputJsonSupplier") public void queryInputJson(int numCopies, char recordSeparator) { @@ -2783,7 +2767,7 @@ private static Stream queryInputJsonSupplier() { } @SuppressWarnings("DataFlowIssue") - @DisabledIf("olderThan20201002ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201002ServiceVersion") @Test public void queryInputParquet() { String fileName = "parquet.parquet"; @@ -2809,7 +2793,7 @@ public void queryInputParquet() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryInputCsvOutputJson() { liveTestScenarioWithRetry(() -> { @@ -2838,7 +2822,7 @@ public void queryInputCsvOutputJson() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryInputJsonOutputCsv() { liveTestScenarioWithRetry(() -> { @@ -2869,7 +2853,7 @@ public void queryInputJsonOutputCsv() { } @SuppressWarnings("resource") - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryInputCsvOutputArrow() { FileQueryDelimitedSerialization inSer = new FileQueryDelimitedSerialization() @@ -2894,7 +2878,7 @@ public void queryInputCsvOutputArrow() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryNonFatalError() { FileQueryDelimitedSerialization base = new FileQueryDelimitedSerialization() @@ -2925,7 +2909,7 @@ public void queryNonFatalError() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryFatalError() { FileQueryDelimitedSerialization base = new FileQueryDelimitedSerialization() @@ -2946,7 +2930,7 @@ public void queryFatalError() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryProgressReceiver() { FileQueryDelimitedSerialization base = new FileQueryDelimitedSerialization() @@ -2988,7 +2972,7 @@ public void queryProgressReceiver() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @EnabledIf("com.azure.storage.file.datalake.DataLakeTestBase#isLiveMode") // Large amount of data. @Test public void queryMultipleRecordsWithProgressReceiver() { @@ -3037,7 +3021,7 @@ public void queryMultipleRecordsWithProgressReceiver() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @CsvSource(value = {"true,false", "false,true"}) public void queryInputOutputIA(boolean input, boolean output) { @@ -3061,7 +3045,7 @@ public void queryInputOutputIA(boolean input, boolean output) { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryArrowInputIA() { FileQueryArrowSerialization inSer = new FileQueryArrowSerialization(); @@ -3078,11 +3062,7 @@ public void queryArrowInputIA() { }); } - private static boolean olderThan20201002ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_10_02); - } - - @DisabledIf("olderThan20201002ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201002ServiceVersion") @Test public void queryParquetOutputIA() { FileQueryParquetSerialization outSer = new FileQueryParquetSerialization(); @@ -3100,7 +3080,7 @@ public void queryParquetOutputIA() { } @SuppressWarnings("resource") - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryError() { fc = dataLakeFileSystemClient.getFileClient(generatePathName()); @@ -3115,7 +3095,7 @@ public void queryError() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @MethodSource("modifiedMatchAndLeaseIdSupplier") public void queryAC(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, @@ -3159,7 +3139,7 @@ private void liveTestScenarioWithRetry(Runnable runnable) { } } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @MethodSource("invalidModifiedMatchAndLeaseIdSupplier") public void queryACFail(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, @@ -3180,7 +3160,7 @@ public void queryACFail(OffsetDateTime modified, OffsetDateTime unmodified, Stri new FileQueryOptions(expression, new ByteArrayOutputStream()).setRequestConditions(bac), null, null)); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @MethodSource("scheduleDeletionSupplier") public void scheduleDeletion(FileScheduleDeletionOptions fileScheduleDeletionOptions, boolean hasExpiry) { @@ -3202,11 +3182,7 @@ private static Stream scheduleDeletionSupplier() { ); } - private static boolean olderThan20191212ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2019_12_12); - } - - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void scheduleDeletionTime() { OffsetDateTime now = testResourceNamer.now(); diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileAsyncApiTests.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileAsyncApiTests.java index f1c1a3c7f58a4..cf4ab75985685 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileAsyncApiTests.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileAsyncApiTests.java @@ -242,11 +242,7 @@ public void createMetadata(String key1, String value1, String key2, String value .verifyComplete(); } - private static boolean olderThan20210410ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2021_04_10); - } - - @DisabledIf("olderThan20210410ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210410ServiceVersion") @Test public void createEncryptionContext() { dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); @@ -333,11 +329,7 @@ public void createPermissionsAndUmask() { "0777", "0057", null, null, null), 201); } - private static boolean olderThan20201206ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_12_06); - } - - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createOptionsWithACL() { List pathAccessControlEntries = PathAccessControlEntry.parseList("user::rwx,group::r--,other::---,mask::rwx"); @@ -353,7 +345,7 @@ public void createOptionsWithACL() { .verifyComplete(); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createOptionsWithOwnerAndGroup() { String ownerName = testResourceNamer.randomUuid(); @@ -436,7 +428,7 @@ public void createOptionsWithPermissionsAndUmask() { .verifyComplete(); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createOptionsWithLeaseId() { String leaseId = CoreUtils.randomUuid().toString(); @@ -455,7 +447,7 @@ public void createOptionsWithLeaseIdError() { .verifyError(DataLakeStorageException.class); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createOptionsWithLeaseDuration() { String leaseId = CoreUtils.randomUuid().toString(); @@ -472,7 +464,7 @@ public void createOptionsWithLeaseDuration() { .verifyComplete(); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @ParameterizedTest @MethodSource("timeExpiresOnOptionsSupplier") public void createOptionsWithTimeExpiresOn(DataLakePathScheduleDeletionOptions deletionOptions) { @@ -485,7 +477,7 @@ private static Stream timeExpiresOnOptionsS return Stream.of(new DataLakePathScheduleDeletionOptions(OffsetDateTime.now().plusDays(1)), null); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createOptionsWithTimeToExpireRelativeToNow() { DataLakePathScheduleDeletionOptions deletionOptions = new DataLakePathScheduleDeletionOptions(Duration.ofDays(6)); @@ -593,7 +585,7 @@ public void createIfNotExistsPermissionsAndUmask() { .setPermissions("0777").setUmask("0057"), Context.NONE), 201); } - @DisabledIf("olderThan20210410ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210410ServiceVersion") @Test public void createIfNotExistsEncryptionContext() { dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); @@ -619,7 +611,7 @@ public void createIfNotExistsEncryptionContext() { .verifyComplete(); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createIfNotExistsOptionsWithACL() { fc = dataLakeFileSystemAsyncClient.getFileAsyncClient(generatePathName()); @@ -637,7 +629,7 @@ public void createIfNotExistsOptionsWithACL() { .verifyComplete(); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createIfNotExistsOptionsWithOwnerAndGroup() { fc = dataLakeFileSystemAsyncClient.getFileAsyncClient(generatePathName()); @@ -730,7 +722,7 @@ public void createIfNotExistsOptionsWithPermissionsAndUmask() { .verifyComplete(); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createIfNotExistsOptionsWithLeaseId() { fc = dataLakeFileSystemAsyncClient.getFileAsyncClient(generatePathName()); @@ -752,7 +744,7 @@ public void createIfNotExistsOptionsWithLeaseIdError() { .verifyError(DataLakeStorageException.class); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createIfNotExistsOptionsWithLeaseDuration() { fc = dataLakeFileSystemAsyncClient.getFileAsyncClient(generatePathName()); @@ -771,7 +763,7 @@ public void createIfNotExistsOptionsWithLeaseDuration() { .verifyComplete(); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @ParameterizedTest @MethodSource("timeExpiresOnOptionsSupplier") public void createIfNotExistsOptionsWithTimeExpiresOn(DataLakePathScheduleDeletionOptions deletionOptions) { @@ -782,7 +774,7 @@ public void createIfNotExistsOptionsWithTimeExpiresOn(DataLakePathScheduleDeleti assertAsyncResponseStatusCode(fc.createIfNotExistsWithResponse(options, null), 201); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @Test public void createIfNotExistsOptionsWithTimeToExpireRelativeToNow() { fc = dataLakeFileSystemAsyncClient.getFileAsyncClient(generatePathName()); @@ -1010,11 +1002,7 @@ public void setACLError() { .verifyError(DataLakeStorageException.class); } - private static boolean olderThan20200210ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_02_10); - } - - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void setACLRecursive() { StepVerifier.create(fc.setAccessControlRecursive(PATH_ACCESS_CONTROL_ENTRIES)) @@ -1026,7 +1014,7 @@ public void setACLRecursive() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void updateACLRecursive() { StepVerifier.create(fc.updateAccessControlRecursive(PATH_ACCESS_CONTROL_ENTRIES)) @@ -1038,7 +1026,7 @@ public void updateACLRecursive() { .verifyComplete(); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void removeACLRecursive() { List removeAccessControlEntries = PathRemoveAccessControlEntry.parseList( @@ -2308,11 +2296,8 @@ public void appendDataLeaseFail() { }); } - private static boolean olderThan20200804ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_08_04); - } - @DisabledIf("olderThan20200804ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200804ServiceVersion") @Test public void appendDataLeaseAcquire() { fc = dataLakeFileSystemAsyncClient.createFileIfNotExists(generatePathName()).block(); @@ -2334,7 +2319,7 @@ public void appendDataLeaseAcquire() { .verifyComplete(); } - @DisabledIf("olderThan20200804ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200804ServiceVersion") @Test public void appendDataLeaseAutoRenew() { fc = dataLakeFileSystemAsyncClient.createFileIfNotExists(generatePathName()).block(); @@ -2383,7 +2368,7 @@ public void appendDataLeaseRelease() { .verifyComplete(); } - @DisabledIf("olderThan20200804ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200804ServiceVersion") @Test public void appendDataLeaseAcquireRelease() { fc = dataLakeFileSystemAsyncClient.createFileIfNotExists(generatePathName()).block(); @@ -2429,7 +2414,7 @@ public void appendDataRetryOnTransientFailure() { .verifyComplete(); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void appendDataFlush() { DataLakeFileAppendOptions appendOptions = new DataLakeFileAppendOptions().setFlush(true); @@ -2469,7 +2454,7 @@ public void appendBinaryData() { .verifyComplete(); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void appendBinaryDataFlush() { DataLakeFileAppendOptions appendOptions = new DataLakeFileAppendOptions().setFlush(true); @@ -3448,7 +3433,7 @@ public void uploadBinaryDataOverwrite() { .verifyComplete(); } - @DisabledIf("olderThan20210410ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210410ServiceVersion") @Test public void uploadEncryptionContext() { String encryptionContext = "encryptionContext"; @@ -3506,7 +3491,7 @@ private void uploadSmallJson(int numCopies) { fc.flush(b.length(), true).block(); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @ValueSource(ints = { 1, // 32 bytes @@ -3543,7 +3528,7 @@ public void queryMin(int numCopies) { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @MethodSource("queryCsvSerializationSeparatorSupplier") public void queryCsvSerializationSeparator(char recordSeparator, char columnSeparator, boolean headersPresentIn, @@ -3607,7 +3592,7 @@ private static Stream queryCsvSerializationSeparatorSupplier() { ); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryCsvSerializationEscapeAndFieldQuote() { FileQueryDelimitedSerialization ser = new FileQueryDelimitedSerialization() @@ -3633,7 +3618,7 @@ public void queryCsvSerializationEscapeAndFieldQuote() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @MethodSource("queryInputJsonSupplier") public void queryInputJson(int numCopies, char recordSeparator) { @@ -3669,7 +3654,7 @@ private static Stream queryInputJsonSupplier() { ); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryInputCsvOutputJson() { liveTestScenarioWithRetry(() -> { @@ -3695,7 +3680,7 @@ public void queryInputCsvOutputJson() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryInputJsonOutputCsv() { liveTestScenarioWithRetry(() -> { @@ -3723,7 +3708,7 @@ public void queryInputJsonOutputCsv() { } @SuppressWarnings("resource") - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryInputCsvOutputArrow() { FileQueryDelimitedSerialization inSer = new FileQueryDelimitedSerialization() @@ -3746,7 +3731,7 @@ public void queryInputCsvOutputArrow() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryNonFatalError() { FileQueryDelimitedSerialization base = new FileQueryDelimitedSerialization() @@ -3768,7 +3753,7 @@ public void queryNonFatalError() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryFatalError() { FileQueryDelimitedSerialization base = new FileQueryDelimitedSerialization() @@ -3789,7 +3774,7 @@ public void queryFatalError() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryProgressReceiver() { FileQueryDelimitedSerialization base = new FileQueryDelimitedSerialization() @@ -3820,7 +3805,7 @@ public void queryProgressReceiver() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @EnabledIf("com.azure.storage.file.datalake.DataLakeTestBase#isLiveMode") // Large amount of data. @Test public void queryMultipleRecordsWithProgressReceiver() { @@ -3848,7 +3833,7 @@ public void queryMultipleRecordsWithProgressReceiver() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @CsvSource(value = {"true,false", "false,true"}) public void queryInputOutputIA(boolean input, boolean output) { @@ -3867,7 +3852,7 @@ public void queryInputOutputIA(boolean input, boolean output) { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryArrowInputIA() { FileQueryArrowSerialization inSer = new FileQueryArrowSerialization(); @@ -3881,11 +3866,7 @@ public void queryArrowInputIA() { }); } - private static boolean olderThan20201002ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_10_02); - } - - @DisabledIf("olderThan20201002ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201002ServiceVersion") @Test public void queryParquetOutputIA() { FileQueryParquetSerialization outSer = new FileQueryParquetSerialization(); @@ -3899,7 +3880,7 @@ public void queryParquetOutputIA() { } @SuppressWarnings("resource") - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void queryError() { fc = dataLakeFileSystemAsyncClient.getFileAsyncClient(generatePathName()); @@ -3910,7 +3891,7 @@ public void queryError() { }); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @MethodSource("modifiedMatchAndLeaseIdSupplier") public void queryAC(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, @@ -3947,7 +3928,7 @@ private void liveTestScenarioWithRetry(Runnable runnable) { } } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @MethodSource("invalidModifiedMatchAndLeaseIdSupplier") public void queryACFail(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, @@ -3966,7 +3947,7 @@ public void queryACFail(OffsetDateTime modified, OffsetDateTime unmodified, Stri .verifyError(DataLakeStorageException.class); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ParameterizedTest @MethodSource("scheduleDeletionSupplier") public void scheduleDeletion(FileScheduleDeletionOptions fileScheduleDeletionOptions, boolean hasExpiry) { @@ -3988,11 +3969,7 @@ private static Stream scheduleDeletionSupplier() { ); } - private static boolean olderThan20191212ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2019_12_12); - } - - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void scheduleDeletionTime() { OffsetDateTime now = testResourceNamer.now(); diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileSystemApiTests.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileSystemApiTests.java index 48a2755a57c6f..3f26d00dbdcd5 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileSystemApiTests.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileSystemApiTests.java @@ -41,7 +41,6 @@ import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.ValueSource; -import reactor.test.StepVerifier; import java.time.Duration; import java.time.OffsetDateTime; @@ -708,7 +707,7 @@ public void createFilePermissionsAndUmask() { null, null, null, Context.NONE).getStatusCode()); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createFileOptionsWithACL() { List pathAccessControlEntries = PathAccessControlEntry.parseList("user::rwx,group::r--,other::---,mask::rwx"); @@ -721,7 +720,7 @@ public void createFileOptionsWithACL() { assertEquals(pathAccessControlEntries.get(1), acl.get(1)); // testing if group is set the same } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createFileOptionsWithOwnerAndGroup() { String ownerName = testResourceNamer.randomUuid(); @@ -809,7 +808,7 @@ public void createFileOptionsWithPermissionsAndUmask() { assertEquals(PathPermissions.parseSymbolic("rwx-w----").toString(), acl.getPermissions().toString()); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createFileOptionsWithLeaseId() { String leaseId = CoreUtils.randomUuid().toString(); @@ -829,7 +828,7 @@ public void createFileOptionsWithLeaseIdError() { () -> dataLakeFileSystemClient.createFileWithResponse(generatePathName(), options, null, null)); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createFileOptionsWithLeaseDuration() { String leaseId = CoreUtils.randomUuid().toString(); @@ -847,7 +846,7 @@ public void createFileOptionsWithLeaseDuration() { assertEquals(LeaseDurationType.FIXED, fileProps.getLeaseDuration()); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @ParameterizedTest @MethodSource("createFileOptionsWithTimeExpiresOnAbsoluteAndNeverExpireSupplier") public void createFileOptionsWithTimeExpiresOnAbsoluteAndNeverExpire(DataLakePathScheduleDeletionOptions deletionOptions) { @@ -859,7 +858,7 @@ private static Stream createFileOptionsWith return Stream.of(new DataLakePathScheduleDeletionOptions(OffsetDateTime.now().plusDays(1)), null); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createFileOptionsWithTimeToExpireRelativeToNow() { DataLakePathCreateOptions options = new DataLakePathCreateOptions() @@ -940,7 +939,7 @@ public void createIfNotExistsFilePermissionsAndUmask() { .getStatusCode()); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createIfNotExistsFileOptionsWithACL() { List pathAccessControlEntries = PathAccessControlEntry.parseList("user::rwx,group::r--,other::---,mask::rwx"); @@ -953,7 +952,7 @@ public void createIfNotExistsFileOptionsWithACL() { assertEquals(pathAccessControlEntries.get(1), acl.get(1)); // testing if group is set the same } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createIfNotExistsFileOptionsWithOwnerAndGroup() { String ownerName = testResourceNamer.randomUuid(); @@ -1031,7 +1030,7 @@ public void createIfNotExistsFileOptionsWithPermissionsAndUmask() { assertEquals(PathPermissions.parseSymbolic("rwx-w----").toString(), acl.getPermissions().toString()); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createIfNotExistsFileOptionsWithLeaseId() { DataLakePathCreateOptions options = new DataLakePathCreateOptions() @@ -1052,7 +1051,7 @@ public void createIfNotExistsFileOptionsWithLeaseIdError() { dataLakeFileSystemClient.createFileIfNotExistsWithResponse(generatePathName(), options, null, null)); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createIfNotExistsFileOptionsWithLeaseDuration() { DataLakePathCreateOptions options = new DataLakePathCreateOptions().setLeaseDuration(15) @@ -1070,7 +1069,7 @@ public void createIfNotExistsFileOptionsWithLeaseDuration() { } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @ParameterizedTest @MethodSource("createIfNotExistsFileOptionsWithTimeExpiresOnAbsoluteAndNeverExpireSupplier") public void createIfNotExistsFileOptionsWithTimeExpiresOnAbsoluteAndNeverExpire(DataLakePathScheduleDeletionOptions deletionOptions) { @@ -1084,7 +1083,7 @@ private static Stream createIfNotExistsFile return Stream.of(new DataLakePathScheduleDeletionOptions(OffsetDateTime.now().plusDays(1)), null); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createIfNotExistsFileOptionsWithTimeToExpireRelativeToNow() { DataLakePathCreateOptions options = new DataLakePathCreateOptions() @@ -1340,7 +1339,7 @@ public void createDirPermissionsAndUmask() { null, null, null, null, Context.NONE).getStatusCode()); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createDirOptionsWithACL() { List pathAccessControlEntries = PathAccessControlEntry.parseList("user::rwx,group::r--,other::---,mask::rwx"); @@ -1353,7 +1352,7 @@ public void createDirOptionsWithACL() { assertEquals(pathAccessControlEntries.get(1), acl.get(1)); // testing if group is set the same } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createDirOptionsWithOwnerAndGroup() { String ownerName = testResourceNamer.randomUuid(); @@ -1547,7 +1546,7 @@ public void createIfNotExistsDirPermissionsAndUmask() { null, Context.NONE).getStatusCode()); } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createIfNotExistsDirOptionsWithACL() { List pathAccessControlEntries = PathAccessControlEntry.parseList("user::rwx,group::r--,other::---,mask::rwx"); @@ -1560,7 +1559,7 @@ public void createIfNotExistsDirOptionsWithACL() { assertEquals(pathAccessControlEntries.get(1), acl.get(1)); // testing if group is set the same } - @DisabledIf("olderThan20210608ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") @Test public void createIfNotExistsDirOptionsWithOwnerAndGroup() { String ownerName = testResourceNamer.randomUuid(); @@ -1870,7 +1869,7 @@ public void listPaths() { assertFalse(response.hasNext()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void listPathsExpiryAndCreation() { String dirName = generatePathName(); @@ -1992,19 +1991,6 @@ public void listPathsEncryptionScope() { assertFalse(response.hasNext()); } - @Test - public void asyncListPathsMaxResultsByPage() { - dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(generatePathName()).create().block(); - dataLakeFileSystemAsyncClient.getFileAsyncClient(generatePathName()).create().block(); - - StepVerifier.create(dataLakeFileSystemAsyncClient.listPaths(new ListPathsOptions()).byPage(1)) - .thenConsumeWhile(page -> { - assertEquals(1, page.getValue().size()); - return true; - }) - .verifyComplete(); - } - @ParameterizedTest @ValueSource(strings = {"%E4%B8%AD%E6%96%87", "az%5B%5D", "hello%20world", "hello%26world", "%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%3F%23%5B%5D"}) @@ -2308,12 +2294,4 @@ public void perCallPolicy() { // // assertThrows(DataLakeStorageException.class, () -> dataLakeFileSystemClient.rename(generateFileSystemName())); // } - - private static boolean olderThan20200210ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_02_10); - } - - private static boolean olderThan20210608ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2021_06_08); - } } diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileSystemAsyncApiTests.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileSystemAsyncApiTests.java new file mode 100644 index 0000000000000..ea2c231d1312e --- /dev/null +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/FileSystemAsyncApiTests.java @@ -0,0 +1,2351 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +package com.azure.storage.file.datalake; + +import com.azure.core.http.HttpHeaderName; +import com.azure.core.util.CoreUtils; +import com.azure.identity.DefaultAzureCredentialBuilder; +import com.azure.storage.blob.BlobUrlParts; +import com.azure.storage.blob.models.BlobErrorCode; +import com.azure.storage.common.Utility; +import com.azure.storage.file.datalake.models.DataLakeAccessPolicy; +import com.azure.storage.file.datalake.models.DataLakeRequestConditions; +import com.azure.storage.file.datalake.models.DataLakeSignedIdentifier; +import com.azure.storage.file.datalake.models.DataLakeStorageException; +import com.azure.storage.file.datalake.models.LeaseDurationType; +import com.azure.storage.file.datalake.models.LeaseStateType; +import com.azure.storage.file.datalake.models.LeaseStatusType; +import com.azure.storage.file.datalake.models.ListPathsOptions; +import com.azure.storage.file.datalake.models.PathAccessControlEntry; +import com.azure.storage.file.datalake.models.PathHttpHeaders; +import com.azure.storage.file.datalake.models.PathPermissions; +import com.azure.storage.file.datalake.models.PublicAccessType; +import com.azure.storage.file.datalake.options.DataLakePathCreateOptions; +import com.azure.storage.file.datalake.options.DataLakePathDeleteOptions; +import com.azure.storage.file.datalake.options.DataLakePathScheduleDeletionOptions; +import com.azure.storage.file.datalake.options.FileScheduleDeletionOptions; +import com.azure.storage.file.datalake.options.FileSystemEncryptionScopeOptions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledIf; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; +import reactor.test.StepVerifier; + +import java.time.Duration; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.temporal.ChronoUnit; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class FileSystemAsyncApiTests extends DataLakeTestBase { + + @Test + public void createAllNull() { + // Overwrite the existing dataLakeFileSystemClient, which has already been created + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createWithResponse(null, null)) + .assertNext(r -> { + assertEquals(201, r.getStatusCode()); + validateBasicHeaders(r.getHeaders()); + }) + .verifyComplete(); + } + + @Test + public void createMin() { + StepVerifier.create(primaryDataLakeServiceAsyncClient.createFileSystem(generateFileSystemName())) + .assertNext(r -> assertNotNull(r.getProperties())) + .verifyComplete(); + } + + @ParameterizedTest + @CsvSource(value = {"null,null,null,null", "foo,bar,fizz,buzz", "testFoo,testBar,testFizz,testBuzz"}, + nullValues = "null") + public void createMetadata(String key1, String value1, String key2, String value2) { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + Map metadata = new HashMap<>(); + if (key1 != null) { + metadata.put(key1, value1); + } + if (key2 != null) { + metadata.put(key2, value2); + } + + dataLakeFileSystemAsyncClient.createWithResponse(metadata, null).block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getPropertiesWithResponse(null)) + .assertNext(r -> assertEquals(metadata, r.getValue().getMetadata())) + .verifyComplete(); + } + + @ParameterizedTest + @MethodSource("publicAccessSupplier") + public void createPublicAccess(PublicAccessType publicAccess) { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + dataLakeFileSystemAsyncClient.createWithResponse(null, publicAccess).block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getProperties()) + .assertNext(p -> assertEquals(publicAccess, p.getDataLakePublicAccess())) + .verifyComplete(); + } + + private static Stream publicAccessSupplier() { + return Stream.of(PublicAccessType.BLOB, PublicAccessType.CONTAINER, null); + } + + @Test + public void createError() { + StepVerifier.create(dataLakeFileSystemAsyncClient.create()) + .verifyErrorSatisfies(r -> { + DataLakeStorageException e = assertInstanceOf(DataLakeStorageException.class, r); + assertEquals(409, e.getStatusCode()); + assertEquals(BlobErrorCode.CONTAINER_ALREADY_EXISTS.toString(), e.getErrorCode()); + }); + } + + @Test + public void createEncryptionScope() { + FileSystemEncryptionScopeOptions encryptionScope = new FileSystemEncryptionScopeOptions() + .setDefaultEncryptionScope(ENCRYPTION_SCOPE_STRING) + .setEncryptionScopeOverridePrevented(true); + + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + DataLakeFileSystemAsyncClient client = getFileSystemClientBuilder(dataLakeFileSystemAsyncClient.getFileSystemUrl()) + .credential(getDataLakeCredential()) + .fileSystemEncryptionScopeOptions(encryptionScope) + .buildAsyncClient(); + + client.create().block(); + StepVerifier.create(client.getProperties()) + .assertNext(p -> { + assertEquals(ENCRYPTION_SCOPE_STRING, p.getEncryptionScope()); + assertTrue(p.isEncryptionScopeOverridePrevented()); + }) + .verifyComplete(); + } + + @ParameterizedTest + @CsvSource(value = {"null,null,null,null", "foo,bar,fizz,buzz", "testFoo,testBar,testFizz,testBuzz"}, + nullValues = "null") + public void createMetadataEncryptionScope(String key1, String value1, String key2, String value2) { + FileSystemEncryptionScopeOptions encryptionScope = new FileSystemEncryptionScopeOptions() + .setDefaultEncryptionScope(ENCRYPTION_SCOPE_STRING) + .setEncryptionScopeOverridePrevented(true); + + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + DataLakeFileSystemAsyncClient client = getFileSystemClientBuilder(dataLakeFileSystemAsyncClient.getFileSystemUrl()) + .credential(getDataLakeCredential()) + .fileSystemEncryptionScopeOptions(encryptionScope) + .buildAsyncClient(); + + Map metadata = new HashMap<>(); + if (key1 != null) { + metadata.put(key1, value1); + } + if (key2 != null) { + metadata.put(key2, value2); + } + + client.createWithResponse(metadata, null).block(); + StepVerifier.create(client.getProperties()) + .assertNext(p -> { + assertEquals(ENCRYPTION_SCOPE_STRING, p.getEncryptionScope()); + assertTrue(p.isEncryptionScopeOverridePrevented()); + assertEquals(metadata, p.getMetadata()); + }) + .verifyComplete(); + } + + @Test + public void createIfNotExistsAllNull() { + // Overwrite the existing dataLakeFileSystemClient, which has already been created + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createIfNotExistsWithResponse(null, null)) + .assertNext(r -> { + assertEquals(201, r.getStatusCode()); + validateBasicHeaders(r.getHeaders()); + }) + .verifyComplete(); + } + + @Test + public void createIfNotExistsMin() { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createIfNotExists()) + .expectNext(true) + .verifyComplete(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.exists()) + .expectNext(true) + .verifyComplete(); + } + + @ParameterizedTest + @CsvSource(value = {"null,null,null,null", "foo,bar,fizz,buzz", "testFoo,testBar,testFizz,testBuzz"}, + nullValues = "null") + public void createIfNotExistsMetadata(String key1, String value1, String key2, String value2) { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + Map metadata = new HashMap<>(); + if (key1 != null) { + metadata.put(key1, value1); + } + if (key2 != null) { + metadata.put(key2, value2); + } + + dataLakeFileSystemAsyncClient.createIfNotExistsWithResponse(metadata, null).block(); + StepVerifier.create(dataLakeFileSystemAsyncClient.getPropertiesWithResponse(null)) + .assertNext(r -> assertEquals(metadata, r.getValue().getMetadata())) + .verifyComplete(); + } + + @ParameterizedTest + @MethodSource("publicAccessSupplier") + public void createIfNotExistsPublicAccess(PublicAccessType publicAccess) { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + dataLakeFileSystemAsyncClient.createIfNotExistsWithResponse(null, publicAccess).block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getProperties()) + .assertNext(p -> assertEquals(publicAccess, p.getDataLakePublicAccess())) + .verifyComplete(); + } + + @Test + public void createIfNotExistsOnFileSystemThatAlreadyExists() { + DataLakeFileSystemAsyncClient dataLakeFileSystemAsyncClient = + primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createIfNotExistsWithResponse(null, null), 201); + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createIfNotExistsWithResponse(null, null), 409); + } + + @Test + public void createIfNotExistsEncryptionScope() { + FileSystemEncryptionScopeOptions encryptionScope = new FileSystemEncryptionScopeOptions() + .setDefaultEncryptionScope(ENCRYPTION_SCOPE_STRING) + .setEncryptionScopeOverridePrevented(true); + + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + DataLakeFileSystemAsyncClient client = getFileSystemClientBuilder(dataLakeFileSystemAsyncClient.getFileSystemUrl()) + .credential(getDataLakeCredential()) + .fileSystemEncryptionScopeOptions(encryptionScope) + .buildAsyncClient(); + + client.createIfNotExists().block(); + StepVerifier.create(client.getProperties()) + .assertNext(p -> { + assertEquals(ENCRYPTION_SCOPE_STRING, p.getEncryptionScope()); + assertTrue(p.isEncryptionScopeOverridePrevented()); + }) + .verifyComplete(); + } + + @Test + public void getPropertiesNull() { + StepVerifier.create(dataLakeFileSystemAsyncClient.getPropertiesWithResponse(null)) + .assertNext(r -> { + validateBasicHeaders(r.getHeaders()); + assertNull(r.getValue().getDataLakePublicAccess()); + assertFalse(r.getValue().hasImmutabilityPolicy()); + assertFalse(r.getValue().hasLegalHold()); + assertNull(r.getValue().getLeaseDuration()); + assertEquals(LeaseStateType.AVAILABLE, r.getValue().getLeaseState()); + assertEquals(LeaseStatusType.UNLOCKED, r.getValue().getLeaseStatus()); + assertEquals(0, r.getValue().getMetadata().size()); + }) + .verifyComplete(); + } + + @Test + public void getPropertiesMin() { + assertNotNull(dataLakeFileSystemAsyncClient.getProperties().block()); + } + + @Test + public void getPropertiesLease() { + String leaseID = setupFileSystemLeaseCondition(dataLakeFileSystemAsyncClient, RECEIVED_LEASE_ID); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.getPropertiesWithResponse(leaseID), 200); + } + + @Test + public void getPropertiesLeaseFail() { + StepVerifier.create(dataLakeFileSystemAsyncClient.getPropertiesWithResponse("garbage")) + .verifyError(DataLakeStorageException.class); + } + + @Test + public void getPropertiesError() { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getProperties()) + .verifyError(DataLakeStorageException.class); + } + + @Test + public void exists() { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + dataLakeFileSystemAsyncClient.create().block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.exists()) + .expectNext(true) + .verifyComplete(); + } + + @Test + public void existsNotExists() { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + StepVerifier.create(dataLakeFileSystemAsyncClient.exists()) + .expectNext(false) + .verifyComplete(); + } + + @Test + public void setMetadata() { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + Map metadata = Collections.singletonMap("key", "value"); + dataLakeFileSystemAsyncClient.createWithResponse(metadata, null).block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.setMetadataWithResponse(null, null)) + .assertNext(r -> { + assertEquals(200, r.getStatusCode()); + validateBasicHeaders(r.getHeaders()); + }) + .verifyComplete(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getProperties()) + .assertNext(p -> assertEquals(0, p.getMetadata().size())) + .verifyComplete(); + } + + @Test + public void setMetadataMin() { + Map metadata = Collections.singletonMap("foo", "bar"); + + dataLakeFileSystemAsyncClient.setMetadata(metadata).block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getProperties()) + .assertNext(p -> assertEquals(metadata, p.getMetadata())) + .verifyComplete(); + } + + @ParameterizedTest + @CsvSource(value = {"null,null,null,null", "foo,bar,fizz,buzz"}, nullValues = "null") + public void setMetadataMetadata(String key1, String value1, String key2, String value2) { + Map metadata = new HashMap<>(); + if (key1 != null) { + metadata.put(key1, value1); + } + if (key2 != null) { + metadata.put(key2, value2); + } + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.setMetadataWithResponse(metadata, null), 200); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getProperties()) + .assertNext(p -> assertEquals(metadata, p.getMetadata())) + .verifyComplete(); + } + + @ParameterizedTest + @MethodSource("setMetadataACSupplier") + public void setMetadataAC(OffsetDateTime modified, String leaseID) { + leaseID = setupFileSystemLeaseCondition(dataLakeFileSystemAsyncClient, leaseID); + DataLakeRequestConditions drc = new DataLakeRequestConditions().setLeaseId(leaseID).setIfModifiedSince(modified); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.setMetadataWithResponse(null, drc), 200); + } + + private static Stream setMetadataACSupplier() { + return Stream.of( + // modified | leaseID + Arguments.of(null, null), + Arguments.of(OLD_DATE, null), + Arguments.of(null, RECEIVED_LEASE_ID) + ); + } + + @ParameterizedTest + @MethodSource("setMetadataACFailSupplier") + public void setMetadataACFail(OffsetDateTime modified, String leaseID) { + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(leaseID) + .setIfModifiedSince(modified); + + StepVerifier.create(dataLakeFileSystemAsyncClient.setMetadataWithResponse(null, drc)) + .verifyError(DataLakeStorageException.class); + } + + private static Stream setMetadataACFailSupplier() { + // modified | leaseID + return Stream.of(Arguments.of(NEW_DATE, null), Arguments.of(null, GARBAGE_LEASE_ID)); + } + + @ParameterizedTest + @MethodSource("setMetadataACIllegalSupplier") + public void setMetadataACIllegal(OffsetDateTime unmodified, String match, String noneMatch) { + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setIfMatch(match) + .setIfNoneMatch(noneMatch) + .setIfUnmodifiedSince(unmodified); + + StepVerifier.create(dataLakeFileSystemAsyncClient.setMetadataWithResponse(null, drc)) + .verifyError(UnsupportedOperationException.class); + } + + private static Stream setMetadataACIllegalSupplier() { + return Stream.of( + // unmodified | match | noneMatch + Arguments.of(NEW_DATE, null, null), + Arguments.of(null, RECEIVED_ETAG, null), + Arguments.of(null, null, GARBAGE_ETAG) + ); + } + + @Test + public void setMetadataError() { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + StepVerifier.create(dataLakeFileSystemAsyncClient.setMetadata(null)) + .verifyError(DataLakeStorageException.class); + } + + @Test + public void delete() { + StepVerifier.create(dataLakeFileSystemAsyncClient.deleteWithResponse(null)) + .assertNext(r -> { + assertEquals(202, r.getStatusCode()); + assertNotNull(r.getHeaders().getValue(X_MS_REQUEST_ID)); + assertNotNull(r.getHeaders().getValue(X_MS_VERSION)); + assertNotNull(r.getHeaders().getValue(HttpHeaderName.DATE)); + }) + .verifyComplete(); + } + + @Test + public void deleteMin() { + dataLakeFileSystemAsyncClient.delete().block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getProperties()) + .verifyErrorSatisfies(r -> { + DataLakeStorageException e = assertInstanceOf(DataLakeStorageException.class, r); + assertEquals(404, e.getStatusCode()); + assertEquals(BlobErrorCode.CONTAINER_NOT_FOUND.toString(), e.getErrorCode()); + assertTrue(e.getServiceMessage().contains("The specified container does not exist.")); + }); + } + + @ParameterizedTest + @MethodSource("modifiedAndLeaseIdSupplier") + public void deleteAC(OffsetDateTime modified, OffsetDateTime unmodified, String leaseID) { + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(setupFileSystemLeaseCondition(dataLakeFileSystemAsyncClient, leaseID)) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteWithResponse(drc), 202); + } + + private static Stream modifiedAndLeaseIdSupplier() { + return Stream.of( + // modified | unmodified | leaseID + Arguments.of(null, null, null), + Arguments.of(OLD_DATE, null, null), + Arguments.of(null, NEW_DATE, null), + Arguments.of(null, null, RECEIVED_LEASE_ID) + ); + } + + @ParameterizedTest + @MethodSource("invalidModifiedAndLeaseIdSupplier") + public void deleteACFail(OffsetDateTime modified, OffsetDateTime unmodified, String leaseID) { + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(leaseID) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + StepVerifier.create(dataLakeFileSystemAsyncClient.deleteWithResponse(drc)) + .verifyError(DataLakeStorageException.class); + } + + private static Stream invalidModifiedAndLeaseIdSupplier() { + return Stream.of( + // modified | unmodified | leaseID + Arguments.of(NEW_DATE, null, null), + Arguments.of(null, OLD_DATE, null), + Arguments.of(null, null, GARBAGE_LEASE_ID) + ); + } + + @ParameterizedTest + @MethodSource("invalidMatchSupplier") + public void deleteACIllegal(String match, String noneMatch) { + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setIfMatch(match) + .setIfNoneMatch(noneMatch); + + StepVerifier.create((dataLakeFileSystemAsyncClient.deleteWithResponse(drc))) + .verifyError(UnsupportedOperationException.class); + } + + private static Stream invalidMatchSupplier() { + return Stream.of( + // match | noneMatch + Arguments.of(RECEIVED_ETAG, null), + Arguments.of(null, GARBAGE_ETAG) + ); + } + + @Test + public void deleteError() { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + StepVerifier.create(dataLakeFileSystemAsyncClient.delete()) + .verifyError(DataLakeStorageException.class); + } + + @Test + public void deleteIfExists() { + DataLakeFileSystemAsyncClient dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + dataLakeFileSystemAsyncClient.create().block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.deleteIfExistsWithResponse(null)) + .assertNext(r -> { + assertEquals(202, r.getStatusCode()); + assertNotNull(r.getHeaders().getValue(X_MS_REQUEST_ID)); + assertNotNull(r.getHeaders().getValue(X_MS_VERSION)); + assertNotNull(r.getHeaders().getValue(HttpHeaderName.DATE)); + }) + .verifyComplete(); + } + + @Test + public void deleteIfExistsMin() { + DataLakeFileSystemAsyncClient dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + dataLakeFileSystemAsyncClient.create().block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.exists()) + .expectNext(true) + .verifyComplete(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.deleteIfExists()) + .expectNext(true) + .verifyComplete(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getProperties()) + .verifyError(DataLakeStorageException.class); + + StepVerifier.create(dataLakeFileSystemAsyncClient.exists()) + .expectNext(false) + .verifyComplete(); + } + + @Test + public void deleteIfExistsOnFileSystemThatDoesNotExist() { + DataLakeFileSystemAsyncClient dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteIfExistsWithResponse(null), 404); + + StepVerifier.create(dataLakeFileSystemAsyncClient.exists()) + .expectNext(false) + .verifyComplete(); + } + + @ParameterizedTest + @MethodSource("modifiedAndLeaseIdSupplier") + public void deleteIfExistsAC(OffsetDateTime modified, OffsetDateTime unmodified, String leaseID) { + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(setupFileSystemLeaseCondition(dataLakeFileSystemAsyncClient, leaseID)) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteIfExistsWithResponse( + new DataLakePathDeleteOptions().setRequestConditions(drc)), 202); + } + + @ParameterizedTest + @MethodSource("invalidModifiedAndLeaseIdSupplier") + public void deleteIfExistsACFail(OffsetDateTime modified, OffsetDateTime unmodified, String leaseID) { + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(leaseID) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + StepVerifier.create(dataLakeFileSystemAsyncClient.deleteIfExistsWithResponse( + new DataLakePathDeleteOptions().setRequestConditions(drc))) + .verifyError(DataLakeStorageException.class); + } + + @ParameterizedTest + @MethodSource("invalidMatchSupplier") + public void deleteIfExistsACIllegal(String match, String noneMatch) { + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setIfMatch(match) + .setIfNoneMatch(noneMatch); + + StepVerifier.create(dataLakeFileSystemAsyncClient.deleteIfExistsWithResponse(new DataLakePathDeleteOptions() + .setRequestConditions(drc))) + .verifyError(UnsupportedOperationException.class); + } + + @Test + public void createFileMin() { + assertDoesNotThrow(() -> dataLakeFileSystemAsyncClient.createFile(generatePathName()).block()); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void createFileOverwrite(boolean overwrite) { + String pathName = generatePathName(); + dataLakeFileSystemAsyncClient.createFile(pathName).block(); + + if (overwrite) { + assertDoesNotThrow(() -> dataLakeFileSystemAsyncClient.createFile(pathName, true).block()); + } else { + StepVerifier.create(dataLakeFileSystemAsyncClient.createFile(pathName, false)) + .verifyError(DataLakeStorageException.class); + } + } + + @Test + public void createFileDefaults() { + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), null, null, + null, null, null)) + .assertNext(r -> { + assertEquals(201, r.getStatusCode()); + validateBasicHeaders(r.getHeaders()); + }) + .verifyComplete(); + } + + @Test + public void createFileError() { + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileWithResponse( + generatePathName(), null, null, null, null, + new DataLakeRequestConditions().setIfMatch("garbage"))) + .verifyError(DataLakeStorageException.class); + } + + @ParameterizedTest + @MethodSource("cacheAndContentSupplier") + public void createFileHeaders(String cacheControl, String contentDisposition, String contentEncoding, + String contentLanguage, String contentType) { + // Create does not set md5 + PathHttpHeaders headers = new PathHttpHeaders() + .setCacheControl(cacheControl) + .setContentDisposition(contentDisposition) + .setContentEncoding(contentEncoding) + .setContentLanguage(contentLanguage) + .setContentType(contentType); + + // If the value isn't set the service will automatically set it + contentType = (contentType == null) ? "application/octet-stream" : contentType; + String finalContentType = contentType; + + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), + null, null, headers, null, null) + .flatMap(r -> r.getValue().getPropertiesWithResponse(null))) + .assertNext(p -> validatePathProperties(p, cacheControl, contentDisposition, contentEncoding, contentLanguage, + null, finalContentType)) + .verifyComplete(); + } + + private static Stream cacheAndContentSupplier() { + return Stream.of( + // cacheControl | contentDisposition | contentEncoding | contentLanguage | contentType + Arguments.of(null, null, null, null, null), + Arguments.of("control", "disposition", "encoding", "language", "type") + ); + } + + @ParameterizedTest + @CsvSource(value = {"null,null,null,null", "foo,bar,fizz,buzz"}, nullValues = "null") + public void createFileMetadata(String key1, String value1, String key2, String value2) { + Map metadata = new HashMap<>(); + if (key1 != null) { + metadata.put(key1, value1); + } + if (key2 != null) { + metadata.put(key2, value2); + } + + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), null, null, null, + metadata, null) + .flatMap(r -> r.getValue().getProperties())) + .assertNext(p -> assertEquals(metadata, p.getMetadata())) + .verifyComplete(); + } + + @ParameterizedTest + @MethodSource("modifiedMatchAndLeaseIdSupplier") + public void createFileAC(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, + String leaseID) { + String pathName = generatePathName(); + DataLakeFileAsyncClient client = dataLakeFileSystemAsyncClient.getFileAsyncClient(pathName); + client.create().block(); + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(setupPathLeaseCondition(client, leaseID)) + .setIfMatch(setupPathMatchCondition(client, match)) + .setIfNoneMatch(noneMatch) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileWithResponse(pathName, null, null, null, null, drc), 201); + } + + private static Stream modifiedMatchAndLeaseIdSupplier() { + return Stream.of( + // modified | unmodified | match | noneMatch | leaseID + Arguments.of(null, null, null, null, null), + Arguments.of(OLD_DATE, null, null, null, null), + Arguments.of(null, NEW_DATE, null, null, null), + Arguments.of(null, null, RECEIVED_ETAG, null, null), + Arguments.of(null, null, null, GARBAGE_ETAG, null), + Arguments.of(null, null, null, null, RECEIVED_LEASE_ID) + ); + } + + @ParameterizedTest + @MethodSource("invalidModifiedMatchAndLeaseIdSupplier") + public void createFileACFail(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, + String leaseID) { + String pathName = generatePathName(); + DataLakeFileAsyncClient client = dataLakeFileSystemAsyncClient.getFileAsyncClient(pathName); + client.create().block(); + setupPathLeaseCondition(client, leaseID); + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(leaseID) + .setIfMatch(match) + .setIfNoneMatch(setupPathMatchCondition(client, noneMatch)) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileWithResponse(pathName, + null, null, null, null, drc)) + .verifyError(DataLakeStorageException.class); + } + + private static Stream invalidModifiedMatchAndLeaseIdSupplier() { + return Stream.of( + // modified | unmodified | match | noneMatch | leaseID + Arguments.of(NEW_DATE, null, null, null, null), + Arguments.of(null, OLD_DATE, null, null, null), + Arguments.of(null, null, GARBAGE_ETAG, null, null), + Arguments.of(null, null, null, RECEIVED_ETAG, null), + Arguments.of(null, null, null, null, GARBAGE_LEASE_ID) + ); + } + + @Test + public void createFilePermissionsAndUmask() { + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), "0777", "0057", null, + null, null), 201); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createFileOptionsWithACL() { + List pathAccessControlEntries = PathAccessControlEntry.parseList("user::rwx,group::r--,other::---,mask::rwx"); + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setAccessControlList(pathAccessControlEntries); + DataLakeFileAsyncClient client = dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), options).block().getValue(); + + StepVerifier.create(client.getAccessControl()) + .assertNext(r -> { + assertEquals(pathAccessControlEntries.get(0), r.getAccessControlList().get(0)); // testing if owner is set the same + assertEquals(pathAccessControlEntries.get(1), r.getAccessControlList().get(1)); // testing if group is set the same + }) + .verifyComplete(); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createFileOptionsWithOwnerAndGroup() { + String ownerName = testResourceNamer.randomUuid(); + String groupName = testResourceNamer.randomUuid(); + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setOwner(ownerName) + .setGroup(groupName); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getAccessControl())) + .assertNext(acl -> { + assertEquals(ownerName, acl.getOwner()); + assertEquals(groupName, acl.getGroup()); + }) + .verifyComplete(); + } + + @Test + public void createFileOptionsWithNullOwnerAndGroup() { + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), new DataLakePathCreateOptions()) + .flatMap(r -> r.getValue().getAccessControl())) + .assertNext(acl -> { + assertEquals("$superuser", acl.getOwner()); + assertEquals("$superuser", acl.getGroup()); + }) + .verifyComplete(); + } + + @ParameterizedTest + @MethodSource("cacheAndContentWithMd5Supplier") + public void createFileOptionsWithPathHttpHeaders(String cacheControl, String contentDisposition, + String contentEncoding, String contentLanguage, byte[] contentMD5, String contentType) { + PathHttpHeaders putHeaders = new PathHttpHeaders() + .setCacheControl(cacheControl) + .setContentDisposition(contentDisposition) + .setContentEncoding(contentEncoding) + .setContentLanguage(contentLanguage) + .setContentMd5(contentMD5) + .setContentType(contentType); + + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setPathHttpHeaders(putHeaders); + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getPropertiesWithResponse(null))) + .assertNext(p -> validatePathProperties(p, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentMD5, contentType)) + .verifyComplete(); + } + + private static Stream cacheAndContentWithMd5Supplier() { + return Stream.of( + // cacheControl | contentDisposition | contentEncoding | contentLanguage | contentMD5 | contentType + Arguments.of(null, null, null, null, null, "application/octet-stream"), + Arguments.of("control", "disposition", "encoding", "language", null, "type") + ); + } + + @ParameterizedTest + @CsvSource(value = {"null,null,null,null", "foo,bar,fizz,buzz"}, nullValues = "null") + public void createFileOptionsWithMetadata(String key1, String value1, String key2, String value2) { + Map metadata = new HashMap<>(); + if (key1 != null && value1 != null) { + metadata.put(key1, value1); + } + if (key2 != null && value2 != null) { + metadata.put(key2, value2); + } + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setMetadata(metadata); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), options) + .flatMap(r -> { + assertEquals(201, r.getStatusCode()); + return r.getValue().getProperties(); + })) + .assertNext(p -> { + for (String k : metadata.keySet()) { + assertTrue(p.getMetadata().containsKey(k)); + assertEquals(metadata.get(k), p.getMetadata().get(k)); + } + }) + .verifyComplete(); + } + + @Test + public void createFileOptionsWithPermissionsAndUmask() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setPermissions("0777") + .setUmask("0057"); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getAccessControlWithResponse(true, null))) + .assertNext(acl -> assertEquals(PathPermissions.parseSymbolic("rwx-w----").toString(), acl.getValue().getPermissions().toString())) + .verifyComplete(); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createFileOptionsWithLeaseId() { + String leaseId = CoreUtils.randomUuid().toString(); + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setProposedLeaseId(leaseId).setLeaseDuration(15); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), options), 201); + } + + @Test + public void createFileOptionsWithLeaseIdError() { + String leaseId = CoreUtils.randomUuid().toString(); + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setProposedLeaseId(leaseId); + + // lease duration must also be set, or else exception is thrown + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), options)) + .verifyError(DataLakeStorageException.class); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createFileOptionsWithLeaseDuration() { + String leaseId = CoreUtils.randomUuid().toString(); + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setLeaseDuration(15).setProposedLeaseId(leaseId); + String fileName = generatePathName(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileWithResponse(fileName, options), 201); + + + StepVerifier.create(dataLakeFileSystemAsyncClient.getFileAsyncClient(fileName).getProperties()) + .assertNext(p -> { + // assert whether lease has been acquired + assertEquals(LeaseStatusType.LOCKED, p.getLeaseStatus()); + assertEquals(LeaseStateType.LEASED, p.getLeaseState()); + assertEquals(LeaseDurationType.FIXED, p.getLeaseDuration()); + }) + .verifyComplete(); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @ParameterizedTest + @MethodSource("createFileOptionsWithTimeExpiresOnAbsoluteAndNeverExpireSupplier") + public void createFileOptionsWithTimeExpiresOnAbsoluteAndNeverExpire(DataLakePathScheduleDeletionOptions deletionOptions) { + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileWithResponse(generatePathName(), + new DataLakePathCreateOptions().setScheduleDeletionOptions(deletionOptions)), 201); + } + + private static Stream createFileOptionsWithTimeExpiresOnAbsoluteAndNeverExpireSupplier() { + return Stream.of(new DataLakePathScheduleDeletionOptions(OffsetDateTime.now().plusDays(1)), null); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createFileOptionsWithTimeToExpireRelativeToNow() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setScheduleDeletionOptions(new DataLakePathScheduleDeletionOptions(Duration.ofDays(6))); + String fileName = generatePathName(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileWithResponse(fileName, options), 201); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getFileAsyncClient(fileName).getProperties()) + .assertNext(p -> compareDatesWithPrecision(p.getExpiresOn(), p.getCreationTime().plusDays(6))) + .verifyComplete(); + } + + @Test + public void createIfNotExistsFileMin() { + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileIfNotExists(generatePathName()) + .flatMap(r -> r.exists())) + .expectNext(true) + .verifyComplete(); + } + + @Test + public void createIfNotExistsFileOverwrite() { + String pathName = generatePathName(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(pathName, null), 201); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(pathName, null), 409); + } + + @Test + public void createIfNotExistsFileDefaults() { + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), null)) + .assertNext(r -> { + assertEquals(201, r.getStatusCode()); + validateBasicHeaders(r.getHeaders()); + }) + .verifyComplete(); + + } + + @ParameterizedTest + @MethodSource("cacheAndContentSupplier") + public void createIfNotExistsFileHeaders(String cacheControl, String contentDisposition, String contentEncoding, + String contentLanguage, String contentType) { + // Create does not set md5 + PathHttpHeaders headers = new PathHttpHeaders().setCacheControl(cacheControl) + .setContentDisposition(contentDisposition) + .setContentEncoding(contentEncoding) + .setContentLanguage(contentLanguage) + .setContentType(contentType); + + // If the value isn't set the service will automatically set it + contentType = (contentType == null) ? "application/octet-stream" : contentType; + String finalContentType = contentType; + + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), + new DataLakePathCreateOptions().setPathHttpHeaders(headers)) + .flatMap(r -> r.getValue().getPropertiesWithResponse(null))) + .assertNext(p -> validatePathProperties(p, cacheControl, contentDisposition, contentEncoding, contentLanguage, null, finalContentType)) + .verifyComplete(); + } + + @ParameterizedTest + @CsvSource(value = {"null,null,null,null", "foo,bar,fizz,buzz"}, nullValues = "null") + public void createIfNotExistsFileMetadata(String key1, String value1, String key2, String value2) { + Map metadata = new HashMap<>(); + if (key1 != null) { + metadata.put(key1, value1); + } + if (key2 != null) { + metadata.put(key2, value2); + } + + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), + new DataLakePathCreateOptions().setMetadata(metadata)) + .flatMap(r -> r.getValue().getProperties())) + .assertNext(p -> assertEquals(metadata, p.getMetadata())) + .verifyComplete(); + } + + @Test + public void createIfNotExistsFilePermissionsAndUmask() { + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), + new DataLakePathCreateOptions().setUmask("0057").setPermissions("0777")), 201); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createIfNotExistsFileOptionsWithACL() { + List pathAccessControlEntries = PathAccessControlEntry.parseList("user::rwx,group::r--,other::---,mask::rwx"); + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setAccessControlList(pathAccessControlEntries); + DataLakeFileAsyncClient client = dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), options).block().getValue(); + + StepVerifier.create(client.getAccessControl()) + .assertNext(r -> { + assertEquals(pathAccessControlEntries.get(0), r.getAccessControlList().get(0)); // testing if owner is set the same + assertEquals(pathAccessControlEntries.get(1), r.getAccessControlList().get(1)); // testing if group is set the same + }) + .verifyComplete(); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createIfNotExistsFileOptionsWithOwnerAndGroup() { + String ownerName = testResourceNamer.randomUuid(); + String groupName = testResourceNamer.randomUuid(); + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setOwner(ownerName) + .setGroup(groupName); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getAccessControl())) + .assertNext(acl -> { + assertEquals(ownerName, acl.getOwner()); + assertEquals(groupName, acl.getGroup()); + }) + .verifyComplete(); + } + + @Test + public void createIfNotExistsFileOptionsWithNullOwnerAndGroup() { + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), null) + .flatMap(r -> r.getValue().getAccessControl())) + .assertNext(acl -> { + assertEquals("$superuser", acl.getOwner()); + assertEquals("$superuser", acl.getGroup()); + }) + .verifyComplete(); + } + + @ParameterizedTest + @MethodSource("cacheAndContentWithMd5Supplier") + public void createIfNotExistsFileOptionsWithPathHttpHeaders(String cacheControl, String contentDisposition, + String contentEncoding, String contentLanguage, byte[] contentMD5, String contentType) { + PathHttpHeaders putHeaders = new PathHttpHeaders() + .setCacheControl(cacheControl) + .setContentDisposition(contentDisposition) + .setContentEncoding(contentEncoding) + .setContentLanguage(contentLanguage) + .setContentMd5(contentMD5) + .setContentType(contentType); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), + new DataLakePathCreateOptions().setPathHttpHeaders(putHeaders)) + .flatMap(r -> r.getValue().getPropertiesWithResponse(null))) + .assertNext(p -> validatePathProperties(p, cacheControl, contentDisposition, contentEncoding, contentLanguage, contentMD5, contentType)) + .verifyComplete(); + + } + + @ParameterizedTest + @CsvSource(value = {"null,null,null,null", "foo,bar,fizz,buzz"}, nullValues = "null") + public void createIfNotExistsFileOptionsWithMetadata(String key1, String value1, String key2, String value2) { + Map metadata = new HashMap<>(); + if (key1 != null && value1 != null) { + metadata.put(key1, value1); + } + if (key2 != null && value2 != null) { + metadata.put(key2, value2); + } + + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), + new DataLakePathCreateOptions().setMetadata(metadata)) + .flatMap(r -> { + assertEquals(201, r.getStatusCode()); + return r.getValue().getProperties(); + })) + .assertNext(p -> { + // Directory adds a directory metadata value + for (String k : metadata.keySet()) { + assertTrue(p.getMetadata().containsKey(k)); + assertEquals(metadata.get(k), p.getMetadata().get(k)); + } + }) + .verifyComplete(); + } + + @Test + public void createIfNotExistsFileOptionsWithPermissionsAndUmask() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setPermissions("0777").setUmask("0057"); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getAccessControlWithResponse(true, null))) + .assertNext(acl -> assertEquals(PathPermissions.parseSymbolic("rwx-w----").toString(), acl.getValue().getPermissions().toString())) + .verifyComplete(); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createIfNotExistsFileOptionsWithLeaseId() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setProposedLeaseId(CoreUtils.randomUuid().toString()) + .setLeaseDuration(15); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), options), 201); + } + + @Test + public void createIfNotExistsFileOptionsWithLeaseIdError() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setProposedLeaseId(CoreUtils.randomUuid().toString()); + + // lease duration must also be set, or else exception is thrown + StepVerifier.create(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), options)) + .verifyError(DataLakeStorageException.class); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createIfNotExistsFileOptionsWithLeaseDuration() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setLeaseDuration(15) + .setProposedLeaseId(CoreUtils.randomUuid().toString()); + String fileName = generatePathName(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(fileName, options), 201); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getFileAsyncClient(fileName).getProperties()) + .assertNext(p -> { + // assert whether lease has been acquired + assertEquals(LeaseStatusType.LOCKED, p.getLeaseStatus()); + assertEquals(LeaseStateType.LEASED, p.getLeaseState()); + assertEquals(LeaseDurationType.FIXED, p.getLeaseDuration()); + }) + .verifyComplete(); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @ParameterizedTest + @MethodSource("createIfNotExistsFileOptionsWithTimeExpiresOnAbsoluteAndNeverExpireSupplier") + public void createIfNotExistsFileOptionsWithTimeExpiresOnAbsoluteAndNeverExpire(DataLakePathScheduleDeletionOptions deletionOptions) { + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setScheduleDeletionOptions(deletionOptions); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileIfNotExistsWithResponse(generatePathName(), options), 201); + } + + private static Stream createIfNotExistsFileOptionsWithTimeExpiresOnAbsoluteAndNeverExpireSupplier() { + return Stream.of(new DataLakePathScheduleDeletionOptions(OffsetDateTime.now().plusDays(1)), null); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createIfNotExistsFileOptionsWithTimeToExpireRelativeToNow() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setScheduleDeletionOptions(new DataLakePathScheduleDeletionOptions(Duration.ofDays(6))); + String fileName = generatePathName(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createFileWithResponse(fileName, options), 201); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getFileAsyncClient(fileName).getProperties()) + .assertNext(p -> compareDatesWithPrecision(p.getExpiresOn(), p.getCreationTime().plusDays(6))) + .verifyComplete(); + } + + @Test + public void deleteFileMin() { + String pathName = generatePathName(); + dataLakeFileSystemAsyncClient.createFile(pathName).block(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteFileWithResponse(pathName, null), 200); + } + + @Test + public void deleteFileFileDoesNotExistAnymore() { + String pathName = generatePathName(); + DataLakeFileAsyncClient client = dataLakeFileSystemAsyncClient.createFile(pathName).block(); + dataLakeFileSystemAsyncClient.deleteFileWithResponse(pathName, null).block(); + + StepVerifier.create(client.getPropertiesWithResponse(null)) + .verifyErrorSatisfies(r -> { + DataLakeStorageException e = assertInstanceOf(DataLakeStorageException.class, r); + assertEquals(404, e.getStatusCode()); + assertEquals(BlobErrorCode.BLOB_NOT_FOUND.toString(), e.getErrorCode()); + }); + } + + @ParameterizedTest + @MethodSource("modifiedMatchAndLeaseIdSupplier") + public void deleteFileAC(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, + String leaseID) { + String pathName = generatePathName(); + DataLakeFileAsyncClient client = dataLakeFileSystemAsyncClient.createFile(pathName).block(); + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(setupPathLeaseCondition(client, leaseID)) + .setIfMatch(setupPathMatchCondition(client, match)) + .setIfNoneMatch(noneMatch) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteFileWithResponse(pathName, drc), 200); + } + + @ParameterizedTest + @MethodSource("invalidModifiedMatchAndLeaseIdSupplier") + public void deleteFileACFail(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, + String leaseID) { + String pathName = generatePathName(); + DataLakeFileAsyncClient client = dataLakeFileSystemAsyncClient.createFile(pathName).block(); + setupPathLeaseCondition(client, leaseID); + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(leaseID) + .setIfMatch(match) + .setIfNoneMatch(setupPathMatchCondition(client, noneMatch)) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + StepVerifier.create(dataLakeFileSystemAsyncClient.deleteFileWithResponse(pathName, drc)) + .verifyError(DataLakeStorageException.class); + } + + @Test + public void deleteIfExistsFileMin() { + String pathName = generatePathName(); + dataLakeFileSystemAsyncClient.createFile(pathName).block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.deleteFileIfExists(pathName)) + .expectNext(true) + .verifyComplete(); + } + + @Test + public void deleteIfExistsFileNullArgs() { + String pathName = generatePathName(); + dataLakeFileSystemAsyncClient.createFile(pathName).block(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteFileIfExistsWithResponse(pathName, null), 200); + } + + @Test + public void deleteIfExistsFileThatDoesNotExists() { + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteFileIfExistsWithResponse(generatePathName(), null), 404); + } + + @Test + public void deleteIfExistsFileThatWasAlreadyDelete() { + String pathName = generatePathName(); + dataLakeFileSystemAsyncClient.createFile(pathName).block(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteFileIfExistsWithResponse(pathName, null), 200); + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteFileIfExistsWithResponse(pathName, null), 404); + } + + @ParameterizedTest + @MethodSource("modifiedMatchAndLeaseIdSupplier") + public void deleteIfExistsFileAC(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, + String leaseID) { + String pathName = generatePathName(); + DataLakeFileAsyncClient client = dataLakeFileSystemAsyncClient.createFile(pathName).block(); + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(setupPathLeaseCondition(client, leaseID)) + .setIfMatch(setupPathMatchCondition(client, match)) + .setIfNoneMatch(noneMatch) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + DataLakePathDeleteOptions options = new DataLakePathDeleteOptions().setRequestConditions(drc); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteFileIfExistsWithResponse(pathName, options), 200); + } + + @ParameterizedTest + @MethodSource("invalidModifiedMatchAndLeaseIdSupplier") + public void deleteIfExistsFileACFail(OffsetDateTime modified, OffsetDateTime unmodified, String match, + String noneMatch, String leaseID) { + String pathName = generatePathName(); + DataLakeFileAsyncClient client = dataLakeFileSystemAsyncClient.createFile(pathName).block(); + setupPathLeaseCondition(client, leaseID); + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(leaseID) + .setIfMatch(match) + .setIfNoneMatch(setupPathMatchCondition(client, noneMatch)) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + DataLakePathDeleteOptions options = new DataLakePathDeleteOptions().setRequestConditions(drc); + + StepVerifier.create(dataLakeFileSystemAsyncClient.deleteFileIfExistsWithResponse(pathName, options)) + .verifyError(DataLakeStorageException.class); + } + + @Test + public void createDirMin() { + assertDoesNotThrow(() -> dataLakeFileSystemAsyncClient.createDirectory(generatePathName()).block()); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + public void createDirOverwrite(boolean overwrite) { + String pathName = generatePathName(); + dataLakeFileSystemAsyncClient.createDirectory(pathName).block(); + + if (overwrite) { + assertDoesNotThrow(() -> dataLakeFileSystemAsyncClient.createDirectory(pathName, true).block()); + } else { + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectory(pathName, false)) + .verifyError(DataLakeStorageException.class); + } + } + + @Test + public void createDirDefaults() { + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), null, + null, null, null, null)) + .assertNext(r -> { + assertEquals(201, r.getStatusCode()); + validateBasicHeaders(r.getHeaders()); + }) + .verifyComplete(); + } + + @Test + public void createDirError() { + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse( + generatePathName(), null, null, null, null, new DataLakeRequestConditions().setIfMatch("garbage"))) + .verifyError(DataLakeStorageException.class); + } + + @ParameterizedTest + @MethodSource("cacheAndContentSupplier") + public void createDirHeaders(String cacheControl, String contentDisposition, String contentEncoding, + String contentLanguage, String contentType) { + // Create does not set md5 + PathHttpHeaders headers = new PathHttpHeaders().setCacheControl(cacheControl) + .setContentDisposition(contentDisposition) + .setContentEncoding(contentEncoding) + .setContentLanguage(contentLanguage) + .setContentType(contentType); + + // If the value isn't set the service will automatically set it + contentType = (contentType == null) ? "application/octet-stream" : contentType; + String finalContentType = contentType; + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), + null, null, headers, null, null) + .flatMap(r -> r.getValue().getPropertiesWithResponse(null))) + .assertNext(p -> validatePathProperties(p, cacheControl, contentDisposition, contentEncoding, contentLanguage, null, finalContentType)) + .verifyComplete(); + } + + @ParameterizedTest + @CsvSource(value = {"null,null,null,null", "foo,bar,fizz,buzz"}, nullValues = "null") + public void createDirMetadata(String key1, String value1, String key2, String value2) { + Map metadata = new HashMap<>(); + if (key1 != null) { + metadata.put(key1, value1); + } + if (key2 != null) { + metadata.put(key2, value2); + } + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), null, null, + null, metadata, null) + .flatMap(r -> r.getValue().getProperties())) + .assertNext(p -> { + // Directory adds a directory metadata value + for (String k : metadata.keySet()) { + assertTrue(p.getMetadata().containsKey(k)); + assertEquals(metadata.get(k), p.getMetadata().get(k)); + } + }) + .verifyComplete(); + } + + @ParameterizedTest + @MethodSource("modifiedMatchAndLeaseIdSupplier") + public void createDirAC(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, + String leaseID) { + String pathName = generatePathName(); + DataLakeDirectoryAsyncClient client = dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(pathName); + client.create().block(); + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(setupPathLeaseCondition(client, leaseID)) + .setIfMatch(setupPathMatchCondition(client, match)) + .setIfNoneMatch(noneMatch) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(pathName, null, null, null, null, drc), 201); + } + + @ParameterizedTest + @MethodSource("invalidModifiedMatchAndLeaseIdSupplier") + public void createDirACFail(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, + String leaseID) { + String pathName = generatePathName(); + DataLakeDirectoryAsyncClient client = dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(pathName); + client.create().block(); + setupPathLeaseCondition(client, leaseID); + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(leaseID) + .setIfMatch(match) + .setIfNoneMatch(setupPathMatchCondition(client, noneMatch)) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(pathName, null, null, null, null, drc)) + .verifyError(DataLakeStorageException.class); + } + + @Test + public void createDirPermissionsAndUmask() { + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), "0777", "0057", + null, null, null), 201); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createDirOptionsWithACL() { + List pathAccessControlEntries = PathAccessControlEntry.parseList("user::rwx,group::r--,other::---,mask::rwx"); + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setAccessControlList(pathAccessControlEntries); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getAccessControl())) + .assertNext(acl -> { + assertEquals(pathAccessControlEntries.get(0), acl.getAccessControlList().get(0)); // testing if owner is set the same + assertEquals(pathAccessControlEntries.get(1), acl.getAccessControlList().get(1)); // testing if group is set the same + }) + .verifyComplete(); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createDirOptionsWithOwnerAndGroup() { + String ownerName = testResourceNamer.randomUuid(); + String groupName = testResourceNamer.randomUuid(); + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setOwner(ownerName).setGroup(groupName); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getAccessControl())) + .assertNext(acl -> { + assertEquals(ownerName, acl.getOwner()); + assertEquals(groupName, acl.getGroup()); + }) + .verifyComplete(); + } + + @Test + public void createDirOptionsWithNullOwnerAndGroup() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setOwner(null).setGroup(null); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getAccessControl())) + .assertNext(acl -> { + assertEquals("$superuser", acl.getOwner()); + assertEquals("$superuser", acl.getGroup()); + }) + .verifyComplete(); + } + + @ParameterizedTest + @MethodSource("cacheAndContentWithMd5Supplier") + public void createDirOptionsWithPathHttpHeaders(String cacheControl, String contentDisposition, + String contentEncoding, String contentLanguage, byte[] contentMD5, String contentType) { + PathHttpHeaders putHeaders = new PathHttpHeaders() + .setCacheControl(cacheControl) + .setContentDisposition(contentDisposition) + .setContentEncoding(contentEncoding) + .setContentLanguage(contentLanguage) + .setContentMd5(contentMD5) + .setContentType(contentType); + + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setPathHttpHeaders(putHeaders); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getPropertiesWithResponse(null))) + .assertNext(p -> validatePathProperties(p, cacheControl, contentDisposition, + contentEncoding, contentLanguage, contentMD5, contentType)) + .verifyComplete(); + } + + @ParameterizedTest + @CsvSource(value = {"null,null,null,null", "foo,bar,fizz,buzz"}, nullValues = "null") + public void createDirOptionsWithMetadata(String key1, String value1, String key2, String value2) { + Map metadata = new HashMap<>(); + if (key1 != null && value1 != null) { + metadata.put(key1, value1); + } + if (key2 != null && value2 != null) { + metadata.put(key2, value2); + } + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setMetadata(metadata); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), options) + .flatMap(r -> { + assertEquals(201, r.getStatusCode()); + return r.getValue().getProperties(); + })) + .assertNext(p -> { + // Directory adds a directory metadata value + for (String k : metadata.keySet()) { + assertTrue(p.getMetadata().containsKey(k)); + assertEquals(metadata.get(k), p.getMetadata().get(k)); + } + }) + .verifyComplete(); + } + + @Test + public void createDirOptionsWithPermissionsAndUmask() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setPermissions("0777") + .setUmask("0057"); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getAccessControlWithResponse(true, null))) + .assertNext(acl -> assertEquals(PathPermissions.parseSymbolic("rwx-w----").toString(), acl.getValue().getPermissions().toString())) + .verifyComplete(); + } + + @Test + public void createDirOptionsWithLeaseId() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setProposedLeaseId(CoreUtils.randomUuid().toString()) + .setLeaseDuration(15); + + // lease id not supported for directories + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), options)) + .verifyError(IllegalArgumentException.class); + } + + @Test + public void createDirOptionsWithLeaseDuration() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setLeaseDuration(15) + .setProposedLeaseId(CoreUtils.randomUuid().toString()); + + // lease duration not supported for directories + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), options)) + .verifyError(IllegalArgumentException.class); + } + + @Test + public void createDirOptionsWithTimeExpiresOn() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setProposedLeaseId(CoreUtils.randomUuid().toString()) + .setScheduleDeletionOptions(new DataLakePathScheduleDeletionOptions(OffsetDateTime.now().plusDays(1))); + + // expires on not supported for directories + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), options)) + .verifyError(IllegalArgumentException.class); + } + + @Test + public void createDirOptionsWithTimeToExpire() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setScheduleDeletionOptions(new DataLakePathScheduleDeletionOptions(Duration.ofDays(6))); + + // time to expire not supported for directories + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryWithResponse(generatePathName(), options)) + .verifyError(IllegalArgumentException.class); + } + + @Test + public void createIfNotExistsDirMin() { + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExists(generatePathName()) + .flatMap(r -> r.exists())) + .expectNext(true) + .verifyComplete(); + } + + @Test + public void createIfNotExistsDirDefaults() { + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), + null)) + .assertNext(r -> { + assertEquals(201, r.getStatusCode()); + validateBasicHeaders(r.getHeaders()); + }) + .verifyComplete(); + } + + @Test + public void createIfNotExistsDirThatAlreadyExists() { + String dirName = generatePathName(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(dirName, + new DataLakePathCreateOptions()), 201); + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(dirName, + new DataLakePathCreateOptions()), 409); + } + + @ParameterizedTest + @MethodSource("cacheAndContentSupplier") + public void createIfNotExistsDirHeaders(String cacheControl, String contentDisposition, String contentEncoding, + String contentLanguage, String contentType) { + // Create does not set md5 + PathHttpHeaders headers = new PathHttpHeaders().setCacheControl(cacheControl) + .setContentDisposition(contentDisposition) + .setContentEncoding(contentEncoding) + .setContentLanguage(contentLanguage) + .setContentType(contentType); + + // If the value isn't set the service will automatically set it + contentType = (contentType == null) ? "application/octet-stream" : contentType; + String finalContentType = contentType; + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), + new DataLakePathCreateOptions().setPathHttpHeaders(headers)) + .flatMap(r -> r.getValue().getPropertiesWithResponse(null))) + .assertNext(p -> validatePathProperties(p, cacheControl, contentDisposition, contentEncoding, contentLanguage, null, finalContentType)) + .verifyComplete(); + } + + @ParameterizedTest + @CsvSource(value = {"null,null,null,null", "foo,bar,fizz,buzz"}, nullValues = "null") + public void createIfNotExistsDirMetadata(String key1, String value1, String key2, String value2) { + Map metadata = new HashMap<>(); + if (key1 != null) { + metadata.put(key1, value1); + } + if (key2 != null) { + metadata.put(key2, value2); + } + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), + new DataLakePathCreateOptions().setMetadata(metadata)) + .flatMap(r -> r.getValue().getProperties())) + .assertNext(p -> { + // Directory adds a directory metadata value + for (String k : metadata.keySet()) { + assertTrue(p.getMetadata().containsKey(k)); + assertEquals(metadata.get(k), p.getMetadata().get(k)); + } + }) + .verifyComplete(); + } + + @Test + public void createIfNotExistsDirPermissionsAndUmask() { + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), + new DataLakePathCreateOptions().setPermissions("0777").setUmask("0057")), 201); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createIfNotExistsDirOptionsWithACL() { + List pathAccessControlEntries = PathAccessControlEntry.parseList("user::rwx,group::r--,other::---,mask::rwx"); + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setAccessControlList(pathAccessControlEntries); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getAccessControl())) + .assertNext(acl -> { + assertEquals(pathAccessControlEntries.get(0), acl.getAccessControlList().get(0)); // testing if owner is set the same + assertEquals(pathAccessControlEntries.get(1), acl.getAccessControlList().get(1)); // testing if group is set the same + }) + .verifyComplete(); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20210608ServiceVersion") + @Test + public void createIfNotExistsDirOptionsWithOwnerAndGroup() { + String ownerName = testResourceNamer.randomUuid(); + String groupName = testResourceNamer.randomUuid(); + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setOwner(ownerName) + .setGroup(groupName); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getAccessControl())) + .assertNext(acl -> { + assertEquals(ownerName, acl.getOwner()); + assertEquals(groupName, acl.getGroup()); + }) + .verifyComplete(); + } + + @Test + public void createIfNotExistsDirOptionsWithNullOwnerAndGroup() { + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), null) + .flatMap(r -> r.getValue().getAccessControl())) + .assertNext(acl -> { + assertEquals("$superuser", acl.getOwner()); + assertEquals("$superuser", acl.getGroup()); + }) + .verifyComplete(); + } + + @ParameterizedTest + @MethodSource("cacheAndContentWithMd5Supplier") + public void createIfNotExistsDirOptionsWithPathHttpHeaders(String cacheControl, String contentDisposition, + String contentEncoding, String contentLanguage, byte[] contentMD5, String contentType) { + PathHttpHeaders putHeaders = new PathHttpHeaders() + .setCacheControl(cacheControl) + .setContentDisposition(contentDisposition) + .setContentEncoding(contentEncoding) + .setContentLanguage(contentLanguage) + .setContentMd5(contentMD5) + .setContentType(contentType); + + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setPathHttpHeaders(putHeaders); + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getPropertiesWithResponse(null))) + .assertNext(p -> validatePathProperties(p, cacheControl, contentDisposition, + contentEncoding, contentLanguage, contentMD5, contentType)) + .verifyComplete(); + } + + @ParameterizedTest + @CsvSource(value = {"null,null,null,null", "foo,bar,fizz,buzz"}, nullValues = "null") + public void createIfNotExistsDirOptionsWithMetadata(String key1, String value1, String key2, String value2) { + Map metadata = new HashMap<>(); + if (key1 != null && value1 != null) { + metadata.put(key1, value1); + } + if (key2 != null && value2 != null) { + metadata.put(key2, value2); + } + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setMetadata(metadata); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), options) + .flatMap(r -> { + assertEquals(201, r.getStatusCode()); + return r.getValue().getProperties(); + })) + .assertNext(p -> { + // Directory adds a directory metadata value + for (String k : metadata.keySet()) { + assertTrue(p.getMetadata().containsKey(k)); + assertEquals(metadata.get(k), p.getMetadata().get(k)); + } + }) + .verifyComplete(); + } + + @Test + public void createIfNotExistsDirOptionsWithPermissionsAndUmask() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setPermissions("0777") + .setUmask("0057"); + + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), options) + .flatMap(r -> r.getValue().getAccessControlWithResponse(true, null))) + .assertNext(acl -> assertEquals(PathPermissions.parseSymbolic("rwx-w----").toString(), acl.getValue().getPermissions().toString())) + .verifyComplete(); + } + + @Test + public void createIfNotExistsDirOptionsWithLeaseId() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setProposedLeaseId(CoreUtils.randomUuid().toString()) + .setLeaseDuration(15); + + // assert lease id not supported for directory + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), options)) + .verifyError(IllegalArgumentException.class); + } + + @Test + public void createIfNotExistsDirOptionsWithLeaseIdError() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setProposedLeaseId(CoreUtils.randomUuid().toString()); + + // assert lease duration not supported for directory + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), options)) + .verifyError(IllegalArgumentException.class); + } + + @Test + public void createIfNotExistsDirOptionsWithLeaseDuration() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions().setLeaseDuration(15) + .setProposedLeaseId(CoreUtils.randomUuid().toString()); + + // assert expires on not supported for directory + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), options)) + .verifyError(IllegalArgumentException.class); + } + + @Test + public void createIfNotExistsDirOptionsWithTimeExpiresOnAbsolute() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setScheduleDeletionOptions(new DataLakePathScheduleDeletionOptions(OffsetDateTime.now().plusDays(1))); + + // assert expires on not supported for directory + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), options)) + .verifyError(IllegalArgumentException.class); + } + + @Test + public void createIfNotExistsDirOptionsWithTimeToExpireRelativeToNow() { + DataLakePathCreateOptions options = new DataLakePathCreateOptions() + .setScheduleDeletionOptions(new DataLakePathScheduleDeletionOptions(Duration.ofDays(6))); + + // assert time to expire not supported for directory + StepVerifier.create(dataLakeFileSystemAsyncClient.createDirectoryIfNotExistsWithResponse(generatePathName(), options)) + .verifyError(IllegalArgumentException.class); + } + + @Test + public void deleteDirMin() { + String pathName = generatePathName(); + dataLakeFileSystemAsyncClient.createDirectory(pathName).block(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteDirectoryWithResponse(pathName, false, null), 200); + } + + @Test + public void deleteDirRecursive() { + String pathName = generatePathName(); + dataLakeFileSystemAsyncClient.createDirectory(pathName).block(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteDirectoryWithResponse(pathName, true, null), 200); + } + + @Test + public void deleteDirDirDoesNotExistAnymore() { + String pathName = generatePathName(); + DataLakeDirectoryAsyncClient client = dataLakeFileSystemAsyncClient.createDirectory(pathName).block(); + dataLakeFileSystemAsyncClient.deleteDirectoryWithResponse(pathName, false, null).block(); + + StepVerifier.create(client.getPropertiesWithResponse(null)) + .verifyErrorSatisfies(r -> { + DataLakeStorageException e = assertInstanceOf(DataLakeStorageException.class, r); + assertEquals(404, e.getResponse().getStatusCode()); + assertEquals(BlobErrorCode.BLOB_NOT_FOUND.toString(), e.getErrorCode()); + }); + } + + @ParameterizedTest + @MethodSource("modifiedMatchAndLeaseIdSupplier") + public void deleteDirAC(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, + String leaseID) { + String pathName = generatePathName(); + DataLakeDirectoryAsyncClient client = dataLakeFileSystemAsyncClient.createDirectory(pathName).block(); + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(setupPathLeaseCondition(client, leaseID)) + .setIfMatch(setupPathMatchCondition(client, match)) + .setIfNoneMatch(noneMatch) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteDirectoryWithResponse(pathName, false, drc), 200); + } + + @ParameterizedTest + @MethodSource("invalidModifiedMatchAndLeaseIdSupplier") + public void deleteDirACFail(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, + String leaseID) { + String pathName = generatePathName(); + DataLakeDirectoryAsyncClient client = dataLakeFileSystemAsyncClient.createDirectory(pathName).block(); + setupPathLeaseCondition(client, leaseID); + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(leaseID) + .setIfMatch(match) + .setIfNoneMatch(setupPathMatchCondition(client, noneMatch)) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + StepVerifier.create(dataLakeFileSystemAsyncClient.deleteDirectoryWithResponse(pathName, false, drc)) + .verifyError(DataLakeStorageException.class); + } + + @Test + public void deleteIfExistsDirMin() { + String pathName = generatePathName(); + dataLakeFileSystemAsyncClient.createDirectory(pathName).block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.deleteDirectoryIfExists(pathName)) + .expectNext(true) + .verifyComplete(); + } + + @Test + public void deleteIfExistsDirNullArgs() { + String pathName = generatePathName(); + dataLakeFileSystemAsyncClient.createDirectory(pathName).block(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteDirectoryIfExistsWithResponse(pathName, null), 200); + } + + @Test + public void deleteIfExistsDirRecursive() { + String pathName = generatePathName(); + dataLakeFileSystemAsyncClient.createDirectory(pathName).block(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteDirectoryIfExistsWithResponse(pathName, + new DataLakePathDeleteOptions().setIsRecursive(true)), 200); + } + + @Test + public void deleteIfExistsDirThatDoesNotExist() { + String pathName = generatePathName(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteDirectoryIfExistsWithResponse(pathName, null), 404); + StepVerifier.create(dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(pathName).exists()) + .expectNext(false) + .verifyComplete(); + } + + @Test + public void deleteIfExistsDirThatWasAlreadyDeleted() { + String pathName = generatePathName(); + dataLakeFileSystemAsyncClient.createDirectory(pathName).block(); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteDirectoryIfExistsWithResponse(pathName, null), 200); + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteDirectoryIfExistsWithResponse(pathName, null), 404); + } + + @ParameterizedTest + @MethodSource("modifiedMatchAndLeaseIdSupplier") + public void deleteIfExistsDirAC(OffsetDateTime modified, OffsetDateTime unmodified, String match, String noneMatch, + String leaseID) { + String pathName = generatePathName(); + DataLakeDirectoryAsyncClient client = dataLakeFileSystemAsyncClient.createDirectory(pathName).block(); + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(setupPathLeaseCondition(client, leaseID)) + .setIfMatch(setupPathMatchCondition(client, match)) + .setIfNoneMatch(noneMatch) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + DataLakePathDeleteOptions options = new DataLakePathDeleteOptions().setRequestConditions(drc).setIsRecursive(false); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.deleteDirectoryIfExistsWithResponse(pathName, options), 200); + } + + @ParameterizedTest + @MethodSource("invalidModifiedMatchAndLeaseIdSupplier") + public void deleteIfExistsDirACFail(OffsetDateTime modified, OffsetDateTime unmodified, String match, + String noneMatch, String leaseID) { + String pathName = generatePathName(); + DataLakeDirectoryAsyncClient client = dataLakeFileSystemAsyncClient.createDirectory(pathName).block(); + setupPathLeaseCondition(client, leaseID); + DataLakeRequestConditions drc = new DataLakeRequestConditions() + .setLeaseId(leaseID) + .setIfMatch(match) + .setIfNoneMatch(setupPathMatchCondition(client, noneMatch)) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + DataLakePathDeleteOptions options = new DataLakePathDeleteOptions().setRequestConditions(drc).setIsRecursive(false); + + StepVerifier.create(dataLakeFileSystemAsyncClient.deleteDirectoryIfExistsWithResponse(pathName, options)) + .verifyError(DataLakeStorageException.class); + } + + @Test + public void listPaths() { + String dirName = generatePathName(); + dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(dirName).create().block(); + + String fileName = generatePathName(); + dataLakeFileSystemAsyncClient.getFileAsyncClient(fileName).create().block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.listPaths()) + .assertNext(r -> { + assertEquals(dirName, r.getName()); + assertNotNull(r.getETag()); + assertNotNull(r.getGroup()); + assertNotNull(r.getLastModified()); + assertNotNull(r.getOwner()); + assertNotNull(r.getPermissions()); + //assertNotNull(dirPath.getContentLength()); // known issue with service + assertTrue(r.isDirectory()); + }) + .assertNext(r -> { + assertEquals(fileName, r.getName()); + assertNotNull(r.getETag()); + assertNotNull(r.getGroup()); + assertNotNull(r.getLastModified()); + assertNotNull(r.getOwner()); + assertNotNull(r.getPermissions()); + //assertNotNull(filePath.getContentLength()); // known issue with service + assertFalse(r.isDirectory()); + }) + .verifyComplete(); + } + + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") + @Test + public void listPathsExpiryAndCreation() { + String dirName = generatePathName(); + dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(dirName).create().block(); + + String fileName = generatePathName(); + DataLakeFileAsyncClient fileClient = dataLakeFileSystemAsyncClient.getFileAsyncClient(fileName); + fileClient.create().block(); + fileClient.scheduleDeletion(new FileScheduleDeletionOptions(OffsetDateTime.now().plusDays(2))).block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.listPaths()) + .assertNext(r -> { + assertEquals(dirName, r.getName()); + assertNotNull(r.getCreationTime()); + assertNull(r.getExpiryTime()); + }) + .assertNext(r -> { + assertEquals(fileName, r.getName()); + assertNotNull(r.getExpiryTime()); + assertNotNull(r.getCreationTime()); + }) + .verifyComplete(); + } + + @Test + public void listPathsRecursive() { + dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(generatePathName()).create().block(); + dataLakeFileSystemAsyncClient.getFileAsyncClient(generatePathName()).create().block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.listPaths(new ListPathsOptions().setRecursive(true))) + .expectNextCount(2) + .verifyComplete(); + } + + @Test + public void listPathsReturnUpn() { + dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(generatePathName()).create().block(); + dataLakeFileSystemAsyncClient.getFileAsyncClient(generatePathName()).create().block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.listPaths(new ListPathsOptions().setUserPrincipalNameReturned(true))) + .expectNextCount(2) + .verifyComplete(); + } + + @Test + public void listPathsMaxResults() { + dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(generatePathName()).create().block(); + dataLakeFileSystemAsyncClient.getFileAsyncClient(generatePathName()).create().block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.listPaths(new ListPathsOptions().setMaxResults(1))) + .expectNextCount(2) + .verifyComplete(); + } + + @Test + public void listPathsEncryptionScope() { + FileSystemEncryptionScopeOptions encryptionScope = new FileSystemEncryptionScopeOptions() + .setDefaultEncryptionScope(ENCRYPTION_SCOPE_STRING) + .setEncryptionScopeOverridePrevented(true); + + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + DataLakeFileSystemAsyncClient client = getFileSystemClientBuilder(dataLakeFileSystemAsyncClient.getFileSystemUrl()) + .credential(getDataLakeCredential()) + .fileSystemEncryptionScopeOptions(encryptionScope) + .buildAsyncClient(); + client.create().block(); + + String dirName = generatePathName(); + client.getDirectoryAsyncClient(dirName).create().block(); + + String fileName = generatePathName(); + dataLakeFileSystemAsyncClient.getFileAsyncClient(fileName).create().block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.listPaths()) + .assertNext(r -> { + assertEquals(dirName, r.getName()); + assertNotNull(r.getETag()); + assertNotNull(r.getGroup()); + assertNotNull(r.getLastModified()); + assertNotNull(r.getOwner()); + assertNotNull(r.getPermissions()); + assertTrue(r.isDirectory()); + assertEquals(ENCRYPTION_SCOPE_STRING, r.getEncryptionScope()); + }) + .assertNext(r -> { + assertEquals(fileName, r.getName()); + assertNotNull(r.getETag()); + assertNotNull(r.getGroup()); + assertNotNull(r.getLastModified()); + assertNotNull(r.getOwner()); + assertNotNull(r.getPermissions()); + assertEquals(ENCRYPTION_SCOPE_STRING, r.getEncryptionScope()); + assertFalse(r.isDirectory()); + }) + .verifyComplete(); + } + + @Test + public void asyncListPathsMaxResultsByPage() { + dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(generatePathName()).create().block(); + dataLakeFileSystemAsyncClient.getFileAsyncClient(generatePathName()).create().block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.listPaths(new ListPathsOptions()).byPage(1)) + .thenConsumeWhile(page -> { + assertEquals(1, page.getValue().size()); + return true; + }) + .verifyComplete(); + } + + @ParameterizedTest + @ValueSource(strings = {"%E4%B8%AD%E6%96%87", "az%5B%5D", "hello%20world", "hello%26world", + "%21%2A%27%28%29%3B%3A%40%26%3D%2B%24%2C%3F%23%5B%5D"}) + public void createUrlSpecialCharsEncoded(String name) { + // Note you cannot use the / character in a path in datalake unless it is to specify an absolute path + // This test checks that we handle path names with encoded special characters correctly. + + DataLakeFileAsyncClient fc1 = dataLakeFileSystemAsyncClient.getFileAsyncClient(name + "file1"); + DataLakeFileAsyncClient fc2 = dataLakeFileSystemAsyncClient.getFileAsyncClient(name + "file2"); + DataLakeDirectoryAsyncClient dc1 = dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(name + "dir1"); + DataLakeDirectoryAsyncClient dc2 = dataLakeFileSystemAsyncClient.getDirectoryAsyncClient(name + "dir2"); + + assertAsyncResponseStatusCode(fc1.createWithResponse(null, null, null, null, null), 201); + fc2.create().block(); + assertAsyncResponseStatusCode(fc2.getPropertiesWithResponse(null), 200); + assertAsyncResponseStatusCode(fc2.appendWithResponse(DATA.getDefaultBinaryData(), 0, null, null), 202); + assertAsyncResponseStatusCode(dc1.createWithResponse(null, null, null, null, null), 201); + dc2.create().block(); + assertAsyncResponseStatusCode(dc2.getPropertiesWithResponse(null), 200); + + StepVerifier.create(dataLakeFileSystemAsyncClient.listPaths()) + .assertNext(r -> assertEquals(Utility.urlDecode(name) + "dir1", r.getName())) + .assertNext(r -> assertEquals(Utility.urlDecode(name) + "dir2", r.getName())) + .assertNext(r -> assertEquals(Utility.urlDecode(name) + "file1", r.getName())) + .assertNext(r -> assertEquals(Utility.urlDecode(name) + "file2", r.getName())) + .verifyComplete(); + } + + @ParameterizedTest + @MethodSource("publicAccessSupplier") + public void setAccessPolicy(PublicAccessType access) { + StepVerifier.create(dataLakeFileSystemAsyncClient.setAccessPolicyWithResponse(access, null, null)) + .assertNext(r -> validateBasicHeaders(r.getHeaders())) + .verifyComplete(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getProperties()) + .assertNext(r -> assertEquals(access, r.getDataLakePublicAccess())) + .verifyComplete(); + } + + @Test + public void setAccessPolicyMinAccess() { + dataLakeFileSystemAsyncClient.setAccessPolicy(PublicAccessType.CONTAINER, null).block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getProperties()) + .assertNext(r -> assertEquals(PublicAccessType.CONTAINER, r.getDataLakePublicAccess())) + .verifyComplete(); + } + + @Test + public void setAccessPolicyMinIds() { + DataLakeSignedIdentifier identifier = new DataLakeSignedIdentifier() + .setId("0000") + .setAccessPolicy(new DataLakeAccessPolicy() + .setStartsOn(OffsetDateTime.now().atZoneSameInstant(ZoneId.of("UTC")).toOffsetDateTime()) + .setExpiresOn(OffsetDateTime.now().atZoneSameInstant(ZoneId.of("UTC")).toOffsetDateTime() + .plusDays(1)) + .setPermissions("r")); + + dataLakeFileSystemAsyncClient.setAccessPolicy(null, Collections.singletonList(identifier)).block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getAccessPolicy()) + .assertNext(r -> assertEquals(identifier.getId(), r.getIdentifiers().get(0).getId())) + .verifyComplete(); + } + + @Test + public void setAccessPolicyIds() { + DataLakeSignedIdentifier identifier = new DataLakeSignedIdentifier() + .setId("0000") + .setAccessPolicy(new DataLakeAccessPolicy() + .setStartsOn(testResourceNamer.now()) + .setExpiresOn(testResourceNamer.now().plusDays(1)) + .setPermissions("r")); + DataLakeSignedIdentifier identifier2 = new DataLakeSignedIdentifier() + .setId("0001") + .setAccessPolicy(new DataLakeAccessPolicy() + .setStartsOn(testResourceNamer.now()) + .setExpiresOn(testResourceNamer.now().plusDays(2)) + .setPermissions("w")); + + StepVerifier.create(dataLakeFileSystemAsyncClient.setAccessPolicyWithResponse(null, + Arrays.asList(identifier, identifier2), null)) + .assertNext(r -> { + assertEquals(200, r.getStatusCode()); + validateBasicHeaders(r.getHeaders()); + }) + .verifyComplete(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getAccessPolicyWithResponse(null)) + .assertNext(r -> { + assertEquals(identifier.getAccessPolicy().getExpiresOn().truncatedTo(ChronoUnit.SECONDS), + r.getValue().getIdentifiers().get(0).getAccessPolicy().getExpiresOn()); + assertEquals(identifier.getAccessPolicy().getStartsOn().truncatedTo(ChronoUnit.SECONDS), + r.getValue().getIdentifiers().get(0).getAccessPolicy().getStartsOn()); + assertEquals(identifier.getAccessPolicy().getPermissions(), + r.getValue().getIdentifiers().get(0).getAccessPolicy().getPermissions()); + assertEquals(identifier2.getAccessPolicy().getExpiresOn().truncatedTo(ChronoUnit.SECONDS), + r.getValue().getIdentifiers().get(1).getAccessPolicy().getExpiresOn()); + assertEquals(identifier2.getAccessPolicy().getStartsOn().truncatedTo(ChronoUnit.SECONDS), + r.getValue().getIdentifiers().get(1).getAccessPolicy().getStartsOn()); + assertEquals(identifier2.getAccessPolicy().getPermissions(), + r.getValue().getIdentifiers().get(1).getAccessPolicy().getPermissions()); + }) + .verifyComplete(); + } + + @ParameterizedTest + @MethodSource("modifiedAndLeaseIdSupplier") + public void setAccessPolicyAC(OffsetDateTime modified, OffsetDateTime unmodified, String leaseID) { + DataLakeRequestConditions cac = new DataLakeRequestConditions() + .setLeaseId(setupFileSystemLeaseCondition(dataLakeFileSystemAsyncClient, leaseID)) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.setAccessPolicyWithResponse(null, null, cac), 200); + } + + @ParameterizedTest + @MethodSource("invalidModifiedAndLeaseIdSupplier") + public void setAccessPolicyACFail(OffsetDateTime modified, OffsetDateTime unmodified, String leaseID) { + DataLakeRequestConditions cac = new DataLakeRequestConditions() + .setLeaseId(leaseID) + .setIfModifiedSince(modified) + .setIfUnmodifiedSince(unmodified); + + StepVerifier.create(dataLakeFileSystemAsyncClient.setAccessPolicyWithResponse(null, null, cac)) + .verifyError(DataLakeStorageException.class); + } + + @ParameterizedTest + @MethodSource("invalidMatchSupplier") + public void setAccessPolicyACIllegal(String match, String noneMatch) { + DataLakeRequestConditions mac = new DataLakeRequestConditions().setIfMatch(match).setIfNoneMatch(noneMatch); + + StepVerifier.create(dataLakeFileSystemAsyncClient.setAccessPolicyWithResponse(null, null, mac)) + .verifyError(UnsupportedOperationException.class); + } + + @Test + public void setAccessPolicyError() { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + StepVerifier.create(dataLakeFileSystemAsyncClient.setAccessPolicy(null, null)) + .verifyError(DataLakeStorageException.class); + } + + @Test + public void getAccessPolicy() { + DataLakeSignedIdentifier identifier = new DataLakeSignedIdentifier() + .setId("0000") + .setAccessPolicy(new DataLakeAccessPolicy() + .setStartsOn(testResourceNamer.now()) + .setExpiresOn(testResourceNamer.now().plusDays(1)) + .setPermissions("r")); + dataLakeFileSystemAsyncClient.setAccessPolicy(PublicAccessType.BLOB, Collections.singletonList(identifier)).block(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getAccessPolicyWithResponse(null)) + .assertNext(r -> { + assertEquals(200, r.getStatusCode()); + assertEquals(PublicAccessType.BLOB, r.getValue().getDataLakeAccessType()); + validateBasicHeaders(r.getHeaders()); + assertEquals(identifier.getAccessPolicy().getExpiresOn().truncatedTo(ChronoUnit.SECONDS), + r.getValue().getIdentifiers().get(0).getAccessPolicy().getExpiresOn()); + assertEquals(identifier.getAccessPolicy().getStartsOn().truncatedTo(ChronoUnit.SECONDS), + r.getValue().getIdentifiers().get(0).getAccessPolicy().getStartsOn()); + assertEquals(identifier.getAccessPolicy().getPermissions(), + r.getValue().getIdentifiers().get(0).getAccessPolicy().getPermissions()); + }) + .verifyComplete(); + } + + @Test + public void getAccessPolicyLease() { + String leaseID = setupFileSystemLeaseCondition(dataLakeFileSystemAsyncClient, RECEIVED_LEASE_ID); + + assertAsyncResponseStatusCode(dataLakeFileSystemAsyncClient.getAccessPolicyWithResponse(leaseID), 200); + } + + @Test + public void getAccessPolicyLeaseFail() { + StepVerifier.create(dataLakeFileSystemAsyncClient.getAccessPolicyWithResponse(GARBAGE_LEASE_ID)) + .verifyError(DataLakeStorageException.class); + } + + @Test + public void getAccessPolicyError() { + dataLakeFileSystemAsyncClient = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getAccessPolicy()) + .verifyError(DataLakeStorageException.class); + } + + @Test + public void builderBearerTokenValidation() { + // Technically no additional checks need to be added to datalake builder since the corresponding blob builder fails + String endpoint = BlobUrlParts.parse(dataLakeFileSystemAsyncClient.getFileSystemUrl()).setScheme("http").toUrl() + .toString(); + + assertThrows(IllegalArgumentException.class, () -> new DataLakeFileSystemClientBuilder() + .credential(new DefaultAzureCredentialBuilder().build()) + .endpoint(endpoint) + .buildAsyncClient()); + } + + @Test + public void listPathsOAuth() { + DataLakeFileSystemAsyncClient fsClient = getOAuthServiceAsyncClient() + .getFileSystemAsyncClient(dataLakeFileSystemAsyncClient.getFileSystemName()); + fsClient.createFile(generatePathName()).block(); + + StepVerifier.create(fsClient.listPaths()) + .thenConsumeWhile(p -> { + assertNotNull(p); + return true; + }) + .verifyComplete(); + } + + @Test + public void setACLRootDirectory() { + DataLakeDirectoryAsyncClient dc = dataLakeFileSystemAsyncClient.getRootDirectoryAsyncClient(); + List pathAccessControlEntries = PathAccessControlEntry.parseList("user::rwx,group::r--,other::---,mask::rwx"); + + StepVerifier.create(dc.setAccessControlList(pathAccessControlEntries, null, null)) + .assertNext(r -> { + assertNotNull(r.getETag()); + assertNotNull(r.getLastModified()); + }) + .verifyComplete(); + } + + // This tests the policy is in the right place because if it were added per retry, it would be after the credentials + // and auth would fail because we changed a signed header. + @Test + public void perCallPolicy() { + DataLakeFileSystemAsyncClient dataLakeFileSystemAsyncClient = getFileSystemClientBuilder(getFileSystemUrl()) + .addPolicy(getPerCallVersionPolicy()).credential(getDataLakeCredential()).buildAsyncClient(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getPropertiesWithResponse(null)) + .assertNext(r -> assertEquals("2019-02-02", r.getHeaders().getValue(X_MS_VERSION))) + .verifyComplete(); + + StepVerifier.create(dataLakeFileSystemAsyncClient.getAccessPolicyWithResponse(null)) + .assertNext(r -> assertEquals("2019-02-02", r.getHeaders().getValue(X_MS_VERSION))) + .verifyComplete(); + } +} diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/SasTests.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/SasTests.java index a7a37f8573d92..f76ef89d3bb0d 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/SasTests.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/SasTests.java @@ -118,7 +118,7 @@ public void fileSasPermission() { assertEquals(DATA.getDefaultText(), os.toString()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void directorySasPermission() { String pathName = generatePathName(); @@ -145,7 +145,7 @@ public void directorySasPermission() { assertDoesNotThrow(() -> client.createSubdirectory(generatePathName())); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void directorySasPermissionFail() { String pathName = generatePathName(); @@ -235,7 +235,7 @@ public void fileUserDelegation() { assertEquals(DATA.getDefaultText(), os.toString()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void directoryUserDelegation() { String pathName = generatePathName(); @@ -299,7 +299,7 @@ public void fileSystemUserDelegation() { assertDoesNotThrow(() -> client.listPaths().iterator().hasNext()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void fileUserDelegationSAOID() { String saoid = testResourceNamer.randomUuid(); @@ -346,7 +346,7 @@ public void fileUserDelegationSAOID() { assertEquals(saoid, accessControl.getOwner()); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void fileUserDelegationSUOID() { String suoid = testResourceNamer.randomUuid(); @@ -431,7 +431,7 @@ public void fileSystemUserDelegationCorrelationId() { assertTrue(sasWithPermissions.contains("scid=" + cid)); } - @DisabledIf("olderThan20200210ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200210ServiceVersion") @Test public void fileSystemUserDelegationCorrelationIdError() { FileSystemSasPermission permissions = new FileSystemSasPermission().setListPermission(true); @@ -545,7 +545,7 @@ public void accountSasTokenOnEndpoint() { values are handled correctly. We will validate the whole SAS with service calls as well as correct serialization of individual parts later. */ - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @ParameterizedTest @MethodSource("sasImplUtilStringToSignSupplier") public void sasImplUtilStringToSign(OffsetDateTime startTime, String identifier, SasIpRange ipRange, @@ -597,7 +597,7 @@ private static Stream sasImplUtilStringToSignSupplier() { ); } - @DisabledIf("olderThan20201206ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201206ServiceVersion") @ParameterizedTest @MethodSource("sasImplUtilStringToSignUserDelegationKeySupplier") public void sasImplUtilStringToSignUserDelegationKey(OffsetDateTime startTime, String keyOid, String keyTid, @@ -752,11 +752,4 @@ public void canUseSasToAuthenticate() { .getProperties()); } - private static boolean olderThan20200210ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_02_10); - } - - private static boolean olderThan20201206ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_12_06); - } } diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/ServiceApiTests.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/ServiceApiTests.java index 3afad15711216..f7b935f8c2eb8 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/ServiceApiTests.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/ServiceApiTests.java @@ -208,7 +208,7 @@ public void setPropsCorsCheck() { assertEquals(202, primaryDataLakeServiceClient.setPropertiesWithResponse(serviceProperties, null, null).getStatusCode()); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @ResourceLock("ServiceProperties") @Test public void setPropsStaticWebsite() { @@ -382,7 +382,7 @@ public void listFileSystemsWithTimeoutStillBackedByPagedFlux() { } @ResourceLock("ServiceProperties") - @DisabledIf("olderThan20201002ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20201002ServiceVersion") @Test public void listSystemFileSystems() { DataLakeAnalyticsLogging logging = new DataLakeAnalyticsLogging().setRead(true).setVersion("1.0") @@ -503,7 +503,7 @@ public void perCallPolicy() { assertEquals("2019-02-02", response.getHeaders().getValue(X_MS_VERSION)); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void restoreFileSystem() { DataLakeFileSystemClient cc1 = primaryDataLakeServiceClient.getFileSystemClient(generateFileSystemName()); @@ -556,7 +556,7 @@ public void restoreFileSystem() { // assertEquals(blobName, pathItems.get(0).getName()); // } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void restoreFileSystemWithResponse() { DataLakeFileSystemClient cc1 = primaryDataLakeServiceClient.getFileSystemClient(generateFileSystemName()); @@ -582,7 +582,7 @@ public void restoreFileSystemWithResponse() { assertEquals(blobName, pathItems.get(0).getName()); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void restoreFileSystemAsync() { DataLakeFileSystemAsyncClient cc1 = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); @@ -607,7 +607,7 @@ public void restoreFileSystemAsync() { .verifyComplete(); } - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void restoreFileSystemAsyncWithResponse() { DataLakeFileSystemAsyncClient cc1 = primaryDataLakeServiceAsyncClient.getFileSystemAsyncClient(generateFileSystemName()); @@ -640,7 +640,7 @@ public void restoreFileSystemError() { } @SuppressWarnings("deprecation") - @DisabledIf("olderThan20191212ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20191212ServiceVersion") @Test public void restoreFileSystemIntoExistingFileSystemError() { DataLakeFileSystemClient cc1 = primaryDataLakeServiceClient.getFileSystemClient(generateFileSystemName()); @@ -773,14 +773,6 @@ public void setConnectionStringWithSasOnServiceClientBuilder() { // primaryDataLakeServiceClient.renameFileSystem(generateFileSystemName(), generateFileSystemName())); // } - private static boolean olderThan20191212ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2019_12_12); - } - - private static boolean olderThan20201002ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_10_02); - } - private static T waitUntilFileSystemIsDeleted( Callable waitUntilOperation) { for (int i = 0; i < 30; i++) { diff --git a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/SoftDeleteTests.java b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/SoftDeleteTests.java index 9461fd0892a51..0fb8e8b30245e 100644 --- a/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/SoftDeleteTests.java +++ b/sdk/storage/azure-storage-file-datalake/src/test/java/com/azure/storage/file/datalake/SoftDeleteTests.java @@ -63,7 +63,7 @@ public void cleanup() { fileSystemClient.delete(); } - @DisabledIf("olderThan20200804ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200804ServiceVersion") @Test public void restorePath() { DataLakeDirectoryClient dir = fileSystemClient.getDirectoryClient(generatePathName()); @@ -92,7 +92,7 @@ public void restorePath() { assertEquals(file.getPathUrl(), returnedClient.getPathUrl()); } - @DisabledIf("olderThan20200804ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200804ServiceVersion") @ParameterizedTest @ValueSource(strings = {"!'();[]@&%=+\\$,#äÄöÖüÜß;", "%21%27%28%29%3B%5B%5D%40%26%25%3D%2B%24%2C%23äÄöÖüÜß%3B", " my cool directory ", "directory"}) @@ -158,7 +158,7 @@ public void listDeletedPathsError() { assertThrows(DataLakeStorageException.class, () -> fsc.listDeletedPaths().iterator().next()); } - @DisabledIf("olderThan20200804ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200804ServiceVersion") @Test public void listDeletedPathsPath() { DataLakeDirectoryClient dir = fileSystemClient.getDirectoryClient(generatePathName()); @@ -180,7 +180,7 @@ public void listDeletedPathsPath() { } // TODO (gapra): Add more get paths tests (Github issue created) - @DisabledIf("olderThan20200804ServiceVersion") + @DisabledIf("com.azure.storage.file.datalake.DataLakeTestBase#olderThan20200804ServiceVersion") @Test public void listDeletedPaths() { DataLakeFileClient fc1 = fileSystemClient.getFileClient(generatePathName()); @@ -196,8 +196,4 @@ public void listDeletedPaths() { assertNotNull(deletedFiles.get(0).getDeletionId()); assertNotNull(deletedFiles.get(0).getRemainingRetentionDays()); } - - private static boolean olderThan20200804ServiceVersion() { - return olderThan(DataLakeServiceVersion.V2020_08_04); - } }