Datastore: Reuse successful future
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / ThreePhaseCommitCohortFailureTest.java
index 870889b350aae84982164109255bda969960628f..672166c4424c7ea0a8fd5c7ddd2e07b057e572b2 100644 (file)
@@ -13,9 +13,12 @@ package org.opendaylight.controller.cluster.datastore;
 import akka.actor.ActorRef;
 import akka.actor.Props;
 import akka.testkit.TestActorRef;
+
 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 +34,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,19 +63,21 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest {
         ShardIdentifier.builder().memberName("member-1")
             .shardName("inventory").type("config").build();
 
-    static {
+    private final ShardContext shardContext = new ShardContext();
+
+    @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, shardContext));
         final DOMStoreThreePhaseCommitCohort mockCohort = Mockito
             .mock(DOMStoreThreePhaseCommitCohort.class);
         final CompositeModification mockComposite =
@@ -93,18 +99,14 @@ 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, shardContext));
         final DOMStoreThreePhaseCommitCohort mockCohort = Mockito
             .mock(DOMStoreThreePhaseCommitCohort.class);
         final CompositeModification mockComposite =
@@ -135,9 +137,8 @@ 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, shardContext));
         final DOMStoreThreePhaseCommitCohort mockCohort = Mockito
             .mock(DOMStoreThreePhaseCommitCohort.class);
         final CompositeModification mockComposite =
@@ -166,15 +167,13 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest {
     @Test(expected = TestException.class)
     public void testNegativeCommitResultsInException() throws Exception {
 
-        final TestActorRef<Shard> subject = TestActorRef
-            .create(getSystem(),
-                Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP,null),
+        final TestActorRef<Shard> subject = TestActorRef.create(getSystem(),
+                Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, shardContext),
                 "testNegativeCommitResultsInException");
 
         final ActorRef shardTransaction =
-            getSystem().actorOf(
-                ShardTransaction.props(store.newReadWriteTransaction(), subject,
-                    TestModel.createTestContext()));
+            getSystem().actorOf(ShardTransaction.props(store.newReadWriteTransaction(), subject,
+                    testSchemaContext, shardContext));
 
         ShardTransactionMessages.WriteData writeData =
             ShardTransactionMessages.WriteData.newBuilder()
@@ -221,12 +220,8 @@ public class ThreePhaseCommitCohortFailureTest extends AbstractActorTest {
                 mockForwardCommitTransaction
                 , 3000);
         Await.result(future, ASK_RESULT_DURATION);
-
-
     }
 
     private class TestException extends Exception {
     }
-
-
 }