Search in sources :

Example 1 with CanCommit

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();
}
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 2 with CanCommit

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);
}
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 3 with CanCommit

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);
}
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 4 with CanCommit

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));
}
Also used : SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) Entry(java.util.Map.Entry) ActorRef(akka.actor.ActorRef) ArrayList(java.util.ArrayList) CanCommit(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit)

Example 5 with CanCommit

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

Aggregations

ActorRef (akka.actor.ActorRef)7 CanCommit (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit)7 Test (org.junit.Test)6 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)6 PreCommit (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit)4 Abort (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Abort)3 Commit (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Commit)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 DataValidationFailedException (org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException)2 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)2 Patterns (akka.pattern.Patterns)1 Timeout (akka.util.Timeout)1 Futures (com.google.common.util.concurrent.Futures)1 JdkFutureAdapters (com.google.common.util.concurrent.JdkFutureAdapters)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)1 Entry (java.util.Map.Entry)1