Search in sources :

Example 11 with DOMDataTreeWriteTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction in project controller by opendaylight.

the class ShardedDOMDataBrokerDelegatingTransactionChainTest method testNewReadWriteTransaction.

@Test
public void testNewReadWriteTransaction() {
    DOMDataTreeReadTransaction delegateReadTx = mock(DOMDataTreeReadTransaction.class);
    doReturn("TEST-READ-TX-DELEGATE").when(delegateReadTx).getIdentifier();
    doReturn(delegateReadTx).when(delegateTxChain).newReadOnlyTransaction();
    DOMDataTreeWriteTransaction delegateWriteTx = mock(DOMDataTreeWriteTransaction.class);
    doReturn(delegateWriteTx).when(delegateTxChain).newWriteOnlyTransaction();
    doReturn("TEST-WRITE-TX-DELEGATE").when(delegateWriteTx).getIdentifier();
    txChain.newReadWriteTransaction();
    verify(delegateTxChain).newReadOnlyTransaction();
    verify(delegateTxChain).newWriteOnlyTransaction();
}
Also used : DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) Test(org.junit.Test)

Example 12 with DOMDataTreeWriteTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction in project controller by opendaylight.

the class ShardedDOMDataBrokerDelegatingTransactionChain method newReadWriteTransaction.

@Override
public DOMDataReadWriteTransaction newReadWriteTransaction() {
    final Object readWriteTxId = newTransactionIdentifier();
    final DOMDataTreeReadTransaction readTxDelegate = txChainDelegate.newReadOnlyTransaction();
    final DOMDataReadOnlyTransaction readTx = new ShardedDOMDataBrokerDelegatingReadTransaction(readWriteTxId, readTxDelegate);
    final DOMDataTreeWriteTransaction writeTxDelegate = txChainDelegate.newWriteOnlyTransaction();
    final DOMDataWriteTransaction writeTx = new ShardedDOMDataBrokerDelegatingWriteTransaction(readWriteTxId, writeTxDelegate);
    final DOMDataReadWriteTransaction readWriteTx = new ShardedDOMDataBrokerDelegatingReadWriteTransaction(readWriteTxId, schemaContext, readTx, writeTx);
    transactionMap.put(readTxDelegate.getIdentifier(), readWriteTx);
    transactionMap.put(writeTxDelegate.getIdentifier(), readWriteTx);
    return readWriteTx;
}
Also used : DOMDataReadWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction) DOMDataReadOnlyTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMDataTreeReadTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction) DOMDataWriteTransaction(org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)

Example 13 with DOMDataTreeWriteTransaction

use of org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction 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

DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)13 Test (org.junit.Test)11 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)6 TransactionChainListener (org.opendaylight.mdsal.common.api.TransactionChainListener)5 DOMTransactionChain (org.opendaylight.mdsal.dom.api.DOMTransactionChain)5 ConcurrentDOMDataBroker (org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker)4 DOMStore (org.opendaylight.mdsal.dom.spi.store.DOMStore)4 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)4 ArrayList (java.util.ArrayList)3 DOMDataTreeReadTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction)3 DOMDataTreeReadWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction)3 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)3 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)3 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)3 Collection (java.util.Collection)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)2 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)1 AsyncTransaction (org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction)1