Search in sources :

Example 61 with TestActorRef

use of akka.testkit.TestActorRef in project controller by opendaylight.

the class DataChangeListenerSupportTest method testInitialChangeListenerEventWithNestedWildcardedListsPath.

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

        {
            final TestActorRef<Shard> actor = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testInitialChangeListenerEventWithNestedWildcardedListsPath");
            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(1);
            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), "testInitialChangeListenerEventWithNestedWildcardedListsPath-DataChangeListener");
            final DataChangeListenerSupport support = new DataChangeListenerSupport(shard);
            support.onMessage(new RegisterChangeListener(path, dclActor, DataChangeScope.ONE, false), 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"));
            // Register for a specific outer list entry
            final MockDataChangeListener listener2 = new MockDataChangeListener(1);
            final YangInstanceIdentifier path2 = OUTER_LIST_PATH.node(outerEntryKey(1)).node(INNER_LIST_QNAME).node(INNER_LIST_QNAME);
            final ActorRef dclActor2 = actorFactory.createActor(DataChangeListener.props(listener2, path2), "testInitialChangeListenerEventWithNestedWildcardedListsPath-DataChangeListener2");
            final DataChangeListenerSupport support2 = new DataChangeListenerSupport(shard);
            support2.onMessage(new RegisterChangeListener(path2, dclActor2, DataChangeScope.ONE, false), true, true);
            listener2.waitForChangeEvents();
            listener2.verifyCreatedData(0, innerEntryPath(1, "one"));
            listener2.verifyCreatedData(0, innerEntryPath(1, "two"));
            listener2.verifyNoCreatedData(0, innerEntryPath(2, "three"));
            listener2.verifyNoCreatedData(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 62 with TestActorRef

use of akka.testkit.TestActorRef in project controller by opendaylight.

the class DataChangeListenerSupportTest method testInitialChangeListenerEventWithListPath.

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

        {
            final TestActorRef<Shard> actor = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testInitialChangeListenerEventWithListPath");
            waitUntilLeader(actor);
            final Shard shard = actor.underlyingActor();
            mergeToStore(shard.getDataStore(), TEST_PATH, testNodeWithOuter(1, 2));
            final MockDataChangeListener listener = new MockDataChangeListener(1);
            final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener, OUTER_LIST_PATH), "testInitialChangeListenerEventWithListPath-DataChangeListener");
            final DataChangeListenerSupport support = new DataChangeListenerSupport(shard);
            support.onMessage(new RegisterChangeListener(OUTER_LIST_PATH, dclActor, DataChangeScope.ONE, false), true, true);
            listener.waitForChangeEvents();
            assertEquals("Outer entry 1 present", true, NormalizedNodes.findNode(listener.getCreatedData(0, OUTER_LIST_PATH), outerEntryKey(1)).isPresent());
            assertEquals("Outer entry 2 present", true, NormalizedNodes.findNode(listener.getCreatedData(0, OUTER_LIST_PATH), outerEntryKey(2)).isPresent());
        }
    };
}
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 63 with TestActorRef

use of akka.testkit.TestActorRef in project controller by opendaylight.

the class DataChangeListenerSupportTest method testInitialChangeListenerEventWithWildcardedListPath.

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

        {
            final TestActorRef<Shard> actor = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testInitialChangeListenerEventWithWildcardedListPath");
            waitUntilLeader(actor);
            final Shard shard = actor.underlyingActor();
            mergeToStore(shard.getDataStore(), TEST_PATH, testNodeWithOuter(1, 2));
            writeToStore(shard.getDataStore(), OUTER_CONTAINER_PATH, ImmutableNodes.containerNode(OUTER_CONTAINER_QNAME));
            final MockDataChangeListener listener = new MockDataChangeListener(1);
            final YangInstanceIdentifier path = OUTER_LIST_PATH.node(OUTER_LIST_QNAME);
            final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener, path), "testInitialChangeListenerEventWithWildcardedListPath-DataChangeListener");
            final DataChangeListenerSupport support = new DataChangeListenerSupport(shard);
            support.onMessage(new RegisterChangeListener(path, dclActor, DataChangeScope.ONE, false), true, true);
            listener.waitForChangeEvents();
            listener.verifyCreatedData(0, outerEntryPath(1));
            listener.verifyCreatedData(0, outerEntryPath(2));
            listener.verifyNoCreatedData(0, OUTER_CONTAINER_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) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 64 with TestActorRef

