|
12 | 12 | import software.amazon.awssdk.awscore.exception.AwsServiceException; |
13 | 13 | import software.amazon.awssdk.core.sync.RequestBody; |
14 | 14 | import software.amazon.awssdk.http.SdkHttpClient; |
15 | | -import software.amazon.awssdk.http.apache.ApacheHttpClient; |
16 | 15 | import software.amazon.awssdk.metrics.MetricCollection; |
17 | 16 | import software.amazon.awssdk.metrics.MetricPublisher; |
18 | 17 | import software.amazon.awssdk.services.s3.S3Client; |
19 | 18 | import software.amazon.awssdk.services.s3.model.AbortMultipartUploadRequest; |
| 19 | +import software.amazon.awssdk.services.s3.model.AbortMultipartUploadResponse; |
20 | 20 | import software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest; |
21 | 21 | import software.amazon.awssdk.services.s3.model.CompleteMultipartUploadResponse; |
22 | 22 | import software.amazon.awssdk.services.s3.model.CompletedPart; |
|
51 | 51 | import static org.hamcrest.Matchers.equalTo; |
52 | 52 | import static org.hamcrest.Matchers.instanceOf; |
53 | 53 | import static org.mockito.ArgumentMatchers.any; |
54 | | -import static org.mockito.Mockito.doAnswer; |
55 | | -import static org.mockito.Mockito.doNothing; |
56 | 54 | import static org.mockito.Mockito.mock; |
57 | 55 | import static org.mockito.Mockito.times; |
58 | 56 | import static org.mockito.Mockito.verify; |
@@ -315,12 +313,19 @@ public void testExecuteMultipartUploadAborted() { |
315 | 313 | when(blobStore.getStorageClass()).thenReturn(randomFrom(StorageClass.values())); |
316 | 314 |
|
317 | 315 | final S3Client client = mock(S3Client.class); |
318 | | - final SdkHttpClient httpClient = mock(ApacheHttpClient.class); |
| 316 | + final SdkHttpClient httpClient = mock(SdkHttpClient.class); |
319 | 317 | final AmazonS3Reference clientReference = new AmazonS3Reference(client, httpClient); |
320 | | - doAnswer(invocation -> { |
321 | | - clientReference.incRef(); |
| 318 | + when(blobStore.clientReference()).then(invocation -> { |
| 319 | + clientReference.mustIncRef(); |
322 | 320 | return clientReference; |
323 | | - }).when(blobStore).clientReference(); |
| 321 | + }); |
| 322 | + when(blobStore.getMetricPublisher(any(), any())).thenReturn(new MetricPublisher() { |
| 323 | + @Override |
| 324 | + public void publish(MetricCollection metricCollection) {} |
| 325 | + |
| 326 | + @Override |
| 327 | + public void close() {} |
| 328 | + }); |
324 | 329 |
|
325 | 330 | final String uploadId = randomAlphaOfLength(25); |
326 | 331 |
|
@@ -360,15 +365,15 @@ public void testExecuteMultipartUploadAborted() { |
360 | 365 | } |
361 | 366 |
|
362 | 367 | final ArgumentCaptor<AbortMultipartUploadRequest> argumentCaptor = ArgumentCaptor.forClass(AbortMultipartUploadRequest.class); |
363 | | - doNothing().when(client).abortMultipartUpload(argumentCaptor.capture()); |
| 368 | + when(client.abortMultipartUpload(argumentCaptor.capture())).thenReturn(AbortMultipartUploadResponse.builder().build()); |
364 | 369 |
|
365 | 370 | final IOException e = expectThrows(IOException.class, () -> { |
366 | 371 | final S3BlobContainer blobContainer = new S3BlobContainer(BlobPath.EMPTY, blobStore); |
367 | 372 | blobContainer.executeMultipartUpload(randomPurpose(), blobStore, blobName, new ByteArrayInputStream(new byte[0]), blobSize); |
368 | 373 | }); |
369 | 374 |
|
370 | 375 | assertEquals("Unable to upload object [" + blobName + "] using multipart upload", e.getMessage()); |
371 | | - assertThat(e.getCause(), instanceOf(S3Exception.class)); // TODO NOMERGE is there a more fine grained error class? |
| 376 | + assertThat(e.getCause(), instanceOf(S3Exception.class)); |
372 | 377 | assertEquals(exceptions.get(stage).getMessage(), e.getCause().getMessage()); |
373 | 378 |
|
374 | 379 | if (stage == 0) { |
|
0 commit comments