Search in sources :

Example 1 with PreCommit

use of org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit 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 PreCommit

use of org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit 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 PreCommit

use of org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit 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)

Example 4 with PreCommit

use of org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit in project controller by opendaylight.

the class DataTreeCohortActorTest method testAbortAfterPreCommit.

@Test
public void testAbortAfterPreCommit() throws Exception {
    ActorRef cohortActor = newCohortActor("testAbortAfterPreCommit");
    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 Abort(txId));
    verify(mockPostPreCommit).abort();
}
Also used : Abort(org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Abort) 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)4 Test (org.junit.Test)4 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)4 CanCommit (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit)4 PreCommit (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.PreCommit)4 Commit (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Commit)3 Abort (org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Abort)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 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 TimeUnit (java.util.concurrent.TimeUnit)1 After (org.junit.After)1