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=ea38c16acc95fc5110165feba04d504f5434fbb0;hb=e9fc7e7ed2b13d274518d6a872ab67749ef4507a;hp=e3875843515c8fca320443196d31e89ff02b0008;hpb=7eeebc36f171b7a56f2ebfc3eefbb66b51efe675;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 e387584351..ea38c16acc 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 @@ -8,25 +8,18 @@ package org.opendaylight.controller.cluster.raft; -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - import akka.actor.Actor; import akka.actor.ActorIdentity; 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; -import akka.testkit.JavaTestKit; import akka.testkit.TestActorRef; +import akka.testkit.javadsl.TestKit; import akka.util.Timeout; import com.google.common.base.Stopwatch; import com.google.common.util.concurrent.Uninterruptibles; @@ -108,8 +101,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, true); + 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; } /** @@ -170,15 +173,15 @@ public class TestActorFactory implements AutoCloseable { return prefix + actorCount++; } - public void killActor(ActorRef actor, JavaTestKit kit) { + public void killActor(ActorRef actor, TestKit kit) { killActor(actor, kit, true); } - private void killActor(ActorRef actor, JavaTestKit kit, boolean remove) { + private void killActor(ActorRef actor, TestKit kit, boolean remove) { LOG.info("Killing actor {}", actor); kit.watch(actor); actor.tell(PoisonPill.getInstance(), ActorRef.noSender()); - kit.expectTerminated(JavaTestKit.duration("5 seconds"), actor); + kit.expectTerminated(kit.duration("5 seconds"), actor); if (remove) { createdActors.remove(actor); @@ -191,7 +194,7 @@ public class TestActorFactory implements AutoCloseable { @Override public void close() { - JavaTestKit kit = new JavaTestKit(system); + TestKit kit = new TestKit(system); for (ActorRef actor : createdActors) { killActor(actor, kit, false); }