Search in sources :

Example 6 with LocalShardFound

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

the class ShardManagerTest method testOnReceiveFindLocalShardForExistentShard.

@Test
public void testOnReceiveFindLocalShardForExistentShard() throws Exception {
    new TestKit(getSystem()) {

        {
            final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
            shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
            shardManager.tell(new ActorInitialized(), mockShardActor);
            shardManager.tell(new FindLocalShard(Shard.DEFAULT_NAME, false), getRef());
            LocalShardFound found = expectMsgClass(duration("5 seconds"), LocalShardFound.class);
            assertTrue("Found path contains " + found.getPath().path().toString(), found.getPath().path().toString().contains("member-1-shard-default-config"));
        }
    };
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) LocalShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardFound) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) FindLocalShard(org.opendaylight.controller.cluster.datastore.messages.FindLocalShard) ActorInitialized(org.opendaylight.controller.cluster.datastore.messages.ActorInitialized) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test) AbstractShardManagerTest(org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)

Example 7 with LocalShardFound

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

the class ShardManager method findLocalShard.

private void findLocalShard(final FindLocalShard message) {
    LOG.debug("{}: findLocalShard : {}", persistenceId(), message.getShardName());
    final ShardInformation shardInformation = localShards.get(message.getShardName());
    if (shardInformation == null) {
        LOG.debug("{}: Local shard {} not found - shards present: {}", persistenceId(), message.getShardName(), localShards.keySet());
        getSender().tell(new LocalShardNotFound(message.getShardName()), getSelf());
        return;
    }
    sendResponse(shardInformation, message.isWaitUntilInitialized(), false, () -> new LocalShardFound(shardInformation.getActor()));
}
Also used : LocalShardNotFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound) LocalShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardFound)

Example 8 with LocalShardFound

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

the class DataChangeListenerRegistrationProxyTest method testSuccessfulRegistration.

@Test(timeout = 10000)
public void testSuccessfulRegistration() {
    new TestKit(getSystem()) {

        {
            ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
            final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy("shard-1", actorContext, mockListener);
            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
            final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
            new Thread(() -> proxy.init(path, scope)).start();
            FiniteDuration timeout = duration("5 seconds");
            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
            reply(new LocalShardFound(getRef()));
            RegisterChangeListener registerMsg = expectMsgClass(timeout, RegisterChangeListener.class);
            Assert.assertEquals("getPath", path, registerMsg.getPath());
            Assert.assertEquals("getScope", scope, registerMsg.getScope());
            Assert.assertEquals("isRegisterOnAllInstances", false, registerMsg.isRegisterOnAllInstances());
            reply(new RegisterDataTreeNotificationListenerReply(getRef()));
            for (int i = 0; i < 20 * 5 && proxy.getListenerRegistrationActor() == null; i++) {
                Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
            }
            Assert.assertEquals("getListenerRegistrationActor", getSystem().actorSelection(getRef().path()), proxy.getListenerRegistrationActor());
            watch(proxy.getDataChangeListenerActor());
            proxy.close();
            // The listener registration actor should get a Close message
            expectMsgClass(timeout, CloseDataTreeNotificationListenerRegistration.class);
            // The DataChangeListener actor should be terminated
            expectMsgClass(timeout, Terminated.class);
            proxy.close();
            expectNoMsg();
        }
    };
}
Also used : DataChangeScope(org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope) RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) LocalShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardFound) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) RegisterChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener) 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 9 with LocalShardFound

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

the class DataTreeChangeListenerProxyTest method testSuccessfulRegistrationForClusteredListener.

@Test(timeout = 10000)
public void testSuccessfulRegistrationForClusteredListener() {
    new TestKit(getSystem()) {

        {
            ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
            ClusteredDOMDataTreeChangeListener mockClusteredListener = mock(ClusteredDOMDataTreeChangeListener.class);
            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
            final DataTreeChangeListenerProxy<ClusteredDOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(actorContext, mockClusteredListener, 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 LocalShardFound(getRef()));
            RegisterDataTreeChangeListener registerMsg = expectMsgClass(timeout, RegisterDataTreeChangeListener.class);
            Assert.assertEquals("getPath", path, registerMsg.getPath());
            Assert.assertEquals("isRegisterOnAllInstances", true, registerMsg.isRegisterOnAllInstances());
            proxy.close();
        }
    };
}
Also used : LocalShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardFound) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) 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) RegisterDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) ClusteredDOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener) Test(org.junit.Test)

Example 10 with LocalShardFound

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

the class DataTreeChangeListenerProxyTest method testSuccessfulRegistration.

@Test(timeout = 10000)
public void testSuccessfulRegistration() {
    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 LocalShardFound(getRef()));
            RegisterDataTreeChangeListener registerMsg = expectMsgClass(timeout, RegisterDataTreeChangeListener.class);
            Assert.assertEquals("getPath", path, registerMsg.getPath());
            Assert.assertEquals("isRegisterOnAllInstances", false, registerMsg.isRegisterOnAllInstances());
            reply(new RegisterDataTreeNotificationListenerReply(getRef()));
            for (int i = 0; i < 20 * 5 && proxy.getListenerRegistrationActor() == null; i++) {
                Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
            }
            Assert.assertEquals("getListenerRegistrationActor", getSystem().actorSelection(getRef().path()), proxy.getListenerRegistrationActor());
            watch(proxy.getDataChangeListenerActor());
            proxy.close();
            // The listener registration actor should get a Close message
            expectMsgClass(timeout, CloseDataTreeNotificationListenerRegistration.class);
            // The DataChangeListener actor should be terminated
            expectMsgClass(timeout, Terminated.class);
            proxy.close();
            expectNoMsg();
        }
    };
}
Also used : RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) LocalShardFound(org.opendaylight.controller.cluster.datastore.messages.LocalShardFound) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) 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) RegisterDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) DOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener) ClusteredDOMDataTreeChangeListener(org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener) Test(org.junit.Test)

Aggregations

LocalShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardFound)10 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)9 TestKit (akka.testkit.javadsl.TestKit)6 Test (org.junit.Test)6 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)4 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)4 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)3 FiniteDuration (scala.concurrent.duration.FiniteDuration)3 ActorRef (akka.actor.ActorRef)2 TestActorRef (akka.testkit.TestActorRef)2 Timeout (akka.util.Timeout)2 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)2 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)2 LocalShardNotFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound)2 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)2 RegisterDataTreeChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener)2 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)2 DataChangeScope (org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope)2 ClusteredDOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener)2