use of software.amazon.awssdk.transfer.s3.CompletedUpload in project aws-sdk-java-v2 by aws.
the class DefaultS3TransferManager method upload.
@Override
public Upload upload(UploadRequest uploadRequest) {
Validate.paramNotNull(uploadRequest, "uploadRequest");
AsyncRequestBody requestBody = uploadRequest.requestBody();
CompletableFuture<CompletedUpload> uploadFuture = new CompletableFuture<>();
TransferProgressUpdater progressUpdater = new TransferProgressUpdater(uploadRequest, requestBody);
progressUpdater.transferInitiated();
requestBody = progressUpdater.wrapRequestBody(requestBody);
progressUpdater.registerCompletion(uploadFuture);
try {
assertNotUnsupportedArn(uploadRequest.putObjectRequest().bucket(), "upload");
CompletableFuture<PutObjectResponse> putObjFuture = s3CrtAsyncClient.putObject(uploadRequest.putObjectRequest(), requestBody);
// Forward upload cancellation to CRT future
CompletableFutureUtils.forwardExceptionTo(uploadFuture, putObjFuture);
CompletableFutureUtils.forwardTransformedResultTo(putObjFuture, uploadFuture, r -> CompletedUpload.builder().response(r).build());
} catch (Throwable throwable) {
uploadFuture.completeExceptionally(throwable);
}
return new DefaultUpload(uploadFuture, progressUpdater.progress());
}
use of software.amazon.awssdk.transfer.s3.CompletedUpload in project aws-sdk-java-v2 by aws.
the class UploadDirectoryHelperParameterizedTest method uploadDirectory_withDelimiter_shouldHonor.
@Test
public void uploadDirectory_withDelimiter_shouldHonor() {
ArgumentCaptor<UploadFileRequest> requestArgumentCaptor = ArgumentCaptor.forClass(UploadFileRequest.class);
when(singleUploadFunction.apply(requestArgumentCaptor.capture())).thenReturn(completedUpload());
DirectoryUpload uploadDirectory = uploadDirectoryHelper.uploadDirectory(UploadDirectoryRequest.builder().sourceDirectory(directory).bucket("bucket").delimiter(",").prefix("yolo").build());
uploadDirectory.completionFuture().join();
List<String> keys = requestArgumentCaptor.getAllValues().stream().map(u -> u.putObjectRequest().key()).collect(Collectors.toList());
assertThat(keys.size()).isEqualTo(3);
assertThat(keys).containsOnly("yolo,foo,2.txt", "yolo,foo,1.txt", "yolo,bar.txt");
}
use of software.amazon.awssdk.transfer.s3.CompletedUpload in project aws-sdk-java-v2 by aws.
the class S3TransferManagerTest method upload_returnsResponse.
@Test
public void upload_returnsResponse() {
PutObjectResponse response = PutObjectResponse.builder().build();
when(mockS3Crt.putObject(any(PutObjectRequest.class), any(AsyncRequestBody.class))).thenReturn(CompletableFuture.completedFuture(response));
CompletedUpload completedUpload = tm.upload(u -> u.putObjectRequest(p -> p.bucket("bucket").key("key")).requestBody(AsyncRequestBody.fromString("foo"))).completionFuture().join();
assertThat(completedUpload.response()).isEqualTo(response);
}
use of software.amazon.awssdk.transfer.s3.CompletedUpload in project aws-sdk-java-v2 by aws.
the class UploadDirectoryHelperParameterizedTest method uploadDirectory_maxLengthOne_shouldOnlyUploadTopLevel.
@Test
public void uploadDirectory_maxLengthOne_shouldOnlyUploadTopLevel() {
ArgumentCaptor<UploadFileRequest> requestArgumentCaptor = ArgumentCaptor.forClass(UploadFileRequest.class);
when(singleUploadFunction.apply(requestArgumentCaptor.capture())).thenReturn(completedUpload());
DirectoryUpload uploadDirectory = uploadDirectoryHelper.uploadDirectory(UploadDirectoryRequest.builder().sourceDirectory(directory).bucket("bucket").overrideConfiguration(o -> o.maxDepth(1)).build());
uploadDirectory.completionFuture().join();
List<UploadFileRequest> actualRequests = requestArgumentCaptor.getAllValues();
actualRequests.forEach(r -> assertThat(r.putObjectRequest().bucket()).isEqualTo("bucket"));
assertThat(actualRequests.size()).isEqualTo(1);
List<String> keys = actualRequests.stream().map(u -> u.putObjectRequest().key()).collect(Collectors.toList());
assertThat(keys).containsOnly("bar.txt");
}
use of software.amazon.awssdk.transfer.s3.CompletedUpload in project aws-sdk-java-v2 by aws.
the class UploadDirectoryHelperParameterizedTest method uploadDirectory_FollowSymlinkTrue_shouldIncludeLinkedFiles.
@Test
public void uploadDirectory_FollowSymlinkTrue_shouldIncludeLinkedFiles() {
// skip the test if we are using jimfs because it doesn't work well with symlink
assumeTrue(configuration.equals(Configuration.forCurrentPlatform()));
ArgumentCaptor<UploadFileRequest> requestArgumentCaptor = ArgumentCaptor.forClass(UploadFileRequest.class);
when(singleUploadFunction.apply(requestArgumentCaptor.capture())).thenReturn(completedUpload());
DirectoryUpload uploadDirectory = uploadDirectoryHelper.uploadDirectory(UploadDirectoryRequest.builder().sourceDirectory(directory).bucket("bucket").overrideConfiguration(o -> o.followSymbolicLinks(true)).build());
uploadDirectory.completionFuture().join();
List<UploadFileRequest> actualRequests = requestArgumentCaptor.getAllValues();
actualRequests.forEach(r -> assertThat(r.putObjectRequest().bucket()).isEqualTo("bucket"));
List<String> keys = actualRequests.stream().map(u -> u.putObjectRequest().key()).collect(Collectors.toList());
assertThat(keys.size()).isEqualTo(5);
assertThat(keys).containsOnly("bar.txt", "foo/1.txt", "foo/2.txt", "symlink/2.txt", "symlink2");
}
Aggregations