Update listeners in registerNotificationListeners 44/104244/1
authorSangwook Ha <sangwook.ha@verizon.com>
Sat, 4 Feb 2023 19:18:38 +0000 (11:18 -0800)
committerSangwook Ha <sangwook.ha@verizon.com>
Sat, 4 Feb 2023 22:54:24 +0000 (14:54 -0800)
'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 <sangwook.ha@verizon.com>
dom/mdsal-dom-broker/src/main/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouter.java
dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMNotificationRouterTest.java

index 5e739888307dd06d025c7b09fba27daa1fd47821..e1575816b8954c5c78874e30f6af1c13a08779d0 100644 (file)
@@ -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() {
index fa07396c06c42ae20e9ef96d1d4058242de5e4f5..beca7c54e029756411cd845fbff7cb1eee62d2b9 100644 (file)
@@ -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 {