Search in sources :

Example 1 with MockDataChangeListener

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

use of org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener 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 3 with MockDataChangeListener

use of org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener in project controller by opendaylight.

the class DataChangeListenerSupportTest method testChangeListenerWithNoInitialData.

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

        {
            final TestActorRef<Shard> actor = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testChangeListenerWithNoInitialData");
            waitUntilLeader(actor);
            final Shard shard = actor.underlyingActor();
            final MockDataChangeListener listener = new MockDataChangeListener(0);
            final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener, TEST_PATH), "testChangeListenerWithNoInitialData-DataChangeListener");
            final DataChangeListenerSupport support = new DataChangeListenerSupport(shard);
            support.onMessage(new RegisterChangeListener(TEST_PATH, dclActor, DataChangeScope.ONE, false), true, true);
            listener.expectNoMoreChanges("Unexpected initial change event");
        }
    };
}
Also used : ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) MockDataChangeListener(org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener) RegisterChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener) Test(org.junit.Test)

Example 4 with MockDataChangeListener

use of org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener in project controller by opendaylight.

the class DataChangeListenerSupportTest method testInitialChangeListenerEventWhenNotInitiallyLeader.

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

        {
            final TestActorRef<Shard> actor = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testInitialChangeListenerEventWhenNotInitiallyLeader");
            waitUntilLeader(actor);
            final Shard shard = actor.underlyingActor();
            mergeToStore(shard.getDataStore(), TEST_PATH, testNodeWithOuter(outerNode(outerNodeEntry(1, innerNode("one", "two")), outerNodeEntry(2, innerNode("three", "four")))));
            final MockDataChangeListener listener = new MockDataChangeListener(0);
            final YangInstanceIdentifier path = OUTER_LIST_PATH.node(OUTER_LIST_QNAME).node(INNER_LIST_QNAME).node(INNER_LIST_QNAME);
            final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener, path), "testInitialChangeListenerEventWhenNotInitiallyLeader-DataChangeListener");
            final DataChangeListenerSupport support = new DataChangeListenerSupport(shard);
            support.onMessage(new RegisterChangeListener(path, dclActor, DataChangeScope.ONE, false), false, true);
            listener.expectNoMoreChanges("Unexpected initial change event");
            listener.reset(1);
            support.onLeadershipChange(true, true);
            listener.waitForChangeEvents();
            listener.verifyCreatedData(0, innerEntryPath(1, "one"));
            listener.verifyCreatedData(0, innerEntryPath(1, "two"));
            listener.verifyCreatedData(0, innerEntryPath(2, "three"));
            listener.verifyCreatedData(0, innerEntryPath(2, "four"));
        }
    };
}
Also used : 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 5 with MockDataChangeListener

use of org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener in project controller by opendaylight.

the class DataChangeListenerSupportTest method testInitialChangeListenerEventWithContainerPath.

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

        {
            final TestActorRef<Shard> actor = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testInitialChangeListenerEventWithContainerPath");
            waitUntilLeader(actor);
            final Shard shard = actor.underlyingActor();
            writeToStore(shard.getDataStore(), TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
            final MockDataChangeListener listener = new MockDataChangeListener(1);
            final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener, TEST_PATH), "testInitialChangeListenerEventWithContainerPath-DataChangeListener");
            final DataChangeListenerSupport support = new DataChangeListenerSupport(shard);
            support.onMessage(new RegisterChangeListener(TEST_PATH, dclActor, DataChangeScope.ONE, false), true, true);
            listener.waitForChangeEvents(TEST_PATH);
        }
    };
}
Also used : ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) MockDataChangeListener(org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener) RegisterChangeListener(org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 MockDataChangeListener (org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener)11 ActorRef (akka.actor.ActorRef)10 TestActorRef (akka.testkit.TestActorRef)10 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)10 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)4 Creator (akka.japi.Creator)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)1 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)1 ElectionTimeout (org.opendaylight.controller.cluster.raft.base.messages.ElectionTimeout)1 FindLeaderReply (org.opendaylight.controller.cluster.raft.client.messages.FindLeaderReply)1 DisableElectionsRaftPolicy (org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy)1