From e0f5a84e163fe758961df93909776790bdfd912f Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Wed, 25 Oct 2017 14:58:57 -0400 Subject: [PATCH] MDSAL-107: Fix pre-existing data notification for wildcarded DTCL This issue was fixed in CDS a while but should also be fixed for the in-memory DOM data store. Change-Id: Ib3e25c6164d6868f5b80680467732aed0beac093 Signed-off-by: Tom Pantelis --- .../adapter/test/DataTreeChangeListenerTest.java | 14 ++++++++++++++ .../InMemoryDOMStoreTreeChangePublisher.java | 16 +++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/DataTreeChangeListenerTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/DataTreeChangeListenerTest.java index 2edb74c991..3de9a66922 100644 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/DataTreeChangeListenerTest.java +++ b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/DataTreeChangeListenerTest.java @@ -143,6 +143,20 @@ public class DataTreeChangeListenerTest extends AbstractDataBrokerTest { verifyModification(barDeleteEvent.getRootNode(), BAR_ARGUMENT, ModificationType.DELETE); } + @Test + public void testWildcardedListListenerWithPreexistingData() throws Exception { + putTx(TOP_PATH, TOP_INITIAL_DATA).submit().get(); + + final EventCapturingListener listener = new EventCapturingListener<>(); + final DataTreeIdentifier wildcard = DataTreeIdentifier.create( + LogicalDatastoreType.OPERATIONAL, TOP_PATH.child(TopLevelList.class)); + dataBrokerImpl.registerDataTreeChangeListener(wildcard, listener); + + final DataTreeModification fooWriteEvent = Iterables.getOnlyElement(listener.nextEvent()); + assertEquals(FOO_PATH, fooWriteEvent.getRootPath().getRootIdentifier()); + verifyModification(fooWriteEvent.getRootNode(), FOO_ARGUMENT, ModificationType.WRITE); + } + private void createAndVerifyTop(final EventCapturingListener listener) throws Exception { putTx(TOP_PATH,TOP_INITIAL_DATA).submit().get(); final Collection> events = listener.nextEvent(); diff --git a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreTreeChangePublisher.java b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreTreeChangePublisher.java index d7d48191cc..647a67e131 100644 --- a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreTreeChangePublisher.java +++ b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreTreeChangePublisher.java @@ -44,6 +44,11 @@ final class InMemoryDOMStoreTreeChangePublisher extends AbstractDOMStoreTreeChan "DataTreeChangeListenerQueueMgr"); } + private InMemoryDOMStoreTreeChangePublisher(QueuedNotificationManager< + AbstractDOMDataTreeChangeListenerRegistration, DataTreeCandidate> notificationManager) { + this.notificationManager = notificationManager; + } + @Override protected void notifyListener(AbstractDOMDataTreeChangeListenerRegistration registration, Collection changes) { @@ -63,10 +68,15 @@ final class InMemoryDOMStoreTreeChangePublisher extends AbstractDOMStoreTreeChan final YangInstanceIdentifier treeId, final L listener, final DataTreeSnapshot snapshot) { final AbstractDOMDataTreeChangeListenerRegistration reg = registerTreeChangeListener(treeId, listener); - final Optional> node = snapshot.readNode(treeId); + final Optional> node = snapshot.readNode(YangInstanceIdentifier.EMPTY); if (node.isPresent()) { - final DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode(treeId, node.get()); - notificationManager.submitNotification(reg, candidate); + final DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode( + YangInstanceIdentifier.EMPTY, node.get()); + + InMemoryDOMStoreTreeChangePublisher publisher = + new InMemoryDOMStoreTreeChangePublisher(notificationManager); + publisher.registerTreeChangeListener(treeId, listener); + publisher.publishChange(candidate); } return reg; -- 2.36.6