Converting away the usage of as[..]
This commit is contained in:
parent
1efed78de8
commit
4f925007ea
2 changed files with 14 additions and 12 deletions
|
|
@ -4,10 +4,11 @@ import java.util.concurrent.{ CountDownLatch, TimeUnit }
|
|||
|
||||
import org.junit.{ Before, After, Test }
|
||||
import org.scalatest.junit.JUnitSuite
|
||||
|
||||
import akka.util.duration._
|
||||
import akka.actor._
|
||||
import akka.actor.Actor._
|
||||
import akka.camel.TypedCamelTestSupport.{ SetExpectedMessageCount ⇒ SetExpectedTestMessageCount, _ }
|
||||
import akka.dispatch.Block
|
||||
|
||||
class TypedConsumerPublishRequestorTest extends JUnitSuite {
|
||||
import TypedConsumerPublishRequestorTest._
|
||||
|
|
@ -39,10 +40,10 @@ class TypedConsumerPublishRequestorTest extends JUnitSuite {
|
|||
@Test
|
||||
def shouldReceiveOneConsumerMethodRegisteredEvent = {
|
||||
Actor.registry.addListener(requestor)
|
||||
val latch = (publisher ? SetExpectedTestMessageCount(1)).as[CountDownLatch].get
|
||||
val latch = Block.sync((publisher ? SetExpectedTestMessageCount(1)).mapTo[CountDownLatch], 3 seconds)
|
||||
val obj = TypedActor.typedActorOf(classOf[SampleTypedSingleConsumer], classOf[SampleTypedSingleConsumerImpl], Props())
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
val event = (publisher ? GetRetainedMessage).as[ConsumerMethodRegistered].get
|
||||
val event = Block.sync((publisher ? GetRetainedMessage).mapTo[ConsumerMethodRegistered], 3 seconds)
|
||||
assert(event.endpointUri === "direct:foo")
|
||||
assert(event.typedActor === obj)
|
||||
assert(event.methodName === "foo")
|
||||
|
|
@ -50,21 +51,21 @@ class TypedConsumerPublishRequestorTest extends JUnitSuite {
|
|||
|
||||
@Test
|
||||
def shouldReceiveOneConsumerMethodUnregisteredEvent = {
|
||||
val latch = (publisher ? SetExpectedTestMessageCount(1)).as[CountDownLatch].get
|
||||
val latch = Block.sync((publisher ? SetExpectedTestMessageCount(1)).mapTo[CountDownLatch], 3 seconds)
|
||||
Actor.registry.addListener(requestor)
|
||||
|
||||
val obj = TypedActor.typedActorOf(classOf[SampleTypedSingleConsumer], classOf[SampleTypedSingleConsumerImpl], Props())
|
||||
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
|
||||
val ignorableEvent = (publisher ? GetRetainedMessage).as[ConsumerMethodRegistered].get
|
||||
val ignorableEvent = Block.sync((publisher ? GetRetainedMessage).mapTo[ConsumerMethodRegistered], 3 seconds)
|
||||
|
||||
val latch2 = (publisher ? SetExpectedTestMessageCount(1)).as[CountDownLatch].get
|
||||
val latch2 = Block.sync((publisher ? SetExpectedTestMessageCount(1)).mapTo[CountDownLatch], 3 seconds)
|
||||
TypedActor.stop(obj)
|
||||
|
||||
assert(latch2.await(5000, TimeUnit.MILLISECONDS))
|
||||
|
||||
val event = (publisher ? GetRetainedMessage).as[ConsumerMethodUnregistered].get
|
||||
val event = Block.sync((publisher ? GetRetainedMessage).mapTo[ConsumerMethodUnregistered], 3 seconds)
|
||||
|
||||
assert(event.endpointUri === "direct:foo")
|
||||
assert(event.typedActor === obj)
|
||||
|
|
@ -74,23 +75,23 @@ class TypedConsumerPublishRequestorTest extends JUnitSuite {
|
|||
@Test
|
||||
def shouldReceiveThreeConsumerMethodRegisteredEvents = {
|
||||
Actor.registry.addListener(requestor)
|
||||
val latch = (publisher ? SetExpectedTestMessageCount(3)).as[CountDownLatch].get
|
||||
val latch = Block.sync((publisher ? SetExpectedTestMessageCount(3)).mapTo[CountDownLatch], 3 seconds)
|
||||
val obj = TypedActor.typedActorOf(classOf[SampleTypedConsumer], classOf[SampleTypedConsumerImpl], Props())
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
val request = GetRetainedMessages(_.isInstanceOf[ConsumerMethodRegistered])
|
||||
val events = (publisher ? request).as[List[ConsumerMethodRegistered]].get
|
||||
val events = Block.sync((publisher ? request).mapTo[List[ConsumerMethodRegistered]], 3 seconds)
|
||||
assert(events.map(_.method.getName).sortWith(_ < _) === List("m2", "m3", "m4"))
|
||||
}
|
||||
|
||||
@Test
|
||||
def shouldReceiveThreeConsumerMethodUnregisteredEvents = {
|
||||
val obj = TypedActor.typedActorOf(classOf[SampleTypedConsumer], classOf[SampleTypedConsumerImpl], Props())
|
||||
val latch = (publisher ? SetExpectedTestMessageCount(3)).as[CountDownLatch].get
|
||||
val latch = Block.sync((publisher ? SetExpectedTestMessageCount(3)).mapTo[CountDownLatch], 3 seconds)
|
||||
Actor.registry.addListener(requestor)
|
||||
TypedActor.stop(obj)
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
val request = GetRetainedMessages(_.isInstanceOf[ConsumerMethodUnregistered])
|
||||
val events = (publisher ? request).as[List[ConsumerMethodUnregistered]].get
|
||||
val events = Block.sync((publisher ? request).mapTo[List[ConsumerMethodUnregistered]], 3 seconds)
|
||||
assert(events.map(_.method.getName).sortWith(_ < _) === List("m2", "m3", "m4"))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import akka.actor._
|
|||
import akka.stm.{ Ref, TransactionFactory }
|
||||
import akka.util.duration._
|
||||
import akka.testkit._
|
||||
import akka.dispatch.Block
|
||||
|
||||
object CoordinatedIncrement {
|
||||
case class Increment(friends: Seq[ActorRef])
|
||||
|
|
@ -72,7 +73,7 @@ class CoordinatedIncrementSpec extends AkkaSpec with BeforeAndAfterAll {
|
|||
counters(0) ! coordinated(Increment(counters.tail))
|
||||
coordinated.await
|
||||
for (counter ← counters) {
|
||||
(counter ? GetCount).as[Int].get must be === 1
|
||||
Block.sync((counter ? GetCount).mapTo[Int], timeout.duration) must be === 1
|
||||
}
|
||||
counters foreach (_.stop())
|
||||
failer.stop()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue