X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDataTreeChangeListenerActorTest.java;h=726b29007a426f734f539b069945141979f3d207;hb=a6af137c30470b86d4bc624d4c48cb686495a182;hp=37a6197dd8170d76ea4800c858bac69b5f2b5baa;hpb=a54ec60368110d22794602343c934902f6833c65;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerActorTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerActorTest.java index 37a6197dd8..726b29007a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerActorTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerActorTest.java @@ -7,10 +7,12 @@ */ package org.opendaylight.controller.cluster.datastore; +import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.TEST_PATH; + import akka.actor.ActorRef; import akka.actor.DeadLetter; import akka.actor.Props; -import akka.testkit.JavaTestKit; +import akka.testkit.javadsl.TestKit; import com.google.common.collect.ImmutableList; import org.junit.Assert; import org.junit.Test; @@ -19,122 +21,123 @@ import org.mockito.Mockito; import org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged; import org.opendaylight.controller.cluster.datastore.messages.DataTreeChangedReply; import org.opendaylight.controller.cluster.datastore.messages.EnableNotification; -import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener; +import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; public class DataTreeChangeListenerActorTest extends AbstractActorTest { - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test - public void testDataChangedWhenNotificationsAreEnabled(){ - new JavaTestKit(getSystem()) {{ - final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class); - final ImmutableList mockCandidates = ImmutableList.of(mockTreeCandidate); - final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class); - final Props props = DataTreeChangeListenerActor.props(mockListener); - final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedNotificationsEnabled"); + public void testDataChangedWhenNotificationsAreEnabled() { + new TestKit(getSystem()) { + { + final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class); + final ImmutableList 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, "testDataTreeChangedNotificationsEnabled"); - // Let the DataChangeListener know that notifications should be enabled - subject.tell(new EnableNotification(true), getRef()); + // Let the DataChangeListener know that notifications should be + // enabled + subject.tell(new EnableNotification(true, "test"), getRef()); - subject.tell(new DataTreeChanged(mockCandidates), - getRef()); + subject.tell(new DataTreeChanged(mockCandidates), getRef()); - expectMsgClass(DataTreeChangedReply.class); + expectMsgClass(DataTreeChangedReply.class); - Mockito.verify(mockListener).onDataTreeChanged(mockCandidates); - }}; + Mockito.verify(mockListener).onDataTreeChanged(mockCandidates); + } + }; } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test - public void testDataChangedWhenNotificationsAreDisabled(){ - new JavaTestKit(getSystem()) {{ - final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class); - final ImmutableList mockCandidates = ImmutableList.of(mockTreeCandidate); - final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class); - final Props props = DataTreeChangeListenerActor.props(mockListener); - final ActorRef subject = - getSystem().actorOf(props, "testDataTreeChangedNotificationsDisabled"); - - subject.tell(new DataTreeChanged(mockCandidates), - getRef()); - - new Within(duration("1 seconds")) { - @Override - protected void run() { + public void testDataChangedWhenNotificationsAreDisabled() { + new TestKit(getSystem()) { + { + final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class); + final ImmutableList 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)); - } - }; - }}; + Mockito.verify(mockListener, Mockito.never()) + .onDataTreeChanged(Matchers.anyCollectionOf(DataTreeCandidate.class)); + return null; + }); + } + }; } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test - public void testDataChangedWithNoSender(){ - new JavaTestKit(getSystem()) {{ - final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class); - final ImmutableList mockCandidates = ImmutableList.of(mockTreeCandidate); - final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class); - final Props props = DataTreeChangeListenerActor.props(mockListener); - 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; + public void testDataChangedWithNoSender() { + new TestKit(getSystem()) { + { + final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class); + final ImmutableList 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); } - - // We may get DeadLetters for other messages we don't care about. - Assert.assertFalse("Unexpected DataTreeChangedReply", - deadLetter.message() instanceof DataTreeChangedReply); } - }}; + }; } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test - public void testDataChangedWithListenerRuntimeEx(){ - new JavaTestKit(getSystem()) {{ - final DataTreeCandidate mockTreeCandidate1 = Mockito.mock(DataTreeCandidate.class); - final ImmutableList mockCandidates1 = ImmutableList.of(mockTreeCandidate1); - final DataTreeCandidate mockTreeCandidate2 = Mockito.mock(DataTreeCandidate.class); - final ImmutableList mockCandidates2 = ImmutableList.of(mockTreeCandidate2); - final DataTreeCandidate mockTreeCandidate3 = Mockito.mock(DataTreeCandidate.class); - final ImmutableList 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); - ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedWithListenerRuntimeEx"); - - // Let the DataChangeListener know that notifications should be enabled - subject.tell(new EnableNotification(true), 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); - }}; + public void testDataChangedWithListenerRuntimeEx() { + new TestKit(getSystem()) { + { + final DataTreeCandidate mockTreeCandidate1 = Mockito.mock(DataTreeCandidate.class); + final ImmutableList mockCandidates1 = ImmutableList.of(mockTreeCandidate1); + final DataTreeCandidate mockTreeCandidate2 = Mockito.mock(DataTreeCandidate.class); + final ImmutableList mockCandidates2 = ImmutableList.of(mockTreeCandidate2); + final DataTreeCandidate mockTreeCandidate3 = Mockito.mock(DataTreeCandidate.class); + final ImmutableList 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); + } + }; } }