Merge pull request #656 from akka/wip-2396-√
#2396 - Removing the Props.apply(ActorContext => Actor.Receive) method a...
This commit is contained in:
commit
4ab5cef2e9
12 changed files with 55 additions and 46 deletions
|
|
@ -99,7 +99,7 @@ trait DeathWatchSpec { this: AkkaSpec with ImplicitSender with DefaultTimeout
|
|||
filterException[ActorKilledException] {
|
||||
val supervisor = system.actorOf(Props(new Supervisor(
|
||||
OneForOneStrategy(maxNrOfRetries = 2)(List(classOf[Exception])))))
|
||||
val terminalProps = Props(context ⇒ { case x ⇒ context.sender ! x })
|
||||
val terminalProps = Props(new Actor { def receive = { case x ⇒ sender ! x } })
|
||||
val terminal = Await.result((supervisor ? terminalProps).mapTo[ActorRef], timeout.duration)
|
||||
|
||||
val monitor = startWatching(terminal)
|
||||
|
|
@ -150,7 +150,7 @@ trait DeathWatchSpec { this: AkkaSpec with ImplicitSender with DefaultTimeout
|
|||
val parent = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "NKOTB" ⇒
|
||||
val currentKid = context.watch(context.actorOf(Props(ctx ⇒ { case "NKOTB" ⇒ ctx stop ctx.self }), "kid"))
|
||||
val currentKid = context.watch(context.actorOf(Props(new Actor { def receive = { case "NKOTB" ⇒ context stop self } }), "kid"))
|
||||
currentKid forward "NKOTB"
|
||||
context become {
|
||||
case Terminated(`currentKid`) ⇒
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class LocalActorRefProviderSpec extends AkkaSpec(LocalActorRefProviderSpec.confi
|
|||
"An LocalActorRefProvider" must {
|
||||
|
||||
"find actor refs using actorFor" in {
|
||||
val a = system.actorOf(Props(ctx ⇒ { case _ ⇒ }))
|
||||
val a = system.actorOf(Props(new Actor { def receive = { case _ ⇒ } }))
|
||||
val b = system.actorFor(a.path)
|
||||
a must be === b
|
||||
}
|
||||
|
|
@ -52,7 +52,7 @@ class LocalActorRefProviderSpec extends AkkaSpec(LocalActorRefProviderSpec.confi
|
|||
for (i ← 0 until 100) {
|
||||
val address = "new-actor" + i
|
||||
implicit val timeout = Timeout(5 seconds)
|
||||
val actors = for (j ← 1 to 4) yield Future(system.actorOf(Props(c ⇒ { case _ ⇒ }), address))
|
||||
val actors = for (j ← 1 to 4) yield Future(system.actorOf(Props(new Actor { def receive = { case _ ⇒ } }), address))
|
||||
val set = Set() ++ actors.map(a ⇒ Await.ready(a, timeout.duration).value match {
|
||||
case Some(Success(a: ActorRef)) ⇒ 1
|
||||
case Some(Failure(ex: InvalidActorNameException)) ⇒ 2
|
||||
|
|
|
|||
|
|
@ -81,12 +81,15 @@ class DispatcherActorSpec extends AkkaSpec(DispatcherActorSpec.config) with Defa
|
|||
val latch = new CountDownLatch(100)
|
||||
val start = new CountDownLatch(1)
|
||||
val fastOne = system.actorOf(
|
||||
Props(context ⇒ { case "sabotage" ⇒ works.set(false) }).withDispatcher(throughputDispatcher))
|
||||
Props(new Actor { def receive = { case "sabotage" ⇒ works.set(false) } })
|
||||
.withDispatcher(throughputDispatcher))
|
||||
|
||||
val slowOne = system.actorOf(
|
||||
Props(context ⇒ {
|
||||
case "hogexecutor" ⇒ context.sender ! "OK"; start.await
|
||||
case "ping" ⇒ if (works.get) latch.countDown()
|
||||
Props(new Actor {
|
||||
def receive = {
|
||||
case "hogexecutor" ⇒ sender ! "OK"; start.await
|
||||
case "ping" ⇒ if (works.get) latch.countDown()
|
||||
}
|
||||
}).withDispatcher(throughputDispatcher))
|
||||
|
||||
assert(Await.result(slowOne ? "hogexecutor", timeout.duration) === "OK")
|
||||
|
|
@ -109,14 +112,18 @@ class DispatcherActorSpec extends AkkaSpec(DispatcherActorSpec.config) with Defa
|
|||
val ready = new CountDownLatch(1)
|
||||
|
||||
val fastOne = system.actorOf(
|
||||
Props(context ⇒ {
|
||||
case "ping" ⇒ if (works.get) latch.countDown(); context.stop(context.self)
|
||||
Props(new Actor {
|
||||
def receive = {
|
||||
case "ping" ⇒ if (works.get) latch.countDown(); context.stop(self)
|
||||
}
|
||||
}).withDispatcher(throughputDispatcher))
|
||||
|
||||
val slowOne = system.actorOf(
|
||||
Props(context ⇒ {
|
||||
case "hogexecutor" ⇒ ready.countDown(); start.await
|
||||
case "ping" ⇒ works.set(false); context.stop(context.self)
|
||||
Props(new Actor {
|
||||
def receive = {
|
||||
case "hogexecutor" ⇒ ready.countDown(); start.await
|
||||
case "ping" ⇒ works.set(false); context.stop(self)
|
||||
}
|
||||
}).withDispatcher(throughputDispatcher))
|
||||
|
||||
slowOne ! "hogexecutor"
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class PinnedActorSpec extends AkkaSpec(PinnedActorSpec.config) with BeforeAndAft
|
|||
|
||||
"support tell" in {
|
||||
var oneWay = new CountDownLatch(1)
|
||||
val actor = system.actorOf(Props(self ⇒ { case "OneWay" ⇒ oneWay.countDown() }).withDispatcher("pinned-dispatcher"))
|
||||
val actor = system.actorOf(Props(new Actor { def receive = { case "OneWay" ⇒ oneWay.countDown() } }).withDispatcher("pinned-dispatcher"))
|
||||
val result = actor ! "OneWay"
|
||||
assert(oneWay.await(1, TimeUnit.SECONDS))
|
||||
system.stop(actor)
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@ class Future2ActorSpec extends AkkaSpec with DefaultTimeout {
|
|||
}
|
||||
|
||||
"support convenient sending to multiple destinations with implicit sender" in {
|
||||
implicit val someActor = system.actorOf(Props(ctx ⇒ Actor.emptyBehavior))
|
||||
implicit val someActor = system.actorOf(Props(new Actor { def receive = Actor.emptyBehavior }))
|
||||
Future(42) pipeTo testActor pipeTo testActor
|
||||
expectMsgAllOf(1 second, 42, 42)
|
||||
lastSender must be(someActor)
|
||||
}
|
||||
|
||||
"support convenient sending with explicit sender" in {
|
||||
val someActor = system.actorOf(Props(ctx ⇒ Actor.emptyBehavior))
|
||||
val someActor = system.actorOf(Props(new Actor { def receive = Actor.emptyBehavior }))
|
||||
Future(42).to(testActor, someActor)
|
||||
expectMsgAllOf(1 second, 42)
|
||||
lastSender must be(someActor)
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ import akka.testkit.AkkaSpec
|
|||
import scala.concurrent.util.duration._
|
||||
import scala.concurrent.Await
|
||||
import akka.testkit.DefaultTimeout
|
||||
import akka.actor.{ Props, ActorRef }
|
||||
import akka.util.Timeout
|
||||
import scala.util.Failure
|
||||
import akka.actor.{ Actor, Props, ActorRef }
|
||||
|
||||
class AskSpec extends AkkaSpec {
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ class AskSpec extends AkkaSpec {
|
|||
|
||||
"return broken promises on 0 timeout" in {
|
||||
implicit val timeout = Timeout(0 seconds)
|
||||
val echo = system.actorOf(Props(ctx ⇒ { case x ⇒ ctx.sender ! x }))
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x ⇒ sender ! x } }))
|
||||
val f = echo ? "foo"
|
||||
val expectedMsg = "Timeout length for an `ask` must be greater or equal to 1. Question not sent to [%s]" format echo
|
||||
intercept[IllegalArgumentException] {
|
||||
|
|
@ -60,7 +60,7 @@ class AskSpec extends AkkaSpec {
|
|||
|
||||
"return broken promises on < 0 timeout" in {
|
||||
implicit val timeout = Timeout(-1000 seconds)
|
||||
val echo = system.actorOf(Props(ctx ⇒ { case x ⇒ ctx.sender ! x }))
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x ⇒ sender ! x } }))
|
||||
val f = echo ? "foo"
|
||||
val expectedMsg = "Timeout length for an `ask` must be greater or equal to 1. Question not sent to [%s]" format echo
|
||||
intercept[IllegalArgumentException] {
|
||||
|
|
@ -70,7 +70,7 @@ class AskSpec extends AkkaSpec {
|
|||
|
||||
"return broken promises on infinite timeout" in {
|
||||
implicit val timeout = Timeout.never
|
||||
val echo = system.actorOf(Props(ctx ⇒ { case x ⇒ ctx.sender ! x }))
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x ⇒ sender ! x } }))
|
||||
val f = echo ? "foo"
|
||||
val expectedMsg = "Timeouts to `ask` must be finite. Question not sent to [%s]" format echo
|
||||
intercept[IllegalArgumentException] {
|
||||
|
|
|
|||
|
|
@ -80,17 +80,15 @@ object ActorDSL extends dsl.Inbox with dsl.Creators {
|
|||
|
||||
protected class Extension(val system: ExtendedActorSystem) extends akka.actor.Extension with InboxExtension {
|
||||
|
||||
val boss = system.asInstanceOf[ActorSystemImpl].systemActorOf(Props.empty, "dsl").asInstanceOf[RepointableActorRef]
|
||||
val boss = system.asInstanceOf[ActorSystemImpl].systemActorOf(Props(
|
||||
new Actor {
|
||||
def receive = { case any ⇒ sender ! any }
|
||||
}), "dsl").asInstanceOf[RepointableActorRef]
|
||||
|
||||
{
|
||||
val timeout = system.settings.CreationTimeout.duration
|
||||
val deadline = Deadline.now + timeout
|
||||
while (!boss.isStarted) {
|
||||
if (deadline.hasTimeLeft)
|
||||
if (system.isTerminated) throw new IllegalStateException("actor system is already shutdown")
|
||||
else Thread.sleep(10)
|
||||
else throw new TimeoutException("failed to create /system/dsl actor within " + timeout)
|
||||
}
|
||||
implicit val timeout = system.settings.CreationTimeout
|
||||
if (Await.result(boss ? "OK", system.settings.CreationTimeout.duration) != "OK")
|
||||
throw new IllegalStateException("Creation of boss actor did not succeed!")
|
||||
}
|
||||
|
||||
lazy val config = system.settings.config.getConfig("akka.actor.dsl")
|
||||
|
|
|
|||
|
|
@ -74,11 +74,6 @@ object Props {
|
|||
* using the supplied thunk.
|
||||
*/
|
||||
def apply(creator: Creator[_ <: Actor]): Props = default.withCreator(creator.create)
|
||||
|
||||
/**
|
||||
* Returns a new Props whose creator will instantiate an Actor that has the behavior specified
|
||||
*/
|
||||
def apply(behavior: ActorContext ⇒ Actor.Receive): Props = apply(new Actor { def receive = behavior(context) })
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ package akka.camel.internal.component
|
|||
import org.scalatest.mock.MockitoSugar
|
||||
import org.scalatest.matchers.MustMatchers
|
||||
import akka.camel.TestSupport.SharedCamelSystem
|
||||
import akka.actor.Props
|
||||
import org.scalatest.WordSpec
|
||||
import akka.actor.{ Actor, Props }
|
||||
|
||||
class ActorEndpointPathTest extends WordSpec with SharedCamelSystem with MustMatchers with MockitoSugar {
|
||||
|
||||
def find(path: String) = ActorEndpointPath.fromCamelPath(path).findActorIn(system)
|
||||
|
||||
"findActorIn returns Some(actor ref) if actor exists" in {
|
||||
val path = system.actorOf(Props(behavior = ctx ⇒ { case _ ⇒ {} }), "knownactor").path
|
||||
val path = system.actorOf(Props(new Actor { def receive = { case _ ⇒ } }), "knownactor").path
|
||||
find(path.toString) must be('defined)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -201,7 +201,18 @@ v2.0 Java::
|
|||
|
||||
v2.1 Java::
|
||||
|
||||
ActorRef router2 = system.actorOf(new Props().withRouter(RoundRobinRouter.create(routees)));
|
||||
ActorRef router2 = system.actorOf(new Props().withRouter(RoundRobinRouter.create(routees)));
|
||||
|
||||
Props: Function-based creation
|
||||
==============================
|
||||
|
||||
v2.0 Scala::
|
||||
|
||||
Props(context => { case someMessage => context.sender ! someMessage })
|
||||
|
||||
v2.1 Scala::
|
||||
|
||||
Props(new Actor { def receive = { case someMessage => sender ! someMessage } })
|
||||
|
||||
Failing Send
|
||||
============
|
||||
|
|
|
|||
|
|
@ -7,15 +7,14 @@ import language.{ postfixOps, reflectiveCalls }
|
|||
|
||||
import org.scalatest.{ WordSpec, BeforeAndAfterAll, Tag }
|
||||
import org.scalatest.matchers.MustMatchers
|
||||
import akka.actor.{ Actor, ActorRef, Props, ActorSystem, PoisonPill, DeadLetter }
|
||||
import akka.actor.{ Actor, Props, ActorSystem, PoisonPill, DeadLetter, ActorSystemImpl }
|
||||
import akka.event.{ Logging, LoggingAdapter }
|
||||
import scala.concurrent.util.duration._
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.{ Await, Future }
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
import java.util.concurrent.TimeoutException
|
||||
import akka.dispatch.{ MessageDispatcher, Dispatchers }
|
||||
import akka.dispatch.Dispatchers
|
||||
import akka.pattern.ask
|
||||
import akka.actor.ActorSystemImpl
|
||||
|
||||
object TimingTest extends Tag("timing")
|
||||
object LongRunningTest extends Tag("long-running")
|
||||
|
|
@ -90,9 +89,8 @@ abstract class AkkaSpec(_system: ActorSystem)
|
|||
|
||||
protected def atTermination() {}
|
||||
|
||||
def spawn(dispatcherId: String = Dispatchers.DefaultDispatcherId)(body: ⇒ Unit) {
|
||||
system.actorOf(Props(ctx ⇒ { case "go" ⇒ try body finally ctx.stop(ctx.self) }).withDispatcher(dispatcherId)) ! "go"
|
||||
}
|
||||
def spawn(dispatcherId: String = Dispatchers.DefaultDispatcherId)(body: ⇒ Unit): Unit =
|
||||
Future(body)(system.dispatchers.lookup(dispatcherId))
|
||||
}
|
||||
|
||||
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ class TestActorRefSpec extends AkkaSpec("disp1.type=Dispatcher") with BeforeAndA
|
|||
|
||||
"used with TestActorRef" in {
|
||||
val a = TestActorRef(Props(new Actor {
|
||||
val nested = TestActorRef(Props(self ⇒ { case _ ⇒ }))
|
||||
val nested = TestActorRef(Props(new Actor { def receive = { case _ ⇒ } }))
|
||||
def receive = { case _ ⇒ sender ! nested }
|
||||
}))
|
||||
a must not be (null)
|
||||
|
|
@ -128,7 +128,7 @@ class TestActorRefSpec extends AkkaSpec("disp1.type=Dispatcher") with BeforeAndA
|
|||
|
||||
"used with ActorRef" in {
|
||||
val a = TestActorRef(Props(new Actor {
|
||||
val nested = context.actorOf(Props(self ⇒ { case _ ⇒ }))
|
||||
val nested = context.actorOf(Props(new Actor { def receive = { case _ ⇒ } }))
|
||||
def receive = { case _ ⇒ sender ! nested }
|
||||
}))
|
||||
a must not be (null)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue