use of com.amazonaws.services.s3.model.MultipartUpload in project bender by Nextdoor.
the class S3TransporterTest method testMultipleUploads.
@Test
public void testMultipleUploads() throws TransportException, IllegalStateException, IOException {
/*
* Create mock client, requets, and replies
*/
AmazonS3Client mockClient = getMockClient();
/*
* Fill buffer with mock data
*/
S3TransportBuffer buffer1 = new S3TransportBuffer(1000, false, new S3TransportSerializer());
S3TransportBuffer buffer2 = new S3TransportBuffer(1000, false, new S3TransportSerializer());
InternalEvent mockIevent = mock(InternalEvent.class);
doReturn("foo").doReturn("bar1").when(mockIevent).getSerialized();
buffer1.add(mockIevent);
buffer2.add(mockIevent);
/*
* Create transport
*/
Map<String, MultiPartUpload> multiPartUploads = new HashMap<String, MultiPartUpload>(0);
S3Transport transport = new S3Transport(mockClient, "bucket", "basepath", false, multiPartUploads);
/*
* Do actual test
*/
LinkedHashMap<String, String> partitions = new LinkedHashMap<String, String>();
partitions.put(S3Transport.FILENAME_KEY, "a_filename");
ArgumentCaptor<UploadPartRequest> argument = ArgumentCaptor.forClass(UploadPartRequest.class);
transport.sendBatch(buffer1, partitions, new TestContext());
transport.sendBatch(buffer2, partitions, new TestContext());
verify(mockClient, times(2)).uploadPart(argument.capture());
List<UploadPartRequest> arguments = argument.getAllValues();
assertEquals(1, arguments.get(0).getPartNumber());
// foo\n
assertEquals(4, arguments.get(0).getPartSize());
assertEquals("123", arguments.get(0).getUploadId());
assertEquals(2, arguments.get(1).getPartNumber());
// bar1\n
assertEquals(5, arguments.get(1).getPartSize());
assertEquals("123", arguments.get(1).getUploadId());
}
Aggregations