use of com.amazonaws.services.s3.transfer.TransferProgress in project herd by FINRAOS.
the class MockS3OperationsImpl method download.
@Override
public Download download(String bucket, String key, File file, TransferManager transferManager) {
MockS3Bucket mockS3Bucket = mockS3Buckets.get(bucket);
MockS3Object mockS3Object = mockS3Bucket.getObjects().get(key);
try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
fileOutputStream.write(mockS3Object.getData());
} catch (IOException e) {
throw new RuntimeException("Error writing to file " + file, e);
}
TransferProgress progress = new TransferProgress();
progress.setTotalBytesToTransfer(mockS3Object.getData().length);
progress.updateProgress(mockS3Object.getData().length);
DownloadImpl download = new DownloadImpl(null, progress, null, null, null, new GetObjectRequest(bucket, key), file, mockS3Object.getObjectMetadata(), false);
download.setState(TransferState.Completed);
return download;
}
use of com.amazonaws.services.s3.transfer.TransferProgress in project herd by FINRAOS.
the class S3DaoTest method testPerformTransferAssertLogWhenStepCountGt300.
@Test
public void testPerformTransferAssertLogWhenStepCountGt300() throws Exception {
S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
S3Operations mockS3Operations = mock(S3Operations.class);
ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
// Shorten the sleep interval for faster tests
long originalSleepIntervalsMillis = (long) ReflectionTestUtils.getField(s3Dao, "sleepIntervalsMillis");
ReflectionTestUtils.setField(s3Dao, "sleepIntervalsMillis", 1l);
try {
S3FileCopyRequestParamsDto s3FileCopyRequestParamsDto = new S3FileCopyRequestParamsDto();
s3FileCopyRequestParamsDto.setSourceBucketName("sourceBucketName");
s3FileCopyRequestParamsDto.setSourceObjectKey("sourceObjectKey");
s3FileCopyRequestParamsDto.setTargetBucketName("targetBucketName");
s3FileCopyRequestParamsDto.setTargetObjectKey("targetObjectKey");
s3FileCopyRequestParamsDto.setKmsKeyId("kmsKeyId");
when(mockS3Operations.copyFile(any(), any())).then(new Answer<Copy>() {
@Override
public Copy answer(InvocationOnMock invocation) throws Throwable {
Copy mockTransfer = mock(Copy.class);
when(mockTransfer.getProgress()).thenReturn(new TransferProgress());
when(mockTransfer.getState()).thenReturn(TransferState.Completed);
when(mockTransfer.isDone()).then(new Answer<Boolean>() {
int callCount = 0;
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
return callCount++ > 600;
}
});
return mockTransfer;
}
});
s3Dao.copyFile(s3FileCopyRequestParamsDto);
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
ReflectionTestUtils.setField(s3Dao, "sleepIntervalsMillis", originalSleepIntervalsMillis);
}
}
use of com.amazonaws.services.s3.transfer.TransferProgress in project herd by FINRAOS.
the class S3DaoTest method testPerformTransferAssertHandleFailedWithAmazonClientException.
@Test
public void testPerformTransferAssertHandleFailedWithAmazonClientException() throws Exception {
S3Operations originalS3Operations = (S3Operations) ReflectionTestUtils.getField(s3Dao, "s3Operations");
S3Operations mockS3Operations = mock(S3Operations.class);
ReflectionTestUtils.setField(s3Dao, "s3Operations", mockS3Operations);
// Shorten the sleep interval for faster tests
long originalSleepIntervalsMillis = (long) ReflectionTestUtils.getField(s3Dao, "sleepIntervalsMillis");
ReflectionTestUtils.setField(s3Dao, "sleepIntervalsMillis", 1l);
try {
S3FileCopyRequestParamsDto s3FileCopyRequestParamsDto = new S3FileCopyRequestParamsDto();
s3FileCopyRequestParamsDto.setSourceBucketName("sourceBucketName");
s3FileCopyRequestParamsDto.setSourceObjectKey("sourceObjectKey");
s3FileCopyRequestParamsDto.setTargetBucketName("targetBucketName");
s3FileCopyRequestParamsDto.setTargetObjectKey("targetObjectKey");
s3FileCopyRequestParamsDto.setKmsKeyId("kmsKeyId");
when(mockS3Operations.copyFile(any(), any())).then(new Answer<Copy>() {
@Override
public Copy answer(InvocationOnMock invocation) throws Throwable {
Copy mockTransfer = mock(Copy.class);
when(mockTransfer.getProgress()).thenReturn(new TransferProgress());
when(mockTransfer.getState()).thenReturn(TransferState.Failed);
when(mockTransfer.isDone()).thenReturn(true);
when(mockTransfer.waitForException()).thenReturn(new AmazonClientException("message"));
return mockTransfer;
}
});
try {
s3Dao.copyFile(s3FileCopyRequestParamsDto);
fail();
} catch (Exception e) {
assertEquals(AmazonClientException.class, e.getClass());
assertEquals("message", e.getMessage());
}
} finally {
ReflectionTestUtils.setField(s3Dao, "s3Operations", originalS3Operations);
ReflectionTestUtils.setField(s3Dao, "sleepIntervalsMillis", originalSleepIntervalsMillis);
}
}
use of com.amazonaws.services.s3.transfer.TransferProgress in project aws-doc-sdk-examples by awsdocs.
the class XferMgrProgress method showMultiUploadProgress.
// Prints progress of a multiple file upload while waiting for it to finish.
public static void showMultiUploadProgress(MultipleFileUpload multi_upload) {
// print the upload's human-readable description
System.out.println(multi_upload.getDescription());
// snippet-start:[s3.java1.s3_xfer_mgr_progress.substranferes]
Collection<? extends Upload> sub_xfers = new ArrayList<Upload>();
sub_xfers = multi_upload.getSubTransfers();
do {
System.out.println("\nSubtransfer progress:\n");
for (Upload u : sub_xfers) {
System.out.println(" " + u.getDescription());
if (u.isDone()) {
TransferState xfer_state = u.getState();
System.out.println(" " + xfer_state);
} else {
TransferProgress progress = u.getProgress();
double pct = progress.getPercentTransferred();
printProgressBar(pct);
System.out.println();
}
}
// wait a bit before the next update.
try {
Thread.sleep(200);
} catch (InterruptedException e) {
return;
}
} while (multi_upload.isDone() == false);
// print the final state of the transfer.
TransferState xfer_state = multi_upload.getState();
System.out.println("\nMultipleFileUpload " + xfer_state);
// snippet-end:[s3.java1.s3_xfer_mgr_progress.substranferes]
}
use of com.amazonaws.services.s3.transfer.TransferProgress in project herd by FINRAOS.
the class MockS3OperationsImpl method upload.
@Override
public Upload upload(PutObjectRequest putObjectRequest, TransferManager transferManager) {
LOGGER.debug("upload(): putObjectRequest.getBucketName() = " + putObjectRequest.getBucketName() + ", putObjectRequest.getKey() = " + putObjectRequest.getKey());
putObject(putObjectRequest, transferManager.getAmazonS3Client());
long contentLength = putObjectRequest.getFile().length();
TransferProgress progress = new TransferProgress();
progress.setTotalBytesToTransfer(contentLength);
progress.updateProgress(contentLength);
UploadImpl upload = new UploadImpl(null, progress, null, null);
upload.setState(TransferState.Completed);
return upload;
}
Aggregations