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%2FAbstractTest.java;h=e57ae8fcedf4fd449c2027dd5740d1b022b51523;hb=refs%2Fchanges%2F22%2F65622%2F11;hp=8256edd27230dd4821f0e0ca2d386cce3cfe11bc;hpb=5370e8be094b802caa732efb4da5a035c53dc9c6;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTest.java index 8256edd272..e57ae8fced 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTest.java @@ -7,13 +7,23 @@ */ 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.Duration; public abstract class AbstractTest { protected static final MemberName MEMBER_NAME = MemberName.forName("member-1"); @@ -28,6 +38,8 @@ public abstract class AbstractTest { private static final AtomicLong HISTORY_COUNTER = new AtomicLong(); private static final AtomicLong TX_COUNTER = new AtomicLong(); + private final Collection actorSystems = new ArrayList<>(); + protected static void setUpStatic() { HISTORY_COUNTER.set(1L); TX_COUNTER.set(1L); @@ -40,4 +52,22 @@ public abstract class AbstractTest { protected static LocalHistoryIdentifier nextHistoryId() { return new LocalHistoryIdentifier(CLIENT_ID, HISTORY_COUNTER.incrementAndGet()); } + + protected static T waitOnAsyncTask(final CompletionStage completionStage, final Duration timeout) + throws Exception { + return Await.result(FutureConverters.toScala(completionStage), timeout); + } + + @After + public void actorSystemCleanup() { + for (final ActorSystem system : actorSystems) { + TestKit.shutdownActorSystem(system, Boolean.TRUE); + } + } + + protected ActorSystem newActorSystem(final String name, final String config) { + ActorSystem system = ActorSystem.create(name, ConfigFactory.load().getConfig(config)); + actorSystems.add(system); + return system; + } }