X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fraft%2FAbstractRaftActorIntegrationTest.java;h=d8d0ce57721d0c5e11876910e1f721c493628a4f;hb=f33beecf2a10955a9219757529ba3017079816cc;hp=ef4151d03ed8227fc43afb4c2857c337904a6aec;hpb=2d60632f7cf63712e8357a3cf3fc40d83366e5e6;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/AbstractRaftActorIntegrationTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/AbstractRaftActorIntegrationTest.java index ef4151d03e..d8d0ce5772 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/AbstractRaftActorIntegrationTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/AbstractRaftActorIntegrationTest.java @@ -17,13 +17,14 @@ import akka.actor.PoisonPill; import akka.actor.Terminated; import akka.dispatch.Dispatchers; import akka.dispatch.Mailboxes; -import akka.testkit.JavaTestKit; import akka.testkit.TestActorRef; +import akka.testkit.javadsl.TestKit; import akka.util.Timeout; import com.google.common.base.Stopwatch; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.Uninterruptibles; import java.io.OutputStream; +import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -90,6 +91,34 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest } } + /** + * Message intended for testing to allow triggering persistData via the mailbox. + */ + public static final class TestPersist { + + private final ActorRef actorRef; + private final Identifier identifier; + private final Payload payload; + + TestPersist(final ActorRef actorRef, final Identifier identifier, final Payload payload) { + this.actorRef = actorRef; + this.identifier = identifier; + this.payload = payload; + } + + public ActorRef getActorRef() { + return actorRef; + } + + public Identifier getIdentifier() { + return identifier; + } + + public Payload getPayload() { + return payload; + } + } + public static class TestRaftActor extends MockRaftActor { private final ActorRef collectorActor; @@ -136,6 +165,12 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest return; } + if (message instanceof TestPersist) { + persistData(((TestPersist) message).getActorRef(), ((TestPersist) message).getIdentifier(), + ((TestPersist) message).getPayload(), false); + return; + } + try { Predicate drop = dropMessages.get(message.getClass()); if (drop == null || !drop.test(message)) { @@ -275,11 +310,11 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest } protected void killActor(final TestActorRef actor) { - JavaTestKit testkit = new JavaTestKit(getSystem()); + TestKit testkit = new TestKit(getSystem()); testkit.watch(actor); actor.tell(PoisonPill.getInstance(), null); - testkit.expectMsgClass(JavaTestKit.duration("5 seconds"), Terminated.class); + testkit.expectMsgClass(Duration.ofSeconds(5), Terminated.class); testkit.unwatch(actor); } @@ -290,8 +325,7 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest } protected void verifySnapshot(final String prefix, final Snapshot snapshot, final long lastAppliedTerm, - final long lastAppliedIndex, final long lastTerm, final long lastIndex) - throws Exception { + final long lastAppliedIndex, final long lastTerm, final long lastIndex) { assertEquals(prefix + " Snapshot getLastAppliedTerm", lastAppliedTerm, snapshot.getLastAppliedTerm()); assertEquals(prefix + " Snapshot getLastAppliedIndex", lastAppliedIndex, snapshot.getLastAppliedIndex()); assertEquals(prefix + " Snapshot getLastTerm", lastTerm, snapshot.getLastTerm());