You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2019/07/04 08:33:32 UTC
[james-project] 04/13: JAMES-2806 Add deleteBucket implementation
for memory and its contract
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 1a7e0588d24a86728dd04289c899fead15c78355
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Mon Jul 1 10:55:21 2019 +0700
JAMES-2806 Add deleteBucket implementation for memory and its contract
---
.../james/blob/api/BucketBlobStoreContract.java | 36 ++++++++++++++++++++++
.../apache/james/blob/memory/MemoryBlobStore.java | 11 ++++---
2 files changed, 43 insertions(+), 4 deletions(-)
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
index 4655bb0..d52d703 100644
--- 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
@@ -20,6 +20,7 @@
package org.apache.james.blob.api;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.ByteArrayInputStream;
@@ -39,6 +40,30 @@ public interface BucketBlobStoreContract {
BlobId.Factory blobIdFactory();
@Test
+ default void deleteBucketShouldThrowWhenNullBucketName() {
+ assertThatThrownBy(() -> testee().deleteBucket(null).block())
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ default void deleteBucketShouldDeleteExistingBucketWithItsData() {
+ BlobId blobId = testee().save(CUSTOM, SHORT_BYTEARRAY).block();
+ testee().deleteBucket(CUSTOM).block();
+
+ assertThatThrownBy(() -> testee().read(CUSTOM, blobId))
+ .isInstanceOf(ObjectStoreException.class);
+ }
+
+ @Test
+ default void deleteBucketShouldBeIdempotent(){
+ testee().save(CUSTOM, SHORT_BYTEARRAY).block();
+ testee().deleteBucket(CUSTOM).block();
+
+ assertThatCode(() -> testee().deleteBucket(CUSTOM).block())
+ .doesNotThrowAnyException();
+ }
+
+ @Test
default void saveBytesShouldThrowWhenNullBucketName() {
assertThatThrownBy(() -> testee().save(null, SHORT_BYTEARRAY).block())
.isInstanceOf(NullPointerException.class);
@@ -103,4 +128,15 @@ public interface BucketBlobStoreContract {
.operationCount(10)
.runSuccessfullyWithin(Duration.ofMinutes(1));
}
+
+ @Test
+ default void deleteBucketConcurrentlyShouldNotFail() throws Exception {
+ testee().save(CUSTOM, SHORT_BYTEARRAY).block();
+
+ ConcurrentTestRunner.builder()
+ .operation(((threadNumber, step) -> testee().deleteBucket(CUSTOM).block()))
+ .threadCount(10)
+ .operationCount(10)
+ .runSuccessfullyWithin(Duration.ofMinutes(1));
+ }
}
diff --git a/server/blob/blob-memory/src/main/java/org/apache/james/blob/memory/MemoryBlobStore.java b/server/blob/blob-memory/src/main/java/org/apache/james/blob/memory/MemoryBlobStore.java
index b7f907a..812ea3d 100644
--- a/server/blob/blob-memory/src/main/java/org/apache/james/blob/memory/MemoryBlobStore.java
+++ b/server/blob/blob-memory/src/main/java/org/apache/james/blob/memory/MemoryBlobStore.java
@@ -27,7 +27,6 @@ import java.util.Optional;
import javax.inject.Inject;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.NotImplementedException;
import org.apache.james.blob.api.BlobId;
import org.apache.james.blob.api.BlobStore;
import org.apache.james.blob.api.BucketName;
@@ -35,10 +34,8 @@ import org.apache.james.blob.api.ObjectStoreException;
import com.google.common.base.Preconditions;
import com.google.common.collect.HashBasedTable;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.Table;
-import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public class MemoryBlobStore implements BlobStore {
@@ -92,7 +89,13 @@ public class MemoryBlobStore implements BlobStore {
@Override
public Mono<Void> deleteBucket(BucketName bucketName) {
- throw new NotImplementedException("not implemented");
+ Preconditions.checkNotNull(bucketName);
+
+ return Mono.fromRunnable(() -> {
+ synchronized (blobs) {
+ blobs.row(bucketName).clear();
+ }
+ });
}
private byte[] retrieveStoredValue(BucketName bucketName, BlobId blobId) {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org