X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fcommon%2Factor%2FMeteredBoundedMailboxTest.java;h=6142bf3ec55a4e2e6a884e6766960855baa0c671;hp=d33e79f533e0de4bbd36c821b9b1a28d10b57cc4;hb=4e696d9795fe7eef40369c05c340d137394126f3;hpb=4a8688c9d42c0be307383f0483c819cb7a78d26d diff --git a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java index d33e79f533..6142bf3ec5 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/test/java/org/opendaylight/controller/cluster/common/actor/MeteredBoundedMailboxTest.java @@ -12,15 +12,14 @@ import akka.actor.ActorSystem; import akka.actor.DeadLetter; import akka.actor.Props; import akka.actor.UntypedActor; -import akka.japi.Creator; import akka.testkit.JavaTestKit; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import scala.concurrent.duration.FiniteDuration; - +import com.typesafe.config.ConfigFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import scala.concurrent.duration.FiniteDuration; public class MeteredBoundedMailboxTest { @@ -28,16 +27,18 @@ public class MeteredBoundedMailboxTest { private static CommonConfig config; private final ReentrantLock lock = new ReentrantLock(); - @Before - public void setUp() throws Exception { - config = new CommonConfig.Builder<>("testsystem").build(); + @BeforeClass + public static void setUp() throws Exception { + config = new CommonConfig.Builder<>("testsystem").withConfigReader(() -> ConfigFactory.load()).build(); actorSystem = ActorSystem.create("testsystem", config.get()); } - @After - public void tearDown() throws Exception { - if (actorSystem != null) - actorSystem.shutdown(); + @AfterClass + public static void tearDown() throws Exception { + if (actorSystem != null) { + actorSystem.terminate(); + actorSystem = null; + } } @Test @@ -45,8 +46,7 @@ public class MeteredBoundedMailboxTest { final JavaTestKit mockReceiver = new JavaTestKit(actorSystem); actorSystem.eventStream().subscribe(mockReceiver.getRef(), DeadLetter.class); - - final FiniteDuration TWENTY_SEC = new FiniteDuration(20, TimeUnit.SECONDS); + final FiniteDuration twentySeconds = new FiniteDuration(20, TimeUnit.SECONDS); ActorRef pingPongActor = actorSystem.actorOf(PingPongActor.props(lock).withMailbox(config.getMailBoxName()), "pingpongactor"); @@ -57,46 +57,42 @@ public class MeteredBoundedMailboxTest { //need to send 12 messages; 1 message is dequeued and actor waits on lock, //2nd to 11th messages are put on the queue //12th message is sent to dead letter. - for (int i=0;i<12;i++){ + for (int i = 0; i < 12; i++) { pingPongActor.tell("ping", mockReceiver.getRef()); } - mockReceiver.expectMsgClass(TWENTY_SEC, DeadLetter.class); + mockReceiver.expectMsgClass(twentySeconds, DeadLetter.class); lock.unlock(); - Object[] eleven = mockReceiver.receiveN(11, TWENTY_SEC); + mockReceiver.receiveN(11, twentySeconds); } /** - * For testing + * For testing. */ - public static class PingPongActor extends UntypedActor{ + public static class PingPongActor extends UntypedActor { ReentrantLock lock; - private PingPongActor(ReentrantLock lock){ + private PingPongActor(final ReentrantLock lock) { this.lock = lock; } - public static Props props(final ReentrantLock lock){ - return Props.create(new Creator(){ - @Override - public PingPongActor create() throws Exception { - return new PingPongActor(lock); - } - }); + public static Props props(final ReentrantLock lock) { + return Props.create(PingPongActor.class, lock); } @Override - public void onReceive(Object message) throws Exception { + public void onReceive(final Object message) throws Exception { lock.lock(); try { - if ("ping".equals(message)) + if ("ping".equals(message)) { getSender().tell("pong", getSelf()); + } } finally { lock.unlock(); } } } -} \ No newline at end of file +}