Search in sources :

Example 1 with DOMDataTreeChangeListener

use of org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener in project controller by opendaylight.

the class ShardDataTreeTest method testListenerNotifiedOnApplySnapshot.

@Test
public void testListenerNotifiedOnApplySnapshot() throws Exception {
    immediatePayloadReplication(shardDataTree, mockShard);
    DOMDataTreeChangeListener listener = mock(DOMDataTreeChangeListener.class);
    shardDataTree.registerTreeChangeListener(CarsModel.CAR_LIST_PATH.node(CarsModel.CAR_QNAME), listener, com.google.common.base.Optional.absent(), noop -> {
    });
    addCar(shardDataTree, "optima");
    verifyOnDataTreeChanged(listener, dtc -> {
        assertEquals("getModificationType", ModificationType.WRITE, dtc.getRootNode().getModificationType());
        assertEquals("getRootPath", CarsModel.newCarPath("optima"), dtc.getRootPath());
    });
    addCar(shardDataTree, "sportage");
    verifyOnDataTreeChanged(listener, dtc -> {
        assertEquals("getModificationType", ModificationType.WRITE, dtc.getRootNode().getModificationType());
        assertEquals("getRootPath", CarsModel.newCarPath("sportage"), dtc.getRootPath());
    });
    ShardDataTree newDataTree = new ShardDataTree(mockShard, fullSchema, TreeType.OPERATIONAL);
    immediatePayloadReplication(newDataTree, mockShard);
    addCar(newDataTree, "optima");
    addCar(newDataTree, "murano");
    shardDataTree.applySnapshot(newDataTree.takeStateSnapshot());
    Map<YangInstanceIdentifier, ModificationType> expChanges = Maps.newHashMap();
    expChanges.put(CarsModel.newCarPath("optima"), ModificationType.WRITE);
    expChanges.put(CarsModel.newCarPath("murano"), ModificationType.WRITE);
    expChanges.put(CarsModel.newCarPath("sportage"), ModificationType.DELETE);
    verifyOnDataTreeChanged(listener, dtc -> {
        ModificationType expType = expChanges.remove(dtc.getRootPath());
        assertNotNull("Got unexpected change for " + dtc.getRootPath(), expType);
        assertEquals("getModificationType", expType, dtc.getRootNode().getModificationType());
    });
    if (!expChanges.isEmpty()) {
        fail("Missing change notifications: " + expChanges);
    }
}
Also used : ModificationType(org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 2 with DOMDataTreeChangeListener

use of org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener in project controller by opendaylight.

the class DataTreeChangeListenerActorTest method testDataChangedWithListenerRuntimeEx.

@Test
public void testDataChangedWithListenerRuntimeEx() {
    new TestKit(getSystem()) {

        {
            final DataTreeCandidate mockTreeCandidate1 = Mockito.mock(DataTreeCandidate.class);
            final ImmutableList<DataTreeCandidate> mockCandidates1 = ImmutableList.of(mockTreeCandidate1);
            final DataTreeCandidate mockTreeCandidate2 = Mockito.mock(DataTreeCandidate.class);
            final ImmutableList<DataTreeCandidate> mockCandidates2 = ImmutableList.of(mockTreeCandidate2);
            final DataTreeCandidate mockTreeCandidate3 = Mockito.mock(DataTreeCandidate.class);
            final ImmutableList<DataTreeCandidate> mockCandidates3 = ImmutableList.of(mockTreeCandidate3);
            final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
            Mockito.doThrow(new RuntimeException("mock")).when(mockListener).onDataTreeChanged(mockCandidates2);
            Props props = DataTreeChangeListenerActor.props(mockListener, TEST_PATH);
            ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedWithListenerRuntimeEx");
            // Let the DataChangeListener know that notifications should be
            // enabled
            subject.tell(new EnableNotification(true, "test"), getRef());
            subject.tell(new DataTreeChanged(mockCandidates1), getRef());
            expectMsgClass(DataTreeChangedReply.class);
            subject.tell(new DataTreeChanged(mockCandidates2), getRef());
            expectMsgClass(DataTreeChangedReply.class);
            subject.tell(new DataTreeChanged(mockCandidates3), getRef());
            expectMsgClass(DataTreeChangedReply.class);
            Mockito.verify(mockListener).onDataTreeChanged(mockCandidates1);
            Mockito.verify(mockListener).onDataTreeChanged(mockCandidates2);
            Mockito.verify(mockListener).onDataTreeChanged(mockCandidates3);
        }
    };
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) EnableNotification(org.opendaylight.controller.cluster.datastore.messages.EnableNotification) DataTreeChanged(org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener) ActorRef(akka.actor.ActorRef) TestKit(akka.testkit.javadsl.TestKit) Props(akka.actor.Props) Test(org.junit.Test)

Example 3 with DOMDataTreeChangeListener

use of org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener in project controller by opendaylight.

the class DataTreeChangeListenerActorTest method testDataChangedWhenNotificationsAreDisabled.

@Test
public void testDataChangedWhenNotificationsAreDisabled() {
    new TestKit(getSystem()) {

        {
            final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class);
            final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate);
            final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
            final Props props = DataTreeChangeListenerActor.props(mockListener, TEST_PATH);
            final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedNotificationsDisabled");
            subject.tell(new DataTreeChanged(mockCandidates), getRef());
            within(duration("1 seconds"), () -> {
                expectNoMsg();
                Mockito.verify(mockListener, Mockito.never()).onDataTreeChanged(Matchers.anyCollectionOf(DataTreeCandidate.class));
                return null;
            });
        }
    };
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DataTreeChanged(org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener) ActorRef(akka.actor.ActorRef) TestKit(akka.testkit.javadsl.TestKit) Props(akka.actor.Props) Test(org.junit.Test)

