This is an automated email from the ASF dual-hosted git repository. aduprat pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 2672ea9c839bbaca795ebe0146bcfdaab7014a75 Author: Rene Cordier <rcord...@linagora.com> AuthorDate: Tue Jun 25 16:49:46 2019 +0700 JAMES-2806 add contract for BlobStore with custom buckets --- .../james/blob/api/BucketBlobStoreContract.java | 106 +++++++++++++++++++++ .../james/blob/memory/MemoryBlobStoreTest.java | 3 +- 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BucketBlobStoreContract.java b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BucketBlobStoreContract.java new file mode 100644 index 0000000..4655bb0 --- /dev/null +++ b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BucketBlobStoreContract.java @@ -0,0 +1,106 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.blob.api; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.time.Duration; + +import org.apache.james.util.concurrency.ConcurrentTestRunner; +import org.junit.jupiter.api.Test; + +public interface BucketBlobStoreContract { + String SHORT_STRING = "toto"; + byte[] SHORT_BYTEARRAY = SHORT_STRING.getBytes(StandardCharsets.UTF_8); + BucketName CUSTOM = BucketName.of("custom"); + + BlobStore testee(); + + BlobId.Factory blobIdFactory(); + + @Test + default void saveBytesShouldThrowWhenNullBucketName() { + assertThatThrownBy(() -> testee().save(null, SHORT_BYTEARRAY).block()) + .isInstanceOf(NullPointerException.class); + } + + @Test + default void saveStringShouldThrowWhenNullBucketName() { + assertThatThrownBy(() -> testee().save(null, SHORT_STRING).block()) + .isInstanceOf(NullPointerException.class); + } + + @Test + default void saveInputStreamShouldThrowWhenNullBucketName() { + assertThatThrownBy(() -> testee().save(null, new ByteArrayInputStream(SHORT_BYTEARRAY)).block()) + .isInstanceOf(NullPointerException.class); + } + + @Test + default void readShouldThrowWhenNullBucketName() { + BlobId blobId = testee().save(BucketName.DEFAULT, SHORT_BYTEARRAY).block(); + assertThatThrownBy(() -> testee().read(null, blobId)) + .isInstanceOf(NullPointerException.class); + } + + @Test + default void readBytesStreamShouldThrowWhenNullBucketName() { + BlobId blobId = testee().save(BucketName.DEFAULT, SHORT_BYTEARRAY).block(); + assertThatThrownBy(() -> testee().readBytes(null, blobId).block()) + .isInstanceOf(NullPointerException.class); + } + + @Test + default void readStringShouldThrowWhenBucketDoesNotExist() { + BlobId blobId = testee().save(BucketName.DEFAULT, SHORT_BYTEARRAY).block(); + assertThatThrownBy(() -> testee().read(CUSTOM, blobId)) + .isInstanceOf(ObjectStoreException.class); + } + + @Test + default void readBytesStreamShouldThrowWhenBucketDoesNotExist() { + BlobId blobId = testee().save(BucketName.DEFAULT, SHORT_BYTEARRAY).block(); + assertThatThrownBy(() -> testee().readBytes(CUSTOM, blobId).block()) + .isInstanceOf(ObjectStoreException.class); + } + + @Test + default void shouldBeAbleToSaveDataInMultipleBuckets() { + BlobId blobIdDefault = testee().save(BucketName.DEFAULT, SHORT_BYTEARRAY).block(); + BlobId blobIdCustom = testee().save(CUSTOM, SHORT_BYTEARRAY).block(); + + byte[] bytesDefault = testee().readBytes(BucketName.DEFAULT, blobIdDefault).block(); + byte[] bytesCustom = testee().readBytes(CUSTOM, blobIdCustom).block(); + + assertThat(bytesDefault).isEqualTo(bytesCustom); + } + + @Test + default void saveConcurrentlyWithNonPreExistingBucketShouldNotFail() throws Exception { + ConcurrentTestRunner.builder() + .operation(((threadNumber, step) -> testee().save(CUSTOM, SHORT_STRING + threadNumber + step).block())) + .threadCount(10) + .operationCount(10) + .runSuccessfullyWithin(Duration.ofMinutes(1)); + } +} diff --git a/server/blob/blob-memory/src/test/java/org/apache/james/blob/memory/MemoryBlobStoreTest.java b/server/blob/blob-memory/src/test/java/org/apache/james/blob/memory/MemoryBlobStoreTest.java index 6dbac34..721c198 100644 --- a/server/blob/blob-memory/src/test/java/org/apache/james/blob/memory/MemoryBlobStoreTest.java +++ b/server/blob/blob-memory/src/test/java/org/apache/james/blob/memory/MemoryBlobStoreTest.java @@ -21,12 +21,13 @@ package org.apache.james.blob.memory; import org.apache.james.blob.api.BlobId; import org.apache.james.blob.api.BlobStore; +import org.apache.james.blob.api.BucketBlobStoreContract; import org.apache.james.blob.api.HashBlobId; import org.apache.james.blob.api.MetricableBlobStore; import org.apache.james.blob.api.MetricableBlobStoreContract; import org.junit.jupiter.api.BeforeEach; -public class MemoryBlobStoreTest implements MetricableBlobStoreContract { +public class MemoryBlobStoreTest implements MetricableBlobStoreContract, BucketBlobStoreContract { private static final HashBlobId.Factory BLOB_ID_FACTORY = new HashBlobId.Factory(); private BlobStore blobStore; --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org