use of org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener 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();
}
};
}
use of org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener 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();
}
};
}
use of org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testDataTreeChangeListenerRegistration.
@Test
public void testDataTreeChangeListenerRegistration() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testDataTreeChangeListenerRegistration", "test-1")) {
testWriteTransaction(dataStore, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
final MockDataTreeChangeListener listener = new MockDataTreeChangeListener(1);
ListenerRegistration<MockDataTreeChangeListener> listenerReg = dataStore.registerTreeChangeListener(TestModel.TEST_PATH, listener);
assertNotNull("registerTreeChangeListener returned null", listenerReg);
IntegrationTestKit.verifyShardState(dataStore, "test-1", state -> assertEquals("getTreeChangeListenerActors", 1, state.getTreeChangeListenerActors().size()));
// Wait for the initial notification
listener.waitForChangeEvents(TestModel.TEST_PATH);
listener.reset(2);
// Write 2 updates.
testWriteTransaction(dataStore, TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
YangInstanceIdentifier listPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).build();
testWriteTransaction(dataStore, listPath, ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1));
// Wait for the 2 updates.
listener.waitForChangeEvents(TestModel.OUTER_LIST_PATH, listPath);
listenerReg.close();
IntegrationTestKit.verifyShardState(dataStore, "test-1", state -> assertEquals("getTreeChangeListenerActors", 0, state.getTreeChangeListenerActors().size()));
testWriteTransaction(dataStore, YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).build(), ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2));
listener.expectNoMoreChanges("Received unexpected change after close");
}
}
};
}
use of org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener in project controller by opendaylight.
the class DataTreeChangeListenerSupportTest method testInitialChangeListenerEventWithContainerPath.
@Test
public void testInitialChangeListenerEventWithContainerPath() throws DataValidationFailedException {
writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME));
Entry<MockDataTreeChangeListener, ActorSelection> entry = registerChangeListener(TEST_PATH, 1);
MockDataTreeChangeListener listener = entry.getKey();
listener.waitForChangeEvents();
listener.verifyNotifiedData(TEST_PATH);
listener.reset(1);
writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME));
listener.waitForChangeEvents();
listener.verifyNotifiedData(TEST_PATH);
listener.reset(1);
TestKit kit = new TestKit(getSystem());
entry.getValue().tell(CloseDataTreeNotificationListenerRegistration.getInstance(), kit.getRef());
kit.expectMsgClass(kit.duration("5 seconds"), CloseDataTreeNotificationListenerRegistrationReply.class);
writeToStore(shard.getDataStore(), TEST_PATH, ImmutableNodes.containerNode(TEST_QNAME));
listener.verifyNoNotifiedData(TEST_PATH);
}
use of org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener in project controller by opendaylight.
the class DataTreeChangeListenerSupportTest method registerChangeListener.
@SuppressWarnings("checkstyle:IllegalCatch")
private Entry<MockDataTreeChangeListener, ActorSelection> registerChangeListener(final YangInstanceIdentifier path, final int expectedEvents) {
MockDataTreeChangeListener listener = new MockDataTreeChangeListener(expectedEvents);
ActorRef dclActor = actorFactory.createActor(DataTreeChangeListenerActor.props(listener, TestModel.TEST_PATH));
RegisterDataTreeNotificationListenerReply reply;
try {
reply = (RegisterDataTreeNotificationListenerReply) Await.result(Patterns.ask(shardActor, new RegisterDataTreeChangeListener(path, dclActor, false), new Timeout(5, TimeUnit.SECONDS)), Duration.create(5, TimeUnit.SECONDS));
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
return new SimpleEntry<>(listener, getSystem().actorSelection(reply.getListenerRegistrationPath()));
}
Aggregations