Merge pull request #16763 from akka/wip-cleanup-actor-∂π
fix all non-deprecation warnings
This commit is contained in:
commit
5e1fd1db6c
42 changed files with 254 additions and 317 deletions
|
|
@ -11,6 +11,8 @@ import java.nio.channels.{ DatagramChannel, ServerSocketChannel }
|
||||||
import akka.actor.{ ActorSystem, ActorRef }
|
import akka.actor.{ ActorSystem, ActorRef }
|
||||||
import akka.testkit.TestProbe
|
import akka.testkit.TestProbe
|
||||||
|
|
||||||
|
import language.reflectiveCalls
|
||||||
|
|
||||||
object TestUtils {
|
object TestUtils {
|
||||||
|
|
||||||
// Structural type needed since DatagramSocket and ServerSocket has no common ancestor apart from Object
|
// Structural type needed since DatagramSocket and ServerSocket has no common ancestor apart from Object
|
||||||
|
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
package akka.actor
|
|
||||||
|
|
||||||
import akka.testkit._
|
|
||||||
import org.scalatest.BeforeAndAfterEach
|
|
||||||
import scala.concurrent.duration._
|
|
||||||
import scala.concurrent.Await
|
|
||||||
import akka.pattern.ask
|
|
||||||
|
|
||||||
object ActorFireForgetRequestReplySpec {
|
|
||||||
|
|
||||||
class ReplyActor extends Actor {
|
|
||||||
def receive = {
|
|
||||||
case "Send" ⇒
|
|
||||||
sender() ! "Reply"
|
|
||||||
case "SendImplicit" ⇒
|
|
||||||
sender() ! "ReplyImplicit"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CrashingActor extends Actor {
|
|
||||||
import context.system
|
|
||||||
def receive = {
|
|
||||||
case "Die" ⇒
|
|
||||||
state.finished.await
|
|
||||||
throw new Exception("Expected exception")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SenderActor(replyActor: ActorRef) extends Actor {
|
|
||||||
import context.system
|
|
||||||
def receive = {
|
|
||||||
case "Init" ⇒
|
|
||||||
replyActor ! "Send"
|
|
||||||
case "Reply" ⇒ {
|
|
||||||
state.s = "Reply"
|
|
||||||
state.finished.await
|
|
||||||
}
|
|
||||||
case "InitImplicit" ⇒ replyActor ! "SendImplicit"
|
|
||||||
case "ReplyImplicit" ⇒ {
|
|
||||||
state.s = "ReplyImplicit"
|
|
||||||
state.finished.await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object state {
|
|
||||||
var s = "NIL"
|
|
||||||
val finished = TestBarrier(2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner])
|
|
||||||
class ActorFireForgetRequestReplySpec extends AkkaSpec with BeforeAndAfterEach with DefaultTimeout {
|
|
||||||
import ActorFireForgetRequestReplySpec._
|
|
||||||
|
|
||||||
override def beforeEach() = {
|
|
||||||
state.finished.reset
|
|
||||||
}
|
|
||||||
|
|
||||||
"An Actor" must {
|
|
||||||
|
|
||||||
"reply to bang message using reply" in {
|
|
||||||
val replyActor = system.actorOf(Props[ReplyActor])
|
|
||||||
val senderActor = system.actorOf(Props(new SenderActor(replyActor)))
|
|
||||||
senderActor ! "Init"
|
|
||||||
state.finished.await
|
|
||||||
state.s should be("Reply")
|
|
||||||
}
|
|
||||||
|
|
||||||
"reply to bang message using implicit sender" in {
|
|
||||||
val replyActor = system.actorOf(Props[ReplyActor])
|
|
||||||
val senderActor = system.actorOf(Props(new SenderActor(replyActor)))
|
|
||||||
senderActor ! "InitImplicit"
|
|
||||||
state.finished.await
|
|
||||||
state.s should be("ReplyImplicit")
|
|
||||||
}
|
|
||||||
|
|
||||||
"shutdown crashed temporary actor" in {
|
|
||||||
filterEvents(EventFilter[Exception]("Expected exception")) {
|
|
||||||
val supervisor = system.actorOf(Props(new Supervisor(
|
|
||||||
OneForOneStrategy(maxNrOfRetries = 0)(List(classOf[Exception])))))
|
|
||||||
val actor = Await.result((supervisor ? Props[CrashingActor]).mapTo[ActorRef], timeout.duration)
|
|
||||||
actor.isTerminated should be(false)
|
|
||||||
actor ! "Die"
|
|
||||||
state.finished.await
|
|
||||||
Thread.sleep(1.second.dilated.toMillis)
|
|
||||||
actor.isTerminated should be(true)
|
|
||||||
system.stop(supervisor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit
|
||||||
import akka.util.Helpers.ConfigOps
|
import akka.util.Helpers.ConfigOps
|
||||||
|
|
||||||
object ActorMailboxSpec {
|
object ActorMailboxSpec {
|
||||||
val mailboxConf = ConfigFactory.parseString("""
|
val mailboxConf = ConfigFactory.parseString(s"""
|
||||||
unbounded-dispatcher {
|
unbounded-dispatcher {
|
||||||
mailbox-type = "akka.dispatch.UnboundedMailbox"
|
mailbox-type = "akka.dispatch.UnboundedMailbox"
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +46,7 @@ object ActorMailboxSpec {
|
||||||
|
|
||||||
requiring-balancing-bounded-dispatcher {
|
requiring-balancing-bounded-dispatcher {
|
||||||
type = "akka.dispatch.BalancingDispatcherConfigurator"
|
type = "akka.dispatch.BalancingDispatcherConfigurator"
|
||||||
mailbox-requirement = "akka.actor.ActorMailboxSpec$MCBoundedMessageQueueSemantics"
|
mailbox-requirement = "akka.actor.ActorMailboxSpec$$MCBoundedMessageQueueSemantics"
|
||||||
}
|
}
|
||||||
|
|
||||||
unbounded-mailbox {
|
unbounded-mailbox {
|
||||||
|
|
@ -68,7 +68,7 @@ object ActorMailboxSpec {
|
||||||
mc-bounded-mailbox {
|
mc-bounded-mailbox {
|
||||||
mailbox-capacity = 1000
|
mailbox-capacity = 1000
|
||||||
mailbox-push-timeout-time = 10s
|
mailbox-push-timeout-time = 10s
|
||||||
mailbox-type = "akka.actor.ActorMailboxSpec$MCBoundedMailbox"
|
mailbox-type = "akka.actor.ActorMailboxSpec$$MCBoundedMailbox"
|
||||||
}
|
}
|
||||||
|
|
||||||
akka.actor.deployment {
|
akka.actor.deployment {
|
||||||
|
|
@ -142,7 +142,7 @@ object ActorMailboxSpec {
|
||||||
}
|
}
|
||||||
|
|
||||||
akka.actor.mailbox.requirements {
|
akka.actor.mailbox.requirements {
|
||||||
"akka.actor.ActorMailboxSpec$MCBoundedMessageQueueSemantics" =
|
"akka.actor.ActorMailboxSpec$$MCBoundedMessageQueueSemantics" =
|
||||||
mc-bounded-mailbox
|
mc-bounded-mailbox
|
||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,12 @@ object UidClashTest {
|
||||||
|
|
||||||
@volatile var oldActor: ActorRef = _
|
@volatile var oldActor: ActorRef = _
|
||||||
|
|
||||||
class EvilCollidingActorRef(override val provider: ActorRefProvider,
|
private[akka] class EvilCollidingActorRef(override val provider: ActorRefProvider,
|
||||||
override val path: ActorPath,
|
override val path: ActorPath,
|
||||||
val eventStream: EventStream) extends MinimalActorRef {
|
val eventStream: EventStream) extends MinimalActorRef {
|
||||||
|
|
||||||
//Ignore everything
|
//Ignore everything
|
||||||
override def isTerminated(): Boolean = true
|
override def isTerminated: Boolean = true
|
||||||
override def sendSystemMessage(message: SystemMessage): Unit = ()
|
override def sendSystemMessage(message: SystemMessage): Unit = ()
|
||||||
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = ()
|
override def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit = ()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,27 @@ object FutureSpec {
|
||||||
|
|
||||||
final case class Req[T](req: T)
|
final case class Req[T](req: T)
|
||||||
final case class Res[T](res: T)
|
final case class Res[T](res: T)
|
||||||
|
|
||||||
|
sealed trait IntAction { def apply(that: Int): Int }
|
||||||
|
final case class IntAdd(n: Int) extends IntAction { def apply(that: Int) = that + n }
|
||||||
|
final case class IntSub(n: Int) extends IntAction { def apply(that: Int) = that - n }
|
||||||
|
final case class IntMul(n: Int) extends IntAction { def apply(that: Int) = that * n }
|
||||||
|
final case class IntDiv(n: Int) extends IntAction { def apply(that: Int) = that / n }
|
||||||
|
|
||||||
|
sealed trait FutureAction {
|
||||||
|
def /:(that: Try[Int]): Try[Int]
|
||||||
|
def /:(that: Future[Int]): Future[Int]
|
||||||
|
}
|
||||||
|
|
||||||
|
final case class MapAction(action: IntAction)(implicit ec: ExecutionContext) extends FutureAction {
|
||||||
|
def /:(that: Try[Int]): Try[Int] = that map action.apply
|
||||||
|
def /:(that: Future[Int]): Future[Int] = that map action.apply
|
||||||
|
}
|
||||||
|
|
||||||
|
final case class FlatMapAction(action: IntAction)(implicit ec: ExecutionContext) extends FutureAction {
|
||||||
|
def /:(that: Try[Int]): Try[Int] = that map action.apply
|
||||||
|
def /:(that: Future[Int]): Future[Int] = that flatMap (n ⇒ Future.successful(action(n)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JavaFutureSpec extends JavaFutureTests with JUnitSuiteLike
|
class JavaFutureSpec extends JavaFutureTests with JUnitSuiteLike
|
||||||
|
|
@ -628,7 +649,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa
|
||||||
"filter result" in {
|
"filter result" in {
|
||||||
f { (future, result) ⇒
|
f { (future, result) ⇒
|
||||||
Await.result((future filter (_ ⇒ true)), timeout.duration) should be(result)
|
Await.result((future filter (_ ⇒ true)), timeout.duration) should be(result)
|
||||||
evaluating { Await.result((future filter (_ ⇒ false)), timeout.duration) } should produce[java.util.NoSuchElementException]
|
intercept[java.util.NoSuchElementException] { Await.result((future filter (_ ⇒ false)), timeout.duration) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"transform result with map" in { f((future, result) ⇒ Await.result((future map (_.toString.length)), timeout.duration) should be(result.toString.length)) }
|
"transform result with map" in { f((future, result) ⇒ Await.result((future map (_.toString.length)), timeout.duration) should be(result.toString.length)) }
|
||||||
|
|
@ -648,7 +669,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa
|
||||||
"zip properly" in {
|
"zip properly" in {
|
||||||
f { (future, result) ⇒
|
f { (future, result) ⇒
|
||||||
Await.result(future zip Promise.successful("foo").future, timeout.duration) should be((result, "foo"))
|
Await.result(future zip Promise.successful("foo").future, timeout.duration) should be((result, "foo"))
|
||||||
(evaluating { Await.result(future zip Promise.failed(new RuntimeException("ohnoes")).future, timeout.duration) } should produce[RuntimeException]).getMessage should be("ohnoes")
|
(intercept[RuntimeException] { Await.result(future zip Promise.failed(new RuntimeException("ohnoes")).future, timeout.duration) }).getMessage should be("ohnoes")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"not recover from exception" in { f((future, result) ⇒ Await.result(future.recover({ case _ ⇒ "pigdog" }), timeout.duration) should be(result)) }
|
"not recover from exception" in { f((future, result) ⇒ Await.result(future.recover({ case _ ⇒ "pigdog" }), timeout.duration) should be(result)) }
|
||||||
|
|
@ -659,7 +680,7 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa
|
||||||
Await.result(p.future, timeout.duration) should be(result)
|
Await.result(p.future, timeout.duration) should be(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"not project a failure" in { f((future, result) ⇒ (evaluating { Await.result(future.failed, timeout.duration) } should produce[NoSuchElementException]).getMessage should be("Future.failed not completed with a throwable.")) }
|
"not project a failure" in { f((future, result) ⇒ (intercept[NoSuchElementException] { Await.result(future.failed, timeout.duration) }).getMessage should be("Future.failed not completed with a throwable.")) }
|
||||||
"not perform action on exception" is pending
|
"not perform action on exception" is pending
|
||||||
"cast using mapTo" in { f((future, result) ⇒ Await.result(future.mapTo[Boolean].recover({ case _: ClassCastException ⇒ false }), timeout.duration) should be(false)) }
|
"cast using mapTo" in { f((future, result) ⇒ Await.result(future.mapTo[Boolean].recover({ case _: ClassCastException ⇒ false }), timeout.duration) should be(false)) }
|
||||||
}
|
}
|
||||||
|
|
@ -674,20 +695,20 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa
|
||||||
f.getMessage should be(message)
|
f.getMessage should be(message)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
"throw exception with 'get'" in { f((future, message) ⇒ (evaluating { Await.result(future, timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)) }
|
"throw exception with 'get'" in { f((future, message) ⇒ (intercept[java.lang.Exception] { Await.result(future, timeout.duration) }).getMessage should be(message)) }
|
||||||
"throw exception with 'Await.result'" in { f((future, message) ⇒ (evaluating { Await.result(future, timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)) }
|
"throw exception with 'Await.result'" in { f((future, message) ⇒ (intercept[java.lang.Exception] { Await.result(future, timeout.duration) }).getMessage should be(message)) }
|
||||||
"retain exception with filter" in {
|
"retain exception with filter" in {
|
||||||
f { (future, message) ⇒
|
f { (future, message) ⇒
|
||||||
(evaluating { Await.result(future filter (_ ⇒ true), timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)
|
(intercept[java.lang.Exception] { Await.result(future filter (_ ⇒ true), timeout.duration) }).getMessage should be(message)
|
||||||
(evaluating { Await.result(future filter (_ ⇒ false), timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)
|
(intercept[java.lang.Exception] { Await.result(future filter (_ ⇒ false), timeout.duration) }).getMessage should be(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"retain exception with map" in { f((future, message) ⇒ (evaluating { Await.result(future map (_.toString.length), timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)) }
|
"retain exception with map" in { f((future, message) ⇒ (intercept[java.lang.Exception] { Await.result(future map (_.toString.length), timeout.duration) }).getMessage should be(message)) }
|
||||||
"retain exception with flatMap" in { f((future, message) ⇒ (evaluating { Await.result(future flatMap (_ ⇒ Promise.successful[Any]("foo").future), timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)) }
|
"retain exception with flatMap" in { f((future, message) ⇒ (intercept[java.lang.Exception] { Await.result(future flatMap (_ ⇒ Promise.successful[Any]("foo").future), timeout.duration) }).getMessage should be(message)) }
|
||||||
"not perform action with foreach" is pending
|
"not perform action with foreach" is pending
|
||||||
|
|
||||||
"zip properly" in {
|
"zip properly" in {
|
||||||
f { (future, message) ⇒ (evaluating { Await.result(future zip Promise.successful("foo").future, timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message) }
|
f { (future, message) ⇒ (intercept[java.lang.Exception] { Await.result(future zip Promise.successful("foo").future, timeout.duration) }).getMessage should be(message) }
|
||||||
}
|
}
|
||||||
"recover from exception" in { f((future, message) ⇒ Await.result(future.recover({ case e if e.getMessage == message ⇒ "pigdog" }), timeout.duration) should be("pigdog")) }
|
"recover from exception" in { f((future, message) ⇒ Await.result(future.recover({ case e if e.getMessage == message ⇒ "pigdog" }), timeout.duration) should be("pigdog")) }
|
||||||
"not perform action on result" is pending
|
"not perform action on result" is pending
|
||||||
|
|
@ -702,27 +723,6 @@ class FutureSpec extends AkkaSpec with Checkers with BeforeAndAfterAll with Defa
|
||||||
"always cast successfully using mapTo" in { f((future, message) ⇒ (evaluating { Await.result(future.mapTo[java.lang.Thread], timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)) }
|
"always cast successfully using mapTo" in { f((future, message) ⇒ (evaluating { Await.result(future.mapTo[java.lang.Thread], timeout.duration) } should produce[java.lang.Exception]).getMessage should be(message)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed trait IntAction { def apply(that: Int): Int }
|
|
||||||
final case class IntAdd(n: Int) extends IntAction { def apply(that: Int) = that + n }
|
|
||||||
final case class IntSub(n: Int) extends IntAction { def apply(that: Int) = that - n }
|
|
||||||
final case class IntMul(n: Int) extends IntAction { def apply(that: Int) = that * n }
|
|
||||||
final case class IntDiv(n: Int) extends IntAction { def apply(that: Int) = that / n }
|
|
||||||
|
|
||||||
sealed trait FutureAction {
|
|
||||||
def /:(that: Try[Int]): Try[Int]
|
|
||||||
def /:(that: Future[Int]): Future[Int]
|
|
||||||
}
|
|
||||||
|
|
||||||
final case class MapAction(action: IntAction) extends FutureAction {
|
|
||||||
def /:(that: Try[Int]): Try[Int] = that map action.apply
|
|
||||||
def /:(that: Future[Int]): Future[Int] = that map action.apply
|
|
||||||
}
|
|
||||||
|
|
||||||
final case class FlatMapAction(action: IntAction) extends FutureAction {
|
|
||||||
def /:(that: Try[Int]): Try[Int] = that map action.apply
|
|
||||||
def /:(that: Future[Int]): Future[Int] = that flatMap (n ⇒ Future.successful(action(n)))
|
|
||||||
}
|
|
||||||
|
|
||||||
implicit def arbFuture: Arbitrary[Future[Int]] = Arbitrary(for (n ← arbitrary[Int]) yield Future(n))
|
implicit def arbFuture: Arbitrary[Future[Int]] = Arbitrary(for (n ← arbitrary[Int]) yield Future(n))
|
||||||
|
|
||||||
implicit def arbFutureAction: Arbitrary[FutureAction] = Arbitrary {
|
implicit def arbFutureAction: Arbitrary[FutureAction] = Arbitrary {
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,9 @@ object EventStreamSpec {
|
||||||
|
|
||||||
// class hierarchy for subchannel test
|
// class hierarchy for subchannel test
|
||||||
class A
|
class A
|
||||||
class B1 extends A
|
|
||||||
class B2 extends A
|
class B2 extends A
|
||||||
class C extends B1
|
class B3 extends A
|
||||||
|
class C extends B2
|
||||||
|
|
||||||
trait T
|
trait T
|
||||||
trait AT extends T
|
trait AT extends T
|
||||||
|
|
@ -137,12 +137,12 @@ class EventStreamSpec extends AkkaSpec(EventStreamSpec.config) {
|
||||||
|
|
||||||
"manage sub-channels using classes" in {
|
"manage sub-channels using classes" in {
|
||||||
val a = new A
|
val a = new A
|
||||||
val b1 = new B1
|
val b1 = new B2
|
||||||
val b2 = new B2
|
val b2 = new B3
|
||||||
val c = new C
|
val c = new C
|
||||||
val bus = new EventStream(system, false)
|
val bus = new EventStream(system, false)
|
||||||
within(2 seconds) {
|
within(2 seconds) {
|
||||||
bus.subscribe(testActor, classOf[B2]) should be(true)
|
bus.subscribe(testActor, classOf[B3]) should be(true)
|
||||||
bus.publish(c)
|
bus.publish(c)
|
||||||
bus.publish(b2)
|
bus.publish(b2)
|
||||||
expectMsg(b2)
|
expectMsg(b2)
|
||||||
|
|
@ -151,7 +151,7 @@ class EventStreamSpec extends AkkaSpec(EventStreamSpec.config) {
|
||||||
expectMsg(c)
|
expectMsg(c)
|
||||||
bus.publish(b1)
|
bus.publish(b1)
|
||||||
expectMsg(b1)
|
expectMsg(b1)
|
||||||
bus.unsubscribe(testActor, classOf[B1]) should be(true)
|
bus.unsubscribe(testActor, classOf[B2]) should be(true)
|
||||||
bus.publish(c)
|
bus.publish(c)
|
||||||
bus.publish(b2)
|
bus.publish(b2)
|
||||||
bus.publish(a)
|
bus.publish(a)
|
||||||
|
|
|
||||||
|
|
@ -97,8 +97,9 @@ object LoggerSpec {
|
||||||
override def mdc(currentMessage: Any): MDC = {
|
override def mdc(currentMessage: Any): MDC = {
|
||||||
reqId += 1
|
reqId += 1
|
||||||
val always = Map("requestId" -> reqId)
|
val always = Map("requestId" -> reqId)
|
||||||
|
val cmim = "Current Message in MDC"
|
||||||
val perMessage = currentMessage match {
|
val perMessage = currentMessage match {
|
||||||
case cm @ "Current Message in MDC" ⇒ Map("currentMsg" -> cm, "currentMsgLength" -> cm.length)
|
case `cmim` ⇒ Map[String, Any]("currentMsg" -> cmim, "currentMsgLength" -> cmim.length)
|
||||||
case _ ⇒ Map()
|
case _ ⇒ Map()
|
||||||
}
|
}
|
||||||
always ++ perMessage
|
always ++ perMessage
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import org.apache.commons.codec.binary.Hex.encodeHex
|
||||||
|
|
||||||
object SerializationTests {
|
object SerializationTests {
|
||||||
|
|
||||||
val serializeConf = """
|
val serializeConf = s"""
|
||||||
akka {
|
akka {
|
||||||
actor {
|
actor {
|
||||||
serialize-messages = off
|
serialize-messages = off
|
||||||
|
|
@ -29,13 +29,13 @@ object SerializationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
serialization-bindings {
|
serialization-bindings {
|
||||||
"akka.serialization.SerializationTests$Person" = java
|
"akka.serialization.SerializationTests$$Person" = java
|
||||||
"akka.serialization.SerializationTests$Address" = java
|
"akka.serialization.SerializationTests$$Address" = java
|
||||||
"akka.serialization.TestSerializable" = test
|
"akka.serialization.TestSerializable" = test
|
||||||
"akka.serialization.SerializationTests$PlainMessage" = test
|
"akka.serialization.SerializationTests$$PlainMessage" = test
|
||||||
"akka.serialization.SerializationTests$A" = java
|
"akka.serialization.SerializationTests$$A" = java
|
||||||
"akka.serialization.SerializationTests$B" = test
|
"akka.serialization.SerializationTests$$B" = test
|
||||||
"akka.serialization.SerializationTests$D" = test
|
"akka.serialization.SerializationTests$$D" = test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ private[akka] class LocalActorRef private[akka] (
|
||||||
* If this method returns true, it will never return false again, but if it
|
* If this method returns true, it will never return false again, but if it
|
||||||
* returns false, you cannot be sure if it's alive still (race condition)
|
* returns false, you cannot be sure if it's alive still (race condition)
|
||||||
*/
|
*/
|
||||||
@deprecated("Use context.watch(actor) and receive Terminated(actor)", "2.2") override def isTerminated: Boolean = actorCell.isTerminated
|
override def isTerminated: Boolean = actorCell.isTerminated
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the actor after initialization.
|
* Starts the actor after initialization.
|
||||||
|
|
|
||||||
|
|
@ -294,20 +294,20 @@ abstract class SupervisorStrategy {
|
||||||
def handleFailure(context: ActorContext, child: ActorRef, cause: Throwable, stats: ChildRestartStats, children: Iterable[ChildRestartStats]): Boolean = {
|
def handleFailure(context: ActorContext, child: ActorRef, cause: Throwable, stats: ChildRestartStats, children: Iterable[ChildRestartStats]): Boolean = {
|
||||||
val directive = decider.applyOrElse(cause, escalateDefault)
|
val directive = decider.applyOrElse(cause, escalateDefault)
|
||||||
directive match {
|
directive match {
|
||||||
case d @ Resume ⇒
|
case Resume ⇒
|
||||||
logFailure(context, child, cause, d)
|
logFailure(context, child, cause, directive)
|
||||||
resumeChild(child, cause)
|
resumeChild(child, cause)
|
||||||
true
|
true
|
||||||
case d @ Restart ⇒
|
case Restart ⇒
|
||||||
logFailure(context, child, cause, d)
|
logFailure(context, child, cause, directive)
|
||||||
processFailure(context, true, child, cause, stats, children)
|
processFailure(context, true, child, cause, stats, children)
|
||||||
true
|
true
|
||||||
case d @ Stop ⇒
|
case Stop ⇒
|
||||||
logFailure(context, child, cause, d)
|
logFailure(context, child, cause, directive)
|
||||||
processFailure(context, false, child, cause, stats, children)
|
processFailure(context, false, child, cause, stats, children)
|
||||||
true
|
true
|
||||||
case d @ Escalate ⇒
|
case Escalate ⇒
|
||||||
logFailure(context, child, cause, d)
|
logFailure(context, child, cause, directive)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -293,7 +293,7 @@ object TypedActor extends ExtensionId[TypedActorExtension] with ExtensionIdProvi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def withContext[T](unitOfWork: ⇒ T): T = {
|
protected def withContext[U](unitOfWork: ⇒ U): U = {
|
||||||
TypedActor.selfReference set proxyVar.get
|
TypedActor.selfReference set proxyVar.get
|
||||||
TypedActor.currentContext set context
|
TypedActor.currentContext set context
|
||||||
try unitOfWork finally {
|
try unitOfWork finally {
|
||||||
|
|
|
||||||
|
|
@ -300,7 +300,7 @@ class CircuitBreaker(scheduler: Scheduler, maxFailures: Int, callTimeout: Finite
|
||||||
*/
|
*/
|
||||||
def callThrough[T](body: ⇒ Future[T]): Future[T] = {
|
def callThrough[T](body: ⇒ Future[T]): Future[T] = {
|
||||||
|
|
||||||
def materialize[T](value: ⇒ Future[T]): Future[T] = try value catch { case NonFatal(t) ⇒ Future.failed(t) }
|
def materialize[U](value: ⇒ Future[U]): Future[U] = try value catch { case NonFatal(t) ⇒ Future.failed(t) }
|
||||||
|
|
||||||
if (callTimeout == Duration.Zero) {
|
if (callTimeout == Duration.Zero) {
|
||||||
materialize(body)
|
materialize(body)
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,6 @@ trait GracefulStopSupport {
|
||||||
* }}}
|
* }}}
|
||||||
*/
|
*/
|
||||||
def gracefulStop(target: ActorRef, timeout: FiniteDuration, stopMessage: Any = PoisonPill): Future[Boolean] = {
|
def gracefulStop(target: ActorRef, timeout: FiniteDuration, stopMessage: Any = PoisonPill): Future[Boolean] = {
|
||||||
if (target.isTerminated) Future successful true
|
|
||||||
else {
|
|
||||||
val internalTarget = target.asInstanceOf[InternalActorRef]
|
val internalTarget = target.asInstanceOf[InternalActorRef]
|
||||||
val ref = PromiseActorRef(internalTarget.provider, Timeout(timeout), target, stopMessage.getClass.getName)
|
val ref = PromiseActorRef(internalTarget.provider, Timeout(timeout), target, stopMessage.getClass.getName)
|
||||||
internalTarget.sendSystemMessage(Watch(internalTarget, ref))
|
internalTarget.sendSystemMessage(Watch(internalTarget, ref))
|
||||||
|
|
@ -59,5 +57,4 @@ trait GracefulStopSupport {
|
||||||
},
|
},
|
||||||
t ⇒ { internalTarget.sendSystemMessage(Unwatch(target, ref)); t })(ref.internalCallingThreadExecutionContext)
|
t ⇒ { internalTarget.sendSystemMessage(Unwatch(target, ref)); t })(ref.internalCallingThreadExecutionContext)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ private[cluster] final class ClusterDaemon(settings: ClusterSettings) extends Ac
|
||||||
withDispatcher(context.props.dispatcher), name = "heartbeatReceiver")
|
withDispatcher(context.props.dispatcher), name = "heartbeatReceiver")
|
||||||
|
|
||||||
def receive = {
|
def receive = {
|
||||||
case msg @ GetClusterCoreRef ⇒ coreSupervisor forward msg
|
case msg: GetClusterCoreRef.type ⇒ coreSupervisor forward msg
|
||||||
case AddOnMemberUpListener(code) ⇒
|
case AddOnMemberUpListener(code) ⇒
|
||||||
context.actorOf(Props(classOf[OnMemberUpListener], code).withDeploy(Deploy.local))
|
context.actorOf(Props(classOf[OnMemberUpListener], code).withDeploy(Deploy.local))
|
||||||
case PublisherCreated(publisher) ⇒
|
case PublisherCreated(publisher) ⇒
|
||||||
|
|
@ -657,6 +657,7 @@ private[cluster] class ClusterCoreDaemon(publisher: ActorRef) extends Actor with
|
||||||
case Same ⇒ gossipStats.incrementSameCount
|
case Same ⇒ gossipStats.incrementSameCount
|
||||||
case Newer ⇒ gossipStats.incrementNewerCount
|
case Newer ⇒ gossipStats.incrementNewerCount
|
||||||
case Older ⇒ gossipStats.incrementOlderCount
|
case Older ⇒ gossipStats.incrementOlderCount
|
||||||
|
case Ignored ⇒ gossipStats // included in receivedGossipCount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -246,21 +246,21 @@ private[cluster] object StressMultiJvmSpec extends MultiNodeConfig {
|
||||||
class ClusterResultAggregator(title: String, expectedResults: Int, settings: Settings) extends Actor with ActorLogging {
|
class ClusterResultAggregator(title: String, expectedResults: Int, settings: Settings) extends Actor with ActorLogging {
|
||||||
import settings.reportMetricsInterval
|
import settings.reportMetricsInterval
|
||||||
import settings.infolog
|
import settings.infolog
|
||||||
val cluster = Cluster(context.system)
|
private val cluster = Cluster(context.system)
|
||||||
var reportTo: Option[ActorRef] = None
|
private var reportTo: Option[ActorRef] = None
|
||||||
var results = Vector.empty[ClusterResult]
|
private var results = Vector.empty[ClusterResult]
|
||||||
var nodeMetrics = Set.empty[NodeMetrics]
|
private var nodeMetrics = Set.empty[NodeMetrics]
|
||||||
var phiValuesObservedByNode = {
|
private var phiValuesObservedByNode = {
|
||||||
import akka.cluster.Member.addressOrdering
|
import akka.cluster.Member.addressOrdering
|
||||||
immutable.SortedMap.empty[Address, immutable.SortedSet[PhiValue]]
|
immutable.SortedMap.empty[Address, immutable.SortedSet[PhiValue]]
|
||||||
}
|
}
|
||||||
var clusterStatsObservedByNode = {
|
private var clusterStatsObservedByNode = {
|
||||||
import akka.cluster.Member.addressOrdering
|
import akka.cluster.Member.addressOrdering
|
||||||
immutable.SortedMap.empty[Address, CurrentInternalStats]
|
immutable.SortedMap.empty[Address, CurrentInternalStats]
|
||||||
}
|
}
|
||||||
|
|
||||||
import context.dispatcher
|
import context.dispatcher
|
||||||
val reportMetricsTask = context.system.scheduler.schedule(
|
private val reportMetricsTask = context.system.scheduler.schedule(
|
||||||
reportMetricsInterval, reportMetricsInterval, self, ReportTick)
|
reportMetricsInterval, reportMetricsInterval, self, ReportTick)
|
||||||
|
|
||||||
// subscribe to ClusterMetricsChanged, re-subscribe when restart
|
// subscribe to ClusterMetricsChanged, re-subscribe when restart
|
||||||
|
|
@ -441,9 +441,9 @@ private[cluster] object StressMultiJvmSpec extends MultiNodeConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
class StatsObserver extends Actor {
|
class StatsObserver extends Actor {
|
||||||
val cluster = Cluster(context.system)
|
private val cluster = Cluster(context.system)
|
||||||
var reportTo: Option[ActorRef] = None
|
private var reportTo: Option[ActorRef] = None
|
||||||
var startStats: Option[GossipStats] = None
|
private var startStats: Option[GossipStats] = None
|
||||||
|
|
||||||
override def preStart(): Unit = cluster.subscribe(self, classOf[CurrentInternalStats])
|
override def preStart(): Unit = cluster.subscribe(self, classOf[CurrentInternalStats])
|
||||||
override def postStop(): Unit = cluster.unsubscribe(self)
|
override def postStop(): Unit = cluster.unsubscribe(self)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ object ClusterConsistentHashingRouterMultiJvmSpec extends MultiNodeConfig {
|
||||||
val third = role("third")
|
val third = role("third")
|
||||||
|
|
||||||
commonConfig(debugConfig(on = false).
|
commonConfig(debugConfig(on = false).
|
||||||
withFallback(ConfigFactory.parseString("""
|
withFallback(ConfigFactory.parseString(s"""
|
||||||
common-router-settings = {
|
common-router-settings = {
|
||||||
router = consistent-hashing-pool
|
router = consistent-hashing-pool
|
||||||
nr-of-instances = 10
|
nr-of-instances = 10
|
||||||
|
|
@ -48,9 +48,9 @@ object ClusterConsistentHashingRouterMultiJvmSpec extends MultiNodeConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
akka.actor.deployment {
|
akka.actor.deployment {
|
||||||
/router1 = ${common-router-settings}
|
/router1 = $${common-router-settings}
|
||||||
/router3 = ${common-router-settings}
|
/router3 = $${common-router-settings}
|
||||||
/router4 = ${common-router-settings}
|
/router4 = $${common-router-settings}
|
||||||
}
|
}
|
||||||
""")).
|
""")).
|
||||||
withFallback(MultiNodeClusterSpec.clusterConfig))
|
withFallback(MultiNodeClusterSpec.clusterConfig))
|
||||||
|
|
|
||||||
|
|
@ -49,14 +49,14 @@ class ClusterHeartbeatSenderStateSpec extends WordSpec with Matchers {
|
||||||
val dd = UniqueAddress(Address("akka.tcp", "sys", "dd", 2552), 4)
|
val dd = UniqueAddress(Address("akka.tcp", "sys", "dd", 2552), 4)
|
||||||
val ee = UniqueAddress(Address("akka.tcp", "sys", "ee", 2552), 5)
|
val ee = UniqueAddress(Address("akka.tcp", "sys", "ee", 2552), 5)
|
||||||
|
|
||||||
def emptyState: ClusterHeartbeatSenderState = emptyState(aa)
|
private def emptyState: ClusterHeartbeatSenderState = emptyState(aa)
|
||||||
|
|
||||||
def emptyState(selfUniqueAddress: UniqueAddress) = ClusterHeartbeatSenderState(
|
private def emptyState(selfUniqueAddress: UniqueAddress) = ClusterHeartbeatSenderState(
|
||||||
ring = HeartbeatNodeRing(selfUniqueAddress, Set(selfUniqueAddress), Set.empty, monitoredByNrOfMembers = 3),
|
ring = HeartbeatNodeRing(selfUniqueAddress, Set(selfUniqueAddress), Set.empty, monitoredByNrOfMembers = 3),
|
||||||
oldReceiversNowUnreachable = Set.empty[UniqueAddress],
|
oldReceiversNowUnreachable = Set.empty[UniqueAddress],
|
||||||
failureDetector = new DefaultFailureDetectorRegistry[Address](() ⇒ new FailureDetectorStub))
|
failureDetector = new DefaultFailureDetectorRegistry[Address](() ⇒ new FailureDetectorStub))
|
||||||
|
|
||||||
def fd(state: ClusterHeartbeatSenderState, node: UniqueAddress): FailureDetectorStub =
|
private def fd(state: ClusterHeartbeatSenderState, node: UniqueAddress): FailureDetectorStub =
|
||||||
state.failureDetector.asInstanceOf[DefaultFailureDetectorRegistry[Address]].failureDetector(node.address).
|
state.failureDetector.asInstanceOf[DefaultFailureDetectorRegistry[Address]].failureDetector(node.address).
|
||||||
get.asInstanceOf[FailureDetectorStub]
|
get.asInstanceOf[FailureDetectorStub]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,10 @@ class HeartbeatNodeRingPerfSpec extends WordSpec with Matchers {
|
||||||
|
|
||||||
val heartbeatNodeRing = createHeartbeatNodeRingOfSize(nodesSize)
|
val heartbeatNodeRing = createHeartbeatNodeRingOfSize(nodesSize)
|
||||||
|
|
||||||
def checkThunkForRing(ring: HeartbeatNodeRing, thunk: HeartbeatNodeRing ⇒ Unit, times: Int): Unit =
|
private def checkThunkForRing(ring: HeartbeatNodeRing, thunk: HeartbeatNodeRing ⇒ Unit, times: Int): Unit =
|
||||||
for (i ← 1 to times) thunk(ring)
|
for (i ← 1 to times) thunk(ring)
|
||||||
|
|
||||||
def myReceivers(ring: HeartbeatNodeRing): Unit = {
|
private def myReceivers(ring: HeartbeatNodeRing): Unit = {
|
||||||
val r = HeartbeatNodeRing(ring.selfAddress, ring.nodes, Set.empty, ring.monitoredByNrOfMembers)
|
val r = HeartbeatNodeRing(ring.selfAddress, ring.nodes, Set.empty, ring.monitoredByNrOfMembers)
|
||||||
r.myReceivers.isEmpty should be(false)
|
r.myReceivers.isEmpty should be(false)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class ReachabilityPerfSpec extends WordSpec with Matchers {
|
||||||
val address = Address("akka.tcp", "sys", "a", 2552)
|
val address = Address("akka.tcp", "sys", "a", 2552)
|
||||||
val node = Address("akka.tcp", "sys", "a", 2552)
|
val node = Address("akka.tcp", "sys", "a", 2552)
|
||||||
|
|
||||||
def createReachabilityOfSize(base: Reachability, size: Int): Reachability =
|
private def createReachabilityOfSize(base: Reachability, size: Int): Reachability =
|
||||||
(base /: (1 to size)) {
|
(base /: (1 to size)) {
|
||||||
case (r, i) ⇒
|
case (r, i) ⇒
|
||||||
val observer = UniqueAddress(address.copy(host = Some("node-" + i)), i)
|
val observer = UniqueAddress(address.copy(host = Some("node-" + i)), i)
|
||||||
|
|
@ -25,7 +25,7 @@ class ReachabilityPerfSpec extends WordSpec with Matchers {
|
||||||
r.unreachable(observer, subject).reachable(observer, subject)
|
r.unreachable(observer, subject).reachable(observer, subject)
|
||||||
}
|
}
|
||||||
|
|
||||||
def addUnreachable(base: Reachability, count: Int): Reachability = {
|
private def addUnreachable(base: Reachability, count: Int): Reachability = {
|
||||||
val observers = base.allObservers.take(count)
|
val observers = base.allObservers.take(count)
|
||||||
val subjects = Stream.continually(base.allObservers).flatten.iterator
|
val subjects = Stream.continually(base.allObservers).flatten.iterator
|
||||||
(base /: observers) {
|
(base /: observers) {
|
||||||
|
|
@ -39,43 +39,43 @@ class ReachabilityPerfSpec extends WordSpec with Matchers {
|
||||||
val reachability3 = addUnreachable(reachability1, nodesSize / 2)
|
val reachability3 = addUnreachable(reachability1, nodesSize / 2)
|
||||||
val allowed = reachability1.allObservers
|
val allowed = reachability1.allObservers
|
||||||
|
|
||||||
def checkThunkFor(r1: Reachability, r2: Reachability, thunk: (Reachability, Reachability) ⇒ Unit, times: Int): Unit = {
|
private def checkThunkFor(r1: Reachability, r2: Reachability, thunk: (Reachability, Reachability) ⇒ Unit, times: Int): Unit = {
|
||||||
for (i ← 1 to times) {
|
for (i ← 1 to times) {
|
||||||
thunk(Reachability(r1.records, r1.versions), Reachability(r2.records, r2.versions))
|
thunk(Reachability(r1.records, r1.versions), Reachability(r2.records, r2.versions))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def checkThunkFor(r1: Reachability, thunk: Reachability ⇒ Unit, times: Int): Unit = {
|
private def checkThunkFor(r1: Reachability, thunk: Reachability ⇒ Unit, times: Int): Unit = {
|
||||||
for (i ← 1 to times) {
|
for (i ← 1 to times) {
|
||||||
thunk(Reachability(r1.records, r1.versions))
|
thunk(Reachability(r1.records, r1.versions))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def merge(expectedRecords: Int)(r1: Reachability, r2: Reachability): Unit = {
|
private def merge(expectedRecords: Int)(r1: Reachability, r2: Reachability): Unit = {
|
||||||
r1.merge(allowed, r2).records.size should be(expectedRecords)
|
r1.merge(allowed, r2).records.size should be(expectedRecords)
|
||||||
}
|
}
|
||||||
|
|
||||||
def checkStatus(r1: Reachability): Unit = {
|
private def checkStatus(r1: Reachability): Unit = {
|
||||||
val record = r1.records.head
|
val record = r1.records.head
|
||||||
r1.status(record.observer, record.subject) should be(record.status)
|
r1.status(record.observer, record.subject) should be(record.status)
|
||||||
}
|
}
|
||||||
|
|
||||||
def checkAggregatedStatus(r1: Reachability): Unit = {
|
private def checkAggregatedStatus(r1: Reachability): Unit = {
|
||||||
val record = r1.records.head
|
val record = r1.records.head
|
||||||
r1.status(record.subject) should be(record.status)
|
r1.status(record.subject) should be(record.status)
|
||||||
}
|
}
|
||||||
|
|
||||||
def allUnreachableOrTerminated(r1: Reachability): Unit = {
|
private def allUnreachableOrTerminated(r1: Reachability): Unit = {
|
||||||
val record = r1.records.head
|
val record = r1.records.head
|
||||||
r1.allUnreachableOrTerminated.isEmpty should be(false)
|
r1.allUnreachableOrTerminated.isEmpty should be(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
def allUnreachable(r1: Reachability): Unit = {
|
private def allUnreachable(r1: Reachability): Unit = {
|
||||||
val record = r1.records.head
|
val record = r1.records.head
|
||||||
r1.allUnreachable.isEmpty should be(false)
|
r1.allUnreachable.isEmpty should be(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
def recordsFrom(r1: Reachability): Unit = {
|
private def recordsFrom(r1: Reachability): Unit = {
|
||||||
r1.allObservers.foreach { o ⇒
|
r1.allObservers.foreach { o ⇒
|
||||||
r1.recordsFrom(o) should not be be(null)
|
r1.recordsFrom(o) should not be be(null)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ object DistributedPubSubMediator {
|
||||||
|
|
||||||
def business: Receive
|
def business: Receive
|
||||||
|
|
||||||
def receive = business orElse defaultReceive
|
def receive = business.orElse[Any, Unit](defaultReceive)
|
||||||
|
|
||||||
def remove(ref: ActorRef): Unit = {
|
def remove(ref: ActorRef): Unit = {
|
||||||
if (subscribers.contains(ref))
|
if (subscribers.contains(ref))
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ trait ReceivePipeline extends Actor {
|
||||||
val around = aroundCache match {
|
val around = aroundCache match {
|
||||||
case Some((`receive`, cached)) ⇒ cached
|
case Some((`receive`, cached)) ⇒ cached
|
||||||
case _ ⇒
|
case _ ⇒
|
||||||
val zipped = pipeline.foldRight(receive)((outer, inner) ⇒ outer(inner) orElse inner)
|
val zipped = pipeline.foldRight[Receive](receive)((outer, inner) ⇒ outer(inner).orElse[Any, Unit](inner))
|
||||||
aroundCache = Some((receive, zipped))
|
aroundCache = Some((receive, zipped))
|
||||||
zipped
|
zipped
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,11 @@ package akka.contrib.pattern
|
||||||
|
|
||||||
import akka.testkit.{ ImplicitSender, AkkaSpec }
|
import akka.testkit.{ ImplicitSender, AkkaSpec }
|
||||||
import akka.actor.{ Actor, Props }
|
import akka.actor.{ Actor, Props }
|
||||||
|
import scala.concurrent.duration._
|
||||||
|
|
||||||
class ReplierActor extends Actor with ReceivePipeline {
|
object ReceivePipelineSpec {
|
||||||
|
|
||||||
|
class ReplierActor extends Actor with ReceivePipeline {
|
||||||
def receive: Actor.Receive = becomeAndReply
|
def receive: Actor.Receive = becomeAndReply
|
||||||
def becomeAndReply: Actor.Receive = {
|
def becomeAndReply: Actor.Receive = {
|
||||||
case "become" ⇒ context.become(justReply)
|
case "become" ⇒ context.become(justReply)
|
||||||
|
|
@ -12,39 +15,47 @@ class ReplierActor extends Actor with ReceivePipeline {
|
||||||
def justReply: Actor.Receive = {
|
def justReply: Actor.Receive = {
|
||||||
case m ⇒ sender ! m
|
case m ⇒ sender ! m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ListBuilderInterceptor {
|
case class IntList(l: List[Int]) {
|
||||||
|
override def toString: String = s"IntList(${l.mkString(", ")})"
|
||||||
|
}
|
||||||
|
|
||||||
|
trait ListBuilderInterceptor {
|
||||||
this: ReceivePipeline ⇒
|
this: ReceivePipeline ⇒
|
||||||
|
|
||||||
pipelineOuter(inner ⇒
|
pipelineOuter(inner ⇒
|
||||||
{
|
{
|
||||||
case n: Int ⇒ inner((n until n + 3).toList)
|
case n: Int ⇒ inner(IntList((n until n + 3).toList))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
trait AdderInterceptor {
|
trait AdderInterceptor {
|
||||||
this: ReceivePipeline ⇒
|
this: ReceivePipeline ⇒
|
||||||
|
|
||||||
pipelineInner(inner ⇒
|
pipelineInner(inner ⇒
|
||||||
{
|
{
|
||||||
case n: Int ⇒ inner(n + 10)
|
case n: Int ⇒ inner(n + 10)
|
||||||
case l: List[Int] ⇒ inner(l.map(_ + 10))
|
case IntList(l) ⇒ inner(IntList(l.map(_ + 10)))
|
||||||
case "explicitly ignored" ⇒
|
case "explicitly ignored" ⇒
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ToStringInterceptor {
|
trait ToStringInterceptor {
|
||||||
this: ReceivePipeline ⇒
|
this: ReceivePipeline ⇒
|
||||||
|
|
||||||
pipelineInner(inner ⇒
|
pipelineInner(inner ⇒
|
||||||
{
|
{
|
||||||
case i: Int ⇒ inner(i.toString)
|
case i: Int ⇒ inner(i.toString)
|
||||||
case l: Iterable[_] ⇒ inner(l.toString())
|
case IntList(l) ⇒ inner(l.toString)
|
||||||
|
case other: Iterable[_] ⇒ inner(other.toString)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ReceivePipelineSpec extends AkkaSpec with ImplicitSender {
|
class ReceivePipelineSpec extends AkkaSpec with ImplicitSender {
|
||||||
|
import ReceivePipelineSpec._
|
||||||
|
|
||||||
"A ReceivePipeline" must {
|
"A ReceivePipeline" must {
|
||||||
|
|
||||||
|
|
@ -82,7 +93,8 @@ class ReceivePipelineSpec extends AkkaSpec with ImplicitSender {
|
||||||
val replier = system.actorOf(Props(
|
val replier = system.actorOf(Props(
|
||||||
new ReplierActor with ListBuilderInterceptor with AdderInterceptor with ToStringInterceptor))
|
new ReplierActor with ListBuilderInterceptor with AdderInterceptor with ToStringInterceptor))
|
||||||
replier ! "explicitly ignored"
|
replier ! "explicitly ignored"
|
||||||
expectNoMsg()
|
replier ! 8L // unhandled by all interceptors but still replied
|
||||||
|
expectMsg(8L)
|
||||||
}
|
}
|
||||||
|
|
||||||
"support changing behavior without losing the interceptions" in {
|
"support changing behavior without losing the interceptions" in {
|
||||||
|
|
@ -101,9 +113,9 @@ class ReceivePipelineSpec extends AkkaSpec with ImplicitSender {
|
||||||
val innerOuterReplier = system.actorOf(Props(
|
val innerOuterReplier = system.actorOf(Props(
|
||||||
new ReplierActor with AdderInterceptor with ListBuilderInterceptor))
|
new ReplierActor with AdderInterceptor with ListBuilderInterceptor))
|
||||||
outerInnerReplier ! 4
|
outerInnerReplier ! 4
|
||||||
expectMsg(List(14, 15, 16))
|
expectMsg(IntList(List(14, 15, 16)))
|
||||||
innerOuterReplier ! 6
|
innerOuterReplier ! 6
|
||||||
expectMsg(List(16, 17, 18))
|
expectMsg(IntList(List(16, 17, 18)))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -231,7 +243,7 @@ object MixinSample extends App {
|
||||||
// The Dude says 'Yeah, well, you know, that's just, like, your opinion, man.'
|
// The Dude says 'Yeah, well, you know, that's just, like, your opinion, man.'
|
||||||
//#mixin-actor
|
//#mixin-actor
|
||||||
|
|
||||||
system.shutdown()
|
system.terminate()
|
||||||
}
|
}
|
||||||
|
|
||||||
object UnhandledSample extends App {
|
object UnhandledSample extends App {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ class MyActor extends Actor {
|
||||||
case BarMessage(bar) => sender() ! BazMessage("Got " + bar)
|
case BarMessage(bar) => sender() ! BazMessage("Got " + bar)
|
||||||
// warning here:
|
// warning here:
|
||||||
// "match may not be exhaustive. It would fail on the following input: FooMessage(_)"
|
// "match may not be exhaustive. It would fail on the following input: FooMessage(_)"
|
||||||
|
//#exhaustiveness-check
|
||||||
|
case FooMessage(_) => // avoid the warning in our build logs
|
||||||
|
//#exhaustiveness-check
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -554,6 +554,7 @@ public class FutureDocTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public void useAfter() throws Exception {
|
public void useAfter() throws Exception {
|
||||||
//#after
|
//#after
|
||||||
final ExecutionContext ec = system.dispatcher();
|
final ExecutionContext ec = system.dispatcher();
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ class Consumer extends Actor with ActorLogging with ConsumerBehavior {
|
||||||
class ProducerConsumer extends Actor with ActorLogging
|
class ProducerConsumer extends Actor with ActorLogging
|
||||||
with ProducerBehavior with ConsumerBehavior {
|
with ProducerBehavior with ConsumerBehavior {
|
||||||
|
|
||||||
def receive = producerBehavior orElse consumerBehavior
|
def receive = producerBehavior.orElse[Any, Unit](consumerBehavior)
|
||||||
}
|
}
|
||||||
|
|
||||||
// protocol
|
// protocol
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,10 @@ import akka.util.ByteString
|
||||||
import akka.actor.Props
|
import akka.actor.Props
|
||||||
import scala.collection.immutable
|
import scala.collection.immutable
|
||||||
|
|
||||||
class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
|
object FSMDocSpec {
|
||||||
|
// messages and data types
|
||||||
//#fsm-code-elided
|
//#test-code
|
||||||
//#simple-imports
|
import akka.actor.ActorRef
|
||||||
import akka.actor.{ ActorRef, FSM }
|
|
||||||
import scala.concurrent.duration._
|
|
||||||
//#simple-imports
|
|
||||||
//#simple-events
|
//#simple-events
|
||||||
// received events
|
// received events
|
||||||
final case class SetTarget(ref: ActorRef)
|
final case class SetTarget(ref: ActorRef)
|
||||||
|
|
@ -38,6 +35,17 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
|
||||||
case object Uninitialized extends Data
|
case object Uninitialized extends Data
|
||||||
final case class Todo(target: ActorRef, queue: immutable.Seq[Any]) extends Data
|
final case class Todo(target: ActorRef, queue: immutable.Seq[Any]) extends Data
|
||||||
//#simple-state
|
//#simple-state
|
||||||
|
//#test-code
|
||||||
|
}
|
||||||
|
|
||||||
|
class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
|
||||||
|
import FSMDocSpec._
|
||||||
|
|
||||||
|
//#fsm-code-elided
|
||||||
|
//#simple-imports
|
||||||
|
import akka.actor.{ ActorRef, FSM }
|
||||||
|
import scala.concurrent.duration._
|
||||||
|
//#simple-imports
|
||||||
//#simple-fsm
|
//#simple-fsm
|
||||||
class Buncher extends FSM[State, Data] {
|
class Buncher extends FSM[State, Data] {
|
||||||
|
|
||||||
|
|
@ -56,6 +64,7 @@ class FSMDocSpec extends MyFavoriteTestFrameWorkPlusAkkaTestKit {
|
||||||
case Active -> Idle =>
|
case Active -> Idle =>
|
||||||
stateData match {
|
stateData match {
|
||||||
case Todo(ref, queue) => ref ! Batch(queue)
|
case Todo(ref, queue) => ref ! Batch(queue)
|
||||||
|
case _ => // nothing to do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//#transition-elided
|
//#transition-elided
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,8 @@ class Worker extends Actor with ActorLogging {
|
||||||
//#messages
|
//#messages
|
||||||
object CounterService {
|
object CounterService {
|
||||||
final case class Increment(n: Int)
|
final case class Increment(n: Int)
|
||||||
case object GetCurrentCount
|
sealed abstract class GetCurrentCount
|
||||||
|
case object GetCurrentCount extends GetCurrentCount
|
||||||
final case class CurrentCount(key: String, count: Long)
|
final case class CurrentCount(key: String, count: Long)
|
||||||
class ServiceUnavailable(msg: String) extends RuntimeException(msg)
|
class ServiceUnavailable(msg: String) extends RuntimeException(msg)
|
||||||
|
|
||||||
|
|
@ -176,9 +177,9 @@ class CounterService extends Actor {
|
||||||
for ((replyTo, msg) <- backlog) c.tell(msg, sender = replyTo)
|
for ((replyTo, msg) <- backlog) c.tell(msg, sender = replyTo)
|
||||||
backlog = IndexedSeq.empty
|
backlog = IndexedSeq.empty
|
||||||
|
|
||||||
case msg @ Increment(n) => forwardOrPlaceInBacklog(msg)
|
case msg: Increment => forwardOrPlaceInBacklog(msg)
|
||||||
|
|
||||||
case msg @ GetCurrentCount => forwardOrPlaceInBacklog(msg)
|
case msg: GetCurrentCount => forwardOrPlaceInBacklog(msg)
|
||||||
|
|
||||||
case Terminated(actorRef) if Some(actorRef) == storage =>
|
case Terminated(actorRef) if Some(actorRef) == storage =>
|
||||||
// After 3 restarts the storage child is stopped.
|
// After 3 restarts the storage child is stopped.
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ class TypedActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
|
||||||
//#typed-actor-call-strict
|
//#typed-actor-call-strict
|
||||||
//#typed-actor-calls
|
//#typed-actor-calls
|
||||||
|
|
||||||
Await.result(fSquare, 3 seconds) should be(100)
|
Await.result(fSquare, 3.seconds) should be(100)
|
||||||
|
|
||||||
oSquare should be(Some(100))
|
oSquare should be(Some(100))
|
||||||
|
|
||||||
|
|
@ -193,7 +193,7 @@ class TypedActorDocSpec extends AkkaSpec(Map("akka.loglevel" -> "INFO")) {
|
||||||
|
|
||||||
TypedActor(system).poisonPill(awesomeFooBar)
|
TypedActor(system).poisonPill(awesomeFooBar)
|
||||||
//#typed-actor-supercharge-usage
|
//#typed-actor-supercharge-usage
|
||||||
Await.result(f, 3 seconds) should be("YES")
|
Await.result(f, 3.seconds) should be("YES")
|
||||||
}
|
}
|
||||||
|
|
||||||
"typed router pattern" in {
|
"typed router pattern" in {
|
||||||
|
|
|
||||||
|
|
@ -70,18 +70,19 @@ class EchoManager(handlerClass: Class[_]) extends Actor with ActorLogging {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#echo-handler
|
||||||
object EchoHandler {
|
object EchoHandler {
|
||||||
|
final case class Ack(offset: Int) extends Tcp.Event
|
||||||
|
|
||||||
def props(connection: ActorRef, remote: InetSocketAddress): Props =
|
def props(connection: ActorRef, remote: InetSocketAddress): Props =
|
||||||
Props(classOf[EchoHandler], connection, remote)
|
Props(classOf[EchoHandler], connection, remote)
|
||||||
}
|
}
|
||||||
|
|
||||||
//#echo-handler
|
|
||||||
class EchoHandler(connection: ActorRef, remote: InetSocketAddress)
|
class EchoHandler(connection: ActorRef, remote: InetSocketAddress)
|
||||||
extends Actor with ActorLogging {
|
extends Actor with ActorLogging {
|
||||||
|
|
||||||
import Tcp._
|
import Tcp._
|
||||||
|
import EchoHandler._
|
||||||
final case class Ack(offset: Int) extends Event
|
|
||||||
|
|
||||||
// sign death pact: this actor terminates when connection breaks
|
// sign death pact: this actor terminates when connection breaks
|
||||||
context watch connection
|
context watch connection
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,8 @@ object ScalaUdpDocSpec {
|
||||||
//#connected
|
//#connected
|
||||||
case msg: String =>
|
case msg: String =>
|
||||||
connection ! UdpConnected.Send(ByteString(msg))
|
connection ! UdpConnected.Send(ByteString(msg))
|
||||||
case d @ UdpConnected.Disconnect => connection ! d
|
case UdpConnected.Disconnect =>
|
||||||
|
connection ! UdpConnected.Disconnect
|
||||||
case UdpConnected.Disconnected => context.stop(self)
|
case UdpConnected.Disconnected => context.stop(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,19 @@
|
||||||
|
|
||||||
package docs.persistence
|
package docs.persistence
|
||||||
|
|
||||||
import akka.actor.{ Actor, ActorSystem, Props }
|
import akka.actor.{ Actor, ActorRef, ActorSystem, Props }
|
||||||
import akka.persistence._
|
import akka.persistence._
|
||||||
import com.typesafe.config.ConfigFactory
|
import com.typesafe.config.ConfigFactory
|
||||||
|
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
import scala.language.postfixOps
|
import scala.language.postfixOps
|
||||||
trait PersistenceDocSpec {
|
|
||||||
|
object PersistenceDocSpec {
|
||||||
|
|
||||||
|
trait SomeOtherMessage
|
||||||
|
|
||||||
|
val persistentActor: ActorRef = ???
|
||||||
|
|
||||||
val config =
|
val config =
|
||||||
"""
|
"""
|
||||||
//#auto-update-interval
|
//#auto-update-interval
|
||||||
|
|
@ -21,13 +27,7 @@ trait PersistenceDocSpec {
|
||||||
//#auto-update
|
//#auto-update
|
||||||
"""
|
"""
|
||||||
|
|
||||||
trait SomeOtherMessage
|
object Recovery {
|
||||||
|
|
||||||
implicit val system: ActorSystem
|
|
||||||
|
|
||||||
import system._
|
|
||||||
|
|
||||||
new AnyRef {
|
|
||||||
trait MyPersistentActor1 extends PersistentActor {
|
trait MyPersistentActor1 extends PersistentActor {
|
||||||
//#recover-on-start-disabled
|
//#recover-on-start-disabled
|
||||||
override def preStart() = ()
|
override def preStart() = ()
|
||||||
|
|
@ -45,7 +45,6 @@ trait PersistenceDocSpec {
|
||||||
//#recover-on-start-custom
|
//#recover-on-start-custom
|
||||||
}
|
}
|
||||||
|
|
||||||
val persistentActor = system.deadLetters
|
|
||||||
//#recover-explicit
|
//#recover-explicit
|
||||||
persistentActor ! Recover()
|
persistentActor ! Recover()
|
||||||
//#recover-explicit
|
//#recover-explicit
|
||||||
|
|
@ -69,7 +68,7 @@ trait PersistenceDocSpec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new AnyRef {
|
object NoRecovery {
|
||||||
trait MyPersistentActor1 extends PersistentActor {
|
trait MyPersistentActor1 extends PersistentActor {
|
||||||
//#recover-fully-disabled
|
//#recover-fully-disabled
|
||||||
override def preStart() = self ! Recover(toSequenceNr = 0L)
|
override def preStart() = self ! Recover(toSequenceNr = 0L)
|
||||||
|
|
@ -77,7 +76,7 @@ trait PersistenceDocSpec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new AnyRef {
|
object PersistenceId {
|
||||||
trait PersistentActorMethods {
|
trait PersistentActorMethods {
|
||||||
//#persistence-id
|
//#persistence-id
|
||||||
def persistenceId: String
|
def persistenceId: String
|
||||||
|
|
@ -101,7 +100,7 @@ trait PersistenceDocSpec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new AnyRef {
|
object AtLeastOnce {
|
||||||
//#at-least-once-example
|
//#at-least-once-example
|
||||||
import akka.actor.{ Actor, ActorPath }
|
import akka.actor.{ Actor, ActorPath }
|
||||||
import akka.persistence.AtLeastOnceDelivery
|
import akka.persistence.AtLeastOnceDelivery
|
||||||
|
|
@ -145,7 +144,7 @@ trait PersistenceDocSpec {
|
||||||
//#at-least-once-example
|
//#at-least-once-example
|
||||||
}
|
}
|
||||||
|
|
||||||
new AnyRef {
|
object SaveSnapshot {
|
||||||
|
|
||||||
class MyPersistentActor extends PersistentActor {
|
class MyPersistentActor extends PersistentActor {
|
||||||
override def persistenceId = "my-stable-persistence-id"
|
override def persistenceId = "my-stable-persistence-id"
|
||||||
|
|
@ -164,7 +163,7 @@ trait PersistenceDocSpec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new AnyRef {
|
object OfferSnapshot {
|
||||||
class MyPersistentActor extends PersistentActor {
|
class MyPersistentActor extends PersistentActor {
|
||||||
override def persistenceId = "my-stable-persistence-id"
|
override def persistenceId = "my-stable-persistence-id"
|
||||||
|
|
||||||
|
|
@ -183,8 +182,6 @@ trait PersistenceDocSpec {
|
||||||
|
|
||||||
import akka.actor.Props
|
import akka.actor.Props
|
||||||
|
|
||||||
val persistentActor = system.actorOf(Props[MyPersistentActor])
|
|
||||||
|
|
||||||
//#snapshot-criteria
|
//#snapshot-criteria
|
||||||
persistentActor ! Recover(fromSnapshot = SnapshotSelectionCriteria(
|
persistentActor ! Recover(fromSnapshot = SnapshotSelectionCriteria(
|
||||||
maxSequenceNr = 457L,
|
maxSequenceNr = 457L,
|
||||||
|
|
@ -192,9 +189,7 @@ trait PersistenceDocSpec {
|
||||||
//#snapshot-criteria
|
//#snapshot-criteria
|
||||||
}
|
}
|
||||||
|
|
||||||
new AnyRef {
|
object PersistAsync {
|
||||||
|
|
||||||
val persistentActor = system.actorOf(Props[MyPersistentActor]())
|
|
||||||
|
|
||||||
//#persist-async
|
//#persist-async
|
||||||
class MyPersistentActor extends PersistentActor {
|
class MyPersistentActor extends PersistentActor {
|
||||||
|
|
@ -228,9 +223,8 @@ trait PersistenceDocSpec {
|
||||||
|
|
||||||
//#persist-async
|
//#persist-async
|
||||||
}
|
}
|
||||||
new AnyRef {
|
|
||||||
|
|
||||||
val persistentActor = system.actorOf(Props[MyPersistentActor]())
|
object Defer {
|
||||||
|
|
||||||
//#defer
|
//#defer
|
||||||
class MyPersistentActor extends PersistentActor {
|
class MyPersistentActor extends PersistentActor {
|
||||||
|
|
@ -268,9 +262,12 @@ trait PersistenceDocSpec {
|
||||||
|
|
||||||
//#defer-caller
|
//#defer-caller
|
||||||
}
|
}
|
||||||
new AnyRef {
|
|
||||||
|
object View {
|
||||||
import akka.actor.Props
|
import akka.actor.Props
|
||||||
|
|
||||||
|
val system: ActorSystem = ???
|
||||||
|
|
||||||
//#view
|
//#view
|
||||||
class MyView extends PersistentView {
|
class MyView extends PersistentView {
|
||||||
override def persistenceId: String = "some-persistence-id"
|
override def persistenceId: String = "some-persistence-id"
|
||||||
|
|
|
||||||
|
|
@ -193,10 +193,11 @@ private[akka] class ClientFSM(name: RoleName, controllerAddr: InetSocketAddress)
|
||||||
case Event(ToServer(msg), d @ Data(Some(channel), None)) ⇒
|
case Event(ToServer(msg), d @ Data(Some(channel), None)) ⇒
|
||||||
channel.write(msg)
|
channel.write(msg)
|
||||||
val token = msg match {
|
val token = msg match {
|
||||||
case EnterBarrier(barrier, timeout) ⇒ barrier
|
case EnterBarrier(barrier, timeout) ⇒ Some(barrier -> sender())
|
||||||
case GetAddress(node) ⇒ node.name
|
case GetAddress(node) ⇒ Some(node.name -> sender())
|
||||||
|
case _ ⇒ None
|
||||||
}
|
}
|
||||||
stay using d.copy(runningOp = Some(token -> sender()))
|
stay using d.copy(runningOp = token)
|
||||||
case Event(ToServer(op), Data(channel, Some((token, _)))) ⇒
|
case Event(ToServer(op), Data(channel, Some((token, _)))) ⇒
|
||||||
log.error("cannot write {} while waiting for {}", op, token)
|
log.error("cannot write {} while waiting for {}", op, token)
|
||||||
stay
|
stay
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class DefaultOSGiLogger extends DefaultLogger {
|
||||||
|
|
||||||
val messageFormat = " %s | %s | %s | %s"
|
val messageFormat = " %s | %s | %s | %s"
|
||||||
|
|
||||||
override def receive: Receive = uninitialisedReceive orElse super.receive
|
override def receive: Receive = uninitialisedReceive.orElse[Any, Unit](super.receive)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Behaviour of the logger that waits for its LogService
|
* Behaviour of the logger that waits for its LogService
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ object SnapshotSpec {
|
||||||
|
|
||||||
override def receiveRecover: Receive = {
|
override def receiveRecover: Receive = {
|
||||||
case payload: String ⇒ state = s"${payload}-${lastSequenceNr}" :: state
|
case payload: String ⇒ state = s"${payload}-${lastSequenceNr}" :: state
|
||||||
case SnapshotOffer(_, snapshot: List[String]) ⇒ state = snapshot
|
case SnapshotOffer(_, snapshot: List[_]) ⇒ state = snapshot.asInstanceOf[List[String]]
|
||||||
}
|
}
|
||||||
|
|
||||||
override def receiveCommand = {
|
override def receiveCommand = {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
package akka.remote
|
package akka.remote
|
||||||
|
|
||||||
import language.postfixOps
|
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
import com.typesafe.config.ConfigFactory
|
import com.typesafe.config.ConfigFactory
|
||||||
import akka.actor._
|
import akka.actor._
|
||||||
import akka.testkit._
|
import akka.testkit._
|
||||||
import akka.remote.AddressUidExtension
|
|
||||||
import akka.remote.testkit.{ MultiNodeConfig, MultiNodeSpec, STMultiNodeSpec }
|
import akka.remote.testkit.{ MultiNodeConfig, MultiNodeSpec, STMultiNodeSpec }
|
||||||
import akka.remote.testconductor.RoleName
|
import akka.remote.testconductor.RoleName
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -586,16 +586,16 @@ class RemotingSpec extends AkkaSpec(RemotingSpec.cfg) with ImplicitSender with D
|
||||||
""").withFallback(config)
|
""").withFallback(config)
|
||||||
val otherSelection = thisSystem.actorSelection(s"akka.tcp://other-system@localhost:${otherAddress.getPort}/user/echo")
|
val otherSelection = thisSystem.actorSelection(s"akka.tcp://other-system@localhost:${otherAddress.getPort}/user/echo")
|
||||||
otherSelection.tell("ping", probeSender)
|
otherSelection.tell("ping", probeSender)
|
||||||
probe.expectNoMsg(1 seconds)
|
probe.expectNoMsg(1.seconds)
|
||||||
val otherSystem = ActorSystem("other-system", otherConfig)
|
val otherSystem = ActorSystem("other-system", otherConfig)
|
||||||
try {
|
try {
|
||||||
muteSystem(otherSystem)
|
muteSystem(otherSystem)
|
||||||
probe.expectNoMsg(2 seconds)
|
probe.expectNoMsg(2.seconds)
|
||||||
otherSystem.actorOf(Props[Echo2], "echo")
|
otherSystem.actorOf(Props[Echo2], "echo")
|
||||||
within(5 seconds) {
|
within(5.seconds) {
|
||||||
awaitAssert {
|
awaitAssert {
|
||||||
otherSelection.tell("ping", probeSender)
|
otherSelection.tell("ping", probeSender)
|
||||||
assert(probe.expectMsgType[(String, ActorRef)](500 millis)._1 == "pong")
|
assert(probe.expectMsgType[(String, ActorRef)](500.millis)._1 == "pong")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -624,18 +624,18 @@ class RemotingSpec extends AkkaSpec(RemotingSpec.cfg) with ImplicitSender with D
|
||||||
""").withFallback(config)
|
""").withFallback(config)
|
||||||
val otherSelection = thisSystem.actorSelection(s"akka.tcp://other-system@localhost:${otherAddress.getPort}/user/echo")
|
val otherSelection = thisSystem.actorSelection(s"akka.tcp://other-system@localhost:${otherAddress.getPort}/user/echo")
|
||||||
otherSelection.tell("ping", thisSender)
|
otherSelection.tell("ping", thisSender)
|
||||||
thisProbe.expectNoMsg(1 seconds)
|
thisProbe.expectNoMsg(1.seconds)
|
||||||
val otherSystem = ActorSystem("other-system", otherConfig)
|
val otherSystem = ActorSystem("other-system", otherConfig)
|
||||||
try {
|
try {
|
||||||
muteSystem(otherSystem)
|
muteSystem(otherSystem)
|
||||||
thisProbe.expectNoMsg(2 seconds)
|
thisProbe.expectNoMsg(2.seconds)
|
||||||
val otherProbe = new TestProbe(otherSystem)
|
val otherProbe = new TestProbe(otherSystem)
|
||||||
val otherSender = otherProbe.ref
|
val otherSender = otherProbe.ref
|
||||||
val thisSelection = otherSystem.actorSelection(s"akka.tcp://this-system@localhost:${port(thisSystem, "tcp")}/user/echo")
|
val thisSelection = otherSystem.actorSelection(s"akka.tcp://this-system@localhost:${port(thisSystem, "tcp")}/user/echo")
|
||||||
within(5 seconds) {
|
within(5.seconds) {
|
||||||
awaitAssert {
|
awaitAssert {
|
||||||
thisSelection.tell("ping", otherSender)
|
thisSelection.tell("ping", otherSender)
|
||||||
assert(otherProbe.expectMsgType[(String, ActorRef)](500 millis)._1 == "pong")
|
assert(otherProbe.expectMsgType[(String, ActorRef)](500.millis)._1 == "pong")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ object SystemMessageDeliveryStressTest {
|
||||||
}
|
}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
class SystemMessageSequenceVerifier(system: ActorSystem, testActor: ActorRef) extends MinimalActorRef {
|
private[akka] class SystemMessageSequenceVerifier(system: ActorSystem, testActor: ActorRef) extends MinimalActorRef {
|
||||||
val provider = RARP(system).provider
|
val provider = RARP(system).provider
|
||||||
val path = provider.tempPath()
|
val path = provider.tempPath()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ object Slf4jLoggerSpec {
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
case class StringWithMDC(s: String, mdc: Map[String, Any])
|
||||||
|
|
||||||
class LogProducer extends Actor with DiagnosticActorLogging {
|
class LogProducer extends Actor with DiagnosticActorLogging {
|
||||||
|
|
||||||
def receive = {
|
def receive = {
|
||||||
|
|
@ -33,7 +35,7 @@ object Slf4jLoggerSpec {
|
||||||
log.error(e, e.getMessage)
|
log.error(e, e.getMessage)
|
||||||
case (s: String, x: Int, y: Int) ⇒
|
case (s: String, x: Int, y: Int) ⇒
|
||||||
log.info(s, x, y)
|
log.info(s, x, y)
|
||||||
case (s: String, mdc: Map[String, Any]) ⇒
|
case StringWithMDC(s, mdc) ⇒
|
||||||
log.mdc(mdc)
|
log.mdc(mdc)
|
||||||
log.info(s)
|
log.info(s)
|
||||||
log.clearMDC()
|
log.clearMDC()
|
||||||
|
|
@ -96,7 +98,7 @@ class Slf4jLoggerSpec extends AkkaSpec(Slf4jLoggerSpec.config) with BeforeAndAft
|
||||||
}
|
}
|
||||||
|
|
||||||
"put custom MDC values when specified" in {
|
"put custom MDC values when specified" in {
|
||||||
producer ! ("Message with custom MDC values", Map("ticketNumber" -> 3671, "ticketDesc" -> "Custom MDC Values"))
|
producer ! StringWithMDC("Message with custom MDC values", Map("ticketNumber" -> 3671, "ticketDesc" -> "Custom MDC Values"))
|
||||||
|
|
||||||
awaitCond(outputString.contains("----"), 5 seconds)
|
awaitCond(outputString.contains("----"), 5 seconds)
|
||||||
val s = outputString
|
val s = outputString
|
||||||
|
|
@ -109,7 +111,7 @@ class Slf4jLoggerSpec extends AkkaSpec(Slf4jLoggerSpec.config) with BeforeAndAft
|
||||||
}
|
}
|
||||||
|
|
||||||
"Support null values in custom MDC" in {
|
"Support null values in custom MDC" in {
|
||||||
producer ! ("Message with null custom MDC values", Map("ticketNumber" -> 3671, "ticketDesc" -> null))
|
producer ! StringWithMDC("Message with null custom MDC values", Map("ticketNumber" -> 3671, "ticketDesc" -> null))
|
||||||
|
|
||||||
awaitCond(outputString.contains("----"), 5 seconds)
|
awaitCond(outputString.contains("----"), 5 seconds)
|
||||||
val s = outputString
|
val s = outputString
|
||||||
|
|
|
||||||
|
|
@ -39,12 +39,11 @@ class AkkaSpecSpec extends WordSpec with Matchers {
|
||||||
"akka.actor.debug.lifecycle" -> true, "akka.actor.debug.event-stream" -> true,
|
"akka.actor.debug.lifecycle" -> true, "akka.actor.debug.event-stream" -> true,
|
||||||
"akka.loglevel" -> "DEBUG", "akka.stdout-loglevel" -> "DEBUG")
|
"akka.loglevel" -> "DEBUG", "akka.stdout-loglevel" -> "DEBUG")
|
||||||
val system = ActorSystem("AkkaSpec1", ConfigFactory.parseMap(conf.asJava).withFallback(AkkaSpec.testConf))
|
val system = ActorSystem("AkkaSpec1", ConfigFactory.parseMap(conf.asJava).withFallback(AkkaSpec.testConf))
|
||||||
val spec = new AkkaSpec(system) {
|
var refs = Seq.empty[ActorRef]
|
||||||
val ref = Seq(testActor, system.actorOf(Props.empty, "name"))
|
val spec = new AkkaSpec(system) { refs = Seq(testActor, system.actorOf(Props.empty, "name")) }
|
||||||
}
|
refs foreach (_.isTerminated should not be true)
|
||||||
spec.ref foreach (_.isTerminated should not be true)
|
|
||||||
TestKit.shutdownActorSystem(system)
|
TestKit.shutdownActorSystem(system)
|
||||||
spec.awaitCond(spec.ref forall (_.isTerminated), 2 seconds)
|
spec.awaitCond(refs forall (_.isTerminated), 2 seconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
"stop correctly when sending PoisonPill to rootGuardian" in {
|
"stop correctly when sending PoisonPill to rootGuardian" in {
|
||||||
|
|
|
||||||
|
|
@ -227,12 +227,13 @@ class TestActorRefSpec extends AkkaSpec("disp1.type=Dispatcher") with BeforeAndA
|
||||||
"A TestActorRef" must {
|
"A TestActorRef" must {
|
||||||
|
|
||||||
"allow access to internals" in {
|
"allow access to internals" in {
|
||||||
val ref = TestActorRef(new TActor {
|
class TA extends TActor {
|
||||||
var s: String = _
|
var s: String = _
|
||||||
def receiveT = {
|
def receiveT = {
|
||||||
case x: String ⇒ s = x
|
case x: String ⇒ s = x
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
val ref = TestActorRef(new TA)
|
||||||
ref ! "hallo"
|
ref ! "hallo"
|
||||||
val actor = ref.underlyingActor
|
val actor = ref.underlyingActor
|
||||||
actor.s should be("hallo")
|
actor.s should be("hallo")
|
||||||
|
|
|
||||||
|
|
@ -287,11 +287,17 @@ object AkkaBuild extends Build {
|
||||||
pomIncludeRepository := (_ => false) // do not leak internal repositories during staging
|
pomIncludeRepository := (_ => false) // do not leak internal repositories during staging
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private def allWarnings: Boolean = System.getProperty("akka.allwarnings", "false").toBoolean
|
||||||
|
|
||||||
lazy val defaultSettings = baseSettings ++ resolverSettings ++ TestExtras.Filter.settings ++
|
lazy val defaultSettings = baseSettings ++ resolverSettings ++ TestExtras.Filter.settings ++
|
||||||
Protobuf.settings ++ Seq(
|
Protobuf.settings ++ Seq(
|
||||||
// compile options
|
// compile options
|
||||||
scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", "-deprecation", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"),
|
scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"),
|
||||||
javacOptions in compile ++= Seq("-encoding", "UTF-8", "-source", "1.6", "-target", "1.6", "-Xlint:unchecked", "-Xlint:deprecation"),
|
scalacOptions in Compile ++= (if (allWarnings) Seq("-deprecation") else Nil),
|
||||||
|
scalacOptions in Test := (scalacOptions in Test).value.filterNot(_ == "-Xlog-reflective-calls"),
|
||||||
|
// -XDignore.symbol.file suppresses sun.misc.Unsafe warnings
|
||||||
|
javacOptions in compile ++= Seq("-encoding", "UTF-8", "-source", "1.6", "-target", "1.6", "-Xlint:unchecked", "-XDignore.symbol.file"),
|
||||||
|
javacOptions in compile ++= (if (allWarnings) Seq("-Xlint:deprecation") else Nil),
|
||||||
javacOptions in doc ++= Seq("-encoding", "UTF-8", "-source", "1.6"),
|
javacOptions in doc ++= Seq("-encoding", "UTF-8", "-source", "1.6"),
|
||||||
incOptions := incOptions.value.withNameHashing(true),
|
incOptions := incOptions.value.withNameHashing(true),
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue