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%2FThreePhaseCommitCohortFailureTest.java;h=4e4c34bcbc75fe0e74369ae407d83624c3438ae0;hb=76cc965bd2d9978fedcbe19603c98e7752abf5a8;hp=672166c4424c7ea0a8fd5c7ddd2e07b057e572b2;hpb=9cd4e7995210f8381892004373acc71c8b3ae7af;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortFailureTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortFailureTest.java index 672166c442..4e4c34bcbc 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortFailureTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortFailureTest.java @@ -13,6 +13,7 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorRef; import akka.actor.Props; import akka.testkit.TestActorRef; +import akka.util.Timeout; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListeningExecutorService; @@ -22,6 +23,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier; +import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats; import org.opendaylight.controller.cluster.datastore.messages.ForwardedCommitTransaction; import org.opendaylight.controller.cluster.datastore.modification.CompositeModification; import org.opendaylight.controller.cluster.datastore.modification.Modification; @@ -63,7 +65,9 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest { ShardIdentifier.builder().memberName("member-1") .shardName("inventory").type("config").build(); - private final ShardContext shardContext = new ShardContext(); + private final DatastoreContext datastoreContext = new DatastoreContext(); + + private final ShardStats shardStats = new ShardStats(SHARD_IDENTIFIER.toString(), "DataStore"); @BeforeClass public static void staticSetup() { @@ -72,18 +76,20 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest { private final FiniteDuration ASK_RESULT_DURATION = Duration.create(5000, TimeUnit.MILLISECONDS); + private ActorRef createShard(){ + return getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, datastoreContext, TestModel.createTestContext())); + } @Test(expected = TestException.class) public void testNegativeAbortResultsInException() throws Exception { - final ActorRef shard = getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, - Collections.EMPTY_MAP, shardContext)); + final ActorRef shard = createShard(); final DOMStoreThreePhaseCommitCohort mockCohort = Mockito .mock(DOMStoreThreePhaseCommitCohort.class); final CompositeModification mockComposite = Mockito.mock(CompositeModification.class); final Props props = - ThreePhaseCommitCohort.props(mockCohort, shard, mockComposite); + ThreePhaseCommitCohort.props(mockCohort, shard, mockComposite, shardStats); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -105,14 +111,13 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest { @Test(expected = OptimisticLockFailedException.class) public void testNegativeCanCommitResultsInException() throws Exception { - final ActorRef shard = getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, - Collections.EMPTY_MAP, shardContext)); + final ActorRef shard = createShard(); final DOMStoreThreePhaseCommitCohort mockCohort = Mockito .mock(DOMStoreThreePhaseCommitCohort.class); final CompositeModification mockComposite = Mockito.mock(CompositeModification.class); final Props props = - ThreePhaseCommitCohort.props(mockCohort, shard, mockComposite); + ThreePhaseCommitCohort.props(mockCohort, shard, mockComposite, shardStats); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -137,14 +142,13 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest { @Test(expected = TestException.class) public void testNegativePreCommitResultsInException() throws Exception { - final ActorRef shard = getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, - Collections.EMPTY_MAP, shardContext)); + final ActorRef shard = createShard(); final DOMStoreThreePhaseCommitCohort mockCohort = Mockito .mock(DOMStoreThreePhaseCommitCohort.class); final CompositeModification mockComposite = Mockito.mock(CompositeModification.class); final Props props = - ThreePhaseCommitCohort.props(mockCohort, shard, mockComposite); + ThreePhaseCommitCohort.props(mockCohort, shard, mockComposite, shardStats); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -168,12 +172,12 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest { public void testNegativeCommitResultsInException() throws Exception { final TestActorRef subject = TestActorRef.create(getSystem(), - Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, shardContext), + Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, datastoreContext, TestModel.createTestContext()), "testNegativeCommitResultsInException"); final ActorRef shardTransaction = getSystem().actorOf(ShardTransaction.props(store.newReadWriteTransaction(), subject, - testSchemaContext, shardContext)); + testSchemaContext, datastoreContext, shardStats)); ShardTransactionMessages.WriteData writeData = ShardTransactionMessages.WriteData.newBuilder() @@ -184,17 +188,17 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest { ).build(); + Timeout askTimeout = new Timeout(ASK_RESULT_DURATION); + //This is done so that Modification list is updated which is used during commit - Future future = - akka.pattern.Patterns.ask(shardTransaction, writeData, 3000); + Future future = akka.pattern.Patterns.ask(shardTransaction, writeData, askTimeout); //ready transaction creates the cohort so that we get into the //block where in commmit is done ShardTransactionMessages.ReadyTransaction readyTransaction = ShardTransactionMessages.ReadyTransaction.newBuilder().build(); - future = - akka.pattern.Patterns.ask(shardTransaction, readyTransaction, 3000); + future = akka.pattern.Patterns.ask(shardTransaction, readyTransaction, askTimeout); //but when the message is sent it will have the MockCommit object //so that we can simulate throwing of exception @@ -215,10 +219,7 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest { when(mockModification.toSerializable()).thenReturn( PersistentMessages.CompositeModification.newBuilder().build()); - future = - akka.pattern.Patterns.ask(subject, - mockForwardCommitTransaction - , 3000); + future = akka.pattern.Patterns.ask(subject, mockForwardCommitTransaction, askTimeout); Await.result(future, ASK_RESULT_DURATION); }