|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package software.amazon.awssdk.services.s3.regression; |
| 17 | + |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
| 19 | +import static software.amazon.awssdk.services.s3.regression.S3ChecksumsTestUtils.assumeNotAccelerateWithArnType; |
| 20 | +import static software.amazon.awssdk.services.s3.regression.S3ChecksumsTestUtils.assumeNotAccelerateWithEoz; |
| 21 | +import static software.amazon.awssdk.services.s3.regression.S3ChecksumsTestUtils.assumeNotAccelerateWithPathStyle; |
| 22 | +import static software.amazon.awssdk.services.s3.regression.S3ChecksumsTestUtils.assumeNotAccessPointWithPathStyle; |
| 23 | +import static software.amazon.awssdk.services.s3.regression.S3ChecksumsTestUtils.crc32; |
| 24 | +import static software.amazon.awssdk.services.s3.regression.S3ChecksumsTestUtils.makeAsyncClient; |
| 25 | +import static software.amazon.awssdk.services.s3.regression.S3ChecksumsTestUtils.makeSyncClient; |
| 26 | + |
| 27 | +import java.util.List; |
| 28 | +import java.util.concurrent.Callable; |
| 29 | +import org.junit.jupiter.api.Assumptions; |
| 30 | +import org.junit.jupiter.params.ParameterizedTest; |
| 31 | +import org.junit.jupiter.params.provider.MethodSource; |
| 32 | +import software.amazon.awssdk.awscore.AwsClient; |
| 33 | +import software.amazon.awssdk.core.sync.RequestBody; |
| 34 | +import software.amazon.awssdk.services.s3.S3AsyncClient; |
| 35 | +import software.amazon.awssdk.services.s3.S3Client; |
| 36 | +import software.amazon.awssdk.services.s3.model.Delete; |
| 37 | +import software.amazon.awssdk.services.s3.model.DeleteObjectsRequest; |
| 38 | +import software.amazon.awssdk.services.s3.model.GlacierJobParameters; |
| 39 | +import software.amazon.awssdk.services.s3.model.ObjectIdentifier; |
| 40 | +import software.amazon.awssdk.services.s3.model.RestoreObjectRequest; |
| 41 | +import software.amazon.awssdk.services.s3.model.RestoreRequest; |
| 42 | +import software.amazon.awssdk.services.s3.model.StorageClass; |
| 43 | +import software.amazon.awssdk.services.s3.model.Tier; |
| 44 | +import software.amazon.awssdk.utils.CompletableFutureUtils; |
| 45 | +import software.amazon.awssdk.utils.Logger; |
| 46 | + |
| 47 | +public class DataplaneOperationRegressionTesting extends BaseS3RegressionTest { |
| 48 | + private static final Logger LOG = Logger.loggerFor(DataplaneOperationRegressionTesting.class); |
| 49 | + |
| 50 | + // Request checksum required |
| 51 | + @ParameterizedTest |
| 52 | + @MethodSource("testConfigs") |
| 53 | + void deleteObject(TestConfig config) throws Exception { |
| 54 | + assumeNotAccessPointWithPathStyle(config); |
| 55 | + assumeNotAccelerateWithPathStyle(config); |
| 56 | + assumeNotAccelerateWithArnType(config); |
| 57 | + assumeNotAccelerateWithEoz(config); |
| 58 | + |
| 59 | + LOG.debug(() -> "Running deleteObject with config: " + config.toString()); |
| 60 | + |
| 61 | + String bucket = bucketForType(config.getBucketType()); |
| 62 | + String key = putRandomObject(config.getBucketType()); |
| 63 | + TestCallable<Void> callable = null; |
| 64 | + try { |
| 65 | + DeleteObjectsRequest req = DeleteObjectsRequest.builder() |
| 66 | + .bucket(bucket) |
| 67 | + .delete(Delete.builder() |
| 68 | + .objects(ObjectIdentifier.builder() |
| 69 | + .key(key) |
| 70 | + .build()) |
| 71 | + .build()) |
| 72 | + .build(); |
| 73 | + |
| 74 | + callable = callDeleteObjects(req, config); |
| 75 | + callable.runnable().call(); |
| 76 | + } finally { |
| 77 | + if (callable != null) { |
| 78 | + callable.client().close(); |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + // Request checksum optional |
| 84 | + @ParameterizedTest |
| 85 | + @MethodSource("testConfigs") |
| 86 | + void restoreObject(TestConfig config) throws Exception { |
| 87 | + assumeNotAccessPointWithPathStyle(config); |
| 88 | + assumeNotAccelerateWithPathStyle(config); |
| 89 | + assumeNotAccelerateWithArnType(config); |
| 90 | + |
| 91 | + Assumptions.assumeFalse(config.getBucketType() == BucketType.EOZ, |
| 92 | + "Restore is not supported for S3 Express"); |
| 93 | + |
| 94 | + LOG.debug(() -> "Running restoreObject with config: " + config); |
| 95 | + |
| 96 | + String bucket = bucketForType(config.getBucketType()); |
| 97 | + String key = putRandomArchivedObject(config.getBucketType()); |
| 98 | + TestCallable<Void> callable = null; |
| 99 | + try { |
| 100 | + RestoreObjectRequest request = RestoreObjectRequest.builder() |
| 101 | + .bucket(bucket) |
| 102 | + .key(key) |
| 103 | + .restoreRequest(RestoreRequest.builder() |
| 104 | + .days(5) |
| 105 | + .glacierJobParameters(GlacierJobParameters.builder() |
| 106 | + .tier(Tier.STANDARD) |
| 107 | + .build()) |
| 108 | + .build()) |
| 109 | + .build(); |
| 110 | + |
| 111 | + callable = callRestoreObject(request, config); |
| 112 | + callable.runnable().call(); |
| 113 | + } finally { |
| 114 | + if (callable != null) { |
| 115 | + callable.client().close(); |
| 116 | + } |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + private TestCallable<Void> callDeleteObjects(DeleteObjectsRequest request, TestConfig config) { |
| 121 | + AwsClient toClose; |
| 122 | + Callable<Void> runnable = null; |
| 123 | + |
| 124 | + if (config.getFlavor().isAsync()) { |
| 125 | + S3AsyncClient s3Async = makeAsyncClient(config, REGION, CREDENTIALS_PROVIDER_CHAIN); |
| 126 | + toClose = s3Async; |
| 127 | + runnable = () -> { |
| 128 | + CompletableFutureUtils.joinLikeSync(s3Async.deleteObjects(request)); |
| 129 | + return null; |
| 130 | + }; |
| 131 | + } else { |
| 132 | + S3Client s3 = makeSyncClient(config, REGION, CREDENTIALS_PROVIDER_CHAIN); |
| 133 | + toClose = s3; |
| 134 | + runnable = () -> { |
| 135 | + s3.deleteObjects(request); |
| 136 | + return null; |
| 137 | + }; |
| 138 | + } |
| 139 | + |
| 140 | + return new TestCallable<>(toClose, runnable); |
| 141 | + } |
| 142 | + |
| 143 | + private TestCallable<Void> callRestoreObject(RestoreObjectRequest request, TestConfig config) { |
| 144 | + AwsClient toClose; |
| 145 | + Callable<Void> callable = null; |
| 146 | + |
| 147 | + if (config.getFlavor().isAsync()) { |
| 148 | + S3AsyncClient s3Async = makeAsyncClient(config, REGION, CREDENTIALS_PROVIDER_CHAIN); |
| 149 | + toClose = s3Async; |
| 150 | + callable = () -> { |
| 151 | + s3Async.restoreObject(request).join(); |
| 152 | + return null; |
| 153 | + }; |
| 154 | + } else { |
| 155 | + S3Client s3 = makeSyncClient(config, REGION, CREDENTIALS_PROVIDER_CHAIN); |
| 156 | + toClose = s3; |
| 157 | + callable = () -> { |
| 158 | + s3.restoreObject(request); |
| 159 | + return null; |
| 160 | + }; |
| 161 | + } |
| 162 | + |
| 163 | + return new TestCallable<>(toClose, callable); |
| 164 | + } |
| 165 | + |
| 166 | + static List<TestConfig> testConfigs() { |
| 167 | + return TestConfig.testConfigs(); |
| 168 | + } |
| 169 | + |
| 170 | + private String putRandomObject(BucketType bucketType) { |
| 171 | + String key = S3ChecksumsTestUtils.randomKey(); |
| 172 | + String bucketName = bucketForType(bucketType); |
| 173 | + s3.putObject(r -> r.bucket(bucketName).key(key), RequestBody.fromString("hello")); |
| 174 | + recordObjectToCleanup(bucketType, key); |
| 175 | + return key; |
| 176 | + } |
| 177 | + |
| 178 | + private String putRandomArchivedObject(BucketType bucketType) { |
| 179 | + String key = S3ChecksumsTestUtils.randomKey(); |
| 180 | + String bucketName = bucketForType(bucketType); |
| 181 | + s3.putObject(r -> r.bucket(bucketName).key(key).storageClass(StorageClass.GLACIER), RequestBody.fromString("hello")); |
| 182 | + recordObjectToCleanup(bucketType, key); |
| 183 | + return key; |
| 184 | + } |
| 185 | + |
| 186 | + |
| 187 | +} |
0 commit comments