Enable fatal errors for docs (#29570)
This commit is contained in:
parent
e0ceb71ccd
commit
ca59d8149c
55 changed files with 268 additions and 223 deletions
|
|
@ -41,7 +41,7 @@ final case class Message(s: String)
|
||||||
|
|
||||||
//#context-actorOf
|
//#context-actorOf
|
||||||
class FirstActor extends Actor {
|
class FirstActor extends Actor {
|
||||||
val child = context.actorOf(Props[MyActor], name = "myChild")
|
val child = context.actorOf(Props[MyActor](), name = "myChild")
|
||||||
//#plus-some-behavior
|
//#plus-some-behavior
|
||||||
def receive = {
|
def receive = {
|
||||||
case x => sender() ! x
|
case x => sender() ! x
|
||||||
|
|
@ -124,7 +124,7 @@ class Hook extends Actor {
|
||||||
var child: ActorRef = _
|
var child: ActorRef = _
|
||||||
//#preStart
|
//#preStart
|
||||||
override def preStart(): Unit = {
|
override def preStart(): Unit = {
|
||||||
child = context.actorOf(Props[MyActor], "child")
|
child = context.actorOf(Props[MyActor](), "child")
|
||||||
}
|
}
|
||||||
//#preStart
|
//#preStart
|
||||||
def receive = Actor.emptyBehavior
|
def receive = Actor.emptyBehavior
|
||||||
|
|
@ -182,7 +182,7 @@ object Manager {
|
||||||
|
|
||||||
class Manager extends Actor {
|
class Manager extends Actor {
|
||||||
import Manager._
|
import Manager._
|
||||||
val worker = context.watch(context.actorOf(Props[Cruncher], "worker"))
|
val worker = context.watch(context.actorOf(Props[Cruncher](), "worker"))
|
||||||
|
|
||||||
def receive = {
|
def receive = {
|
||||||
case "job" => worker ! "crunch"
|
case "job" => worker ! "crunch"
|
||||||
|
|
@ -224,7 +224,7 @@ class Swapper extends Actor {
|
||||||
|
|
||||||
object SwapperApp extends App {
|
object SwapperApp extends App {
|
||||||
val system = ActorSystem("SwapperSystem")
|
val system = ActorSystem("SwapperSystem")
|
||||||
val swap = system.actorOf(Props[Swapper], name = "swapper")
|
val swap = system.actorOf(Props[Swapper](), name = "swapper")
|
||||||
swap ! Swap // logs Hi
|
swap ! Swap // logs Hi
|
||||||
swap ! Swap // logs Ho
|
swap ! Swap // logs Ho
|
||||||
swap ! Swap // logs Hi
|
swap ! Swap // logs Hi
|
||||||
|
|
@ -328,7 +328,7 @@ class ActorDocSpec extends AkkaSpec("""
|
||||||
//#import-context
|
//#import-context
|
||||||
class FirstActor extends Actor {
|
class FirstActor extends Actor {
|
||||||
import context._
|
import context._
|
||||||
val myActor = actorOf(Props[MyActor], name = "myactor")
|
val myActor = actorOf(Props[MyActor](), name = "myactor")
|
||||||
def receive = {
|
def receive = {
|
||||||
case x => myActor ! x
|
case x => myActor ! x
|
||||||
}
|
}
|
||||||
|
|
@ -341,7 +341,7 @@ class ActorDocSpec extends AkkaSpec("""
|
||||||
}
|
}
|
||||||
|
|
||||||
"creating actor with system.actorOf" in {
|
"creating actor with system.actorOf" in {
|
||||||
val myActor = system.actorOf(Props[MyActor])
|
val myActor = system.actorOf(Props[MyActor]())
|
||||||
|
|
||||||
// testing the actor
|
// testing the actor
|
||||||
|
|
||||||
|
|
@ -369,7 +369,7 @@ class ActorDocSpec extends AkkaSpec("""
|
||||||
//#fiddle_code
|
//#fiddle_code
|
||||||
val system = ActorSystem("pingpong")
|
val system = ActorSystem("pingpong")
|
||||||
|
|
||||||
val pinger = system.actorOf(Props[Pinger], "pinger")
|
val pinger = system.actorOf(Props[Pinger](), "pinger")
|
||||||
|
|
||||||
val ponger = system.actorOf(Props(classOf[Ponger], pinger), "ponger")
|
val ponger = system.actorOf(Props(classOf[Ponger], pinger), "ponger")
|
||||||
|
|
||||||
|
|
@ -397,7 +397,7 @@ class ActorDocSpec extends AkkaSpec("""
|
||||||
}
|
}
|
||||||
|
|
||||||
"use poison pill" in {
|
"use poison pill" in {
|
||||||
val victim = system.actorOf(Props[MyActor])
|
val victim = system.actorOf(Props[MyActor]())
|
||||||
//#poison-pill
|
//#poison-pill
|
||||||
watch(victim)
|
watch(victim)
|
||||||
victim ! PoisonPill
|
victim ! PoisonPill
|
||||||
|
|
@ -409,7 +409,7 @@ class ActorDocSpec extends AkkaSpec("""
|
||||||
//#creating-props
|
//#creating-props
|
||||||
import akka.actor.Props
|
import akka.actor.Props
|
||||||
|
|
||||||
val props1 = Props[MyActor]
|
val props1 = Props[MyActor]()
|
||||||
val props2 = Props(new ActorWithArgs("arg")) // careful, see below
|
val props2 = Props(new ActorWithArgs("arg")) // careful, see below
|
||||||
val props3 = Props(classOf[ActorWithArgs], "arg") // no support for value class arguments
|
val props3 = Props(classOf[ActorWithArgs], "arg") // no support for value class arguments
|
||||||
//#creating-props
|
//#creating-props
|
||||||
|
|
@ -427,7 +427,7 @@ class ActorDocSpec extends AkkaSpec("""
|
||||||
|
|
||||||
// ActorSystem is a heavy object: create only one per application
|
// ActorSystem is a heavy object: create only one per application
|
||||||
val system = ActorSystem("mySystem")
|
val system = ActorSystem("mySystem")
|
||||||
val myActor = system.actorOf(Props[MyActor], "myactor2")
|
val myActor = system.actorOf(Props[MyActor](), "myactor2")
|
||||||
//#system-actorOf
|
//#system-actorOf
|
||||||
shutdown(system)
|
shutdown(system)
|
||||||
}
|
}
|
||||||
|
|
@ -480,7 +480,7 @@ class ActorDocSpec extends AkkaSpec("""
|
||||||
}
|
}
|
||||||
|
|
||||||
"using implicit timeout" in {
|
"using implicit timeout" in {
|
||||||
val myActor = system.actorOf(Props[FirstActor])
|
val myActor = system.actorOf(Props[FirstActor]())
|
||||||
//#using-implicit-timeout
|
//#using-implicit-timeout
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
import akka.util.Timeout
|
import akka.util.Timeout
|
||||||
|
|
@ -493,7 +493,7 @@ class ActorDocSpec extends AkkaSpec("""
|
||||||
}
|
}
|
||||||
|
|
||||||
"using explicit timeout" in {
|
"using explicit timeout" in {
|
||||||
val myActor = system.actorOf(Props[FirstActor])
|
val myActor = system.actorOf(Props[FirstActor]())
|
||||||
//#using-explicit-timeout
|
//#using-explicit-timeout
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
import akka.pattern.ask
|
import akka.pattern.ask
|
||||||
|
|
@ -658,7 +658,7 @@ class ActorDocSpec extends AkkaSpec("""
|
||||||
}
|
}
|
||||||
|
|
||||||
"using pattern gracefulStop" in {
|
"using pattern gracefulStop" in {
|
||||||
val actorRef = system.actorOf(Props[Manager])
|
val actorRef = system.actorOf(Props[Manager]())
|
||||||
//#gracefulStop
|
//#gracefulStop
|
||||||
import akka.pattern.gracefulStop
|
import akka.pattern.gracefulStop
|
||||||
import scala.concurrent.Await
|
import scala.concurrent.Await
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
|
||||||
//#when-syntax
|
//#when-syntax
|
||||||
when(Idle) {
|
when(Idle) {
|
||||||
case Event(SetTarget(ref), Uninitialized) =>
|
case Event(SetTarget(ref), Uninitialized) =>
|
||||||
stay.using(Todo(ref, Vector.empty))
|
stay().using(Todo(ref, Vector.empty))
|
||||||
}
|
}
|
||||||
//#when-syntax
|
//#when-syntax
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
|
||||||
|
|
||||||
case Event(e, s) =>
|
case Event(e, s) =>
|
||||||
log.warning("received unhandled request {} in state {}/{}", e, stateName, s)
|
log.warning("received unhandled request {} in state {}/{}", e, stateName, s)
|
||||||
stay
|
stay()
|
||||||
}
|
}
|
||||||
//#unhandled-elided
|
//#unhandled-elided
|
||||||
//#fsm-body
|
//#fsm-body
|
||||||
|
|
@ -140,7 +140,7 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
|
||||||
|
|
||||||
//#transform-syntax
|
//#transform-syntax
|
||||||
when(SomeState)(transform {
|
when(SomeState)(transform {
|
||||||
case Event(bytes: ByteString, read) => stay.using(read + bytes.length)
|
case Event(bytes: ByteString, read) => stay().using(read + bytes.length)
|
||||||
}.using {
|
}.using {
|
||||||
case s @ FSM.State(state, read, timeout, stopReason, replies) if read > 1000 =>
|
case s @ FSM.State(state, read, timeout, stopReason, replies) if read > 1000 =>
|
||||||
goto(Processing)
|
goto(Processing)
|
||||||
|
|
@ -154,7 +154,7 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
|
||||||
}
|
}
|
||||||
|
|
||||||
when(SomeState)(transform {
|
when(SomeState)(transform {
|
||||||
case Event(bytes: ByteString, read) => stay.using(read + bytes.length)
|
case Event(bytes: ByteString, read) => stay().using(read + bytes.length)
|
||||||
}.using(processingTrigger))
|
}.using(processingTrigger))
|
||||||
//#alt-transform-syntax
|
//#alt-transform-syntax
|
||||||
|
|
||||||
|
|
@ -170,7 +170,7 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
|
||||||
whenUnhandled {
|
whenUnhandled {
|
||||||
case Event(x: X, data) =>
|
case Event(x: X, data) =>
|
||||||
log.info("Received unhandled event: " + x)
|
log.info("Received unhandled event: " + x)
|
||||||
stay
|
stay()
|
||||||
case Event(msg, _) =>
|
case Event(msg, _) =>
|
||||||
log.warning("Received unknown event: " + msg)
|
log.warning("Received unknown event: " + msg)
|
||||||
goto(Error)
|
goto(Error)
|
||||||
|
|
@ -226,7 +226,7 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
|
||||||
"not batch if uninitialized" in {
|
"not batch if uninitialized" in {
|
||||||
val buncher = system.actorOf(Props(classOf[Buncher], this))
|
val buncher = system.actorOf(Props(classOf[Buncher], this))
|
||||||
buncher ! Queue(42)
|
buncher ! Queue(42)
|
||||||
expectNoMsg
|
expectNoMessage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ object FaultHandlingDocSample extends App {
|
||||||
""")
|
""")
|
||||||
|
|
||||||
val system = ActorSystem("FaultToleranceSample", config)
|
val system = ActorSystem("FaultToleranceSample", config)
|
||||||
val worker = system.actorOf(Props[Worker], name = "worker")
|
val worker = system.actorOf(Props[Worker](), name = "worker")
|
||||||
val listener = system.actorOf(Props[Listener], name = "listener")
|
val listener = system.actorOf(Props[Listener](), name = "listener")
|
||||||
// start the work and listen on progress
|
// start the work and listen on progress
|
||||||
// note that the listener is used as sender of the tell,
|
// note that the listener is used as sender of the tell,
|
||||||
// i.e. it will receive replies from the worker
|
// i.e. it will receive replies from the worker
|
||||||
|
|
@ -90,7 +90,7 @@ class Worker extends Actor with ActorLogging {
|
||||||
// The sender of the initial Start message will continuously be notified
|
// The sender of the initial Start message will continuously be notified
|
||||||
// about progress
|
// about progress
|
||||||
var progressListener: Option[ActorRef] = None
|
var progressListener: Option[ActorRef] = None
|
||||||
val counterService = context.actorOf(Props[CounterService], name = "counter")
|
val counterService = context.actorOf(Props[CounterService](), name = "counter")
|
||||||
val totalCount = 51
|
val totalCount = 51
|
||||||
import context.dispatcher // Use this Actors' Dispatcher as ExecutionContext
|
import context.dispatcher // Use this Actors' Dispatcher as ExecutionContext
|
||||||
|
|
||||||
|
|
@ -160,7 +160,7 @@ class CounterService extends Actor {
|
||||||
* Watch the child so we receive Terminated message when it has been terminated.
|
* Watch the child so we receive Terminated message when it has been terminated.
|
||||||
*/
|
*/
|
||||||
def initStorage(): Unit = {
|
def initStorage(): Unit = {
|
||||||
storage = Some(context.watch(context.actorOf(Props[Storage], name = "storage")))
|
storage = Some(context.watch(context.actorOf(Props[Storage](), name = "storage")))
|
||||||
// Tell the counter, if any, to use the new storage
|
// Tell the counter, if any, to use the new storage
|
||||||
counter.foreach { _ ! UseStorage(storage) }
|
counter.foreach { _ ! UseStorage(storage) }
|
||||||
// We need the initial value to be able to operate
|
// We need the initial value to be able to operate
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ class FaultHandlingDocSpec(_system: ActorSystem)
|
||||||
}
|
}
|
||||||
""")))
|
""")))
|
||||||
|
|
||||||
override def afterAll: Unit = {
|
override def afterAll(): Unit = {
|
||||||
TestKit.shutdownActorSystem(system)
|
TestKit.shutdownActorSystem(system)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,9 +129,9 @@ class FaultHandlingDocSpec(_system: ActorSystem)
|
||||||
//#testkit
|
//#testkit
|
||||||
|
|
||||||
//#create
|
//#create
|
||||||
val supervisor = system.actorOf(Props[Supervisor], "supervisor")
|
val supervisor = system.actorOf(Props[Supervisor](), "supervisor")
|
||||||
|
|
||||||
supervisor ! Props[Child]
|
supervisor ! Props[Child]()
|
||||||
val child = expectMsgType[ActorRef] // retrieve answer from TestKit’s testActor
|
val child = expectMsgType[ActorRef] // retrieve answer from TestKit’s testActor
|
||||||
//#create
|
//#create
|
||||||
EventFilter.warning(occurrences = 1).intercept {
|
EventFilter.warning(occurrences = 1).intercept {
|
||||||
|
|
@ -161,7 +161,7 @@ class FaultHandlingDocSpec(_system: ActorSystem)
|
||||||
}
|
}
|
||||||
EventFilter[Exception]("CRASH", occurrences = 2).intercept {
|
EventFilter[Exception]("CRASH", occurrences = 2).intercept {
|
||||||
//#escalate-kill
|
//#escalate-kill
|
||||||
supervisor ! Props[Child] // create new child
|
supervisor ! Props[Child]() // create new child
|
||||||
val child2 = expectMsgType[ActorRef]
|
val child2 = expectMsgType[ActorRef]
|
||||||
watch(child2)
|
watch(child2)
|
||||||
child2 ! "get" // verify it is alive
|
child2 ! "get" // verify it is alive
|
||||||
|
|
@ -173,9 +173,9 @@ class FaultHandlingDocSpec(_system: ActorSystem)
|
||||||
}
|
}
|
||||||
//#escalate-kill
|
//#escalate-kill
|
||||||
//#escalate-restart
|
//#escalate-restart
|
||||||
val supervisor2 = system.actorOf(Props[Supervisor2], "supervisor2")
|
val supervisor2 = system.actorOf(Props[Supervisor2](), "supervisor2")
|
||||||
|
|
||||||
supervisor2 ! Props[Child]
|
supervisor2 ! Props[Child]()
|
||||||
val child3 = expectMsgType[ActorRef]
|
val child3 = expectMsgType[ActorRef]
|
||||||
|
|
||||||
child3 ! 23
|
child3 ! 23
|
||||||
|
|
|
||||||
|
|
@ -58,11 +58,11 @@ class InitializationDocSpec extends AkkaSpec with ImplicitSender {
|
||||||
"Message based initialization example" must {
|
"Message based initialization example" must {
|
||||||
|
|
||||||
"work correctly" in {
|
"work correctly" in {
|
||||||
val example = system.actorOf(Props[MessageInitExample], "messageInitExample")
|
val example = system.actorOf(Props[MessageInitExample](), "messageInitExample")
|
||||||
val probe = "U OK?"
|
val probe = "U OK?"
|
||||||
|
|
||||||
example ! probe
|
example ! probe
|
||||||
expectNoMsg()
|
expectNoMessage()
|
||||||
|
|
||||||
example ! "init"
|
example ! "init"
|
||||||
example ! probe
|
example ! probe
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ class PropsEdgeCaseSpec extends AnyWordSpec with CompileOnlySpec {
|
||||||
case x: Int => sender() ! (x * b)
|
case x: Int => sender() ! (x * b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val defaultValueProp2 = Props[DefaultValueActor2] // Unsupported
|
val defaultValueProp2 = Props[DefaultValueActor2]() // Unsupported
|
||||||
val defaultValueProp3 = Props(classOf[DefaultValueActor2]) // Unsupported
|
val defaultValueProp3 = Props(classOf[DefaultValueActor2]) // Unsupported
|
||||||
//#props-edge-cases-default-values
|
//#props-edge-cases-default-values
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import scala.collection.mutable.ListBuffer
|
||||||
* Requirements are as follows:
|
* Requirements are as follows:
|
||||||
* The first thing the actor needs to do, is to subscribe to a channel of events,
|
* The first thing the actor needs to do, is to subscribe to a channel of events,
|
||||||
* Then it must replay (process) all "old" events
|
* Then it must replay (process) all "old" events
|
||||||
* Then it has to wait for a GoAhead signal to begin processing the new events
|
* Then it has to wait for a GoAhead message to begin processing the new events
|
||||||
* It mustn't "miss" events that happen between catching up with the old events and getting the GoAhead signal
|
* It mustn't "miss" events that happen between catching up with the old events and getting the GoAhead signal
|
||||||
*/
|
*/
|
||||||
class UnnestedReceives extends Actor {
|
class UnnestedReceives extends Actor {
|
||||||
|
|
@ -26,21 +26,21 @@ class UnnestedReceives extends Actor {
|
||||||
//This method retrieves all prior messages/events
|
//This method retrieves all prior messages/events
|
||||||
def allOldMessages() = List()
|
def allOldMessages() = List()
|
||||||
|
|
||||||
override def preStart: Unit = {
|
override def preStart(): Unit = {
|
||||||
//We override preStart to be sure that the first message the actor gets is
|
//We override preStart to be sure that the first message the actor gets is
|
||||||
//'Replay, that message will start to be processed _after_ the actor is started
|
//Replay, that message will start to be processed _after_ the actor is started
|
||||||
self ! 'Replay
|
self ! "Replay"
|
||||||
//Then we subscribe to the stream of messages/events
|
//Then we subscribe to the stream of messages/events
|
||||||
subscribe()
|
subscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
def receive = {
|
def receive = {
|
||||||
case 'Replay => //Our first message should be a 'Replay message, all others are invalid
|
case "Replay" => //Our first message should be a Replay message, all others are invalid
|
||||||
allOldMessages().foreach(process) //Process all old messages/events
|
allOldMessages().foreach(process) //Process all old messages/events
|
||||||
become { //Switch behavior to look for the GoAhead signal
|
become { //Switch behavior to look for the GoAhead signal
|
||||||
case 'GoAhead => //When we get the GoAhead signal we process all our buffered messages/events
|
case "GoAhead" => //When we get the GoAhead signal we process all our buffered messages/events
|
||||||
queue.foreach(process)
|
queue.foreach(process)
|
||||||
queue.clear
|
queue.clear()
|
||||||
become { //Then we change behavior to process incoming messages/events as they arrive
|
become { //Then we change behavior to process incoming messages/events as they arrive
|
||||||
case msg => process(msg)
|
case msg => process(msg)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class CoordinatedActorShutdownSpec {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def showCancel: Unit = {
|
def showCancel(): Unit = {
|
||||||
val system = ActorSystem(root, "main")
|
val system = ActorSystem(root, "main")
|
||||||
|
|
||||||
def cleanup(): Unit = {}
|
def cleanup(): Unit = {}
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,8 @@ object FactorialBackend {
|
||||||
.withFallback(ConfigFactory.load("factorial"))
|
.withFallback(ConfigFactory.load("factorial"))
|
||||||
|
|
||||||
val system = ActorSystem("ClusterSystem", config)
|
val system = ActorSystem("ClusterSystem", config)
|
||||||
system.actorOf(Props[FactorialBackend], name = "factorialBackend")
|
system.actorOf(Props[FactorialBackend](), name = "factorialBackend")
|
||||||
|
|
||||||
system.actorOf(Props[MetricsListener], name = "metricsListener")
|
system.actorOf(Props[MetricsListener](), name = "metricsListener")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ abstract class FactorialFrontend3 extends Actor {
|
||||||
totalInstances = 100,
|
totalInstances = 100,
|
||||||
maxInstancesPerNode = 3,
|
maxInstancesPerNode = 3,
|
||||||
allowLocalRoutees = false,
|
allowLocalRoutees = false,
|
||||||
useRoles = Set("backend"))).props(Props[FactorialBackend]),
|
useRoles = Set("backend"))).props(Props[FactorialBackend]()),
|
||||||
name = "factorialBackendRouter3")
|
name = "factorialBackendRouter3")
|
||||||
//#router-deploy-in-code
|
//#router-deploy-in-code
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,6 @@ object TransformationBackend {
|
||||||
.withFallback(ConfigFactory.load())
|
.withFallback(ConfigFactory.load())
|
||||||
|
|
||||||
val system = ActorSystem("ClusterSystem", config)
|
val system = ActorSystem("ClusterSystem", config)
|
||||||
system.actorOf(Props[TransformationBackend], name = "backend")
|
system.actorOf(Props[TransformationBackend](), name = "backend")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ object TransformationFrontend {
|
||||||
.withFallback(ConfigFactory.load())
|
.withFallback(ConfigFactory.load())
|
||||||
|
|
||||||
val system = ActorSystem("ClusterSystem", config)
|
val system = ActorSystem("ClusterSystem", config)
|
||||||
val frontend = system.actorOf(Props[TransformationFrontend], name = "frontend")
|
val frontend = system.actorOf(Props[TransformationFrontend](), name = "frontend")
|
||||||
|
|
||||||
val counter = new AtomicInteger
|
val counter = new AtomicInteger
|
||||||
import system.dispatcher
|
import system.dispatcher
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class SampleLease(settings: LeaseSettings) extends Lease(settings) {
|
||||||
|
|
||||||
object LeaseDocSpec {
|
object LeaseDocSpec {
|
||||||
|
|
||||||
def config() =
|
def config =
|
||||||
ConfigFactory.parseString("""
|
ConfigFactory.parseString("""
|
||||||
jdocs-lease.lease-class = "jdocs.coordination.LeaseDocTest$SampleLease"
|
jdocs-lease.lease-class = "jdocs.coordination.LeaseDocTest$SampleLease"
|
||||||
#lease-config
|
#lease-config
|
||||||
|
|
|
||||||
|
|
@ -240,11 +240,11 @@ object DispatcherDocSpec {
|
||||||
extends UnboundedStablePriorityMailbox(
|
extends UnboundedStablePriorityMailbox(
|
||||||
// Create a new PriorityGenerator, lower prio means more important
|
// Create a new PriorityGenerator, lower prio means more important
|
||||||
PriorityGenerator {
|
PriorityGenerator {
|
||||||
// 'highpriority messages should be treated first if possible
|
// highpriority messages should be treated first if possible
|
||||||
case 'highpriority => 0
|
case "highpriority" => 0
|
||||||
|
|
||||||
// 'lowpriority messages should be treated last if possible
|
// lowpriority messages should be treated last if possible
|
||||||
case 'lowpriority => 2
|
case "lowpriority" => 2
|
||||||
|
|
||||||
// PoisonPill when no other left
|
// PoisonPill when no other left
|
||||||
case PoisonPill => 3
|
case PoisonPill => 3
|
||||||
|
|
@ -293,7 +293,7 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
val context = system
|
val context = system
|
||||||
//#defining-dispatcher-in-config
|
//#defining-dispatcher-in-config
|
||||||
import akka.actor.Props
|
import akka.actor.Props
|
||||||
val myActor = context.actorOf(Props[MyActor], "myactor")
|
val myActor = context.actorOf(Props[MyActor](), "myactor")
|
||||||
//#defining-dispatcher-in-config
|
//#defining-dispatcher-in-config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -302,7 +302,7 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
//#defining-dispatcher-in-code
|
//#defining-dispatcher-in-code
|
||||||
import akka.actor.Props
|
import akka.actor.Props
|
||||||
val myActor =
|
val myActor =
|
||||||
context.actorOf(Props[MyActor].withDispatcher("my-dispatcher"), "myactor1")
|
context.actorOf(Props[MyActor]().withDispatcher("my-dispatcher"), "myactor1")
|
||||||
//#defining-dispatcher-in-code
|
//#defining-dispatcher-in-code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -314,7 +314,7 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
val context = system
|
val context = system
|
||||||
//#defining-fixed-pool-size-dispatcher
|
//#defining-fixed-pool-size-dispatcher
|
||||||
val myActor =
|
val myActor =
|
||||||
context.actorOf(Props[MyActor].withDispatcher("blocking-io-dispatcher"), "myactor2")
|
context.actorOf(Props[MyActor]().withDispatcher("blocking-io-dispatcher"), "myactor2")
|
||||||
//#defining-fixed-pool-size-dispatcher
|
//#defining-fixed-pool-size-dispatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,7 +322,7 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
val context = system
|
val context = system
|
||||||
//#defining-pinned-dispatcher
|
//#defining-pinned-dispatcher
|
||||||
val myActor =
|
val myActor =
|
||||||
context.actorOf(Props[MyActor].withDispatcher("my-pinned-dispatcher"), "myactor3")
|
context.actorOf(Props[MyActor]().withDispatcher("my-pinned-dispatcher"), "myactor3")
|
||||||
//#defining-pinned-dispatcher
|
//#defining-pinned-dispatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -330,7 +330,7 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
val context = system
|
val context = system
|
||||||
//#defining-affinity-pool-dispatcher
|
//#defining-affinity-pool-dispatcher
|
||||||
val myActor =
|
val myActor =
|
||||||
context.actorOf(Props[MyActor].withDispatcher("affinity-pool-dispatcher"), "myactor4")
|
context.actorOf(Props[MyActor]().withDispatcher("affinity-pool-dispatcher"), "myactor4")
|
||||||
//#defining-affinity-pool-dispatcher
|
//#defining-affinity-pool-dispatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -345,7 +345,7 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
val context = system
|
val context = system
|
||||||
//#defining-mailbox-in-config
|
//#defining-mailbox-in-config
|
||||||
import akka.actor.Props
|
import akka.actor.Props
|
||||||
val myActor = context.actorOf(Props[MyActor], "priomailboxactor")
|
val myActor = context.actorOf(Props[MyActor](), "priomailboxactor")
|
||||||
//#defining-mailbox-in-config
|
//#defining-mailbox-in-config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -353,13 +353,13 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
val context = system
|
val context = system
|
||||||
//#defining-mailbox-in-code
|
//#defining-mailbox-in-code
|
||||||
import akka.actor.Props
|
import akka.actor.Props
|
||||||
val myActor = context.actorOf(Props[MyActor].withMailbox("prio-mailbox"))
|
val myActor = context.actorOf(Props[MyActor]().withMailbox("prio-mailbox"))
|
||||||
//#defining-mailbox-in-code
|
//#defining-mailbox-in-code
|
||||||
}
|
}
|
||||||
|
|
||||||
"using a required mailbox" in {
|
"using a required mailbox" in {
|
||||||
val context = system
|
val context = system
|
||||||
val myActor = context.actorOf(Props[MyBoundedActor])
|
val myActor = context.actorOf(Props[MyBoundedActor]())
|
||||||
}
|
}
|
||||||
|
|
||||||
"defining priority dispatcher" in {
|
"defining priority dispatcher" in {
|
||||||
|
|
@ -370,13 +370,14 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
class Logger extends Actor {
|
class Logger extends Actor {
|
||||||
val log: LoggingAdapter = Logging(context.system, this)
|
val log: LoggingAdapter = Logging(context.system, this)
|
||||||
|
|
||||||
self ! 'lowpriority
|
self ! "lowpriority"
|
||||||
self ! 'lowpriority
|
self ! "lowpriority"
|
||||||
self ! 'highpriority
|
self ! "highpriority"
|
||||||
self ! 'pigdog
|
self ! "pigdog"
|
||||||
self ! 'pigdog2
|
self ! "pigdog2"
|
||||||
self ! 'pigdog3
|
self ! "pigdog3"
|
||||||
self ! 'highpriority
|
self ! "highpriority"
|
||||||
|
|
||||||
self ! PoisonPill
|
self ! PoisonPill
|
||||||
|
|
||||||
def receive = {
|
def receive = {
|
||||||
|
|
@ -387,13 +388,13 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Logs:
|
* Logs:
|
||||||
* 'highpriority
|
* highpriority
|
||||||
* 'highpriority
|
* highpriority
|
||||||
* 'pigdog
|
* pigdog
|
||||||
* 'pigdog2
|
* pigdog2
|
||||||
* 'pigdog3
|
* pigdog3
|
||||||
* 'lowpriority
|
* lowpriority
|
||||||
* 'lowpriority
|
* lowpriority
|
||||||
*/
|
*/
|
||||||
//#prio-dispatcher
|
//#prio-dispatcher
|
||||||
|
|
||||||
|
|
@ -410,8 +411,8 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
class Logger extends Actor {
|
class Logger extends Actor {
|
||||||
val log: LoggingAdapter = Logging(context.system, this)
|
val log: LoggingAdapter = Logging(context.system, this)
|
||||||
|
|
||||||
self ! 'foo
|
self ! "foo"
|
||||||
self ! 'bar
|
self ! "bar"
|
||||||
self ! MyControlMessage
|
self ! MyControlMessage
|
||||||
self ! PoisonPill
|
self ! PoisonPill
|
||||||
|
|
||||||
|
|
@ -424,8 +425,8 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
/*
|
/*
|
||||||
* Logs:
|
* Logs:
|
||||||
* MyControlMessage
|
* MyControlMessage
|
||||||
* 'foo
|
* foo
|
||||||
* 'bar
|
* bar
|
||||||
*/
|
*/
|
||||||
//#control-aware-dispatcher
|
//#control-aware-dispatcher
|
||||||
|
|
||||||
|
|
@ -435,11 +436,11 @@ class DispatcherDocSpec extends AkkaSpec(DispatcherDocSpec.config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
"require custom mailbox on dispatcher" in {
|
"require custom mailbox on dispatcher" in {
|
||||||
val myActor = system.actorOf(Props[MyActor].withDispatcher("custom-dispatcher"))
|
val myActor = system.actorOf(Props[MyActor]().withDispatcher("custom-dispatcher"))
|
||||||
}
|
}
|
||||||
|
|
||||||
"require custom mailbox on actor" in {
|
"require custom mailbox on actor" in {
|
||||||
val myActor = system.actorOf(Props[MySpecialActor])
|
val myActor = system.actorOf(Props[MySpecialActor]())
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ object EventBusDocSpec {
|
||||||
|
|
||||||
// determines the initial size of the index data structure
|
// determines the initial size of the index data structure
|
||||||
// used internally (i.e. the expected number of different classifiers)
|
// used internally (i.e. the expected number of different classifiers)
|
||||||
override protected def mapSize: Int = 128
|
override protected def mapSize(): Int = 128
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,7 +199,7 @@ class EventBusDocSpec extends AkkaSpec {
|
||||||
probe2.expectMsg(Notification(observer1, 100))
|
probe2.expectMsg(Notification(observer1, 100))
|
||||||
actorBus.publish(Notification(observer2, 101))
|
actorBus.publish(Notification(observer2, 101))
|
||||||
probe2.expectMsg(Notification(observer2, 101))
|
probe2.expectMsg(Notification(observer2, 101))
|
||||||
probe1.expectNoMsg(500.millis)
|
probe1.expectNoMessage(500.millis)
|
||||||
//#actor-bus-test
|
//#actor-bus-test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -146,17 +146,17 @@ class LoggingDocSpec extends AkkaSpec {
|
||||||
import LoggingDocSpec.{ MdcActor, MdcActorMixin, MyActor, Req }
|
import LoggingDocSpec.{ MdcActor, MdcActorMixin, MyActor, Req }
|
||||||
|
|
||||||
"use a logging actor" in {
|
"use a logging actor" in {
|
||||||
val myActor = system.actorOf(Props[MyActor])
|
val myActor = system.actorOf(Props[MyActor]())
|
||||||
myActor ! "test"
|
myActor ! "test"
|
||||||
}
|
}
|
||||||
|
|
||||||
"use a MDC logging actor" in {
|
"use a MDC logging actor" in {
|
||||||
val mdcActor = system.actorOf(Props[MdcActor])
|
val mdcActor = system.actorOf(Props[MdcActor]())
|
||||||
mdcActor ! "some request"
|
mdcActor ! "some request"
|
||||||
}
|
}
|
||||||
|
|
||||||
"use a MDC logging actor by mixin" in {
|
"use a MDC logging actor by mixin" in {
|
||||||
val mdcActor = system.actorOf(Props[MdcActorMixin])
|
val mdcActor = system.actorOf(Props[MdcActorMixin]())
|
||||||
mdcActor ! Req("some request", 5678)
|
mdcActor ! Req("some request", 5678)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,7 +164,7 @@ class LoggingDocSpec extends AkkaSpec {
|
||||||
import LoggingDocSpec.Listeners._
|
import LoggingDocSpec.Listeners._
|
||||||
//#deadletters
|
//#deadletters
|
||||||
|
|
||||||
val listener = system.actorOf(Props[DeadLetterListener])
|
val listener = system.actorOf(Props[DeadLetterListener]())
|
||||||
system.eventStream.subscribe(listener, classOf[DeadLetter])
|
system.eventStream.subscribe(listener, classOf[DeadLetter])
|
||||||
//#deadletters
|
//#deadletters
|
||||||
}
|
}
|
||||||
|
|
@ -173,8 +173,8 @@ class LoggingDocSpec extends AkkaSpec {
|
||||||
import LoggingDocSpec.Listeners._
|
import LoggingDocSpec.Listeners._
|
||||||
//#superclass-subscription-eventstream
|
//#superclass-subscription-eventstream
|
||||||
|
|
||||||
val jazzListener = system.actorOf(Props[Listener])
|
val jazzListener = system.actorOf(Props[Listener]())
|
||||||
val musicListener = system.actorOf(Props[Listener])
|
val musicListener = system.actorOf(Props[Listener]())
|
||||||
system.eventStream.subscribe(jazzListener, classOf[Jazz])
|
system.eventStream.subscribe(jazzListener, classOf[Jazz])
|
||||||
system.eventStream.subscribe(musicListener, classOf[AllKindsOfMusic])
|
system.eventStream.subscribe(musicListener, classOf[AllKindsOfMusic])
|
||||||
|
|
||||||
|
|
@ -188,7 +188,7 @@ class LoggingDocSpec extends AkkaSpec {
|
||||||
|
|
||||||
"allow registration to suppressed dead letters" in {
|
"allow registration to suppressed dead letters" in {
|
||||||
import akka.actor.Props
|
import akka.actor.Props
|
||||||
val listener = system.actorOf(Props[MyActor])
|
val listener = system.actorOf(Props[MyActor]())
|
||||||
|
|
||||||
//#suppressed-deadletters
|
//#suppressed-deadletters
|
||||||
import akka.actor.SuppressedDeadLetter
|
import akka.actor.SuppressedDeadLetter
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ class ExtensionDocSpec extends AkkaSpec(ExtensionDocSpec.config) {
|
||||||
|
|
||||||
"demonstrate how to create an extension in Scala" in {
|
"demonstrate how to create an extension in Scala" in {
|
||||||
//#extension-usage
|
//#extension-usage
|
||||||
CountExtension(system).increment
|
CountExtension(system).increment()
|
||||||
//#extension-usage
|
//#extension-usage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import akka.testkit.AkkaSpec
|
||||||
class SettingsImpl(config: Config) extends Extension {
|
class SettingsImpl(config: Config) extends Extension {
|
||||||
val DbUri: String = config.getString("myapp.db.uri")
|
val DbUri: String = config.getString("myapp.db.uri")
|
||||||
val CircuitBreakerTimeout: Duration =
|
val CircuitBreakerTimeout: Duration =
|
||||||
Duration(config.getMilliseconds("myapp.circuit-breaker.timeout"), TimeUnit.MILLISECONDS)
|
Duration(config.getDuration("myapp.circuit-breaker.timeout", TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS)
|
||||||
}
|
}
|
||||||
//#extension
|
//#extension
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@ class FutureDocSpec extends AkkaSpec {
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate usage of blocking from actor" in {
|
"demonstrate usage of blocking from actor" in {
|
||||||
val actor = system.actorOf(Props[MyActor])
|
val actor = system.actorOf(Props[MyActor]())
|
||||||
val msg = "hello"
|
val msg = "hello"
|
||||||
//#ask-blocking
|
//#ask-blocking
|
||||||
import scala.concurrent.Await
|
import scala.concurrent.Await
|
||||||
|
|
@ -167,7 +167,7 @@ class FutureDocSpec extends AkkaSpec {
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate usage of mapTo" in {
|
"demonstrate usage of mapTo" in {
|
||||||
val actor = system.actorOf(Props[MyActor])
|
val actor = system.actorOf(Props[MyActor]())
|
||||||
val msg = "hello"
|
val msg = "hello"
|
||||||
implicit val timeout = Timeout(5 seconds)
|
implicit val timeout = Timeout(5 seconds)
|
||||||
//#map-to
|
//#map-to
|
||||||
|
|
@ -280,9 +280,9 @@ class FutureDocSpec extends AkkaSpec {
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate wrong way of composing" in {
|
"demonstrate wrong way of composing" in {
|
||||||
val actor1 = system.actorOf(Props[MyActor])
|
val actor1 = system.actorOf(Props[MyActor]())
|
||||||
val actor2 = system.actorOf(Props[MyActor])
|
val actor2 = system.actorOf(Props[MyActor]())
|
||||||
val actor3 = system.actorOf(Props[MyActor])
|
val actor3 = system.actorOf(Props[MyActor]())
|
||||||
val msg1 = 1
|
val msg1 = 1
|
||||||
val msg2 = 2
|
val msg2 = 2
|
||||||
implicit val timeout = Timeout(5 seconds)
|
implicit val timeout = Timeout(5 seconds)
|
||||||
|
|
@ -304,9 +304,9 @@ class FutureDocSpec extends AkkaSpec {
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate composing" in {
|
"demonstrate composing" in {
|
||||||
val actor1 = system.actorOf(Props[MyActor])
|
val actor1 = system.actorOf(Props[MyActor]())
|
||||||
val actor2 = system.actorOf(Props[MyActor])
|
val actor2 = system.actorOf(Props[MyActor]())
|
||||||
val actor3 = system.actorOf(Props[MyActor])
|
val actor3 = system.actorOf(Props[MyActor]())
|
||||||
val msg1 = 1
|
val msg1 = 1
|
||||||
val msg2 = 2
|
val msg2 = 2
|
||||||
implicit val timeout = Timeout(5 seconds)
|
implicit val timeout = Timeout(5 seconds)
|
||||||
|
|
@ -331,7 +331,7 @@ class FutureDocSpec extends AkkaSpec {
|
||||||
|
|
||||||
"demonstrate usage of sequence with actors" in {
|
"demonstrate usage of sequence with actors" in {
|
||||||
implicit val timeout = Timeout(5 seconds)
|
implicit val timeout = Timeout(5 seconds)
|
||||||
val oddActor = system.actorOf(Props[OddActor])
|
val oddActor = system.actorOf(Props[OddActor]())
|
||||||
//#sequence-ask
|
//#sequence-ask
|
||||||
// oddActor returns odd numbers sequentially from 1 as a List[Future[Int]]
|
// oddActor returns odd numbers sequentially from 1 as a List[Future[Int]]
|
||||||
val listOfFutures = List.fill(100)(akka.pattern.ask(oddActor, GetNext).mapTo[Int])
|
val listOfFutures = List.fill(100)(akka.pattern.ask(oddActor, GetNext).mapTo[Int])
|
||||||
|
|
@ -368,7 +368,7 @@ class FutureDocSpec extends AkkaSpec {
|
||||||
//#fold
|
//#fold
|
||||||
// Create a sequence of Futures
|
// Create a sequence of Futures
|
||||||
val futures = for (i <- 1 to 1000) yield Future(i * 2)
|
val futures = for (i <- 1 to 1000) yield Future(i * 2)
|
||||||
val futureSum = Future.fold(futures)(0)(_ + _)
|
val futureSum = Future.foldLeft(futures)(0)(_ + _)
|
||||||
futureSum.foreach(println)
|
futureSum.foreach(println)
|
||||||
//#fold
|
//#fold
|
||||||
Await.result(futureSum, 3 seconds) should be(1001000)
|
Await.result(futureSum, 3 seconds) should be(1001000)
|
||||||
|
|
@ -378,7 +378,7 @@ class FutureDocSpec extends AkkaSpec {
|
||||||
//#reduce
|
//#reduce
|
||||||
// Create a sequence of Futures
|
// Create a sequence of Futures
|
||||||
val futures = for (i <- 1 to 1000) yield Future(i * 2)
|
val futures = for (i <- 1 to 1000) yield Future(i * 2)
|
||||||
val futureSum = Future.reduce(futures)(_ + _)
|
val futureSum = Future.reduceLeft(futures)(_ + _)
|
||||||
futureSum.foreach(println)
|
futureSum.foreach(println)
|
||||||
//#reduce
|
//#reduce
|
||||||
Await.result(futureSum, 3 seconds) should be(1001000)
|
Await.result(futureSum, 3 seconds) should be(1001000)
|
||||||
|
|
@ -386,7 +386,7 @@ class FutureDocSpec extends AkkaSpec {
|
||||||
|
|
||||||
"demonstrate usage of recover" in {
|
"demonstrate usage of recover" in {
|
||||||
implicit val timeout = Timeout(5 seconds)
|
implicit val timeout = Timeout(5 seconds)
|
||||||
val actor = system.actorOf(Props[MyActor])
|
val actor = system.actorOf(Props[MyActor]())
|
||||||
val msg1 = -1
|
val msg1 = -1
|
||||||
//#recover
|
//#recover
|
||||||
val future = akka.pattern.ask(actor, msg1).recover {
|
val future = akka.pattern.ask(actor, msg1).recover {
|
||||||
|
|
@ -399,7 +399,7 @@ class FutureDocSpec extends AkkaSpec {
|
||||||
|
|
||||||
"demonstrate usage of recoverWith" in {
|
"demonstrate usage of recoverWith" in {
|
||||||
implicit val timeout = Timeout(5 seconds)
|
implicit val timeout = Timeout(5 seconds)
|
||||||
val actor = system.actorOf(Props[MyActor])
|
val actor = system.actorOf(Props[MyActor]())
|
||||||
val msg1 = -1
|
val msg1 = -1
|
||||||
//#try-recover
|
//#try-recover
|
||||||
val future = akka.pattern.ask(actor, msg1).recoverWith {
|
val future = akka.pattern.ask(actor, msg1).recoverWith {
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class Server extends Actor {
|
||||||
//#server
|
//#server
|
||||||
context.parent ! c
|
context.parent ! c
|
||||||
//#server
|
//#server
|
||||||
val handler = context.actorOf(Props[SimplisticHandler])
|
val handler = context.actorOf(Props[SimplisticHandler]())
|
||||||
val connection = sender()
|
val connection = sender()
|
||||||
connection ! Register(handler)
|
connection ! Register(handler)
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +106,7 @@ class Client(remote: InetSocketAddress, listener: ActorRef) extends Actor {
|
||||||
class IODocSpec extends AkkaSpec {
|
class IODocSpec extends AkkaSpec {
|
||||||
|
|
||||||
class Parent extends Actor {
|
class Parent extends Actor {
|
||||||
context.actorOf(Props[Server], "server")
|
context.actorOf(Props[Server](), "server")
|
||||||
def receive = {
|
def receive = {
|
||||||
case msg => testActor.forward(msg)
|
case msg => testActor.forward(msg)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ object PullReadingExample {
|
||||||
|
|
||||||
import context.system
|
import context.system
|
||||||
|
|
||||||
override def preStart: Unit =
|
override def preStart(): Unit =
|
||||||
//#pull-mode-bind
|
//#pull-mode-bind
|
||||||
IO(Tcp) ! Bind(self, new InetSocketAddress("localhost", 0), pullMode = true)
|
IO(Tcp) ! Bind(self, new InetSocketAddress("localhost", 0), pullMode = true)
|
||||||
//#pull-mode-bind
|
//#pull-mode-bind
|
||||||
|
|
@ -51,7 +51,7 @@ object PullReadingExample {
|
||||||
class PullEcho(connection: ActorRef) extends Actor {
|
class PullEcho(connection: ActorRef) extends Actor {
|
||||||
|
|
||||||
//#pull-reading-echo
|
//#pull-reading-echo
|
||||||
override def preStart: Unit = connection ! ResumeReading
|
override def preStart(): Unit = connection ! ResumeReading
|
||||||
|
|
||||||
def receive = {
|
def receive = {
|
||||||
case Received(data) => connection ! Write(data, Ack)
|
case Received(data) => connection ! Write(data, Ack)
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ abstract class UdpDocSpec extends AkkaSpec {
|
||||||
listener ! Udp.SuspendReading
|
listener ! Udp.SuspendReading
|
||||||
Thread.sleep(1000) // no way to find out when the above is finished
|
Thread.sleep(1000) // no way to find out when the above is finished
|
||||||
val send = system.actorOf(simpleSenderProps(local))
|
val send = system.actorOf(simpleSenderProps(local))
|
||||||
probe.expectNoMsg(500.millis)
|
probe.expectNoMessage(500.millis)
|
||||||
listener ! Udp.ResumeReading
|
listener ! Udp.ResumeReading
|
||||||
probe.expectMsg("hello")
|
probe.expectMsg("hello")
|
||||||
send ! "world"
|
send ! "world"
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import scala.collection.immutable
|
||||||
|
|
||||||
class PersistenceEventAdapterDocSpec(config: String) extends AkkaSpec(config) {
|
class PersistenceEventAdapterDocSpec(config: String) extends AkkaSpec(config) {
|
||||||
|
|
||||||
def this() {
|
def this() = {
|
||||||
this("""
|
this("""
|
||||||
akka.persistence.snapshot-store.plugin = "akka.persistence.snapshot-store.local"
|
akka.persistence.snapshot-store.plugin = "akka.persistence.snapshot-store.local"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ trait SharedLeveldbPluginDocSpec {
|
||||||
//#shared-store-creation
|
//#shared-store-creation
|
||||||
import akka.persistence.journal.leveldb.SharedLeveldbStore
|
import akka.persistence.journal.leveldb.SharedLeveldbStore
|
||||||
|
|
||||||
val store = system.actorOf(Props[SharedLeveldbStore], "store")
|
val store = system.actorOf(Props[SharedLeveldbStore](), "store")
|
||||||
//#shared-store-creation
|
//#shared-store-creation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class ExamplePersistentActor extends PersistentActor {
|
||||||
object PersistentActorExample extends App {
|
object PersistentActorExample extends App {
|
||||||
|
|
||||||
val system = ActorSystem("example")
|
val system = ActorSystem("example")
|
||||||
val persistentActor = system.actorOf(Props[ExamplePersistentActor], "persistentActor-4-scala")
|
val persistentActor = system.actorOf(Props[ExamplePersistentActor](), "persistentActor-4-scala")
|
||||||
|
|
||||||
persistentActor ! Cmd("foo")
|
persistentActor ! Cmd("foo")
|
||||||
persistentActor ! Cmd("baz")
|
persistentActor ! Cmd("baz")
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ object LeveldbPersistenceQueryDocSpec {
|
||||||
val colors = Set("green", "black", "blue")
|
val colors = Set("green", "black", "blue")
|
||||||
override def toJournal(event: Any): Any = event match {
|
override def toJournal(event: Any): Any = event match {
|
||||||
case s: String =>
|
case s: String =>
|
||||||
var tags = colors.foldLeft(Set.empty[String]) { (acc, c) =>
|
val tags = colors.foldLeft(Set.empty[String]) { (acc, c) =>
|
||||||
if (s.contains(c)) acc + c else acc
|
if (s.contains(c)) acc + c else acc
|
||||||
}
|
}
|
||||||
if (tags.isEmpty) event
|
if (tags.isEmpty) event
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class MyEventsByTagSource(tag: String, offset: Long, refreshInterval: FiniteDura
|
||||||
tryPush()
|
tryPush()
|
||||||
}
|
}
|
||||||
|
|
||||||
override def onDownstreamFinish(): Unit = {
|
override def onDownstreamFinish(cause: Throwable): Unit = {
|
||||||
// close connection if responsible for doing so
|
// close connection if responsible for doing so
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +94,8 @@ class MyEventsByTagSource(tag: String, offset: Long, refreshInterval: FiniteDura
|
||||||
Offset.sequence(currentOffset),
|
Offset.sequence(currentOffset),
|
||||||
rs.getString("persistence_id"),
|
rs.getString("persistence_id"),
|
||||||
rs.getLong("seq_nr"),
|
rs.getLong("seq_nr"),
|
||||||
deserialized)
|
deserialized,
|
||||||
|
System.currentTimeMillis())
|
||||||
}
|
}
|
||||||
b.result()
|
b.result()
|
||||||
} finally s.close()
|
} finally s.close()
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,7 @@ object PersistenceQueryDocSpec {
|
||||||
class PersistenceQueryDocSpec(s: String) extends AkkaSpec(s) {
|
class PersistenceQueryDocSpec(s: String) extends AkkaSpec(s) {
|
||||||
import PersistenceQueryDocSpec._
|
import PersistenceQueryDocSpec._
|
||||||
|
|
||||||
def this() {
|
def this() = {
|
||||||
this("""
|
this("""
|
||||||
akka.persistence.query.my-read-journal {
|
akka.persistence.query.my-read-journal {
|
||||||
class = "docs.persistence.query.PersistenceQueryDocSpec$MyReadJournalProvider"
|
class = "docs.persistence.query.PersistenceQueryDocSpec$MyReadJournalProvider"
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
package docs.persistence.testkit
|
package docs.persistence.testkit
|
||||||
|
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
import akka.Done
|
import akka.Done
|
||||||
import akka.actor.testkit.typed.scaladsl.ScalaTestWithActorTestKit
|
import akka.actor.testkit.typed.scaladsl.ScalaTestWithActorTestKit
|
||||||
import org.scalatest.wordspec.AnyWordSpecLike
|
import org.scalatest.wordspec.AnyWordSpecLike
|
||||||
|
|
@ -17,14 +19,11 @@ import scala.concurrent.duration._
|
||||||
|
|
||||||
//#imports
|
//#imports
|
||||||
|
|
||||||
class PersistenceInitSpec
|
class PersistenceInitSpec extends ScalaTestWithActorTestKit(s"""
|
||||||
extends ScalaTestWithActorTestKit(
|
|
||||||
"""
|
|
||||||
akka.persistence.journal.plugin = "akka.persistence.journal.inmem"
|
akka.persistence.journal.plugin = "akka.persistence.journal.inmem"
|
||||||
akka.persistence.snapshot-store.plugin = "akka.persistence.snapshot-store.local"
|
akka.persistence.snapshot-store.plugin = "akka.persistence.snapshot-store.local"
|
||||||
akka.persistence.snapshot-store.local.dir = "target/snapshot-${UUID.randomUUID().toString}"
|
akka.persistence.snapshot-store.local.dir = "target/snapshot-${UUID.randomUUID().toString}"
|
||||||
""")
|
""") with AnyWordSpecLike {
|
||||||
with AnyWordSpecLike {
|
|
||||||
|
|
||||||
"PersistenceInit" should {
|
"PersistenceInit" should {
|
||||||
"initialize plugins" in {
|
"initialize plugins" in {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class RemoteDeploymentDocSpec extends AkkaSpec("""
|
||||||
|
|
||||||
"demonstrate programmatic deployment" in {
|
"demonstrate programmatic deployment" in {
|
||||||
//#deploy
|
//#deploy
|
||||||
val ref = system.actorOf(Props[SampleActor].withDeploy(Deploy(scope = RemoteScope(address))))
|
val ref = system.actorOf(Props[SampleActor]().withDeploy(Deploy(scope = RemoteScope(address))))
|
||||||
//#deploy
|
//#deploy
|
||||||
ref.path.address should be(address)
|
ref.path.address should be(address)
|
||||||
ref ! "test"
|
ref ! "test"
|
||||||
|
|
@ -61,7 +61,7 @@ class RemoteDeploymentDocSpec extends AkkaSpec("""
|
||||||
"demonstrate sampleActor" in {
|
"demonstrate sampleActor" in {
|
||||||
//#sample-actor
|
//#sample-actor
|
||||||
|
|
||||||
val actor = system.actorOf(Props[SampleActor], "sampleActor")
|
val actor = system.actorOf(Props[SampleActor](), "sampleActor")
|
||||||
actor ! "Pretty slick"
|
actor ! "Pretty slick"
|
||||||
//#sample-actor
|
//#sample-actor
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ class ConsistentHashingRouterDocSpec extends AkkaSpec with ImplicitSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
val cache: ActorRef =
|
val cache: ActorRef =
|
||||||
context.actorOf(ConsistentHashingPool(10, hashMapping = hashMapping).props(Props[Cache]), name = "cache")
|
context.actorOf(ConsistentHashingPool(10, hashMapping = hashMapping).props(Props[Cache]()), name = "cache")
|
||||||
|
|
||||||
cache ! ConsistentHashableEnvelope(message = Entry("hello", "HELLO"), hashKey = "hello")
|
cache ! ConsistentHashableEnvelope(message = Entry("hello", "HELLO"), hashKey = "hello")
|
||||||
cache ! ConsistentHashableEnvelope(message = Entry("hi", "HI"), hashKey = "hi")
|
cache ! ConsistentHashableEnvelope(message = Entry("hi", "HI"), hashKey = "hi")
|
||||||
|
|
|
||||||
|
|
@ -117,7 +117,7 @@ class CustomRouterDocSpec extends AkkaSpec(CustomRouterDocSpec.config) with Impl
|
||||||
|
|
||||||
"demonstrate usage of custom router" in {
|
"demonstrate usage of custom router" in {
|
||||||
//#usage-1
|
//#usage-1
|
||||||
for (n <- 1 to 10) system.actorOf(Props[Storage], "s" + n)
|
for (n <- 1 to 10) system.actorOf(Props[Storage](), "s" + n)
|
||||||
|
|
||||||
val paths = for (n <- 1 to 10) yield ("/user/s" + n)
|
val paths = for (n <- 1 to 10) yield ("/user/s" + n)
|
||||||
val redundancy1: ActorRef =
|
val redundancy1: ActorRef =
|
||||||
|
|
|
||||||
|
|
@ -299,7 +299,7 @@ router-dispatcher {}
|
||||||
class Master extends Actor {
|
class Master extends Actor {
|
||||||
var router = {
|
var router = {
|
||||||
val routees = Vector.fill(5) {
|
val routees = Vector.fill(5) {
|
||||||
val r = context.actorOf(Props[Worker])
|
val r = context.actorOf(Props[Worker]())
|
||||||
context.watch(r)
|
context.watch(r)
|
||||||
ActorRefRoutee(r)
|
ActorRefRoutee(r)
|
||||||
}
|
}
|
||||||
|
|
@ -311,7 +311,7 @@ router-dispatcher {}
|
||||||
router.route(w, sender())
|
router.route(w, sender())
|
||||||
case Terminated(a) =>
|
case Terminated(a) =>
|
||||||
router = router.removeRoutee(a)
|
router = router.removeRoutee(a)
|
||||||
val r = context.actorOf(Props[Worker])
|
val r = context.actorOf(Props[Worker]())
|
||||||
context.watch(r)
|
context.watch(r)
|
||||||
router = router.addRoutee(r)
|
router = router.addRoutee(r)
|
||||||
}
|
}
|
||||||
|
|
@ -326,9 +326,9 @@ router-dispatcher {}
|
||||||
|
|
||||||
//#create-worker-actors
|
//#create-worker-actors
|
||||||
class Workers extends Actor {
|
class Workers extends Actor {
|
||||||
context.actorOf(Props[Worker], name = "w1")
|
context.actorOf(Props[Worker](), name = "w1")
|
||||||
context.actorOf(Props[Worker], name = "w2")
|
context.actorOf(Props[Worker](), name = "w2")
|
||||||
context.actorOf(Props[Worker], name = "w3")
|
context.actorOf(Props[Worker](), name = "w3")
|
||||||
// ...
|
// ...
|
||||||
//#create-worker-actors
|
//#create-worker-actors
|
||||||
|
|
||||||
|
|
@ -345,12 +345,12 @@ router-dispatcher {}
|
||||||
|
|
||||||
//#round-robin-pool-1
|
//#round-robin-pool-1
|
||||||
val router1: ActorRef =
|
val router1: ActorRef =
|
||||||
context.actorOf(FromConfig.props(Props[Worker]), "router1")
|
context.actorOf(FromConfig.props(Props[Worker]()), "router1")
|
||||||
//#round-robin-pool-1
|
//#round-robin-pool-1
|
||||||
|
|
||||||
//#round-robin-pool-2
|
//#round-robin-pool-2
|
||||||
val router2: ActorRef =
|
val router2: ActorRef =
|
||||||
context.actorOf(RoundRobinPool(5).props(Props[Worker]), "router2")
|
context.actorOf(RoundRobinPool(5).props(Props[Worker]()), "router2")
|
||||||
//#round-robin-pool-2
|
//#round-robin-pool-2
|
||||||
|
|
||||||
//#round-robin-group-1
|
//#round-robin-group-1
|
||||||
|
|
@ -365,12 +365,12 @@ router-dispatcher {}
|
||||||
|
|
||||||
//#random-pool-1
|
//#random-pool-1
|
||||||
val router5: ActorRef =
|
val router5: ActorRef =
|
||||||
context.actorOf(FromConfig.props(Props[Worker]), "router5")
|
context.actorOf(FromConfig.props(Props[Worker]()), "router5")
|
||||||
//#random-pool-1
|
//#random-pool-1
|
||||||
|
|
||||||
//#random-pool-2
|
//#random-pool-2
|
||||||
val router6: ActorRef =
|
val router6: ActorRef =
|
||||||
context.actorOf(RandomPool(5).props(Props[Worker]), "router6")
|
context.actorOf(RandomPool(5).props(Props[Worker]()), "router6")
|
||||||
//#random-pool-2
|
//#random-pool-2
|
||||||
|
|
||||||
//#random-group-1
|
//#random-group-1
|
||||||
|
|
@ -385,17 +385,17 @@ router-dispatcher {}
|
||||||
|
|
||||||
//#balancing-pool-1
|
//#balancing-pool-1
|
||||||
val router9: ActorRef =
|
val router9: ActorRef =
|
||||||
context.actorOf(FromConfig.props(Props[Worker]), "router9")
|
context.actorOf(FromConfig.props(Props[Worker]()), "router9")
|
||||||
//#balancing-pool-1
|
//#balancing-pool-1
|
||||||
|
|
||||||
//#balancing-pool-2
|
//#balancing-pool-2
|
||||||
val router10: ActorRef =
|
val router10: ActorRef =
|
||||||
context.actorOf(BalancingPool(5).props(Props[Worker]), "router10")
|
context.actorOf(BalancingPool(5).props(Props[Worker]()), "router10")
|
||||||
//#balancing-pool-2
|
//#balancing-pool-2
|
||||||
|
|
||||||
// #balancing-pool-3
|
// #balancing-pool-3
|
||||||
val router10b: ActorRef =
|
val router10b: ActorRef =
|
||||||
context.actorOf(BalancingPool(20).props(Props[Worker]), "router10b")
|
context.actorOf(BalancingPool(20).props(Props[Worker]()), "router10b")
|
||||||
//#balancing-pool-3
|
//#balancing-pool-3
|
||||||
for (i <- 1 to 100) router10b ! i
|
for (i <- 1 to 100) router10b ! i
|
||||||
val threads10b = Thread.getAllStackTraces.keySet.asScala.filter { _.getName contains "router10b" }
|
val threads10b = Thread.getAllStackTraces.keySet.asScala.filter { _.getName contains "router10b" }
|
||||||
|
|
@ -406,22 +406,22 @@ router-dispatcher {}
|
||||||
|
|
||||||
//#smallest-mailbox-pool-1
|
//#smallest-mailbox-pool-1
|
||||||
val router11: ActorRef =
|
val router11: ActorRef =
|
||||||
context.actorOf(FromConfig.props(Props[Worker]), "router11")
|
context.actorOf(FromConfig.props(Props[Worker]()), "router11")
|
||||||
//#smallest-mailbox-pool-1
|
//#smallest-mailbox-pool-1
|
||||||
|
|
||||||
//#smallest-mailbox-pool-2
|
//#smallest-mailbox-pool-2
|
||||||
val router12: ActorRef =
|
val router12: ActorRef =
|
||||||
context.actorOf(SmallestMailboxPool(5).props(Props[Worker]), "router12")
|
context.actorOf(SmallestMailboxPool(5).props(Props[Worker]()), "router12")
|
||||||
//#smallest-mailbox-pool-2
|
//#smallest-mailbox-pool-2
|
||||||
|
|
||||||
//#broadcast-pool-1
|
//#broadcast-pool-1
|
||||||
val router13: ActorRef =
|
val router13: ActorRef =
|
||||||
context.actorOf(FromConfig.props(Props[Worker]), "router13")
|
context.actorOf(FromConfig.props(Props[Worker]()), "router13")
|
||||||
//#broadcast-pool-1
|
//#broadcast-pool-1
|
||||||
|
|
||||||
//#broadcast-pool-2
|
//#broadcast-pool-2
|
||||||
val router14: ActorRef =
|
val router14: ActorRef =
|
||||||
context.actorOf(BroadcastPool(5).props(Props[Worker]), "router14")
|
context.actorOf(BroadcastPool(5).props(Props[Worker]()), "router14")
|
||||||
//#broadcast-pool-2
|
//#broadcast-pool-2
|
||||||
|
|
||||||
//#broadcast-group-1
|
//#broadcast-group-1
|
||||||
|
|
@ -436,12 +436,12 @@ router-dispatcher {}
|
||||||
|
|
||||||
//#scatter-gather-pool-1
|
//#scatter-gather-pool-1
|
||||||
val router17: ActorRef =
|
val router17: ActorRef =
|
||||||
context.actorOf(FromConfig.props(Props[Worker]), "router17")
|
context.actorOf(FromConfig.props(Props[Worker]()), "router17")
|
||||||
//#scatter-gather-pool-1
|
//#scatter-gather-pool-1
|
||||||
|
|
||||||
//#scatter-gather-pool-2
|
//#scatter-gather-pool-2
|
||||||
val router18: ActorRef =
|
val router18: ActorRef =
|
||||||
context.actorOf(ScatterGatherFirstCompletedPool(5, within = 10.seconds).props(Props[Worker]), "router18")
|
context.actorOf(ScatterGatherFirstCompletedPool(5, within = 10.seconds).props(Props[Worker]()), "router18")
|
||||||
//#scatter-gather-pool-2
|
//#scatter-gather-pool-2
|
||||||
|
|
||||||
//#scatter-gather-group-1
|
//#scatter-gather-group-1
|
||||||
|
|
@ -456,12 +456,12 @@ router-dispatcher {}
|
||||||
|
|
||||||
//#tail-chopping-pool-1
|
//#tail-chopping-pool-1
|
||||||
val router21: ActorRef =
|
val router21: ActorRef =
|
||||||
context.actorOf(FromConfig.props(Props[Worker]), "router21")
|
context.actorOf(FromConfig.props(Props[Worker]()), "router21")
|
||||||
//#tail-chopping-pool-1
|
//#tail-chopping-pool-1
|
||||||
|
|
||||||
//#tail-chopping-pool-2
|
//#tail-chopping-pool-2
|
||||||
val router22: ActorRef =
|
val router22: ActorRef =
|
||||||
context.actorOf(TailChoppingPool(5, within = 10.seconds, interval = 20.millis).props(Props[Worker]), "router22")
|
context.actorOf(TailChoppingPool(5, within = 10.seconds, interval = 20.millis).props(Props[Worker]()), "router22")
|
||||||
//#tail-chopping-pool-2
|
//#tail-chopping-pool-2
|
||||||
|
|
||||||
//#tail-chopping-group-1
|
//#tail-chopping-group-1
|
||||||
|
|
@ -476,12 +476,12 @@ router-dispatcher {}
|
||||||
|
|
||||||
//#consistent-hashing-pool-1
|
//#consistent-hashing-pool-1
|
||||||
val router25: ActorRef =
|
val router25: ActorRef =
|
||||||
context.actorOf(FromConfig.props(Props[Worker]), "router25")
|
context.actorOf(FromConfig.props(Props[Worker]()), "router25")
|
||||||
//#consistent-hashing-pool-1
|
//#consistent-hashing-pool-1
|
||||||
|
|
||||||
//#consistent-hashing-pool-2
|
//#consistent-hashing-pool-2
|
||||||
val router26: ActorRef =
|
val router26: ActorRef =
|
||||||
context.actorOf(ConsistentHashingPool(5).props(Props[Worker]), "router26")
|
context.actorOf(ConsistentHashingPool(5).props(Props[Worker]()), "router26")
|
||||||
//#consistent-hashing-pool-2
|
//#consistent-hashing-pool-2
|
||||||
|
|
||||||
//#consistent-hashing-group-1
|
//#consistent-hashing-group-1
|
||||||
|
|
@ -496,18 +496,18 @@ router-dispatcher {}
|
||||||
|
|
||||||
//#resize-pool-1
|
//#resize-pool-1
|
||||||
val router29: ActorRef =
|
val router29: ActorRef =
|
||||||
context.actorOf(FromConfig.props(Props[Worker]), "router29")
|
context.actorOf(FromConfig.props(Props[Worker]()), "router29")
|
||||||
//#resize-pool-1
|
//#resize-pool-1
|
||||||
|
|
||||||
//#resize-pool-2
|
//#resize-pool-2
|
||||||
val resizer = DefaultResizer(lowerBound = 2, upperBound = 15)
|
val resizer = DefaultResizer(lowerBound = 2, upperBound = 15)
|
||||||
val router30: ActorRef =
|
val router30: ActorRef =
|
||||||
context.actorOf(RoundRobinPool(5, Some(resizer)).props(Props[Worker]), "router30")
|
context.actorOf(RoundRobinPool(5, Some(resizer)).props(Props[Worker]()), "router30")
|
||||||
//#resize-pool-2
|
//#resize-pool-2
|
||||||
|
|
||||||
//#optimal-size-exploring-resize-pool
|
//#optimal-size-exploring-resize-pool
|
||||||
val router31: ActorRef =
|
val router31: ActorRef =
|
||||||
context.actorOf(FromConfig.props(Props[Worker]), "router31")
|
context.actorOf(FromConfig.props(Props[Worker]()), "router31")
|
||||||
//#optimal-size-exploring-resize-pool
|
//#optimal-size-exploring-resize-pool
|
||||||
|
|
||||||
def receive = {
|
def receive = {
|
||||||
|
|
@ -528,11 +528,11 @@ class RouterDocSpec extends AkkaSpec(RouterDocSpec.config) with ImplicitSender {
|
||||||
import RouterDocSpec._
|
import RouterDocSpec._
|
||||||
|
|
||||||
//#create-workers
|
//#create-workers
|
||||||
system.actorOf(Props[Workers], "workers")
|
system.actorOf(Props[Workers](), "workers")
|
||||||
//#create-workers
|
//#create-workers
|
||||||
|
|
||||||
//#create-parent
|
//#create-parent
|
||||||
system.actorOf(Props[Parent], "parent")
|
system.actorOf(Props[Parent](), "parent")
|
||||||
//#create-parent
|
//#create-parent
|
||||||
|
|
||||||
"demonstrate dispatcher" in {
|
"demonstrate dispatcher" in {
|
||||||
|
|
@ -540,13 +540,13 @@ class RouterDocSpec extends AkkaSpec(RouterDocSpec.config) with ImplicitSender {
|
||||||
val router: ActorRef = system.actorOf(
|
val router: ActorRef = system.actorOf(
|
||||||
// “head” router actor will run on "router-dispatcher" dispatcher
|
// “head” router actor will run on "router-dispatcher" dispatcher
|
||||||
// Worker routees will run on "pool-dispatcher" dispatcher
|
// Worker routees will run on "pool-dispatcher" dispatcher
|
||||||
RandomPool(5, routerDispatcher = "router-dispatcher").props(Props[Worker]),
|
RandomPool(5, routerDispatcher = "router-dispatcher").props(Props[Worker]()),
|
||||||
name = "poolWithDispatcher")
|
name = "poolWithDispatcher")
|
||||||
//#dispatchers
|
//#dispatchers
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate broadcast" in {
|
"demonstrate broadcast" in {
|
||||||
val router = system.actorOf(RoundRobinPool(nrOfInstances = 5).props(Props[Echo]))
|
val router = system.actorOf(RoundRobinPool(nrOfInstances = 5).props(Props[Echo]()))
|
||||||
//#broadcastDavyJonesWarning
|
//#broadcastDavyJonesWarning
|
||||||
import akka.routing.Broadcast
|
import akka.routing.Broadcast
|
||||||
router ! Broadcast("Watch out for Davy Jones' locker")
|
router ! Broadcast("Watch out for Davy Jones' locker")
|
||||||
|
|
@ -555,7 +555,7 @@ class RouterDocSpec extends AkkaSpec(RouterDocSpec.config) with ImplicitSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate PoisonPill" in {
|
"demonstrate PoisonPill" in {
|
||||||
val router = watch(system.actorOf(RoundRobinPool(nrOfInstances = 5).props(Props[Echo])))
|
val router = watch(system.actorOf(RoundRobinPool(nrOfInstances = 5).props(Props[Echo]())))
|
||||||
//#poisonPill
|
//#poisonPill
|
||||||
import akka.actor.PoisonPill
|
import akka.actor.PoisonPill
|
||||||
router ! PoisonPill
|
router ! PoisonPill
|
||||||
|
|
@ -564,7 +564,7 @@ class RouterDocSpec extends AkkaSpec(RouterDocSpec.config) with ImplicitSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate broadcast of PoisonPill" in {
|
"demonstrate broadcast of PoisonPill" in {
|
||||||
val router = watch(system.actorOf(RoundRobinPool(nrOfInstances = 5).props(Props[Echo])))
|
val router = watch(system.actorOf(RoundRobinPool(nrOfInstances = 5).props(Props[Echo]())))
|
||||||
//#broadcastPoisonPill
|
//#broadcastPoisonPill
|
||||||
import akka.actor.PoisonPill
|
import akka.actor.PoisonPill
|
||||||
import akka.routing.Broadcast
|
import akka.routing.Broadcast
|
||||||
|
|
@ -574,7 +574,7 @@ class RouterDocSpec extends AkkaSpec(RouterDocSpec.config) with ImplicitSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate Kill" in {
|
"demonstrate Kill" in {
|
||||||
val router = watch(system.actorOf(RoundRobinPool(nrOfInstances = 5).props(Props[Echo])))
|
val router = watch(system.actorOf(RoundRobinPool(nrOfInstances = 5).props(Props[Echo]())))
|
||||||
//#kill
|
//#kill
|
||||||
import akka.actor.Kill
|
import akka.actor.Kill
|
||||||
router ! Kill
|
router ! Kill
|
||||||
|
|
@ -583,7 +583,7 @@ class RouterDocSpec extends AkkaSpec(RouterDocSpec.config) with ImplicitSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
"demonstrate broadcast of Kill" in {
|
"demonstrate broadcast of Kill" in {
|
||||||
val router = watch(system.actorOf(RoundRobinPool(nrOfInstances = 5).props(Props[Echo])))
|
val router = watch(system.actorOf(RoundRobinPool(nrOfInstances = 5).props(Props[Echo]())))
|
||||||
//#broadcastKill
|
//#broadcastKill
|
||||||
import akka.actor.Kill
|
import akka.actor.Kill
|
||||||
import akka.routing.Broadcast
|
import akka.routing.Broadcast
|
||||||
|
|
@ -598,7 +598,7 @@ class RouterDocSpec extends AkkaSpec(RouterDocSpec.config) with ImplicitSender {
|
||||||
import akka.remote.routing.RemoteRouterConfig
|
import akka.remote.routing.RemoteRouterConfig
|
||||||
val addresses =
|
val addresses =
|
||||||
Seq(Address("akka", "remotesys", "otherhost", 1234), AddressFromURIString("akka://othersys@anotherhost:1234"))
|
Seq(Address("akka", "remotesys", "otherhost", 1234), AddressFromURIString("akka://othersys@anotherhost:1234"))
|
||||||
val routerRemote = system.actorOf(RemoteRouterConfig(RoundRobinPool(5), addresses).props(Props[Echo]))
|
val routerRemote = system.actorOf(RemoteRouterConfig(RoundRobinPool(5), addresses).props(Props[Echo]()))
|
||||||
//#remoteRoutees
|
//#remoteRoutees
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -609,7 +609,7 @@ class RouterDocSpec extends AkkaSpec(RouterDocSpec.config) with ImplicitSender {
|
||||||
import akka.remote.routing.RemoteRouterConfig
|
import akka.remote.routing.RemoteRouterConfig
|
||||||
val addresses =
|
val addresses =
|
||||||
Seq(Address("akka", "remotesys", "otherhost", 1234), AddressFromURIString("akka://othersys@anotherhost:1234"))
|
Seq(Address("akka", "remotesys", "otherhost", 1234), AddressFromURIString("akka://othersys@anotherhost:1234"))
|
||||||
val routerRemote = system.actorOf(RemoteRouterConfig(RoundRobinPool(5), addresses).props(Props[Echo]))
|
val routerRemote = system.actorOf(RemoteRouterConfig(RoundRobinPool(5), addresses).props(Props[Echo]()))
|
||||||
//#remoteRoutees-artery
|
//#remoteRoutees-artery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,10 @@
|
||||||
|
|
||||||
package docs.stream
|
package docs.stream
|
||||||
|
|
||||||
|
import akka.Done
|
||||||
import akka.NotUsed
|
import akka.NotUsed
|
||||||
import akka.actor.{ Actor, ActorSystem, Cancellable }
|
import akka.actor.{ Actor, ActorSystem, Cancellable }
|
||||||
|
import akka.stream.CompletionStrategy
|
||||||
import akka.stream.Materializer
|
import akka.stream.Materializer
|
||||||
import akka.stream.{ ClosedShape, FlowShape, OverflowStrategy }
|
import akka.stream.{ ClosedShape, FlowShape, OverflowStrategy }
|
||||||
import akka.stream.scaladsl._
|
import akka.stream.scaladsl._
|
||||||
|
|
@ -99,7 +101,7 @@ class FlowDocSpec extends AkkaSpec with CompileOnlySpec {
|
||||||
Source(List(1, 2, 3))
|
Source(List(1, 2, 3))
|
||||||
|
|
||||||
// Create a source from a Future
|
// Create a source from a Future
|
||||||
Source.fromFuture(Future.successful("Hello Streams!"))
|
Source.future(Future.successful("Hello Streams!"))
|
||||||
|
|
||||||
// Create a source from a single element
|
// Create a source from a single element
|
||||||
Source.single("only one element")
|
Source.single("only one element")
|
||||||
|
|
@ -227,8 +229,13 @@ class FlowDocSpec extends AkkaSpec with CompileOnlySpec {
|
||||||
|
|
||||||
"source pre-materialization" in {
|
"source pre-materialization" in {
|
||||||
//#source-prematerialization
|
//#source-prematerialization
|
||||||
|
val completeWithDone: PartialFunction[Any, CompletionStrategy] = { case Done => CompletionStrategy.immediately }
|
||||||
val matValuePoweredSource =
|
val matValuePoweredSource =
|
||||||
Source.actorRef[String](bufferSize = 100, overflowStrategy = OverflowStrategy.fail)
|
Source.actorRef[String](
|
||||||
|
completionMatcher = completeWithDone,
|
||||||
|
failureMatcher = PartialFunction.empty,
|
||||||
|
bufferSize = 100,
|
||||||
|
overflowStrategy = OverflowStrategy.fail)
|
||||||
|
|
||||||
val (actorRef, source) = matValuePoweredSource.preMaterialize()
|
val (actorRef, source) = matValuePoweredSource.preMaterialize()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class FlowStreamRefsDocSpec extends AkkaSpec with CompileOnlySpec {
|
||||||
//#offer-source
|
//#offer-source
|
||||||
|
|
||||||
//#offer-source-use
|
//#offer-source-use
|
||||||
val sourceActor = system.actorOf(Props[DataSource], "dataSource")
|
val sourceActor = system.actorOf(Props[DataSource](), "dataSource")
|
||||||
|
|
||||||
sourceActor ! RequestLogs(1337)
|
sourceActor ! RequestLogs(1337)
|
||||||
val offer = expectMsgType[LogsOffer]
|
val offer = expectMsgType[LogsOffer]
|
||||||
|
|
@ -87,7 +87,7 @@ class FlowStreamRefsDocSpec extends AkkaSpec with CompileOnlySpec {
|
||||||
def localMetrics(): Source[String, NotUsed] = Source.single("")
|
def localMetrics(): Source[String, NotUsed] = Source.single("")
|
||||||
|
|
||||||
//#offer-sink-use
|
//#offer-sink-use
|
||||||
val receiver = system.actorOf(Props[DataReceiver], "receiver")
|
val receiver = system.actorOf(Props[DataReceiver](), "receiver")
|
||||||
|
|
||||||
receiver ! PrepareUpload("system-42-tmp")
|
receiver ! PrepareUpload("system-42-tmp")
|
||||||
val ready = expectMsgType[MeasurementsSinkReady]
|
val ready = expectMsgType[MeasurementsSinkReady]
|
||||||
|
|
|
||||||
|
|
@ -506,7 +506,7 @@ class GraphStageDocSpec extends AkkaSpec {
|
||||||
if (buffer.isEmpty) {
|
if (buffer.isEmpty) {
|
||||||
downstreamWaiting = true
|
downstreamWaiting = true
|
||||||
} else {
|
} else {
|
||||||
val elem = buffer.dequeue
|
val elem = buffer.dequeue()
|
||||||
push(out, elem)
|
push(out, elem)
|
||||||
}
|
}
|
||||||
if (!bufferFull && !hasBeenPulled(in)) {
|
if (!bufferFull && !hasBeenPulled(in)) {
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@
|
||||||
|
|
||||||
package docs.stream
|
package docs.stream
|
||||||
|
|
||||||
import akka.NotUsed
|
|
||||||
|
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
|
|
||||||
|
import akka.Done
|
||||||
|
import akka.NotUsed
|
||||||
import akka.testkit.AkkaSpec
|
import akka.testkit.AkkaSpec
|
||||||
import akka.stream.scaladsl._
|
import akka.stream.scaladsl._
|
||||||
import akka.stream._
|
import akka.stream._
|
||||||
|
|
@ -134,7 +135,7 @@ class IntegrationDocSpec extends AkkaSpec(IntegrationDocSpec.config) {
|
||||||
import TwitterStreamQuickstartDocSpec._
|
import TwitterStreamQuickstartDocSpec._
|
||||||
import IntegrationDocSpec._
|
import IntegrationDocSpec._
|
||||||
|
|
||||||
val ref: ActorRef = system.actorOf(Props[Translator])
|
val ref: ActorRef = system.actorOf(Props[Translator]())
|
||||||
|
|
||||||
"ask" in {
|
"ask" in {
|
||||||
//#ask
|
//#ask
|
||||||
|
|
@ -494,16 +495,25 @@ class IntegrationDocSpec extends AkkaSpec(IntegrationDocSpec.config) {
|
||||||
//#source-actorRef
|
//#source-actorRef
|
||||||
val bufferSize = 10
|
val bufferSize = 10
|
||||||
|
|
||||||
|
val cm: PartialFunction[Any, CompletionStrategy] = {
|
||||||
|
case Done =>
|
||||||
|
CompletionStrategy.immediately
|
||||||
|
}
|
||||||
|
|
||||||
val ref = Source
|
val ref = Source
|
||||||
.actorRef[Int](bufferSize, OverflowStrategy.fail) // note: backpressure is not supported
|
.actorRef[Int](
|
||||||
|
completionMatcher = cm,
|
||||||
|
failureMatcher = PartialFunction.empty[Any, Throwable],
|
||||||
|
bufferSize = bufferSize,
|
||||||
|
overflowStrategy = OverflowStrategy.fail) // note: backpressure is not supported
|
||||||
.map(x => x * x)
|
.map(x => x * x)
|
||||||
.toMat(Sink.foreach(x => println(s"completed $x")))(Keep.left)
|
.toMat(Sink.foreach((x: Int) => println(s"completed $x")))(Keep.left)
|
||||||
.run()
|
.run()
|
||||||
|
|
||||||
ref ! 1
|
ref ! 1
|
||||||
ref ! 2
|
ref ! 2
|
||||||
ref ! 3
|
ref ! 3
|
||||||
ref ! akka.actor.Status.Success("done")
|
ref ! Done
|
||||||
//#source-actorRef
|
//#source-actorRef
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,11 @@ class RateTransformationDocSpec extends AkkaSpec {
|
||||||
//#conflate-summarize
|
//#conflate-summarize
|
||||||
|
|
||||||
val fut =
|
val fut =
|
||||||
Source.fromIterator(() => Iterator.continually(Random.nextGaussian)).via(statsFlow).grouped(10).runWith(Sink.head)
|
Source
|
||||||
|
.fromIterator(() => Iterator.continually(Random.nextGaussian()))
|
||||||
|
.via(statsFlow)
|
||||||
|
.grouped(10)
|
||||||
|
.runWith(Sink.head)
|
||||||
|
|
||||||
fut.futureValue
|
fut.futureValue
|
||||||
}
|
}
|
||||||
|
|
@ -38,8 +42,8 @@ class RateTransformationDocSpec extends AkkaSpec {
|
||||||
val p = 0.01
|
val p = 0.01
|
||||||
val sampleFlow = Flow[Double]
|
val sampleFlow = Flow[Double]
|
||||||
.conflateWithSeed(immutable.Seq(_)) {
|
.conflateWithSeed(immutable.Seq(_)) {
|
||||||
case (acc, elem) if Random.nextDouble < p => acc :+ elem
|
case (acc, elem) if Random.nextDouble() < p => acc :+ elem
|
||||||
case (acc, _) => acc
|
case (acc, _) => acc
|
||||||
}
|
}
|
||||||
.mapConcat(identity)
|
.mapConcat(identity)
|
||||||
//#conflate-sample
|
//#conflate-sample
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ class ReactiveStreamsDocSpec extends AkkaSpec {
|
||||||
override def tweets: Publisher[Tweet] =
|
override def tweets: Publisher[Tweet] =
|
||||||
TwitterStreamQuickstartDocSpec.tweets.runWith(Sink.asPublisher(fanout = false))
|
TwitterStreamQuickstartDocSpec.tweets.runWith(Sink.asPublisher(fanout = false))
|
||||||
|
|
||||||
override def storage = TestSubscriber.manualProbe[Author]
|
override def storage = TestSubscriber.manualProbe[Author]()
|
||||||
|
|
||||||
override def alert = TestSubscriber.manualProbe[Author]
|
override def alert = TestSubscriber.manualProbe[Author]()
|
||||||
}
|
}
|
||||||
|
|
||||||
def assertResult(storage: TestSubscriber.ManualProbe[Author]): Unit = {
|
def assertResult(storage: TestSubscriber.ManualProbe[Author]): Unit = {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class RestartDocSpec extends AkkaSpec with CompileOnlySpec {
|
||||||
maxRestarts = 20 // limits the amount of restarts to 20
|
maxRestarts = 20 // limits the amount of restarts to 20
|
||||||
) { () =>
|
) { () =>
|
||||||
// Create a source from a future of a source
|
// Create a source from a future of a source
|
||||||
Source.fromFutureSource {
|
Source.futureSource {
|
||||||
// Make a single request with akka-http
|
// Make a single request with akka-http
|
||||||
Http()
|
Http()
|
||||||
.singleRequest(HttpRequest(uri = "http://example.com/eventstream"))
|
.singleRequest(HttpRequest(uri = "http://example.com/eventstream"))
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ class StreamPartialGraphDSLDocSpec extends AkkaSpec {
|
||||||
"combine sinks with simplified API" in {
|
"combine sinks with simplified API" in {
|
||||||
val actorRef: ActorRef = testActor
|
val actorRef: ActorRef = testActor
|
||||||
//#sink-combine
|
//#sink-combine
|
||||||
val sendRmotely = Sink.actorRef(actorRef, "Done")
|
val sendRmotely = Sink.actorRef(actorRef, "Done", _ => "Failed")
|
||||||
val localProcessing = Sink.foreach[Int](_ => /* do something useful */ ())
|
val localProcessing = Sink.foreach[Int](_ => /* do something useful */ ())
|
||||||
|
|
||||||
val sink = Sink.combine(sendRmotely, localProcessing)(Broadcast[Int](_))
|
val sink = Sink.combine(sendRmotely, localProcessing)(Broadcast[Int](_))
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,14 @@
|
||||||
|
|
||||||
package docs.stream
|
package docs.stream
|
||||||
|
|
||||||
import akka.stream._
|
|
||||||
import akka.stream.scaladsl._
|
|
||||||
import akka.stream.testkit.scaladsl._
|
|
||||||
import scala.util._
|
import scala.util._
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
import scala.concurrent._
|
import scala.concurrent._
|
||||||
|
|
||||||
|
import akka.Done
|
||||||
|
import akka.stream._
|
||||||
|
import akka.stream.scaladsl._
|
||||||
|
import akka.stream.testkit.scaladsl._
|
||||||
import akka.testkit.{ AkkaSpec, TestProbe }
|
import akka.testkit.{ AkkaSpec, TestProbe }
|
||||||
import akka.pattern
|
import akka.pattern
|
||||||
|
|
||||||
|
|
@ -67,10 +69,12 @@ class StreamTestKitDocSpec extends AkkaSpec {
|
||||||
val sourceUnderTest = Source.tick(0.seconds, 200.millis, Tick)
|
val sourceUnderTest = Source.tick(0.seconds, 200.millis, Tick)
|
||||||
|
|
||||||
val probe = TestProbe()
|
val probe = TestProbe()
|
||||||
val cancellable = sourceUnderTest.to(Sink.actorRef(probe.ref, "completed")).run()
|
val cancellable = sourceUnderTest
|
||||||
|
.to(Sink.actorRef(probe.ref, onCompleteMessage = "completed", onFailureMessage = _ => "failed"))
|
||||||
|
.run()
|
||||||
|
|
||||||
probe.expectMsg(1.second, Tick)
|
probe.expectMsg(1.second, Tick)
|
||||||
probe.expectNoMsg(100.millis)
|
probe.expectNoMessage(100.millis)
|
||||||
probe.expectMsg(3.seconds, Tick)
|
probe.expectMsg(3.seconds, Tick)
|
||||||
cancellable.cancel()
|
cancellable.cancel()
|
||||||
probe.expectMsg(3.seconds, "completed")
|
probe.expectMsg(3.seconds, "completed")
|
||||||
|
|
@ -81,12 +85,23 @@ class StreamTestKitDocSpec extends AkkaSpec {
|
||||||
//#source-actorref
|
//#source-actorref
|
||||||
val sinkUnderTest = Flow[Int].map(_.toString).toMat(Sink.fold("")(_ + _))(Keep.right)
|
val sinkUnderTest = Flow[Int].map(_.toString).toMat(Sink.fold("")(_ + _))(Keep.right)
|
||||||
|
|
||||||
val (ref, future) = Source.actorRef(8, OverflowStrategy.fail).toMat(sinkUnderTest)(Keep.both).run()
|
val (ref, future) = Source
|
||||||
|
.actorRef(
|
||||||
|
completionMatcher = {
|
||||||
|
case Done =>
|
||||||
|
CompletionStrategy.draining
|
||||||
|
},
|
||||||
|
// Never fail the stream because of a message:
|
||||||
|
failureMatcher = PartialFunction.empty,
|
||||||
|
bufferSize = 8,
|
||||||
|
overflowStrategy = OverflowStrategy.fail)
|
||||||
|
.toMat(sinkUnderTest)(Keep.both)
|
||||||
|
.run()
|
||||||
|
|
||||||
ref ! 1
|
ref ! 1
|
||||||
ref ! 2
|
ref ! 2
|
||||||
ref ! 3
|
ref ! 3
|
||||||
ref ! akka.actor.Status.Success(CompletionStrategy.draining)
|
ref ! Done
|
||||||
|
|
||||||
val result = Await.result(future, 3.seconds)
|
val result = Await.result(future, 3.seconds)
|
||||||
assert(result == "123")
|
assert(result == "123")
|
||||||
|
|
@ -116,9 +131,7 @@ class StreamTestKitDocSpec extends AkkaSpec {
|
||||||
val (probe, future) = TestSource.probe[Int].toMat(sinkUnderTest)(Keep.both).run()
|
val (probe, future) = TestSource.probe[Int].toMat(sinkUnderTest)(Keep.both).run()
|
||||||
probe.sendError(new Exception("boom"))
|
probe.sendError(new Exception("boom"))
|
||||||
|
|
||||||
Await.ready(future, 3.seconds)
|
assert(future.failed.futureValue.getMessage == "boom")
|
||||||
val Failure(exception) = future.value.get
|
|
||||||
assert(exception.getMessage == "boom")
|
|
||||||
//#injecting-failure
|
//#injecting-failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,13 @@ class RecipeAdhocSource extends RecipeSpec {
|
||||||
|
|
||||||
//#adhoc-source
|
//#adhoc-source
|
||||||
def adhocSource[T](source: Source[T, _], timeout: FiniteDuration, maxRetries: Int): Source[T, _] =
|
def adhocSource[T](source: Source[T, _], timeout: FiniteDuration, maxRetries: Int): Source[T, _] =
|
||||||
Source.lazily(
|
Source.lazySource(
|
||||||
() =>
|
() =>
|
||||||
source
|
source
|
||||||
.backpressureTimeout(timeout)
|
.backpressureTimeout(timeout)
|
||||||
.recoverWithRetries(maxRetries, {
|
.recoverWithRetries(maxRetries, {
|
||||||
case t: TimeoutException =>
|
case t: TimeoutException =>
|
||||||
Source.lazily(() => source.backpressureTimeout(timeout)).mapMaterializedValue(_ => NotUsed)
|
Source.lazySource(() => source.backpressureTimeout(timeout)).mapMaterializedValue(_ => NotUsed)
|
||||||
}))
|
}))
|
||||||
//#adhoc-source
|
//#adhoc-source
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
package docs.stream.operators
|
package docs.stream.operators
|
||||||
|
|
||||||
import akka.Done
|
|
||||||
import akka.actor.ActorSystem
|
import akka.actor.ActorSystem
|
||||||
import akka.testkit.TestProbe
|
import akka.testkit.TestProbe
|
||||||
|
|
||||||
|
|
@ -12,7 +11,7 @@ object SourceOperators {
|
||||||
|
|
||||||
implicit val system: ActorSystem = ???
|
implicit val system: ActorSystem = ???
|
||||||
|
|
||||||
def fromFuture = {
|
def fromFuture(): Unit = {
|
||||||
//#sourceFromFuture
|
//#sourceFromFuture
|
||||||
|
|
||||||
import akka.actor.ActorSystem
|
import akka.actor.ActorSystem
|
||||||
|
|
@ -35,7 +34,6 @@ object SourceOperators {
|
||||||
import akka.stream.OverflowStrategy
|
import akka.stream.OverflowStrategy
|
||||||
import akka.stream.CompletionStrategy
|
import akka.stream.CompletionStrategy
|
||||||
import akka.stream.scaladsl._
|
import akka.stream.scaladsl._
|
||||||
import scala.util.Failure
|
|
||||||
|
|
||||||
val source: Source[Any, ActorRef] = Source.actorRef(
|
val source: Source[Any, ActorRef] = Source.actorRef(
|
||||||
completionMatcher = {
|
completionMatcher = {
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,10 @@ class StreamConvertersToJava extends AkkaSpec with Futures {
|
||||||
"demonstrate conversion from Java8 streams" in {
|
"demonstrate conversion from Java8 streams" in {
|
||||||
//#fromJavaStream
|
//#fromJavaStream
|
||||||
def factory(): IntStream = IntStream.rangeClosed(0, 9)
|
def factory(): IntStream = IntStream.rangeClosed(0, 9)
|
||||||
val source: Source[Int, NotUsed] = StreamConverters.fromJavaStream(factory).map(_.intValue())
|
val source: Source[Int, NotUsed] = StreamConverters.fromJavaStream(() => factory()).map(_.intValue())
|
||||||
val sink: Sink[Int, Future[immutable.Seq[Int]]] = Sink.seq[Int]
|
val sink: Sink[Int, Future[immutable.Seq[Int]]] = Sink.seq[Int]
|
||||||
|
|
||||||
val futureInts: Future[immutable.Seq[Int]] = source.toMat(sink)(Keep.right).run
|
val futureInts: Future[immutable.Seq[Int]] = source.toMat(sink)(Keep.right).run()
|
||||||
|
|
||||||
//#fromJavaStream
|
//#fromJavaStream
|
||||||
whenReady(futureInts) { ints =>
|
whenReady(futureInts) { ints =>
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,6 @@ import akka.stream.scaladsl.Source
|
||||||
import akka.stream.scaladsl.Tcp
|
import akka.stream.scaladsl.Tcp
|
||||||
import akka.stream.testkit.TestPublisher
|
import akka.stream.testkit.TestPublisher
|
||||||
import akka.stream.testkit.TestSubscriber
|
import akka.stream.testkit.TestSubscriber
|
||||||
import akka.stream.testkit.Utils.TE
|
|
||||||
import akka.stream.testkit.scaladsl.TestSource
|
|
||||||
import akka.stream.testkit.scaladsl.TestSink
|
|
||||||
import akka.util.ByteString
|
import akka.util.ByteString
|
||||||
|
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
|
|
@ -63,7 +60,7 @@ object FromSinkAndSource {
|
||||||
def testing(): Unit = {
|
def testing(): Unit = {
|
||||||
def myApiThatTakesAFlow[In, Out](flow: Flow[In, Out, NotUsed]): Unit = ???
|
def myApiThatTakesAFlow[In, Out](flow: Flow[In, Out, NotUsed]): Unit = ???
|
||||||
// #testing
|
// #testing
|
||||||
val inProbe = TestSubscriber.probe[String]
|
val inProbe = TestSubscriber.probe[String]()
|
||||||
val outProbe = TestPublisher.probe[String]()
|
val outProbe = TestPublisher.probe[String]()
|
||||||
val testFlow = Flow.fromSinkAndSource(Sink.fromSubscriber(inProbe), Source.fromPublisher(outProbe))
|
val testFlow = Flow.fromSinkAndSource(Sink.fromSubscriber(inProbe), Source.fromPublisher(outProbe))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ object Restart extends App {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def onRestartWithBackoffInnerComplete() {
|
def onRestartWithBackoffInnerComplete() = {
|
||||||
|
|
||||||
//#restart-failure-inner-complete
|
//#restart-failure-inner-complete
|
||||||
val finiteSource = Source.tick(1.second, 1.second, "tick").take(3)
|
val finiteSource = Source.tick(1.second, 1.second, "tick").take(3)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ object Tick {
|
||||||
case class Response(text: String)
|
case class Response(text: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
def simple() {
|
def simple() = {
|
||||||
// #simple
|
// #simple
|
||||||
Source
|
Source
|
||||||
.tick(
|
.tick(
|
||||||
|
|
@ -39,7 +39,7 @@ object Tick {
|
||||||
// #simple
|
// #simple
|
||||||
}
|
}
|
||||||
|
|
||||||
def pollSomething() {
|
def pollSomething() = {
|
||||||
// #poll-actor
|
// #poll-actor
|
||||||
val periodicActorResponse: Source[String, Cancellable] = Source
|
val periodicActorResponse: Source[String, Cancellable] = Source
|
||||||
.tick(1.second, 1.second, "tick")
|
.tick(1.second, 1.second, "tick")
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
package docs.stream.operators.source
|
package docs.stream.operators.source
|
||||||
|
|
||||||
import akka.NotUsed
|
|
||||||
import akka.actor.typed.ActorSystem
|
import akka.actor.typed.ActorSystem
|
||||||
import akka.stream.scaladsl.Source
|
import akka.stream.scaladsl.Source
|
||||||
|
|
||||||
|
|
@ -48,7 +47,7 @@ object Zip {
|
||||||
// #zipWithN-simple
|
// #zipWithN-simple
|
||||||
}
|
}
|
||||||
|
|
||||||
def zipAll() {
|
def zipAll() = {
|
||||||
// #zipAll-simple
|
// #zipAll-simple
|
||||||
val numbers = Source(1 :: 2 :: 3 :: 4 :: Nil)
|
val numbers = Source(1 :: 2 :: 3 :: 4 :: Nil)
|
||||||
val letters = Source("a" :: "b" :: "c" :: Nil)
|
val letters = Source("a" :: "b" :: "c" :: Nil)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import org.scalatest.BeforeAndAfterAll
|
||||||
*/
|
*/
|
||||||
//#test-example
|
//#test-example
|
||||||
class Parent extends Actor {
|
class Parent extends Actor {
|
||||||
val child = context.actorOf(Props[Child], "child")
|
val child = context.actorOf(Props[Child](), "child")
|
||||||
var ponged = false
|
var ponged = false
|
||||||
|
|
||||||
def receive = {
|
def receive = {
|
||||||
|
|
@ -71,7 +71,7 @@ class GenericDependentParent(childMaker: ActorRefFactory => ActorRef) extends Ac
|
||||||
*/
|
*/
|
||||||
class MockedChild extends Actor {
|
class MockedChild extends Actor {
|
||||||
def receive = {
|
def receive = {
|
||||||
case "ping" => sender ! "pong"
|
case "ping" => sender() ! "pong"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,8 +139,8 @@ class ParentChildSpec extends AnyWordSpec with Matchers with TestKitBase with Be
|
||||||
val parent = system.actorOf(Props(new Actor {
|
val parent = system.actorOf(Props(new Actor {
|
||||||
val child = context.actorOf(Props(new Child), "child")
|
val child = context.actorOf(Props(new Child), "child")
|
||||||
def receive = {
|
def receive = {
|
||||||
case x if sender == child => proxy.ref.forward(x)
|
case x if sender() == child => proxy.ref.forward(x)
|
||||||
case x => child.forward(x)
|
case x => child.forward(x)
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class MySpec()
|
||||||
with BeforeAndAfterAll {
|
with BeforeAndAfterAll {
|
||||||
//#implicit-sender
|
//#implicit-sender
|
||||||
|
|
||||||
override def afterAll: Unit = {
|
override def afterAll(): Unit = {
|
||||||
TestKit.shutdownActorSystem(system)
|
TestKit.shutdownActorSystem(system)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class TestKitUsageSpec
|
||||||
val seqRef =
|
val seqRef =
|
||||||
system.actorOf(Props(classOf[SequencingActor], testActor, headList, tailList))
|
system.actorOf(Props(classOf[SequencingActor], testActor, headList, tailList))
|
||||||
|
|
||||||
override def afterAll: Unit = {
|
override def afterAll(): Unit = {
|
||||||
shutdown()
|
shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,7 +72,7 @@ class TestKitUsageSpec
|
||||||
filterRef ! "test"
|
filterRef ! "test"
|
||||||
expectMsg("test")
|
expectMsg("test")
|
||||||
filterRef ! 1
|
filterRef ! 1
|
||||||
expectNoMsg
|
expectNoMessage()
|
||||||
filterRef ! "some"
|
filterRef ! "some"
|
||||||
filterRef ! "more"
|
filterRef ! "more"
|
||||||
filterRef ! 1
|
filterRef ! 1
|
||||||
|
|
@ -98,8 +98,8 @@ class TestKitUsageSpec
|
||||||
ignoreMsg {
|
ignoreMsg {
|
||||||
case msg: String => msg == "1"
|
case msg: String => msg == "1"
|
||||||
}
|
}
|
||||||
expectNoMsg
|
expectNoMessage()
|
||||||
ignoreNoMsg
|
ignoreNoMsg()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -170,8 +170,7 @@ class TestKitDocSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
||||||
val actorRef = TestActorRef(new MyActor)
|
val actorRef = TestActorRef(new MyActor)
|
||||||
// hypothetical message stimulating a '42' answer
|
// hypothetical message stimulating a '42' answer
|
||||||
val future = actorRef ? Say42
|
val future = actorRef ? Say42
|
||||||
val Success(result: Int) = future.value.get
|
future.futureValue should be(42)
|
||||||
result should be(42)
|
|
||||||
//#test-behavior
|
//#test-behavior
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,11 +203,11 @@ class TestKitDocSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
||||||
import akka.actor.Props
|
import akka.actor.Props
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
|
|
||||||
val worker = system.actorOf(Props[Worker])
|
val worker = system.actorOf(Props[Worker]())
|
||||||
within(200 millis) {
|
within(200 millis) {
|
||||||
worker ! "some work"
|
worker ! "some work"
|
||||||
expectMsg("some result")
|
expectMsg("some result")
|
||||||
expectNoMessage // will block for the rest of the 200ms
|
expectNoMessage() // will block for the rest of the 200ms
|
||||||
Thread.sleep(300) // will NOT make this block fail
|
Thread.sleep(300) // will NOT make this block fail
|
||||||
}
|
}
|
||||||
//#test-within
|
//#test-within
|
||||||
|
|
@ -226,7 +225,7 @@ class TestKitDocSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
||||||
//#test-probe
|
//#test-probe
|
||||||
val probe1 = TestProbe()
|
val probe1 = TestProbe()
|
||||||
val probe2 = TestProbe()
|
val probe2 = TestProbe()
|
||||||
val actor = system.actorOf(Props[MyDoubleEcho])
|
val actor = system.actorOf(Props[MyDoubleEcho]())
|
||||||
actor ! ((probe1.ref, probe2.ref))
|
actor ! ((probe1.ref, probe2.ref))
|
||||||
actor ! "hello"
|
actor ! "hello"
|
||||||
probe1.expectMsg(500 millis, "hello")
|
probe1.expectMsg(500 millis, "hello")
|
||||||
|
|
@ -287,7 +286,7 @@ class TestKitDocSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
||||||
//#test-probe-forward
|
//#test-probe-forward
|
||||||
val probe = TestProbe()
|
val probe = TestProbe()
|
||||||
val source = system.actorOf(Props(classOf[Source], probe.ref))
|
val source = system.actorOf(Props(classOf[Source], probe.ref))
|
||||||
val dest = system.actorOf(Props[Destination])
|
val dest = system.actorOf(Props[Destination]())
|
||||||
source ! "start"
|
source ! "start"
|
||||||
probe.expectMsg("work")
|
probe.expectMsg("work")
|
||||||
probe.forward(dest)
|
probe.forward(dest)
|
||||||
|
|
@ -313,7 +312,7 @@ class TestKitDocSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
||||||
"demonstrate calling thread dispatcher" in {
|
"demonstrate calling thread dispatcher" in {
|
||||||
//#calling-thread-dispatcher
|
//#calling-thread-dispatcher
|
||||||
import akka.testkit.CallingThreadDispatcher
|
import akka.testkit.CallingThreadDispatcher
|
||||||
val ref = system.actorOf(Props[MyActor].withDispatcher(CallingThreadDispatcher.Id))
|
val ref = system.actorOf(Props[MyActor]().withDispatcher(CallingThreadDispatcher.Id))
|
||||||
//#calling-thread-dispatcher
|
//#calling-thread-dispatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -233,6 +233,7 @@ lazy val docs = akkaModule("akka-docs")
|
||||||
streamTestkit % "compile->compile;test->test",
|
streamTestkit % "compile->compile;test->test",
|
||||||
persistenceTestkit % "compile->compile;test->test")
|
persistenceTestkit % "compile->compile;test->test")
|
||||||
.settings(Dependencies.docs)
|
.settings(Dependencies.docs)
|
||||||
|
.settings(AkkaDisciplinePlugin.docs)
|
||||||
.settings(Paradox.settings)
|
.settings(Paradox.settings)
|
||||||
.settings(javacOptions += "-parameters") // for Jackson
|
.settings(javacOptions += "-parameters") // for Jackson
|
||||||
.enablePlugins(
|
.enablePlugins(
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ object AkkaDisciplinePlugin extends AutoPlugin {
|
||||||
val enabled = !sys.props.contains("akka.no.discipline")
|
val enabled = !sys.props.contains("akka.no.discipline")
|
||||||
|
|
||||||
// We allow warnings in docs to get the 'snippets' right
|
// We allow warnings in docs to get the 'snippets' right
|
||||||
val nonFatalWarningsFor = Set("akka-docs")
|
|
||||||
val nonFatalJavaWarningsFor = Set(
|
val nonFatalJavaWarningsFor = Set(
|
||||||
// for sun.misc.Unsafe and AbstractScheduler
|
// for sun.misc.Unsafe and AbstractScheduler
|
||||||
"akka-actor",
|
"akka-actor",
|
||||||
|
|
@ -51,6 +50,7 @@ object AkkaDisciplinePlugin extends AutoPlugin {
|
||||||
"akka-cluster-sharding",
|
"akka-cluster-sharding",
|
||||||
"akka-cluster-sharding-typed",
|
"akka-cluster-sharding-typed",
|
||||||
"akka-distributed-data",
|
"akka-distributed-data",
|
||||||
|
"akka-docs",
|
||||||
"akka-persistence",
|
"akka-persistence",
|
||||||
"akka-persistence-tck",
|
"akka-persistence-tck",
|
||||||
"akka-persistence-typed",
|
"akka-persistence-typed",
|
||||||
|
|
@ -74,10 +74,7 @@ object AkkaDisciplinePlugin extends AutoPlugin {
|
||||||
lazy val disciplineSettings =
|
lazy val disciplineSettings =
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
silencerSettings ++ Seq(
|
silencerSettings ++ Seq(
|
||||||
Compile / scalacOptions ++= (
|
Compile / scalacOptions ++= Seq("-Xfatal-warnings"),
|
||||||
if (!nonFatalWarningsFor(name.value)) Seq("-Xfatal-warnings")
|
|
||||||
else Seq.empty
|
|
||||||
),
|
|
||||||
Test / scalacOptions --= testUndicipline,
|
Test / scalacOptions --= testUndicipline,
|
||||||
Compile / javacOptions ++= (
|
Compile / javacOptions ++= (
|
||||||
if (!nonFatalJavaWarningsFor(name.value)) Seq("-Werror", "-Xlint:deprecation", "-Xlint:unchecked")
|
if (!nonFatalJavaWarningsFor(name.value)) Seq("-Werror", "-Xlint:deprecation", "-Xlint:unchecked")
|
||||||
|
|
@ -136,4 +133,23 @@ object AkkaDisciplinePlugin extends AutoPlugin {
|
||||||
"-Ypartial-unification",
|
"-Ypartial-unification",
|
||||||
"-Ywarn-extra-implicit")
|
"-Ywarn-extra-implicit")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We are a little less strict in docs
|
||||||
|
*/
|
||||||
|
val docs = Seq(
|
||||||
|
scalacOptions ++= Seq(
|
||||||
|
// In docs, 'unused' variables can be useful for naming and showing the type
|
||||||
|
"-P:silencer:globalFilters=is never used",
|
||||||
|
// Import statements are often duplicated across multiple snippets in one file
|
||||||
|
"-P:silencer:globalFilters=Unused import",
|
||||||
|
// We keep documentation for this old API around for a while:
|
||||||
|
"-P:silencer:globalFilters=in object Dns is deprecated",
|
||||||
|
"-P:silencer:globalFilters=in class Dns is deprecated",
|
||||||
|
// Because we sometimes wrap things in a class:
|
||||||
|
"-P:silencer:globalFilters=The outer reference in this type test cannot be checked at run time",
|
||||||
|
// Because we show some things that are deprecated in
|
||||||
|
// 2.13 but don't have a replacement that was in 2.12:
|
||||||
|
"-P:silencer:globalFilters=deprecated \\(since 2.13.0\\)"
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue