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 bt...@apache.org on 2019/07/01 07:00:17 UTC
[james-project] 04/06: JAMES-2806 add BucketName in BlobStore read
This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit b0858e33595d996cc33f62e90047e81c43ef29b3
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Tue Jun 25 11:11:12 2019 +0700
JAMES-2806 add BucketName in BlobStore read
---
.../cassandra/mail/CassandraAttachmentMapper.java | 2 +-
.../cassandra/mail/CassandraMessageDAO.java | 2 +-
.../mail/migration/AttachmentV2MigrationTest.java | 6 +--
.../java/org/apache/james/blob/api/BlobStore.java | 4 +-
.../apache/james/blob/api/MetricableBlobStore.java | 8 ++--
.../main/java/org/apache/james/blob/api/Store.java | 2 +-
.../apache/james/blob/api/BlobStoreContract.java | 22 ++++-----
.../blob/api/MetricableBlobStoreContract.java | 8 ++--
.../james/blob/cassandra/CassandraBlobsDAO.java | 4 +-
.../blob/cassandra/CassandraBlobsDAOTest.java | 4 +-
.../export/file/LocalFileBlobExportMechanism.java | 3 +-
.../apache/james/blob/memory/MemoryBlobStore.java | 4 +-
.../blob/objectstorage/ObjectStorageBlobsDAO.java | 6 +--
.../ObjectStorageBlobsDAOContract.java | 2 +-
.../objectstorage/ObjectStorageBlobsDAOTest.java | 8 ++--
.../apache/james/blob/union/UnionBlobStore.java | 24 +++++-----
.../james/blob/union/UnionBlobStoreTest.java | 56 +++++++++++-----------
.../james/blob/mail/MimeMessageStoreTest.java | 5 +-
.../routes/DeletedMessagesVaultRoutesTest.java | 3 +-
.../linshare/LinshareBlobExportMechanism.java | 3 +-
20 files changed, 90 insertions(+), 86 deletions(-)
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
index f9c69cd..38f840e 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
@@ -80,7 +80,7 @@ public class CassandraAttachmentMapper implements AttachmentMapper {
}
private Mono<Attachment> retrievePayload(DAOAttachment daoAttachment) {
- return blobStore.readBytes(daoAttachment.getBlobId())
+ return blobStore.readBytes(BucketName.DEFAULT, daoAttachment.getBlobId())
.map(daoAttachment::toAttachment);
}
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
index c6435d2..8457cbd 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
@@ -359,7 +359,7 @@ public class CassandraMessageDAO {
}
private Mono<byte[]> getFieldContent(String field, Row row) {
- return blobStore.readBytes(blobIdFactory.from(row.getString(field)));
+ return blobStore.readBytes(BucketName.DEFAULT, blobIdFactory.from(row.getString(field)));
}
public static MessageResult notFound(ComposedMessageIdWithMetaData id) {
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2MigrationTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2MigrationTest.java
index 70f7b3f..d3ec71f 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2MigrationTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/AttachmentV2MigrationTest.java
@@ -114,9 +114,9 @@ class AttachmentV2MigrationTest {
.contains(CassandraAttachmentDAOV2.from(attachment1, BLOB_ID_FACTORY.forPayload(attachment1.getBytes())));
assertThat(attachmentDAOV2.getAttachment(ATTACHMENT_ID_2).blockOptional())
.contains(CassandraAttachmentDAOV2.from(attachment2, BLOB_ID_FACTORY.forPayload(attachment2.getBytes())));
- assertThat(blobsDAO.readBytes(BLOB_ID_FACTORY.forPayload(attachment1.getBytes())).block())
+ assertThat(blobsDAO.readBytes(BucketName.DEFAULT, BLOB_ID_FACTORY.forPayload(attachment1.getBytes())).block())
.isEqualTo(attachment1.getBytes());
- assertThat(blobsDAO.readBytes(BLOB_ID_FACTORY.forPayload(attachment2.getBytes())).block())
+ assertThat(blobsDAO.readBytes(BucketName.DEFAULT, BLOB_ID_FACTORY.forPayload(attachment2.getBytes())).block())
.isEqualTo(attachment2.getBytes());
}
@@ -155,7 +155,7 @@ class AttachmentV2MigrationTest {
when(attachmentDAO.retrieveAll()).thenReturn(Flux.just(
attachment1,
attachment2));
- when(blobsDAO.save(BucketName.DEFAULT, any(byte[].class))).thenThrow(new RuntimeException());
+ when(blobsDAO.save(any(BucketName.class), any(byte[].class))).thenThrow(new RuntimeException());
assertThat(migration.run()).isEqualTo(Migration.Result.PARTIAL);
}
diff --git a/server/blob/blob-api/src/main/java/org/apache/james/blob/api/BlobStore.java b/server/blob/blob-api/src/main/java/org/apache/james/blob/api/BlobStore.java
index bcb9357..ed7f6f7 100644
--- a/server/blob/blob-api/src/main/java/org/apache/james/blob/api/BlobStore.java
+++ b/server/blob/blob-api/src/main/java/org/apache/james/blob/api/BlobStore.java
@@ -29,9 +29,9 @@ public interface BlobStore {
Mono<BlobId> save(BucketName bucketName, InputStream data);
- Mono<byte[]> readBytes(BlobId blobId);
+ Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId);
- InputStream read(BlobId blobId);
+ InputStream read(BucketName bucketName, BlobId blobId);
default Mono<BlobId> save(BucketName bucketName, String data) {
return save(bucketName, data.getBytes(StandardCharsets.UTF_8));
diff --git a/server/blob/blob-api/src/main/java/org/apache/james/blob/api/MetricableBlobStore.java b/server/blob/blob-api/src/main/java/org/apache/james/blob/api/MetricableBlobStore.java
index 2f0218f..3976bcd 100644
--- a/server/blob/blob-api/src/main/java/org/apache/james/blob/api/MetricableBlobStore.java
+++ b/server/blob/blob-api/src/main/java/org/apache/james/blob/api/MetricableBlobStore.java
@@ -60,14 +60,14 @@ public class MetricableBlobStore implements BlobStore {
}
@Override
- public Mono<byte[]> readBytes(BlobId blobId) {
+ public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
return metricFactory
- .runPublishingTimerMetric(READ_BYTES_TIMER_NAME, blobStoreImpl.readBytes(blobId));
+ .runPublishingTimerMetric(READ_BYTES_TIMER_NAME, blobStoreImpl.readBytes(bucketName, blobId));
}
@Override
- public InputStream read(BlobId blobId) {
+ public InputStream read(BucketName bucketName, BlobId blobId) {
return metricFactory
- .runPublishingTimerMetric(READ_TIMER_NAME, () -> blobStoreImpl.read(blobId));
+ .runPublishingTimerMetric(READ_TIMER_NAME, () -> blobStoreImpl.read(bucketName, blobId));
}
}
diff --git a/server/blob/blob-api/src/main/java/org/apache/james/blob/api/Store.java b/server/blob/blob-api/src/main/java/org/apache/james/blob/api/Store.java
index 5e87b7f..6a4f859 100644
--- a/server/blob/blob-api/src/main/java/org/apache/james/blob/api/Store.java
+++ b/server/blob/blob-api/src/main/java/org/apache/james/blob/api/Store.java
@@ -104,7 +104,7 @@ public interface Store<T, I> {
return Flux.fromIterable(blobIds.asMap().entrySet())
.publishOn(Schedulers.elastic())
.flatMapSequential(
- entry -> blobStore.readBytes(entry.getValue())
+ entry -> blobStore.readBytes(BucketName.DEFAULT, entry.getValue())
.zipWith(Mono.just(entry.getKey())))
.map(entry -> Pair.of(entry.getT2(), entry.getT1()))
.collectList()
diff --git a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobStoreContract.java b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobStoreContract.java
index 55cc049..34ef95e 100644
--- a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobStoreContract.java
+++ b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/BlobStoreContract.java
@@ -64,7 +64,7 @@ public interface BlobStoreContract {
default void saveShouldSaveEmptyData() {
BlobId blobId = testee().save(BucketName.DEFAULT, EMPTY_BYTEARRAY).block();
- byte[] bytes = testee().readBytes(blobId).block();
+ byte[] bytes = testee().readBytes(BucketName.DEFAULT, blobId).block();
assertThat(new String(bytes, StandardCharsets.UTF_8)).isEmpty();
}
@@ -73,7 +73,7 @@ public interface BlobStoreContract {
default void saveShouldSaveEmptyString() {
BlobId blobId = testee().save(BucketName.DEFAULT, new String()).block();
- byte[] bytes = testee().readBytes(blobId).block();
+ byte[] bytes = testee().readBytes(BucketName.DEFAULT, blobId).block();
assertThat(new String(bytes, StandardCharsets.UTF_8)).isEmpty();
}
@@ -82,7 +82,7 @@ public interface BlobStoreContract {
default void saveShouldSaveEmptyInputStream() {
BlobId blobId = testee().save(BucketName.DEFAULT, new ByteArrayInputStream(EMPTY_BYTEARRAY)).block();
- byte[] bytes = testee().readBytes(blobId).block();
+ byte[] bytes = testee().readBytes(BucketName.DEFAULT, blobId).block();
assertThat(new String(bytes, StandardCharsets.UTF_8)).isEmpty();
}
@@ -111,7 +111,7 @@ public interface BlobStoreContract {
@Test
default void readBytesShouldThrowWhenNoExisting() {
- assertThatThrownBy(() -> testee().readBytes(blobIdFactory().from("unknown")).block())
+ assertThatThrownBy(() -> testee().readBytes(BucketName.DEFAULT, blobIdFactory().from("unknown")).block())
.isExactlyInstanceOf(ObjectStoreException.class);
}
@@ -119,7 +119,7 @@ public interface BlobStoreContract {
default void readBytesShouldReturnSavedData() {
BlobId blobId = testee().save(BucketName.DEFAULT, SHORT_BYTEARRAY).block();
- byte[] bytes = testee().readBytes(blobId).block();
+ byte[] bytes = testee().readBytes(BucketName.DEFAULT, blobId).block();
assertThat(bytes).isEqualTo(SHORT_BYTEARRAY);
}
@@ -128,7 +128,7 @@ public interface BlobStoreContract {
default void readBytesShouldReturnLongSavedData() {
BlobId blobId = testee().save(BucketName.DEFAULT, ELEVEN_KILOBYTES).block();
- byte[] bytes = testee().readBytes(blobId).block();
+ byte[] bytes = testee().readBytes(BucketName.DEFAULT, blobId).block();
assertThat(bytes).isEqualTo(ELEVEN_KILOBYTES);
}
@@ -137,14 +137,14 @@ public interface BlobStoreContract {
default void readBytesShouldReturnBigSavedData() {
BlobId blobId = testee().save(BucketName.DEFAULT, TWELVE_MEGABYTES).block();
- byte[] bytes = testee().readBytes(blobId).block();
+ byte[] bytes = testee().readBytes(BucketName.DEFAULT, blobId).block();
assertThat(bytes).isEqualTo(TWELVE_MEGABYTES);
}
@Test
default void readShouldThrowWhenNoExistingStream() {
- assertThatThrownBy(() -> testee().read(blobIdFactory().from("unknown")))
+ assertThatThrownBy(() -> testee().read(BucketName.DEFAULT, blobIdFactory().from("unknown")))
.isInstanceOf(ObjectStoreException.class);
}
@@ -152,7 +152,7 @@ public interface BlobStoreContract {
default void readShouldReturnSavedData() {
BlobId blobId = testee().save(BucketName.DEFAULT, SHORT_BYTEARRAY).block();
- InputStream read = testee().read(blobId);
+ InputStream read = testee().read(BucketName.DEFAULT, blobId);
assertThat(read).hasSameContentAs(new ByteArrayInputStream(SHORT_BYTEARRAY));
}
@@ -161,7 +161,7 @@ public interface BlobStoreContract {
default void readShouldReturnLongSavedData() {
BlobId blobId = testee().save(BucketName.DEFAULT, ELEVEN_KILOBYTES).block();
- InputStream read = testee().read(blobId);
+ InputStream read = testee().read(BucketName.DEFAULT, blobId);
assertThat(read).hasSameContentAs(new ByteArrayInputStream(ELEVEN_KILOBYTES));
}
@@ -171,7 +171,7 @@ public interface BlobStoreContract {
// 12 MB of text
BlobId blobId = testee().save(BucketName.DEFAULT, TWELVE_MEGABYTES).block();
- InputStream read = testee().read(blobId);
+ InputStream read = testee().read(BucketName.DEFAULT, blobId);
assertThat(read).hasSameContentAs(new ByteArrayInputStream(TWELVE_MEGABYTES));
}
diff --git a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/MetricableBlobStoreContract.java b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/MetricableBlobStoreContract.java
index 11c3c22..74a30ff 100644
--- a/server/blob/blob-api/src/test/java/org/apache/james/blob/api/MetricableBlobStoreContract.java
+++ b/server/blob/blob-api/src/test/java/org/apache/james/blob/api/MetricableBlobStoreContract.java
@@ -85,8 +85,8 @@ public interface MetricableBlobStoreContract extends BlobStoreContract {
@Test
default void readBytesShouldPublishReadBytesTimerMetrics() {
BlobId blobId = testee().save(BucketName.DEFAULT, BYTES_CONTENT).block();
- testee().readBytes(blobId).block();
- testee().readBytes(blobId).block();
+ testee().readBytes(BucketName.DEFAULT, blobId).block();
+ testee().readBytes(BucketName.DEFAULT, blobId).block();
assertThat(metricsTestExtension.getMetricFactory().executionTimesFor(READ_BYTES_TIMER_NAME))
.hasSize(2);
@@ -95,8 +95,8 @@ public interface MetricableBlobStoreContract extends BlobStoreContract {
@Test
default void readShouldPublishReadTimerMetrics() {
BlobId blobId = testee().save(BucketName.DEFAULT, BYTES_CONTENT).block();
- testee().read(blobId);
- testee().read(blobId);
+ testee().read(BucketName.DEFAULT, blobId);
+ testee().read(BucketName.DEFAULT, blobId);
assertThat(metricsTestExtension.getMetricFactory().executionTimesFor(READ_TIMER_NAME))
.hasSize(2);
diff --git a/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/CassandraBlobsDAO.java b/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/CassandraBlobsDAO.java
index aa8f233..23be4e5 100644
--- a/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/CassandraBlobsDAO.java
+++ b/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/CassandraBlobsDAO.java
@@ -164,7 +164,7 @@ public class CassandraBlobsDAO implements BlobStore {
}
@Override
- public Mono<byte[]> readBytes(BlobId blobId) {
+ public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
return readBlobParts(blobId)
.collectList()
.map(parts -> Bytes.concat(parts.toArray(new byte[0][])));
@@ -194,7 +194,7 @@ public class CassandraBlobsDAO implements BlobStore {
}
@Override
- public InputStream read(BlobId blobId) {
+ public InputStream read(BucketName bucketName, BlobId blobId) {
PipedInputStream pipedInputStream = new PipedInputStream();
readBlobParts(blobId)
.subscribe(new PipedStreamSubscriber(pipedInputStream));
diff --git a/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/CassandraBlobsDAOTest.java b/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/CassandraBlobsDAOTest.java
index 375e577..758ad7e 100644
--- a/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/CassandraBlobsDAOTest.java
+++ b/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/CassandraBlobsDAOTest.java
@@ -75,7 +75,7 @@ public class CassandraBlobsDAOTest implements MetricableBlobStoreContract {
String longString = Strings.repeat("0123456789\n", MULTIPLE_CHUNK_SIZE);
BlobId blobId = testee.save(BucketName.DEFAULT, longString).block();
- byte[] bytes = testee.readBytes(blobId).block();
+ byte[] bytes = testee.readBytes(BucketName.DEFAULT, blobId).block();
assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo(longString);
}
@@ -83,7 +83,7 @@ public class CassandraBlobsDAOTest implements MetricableBlobStoreContract {
@Test
void blobStoreShouldSupport100MBBlob() {
BlobId blobId = testee.save(BucketName.DEFAULT, new ZeroedInputStream(100_000_000)).block();
- InputStream bytes = testee.read(blobId);
+ InputStream bytes = testee.read(BucketName.DEFAULT, blobId);
assertThat(bytes).hasSameContentAs(new ZeroedInputStream(100_000_000));
}
diff --git a/server/blob/blob-export-file/src/main/java/org/apache/james/blob/export/file/LocalFileBlobExportMechanism.java b/server/blob/blob-export-file/src/main/java/org/apache/james/blob/export/file/LocalFileBlobExportMechanism.java
index 15add95..d6b047e 100644
--- a/server/blob/blob-export-file/src/main/java/org/apache/james/blob/export/file/LocalFileBlobExportMechanism.java
+++ b/server/blob/blob-export-file/src/main/java/org/apache/james/blob/export/file/LocalFileBlobExportMechanism.java
@@ -30,6 +30,7 @@ import javax.inject.Inject;
import org.apache.commons.io.FileUtils;
import org.apache.james.blob.api.BlobId;
import org.apache.james.blob.api.BlobStore;
+import org.apache.james.blob.api.BucketName;
import org.apache.james.blob.export.api.BlobExportMechanism;
import org.apache.james.blob.export.api.ExportedFileNamesGenerator;
import org.apache.james.blob.export.api.FileExtension;
@@ -120,7 +121,7 @@ public class LocalFileBlobExportMechanism implements BlobExportMechanism {
String fileName = ExportedFileNamesGenerator.generateFileName(fileCustomPrefix, blobId, fileExtension);
String fileURL = configuration.exportDirectory + "/" + fileName;
File file = fileSystem.getFile(fileURL);
- FileUtils.copyToFile(blobStore.read(blobId), file);
+ FileUtils.copyToFile(blobStore.read(BucketName.DEFAULT, blobId), file);
return file.getAbsolutePath();
} catch (IOException e) {
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 7173afa..173ce78 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
@@ -69,12 +69,12 @@ public class MemoryBlobStore implements BlobStore {
}
@Override
- public Mono<byte[]> readBytes(BlobId blobId) {
+ public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
return Mono.fromCallable(() -> retrieveStoredValue(blobId));
}
@Override
- public InputStream read(BlobId blobId) {
+ public InputStream read(BucketName bucketName, BlobId blobId) {
return new ByteArrayInputStream(retrieveStoredValue(blobId));
}
diff --git a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
index ef00893..7bbd2da 100644
--- a/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
+++ b/server/blob/blob-objectstorage/src/main/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAO.java
@@ -126,12 +126,12 @@ public class ObjectStorageBlobsDAO implements BlobStore {
}
@Override
- public Mono<byte[]> readBytes(BlobId blobId) {
- return Mono.fromCallable(() -> IOUtils.toByteArray(read(blobId)));
+ public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
+ return Mono.fromCallable(() -> IOUtils.toByteArray(read(bucketName, blobId)));
}
@Override
- public InputStream read(BlobId blobId) throws ObjectStoreException {
+ public InputStream read(BucketName bucketName, BlobId blobId) throws ObjectStoreException {
Blob blob = blobStore.getBlob(containerName.value(), blobId.asString());
try {
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java
index 66d0f36..8f7e868 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOContract.java
@@ -41,7 +41,7 @@ public interface ObjectStorageBlobsDAOContract {
BlobId blobId = dao.save(BucketName.DEFAULT, CONTENT).block();
- InputStream inputStream = dao.read(blobId);
+ InputStream inputStream = dao.read(BucketName.DEFAULT, blobId);
assertThat(inputStream).hasSameContentAs(IOUtils.toInputStream(CONTENT, StandardCharsets.UTF_8));
}
}
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
index da75e96..e0214ee 100644
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
+++ b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/ObjectStorageBlobsDAOTest.java
@@ -137,7 +137,7 @@ public class ObjectStorageBlobsDAOTest implements MetricableBlobStoreContract {
String content = "James is the best!";
BlobId blobId = encryptedDao.save(BucketName.DEFAULT, content).block();
- InputStream read = encryptedDao.read(blobId);
+ InputStream read = encryptedDao.read(BucketName.DEFAULT, blobId);
String expectedContent = IOUtils.toString(read, Charsets.UTF_8);
assertThat(content).isEqualTo(expectedContent);
}
@@ -153,12 +153,12 @@ public class ObjectStorageBlobsDAOTest implements MetricableBlobStoreContract {
String content = "James is the best!";
BlobId blobId = encryptedDao.save(BucketName.DEFAULT, content).block();
- InputStream encryptedIs = testee.read(blobId);
+ InputStream encryptedIs = testee.read(BucketName.DEFAULT, blobId);
assertThat(encryptedIs).isNotNull();
String encryptedString = IOUtils.toString(encryptedIs, Charsets.UTF_8);
assertThat(encryptedString).isNotEqualTo(content);
- InputStream clearTextIs = encryptedDao.read(blobId);
+ InputStream clearTextIs = encryptedDao.read(BucketName.DEFAULT, blobId);
String expectedContent = IOUtils.toString(clearTextIs, Charsets.UTF_8);
assertThat(content).isEqualTo(expectedContent);
}
@@ -198,7 +198,7 @@ public class ObjectStorageBlobsDAOTest implements MetricableBlobStoreContract {
@Test
void readBytesShouldNotCompleteWhenDoesNotAwait() {
BlobId blobId = testee().save(BucketName.DEFAULT, BIG_STRING).block();
- Mono<byte[]> resultFuture = testee.readBytes(blobId).subscribeOn(Schedulers.elastic());
+ Mono<byte[]> resultFuture = testee.readBytes(BucketName.DEFAULT, blobId).subscribeOn(Schedulers.elastic());
assertThat(resultFuture.toFuture()).isNotCompleted();
}
}
diff --git a/server/blob/blob-union/src/main/java/org/apache/james/blob/union/UnionBlobStore.java b/server/blob/blob-union/src/main/java/org/apache/james/blob/union/UnionBlobStore.java
index a4aceb8..3f14fd0 100644
--- a/server/blob/blob-union/src/main/java/org/apache/james/blob/union/UnionBlobStore.java
+++ b/server/blob/blob-union/src/main/java/org/apache/james/blob/union/UnionBlobStore.java
@@ -118,31 +118,31 @@ public class UnionBlobStore implements BlobStore {
}
@Override
- public Mono<byte[]> readBytes(BlobId blobId) {
+ public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
try {
- return readBytesFallBackIfFailsOrEmptyResult(blobId);
+ return readBytesFallBackIfFailsOrEmptyResult(bucketName, blobId);
} catch (Exception e) {
LOGGER.error("exception directly happens while readBytes, fall back to legacy blob store", e);
- return Mono.defer(() -> legacyBlobStore.readBytes(blobId));
+ return Mono.defer(() -> legacyBlobStore.readBytes(bucketName, blobId));
}
}
@Override
- public InputStream read(BlobId blobId) {
+ public InputStream read(BucketName bucketName, BlobId blobId) {
try {
- return readFallBackIfEmptyResult(blobId);
+ return readFallBackIfEmptyResult(bucketName, blobId);
} catch (Exception e) {
LOGGER.error("exception directly happens while read, fall back to legacy blob store", e);
- return legacyBlobStore.read(blobId);
+ return legacyBlobStore.read(bucketName, blobId);
}
}
- private InputStream readFallBackIfEmptyResult(BlobId blobId) {
- return Optional.ofNullable(currentBlobStore.read(blobId))
+ private InputStream readFallBackIfEmptyResult(BucketName bucketName, BlobId blobId) {
+ return Optional.ofNullable(currentBlobStore.read(bucketName, blobId))
.map(PushbackInputStream::new)
.filter(Throwing.predicate(this::streamHasContent).sneakyThrow())
.<InputStream>map(Function.identity())
- .orElseGet(() -> legacyBlobStore.read(blobId));
+ .orElseGet(() -> legacyBlobStore.read(bucketName, blobId));
}
@VisibleForTesting
@@ -155,10 +155,10 @@ public class UnionBlobStore implements BlobStore {
return false;
}
- private Mono<byte[]> readBytesFallBackIfFailsOrEmptyResult(BlobId blobId) {
- return Mono.defer(() -> currentBlobStore.readBytes(blobId))
+ private Mono<byte[]> readBytesFallBackIfFailsOrEmptyResult(BucketName bucketName, BlobId blobId) {
+ return Mono.defer(() -> currentBlobStore.readBytes(bucketName, blobId))
.onErrorResume(this::logAndReturnEmpty)
- .switchIfEmpty(legacyBlobStore.readBytes(blobId));
+ .switchIfEmpty(legacyBlobStore.readBytes(bucketName, blobId));
}
private Mono<BlobId> saveToCurrentFallbackIfFails(
diff --git a/server/blob/blob-union/src/test/java/org/apache/james/blob/union/UnionBlobStoreTest.java b/server/blob/blob-union/src/test/java/org/apache/james/blob/union/UnionBlobStoreTest.java
index 182e568..cba98da 100644
--- a/server/blob/blob-union/src/test/java/org/apache/james/blob/union/UnionBlobStoreTest.java
+++ b/server/blob/blob-union/src/test/java/org/apache/james/blob/union/UnionBlobStoreTest.java
@@ -72,12 +72,12 @@ class UnionBlobStoreTest implements BlobStoreContract {
}
@Override
- public Mono<byte[]> readBytes(BlobId blobId) {
+ public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
return Mono.error(new RuntimeException("broken everywhere"));
}
@Override
- public InputStream read(BlobId blobId) {
+ public InputStream read(BucketName bucketName, BlobId blobId) {
throw new RuntimeException("broken everywhere");
}
@@ -106,12 +106,12 @@ class UnionBlobStoreTest implements BlobStoreContract {
}
@Override
- public Mono<byte[]> readBytes(BlobId blobId) {
+ public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
throw new RuntimeException("broken everywhere");
}
@Override
- public InputStream read(BlobId blobId) {
+ public InputStream read(BucketName bucketName, BlobId blobId) {
throw new RuntimeException("broken everywhere");
}
@@ -163,9 +163,9 @@ class UnionBlobStoreTest implements BlobStoreContract {
BlobId blobId = unionBlobStore.save(BucketName.DEFAULT, BLOB_CONTENT).block();
SoftAssertions.assertSoftly(softly -> {
- softly.assertThat(unionBlobStore.read(blobId))
+ softly.assertThat(unionBlobStore.read(BucketName.DEFAULT, blobId))
.hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
- softly.assertThat(legacyBlobStore.read(blobId))
+ softly.assertThat(legacyBlobStore.read(BucketName.DEFAULT, blobId))
.hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
});
}
@@ -180,9 +180,9 @@ class UnionBlobStoreTest implements BlobStoreContract {
BlobId blobId = unionBlobStore.save(BucketName.DEFAULT, new ByteArrayInputStream(BLOB_CONTENT)).block();
SoftAssertions.assertSoftly(softly -> {
- softly.assertThat(unionBlobStore.read(blobId))
+ softly.assertThat(unionBlobStore.read(BucketName.DEFAULT, blobId))
.hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
- softly.assertThat(legacyBlobStore.read(blobId))
+ softly.assertThat(legacyBlobStore.read(BucketName.DEFAULT, blobId))
.hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
});
}
@@ -201,9 +201,9 @@ class UnionBlobStoreTest implements BlobStoreContract {
BlobId blobId = unionBlobStore.save(BucketName.DEFAULT, BLOB_CONTENT).block();
SoftAssertions.assertSoftly(softly -> {
- softly.assertThat(unionBlobStore.read(blobId))
+ softly.assertThat(unionBlobStore.read(BucketName.DEFAULT, blobId))
.hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
- softly.assertThat(legacyBlobStore.read(blobId))
+ softly.assertThat(legacyBlobStore.read(BucketName.DEFAULT, blobId))
.hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
});
}
@@ -218,9 +218,9 @@ class UnionBlobStoreTest implements BlobStoreContract {
BlobId blobId = unionBlobStore.save(BucketName.DEFAULT, new ByteArrayInputStream(BLOB_CONTENT)).block();
SoftAssertions.assertSoftly(softly -> {
- softly.assertThat(unionBlobStore.read(blobId))
+ softly.assertThat(unionBlobStore.read(BucketName.DEFAULT, blobId))
.hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
- softly.assertThat(legacyBlobStore.read(blobId))
+ softly.assertThat(legacyBlobStore.read(BucketName.DEFAULT, blobId))
.hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
});
}
@@ -239,7 +239,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
.build();
BlobId blobId = legacyBlobStore.save(BucketName.DEFAULT, BLOB_CONTENT).block();
- assertThat(unionBlobStore.read(blobId))
+ assertThat(unionBlobStore.read(BucketName.DEFAULT, blobId))
.hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
}
@@ -253,7 +253,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
.build();
BlobId blobId = legacyBlobStore.save(BucketName.DEFAULT, BLOB_CONTENT).block();
- assertThat(unionBlobStore.readBytes(blobId).block())
+ assertThat(unionBlobStore.readBytes(BucketName.DEFAULT, blobId).block())
.isEqualTo(BLOB_CONTENT);
}
@@ -271,7 +271,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
.build();
BlobId blobId = legacyBlobStore.save(BucketName.DEFAULT, BLOB_CONTENT).block();
- assertThat(unionBlobStore.read(blobId))
+ assertThat(unionBlobStore.read(BucketName.DEFAULT, blobId))
.hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
}
@@ -284,7 +284,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
.build();
BlobId blobId = legacyBlobStore.save(BucketName.DEFAULT, BLOB_CONTENT).block();
- assertThat(unionBlobStore.readBytes(blobId).block())
+ assertThat(unionBlobStore.readBytes(BucketName.DEFAULT, blobId).block())
.isEqualTo(BLOB_CONTENT);
}
}
@@ -299,12 +299,12 @@ class UnionBlobStoreTest implements BlobStoreContract {
blobStore -> blobStore.save(BucketName.DEFAULT, BLOB_CONTENT),
blobStore -> blobStore.save(BucketName.DEFAULT, STRING_CONTENT),
blobStore -> blobStore.save(BucketName.DEFAULT, new ByteArrayInputStream(BLOB_CONTENT)),
- blobStore -> blobStore.readBytes(BLOB_ID_FACTORY.randomId()));
+ blobStore -> blobStore.readBytes(BucketName.DEFAULT, BLOB_ID_FACTORY.randomId()));
}
Stream<Function<UnionBlobStore, InputStream>> blobStoreOperationsNotReturnFutures() {
return Stream.of(
- blobStore -> blobStore.read(BLOB_ID_FACTORY.randomId()));
+ blobStore -> blobStore.read(BucketName.DEFAULT, BLOB_ID_FACTORY.randomId()));
}
Stream<Arguments> blobStoresCauseReturnExceptionallyFutures() {
@@ -362,7 +362,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
void readShouldReturnFromCurrentWhenAvailable() {
BlobId blobId = currentBlobStore.save(BucketName.DEFAULT, BLOB_CONTENT).block();
- assertThat(unionBlobStore.read(blobId))
+ assertThat(unionBlobStore.read(BucketName.DEFAULT, blobId))
.hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
}
@@ -370,7 +370,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
void readShouldReturnFromLegacyWhenCurrentNotAvailable() {
BlobId blobId = legacyBlobStore.save(BucketName.DEFAULT, BLOB_CONTENT).block();
- assertThat(unionBlobStore.read(blobId))
+ assertThat(unionBlobStore.read(BucketName.DEFAULT, blobId))
.hasSameContentAs(new ByteArrayInputStream(BLOB_CONTENT));
}
@@ -378,7 +378,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
void readBytesShouldReturnFromCurrentWhenAvailable() {
BlobId blobId = currentBlobStore.save(BucketName.DEFAULT, BLOB_CONTENT).block();
- assertThat(unionBlobStore.readBytes(blobId).block())
+ assertThat(unionBlobStore.readBytes(BucketName.DEFAULT, blobId).block())
.isEqualTo(BLOB_CONTENT);
}
@@ -386,7 +386,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
void readBytesShouldReturnFromLegacyWhenCurrentNotAvailable() {
BlobId blobId = legacyBlobStore.save(BucketName.DEFAULT, BLOB_CONTENT).block();
- assertThat(unionBlobStore.readBytes(blobId).block())
+ assertThat(unionBlobStore.readBytes(BucketName.DEFAULT, blobId).block())
.isEqualTo(BLOB_CONTENT);
}
@@ -394,7 +394,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
void saveShouldWriteToCurrent() {
BlobId blobId = unionBlobStore.save(BucketName.DEFAULT, BLOB_CONTENT).block();
- assertThat(currentBlobStore.readBytes(blobId).block())
+ assertThat(currentBlobStore.readBytes(BucketName.DEFAULT, blobId).block())
.isEqualTo(BLOB_CONTENT);
}
@@ -402,7 +402,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
void saveShouldNotWriteToLegacy() {
BlobId blobId = unionBlobStore.save(BucketName.DEFAULT, BLOB_CONTENT).block();
- assertThatThrownBy(() -> legacyBlobStore.readBytes(blobId).block())
+ assertThatThrownBy(() -> legacyBlobStore.readBytes(BucketName.DEFAULT, blobId).block())
.isInstanceOf(ObjectStoreException.class);
}
@@ -410,7 +410,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
void saveStringShouldWriteToCurrent() {
BlobId blobId = unionBlobStore.save(BucketName.DEFAULT, STRING_CONTENT).block();
- assertThat(currentBlobStore.readBytes(blobId).block())
+ assertThat(currentBlobStore.readBytes(BucketName.DEFAULT, blobId).block())
.isEqualTo(BLOB_CONTENT);
}
@@ -418,7 +418,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
void saveStringShouldNotWriteToLegacy() {
BlobId blobId = unionBlobStore.save(BucketName.DEFAULT, STRING_CONTENT).block();
- assertThatThrownBy(() -> legacyBlobStore.readBytes(blobId).block())
+ assertThatThrownBy(() -> legacyBlobStore.readBytes(BucketName.DEFAULT, blobId).block())
.isInstanceOf(ObjectStoreException.class);
}
@@ -426,7 +426,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
void saveInputStreamShouldWriteToCurrent() {
BlobId blobId = unionBlobStore.save(BucketName.DEFAULT, new ByteArrayInputStream(BLOB_CONTENT)).block();
- assertThat(currentBlobStore.readBytes(blobId).block())
+ assertThat(currentBlobStore.readBytes(BucketName.DEFAULT, blobId).block())
.isEqualTo(BLOB_CONTENT);
}
@@ -434,7 +434,7 @@ class UnionBlobStoreTest implements BlobStoreContract {
void saveInputStreamShouldNotWriteToLegacy() {
BlobId blobId = unionBlobStore.save(BucketName.DEFAULT, new ByteArrayInputStream(BLOB_CONTENT)).block();
- assertThatThrownBy(() -> legacyBlobStore.readBytes(blobId).block())
+ assertThatThrownBy(() -> legacyBlobStore.readBytes(BucketName.DEFAULT, blobId).block())
.isInstanceOf(ObjectStoreException.class);
}
diff --git a/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java b/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java
index 4bec4a4..6053366 100644
--- a/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java
+++ b/server/blob/mail-store/src/test/java/org/apache/james/blob/mail/MimeMessageStoreTest.java
@@ -28,6 +28,7 @@ import javax.mail.internet.MimeMessage;
import org.apache.james.blob.api.BlobId;
import org.apache.james.blob.api.BlobStore;
+import org.apache.james.blob.api.BucketName;
import org.apache.james.blob.api.HashBlobId;
import org.apache.james.blob.api.Store;
import org.apache.james.blob.memory.MemoryBlobStore;
@@ -112,7 +113,7 @@ class MimeMessageStoreTest {
BlobId headerBlobId = parts.getHeaderBlobId();
BlobId bodyBlobId = parts.getBodyBlobId();
- softly.assertThat(new String(blobStore.readBytes(headerBlobId).block(), StandardCharsets.UTF_8))
+ softly.assertThat(new String(blobStore.readBytes(BucketName.DEFAULT, headerBlobId).block(), StandardCharsets.UTF_8))
.isEqualTo("Date: Thu, 6 Sep 2018 13:29:13 +0700 (ICT)\r\n" +
"From: any@any.com\r\n" +
"To: toddy@any.com\r\n" +
@@ -121,7 +122,7 @@ class MimeMessageStoreTest {
"MIME-Version: 1.0\r\n" +
"Content-Type: text/plain; charset=UTF-8\r\n" +
"Content-Transfer-Encoding: 7bit\r\n\r\n");
- softly.assertThat(new String(blobStore.readBytes(bodyBlobId).block(), StandardCharsets.UTF_8))
+ softly.assertThat(new String(blobStore.readBytes(BucketName.DEFAULT, bodyBlobId).block(), StandardCharsets.UTF_8))
.isEqualTo("Important mail content");
});
}
diff --git a/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/DeletedMessagesVaultRoutesTest.java b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/DeletedMessagesVaultRoutesTest.java
index 74aa72d..aae07a5 100644
--- a/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/DeletedMessagesVaultRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-mailbox-deleted-message-vault/src/test/java/org/apache/james/webadmin/vault/routes/DeletedMessagesVaultRoutesTest.java
@@ -72,6 +72,7 @@ import java.util.stream.Stream;
import org.apache.commons.configuration.DefaultConfigurationBuilder;
import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.BucketName;
import org.apache.james.blob.api.HashBlobId;
import org.apache.james.blob.export.api.BlobExportMechanism;
import org.apache.james.blob.memory.MemoryBlobStore;
@@ -1904,7 +1905,7 @@ class DeletedMessagesVaultRoutesTest {
byte[] expectedZippedData = zippedMessagesData();
- assertThat(blobStore.read(blobIdFactory.forPayload(expectedZippedData)))
+ assertThat(blobStore.read(BucketName.DEFAULT, blobIdFactory.forPayload(expectedZippedData)))
.hasSameContentAs(new ByteArrayInputStream(expectedZippedData));
}
diff --git a/third-party/linshare/src/main/java/org/apache/james/linshare/LinshareBlobExportMechanism.java b/third-party/linshare/src/main/java/org/apache/james/linshare/LinshareBlobExportMechanism.java
index d86dabb..69258eb 100644
--- a/third-party/linshare/src/main/java/org/apache/james/linshare/LinshareBlobExportMechanism.java
+++ b/third-party/linshare/src/main/java/org/apache/james/linshare/LinshareBlobExportMechanism.java
@@ -28,6 +28,7 @@ import javax.inject.Inject;
import org.apache.commons.io.FileUtils;
import org.apache.james.blob.api.BlobId;
import org.apache.james.blob.api.BlobStore;
+import org.apache.james.blob.api.BucketName;
import org.apache.james.blob.export.api.BlobExportMechanism;
import org.apache.james.blob.export.api.ExportedFileNamesGenerator;
import org.apache.james.blob.export.api.FileExtension;
@@ -67,7 +68,7 @@ public class LinshareBlobExportMechanism implements BlobExportMechanism {
String fileName = ExportedFileNamesGenerator.generateFileName(fileCustomPrefix, blobId, fileExtension);
File tempFile = new File(tempDir, fileName);
try {
- FileUtils.copyInputStreamToFile(blobStore.read(blobId), tempFile);
+ FileUtils.copyInputStreamToFile(blobStore.read(BucketName.DEFAULT, blobId), tempFile);
uploadAndShare(mailAddress, tempFile, explanation);
} finally {
FileUtils.forceDelete(tempFile);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org