From cdeece481d052fee522a0280972570c1facb3f00 Mon Sep 17 00:00:00 2001 From: Thomas Segismont Date: Tue, 28 Jun 2022 17:43:07 +0200 Subject: [PATCH] EventBus removeInboundInterceptor should use the INBOUND_INTERCEPTORS_UPDATER (#4423) Fixes #4422 Otherwise, no inbound interceptor will ever be removed. Signed-off-by: Thomas Segismont --- .../core/eventbus/impl/EventBusImpl.java | 10 +++---- .../eventbus/EventBusInterceptorTest.java | 29 ++++++++++--------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main/java/io/vertx/core/eventbus/impl/EventBusImpl.java b/src/main/java/io/vertx/core/eventbus/impl/EventBusImpl.java index 7c3d2037af0..c889da21e0d 100644 --- a/src/main/java/io/vertx/core/eventbus/impl/EventBusImpl.java +++ b/src/main/java/io/vertx/core/eventbus/impl/EventBusImpl.java @@ -57,25 +57,25 @@ public EventBusImpl(VertxInternal vertx) { @Override public EventBus addOutboundInterceptor(Handler> interceptor) { - addInterceptor(OUTBOUND_INTERCEPTORS_UPDATER, interceptor); + addInterceptor(OUTBOUND_INTERCEPTORS_UPDATER, Objects.requireNonNull(interceptor)); return this; } @Override public EventBus addInboundInterceptor(Handler> interceptor) { - addInterceptor(INBOUND_INTERCEPTORS_UPDATER, interceptor); + addInterceptor(INBOUND_INTERCEPTORS_UPDATER, Objects.requireNonNull(interceptor)); return this; } @Override public EventBus removeOutboundInterceptor(Handler> interceptor) { - removeInterceptor(OUTBOUND_INTERCEPTORS_UPDATER, interceptor); + removeInterceptor(OUTBOUND_INTERCEPTORS_UPDATER, Objects.requireNonNull(interceptor)); return this; } @Override public EventBus removeInboundInterceptor(Handler> interceptor) { - removeInterceptor(OUTBOUND_INTERCEPTORS_UPDATER, interceptor); + removeInterceptor(INBOUND_INTERCEPTORS_UPDATER, Objects.requireNonNull(interceptor)); return this; } @@ -455,7 +455,7 @@ private void removeInterceptor(AtomicReferenceFieldUpdater { if (msg.body().equals("armadillo")) { - assertEquals(1, cnt1.get()); - assertEquals(1, cnt2.get()); - assertEquals(1, cnt3.get()); - eb.removeOutboundInterceptor(eb2); - eb.send("some-address", "aardvark"); - } else if (msg.body().equals("aardvark")) { assertEquals(2, cnt1.get()); - assertEquals(1, cnt2.get()); + assertEquals(2, cnt2.get()); assertEquals(2, cnt3.get()); - eb.removeOutboundInterceptor(eb3); + eb.removeInboundInterceptor(eb2).removeOutboundInterceptor(eb2); + eb.send("some-address", "aardvark"); + } else if (msg.body().equals("aardvark")) { + assertEquals(4, cnt1.get()); + assertEquals(2, cnt2.get()); + assertEquals(4, cnt3.get()); + eb.removeInboundInterceptor(eb3).removeOutboundInterceptor(eb3); eb.send("some-address", "anteater"); } else if (msg.body().equals("anteater")) { - assertEquals(3, cnt1.get()); - assertEquals(1, cnt2.get()); - assertEquals(2, cnt3.get()); + assertEquals(6, cnt1.get()); + assertEquals(2, cnt2.get()); + assertEquals(4, cnt3.get()); testComplete(); } else { fail("wrong body");