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);
}
};
}
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);
}
};
}
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;
}
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();
}
}
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);
}
};
}
Aggregations