MultipartTransferManager { public void awaitCompletion() { for (Future<Void> f : responses) { try { f.get(); } catch (InterruptedException e) { LOG.info("Thread interrupted while waiting for transfer completion", e); Thread.currentThread().interrupt(); return; } catch (ExecutionException e) { LOG.info("Execution exception while waiting for transfer completion", e); } } }  synchronized void startTransfer(final UploadPartRequest request); void awaitCompletion(); void abortAll();  }
@Test public void awaitCompletion() { UploadPartRequest request1 = UploadPartRequest.builder().uploadPartNum(1).build(); UploadPartRequest request2 = UploadPartRequest.builder().uploadPartNum(2).build(); final UploadPartResponse response1 = UploadPartResponse.builder().build(); when(service.uploadPart(request1)) .thenAnswer( new Answer<UploadPartResponse>() { @Override public UploadPartResponse answer(InvocationOnMock arg0) throws Throwable { Thread.sleep(10000L); return response1; } }); when(service.uploadPart(request2)).thenThrow(new RuntimeException()); manager.startTransfer(request1); manager.startTransfer(request2); List<Integer> inProgressParts = manifest.listInProgressParts(); assertEquals(2, inProgressParts.size()); assertEquals(1, inProgressParts.get(0).intValue()); assertEquals(2, inProgressParts.get(1).intValue()); manager.awaitCompletion(); List<CommitMultipartUploadPartDetails> successfulParts = manifest.listCompletedParts(); assertEquals(1, successfulParts.size()); assertEquals(1, successfulParts.get(0).getPartNum().intValue()); List<Integer> failedParts = manifest.listFailedParts(); assertEquals(1, failedParts.size()); assertEquals(2, failedParts.get(0).intValue()); assertTrue(manifest.listInProgressParts().isEmpty()); }