use of akka.testkit.TestActorRef in project controller by opendaylight.

the class RoleChangeNotifierTest method testHandleRaftRoleChanged.

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

        {
            String memberId = "testHandleRegisterRoleChangeListenerWithNotificationSet";
            ActorRef listenerActor = getSystem().actorOf(MessageCollectorActor.props());
            ActorRef shardActor = getTestActor();
            TestActorRef<RoleChangeNotifier> notifierTestActorRef = TestActorRef.create(getSystem(), RoleChangeNotifier.getProps(memberId), memberId);
            notifierTestActorRef.tell(new RoleChanged(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), shardActor);
            // no notification should be sent as listener has not yet
            // registered
            assertNull(MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class));
            // listener registers after role has been changed, ensure we
            // sent the latest role change after a reply
            notifierTestActorRef.tell(new RegisterRoleChangeListener(), listenerActor);
            RegisterRoleChangeListenerReply reply = MessageCollectorActor.getFirstMatching(listenerActor, RegisterRoleChangeListenerReply.class);
            assertNotNull(reply);
            RoleChangeNotification notification = MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class);
            assertNotNull(notification);
            assertEquals(RaftState.Candidate.name(), notification.getOldRole());
            assertEquals(RaftState.Leader.name(), notification.getNewRole());
        }
    };
}
Also used : RoleChangeNotifier(org.opendaylight.controller.cluster.notifications.RoleChangeNotifier) RegisterRoleChangeListener(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener) TestActorRef(akka.testkit.TestActorRef) ActorRef(akka.actor.ActorRef) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) RegisterRoleChangeListenerReply(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListenerReply) TestKit(akka.testkit.javadsl.TestKit) RoleChanged(org.opendaylight.controller.cluster.notifications.RoleChanged) Test(org.junit.Test)

Example 65 with TestActorRef

use of akka.testkit.TestActorRef in project controller by opendaylight.

the class RoleChangeNotifierTest method testHandleRegisterRoleChangeListener.

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

        {
            String memberId = "testHandleRegisterRoleChangeListener";
            ActorRef listenerActor = getSystem().actorOf(MessageCollectorActor.props());
            TestActorRef<RoleChangeNotifier> notifierTestActorRef = TestActorRef.create(getSystem(), RoleChangeNotifier.getProps(memberId), memberId);
            notifierTestActorRef.tell(new RegisterRoleChangeListener(), listenerActor);
            RegisterRoleChangeListenerReply reply = MessageCollectorActor.getFirstMatching(listenerActor, RegisterRoleChangeListenerReply.class);
            assertNotNull(reply);
            RoleChangeNotification notification = MessageCollectorActor.getFirstMatching(listenerActor, RoleChangeNotification.class);
            assertNull(notification);
        }
    };
}
Also used : RoleChangeNotifier(org.opendaylight.controller.cluster.notifications.RoleChangeNotifier) RegisterRoleChangeListener(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener) TestActorRef(akka.testkit.TestActorRef) ActorRef(akka.actor.ActorRef) RegisterRoleChangeListenerReply(org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListenerReply) RoleChangeNotification(org.opendaylight.controller.cluster.notifications.RoleChangeNotification) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test)

Aggregations

ActorRef (akka.actor.ActorRef)65 TestActorRef (akka.testkit.TestActorRef)65 Test (org.junit.Test)64 FiniteDuration (scala.concurrent.duration.FiniteDuration)18 TestKit (akka.testkit.javadsl.TestKit)17 AddServer (org.opendaylight.controller.cluster.raft.messages.AddServer)14 AddServerReply (org.opendaylight.controller.cluster.raft.messages.AddServerReply)13 SimpleReplicatedLogEntry (org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry)13 DisableElectionsRaftPolicy (org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy)12 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)11 ByteString (com.google.protobuf.ByteString)10 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)10 MockDataChangeListener (org.opendaylight.controller.cluster.datastore.utils.MockDataChangeListener)10 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)10 AddressFromURIString (akka.actor.AddressFromURIString)9 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)9 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)9 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)9 Follower (org.opendaylight.controller.cluster.raft.behaviors.Follower)9 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)8