Search in sources :

Example 1 with RegisterDataTreeNotificationListenerReply

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

the class ShardTest method testClusteredDataTreeChangeListenerRegistration.

@Test
public void testClusteredDataTreeChangeListenerRegistration() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final String testName = "testClusteredDataTreeChangeListenerRegistration";
            final ShardIdentifier followerShardID = ShardIdentifier.create("inventory", MemberName.forName(actorFactory.generateActorId(testName + "-follower")), "config");
            final ShardIdentifier leaderShardID = ShardIdentifier.create("inventory", MemberName.forName(actorFactory.generateActorId(testName + "-leader")), "config");
            final TestActorRef<Shard> followerShard = actorFactory.createTestActor(Shard.builder().id(followerShardID).datastoreContext(dataStoreContextBuilder.shardElectionTimeoutFactor(1000).build()).peerAddresses(Collections.singletonMap(leaderShardID.toString(), "akka://test/user/" + leaderShardID.toString())).schemaContextProvider(() -> SCHEMA_CONTEXT).props().withDispatcher(Dispatchers.DefaultDispatcherId()), followerShardID.toString());
            final TestActorRef<Shard> leaderShard = actorFactory.createTestActor(Shard.builder().id(leaderShardID).datastoreContext(newDatastoreContext()).peerAddresses(Collections.singletonMap(followerShardID.toString(), "akka://test/user/" + followerShardID.toString())).schemaContextProvider(() -> SCHEMA_CONTEXT).props().withDispatcher(Dispatchers.DefaultDispatcherId()), leaderShardID.toString());
            leaderShard.tell(TimeoutNow.INSTANCE, ActorRef.noSender());
            final String leaderPath = waitUntilLeader(followerShard);
            assertEquals("Shard leader path", leaderShard.path().toString(), leaderPath);
            final YangInstanceIdentifier path = TestModel.TEST_PATH;
            final MockDataTreeChangeListener listener = new MockDataTreeChangeListener(1);
            final ActorRef dclActor = actorFactory.createActor(DataTreeChangeListenerActor.props(listener, path), actorFactory.generateActorId(testName + "-DataTreeChangeListener"));
            followerShard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, true), getRef());
            final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), RegisterDataTreeNotificationListenerReply.class);
            assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath());
            writeToStore(followerShard, path, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
            listener.waitForChangeEvents();
        }
    };
}
Also used : RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) MockDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) RegisterDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener) Test(org.junit.Test)

Example 2 with RegisterDataTreeNotificationListenerReply

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

the class ShardTest method testClusteredDataChangeListenerWithDelayedRegistration.

@Test
public void testClusteredDataChangeListenerWithDelayedRegistration() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final String testName = "testClusteredDataChangeListenerWithDelayedRegistration";
            dataStoreContextBuilder.shardElectionTimeoutFactor(1000).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName());
            final YangInstanceIdentifier path = TestModel.TEST_PATH;
            final MockDataChangeListener listener = new MockDataChangeListener(1);
            final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener, path), actorFactory.generateActorId(testName + "-DataChangeListener"));
            setupInMemorySnapshotStore();
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardBuilder().props().withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(testName + "-shard"));
            waitUntilNoLeader(shard);
            shard.tell(new RegisterChangeListener(path, dclActor, AsyncDataBroker.DataChangeScope.BASE, true), getRef());
            final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), RegisterDataTreeNotificationListenerReply.class);
            assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath());
            shard.tell(DatastoreContext.newBuilderFrom(dataStoreContextBuilder.build()).customRaftPolicyImplementation(null).build(), ActorRef.noSender());
            listener.waitForChangeEvents();
        }
    };
}
Also used : RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) MockDataChangeListener(org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener) RegisterChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 3 with RegisterDataTreeNotificationListenerReply

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

the class ShardTest method testRegisterChangeListener.

@Test
public void testRegisterChangeListener() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testRegisterChangeListener");
            waitUntilLeader(shard);
            shard.tell(new UpdateSchemaContext(SchemaContextHelper.full()), ActorRef.noSender());
            final MockDataChangeListener listener = new MockDataChangeListener(1);
            final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener, TestModel.TEST_PATH), "testRegisterChangeListener-DataChangeListener");
            shard.tell(new RegisterChangeListener(TestModel.TEST_PATH, dclActor, AsyncDataBroker.DataChangeScope.BASE, true), getRef());
            final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("3 seconds"), RegisterDataTreeNotificationListenerReply.class);
            final String replyPath = reply.getListenerRegistrationPath().toString();
            assertTrue("Incorrect reply path: " + replyPath, replyPath.matches("akka:\\/\\/test\\/user\\/testRegisterChangeListener\\/\\$.*"));
            final YangInstanceIdentifier path = TestModel.TEST_PATH;
            writeToStore(shard, path, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
            listener.waitForChangeEvents(path);
        }
    };
}
Also used : UpdateSchemaContext(org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext) RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) MockDataChangeListener(org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener) RegisterChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 4 with RegisterDataTreeNotificationListenerReply

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

the class ShardTest method testClusteredDataTreeChangeListenerWithDelayedRegistration.

@Test
public void testClusteredDataTreeChangeListenerWithDelayedRegistration() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final String testName = "testClusteredDataTreeChangeListenerWithDelayedRegistration";
            dataStoreContextBuilder.shardElectionTimeoutFactor(1000).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName());
            final MockDataTreeChangeListener listener = new MockDataTreeChangeListener(1);
            final ActorRef dclActor = actorFactory.createActor(DataTreeChangeListenerActor.props(listener, TestModel.TEST_PATH), actorFactory.generateActorId(testName + "-DataTreeChangeListener"));
            setupInMemorySnapshotStore();
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardBuilder().props().withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(testName + "-shard"));
            waitUntilNoLeader(shard);
            shard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, true), getRef());
            final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), RegisterDataTreeNotificationListenerReply.class);
            assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath());
            shard.tell(DatastoreContext.newBuilderFrom(dataStoreContextBuilder.build()).customRaftPolicyImplementation(null).build(), ActorRef.noSender());
            listener.waitForChangeEvents();
        }
    };
}
Also used : RegisterDataTreeNotificationListenerReply(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply) MockDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) DisableElectionsRaftPolicy(org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy) RegisterDataTreeChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener) Test(org.junit.Test)

Example 5 with RegisterDataTreeNotificationListenerReply

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

the class DataChangeListenerRegistrationProxyTest method testSuccessfulRegistrationForClusteredListener.

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

        {
            ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class), mock(Configuration.class));
            AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> mockClusteredListener = Mockito.mock(ClusteredDOMDataChangeListener.class);
            final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy("shard-1", actorContext, mockClusteredListener);
            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", true, 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) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)18 Test (org.junit.Test)14 ActorRef (akka.actor.ActorRef)13 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)12 TestActorRef (akka.testkit.TestActorRef)10 RegisterDataTreeChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener)9 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)8 MockDataTreeChangeListener (org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener)6 TestKit (akka.testkit.javadsl.TestKit)5 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)5 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)5 LocalShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardFound)5 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)5 FiniteDuration (scala.concurrent.duration.FiniteDuration)5 MockDataChangeListener (org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener)4 Timeout (akka.util.Timeout)3 ActorSystem (akka.actor.ActorSystem)2 Props (akka.actor.Props)2 Terminated (akka.actor.Terminated)2 ExecutionContexts (akka.dispatch.ExecutionContexts)2