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=ac970c64e479558236fd6e03392d5cd86b074ec6;hb=refs%2Fchanges%2F22%2F65622%2F11;hp=1119a3260a140888b0645040b66aaa8f65f65d99;hpb=a66b0a0f12639e4cfb43bb92602407f09b849c3f;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 1119a3260a..ac970c64e4 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 @@ -16,8 +16,9 @@ import akka.actor.InvalidActorNameException; import akka.actor.PoisonPill; import akka.actor.Terminated; import akka.dispatch.Dispatchers; -import akka.testkit.JavaTestKit; +import akka.dispatch.Mailboxes; 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; @@ -66,7 +67,7 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest private static final class MockIdentifier extends AbstractStringIdentifier { private static final long serialVersionUID = 1L; - protected MockIdentifier(String string) { + protected MockIdentifier(final String string) { super(string); } } @@ -75,7 +76,7 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest private final String peerId; private final String peerAddress; - public SetPeerAddress(String peerId, String peerAddress) { + public SetPeerAddress(final String peerId, final String peerAddress) { this.peerId = peerId; this.peerAddress = peerAddress; } @@ -91,23 +92,23 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest public static class TestRaftActor extends MockRaftActor { - private final TestActorRef collectorActor; + private final ActorRef collectorActor; private final Map, Predicate> dropMessages = new ConcurrentHashMap<>(); - private TestRaftActor(Builder builder) { + TestRaftActor(final Builder builder) { super(builder); this.collectorActor = builder.collectorActor; } - public void startDropMessages(Class msgClass) { + public void startDropMessages(final Class msgClass) { dropMessages.put(msgClass, msg -> true); } - void startDropMessages(Class msgClass, Predicate filter) { + void startDropMessages(final Class msgClass, final Predicate filter) { dropMessages.put(msgClass, filter); } - public void stopDropMessages(Class msgClass) { + public void stopDropMessages(final Class msgClass) { dropMessages.remove(msgClass); } @@ -117,7 +118,7 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest @SuppressWarnings({ "rawtypes", "unchecked", "checkstyle:IllegalCatch" }) @Override - public void handleCommand(Object message) { + public void handleCommand(final Object message) { if (message instanceof MockPayload) { MockPayload payload = (MockPayload) message; super.persistData(collectorActor, new MockIdentifier(payload.toString()), payload, false); @@ -130,7 +131,7 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest } if (message instanceof SetPeerAddress) { - setPeerAddress(((SetPeerAddress) message).getPeerId().toString(), + setPeerAddress(((SetPeerAddress) message).getPeerId(), ((SetPeerAddress) message).getPeerAddress()); return; } @@ -153,7 +154,7 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest @Override @SuppressWarnings("checkstyle:IllegalCatch") - public void createSnapshot(ActorRef actorRef, Optional installSnapshotStream) { + public void createSnapshot(final ActorRef actorRef, final Optional installSnapshotStream) { MockSnapshotState snapshotState = new MockSnapshotState(new ArrayList<>(getState())); if (installSnapshotStream.isPresent()) { SerializationUtils.serialize(snapshotState, installSnapshotStream.get()); @@ -171,15 +172,15 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest } public static class Builder extends AbstractBuilder { - private TestActorRef collectorActor; + private ActorRef collectorActor; - public Builder collectorActor(TestActorRef newCollectorActor) { - this.collectorActor = newCollectorActor; - return this; + Builder() { + super(TestRaftActor.class); } - private Builder() { - super(TestRaftActor.class); + public Builder collectorActor(final ActorRef newCollectorActor) { + this.collectorActor = newCollectorActor; + return this; } } } @@ -215,6 +216,7 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest protected long currentTerm; protected int snapshotBatchCount = 4; + protected int snapshotChunkSize = SNAPSHOT_CHUNK_SIZE; protected List expSnapshotState = new ArrayList<>(); @@ -232,7 +234,7 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest configParams.setSnapshotBatchCount(snapshotBatchCount); configParams.setSnapshotDataThresholdPercentage(70); configParams.setIsolatedLeaderCheckInterval(new FiniteDuration(1, TimeUnit.DAYS)); - configParams.setSnapshotChunkSize(SNAPSHOT_CHUNK_SIZE); + configParams.setSnapshotChunkSize(snapshotChunkSize); return configParams; } @@ -243,25 +245,25 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest return configParams; } - protected void waitUntilLeader(ActorRef actorRef) { + protected void waitUntilLeader(final ActorRef actorRef) { RaftActorTestKit.waitUntilLeader(actorRef); } - protected TestActorRef newTestRaftActor(String id, Map newPeerAddresses, - ConfigParams configParams) { + protected TestActorRef newTestRaftActor(final String id, final Map newPeerAddresses, + final ConfigParams configParams) { return newTestRaftActor(id, TestRaftActor.newBuilder().peerAddresses(newPeerAddresses != null ? newPeerAddresses : Collections.emptyMap()).config(configParams)); } - protected TestActorRef newTestRaftActor(String id, TestRaftActor.Builder builder) { - builder.collectorActor(factory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - factory.generateActorId(id + "-collector"))).id(id); + protected TestActorRef newTestRaftActor(final String id, final TestRaftActor.Builder builder) { + builder.collectorActor(factory.createActor( + MessageCollectorActor.props(), factory.generateActorId(id + "-collector"))).id(id); InvalidActorNameException lastEx = null; for (int i = 0; i < 10; i++) { try { - return factory.createTestActor(builder.props().withDispatcher(Dispatchers.DefaultDispatcherId()), id); + return factory.createTestActor(builder.props().withDispatcher(Dispatchers.DefaultDispatcherId()) + .withMailbox(Mailboxes.DefaultMailboxId()), id); } catch (InvalidActorNameException e) { lastEx = e; Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); @@ -272,23 +274,23 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest throw lastEx; } - protected void killActor(TestActorRef actor) { - JavaTestKit testkit = new JavaTestKit(getSystem()); + protected void killActor(final TestActorRef actor) { + TestKit testkit = new TestKit(getSystem()); testkit.watch(actor); actor.tell(PoisonPill.getInstance(), null); - testkit.expectMsgClass(JavaTestKit.duration("5 seconds"), Terminated.class); + testkit.expectMsgClass(testkit.duration("5 seconds"), Terminated.class); testkit.unwatch(actor); } - protected void verifyApplyJournalEntries(ActorRef actor, final long expIndex) { + protected void verifyApplyJournalEntries(final ActorRef actor, final long expIndex) { MessageCollectorActor.expectFirstMatching(actor, ApplyJournalEntries.class, msg -> msg.getToIndex() == expIndex); } - protected void verifySnapshot(String prefix, Snapshot snapshot, long lastAppliedTerm, - long lastAppliedIndex, long lastTerm, long lastIndex) + protected void verifySnapshot(final String prefix, final Snapshot snapshot, final long lastAppliedTerm, + final long lastAppliedIndex, final long lastTerm, final long lastIndex) throws Exception { assertEquals(prefix + " Snapshot getLastAppliedTerm", lastAppliedTerm, snapshot.getLastAppliedTerm()); assertEquals(prefix + " Snapshot getLastAppliedIndex", lastAppliedIndex, snapshot.getLastAppliedIndex()); @@ -303,7 +305,8 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest } } - protected void verifyPersistedJournal(String persistenceId, List expJournal) { + protected void verifyPersistedJournal(final String persistenceId, + final List expJournal) { List journal = InMemoryJournal.get(persistenceId, ReplicatedLogEntry.class); assertEquals("Journal ReplicatedLogEntry count", expJournal.size(), journal.size()); for (int i = 0; i < expJournal.size(); i++) { @@ -313,11 +316,11 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest } } - protected MockPayload sendPayloadData(ActorRef actor, String data) { + protected MockPayload sendPayloadData(final ActorRef actor, final String data) { return sendPayloadData(actor, data, 0); } - protected MockPayload sendPayloadData(ActorRef actor, String data, int size) { + protected MockPayload sendPayloadData(final ActorRef actor, final String data, final int size) { MockPayload payload; if (size > 0) { payload = new MockPayload(data, size); @@ -329,8 +332,8 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest return payload; } - protected void verifyApplyState(ApplyState applyState, ActorRef expClientActor, - String expId, long expTerm, long expIndex, Payload payload) { + protected void verifyApplyState(final ApplyState applyState, final ActorRef expClientActor, + final String expId, final long expTerm, final long expIndex, final Payload payload) { assertEquals("ApplyState getClientActor", expClientActor, applyState.getClientActor()); final Identifier id = expId == null ? null : new MockIdentifier(expId); @@ -339,31 +342,32 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest verifyReplicatedLogEntry(replicatedLogEntry, expTerm, expIndex, payload); } - protected void verifyReplicatedLogEntry(ReplicatedLogEntry replicatedLogEntry, long expTerm, long expIndex, - Payload payload) { + protected void verifyReplicatedLogEntry(final ReplicatedLogEntry replicatedLogEntry, final long expTerm, + final long expIndex, final Payload payload) { assertEquals("ReplicatedLogEntry getTerm", expTerm, replicatedLogEntry.getTerm()); assertEquals("ReplicatedLogEntry getIndex", expIndex, replicatedLogEntry.getIndex()); assertEquals("ReplicatedLogEntry getData", payload, replicatedLogEntry.getData()); } - protected String testActorPath(String id) { + protected String testActorPath(final String id) { return factory.createTestActorPath(id); } - protected void verifyLeadersTrimmedLog(long lastIndex) { + protected void verifyLeadersTrimmedLog(final long lastIndex) { verifyTrimmedLog("Leader", leaderActor, lastIndex, lastIndex - 1); } - protected void verifyLeadersTrimmedLog(long lastIndex, long replicatedToAllIndex) { + protected void verifyLeadersTrimmedLog(final long lastIndex, final long replicatedToAllIndex) { verifyTrimmedLog("Leader", leaderActor, lastIndex, replicatedToAllIndex); } - protected void verifyFollowersTrimmedLog(int num, TestActorRef actorRef, long lastIndex) { + protected void verifyFollowersTrimmedLog(final int num, final TestActorRef actorRef, + final long lastIndex) { verifyTrimmedLog("Follower " + num, actorRef, lastIndex, lastIndex - 1); } - protected void verifyTrimmedLog(String name, TestActorRef actorRef, long lastIndex, - long replicatedToAllIndex) { + protected void verifyTrimmedLog(final String name, final TestActorRef actorRef, final long lastIndex, + final long replicatedToAllIndex) { TestRaftActor actor = actorRef.underlyingActor(); RaftActorContext context = actor.getRaftActorContext(); long snapshotIndex = lastIndex - 1; @@ -379,7 +383,7 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest } @SuppressWarnings("checkstyle:IllegalCatch") - static void verifyRaftState(ActorRef raftActor, Consumer verifier) { + static void verifyRaftState(final ActorRef raftActor, final Consumer verifier) { Timeout timeout = new Timeout(500, TimeUnit.MILLISECONDS); AssertionError lastError = null; Stopwatch sw = Stopwatch.createStarted();