MultipartObjectAssembler { public synchronized MultipartManifest resumeRequest(String uploadId) { checkInitialized(); MultipartUpload existingUpload = find(uploadId); if (existingUpload == null) { throw new IllegalArgumentException( "Could not find existing upload with ID " + uploadId + " in namespace/bucket " + namespaceName + "/" + bucketName); } MultipartManifestImpl manifest = new MultipartManifestImpl(uploadId); String nextPageToken = null; do { ListMultipartUploadPartsResponse parts = service.listMultipartUploadParts( ListMultipartUploadPartsRequest.builder() .invocationCallback(invocationCallback) .namespaceName(namespaceName) .bucketName(bucketName) .objectName(objectName) .uploadId(uploadId) .opcClientRequestId(createClientRequestId("-list")) .limit(100) .page(nextPageToken) .build()); for (MultipartUploadPartSummary part : parts.getItems()) { manifest.registerExisting(part); } nextPageToken = parts.getOpcNextPage(); } while (nextPageToken != null); this.manifest = manifest; this.transferManager = new MultipartTransferManager(executorService, this.manifest, service); this.initialized = true; return manifest; } @Deprecated  MultipartObjectAssembler(
            ObjectStorage service,
            String namespaceName,
            String bucketName,
            String objectName,
            boolean allowOverwrite,
            ExecutorService executorService); @Builder private  MultipartObjectAssembler(
            ObjectStorage service,
            String namespaceName,
            String bucketName,
            String objectName,
            boolean allowOverwrite,
            ExecutorService executorService,
            String opcClientRequestId,
            Consumer<Invocation.Builder> invocationCallback,
            RetryConfiguration retryConfiguration); synchronized MultipartManifest newRequest(
            String contentType,
            String contentLanguage,
            String contentEncoding,
            Map<String, String> opcMeta); synchronized MultipartManifest resumeRequest(String uploadId); int addPart(File file, String md5); int addPart(InputStream stream, long contentLength, String md5); void setPart(File file, String md5, int partNum); void setPart(InputStream stream, long contentLength, String md5, int partNum); AbortMultipartUploadResponse abort(); CommitMultipartUploadResponse commit();  }
@Test public void resumeUpload_noMatchingUploadId_shouldThrowIllegalArgumentException() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Could not find existing upload with ID doesNotExist"); ArrayList<MultipartUpload> existingUploads = new ArrayList<>(); existingUploads.add(MultipartUpload.builder().uploadId("foobar").build()); ListMultipartUploadsResponse listResponse1 = ListMultipartUploadsResponse.builder() .opcNextPage("nextPage") .items(existingUploads) .build(); ListMultipartUploadsResponse listResponse2 = ListMultipartUploadsResponse.builder() .items(new ArrayList<MultipartUpload>()) .build(); when(service.listMultipartUploads(any(ListMultipartUploadsRequest.class))) .thenReturn(listResponse1) .thenReturn(listResponse2); assembler.resumeRequest("doesNotExist"); }
@Test public void resumeUpload_andVerifyListMultipartUploadPartsResponse() { String pageToken = "nextPage"; String uploadId = "exists"; ArrayList<MultipartUpload> existingUploads = new ArrayList<>(); existingUploads.add(MultipartUpload.builder().uploadId(uploadId).build()); ListMultipartUploadsResponse listResponse1 = ListMultipartUploadsResponse.builder() .opcNextPage(pageToken) .items(new ArrayList<MultipartUpload>()) .build(); ListMultipartUploadsResponse listResponse2 = ListMultipartUploadsResponse.builder().items(existingUploads).build(); when(service.listMultipartUploads(any(ListMultipartUploadsRequest.class))) .thenReturn(listResponse1) .thenReturn(listResponse2); ArrayList<MultipartUploadPartSummary> parts1 = new ArrayList<>(); parts1.add(MultipartUploadPartSummary.builder().etag("etag1").partNumber(1).build()); ArrayList<MultipartUploadPartSummary> parts2 = new ArrayList<>(); parts2.add(MultipartUploadPartSummary.builder().etag("etag3").partNumber(3).build()); ListMultipartUploadPartsResponse partsResponse1 = ListMultipartUploadPartsResponse.builder() .opcNextPage(pageToken) .items(parts1) .build(); ListMultipartUploadPartsResponse partsResponse2 = ListMultipartUploadPartsResponse.builder().items(parts2).build(); when(service.listMultipartUploadParts(any(ListMultipartUploadPartsRequest.class))) .thenReturn(partsResponse1) .thenReturn(partsResponse2); MultipartManifest manifest = assembler.resumeRequest(uploadId); assertNotNull(manifest); assertEquals(uploadId, manifest.getUploadId()); assertEquals(2, manifest.listCompletedParts().size()); ArgumentCaptor<ListMultipartUploadsRequest> listUploadsCaptor = ArgumentCaptor.forClass(ListMultipartUploadsRequest.class); verify(service, times(2)).listMultipartUploads(listUploadsCaptor.capture()); ListMultipartUploadsRequest listUploadsRequest1 = listUploadsCaptor.getAllValues().get(0); assertEquals(NAMESPACE, listUploadsRequest1.getNamespaceName()); assertEquals(BUCKET, listUploadsRequest1.getBucketName()); assertEquals(100, listUploadsRequest1.getLimit().intValue()); assertEquals(mockInvocationCallback, listUploadsRequest1.getInvocationCallback()); assertNull(listUploadsRequest1.getPage()); ListMultipartUploadsRequest listUploadsRequest2 = listUploadsCaptor.getAllValues().get(1); assertEquals(NAMESPACE, listUploadsRequest2.getNamespaceName()); assertEquals(BUCKET, listUploadsRequest2.getBucketName()); assertEquals(100, listUploadsRequest2.getLimit().intValue()); assertEquals(pageToken, listUploadsRequest2.getPage()); assertEquals(mockInvocationCallback, listUploadsRequest2.getInvocationCallback()); ArgumentCaptor<ListMultipartUploadPartsRequest> listPartsCaptor = ArgumentCaptor.forClass(ListMultipartUploadPartsRequest.class); verify(service, times(2)).listMultipartUploadParts(listPartsCaptor.capture()); ListMultipartUploadPartsRequest listPartsRequest1 = listPartsCaptor.getAllValues().get(0); assertEquals(NAMESPACE, listPartsRequest1.getNamespaceName()); assertEquals(BUCKET, listPartsRequest1.getBucketName()); assertEquals(uploadId, listPartsRequest1.getUploadId()); assertEquals(100, listPartsRequest1.getLimit().intValue()); assertEquals(mockInvocationCallback, listPartsRequest1.getInvocationCallback()); assertNull(listPartsRequest1.getPage()); ListMultipartUploadPartsRequest listPartsRequest2 = listPartsCaptor.getAllValues().get(1); assertEquals(NAMESPACE, listPartsRequest2.getNamespaceName()); assertEquals(BUCKET, listPartsRequest2.getBucketName()); assertEquals(uploadId, listPartsRequest2.getUploadId()); assertEquals(100, listPartsRequest2.getLimit().intValue()); assertEquals(pageToken, listPartsRequest2.getPage()); assertEquals(mockInvocationCallback, listPartsRequest2.getInvocationCallback()); }