Search in sources :

Example 6 with DOMTransactionChainListener

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

the class AbstractDistributedDataStoreIntegrationTest method testCreateChainedTransactionsInQuickSuccession.

@Test
public void testCreateChainedTransactionsInQuickSuccession() throws Exception {
    final IntegrationTestKit testKit = new IntegrationTestKit(getSystem(), datastoreContextBuilder);
    try (AbstractDataStore dataStore = testKit.setupAbstractDataStore(testParameter, "testCreateChainedTransactionsInQuickSuccession", "cars-1")) {
        final ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(LogicalDatastoreType.CONFIGURATION, dataStore).build(), MoreExecutors.directExecutor());
        final DOMTransactionChainListener listener = Mockito.mock(DOMTransactionChainListener.class);
        DOMTransactionChain txChain = broker.createTransactionChain(listener);
        final List<ListenableFuture<?>> futures = new ArrayList<>();
        final DOMDataTreeWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
        writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, CarsModel.emptyContainer());
        writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
        futures.add(writeTx.commit());
        int numCars = 100;
        for (int i = 0; i < numCars; i++) {
            final DOMDataTreeReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
            rwTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.newCarPath("car" + i), CarsModel.newCarEntry("car" + i, Uint64.valueOf(20000)));
            futures.add(rwTx.commit());
        }
        for (final ListenableFuture<?> f : futures) {
            f.get(5, TimeUnit.SECONDS);
        }
        final Optional<NormalizedNode> optional = txChain.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
        assertTrue("isPresent", optional.isPresent());
        assertEquals("# cars", numCars, ((Collection<?>) optional.get().body()).size());
        txChain.close();
        broker.close();
    }
}
Also used : ConcurrentDOMDataBroker(org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) ArrayList(java.util.ArrayList) DOMTransactionChain(org.opendaylight.mdsal.dom.api.DOMTransactionChain) DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DOMTransactionChainListener(org.opendaylight.mdsal.dom.api.DOMTransactionChainListener) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

DOMTransactionChain (org.opendaylight.mdsal.dom.api.DOMTransactionChain)6 DOMTransactionChainListener (org.opendaylight.mdsal.dom.api.DOMTransactionChainListener)6 Test (org.junit.Test)5 ConcurrentDOMDataBroker (org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 ExecutionException (java.util.concurrent.ExecutionException)4 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)4 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ArrayList (java.util.ArrayList)2 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)2 DOMDataTreeReadWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction)2 MoreObjects (com.google.common.base.MoreObjects)1 Stopwatch (com.google.common.base.Stopwatch)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1