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=d2e6b02490edffce2690e954247667f7f3a3c284;hp=9fe8a13222f9e731ea8312e10a249dc79764e41a;hb=69228db0423bedd1d18b374c0f357762fa8021b2;hpb=ad98c16f6f690874866b6c218c178489e7f4b373 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 9fe8a13222..d2e6b02490 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 @@ -13,7 +13,6 @@ import akka.actor.DeadLetter; import akka.actor.Props; import akka.actor.UntypedActor; import akka.testkit.JavaTestKit; -import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; @@ -30,12 +29,7 @@ public class MeteredBoundedMailboxTest { @BeforeClass public static void setUp() throws Exception { - config = new CommonConfig.Builder<>("testsystem").withConfigReader(new AkkaConfigurationReader() { - @Override - public Config read() { - return ConfigFactory.load(); - } - }).build(); + config = new CommonConfig.Builder<>("testsystem").withConfigReader(() -> ConfigFactory.load()).build(); actorSystem = ActorSystem.create("testsystem", config.get()); } @@ -52,41 +46,42 @@ 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"); actorSystem.mailboxes().settings(); lock.lock(); - //queue capacity = 10 - //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++){ - pingPongActor.tell("ping", mockReceiver.getRef()); - } - - mockReceiver.expectMsgClass(TWENTY_SEC, DeadLetter.class); + try { + //queue capacity = 10 + //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++) { + pingPongActor.tell("ping", mockReceiver.getRef()); + } - lock.unlock(); + mockReceiver.expectMsgClass(twentySeconds, DeadLetter.class); + } finally { + 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(final ReentrantLock lock){ + private PingPongActor(final ReentrantLock lock) { this.lock = lock; } - public static Props props(final ReentrantLock lock){ + public static Props props(final ReentrantLock lock) { return Props.create(PingPongActor.class, lock); } @@ -102,4 +97,4 @@ public class MeteredBoundedMailboxTest { } } } -} \ No newline at end of file +}