use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot in project controller by opendaylight.
the class ShardDataTreeTest method testAbortWithPendingCommits.
@SuppressWarnings("unchecked")
@Test
public void testAbortWithPendingCommits() throws Exception {
final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()));
final ShardDataTreeCohort cohort2 = newShardDataTreeCohort(snapshot -> snapshot.write(PeopleModel.BASE_PATH, PeopleModel.create()));
final ShardDataTreeCohort cohort3 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()));
YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
MapEntryNode carNode = CarsModel.newCarEntry("optima", new BigInteger("100"));
final ShardDataTreeCohort cohort4 = newShardDataTreeCohort(snapshot -> snapshot.write(carPath, carNode));
coordinatedCanCommit(cohort2);
immediateCanCommit(cohort1);
coordinatedCanCommit(cohort3);
coordinatedCanCommit(cohort4);
coordinatedPreCommit(cohort1);
coordinatedPreCommit(cohort2);
coordinatedPreCommit(cohort3);
FutureCallback<Void> mockAbortCallback = mock(FutureCallback.class);
doNothing().when(mockAbortCallback).onSuccess(null);
cohort2.abort(mockAbortCallback);
verify(mockAbortCallback).onSuccess(null);
coordinatedPreCommit(cohort4);
coordinatedCommit(cohort1);
coordinatedCommit(cohort3);
coordinatedCommit(cohort4);
InOrder inOrder = inOrder(mockShard);
inOrder.verify(mockShard).persistPayload(eq(cohort1.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
inOrder.verify(mockShard).persistPayload(eq(cohort3.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
inOrder.verify(mockShard).persistPayload(eq(cohort4.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
// The payload instance doesn't matter - it just needs to be of type CommitTransactionPayload.
CommitTransactionPayload mockPayload = CommitTransactionPayload.create(nextTransactionId(), cohort1.getCandidate());
shardDataTree.applyReplicatedPayload(cohort1.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort3.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort4.getIdentifier(), mockPayload);
final DataTreeSnapshot snapshot = shardDataTree.newReadOnlyTransaction(nextTransactionId()).getSnapshot();
Optional<NormalizedNode<?, ?>> optional = snapshot.readNode(carPath);
assertEquals("Car node present", true, optional.isPresent());
assertEquals("Car node", carNode, optional.get());
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot in project controller by opendaylight.
the class ShardDataTreeTest method testPipelinedTransactionsWithImmediateCommits.
@Test
public void testPipelinedTransactionsWithImmediateCommits() throws Exception {
final ShardDataTreeCohort cohort1 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.BASE_PATH, CarsModel.emptyContainer()));
final ShardDataTreeCohort cohort2 = newShardDataTreeCohort(snapshot -> snapshot.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode()));
YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
MapEntryNode carNode = CarsModel.newCarEntry("optima", new BigInteger("100"));
final ShardDataTreeCohort cohort3 = newShardDataTreeCohort(snapshot -> snapshot.write(carPath, carNode));
final FutureCallback<UnsignedLong> commitCallback2 = immediate3PhaseCommit(cohort2);
final FutureCallback<UnsignedLong> commitCallback3 = immediate3PhaseCommit(cohort3);
final FutureCallback<UnsignedLong> commitCallback1 = immediate3PhaseCommit(cohort1);
InOrder inOrder = inOrder(mockShard);
inOrder.verify(mockShard).persistPayload(eq(cohort1.getIdentifier()), any(CommitTransactionPayload.class), eq(true));
inOrder.verify(mockShard).persistPayload(eq(cohort2.getIdentifier()), any(CommitTransactionPayload.class), eq(true));
inOrder.verify(mockShard).persistPayload(eq(cohort3.getIdentifier()), any(CommitTransactionPayload.class), eq(false));
// The payload instance doesn't matter - it just needs to be of type CommitTransactionPayload.
CommitTransactionPayload mockPayload = CommitTransactionPayload.create(nextTransactionId(), cohort1.getCandidate());
shardDataTree.applyReplicatedPayload(cohort1.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort2.getIdentifier(), mockPayload);
shardDataTree.applyReplicatedPayload(cohort3.getIdentifier(), mockPayload);
inOrder = inOrder(commitCallback1, commitCallback2, commitCallback3);
inOrder.verify(commitCallback1).onSuccess(any(UnsignedLong.class));
inOrder.verify(commitCallback2).onSuccess(any(UnsignedLong.class));
inOrder.verify(commitCallback3).onSuccess(any(UnsignedLong.class));
final DataTreeSnapshot snapshot = shardDataTree.newReadOnlyTransaction(nextTransactionId()).getSnapshot();
Optional<NormalizedNode<?, ?>> optional = snapshot.readNode(carPath);
assertEquals("Car node present", true, optional.isPresent());
assertEquals("Car node", carNode, optional.get());
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot in project controller by opendaylight.
the class ShardRecoveryCoordinatorTest method createSnapshot.
private static ShardSnapshotState createSnapshot() {
final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, SchemaContextHelper.PEOPLE_YANG));
DataTreeSnapshot snapshot = dataTree.takeSnapshot();
DataTreeModification modification = snapshot.newModification();
modification.merge(CarsModel.BASE_PATH, CarsModel.create());
modification.merge(PeopleModel.BASE_PATH, PeopleModel.create());
modification.ready();
dataTree.commit(dataTree.prepare(modification));
return new ShardSnapshotState(new MetadataShardDataTreeSnapshot(dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get()));
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot in project controller by opendaylight.
the class TransactionProxyTest method createDataTree.
private static DataTree createDataTree(final NormalizedNode<?, ?> readResponse) {
DataTree dataTree = mock(DataTree.class);
DataTreeSnapshot dataTreeSnapshot = mock(DataTreeSnapshot.class);
DataTreeModification dataTreeModification = mock(DataTreeModification.class);
doReturn(dataTreeSnapshot).when(dataTree).takeSnapshot();
doReturn(dataTreeModification).when(dataTreeSnapshot).newModification();
doReturn(java.util.Optional.of(readResponse)).when(dataTreeModification).readNode(any(YangInstanceIdentifier.class));
return dataTree;
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot in project controller by opendaylight.
the class InMemoryDataStoreTest method testReadWithReadOnlyTransactionFailure.
@Test(expected = ReadFailedException.class)
public void testReadWithReadOnlyTransactionFailure() throws Exception {
DataTreeSnapshot mockSnapshot = Mockito.mock(DataTreeSnapshot.class);
Mockito.doThrow(new RuntimeException("mock ex")).when(mockSnapshot).readNode(Mockito.any(YangInstanceIdentifier.class));
DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadTransaction("1", true, mockSnapshot);
doReadAndThrowEx(readTx);
}
Aggregations