MultipartUploadS3StorageOutputStream extends OutputStream { @Override @Synchronized public void close() throws IOException { if (currentOutputStream == null) { return; } if (isMultiPartUpload()) { finishMultiPartUpload(); } else { finishSimpleUpload(); } } MultipartUploadS3StorageOutputStream(String bucketName, String objectKey, AmazonS3 amazonS3,
                                         ExecutorService executorService,
                                         List<? extends ResourceWriteCallback> callbacks); @Override @Synchronized void write(byte[] bytes, int off, int len); @Override @Synchronized void write(int b); @Override @Synchronized void close();  }
@Test @SneakyThrows void writeByteByByteNoChunked() { writeByteByByte(shortChunk); tested.close(); verify(executorService, never()).submit(any(UploadChunkResultCallable.class)); assertThat(bytesSentDirectly.getValue()).hasContent(new String(shortChunk)); }
@Test @SneakyThrows void writeByteByByteChunkedExactChunk() { writeByteByByte(exactOneMultipartChunk); tested.close(); assertThat(bytesSentDirectly.getAllValues()).isEmpty(); assertThat(uploadChunk.getAllValues()).hasSize(1); assertThat(uploadChunk.getAllValues().get(0).getInputStream()).hasContent(new String(exactOneMultipartChunk)); }
@Test @SneakyThrows void writeByteByByteChunked() { writeByteByByte(multipartChunkWithTail); tested.close(); assertThat(bytesSentDirectly.getAllValues()).isEmpty(); assertThat(uploadChunk.getAllValues()).hasSize(2); assertThat(uploadChunk.getAllValues().get(0).getInputStream()) .hasContent(new String(Arrays.copyOfRange(multipartChunkWithTail, 0, BUFFER_SIZE))); int partialPartSize = (int) uploadChunk.getAllValues().get(1).getPartSize(); byte[] partialChunk = new byte[partialPartSize]; ByteStreams.readFully(uploadChunk.getAllValues().get(1).getInputStream(), partialChunk, 0, partialPartSize); assertThat(new String(partialChunk)) .isEqualTo(new String(Arrays.copyOfRange( multipartChunkWithTail, BUFFER_SIZE, multipartChunkWithTail.length) ) ); }
@Test @SneakyThrows void writeZeroSized() { tested.close(); verify(executorService, never()).submit(any(UploadChunkResultCallable.class)); assertThat(bytesSentDirectly.getValue()).hasContent(""); }