This is an automated email from the ASF dual-hosted git repository. rcordier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 999655314fb9054cb162992b93672928af0ecb16 Author: Rene Cordier <[email protected]> AuthorDate: Fri Jul 10 11:43:27 2020 +0700 JAMES-3305 Key registration should not crash on invalid messages --- .../james/mailbox/events/RabbitMQEventBusTest.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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 58d1979..d2eac1f 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 @@ -67,6 +67,7 @@ import org.apache.james.event.json.EventSerializer; import org.apache.james.mailbox.events.EventBusTestFixture.GroupA; import org.apache.james.mailbox.events.EventBusTestFixture.MailboxListenerCountingSuccessfulExecution; import org.apache.james.mailbox.events.EventDispatcher.DispatchingFailureGroup; +import org.apache.james.mailbox.events.RoutingKeyConverter.RoutingKey; import org.apache.james.mailbox.model.TestId; import org.apache.james.mailbox.model.TestMessageId; import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver; @@ -241,6 +242,39 @@ class RabbitMQEventBusTest implements GroupContract.SingleEventBusGroupContract, } @Test + void registrationShouldNotCrashOnInvalidMessage() { + EventCollector listener = new EventCollector(); + Mono.from(eventBus.register(listener, KEY_1)).block(); + + rabbitMQExtension.getSender() + .send(Mono.just(new OutboundMessage(MAILBOX_EVENT_EXCHANGE_NAME, + RoutingKey.of(KEY_1).asString(), + "BAD_PAYLOAD!".getBytes(StandardCharsets.UTF_8)))) + .block(); + + eventBus.dispatch(EVENT, KEY_1).block(); + await().timeout(org.awaitility.Duration.TEN_SECONDS) + .untilAsserted(() -> assertThat(listener.getEvents()).containsOnly(EVENT)); + } + + @Test + void registrationShouldNotCrashOnInvalidMessages() { + EventCollector listener = new EventCollector(); + Mono.from(eventBus.register(listener, KEY_1)).block(); + + IntStream.range(0, 100) + .forEach(i -> rabbitMQExtension.getSender() + .send(Mono.just(new OutboundMessage(MAILBOX_EVENT_EXCHANGE_NAME, + RoutingKey.of(KEY_1).asString(), + "BAD_PAYLOAD!".getBytes(StandardCharsets.UTF_8)))) + .block()); + + eventBus.dispatch(EVENT, KEY_1).block(); + await().timeout(org.awaitility.Duration.TEN_SECONDS) + .untilAsserted(() -> assertThat(listener.getEvents()).containsOnly(EVENT)); + } + + @Test void deserializeEventCollectorGroup() throws Exception { assertThat(Group.deserialize("org.apache.james.mailbox.util.EventCollector$EventCollectorGroup")) .isEqualTo(new EventCollector.EventCollectorGroup()); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
