Search in sources :

Example 1 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class ClientTransactionTest method testReadyEmpty.

@Test
public void testReadyEmpty() throws Exception {
    final DOMStoreThreePhaseCommitCohort cohort = getHandle().ready();
    assertFutureEquals(true, cohort.canCommit());
    assertFutureEquals(null, cohort.preCommit());
    assertFutureEquals(null, cohort.commit());
}
Also used : DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 2 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class ConcurrentDOMDataBrokerTest method testSubmitWithPreCommitException.

@Test
public void testSubmitWithPreCommitException() throws Exception {
    doReturn(Futures.immediateFuture(true)).when(mockCohort1).canCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCohort1).preCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCohort1).abort();
    doReturn(Futures.immediateFuture(true)).when(mockCohort2).canCommit();
    IllegalStateException cause = new IllegalStateException("mock");
    doReturn(Futures.immediateFailedFuture(cause)).when(mockCohort2).preCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCohort2).abort();
    DOMStoreThreePhaseCommitCohort mockCohort3 = mock(DOMStoreThreePhaseCommitCohort.class);
    doReturn(Futures.immediateFuture(true)).when(mockCohort3).canCommit();
    doReturn(Futures.immediateFailedFuture(new IllegalStateException("mock2"))).when(mockCohort3).preCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCohort3).abort();
    CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(transaction, Arrays.asList(mockCohort1, mockCohort2, mockCohort3));
    assertFailure(future, cause, mockCohort1, mockCohort2, mockCohort3);
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 3 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class ConcurrentDOMDataBrokerTest method testSubmitWithOnlyOneSubTransaction.

@Test
public void testSubmitWithOnlyOneSubTransaction() throws InterruptedException {
    DOMStore configDomStore = mock(DOMStore.class);
    DOMStore operationalDomStore = mock(DOMStore.class);
    DOMStoreReadWriteTransaction mockStoreReadWriteTransaction = mock(DOMStoreReadWriteTransaction.class);
    DOMStoreThreePhaseCommitCohort mockCohort = mock(DOMStoreThreePhaseCommitCohort.class);
    doReturn(mockStoreReadWriteTransaction).when(operationalDomStore).newReadWriteTransaction();
    doReturn(mockCohort).when(mockStoreReadWriteTransaction).ready();
    doReturn(Futures.immediateFuture(false)).when(mockCohort).canCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCohort).abort();
    final CountDownLatch latch = new CountDownLatch(1);
    final List<DOMStoreThreePhaseCommitCohort> commitCohorts = new ArrayList<>();
    try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, operationalDomStore, LogicalDatastoreType.CONFIGURATION, configDomStore), futureExecutor) {

        @Override
        public CheckedFuture<Void, TransactionCommitFailedException> submit(DOMDataTreeWriteTransaction writeTx, Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
            commitCohorts.addAll(cohorts);
            latch.countDown();
            return super.submit(writeTx, cohorts);
        }
    }) {
        DOMDataTreeReadWriteTransaction domDataReadWriteTransaction = dataBroker.newReadWriteTransaction();
        domDataReadWriteTransaction.delete(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
        domDataReadWriteTransaction.submit();
        assertTrue(latch.await(10, TimeUnit.SECONDS));
        assertTrue(commitCohorts.size() == 1);
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) DOMStore(org.opendaylight.mdsal.dom.spi.store.DOMStore) DOMDataTreeWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction) DOMStoreReadWriteTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction) ArrayList(java.util.ArrayList) Collection(java.util.Collection) CountDownLatch(java.util.concurrent.CountDownLatch) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 4 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class ConcurrentDOMDataBrokerTest method testSubmitWithNegativeCanCommitResponse.

@Test
public void testSubmitWithNegativeCanCommitResponse() throws Exception {
    doReturn(Futures.immediateFuture(true)).when(mockCohort1).canCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCohort1).abort();
    doReturn(Futures.immediateFuture(false)).when(mockCohort2).canCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCohort2).abort();
    DOMStoreThreePhaseCommitCohort mockCohort3 = mock(DOMStoreThreePhaseCommitCohort.class);
    doReturn(Futures.immediateFuture(false)).when(mockCohort3).canCommit();
    doReturn(Futures.immediateFuture(null)).when(mockCohort3).abort();
    CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(transaction, Arrays.asList(mockCohort1, mockCohort2, mockCohort3));
    assertFailure(future, null, mockCohort1, mockCohort2, mockCohort3);
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort) Test(org.junit.Test)

Example 5 with DOMStoreThreePhaseCommitCohort

use of org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort in project controller by opendaylight.

the class PrefixedShardConfigWriter method writeInitialParent.

private void writeInitialParent() {
    final ClientTransaction tx = history.createTransaction();
    final DOMDataTreeWriteCursor cursor = tx.openCursor();
    final ContainerNode root = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ClusterUtils.PREFIX_SHARDS_QNAME)).withChild(ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(ClusterUtils.SHARD_LIST_QNAME)).build()).build();
    cursor.merge(ClusterUtils.PREFIX_SHARDS_PATH.getLastPathArgument(), root);
    cursor.close();
    final DOMStoreThreePhaseCommitCohort cohort = tx.ready();
    submitBlocking(cohort);
}
Also used : DOMDataTreeWriteCursor(org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor) ClientTransaction(org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DOMStoreThreePhaseCommitCohort(org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)

Aggregations

DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)40 Test (org.junit.Test)31 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)17 ActorRef (akka.actor.ActorRef)11 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)11 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)10 DOMStoreReadTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction)8 DOMStoreReadWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction)8 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)8 CountDownLatch (java.util.concurrent.CountDownLatch)6 ExecutionException (java.util.concurrent.ExecutionException)6 NoShardLeaderException (org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException)6 CommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply)6 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)6 AddressFromURIString (akka.actor.AddressFromURIString)5 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)5 DOMStoreTransactionChain (org.opendaylight.mdsal.dom.spi.store.DOMStoreTransactionChain)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)5 IOException (java.io.IOException)4