From c60ed32146df976446f5d1346488d96044f76f40 Mon Sep 17 00:00:00 2001 From: Sangwook Ha Date: Sat, 4 Feb 2023 11:18:38 -0800 Subject: [PATCH] Update listeners in registerNotificationListeners 'registerNotificationListeners' does not include a step to replace the the listener map with a new one. Make sure that the listener map is actually updated. Also, add test cases for the registration methods. JIRA: MDSAL-811 Change-Id: I469000b6f92e8d45186cafa1a3a2c737f642de01 Signed-off-by: Sangwook Ha --- .../dom/broker/DOMNotificationRouter.java | 1 + .../dom/broker/DOMNotificationRouterTest.java | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouter.java b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouter.java index 5e73988830..e1575816b8 100644 --- a/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouter.java +++ b/dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouter.java @@ -171,6 +171,7 @@ public class DOMNotificationRouter implements AutoCloseable, DOMNotificationPubl for (var e : typeToListener.entrySet()) { b.put(e.getKey(), tmp.computeIfAbsent(e.getValue(), ComponentReg::new)); } + replaceListeners(b.build()); final var regs = List.copyOf(tmp.values()); return new AbstractRegistration() { diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouterTest.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouterTest.java index fa07396c06..beca7c54e0 100644 --- a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouterTest.java +++ b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouterTest.java @@ -24,6 +24,7 @@ import com.google.common.util.concurrent.ListenableFuture; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; @@ -33,6 +34,7 @@ import org.opendaylight.mdsal.dom.api.DOMNotificationListener; import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService; import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListener; import org.opendaylight.yangtools.util.ListenerRegistry; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute; public class DOMNotificationRouterTest { @@ -42,6 +44,33 @@ public class DOMNotificationRouterTest { assertNotNull(DOMNotificationRouter.create(1024)); } + @Test + public void registerNotificationListener() { + final var domNotificationRouter = new DOMNotificationRouter(1024); + final var domNotificationListener = mock(DOMNotificationListener.class); + + domNotificationRouter.registerNotificationListener(domNotificationListener, + List.of(Absolute.of(QName.create("urn:opendaylight:test-listener", "notif1")))); + assertEquals(1, domNotificationRouter.listeners().size()); + + domNotificationRouter.registerNotificationListener(domNotificationListener, + List.of(Absolute.of(QName.create("urn:opendaylight:test-listener", "notif2")), + Absolute.of(QName.create("urn:opendaylight:test-listener", "notif3")))); + assertEquals(3, domNotificationRouter.listeners().size()); + } + + @Test + public void registerNotificationListeners() { + final var domNotificationRouter = new DOMNotificationRouter(1024); + final var domNotificationListener1 = mock(DOMNotificationListener.class); + final var domNotificationListener2 = mock(DOMNotificationListener.class); + + domNotificationRouter.registerNotificationListeners( + Map.of(Absolute.of(QName.create("urn:opendaylight:test-listener", "notif1")), domNotificationListener1, + Absolute.of(QName.create("urn:opendaylight:test-listener", "notif2")), domNotificationListener2)); + assertEquals(2, domNotificationRouter.listeners().size()); + } + @SuppressWarnings("checkstyle:IllegalCatch") @Test public void complexTest() throws Exception { -- 2.36.6