Search in sources :

Example 6 with UploadResult

use of com.amazonaws.services.s3.transfer.model.UploadResult in project qpp-conversion-tool by CMSgov.

the class StorageServiceImplTest method before.

@BeforeEach
void before() {
    doAnswer(invocationOnMock -> {
        Runnable method = invocationOnMock.getArgument(0);
        CompletableFuture.runAsync(method);
        return null;
    }).when(taskExecutor).execute(any(Runnable.class));
    result = new UploadResult();
    result.setKey("meep");
    when(transferManager.upload(any(PutObjectRequest.class))).thenReturn(upload);
}
Also used : UploadResult(com.amazonaws.services.s3.transfer.model.UploadResult) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with UploadResult

use of com.amazonaws.services.s3.transfer.model.UploadResult in project bender by Nextdoor.

the class S3TransporterTest method testAmazonClientException.

@Test(expected = TransportException.class)
public void testAmazonClientException() throws TransportException, IllegalStateException, IOException {
    /*
     * Create mock client, requets, and replies
     */
    AmazonS3Client mockClient = mock(AmazonS3Client.class);
    UploadPartResult uploadResult = new UploadPartResult();
    uploadResult.setETag("foo");
    doThrow(new AmazonClientException("expected")).when(mockClient).uploadPart(any(UploadPartRequest.class));
    InitiateMultipartUploadResult initUploadResult = new InitiateMultipartUploadResult();
    initUploadResult.setUploadId("123");
    doReturn(initUploadResult).when(mockClient).initiateMultipartUpload(any(InitiateMultipartUploadRequest.class));
    /*
     * Fill buffer with mock data
     */
    S3TransportBuffer buffer = new S3TransportBuffer(1000, false, new S3TransportSerializer());
    InternalEvent mockIevent = mock(InternalEvent.class);
    doReturn("foo").when(mockIevent).getSerialized();
    /*
     * Create transport
     */
    Map<String, MultiPartUpload> multiPartUploads = new HashMap<String, MultiPartUpload>(0);
    S3Transport transport = new S3Transport(mockClient, "bucket", "basepath", false, multiPartUploads);
    /*
     * Do actual test
     */
    buffer.add(mockIevent);
    LinkedHashMap<String, String> partitions = new LinkedHashMap<String, String>();
    partitions.put(S3Transport.FILENAME_KEY, "a_filename");
    ArgumentCaptor<UploadPartRequest> argument = ArgumentCaptor.forClass(UploadPartRequest.class);
    try {
        transport.sendBatch(buffer, partitions, new TestContext());
    } catch (Exception e) {
        assertEquals(e.getCause().getClass(), AmazonClientException.class);
        throw e;
    }
}
Also used : InitiateMultipartUploadResult(com.amazonaws.services.s3.model.InitiateMultipartUploadResult) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AmazonClientException(com.amazonaws.AmazonClientException) TestContext(com.nextdoor.bender.aws.TestContext) InitiateMultipartUploadRequest(com.amazonaws.services.s3.model.InitiateMultipartUploadRequest) UploadPartRequest(com.amazonaws.services.s3.model.UploadPartRequest) TransportException(com.nextdoor.bender.ipc.TransportException) IOException(java.io.IOException) AmazonClientException(com.amazonaws.AmazonClientException) InternalEvent(com.nextdoor.bender.InternalEvent) LinkedHashMap(java.util.LinkedHashMap) UploadPartResult(com.amazonaws.services.s3.model.UploadPartResult) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) Test(org.junit.Test)

Aggregations

InitiateMultipartUploadRequest (com.amazonaws.services.s3.model.InitiateMultipartUploadRequest)4 InitiateMultipartUploadResult (com.amazonaws.services.s3.model.InitiateMultipartUploadResult)4 UploadPartRequest (com.amazonaws.services.s3.model.UploadPartRequest)4 UploadPartResult (com.amazonaws.services.s3.model.UploadPartResult)3 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)2 CompleteMultipartUploadRequest (com.amazonaws.services.s3.model.CompleteMultipartUploadRequest)2 CompleteMultipartUploadResult (com.amazonaws.services.s3.model.CompleteMultipartUploadResult)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)2 PartETag (com.amazonaws.services.s3.model.PartETag)2 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)2 UploadResult (com.amazonaws.services.s3.transfer.model.UploadResult)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 SdkClientException (com.amazonaws.SdkClientException)1 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)1 Regions (com.amazonaws.regions.Regions)1