Search in sources :

Example 6 with DataTreeSnapshot

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());
}
Also used : InOrder(org.mockito.InOrder) BigInteger(java.math.BigInteger) CommitTransactionPayload(org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 7 with DataTreeSnapshot

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());
}
Also used : InOrder(org.mockito.InOrder) UnsignedLong(com.google.common.primitives.UnsignedLong) BigInteger(java.math.BigInteger) CommitTransactionPayload(org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 8 with DataTreeSnapshot

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()));
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)

Example 9 with DataTreeSnapshot

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;
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 10 with DataTreeSnapshot

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);
}
Also used : DOMStoreReadTransaction(org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

DataTreeSnapshot (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)18 Test (org.junit.Test)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)7 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)6 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)5 BigInteger (java.math.BigInteger)4 InOrder (org.mockito.InOrder)4 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 UnsignedLong (com.google.common.primitives.UnsignedLong)3 CommitTransactionPayload (org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload)3 TestProbe (akka.testkit.TestProbe)2 MetadataShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)2 DOMStoreReadTransaction (org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction)2 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification)2 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)2 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)2 ClientActorContext (org.opendaylight.controller.cluster.access.client.ClientActorContext)1 ConnectClientRequest (org.opendaylight.controller.cluster.access.commands.ConnectClientRequest)1 ConnectClientSuccess (org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess)1