From: Robert Varga Date: Thu, 18 Jan 2024 19:14:29 +0000 (+0100) Subject: Expose a List of changes in DOMDataTreeChangeListener X-Git-Tag: v13.0.0~5 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=mdsal.git;a=commitdiff_plain;h=d2c0f28aef06857cbe7fcfb96a7745055b290db4 Expose a List of changes in DOMDataTreeChangeListener The collection of changes needs to be considered to be ordered. This patch codifies that by using a List. This has the up side of making it easier to access first/last item as well as to navigate around. Change-Id: If747e0000f8a9bb33d934b84c0c078d56d4c6126 Signed-off-by: Robert Varga --- diff --git a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataChangeListenerAdapter.java b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataChangeListenerAdapter.java index 364fa59e0f..53895f7a20 100644 --- a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataChangeListenerAdapter.java +++ b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataChangeListenerAdapter.java @@ -10,8 +10,7 @@ package org.opendaylight.mdsal.binding.api; import static java.util.Objects.requireNonNull; import com.google.common.collect.ForwardingObject; -import com.google.common.collect.Iterables; -import java.util.Collection; +import java.util.List; import org.opendaylight.yangtools.yang.binding.DataObject; final class DataChangeListenerAdapter extends ForwardingObject @@ -23,9 +22,9 @@ final class DataChangeListenerAdapter extends ForwardingOb } @Override - public void onDataTreeChanged(final Collection> changes) { - delegate.dataChanged(changes.iterator().next().getRootNode().dataBefore(), - Iterables.getLast(changes).getRootNode().dataAfter()); + public void onDataTreeChanged(final List> changes) { + delegate.dataChanged(changes.get(0).getRootNode().dataBefore(), + changes.get(changes.size() - 1).getRootNode().dataAfter()); } @Override diff --git a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataListenerAdapter.java b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataListenerAdapter.java index b12fbc82a1..8d6dc87f52 100644 --- a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataListenerAdapter.java +++ b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataListenerAdapter.java @@ -10,8 +10,7 @@ package org.opendaylight.mdsal.binding.api; import static java.util.Objects.requireNonNull; import com.google.common.collect.ForwardingObject; -import com.google.common.collect.Iterables; -import java.util.Collection; +import java.util.List; import org.opendaylight.yangtools.yang.binding.DataObject; final class DataListenerAdapter extends ForwardingObject @@ -23,8 +22,8 @@ final class DataListenerAdapter extends ForwardingObject } @Override - public void onDataTreeChanged(final Collection> changes) { - delegate.dataChangedTo(Iterables.getLast(changes).getRootNode().dataAfter()); + public void onDataTreeChanged(final List> changes) { + delegate.dataChangedTo(changes.get(changes.size() - 1).getRootNode().dataAfter()); } @Override diff --git a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataTreeChangeListener.java b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataTreeChangeListener.java index 3c6c43c294..c9d4a351be 100644 --- a/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataTreeChangeListener.java +++ b/binding/mdsal-binding-api/src/main/java/org/opendaylight/mdsal/binding/api/DataTreeChangeListener.java @@ -7,53 +7,49 @@ */ package org.opendaylight.mdsal.binding.api; -import java.util.Collection; +import java.util.List; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.binding.DataObject; /** - * Interface implemented by classes interested in receiving notifications about - * data tree changes. It provides a cursor-based view of the change, which has potentially - * lower overhead and allow more flexible consumption of change event. + * Interface implemented by classes interested in receiving notifications about changes to a data tree. It provides + * a cursor-based view of the change, which has potentially lower overhead and allow more flexible consumption of change + * events. */ public interface DataTreeChangeListener { /** - * Invoked when there was data change for the supplied path, which was used - * to register this listener. + * Invoked when there was data change for the supplied path, which was used to register this listener. * *

- * This method may be also invoked during registration of the listener if - * there is any pre-existing data in the conceptual data tree for supplied - * path. This initial event will contain all pre-existing data as created. + * This method may be also invoked during registration of the listener if there is any pre-existing data in the + * conceptual data tree for supplied path. This initial event will contain all pre-existing data as created. * *

* Note: If there is no pre-existing data, the method {@link #onInitialData} will be invoked. * *

- * A data change event may be triggered spuriously, e.g. such that data before - * and after compare as equal. Implementations of this interface are expected - * to recover from such events. Event producers are expected to exert reasonable - * effort to suppress such events. + * A data change event may be triggered spuriously, e.g. such that data before and after compare as equal. + * Implementations of this interface are expected to recover from such events. Event producers are expected to exert + * reasonable effort to suppress such events. * *

- * In other words, it is completely acceptable to observe - * a {@link DataObjectModification}, while the state observed before and - * after- data items compare as equal. + * In other words, it is completely acceptable to observe a {@link DataObjectModification}, while the state observed + * before and after- data items compare as equal. * - * @param changes Collection of change events, may not be null or empty. + * @param changes List of change events, may not be null or empty. */ - void onDataTreeChanged(@NonNull Collection> changes); + void onDataTreeChanged(@NonNull List> changes); /** - * Invoked only once during registration of the listener if there was no data in the conceptual data tree - * for the supplied path, which was used to register this listener, and after this - * {@link #onDataTreeChanged(Collection)} would always be invoked for data changes. + * Invoked only once during registration of the listener if there was no data in the conceptual data tree for the + * supplied path, which was used to register this listener, and after this {@link #onDataTreeChanged(List)} would + * always be invoked for data changes. * *

- * Default implementation does nothing and is appropriate for users who do not care about ascertaining - * initial state. + * Default implementation does nothing and is appropriate for users who do not care about ascertaining initial + * state. */ - // FIXME: 8.0.0: this method should be non-default + // FIXME: 14.0.0: this method should be non-default default void onInitialData() { //no-op } diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMDataTreeChangeServiceAdapterTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMDataTreeChangeServiceAdapterTest.java index 42a8d2e959..1a00a51693 100644 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMDataTreeChangeServiceAdapterTest.java +++ b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingDOMDataTreeChangeServiceAdapterTest.java @@ -15,7 +15,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; -import java.util.Collection; +import java.util.List; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,7 +33,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker.DataTreeChangeExtension; import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top; -import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; @@ -53,9 +53,8 @@ public class BindingDOMDataTreeChangeServiceAdapterTest { @Mock private BindingDOMCodecServices services; - @SuppressWarnings("rawtypes") @Mock - private ListenerRegistration mockDOMReg; + private Registration mockDOMReg; @Before public void setUp() { @@ -94,14 +93,14 @@ public class BindingDOMDataTreeChangeServiceAdapterTest { private static final class TestClusteredDataTreeChangeListener implements ClusteredDataTreeChangeListener { @Override - public void onDataTreeChanged(final Collection> changes) { + public void onDataTreeChanged(final List> changes) { // No-op } } private static final class TestDataTreeChangeListener implements DataTreeChangeListener { @Override - public void onDataTreeChanged(final Collection> changes) { + public void onDataTreeChanged(final List> changes) { // No-op } } diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Bug4513Test.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Bug4513Test.java index d9355986d0..2bed1fc742 100644 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Bug4513Test.java +++ b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Bug4513Test.java @@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; -import java.util.Collection; +import java.util.List; import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; @@ -40,23 +40,23 @@ class Bug4513Test extends AbstractDataBrokerTest { @Mock private DataTreeChangeListener listener; @Captor - private ArgumentCaptor>> captor; + private ArgumentCaptor>> captor; @Test void testDataTreeChangeListener() { final var dataBroker = getDataBroker(); final var wildCard = InstanceIdentifier.builder(ListenerTest.class).child(ListItem.class).build(); - final var reg = dataBroker.registerDataTreeChangeListener( - DataTreeIdentifier.of(LogicalDatastoreType.OPERATIONAL, wildCard), listener); + try (var reg = dataBroker.registerDataTreeChangeListener( + DataTreeIdentifier.of(LogicalDatastoreType.OPERATIONAL, wildCard), listener)) { + final var item = writeListItem(); - final var item = writeListItem(); + verify(listener, timeout(100)).onDataTreeChanged(captor.capture()); - verify(listener, timeout(100)).onDataTreeChanged(captor.capture()); - - final var mods = captor.getValue(); - assertEquals(1, mods.size()); - assertEquals(item, mods.iterator().next().getRootNode().getDataAfter()); + final var mods = captor.getValue(); + assertEquals(1, mods.size()); + assertEquals(item, mods.get(0).getRootNode().dataAfter()); + } } private ListItem writeListItem() { diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/DataTreeChangeListenerTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/DataTreeChangeListenerTest.java index 58a61e2078..e2e03620b2 100644 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/DataTreeChangeListenerTest.java +++ b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/DataTreeChangeListenerTest.java @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.util.concurrent.SettableFuture; import java.util.Collection; +import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; import org.junit.Test; @@ -62,17 +63,15 @@ public class DataTreeChangeListenerTest extends AbstractDataBrokerTest { private BindingDOMDataBrokerAdapter dataBrokerImpl; private static final class EventCapturingListener implements DataTreeChangeListener { - - private SettableFuture>> futureChanges = SettableFuture.create(); + private SettableFuture>> futureChanges = SettableFuture.create(); @Override - public void onDataTreeChanged(final Collection> changes) { + public void onDataTreeChanged(final List> changes) { futureChanges.set(changes); - } Collection> nextEvent() throws Exception { - final Collection> result = futureChanges.get(200,TimeUnit.MILLISECONDS); + final var result = futureChanges.get(200,TimeUnit.MILLISECONDS); futureChanges = SettableFuture.create(); return result; } diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Mdsal298Test.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Mdsal298Test.java index 258eacee00..794a3eeb9d 100644 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Mdsal298Test.java +++ b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Mdsal298Test.java @@ -8,15 +8,13 @@ package org.opendaylight.mdsal.binding.dom.adapter; import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.anyCollection; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION; -import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.concurrent.ExecutionException; import org.junit.Test; @@ -105,38 +103,38 @@ public class Mdsal298Test extends AbstractDataBrokerTest { .build()); domTx.commit().get(); - final var captor = ArgumentCaptor.forClass(Collection.class); + final var captor = ArgumentCaptor.forClass(List.class); verify(listener).onDataTreeChanged(captor.capture()); - Collection> capture = captor.getValue(); + List> capture = captor.getValue(); assertEquals(1, capture.size()); - final DataTreeModification change = capture.iterator().next(); + final DataTreeModification change = capture.get(0); assertEquals(CONTAINER_TID, change.getRootPath()); final DataObjectModification changedContainer = change.getRootNode(); - assertEquals(new NodeStep<>(Container.class), changedContainer.getIdentifier()); - assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.getModificationType()); + assertEquals(new NodeStep<>(Container.class), changedContainer.step()); + assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.modificationType()); - final Container containerAfter = changedContainer.getDataAfter(); + final Container containerAfter = changedContainer.dataAfter(); assertEquals(new ContainerBuilder() .setKeyed(List.of( new KeyedBuilder().setFoo("foo").withKey(new KeyedKey("foo")).build(), new KeyedBuilder().setFoo("bar").withKey(new KeyedKey("bar")).build())) .build(), containerAfter); - final Collection> changedChildren = changedContainer.getModifiedChildren(); + final var changedChildren = changedContainer.modifiedChildren(); assertEquals(2, changedChildren.size()); - final Iterator> it = changedChildren.iterator(); + final var it = changedChildren.iterator(); final DataObjectModification changedChild1 = it.next(); - assertEquals(ModificationType.WRITE, changedChild1.getModificationType()); - assertEquals(List.of(), changedChild1.getModifiedChildren()); - final Keyed child1After = (Keyed) changedChild1.getDataAfter(); + assertEquals(ModificationType.WRITE, changedChild1.modificationType()); + assertEquals(List.of(), changedChild1.modifiedChildren()); + final Keyed child1After = (Keyed) changedChild1.dataAfter(); assertEquals("foo", child1After.getFoo()); final DataObjectModification changedChild2 = it.next(); - assertEquals(ModificationType.WRITE, changedChild2.getModificationType()); - assertEquals(List.of(), changedChild2.getModifiedChildren()); - final Keyed child2After = (Keyed) changedChild2.getDataAfter(); + assertEquals(ModificationType.WRITE, changedChild2.modificationType()); + assertEquals(List.of(), changedChild2.modifiedChildren()); + final Keyed child2After = (Keyed) changedChild2.dataAfter(); assertEquals("bar", child2After.getFoo()); } @@ -160,25 +158,25 @@ public class Mdsal298Test extends AbstractDataBrokerTest { .build()); domTx.commit().get(); - final var captor = ArgumentCaptor.forClass(Collection.class); + final var captor = ArgumentCaptor.forClass(List.class); verify(listener).onDataTreeChanged(captor.capture()); - Collection> capture = captor.getValue(); + List> capture = captor.getValue(); assertEquals(1, capture.size()); - final DataTreeModification change = capture.iterator().next(); + final DataTreeModification change = capture.get(0); assertEquals(CONTAINER_TID, change.getRootPath()); final DataObjectModification changedContainer = change.getRootNode(); - assertEquals(new NodeStep<>(Container.class), changedContainer.getIdentifier()); - assertEquals(ModificationType.WRITE, changedContainer.getModificationType()); + assertEquals(new NodeStep<>(Container.class), changedContainer.step()); + assertEquals(ModificationType.WRITE, changedContainer.modificationType()); - final Container containerAfter = changedContainer.getDataAfter(); + final Container containerAfter = changedContainer.dataAfter(); assertEquals(new ContainerBuilder() .setUnkeyed(List.of( new UnkeyedBuilder().setFoo("foo").build(), new UnkeyedBuilder().setFoo("bar").build())) .build(), containerAfter); - final Collection> changedChildren = changedContainer.getModifiedChildren(); + final var changedChildren = changedContainer.modifiedChildren(); assertEquals(0, changedChildren.size()); } @@ -186,31 +184,30 @@ public class Mdsal298Test extends AbstractDataBrokerTest { public void testChoiceDataTreeModificationAddressable() throws InterruptedException, ExecutionException { final DataTreeChangeListener listener = assertWrittenWithChoice(); - doNothing().when(listener).onDataTreeChanged(anyCollection()); + doNothing().when(listener).onDataTreeChanged(anyList()); final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); writeTx.put(CONFIGURATION, ADDRESSABLE_CASE, new AddressableBuilder().build()); writeTx.commit().get(); - final var captor = ArgumentCaptor.forClass(Collection.class); + final var captor = ArgumentCaptor.forClass(List.class); verify(listener).onDataTreeChanged(captor.capture()); - Collection> capture = captor.getValue(); + List> capture = captor.getValue(); assertEquals(1, capture.size()); final DataTreeModification choiceChange = capture.iterator().next(); assertEquals(CHOICE_CONTAINER_TID, choiceChange.getRootPath()); final DataObjectModification changedContainer = choiceChange.getRootNode(); - assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.getModificationType()); - assertEquals(new NodeStep<>(WithChoice.class), changedContainer.getIdentifier()); + assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.modificationType()); + assertEquals(new NodeStep<>(WithChoice.class), changedContainer.step()); - final Collection> choiceChildren = changedContainer.getModifiedChildren(); + final var choiceChildren = changedContainer.modifiedChildren(); assertEquals(1, choiceChildren.size()); - final DataObjectModification changedCase = (DataObjectModification) choiceChildren - .iterator().next(); - assertEquals(ModificationType.WRITE, changedCase.getModificationType()); - assertEquals(new NodeStep<>(Addressable.class), changedCase.getIdentifier()); - assertEquals(new AddressableBuilder().build(), changedCase.getDataAfter()); + final var changedCase = (DataObjectModification) choiceChildren.iterator().next(); + assertEquals(ModificationType.WRITE, changedCase.modificationType()); + assertEquals(new NodeStep<>(Addressable.class), changedCase.step()); + assertEquals(new AddressableBuilder().build(), changedCase.dataAfter()); } @Test @@ -218,32 +215,31 @@ public class Mdsal298Test extends AbstractDataBrokerTest { final DataTreeChangeListener listener = assertWrittenContainer(AddressableCont.QNAME, AddressableCont.class, new AddressableContBuilder().build()); - doNothing().when(listener).onDataTreeChanged(anyCollection()); + doNothing().when(listener).onDataTreeChanged(anyList()); final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); writeTx.put(CONFIGURATION, ADDRESSABLE_CONTAINER.child(AddressableChild.class), new AddressableChildBuilder().build()); writeTx.commit().get(); - final var captor = ArgumentCaptor.forClass(Collection.class); + final var captor = ArgumentCaptor.forClass(List.class); verify(listener).onDataTreeChanged(captor.capture()); - Collection> capture = captor.getValue(); + final List> capture = captor.getValue(); assertEquals(1, capture.size()); final DataTreeModification contChange = capture.iterator().next(); assertEquals(ADDRESSABLE_CONTAINER_TID, contChange.getRootPath()); final DataObjectModification changedContainer = contChange.getRootNode(); - assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.getModificationType()); - assertEquals(new NodeStep<>(AddressableCont.class), changedContainer.getIdentifier()); + assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.modificationType()); + assertEquals(new NodeStep<>(AddressableCont.class), changedContainer.step()); - final Collection> contChildren = changedContainer.getModifiedChildren(); + final var contChildren = changedContainer.modifiedChildren(); assertEquals(1, contChildren.size()); - final DataObjectModification changedChild = (DataObjectModification) contChildren - .iterator().next(); - assertEquals(ModificationType.WRITE, changedChild.getModificationType()); - assertEquals(new NodeStep<>(AddressableChild.class), changedChild.getIdentifier()); - assertEquals(new AddressableChildBuilder().build(), changedChild.getDataAfter()); + final var changedChild = (DataObjectModification) contChildren.iterator().next(); + assertEquals(ModificationType.WRITE, changedChild.modificationType()); + assertEquals(new NodeStep<>(AddressableChild.class), changedChild.step()); + assertEquals(new AddressableChildBuilder().build(), changedChild.dataAfter()); } @Test @@ -251,7 +247,7 @@ public class Mdsal298Test extends AbstractDataBrokerTest { final DataTreeChangeListener listener = assertWrittenContainer(UnaddressableCont.QNAME, UnaddressableCont.class, new UnaddressableContBuilder().build()); - doNothing().when(listener).onDataTreeChanged(anyCollection()); + doNothing().when(listener).onDataTreeChanged(anyList()); final DOMDataTreeWriteTransaction domTx = getDomBroker().newWriteOnlyTransaction(); domTx.put(CONFIGURATION, YangInstanceIdentifier.of(UNADDRESSABLE_CONTAINER_NID) @@ -259,18 +255,18 @@ public class Mdsal298Test extends AbstractDataBrokerTest { ImmutableNodes.leafNode(BAZ_QNAME, "baz")); domTx.commit().get(); - final var captor = ArgumentCaptor.forClass(Collection.class); + final var captor = ArgumentCaptor.forClass(List.class); verify(listener).onDataTreeChanged(captor.capture()); - Collection> capture = captor.getValue(); + List> capture = captor.getValue(); assertEquals(1, capture.size()); final DataTreeModification contChange = capture.iterator().next(); assertEquals(UNADDRESSABLE_CONTAINER_TID, contChange.getRootPath()); final DataObjectModification changedContainer = contChange.getRootNode(); - assertEquals(ModificationType.WRITE, changedContainer.getModificationType()); - assertEquals(new NodeStep<>(UnaddressableCont.class), changedContainer.getIdentifier()); + assertEquals(ModificationType.WRITE, changedContainer.modificationType()); + assertEquals(new NodeStep<>(UnaddressableCont.class), changedContainer.step()); - final Collection> contChildren = changedContainer.getModifiedChildren(); + final var contChildren = changedContainer.modifiedChildren(); assertEquals(0, contChildren.size()); } @@ -278,7 +274,7 @@ public class Mdsal298Test extends AbstractDataBrokerTest { public void testChoiceDataTreeModificationUnaddressable() throws InterruptedException, ExecutionException { final DataTreeChangeListener listener = assertWrittenWithChoice(); - doNothing().when(listener).onDataTreeChanged(anyCollection()); + doNothing().when(listener).onDataTreeChanged(anyList()); final DOMDataTreeWriteTransaction domTx = getDomBroker().newWriteOnlyTransaction(); domTx.put(CONFIGURATION, YangInstanceIdentifier.of(CHOICE_CONTAINER_NID).node(Foo.QNAME), @@ -291,20 +287,20 @@ public class Mdsal298Test extends AbstractDataBrokerTest { .build()); domTx.commit().get(); - final var captor = ArgumentCaptor.forClass(Collection.class); + final var captor = ArgumentCaptor.forClass(List.class); verify(listener).onDataTreeChanged(captor.capture()); - Collection> capture = captor.getValue(); + List> capture = captor.getValue(); assertEquals(1, capture.size()); - final DataTreeModification choiceChange = capture.iterator().next(); + final DataTreeModification choiceChange = capture.get(0); assertEquals(CHOICE_CONTAINER_TID, choiceChange.getRootPath()); final DataObjectModification changedContainer = choiceChange.getRootNode(); // Should be write - assertEquals(ModificationType.WRITE, changedContainer.getModificationType()); - assertEquals(new NodeStep<>(WithChoice.class), changedContainer.getIdentifier()); + assertEquals(ModificationType.WRITE, changedContainer.modificationType()); + assertEquals(new NodeStep<>(WithChoice.class), changedContainer.step()); - final Collection> choiceChildren = changedContainer.getModifiedChildren(); + final var choiceChildren = changedContainer.modifiedChildren(); assertEquals(0, choiceChildren.size()); } @@ -312,7 +308,7 @@ public class Mdsal298Test extends AbstractDataBrokerTest { final Class bindingClass, final T expected) throws InterruptedException, ExecutionException { final DataTreeChangeListener listener = mock(DataTreeChangeListener.class); - doNothing().when(listener).onDataTreeChanged(anyCollection()); + doNothing().when(listener).onDataTreeChanged(anyList()); final DataTreeIdentifier dti = DataTreeIdentifier.of(CONFIGURATION, InstanceIdentifier.create(bindingClass)); getDataBroker().registerDataTreeChangeListener(dti, listener); @@ -322,32 +318,32 @@ public class Mdsal298Test extends AbstractDataBrokerTest { ImmutableNodes.newContainerBuilder().withNodeIdentifier(new NodeIdentifier(qname)).build()); domTx.commit().get(); - final var captor = ArgumentCaptor.forClass(Collection.class); + final var captor = ArgumentCaptor.forClass(List.class); verify(listener).onDataTreeChanged(captor.capture()); - Collection> capture = captor.getValue(); + List> capture = captor.getValue(); assertEquals(1, capture.size()); final DataTreeModification change = capture.iterator().next(); assertEquals(dti, change.getRootPath()); final DataObjectModification changedContainer = change.getRootNode(); - assertEquals(ModificationType.WRITE, changedContainer.getModificationType()); - assertEquals(new NodeStep<>(bindingClass), changedContainer.getIdentifier()); + assertEquals(ModificationType.WRITE, changedContainer.modificationType()); + assertEquals(new NodeStep<>(bindingClass), changedContainer.step()); - final T containerAfter = changedContainer.getDataAfter(); + final T containerAfter = changedContainer.dataAfter(); assertEquals(expected, containerAfter); // No further modifications should occur - assertEquals(List.of(), changedContainer.getModifiedChildren()); + assertEquals(List.of(), changedContainer.modifiedChildren()); reset(listener); - doNothing().when(listener).onDataTreeChanged(anyCollection()); + doNothing().when(listener).onDataTreeChanged(anyList()); return listener; } private DataTreeChangeListener assertWrittenWithChoice() throws InterruptedException, ExecutionException { final DataTreeChangeListener listener = mock(DataTreeChangeListener.class); - doNothing().when(listener).onDataTreeChanged(anyCollection()); + doNothing().when(listener).onDataTreeChanged(anyList()); getDataBroker().registerDataTreeChangeListener(CHOICE_CONTAINER_TID, listener); final DOMDataTreeWriteTransaction domTx = getDomBroker().newWriteOnlyTransaction(); @@ -357,25 +353,25 @@ public class Mdsal298Test extends AbstractDataBrokerTest { .build()); domTx.commit().get(); - final var captor = ArgumentCaptor.forClass(Collection.class); + final var captor = ArgumentCaptor.forClass(List.class); verify(listener).onDataTreeChanged(captor.capture()); - Collection> capture = captor.getValue(); + List> capture = captor.getValue(); assertEquals(1, capture.size()); final DataTreeModification change = capture.iterator().next(); assertEquals(CHOICE_CONTAINER_TID, change.getRootPath()); final DataObjectModification changedContainer = change.getRootNode(); - assertEquals(ModificationType.WRITE, changedContainer.getModificationType()); - assertEquals(new NodeStep<>(WithChoice.class), changedContainer.getIdentifier()); + assertEquals(ModificationType.WRITE, changedContainer.modificationType()); + assertEquals(new NodeStep<>(WithChoice.class), changedContainer.step()); - final WithChoice containerAfter = changedContainer.getDataAfter(); + final WithChoice containerAfter = changedContainer.dataAfter(); assertEquals(new WithChoiceBuilder().build(), containerAfter); // No further modifications should occur - assertEquals(List.of(), changedContainer.getModifiedChildren()); + assertEquals(List.of(), changedContainer.modifiedChildren()); reset(listener); - doNothing().when(listener).onDataTreeChanged(anyCollection()); + doNothing().when(listener).onDataTreeChanged(anyList()); return listener; } diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/AbstractDataTreeChangeListenerTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/AbstractDataTreeChangeListenerTest.java index 274ca6eeac..e2b4887f83 100644 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/AbstractDataTreeChangeListenerTest.java +++ b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/AbstractDataTreeChangeListenerTest.java @@ -14,8 +14,8 @@ import com.google.common.base.Stopwatch; import com.google.common.util.concurrent.Uninterruptibles; import java.util.ArrayDeque; import java.util.Arrays; -import java.util.Collection; import java.util.Deque; +import java.util.List; import java.util.Objects; import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNull; @@ -90,7 +90,7 @@ public class AbstractDataTreeChangeListenerTest extends AbstractConcurrentDataBr private boolean synced; @Override - public synchronized void onDataTreeChanged(final Collection> changes) { + public synchronized void onDataTreeChanged(final List> changes) { accumulatedChanges.addAll(changes); synced = true; }