Example 4 with DOMDataTreeChangeListener

use of org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener in project controller by opendaylight.

the class DataTreeChangeListenerActorTest method testDataChangedWithNoSender.

@Test
public void testDataChangedWithNoSender() {
    new TestKit(getSystem()) {

        {
            final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class);
            final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate);
            final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
            final Props props = DataTreeChangeListenerActor.props(mockListener, TEST_PATH);
            final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedWithNoSender");
            getSystem().eventStream().subscribe(getRef(), DeadLetter.class);
            subject.tell(new DataTreeChanged(mockCandidates), ActorRef.noSender());
            // Make sure no DataChangedReply is sent to DeadLetters.
            while (true) {
                DeadLetter deadLetter;
                try {
                    deadLetter = expectMsgClass(duration("1 seconds"), DeadLetter.class);
                } catch (AssertionError e) {
                    // Timed out - got no DeadLetter - this is good
                    break;
                }
                // We may get DeadLetters for other messages we don't care
                // about.
                Assert.assertFalse("Unexpected DataTreeChangedReply", deadLetter.message() instanceof DataTreeChangedReply);
            }
        }
    };
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DeadLetter(akka.actor.DeadLetter) DataTreeChanged(org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener) ActorRef(akka.actor.ActorRef) TestKit(akka.testkit.javadsl.TestKit) Props(akka.actor.Props) DataTreeChangedReply(org.opendaylight.controller.cluster.datastore.messages.DataTreeChangedReply) Test(org.junit.Test)

Example 5 with DOMDataTreeChangeListener

use of org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener in project controller by opendaylight.

the class DataTreeChangeListenerProxyTest method testLocalShardNotInitialized.

@Test(timeout = 10000)
public void testLocalShardNotInitialized() {
    new TestKit(getSystem()) {

        {
            ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
            final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(actorContext, mockListener, path);
            new Thread(() -> proxy.init("shard-1")).start();
            FiniteDuration timeout = duration("5 seconds");
            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
            reply(new NotInitializedException("not initialized"));
            within(duration("1 seconds"), () -> {
                expectNoMsg();
                return null;
            });
            proxy.close();
        }
    };
}
Also used : NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener) ClusteredDOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener) FiniteDuration(scala.concurrent.duration.FiniteDuration) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) TestKit(akka.testkit.javadsl.TestKit) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) Test(org.junit.Test)

Aggregations

DOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)11 Test (org.junit.Test)10 TestKit (akka.testkit.javadsl.TestKit)9 ActorRef (akka.actor.ActorRef)6 Props (akka.actor.Props)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)6 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)5 ClusteredDOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener)5 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)4 DataTreeChanged (org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged)4 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)4 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)4 FiniteDuration (scala.concurrent.duration.FiniteDuration)4 ActorSystem (akka.actor.ActorSystem)2 Timeout (akka.util.Timeout)2 NotInitializedException (org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException)2 EnableNotification (org.opendaylight.controller.cluster.datastore.messages.EnableNotification)2 LocalShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardFound)2 LocalShardNotFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound)2 RegisterDataTreeChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener)2