X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FThreePhaseCommitCohortProxyTest.java;h=46060dda2a9bdd1cf1ec94e98d24c53ec97ed5a3;hb=82be26d1da9096cb86f2f36e142854003415f4ae;hp=adb12b298e99260b6f33a6c309f3c6eb16ca78bb;hpb=e90bec01888e6b2a2503d21de25f3a674d607163;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java index adb12b298e..46060dda2a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java @@ -4,19 +4,8 @@ import akka.actor.ActorPath; import akka.actor.ActorSelection; import akka.actor.Props; import akka.dispatch.Futures; - import com.google.common.collect.Lists; import com.google.common.util.concurrent.ListenableFuture; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.times; - import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -33,14 +22,20 @@ import org.opendaylight.controller.cluster.datastore.messages.PreCommitTransacti import org.opendaylight.controller.cluster.datastore.messages.SerializableMessage; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.cluster.datastore.utils.DoNothingActor; - import scala.concurrent.Future; -import scala.concurrent.duration.FiniteDuration; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.isA; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { @SuppressWarnings("serial") @@ -57,28 +52,28 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { doReturn(getSystem()).when(actorContext).getActorSystem(); } - private Future newCohortPath() { + private Future newCohort() { ActorPath path = getSystem().actorOf(Props.create(DoNothingActor.class)).path(); - doReturn(mock(ActorSelection.class)).when(actorContext).actorSelection(path); - return Futures.successful(path); + ActorSelection actorSelection = getSystem().actorSelection(path); + return Futures.successful(actorSelection); } private final ThreePhaseCommitCohortProxy setupProxy(int nCohorts) throws Exception { - List> cohortPathFutures = Lists.newArrayList(); + List> cohortFutures = Lists.newArrayList(); for(int i = 1; i <= nCohorts; i++) { - cohortPathFutures.add(newCohortPath()); + cohortFutures.add(newCohort()); } - return new ThreePhaseCommitCohortProxy(actorContext, cohortPathFutures, "txn-1"); + return new ThreePhaseCommitCohortProxy(actorContext, cohortFutures, "txn-1"); } private ThreePhaseCommitCohortProxy setupProxyWithFailedCohortPath() throws Exception { - List> cohortPathFutures = Lists.newArrayList(); - cohortPathFutures.add(newCohortPath()); - cohortPathFutures.add(Futures.failed(new TestException())); + List> cohortFutures = Lists.newArrayList(); + cohortFutures.add(newCohort()); + cohortFutures.add(Futures.failed(new TestException())); - return new ThreePhaseCommitCohortProxy(actorContext, cohortPathFutures, "txn-1"); + return new ThreePhaseCommitCohortProxy(actorContext, cohortFutures, "txn-1"); } private void setupMockActorContext(Class requestType, Object... responses) { @@ -92,13 +87,13 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { .successful(((SerializableMessage) responses[i]).toSerializable())); } - stubber.when(actorContext).executeRemoteOperationAsync(any(ActorSelection.class), - isA(requestType), any(FiniteDuration.class)); + stubber.when(actorContext).executeOperationAsync(any(ActorSelection.class), + isA(requestType)); } private void verifyCohortInvocations(int nCohorts, Class requestType) { - verify(actorContext, times(nCohorts)).executeRemoteOperationAsync( - any(ActorSelection.class), isA(requestType), any(FiniteDuration.class)); + verify(actorContext, times(nCohorts)).executeOperationAsync( + any(ActorSelection.class), isA(requestType)); } private void propagateExecutionExceptionCause(ListenableFuture future) throws Throwable { @@ -199,24 +194,13 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { @Test public void testPreCommit() throws Exception { + // Precommit is currently a no-op ThreePhaseCommitCohortProxy proxy = setupProxy(1); setupMockActorContext(PreCommitTransaction.SERIALIZABLE_CLASS, new PreCommitTransactionReply()); proxy.preCommit().get(5, TimeUnit.SECONDS); - - verifyCohortInvocations(1, PreCommitTransaction.SERIALIZABLE_CLASS); - } - - @Test(expected = ExecutionException.class) - public void testPreCommitWithFailure() throws Exception { - ThreePhaseCommitCohortProxy proxy = setupProxy(2); - - setupMockActorContext(PreCommitTransaction.SERIALIZABLE_CLASS, - new PreCommitTransactionReply(), new RuntimeException("mock")); - - proxy.preCommit().get(5, TimeUnit.SECONDS); } @Test @@ -318,7 +302,6 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { proxy.commit().get(5, TimeUnit.SECONDS); verifyCohortInvocations(2, CanCommitTransaction.SERIALIZABLE_CLASS); - verifyCohortInvocations(2, PreCommitTransaction.SERIALIZABLE_CLASS); verifyCohortInvocations(2, CommitTransaction.SERIALIZABLE_CLASS); } }