use of org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener in project controller by opendaylight.
the class DataTreeChangeListenerSupportTest method testInitialChangeListenerEventWithWildcardedListPath.
@Test
public void testInitialChangeListenerEventWithWildcardedListPath() throws DataValidationFailedException {
mergeToStore(shard.getDataStore(), TEST_PATH, testNodeWithOuter(1, 2));
MockDataTreeChangeListener listener = registerChangeListener(OUTER_LIST_PATH.node(OUTER_LIST_QNAME), 1).getKey();
listener.waitForChangeEvents();
listener.verifyNotifiedData(outerEntryPath(1), outerEntryPath(2));
}
use of org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener in project controller by opendaylight.
the class DataTreeChangeListenerSupportTest method testInitialChangeListenerEventWithNestedWildcardedListsPath.
@Test
public void testInitialChangeListenerEventWithNestedWildcardedListsPath() throws DataValidationFailedException {
mergeToStore(shard.getDataStore(), TEST_PATH, testNodeWithOuter(outerNode(outerNodeEntry(1, innerNode("one", "two")), outerNodeEntry(2, innerNode("three", "four")))));
MockDataTreeChangeListener listener = registerChangeListener(OUTER_LIST_PATH.node(OUTER_LIST_QNAME).node(INNER_LIST_QNAME).node(INNER_LIST_QNAME), 1).getKey();
listener.waitForChangeEvents();
listener.verifyNotifiedData(innerEntryPath(1, "one"), innerEntryPath(1, "two"), innerEntryPath(2, "three"), innerEntryPath(2, "four"));
// Register for a specific outer list entry
MockDataTreeChangeListener listener2 = registerChangeListener(OUTER_LIST_PATH.node(outerEntryKey(1)).node(INNER_LIST_QNAME).node(INNER_LIST_QNAME), 1).getKey();
listener2.waitForChangeEvents();
listener2.verifyNotifiedData(innerEntryPath(1, "one"), innerEntryPath(1, "two"));
listener2.verifyNoNotifiedData(innerEntryPath(2, "three"), innerEntryPath(2, "four"));
listener.reset(1);
listener2.reset(1);
mergeToStore(shard.getDataStore(), TEST_PATH, testNodeWithOuter(outerNode(outerNodeEntry(1, innerNode("three")))));
listener.waitForChangeEvents();
listener.verifyNotifiedData(innerEntryPath(1, "three"));
listener2.waitForChangeEvents();
listener2.verifyNotifiedData(innerEntryPath(1, "three"));
}
use of org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener in project controller by opendaylight.
the class ShardTest method testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration.
@SuppressWarnings("serial")
@Test
public void testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration() throws Exception {
final CountDownLatch onFirstElectionTimeout = new CountDownLatch(1);
final CountDownLatch onChangeListenerRegistered = new CountDownLatch(1);
final Creator<Shard> creator = new Creator<Shard>() {
boolean firstElectionTimeout = true;
@Override
public Shard create() throws Exception {
return new Shard(newShardBuilder()) {
@Override
public void handleCommand(final Object message) {
if (message instanceof ElectionTimeout && firstElectionTimeout) {
firstElectionTimeout = false;
final ActorRef self = getSelf();
new Thread(() -> {
Uninterruptibles.awaitUninterruptibly(onChangeListenerRegistered, 5, TimeUnit.SECONDS);
self.tell(message, self);
}).start();
onFirstElectionTimeout.countDown();
} else {
super.handleCommand(message);
}
}
};
}
};
setupInMemorySnapshotStore();
final YangInstanceIdentifier path = TestModel.TEST_PATH;
final MockDataTreeChangeListener listener = new MockDataTreeChangeListener(1);
final ActorRef dclActor = actorFactory.createActor(DataTreeChangeListenerActor.props(listener, path), "testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration-DataChangeListener");
final TestActorRef<Shard> shard = actorFactory.createTestActor(Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), "testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration");
new ShardTestKit(getSystem()) {
{
assertEquals("Got first ElectionTimeout", true, onFirstElectionTimeout.await(5, TimeUnit.SECONDS));
shard.tell(new RegisterDataTreeChangeListener(path, dclActor, false), getRef());
final RegisterDataTreeNotificationListenerReply reply = expectMsgClass(duration("5 seconds"), RegisterDataTreeNotificationListenerReply.class);
assertNotNull("getListenerRegistratioznPath", reply.getListenerRegistrationPath());
shard.tell(FindLeader.INSTANCE, getRef());
final FindLeaderReply findLeadeReply = expectMsgClass(duration("5 seconds"), FindLeaderReply.class);
assertFalse("Expected the shard not to be the leader", findLeadeReply.getLeaderActor().isPresent());
onChangeListenerRegistered.countDown();
// TODO: investigate why we do not receive data chage events
listener.waitForChangeEvents();
}
};
}
use of org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener in project controller by opendaylight.
the class ShardTest method testClusteredDataTreeChangeListenerWithDelayedRegistrationClosed.
@Test
public void testClusteredDataTreeChangeListenerWithDelayedRegistrationClosed() throws Exception {
new ShardTestKit(getSystem()) {
{
final String testName = "testClusteredDataTreeChangeListenerWithDelayedRegistrationClosed";
dataStoreContextBuilder.shardElectionTimeoutFactor(1000).customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName());
final MockDataTreeChangeListener listener = new MockDataTreeChangeListener(0);
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());
final ActorSelection regActor = getSystem().actorSelection(reply.getListenerRegistrationPath());
regActor.tell(CloseDataTreeNotificationListenerRegistration.getInstance(), getRef());
expectMsgClass(CloseDataTreeNotificationListenerRegistrationReply.class);
shard.tell(DatastoreContext.newBuilderFrom(dataStoreContextBuilder.build()).customRaftPolicyImplementation(null).build(), ActorRef.noSender());
listener.expectNoMoreChanges("Received unexpected change after close");
}
};
}
use of org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener in project controller by opendaylight.
the class ShardTest method testRegisterDataTreeChangeListener.
@Test
public void testRegisterDataTreeChangeListener() throws Exception {
new ShardTestKit(getSystem()) {
{
final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testRegisterDataTreeChangeListener");
waitUntilLeader(shard);
shard.tell(new UpdateSchemaContext(SchemaContextHelper.full()), ActorRef.noSender());
final MockDataTreeChangeListener listener = new MockDataTreeChangeListener(1);
final ActorRef dclActor = actorFactory.createActor(DataTreeChangeListenerActor.props(listener, TestModel.TEST_PATH), "testRegisterDataTreeChangeListener-DataTreeChangeListener");
shard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, false), 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\\/testRegisterDataTreeChangeListener\\/\\$.*"));
final YangInstanceIdentifier path = TestModel.TEST_PATH;
writeToStore(shard, path, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
listener.waitForChangeEvents();
}
};
}
Aggregations