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=b7a303e8d2eec6729e8952065566923f1fc152bd;hb=3115b8171461584e85f58d87a9f179013cfbb262;hp=dadd3a99f7f8d0def3b7025d0206c3098d4cb907;hpb=b5cb353e3553a39f576c284119af75ffa5ea66a9;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 dadd3a99f7..b7a303e8d2 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 @@ -16,7 +16,7 @@ import static org.opendaylight.controller.cluster.datastore.DataStoreVersions.CU import akka.actor.ActorSelection; import akka.actor.Props; -import akka.actor.UntypedActor; +import akka.actor.UntypedAbstractActor; import akka.dispatch.Dispatchers; import akka.dispatch.Futures; import akka.testkit.TestActorRef; @@ -45,7 +45,7 @@ import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransacti import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply; import org.opendaylight.controller.cluster.datastore.messages.CommitTransaction; import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply; -import org.opendaylight.controller.cluster.datastore.utils.ActorContext; +import org.opendaylight.controller.cluster.datastore.utils.ActorUtils; import org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper; import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration; import org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache; @@ -58,7 +58,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { static class TestException extends RuntimeException { } - private ActorContext actorContext; + private ActorUtils actorUtils; @Mock private Timer commitTimer; @@ -78,7 +78,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { public void setUp() { MockitoAnnotations.initMocks(this); - actorContext = new ActorContext(getSystem(), actorFactory.createActor(Props.create(DoNothingActor.class)), + actorUtils = new ActorUtils(getSystem(), actorFactory.createActor(Props.create(DoNothingActor.class)), new MockClusterWrapper(), new MockConfiguration(), DatastoreContext.newBuilder().build(), new PrimaryShardInfoFutureCache()) { @Override @@ -103,7 +103,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { @Test public void testCanCommitYesWithOneCohort() throws Exception { - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, Arrays.asList( + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, Arrays.asList( newCohortInfo(new CohortActor.Builder(tx).expectCanCommit( CanCommitTransactionReply.yes(CURRENT_VERSION)))), tx); @@ -113,7 +113,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { @Test public void testCanCommitNoWithOneCohort() throws Exception { - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, Arrays.asList( + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, Arrays.asList( newCohortInfo(new CohortActor.Builder(tx).expectCanCommit( CanCommitTransactionReply.no(CURRENT_VERSION)))), tx); @@ -128,7 +128,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { CanCommitTransactionReply.yes(CURRENT_VERSION))), newCohortInfo(new CohortActor.Builder(tx).expectCanCommit( CanCommitTransactionReply.yes(CURRENT_VERSION)))); - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, cohorts, tx); + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, cohorts, tx); verifyCanCommit(proxy.canCommit(), true); verifyCohortActors(); @@ -142,7 +142,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { newCohortInfo(new CohortActor.Builder(tx).expectCanCommit( CanCommitTransactionReply.no(CURRENT_VERSION))), newCohortInfo(new CohortActor.Builder(tx))); - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, cohorts, tx); + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, cohorts, tx); verifyCanCommit(proxy.canCommit(), false); verifyCohortActors(); @@ -150,7 +150,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { @Test(expected = TestException.class) public void testCanCommitWithExceptionFailure() throws Exception { - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, Arrays.asList( + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, Arrays.asList( newCohortInfo(new CohortActor.Builder(tx).expectCanCommit(new TestException()))), tx); propagateExecutionExceptionCause(proxy.canCommit()); @@ -158,7 +158,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { @Test(expected = IllegalArgumentException.class) public void testCanCommitWithInvalidResponseType() throws Exception { - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, Arrays.asList( + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, Arrays.asList( newCohortInfo(new CohortActor.Builder(tx).expectCanCommit("invalid"))), tx); propagateExecutionExceptionCause(proxy.canCommit()); @@ -170,7 +170,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { newCohortInfo(new CohortActor.Builder(tx)), newCohortInfoWithFailedFuture(new TestException()), newCohortInfo(new CohortActor.Builder(tx))); - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, cohorts, tx); + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, cohorts, tx); propagateExecutionExceptionCause(proxy.canCommit()); } @@ -184,7 +184,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { newCohortInfo( new CohortActor.Builder(tx).expectCanCommit(CanCommitTransactionReply.yes(CURRENT_VERSION)) .expectCommit(CommitTransactionReply.instance(CURRENT_VERSION)))); - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, cohorts, tx); + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, cohorts, tx); verifyCanCommit(proxy.canCommit(), true); verifySuccessfulFuture(proxy.preCommit()); @@ -201,7 +201,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { newCohortInfo( new CohortActor.Builder(tx).expectCanCommit(CanCommitTransactionReply.yes(CURRENT_VERSION)) .expectCommit(new TestException()))); - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, cohorts, tx); + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, cohorts, tx); verifyCanCommit(proxy.canCommit(), true); verifySuccessfulFuture(proxy.preCommit()); @@ -210,7 +210,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { @Test(expected = IllegalArgumentException.class) public void testCommitWithInvalidResponseType() throws Exception { - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, Arrays.asList(newCohortInfo(new CohortActor.Builder(tx) .expectCanCommit(CanCommitTransactionReply.yes(CURRENT_VERSION)).expectCommit("invalid"))), tx); @@ -221,7 +221,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { @Test public void testAbort() throws Exception { - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, Arrays.asList( + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, Arrays.asList( newCohortInfo(new CohortActor.Builder(tx).expectAbort( AbortTransactionReply.instance(CURRENT_VERSION)))), tx); @@ -231,7 +231,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { @Test public void testAbortWithFailure() throws Exception { - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, Arrays.asList( + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, Arrays.asList( newCohortInfo(new CohortActor.Builder(tx).expectAbort(new RuntimeException("mock")))), tx); // The exception should not get propagated. @@ -243,7 +243,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { public void testAbortWithFailedCohortFuture() throws Exception { List cohorts = Arrays.asList( newCohortInfoWithFailedFuture(new TestException()), newCohortInfo(new CohortActor.Builder(tx))); - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, cohorts, tx); + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, cohorts, tx); verifySuccessfulFuture(proxy.abort()); verifyCohortActors(); @@ -251,7 +251,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { @Test public void testWithNoCohorts() throws Exception { - ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorContext, + ThreePhaseCommitCohortProxy proxy = new ThreePhaseCommitCohortProxy(actorUtils, Collections.emptyList(), tx); verifyCanCommit(proxy.canCommit(), true); @@ -260,8 +260,8 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { verifyCohortActors(); } + @SuppressWarnings("checkstyle:avoidHidingCauseException") private void propagateExecutionExceptionCause(final ListenableFuture future) throws Exception { - try { future.get(5, TimeUnit.SECONDS); fail("Expected ExecutionException"); @@ -308,14 +308,14 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { assertEquals("canCommit", expected, actual); } - private static class CohortActor extends UntypedActor { + private static class CohortActor extends UntypedAbstractActor { private final Builder builder; private final AtomicInteger canCommitCount = new AtomicInteger(); private final AtomicInteger commitCount = new AtomicInteger(); private final AtomicInteger abortCount = new AtomicInteger(); private volatile AssertionError assertionError; - private CohortActor(final Builder builder) { + CohortActor(final Builder builder) { this.builder = builder; }