Search in sources :

Example 1 with DataTreeCandidateTip

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip in project controller by opendaylight.

the class SimpleShardDataTreeCohortTest method preCommitSuccess.

private DataTreeCandidateTip preCommitSuccess() {
    final DataTreeCandidateTip mockCandidate = mock(DataTreeCandidateTip.class);
    doAnswer(invocation -> {
        invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).successfulPreCommit(mockCandidate);
        return null;
    }).when(mockShardDataTree).startPreCommit(cohort);
    @SuppressWarnings("unchecked") final FutureCallback<DataTreeCandidate> callback = mock(FutureCallback.class);
    cohort.preCommit(callback);
    verify(callback).onSuccess(mockCandidate);
    verifyNoMoreInteractions(callback);
    assertSame("getCandidate", mockCandidate, cohort.getCandidate());
    return mockCandidate;
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DataTreeCandidateTip(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)

Example 2 with DataTreeCandidateTip

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip in project controller by opendaylight.

the class SimpleShardDataTreeCohortTest method testCommitWithIllegalArgumentEx.

@Test
public void testCommitWithIllegalArgumentEx() {
    canCommitSuccess();
    final DataTreeCandidateTip candidate = preCommitSuccess();
    final Exception cause = new IllegalArgumentException("mock");
    doAnswer(invocation -> {
        invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).failedCommit(cause);
        return null;
    }).when(mockShardDataTree).startCommit(cohort, candidate);
    @SuppressWarnings("unchecked") final FutureCallback<UnsignedLong> callback = mock(FutureCallback.class);
    cohort.commit(callback);
    verify(callback).onFailure(cause);
    verifyNoMoreInteractions(callback);
    verify(mockUserCohorts).abort();
}
Also used : UnsignedLong(com.google.common.primitives.UnsignedLong) DataTreeCandidateTip(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) ConflictingModificationAppliedException(org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException) Test(org.junit.Test)

Example 3 with DataTreeCandidateTip

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip in project controller by opendaylight.

the class SimpleShardDataTreeCohortTest method testPreCommitAndCommitSuccess.

@Test
public void testPreCommitAndCommitSuccess() throws Exception {
    canCommitSuccess();
    final DataTreeCandidateTip candidate = preCommitSuccess();
    doAnswer(invocation -> {
        invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).successfulCommit(UnsignedLong.valueOf(0), () -> {
        });
        return null;
    }).when(mockShardDataTree).startCommit(cohort, candidate);
    @SuppressWarnings("unchecked") final FutureCallback<UnsignedLong> mockCommitCallback = mock(FutureCallback.class);
    cohort.commit(mockCommitCallback);
    verify(mockCommitCallback).onSuccess(any(UnsignedLong.class));
    verifyNoMoreInteractions(mockCommitCallback);
    verify(mockUserCohorts).commit();
}
Also used : UnsignedLong(com.google.common.primitives.UnsignedLong) DataTreeCandidateTip(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip) Test(org.junit.Test)

Example 4 with DataTreeCandidateTip

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip in project controller by opendaylight.

the class AbstractShardTest method mockUnmodifiedCandidate.

static DataTreeCandidateTip mockUnmodifiedCandidate(final String name) {
    final DataTreeCandidateTip mockCandidate = mock(DataTreeCandidateTip.class, name);
    final DataTreeCandidateNode mockCandidateNode = mock(DataTreeCandidateNode.class, name + "-node");
    doReturn(ModificationType.UNMODIFIED).when(mockCandidateNode).getModificationType();
    doReturn(YangInstanceIdentifier.EMPTY).when(mockCandidate).getRootPath();
    doReturn(mockCandidateNode).when(mockCandidate).getRootNode();
    return mockCandidate;
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) DataTreeCandidateTip(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)

Example 5 with DataTreeCandidateTip

use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip in project controller by opendaylight.

the class AbstractShardTest method mockCandidate.

public static DataTreeCandidateTip mockCandidate(final String name) {
    final DataTreeCandidateTip mockCandidate = mock(DataTreeCandidateTip.class, name);
    final DataTreeCandidateNode mockCandidateNode = mock(DataTreeCandidateNode.class, name + "-node");
    doReturn(ModificationType.WRITE).when(mockCandidateNode).getModificationType();
    doReturn(Optional.of(ImmutableNodes.containerNode(CarsModel.CARS_QNAME))).when(mockCandidateNode).getDataAfter();
    doReturn(CarsModel.BASE_PATH).when(mockCandidate).getRootPath();
    doReturn(mockCandidateNode).when(mockCandidate).getRootNode();
    return mockCandidate;
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode) DataTreeCandidateTip(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)

Aggregations

DataTreeCandidateTip (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip)7 UnsignedLong (com.google.common.primitives.UnsignedLong)2 Test (org.junit.Test)2 DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode)2 Stopwatch (com.google.common.base.Stopwatch)1 MetadataShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)1 ShardDataTreeSnapshotMetadata (org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshotMetadata)1 PruningDataTreeModification (org.opendaylight.controller.cluster.datastore.utils.PruningDataTreeModification)1 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)1 ConflictingModificationAppliedException (org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException)1 DataTreeCandidate (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate)1 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)1 DataValidationFailedException (org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException)1