Search in sources :

Example 6 with DOMTransactionChain

use of org.opendaylight.mdsal.dom.api.DOMTransactionChain 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();
            }
        }
    };
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) ConcurrentDOMDataBroker(org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker) TransactionChainListener(org.opendaylight.mdsal.common.api.TransactionChainListener) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 TransactionChainListener (org.opendaylight.mdsal.common.api.TransactionChainListener)6 DOMTransactionChain (org.opendaylight.mdsal.dom.api.DOMTransactionChain)6 ConcurrentDOMDataBroker (org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker)5 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)5 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)4 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 DOMDataTreeReadWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction)2 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)1 ArrayList (java.util.ArrayList)1 DOMStore (org.opendaylight.mdsal.dom.spi.store.DOMStore)1 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)1 DOMStoreTransactionChain (org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain)1