Search in sources :

Example 16 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class DataTreeCohortActorTest method testAsyncCohort.

@SuppressWarnings("unchecked")
@Test
public void testAsyncCohort() throws Exception {
    ExecutorService executor = Executors.newSingleThreadExecutor();
    doReturn(Futures.makeChecked(executeWithDelay(executor, mockPostCanCommit), ex -> new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock"))).when(mockCohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
    doReturn(JdkFutureAdapters.listenInPoolThread(executor.submit(() -> mockPostPreCommit), MoreExecutors.directExecutor())).when(mockPostCanCommit).preCommit();
    doReturn(JdkFutureAdapters.listenInPoolThread(executor.submit(() -> null), MoreExecutors.directExecutor())).when(mockPostPreCommit).commit();
    ActorRef cohortActor = newCohortActor("testAsyncCohort");
    TransactionIdentifier txId = nextTransactionId();
    askAndAwait(cohortActor, new CanCommit(txId, CANDIDATES, MOCK_SCHEMA, cohortActor));
    verify(mockCohort).canCommit(txId, CANDIDATES, MOCK_SCHEMA);
    askAndAwait(cohortActor, new PreCommit(txId));
    verify(mockPostCanCommit).preCommit();
    askAndAwait(cohortActor, new Commit(txId));
    verify(mockPostPreCommit).commit();
    executor.shutdownNow();
}
Also used : ThreePhaseCommitStep(org.opendaylight.mdsal.common.api.ThreePhaseCommitStep) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) PreCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit) JdkFutureAdapters(com.google.common.util.concurrent.JdkFutureAdapters) Commit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Commit) PostCanCommitStep(org.opendaylight.mdsal.common.api.PostCanCommitStep) Timeout(akka.util.Timeout) ArrayList(java.util.ArrayList) ActorRef(akka.actor.ActorRef) After(org.junit.After) Patterns(akka.pattern.Patterns) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) CommitProtocolCommand(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CommitProtocolCommand) Mockito.doReturn(org.mockito.Mockito.doReturn) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) CanCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit) TestActorFactory(org.opendaylight.controller.cluster.raft.TestActorFactory) PostPreCommitStep(org.opendaylight.mdsal.common.api.PostPreCommitStep) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Abort(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Abort) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) Executors(java.util.concurrent.Executors) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) TimeUnit(java.util.concurrent.TimeUnit) DOMDataTreeCandidate(org.opendaylight.mdsal.dom.api.DOMDataTreeCandidate) Futures(com.google.common.util.concurrent.Futures) DOMDataTreeCommitCohort(org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohort) Success(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Success) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Mockito.reset(org.mockito.Mockito.reset) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) Await(scala.concurrent.Await) DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) PreCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit) Commit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Commit) CanCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit) ActorRef(akka.actor.ActorRef) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ExecutorService(java.util.concurrent.ExecutorService) PreCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit) Collection(java.util.Collection) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) CanCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit) Test(org.junit.Test)

Example 17 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class DataTreeCohortActorTest method testSuccessfulThreePhaseCommit.

@Test
public void testSuccessfulThreePhaseCommit() throws Exception {
    ActorRef cohortActor = newCohortActor("testSuccessfulThreePhaseCommit");
    TransactionIdentifier txId = nextTransactionId();
    askAndAwait(cohortActor, new CanCommit(txId, CANDIDATES, MOCK_SCHEMA, cohortActor));
    verify(mockCohort).canCommit(txId, CANDIDATES, MOCK_SCHEMA);
    askAndAwait(cohortActor, new PreCommit(txId));
    verify(mockPostCanCommit).preCommit();
    askAndAwait(cohortActor, new Commit(txId));
    verify(mockPostPreCommit).commit();
    resetMockCohort();
    askAndAwait(cohortActor, new CanCommit(txId, CANDIDATES, MOCK_SCHEMA, cohortActor));
    verify(mockCohort).canCommit(txId, CANDIDATES, MOCK_SCHEMA);
}
Also used : PreCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit) Commit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Commit) CanCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit) ActorRef(akka.actor.ActorRef) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) PreCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit) CanCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit) Test(org.junit.Test)

Example 18 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class DataTreeCohortActorTest method testFailureOnCanCommit.

@SuppressWarnings("unchecked")
@Test
public void testFailureOnCanCommit() throws Exception {
    DataValidationFailedException failure = new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock");
    doReturn(Futures.immediateFailedCheckedFuture(failure)).when(mockCohort).canCommit(any(Object.class), any(Collection.class), any(SchemaContext.class));
    ActorRef cohortActor = newCohortActor("testFailureOnCanCommit");
    TransactionIdentifier txId = nextTransactionId();
    try {
        askAndAwait(cohortActor, new CanCommit(txId, CANDIDATES, MOCK_SCHEMA, cohortActor));
    } catch (DataValidationFailedException e) {
        assertEquals("DataValidationFailedException", failure, e);
    }
    resetMockCohort();
    askAndAwait(cohortActor, new CanCommit(txId, CANDIDATES, MOCK_SCHEMA, cohortActor));
    verify(mockCohort).canCommit(txId, CANDIDATES, MOCK_SCHEMA);
}
Also used : DataValidationFailedException(org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException) ActorRef(akka.actor.ActorRef) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Collection(java.util.Collection) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) CanCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit) Test(org.junit.Test)

Example 19 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class SingleClientHistory method doCreateTransaction.

@Override
ClientTransaction doCreateTransaction() {
    final TransactionIdentifier txId = new TransactionIdentifier(getIdentifier(), nextTx());
    LOG.debug("{}: creating a new transaction {}", this, txId);
    return new ClientTransaction(this, txId);
}
Also used : TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)

Example 20 with TransactionIdentifier

use of org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier in project controller by opendaylight.

the class AbstractClientHistory method onTransactionReady.

/**
 * Callback invoked from {@link ClientTransaction} when a child transaction readied for submission.
 *
 * @param txId Transaction identifier
 * @param cohort Transaction commit cohort
 */
synchronized AbstractTransactionCommitCohort onTransactionReady(final ClientTransaction tx, final AbstractTransactionCommitCohort cohort) {
    final TransactionIdentifier txId = tx.getIdentifier();
    if (openTransactions.remove(txId) == null) {
        LOG.warn("Transaction {} not recorded, proceeding with readiness", txId);
    }
    final AbstractTransactionCommitCohort previous = readyTransactions.putIfAbsent(txId, cohort);
    Preconditions.checkState(previous == null, "Duplicate cohort %s for transaction %s, already have %s", cohort, txId, previous);
    LOG.debug("Local history {} readied transaction {}", this, txId);
    return cohort;
}
Also used : TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)

Aggregations

TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)57 Test (org.junit.Test)37 FiniteDuration (scala.concurrent.duration.FiniteDuration)17 CanCommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction)16 CommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CommitTransaction)12 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)11 CanCommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply)10 ActorRef (akka.actor.ActorRef)8 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)8 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)8 BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)7 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)7 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)7 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)7 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)6 CanCommit (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit)6 Failure (akka.actor.Status.Failure)5 Timeout (akka.util.Timeout)5 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)5