Search in sources :

Example 6 with DOMDataTreeChangeListener

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

the class DataTreeChangeListenerProxyTest method testFailedRegistration.

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

        {
            ActorSystem mockActorSystem = mock(ActorSystem.class);
            ActorRef mockActor = getSystem().actorOf(Props.create(DoNothingActor.class), "testFailedRegistration");
            doReturn(mockActor).when(mockActorSystem).actorOf(any(Props.class));
            ExecutionContextExecutor executor = ExecutionContexts.fromExecutor(MoreExecutors.directExecutor());
            ActorContext actorContext = mock(ActorContext.class);
            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
            doReturn(executor).when(actorContext).getClientDispatcher();
            doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext();
            doReturn(mockActorSystem).when(actorContext).getActorSystem();
            String shardName = "shard-1";
            final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(actorContext, mockListener, path);
            doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
            doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
            doReturn(Futures.failed(new RuntimeException("mock"))).when(actorContext).executeOperationAsync(any(ActorRef.class), any(Object.class), any(Timeout.class));
            doReturn(mock(DatastoreContext.class)).when(actorContext).getDatastoreContext();
            proxy.init("shard-1");
            Assert.assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor());
            proxy.close();
        }
    };
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) TestKit(akka.testkit.javadsl.TestKit) Props(akka.actor.Props) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) DoNothingActor(org.opendaylight.controller.cluster.raft.utils.DoNothingActor) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener) ClusteredDOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener) ExecutionContextExecutor(scala.concurrent.ExecutionContextExecutor) Test(org.junit.Test)

Example 7 with DOMDataTreeChangeListener

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

the class DataTreeChangeListenerProxyTest method testLocalShardNotFound.

@Test(timeout = 10000)
public void testLocalShardNotFound() {
    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 LocalShardNotFound("shard-1"));
            expectNoMsg(duration("1 seconds"));
            proxy.close();
        }
    };
}
Also used : LocalShardNotFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound) 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)

Example 8 with DOMDataTreeChangeListener

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

the class DataTreeChangeListenerSupport method doRegistration.

@Override
void doRegistration(final RegisterDataTreeChangeListener message, final ActorRef registrationActor) {
    final ActorSelection listenerActor = processListenerRegistrationMessage(message);
    DOMDataTreeChangeListener listener = new ForwardingDataTreeChangeListener(listenerActor);
    log().debug("{}: Registering listenerActor {} for path {}", persistenceId(), listenerActor, message.getPath());
    final ShardDataTree shardDataTree = getShard().getDataStore();
    shardDataTree.registerTreeChangeListener(message.getPath(), listener, shardDataTree.readCurrentData(), registration -> registrationActor.tell(new DataTreeNotificationListenerRegistrationActor.SetRegistration(registration, () -> removeListenerActor(listenerActor)), ActorRef.noSender()));
}
Also used : ActorSelection(akka.actor.ActorSelection) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)

Example 9 with DOMDataTreeChangeListener

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

the class DataTreeChangeListenerActorTest method testDataChangedWhenNotificationsAreEnabled.

@Test
public void testDataChangedWhenNotificationsAreEnabled() {
    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, "testDataTreeChangedNotificationsEnabled");
            // Let the DataChangeListener know that notifications should be
            // enabled
            subject.tell(new EnableNotification(true, "test"), getRef());
            subject.tell(new DataTreeChanged(mockCandidates), getRef());
            expectMsgClass(DataTreeChangedReply.class);
            Mockito.verify(mockListener).onDataTreeChanged(mockCandidates);
        }
    };
}
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 10 with DOMDataTreeChangeListener

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

the class DataTreeChangeListenerProxyTest method testCloseBeforeRegistration.

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

        {
            ActorContext actorContext = mock(ActorContext.class);
            String shardName = "shard-1";
            doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext();
            doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(actorContext).getClientDispatcher();
            doReturn(getSystem()).when(actorContext).getActorSystem();
            doReturn(Dispatchers.DEFAULT_DISPATCHER_PATH).when(actorContext).getNotificationDispatcherPath();
            doReturn(getSystem().actorSelection(getRef().path())).when(actorContext).actorSelection(getRef().path());
            doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
            doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
            final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(actorContext, mockListener, YangInstanceIdentifier.of(TestModel.TEST_QNAME));
            Answer<Future<Object>> answer = invocation -> {
                proxy.close();
                return Futures.successful((Object) new RegisterDataTreeNotificationListenerReply(getRef()));
            };
            doAnswer(answer).when(actorContext).executeOperationAsync(any(ActorRef.class), any(Object.class), any(Timeout.class));
            proxy.init(shardName);
            expectMsgClass(duration("5 seconds"), CloseDataTreeNotificationListenerRegistration.class);
            Assert.assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor());
        }
    };
}
Also used : Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) Terminated(akka.actor.Terminated) NotInitializedException(org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException) TestModel(org.opendaylight.controller.md.cluster.datastore.model.TestModel) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener) Timeout(akka.util.Timeout) LocalShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardFound) Answer(org.mockito.stubbing.Answer) LocalShardNotFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound) DoNothingActor(org.opendaylight.controller.cluster.raft.utils.DoNothingActor) ActorRef(akka.actor.ActorRef) Matchers.eq(org.mockito.Matchers.eq) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) CloseDataTreeNotificationListenerRegistration(org.opendaylight.controller.cluster.datastore.messages.CloseDataTreeNotificationListenerRegistration) ClusteredDOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener) Mockito.doReturn(org.mockito.Mockito.doReturn) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Future(scala.concurrent.Future) FiniteDuration(scala.concurrent.duration.FiniteDuration) Test(org.junit.Test) TestKit(akka.testkit.javadsl.TestKit) ExecutionContexts(akka.dispatch.ExecutionContexts) Matchers.any(org.mockito.Matchers.any) Futures(akka.dispatch.Futures) TimeUnit(java.util.concurrent.TimeUnit) RegisterDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener) RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) ActorSystem(akka.actor.ActorSystem) ExecutionContextExecutor(scala.concurrent.ExecutionContextExecutor) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) Assert(org.junit.Assert) Props(akka.actor.Props) Mockito.mock(org.mockito.Mockito.mock) RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout) TestKit(akka.testkit.javadsl.TestKit) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener) ClusteredDOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener) Future(scala.concurrent.Future) 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