Merge branch 'master' of github.com:jboner/akka
This commit is contained in:
commit
0e39f4562a
28 changed files with 123 additions and 78 deletions
|
|
@ -26,7 +26,7 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
|
|||
// count expectations in the next step (needed for testing only).
|
||||
service.consumerPublisher.start
|
||||
// set expectations on publish count
|
||||
val latch = service.consumerPublisher.!).get
|
||||
val latch = (service.consumerPublisher !! SetExpectedMessageCount(1)).as[CountDownLatch].get
|
||||
// start the CamelService
|
||||
service.load
|
||||
// await publication of first test consumer
|
||||
|
|
@ -43,7 +43,7 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
|
|||
scenario("access registered consumer actors via Camel direct-endpoints") {
|
||||
|
||||
given("two consumer actors registered before and after CamelService startup")
|
||||
val latch = service.consumerPublisher.!).get
|
||||
val latch = (service.consumerPublisher !! SetExpectedMessageCount(1)).as[CountDownLatch].get
|
||||
actorOf(new TestConsumer("direct:publish-test-2")).start
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
|
||||
|
|
@ -64,12 +64,12 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
|
|||
|
||||
given("a consumer actor that has been stopped")
|
||||
assert(CamelContextManager.context.hasEndpoint(endpointUri) eq null)
|
||||
var latch = service.consumerPublisher.!).get
|
||||
var latch = (service.consumerPublisher !! SetExpectedMessageCount(1)).as[CountDownLatch].get
|
||||
val consumer = actorOf(new TestConsumer(endpointUri)).start
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
assert(CamelContextManager.context.hasEndpoint(endpointUri) ne null)
|
||||
|
||||
latch = service.consumerPublisher.!).get
|
||||
latch = (service.consumerPublisher !! SetExpectedMessageCount(1)).as[CountDownLatch].get
|
||||
consumer.stop
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
// endpoint is still there but the route has been stopped
|
||||
|
|
@ -103,7 +103,7 @@ class CamelServiceFeatureTest extends FeatureSpec with BeforeAndAfterAll with Gi
|
|||
scenario("access active object methods via Camel direct-endpoints") {
|
||||
|
||||
given("an active object registered after CamelService startup")
|
||||
val latch = service.consumerPublisher.!).get
|
||||
val latch = (service.consumerPublisher !! SetExpectedMessageCount(3)).as[CountDownLatch].get
|
||||
ActiveObject.newInstance(classOf[PojoBase])
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class ProducerFeatureTest extends FeatureSpec with BeforeAndAfterAll with Before
|
|||
|
||||
when("a fail message is sent to the producer")
|
||||
val message = Message("fail", Map(Message.MessageExchangeId -> "123"))
|
||||
val result = producer.!
|
||||
val result = (producer !! message).as[Failure]
|
||||
|
||||
then("the expected failure message should be returned including a correlation identifier")
|
||||
val expectedFailureText = result.get.cause.getMessage
|
||||
|
|
@ -84,7 +84,7 @@ class ProducerFeatureTest extends FeatureSpec with BeforeAndAfterAll with Before
|
|||
|
||||
when("a fail message is sent to the producer")
|
||||
val message = Message("fail", Map(Message.MessageExchangeId -> "123"))
|
||||
val result = producer.!
|
||||
val result = (producer !! message).as[Failure]
|
||||
|
||||
then("the expected failure message should be returned including a correlation identifier")
|
||||
val expectedFailureText = result.get.cause.getMessage
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class PublishRequestorTest extends JUnitSuite {
|
|||
@Test def shouldReceiveConsumerMethodRegisteredEvent = {
|
||||
val obj = ActiveObject.newInstance(classOf[PojoSingle])
|
||||
val init = AspectInit(classOf[PojoSingle], null, None, 1000)
|
||||
val latch = publisher.!).get
|
||||
val latch = (publisher !! SetExpectedTestMessageCount(1)).as[CountDownLatch].get
|
||||
requestor ! AspectInitRegistered(obj, init)
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
val event = (publisher !! GetRetainedMessage).get.asInstanceOf[ConsumerMethodRegistered]
|
||||
|
|
@ -45,7 +45,7 @@ class PublishRequestorTest extends JUnitSuite {
|
|||
}
|
||||
|
||||
@Test def shouldReceiveConsumerRegisteredEvent = {
|
||||
val latch = publisher.!).get
|
||||
val latch = (publisher !! SetExpectedTestMessageCount(1)).as[CountDownLatch].get
|
||||
requestor ! ActorRegistered(consumer)
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
assert((publisher !! GetRetainedMessage) ===
|
||||
|
|
@ -53,7 +53,7 @@ class PublishRequestorTest extends JUnitSuite {
|
|||
}
|
||||
|
||||
@Test def shouldReceiveConsumerUnregisteredEvent = {
|
||||
val latch = publisher.!).get
|
||||
val latch = (publisher !! SetExpectedTestMessageCount(1)).as[CountDownLatch].get
|
||||
requestor ! ActorUnregistered(consumer)
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
assert((publisher !! GetRetainedMessage) ===
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class RemoteConsumerTest extends FeatureSpec with BeforeAndAfterAll with GivenWh
|
|||
val consumer = actorOf[RemoteConsumer].start
|
||||
|
||||
when("remote consumer publication is triggered")
|
||||
val latch = service.consumerPublisher.!).get
|
||||
val latch = (service.consumerPublisher !! SetExpectedMessageCount(1)).as[CountDownLatch].get
|
||||
consumer !! "init"
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class ActorComponentFeatureTest extends FeatureSpec with BeforeAndAfterAll with
|
|||
|
||||
scenario("one-way communication using actor id") {
|
||||
val actor = actorOf[Tester1].start
|
||||
val latch = actor.!).get
|
||||
val latch = (actor !! SetExpectedMessageCount(1)).as[CountDownLatch].get
|
||||
template.sendBody("actor:%s" format actor.id, "Martin")
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
val reply = (actor !! GetRetainedMessage).get.asInstanceOf[Message]
|
||||
|
|
@ -35,7 +35,7 @@ class ActorComponentFeatureTest extends FeatureSpec with BeforeAndAfterAll with
|
|||
|
||||
scenario("one-way communication using actor uuid") {
|
||||
val actor = actorOf[Tester1].start
|
||||
val latch = actor.!).get
|
||||
val latch = (actor !! SetExpectedMessageCount(1)).as[CountDownLatch].get
|
||||
template.sendBody("actor:uuid:%s" format actor.uuid, "Martin")
|
||||
assert(latch.await(5000, TimeUnit.MILLISECONDS))
|
||||
val reply = (actor !! GetRetainedMessage).get.asInstanceOf[Message]
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class ActorProducerTest extends JUnitSuite with BeforeAndAfterAll {
|
|||
|
||||
@Test def shouldSendMessageToActor = {
|
||||
val actor = actorOf[Tester1].start
|
||||
val latch = actor.!).get
|
||||
val latch = (actor !! SetExpectedMessageCount(1)).as[CountDownLatch].get
|
||||
val endpoint = mockEndpoint("actor:uuid:%s" format actor.uuid)
|
||||
val exchange = endpoint.createExchange(ExchangePattern.InOnly)
|
||||
exchange.getIn.setBody("Martin")
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package se.scalablesolutions.akka.actor
|
||||
|
||||
import Actor._
|
||||
import se.scalablesolutions.akka.config.FaultHandlingStrategy
|
||||
import se.scalablesolutions.akka.remote.protocol.RemoteProtocol.RemoteRequestProtocol
|
||||
import se.scalablesolutions.akka.remote.{RemoteProtocolBuilder, RemoteClient, RemoteRequestProtocolIdFactory}
|
||||
|
|
@ -548,7 +549,7 @@ private[akka] sealed class ActiveObjectAspect {
|
|||
actorRef ! Invocation(joinPoint, true, true, sender, senderFuture)
|
||||
null.asInstanceOf[AnyRef]
|
||||
} else {
|
||||
val result = actorRef !! (Invocation(joinPoint, false, isOneWay, sender, senderFuture), timeout)
|
||||
val result = (actorRef !! (Invocation(joinPoint, false, isOneWay, sender, senderFuture), timeout)).as[AnyRef]
|
||||
if (result.isDefined) result.get
|
||||
else throw new IllegalStateException("No result defined for invocation [" + joinPoint + "]")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ package se.scalablesolutions.akka.actor
|
|||
import se.scalablesolutions.akka.dispatch._
|
||||
import se.scalablesolutions.akka.config.Config._
|
||||
import se.scalablesolutions.akka.config.ScalaConfig._
|
||||
import se.scalablesolutions.akka.util.Logging
|
||||
import se.scalablesolutions.akka.serialization.Serializer
|
||||
import se.scalablesolutions.akka.util.Helpers.{ narrow, narrowSilently }
|
||||
import se.scalablesolutions.akka.util.Logging
|
||||
|
||||
import com.google.protobuf.Message
|
||||
|
||||
|
|
@ -279,8 +280,13 @@ object Actor extends Logging {
|
|||
case Spawn => body; self.stop
|
||||
}
|
||||
}).start ! Spawn
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Implicitly converts the given Option[Any] to a AnyOptionAsTypedOption which offers the method <code>as[T]</code>
|
||||
* to convert an Option[Any] to an Option[T].
|
||||
*/
|
||||
implicit def toAnyOptionAsTypedOption(anyOption: Option[Any]) = new AnyOptionAsTypedOption(anyOption)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -496,3 +502,18 @@ trait Actor extends Logging {
|
|||
case Kill => throw new ActorKilledException("Actor [" + toString + "] was killed by a Kill message")
|
||||
}
|
||||
}
|
||||
|
||||
private[actor] class AnyOptionAsTypedOption(anyOption: Option[Any]) {
|
||||
|
||||
/**
|
||||
* Convenience helper to cast the given Option of Any to an Option of the given type. Will throw a ClassCastException
|
||||
* if the actual type is not assignable from the given one.
|
||||
*/
|
||||
def as[T]: Option[T] = narrow[T](anyOption)
|
||||
|
||||
/**
|
||||
* Convenience helper to cast the given Option of Any to an Option of the given type. Will swallow a possible
|
||||
* ClassCastException and return None in that case.
|
||||
*/
|
||||
def asSilently[T: Manifest]: Option[T] = narrowSilently[T](anyOption)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -392,9 +392,9 @@ trait ActorRef extends TransactionManagement {
|
|||
* If you are sending messages using <code>!!</code> then you <b>have to</b> use <code>self.reply(..)</code>
|
||||
* to send a reply message to the original sender. If not then the sender will block until the timeout expires.
|
||||
*/
|
||||
def !(implicit sender: Option[ActorRef] = None): Option[T] = {
|
||||
def !!(message: Any, timeout: Long = this.timeout)(implicit sender: Option[ActorRef] = None): Option[Any] = {
|
||||
if (isRunning) {
|
||||
val future = postMessageToMailboxAndCreateFutureResultWithTimeout[T](message, timeout, sender, None)
|
||||
val future = postMessageToMailboxAndCreateFutureResultWithTimeout[Any](message, timeout, sender, None)
|
||||
val isActiveObject = message.isInstanceOf[Invocation]
|
||||
if (isActiveObject && message.asInstanceOf[Invocation].isVoid) {
|
||||
future.asInstanceOf[CompletableFuture[Option[_]]].completeWithResult(None)
|
||||
|
|
|
|||
|
|
@ -102,10 +102,10 @@ import se.scalablesolutions.akka.dispatch.CompletableFuture
|
|||
else {
|
||||
val out = actorOf(new Out(this)).start
|
||||
blockedReaders.offer(out)
|
||||
val result = out !! Get
|
||||
val result = (out !! Get).as[T]
|
||||
out ! Exit
|
||||
result.getOrElse(throw new DataFlowVariableException(
|
||||
"Timed out (after " + TIME_OUT + " milliseconds) while waiting for result"))
|
||||
if (result.isDefined) result.get
|
||||
else throw new DataFlowVariableException("Timed out (after " + TIME_OUT + " milliseconds) while waiting for result")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import java.util.concurrent.{ConcurrentHashMap, Executors}
|
|||
import java.util.{Map => JMap}
|
||||
|
||||
import se.scalablesolutions.akka.actor._
|
||||
import se.scalablesolutions.akka.actor.Actor._
|
||||
import se.scalablesolutions.akka.util._
|
||||
import se.scalablesolutions.akka.remote.protocol.RemoteProtocol._
|
||||
import se.scalablesolutions.akka.config.Config.config
|
||||
|
|
@ -369,8 +370,8 @@ class RemoteServerHandler(
|
|||
if (request.getIsOneWay) actorRef.!(message)(sender)
|
||||
else {
|
||||
try {
|
||||
val resultOrNone = actorRef.!!(message)(sender)
|
||||
val result: AnyRef = if (resultOrNone.isDefined) resultOrNone.get else null
|
||||
val resultOrNone = (actorRef.!!(message)(sender)).as[AnyRef]
|
||||
val result = if (resultOrNone.isDefined) resultOrNone.get else null
|
||||
log.debug("Returning result from actor invocation [%s]", result)
|
||||
val replyBuilder = RemoteReplyProtocol.newBuilder
|
||||
.setId(request.getId)
|
||||
|
|
|
|||
|
|
@ -37,5 +37,26 @@ object Helpers extends Logging {
|
|||
})
|
||||
sb.toString
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience helper to cast the given Option of Any to an Option of the given type. Will throw a ClassCastException
|
||||
* if the actual type is not assignable from the given one.
|
||||
*/
|
||||
def narrow[T](o: Option[Any]): Option[T] = {
|
||||
require(o != null, "Option to be narrowed must not be null!")
|
||||
o.asInstanceOf[Option[T]]
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience helper to cast the given Option of Any to an Option of the given type. Will swallow a possible
|
||||
* ClassCastException and return None in that case.
|
||||
*/
|
||||
def narrowSilently[T: Manifest](o: Option[Any]): Option[T] =
|
||||
try {
|
||||
narrow(o)
|
||||
} catch {
|
||||
case e: ClassCastException =>
|
||||
log.warning(e, "Cannot narrow %s to expected type %s!", o, implicitly[Manifest[T]].erasure.getName)
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ class ActorPatternsTest extends junit.framework.TestCase with Suite with MustMat
|
|||
}.start
|
||||
|
||||
val result = for {
|
||||
a <- (d.!)
|
||||
b <- (d.!)
|
||||
c <- (d.!)
|
||||
a <- (d !! (testMsg1,5000)).as[Int]
|
||||
b <- (d !! (testMsg2,5000)).as[Int]
|
||||
c <- (d !! (testMsg3,5000)).as[Int]
|
||||
} yield a + b + c
|
||||
|
||||
result.get must be(21)
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ class ExecutorBasedEventDrivenDispatcherActorSpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldSendReplySync = {
|
||||
val actor = actorOf[TestActor].start
|
||||
val result: String = (actor !! ("Hello", 10000)).get
|
||||
assert("World" === result)
|
||||
val result = (actor !! ("Hello", 10000)).as[String]
|
||||
assert("World" === result.get)
|
||||
actor.stop
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
stateful.start
|
||||
stateful ! SetMapStateOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init") // set init state
|
||||
stateful ! SuccessOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
val notifier: Option[CountDownLatch] = stateful !! GetNotifier
|
||||
val notifier = (stateful !! GetNotifier).as[CountDownLatch]
|
||||
assert(notifier.get.await(1, TimeUnit.SECONDS))
|
||||
assert("new state" === (stateful !! GetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess")).get)
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
failer.start
|
||||
stateful ! SetMapStateOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "init") // set init state
|
||||
stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
val notifier: Option[CountDownLatch] = stateful !! GetNotifier
|
||||
val notifier = (stateful !! GetNotifier).as[CountDownLatch]
|
||||
assert(notifier.get.await(1, TimeUnit.SECONDS))
|
||||
assert("init" === (stateful !! GetMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")).get) // check that state is == init state
|
||||
}
|
||||
|
|
@ -163,7 +163,7 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
stateful.start
|
||||
stateful ! SetVectorStateOneWay("init") // set init state
|
||||
stateful ! SuccessOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
val notifier: Option[CountDownLatch] = stateful !! GetNotifier
|
||||
val notifier = (stateful !! GetNotifier).as[CountDownLatch]
|
||||
assert(notifier.get.await(1, TimeUnit.SECONDS))
|
||||
assert(2 === (stateful !! GetVectorSize).get)
|
||||
}
|
||||
|
|
@ -186,7 +186,7 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
val failer = actorOf[InMemFailerActor]
|
||||
failer.start
|
||||
stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
val notifier: Option[CountDownLatch] = stateful !! GetNotifier
|
||||
val notifier = (stateful !! GetNotifier).as[CountDownLatch]
|
||||
assert(notifier.get.await(1, TimeUnit.SECONDS))
|
||||
assert(1 === (stateful !! GetVectorSize).get)
|
||||
}
|
||||
|
|
@ -211,7 +211,7 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
stateful.start
|
||||
stateful ! SetRefStateOneWay("init") // set init state
|
||||
stateful ! SuccessOneWay("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
val notifier: Option[CountDownLatch] = stateful !! GetNotifier
|
||||
val notifier = (stateful !! GetNotifier).as[CountDownLatch]
|
||||
assert(notifier.get.await(1, TimeUnit.SECONDS))
|
||||
assert("new state" === (stateful !! GetRefState).get)
|
||||
}
|
||||
|
|
@ -234,7 +234,7 @@ class InMemoryActorSpec extends JUnitSuite {
|
|||
val failer = actorOf[InMemFailerActor]
|
||||
failer.start
|
||||
stateful ! FailureOneWay("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
val notifier: Option[CountDownLatch] = stateful !! GetNotifier
|
||||
val notifier = (stateful !! GetNotifier).as[CountDownLatch]
|
||||
assert(notifier.get.await(1, TimeUnit.SECONDS))
|
||||
assert("init" === (stateful !! (GetRefState, 1000000)).get) // check that state is == init state
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class ReactorBasedSingleThreadEventDrivenDispatcherActorSpec extends JUnitSuite
|
|||
|
||||
@Test def shouldSendReplySync = {
|
||||
val actor = actorOf[TestActor].start
|
||||
val result: String = (actor !! ("Hello", 10000)).get
|
||||
val result = (actor !! ("Hello", 10000)).as[String].get
|
||||
assert("World" === result)
|
||||
actor.stop
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class ReactorBasedThreadPoolEventDrivenDispatcherActorSpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldSendReplySync = {
|
||||
val actor = actorOf[TestActor].start
|
||||
val result: String = (actor !! ("Hello", 10000)).get
|
||||
val result = (actor !! ("Hello", 10000)).as[String].get
|
||||
assert("World" === result)
|
||||
actor.stop
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,10 +88,10 @@ class StmSpec extends
|
|||
try {
|
||||
val actor = actorOf[GlobalTransactionVectorTestActor].start
|
||||
actor !! Add(5)
|
||||
val size1: Int = (actor !! Size).getOrElse(fail("Could not get Vector::size"))
|
||||
val size1 = (actor !! Size).as[Int].getOrElse(fail("Could not get Vector::size"))
|
||||
size1 should equal(2)
|
||||
actor !! Add(2)
|
||||
val size2: Int = (actor !! Size).getOrElse(fail("Could not get Vector::size"))
|
||||
val size2 = (actor !! Size).as[Int].getOrElse(fail("Could not get Vector::size"))
|
||||
size2 should equal(3)
|
||||
} catch {
|
||||
case e =>
|
||||
|
|
@ -107,18 +107,18 @@ class StmSpec extends
|
|||
try {
|
||||
val actor = actorOf[NestedTransactorLevelOneActor].start
|
||||
actor !! Add(2)
|
||||
val size1: Int = (actor !! Size).getOrElse(fail("Could not get size"))
|
||||
val size1 = (actor !! Size).as[Int].getOrElse(fail("Could not get size"))
|
||||
size1 should equal(2)
|
||||
actor !! Add(7)
|
||||
actor ! "HiLevelOne"
|
||||
val size2: Int = (actor !! Size).getOrElse(fail("Could not get size"))
|
||||
val size2 = (actor !! Size).as[Int].getOrElse(fail("Could not get size"))
|
||||
size2 should equal(7)
|
||||
actor !! Add(0)
|
||||
actor ! "HiLevelTwo"
|
||||
val size3: Int = (actor !! Size).getOrElse(fail("Could not get size"))
|
||||
val size3 = (actor !! Size).as[Int].getOrElse(fail("Could not get size"))
|
||||
size3 should equal(0)
|
||||
actor !! Add(3)
|
||||
val size4: Int = (actor !! Size).getOrElse(fail("Could not get size"))
|
||||
val size4 = (actor !! Size).as[Int].getOrElse(fail("Could not get size"))
|
||||
size4 should equal(3)
|
||||
} catch {
|
||||
case e =>
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ class ThreadBasedActorSpec extends JUnitSuite {
|
|||
|
||||
@Test def shouldSendReplySync = {
|
||||
val actor = actorOf[TestActor].start
|
||||
val result: String = (actor !! ("Hello", 10000)).get
|
||||
assert("World" === result)
|
||||
val result = (actor !! ("Hello", 10000)).as[String]
|
||||
assert("World" === result.get)
|
||||
actor.stop
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@
|
|||
package se.scalablesolutions.akka.security
|
||||
|
||||
import se.scalablesolutions.akka.actor.{Scheduler, Actor, ActorRef, ActorRegistry}
|
||||
import se.scalablesolutions.akka.util.Logging
|
||||
import se.scalablesolutions.akka.actor.Actor._
|
||||
import se.scalablesolutions.akka.config.Config
|
||||
import se.scalablesolutions.akka.util.Logging
|
||||
|
||||
import com.sun.jersey.api.model.AbstractMethod
|
||||
import com.sun.jersey.spi.container.{ResourceFilterFactory, ContainerRequest, ContainerRequestFilter, ContainerResponse, ContainerResponseFilter, ResourceFilter}
|
||||
|
|
@ -87,7 +88,7 @@ class AkkaSecurityFilterFactory extends ResourceFilterFactory with Logging {
|
|||
override def filter(request: ContainerRequest): ContainerRequest =
|
||||
rolesAllowed match {
|
||||
case Some(roles) => {
|
||||
val result : Option[AnyRef] = authenticator !! Authenticate(request, roles)
|
||||
val result = (authenticator !! Authenticate(request, roles)).as[AnyRef]
|
||||
result match {
|
||||
case Some(OK) => request
|
||||
case Some(r) if r.isInstanceOf[Response] =>
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class BasicAuthenticatorSpec extends junit.framework.TestCase
|
|||
@Test def testChallenge = {
|
||||
val req = mock[ContainerRequest]
|
||||
|
||||
val result: Response = (authenticator !! (Authenticate(req, List("foo")), 10000)).get
|
||||
val result = (authenticator !! (Authenticate(req, List("foo")), 10000)).as[Response].get
|
||||
|
||||
// the actor replies with a challenge for the browser
|
||||
result.getStatus must equal(Response.Status.UNAUTHORIZED.getStatusCode)
|
||||
|
|
@ -54,7 +54,7 @@ class BasicAuthenticatorSpec extends junit.framework.TestCase
|
|||
// fake a request authorization -> this will authorize the user
|
||||
when(req.isUserInRole("chef")).thenReturn(true)
|
||||
|
||||
val result: AnyRef = (authenticator !! (Authenticate(req, List("chef")), 10000)).get
|
||||
val result = (authenticator !! (Authenticate(req, List("chef")), 10000)).as[AnyRef].get
|
||||
|
||||
result must be(OK)
|
||||
// the authenticator must have set a security context
|
||||
|
|
@ -68,7 +68,7 @@ class BasicAuthenticatorSpec extends junit.framework.TestCase
|
|||
when(req.getHeaderValue("Authorization")).thenReturn("Basic " + new String(Base64.encode("foo:bar")))
|
||||
when(req.isUserInRole("chef")).thenReturn(false) // this will deny access
|
||||
|
||||
val result: Response = (authenticator !! (Authenticate(req, List("chef")), 10000)).get
|
||||
val result = (authenticator !! (Authenticate(req, List("chef")), 10000)).as[Response].get
|
||||
|
||||
result.getStatus must equal(Response.Status.FORBIDDEN.getStatusCode)
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class CassandraPersistentActorSpec extends JUnitSuite {
|
|||
stateful.start
|
||||
stateful !! SetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "init") // set init state
|
||||
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
val result: Array[Byte] = (stateful !! GetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess")).get
|
||||
val result = (stateful !! GetMapState("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess")).as[Array[Byte]].get
|
||||
assertEquals("new state", new String(result, 0, result.length, "UTF-8"))
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +95,7 @@ class CassandraPersistentActorSpec extends JUnitSuite {
|
|||
stateful !! Failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
fail("should have thrown an exception")
|
||||
} catch {case e: RuntimeException => {}}
|
||||
val result: Array[Byte] = (stateful !! GetMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")).get
|
||||
val result = (stateful !! GetMapState("testShouldRollbackStateForStatefulServerInCaseOfFailure")).as[Array[Byte]].get
|
||||
assertEquals("init", new String(result, 0, result.length, "UTF-8")) // check that state is == init state
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ class CassandraPersistentActorSpec extends JUnitSuite {
|
|||
stateful.start
|
||||
stateful !! SetRefState("init") // set init state
|
||||
stateful !! Success("testShouldNotRollbackStateForStatefulServerInCaseOfSuccess", "new state") // transactionrequired
|
||||
val result: Array[Byte] = (stateful !! GetRefState).get
|
||||
val result = (stateful !! GetRefState).as[Array[Byte]].get
|
||||
assertEquals("new state", new String(result, 0, result.length, "UTF-8"))
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ class CassandraPersistentActorSpec extends JUnitSuite {
|
|||
stateful !! Failure("testShouldRollbackStateForStatefulServerInCaseOfFailure", "new state", failer) // call failing transactionrequired method
|
||||
fail("should have thrown an exception")
|
||||
} catch {case e: RuntimeException => {}}
|
||||
val result: Array[Byte] = (stateful !! GetRefState).get
|
||||
val result = (stateful !! GetRefState).as[Array[Byte]].get
|
||||
assertEquals("init", new String(result, 0, result.length, "UTF-8")) // check that state is == init state
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,9 +66,9 @@ object Runner {
|
|||
def run {
|
||||
val proc = actorOf[RedisSampleStorage]
|
||||
proc.start
|
||||
val i: Option[String] = proc !! SETFOO("debasish")
|
||||
val i = (proc !! SETFOO("debasish")).as[String]
|
||||
println("i = " + i)
|
||||
val ev: Option[Int] = proc !! GETFOO("debasish")
|
||||
val ev = (proc !! GETFOO("debasish")).as[Int]
|
||||
println(ev)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ class RedisPersistentActorSpec extends JUnitSuite {
|
|||
bactor !! Debit("a-123", 8000, failer)
|
||||
assertEquals(BigInt(1000), (bactor !! Balance("a-123")).get)
|
||||
|
||||
val c: Int = (bactor !! LogSize).get
|
||||
val c = (bactor !! LogSize).as[Int].get
|
||||
assertTrue(7 == c)
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +134,7 @@ class RedisPersistentActorSpec extends JUnitSuite {
|
|||
assertEquals(BigInt(5000), (bactor !! Balance("a-123")).get)
|
||||
|
||||
// should not count the failed one
|
||||
val c: Int = (bactor !! LogSize).get
|
||||
val c = (bactor !! LogSize).as[Int].get
|
||||
assertTrue(3 == c)
|
||||
}
|
||||
|
||||
|
|
@ -156,7 +156,7 @@ class RedisPersistentActorSpec extends JUnitSuite {
|
|||
assertEquals(BigInt(5000), (bactor !! (Balance("a-123"), 5000)).get)
|
||||
|
||||
// should not count the failed one
|
||||
val c: Int = (bactor !! LogSize).get
|
||||
val c = (bactor !! LogSize).as[Int].get
|
||||
assertTrue(3 == c)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class RedisPersistentQSpec extends JUnitSuite {
|
|||
qa !! NQ("a-123")
|
||||
qa !! NQ("a-124")
|
||||
qa !! NQ("a-125")
|
||||
val t: Int = (qa !! SZ).get
|
||||
val t = (qa !! SZ).as[Int].get
|
||||
assertTrue(3 == t)
|
||||
}
|
||||
|
||||
|
|
@ -69,12 +69,12 @@ class RedisPersistentQSpec extends JUnitSuite {
|
|||
qa !! NQ("a-123")
|
||||
qa !! NQ("a-124")
|
||||
qa !! NQ("a-125")
|
||||
val s: Int = (qa !! SZ).get
|
||||
val s = (qa !! SZ).as[Int].get
|
||||
assertTrue(3 == s)
|
||||
assertEquals("a-123", (qa !! DQ).get)
|
||||
assertEquals("a-124", (qa !! DQ).get)
|
||||
assertEquals("a-125", (qa !! DQ).get)
|
||||
val t: Int = (qa !! SZ).get
|
||||
val t = (qa !! SZ).as[Int].get
|
||||
assertTrue(0 == t)
|
||||
}
|
||||
|
||||
|
|
@ -88,13 +88,13 @@ class RedisPersistentQSpec extends JUnitSuite {
|
|||
qa !! NQ("a-123")
|
||||
qa !! NQ("a-124")
|
||||
qa !! NQ("a-125")
|
||||
val t: Int = (qa !! SZ).get
|
||||
val t = (qa !! SZ).as[Int].get
|
||||
assertTrue(3 == t)
|
||||
assertEquals("a-123", (qa !! DQ).get)
|
||||
val s: Int = (qa !! SZ).get
|
||||
val s = (qa !! SZ).as[Int].get
|
||||
assertTrue(2 == s)
|
||||
qa !! MNDQ(List("a-126", "a-127"), 2, failer)
|
||||
val u: Int = (qa !! SZ).get
|
||||
val u = (qa !! SZ).as[Int].get
|
||||
assertTrue(2 == u)
|
||||
}
|
||||
|
||||
|
|
@ -110,25 +110,25 @@ class RedisPersistentQSpec extends JUnitSuite {
|
|||
qa !! NQ("a-124")
|
||||
qa !! NQ("a-125")
|
||||
|
||||
val t: Int = (qa !! SZ).get
|
||||
val t = (qa !! SZ).as[Int].get
|
||||
assertTrue(3 == t)
|
||||
|
||||
// dequeue 1
|
||||
assertEquals("a-123", (qa !! DQ).get)
|
||||
|
||||
// size == 2
|
||||
val s: Int = (qa !! SZ).get
|
||||
val s = (qa !! SZ).as[Int].get
|
||||
assertTrue(2 == s)
|
||||
|
||||
// enqueue 2, dequeue 2 => size == 2
|
||||
qa !! MNDQ(List("a-126", "a-127"), 2, failer)
|
||||
val u: Int = (qa !! SZ).get
|
||||
val u = (qa !! SZ).as[Int].get
|
||||
assertTrue(2 == u)
|
||||
|
||||
// enqueue 2 => size == 4
|
||||
qa !! NQ("a-128")
|
||||
qa !! NQ("a-129")
|
||||
val v: Int = (qa !! SZ).get
|
||||
val v = (qa !! SZ).as[Int].get
|
||||
assertTrue(4 == v)
|
||||
|
||||
// enqueue 1 => size 5
|
||||
|
|
@ -138,7 +138,7 @@ class RedisPersistentQSpec extends JUnitSuite {
|
|||
qa !! MNDQ(List("a-130"), 6, failer)
|
||||
} catch { case e: Exception => {} }
|
||||
|
||||
val w: Int = (qa !! SZ).get
|
||||
val w = (qa !! SZ).as[Int].get
|
||||
assertTrue(4 == w)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,10 +63,10 @@ case class ChatMessage(from: String, message: String) extends Event
|
|||
class ChatClient(val name: String) {
|
||||
val chat = RemoteClient.actorFor("chat:service", "localhost", 9999)
|
||||
|
||||
def login = chat ! Login(name)
|
||||
def logout = chat ! Logout(name)
|
||||
def login = chat ! Login(name)
|
||||
def logout = chat ! Logout(name)
|
||||
def post(message: String) = chat ! ChatMessage(name, name + ": " + message)
|
||||
def chatLog: ChatLog = (chat !! GetChatLog(name)).getOrElse(throw new Exception("Couldn't get the chat log from ChatServer"))
|
||||
def chatLog = (chat !! GetChatLog(name)).as[ChatLog].getOrElse(throw new Exception("Couldn't get the chat log from ChatServer"))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class SimpleService {
|
|||
//Fetch the first actor of type SimpleServiceActor
|
||||
//Send it the "Tick" message and expect a NodeSeq back
|
||||
val result = for{a <- actorsFor(classOf[SimpleServiceActor]).headOption
|
||||
r <- a.!} yield r
|
||||
r <- (a !! "Tick").as[NodeSeq]} yield r
|
||||
//Return either the resulting NodeSeq or a default one
|
||||
result getOrElse <error>Error in counter</error>
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ class PersistentSimpleService {
|
|||
//Fetch the first actor of type PersistentSimpleServiceActor
|
||||
//Send it the "Tick" message and expect a NodeSeq back
|
||||
val result = for{a <- actorsFor(classOf[PersistentSimpleServiceActor]).headOption
|
||||
r <- a.!} yield r
|
||||
r <- (a !! "Tick").as[NodeSeq]} yield r
|
||||
//Return either the resulting NodeSeq or a default one
|
||||
result getOrElse <error>Error in counter</error>
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ class Chat {
|
|||
//Fetch the first actor of type ChatActor
|
||||
//Send it the "Tick" message and expect a NodeSeq back
|
||||
val result = for{a <- actorsFor(classOf[ChatActor]).headOption
|
||||
r <- a.!} yield r
|
||||
r <- (a !! msg).as[String]} yield r
|
||||
//Return either the resulting String or a default one
|
||||
result getOrElse "System__error"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ class SecureTickService {
|
|||
//Fetch the first actor of type PersistentSimpleServiceActor
|
||||
//Send it the "Tick" message and expect a NdeSeq back
|
||||
val result = for{a <- actorsFor(classOf[SecureTickActor]).headOption
|
||||
r <- a.!} yield r
|
||||
r <- (a !! "Tick").as[Integer]} yield r
|
||||
//Return either the resulting NodeSeq or a default one
|
||||
result match {
|
||||
case (Some(counter)) => (<success>Tick: {counter}</success>)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue