Search in sources :

Example 11 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class DataChangeListenerTest method testDataChangedWhenNotificationsAreEnabled.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testDataChangedWhenNotificationsAreEnabled() {
    new TestKit(getSystem()) {

        {
            final AsyncDataChangeEvent mockChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
            final AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
            final Props props = DataChangeListener.props(mockListener, TEST_PATH);
            final ActorRef subject = getSystem().actorOf(props, "testDataChangedNotificationsEnabled");
            // Let the DataChangeListener know that notifications should be
            // enabled
            subject.tell(new EnableNotification(true, "test"), getRef());
            subject.tell(new DataChanged(mockChangeEvent), getRef());
            expectMsgClass(DataChangedReply.class);
            Mockito.verify(mockListener).onDataChanged(mockChangeEvent);
        }
    };
}
Also used : DataChanged(org.opendaylight.controller.cluster.datastore.messages.DataChanged) EnableNotification(org.opendaylight.controller.cluster.datastore.messages.EnableNotification) AsyncDataChangeListener(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener) ActorRef(akka.actor.ActorRef) TestKit(akka.testkit.javadsl.TestKit) Props(akka.actor.Props) AsyncDataChangeEvent(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent) Test(org.junit.Test)

Example 12 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class DataChangeListenerTest method testDataChangedWhenNotificationsAreDisabled.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testDataChangedWhenNotificationsAreDisabled() {
    new TestKit(getSystem()) {

        {
            final AsyncDataChangeEvent mockChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
            final AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
            final Props props = DataChangeListener.props(mockListener, TEST_PATH);
            final ActorRef subject = getSystem().actorOf(props, "testDataChangedNotificationsDisabled");
            subject.tell(new DataChanged(mockChangeEvent), getRef());
            within(duration("1 seconds"), () -> {
                expectNoMsg();
                Mockito.verify(mockListener, Mockito.never()).onDataChanged(Mockito.any(AsyncDataChangeEvent.class));
                return null;
            });
        }
    };
}
Also used : DataChanged(org.opendaylight.controller.cluster.datastore.messages.DataChanged) AsyncDataChangeListener(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener) ActorRef(akka.actor.ActorRef) TestKit(akka.testkit.javadsl.TestKit) Props(akka.actor.Props) AsyncDataChangeEvent(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent) Test(org.junit.Test)

Example 13 with TestKit

use of akka.testkit.javadsl.TestKit 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 14 with TestKit

use of akka.testkit.javadsl.TestKit 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 15 with TestKit

use of akka.testkit.javadsl.TestKit 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)

Aggregations

TestKit (akka.testkit.javadsl.TestKit)124 Test (org.junit.Test)115 ActorRef (akka.actor.ActorRef)84 TestActorRef (akka.testkit.TestActorRef)63 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)44 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)37 AddressFromURIString (akka.actor.AddressFromURIString)28 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)26 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)22 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)22 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)17 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)17 FindPrimary (org.opendaylight.controller.cluster.datastore.messages.FindPrimary)16 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)16 Props (akka.actor.Props)15 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)15 Failure (akka.actor.Status.Failure)14 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)14 FiniteDuration (scala.concurrent.duration.FiniteDuration)14 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)13