Specify initial serialization buffer capacity for Payloads
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / AbstractTest.java
index 66a41275fcc5803fadfea1866cec2d2bea500122..a3726e270bea47a1ad4b840e20ab14b6b5753709 100644 (file)
@@ -7,16 +7,28 @@
  */
 package org.opendaylight.controller.cluster.datastore;
 
+import akka.actor.ActorSystem;
+import akka.testkit.javadsl.TestKit;
+import com.typesafe.config.ConfigFactory;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.CompletionStage;
 import java.util.concurrent.atomic.AtomicLong;
+import org.junit.After;
 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.MemberName;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
+import scala.compat.java8.FutureConverters;
+import scala.concurrent.Await;
+import scala.concurrent.duration.FiniteDuration;
 
 public abstract class AbstractTest {
     protected static final MemberName MEMBER_NAME = MemberName.forName("member-1");
+    protected static final MemberName MEMBER_2_NAME = MemberName.forName("member-2");
+
     private static final FrontendType FRONTEND_TYPE = FrontendType.forName(ShardTransactionTest.class.getSimpleName());
 
     protected static final FrontendIdentifier FRONTEND_ID = FrontendIdentifier.create(MEMBER_NAME, FRONTEND_TYPE);
@@ -26,6 +38,13 @@ public abstract class AbstractTest {
     private static final AtomicLong HISTORY_COUNTER = new AtomicLong();
     private static final AtomicLong TX_COUNTER = new AtomicLong();
 
+    private final Collection<ActorSystem> actorSystems = new ArrayList<>();
+
+    protected static void setUpStatic() {
+        HISTORY_COUNTER.set(1L);
+        TX_COUNTER.set(1L);
+    }
+
     protected static TransactionIdentifier nextTransactionId() {
         return new TransactionIdentifier(HISTORY_ID, TX_COUNTER.getAndIncrement());
     }
@@ -33,4 +52,22 @@ public abstract class AbstractTest {
     protected static LocalHistoryIdentifier nextHistoryId() {
         return new LocalHistoryIdentifier(CLIENT_ID, HISTORY_COUNTER.incrementAndGet());
     }
+
+    protected static <T> T waitOnAsyncTask(final CompletionStage<T> completionStage, final FiniteDuration timeout)
+            throws Exception {
+        return Await.result(FutureConverters.toScala(completionStage), timeout);
+    }
+
+    @After
+    public void actorSystemCleanup() {
+        for (final ActorSystem system : actorSystems) {
+            TestKit.shutdownActorSystem(system, true);
+        }
+    }
+
+    protected ActorSystem newActorSystem(final String name, final String config) {
+        ActorSystem system = ActorSystem.create(name, ConfigFactory.load().getConfig(config));
+        actorSystems.add(system);
+        return system;
+    }
 }