use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.
the class StorageHelper method getS3FileCopyRequestParamsDto.
/**
* Returns a new {@link org.finra.herd.model.dto.S3FileCopyRequestParamsDto} with proxy host and port populated from the configuration.
*
* @return {@link org.finra.herd.model.dto.S3FileCopyRequestParamsDto} with proxy host and port.
*/
public S3FileCopyRequestParamsDto getS3FileCopyRequestParamsDto() {
S3FileCopyRequestParamsDto params = new S3FileCopyRequestParamsDto();
// Update the parameters with proxy host and port retrieved from the configuration.
setProxyHostAndPort(params);
return params;
}
use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto 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 org.finra.herd.model.dto.S3FileCopyRequestParamsDto 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 org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testCopyFile.
/**
* Test S3 file copy without any errors.
*/
@Test
public void testCopyFile() throws InterruptedException {
// Put a 1 byte file in S3.
s3Operations.putObject(new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), null), null);
S3FileCopyRequestParamsDto transferDto = new S3FileCopyRequestParamsDto();
transferDto.setSourceBucketName(storageDaoTestHelper.getS3LoadingDockBucketName());
transferDto.setTargetBucketName(storageDaoTestHelper.getS3ExternalBucketName());
transferDto.setSourceObjectKey(TARGET_S3_KEY);
transferDto.setTargetObjectKey(TARGET_S3_KEY);
transferDto.setKmsKeyId(MockS3OperationsImpl.MOCK_KMS_ID);
S3FileTransferResultsDto resultsDto = s3Dao.copyFile(transferDto);
assertEquals(Long.valueOf(1L), resultsDto.getTotalFilesTransferred());
}
use of org.finra.herd.model.dto.S3FileCopyRequestParamsDto in project herd by FINRAOS.
the class S3DaoTest method testCopyFileNoKmsId.
/**
* Test S3 file copy without a KMS ID specified.
*/
@Test
public void testCopyFileNoKmsId() throws InterruptedException {
// Put a 1 byte file in S3.
s3Operations.putObject(new PutObjectRequest(storageDaoTestHelper.getS3LoadingDockBucketName(), TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), null), null);
// Perform an S3 file copy operation when KMS ID value is not specified.
for (String kmsId : Arrays.asList(BLANK_TEXT, null)) {
S3FileCopyRequestParamsDto transferDto = new S3FileCopyRequestParamsDto();
transferDto.setSourceBucketName(storageDaoTestHelper.getS3LoadingDockBucketName());
transferDto.setTargetBucketName(storageDaoTestHelper.getS3ExternalBucketName());
transferDto.setSourceObjectKey(TARGET_S3_KEY);
transferDto.setTargetObjectKey(TARGET_S3_KEY);
transferDto.setKmsKeyId(kmsId);
S3FileTransferResultsDto resultsDto = s3Dao.copyFile(transferDto);
assertEquals(Long.valueOf(1L), resultsDto.getTotalFilesTransferred());
}
}
Aggregations