use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testChainedTransactionFailureWithSingleShard.
@Test
public void testChainedTransactionFailureWithSingleShard() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testChainedTransactionFailureWithSingleShard", "cars-1")) {
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(LogicalDatastoreType.CONFIGURATION, dataStore).build(), MoreExecutors.directExecutor());
final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
final DOMTransactionChain txChain = broker.createTransactionChain(listener);
final DOMDataTreeReadWriteTransaction writeTx = txChain.newReadWriteTransaction();
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();
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 DistributedDataStoreIntegrationTest method testChainedTransactionFailureWithMultipleShards.
@Test
public void testChainedTransactionFailureWithMultipleShards() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, "testChainedTransactionFailureWithMultipleShards", "cars-1", "people-1")) {
final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(LogicalDatastoreType.CONFIGURATION, dataStore).build(), MoreExecutors.directExecutor());
final TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
final DOMTransactionChain txChain = broker.createTransactionChain(listener);
final DOMDataTreeWriteTransaction writeTx = txChain.newReadWriteTransaction();
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();
writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
// done for put for performance reasons.
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 testInstallSnapshot.
@Test
public void testInstallSnapshot() throws Exception {
final String testName = "testInstallSnapshot";
final String leaderCarShardName = "member-1-shard-cars-" + testName;
final String followerCarShardName = "member-2-shard-cars-" + testName;
// Setup a saved snapshot on the leader. The follower will startup with no data and the leader should
// install a snapshot to sync the follower.
DataTree tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, SchemaContextHelper.full());
final ContainerNode carsNode = CarsModel.newCarsNode(CarsModel.newCarsMapNode(CarsModel.newCarEntry("optima", BigInteger.valueOf(20000))));
AbstractShardTest.writeToStore(tree, CarsModel.BASE_PATH, carsNode);
final NormalizedNode<?, ?> snapshotRoot = AbstractShardTest.readStore(tree, YangInstanceIdentifier.EMPTY);
final Snapshot initialSnapshot = Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(snapshotRoot)), Collections.emptyList(), 5, 1, 5, 1, 1, null, null);
InMemorySnapshotStore.addSnapshot(leaderCarShardName, initialSnapshot);
InMemorySnapshotStore.addSnapshotSavedLatch(leaderCarShardName);
InMemorySnapshotStore.addSnapshotSavedLatch(followerCarShardName);
initDatastoresWithCars(testName);
final Optional<NormalizedNode<?, ?>> readOptional = leaderDistributedDataStore.newReadOnlyTransaction().read(CarsModel.BASE_PATH).checkedGet(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, readOptional.isPresent());
assertEquals("Node", carsNode, readOptional.get());
verifySnapshot(InMemorySnapshotStore.waitForSavedSnapshot(leaderCarShardName, Snapshot.class), initialSnapshot, snapshotRoot);
verifySnapshot(InMemorySnapshotStore.waitForSavedSnapshot(followerCarShardName, Snapshot.class), initialSnapshot, snapshotRoot);
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class DataTreeCohortIntegrationTest method testSuccessfulCanCommitWithNoopPostStep.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testSuccessfulCanCommitWithNoopPostStep() 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));
ArgumentCaptor<Collection> candidateCapt = ArgumentCaptor.forClass(Collection.class);
IntegrationTestKit kit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
try (AbstractDataStore dataStore = kit.setupAbstractDataStore(DistributedDataStore.class, "testSuccessfulCanCommitWithNoopPostStep", "test-1")) {
final ObjectRegistration<DOMDataTreeCommitCohort> cohortReg = dataStore.registerCommitCohort(TEST_ID, cohort);
assertNotNull(cohortReg);
IntegrationTestKit.verifyShardState(dataStore, "test-1", state -> assertEquals("Cohort registrations", 1, state.getCommitCohortActors().size()));
final ContainerNode node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
kit.testWriteTransaction(dataStore, TestModel.TEST_PATH, node);
verify(cohort).canCommit(any(Object.class), candidateCapt.capture(), any(SchemaContext.class));
assertDataTreeCandidate((DOMDataTreeCandidate) candidateCapt.getValue().iterator().next(), TEST_ID, ModificationType.WRITE, Optional.of(node), Optional.absent());
reset(cohort);
doReturn(PostCanCommitStep.NOOP_SUCCESS_FUTURE).when(cohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
kit.testWriteTransaction(dataStore, TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
verify(cohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
cohortReg.close();
IntegrationTestKit.verifyShardState(dataStore, "test-1", state -> assertEquals("Cohort registrations", 0, state.getCommitCohortActors().size()));
kit.testWriteTransaction(dataStore, TestModel.TEST_PATH, node);
verifyNoMoreInteractions(cohort);
}
}
use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode in project controller by opendaylight.
the class NormalizedNodeStreamReaderWriterTest method testNormalizedNodeStreaming.
@Test
public void testNormalizedNodeStreaming() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
NormalizedNodeDataOutput nnout = NormalizedNodeInputOutput.newDataOutput(ByteStreams.newDataOutput(bos));
NormalizedNode<?, ?> testContainer = createTestContainer();
nnout.writeNormalizedNode(testContainer);
QName toaster = QName.create("http://netconfcentral.org/ns/toaster", "2009-11-20", "toaster");
QName darknessFactor = QName.create("http://netconfcentral.org/ns/toaster", "2009-11-20", "darknessFactor");
QName description = QName.create("http://netconfcentral.org/ns/toaster", "2009-11-20", "description");
ContainerNode toasterNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(toaster)).withChild(ImmutableNodes.leafNode(darknessFactor, "1000")).withChild(ImmutableNodes.leafNode(description, largeString(20))).build();
ContainerNode toasterContainer = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(SchemaContext.NAME)).withChild(toasterNode).build();
nnout.writeNormalizedNode(toasterContainer);
NormalizedNodeDataInput nnin = NormalizedNodeInputOutput.newDataInput(ByteStreams.newDataInput(bos.toByteArray()));
NormalizedNode<?, ?> node = nnin.readNormalizedNode();
Assert.assertEquals(testContainer, node);
node = nnin.readNormalizedNode();
Assert.assertEquals(toasterContainer, node);
}
Aggregations