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 2018/09/28 02:10:45 UTC
[4/5] james-project git commit: JAMES-2550 Cassandra MailQueueView
support for deletion
JAMES-2550 Cassandra MailQueueView support for deletion
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/80bcd2fe
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/80bcd2fe
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/80bcd2fe
Branch: refs/heads/master
Commit: 80bcd2fe0afb594a843cab798b74043b0f94929b
Parents: 38189c0
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Sep 13 11:13:07 2018 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Fri Sep 28 09:07:50 2018 +0700
----------------------------------------------------------------------
.../james/queue/rabbitmq/RabbitMQMailQueue.java | 8 +-
.../cassandra/CassandraMailQueueMailDelete.java | 13 +++-
.../view/cassandra/CassandraMailQueueView.java | 26 +++++--
.../queue/rabbitmq/RabbitMQMailQueueTest.java | 79 +-------------------
4 files changed, 33 insertions(+), 93 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/80bcd2fe/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueue.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueue.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueue.java
index 50853aa..443b94f 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueue.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueue.java
@@ -26,12 +26,12 @@ import java.util.function.Function;
import javax.inject.Inject;
import javax.mail.internet.MimeMessage;
-import org.apache.commons.lang3.NotImplementedException;
import org.apache.james.blob.api.BlobId;
import org.apache.james.blob.api.Store;
import org.apache.james.blob.mail.MimeMessagePartsId;
import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.queue.api.ManageableMailQueue;
+import org.apache.james.queue.rabbitmq.view.api.DeleteCondition;
import org.apache.james.queue.rabbitmq.view.api.MailQueueView;
import org.apache.mailet.Mail;
import org.slf4j.Logger;
@@ -133,16 +133,16 @@ public class RabbitMQMailQueue implements ManageableMailQueue {
@Override
public long clear() {
- throw new NotImplementedException("Not yet implemented");
+ return mailQueueView.delete(DeleteCondition.all()).join();
}
@Override
public long remove(Type type, String value) {
- throw new NotImplementedException("Not yet implemented");
+ return mailQueueView.delete(DeleteCondition.from(type, value)).join();
}
@Override
public MailQueueIterator browse() {
return mailQueueView.browse();
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/80bcd2fe/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java
index c8c0a0e..4b65700 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueMailDelete.java
@@ -59,11 +59,18 @@ class CassandraMailQueueMailDelete {
.thenRunAsync(() -> maybeUpdateBrowseStart(mailQueueName));
}
+ CompletableFuture<Boolean> isDeleted(Mail mail, MailQueueName mailQueueName) {
+ return deletedMailsDao.isDeleted(mailQueueName, MailKey.fromMail(mail));
+ }
+
+ CompletableFuture<Void> updateBrowseStart(MailQueueName mailQueueName) {
+ return findNewBrowseStart(mailQueueName)
+ .thenCompose(newBrowseStart -> updateNewBrowseStart(mailQueueName, newBrowseStart));
+ }
+
private void maybeUpdateBrowseStart(MailQueueName mailQueueName) {
if (shouldUpdateBrowseStart()) {
- findNewBrowseStart(mailQueueName)
- .thenCompose(newBrowseStart -> updateNewBrowseStart(mailQueueName, newBrowseStart))
- .join();
+ updateBrowseStart(mailQueueName).join();
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/80bcd2fe/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java
index 5cd37c6..f60528d 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/view/cassandra/CassandraMailQueueView.java
@@ -21,14 +21,15 @@ package org.apache.james.queue.rabbitmq.view.cassandra;
import java.time.Instant;
import java.util.concurrent.CompletableFuture;
+import java.util.stream.Stream;
import javax.inject.Inject;
-import org.apache.commons.lang.NotImplementedException;
import org.apache.james.queue.api.ManageableMailQueue;
import org.apache.james.queue.rabbitmq.MailQueueName;
import org.apache.james.queue.rabbitmq.view.api.DeleteCondition;
import org.apache.james.queue.rabbitmq.view.api.MailQueueView;
+import org.apache.james.util.FluentFutureStream;
import org.apache.mailet.Mail;
import com.google.common.collect.Iterators;
@@ -59,9 +60,9 @@ public class CassandraMailQueueView implements MailQueueView {
private final MailQueueName mailQueueName;
CassandraMailQueueView(CassandraMailQueueMailStore storeHelper,
- MailQueueName mailQueueName,
- CassandraMailQueueBrowser cassandraMailQueueBrowser,
- CassandraMailQueueMailDelete cassandraMailQueueMailDelete) {
+ MailQueueName mailQueueName,
+ CassandraMailQueueBrowser cassandraMailQueueBrowser,
+ CassandraMailQueueMailDelete cassandraMailQueueMailDelete) {
this.mailQueueName = mailQueueName;
this.storeHelper = storeHelper;
this.cassandraMailQueueBrowser = cassandraMailQueueBrowser;
@@ -94,12 +95,21 @@ public class CassandraMailQueueView implements MailQueueView {
@Override
public CompletableFuture<Long> delete(DeleteCondition deleteCondition) {
- throw new NotImplementedException("Not implemented yet");
- }
+ CompletableFuture<Long> result = cassandraMailQueueBrowser.browseReferences(mailQueueName)
+ .filter(mailReference -> deleteCondition.shouldBeDeleted(mailReference.getMail()))
+ .map(mailReference -> cassandraMailQueueMailDelete.considerDeleted(mailReference.getMail(), mailQueueName),
+ FluentFutureStream::unboxFuture)
+ .completableFuture()
+ .thenApply(Stream::count);
+
+ result.thenRunAsync(() -> cassandraMailQueueMailDelete.updateBrowseStart(mailQueueName));
+ return result;
+ }
@Override
- public CompletableFuture<Boolean> isDeleted(Mail mail) {
- throw new NotImplementedException("Not implemented yet");
+ public CompletableFuture<Boolean> isPresent(Mail mail) {
+ return cassandraMailQueueMailDelete.isDeleted(mail, mailQueueName)
+ .thenApply(bool -> !bool);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/80bcd2fe/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
index e2c84b9..d9c8156 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
@@ -212,88 +212,11 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract, MailQ
assertThat(initialized).isTrue();
}
- @Disabled
- @Override
- public void clearShouldNotFailWhenBrowsingIterating() {
-
- }
-
- @Disabled
- @Override
- public void browseShouldNotFailWhenConcurrentClearWhenIterating() {
-
- }
-
- @Disabled
- @Override
- public void removeShouldNotFailWhenBrowsingIterating() {
-
- }
-
- @Disabled
- @Override
- public void browseShouldNotFailWhenConcurrentRemoveWhenIterating() {
-
- }
-
- @Disabled
- @Override
- public void removeByNameShouldRemoveSpecificEmail() {
-
- }
-
- @Disabled
- @Override
- public void removeBySenderShouldRemoveSpecificEmail() {
-
- }
-
- @Disabled
- @Override
- public void removeByRecipientShouldRemoveSpecificEmail() {
-
- }
-
- @Disabled
- @Override
- public void removeByRecipientShouldRemoveSpecificEmailWhenMultipleRecipients() {
-
- }
-
- @Disabled
- @Override
- public void removeByNameShouldNotFailWhenQueueIsEmpty() {
-
- }
-
- @Disabled
- @Override
- public void removeBySenderShouldNotFailWhenQueueIsEmpty() {
-
- }
-
- @Disabled
- @Override
- public void removeByRecipientShouldNotFailWhenQueueIsEmpty() {
-
- }
-
- @Disabled
- @Override
- public void clearShouldNotFailWhenQueueIsEmpty() {
-
- }
-
- @Disabled
- @Override
- public void clearShouldRemoveAllElements() {
- }
-
@Disabled("RabbitMQ Mail Queue do not yet implement getSize()")
@Override
public void constructorShouldRegisterGetQueueSizeGauge(MailQueueMetricExtension.MailQueueMetricTestSystem testSystem) {
}
-
+
private void enqueueMailsInSlice(int slice, int emailCount) {
ManageableMailQueue mailQueue = getManageableMailQueue();
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org