use of org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit 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.datastore.DataTreeCohortActor.CanCommit 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.datastore.DataTreeCohortActor.CanCommit 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.datastore.DataTreeCohortActor.CanCommit in project controller by opendaylight.
the class CompositeDataTreeCohort method canCommit.
Optional<CompletionStage<Void>> canCommit(final DataTreeCandidate tip) {
if (LOG.isTraceEnabled()) {
LOG.trace("{}: canCommit - candidate: {}", txId, tip);
} else {
LOG.debug("{}: canCommit - candidate rootPath: {}", txId, tip.getRootPath());
}
final List<CanCommit> messages = registry.createCanCommitMessages(txId, tip, schema);
LOG.debug("{}: canCommit - messages: {}", txId, messages);
if (messages.isEmpty()) {
successfulFromPrevious = Collections.emptyList();
changeStateFrom(State.IDLE, State.CAN_COMMIT_SUCCESSFUL);
return Optional.empty();
}
final List<Entry<ActorRef, Future<Object>>> futures = new ArrayList<>(messages.size());
for (CanCommit message : messages) {
final ActorRef actor = message.getCohort();
final Future<Object> future = Patterns.ask(actor, message, timeout).recover(EXCEPTION_TO_MESSAGE, ExecutionContexts.global());
LOG.trace("{}: requesting canCommit from {}", txId, actor);
futures.add(new SimpleImmutableEntry<>(actor, future));
}
changeStateFrom(State.IDLE, State.CAN_COMMIT_SENT);
return Optional.of(processResponses(futures, State.CAN_COMMIT_SENT, State.CAN_COMMIT_SUCCESSFUL));
}
use of org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit in project controller by opendaylight.
the class DataTreeCohortActorTest method testMultipleThreePhaseCommits.
@Test
public void testMultipleThreePhaseCommits() throws Exception {
ActorRef cohortActor = newCohortActor("testMultipleThreePhaseCommits");
TransactionIdentifier txId1 = nextTransactionId();
TransactionIdentifier txId2 = nextTransactionId();
askAndAwait(cohortActor, new CanCommit(txId1, CANDIDATES, MOCK_SCHEMA, cohortActor));
askAndAwait(cohortActor, new CanCommit(txId2, CANDIDATES, MOCK_SCHEMA, cohortActor));
askAndAwait(cohortActor, new PreCommit(txId1));
askAndAwait(cohortActor, new PreCommit(txId2));
askAndAwait(cohortActor, new Commit(txId1));
askAndAwait(cohortActor, new Commit(txId2));
}
Aggregations