From: Tom Pantelis Date: Wed, 6 Sep 2017 10:59:32 +0000 (-0400) Subject: Fix intermittent PreLeaderScenarioTest failure X-Git-Tag: release/oxygen~101 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=c32a09739f0f7a008fe203b7b4ca172755136307 Fix intermittent PreLeaderScenarioTest failure testUnComittedEntryOnLeaderChange(org.opendaylight.controller.cluster.raft.PreLeaderScenarioTest) Time elapsed: 5.207 sec <<< FAILURE! java.lang.AssertionError: Did not receive message of type class org.opendaylight.controller.cluster.raft.messages.AppendEntries at org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.expectFirstMatching(MessageCollectorActor.java:147) at org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.expectFirstMatching(MessageCollectorActor.java:125) at org.opendaylight.controller.cluster.raft.PreLeaderScenarioTest.testUnComittedEntryOnLeaderChange(PreLeaderScenarioTest.java:56) The MessageCollectorActor does receive the message but occasionally out of order w.r.t the CLEAR_MESSAGES although the latter is sent prior. The problem is that AppendEntries is a ControlMessage so can get delivered before CLEAR_MESSAGES thus CLEAR_MESSAGES needs to also be a ControlMessage. Another problem with many of the tests is that MessageCollectorActors are created as TestActors and thus get the CallingThreadDispatcher by default which really isn't desirable. Some of the tests specifically set the default fork-join dispatcher but we should just create MessageCollectorActors as normal actors. Change-Id: I455a500d39aae4c46fb33d59be24c6327a9d321d Signed-off-by: Tom Pantelis --- 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 c50a10894a..05a2df4094 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 @@ -92,7 +92,7 @@ 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) { @@ -172,9 +172,9 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest } public static class Builder extends AbstractBuilder { - private TestActorRef collectorActor; + private ActorRef collectorActor; - public Builder collectorActor(TestActorRef newCollectorActor) { + public Builder collectorActor(ActorRef newCollectorActor) { this.collectorActor = newCollectorActor; return this; } @@ -256,9 +256,8 @@ public abstract class AbstractRaftActorIntegrationTest extends AbstractActorTest } protected TestActorRef newTestRaftActor(String id, TestRaftActor.Builder builder) { - builder.collectorActor(factory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - factory.generateActorId(id + "-collector"))).id(id); + builder.collectorActor(factory.createActor( + MessageCollectorActor.props(), factory.generateActorId(id + "-collector"))).id(id); InvalidActorNameException lastEx = null; for (int i = 0; i < 10; i++) { diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/IsolationScenarioTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/IsolationScenarioTest.java index fb810e3aeb..179f4f039e 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/IsolationScenarioTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/IsolationScenarioTest.java @@ -15,10 +15,7 @@ import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorAct import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.expectMatching; import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.getAllMatching; -import akka.actor.Actor; import akka.actor.ActorRef; -import akka.actor.Props; -import akka.testkit.TestActorRef; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import java.util.List; @@ -41,8 +38,8 @@ import scala.concurrent.duration.FiniteDuration; * @author Thomas Pantelis */ public class IsolationScenarioTest extends AbstractRaftActorIntegrationTest { - private TestActorRef follower1NotifierActor; - private TestActorRef leaderNotifierActor; + private ActorRef follower1NotifierActor; + private ActorRef leaderNotifierActor; /** * Isolates the leader after all initial payload entries have been committed and applied on all nodes. While @@ -424,7 +421,7 @@ public class IsolationScenarioTest extends AbstractRaftActorIntegrationTest { private void createRaftActors() { testLog.info("createRaftActors starting"); - follower1NotifierActor = factory.createTestActor(Props.create(MessageCollectorActor.class), + follower1NotifierActor = factory.createActor(MessageCollectorActor.props(), factory.generateActorId(follower1Id + "-notifier")); DefaultConfigParamsImpl followerConfigParams = new DefaultConfigParamsImpl(); @@ -444,7 +441,7 @@ public class IsolationScenarioTest extends AbstractRaftActorIntegrationTest { leaderConfigParams = newLeaderConfigParams(); leaderConfigParams.setIsolatedLeaderCheckInterval(new FiniteDuration(500, TimeUnit.MILLISECONDS)); - leaderNotifierActor = factory.createTestActor(Props.create(MessageCollectorActor.class), + leaderNotifierActor = factory.createActor(MessageCollectorActor.props(), factory.generateActorId(leaderId + "-notifier")); leaderActor = newTestRaftActor(leaderId, TestRaftActor.newBuilder().peerAddresses(peerAddresses) diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/LeadershipTransferIntegrationTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/LeadershipTransferIntegrationTest.java index a4a7f555ab..48c9fee8a9 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/LeadershipTransferIntegrationTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/LeadershipTransferIntegrationTest.java @@ -14,7 +14,6 @@ import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorAct import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.expectMatching; import akka.actor.ActorRef; -import akka.actor.Props; import akka.actor.Status; import akka.pattern.Patterns; import akka.testkit.JavaTestKit; @@ -50,10 +49,10 @@ import scala.concurrent.duration.FiniteDuration; public class LeadershipTransferIntegrationTest extends AbstractRaftActorIntegrationTest { private final String follower3Id = factory.generateActorId("follower"); - private TestActorRef leaderNotifierActor; - private TestActorRef follower1NotifierActor; - private TestActorRef follower2NotifierActor; - private TestActorRef follower3NotifierActor; + private ActorRef leaderNotifierActor; + private ActorRef follower1NotifierActor; + private ActorRef follower2NotifierActor; + private ActorRef follower3NotifierActor; private TestActorRef follower3Actor; private ActorRef follower3CollectorActor; private ActorRef requestLeadershipResultCollectorActor; @@ -154,21 +153,21 @@ public class LeadershipTransferIntegrationTest extends AbstractRaftActorIntegrat InMemorySnapshotStore.addSnapshot(follower2Id, snapshot); InMemorySnapshotStore.addSnapshot(follower3Id, snapshot); - follower1NotifierActor = factory.createTestActor(Props.create(MessageCollectorActor.class), + follower1NotifierActor = factory.createActor(MessageCollectorActor.props(), factory.generateActorId(follower1Id + "-notifier")); follower1Actor = newTestRaftActor(follower1Id, TestRaftActor.newBuilder().peerAddresses( ImmutableMap.of(leaderId, testActorPath(leaderId), follower2Id, testActorPath(follower2Id), follower3Id, testActorPath(follower3Id))) .config(newFollowerConfigParams()).roleChangeNotifier(follower1NotifierActor)); - follower2NotifierActor = factory.createTestActor(Props.create(MessageCollectorActor.class), + follower2NotifierActor = factory.createActor(MessageCollectorActor.props(), factory.generateActorId(follower2Id + "-notifier")); follower2Actor = newTestRaftActor(follower2Id,TestRaftActor.newBuilder().peerAddresses( ImmutableMap.of(leaderId, testActorPath(leaderId), follower1Id, follower1Actor.path().toString(), follower3Id, testActorPath(follower3Id))) .config(newFollowerConfigParams()).roleChangeNotifier(follower2NotifierActor)); - follower3NotifierActor = factory.createTestActor(Props.create(MessageCollectorActor.class), + follower3NotifierActor = factory.createActor(MessageCollectorActor.props(), factory.generateActorId(follower3Id + "-notifier")); follower3Actor = newTestRaftActor(follower3Id,TestRaftActor.newBuilder().peerAddresses( ImmutableMap.of(leaderId, testActorPath(leaderId), follower1Id, follower1Actor.path().toString(), @@ -182,7 +181,7 @@ public class LeadershipTransferIntegrationTest extends AbstractRaftActorIntegrat leaderConfigParams = newLeaderConfigParams(); leaderConfigParams.setElectionTimeoutFactor(3); - leaderNotifierActor = factory.createTestActor(Props.create(MessageCollectorActor.class), + leaderNotifierActor = factory.createActor(MessageCollectorActor.props(), factory.generateActorId(leaderId + "-notifier")); leaderActor = newTestRaftActor(leaderId, TestRaftActor.newBuilder().peerAddresses(peerAddresses) .config(leaderConfigParams).roleChangeNotifier(leaderNotifierActor)); @@ -203,7 +202,7 @@ public class LeadershipTransferIntegrationTest extends AbstractRaftActorIntegrat verifyRaftState(raftActor, rs -> assertEquals("getRaftState", expState.toString(), rs.getRaftState())); } - private static void verifyLeaderStateChangedMessages(final TestActorRef notifierActor, + private static void verifyLeaderStateChangedMessages(final ActorRef notifierActor, final String... expLeaderIds) { List leaderStateChanges = expectMatching(notifierActor, LeaderStateChanged.class, expLeaderIds.length); diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/NonVotingFollowerIntegrationTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/NonVotingFollowerIntegrationTest.java index 575c4fbca8..660d791438 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/NonVotingFollowerIntegrationTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/NonVotingFollowerIntegrationTest.java @@ -10,7 +10,6 @@ package org.opendaylight.controller.cluster.raft; import static org.junit.Assert.assertEquals; import akka.actor.ActorRef; -import akka.dispatch.Dispatchers; import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Sets; @@ -358,9 +357,8 @@ public class NonVotingFollowerIntegrationTest extends AbstractRaftActorIntegrati public void testFollowerLeaderStateChanges() { testLog.info("testFollowerLeaderStateChanges"); - ActorRef roleChangeNotifier = factory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - factory.generateActorId("roleChangeNotifier")); + ActorRef roleChangeNotifier = factory.createActor( + MessageCollectorActor.props(), factory.generateActorId("roleChangeNotifier")); follower1Builder.roleChangeNotifier(roleChangeNotifier); setupLeaderAndNonVotingFollower(); diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/PreLeaderScenarioTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/PreLeaderScenarioTest.java index e4628d7a0a..bb201863c9 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/PreLeaderScenarioTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/PreLeaderScenarioTest.java @@ -12,10 +12,7 @@ import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorAct import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.expectFirstMatching; import static org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor.expectMatching; -import akka.actor.Actor; import akka.actor.ActorRef; -import akka.actor.Props; -import akka.testkit.TestActorRef; import com.google.common.collect.ImmutableMap; import java.util.List; import java.util.concurrent.TimeUnit; @@ -37,7 +34,7 @@ import scala.concurrent.duration.FiniteDuration; */ public class PreLeaderScenarioTest extends AbstractRaftActorIntegrationTest { - private TestActorRef follower1NotifierActor; + private ActorRef follower1NotifierActor; private DefaultConfigParamsImpl followerConfigParams; @Test @@ -130,7 +127,7 @@ public class PreLeaderScenarioTest extends AbstractRaftActorIntegrationTest { private void createRaftActors() { testLog.info("createRaftActors starting"); - follower1NotifierActor = factory.createTestActor(Props.create(MessageCollectorActor.class), + follower1NotifierActor = factory.createActor(MessageCollectorActor.props(), factory.generateActorId(follower1Id + "-notifier")); followerConfigParams = newFollowerConfigParams(); @@ -171,6 +168,6 @@ public class PreLeaderScenarioTest extends AbstractRaftActorIntegrationTest { follower1Context = follower1Actor.underlyingActor().getRaftActorContext(); follower2Context = follower2Actor.underlyingActor().getRaftActorContext(); - testLog.info("createRaftActors ending"); + testLog.info("createRaftActors ending - follower1: {}, follower2: {}", follower1Id, follower2Id); } } diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupportTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupportTest.java index c22a0e567e..e844ddf790 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupportTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorServerConfigurationSupportTest.java @@ -98,7 +98,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { actorFactory.generateActorId(FOLLOWER_ID)); private TestActorRef newFollowerRaftActor; - private TestActorRef newFollowerCollectorActor; + private ActorRef newFollowerCollectorActor; private RaftActorContext newFollowerActorContext; private final JavaTestKit testKit = new JavaTestKit(getSystem()); @@ -113,8 +113,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { private void setupNewFollower() { DefaultConfigParamsImpl configParams = newFollowerConfigParams(); - newFollowerCollectorActor = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), + newFollowerCollectorActor = actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId(NEW_SERVER_ID + "Collector")); newFollowerRaftActor = actorFactory.createTestActor(MockNewFollowerRaftActor.props( configParams, newFollowerCollectorActor).withDispatcher(Dispatchers.DefaultDispatcherId()), @@ -164,7 +163,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { clearMessages(followerActor); MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); - final TestActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); + final ActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); leaderActor.tell(new AddServer(NEW_SERVER_ID, newFollowerRaftActor.path().toString(), true), testKit.getRef()); @@ -244,7 +243,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); final RaftActorContext leaderActorContext = leaderRaftActor.getRaftActorContext(); - final TestActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); + final ActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); leaderActor.tell(new AddServer(NEW_SERVER_ID, newFollowerRaftActor.path().toString(), true), testKit.getRef()); @@ -296,7 +295,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); final RaftActorContext leaderActorContext = leaderRaftActor.getRaftActorContext(); - final TestActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); + final ActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); leaderActor.tell(new AddServer(NEW_SERVER_ID, newFollowerRaftActor.path().toString(), false), testKit.getRef()); @@ -366,7 +365,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); final RaftActorContext leaderActorContext = leaderRaftActor.getRaftActorContext(); - final TestActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); + final ActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); RaftActorContext follower2ActorContext = newFollowerContext(NEW_SERVER_ID2, followerActor); Follower newFollower2 = new Follower(follower2ActorContext); @@ -429,7 +428,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); final RaftActorContext leaderActorContext = leaderRaftActor.getRaftActorContext(); - TestActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); + ActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); // Drop commit message for now to delay snapshot completion leaderRaftActor.setDropMessageOfType(String.class); @@ -509,7 +508,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { RaftActorContext leaderActorContext = leaderRaftActor.getRaftActorContext(); ((DefaultConfigParamsImpl)leaderActorContext.getConfigParams()).setElectionTimeoutFactor(100); - final TestActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); + final ActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); // Drop the commit message so the snapshot doesn't complete yet. leaderRaftActor.setDropMessageOfType(COMMIT_MESSAGE_CLASS); @@ -559,7 +558,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { ((DefaultConfigParamsImpl)leaderActorContext.getConfigParams()).setElectionTimeoutFactor(8); - TestActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); + ActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); // Drop the UnInitializedFollowerSnapshotReply to delay it. leaderRaftActor.setDropMessageOfType(UnInitializedFollowerSnapshotReply.class); @@ -658,7 +657,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { MockLeaderRaftActor leaderRaftActor = leaderActor.underlyingActor(); final RaftActorContext leaderActorContext = leaderRaftActor.getRaftActorContext(); - final TestActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); + final ActorRef leaderCollectorActor = newLeaderCollectorActor(leaderRaftActor); // Drop UnInitializedFollowerSnapshotReply initially leaderRaftActor.setDropMessageOfType(UnInitializedFollowerSnapshotReply.class); @@ -731,9 +730,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl(); configParams.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS)); - TestActorRef leaderActor = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId(LEADER_ID)); + ActorRef leaderActor = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId(LEADER_ID)); TestActorRef followerRaftActor = actorFactory.createTestActor( MockRaftActor.builder().id(FOLLOWER_ID).peerAddresses(ImmutableMap.of(LEADER_ID, @@ -828,9 +826,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { DefaultConfigParamsImpl configParams = new DefaultConfigParamsImpl(); configParams.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS)); - TestActorRef leaderActor = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId(LEADER_ID)); + ActorRef leaderActor = actorFactory.createTestActor( + MessageCollectorActor.props(), actorFactory.generateActorId(LEADER_ID)); TestActorRef followerRaftActor = actorFactory.createTestActor( MockRaftActor.builder().id(FOLLOWER_ID).peerAddresses(ImmutableMap.of(LEADER_ID, @@ -868,20 +865,17 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); - final TestActorRef leaderCollector = - newLeaderCollectorActor(leaderActor.underlyingActor()); + final ActorRef leaderCollector = newLeaderCollectorActor(leaderActor.underlyingActor()); - TestActorRef follower1Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef follower1Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); final TestActorRef follower1Actor = actorFactory.createTestActor( CollectingMockRaftActor.props(FOLLOWER_ID, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID2, follower2ActorPath, downNodeId, ""), configParams, NO_PERSISTENCE, follower1Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), follower1ActorId); - TestActorRef follower2Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef follower2Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); final TestActorRef follower2Actor = actorFactory.createTestActor( CollectingMockRaftActor.props(FOLLOWER_ID2, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID, follower1ActorPath, downNodeId, ""), configParams, NO_PERSISTENCE, @@ -932,12 +926,10 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { initialActorContext).withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); - final TestActorRef leaderCollector = - newLeaderCollectorActor(leaderActor.underlyingActor()); + final ActorRef leaderCollector = newLeaderCollectorActor(leaderActor.underlyingActor()); - final TestActorRef followerCollector = - actorFactory.createTestActor(MessageCollectorActor.props() - .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId("collector")); + final ActorRef followerCollector = + actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId("collector")); actorFactory.createTestActor( CollectingMockRaftActor.props(FOLLOWER_ID, ImmutableMap.of(LEADER_ID, leaderActor.path().toString()), configParams, NO_PERSISTENCE, followerCollector) @@ -993,19 +985,17 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, follower1ActorPath, FOLLOWER_ID2, follower2ActorPath), new MockRaftActorContext()) .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); - TestActorRef leaderCollector = newLeaderCollectorActor(leaderActor.underlyingActor()); + ActorRef leaderCollector = newLeaderCollectorActor(leaderActor.underlyingActor()); - TestActorRef follower1Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef follower1Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); final TestActorRef follower1RaftActor = actorFactory.createTestActor( CollectingMockRaftActor.props(FOLLOWER_ID, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID2, follower2ActorPath), configParams, NO_PERSISTENCE, follower1Collector) .withDispatcher(Dispatchers.DefaultDispatcherId()), follower1ActorId); - TestActorRef follower2Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef follower2Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); final TestActorRef follower2RaftActor = actorFactory.createTestActor( CollectingMockRaftActor.props(FOLLOWER_ID2, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID, follower1ActorPath), configParams, NO_PERSISTENCE, follower2Collector) @@ -1074,19 +1064,17 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { MockLeaderRaftActor.props(ImmutableMap.of(FOLLOWER_ID, follower1ActorPath, FOLLOWER_ID2, follower2ActorPath), new MockRaftActorContext()) .withDispatcher(Dispatchers.DefaultDispatcherId()), actorFactory.generateActorId(LEADER_ID)); - TestActorRef leaderCollector = newLeaderCollectorActor(leaderActor.underlyingActor()); + ActorRef leaderCollector = newLeaderCollectorActor(leaderActor.underlyingActor()); - TestActorRef follower1Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef follower1Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); final TestActorRef follower1RaftActor = actorFactory.createTestActor( CollectingMockRaftActor.props(FOLLOWER_ID, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID2, follower2ActorPath), configParams, NO_PERSISTENCE, follower1Collector) .withDispatcher(Dispatchers.DefaultDispatcherId()), follower1ActorId); - TestActorRef follower2Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef follower2Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); final TestActorRef follower2RaftActor = actorFactory.createTestActor( CollectingMockRaftActor.props(FOLLOWER_ID2, ImmutableMap.of(LEADER_ID, leaderActor.path().toString(), FOLLOWER_ID, follower1ActorPath), configParams, NO_PERSISTENCE, follower2Collector) @@ -1160,17 +1148,15 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { InMemoryJournal.addEntry(node2ID, 2, persistedServerConfigEntry); InMemoryJournal.addEntry(node2ID, 3, new ApplyJournalEntries(0)); - TestActorRef node1Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef node1Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node1RaftActorRef = actorFactory.createTestActor( CollectingMockRaftActor.props(node1ID, ImmutableMap.of(), configParams, PERSISTENT, node1Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node1ID); CollectingMockRaftActor node1RaftActor = node1RaftActorRef.underlyingActor(); - TestActorRef node2Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef node2Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node2RaftActorRef = actorFactory.createTestActor( CollectingMockRaftActor.props(node2ID, ImmutableMap.of(), configParams, PERSISTENT, node2Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node2ID); @@ -1270,9 +1256,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { configParams1.setHeartBeatInterval(new FiniteDuration(100, TimeUnit.MILLISECONDS)); configParams1.setElectionTimeoutFactor(1); configParams1.setPeerAddressResolver(peerAddressResolver); - TestActorRef node1Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef node1Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node1RaftActorRef = actorFactory.createTestActor( CollectingMockRaftActor.props(node1ID, ImmutableMap.of(), configParams1, PERSISTENT, node1Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node1ID); @@ -1281,9 +1266,8 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { DefaultConfigParamsImpl configParams2 = new DefaultConfigParamsImpl(); configParams2.setElectionTimeoutFactor(1000000); configParams2.setPeerAddressResolver(peerAddressResolver); - TestActorRef node2Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef node2Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node2RaftActorRef = actorFactory.createTestActor( CollectingMockRaftActor.props(node2ID, ImmutableMap.of(), configParams2, PERSISTENT, node2Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node2ID); @@ -1337,17 +1321,15 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { new MockRaftActorContext.MockPayload("2"))); InMemoryJournal.addEntry(node2ID, 4, new ApplyJournalEntries(1)); - TestActorRef node1Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef node1Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node1RaftActorRef = actorFactory.createTestActor( CollectingMockRaftActor.props(node1ID, ImmutableMap.of(), configParams, PERSISTENT, node1Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node1ID); final CollectingMockRaftActor node1RaftActor = node1RaftActorRef.underlyingActor(); - TestActorRef node2Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef node2Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node2RaftActorRef = actorFactory.createTestActor( CollectingMockRaftActor.props(node2ID, ImmutableMap.of(), configParams, PERSISTENT, node2Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node2ID); @@ -1402,17 +1384,15 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { InMemoryJournal.addEntry(node2ID, 1, new UpdateElectionTerm(1, "node1")); InMemoryJournal.addEntry(node2ID, 2, persistedServerConfigEntry); - TestActorRef node1Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef node1Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node1RaftActorRef = actorFactory.createTestActor( CollectingMockRaftActor.props(node1ID, ImmutableMap.of(), configParams, PERSISTENT, node1Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node1ID); final CollectingMockRaftActor node1RaftActor = node1RaftActorRef.underlyingActor(); - TestActorRef node2Collector = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId("collector")); + ActorRef node2Collector = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("collector")); TestActorRef node2RaftActorRef = actorFactory.createTestActor( CollectingMockRaftActor.props(node2ID, ImmutableMap.of(), configParams, PERSISTENT, node2Collector).withDispatcher(Dispatchers.DefaultDispatcherId()), node2ID); @@ -1471,14 +1451,13 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { return new ServerInfo(id, false); } - private TestActorRef newLeaderCollectorActor(MockLeaderRaftActor leaderRaftActor) { + private ActorRef newLeaderCollectorActor(MockLeaderRaftActor leaderRaftActor) { return newCollectorActor(leaderRaftActor, LEADER_ID); } - private TestActorRef newCollectorActor(AbstractMockRaftActor raftActor, String id) { - TestActorRef collectorActor = actorFactory.createTestActor( - MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), - actorFactory.generateActorId(id + "Collector")); + private ActorRef newCollectorActor(AbstractMockRaftActor raftActor, String id) { + ActorRef collectorActor = actorFactory.createTestActor( + MessageCollectorActor.props(), actorFactory.generateActorId(id + "Collector")); raftActor.setCollectorActor(collectorActor); return collectorActor; } @@ -1503,11 +1482,11 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { } abstract static class AbstractMockRaftActor extends MockRaftActor { - private volatile TestActorRef collectorActor; + private volatile ActorRef collectorActor; private volatile Class dropMessageOfType; AbstractMockRaftActor(String id, Map peerAddresses, Optional config, - boolean persistent, TestActorRef collectorActor) { + boolean persistent, ActorRef collectorActor) { super(builder().id(id).peerAddresses(peerAddresses).config(config.get()) .persistent(Optional.of(persistent))); this.collectorActor = collectorActor; @@ -1517,7 +1496,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { this.dropMessageOfType = dropMessageOfType; } - void setCollectorActor(TestActorRef collectorActor) { + void setCollectorActor(ActorRef collectorActor) { this.collectorActor = collectorActor; } @@ -1536,7 +1515,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { public static class CollectingMockRaftActor extends AbstractMockRaftActor { CollectingMockRaftActor(String id, Map peerAddresses, Optional config, - boolean persistent, TestActorRef collectorActor) { + boolean persistent, ActorRef collectorActor) { super(id, peerAddresses, config, persistent, collectorActor); snapshotCohortDelegate = new RaftActorSnapshotCohort() { @Override @@ -1558,7 +1537,7 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { } public static Props props(final String id, final Map peerAddresses, - ConfigParams config, boolean persistent, TestActorRef collectorActor) { + ConfigParams config, boolean persistent, ActorRef collectorActor) { return Props.create(CollectingMockRaftActor.class, id, peerAddresses, Optional.of(config), persistent, collectorActor); @@ -1611,13 +1590,13 @@ public class RaftActorServerConfigurationSupportTest extends AbstractActorTest { } public static class MockNewFollowerRaftActor extends AbstractMockRaftActor { - public MockNewFollowerRaftActor(ConfigParams config, TestActorRef collectorActor) { + public MockNewFollowerRaftActor(ConfigParams config, ActorRef collectorActor) { super(NEW_SERVER_ID, Maps.newHashMap(), Optional.of(config), NO_PERSISTENCE, collectorActor); setPersistence(false); } - static Props props(ConfigParams config, TestActorRef collectorActor) { + static Props props(ConfigParams config, ActorRef collectorActor) { return Props.create(MockNewFollowerRaftActor.class, config, collectorActor); } } diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTest.java index a810fe0a42..b8be07a7b6 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/RaftActorTest.java @@ -27,7 +27,6 @@ import static org.mockito.Mockito.verify; import akka.actor.ActorRef; import akka.actor.PoisonPill; -import akka.actor.Props; import akka.actor.Status.Failure; import akka.actor.Terminated; import akka.dispatch.Dispatchers; @@ -420,8 +419,7 @@ public class RaftActorTest extends AbstractActorTest { @Test public void testRaftRoleChangeNotifierWhenRaftActorHasNoPeers() throws Exception { - TestActorRef notifierActor = factory.createTestActor( - Props.create(MessageCollectorActor.class)); + ActorRef notifierActor = factory.createActor(MessageCollectorActor.props()); MessageCollectorActor.waitUntilReady(notifierActor); DefaultConfigParamsImpl config = new DefaultConfigParamsImpl(); @@ -463,7 +461,7 @@ public class RaftActorTest extends AbstractActorTest { assertEquals(raftRoleChanged.getMemberId(), leaderStateChange.getLeaderId()); assertEquals(MockRaftActor.PAYLOAD_VERSION, leaderStateChange.getLeaderPayloadVersion()); - notifierActor.underlyingActor().clear(); + MessageCollectorActor.clearMessages(notifierActor); MockRaftActor raftActor = raftActorRef.underlyingActor(); final String newLeaderId = "new-leader"; @@ -487,7 +485,7 @@ public class RaftActorTest extends AbstractActorTest { assertEquals(RaftState.Leader.name(), raftRoleChanged.getOldRole()); assertEquals(RaftState.Follower.name(), raftRoleChanged.getNewRole()); - notifierActor.underlyingActor().clear(); + MessageCollectorActor.clearMessages(notifierActor); raftActor.handleCommand("any"); @@ -496,7 +494,7 @@ public class RaftActorTest extends AbstractActorTest { assertEquals(newLeaderId, leaderStateChange.getLeaderId()); assertEquals(newLeaderVersion, leaderStateChange.getLeaderPayloadVersion()); - notifierActor.underlyingActor().clear(); + MessageCollectorActor.clearMessages(notifierActor); raftActor.handleCommand("any"); @@ -507,7 +505,7 @@ public class RaftActorTest extends AbstractActorTest { @Test public void testRaftRoleChangeNotifierWhenRaftActorHasPeers() throws Exception { - ActorRef notifierActor = factory.createActor(Props.create(MessageCollectorActor.class)); + ActorRef notifierActor = factory.createActor(MessageCollectorActor.props()); MessageCollectorActor.waitUntilReady(notifierActor); DefaultConfigParamsImpl config = new DefaultConfigParamsImpl(); @@ -552,8 +550,7 @@ public class RaftActorTest extends AbstractActorTest { final String persistenceId = factory.generateActorId("leader-"); final String follower1Id = factory.generateActorId("follower-"); - ActorRef followerActor1 = - factory.createActor(Props.create(MessageCollectorActor.class)); + ActorRef followerActor1 = factory.createActor(MessageCollectorActor.props()); DefaultConfigParamsImpl config = new DefaultConfigParamsImpl(); config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS)); @@ -642,9 +639,7 @@ public class RaftActorTest extends AbstractActorTest { final String persistenceId = factory.generateActorId("follower-"); final String leaderId = factory.generateActorId("leader-"); - - ActorRef leaderActor1 = - factory.createActor(Props.create(MessageCollectorActor.class)); + ActorRef leaderActor1 = factory.createActor(MessageCollectorActor.props()); DefaultConfigParamsImpl config = new DefaultConfigParamsImpl(); config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS)); @@ -734,8 +729,8 @@ public class RaftActorTest extends AbstractActorTest { final String follower1Id = factory.generateActorId("follower-"); final String follower2Id = factory.generateActorId("follower-"); - final ActorRef followerActor1 = factory.createActor(Props.create(MessageCollectorActor.class), follower1Id); - final ActorRef followerActor2 = factory.createActor(Props.create(MessageCollectorActor.class), follower2Id); + final ActorRef followerActor1 = factory.createActor(MessageCollectorActor.props(), follower1Id); + final ActorRef followerActor2 = factory.createActor(MessageCollectorActor.props(), follower2Id); DefaultConfigParamsImpl config = new DefaultConfigParamsImpl(); config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS)); @@ -1242,8 +1237,7 @@ public class RaftActorTest extends AbstractActorTest { public void testLeaderTransitioning() throws Exception { TEST_LOG.info("testLeaderTransitioning starting"); - TestActorRef notifierActor = factory.createTestActor( - Props.create(MessageCollectorActor.class)); + ActorRef notifierActor = factory.createActor(MessageCollectorActor.props()); DefaultConfigParamsImpl config = new DefaultConfigParamsImpl(); config.setCustomRaftPolicyImplementationClass(DisableElectionsRaftPolicy.class.getName()); @@ -1280,7 +1274,7 @@ public class RaftActorTest extends AbstractActorTest { final String leaderId = factory.generateActorId("leader-"); final String followerId = factory.generateActorId("follower-"); - final ActorRef followerActor = factory.createActor(Props.create(MessageCollectorActor.class)); + final ActorRef followerActor = factory.createActor(MessageCollectorActor.props()); DefaultConfigParamsImpl config = new DefaultConfigParamsImpl(); config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS)); @@ -1325,7 +1319,7 @@ public class RaftActorTest extends AbstractActorTest { final String leaderId = factory.generateActorId("leader-"); final String followerId = factory.generateActorId("follower-"); - final ActorRef followerActor = factory.createActor(Props.create(MessageCollectorActor.class)); + final ActorRef followerActor = factory.createActor(MessageCollectorActor.props()); DefaultConfigParamsImpl config = new DefaultConfigParamsImpl(); config.setHeartBeatInterval(new FiniteDuration(1, TimeUnit.DAYS)); diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/SnapshotManagerTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/SnapshotManagerTest.java index fdfaa046fd..ccbdb5531f 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/SnapshotManagerTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/SnapshotManagerTest.java @@ -26,7 +26,6 @@ import static org.mockito.Mockito.verify; import akka.actor.ActorRef; import akka.persistence.SnapshotSelectionCriteria; -import akka.testkit.TestActorRef; import java.io.OutputStream; import java.util.Arrays; import java.util.Optional; @@ -77,7 +76,7 @@ public class SnapshotManagerTest extends AbstractActorTest { private TestActorFactory factory; - private TestActorRef actorRef; + private ActorRef actorRef; @Before public void setUp() { @@ -103,7 +102,7 @@ public class SnapshotManagerTest extends AbstractActorTest { snapshotManager = new SnapshotManager(mockRaftActorContext, LoggerFactory.getLogger(this.getClass())); factory = new TestActorFactory(getSystem()); - actorRef = factory.createTestActor(MessageCollectorActor.props(), factory.generateActorId("test-")); + actorRef = factory.createActor(MessageCollectorActor.props(), factory.generateActorId("test-")); doReturn(actorRef).when(mockRaftActorContext).getActor(); snapshotManager.setCreateSnapshotConsumer(mockProcedure); @@ -146,7 +145,7 @@ public class SnapshotManagerTest extends AbstractActorTest { // assertEquals(-1L, captureSnapshot.getReplicatedToAllIndex()); assertEquals(-1L, captureSnapshot.getReplicatedToAllTerm()); - actorRef.underlyingActor().clear(); + MessageCollectorActor.clearMessages(actorRef); } @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -177,8 +176,7 @@ public class SnapshotManagerTest extends AbstractActorTest { assertEquals(-1L, captureSnapshot.getReplicatedToAllIndex()); assertEquals(-1L, captureSnapshot.getReplicatedToAllTerm()); - actorRef.underlyingActor().clear(); - + MessageCollectorActor.clearMessages(actorRef); } @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -207,8 +205,7 @@ public class SnapshotManagerTest extends AbstractActorTest { // assertEquals(-1L, captureSnapshot.getReplicatedToAllIndex()); assertEquals(-1L, captureSnapshot.getReplicatedToAllTerm()); - actorRef.underlyingActor().clear(); - + MessageCollectorActor.clearMessages(actorRef); } @Test diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeaderElectionScenarioTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeaderElectionScenarioTest.java index 1d4fde1a44..27fc7c0974 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeaderElectionScenarioTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeaderElectionScenarioTest.java @@ -151,12 +151,11 @@ public class AbstractLeaderElectionScenarioTest { dropMessagesToBehavior.clear(); } - @Override public void clear() { behaviorStateChangeLatch = null; clearDropMessagesToBehavior(); messagesReceivedLatches.clear(); - super.clear(); + clearMessages(getSelf()); } void forwardCapturedMessageToBehavior(final Class msgClass, final ActorRef sender) { diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehaviorTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehaviorTest.java index 94563da318..cb84ea9786 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehaviorTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractRaftActorBehaviorTest.java @@ -13,8 +13,6 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import akka.actor.ActorRef; -import akka.actor.Props; -import akka.testkit.TestActorRef; import com.google.protobuf.ByteString; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -49,8 +47,8 @@ public abstract class AbstractRaftActorBehaviorTest protected final TestActorFactory actorFactory = new TestActorFactory(getSystem()); - private final TestActorRef behaviorActor = actorFactory.createTestActor( - Props.create(MessageCollectorActor.class), actorFactory.generateActorId("behavior")); + private final ActorRef behaviorActor = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("behavior")); RaftActorBehavior behavior; @@ -156,7 +154,7 @@ public abstract class AbstractRaftActorBehaviorTest handleAppendEntriesAddSameEntryToLogReply(behaviorActor); } - protected void handleAppendEntriesAddSameEntryToLogReply(final TestActorRef replyActor) { + protected void handleAppendEntriesAddSameEntryToLogReply(final ActorRef replyActor) { AppendEntriesReply reply = MessageCollectorActor.getFirstMatching(replyActor, AppendEntriesReply.class); Assert.assertNull("Expected no AppendEntriesReply", reply); } diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/CandidateTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/CandidateTest.java index e39a674426..6dd5336716 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/CandidateTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/CandidateTest.java @@ -12,7 +12,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import akka.actor.ActorRef; -import akka.actor.Props; +import akka.dispatch.Dispatchers; import akka.testkit.TestActorRef; import com.google.common.base.Stopwatch; import java.util.ArrayList; @@ -49,9 +49,10 @@ public class CandidateTest extends AbstractRaftActorBehaviorTest { static final Logger LOG = LoggerFactory.getLogger(CandidateTest.class); private final TestActorRef candidateActor = actorFactory.createTestActor( - Props.create(MessageCollectorActor.class), actorFactory.generateActorId("candidate")); + MessageCollectorActor.props().withDispatcher(Dispatchers.DefaultDispatcherId()), + actorFactory.generateActorId("candidate")); - private TestActorRef[] peerActors; + private ActorRef[] peerActors; private RaftActorBehavior candidate; @@ -352,12 +353,11 @@ public class CandidateTest extends AbstractRaftActorBehaviorTest { return new MockRaftActorContext("candidate", getSystem(), candidateActor); } - @SuppressWarnings("unchecked") private Map setupPeers(final int count) { Map peerMap = new HashMap<>(); - peerActors = new TestActorRef[count]; + peerActors = new ActorRef[count]; for (int i = 0; i < count; i++) { - peerActors[i] = actorFactory.createTestActor(Props.create(MessageCollectorActor.class), + peerActors[i] = actorFactory.createActor(MessageCollectorActor.props(), actorFactory.generateActorId("peer")); peerMap.put("peer" + (i + 1), peerActors[i].path().toString()); } diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/FollowerTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/FollowerTest.java index 3e6c7590c0..ab8218808f 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/FollowerTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/FollowerTest.java @@ -20,7 +20,6 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import akka.actor.ActorRef; -import akka.actor.Props; import akka.dispatch.Dispatchers; import akka.testkit.JavaTestKit; import akka.testkit.TestActorRef; @@ -78,11 +77,11 @@ import scala.concurrent.duration.FiniteDuration; public class FollowerTest extends AbstractRaftActorBehaviorTest { - private final TestActorRef followerActor = actorFactory.createTestActor( - Props.create(MessageCollectorActor.class), actorFactory.generateActorId("follower")); + private final ActorRef followerActor = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("follower")); - private final TestActorRef leaderActor = actorFactory.createTestActor( - Props.create(MessageCollectorActor.class), actorFactory.generateActorId("leader")); + private final ActorRef leaderActor = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("leader")); private Follower follower; @@ -356,7 +355,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { assertFalse(syncStatus.isInitialSyncDone()); // Clear all the messages - followerActor.underlyingActor().clear(); + MessageCollectorActor.clearMessages(followerActor); context.setLastApplied(101); context.setCommitIndex(101); @@ -372,7 +371,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { assertTrue(syncStatus.isInitialSyncDone()); - followerActor.underlyingActor().clear(); + MessageCollectorActor.clearMessages(followerActor); // Sending the same message again should not generate another message @@ -404,7 +403,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { assertFalse(syncStatus.isInitialSyncDone()); // Clear all the messages - followerActor.underlyingActor().clear(); + MessageCollectorActor.clearMessages(followerActor); context.setLastApplied(100); setLastLogEntry(context, 1, 100, @@ -444,7 +443,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { assertFalse(syncStatus.isInitialSyncDone()); // Clear all the messages - followerActor.underlyingActor().clear(); + MessageCollectorActor.clearMessages(followerActor); context.setLastApplied(101); context.setCommitIndex(101); @@ -463,7 +462,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { assertTrue(syncStatus.isInitialSyncDone()); // Clear all the messages - followerActor.underlyingActor().clear(); + MessageCollectorActor.clearMessages(followerActor); context.setLastApplied(100); setLastLogEntry(context, 1, 100, @@ -749,7 +748,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { entries = Arrays.asList(newReplicatedLogEntry(1, 1, "one"), newReplicatedLogEntry(1, 2, "two")); - leaderActor.underlyingActor().clear(); + MessageCollectorActor.clearMessages(leaderActor); follower.handleMessage(leaderActor, new AppendEntries(1, "leader", 0, 1, entries, 2, -1, (short)0)); assertEquals("Next index", 3, log.last().getIndex() + 1); @@ -977,7 +976,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { assertFalse(syncStatus.isInitialSyncDone()); // Clear all the messages - followerActor.underlyingActor().clear(); + MessageCollectorActor.clearMessages(followerActor); context.setLastApplied(101); context.setCommitIndex(101); @@ -1378,7 +1377,7 @@ public class FollowerTest extends AbstractRaftActorBehaviorTest { } @Override - protected void handleAppendEntriesAddSameEntryToLogReply(final TestActorRef replyActor) { + protected void handleAppendEntriesAddSameEntryToLogReply(final ActorRef replyActor) { AppendEntriesReply reply = MessageCollectorActor.expectFirstMatching(replyActor, AppendEntriesReply.class); assertEquals("isSuccess", true, reply.isSuccess()); } diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/IsolatedLeaderTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/IsolatedLeaderTest.java index dae7c6c0d2..283826af3b 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/IsolatedLeaderTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/IsolatedLeaderTest.java @@ -10,8 +10,6 @@ package org.opendaylight.controller.cluster.raft.behaviors; import static org.junit.Assert.assertEquals; import akka.actor.ActorRef; -import akka.actor.Props; -import akka.testkit.TestActorRef; import java.util.HashMap; import java.util.Map; import org.junit.After; @@ -25,11 +23,11 @@ import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor; public class IsolatedLeaderTest extends AbstractLeaderTest { - private final TestActorRef leaderActor = actorFactory.createTestActor( - Props.create(MessageCollectorActor.class), actorFactory.generateActorId("leader")); + private final ActorRef leaderActor = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("leader")); - private final TestActorRef senderActor = actorFactory.createTestActor( - Props.create(MessageCollectorActor.class), actorFactory.generateActorId("sender")); + private final ActorRef senderActor = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("sender")); private AbstractLeader isolatedLeader; diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java index ae58652b20..00a2fcd9f0 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java @@ -2029,8 +2029,8 @@ public class LeaderTest extends AbstractLeaderTest { leaderActorContext.setLastApplied(-1); String nonVotingFollowerId = "nonvoting-follower"; - TestActorRef nonVotingFollowerActor = actorFactory.createTestActor( - Props.create(MessageCollectorActor.class), actorFactory.generateActorId(nonVotingFollowerId)); + ActorRef nonVotingFollowerActor = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId(nonVotingFollowerId)); leaderActorContext.addToPeers(nonVotingFollowerId, nonVotingFollowerActor.path().toString(), VotingState.NON_VOTING); diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/SyncStatusTrackerTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/SyncStatusTrackerTest.java index 271250c16c..b4f4c5d613 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/SyncStatusTrackerTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/SyncStatusTrackerTest.java @@ -15,8 +15,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import akka.actor.Props; -import akka.testkit.TestActorRef; +import akka.actor.ActorRef; import org.junit.After; import org.junit.Test; import org.opendaylight.controller.cluster.raft.AbstractActorTest; @@ -27,8 +26,8 @@ import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor; public class SyncStatusTrackerTest extends AbstractActorTest { protected final TestActorFactory actorFactory = new TestActorFactory(getSystem()); - private final TestActorRef listener = actorFactory.createTestActor( - Props.create(MessageCollectorActor.class), actorFactory.generateActorId("listener")); + private final ActorRef listener = actorFactory.createActor( + MessageCollectorActor.props(), actorFactory.generateActorId("listener")); @After public void tearDown() { diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/ForwardMessageToBehaviorActor.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/ForwardMessageToBehaviorActor.java index 6c6f1905e4..0bd7d5c67d 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/ForwardMessageToBehaviorActor.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/ForwardMessageToBehaviorActor.java @@ -49,9 +49,8 @@ public class ForwardMessageToBehaviorActor extends MessageCollectorActor { return behaviorChanges; } - @Override public void clear() { - super.clear(); + clearMessages(getSelf()); behaviorChanges.clear(); } } diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/MessageCollectorActor.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/MessageCollectorActor.java index 32077a2719..d234913944 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/MessageCollectorActor.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/utils/MessageCollectorActor.java @@ -11,6 +11,7 @@ package org.opendaylight.controller.cluster.raft.utils; import akka.actor.ActorRef; import akka.actor.Props; import akka.actor.UntypedActor; +import akka.dispatch.ControlMessage; import akka.pattern.Patterns; import akka.util.Timeout; import com.google.common.base.Predicate; @@ -32,7 +33,13 @@ import scala.concurrent.duration.FiniteDuration; public class MessageCollectorActor extends UntypedActor { private static final String ARE_YOU_READY = "ARE_YOU_READY"; public static final String GET_ALL_MESSAGES = "messages"; - private static final String CLEAR_MESSAGES = "clear-messages"; + + private static final Object CLEAR_MESSAGES = new ControlMessage() { + @Override + public String toString() { + return "clear-messages"; + } + }; private final List messages = new ArrayList<>(); @@ -42,18 +49,14 @@ public class MessageCollectorActor extends UntypedActor { } else if (GET_ALL_MESSAGES.equals(message)) { getSender().tell(new ArrayList<>(messages), getSelf()); } else if (CLEAR_MESSAGES.equals(message)) { - clear(); + messages.clear(); } else if (message != null) { messages.add(message); } } - public void clear() { - messages.clear(); - } - @SuppressWarnings({"unchecked", "checkstyle:illegalCatch"}) - private static List getAllMessages(final ActorRef actor) { + public static List getAllMessages(final ActorRef actor) { FiniteDuration operationDuration = Duration.create(5, TimeUnit.SECONDS); Timeout operationTimeout = new Timeout(operationDuration); Future future = Patterns.ask(actor, GET_ALL_MESSAGES, operationTimeout); @@ -144,7 +147,8 @@ public class MessageCollectorActor extends UntypedActor { Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS); } - throw new AssertionError("Did not receive message of type " + clazz, lastEx); + throw new AssertionError(actor + ": Did not receive message of type " + clazz + ", Actual received was " + + getAllMessages(actor), lastEx); } @SuppressWarnings("checkstyle:IllegalCatch") diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardManagerTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardManagerTest.java index 8152c9e6e2..f6f45b0b2f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardManagerTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardManagerTest.java @@ -14,7 +14,6 @@ import static org.mockito.MockitoAnnotations.initMocks; import akka.actor.ActorRef; import akka.actor.PoisonPill; import akka.actor.Props; -import akka.testkit.TestActorRef; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.junit.After; @@ -34,7 +33,7 @@ public class AbstractShardManagerTest extends AbstractClusterRefActorTest { protected static final MemberName MEMBER_1 = MemberName.forName("member-1"); protected static int ID_COUNTER = 1; - protected static TestActorRef mockShardActor; + protected static ActorRef mockShardActor; protected static ShardIdentifier mockShardName; protected final String shardMrgIDSuffix = "config" + ID_COUNTER++; @@ -68,11 +67,10 @@ public class AbstractShardManagerTest extends AbstractClusterRefActorTest { if (mockShardActor == null) { mockShardName = ShardIdentifier.create(Shard.DEFAULT_NAME, MEMBER_1, "config"); - mockShardActor = TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class), - mockShardName.toString()); + mockShardActor = getSystem().actorOf(MessageCollectorActor.props(), mockShardName.toString()); } - mockShardActor.underlyingActor().clear(); + MessageCollectorActor.clearMessages(mockShardActor); } @After diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerProxyTest.java index d5416a0d5b..7b679dac21 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerProxyTest.java @@ -75,8 +75,7 @@ public class DataChangeListenerProxyTest extends AbstractActorTest { @Test public void testOnDataChanged() throws Exception { - final Props props = Props.create(MessageCollectorActor.class); - final ActorRef actorRef = getSystem().actorOf(props); + final ActorRef actorRef = getSystem().actorOf(MessageCollectorActor.props()); DataChangeListenerProxy dataChangeListenerProxy = new DataChangeListenerProxy( getSystem().actorSelection(actorRef.path())); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ForwardingDataTreeChangeListenerTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ForwardingDataTreeChangeListenerTest.java index 1005c2a8b8..41458f86fd 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ForwardingDataTreeChangeListenerTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ForwardingDataTreeChangeListenerTest.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorRef; -import akka.actor.Props; import java.util.Arrays; import java.util.Collection; import org.junit.Assert; @@ -22,8 +21,7 @@ public class ForwardingDataTreeChangeListenerTest extends AbstractActorTest { @Test public void testOnDataChanged() throws Exception { - final Props props = Props.create(MessageCollectorActor.class); - final ActorRef actorRef = getSystem().actorOf(props); + final ActorRef actorRef = getSystem().actorOf(MessageCollectorActor.props()); ForwardingDataTreeChangeListener forwardingListener = new ForwardingDataTreeChangeListener( getSystem().actorSelection(actorRef.path())); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/RoleChangeNotifierTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/RoleChangeNotifierTest.java index 13c42f919e..8e391cbf72 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/RoleChangeNotifierTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/RoleChangeNotifierTest.java @@ -13,7 +13,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import akka.actor.ActorRef; -import akka.actor.Props; import akka.testkit.JavaTestKit; import akka.testkit.TestActorRef; import org.junit.Test; @@ -33,7 +32,7 @@ public class RoleChangeNotifierTest extends AbstractActorTest { new JavaTestKit(getSystem()) { { String memberId = "testHandleRegisterRoleChangeListener"; - ActorRef listenerActor = getSystem().actorOf(Props.create(MessageCollectorActor.class)); + ActorRef listenerActor = getSystem().actorOf(MessageCollectorActor.props()); TestActorRef notifierTestActorRef = TestActorRef.create(getSystem(), RoleChangeNotifier.getProps(memberId), memberId); @@ -56,7 +55,7 @@ public class RoleChangeNotifierTest extends AbstractActorTest { new JavaTestKit(getSystem()) { { String memberId = "testHandleRegisterRoleChangeListenerWithNotificationSet"; - ActorRef listenerActor = getSystem().actorOf(Props.create(MessageCollectorActor.class)); + ActorRef listenerActor = getSystem().actorOf(MessageCollectorActor.props()); ActorRef shardActor = getTestActor(); TestActorRef notifierTestActorRef = TestActorRef.create(getSystem(), diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java index 54183ae0ff..5869271fb8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java @@ -2076,8 +2076,7 @@ public class ShardTest extends AbstractShardTest { waitUntilLeader(shard); - final TestActorRef listener = - TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class)); + final ActorRef listener = getSystem().actorOf(MessageCollectorActor.props()); shard.tell(new RegisterRoleChangeListener(), listener); @@ -2324,7 +2323,8 @@ public class ShardTest extends AbstractShardTest { @Test public void testServerRemoved() throws Exception { - final TestActorRef parent = actorFactory.createTestActor(MessageCollectorActor.props()); + final TestActorRef parent = actorFactory.createTestActor(MessageCollectorActor.props() + .withDispatcher(Dispatchers.DefaultDispatcherId())); final ActorRef shard = parent.underlyingActor().context().actorOf( newShardBuilder().props().withDispatcher(Dispatchers.DefaultDispatcherId()), diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShardTest.java index 276f11f936..ca104f1ecf 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShardTest.java @@ -257,7 +257,7 @@ public class EntityOwnershipShardTest extends AbstractEntityOwnershipTest { ShardIdentifier localId = newShardId(LOCAL_MEMBER_NAME); TestActorRef leader = actorFactory.createTestActor(TestEntityOwnershipShard.props( newShardBuilder(leaderId, peerMap(localId.toString()), PEER_MEMBER_1_NAME), - actorFactory.createTestActor(MessageCollectorActor.props())), leaderId.toString()); + actorFactory.createActor(MessageCollectorActor.props())), leaderId.toString()); final TestEntityOwnershipShard leaderShard = leader.underlyingActor(); TestActorRef local = actorFactory.createTestActor(TestEntityOwnershipShard.props( @@ -871,7 +871,7 @@ public class EntityOwnershipShardTest extends AbstractEntityOwnershipTest { TestActorRef peer1 = actorFactory.createTestActor(TestEntityOwnershipShard.props( newShardBuilder(peerId1, peerMap(leaderId.toString(), peerId2.toString()), PEER_MEMBER_1_NAME), - actorFactory.createTestActor(MessageCollectorActor.props())), peerId1.toString()); + actorFactory.createActor(MessageCollectorActor.props())), peerId1.toString()); peer1.underlyingActor().startDroppingMessagesOfType(ElectionTimeout.class); TestActorRef peer2 = actorFactory.createTestActor(TestEntityOwnershipShard.props( @@ -1263,10 +1263,10 @@ public class EntityOwnershipShardTest extends AbstractEntityOwnershipTest { } private static class TestEntityOwnershipShard extends EntityOwnershipShard { - private final TestActorRef collectorActor; + private final ActorRef collectorActor; private final Map, Predicate> dropMessagesOfType = new ConcurrentHashMap<>(); - TestEntityOwnershipShard(final Builder builder, final TestActorRef collectorActor) { + TestEntityOwnershipShard(final Builder builder, final ActorRef collectorActor) { super(builder); this.collectorActor = collectorActor; } @@ -1296,7 +1296,7 @@ public class EntityOwnershipShardTest extends AbstractEntityOwnershipTest { dropMessagesOfType.remove(msgClass); } - TestActorRef collectorActor() { + ActorRef collectorActor() { return collectorActor; } @@ -1304,7 +1304,7 @@ public class EntityOwnershipShardTest extends AbstractEntityOwnershipTest { return props(builder, null); } - static Props props(final Builder builder, final TestActorRef collectorActor) { + static Props props(final Builder builder, final ActorRef collectorActor) { return Props.create(TestEntityOwnershipShard.class, builder, collectorActor) .withDispatcher(Dispatchers.DefaultDispatcherId()); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerTest.java index b3d6628375..a3cf9aaf65 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerTest.java @@ -141,10 +141,10 @@ public class ShardManagerTest extends AbstractShardManagerTest { private ActorRef newMockShardActor(final ActorSystem system, final String shardName, final String memberName) { String name = ShardIdentifier.create(shardName, MemberName.forName(memberName), "config").toString(); if (system == getSystem()) { - return actorFactory.createActor(Props.create(MessageCollectorActor.class), name); + return actorFactory.createActor(MessageCollectorActor.props(), name); } - return system.actorOf(Props.create(MessageCollectorActor.class), name); + return system.actorOf(MessageCollectorActor.props(), name); } private Props newShardMgrProps() { @@ -246,9 +246,9 @@ public class ShardManagerTest extends AbstractShardManagerTest { }; final ActorRef defaultShardActor = actorFactory.createActor( - Props.create(MessageCollectorActor.class), actorFactory.generateActorId("default")); + MessageCollectorActor.props(), actorFactory.generateActorId("default")); final ActorRef topologyShardActor = actorFactory.createActor( - Props.create(MessageCollectorActor.class), actorFactory.generateActorId("topology")); + MessageCollectorActor.props(), actorFactory.generateActorId("topology")); final Map> shardInfoMap = Collections.synchronizedMap( new HashMap>()); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java index 3c60fb7dee..960e0328d6 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java @@ -349,8 +349,7 @@ public class ActorContextTest extends AbstractActorTest { @Test public void testFindPrimaryShardAsyncRemotePrimaryFound() throws Exception { - TestActorRef shardManager = TestActorRef.create(getSystem(), - Props.create(MessageCollectorActor.class)); + ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props()); DatastoreContext dataStoreContext = DatastoreContext.newBuilder() .logicalStoreType(LogicalDatastoreType.CONFIGURATION) @@ -391,8 +390,7 @@ public class ActorContextTest extends AbstractActorTest { @Test public void testFindPrimaryShardAsyncLocalPrimaryFound() throws Exception { - TestActorRef shardManager = TestActorRef.create(getSystem(), - Props.create(MessageCollectorActor.class)); + ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props()); DatastoreContext dataStoreContext = DatastoreContext.newBuilder() .logicalStoreType(LogicalDatastoreType.CONFIGURATION) @@ -443,8 +441,7 @@ public class ActorContextTest extends AbstractActorTest { @SuppressWarnings("checkstyle:IllegalCatch") private static void testFindPrimaryExceptions(final Object expectedException) throws Exception { - TestActorRef shardManager = - TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class)); + ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props()); DatastoreContext dataStoreContext = DatastoreContext.newBuilder() .logicalStoreType(LogicalDatastoreType.CONFIGURATION) @@ -479,8 +476,8 @@ public class ActorContextTest extends AbstractActorTest { public void testBroadcast() { new JavaTestKit(getSystem()) { { - ActorRef shardActorRef1 = getSystem().actorOf(Props.create(MessageCollectorActor.class)); - ActorRef shardActorRef2 = getSystem().actorOf(Props.create(MessageCollectorActor.class)); + ActorRef shardActorRef1 = getSystem().actorOf(MessageCollectorActor.props()); + ActorRef shardActorRef2 = getSystem().actorOf(MessageCollectorActor.props()); TestActorRef shardManagerActorRef = TestActorRef.create(getSystem(), MockShardManager.props());