|
| 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.s3benchmarks; |
| 17 | + |
| 18 | +import java.io.File; |
| 19 | +import java.util.List; |
| 20 | +import software.amazon.awssdk.core.async.AsyncResponseTransformer; |
| 21 | +import software.amazon.awssdk.utils.Logger; |
| 22 | + |
| 23 | +public class JavaS3ClientDownloadBenchmark extends BaseJavaS3ClientBenchmark { |
| 24 | + private static final Logger log = Logger.loggerFor(JavaS3ClientDownloadBenchmark.class); |
| 25 | + private final String filePath; |
| 26 | + |
| 27 | + public JavaS3ClientDownloadBenchmark(TransferManagerBenchmarkConfig config) { |
| 28 | + super(config); |
| 29 | + this.filePath = config.filePath(); |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + protected void sendOneRequest(List<Double> latencies) throws Exception { |
| 34 | + Double latency; |
| 35 | + if (filePath == null) { |
| 36 | + log.info(() -> "Starting download to memory"); |
| 37 | + latency = runWithTime(s3AsyncClient.getObject( |
| 38 | + req -> req.key(key).bucket(bucket), AsyncResponseTransformer.toBytes() |
| 39 | + )::join).latency(); |
| 40 | + } else { |
| 41 | + log.info(() -> "Starting download to file"); |
| 42 | + latency = runWithTime(s3AsyncClient.getObject( |
| 43 | + req -> req.key(key).bucket(bucket), new File(filePath).toPath() |
| 44 | + )::join).latency(); |
| 45 | + } |
| 46 | + latencies.add(latency); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + protected long contentLength() throws Exception { |
| 51 | + return s3Client.headObject(b -> b.bucket(bucket).key(key)).contentLength(); |
| 52 | + } |
| 53 | +} |
0 commit comments