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%2FTestActorFactory.java;h=639436d026c04c5c96169b3fc330a120484896ba;hb=ddd479df27cfc49f353ceb66cd289694e891761a;hp=92b401581c3721bd8d978d1b0faf33f712c7d70d;hpb=e1eca73a5ae2ffae8dd78c6fe5281cd2f45d5ef3;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/TestActorFactory.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/TestActorFactory.java index 92b401581c..639436d026 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/TestActorFactory.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/TestActorFactory.java @@ -22,6 +22,7 @@ import akka.actor.ActorRef; import akka.actor.ActorSelection; import akka.actor.ActorSystem; import akka.actor.Identify; +import akka.actor.InvalidActorNameException; import akka.actor.PoisonPill; import akka.actor.Props; import akka.pattern.Patterns; @@ -71,7 +72,7 @@ public class TestActorFactory implements AutoCloseable { */ public ActorRef createActor(Props props) { ActorRef actorRef = system.actorOf(props); - return addActor(actorRef); + return addActor(actorRef, true); } /** @@ -83,7 +84,19 @@ public class TestActorFactory implements AutoCloseable { */ public ActorRef createActor(Props props, String actorId) { ActorRef actorRef = system.actorOf(props, actorId); - return addActor(actorRef); + return addActor(actorRef, true); + } + + /** + * Create a normal actor with the passed in name w/o verifying that the actor is ready. + * + * @param props the actor Props + * @param actorId name of actor + * @return the ActorRef + */ + public ActorRef createActorNoVerify(Props props, String actorId) { + ActorRef actorRef = system.actorOf(props, actorId); + return addActor(actorRef, false); } /** @@ -96,8 +109,18 @@ public class TestActorFactory implements AutoCloseable { */ @SuppressWarnings("unchecked") public TestActorRef createTestActor(Props props, String actorId) { - TestActorRef actorRef = TestActorRef.create(system, props, actorId); - return (TestActorRef) addActor(actorRef); + InvalidActorNameException lastError = null; + for (int i = 0; i < 10; i++) { + try { + TestActorRef actorRef = TestActorRef.create(system, props, actorId); + return (TestActorRef) addActor(actorRef, true); + } catch (InvalidActorNameException e) { + lastError = e; + Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); + } + } + + throw lastError; } /** @@ -110,12 +133,15 @@ public class TestActorFactory implements AutoCloseable { @SuppressWarnings("unchecked") public TestActorRef createTestActor(Props props) { TestActorRef actorRef = TestActorRef.create(system, props); - return (TestActorRef) addActor(actorRef); + return (TestActorRef) addActor(actorRef, true); } - private ActorRef addActor(T actorRef) { + private ActorRef addActor(T actorRef, boolean verify) { createdActors.add(actorRef); - verifyActorReady(actorRef); + if (verify) { + verifyActorReady(actorRef); + } + return actorRef; }