X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FThreePhaseCommitCohortFailureTest.java;h=e39b9abd65a711e333f9c0315b25de2e3457266a;hp=870889b350aae84982164109255bda969960628f;hb=2dc333588d0c15eb7f2df6223dcdcc15e05b077e;hpb=63b36aa3537d77bd9be323e1113716ef2cd54098 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 870889b350..e39b9abd65 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,9 +13,13 @@ 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; import com.google.common.util.concurrent.MoreExecutors; + +import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier; @@ -31,6 +35,7 @@ import org.opendaylight.controller.protobuff.messages.persistent.PersistentMessa import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages; import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; import org.opendaylight.yangtools.yang.model.api.SchemaContext; + import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.Duration; @@ -59,25 +64,28 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest { ShardIdentifier.builder().memberName("member-1") .shardName("inventory").type("config").build(); - static { + private final DatastoreContext datastoreContext = new DatastoreContext(); + + + @BeforeClass + public static void staticSetup() { store.onGlobalContextUpdated(testSchemaContext); } - private FiniteDuration ASK_RESULT_DURATION = Duration.create(3000, TimeUnit.MILLISECONDS); + private final FiniteDuration ASK_RESULT_DURATION = Duration.create(5000, TimeUnit.MILLISECONDS); @Test(expected = TestException.class) public void testNegativeAbortResultsInException() throws Exception { - final ActorRef shard = - getSystem() - .actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); + final ActorRef shard = getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, + Collections.EMPTY_MAP, datastoreContext)); 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,SHARD_IDENTIFIER.toString()); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -93,24 +101,20 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest { assertTrue(future.isCompleted()); Await.result(future, ASK_RESULT_DURATION); - - - } @Test(expected = OptimisticLockFailedException.class) public void testNegativeCanCommitResultsInException() throws Exception { - final ActorRef shard = - getSystem() - .actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null)); + final ActorRef shard = getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, + Collections.EMPTY_MAP, datastoreContext)); 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,SHARD_IDENTIFIER.toString()); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -135,15 +139,14 @@ 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,null)); + final ActorRef shard = getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, + Collections.EMPTY_MAP, datastoreContext)); 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,SHARD_IDENTIFIER.toString()); final TestActorRef subject = TestActorRef .create(getSystem(), props, @@ -166,15 +169,13 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest { @Test(expected = TestException.class) public void testNegativeCommitResultsInException() throws Exception { - final TestActorRef subject = TestActorRef - .create(getSystem(), - Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null), + final TestActorRef subject = TestActorRef.create(getSystem(), + Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, datastoreContext), "testNegativeCommitResultsInException"); final ActorRef shardTransaction = - getSystem().actorOf( - ShardTransaction.props(store.newReadWriteTransaction(), subject, - TestModel.createTestContext())); + getSystem().actorOf(ShardTransaction.props(store.newReadWriteTransaction(), subject, + testSchemaContext, datastoreContext,SHARD_IDENTIFIER.toString())); ShardTransactionMessages.WriteData writeData = ShardTransactionMessages.WriteData.newBuilder() @@ -185,17 +186,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 @@ -216,17 +217,10 @@ 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); - - } private class TestException extends Exception { } - - }