use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testChainedTransactionFailureWithMultipleShards.
@Test
public void testChainedTransactionFailureWithMultipleShards() throws Exception {
initDatastoresWithCarsAndPeople("testChainedTransactionFailureWithMultipleShards");
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(LogicalDatastoreType.CONFIGURATION, followerDistributedDataStore).build(), MoreExecutors.directExecutor());
final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
final DOMTransactionChain txChain = broker.createTransactionChain(listener);
final DOMDataTreeWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
// Note that merge will validate the data and fail but put succeeds b/c deep validation is not
// done for put for performance reasons.
writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
try {
writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (final TransactionCommitFailedException e) {
// Expected
}
verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
txChain.close();
broker.close();
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testChainedTransactionFailureWithSingleShard.
@Test
public void testChainedTransactionFailureWithSingleShard() throws Exception {
initDatastoresWithCars("testChainedTransactionFailureWithSingleShard");
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(LogicalDatastoreType.CONFIGURATION, followerDistributedDataStore).build(), MoreExecutors.directExecutor());
final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
final DOMTransactionChain txChain = broker.createTransactionChain(listener);
final DOMDataTreeWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
try {
writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
fail("Expected TransactionCommitFailedException");
} catch (final TransactionCommitFailedException e) {
// Expected
}
verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
txChain.close();
broker.close();
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class TransactionProxyTest method testReadRoot.
@Test
public void testReadRoot() throws ReadFailedException, InterruptedException, ExecutionException, java.util.concurrent.TimeoutException {
SchemaContext schemaContext = SchemaContextHelper.full();
Configuration configuration = mock(Configuration.class);
doReturn(configuration).when(mockActorContext).getConfiguration();
doReturn(schemaContext).when(mockActorContext).getSchemaContext();
doReturn(Sets.newHashSet("test", "cars")).when(configuration).getAllShardNames();
NormalizedNode<?, ?> expectedNode1 = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
NormalizedNode<?, ?> expectedNode2 = ImmutableNodes.containerNode(CarsModel.CARS_QNAME);
setUpReadData("test", NormalizedNodeAggregatorTest.getRootNode(expectedNode1, schemaContext));
setUpReadData("cars", NormalizedNodeAggregatorTest.getRootNode(expectedNode2, schemaContext));
doReturn(MemberName.forName(memberName)).when(mockActorContext).getCurrentMemberName();
doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(mockActorContext).getClientDispatcher();
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_ONLY);
Optional<NormalizedNode<?, ?>> readOptional = transactionProxy.read(YangInstanceIdentifier.EMPTY).get(5, TimeUnit.SECONDS);
assertEquals("NormalizedNode isPresent", true, readOptional.isPresent());
NormalizedNode<?, ?> normalizedNode = readOptional.get();
assertTrue("Expect value to be a Collection", normalizedNode.getValue() instanceof Collection);
@SuppressWarnings("unchecked") Collection<NormalizedNode<?, ?>> collection = (Collection<NormalizedNode<?, ?>>) normalizedNode.getValue();
for (NormalizedNode<?, ?> node : collection) {
assertTrue("Expected " + node + " to be a ContainerNode", node instanceof ContainerNode);
}
assertTrue("Child with QName = " + TestModel.TEST_QNAME + " not found", NormalizedNodeAggregatorTest.findChildWithQName(collection, TestModel.TEST_QNAME) != null);
assertEquals(expectedNode1, NormalizedNodeAggregatorTest.findChildWithQName(collection, TestModel.TEST_QNAME));
assertTrue("Child with QName = " + CarsModel.BASE_QNAME + " not found", NormalizedNodeAggregatorTest.findChildWithQName(collection, CarsModel.BASE_QNAME) != null);
assertEquals(expectedNode2, NormalizedNodeAggregatorTest.findChildWithQName(collection, CarsModel.BASE_QNAME));
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class AbstractEntityOwnershipTest method verifyEntityCandidate.
protected void verifyEntityCandidate(final NormalizedNode<?, ?> node, final String entityType, final YangInstanceIdentifier entityId, final String candidateName, final boolean expectPresent) {
try {
assertNotNull("Missing " + EntityOwners.QNAME.toString(), node);
assertTrue(node instanceof ContainerNode);
ContainerNode entityOwnersNode = (ContainerNode) node;
MapEntryNode entityTypeEntry = getMapEntryNodeChild(entityOwnersNode, EntityType.QNAME, ENTITY_TYPE_QNAME, entityType, true);
MapEntryNode entityEntry = getMapEntryNodeChild(entityTypeEntry, ENTITY_QNAME, ENTITY_ID_QNAME, entityId, true);
getMapEntryNodeChild(entityEntry, Candidate.QNAME, CANDIDATE_NAME_QNAME, candidateName, expectPresent);
} catch (AssertionError e) {
throw new AssertionError("Verification of entity candidate failed - returned data was: " + node, e);
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class TestModel method createAugmentedListEntry.
public static MapEntryNode createAugmentedListEntry(final int id, final String name) {
Set<QName> childAugmentations = new HashSet<>();
childAugmentations.add(AUG_CONT_QNAME);
ContainerNode augCont = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(AUG_CONT_QNAME)).withChild(ImmutableNodes.leafNode(AUG_NAME_QNAME, name)).build();
final YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier = new YangInstanceIdentifier.AugmentationIdentifier(childAugmentations);
final AugmentationNode augmentationNode = Builders.augmentationBuilder().withNodeIdentifier(augmentationIdentifier).withChild(augCont).build();
return ImmutableMapEntryNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifierWithPredicates(AUGMENTED_LIST_QNAME, ID_QNAME, id)).withChild(ImmutableNodes.leafNode(ID_QNAME, id)).withChild(augmentationNode).build();
}
Aggregations