import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
-import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats;
import org.opendaylight.controller.cluster.datastore.messages.AbortTransaction;
import org.opendaylight.controller.cluster.datastore.messages.AbortTransactionReply;
import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications;
writeToStore(shard, path, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
listener.waitForChangeEvents();
+ listener.verifyOnInitialDataEvent();
+
+ final MockDataTreeChangeListener listener2 = new MockDataTreeChangeListener(1);
+ final ActorRef dclActor2 = actorFactory.createActor(DataTreeChangeListenerActor.props(listener2,
+ TestModel.TEST_PATH), "testRegisterDataTreeChangeListener-DataTreeChangeListener2");
+
+ shard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor2, false), testKit.getRef());
+
+ testKit.expectMsgClass(Duration.ofSeconds(3), RegisterDataTreeNotificationListenerReply.class);
+
+ listener2.waitForChangeEvents();
+ listener2.verifyNoOnInitialDataEvent();
}
@SuppressWarnings("serial")
public void testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration() throws Exception {
final CountDownLatch onFirstElectionTimeout = new CountDownLatch(1);
final CountDownLatch onChangeListenerRegistered = new CountDownLatch(1);
- final Creator<Shard> creator = new Creator<Shard>() {
+ final Creator<Shard> creator = new Creator<>() {
boolean firstElectionTimeout = true;
@Override
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()),
+ final TestActorRef<Shard> shard = actorFactory.createTestActor(Props.create(Shard.class,
+ new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()),
"testDataTreeChangeListenerNotifiedWhenNotTheLeaderOnRegistration");
final ShardTestKit testKit = new ShardTestKit(getSystem());
CreateTransactionReply.class);
final String path = reply.getTransactionPath().toString();
- assertTrue("Unexpected transaction path " + path, path.startsWith(String.format(
- "akka://test/user/testCreateTransaction/shard-%s-%s:ShardTransactionTest@0:",
+ assertTrue("Unexpected transaction path " + path, path.contains(String.format(
+ "/user/testCreateTransaction/shard-%s-%s:ShardTransactionTest@0:",
shardID.getShardName(), shardID.getMemberName().getName())));
}
CreateTransactionReply.class);
final String path = reply.getTransactionPath().toString();
- assertTrue("Unexpected transaction path " + path, path.startsWith(String.format(
- "akka://test/user/testCreateTransactionOnChain/shard-%s-%s:ShardTransactionTest@0:",
+ assertTrue("Unexpected transaction path " + path, path.contains(String.format(
+ "/user/testCreateTransactionOnChain/shard-%s-%s:ShardTransactionTest@0:",
shardID.getShardName(), shardID.getMemberName().getName())));
}
writeToStore(store, TestModel.TEST_PATH, container);
- final YangInstanceIdentifier root = YangInstanceIdentifier.EMPTY;
- final NormalizedNode<?,?> expected = readStore(store, root);
+ final YangInstanceIdentifier root = YangInstanceIdentifier.empty();
+ final NormalizedNode expected = readStore(store, root);
final Snapshot snapshot = Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(expected)),
Collections.emptyList(), 1, 2, 3, 4, -1, null, null);
while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
Uninterruptibles.sleepUninterruptibly(75, TimeUnit.MILLISECONDS);
- final NormalizedNode<?,?> actual = readStore(shard, TestModel.TEST_PATH);
+ final NormalizedNode actual = readStore(shard, TestModel.TEST_PATH);
if (actual != null) {
assertEquals("Applied state", node, actual);
return;
// Add some ModificationPayload entries
for (int i = 1; i <= nListEntries; i++) {
- listEntryKeys.add(Integer.valueOf(i));
+ listEntryKeys.add(i);
final YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
.nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, i).build();
InMemoryJournal.addEntry(shardID.toString(), nListEntries + 2,
new ApplyJournalEntries(nListEntries));
- testRecovery(listEntryKeys);
+ testRecovery(listEntryKeys, true);
}
@Test
ImmutableNodes.containerNode(TestModel.TEST_QNAME), false), testKit.getRef());
final ReadyTransactionReply readyReply = ReadyTransactionReply
.fromSerializable(testKit.expectMsgClass(duration, ReadyTransactionReply.class));
- assertEquals("Cohort path", shard.path().toString(), readyReply.getCohortPath());
+
+ String pathSuffix = shard.path().toString().replaceFirst("akka://test", "");
+ assertTrue("Cohort path", readyReply.getCohortPath().endsWith(pathSuffix));
// Send the CanCommitTransaction message for the first Tx.
shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), testKit.getRef());
verifyOuterListEntry(shard, 1);
- verifyLastApplied(shard, 5);
+ verifyLastApplied(shard, 3);
}
@Test
// Verify data in the data store.
- final NormalizedNode<?, ?> actualNode = readStore(shard, path);
+ final NormalizedNode actualNode = readStore(shard, path);
assertEquals("Stored node", containerNode, actualNode);
}
public void testOnBatchedModificationsWhenNotLeader() {
final AtomicBoolean overrideLeaderCalls = new AtomicBoolean();
final ShardTestKit testKit = new ShardTestKit(getSystem());
- final Creator<Shard> creator = new Creator<Shard>() {
+ final Creator<Shard> creator = new Creator<>() {
private static final long serialVersionUID = 1L;
@Override
}
};
- final TestActorRef<Shard> shard = actorFactory.createTestActor(Props
- .create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()),
+ final TestActorRef<Shard> shard = actorFactory.createTestActor(Props.create(Shard.class,
+ new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()),
"testOnBatchedModificationsWhenNotLeader");
ShardTestKit.waitUntilLeader(shard);
ShardTestKit.waitUntilLeader(shard);
final TransactionIdentifier transactionID = nextTransactionId();
- final NormalizedNode<?, ?> containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+ final NormalizedNode containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
if (readWrite) {
shard.tell(prepareForwardedReadyTransaction(shard, transactionID, TestModel.TEST_PATH, containerNode, true),
testKit.getRef());
testKit.expectMsgClass(Duration.ofSeconds(5), CommitTransactionReply.class);
- final NormalizedNode<?, ?> actualNode = readStore(shard, TestModel.TEST_PATH);
+ final NormalizedNode actualNode = readStore(shard, TestModel.TEST_PATH);
assertEquals(TestModel.TEST_QNAME.getLocalName(), containerNode, actualNode);
}
testKit.expectMsgClass(CommitTransactionReply.class);
- final NormalizedNode<?, ?> actualNode = readStore(shard, TestModel.OUTER_LIST_PATH);
+ final NormalizedNode actualNode = readStore(shard, TestModel.OUTER_LIST_PATH);
assertEquals(TestModel.OUTER_LIST_QNAME.getLocalName(), mergeData, actualNode);
}
shard.tell(new CommitTransaction(txId, CURRENT_VERSION).toSerializable(), testKit.getRef());
testKit.expectMsgClass(CommitTransactionReply.class);
- final NormalizedNode<?, ?> actualNode = readStore(shard, TestModel.OUTER_LIST_PATH);
+ final NormalizedNode actualNode = readStore(shard, TestModel.OUTER_LIST_PATH);
assertEquals(TestModel.OUTER_LIST_QNAME.getLocalName(), mergeData, actualNode);
}
final Duration duration = Duration.ofSeconds(5);
final TransactionIdentifier transactionID = nextTransactionId();
- final NormalizedNode<?, ?> containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+ final NormalizedNode containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
shard.tell(prepareBatchedModifications(transactionID, TestModel.TEST_PATH, containerNode, false),
testKit.getRef());
testKit.expectMsgClass(duration, ReadyTransactionReply.class);
shard.tell(new CommitTransaction(transactionID, CURRENT_VERSION).toSerializable(), testKit.getRef());
testKit.expectMsgClass(duration, CommitTransactionReply.class);
- final NormalizedNode<?, ?> actualNode = readStore(shard, TestModel.TEST_PATH);
+ final NormalizedNode actualNode = readStore(shard, TestModel.TEST_PATH);
assertEquals(TestModel.TEST_QNAME.getLocalName(), containerNode, actualNode);
}
// Committed transaction count should increase as usual
assertEquals(1, shardStats.getCommittedTransactionsCount());
- // Commit index should advance as we do not have an empty
- // modification
+ // Commit index should advance 1 to account for disabling metadata
assertEquals(1, shardStats.getCommitIndex());
}
// Wait for the 2nd Tx to complete the canCommit phase.
final CountDownLatch latch = new CountDownLatch(1);
- canCommitFuture.onComplete(new OnComplete<Object>() {
+ canCommitFuture.onComplete(new OnComplete<>() {
@Override
public void onComplete(final Throwable failure, final Object resp) {
latch.countDown();
// Wait for the 2nd Tx to complete the canCommit phase.
final CountDownLatch latch = new CountDownLatch(1);
- canCommitFuture.onComplete(new OnComplete<Object>() {
+ canCommitFuture.onComplete(new OnComplete<>() {
@Override
public void onComplete(final Throwable failure, final Object resp) {
latch.countDown();
final Duration duration = Duration.ofSeconds(5);
final TransactionIdentifier transactionID1 = nextTransactionId();
- doThrow(new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock canCommit failure"))
+ doThrow(new DataValidationFailedException(YangInstanceIdentifier.empty(), "mock canCommit failure"))
.doNothing().when(dataTree).validate(any(DataTreeModification.class));
shard.tell(newBatchedModifications(transactionID1, TestModel.TEST_PATH,
ShardTestKit.waitUntilLeader(shard);
- doThrow(new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock canCommit failure"))
+ doThrow(new DataValidationFailedException(YangInstanceIdentifier.empty(), "mock canCommit failure"))
.doNothing().when(dataTree).validate(any(DataTreeModification.class));
final Duration duration = Duration.ofSeconds(5);
}
};
- final TestActorRef<Shard> shard = actorFactory.createTestActor(Props
- .create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()),
+ final TestActorRef<Shard> shard = actorFactory.createTestActor(Props.create(Shard.class,
+ new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()),
"testAbortWithCommitPending");
ShardTestKit.waitUntilLeader(shard);
shard.tell(new CommitTransaction(transactionID, CURRENT_VERSION).toSerializable(), testKit.getRef());
testKit.expectMsgClass(duration, CommitTransactionReply.class);
- final NormalizedNode<?, ?> node = readStore(shard, TestModel.TEST_PATH);
+ final NormalizedNode node = readStore(shard, TestModel.TEST_PATH);
// Since we're simulating an abort occurring during replication
// and before finish commit,
shard.tell(new CommitTransaction(transactionID2, CURRENT_VERSION).toSerializable(), testKit.getRef());
testKit.expectMsgClass(duration, CommitTransactionReply.class);
- final NormalizedNode<?, ?> node = readStore(shard, listNodePath);
+ final NormalizedNode node = readStore(shard, listNodePath);
assertNotNull(listNodePath + " not found", node);
}
testKit.expectMsgClass(duration, CommitTransactionReply.class);
- final NormalizedNode<?, ?> node = readStore(shard, TestModel.TEST2_PATH);
+ final NormalizedNode node = readStore(shard, TestModel.TEST2_PATH);
assertNotNull(TestModel.TEST2_PATH + " not found", node);
}
dataStoreContextBuilder.persistent(persistent);
- class TestShard extends Shard {
+ final class TestShard extends Shard {
- protected TestShard(final AbstractBuilder<?, ?> builder) {
+ TestShard(final AbstractBuilder<?, ?> builder) {
super(builder);
setPersistence(new TestPersistentDataProvider(super.persistence()));
}
final Creator<Shard> creator = () -> new TestShard(newShardBuilder());
- final TestActorRef<Shard> shard = actorFactory.createTestActor(Props
- .create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()),
- shardActorName);
+ final TestActorRef<Shard> shard = actorFactory.createTestActor(Props.create(Shard.class,
+ new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), shardActorName);
ShardTestKit.waitUntilLeader(shard);
writeToStore(shard, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
- final NormalizedNode<?, ?> expectedRoot = readStore(shard, YangInstanceIdentifier.EMPTY);
+ final NormalizedNode expectedRoot = readStore(shard, YangInstanceIdentifier.empty());
// Trigger creation of a snapshot by ensuring
final RaftActorContext raftActorContext = ((TestShard) shard.underlyingActor()).getRaftActorContext();
}
private static void awaitAndValidateSnapshot(final AtomicReference<CountDownLatch> latch,
- final AtomicReference<Object> savedSnapshot, final NormalizedNode<?, ?> expectedRoot)
+ final AtomicReference<Object> savedSnapshot, final NormalizedNode expectedRoot)
throws InterruptedException {
assertTrue("Snapshot saved", latch.get().await(5, TimeUnit.SECONDS));
savedSnapshot.set(null);
}
- private static void verifySnapshot(final Snapshot snapshot, final NormalizedNode<?, ?> expectedRoot) {
- final NormalizedNode<?, ?> actual = ((ShardSnapshotState)snapshot.getState()).getSnapshot().getRootNode().get();
+ private static void verifySnapshot(final Snapshot snapshot, final NormalizedNode expectedRoot) {
+ final NormalizedNode actual = ((ShardSnapshotState)snapshot.getState()).getSnapshot().getRootNode().get();
assertEquals("Root node", expectedRoot, actual);
}
commitTransaction(store, putTransaction);
- final NormalizedNode<?, ?> expected = readStore(store, YangInstanceIdentifier.EMPTY);
+ final NormalizedNode expected = readStore(store, YangInstanceIdentifier.empty());
final DataTreeModification writeTransaction = store.takeSnapshot().newModification();
- writeTransaction.delete(YangInstanceIdentifier.EMPTY);
- writeTransaction.write(YangInstanceIdentifier.EMPTY, expected);
+ writeTransaction.delete(YangInstanceIdentifier.empty());
+ writeTransaction.write(YangInstanceIdentifier.empty(), expected);
commitTransaction(store, writeTransaction);
- final NormalizedNode<?, ?> actual = readStore(store, YangInstanceIdentifier.EMPTY);
+ final NormalizedNode actual = readStore(store, YangInstanceIdentifier.empty());
assertEquals(expected, actual);
}