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=13d3882a04b0fe0681d3bc7c4cd2cf1bc10ab2a1;hb=afe114674227071a2598dd3a3f6589a99573e075;hp=ba7295bcea75a7a3b4f9806549065211a0290f13;hpb=2d60632f7cf63712e8357a3cf3fc40d83366e5e6;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 ba7295bcea..13d3882a04 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 @@ -5,9 +5,9 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.datastore; +import static java.util.Objects.requireNonNull; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; @@ -16,13 +16,12 @@ 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; import com.codahale.metrics.Snapshot; import com.codahale.metrics.Timer; -import com.google.common.base.Preconditions; import com.google.common.base.Throwables; import com.google.common.util.concurrent.ListenableFuture; import java.util.ArrayList; @@ -45,7 +44,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 +57,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { static class TestException extends RuntimeException { } - private ActorContext actorContext; + private ActorUtils actorUtils; @Mock private Timer commitTimer; @@ -78,7 +77,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 +102,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 +112,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 +127,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 +141,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 +149,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 +157,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 +169,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 +183,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 +200,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 +209,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 +220,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 +230,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 +242,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 +250,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); @@ -308,7 +307,7 @@ 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(); @@ -383,7 +382,7 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { private final TransactionIdentifier transactionId; Builder(final TransactionIdentifier transactionId) { - this.transactionId = Preconditions.checkNotNull(transactionId); + this.transactionId = requireNonNull(transactionId); } Builder expectCanCommit(final Class newExpCanCommitType, final Object newCanCommitReply) {