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/01/22 10:09:58 UTC
[3/6] james-project git commit: MAILBOX-374 RabbitMQ should support
generic groups
MAILBOX-374 RabbitMQ should support generic groups
This bug caused only one of the QuotaMailing listeners to be triggered
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/04e8f7bd
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/04e8f7bd
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/04e8f7bd
Branch: refs/heads/master
Commit: 04e8f7bd2ca6b8185a556aaa5f8679437f37324b
Parents: 8a42e9e
Author: Benoit Tellier <bt...@linagora.com>
Authored: Thu Jan 17 17:34:53 2019 +0700
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Tue Jan 22 17:07:15 2019 +0700
----------------------------------------------------------------------
.../org/apache/james/mailbox/events/GenericGroup.java | 5 +++++
.../java/org/apache/james/mailbox/events/Group.java | 4 ++++
.../apache/james/mailbox/events/GroupContract.java | 14 ++++++++++++++
.../org/apache/james/mailbox/events/GroupTest.java | 10 ++++++++++
.../james/mailbox/events/GroupConsumerRetry.java | 2 +-
.../james/mailbox/events/GroupRegistration.java | 13 ++-----------
.../james/mailbox/events/RabbitMQEventBusTest.java | 4 ++--
7 files changed, 38 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/04e8f7bd/mailbox/api/src/main/java/org/apache/james/mailbox/events/GenericGroup.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/events/GenericGroup.java b/mailbox/api/src/main/java/org/apache/james/mailbox/events/GenericGroup.java
index ed36568..df14453 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/events/GenericGroup.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/events/GenericGroup.java
@@ -29,6 +29,11 @@ public class GenericGroup extends Group {
}
@Override
+ public String asString() {
+ return super.asString() + "-" + groupName;
+ }
+
+ @Override
public final boolean equals(Object o) {
if (o instanceof GenericGroup) {
GenericGroup that = (GenericGroup) o;
http://git-wip-us.apache.org/repos/asf/james-project/blob/04e8f7bd/mailbox/api/src/main/java/org/apache/james/mailbox/events/Group.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/events/Group.java b/mailbox/api/src/main/java/org/apache/james/mailbox/events/Group.java
index 2da5cb4..9fb9d25 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/events/Group.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/events/Group.java
@@ -22,6 +22,10 @@ package org.apache.james.mailbox.events;
import java.util.Objects;
public class Group {
+ public String asString() {
+ return getClass().getName();
+ }
+
@Override
public boolean equals(Object o) {
if (o == null) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/04e8f7bd/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupContract.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupContract.java b/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupContract.java
index c7f5009..aa500be 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupContract.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupContract.java
@@ -227,6 +227,20 @@ public interface GroupContract {
verify(listener, timeout(ONE_SECOND).times(1)).event(any());
}
+
+ @Test
+ default void allGroupListenersShouldBeExecutedWhenGenericGroups() throws Exception {
+ MailboxListener listener1 = newListener();
+ MailboxListener listener2 = newListener();
+
+ eventBus().register(listener1, new GenericGroup("a"));
+ eventBus().register(listener2, new GenericGroup("b"));
+
+ eventBus().dispatch(EVENT, NO_KEYS).block();
+
+ verify(listener1, timeout(ONE_SECOND).times(1)).event(any());
+ verify(listener2, timeout(ONE_SECOND).times(1)).event(any());
+ }
}
interface MultipleEventBusGroupContract extends EventBusContract.MultipleEventBusContract {
http://git-wip-us.apache.org/repos/asf/james-project/blob/04e8f7bd/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupTest.java
index 0acb141..6b5fb6b 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/events/GroupTest.java
@@ -65,4 +65,14 @@ class GroupTest {
.withRedefinedSuperclass()
.verify();
}
+
+ @Test
+ void asStringShouldReturnFqdnByDefault() {
+ assertThat(new EventBusTestFixture.GroupA().asString()).isEqualTo("org.apache.james.mailbox.events.EventBusTestFixture$GroupA");
+ }
+
+ @Test
+ void asStringShouldReturnNameWhenGenericGroup() {
+ assertThat(new GenericGroup("abc").asString()).isEqualTo("org.apache.james.mailbox.events.GenericGroup-abc");
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/04e8f7bd/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupConsumerRetry.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupConsumerRetry.java b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupConsumerRetry.java
index 2b99c49..ce2c713 100644
--- a/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupConsumerRetry.java
+++ b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupConsumerRetry.java
@@ -46,7 +46,7 @@ class GroupConsumerRetry {
static class RetryExchangeName {
static RetryExchangeName of(Group group) {
- return new RetryExchangeName(GroupRegistration.groupName(group.getClass()));
+ return new RetryExchangeName(group.asString());
}
static final String MAILBOX_EVENT_RETRY_EXCHANGE_PREFIX = MAILBOX_EVENT + "-retryExchange-";
http://git-wip-us.apache.org/repos/asf/james-project/blob/04e8f7bd/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupRegistration.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupRegistration.java b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupRegistration.java
index 7e4fe6d..d7c4c91 100644
--- a/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupRegistration.java
+++ b/mailbox/event/event-rabbitmq/src/main/java/org/apache/james/mailbox/events/GroupRegistration.java
@@ -36,7 +36,6 @@ import org.apache.james.mailbox.Event;
import org.apache.james.mailbox.MailboxListener;
import com.github.fge.lambdas.Throwing;
-import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.rabbitmq.client.Connection;
@@ -56,8 +55,6 @@ import reactor.rabbitmq.Sender;
class GroupRegistration implements Registration {
static class WorkQueueName {
-
- @VisibleForTesting
static WorkQueueName of(Group group) {
return new WorkQueueName(group);
}
@@ -65,27 +62,21 @@ class GroupRegistration implements Registration {
static final String MAILBOX_EVENT_WORK_QUEUE_PREFIX = MAILBOX_EVENT + "-workQueue-";
private final Group group;
- private final String name;
private WorkQueueName(Group group) {
Preconditions.checkNotNull(group, "Group must be specified");
this.group = group;
- this.name = groupName(group.getClass());
}
- public Group getGroup() {
+ Group getGroup() {
return group;
}
String asString() {
- return MAILBOX_EVENT_WORK_QUEUE_PREFIX + name;
+ return MAILBOX_EVENT_WORK_QUEUE_PREFIX + group.asString();
}
}
- static String groupName(Class<? extends Group> clazz) {
- return clazz.getName();
- }
-
static final String RETRY_COUNT = "retry-count";
static final int DEFAULT_RETRY_COUNT = 0;
http://git-wip-us.apache.org/repos/asf/james-project/blob/04e8f7bd/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java
----------------------------------------------------------------------
diff --git a/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java b/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java
index 0d55f30..8784493 100644
--- a/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java
+++ b/mailbox/event/event-rabbitmq/src/test/java/org/apache/james/mailbox/events/RabbitMQEventBusTest.java
@@ -118,8 +118,8 @@ class RabbitMQEventBusTest implements GroupContract.SingleEventBusGroupContract,
eventBus2.stop();
eventBus3.stop();
ALL_GROUPS.stream()
- .map(groupClass -> GroupRegistration.WorkQueueName.of(groupClass).asString())
- .forEach(queueName -> sender.delete(QueueSpecification.queue(queueName)).block());
+ .map(GroupRegistration.WorkQueueName::of)
+ .forEach(queueName -> sender.delete(QueueSpecification.queue(queueName.asString())).block());
sender.delete(ExchangeSpecification.exchange(MAILBOX_EVENT_EXCHANGE_NAME)).block();
sender.close();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org