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"));
}
};
}
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());
}
};
}
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);
}
};
}
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());
}
};
}
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);
}
};
}
Aggregations