Search in sources :

Example 1 with EnableNotification

use of org.opendaylight.controller.cluster.datastore.messages.EnableNotification 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 2 with EnableNotification

use of org.opendaylight.controller.cluster.datastore.messages.EnableNotification 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 EnableNotification

use of org.opendaylight.controller.cluster.datastore.messages.EnableNotification in project controller by opendaylight.

the class AbstractDataListenerSupport method processListenerRegistrationMessage.

protected ActorSelection processListenerRegistrationMessage(M message) {
    final ActorSelection listenerActor = selectActor(message.getListenerActorPath());
    // We have a leader so enable the listener.
    listenerActor.tell(new EnableNotification(true, persistenceId()), getSelf());
    if (!message.isRegisterOnAllInstances()) {
        // This is a leader-only registration so store a reference to the listener actor so it can be notified
        // at a later point if notifications should be enabled or disabled.
        leaderOnlyListenerActors.add(listenerActor);
    }
    allListenerActors.add(listenerActor);
    return listenerActor;
}
Also used : ActorSelection(akka.actor.ActorSelection) EnableNotification(org.opendaylight.controller.cluster.datastore.messages.EnableNotification)

Example 4 with EnableNotification

use of org.opendaylight.controller.cluster.datastore.messages.EnableNotification in project controller by opendaylight.

the class AbstractDataListenerSupport method onLeadershipChange.

@Override
void onLeadershipChange(boolean isLeader, boolean hasLeader) {
    log.debug("{}: onLeadershipChange, isLeader: {}, hasLeader : {}", persistenceId(), isLeader, hasLeader);
    final EnableNotification msg = new EnableNotification(isLeader, persistenceId());
    for (ActorSelection dataChangeListener : leaderOnlyListenerActors) {
        dataChangeListener.tell(msg, getSelf());
    }
    if (hasLeader) {
        for (DelayedListenerRegistration<L, M> reg : delayedListenerOnAllRegistrations) {
            reg.doRegistration(this);
        }
        delayedListenerOnAllRegistrations.clear();
    }
    if (isLeader) {
        for (DelayedListenerRegistration<L, M> reg : delayedListenerRegistrations) {
            reg.doRegistration(this);
        }
        delayedListenerRegistrations.clear();
    }
}
Also used : ActorSelection(akka.actor.ActorSelection) EnableNotification(org.opendaylight.controller.cluster.datastore.messages.EnableNotification)

Example 5 with EnableNotification

use of org.opendaylight.controller.cluster.datastore.messages.EnableNotification in project controller by opendaylight.

the class DataChangeListenerTest method testDataChangedWithListenerRuntimeEx.

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

        {
            final AsyncDataChangeEvent mockChangeEvent1 = Mockito.mock(AsyncDataChangeEvent.class);
            final AsyncDataChangeEvent mockChangeEvent2 = Mockito.mock(AsyncDataChangeEvent.class);
            final AsyncDataChangeEvent mockChangeEvent3 = Mockito.mock(AsyncDataChangeEvent.class);
            AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
            Mockito.doThrow(new RuntimeException("mock")).when(mockListener).onDataChanged(mockChangeEvent2);
            Props props = DataChangeListener.props(mockListener, TEST_PATH);
            ActorRef subject = getSystem().actorOf(props, "testDataChangedWithListenerRuntimeEx");
            // Let the DataChangeListener know that notifications should be
            // enabled
            subject.tell(new EnableNotification(true, "test"), getRef());
            subject.tell(new DataChanged(mockChangeEvent1), getRef());
            expectMsgClass(DataChangedReply.class);
            subject.tell(new DataChanged(mockChangeEvent2), getRef());
            expectMsgClass(DataChangedReply.class);
            subject.tell(new DataChanged(mockChangeEvent3), getRef());
            expectMsgClass(DataChangedReply.class);
            Mockito.verify(mockListener).onDataChanged(mockChangeEvent1);
            Mockito.verify(mockListener).onDataChanged(mockChangeEvent2);
            Mockito.verify(mockListener).onDataChanged(mockChangeEvent3);
        }
    };
}
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)

Aggregations

EnableNotification (org.opendaylight.controller.cluster.datastore.messages.EnableNotification)6 ActorRef (akka.actor.ActorRef)4 Props (akka.actor.Props)4 TestKit (akka.testkit.javadsl.TestKit)4 Test (org.junit.Test)4 ActorSelection (akka.actor.ActorSelection)2 DataChanged (org.opendaylight.controller.cluster.datastore.messages.DataChanged)2 DataTreeChanged (org.opendaylight.controller.cluster.datastore.messages.DataTreeChanged)2 AsyncDataChangeEvent (org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent)2 AsyncDataChangeListener (org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener)2 DOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)2 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)2