use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class DataTreeCohortIntegrationTest method testCanCommitWithListEntries.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testCanCommitWithListEntries() throws Exception {
final DOMDataTreeCommitCohort cohort = mock(DOMDataTreeCommitCohort.class);
doReturn(PostCanCommitStep.NOOP_SUCCESS_FUTURE).when(cohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
try (AbstractDataStore dataStore = kit.setupAbstractDataStore(DistributedDataStore.class, "testCanCommitWithMultipleListEntries", "cars-1")) {
final ObjectRegistration<DOMDataTreeCommitCohort> cohortReg = dataStore.registerCommitCohort(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH.node(CarsModel.CAR_QNAME)), cohort);
assertNotNull(cohortReg);
IntegrationTestKit.verifyShardState(dataStore, "cars-1", state -> assertEquals("Cohort registrations", 1, state.getCommitCohortActors().size()));
// First write an empty base container and verify the cohort isn't invoked.
DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
kit.doCommit(writeTx.ready());
verifyNoMoreInteractions(cohort);
// Write a single car entry and verify the cohort is invoked.
writeTx = dataStore.newWriteOnlyTransaction();
final YangInstanceIdentifier optimaPath = CarsModel.newCarPath("optima");
final MapEntryNode optimaNode = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
writeTx.write(optimaPath, optimaNode);
kit.doCommit(writeTx.ready());
ArgumentCaptor<Collection> candidateCapture = ArgumentCaptor.forClass(Collection.class);
verify(cohort).canCommit(any(Object.class), candidateCapture.capture(), any(SchemaContext.class));
assertDataTreeCandidate((DOMDataTreeCandidate) candidateCapture.getValue().iterator().next(), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, optimaPath), ModificationType.WRITE, Optional.of(optimaNode), Optional.absent());
// Write replace the cars container with 2 new car entries. The cohort should get invoked with 3
// DOMDataTreeCandidates: once for each of the 2 new car entries (WRITE mod) and once for the deleted prior
// car entry (DELETE mod).
reset(cohort);
doReturn(PostCanCommitStep.NOOP_SUCCESS_FUTURE).when(cohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
writeTx = dataStore.newWriteOnlyTransaction();
final YangInstanceIdentifier sportagePath = CarsModel.newCarPath("sportage");
final MapEntryNode sportageNode = CarsModel.newCarEntry("sportage", BigInteger.valueOf(20000));
final YangInstanceIdentifier soulPath = CarsModel.newCarPath("soul");
final MapEntryNode soulNode = CarsModel.newCarEntry("soul", BigInteger.valueOf(20000));
writeTx.write(CarsModel.BASE_PATH, CarsModel.newCarsNode(CarsModel.newCarsMapNode(sportageNode, soulNode)));
kit.doCommit(writeTx.ready());
candidateCapture = ArgumentCaptor.forClass(Collection.class);
verify(cohort).canCommit(any(Object.class), candidateCapture.capture(), any(SchemaContext.class));
assertDataTreeCandidate(findCandidate(candidateCapture, sportagePath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, sportagePath), ModificationType.WRITE, Optional.of(sportageNode), Optional.absent());
assertDataTreeCandidate(findCandidate(candidateCapture, soulPath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, soulPath), ModificationType.WRITE, Optional.of(soulNode), Optional.absent());
assertDataTreeCandidate(findCandidate(candidateCapture, optimaPath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, optimaPath), ModificationType.DELETE, Optional.absent(), Optional.of(optimaNode));
// Delete the cars container - cohort should be invoked for the 2 deleted car entries.
reset(cohort);
doReturn(PostCanCommitStep.NOOP_SUCCESS_FUTURE).when(cohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
writeTx = dataStore.newWriteOnlyTransaction();
writeTx.delete(CarsModel.BASE_PATH);
kit.doCommit(writeTx.ready());
candidateCapture = ArgumentCaptor.forClass(Collection.class);
verify(cohort).canCommit(any(Object.class), candidateCapture.capture(), any(SchemaContext.class));
assertDataTreeCandidate(findCandidate(candidateCapture, sportagePath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, sportagePath), ModificationType.DELETE, Optional.absent(), Optional.of(sportageNode));
assertDataTreeCandidate(findCandidate(candidateCapture, soulPath), new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, soulPath), ModificationType.DELETE, Optional.absent(), Optional.of(soulNode));
}
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class AbstractEntityOwnershipTest method verifyOwner.
static void verifyOwner(final String expected, final String entityType, final YangInstanceIdentifier entityId, final Function<YangInstanceIdentifier, NormalizedNode<?, ?>> reader) {
AssertionError lastError = null;
YangInstanceIdentifier entityPath = entityPath(entityType, entityId).node(ENTITY_OWNER_QNAME);
Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.MILLISECONDS) <= 5000) {
try {
NormalizedNode<?, ?> node = reader.apply(entityPath);
Assert.assertNotNull("Owner was not set for entityId: " + entityId, node);
Assert.assertEquals("Entity owner", expected, node.getValue().toString());
return;
} catch (AssertionError e) {
lastError = e;
Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
}
}
throw lastError;
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class LocalTransactionContextTest method testMerge.
@Test
public void testMerge() {
YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
localTransactionContext.executeModification(new MergeModification(yangInstanceIdentifier, normalizedNode));
verify(readWriteTransaction).merge(yangInstanceIdentifier, normalizedNode);
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class LocalTransactionContextTest method testDelete.
@Test
public void testDelete() {
YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
localTransactionContext.executeModification(new DeleteModification(yangInstanceIdentifier));
verify(readWriteTransaction).delete(yangInstanceIdentifier);
}
use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.
the class LocalTransactionContextTest method testReadyWithWriteError.
@Test
public void testReadyWithWriteError() {
YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
RuntimeException error = new RuntimeException("mock");
doThrow(error).when(readWriteTransaction).write(yangInstanceIdentifier, normalizedNode);
localTransactionContext.executeModification(new WriteModification(yangInstanceIdentifier, normalizedNode));
localTransactionContext.executeModification(new WriteModification(yangInstanceIdentifier, normalizedNode));
verify(readWriteTransaction).write(yangInstanceIdentifier, normalizedNode);
doReadyWithExpectedError(error);
}
Aggregations