@Override public CompletableFuture<BlobId> save(InputStream data) { return metricFactory .runPublishingTimerMetric(SAVE_INPUT_STREAM_TIMER_NAME, blobStoreImpl.save(data)); }
@Override public CompletableFuture<BlobId> save(byte[] data) { return metricFactory .runPublishingTimerMetric(SAVE_BYTES_TIMER_NAME, blobStoreImpl.save(data)); }
public CompletableFuture<Void> storeAttachmentAsync(Attachment attachment, MessageId ownerMessageId) { return blobStore.save(attachment.getBytes()) .thenApply(blobId -> CassandraAttachmentDAOV2.from(attachment, blobId)) .thenCompose(daoAttachment -> storeAttachmentWithIndex(daoAttachment, ownerMessageId)); }
@Test default void saveInputStreamShouldPublishSaveInputStreamTimerMetrics() { testee().save(new ByteArrayInputStream(BYTES_CONTENT)).join(); testee().save(new ByteArrayInputStream(BYTES_CONTENT)).join(); testee().save(new ByteArrayInputStream(BYTES_CONTENT)).join(); verify(metricsTestExtension.saveInputStreamTimeMetric, times(3)).stopAndPublish(); }
@Test void readBytesShouldReturnSplitSavedDataByChunk() { String longString = Strings.repeat("0123456789\n", MULTIPLE_CHUNK_SIZE); BlobId blobId = testee.save(longString.getBytes(StandardCharsets.UTF_8)).join(); byte[] bytes = testee.readBytes(blobId).join(); assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo(longString); }
@Test default void saveShouldThrowWhenNullData() { assertThatThrownBy(() -> testee().save((byte[]) null)) .isInstanceOf(NullPointerException.class); }
@Test default void saveShouldThrowWhenNullInputStream() { assertThatThrownBy(() -> testee().save((InputStream) null)) .isInstanceOf(NullPointerException.class); }
@Test default void saveShouldReturnBlobIdOfInputStream() { BlobId blobId = testee().save(new ByteArrayInputStream(SHORT_BYTEARRAY)).join(); assertThat(blobId).isEqualTo(blobIdFactory().from("31f7a65e315586ac198bd798b6629ce4903d0899476d5741a9f32e2e521b6a66")); }
@Test default void saveShouldSaveEmptyInputStream() { BlobId blobId = testee().save(new ByteArrayInputStream(EMPTY_BYTEARRAY)).join(); byte[] bytes = testee().readBytes(blobId).join(); assertThat(new String(bytes, StandardCharsets.UTF_8)).isEmpty(); }
@Test default void saveShouldReturnBlobId() { BlobId blobId = testee().save(SHORT_BYTEARRAY).join(); assertThat(blobId).isEqualTo(blobIdFactory().from("31f7a65e315586ac198bd798b6629ce4903d0899476d5741a9f32e2e521b6a66")); }
@Test default void saveShouldSaveEmptyData() { BlobId blobId = testee().save(EMPTY_BYTEARRAY).join(); byte[] bytes = testee().readBytes(blobId).join(); assertThat(new String(bytes, StandardCharsets.UTF_8)).isEmpty(); }
@Test default void readBytesShouldReturnLongSavedData() { BlobId blobId = testee().save(ELEVEN_KILOBYTES).join(); byte[] bytes = testee().readBytes(blobId).join(); assertThat(bytes).isEqualTo(ELEVEN_KILOBYTES); }
@Test default void readBytesShouldReturnSavedData() { BlobId blobId = testee().save(SHORT_BYTEARRAY).join(); byte[] bytes = testee().readBytes(blobId).join(); assertThat(bytes).isEqualTo(SHORT_BYTEARRAY); }
@Test default void readShouldReturnSavedData() { BlobId blobId = testee().save(SHORT_BYTEARRAY).join(); InputStream read = testee().read(blobId); assertThat(read).hasSameContentAs(new ByteArrayInputStream(SHORT_BYTEARRAY)); }
@Test default void readShouldReturnBigSavedData() { // 12 MB of text BlobId blobId = testee().save(TWELVE_MEGABYTES).join(); InputStream read = testee().read(blobId); assertThat(read).hasSameContentAs(new ByteArrayInputStream(TWELVE_MEGABYTES)); } }
@Test default void readBytesShouldReturnBigSavedData() { BlobId blobId = testee().save(TWELVE_MEGABYTES).join(); byte[] bytes = testee().readBytes(blobId).join(); assertThat(bytes).isEqualTo(TWELVE_MEGABYTES); }
@Test default void readShouldReturnLongSavedData() { BlobId blobId = testee().save(ELEVEN_KILOBYTES).join(); InputStream read = testee().read(blobId); assertThat(read).hasSameContentAs(new ByteArrayInputStream(ELEVEN_KILOBYTES)); }
@Test default void readBytesShouldPublishReadBytesTimerMetrics() { BlobId blobId = testee().save(BYTES_CONTENT).join(); testee().readBytes(blobId).join(); testee().readBytes(blobId).join(); verify(metricsTestExtension.readBytesTimeMetric, times(2)).stopAndPublish(); }
@Test default void readShouldPublishReadTimerMetrics() { BlobId blobId = testee().save(BYTES_CONTENT).join(); testee().read(blobId); testee().read(blobId); verify(metricsTestExtension.readTimeMetric, times(2)).stopAndPublish(); } }