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();
}
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);
}
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);
}
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);
}
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;
}
Aggregations