replace unicode arrows
* ⇒, →, ← * because we don't want to show them in documentation snippets and then it's complicated to avoid that when snippets are located in src/test/scala in individual modules * dont replace object `→` in FSM.scala and PersistentFSM.scala
This commit is contained in:
parent
e4d38f92a4
commit
5c96a5f556
1521 changed files with 18846 additions and 18786 deletions
|
|
@ -72,8 +72,8 @@ object CapturedLogEvent {
|
|||
* Helper method to convert [[OptionVal]] to [[Option]]
|
||||
*/
|
||||
private def toOption[A](optionVal: OptionVal[A]): Option[A] = optionVal match {
|
||||
case OptionVal.Some(x) ⇒ Some(x)
|
||||
case _ ⇒ None
|
||||
case OptionVal.Some(x) => Some(x)
|
||||
case _ => None
|
||||
}
|
||||
|
||||
def apply(
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ object Effect {
|
|||
extends Effect with Product3[Behavior[T], String, Props] with Serializable {
|
||||
|
||||
override def equals(other: Any) = other match {
|
||||
case o: Spawned[_] ⇒
|
||||
case o: Spawned[_] =>
|
||||
this.behavior == o.behavior &&
|
||||
this.childName == o.childName &&
|
||||
this.props == o.props
|
||||
case _ ⇒ false
|
||||
case _ => false
|
||||
}
|
||||
override def hashCode: Int = (behavior.## * 31 + childName.##) * 31 + props.##
|
||||
override def toString: String = s"Spawned($behavior, $childName, $props)"
|
||||
|
|
@ -60,8 +60,8 @@ object Effect {
|
|||
extends Effect with Product2[Behavior[T], Props] with Serializable {
|
||||
|
||||
override def equals(other: Any) = other match {
|
||||
case o: SpawnedAnonymous[_] ⇒ this.behavior == o.behavior && this.props == o.props
|
||||
case _ ⇒ false
|
||||
case o: SpawnedAnonymous[_] => this.behavior == o.behavior && this.props == o.props
|
||||
case _ => false
|
||||
}
|
||||
override def hashCode: Int = behavior.## * 31 + props.##
|
||||
override def toString: String = s"SpawnedAnonymous($behavior, $props)"
|
||||
|
|
@ -86,8 +86,8 @@ object Effect {
|
|||
extends Effect with Product1[String] with Serializable {
|
||||
|
||||
override def equals(other: Any) = other match {
|
||||
case o: SpawnedAdapter[_] ⇒ this.name == o.name
|
||||
case _ ⇒ false
|
||||
case o: SpawnedAdapter[_] => this.name == o.name
|
||||
case _ => false
|
||||
}
|
||||
override def hashCode: Int = name.##
|
||||
override def toString: String = s"SpawnedAdapter($name)"
|
||||
|
|
@ -116,8 +116,8 @@ object Effect {
|
|||
extends Effect with Product with Serializable {
|
||||
|
||||
override def equals(other: Any): Boolean = other match {
|
||||
case _: SpawnedAnonymousAdapter[_] ⇒ true
|
||||
case _ ⇒ false
|
||||
case _: SpawnedAnonymousAdapter[_] => true
|
||||
case _ => false
|
||||
}
|
||||
override def hashCode: Int = Nil.##
|
||||
override def toString: String = "SpawnedAnonymousAdapter"
|
||||
|
|
@ -141,7 +141,7 @@ object Effect {
|
|||
/**
|
||||
* The behavior create a message adapter for the messages of type clazz
|
||||
*/
|
||||
final case class MessageAdapter[A, T](messageClass: Class[A], adapt: A ⇒ T) extends Effect {
|
||||
final case class MessageAdapter[A, T](messageClass: Class[A], adapt: A => T) extends Effect {
|
||||
/**
|
||||
* JAVA API
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ final class TestKitSettings(val config: Config) {
|
|||
import akka.util.Helpers._
|
||||
|
||||
val TestTimeFactor = config.getDouble("timefactor").
|
||||
requiring(tf ⇒ !tf.isInfinite && tf > 0, "timefactor must be positive finite double")
|
||||
requiring(tf => !tf.isInfinite && tf > 0, "timefactor must be positive finite double")
|
||||
|
||||
/** dilated with `TestTimeFactor` */
|
||||
val SingleExpectDefaultTimeout: FiniteDuration = dilated(config.getMillisDuration("single-expect-default"))
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import akka.actor.typed.internal.ActorRefImpl
|
|||
import akka.actor.typed.{ ActorRef, ActorSystem, Behavior, DispatcherSelector, Dispatchers, Extension, ExtensionId, Logger, Props, Settings, Terminated }
|
||||
import akka.annotation.InternalApi
|
||||
import akka.util.Timeout
|
||||
import akka.{ actor ⇒ untyped }
|
||||
import akka.{ actor => untyped }
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import scala.compat.java8.FutureConverters
|
||||
import scala.concurrent._
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ private[akka] final class BehaviorTestKitImpl[T](_path: ActorPath, _initialBehav
|
|||
runAllTasks()
|
||||
|
||||
override def retrieveEffect(): Effect = context.effectQueue.poll() match {
|
||||
case null ⇒ NoEffects
|
||||
case x ⇒ x
|
||||
case null => NoEffects
|
||||
case x => x
|
||||
}
|
||||
|
||||
override def childInbox[U](name: String): TestInboxImpl[U] = {
|
||||
|
|
@ -58,8 +58,8 @@ private[akka] final class BehaviorTestKitImpl[T](_path: ActorPath, _initialBehav
|
|||
|
||||
override def retrieveAllEffects(): immutable.Seq[Effect] = {
|
||||
@tailrec def rec(acc: List[Effect]): List[Effect] = context.effectQueue.poll() match {
|
||||
case null ⇒ acc.reverse
|
||||
case x ⇒ rec(x :: acc)
|
||||
case null => acc.reverse
|
||||
case x => rec(x :: acc)
|
||||
}
|
||||
|
||||
rec(Nil)
|
||||
|
|
@ -71,27 +71,27 @@ private[akka] final class BehaviorTestKitImpl[T](_path: ActorPath, _initialBehav
|
|||
|
||||
override def expectEffect(expectedEffect: Effect): Unit = {
|
||||
context.effectQueue.poll() match {
|
||||
case null ⇒ assert(expectedEffect == NoEffects, s"expected: $expectedEffect but no effects were recorded")
|
||||
case effect ⇒ assert(expectedEffect == effect, s"expected: $expectedEffect but found $effect")
|
||||
case null => assert(expectedEffect == NoEffects, s"expected: $expectedEffect but no effects were recorded")
|
||||
case effect => assert(expectedEffect == effect, s"expected: $expectedEffect but found $effect")
|
||||
}
|
||||
}
|
||||
|
||||
def expectEffectClass[E <: Effect](effectClass: Class[E]): E = {
|
||||
context.effectQueue.poll() match {
|
||||
case null if effectClass.isAssignableFrom(NoEffects.getClass) ⇒ effectClass.cast(NoEffects)
|
||||
case null ⇒ throw new AssertionError(s"expected: effect type ${effectClass.getName} but no effects were recorded")
|
||||
case effect if effectClass.isAssignableFrom(effect.getClass) ⇒ effect.asInstanceOf[E]
|
||||
case other ⇒ throw new AssertionError(s"expected: effect class ${effectClass.getName} but found $other")
|
||||
case null if effectClass.isAssignableFrom(NoEffects.getClass) => effectClass.cast(NoEffects)
|
||||
case null => throw new AssertionError(s"expected: effect type ${effectClass.getName} but no effects were recorded")
|
||||
case effect if effectClass.isAssignableFrom(effect.getClass) => effect.asInstanceOf[E]
|
||||
case other => throw new AssertionError(s"expected: effect class ${effectClass.getName} but found $other")
|
||||
}
|
||||
}
|
||||
|
||||
def expectEffectPF[R](f: PartialFunction[Effect, R]): R = {
|
||||
context.effectQueue.poll() match {
|
||||
case null if f.isDefinedAt(NoEffects) ⇒
|
||||
case null if f.isDefinedAt(NoEffects) =>
|
||||
f.apply(NoEffects)
|
||||
case eff if f.isDefinedAt(eff) ⇒
|
||||
case eff if f.isDefinedAt(eff) =>
|
||||
f.apply(eff)
|
||||
case other ⇒
|
||||
case other =>
|
||||
throw new AssertionError(s"expected matching effect but got: $other")
|
||||
}
|
||||
}
|
||||
|
|
@ -104,18 +104,18 @@ private[akka] final class BehaviorTestKitImpl[T](_path: ActorPath, _initialBehav
|
|||
def isAlive: Boolean = Behavior.isAlive(current)
|
||||
|
||||
private def handleException: Catcher[Unit] = {
|
||||
case NonFatal(e) ⇒
|
||||
case NonFatal(e) =>
|
||||
try Behavior.canonicalize(Behavior.interpretSignal(current, context, PostStop), current, context) // TODO why canonicalize here?
|
||||
catch {
|
||||
case NonFatal(_) ⇒ /* ignore, real is logging */
|
||||
case NonFatal(_) => /* ignore, real is logging */
|
||||
}
|
||||
throw e
|
||||
}
|
||||
|
||||
private def runAllTasks(): Unit = {
|
||||
context.executionContext match {
|
||||
case controlled: ControlledExecutor ⇒ controlled.runAll()
|
||||
case _ ⇒
|
||||
case controlled: ControlledExecutor => controlled.runAll()
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import java.util.concurrent.ConcurrentLinkedQueue
|
|||
import akka.actor.typed.ActorRef
|
||||
import akka.actor.typed.internal.{ ActorRefImpl, SystemMessage }
|
||||
import akka.annotation.InternalApi
|
||||
import akka.{ actor ⇒ untyped }
|
||||
import akka.{ actor => untyped }
|
||||
import scala.annotation.tailrec
|
||||
|
||||
import akka.actor.ActorRefProvider
|
||||
|
|
@ -27,36 +27,36 @@ import akka.actor.typed.internal.InternalRecipientRef
|
|||
override def sendSystem(signal: SystemMessage): Unit = q.add(Left(signal))
|
||||
|
||||
def hasMessage: Boolean = q.peek match {
|
||||
case null ⇒ false
|
||||
case Left(_) ⇒ false
|
||||
case Right(_) ⇒ true
|
||||
case null => false
|
||||
case Left(_) => false
|
||||
case Right(_) => true
|
||||
}
|
||||
|
||||
def hasSignal: Boolean = q.peek match {
|
||||
case null ⇒ false
|
||||
case Left(_) ⇒ true
|
||||
case Right(_) ⇒ false
|
||||
case null => false
|
||||
case Left(_) => true
|
||||
case Right(_) => false
|
||||
}
|
||||
|
||||
def hasSomething: Boolean = q.peek != null
|
||||
|
||||
def receiveMessage(): T = q.poll match {
|
||||
case null ⇒ throw new NoSuchElementException("empty DebugRef")
|
||||
case Left(signal) ⇒ throw new IllegalStateException(s"expected message but found signal $signal")
|
||||
case Right(message) ⇒ message
|
||||
case null => throw new NoSuchElementException("empty DebugRef")
|
||||
case Left(signal) => throw new IllegalStateException(s"expected message but found signal $signal")
|
||||
case Right(message) => message
|
||||
}
|
||||
|
||||
def receiveSignal(): SystemMessage = q.poll match {
|
||||
case null ⇒ throw new NoSuchElementException("empty DebugRef")
|
||||
case Left(signal) ⇒ signal
|
||||
case Right(message) ⇒ throw new IllegalStateException(s"expected signal but found message $message")
|
||||
case null => throw new NoSuchElementException("empty DebugRef")
|
||||
case Left(signal) => signal
|
||||
case Right(message) => throw new IllegalStateException(s"expected signal but found message $message")
|
||||
}
|
||||
|
||||
def receiveAll(): List[Either[SystemMessage, T]] = {
|
||||
@tailrec def rec(acc: List[Either[SystemMessage, T]]): List[Either[SystemMessage, T]] =
|
||||
q.poll match {
|
||||
case null ⇒ acc.reverse
|
||||
case other ⇒ rec(other :: acc)
|
||||
case null => acc.reverse
|
||||
case other => rec(other :: acc)
|
||||
}
|
||||
rec(Nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,17 +29,17 @@ import scala.compat.java8.FunctionConverters._
|
|||
effectQueue.offer(new SpawnedAnonymous(behavior, props, ref))
|
||||
ref
|
||||
}
|
||||
override def spawnMessageAdapter[U](f: U ⇒ T): ActorRef[U] = {
|
||||
override def spawnMessageAdapter[U](f: U => T): ActorRef[U] = {
|
||||
val ref = super.spawnMessageAdapter(f)
|
||||
effectQueue.offer(new SpawnedAnonymousAdapter(ref))
|
||||
ref
|
||||
}
|
||||
override def spawnMessageAdapter[U](f: U ⇒ T, name: String): ActorRef[U] = {
|
||||
override def spawnMessageAdapter[U](f: U => T, name: String): ActorRef[U] = {
|
||||
val ref = super.spawnMessageAdapter(f, name)
|
||||
effectQueue.offer(new SpawnedAdapter(name, ref))
|
||||
ref
|
||||
}
|
||||
override def messageAdapter[U: ClassTag](f: U ⇒ T): ActorRef[U] = {
|
||||
override def messageAdapter[U: ClassTag](f: U => T): ActorRef[U] = {
|
||||
val ref = super.messageAdapter(f)
|
||||
effectQueue.offer(MessageAdapter(implicitly[ClassTag[U]].runtimeClass.asInstanceOf[Class[U]], f))
|
||||
ref
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ import akka.actor.{ ActorPath, InvalidMessageException }
|
|||
import akka.annotation.InternalApi
|
||||
import akka.event.Logging
|
||||
import akka.util.{ Helpers, OptionVal }
|
||||
import akka.{ actor ⇒ untyped }
|
||||
import java.util.concurrent.ThreadLocalRandom.{ current ⇒ rnd }
|
||||
import akka.{ actor => untyped }
|
||||
import java.util.concurrent.ThreadLocalRandom.{ current => rnd }
|
||||
|
||||
import scala.collection.immutable.TreeMap
|
||||
import scala.concurrent.ExecutionContextExecutor
|
||||
|
|
@ -31,7 +31,7 @@ import akka.actor.ActorRefProvider
|
|||
@InternalApi
|
||||
private[akka] final class FunctionRef[-T](
|
||||
override val path: ActorPath,
|
||||
send: (T, FunctionRef[T]) ⇒ Unit)
|
||||
send: (T, FunctionRef[T]) => Unit)
|
||||
extends ActorRef[T] with ActorRefImpl[T] with InternalRecipientRef[T] {
|
||||
|
||||
override def tell(message: T): Unit = {
|
||||
|
|
@ -172,15 +172,15 @@ private[akka] final class FunctionRef[-T](
|
|||
|
||||
override def spawnAnonymous[U](behavior: Behavior[U], props: Props = Props.empty): ActorRef[U] = {
|
||||
val btk = new BehaviorTestKitImpl[U](path / childName.next() withUid rnd().nextInt(), behavior)
|
||||
_children += btk.context.self.path.name → btk
|
||||
_children += btk.context.self.path.name -> btk
|
||||
btk.context.self
|
||||
}
|
||||
override def spawn[U](behavior: Behavior[U], name: String, props: Props = Props.empty): ActorRef[U] =
|
||||
_children get name match {
|
||||
case Some(_) ⇒ throw untyped.InvalidActorNameException(s"actor name $name is already taken")
|
||||
case None ⇒
|
||||
case Some(_) => throw untyped.InvalidActorNameException(s"actor name $name is already taken")
|
||||
case None =>
|
||||
val btk = new BehaviorTestKitImpl[U](path / name withUid rnd().nextInt(), behavior)
|
||||
_children += name → btk
|
||||
_children += name -> btk
|
||||
btk.context.self
|
||||
}
|
||||
|
||||
|
|
@ -214,16 +214,16 @@ private[akka] final class FunctionRef[-T](
|
|||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
@InternalApi private[akka] def internalSpawnMessageAdapter[U](f: U ⇒ T, name: String): ActorRef[U] = {
|
||||
@InternalApi private[akka] def internalSpawnMessageAdapter[U](f: U => T, name: String): ActorRef[U] = {
|
||||
|
||||
val n = if (name != "") s"${childName.next()}-$name" else childName.next()
|
||||
val p = path / n withUid rnd().nextInt()
|
||||
val i = new BehaviorTestKitImpl[U](p, Behavior.ignore)
|
||||
_children += p.name → i
|
||||
_children += p.name -> i
|
||||
|
||||
new FunctionRef[U](
|
||||
p,
|
||||
(message, _) ⇒ { val m = f(message); if (m != null) { selfInbox.ref ! m; i.selfInbox.ref ! message } })
|
||||
(message, _) => { val m = f(message); if (m != null) { selfInbox.ref ! m; i.selfInbox.ref ! message } })
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -23,26 +23,26 @@ private[akka] final class TestInboxImpl[T](path: ActorPath)
|
|||
|
||||
private val q = new ConcurrentLinkedQueue[T]
|
||||
|
||||
override val ref: ActorRef[T] = new FunctionRef[T](path, (message, self) ⇒ q.add(message))
|
||||
override val ref: ActorRef[T] = new FunctionRef[T](path, (message, self) => q.add(message))
|
||||
override def getRef() = ref
|
||||
|
||||
override def receiveMessage(): T = q.poll() match {
|
||||
case null ⇒ throw new NoSuchElementException(s"polling on an empty inbox: $path")
|
||||
case x ⇒ x
|
||||
case null => throw new NoSuchElementException(s"polling on an empty inbox: $path")
|
||||
case x => x
|
||||
}
|
||||
|
||||
override def expectMessage(expectedMessage: T): TestInboxImpl[T] = {
|
||||
q.poll() match {
|
||||
case null ⇒ assert(assertion = false, s"expected message: $expectedMessage but no messages were received")
|
||||
case message ⇒ assert(message == expectedMessage, s"expected: $expectedMessage but received $message")
|
||||
case null => assert(assertion = false, s"expected message: $expectedMessage but no messages were received")
|
||||
case message => assert(message == expectedMessage, s"expected: $expectedMessage but received $message")
|
||||
}
|
||||
this
|
||||
}
|
||||
|
||||
override protected def internalReceiveAll(): immutable.Seq[T] = {
|
||||
@tailrec def rec(acc: List[T]): List[T] = q.poll() match {
|
||||
case null ⇒ acc.reverse
|
||||
case x ⇒ rec(x :: acc)
|
||||
case null => acc.reverse
|
||||
case x => rec(x :: acc)
|
||||
}
|
||||
|
||||
rec(Nil)
|
||||
|
|
|
|||
|
|
@ -26,17 +26,17 @@ private[akka] object ActorTestKitGuardian {
|
|||
final case object Ack
|
||||
|
||||
val testKitGuardian: Behavior[TestKitCommand] = Behaviors.receive[TestKitCommand] {
|
||||
case (context, SpawnActor(name, behavior, reply, props)) ⇒
|
||||
case (context, SpawnActor(name, behavior, reply, props)) =>
|
||||
reply ! context.spawn(behavior, name, props)
|
||||
Behaviors.same
|
||||
case (context, SpawnActorAnonymous(behavior, reply, props)) ⇒
|
||||
case (context, SpawnActorAnonymous(behavior, reply, props)) =>
|
||||
reply ! context.spawnAnonymous(behavior, props)
|
||||
Behaviors.same
|
||||
case (context, StopActor(ref, reply)) ⇒
|
||||
case (context, StopActor(ref, reply)) =>
|
||||
context.watchWith(ref, ActorStopped(reply))
|
||||
context.stop(ref)
|
||||
Behaviors.same
|
||||
case (_, ActorStopped(reply)) ⇒
|
||||
case (_, ActorStopped(reply)) =>
|
||||
reply ! Ack
|
||||
Behaviors.same
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ private[akka] object TestKitUtils {
|
|||
try {
|
||||
Modifier.isAbstract(Class.forName(className).getModifiers)
|
||||
} catch {
|
||||
case _: Throwable ⇒ false // yes catch everything, best effort check
|
||||
case _: Throwable => false // yes catch everything, best effort check
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,11 +68,11 @@ private[akka] object TestKitUtils {
|
|||
.dropWhile(!_.startsWith(startFrom))
|
||||
// then continue to the next entry after classToStartFrom that makes sense
|
||||
.dropWhile {
|
||||
case `startFrom` ⇒ true
|
||||
case str if str.startsWith(startFrom + "$") ⇒ true // lambdas inside startFrom etc
|
||||
case TestKitRegex() ⇒ true // testkit internals
|
||||
case str if isAbstractClass(str) ⇒ true
|
||||
case _ ⇒ false
|
||||
case `startFrom` => true
|
||||
case str if str.startsWith(startFrom + "$") => true // lambdas inside startFrom etc
|
||||
case TestKitRegex() => true // testkit internals
|
||||
case str if isAbstractClass(str) => true
|
||||
case _ => false
|
||||
}
|
||||
|
||||
if (filteredStack.isEmpty)
|
||||
|
|
@ -100,7 +100,7 @@ private[akka] object TestKitUtils {
|
|||
throwIfShutdownTimesOut: Boolean): Unit = {
|
||||
system.terminate()
|
||||
try Await.ready(system.whenTerminated, timeout) catch {
|
||||
case _: TimeoutException ⇒
|
||||
case _: TimeoutException =>
|
||||
val message = "Failed to stop [%s] within [%s] \n%s".format(system.name, timeout, system.printTree)
|
||||
if (throwIfShutdownTimesOut) throw new RuntimeException(message)
|
||||
else println(message)
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
package akka.actor.testkit.typed.internal
|
||||
|
||||
import java.time.{ Duration ⇒ JDuration }
|
||||
import java.time.{ Duration => JDuration }
|
||||
import java.util.concurrent.BlockingDeque
|
||||
import java.util.concurrent.LinkedBlockingDeque
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.function.Supplier
|
||||
import java.util.{ List ⇒ JList }
|
||||
import java.util.{ List => JList }
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.JavaConverters._
|
||||
|
|
@ -21,9 +21,9 @@ import scala.util.control.NonFatal
|
|||
|
||||
import akka.actor.testkit.typed.FishingOutcome
|
||||
import akka.actor.testkit.typed.TestKitSettings
|
||||
import akka.actor.testkit.typed.javadsl.{ TestProbe ⇒ JavaTestProbe }
|
||||
import akka.actor.testkit.typed.javadsl.{ TestProbe => JavaTestProbe }
|
||||
import akka.actor.testkit.typed.scaladsl.TestDuration
|
||||
import akka.actor.testkit.typed.scaladsl.{ TestProbe ⇒ ScalaTestProbe }
|
||||
import akka.actor.testkit.typed.scaladsl.{ TestProbe => ScalaTestProbe }
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.Behavior
|
||||
|
|
@ -43,19 +43,19 @@ private[akka] object TestProbeImpl {
|
|||
private case object Stop
|
||||
|
||||
private def testActor[M](queue: BlockingDeque[M], terminations: BlockingDeque[Terminated]): Behavior[M] =
|
||||
Behaviors.receive[M] { (context, msg) ⇒
|
||||
Behaviors.receive[M] { (context, msg) =>
|
||||
msg match {
|
||||
case WatchActor(ref) ⇒
|
||||
case WatchActor(ref) =>
|
||||
context.watch(ref)
|
||||
Behaviors.same
|
||||
case Stop ⇒
|
||||
case Stop =>
|
||||
Behaviors.stopped
|
||||
case other ⇒
|
||||
case other =>
|
||||
queue.offerLast(other)
|
||||
Behaviors.same
|
||||
}
|
||||
}.receiveSignal {
|
||||
case (_, t: Terminated) ⇒
|
||||
case (_, t: Terminated) =>
|
||||
terminations.offerLast(t)
|
||||
Behaviors.same
|
||||
}
|
||||
|
|
@ -91,25 +91,25 @@ private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
|||
override def getRemainingOrDefault: JDuration = remainingOrDefault.asJava
|
||||
|
||||
override def remaining: FiniteDuration = end match {
|
||||
case f: FiniteDuration ⇒ f - now
|
||||
case _ ⇒ assertFail("`remaining` may not be called outside of `within`")
|
||||
case f: FiniteDuration => f - now
|
||||
case _ => assertFail("`remaining` may not be called outside of `within`")
|
||||
}
|
||||
|
||||
override def getRemaining: JDuration = remaining.asJava
|
||||
|
||||
override def remainingOr(duration: FiniteDuration): FiniteDuration = end match {
|
||||
case x if x eq Duration.Undefined ⇒ duration
|
||||
case x if !x.isFinite ⇒ throw new IllegalArgumentException("`end` cannot be infinite")
|
||||
case f: FiniteDuration ⇒ f - now
|
||||
case x if x eq Duration.Undefined => duration
|
||||
case x if !x.isFinite => throw new IllegalArgumentException("`end` cannot be infinite")
|
||||
case f: FiniteDuration => f - now
|
||||
}
|
||||
|
||||
override def getRemainingOr(duration: JDuration): JDuration =
|
||||
remainingOr(duration.asScala).asJava
|
||||
|
||||
override def within[T](min: FiniteDuration, max: FiniteDuration)(f: ⇒ T): T =
|
||||
override def within[T](min: FiniteDuration, max: FiniteDuration)(f: => T): T =
|
||||
within_internal(min, max.dilated, f)
|
||||
|
||||
override def within[T](max: FiniteDuration)(f: ⇒ T): T =
|
||||
override def within[T](max: FiniteDuration)(f: => T): T =
|
||||
within_internal(Duration.Zero, max.dilated, f)
|
||||
|
||||
override def within[T](min: JDuration, max: JDuration)(f: Supplier[T]): T =
|
||||
|
|
@ -118,7 +118,7 @@ private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
|||
def within[T](max: JDuration)(f: Supplier[T]): T =
|
||||
within_internal(Duration.Zero, max.asScala.dilated, f.get())
|
||||
|
||||
private def within_internal[T](min: FiniteDuration, max: FiniteDuration, f: ⇒ T): T = {
|
||||
private def within_internal[T](min: FiniteDuration, max: FiniteDuration, f: => T): T = {
|
||||
val start = now
|
||||
val rem = if (end == Duration.Undefined) Duration.Inf else end - start
|
||||
assert(rem >= min, s"required min time $min not possible, only ${rem.pretty} left")
|
||||
|
|
@ -157,9 +157,9 @@ private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
|||
val o = receiveOne_internal(max)
|
||||
val hintOrEmptyString = hint.map(": " + _).getOrElse("")
|
||||
o match {
|
||||
case Some(m) if obj == m ⇒ m.asInstanceOf[T]
|
||||
case Some(m) ⇒ assertFail(s"expected $obj, found $m$hintOrEmptyString")
|
||||
case None ⇒ assertFail(s"timeout ($max) during expectMessage while waiting for $obj$hintOrEmptyString")
|
||||
case Some(m) if obj == m => m.asInstanceOf[T]
|
||||
case Some(m) => assertFail(s"expected $obj, found $m$hintOrEmptyString")
|
||||
case None => assertFail(s"timeout ($max) during expectMessage while waiting for $obj$hintOrEmptyString")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -203,8 +203,8 @@ private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
|||
private def expectNoMessage_internal(max: FiniteDuration): Unit = {
|
||||
val o = receiveOne_internal(max)
|
||||
o match {
|
||||
case None ⇒ lastWasNoMessage = true
|
||||
case Some(m) ⇒ assertFail(s"Received unexpected message $m")
|
||||
case None => lastWasNoMessage = true
|
||||
case Some(m) => assertFail(s"Received unexpected message $m")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -224,9 +224,9 @@ private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
|||
val o = receiveOne_internal(max)
|
||||
val bt = BoxedType(c)
|
||||
o match {
|
||||
case Some(m) if bt isInstance m ⇒ m.asInstanceOf[C]
|
||||
case Some(m) ⇒ assertFail(s"Expected $c, found ${m.getClass} ($m)")
|
||||
case None ⇒ assertFail(s"Timeout ($max) during expectMessageClass waiting for $c")
|
||||
case Some(m) if bt isInstance m => m.asInstanceOf[C]
|
||||
case Some(m) => assertFail(s"Expected $c, found ${m.getClass} ($m)")
|
||||
case None => assertFail(s"Timeout ($max) during expectMessageClass waiting for $c")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -244,20 +244,20 @@ private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
|||
|
||||
private def receiveMessages_internal(n: Int, max: FiniteDuration): immutable.Seq[M] = {
|
||||
val stop = max + now
|
||||
for (x ← 1 to n) yield {
|
||||
for (x <- 1 to n) yield {
|
||||
val timeout = stop - now
|
||||
val o = receiveOne_internal(timeout)
|
||||
o match {
|
||||
case Some(m) ⇒ m
|
||||
case None ⇒ assertFail(s"timeout ($max) while expecting $n messages (got ${x - 1})")
|
||||
case Some(m) => m
|
||||
case None => assertFail(s"timeout ($max) while expecting $n messages (got ${x - 1})")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def fishForMessage(max: FiniteDuration, hint: String)(fisher: M ⇒ FishingOutcome): immutable.Seq[M] =
|
||||
override def fishForMessage(max: FiniteDuration, hint: String)(fisher: M => FishingOutcome): immutable.Seq[M] =
|
||||
fishForMessage_internal(max.dilated, hint, fisher)
|
||||
|
||||
override def fishForMessage(max: FiniteDuration)(fisher: M ⇒ FishingOutcome): immutable.Seq[M] =
|
||||
override def fishForMessage(max: FiniteDuration)(fisher: M => FishingOutcome): immutable.Seq[M] =
|
||||
fishForMessage(max, "")(fisher)
|
||||
|
||||
override def fishForMessage(max: JDuration, fisher: java.util.function.Function[M, FishingOutcome]): JList[M] =
|
||||
|
|
@ -266,29 +266,29 @@ private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
|||
override def fishForMessage(max: JDuration, hint: String, fisher: java.util.function.Function[M, FishingOutcome]): JList[M] =
|
||||
fishForMessage_internal(max.asScala.dilated, hint, fisher.apply).asJava
|
||||
|
||||
private def fishForMessage_internal(max: FiniteDuration, hint: String, fisher: M ⇒ FishingOutcome): List[M] = {
|
||||
private def fishForMessage_internal(max: FiniteDuration, hint: String, fisher: M => FishingOutcome): List[M] = {
|
||||
@tailrec def loop(timeout: FiniteDuration, seen: List[M]): List[M] = {
|
||||
val start = System.nanoTime()
|
||||
val maybeMsg = receiveOne_internal(timeout)
|
||||
maybeMsg match {
|
||||
case Some(message) ⇒
|
||||
case Some(message) =>
|
||||
val outcome = try fisher(message) catch {
|
||||
case ex: MatchError ⇒ throw new AssertionError(
|
||||
case ex: MatchError => throw new AssertionError(
|
||||
s"Unexpected message $message while fishing for messages, " +
|
||||
s"seen messages ${seen.reverse}, hint: $hint", ex)
|
||||
}
|
||||
outcome match {
|
||||
case FishingOutcome.Complete ⇒ (message :: seen).reverse
|
||||
case FishingOutcome.Fail(error) ⇒ assertFail(s"$error, hint: $hint")
|
||||
case continue: FishingOutcome.ContinueOutcome ⇒
|
||||
case FishingOutcome.Complete => (message :: seen).reverse
|
||||
case FishingOutcome.Fail(error) => assertFail(s"$error, hint: $hint")
|
||||
case continue: FishingOutcome.ContinueOutcome =>
|
||||
val newTimeout = timeout - (System.nanoTime() - start).nanos
|
||||
continue match {
|
||||
case FishingOutcome.Continue ⇒ loop(newTimeout, message :: seen)
|
||||
case FishingOutcome.ContinueAndIgnore ⇒ loop(newTimeout, seen)
|
||||
case FishingOutcome.Continue => loop(newTimeout, message :: seen)
|
||||
case FishingOutcome.ContinueAndIgnore => loop(newTimeout, seen)
|
||||
}
|
||||
}
|
||||
|
||||
case None ⇒
|
||||
case None =>
|
||||
assertFail(s"timeout ($max) during fishForMessage, seen messages ${seen.reverse}, hint: $hint")
|
||||
}
|
||||
}
|
||||
|
|
@ -319,13 +319,13 @@ private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
|||
assert(message.ref == actorRef, s"expected [${actorRef.path}] to stop, but saw [${message.ref.path}] stop")
|
||||
}
|
||||
|
||||
override def awaitAssert[A](a: ⇒ A, max: FiniteDuration, interval: FiniteDuration): A =
|
||||
override def awaitAssert[A](a: => A, max: FiniteDuration, interval: FiniteDuration): A =
|
||||
awaitAssert_internal(a, max.dilated, interval)
|
||||
|
||||
override def awaitAssert[A](a: ⇒ A, max: FiniteDuration): A =
|
||||
override def awaitAssert[A](a: => A, max: FiniteDuration): A =
|
||||
awaitAssert_internal(a, max.dilated, 100.millis)
|
||||
|
||||
override def awaitAssert[A](a: ⇒ A): A =
|
||||
override def awaitAssert[A](a: => A): A =
|
||||
awaitAssert_internal(a, remainingOrDefault, 100.millis)
|
||||
|
||||
override def awaitAssert[A](max: JDuration, interval: JDuration, supplier: Supplier[A]): A =
|
||||
|
|
@ -337,7 +337,7 @@ private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
|||
def awaitAssert[A](supplier: Supplier[A]): A =
|
||||
awaitAssert(getRemainingOrDefault, supplier)
|
||||
|
||||
private def awaitAssert_internal[A](a: ⇒ A, max: FiniteDuration, interval: FiniteDuration): A = {
|
||||
private def awaitAssert_internal[A](a: => A, max: FiniteDuration, interval: FiniteDuration): A = {
|
||||
val stop = now + max
|
||||
|
||||
@tailrec
|
||||
|
|
@ -351,7 +351,7 @@ private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
|||
failed = false
|
||||
aRes
|
||||
} catch {
|
||||
case NonFatal(e) ⇒
|
||||
case NonFatal(e) =>
|
||||
failed = true
|
||||
if ((now + t) >= stop) throw e
|
||||
else null.asInstanceOf[A]
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ object ManualTime {
|
|||
*/
|
||||
def get[A](system: ActorSystem[A]): ManualTime =
|
||||
system.scheduler match {
|
||||
case sc: akka.testkit.ExplicitlyTriggeredScheduler ⇒ new ManualTime(sc)
|
||||
case _ ⇒ throw new IllegalArgumentException("ActorSystem not configured with explicitly triggered scheduler, " +
|
||||
case sc: akka.testkit.ExplicitlyTriggeredScheduler => new ManualTime(sc)
|
||||
case _ => throw new IllegalArgumentException("ActorSystem not configured with explicitly triggered scheduler, " +
|
||||
"make sure to include akka.actor.testkit.typed.javadsl.ManualTime.config() when setting up the test")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ package akka.actor.testkit.typed.javadsl
|
|||
|
||||
import java.time.Duration
|
||||
import java.util.function.Supplier
|
||||
import java.util.{ List ⇒ JList }
|
||||
import java.util.{ List => JList }
|
||||
|
||||
import akka.actor.testkit.typed.FishingOutcome
|
||||
import akka.actor.testkit.typed.TestKitSettings
|
||||
|
|
|
|||
|
|
@ -181,9 +181,9 @@ final class ActorTestKit private[akka] (val name: String, val config: Config, se
|
|||
* Other actors will not be stopped by this method.
|
||||
*/
|
||||
def stop[T](ref: ActorRef[T], max: FiniteDuration = timeout.duration): Unit = try {
|
||||
Await.result(internalSystem.ask { x: ActorRef[ActorTestKitGuardian.Ack.type] ⇒ ActorTestKitGuardian.StopActor(ref, x) }, max)
|
||||
Await.result(internalSystem.ask { x: ActorRef[ActorTestKitGuardian.Ack.type] => ActorTestKitGuardian.StopActor(ref, x) }, max)
|
||||
} catch {
|
||||
case _: TimeoutException ⇒
|
||||
case _: TimeoutException =>
|
||||
assert(false, s"timeout ($max) during stop() waiting for actor [${ref.path}] to stop")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ object ManualTime {
|
|||
*/
|
||||
def apply()(implicit system: ActorSystem[_]): ManualTime =
|
||||
system.scheduler match {
|
||||
case sc: akka.testkit.ExplicitlyTriggeredScheduler ⇒ new ManualTime(sc)
|
||||
case _ ⇒ throw new IllegalArgumentException("ActorSystem not configured with explicitly triggered scheduler, " +
|
||||
case sc: akka.testkit.ExplicitlyTriggeredScheduler => new ManualTime(sc)
|
||||
case _ => throw new IllegalArgumentException("ActorSystem not configured with explicitly triggered scheduler, " +
|
||||
"make sure to include akka.actor.testkit.typed.scaladsl.ManualTime.config() when setting up the test")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,12 +96,12 @@ object TestProbe {
|
|||
* }
|
||||
* }}}
|
||||
*/
|
||||
def within[T](min: FiniteDuration, max: FiniteDuration)(f: ⇒ T): T
|
||||
def within[T](min: FiniteDuration, max: FiniteDuration)(f: => T): T
|
||||
|
||||
/**
|
||||
* Same as calling `within(0 seconds, max)(f)`.
|
||||
*/
|
||||
def within[T](max: FiniteDuration)(f: ⇒ T): T
|
||||
def within[T](max: FiniteDuration)(f: => T): T
|
||||
|
||||
/**
|
||||
* Same as `expectMessage(remainingOrDefault, obj)`, but using the default timeout as deadline.
|
||||
|
|
@ -189,12 +189,12 @@ object TestProbe {
|
|||
* The timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".
|
||||
* @return The messages accepted in the order they arrived
|
||||
*/
|
||||
def fishForMessage(max: FiniteDuration, hint: String)(fisher: M ⇒ FishingOutcome): immutable.Seq[M]
|
||||
def fishForMessage(max: FiniteDuration, hint: String)(fisher: M => FishingOutcome): immutable.Seq[M]
|
||||
|
||||
/**
|
||||
* Same as the other `fishForMessage` but with no hint
|
||||
*/
|
||||
def fishForMessage(max: FiniteDuration)(fisher: M ⇒ FishingOutcome): immutable.Seq[M]
|
||||
def fishForMessage(max: FiniteDuration)(fisher: M => FishingOutcome): immutable.Seq[M]
|
||||
|
||||
/**
|
||||
* Expect the given actor to be stopped or stop within the given timeout or
|
||||
|
|
@ -215,7 +215,7 @@ object TestProbe {
|
|||
*
|
||||
* Note that the timeout is scaled using the configuration entry "akka.actor.testkit.typed.timefactor".
|
||||
*/
|
||||
def awaitAssert[A](a: ⇒ A, max: FiniteDuration, interval: FiniteDuration): A
|
||||
def awaitAssert[A](a: => A, max: FiniteDuration, interval: FiniteDuration): A
|
||||
|
||||
/**
|
||||
* Evaluate the given assert every 100 ms until it does not throw an exception and return the
|
||||
|
|
@ -223,7 +223,7 @@ object TestProbe {
|
|||
*
|
||||
* If the `max` timeout expires the last exception is thrown.
|
||||
*/
|
||||
def awaitAssert[A](a: ⇒ A, max: FiniteDuration): A
|
||||
def awaitAssert[A](a: => A, max: FiniteDuration): A
|
||||
|
||||
/**
|
||||
* Evaluate the given assert every 100 ms until it does not throw an exception and return the
|
||||
|
|
@ -231,7 +231,7 @@ object TestProbe {
|
|||
*
|
||||
* If the default timeout expires the last exception is thrown.
|
||||
*/
|
||||
def awaitAssert[A](a: ⇒ A): A
|
||||
def awaitAssert[A](a: => A): A
|
||||
|
||||
/**
|
||||
* Stops the [[TestProbe.ref]], which is useful when testing watch and termination.
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class ActorTestKitSpec extends ScalaTestWithActorTestKit with WordSpecLike {
|
|||
|
||||
"spawn an actor" in {
|
||||
val sawMessage = Promise[Boolean]()
|
||||
val ref = spawn(Behaviors.setup[AnyRef] { context ⇒
|
||||
val ref = spawn(Behaviors.setup[AnyRef] { context =>
|
||||
sawMessage.trySuccess(true)
|
||||
Behaviors.empty
|
||||
})
|
||||
|
|
@ -50,7 +50,7 @@ class ActorTestKitSpec extends ScalaTestWithActorTestKit with WordSpecLike {
|
|||
|
||||
"spawn a named actor" in {
|
||||
val spawnedWithName = Promise[String]()
|
||||
val ref = spawn(Behaviors.setup[AnyRef] { context ⇒
|
||||
val ref = spawn(Behaviors.setup[AnyRef] { context =>
|
||||
spawnedWithName.trySuccess(context.self.path.name)
|
||||
Behaviors.empty
|
||||
}, "name")
|
||||
|
|
|
|||
|
|
@ -31,75 +31,75 @@ object BehaviorTestKitSpec {
|
|||
case class StopChild(child: ActorRef[String]) extends Command
|
||||
case object SpawnAdapter extends Command
|
||||
case class SpawnAdapterWithName(name: String) extends Command
|
||||
case class CreateMessageAdapter[U](messageClass: Class[U], f: U ⇒ Command) extends Command
|
||||
case class CreateMessageAdapter[U](messageClass: Class[U], f: U => Command) extends Command
|
||||
case class SpawnAndWatchUnwatch(name: String) extends Command
|
||||
case class SpawnAndWatchWith(name: String) extends Command
|
||||
case class SpawnSession(replyTo: ActorRef[ActorRef[String]], sessionHandler: ActorRef[String]) extends Command
|
||||
case class KillSession(session: ActorRef[String], replyTo: ActorRef[Done]) extends Command
|
||||
case class Log(what: String) extends Command
|
||||
|
||||
val init: Behavior[Command] = Behaviors.receive[Command] { (context, message) ⇒
|
||||
val init: Behavior[Command] = Behaviors.receive[Command] { (context, message) =>
|
||||
message match {
|
||||
case SpawnChild ⇒
|
||||
case SpawnChild =>
|
||||
context.spawn(Child.initial, "child")
|
||||
Behaviors.same
|
||||
case SpawnChildren(numberOfChildren) if numberOfChildren > 0 ⇒
|
||||
0.until(numberOfChildren).foreach { i ⇒
|
||||
case SpawnChildren(numberOfChildren) if numberOfChildren > 0 =>
|
||||
0.until(numberOfChildren).foreach { i =>
|
||||
context.spawn(Child.initial, s"child$i")
|
||||
}
|
||||
Behaviors.same
|
||||
case SpawnChildrenWithProps(numberOfChildren, props) if numberOfChildren > 0 ⇒
|
||||
0.until(numberOfChildren).foreach { i ⇒
|
||||
case SpawnChildrenWithProps(numberOfChildren, props) if numberOfChildren > 0 =>
|
||||
0.until(numberOfChildren).foreach { i =>
|
||||
context.spawn(Child.initial, s"child$i", props)
|
||||
}
|
||||
Behaviors.same
|
||||
case SpawnAnonymous(numberOfChildren) if numberOfChildren > 0 ⇒
|
||||
0.until(numberOfChildren).foreach { _ ⇒
|
||||
case SpawnAnonymous(numberOfChildren) if numberOfChildren > 0 =>
|
||||
0.until(numberOfChildren).foreach { _ =>
|
||||
context.spawnAnonymous(Child.initial)
|
||||
}
|
||||
Behaviors.same
|
||||
case SpawnAnonymousWithProps(numberOfChildren, props) if numberOfChildren > 0 ⇒
|
||||
0.until(numberOfChildren).foreach { _ ⇒
|
||||
case SpawnAnonymousWithProps(numberOfChildren, props) if numberOfChildren > 0 =>
|
||||
0.until(numberOfChildren).foreach { _ =>
|
||||
context.spawnAnonymous(Child.initial, props)
|
||||
}
|
||||
Behaviors.same
|
||||
case StopChild(child) ⇒
|
||||
case StopChild(child) =>
|
||||
context.stop(child)
|
||||
Behaviors.same
|
||||
case SpawnAdapter ⇒
|
||||
case SpawnAdapter =>
|
||||
context.spawnMessageAdapter {
|
||||
r: Reproduce ⇒ SpawnAnonymous(r.times)
|
||||
r: Reproduce => SpawnAnonymous(r.times)
|
||||
}
|
||||
Behaviors.same
|
||||
case SpawnAdapterWithName(name) ⇒
|
||||
case SpawnAdapterWithName(name) =>
|
||||
context.spawnMessageAdapter({
|
||||
r: Reproduce ⇒ SpawnAnonymous(r.times)
|
||||
r: Reproduce => SpawnAnonymous(r.times)
|
||||
}, name)
|
||||
Behaviors.same
|
||||
case SpawnAndWatchUnwatch(name) ⇒
|
||||
case SpawnAndWatchUnwatch(name) =>
|
||||
val c = context.spawn(Child.initial, name)
|
||||
context.watch(c)
|
||||
context.unwatch(c)
|
||||
Behaviors.same
|
||||
case m @ SpawnAndWatchWith(name) ⇒
|
||||
case m @ SpawnAndWatchWith(name) =>
|
||||
val c = context.spawn(Child.initial, name)
|
||||
context.watchWith(c, m)
|
||||
Behaviors.same
|
||||
case SpawnSession(replyTo, sessionHandler) ⇒
|
||||
val session = context.spawnAnonymous[String](Behaviors.receiveMessage { message ⇒
|
||||
case SpawnSession(replyTo, sessionHandler) =>
|
||||
val session = context.spawnAnonymous[String](Behaviors.receiveMessage { message =>
|
||||
sessionHandler ! message
|
||||
Behavior.same
|
||||
})
|
||||
replyTo ! session
|
||||
Behaviors.same
|
||||
case KillSession(session, replyTo) ⇒
|
||||
case KillSession(session, replyTo) =>
|
||||
context.stop(session)
|
||||
replyTo ! Done
|
||||
Behaviors.same
|
||||
case CreateMessageAdapter(messageClass, f) ⇒
|
||||
case CreateMessageAdapter(messageClass, f) =>
|
||||
context.messageAdapter(f)(ClassTag(messageClass))
|
||||
Behaviors.same
|
||||
case Log(what) ⇒
|
||||
case Log(what) =>
|
||||
context.log.info(what)
|
||||
Behaviors.same
|
||||
}
|
||||
|
|
@ -110,9 +110,9 @@ object BehaviorTestKitSpec {
|
|||
|
||||
sealed trait Action
|
||||
|
||||
val initial: Behavior[Action] = Behaviors.receive[Action] { (_, message) ⇒
|
||||
val initial: Behavior[Action] = Behaviors.receive[Action] { (_, message) =>
|
||||
message match {
|
||||
case _ ⇒
|
||||
case _ =>
|
||||
Behaviors.empty
|
||||
}
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ class BehaviorTestKitSpec extends WordSpec with Matchers {
|
|||
testkit.run(SpawnChildren(1))
|
||||
val ae = intercept[AssertionError] {
|
||||
testkit.expectEffectPF {
|
||||
case SpawnedAnonymous(_, _) ⇒
|
||||
case SpawnedAnonymous(_, _) =>
|
||||
}
|
||||
}
|
||||
ae.getMessage should startWith("expected matching effect but got: ")
|
||||
|
|
@ -166,7 +166,7 @@ class BehaviorTestKitSpec extends WordSpec with Matchers {
|
|||
val testkit = BehaviorTestKit[Father.Command](Father.init)
|
||||
testkit.run(SpawnChildren(1))
|
||||
val childName = testkit.expectEffectPF {
|
||||
case Spawned(_, name, _) ⇒ name
|
||||
case Spawned(_, name, _) => name
|
||||
}
|
||||
childName should ===("child0")
|
||||
}
|
||||
|
|
@ -174,7 +174,7 @@ class BehaviorTestKitSpec extends WordSpec with Matchers {
|
|||
"allow assertions using partial functions - match on NoEffect" in {
|
||||
val testkit = BehaviorTestKit[Father.Command](Father.init)
|
||||
val hasEffects = testkit.expectEffectPF {
|
||||
case NoEffects ⇒ false
|
||||
case NoEffects => false
|
||||
}
|
||||
hasEffects should ===(false)
|
||||
}
|
||||
|
|
@ -248,7 +248,7 @@ class BehaviorTestKitSpec extends WordSpec with Matchers {
|
|||
"BehaviorTestkit's messageAdapter" must {
|
||||
"create message adapters and record effects" in {
|
||||
val testkit = BehaviorTestKit[Father.Command](Father.init)
|
||||
testkit.run(CreateMessageAdapter(classOf[String], (_: String) ⇒ SpawnChildren(1)))
|
||||
testkit.run(CreateMessageAdapter(classOf[String], (_: String) => SpawnChildren(1)))
|
||||
testkit.expectEffectType[MessageAdapter[String, Command]]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class TestProbeSpec extends ScalaTestWithActorTestKit with WordSpecLike {
|
|||
def compileOnlyApiTest(): Unit = {
|
||||
val probe = TestProbe[AnyRef]()
|
||||
probe.fishForMessage(100.millis) {
|
||||
case _ ⇒ FishingOutcomes.complete
|
||||
case _ => FishingOutcomes.complete
|
||||
}
|
||||
probe.awaitAssert({
|
||||
"result"
|
||||
|
|
@ -43,11 +43,11 @@ class TestProbeSpec extends ScalaTestWithActorTestKit with WordSpecLike {
|
|||
"allow probing for actor stop when actor has not stopped yet" in {
|
||||
case object Stop
|
||||
val probe = TestProbe()
|
||||
val ref = spawn(Behaviors.receive[Stop.type]((context, message) ⇒
|
||||
Behaviors.withTimers { (timer) ⇒
|
||||
val ref = spawn(Behaviors.receive[Stop.type]((context, message) =>
|
||||
Behaviors.withTimers { (timer) =>
|
||||
timer.startSingleTimer("key", Stop, 300.millis)
|
||||
|
||||
Behaviors.receive((context, stop) ⇒
|
||||
Behaviors.receive((context, stop) =>
|
||||
Behaviors.stopped
|
||||
)
|
||||
}
|
||||
|
|
@ -65,8 +65,8 @@ class TestProbeSpec extends ScalaTestWithActorTestKit with WordSpecLike {
|
|||
probe.ref ! "two"
|
||||
|
||||
val result = probe.fishForMessage(300.millis) {
|
||||
case "one" ⇒ FishingOutcomes.continue
|
||||
case "two" ⇒ FishingOutcomes.complete
|
||||
case "one" => FishingOutcomes.continue
|
||||
case "two" => FishingOutcomes.complete
|
||||
}
|
||||
|
||||
result should ===(List("one", "two"))
|
||||
|
|
@ -81,8 +81,8 @@ class TestProbeSpec extends ScalaTestWithActorTestKit with WordSpecLike {
|
|||
|
||||
intercept[AssertionError] {
|
||||
probe.fishForMessage(300.millis) {
|
||||
case "one" ⇒ FishingOutcomes.continue
|
||||
case "two" ⇒ FishingOutcomes.fail("not the fish I'm looking for")
|
||||
case "one" => FishingOutcomes.continue
|
||||
case "two" => FishingOutcomes.fail("not the fish I'm looking for")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -91,7 +91,7 @@ class TestProbeSpec extends ScalaTestWithActorTestKit with WordSpecLike {
|
|||
val probe = TestProbe[AnyRef]()
|
||||
|
||||
assertThrows[AssertionError] {
|
||||
probe.fishForMessage(100.millis) { _ ⇒
|
||||
probe.fishForMessage(100.millis) { _ =>
|
||||
Thread.sleep(150)
|
||||
FishingOutcomes.complete
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ class TestProbeSpec extends ScalaTestWithActorTestKit with WordSpecLike {
|
|||
|
||||
intercept[AssertionError] {
|
||||
probe.fishForMessage(300.millis) {
|
||||
case "one" ⇒ FishingOutcomes.continue
|
||||
case "one" => FishingOutcomes.continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ class TestProbeSpec extends ScalaTestWithActorTestKit with WordSpecLike {
|
|||
|
||||
intercept[AssertionError] {
|
||||
probe.fishForMessage(300.millis) {
|
||||
case "one" ⇒ FishingOutcomes.continue
|
||||
case "one" => FishingOutcomes.continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -147,7 +147,7 @@ class TestProbeSpec extends ScalaTestWithActorTestKit with WordSpecLike {
|
|||
|
||||
"allow receiving one message of type TestProbe[M]" in {
|
||||
val probe = createTestProbe[EventT]()
|
||||
eventsT(10).forall { e ⇒
|
||||
eventsT(10).forall { e =>
|
||||
probe.ref ! e
|
||||
probe.receiveMessage == e
|
||||
} should ===(true)
|
||||
|
|
@ -179,7 +179,7 @@ object TestProbeSpec {
|
|||
|
||||
/** Creates the `expected` number of events to test. */
|
||||
def eventsT(expected: Int): Seq[EventT] =
|
||||
for (n ← 1 to expected) yield EventT(n)
|
||||
for (n <- 1 to expected) yield EventT(n)
|
||||
}
|
||||
|
||||
class TestProbeTimeoutSpec extends ScalaTestWithActorTestKit(TestProbeSpec.timeoutConfig) with WordSpecLike {
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ object AsyncTestingExampleSpec {
|
|||
case class Ping(message: String, response: ActorRef[Pong])
|
||||
case class Pong(message: String)
|
||||
|
||||
val echoActor: Behavior[Ping] = Behaviors.receive { (_, message) ⇒
|
||||
val echoActor: Behavior[Ping] = Behaviors.receive { (_, message) =>
|
||||
message match {
|
||||
case Ping(m, replyTo) ⇒
|
||||
case Ping(m, replyTo) =>
|
||||
replyTo ! Pong(m)
|
||||
Behaviors.same
|
||||
}
|
||||
|
|
@ -43,7 +43,7 @@ object AsyncTestingExampleSpec {
|
|||
}
|
||||
|
||||
private def publish(i: Int)(implicit timeout: Timeout): Future[Try[Int]] = {
|
||||
publisher.ask(ref ⇒ Message(i, ref))
|
||||
publisher.ask(ref => Message(i, ref))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ class AsyncTestingExampleSpec extends WordSpec with BeforeAndAfterAll with Match
|
|||
import testKit._
|
||||
|
||||
// simulate the happy path
|
||||
val mockedBehavior = Behaviors.receiveMessage[Message] { msg ⇒
|
||||
val mockedBehavior = Behaviors.receiveMessage[Message] { msg =>
|
||||
msg.replyTo ! Success(msg.i)
|
||||
Behaviors.same
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ class AsyncTestingExampleSpec extends WordSpec with BeforeAndAfterAll with Match
|
|||
producer.produce(messages)
|
||||
|
||||
// verify expected behavior
|
||||
for (i ← 0 until messages) {
|
||||
for (i <- 0 until messages) {
|
||||
val msg = probe.expectMessageType[Message]
|
||||
msg.i shouldBe i
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ class ManualTimerExampleSpec extends ScalaTestWithActorTestKit(ManualTime.config
|
|||
case object Tock
|
||||
|
||||
val probe = TestProbe[Tock.type]()
|
||||
val behavior = Behaviors.withTimers[Tick.type] { timer ⇒
|
||||
val behavior = Behaviors.withTimers[Tick.type] { timer =>
|
||||
timer.startSingleTimer("T", Tick, 10.millis)
|
||||
Behaviors.receiveMessage { _ ⇒
|
||||
Behaviors.receiveMessage { _ =>
|
||||
probe.ref ! Tock
|
||||
Behaviors.same
|
||||
}
|
||||
|
|
@ -46,9 +46,9 @@ class ManualTimerExampleSpec extends ScalaTestWithActorTestKit(ManualTime.config
|
|||
case object Tock
|
||||
|
||||
val probe = TestProbe[Tock.type]()
|
||||
val behavior = Behaviors.withTimers[Tick.type] { timer ⇒
|
||||
val behavior = Behaviors.withTimers[Tick.type] { timer =>
|
||||
timer.startPeriodicTimer("T", Tick, 10.millis)
|
||||
Behaviors.receive { (context, Tick) ⇒
|
||||
Behaviors.receive { (context, Tick) =>
|
||||
probe.ref ! Tock
|
||||
Behaviors.same
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ class ManualTimerExampleSpec extends ScalaTestWithActorTestKit(ManualTime.config
|
|||
|
||||
spawn(behavior)
|
||||
|
||||
for (_ ← Range(0, 5)) {
|
||||
for (_ <- Range(0, 5)) {
|
||||
manualTime.expectNoMessageFor(9.millis, probe)
|
||||
|
||||
manualTime.timePasses(1.milli)
|
||||
|
|
@ -75,14 +75,14 @@ class ManualTimerExampleSpec extends ScalaTestWithActorTestKit(ManualTime.config
|
|||
val probe = TestProbe[Event]("evt")
|
||||
val interval = 10.millis
|
||||
|
||||
val behavior = Behaviors.withTimers[Command] { timer ⇒
|
||||
val behavior = Behaviors.withTimers[Command] { timer =>
|
||||
timer.startPeriodicTimer("T", Tick(1), interval)
|
||||
Behaviors.receive { (context, cmd) ⇒
|
||||
Behaviors.receive { (context, cmd) =>
|
||||
cmd match {
|
||||
case Tick(n) ⇒
|
||||
case Tick(n) =>
|
||||
probe.ref ! Tock(n)
|
||||
Behaviors.same
|
||||
case SlowThenBump(nextCount) ⇒
|
||||
case SlowThenBump(nextCount) =>
|
||||
manualTime.timePasses(interval)
|
||||
timer.startPeriodicTimer("T", Tick(nextCount), interval)
|
||||
probe.ref ! SlowThenBumpAck
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import org.scalatest.WordSpec
|
|||
|
||||
object SyncTestingExampleSpec {
|
||||
//#child
|
||||
val childActor = Behaviors.receiveMessage[String] { _ ⇒
|
||||
val childActor = Behaviors.receiveMessage[String] { _ =>
|
||||
Behaviors.same[String]
|
||||
}
|
||||
//#child
|
||||
|
|
@ -33,24 +33,24 @@ object SyncTestingExampleSpec {
|
|||
case class LogAndSayHello(who: ActorRef[String]) extends Cmd
|
||||
|
||||
val myBehavior = Behaviors.receivePartial[Cmd] {
|
||||
case (context, CreateChild(name)) ⇒
|
||||
case (context, CreateChild(name)) =>
|
||||
context.spawn(childActor, name)
|
||||
Behaviors.same
|
||||
case (context, CreateAnonymousChild) ⇒
|
||||
case (context, CreateAnonymousChild) =>
|
||||
context.spawnAnonymous(childActor)
|
||||
Behaviors.same
|
||||
case (context, SayHelloToChild(childName)) ⇒
|
||||
case (context, SayHelloToChild(childName)) =>
|
||||
val child: ActorRef[String] = context.spawn(childActor, childName)
|
||||
child ! "hello"
|
||||
Behaviors.same
|
||||
case (context, SayHelloToAnonymousChild) ⇒
|
||||
case (context, SayHelloToAnonymousChild) =>
|
||||
val child: ActorRef[String] = context.spawnAnonymous(childActor)
|
||||
child ! "hello stranger"
|
||||
Behaviors.same
|
||||
case (_, SayHello(who)) ⇒
|
||||
case (_, SayHello(who)) =>
|
||||
who ! "hello"
|
||||
Behaviors.same
|
||||
case (context, LogAndSayHello(who)) ⇒
|
||||
case (context, LogAndSayHello(who)) =>
|
||||
context.log.info("Saying hello to {}", who.path.name)
|
||||
who ! "hello"
|
||||
Behaviors.same
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ object ActorConfigurationVerificationSpec {
|
|||
|
||||
class TestActor extends Actor {
|
||||
def receive: Receive = {
|
||||
case _ ⇒
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ object ActorCreationPerfSpec {
|
|||
akka.actor.serialize-messages = off
|
||||
""")
|
||||
|
||||
final case class Create(number: Int, props: () ⇒ Props)
|
||||
final case class Create(number: Int, props: () => Props)
|
||||
case object Created
|
||||
case object IsAlive
|
||||
case object Alive
|
||||
|
|
@ -42,24 +42,24 @@ object ActorCreationPerfSpec {
|
|||
|
||||
class EmptyActor extends Actor {
|
||||
def receive = {
|
||||
case IsAlive ⇒ sender() ! Alive
|
||||
case IsAlive => sender() ! Alive
|
||||
}
|
||||
}
|
||||
|
||||
class EmptyArgsActor(val foo: Int, val bar: Int) extends Actor {
|
||||
def receive = {
|
||||
case IsAlive ⇒ sender() ! Alive
|
||||
case IsAlive => sender() ! Alive
|
||||
}
|
||||
}
|
||||
|
||||
class TimingDriver(hist: Histogram) extends Actor {
|
||||
|
||||
def receive = {
|
||||
case IsAlive ⇒
|
||||
case IsAlive =>
|
||||
sender() ! Alive
|
||||
case Create(number, propsCreator) ⇒
|
||||
case Create(number, propsCreator) =>
|
||||
|
||||
for (i ← 1 to number) {
|
||||
for (i <- 1 to number) {
|
||||
val start = System.nanoTime()
|
||||
context.actorOf(propsCreator.apply())
|
||||
// yes, we are aware of this being skewed
|
||||
|
|
@ -68,7 +68,7 @@ object ActorCreationPerfSpec {
|
|||
}
|
||||
|
||||
sender() ! Created
|
||||
case WaitForChildren ⇒
|
||||
case WaitForChildren =>
|
||||
context.children.foreach(_ ! IsAlive)
|
||||
context.become(waiting(context.children.size, sender()), discardOld = false)
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ object ActorCreationPerfSpec {
|
|||
var current = number
|
||||
|
||||
{
|
||||
case Alive ⇒
|
||||
case Alive =>
|
||||
current -= 1
|
||||
if (current == 0) {
|
||||
replyTo ! Waited
|
||||
|
|
@ -90,14 +90,14 @@ object ActorCreationPerfSpec {
|
|||
class Driver extends Actor {
|
||||
|
||||
def receive = {
|
||||
case IsAlive ⇒
|
||||
case IsAlive =>
|
||||
sender() ! Alive
|
||||
case Create(number, propsCreator) ⇒
|
||||
for (i ← 1 to number) {
|
||||
case Create(number, propsCreator) =>
|
||||
for (i <- 1 to number) {
|
||||
context.actorOf(propsCreator.apply())
|
||||
}
|
||||
sender() ! Created
|
||||
case WaitForChildren ⇒
|
||||
case WaitForChildren =>
|
||||
context.children.foreach(_ ! IsAlive)
|
||||
context.become(waiting(context.children.size, sender()), discardOld = false)
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ object ActorCreationPerfSpec {
|
|||
var current = number
|
||||
|
||||
{
|
||||
case Alive ⇒
|
||||
case Alive =>
|
||||
current -= 1
|
||||
if (current == 0) {
|
||||
replyTo ! Waited
|
||||
|
|
@ -133,7 +133,7 @@ class ActorCreationPerfSpec extends AkkaSpec(ActorCreationPerfSpec.config) with
|
|||
override val reportMetricsEnabled = metricsConfig.getBoolean("akka.test.actor.ActorPerfSpec.report-metrics")
|
||||
override val forceGcEnabled = metricsConfig.getBoolean("akka.test.actor.ActorPerfSpec.force-gc")
|
||||
|
||||
def runWithCounterInside(metricName: String, scenarioName: String, number: Int, propsCreator: () ⇒ Props): Unit = {
|
||||
def runWithCounterInside(metricName: String, scenarioName: String, number: Int, propsCreator: () => Props): Unit = {
|
||||
val hist = histogram(BlockingTimeKey / metricName)
|
||||
|
||||
val driver = system.actorOf(Props(classOf[TimingDriver], hist), scenarioName)
|
||||
|
|
@ -141,10 +141,10 @@ class ActorCreationPerfSpec extends AkkaSpec(ActorCreationPerfSpec.config) with
|
|||
expectMsg(Alive)
|
||||
|
||||
driver ! Create(number, propsCreator)
|
||||
expectMsgPF(15 seconds, s"$scenarioName waiting for Created") { case Created ⇒ }
|
||||
expectMsgPF(15 seconds, s"$scenarioName waiting for Created") { case Created => }
|
||||
|
||||
driver ! WaitForChildren
|
||||
expectMsgPF(15 seconds, s"$scenarioName waiting for Waited") { case Waited ⇒ }
|
||||
expectMsgPF(15 seconds, s"$scenarioName waiting for Waited") { case Waited => }
|
||||
|
||||
driver ! PoisonPill
|
||||
watch(driver)
|
||||
|
|
@ -152,7 +152,7 @@ class ActorCreationPerfSpec extends AkkaSpec(ActorCreationPerfSpec.config) with
|
|||
gc()
|
||||
}
|
||||
|
||||
def runWithoutCounter(scenarioName: String, number: Int, propsCreator: () ⇒ Props): HeapMemoryUsage = {
|
||||
def runWithoutCounter(scenarioName: String, number: Int, propsCreator: () => Props): HeapMemoryUsage = {
|
||||
val mem = measureMemory(TotalTimeKey / scenarioName)
|
||||
|
||||
val driver = system.actorOf(Props(classOf[Driver]), scenarioName)
|
||||
|
|
@ -163,10 +163,10 @@ class ActorCreationPerfSpec extends AkkaSpec(ActorCreationPerfSpec.config) with
|
|||
val before = mem.getHeapSnapshot
|
||||
|
||||
driver ! Create(number, propsCreator)
|
||||
expectMsgPF(15 seconds, s"$scenarioName waiting for Created") { case Created ⇒ }
|
||||
expectMsgPF(15 seconds, s"$scenarioName waiting for Created") { case Created => }
|
||||
|
||||
driver ! WaitForChildren
|
||||
expectMsgPF(15 seconds, s"$scenarioName waiting for Waited") { case Waited ⇒ }
|
||||
expectMsgPF(15 seconds, s"$scenarioName waiting for Waited") { case Waited => }
|
||||
|
||||
gc()
|
||||
val after = mem.getHeapSnapshot
|
||||
|
|
@ -178,7 +178,7 @@ class ActorCreationPerfSpec extends AkkaSpec(ActorCreationPerfSpec.config) with
|
|||
after diff before
|
||||
}
|
||||
|
||||
def registerTests(name: String, propsCreator: () ⇒ Props): Unit = {
|
||||
def registerTests(name: String, propsCreator: () => Props): Unit = {
|
||||
val scenarioName = name.replaceAll("""[^\w]""", "")
|
||||
|
||||
s"warm-up before: $name" taggedAs PerformanceTest in {
|
||||
|
|
@ -192,7 +192,7 @@ class ActorCreationPerfSpec extends AkkaSpec(ActorCreationPerfSpec.config) with
|
|||
s"measure synchronous blocked time for $name" taggedAs PerformanceTest in {
|
||||
// note: measuring per-actor-memory-use in this scenario is skewed as the Actor contains references to counters etc!
|
||||
// for measuring actor size use refer to the `runWithoutCounter` method
|
||||
for (i ← 1 to nrOfRepeats) {
|
||||
for (i <- 1 to nrOfRepeats) {
|
||||
runWithCounterInside(name, s"${scenarioName}_driver_inside_$i", nrOfActors, propsCreator)
|
||||
}
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ class ActorCreationPerfSpec extends AkkaSpec(ActorCreationPerfSpec.config) with
|
|||
s"measure total creation time for $name" taggedAs PerformanceTest in {
|
||||
val avgMem = averageGauge(ActorCreationKey / name / "avg-mem-per-actor")
|
||||
|
||||
for (i ← 1 to nrOfRepeats) {
|
||||
for (i <- 1 to nrOfRepeats) {
|
||||
val heapUsed = timedWithKnownOps(TotalTimeKey / s"creating-$nrOfActors-actors" / name, ops = nrOfActors) {
|
||||
runWithoutCounter(s"${scenarioName}_driver_outside_$i", nrOfActors, propsCreator)
|
||||
}
|
||||
|
|
@ -217,25 +217,25 @@ class ActorCreationPerfSpec extends AkkaSpec(ActorCreationPerfSpec.config) with
|
|||
|
||||
"Actor creation with actorOf" must {
|
||||
|
||||
registerTests("Props[EmptyActor] with new Props", () ⇒ Props[EmptyActor])
|
||||
registerTests("Props[EmptyActor] with new Props", () => Props[EmptyActor])
|
||||
|
||||
val props1 = Props[EmptyActor]
|
||||
registerTests("Props[EmptyActor] with same Props", () ⇒ props1)
|
||||
registerTests("Props[EmptyActor] with same Props", () => props1)
|
||||
|
||||
registerTests("Props(new EmptyActor) new", () ⇒ { Props(new EmptyActor) })
|
||||
registerTests("Props(new EmptyActor) new", () => { Props(new EmptyActor) })
|
||||
|
||||
val props2 = Props(new EmptyActor)
|
||||
registerTests("Props(new EmptyActor) same", () ⇒ { props2 })
|
||||
registerTests("Props(new EmptyActor) same", () => { props2 })
|
||||
|
||||
registerTests("Props(classOf[EmptyArgsActor], ...) new", () ⇒ { Props(classOf[EmptyArgsActor], 4711, 1729) })
|
||||
registerTests("Props(classOf[EmptyArgsActor], ...) new", () => { Props(classOf[EmptyArgsActor], 4711, 1729) })
|
||||
|
||||
val props3 = Props(classOf[EmptyArgsActor], 4711, 1729)
|
||||
registerTests("Props(classOf[EmptyArgsActor], ...) same", () ⇒ { props3 })
|
||||
registerTests("Props(classOf[EmptyArgsActor], ...) same", () => { props3 })
|
||||
|
||||
registerTests("Props(new EmptyArgsActor(...)) new", () ⇒ { Props(new EmptyArgsActor(4711, 1729)) })
|
||||
registerTests("Props(new EmptyArgsActor(...)) new", () => { Props(new EmptyArgsActor(4711, 1729)) })
|
||||
|
||||
val props4 = Props(new EmptyArgsActor(4711, 1729))
|
||||
registerTests("Props(new EmptyArgsActor(...)) same", () ⇒ { props4 })
|
||||
registerTests("Props(new EmptyArgsActor(...)) same", () => { props4 })
|
||||
}
|
||||
|
||||
override def afterTermination() = shutdownMetrics()
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class ActorDSLSpec extends AkkaSpec {
|
|||
|
||||
val echo = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case x ⇒ sender() ! x
|
||||
case x => sender() ! x
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -59,9 +59,9 @@ class ActorDSLSpec extends AkkaSpec {
|
|||
val i = inbox()
|
||||
import system.dispatcher
|
||||
val res = Future.sequence(Seq(
|
||||
Future { i.receive() } recover { case x ⇒ x },
|
||||
Future { Thread.sleep(100); i.select() { case "world" ⇒ 1 } } recover { case x ⇒ x },
|
||||
Future { Thread.sleep(200); i.select() { case "hello" ⇒ 2 } } recover { case x ⇒ x }))
|
||||
Future { i.receive() } recover { case x => x },
|
||||
Future { Thread.sleep(100); i.select() { case "world" => 1 } } recover { case x => x },
|
||||
Future { Thread.sleep(200); i.select() { case "hello" => 2 } } recover { case x => x }))
|
||||
Thread.sleep(1000)
|
||||
res.isCompleted should ===(false)
|
||||
i.receiver ! 42
|
||||
|
|
@ -75,7 +75,7 @@ class ActorDSLSpec extends AkkaSpec {
|
|||
i.receiver ! "hello"
|
||||
i.receiver ! "world"
|
||||
val result = i.select() {
|
||||
case "world" ⇒ true
|
||||
case "world" => true
|
||||
}
|
||||
result should ===(true)
|
||||
i.receive() should ===("hello")
|
||||
|
|
@ -85,7 +85,7 @@ class ActorDSLSpec extends AkkaSpec {
|
|||
val i = inbox()
|
||||
system.eventStream.subscribe(testActor, classOf[Warning])
|
||||
try {
|
||||
for (_ ← 1 to 1000) i.receiver ! 0
|
||||
for (_ <- 1 to 1000) i.receiver ! 0
|
||||
expectNoMsg(1 second)
|
||||
EventFilter.warning(start = "dropping message", occurrences = 1) intercept {
|
||||
i.receiver ! 42
|
||||
|
|
@ -93,8 +93,8 @@ class ActorDSLSpec extends AkkaSpec {
|
|||
expectMsgType[Warning]
|
||||
i.receiver ! 42
|
||||
expectNoMsg(1 second)
|
||||
val gotit = for (_ ← 1 to 1000) yield i.receive()
|
||||
gotit should ===((1 to 1000) map (_ ⇒ 0))
|
||||
val gotit = for (_ <- 1 to 1000) yield i.receive()
|
||||
gotit should ===((1 to 1000) map (_ => 0))
|
||||
intercept[TimeoutException] {
|
||||
i.receive(1 second)
|
||||
}
|
||||
|
|
@ -121,7 +121,7 @@ class ActorDSLSpec extends AkkaSpec {
|
|||
//#simple-actor
|
||||
val a = actor(new Act {
|
||||
become {
|
||||
case "hello" ⇒ sender() ! "hi"
|
||||
case "hello" => sender() ! "hi"
|
||||
}
|
||||
})
|
||||
//#simple-actor
|
||||
|
|
@ -135,13 +135,13 @@ class ActorDSLSpec extends AkkaSpec {
|
|||
//#becomeStacked
|
||||
val a = actor(new Act {
|
||||
become { // this will replace the initial (empty) behavior
|
||||
case "info" ⇒ sender() ! "A"
|
||||
case "switch" ⇒
|
||||
case "info" => sender() ! "A"
|
||||
case "switch" =>
|
||||
becomeStacked { // this will stack upon the "A" behavior
|
||||
case "info" ⇒ sender() ! "B"
|
||||
case "switch" ⇒ unbecome() // return to the "A" behavior
|
||||
case "info" => sender() ! "B"
|
||||
case "switch" => unbecome() // return to the "A" behavior
|
||||
}
|
||||
case "lobotomize" ⇒ unbecome() // OH NOES: Actor.emptyBehavior
|
||||
case "lobotomize" => unbecome() // OH NOES: Actor.emptyBehavior
|
||||
}
|
||||
})
|
||||
//#becomeStacked
|
||||
|
|
@ -174,18 +174,18 @@ class ActorDSLSpec extends AkkaSpec {
|
|||
//#failing-actor
|
||||
val a = actor(new Act {
|
||||
become {
|
||||
case "die" ⇒ throw new Exception
|
||||
case "die" => throw new Exception
|
||||
}
|
||||
whenFailing { case m @ (cause, msg) ⇒ testActor ! m }
|
||||
whenRestarted { cause ⇒ testActor ! cause }
|
||||
whenFailing { case m @ (cause, msg) => testActor ! m }
|
||||
whenRestarted { cause => testActor ! cause }
|
||||
})
|
||||
//#failing-actor
|
||||
|
||||
EventFilter[Exception](occurrences = 1) intercept {
|
||||
a ! "die"
|
||||
}
|
||||
expectMsgPF() { case (x: Exception, Some("die")) ⇒ }
|
||||
expectMsgPF() { case _: Exception ⇒ }
|
||||
expectMsgPF() { case (x: Exception, Some("die")) => }
|
||||
expectMsgPF() { case _: Exception => }
|
||||
}
|
||||
|
||||
"support superviseWith" in {
|
||||
|
|
@ -193,19 +193,19 @@ class ActorDSLSpec extends AkkaSpec {
|
|||
val system = null // shadow the implicit system
|
||||
//#supervise-with
|
||||
superviseWith(OneForOneStrategy() {
|
||||
case e: Exception if e.getMessage == "hello" ⇒ Stop
|
||||
case _: Exception ⇒ Resume
|
||||
case e: Exception if e.getMessage == "hello" => Stop
|
||||
case _: Exception => Resume
|
||||
})
|
||||
//#supervise-with
|
||||
val child = actor("child")(new Act {
|
||||
whenFailing { (_, _) ⇒ }
|
||||
whenFailing { (_, _) => }
|
||||
become {
|
||||
case ref: ActorRef ⇒ whenStopping(ref ! "stopped")
|
||||
case ex: Exception ⇒ throw ex
|
||||
case ref: ActorRef => whenStopping(ref ! "stopped")
|
||||
case ex: Exception => throw ex
|
||||
}
|
||||
})
|
||||
become {
|
||||
case x ⇒ child ! x
|
||||
case x => child ! x
|
||||
}
|
||||
})
|
||||
a ! testActor
|
||||
|
|
@ -228,7 +228,7 @@ class ActorDSLSpec extends AkkaSpec {
|
|||
whenStarting { context.parent ! ("hello from " + self.path) }
|
||||
})
|
||||
become {
|
||||
case x ⇒ testActor ! x
|
||||
case x => testActor ! x
|
||||
}
|
||||
})
|
||||
//#nested-actor
|
||||
|
|
@ -240,10 +240,10 @@ class ActorDSLSpec extends AkkaSpec {
|
|||
//#act-with-stash
|
||||
val a = actor(new ActWithStash {
|
||||
become {
|
||||
case 1 ⇒ stash()
|
||||
case 2 ⇒
|
||||
case 1 => stash()
|
||||
case 2 =>
|
||||
testActor ! 2; unstashAll(); becomeStacked {
|
||||
case 1 ⇒ testActor ! 1; unbecome()
|
||||
case 1 => testActor ! 1; unbecome()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import scala.concurrent.duration._
|
|||
import java.util.concurrent.atomic._
|
||||
import scala.concurrent.Await
|
||||
import akka.pattern.ask
|
||||
import java.util.UUID.{ randomUUID ⇒ newUuid }
|
||||
import java.util.UUID.{ randomUUID => newUuid }
|
||||
|
||||
object ActorLifeCycleSpec {
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ object ActorLifeCycleSpec {
|
|||
val currentGen = generationProvider.getAndIncrement()
|
||||
override def preStart(): Unit = { report("preStart") }
|
||||
override def postStop(): Unit = { report("postStop") }
|
||||
def receive = { case "status" ⇒ sender() ! message("OK") }
|
||||
def receive = { case "status" => sender() ! message("OK") }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -127,18 +127,18 @@ class ActorLifeCycleSpec extends AkkaSpec("akka.actor.serialize-messages=off") w
|
|||
}
|
||||
|
||||
"clear the behavior stack upon restart" in {
|
||||
final case class Become(recv: ActorContext ⇒ Receive)
|
||||
final case class Become(recv: ActorContext => Receive)
|
||||
val a = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case Become(beh) ⇒ { context.become(beh(context), discardOld = false); sender() ! "ok" }
|
||||
case x ⇒ sender() ! 42
|
||||
case Become(beh) => { context.become(beh(context), discardOld = false); sender() ! "ok" }
|
||||
case x => sender() ! 42
|
||||
}
|
||||
}))
|
||||
a ! "hello"
|
||||
expectMsg(42)
|
||||
a ! Become(ctx ⇒ {
|
||||
case "fail" ⇒ throw new RuntimeException("buh")
|
||||
case x ⇒ ctx.sender() ! 43
|
||||
a ! Become(ctx => {
|
||||
case "fail" => throw new RuntimeException("buh")
|
||||
case x => ctx.sender() ! 43
|
||||
})
|
||||
expectMsg("ok")
|
||||
a ! "hello"
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ object ActorLookupSpec {
|
|||
|
||||
class Node extends Actor {
|
||||
def receive = {
|
||||
case Create(name) ⇒ sender() ! context.actorOf(p, name)
|
||||
case LookupElems(path) ⇒ sender() ! context.actorFor(path)
|
||||
case LookupString(path) ⇒ sender() ! context.actorFor(path)
|
||||
case LookupPath(path) ⇒ sender() ! context.actorFor(path)
|
||||
case GetSender(ref) ⇒ ref ! sender()
|
||||
case Create(name) => sender() ! context.actorOf(p, name)
|
||||
case LookupElems(path) => sender() ! context.actorFor(path)
|
||||
case LookupString(path) => sender() ! context.actorFor(path)
|
||||
case LookupPath(path) => sender() ! context.actorFor(path)
|
||||
case GetSender(ref) => ref ! sender()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
def empty(path: String) =
|
||||
new EmptyLocalActorRef(sysImpl.provider, path match {
|
||||
case RelativeActorPath(elems) ⇒ system.actorFor("/").path / elems
|
||||
case RelativeActorPath(elems) => system.actorFor("/").path / elems
|
||||
}, system.eventStream)
|
||||
|
||||
"An ActorSystem" must {
|
||||
|
|
@ -179,8 +179,8 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
|
|||
Await.result(looker ? LookupPath(pathOf.path), timeout.duration) should ===(result)
|
||||
}
|
||||
for {
|
||||
looker ← all
|
||||
target ← all
|
||||
looker <- all
|
||||
target <- all
|
||||
} check(looker, target, target)
|
||||
}
|
||||
|
||||
|
|
@ -193,8 +193,8 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
|
|||
Await.result(looker ? LookupString(pathOf.path.toString + "/"), timeout.duration) should ===(result)
|
||||
}
|
||||
for {
|
||||
looker ← all
|
||||
target ← all
|
||||
looker <- all
|
||||
target <- all
|
||||
} check(looker, target, target)
|
||||
}
|
||||
|
||||
|
|
@ -204,8 +204,8 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
|
|||
Await.result(looker ? LookupString(pathOf.path.elements.mkString("/", "/", "/")), timeout.duration) should ===(result)
|
||||
}
|
||||
for {
|
||||
looker ← all
|
||||
target ← all
|
||||
looker <- all
|
||||
target <- all
|
||||
} check(looker, target, target)
|
||||
}
|
||||
|
||||
|
|
@ -217,8 +217,8 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
|
|||
}
|
||||
check(c1, user, "..")
|
||||
for {
|
||||
looker ← Seq(c1, c2)
|
||||
target ← all
|
||||
looker <- Seq(c1, c2)
|
||||
target <- all
|
||||
} check(looker, target, Seq("..") ++ target.path.elements.drop(1): _*)
|
||||
check(c21, user, "..", "..")
|
||||
check(c21, root, "..", "..", "..")
|
||||
|
|
@ -227,7 +227,7 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
"find system-generated actors" in {
|
||||
def check(target: ActorRef): Unit = {
|
||||
for (looker ← all) {
|
||||
for (looker <- all) {
|
||||
Await.result(looker ? LookupPath(target.path), timeout.duration) should ===(target)
|
||||
Await.result(looker ? LookupString(target.path.toString), timeout.duration) should ===(target)
|
||||
Await.result(looker ? LookupString(target.path.toString + "/"), timeout.duration) should ===(target)
|
||||
|
|
@ -235,7 +235,7 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
|
|||
if (target != root) Await.result(looker ? LookupString(target.path.elements.mkString("/", "/", "/")), timeout.duration) should ===(target)
|
||||
}
|
||||
}
|
||||
for (target ← Seq(root, syst, user, system.deadLetters)) check(target)
|
||||
for (target <- Seq(root, syst, user, system.deadLetters)) check(target)
|
||||
}
|
||||
|
||||
"return deadLetters or EmptyLocalActorRef, respectively, for non-existing paths" in {
|
||||
|
|
@ -249,18 +249,18 @@ class ActorLookupSpec extends AkkaSpec with DefaultTimeout {
|
|||
def check(looker: ActorRef): Unit = {
|
||||
val lookname = looker.path.elements.mkString("", "/", "/")
|
||||
for (
|
||||
(l, r) ← Seq(
|
||||
LookupString("a/b/c") → empty(lookname + "a/b/c"),
|
||||
LookupString("") → system.deadLetters,
|
||||
LookupString("akka://all-systems/Nobody") → system.deadLetters,
|
||||
LookupPath(system / "hallo") → empty("user/hallo"),
|
||||
LookupPath(looker.path child "hallo") → empty(lookname + "hallo"), // test Java API
|
||||
LookupPath(looker.path descendant Seq("a", "b").asJava) → empty(lookname + "a/b"), // test Java API
|
||||
LookupElems(Seq()) → system.deadLetters,
|
||||
LookupElems(Seq("a")) → empty(lookname + "a"))
|
||||
(l, r) <- Seq(
|
||||
LookupString("a/b/c") -> empty(lookname + "a/b/c"),
|
||||
LookupString("") -> system.deadLetters,
|
||||
LookupString("akka://all-systems/Nobody") -> system.deadLetters,
|
||||
LookupPath(system / "hallo") -> empty("user/hallo"),
|
||||
LookupPath(looker.path child "hallo") -> empty(lookname + "hallo"), // test Java API
|
||||
LookupPath(looker.path descendant Seq("a", "b").asJava) -> empty(lookname + "a/b"), // test Java API
|
||||
LookupElems(Seq()) -> system.deadLetters,
|
||||
LookupElems(Seq("a")) -> empty(lookname + "a"))
|
||||
) checkOne(looker, l, r)
|
||||
}
|
||||
for (looker ← all) check(looker)
|
||||
for (looker <- all) check(looker)
|
||||
}
|
||||
|
||||
"find temporary actors" in {
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ object ActorMailboxSpec {
|
|||
|
||||
class QueueReportingActor extends Actor {
|
||||
def receive = {
|
||||
case _ ⇒ sender() ! context.asInstanceOf[ActorCell].mailbox.messageQueue
|
||||
case _ => sender() ! context.asInstanceOf[ActorCell].mailbox.messageQueue
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +231,7 @@ class ActorMailboxSpec(conf: Config) extends AkkaSpec(conf) with DefaultTimeout
|
|||
|
||||
actor ! "ping"
|
||||
val q = expectMsgType[MessageQueue]
|
||||
types foreach (t ⇒ assert(t isInstance q, s"Type [${q.getClass.getName}] is not assignable to [${t.getName}]"))
|
||||
types foreach (t => assert(t isInstance q, s"Type [${q.getClass.getName}] is not assignable to [${t.getName}]"))
|
||||
q
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,28 +23,28 @@ object ActorRefSpec {
|
|||
var replyTo: ActorRef = null
|
||||
|
||||
def receive = {
|
||||
case "complexRequest" ⇒ {
|
||||
case "complexRequest" => {
|
||||
replyTo = sender()
|
||||
val worker = context.actorOf(Props[WorkerActor])
|
||||
worker ! "work"
|
||||
}
|
||||
case "complexRequest2" ⇒
|
||||
case "complexRequest2" =>
|
||||
val worker = context.actorOf(Props[WorkerActor])
|
||||
worker ! ReplyTo(sender())
|
||||
case "workDone" ⇒ replyTo ! "complexReply"
|
||||
case "simpleRequest" ⇒ sender() ! "simpleReply"
|
||||
case "workDone" => replyTo ! "complexReply"
|
||||
case "simpleRequest" => sender() ! "simpleReply"
|
||||
}
|
||||
}
|
||||
|
||||
class WorkerActor() extends Actor {
|
||||
import context.system
|
||||
def receive = {
|
||||
case "work" ⇒ {
|
||||
case "work" => {
|
||||
work()
|
||||
sender() ! "workDone"
|
||||
context.stop(self)
|
||||
}
|
||||
case ReplyTo(replyTo) ⇒ {
|
||||
case ReplyTo(replyTo) => {
|
||||
work()
|
||||
replyTo ! "complexReply"
|
||||
}
|
||||
|
|
@ -56,13 +56,13 @@ object ActorRefSpec {
|
|||
class SenderActor(replyActor: ActorRef, latch: TestLatch) extends Actor {
|
||||
|
||||
def receive = {
|
||||
case "complex" ⇒ replyActor ! "complexRequest"
|
||||
case "complex2" ⇒ replyActor ! "complexRequest2"
|
||||
case "simple" ⇒ replyActor ! "simpleRequest"
|
||||
case "complexReply" ⇒ {
|
||||
case "complex" => replyActor ! "complexRequest"
|
||||
case "complex2" => replyActor ! "complexRequest2"
|
||||
case "simple" => replyActor ! "simpleRequest"
|
||||
case "complexReply" => {
|
||||
latch.countDown()
|
||||
}
|
||||
case "simpleReply" ⇒ {
|
||||
case "simpleReply" => {
|
||||
latch.countDown()
|
||||
}
|
||||
}
|
||||
|
|
@ -70,8 +70,8 @@ object ActorRefSpec {
|
|||
|
||||
class OuterActor(val inner: ActorRef) extends Actor {
|
||||
def receive = {
|
||||
case "self" ⇒ sender() ! self
|
||||
case x ⇒ inner forward x
|
||||
case "self" => sender() ! self
|
||||
case x => inner forward x
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -79,8 +79,8 @@ object ActorRefSpec {
|
|||
val fail = new InnerActor
|
||||
|
||||
def receive = {
|
||||
case "self" ⇒ sender() ! self
|
||||
case x ⇒ inner forward x
|
||||
case "self" => sender() ! self
|
||||
case x => inner forward x
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -90,8 +90,8 @@ object ActorRefSpec {
|
|||
|
||||
class InnerActor extends Actor {
|
||||
def receive = {
|
||||
case "innerself" ⇒ sender() ! self
|
||||
case other ⇒ sender() ! other
|
||||
case "innerself" => sender() ! self
|
||||
case other => sender() ! other
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,8 +99,8 @@ object ActorRefSpec {
|
|||
val fail = new InnerActor
|
||||
|
||||
def receive = {
|
||||
case "innerself" ⇒ sender() ! self
|
||||
case other ⇒ sender() ! other
|
||||
case "innerself" => sender() ! self
|
||||
case other => sender() ! other
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -112,17 +112,17 @@ object ActorRefSpec {
|
|||
class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
||||
import akka.actor.ActorRefSpec._
|
||||
|
||||
def promiseIntercept(f: ⇒ Actor)(to: Promise[Actor]): Actor = try {
|
||||
def promiseIntercept(f: => Actor)(to: Promise[Actor]): Actor = try {
|
||||
val r = f
|
||||
to.success(r)
|
||||
r
|
||||
} catch {
|
||||
case e: Throwable ⇒
|
||||
case e: Throwable =>
|
||||
to.failure(e)
|
||||
throw e
|
||||
}
|
||||
|
||||
def wrap[T](f: Promise[Actor] ⇒ T): T = {
|
||||
def wrap[T](f: Promise[Actor] => T): T = {
|
||||
val result = Promise[Actor]()
|
||||
val r = f(result)
|
||||
Await.result(result.future, 1 minute)
|
||||
|
|
@ -134,17 +134,17 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
"not allow Actors to be created outside of an actorOf" in {
|
||||
import system.actorOf
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
new Actor { def receive = { case _ ⇒ } }
|
||||
new Actor { def receive = { case _ => } }
|
||||
}
|
||||
|
||||
def contextStackMustBeEmpty(): Unit = ActorCell.contextStack.get.headOption should ===(None)
|
||||
|
||||
EventFilter[ActorInitializationException](occurrences = 1) intercept {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
actorOf(Props(new Actor {
|
||||
val nested = promiseIntercept(new Actor { def receive = { case _ ⇒ } })(result)
|
||||
def receive = { case _ ⇒ }
|
||||
val nested = promiseIntercept(new Actor { def receive = { case _ => } })(result)
|
||||
def receive = { case _ => }
|
||||
})))
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
EventFilter[ActorInitializationException](occurrences = 1) intercept {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
actorOf(Props(promiseIntercept(new FailingOuterActor(actorOf(Props(new InnerActor))))(result))))
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
EventFilter[ActorInitializationException](occurrences = 1) intercept {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
actorOf(Props(new OuterActor(actorOf(Props(promiseIntercept(new FailingInnerActor)(result)))))))
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
EventFilter[ActorInitializationException](occurrences = 1) intercept {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
actorOf(Props(promiseIntercept(new FailingInheritingOuterActor(actorOf(Props(new InnerActor))))(result))))
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
EventFilter[ActorInitializationException](occurrences = 2) intercept {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
actorOf(Props(new FailingOuterActor(actorOf(Props(promiseIntercept(new FailingInheritingInnerActor)(result)))))))
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
EventFilter[ActorInitializationException](occurrences = 2) intercept {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
actorOf(Props(new FailingInheritingOuterActor(actorOf(Props(promiseIntercept(new FailingInheritingInnerActor)(result)))))))
|
||||
}
|
||||
|
||||
|
|
@ -198,7 +198,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
EventFilter[ActorInitializationException](occurrences = 2) intercept {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
actorOf(Props(new FailingInheritingOuterActor(actorOf(Props(promiseIntercept(new FailingInnerActor)(result)))))))
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
EventFilter[ActorInitializationException](occurrences = 1) intercept {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
actorOf(Props(new OuterActor(actorOf(Props(new InnerActor {
|
||||
val a = promiseIntercept(new InnerActor)(result)
|
||||
}))))))
|
||||
|
|
@ -218,7 +218,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
EventFilter[ActorInitializationException](occurrences = 2) intercept {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
actorOf(Props(new FailingOuterActor(actorOf(Props(promiseIntercept(new FailingInheritingInnerActor)(result)))))))
|
||||
}
|
||||
|
||||
|
|
@ -227,7 +227,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
EventFilter[ActorInitializationException](occurrences = 1) intercept {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
actorOf(Props(new OuterActor(actorOf(Props(promiseIntercept(new FailingInheritingInnerActor)(result)))))))
|
||||
}
|
||||
|
||||
|
|
@ -236,7 +236,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
EventFilter[ActorInitializationException](occurrences = 1) intercept {
|
||||
intercept[akka.actor.ActorInitializationException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
actorOf(Props(new OuterActor(actorOf(Props(promiseIntercept({ new InnerActor; new InnerActor })(result)))))))
|
||||
}
|
||||
|
||||
|
|
@ -245,7 +245,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
EventFilter[ActorInitializationException](occurrences = 1) intercept {
|
||||
(intercept[java.lang.IllegalStateException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
actorOf(Props(new OuterActor(actorOf(Props(promiseIntercept({ throw new IllegalStateException("Ur state be b0rked"); new InnerActor })(result)))))))
|
||||
}).getMessage should ===("Ur state be b0rked")
|
||||
|
||||
|
|
@ -256,7 +256,7 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
"insert its path in a ActorInitializationException" in {
|
||||
EventFilter[ActorInitializationException](occurrences = 1, pattern = "/user/failingActor:") intercept {
|
||||
intercept[java.lang.IllegalStateException] {
|
||||
wrap(result ⇒
|
||||
wrap(result =>
|
||||
system.actorOf(Props(promiseIntercept({
|
||||
throw new IllegalStateException
|
||||
})(result)), "failingActor"))
|
||||
|
|
@ -344,8 +344,8 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
"support nested actorOfs" in {
|
||||
val a = system.actorOf(Props(new Actor {
|
||||
val nested = system.actorOf(Props(new Actor { def receive = { case _ ⇒ } }))
|
||||
def receive = { case _ ⇒ sender() ! nested }
|
||||
val nested = system.actorOf(Props(new Actor { def receive = { case _ => } }))
|
||||
def receive = { case _ => sender() ! nested }
|
||||
}))
|
||||
|
||||
val nested = Await.result((a ? "any").mapTo[ActorRef], timeout.duration)
|
||||
|
|
@ -401,8 +401,8 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
val timeout = Timeout(20.seconds)
|
||||
val ref = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case 5 ⇒ sender() ! "five"
|
||||
case 0 ⇒ sender() ! "null"
|
||||
case 5 => sender() ! "five"
|
||||
case 0 => sender() ! "null"
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -428,12 +428,12 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
val ref = context.actorOf(
|
||||
Props(new Actor {
|
||||
def receive = { case _ ⇒ }
|
||||
def receive = { case _ => }
|
||||
override def preRestart(reason: Throwable, msg: Option[Any]) = latch.countDown()
|
||||
override def postRestart(reason: Throwable) = latch.countDown()
|
||||
}))
|
||||
|
||||
def receive = { case "sendKill" ⇒ ref ! Kill }
|
||||
def receive = { case "sendKill" => ref ! Kill }
|
||||
}))
|
||||
|
||||
boss ! "sendKill"
|
||||
|
|
@ -446,10 +446,10 @@ class ActorRefSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
val child = context.actorOf(
|
||||
Props(new Actor {
|
||||
def receive = { case _ ⇒ }
|
||||
def receive = { case _ => }
|
||||
}), "child")
|
||||
|
||||
def receive = { case name: String ⇒ sender() ! context.child(name).isDefined }
|
||||
def receive = { case name: String => sender() ! context.child(name).isDefined }
|
||||
}), "parent")
|
||||
|
||||
assert(Await.result((parent ? "child"), timeout.duration) === true)
|
||||
|
|
|
|||
|
|
@ -25,12 +25,12 @@ object ActorSelectionSpec {
|
|||
|
||||
class Node extends Actor {
|
||||
def receive = {
|
||||
case Create(name) ⇒ sender() ! context.actorOf(p, name)
|
||||
case SelectString(path) ⇒ sender() ! context.actorSelection(path)
|
||||
case SelectPath(path) ⇒ sender() ! context.actorSelection(path)
|
||||
case GetSender(ref) ⇒ ref ! sender()
|
||||
case Forward(path, msg) ⇒ context.actorSelection(path).forward(msg)
|
||||
case msg ⇒ sender() ! msg
|
||||
case Create(name) => sender() ! context.actorOf(p, name)
|
||||
case SelectString(path) => sender() ! context.actorSelection(path)
|
||||
case SelectPath(path) => sender() ! context.actorSelection(path)
|
||||
case GetSender(ref) => ref ! sender()
|
||||
case Forward(path, msg) => context.actorSelection(path).forward(msg)
|
||||
case msg => sender() ! msg
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
def empty(path: String) =
|
||||
new EmptyLocalActorRef(sysImpl.provider, path match {
|
||||
case RelativeActorPath(elems) ⇒ sysImpl.lookupRoot.path / elems
|
||||
case RelativeActorPath(elems) => sysImpl.lookupRoot.path / elems
|
||||
}, system.eventStream)
|
||||
|
||||
val idProbe = TestProbe()
|
||||
|
|
@ -59,7 +59,7 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
def identify(selection: ActorSelection): Option[ActorRef] = {
|
||||
selection.tell(Identify(selection), idProbe.ref)
|
||||
val result = idProbe.expectMsgPF() {
|
||||
case ActorIdentity(`selection`, ref) ⇒ ref
|
||||
case ActorIdentity(`selection`, ref) => ref
|
||||
}
|
||||
val asked = Await.result((selection ? Identify(selection)).mapTo[ActorIdentity], timeout.duration)
|
||||
asked.ref should ===(result)
|
||||
|
|
@ -67,7 +67,7 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
implicit val ec = system.dispatcher
|
||||
val resolved = Await.result(
|
||||
selection.resolveOne(timeout.duration).mapTo[ActorRef] recover { case _ ⇒ null },
|
||||
selection.resolveOne(timeout.duration).mapTo[ActorRef] recover { case _ => null },
|
||||
timeout.duration)
|
||||
Option(resolved) should ===(result)
|
||||
|
||||
|
|
@ -79,8 +79,8 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
def askNode(node: ActorRef, query: Query): Option[ActorRef] = {
|
||||
Await.result(node ? query, timeout.duration) match {
|
||||
case ref: ActorRef ⇒ Some(ref)
|
||||
case selection: ActorSelection ⇒ identify(selection)
|
||||
case ref: ActorRef => Some(ref)
|
||||
case selection: ActorSelection => identify(selection)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -188,8 +188,8 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
askNode(looker, SelectPath(pathOf.path)) should ===(Some(result))
|
||||
}
|
||||
for {
|
||||
looker ← all
|
||||
target ← all
|
||||
looker <- all
|
||||
target <- all
|
||||
} check(looker, target, target)
|
||||
}
|
||||
|
||||
|
|
@ -200,8 +200,8 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
askNode(looker, SelectString(pathOf.path.toStringWithoutAddress + "/")) should ===(Some(result))
|
||||
}
|
||||
for {
|
||||
looker ← all
|
||||
target ← all
|
||||
looker <- all
|
||||
target <- all
|
||||
} check(looker, target, target)
|
||||
}
|
||||
|
||||
|
|
@ -211,8 +211,8 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
askNode(looker, SelectString(pathOf.path.elements.mkString("/", "/", "/"))) should ===(Some(result))
|
||||
}
|
||||
for {
|
||||
looker ← all
|
||||
target ← all
|
||||
looker <- all
|
||||
target <- all
|
||||
} check(looker, target, target)
|
||||
}
|
||||
|
||||
|
|
@ -223,8 +223,8 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
}
|
||||
check(c1, user, "..")
|
||||
for {
|
||||
looker ← Seq(c1, c2)
|
||||
target ← all
|
||||
looker <- Seq(c1, c2)
|
||||
target <- all
|
||||
} check(looker, target, Seq("..") ++ target.path.elements.drop(1): _*)
|
||||
check(c21, user, "..", "..")
|
||||
check(c21, root, "..", "..", "..")
|
||||
|
|
@ -233,7 +233,7 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
"find system-generated actors" in {
|
||||
def check(target: ActorRef): Unit = {
|
||||
for (looker ← all) {
|
||||
for (looker <- all) {
|
||||
askNode(looker, SelectPath(target.path)) should ===(Some(target))
|
||||
askNode(looker, SelectString(target.path.toString)) should ===(Some(target))
|
||||
askNode(looker, SelectString(target.path.toString + "/")) should ===(Some(target))
|
||||
|
|
@ -241,7 +241,7 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
if (target != root)
|
||||
askNode(c1, SelectString("../.." + target.path.elements.mkString("/", "/", "/"))) should ===(Some(target))
|
||||
}
|
||||
for (target ← Seq(root, syst, user)) check(target)
|
||||
for (target <- Seq(root, syst, user)) check(target)
|
||||
}
|
||||
|
||||
"return deadLetters or ActorIdentity(None), respectively, for non-existing paths" in {
|
||||
|
|
@ -254,15 +254,15 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
def check(looker: ActorRef): Unit = {
|
||||
val lookname = looker.path.elements.mkString("", "/", "/")
|
||||
for (
|
||||
(l, r) ← Seq(
|
||||
SelectString("a/b/c") → None,
|
||||
SelectString("akka://all-systems/Nobody") → None,
|
||||
SelectPath(system / "hallo") → None,
|
||||
SelectPath(looker.path child "hallo") → None, // test Java API
|
||||
SelectPath(looker.path descendant Seq("a", "b").asJava) → None) // test Java API
|
||||
(l, r) <- Seq(
|
||||
SelectString("a/b/c") -> None,
|
||||
SelectString("akka://all-systems/Nobody") -> None,
|
||||
SelectPath(system / "hallo") -> None,
|
||||
SelectPath(looker.path child "hallo") -> None, // test Java API
|
||||
SelectPath(looker.path descendant Seq("a", "b").asJava) -> None) // test Java API
|
||||
) checkOne(looker, l, r)
|
||||
}
|
||||
for (looker ← all) check(looker)
|
||||
for (looker <- all) check(looker)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -291,7 +291,7 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
implicit val sender = c1
|
||||
ActorSelection(c21, "../../*") ! GetSender(testActor)
|
||||
val actors = Set() ++ receiveWhile(messages = 2) {
|
||||
case `c1` ⇒ lastSender
|
||||
case `c1` => lastSender
|
||||
}
|
||||
actors should ===(Set(c1, c2))
|
||||
expectNoMsg(1 second)
|
||||
|
|
@ -301,7 +301,7 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
implicit val sender = c2
|
||||
ActorSelection(c21, "../../*/c21") ! GetSender(testActor)
|
||||
val actors = receiveWhile(messages = 2) {
|
||||
case `c2` ⇒ lastSender
|
||||
case `c2` => lastSender
|
||||
}
|
||||
actors should ===(Seq(c21))
|
||||
expectNoMsg(200.millis)
|
||||
|
|
@ -368,7 +368,7 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
val probe = TestProbe()
|
||||
system.actorSelection("/user/a/*").tell(Identify(1), probe.ref)
|
||||
probe.receiveN(2).map { case ActorIdentity(1, r) ⇒ r }.toSet should ===(Set[Option[ActorRef]](Some(b1), Some(b2)))
|
||||
probe.receiveN(2).map { case ActorIdentity(1, r) => r }.toSet should ===(Set[Option[ActorRef]](Some(b1), Some(b2)))
|
||||
probe.expectNoMsg(200.millis)
|
||||
|
||||
system.actorSelection("/user/a/b1/*").tell(Identify(2), probe.ref)
|
||||
|
|
|
|||
|
|
@ -27,14 +27,14 @@ object ActorSystemSpec {
|
|||
var terminaters = Set[ActorRef]()
|
||||
|
||||
def receive = {
|
||||
case n: Int ⇒
|
||||
case n: Int =>
|
||||
master = sender()
|
||||
terminaters = Set() ++ (for (i ← 1 to n) yield {
|
||||
terminaters = Set() ++ (for (i <- 1 to n) yield {
|
||||
val man = context.watch(context.system.actorOf(Props[Terminater]))
|
||||
man ! "run"
|
||||
man
|
||||
})
|
||||
case Terminated(child) if terminaters contains child ⇒
|
||||
case Terminated(child) if terminaters contains child =>
|
||||
terminaters -= child
|
||||
if (terminaters.isEmpty) {
|
||||
master ! "done"
|
||||
|
|
@ -52,13 +52,13 @@ object ActorSystemSpec {
|
|||
|
||||
class Terminater extends Actor {
|
||||
def receive = {
|
||||
case "run" ⇒ context.stop(self)
|
||||
case "run" => context.stop(self)
|
||||
}
|
||||
}
|
||||
|
||||
class Strategy extends SupervisorStrategyConfigurator {
|
||||
def create() = OneForOneStrategy() {
|
||||
case _ ⇒ SupervisorStrategy.Escalate
|
||||
case _ => SupervisorStrategy.Escalate
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ object ActorSystemSpec {
|
|||
latch.countDown()
|
||||
|
||||
def receive = {
|
||||
case _ ⇒
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ object ActorSystemSpec {
|
|||
doneIt.switchOn {
|
||||
TestKit.awaitCond(mbox.actor.actor != null, 1.second)
|
||||
mbox.actor.actor match {
|
||||
case FastActor(latch, _) ⇒ Await.ready(latch, 1.second)
|
||||
case FastActor(latch, _) => Await.ready(latch, 1.second)
|
||||
}
|
||||
}
|
||||
ret
|
||||
|
|
@ -132,7 +132,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
|
||||
"reject invalid names" in {
|
||||
for (
|
||||
n ← Seq(
|
||||
n <- Seq(
|
||||
"-hallowelt",
|
||||
"_hallowelt",
|
||||
"hallo*welt",
|
||||
|
|
@ -190,7 +190,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
val count = 10
|
||||
val latch = TestLatch(count)
|
||||
|
||||
for (i ← 1 to count) {
|
||||
for (i <- 1 to count) {
|
||||
system2.registerOnTermination {
|
||||
Thread.sleep((i % 3).millis.dilated.toMillis)
|
||||
result add i
|
||||
|
|
@ -201,7 +201,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
system2.terminate()
|
||||
Await.ready(latch, 5 seconds)
|
||||
|
||||
val expected = (for (i ← 1 to count) yield i).reverse
|
||||
val expected = (for (i <- 1 to count) yield i).reverse
|
||||
|
||||
immutableSeq(result) should ===(expected)
|
||||
}
|
||||
|
|
@ -253,7 +253,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
system2.terminate()
|
||||
system2.registerOnTermination { count.incrementAndGet() }
|
||||
} catch {
|
||||
case _: RejectedExecutionException ⇒ count.incrementAndGet()
|
||||
case _: RejectedExecutionException => count.incrementAndGet()
|
||||
}
|
||||
|
||||
Await.ready(system2.whenTerminated, 10.seconds)
|
||||
|
|
@ -263,7 +263,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
"reliably create waves of actors" in {
|
||||
import system.dispatcher
|
||||
implicit val timeout = Timeout((20 seconds).dilated)
|
||||
val waves = for (i ← 1 to 3) yield system.actorOf(Props[ActorSystemSpec.Waves]) ? 50000
|
||||
val waves = for (i <- 1 to 3) yield system.actorOf(Props[ActorSystemSpec.Waves]) ? 50000
|
||||
Await.result(Future.sequence(waves), timeout.duration + 5.seconds) should ===(Vector("done", "done", "done"))
|
||||
}
|
||||
|
||||
|
|
@ -285,7 +285,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
created :+= t
|
||||
if (created.size % 1000 == 0) Thread.sleep(50) // in case of unfair thread scheduling
|
||||
} catch {
|
||||
case _: IllegalStateException ⇒ failing = true
|
||||
case _: IllegalStateException => failing = true
|
||||
}
|
||||
|
||||
if (!failing && system.uptime >= 10) {
|
||||
|
|
@ -295,7 +295,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
}
|
||||
}
|
||||
|
||||
created filter (ref ⇒ !ref.isTerminated && !ref.asInstanceOf[ActorRefWithCell].underlying.isInstanceOf[UnstartedCell]) should ===(Seq.empty[ActorRef])
|
||||
created filter (ref => !ref.isTerminated && !ref.asInstanceOf[ActorRefWithCell].underlying.isInstanceOf[UnstartedCell]) should ===(Seq.empty[ActorRef])
|
||||
}
|
||||
|
||||
"shut down when /user fails" in {
|
||||
|
|
@ -313,7 +313,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
.withFallback(AkkaSpec.testConf))
|
||||
val a = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "die" ⇒ throw new Exception("hello")
|
||||
case "die" => throw new Exception("hello")
|
||||
}
|
||||
}))
|
||||
val probe = TestProbe()
|
||||
|
|
@ -334,7 +334,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
.withFallback(AkkaSpec.testConf))
|
||||
val a = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "die" ⇒ throw new Exception("hello")
|
||||
case "die" => throw new Exception("hello")
|
||||
}
|
||||
}))
|
||||
EventFilter[Exception]("hello") intercept {
|
||||
|
|
@ -352,7 +352,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
try {
|
||||
val ref = system2.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "ping" ⇒ sender() ! "pong"
|
||||
case "ping" => sender() ! "pong"
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
|
|||
|
|
@ -19,18 +19,18 @@ object ActorWithBoundedStashSpec {
|
|||
|
||||
class StashingActor extends Actor with Stash {
|
||||
def receive = {
|
||||
case msg: String if msg.startsWith("hello") ⇒
|
||||
case msg: String if msg.startsWith("hello") =>
|
||||
stash()
|
||||
sender() ! "ok"
|
||||
|
||||
case "world" ⇒
|
||||
case "world" =>
|
||||
context.become(afterWorldBehavior)
|
||||
unstashAll()
|
||||
|
||||
}
|
||||
|
||||
def afterWorldBehavior: Receive = {
|
||||
case _ ⇒ stash()
|
||||
case _ => stash()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,10 +38,10 @@ object ActorWithBoundedStashSpec {
|
|||
var numStashed = 0
|
||||
|
||||
def receive = {
|
||||
case msg: String if msg.startsWith("hello") ⇒
|
||||
case msg: String if msg.startsWith("hello") =>
|
||||
numStashed += 1
|
||||
try { stash(); sender() ! "ok" } catch {
|
||||
case _: StashOverflowException ⇒
|
||||
case _: StashOverflowException =>
|
||||
if (numStashed == 21) {
|
||||
sender() ! "STASHOVERFLOW"
|
||||
context stop self
|
||||
|
|
@ -97,7 +97,7 @@ class ActorWithBoundedStashSpec extends AkkaSpec(ActorWithBoundedStashSpec.testC
|
|||
|
||||
def testDeadLetters(stasher: ActorRef): Unit = {
|
||||
// fill up stash
|
||||
for (n ← 1 to 11) {
|
||||
for (n <- 1 to 11) {
|
||||
stasher ! "hello" + n
|
||||
expectMsg("ok")
|
||||
}
|
||||
|
|
@ -108,12 +108,12 @@ class ActorWithBoundedStashSpec extends AkkaSpec(ActorWithBoundedStashSpec.testC
|
|||
|
||||
stasher ! PoisonPill
|
||||
// stashed messages are sent to deadletters when stasher is stopped
|
||||
for (n ← 2 to 11) expectMsg(DeadLetter("hello" + n, testActor, stasher))
|
||||
for (n <- 2 to 11) expectMsg(DeadLetter("hello" + n, testActor, stasher))
|
||||
}
|
||||
|
||||
def testStashOverflowException(stasher: ActorRef): Unit = {
|
||||
// fill up stash
|
||||
for (n ← 1 to 20) {
|
||||
for (n <- 1 to 20) {
|
||||
stasher ! "hello" + n
|
||||
expectMsg("ok")
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ class ActorWithBoundedStashSpec extends AkkaSpec(ActorWithBoundedStashSpec.testC
|
|||
expectMsg("STASHOVERFLOW")
|
||||
|
||||
// stashed messages are sent to deadletters when stasher is stopped,
|
||||
for (n ← 1 to 20) expectMsg(DeadLetter("hello" + n, testActor, stasher))
|
||||
for (n <- 1 to 20) expectMsg(DeadLetter("hello" + n, testActor, stasher))
|
||||
}
|
||||
|
||||
"An Actor with Stash" must {
|
||||
|
|
|
|||
|
|
@ -20,49 +20,49 @@ object ActorWithStashSpec {
|
|||
class StashingActor extends Actor with Stash {
|
||||
import context.system
|
||||
def greeted: Receive = {
|
||||
case "bye" ⇒
|
||||
case "bye" =>
|
||||
state.s = "bye"
|
||||
state.finished.await
|
||||
case _ ⇒ // do nothing
|
||||
case _ => // do nothing
|
||||
}
|
||||
|
||||
def receive = {
|
||||
case "hello" ⇒
|
||||
case "hello" =>
|
||||
state.s = "hello"
|
||||
unstashAll()
|
||||
context.become(greeted)
|
||||
case msg ⇒ stash()
|
||||
case msg => stash()
|
||||
}
|
||||
}
|
||||
|
||||
class StashingTwiceActor extends Actor with Stash {
|
||||
def receive = {
|
||||
case "hello" ⇒
|
||||
case "hello" =>
|
||||
try {
|
||||
stash()
|
||||
stash()
|
||||
} catch {
|
||||
case e: IllegalStateException ⇒
|
||||
case e: IllegalStateException =>
|
||||
state.expectedException.open()
|
||||
}
|
||||
case msg ⇒ // do nothing
|
||||
case msg => // do nothing
|
||||
}
|
||||
}
|
||||
|
||||
class ActorWithProtocol extends Actor with Stash {
|
||||
import context.system
|
||||
def receive = {
|
||||
case "open" ⇒
|
||||
case "open" =>
|
||||
unstashAll()
|
||||
context.become {
|
||||
case "write" ⇒ // do writing...
|
||||
case "close" ⇒
|
||||
case "write" => // do writing...
|
||||
case "close" =>
|
||||
unstashAll()
|
||||
context.unbecome()
|
||||
case msg ⇒ stash()
|
||||
case msg => stash()
|
||||
}
|
||||
case "done" ⇒ state.finished.await
|
||||
case msg ⇒ stash()
|
||||
case "done" => state.finished.await
|
||||
case msg => stash()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ object ActorWithStashSpec {
|
|||
context.stop(watched)
|
||||
|
||||
def receive = {
|
||||
case Terminated(`watched`) ⇒
|
||||
case Terminated(`watched`) =>
|
||||
if (!stashed) {
|
||||
stash()
|
||||
stashed = true
|
||||
|
|
@ -150,15 +150,15 @@ class ActorWithStashSpec extends AkkaSpec(ActorWithStashSpec.testConf) with Defa
|
|||
|
||||
val slaveProps = Props(new Actor with Stash {
|
||||
def receive = {
|
||||
case "crash" ⇒
|
||||
case "crash" =>
|
||||
throw new Exception("Crashing...")
|
||||
|
||||
// when restartLatch is not yet open, stash all messages != "crash"
|
||||
case msg if !restartLatch.isOpen ⇒
|
||||
case msg if !restartLatch.isOpen =>
|
||||
stash()
|
||||
|
||||
// when restartLatch is open, must receive "hello"
|
||||
case "hello" ⇒
|
||||
case "hello" =>
|
||||
hasMsgLatch.open()
|
||||
}
|
||||
|
||||
|
|
@ -190,9 +190,9 @@ class ActorWithStashSpec extends AkkaSpec(ActorWithStashSpec.testConf) with Defa
|
|||
import ActorDSL._
|
||||
val a = actor(new ActWithStash {
|
||||
become {
|
||||
case "die" ⇒ throw new RuntimeException("dying")
|
||||
case "die" => throw new RuntimeException("dying")
|
||||
}
|
||||
whenRestarted { thr ⇒
|
||||
whenRestarted { thr =>
|
||||
testActor ! "restarted"
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -30,42 +30,42 @@ object Chameneos {
|
|||
mall ! Meet(self, colour)
|
||||
|
||||
def receive = {
|
||||
case Meet(from, otherColour) ⇒
|
||||
case Meet(from, otherColour) =>
|
||||
colour = complement(otherColour)
|
||||
meetings = meetings + 1
|
||||
from ! Change(colour)
|
||||
mall ! Meet(self, colour)
|
||||
|
||||
case Change(newColour) ⇒
|
||||
case Change(newColour) =>
|
||||
colour = newColour
|
||||
meetings = meetings + 1
|
||||
mall ! Meet(self, colour)
|
||||
|
||||
case Exit ⇒
|
||||
case Exit =>
|
||||
colour = FADED
|
||||
sender() ! MeetingCount(meetings)
|
||||
}
|
||||
|
||||
def complement(otherColour: Colour): Colour = colour match {
|
||||
case RED ⇒ otherColour match {
|
||||
case RED ⇒ RED
|
||||
case YELLOW ⇒ BLUE
|
||||
case BLUE ⇒ YELLOW
|
||||
case FADED ⇒ FADED
|
||||
case RED => otherColour match {
|
||||
case RED => RED
|
||||
case YELLOW => BLUE
|
||||
case BLUE => YELLOW
|
||||
case FADED => FADED
|
||||
}
|
||||
case YELLOW ⇒ otherColour match {
|
||||
case RED ⇒ BLUE
|
||||
case YELLOW ⇒ YELLOW
|
||||
case BLUE ⇒ RED
|
||||
case FADED ⇒ FADED
|
||||
case YELLOW => otherColour match {
|
||||
case RED => BLUE
|
||||
case YELLOW => YELLOW
|
||||
case BLUE => RED
|
||||
case FADED => FADED
|
||||
}
|
||||
case BLUE ⇒ otherColour match {
|
||||
case RED ⇒ YELLOW
|
||||
case YELLOW ⇒ RED
|
||||
case BLUE ⇒ BLUE
|
||||
case FADED ⇒ FADED
|
||||
case BLUE => otherColour match {
|
||||
case RED => YELLOW
|
||||
case YELLOW => RED
|
||||
case BLUE => BLUE
|
||||
case FADED => FADED
|
||||
}
|
||||
case FADED ⇒ FADED
|
||||
case FADED => FADED
|
||||
}
|
||||
|
||||
override def toString = cid + "(" + colour + ")"
|
||||
|
|
@ -77,11 +77,11 @@ object Chameneos {
|
|||
var numFaded = 0
|
||||
|
||||
override def preStart() = {
|
||||
for (i ← 0 until numChameneos) context.actorOf(Props(new Chameneo(self, colours(i % 3), i)))
|
||||
for (i <- 0 until numChameneos) context.actorOf(Props(new Chameneo(self, colours(i % 3), i)))
|
||||
}
|
||||
|
||||
def receive = {
|
||||
case MeetingCount(i) ⇒
|
||||
case MeetingCount(i) =>
|
||||
numFaded += 1
|
||||
sumMeetings += i
|
||||
if (numFaded == numChameneos) {
|
||||
|
|
@ -89,14 +89,14 @@ object Chameneos {
|
|||
context.stop(self)
|
||||
}
|
||||
|
||||
case msg @ Meet(a, c) ⇒
|
||||
case msg @ Meet(a, c) =>
|
||||
if (n > 0) {
|
||||
waitingChameneo match {
|
||||
case Some(chameneo) ⇒
|
||||
case Some(chameneo) =>
|
||||
n -= 1
|
||||
chameneo ! msg
|
||||
waitingChameneo = None
|
||||
case None ⇒ waitingChameneo = Some(sender())
|
||||
case None => waitingChameneo = Some(sender())
|
||||
}
|
||||
} else {
|
||||
waitingChameneo.foreach(_ ! Exit)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ object ConsistencySpec {
|
|||
var right = new CacheMisaligned(0, 0, 0, 0) //var
|
||||
var lastStep = -1L
|
||||
def receive = {
|
||||
case step: Long ⇒
|
||||
case step: Long =>
|
||||
|
||||
if (lastStep != (step - 1))
|
||||
sender() ! "Test failed: Last step %s, this step %s".format(lastStep, step)
|
||||
|
|
@ -48,7 +48,7 @@ object ConsistencySpec {
|
|||
}
|
||||
|
||||
lastStep = step
|
||||
case "done" ⇒ sender() ! "done"; context.stop(self)
|
||||
case "done" => sender() ! "done"; context.stop(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -64,13 +64,13 @@ class ConsistencySpec extends AkkaSpec(ConsistencySpec.config) {
|
|||
val props = Props[ConsistencyCheckingActor].withDispatcher("consistency-dispatcher")
|
||||
val actors = Vector.fill(noOfActors)(system.actorOf(props))
|
||||
|
||||
for (i ← 0L until 10000L) {
|
||||
for (i <- 0L until 10000L) {
|
||||
actors.foreach(_.tell(i, testActor))
|
||||
}
|
||||
|
||||
for (a ← actors) { a.tell("done", testActor) }
|
||||
for (a <- actors) { a.tell("done", testActor) }
|
||||
|
||||
for (a ← actors) expectMsg(5 minutes, "done")
|
||||
for (a <- actors) expectMsg(5 minutes, "done")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,15 +34,15 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
private def checkTopologicalSort(phases: Map[String, Phase]): List[String] = {
|
||||
val result = CoordinatedShutdown.topologicalSort(phases)
|
||||
result.zipWithIndex.foreach {
|
||||
case (phase, i) ⇒
|
||||
case (phase, i) =>
|
||||
phases.get(phase) match {
|
||||
case Some(Phase(dependsOn, _, _, _)) ⇒
|
||||
dependsOn.foreach { depPhase ⇒
|
||||
case Some(Phase(dependsOn, _, _, _)) =>
|
||||
dependsOn.foreach { depPhase =>
|
||||
withClue(s"phase [$phase] depends on [$depPhase] but was ordered before it in topological sort result $result") {
|
||||
i should be > result.indexOf(depPhase)
|
||||
}
|
||||
}
|
||||
case None ⇒ // ok
|
||||
case None => // ok
|
||||
}
|
||||
}
|
||||
result
|
||||
|
|
@ -56,37 +56,37 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
checkTopologicalSort(Map.empty) should ===(Nil)
|
||||
|
||||
checkTopologicalSort(Map(
|
||||
"a" → emptyPhase)) should ===(List("a"))
|
||||
"a" -> emptyPhase)) should ===(List("a"))
|
||||
|
||||
checkTopologicalSort(Map(
|
||||
"b" → phase("a"))) should ===(List("a", "b"))
|
||||
"b" -> phase("a"))) should ===(List("a", "b"))
|
||||
|
||||
val result1 = checkTopologicalSort(Map(
|
||||
"c" → phase("a"), "b" → phase("a")))
|
||||
"c" -> phase("a"), "b" -> phase("a")))
|
||||
result1.head should ===("a")
|
||||
// b, c can be in any order
|
||||
result1.toSet should ===(Set("a", "b", "c"))
|
||||
|
||||
checkTopologicalSort(Map(
|
||||
"b" → phase("a"), "c" → phase("b"))) should ===(List("a", "b", "c"))
|
||||
"b" -> phase("a"), "c" -> phase("b"))) should ===(List("a", "b", "c"))
|
||||
|
||||
checkTopologicalSort(Map(
|
||||
"b" → phase("a"), "c" → phase("a", "b"))) should ===(List("a", "b", "c"))
|
||||
"b" -> phase("a"), "c" -> phase("a", "b"))) should ===(List("a", "b", "c"))
|
||||
|
||||
val result2 = checkTopologicalSort(Map(
|
||||
"c" → phase("a", "b")))
|
||||
"c" -> phase("a", "b")))
|
||||
result2.last should ===("c")
|
||||
// a, b can be in any order
|
||||
result2.toSet should ===(Set("a", "b", "c"))
|
||||
|
||||
checkTopologicalSort(Map(
|
||||
"b" → phase("a"), "c" → phase("b"), "d" → phase("b", "c"),
|
||||
"e" → phase("d"))) should ===(
|
||||
"b" -> phase("a"), "c" -> phase("b"), "d" -> phase("b", "c"),
|
||||
"e" -> phase("d"))) should ===(
|
||||
List("a", "b", "c", "d", "e"))
|
||||
|
||||
val result3 = checkTopologicalSort(Map(
|
||||
"a2" → phase("a1"), "a3" → phase("a2"),
|
||||
"b2" → phase("b1"), "b3" → phase("b2")))
|
||||
"a2" -> phase("a1"), "a3" -> phase("a2"),
|
||||
"b2" -> phase("b1"), "b3" -> phase("b2")))
|
||||
val (a, b) = result3.partition(_.charAt(0) == 'a')
|
||||
a should ===(List("a1", "a2", "a3"))
|
||||
b should ===(List("b1", "b2", "b3"))
|
||||
|
|
@ -95,22 +95,22 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
"detect cycles in phases (non-DAG)" in {
|
||||
intercept[IllegalArgumentException] {
|
||||
CoordinatedShutdown.topologicalSort(Map(
|
||||
"a" → phase("a")))
|
||||
"a" -> phase("a")))
|
||||
}
|
||||
|
||||
intercept[IllegalArgumentException] {
|
||||
CoordinatedShutdown.topologicalSort(Map(
|
||||
"b" → phase("a"), "a" → phase("b")))
|
||||
"b" -> phase("a"), "a" -> phase("b")))
|
||||
}
|
||||
|
||||
intercept[IllegalArgumentException] {
|
||||
CoordinatedShutdown.topologicalSort(Map(
|
||||
"c" → phase("a"), "c" → phase("b"), "b" → phase("c")))
|
||||
"c" -> phase("a"), "c" -> phase("b"), "b" -> phase("c")))
|
||||
}
|
||||
|
||||
intercept[IllegalArgumentException] {
|
||||
CoordinatedShutdown.topologicalSort(Map(
|
||||
"d" → phase("a"), "d" → phase("c"), "c" → phase("b"), "b" → phase("d")))
|
||||
"d" -> phase("a"), "d" -> phase("c"), "c" -> phase("b"), "b" -> phase("d")))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -135,19 +135,19 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
"run ordered phases" in {
|
||||
import system.dispatcher
|
||||
val phases = Map(
|
||||
"a" → emptyPhase,
|
||||
"b" → phase("a"),
|
||||
"c" → phase("b", "a"))
|
||||
"a" -> emptyPhase,
|
||||
"b" -> phase("a"),
|
||||
"c" -> phase("b", "a"))
|
||||
val co = new CoordinatedShutdown(extSys, phases)
|
||||
co.addTask("a", "a1") { () ⇒
|
||||
co.addTask("a", "a1") { () =>
|
||||
testActor ! "A"
|
||||
Future.successful(Done)
|
||||
}
|
||||
co.addTask("b", "b1") { () ⇒
|
||||
co.addTask("b", "b1") { () =>
|
||||
testActor ! "B"
|
||||
Future.successful(Done)
|
||||
}
|
||||
co.addTask("b", "b2") { () ⇒
|
||||
co.addTask("b", "b2") { () =>
|
||||
Future {
|
||||
// to verify that c is not performed before b
|
||||
Thread.sleep(100)
|
||||
|
|
@ -155,7 +155,7 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
Done
|
||||
}
|
||||
}
|
||||
co.addTask("c", "c1") { () ⇒
|
||||
co.addTask("c", "c1") { () =>
|
||||
testActor ! "C"
|
||||
Future.successful(Done)
|
||||
}
|
||||
|
|
@ -165,19 +165,19 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
|
||||
"run from a given phase" in {
|
||||
val phases = Map(
|
||||
"a" → emptyPhase,
|
||||
"b" → phase("a"),
|
||||
"c" → phase("b", "a"))
|
||||
"a" -> emptyPhase,
|
||||
"b" -> phase("a"),
|
||||
"c" -> phase("b", "a"))
|
||||
val co = new CoordinatedShutdown(extSys, phases)
|
||||
co.addTask("a", "a1") { () ⇒
|
||||
co.addTask("a", "a1") { () =>
|
||||
testActor ! "A"
|
||||
Future.successful(Done)
|
||||
}
|
||||
co.addTask("b", "b1") { () ⇒
|
||||
co.addTask("b", "b1") { () =>
|
||||
testActor ! "B"
|
||||
Future.successful(Done)
|
||||
}
|
||||
co.addTask("c", "c1") { () ⇒
|
||||
co.addTask("c", "c1") { () =>
|
||||
testActor ! "C"
|
||||
Future.successful(Done)
|
||||
}
|
||||
|
|
@ -187,9 +187,9 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
}
|
||||
|
||||
"only run once" in {
|
||||
val phases = Map("a" → emptyPhase)
|
||||
val phases = Map("a" -> emptyPhase)
|
||||
val co = new CoordinatedShutdown(extSys, phases)
|
||||
co.addTask("a", "a1") { () ⇒
|
||||
co.addTask("a", "a1") { () =>
|
||||
testActor ! "A"
|
||||
Future.successful(Done)
|
||||
}
|
||||
|
|
@ -206,15 +206,15 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
"continue after timeout or failure" in {
|
||||
import system.dispatcher
|
||||
val phases = Map(
|
||||
"a" → emptyPhase,
|
||||
"b" → Phase(dependsOn = Set("a"), timeout = 100.millis, recover = true, enabled = true),
|
||||
"c" → phase("b", "a"))
|
||||
"a" -> emptyPhase,
|
||||
"b" -> Phase(dependsOn = Set("a"), timeout = 100.millis, recover = true, enabled = true),
|
||||
"c" -> phase("b", "a"))
|
||||
val co = new CoordinatedShutdown(extSys, phases)
|
||||
co.addTask("a", "a1") { () ⇒
|
||||
co.addTask("a", "a1") { () =>
|
||||
testActor ! "A"
|
||||
Future.failed(new RuntimeException("boom"))
|
||||
}
|
||||
co.addTask("a", "a2") { () ⇒
|
||||
co.addTask("a", "a2") { () =>
|
||||
Future {
|
||||
// to verify that b is not performed before a also in case of failure
|
||||
Thread.sleep(100)
|
||||
|
|
@ -222,11 +222,11 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
Done
|
||||
}
|
||||
}
|
||||
co.addTask("b", "b1") { () ⇒
|
||||
co.addTask("b", "b1") { () =>
|
||||
testActor ! "B"
|
||||
Promise[Done]().future // never completed
|
||||
}
|
||||
co.addTask("c", "c1") { () ⇒
|
||||
co.addTask("c", "c1") { () =>
|
||||
testActor ! "C"
|
||||
Future.successful(Done)
|
||||
}
|
||||
|
|
@ -243,15 +243,15 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
|
||||
"abort if recover=off" in {
|
||||
val phases = Map(
|
||||
"a" → emptyPhase,
|
||||
"b" → Phase(dependsOn = Set("a"), timeout = 100.millis, recover = false, enabled = true),
|
||||
"c" → phase("b", "a"))
|
||||
"a" -> emptyPhase,
|
||||
"b" -> Phase(dependsOn = Set("a"), timeout = 100.millis, recover = false, enabled = true),
|
||||
"c" -> phase("b", "a"))
|
||||
val co = new CoordinatedShutdown(extSys, phases)
|
||||
co.addTask("b", "b1") { () ⇒
|
||||
co.addTask("b", "b1") { () =>
|
||||
testActor ! "B"
|
||||
Promise[Done]().future // never completed
|
||||
}
|
||||
co.addTask("c", "c1") { () ⇒
|
||||
co.addTask("c", "c1") { () =>
|
||||
testActor ! "C"
|
||||
Future.successful(Done)
|
||||
}
|
||||
|
|
@ -265,15 +265,15 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
|
||||
"skip tasks in disabled phase" in {
|
||||
val phases = Map(
|
||||
"a" → emptyPhase,
|
||||
"b" → Phase(dependsOn = Set("a"), timeout = 100.millis, recover = false, enabled = false),
|
||||
"c" → phase("b", "a"))
|
||||
"a" -> emptyPhase,
|
||||
"b" -> Phase(dependsOn = Set("a"), timeout = 100.millis, recover = false, enabled = false),
|
||||
"c" -> phase("b", "a"))
|
||||
val co = new CoordinatedShutdown(extSys, phases)
|
||||
co.addTask("b", "b1") { () ⇒
|
||||
co.addTask("b", "b1") { () =>
|
||||
testActor ! "B"
|
||||
Future.failed(new RuntimeException("Was expected to not be executed"))
|
||||
}
|
||||
co.addTask("c", "c1") { () ⇒
|
||||
co.addTask("c", "c1") { () =>
|
||||
testActor ! "C"
|
||||
Future.successful(Done)
|
||||
}
|
||||
|
|
@ -286,12 +286,12 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
|
||||
"be possible to add tasks in later phase from task in earlier phase" in {
|
||||
val phases = Map(
|
||||
"a" → emptyPhase,
|
||||
"b" → phase("a"))
|
||||
"a" -> emptyPhase,
|
||||
"b" -> phase("a"))
|
||||
val co = new CoordinatedShutdown(extSys, phases)
|
||||
co.addTask("a", "a1") { () ⇒
|
||||
co.addTask("a", "a1") { () =>
|
||||
testActor ! "A"
|
||||
co.addTask("b", "b1") { () ⇒
|
||||
co.addTask("b", "b1") { () =>
|
||||
testActor ! "B"
|
||||
Future.successful(Done)
|
||||
}
|
||||
|
|
@ -318,9 +318,9 @@ class CoordinatedShutdownSpec extends AkkaSpec(ConfigFactory.parseString(
|
|||
}
|
||||
}
|
||||
""")) should ===(Map(
|
||||
"a" → Phase(dependsOn = Set.empty, timeout = 10.seconds, recover = true, enabled = true),
|
||||
"b" → Phase(dependsOn = Set("a"), timeout = 15.seconds, recover = true, enabled = true),
|
||||
"c" → Phase(dependsOn = Set("a", "b"), timeout = 10.seconds, recover = false, enabled = true)))
|
||||
"a" -> Phase(dependsOn = Set.empty, timeout = 10.seconds, recover = true, enabled = true),
|
||||
"b" -> Phase(dependsOn = Set("a"), timeout = 15.seconds, recover = true, enabled = true),
|
||||
"c" -> Phase(dependsOn = Set("a", "b"), timeout = 10.seconds, recover = false, enabled = true)))
|
||||
}
|
||||
|
||||
"default exit code to 0" in {
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ object DeathWatchSpec {
|
|||
class Watcher(target: ActorRef, testActor: ActorRef) extends Actor {
|
||||
context.watch(target)
|
||||
def receive = {
|
||||
case t: Terminated ⇒ testActor forward WrappedTerminated(t)
|
||||
case x ⇒ testActor forward x
|
||||
case t: Terminated => testActor forward WrappedTerminated(t)
|
||||
case x => testActor forward x
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -35,11 +35,11 @@ object DeathWatchSpec {
|
|||
|
||||
class NKOTBWatcher(testActor: ActorRef) extends Actor {
|
||||
def receive = {
|
||||
case "NKOTB" ⇒
|
||||
val currentKid = context.watch(context.actorOf(Props(new Actor { def receive = { case "NKOTB" ⇒ context stop self } }), "kid"))
|
||||
case "NKOTB" =>
|
||||
val currentKid = context.watch(context.actorOf(Props(new Actor { def receive = { case "NKOTB" => context stop self } }), "kid"))
|
||||
currentKid forward "NKOTB"
|
||||
context become {
|
||||
case Terminated(`currentKid`) ⇒
|
||||
case Terminated(`currentKid`) =>
|
||||
testActor ! "GREEN"
|
||||
context unbecome
|
||||
}
|
||||
|
|
@ -48,9 +48,9 @@ object DeathWatchSpec {
|
|||
|
||||
class WUWatcher extends Actor {
|
||||
def receive = {
|
||||
case W(ref) ⇒ context watch ref
|
||||
case U(ref) ⇒ context unwatch ref
|
||||
case Latches(t1: TestLatch, t2: TestLatch) ⇒
|
||||
case W(ref) => context watch ref
|
||||
case U(ref) => context unwatch ref
|
||||
case Latches(t1: TestLatch, t2: TestLatch) =>
|
||||
t1.countDown()
|
||||
Await.ready(t2, 3.seconds)
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ object DeathWatchSpec {
|
|||
final case class Latches(t1: TestLatch, t2: TestLatch) extends NoSerializationVerificationNeeded
|
||||
}
|
||||
|
||||
trait DeathWatchSpec { this: AkkaSpec with ImplicitSender with DefaultTimeout ⇒
|
||||
trait DeathWatchSpec { this: AkkaSpec with ImplicitSender with DefaultTimeout =>
|
||||
|
||||
import DeathWatchSpec._
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ trait DeathWatchSpec { this: AkkaSpec with ImplicitSender with DefaultTimeout
|
|||
|
||||
"The Death Watch" must {
|
||||
def expectTerminationOf(actorRef: ActorRef) = expectMsgPF(5 seconds, actorRef + ": Stopped or Already terminated when linking") {
|
||||
case WrappedTerminated(Terminated(`actorRef`)) ⇒ true
|
||||
case WrappedTerminated(Terminated(`actorRef`)) => true
|
||||
}
|
||||
|
||||
"notify with one Terminated message when an Actor is stopped" in {
|
||||
|
|
@ -123,8 +123,8 @@ trait DeathWatchSpec { this: AkkaSpec with ImplicitSender with DefaultTimeout
|
|||
context.watch(terminal)
|
||||
context.unwatch(terminal)
|
||||
def receive = {
|
||||
case "ping" ⇒ sender() ! "pong"
|
||||
case t: Terminated ⇒ testActor ! WrappedTerminated(t)
|
||||
case "ping" => sender() ! "pong"
|
||||
case t: Terminated => testActor ! WrappedTerminated(t)
|
||||
}
|
||||
}).withDeploy(Deploy.local))
|
||||
|
||||
|
|
@ -180,9 +180,9 @@ trait DeathWatchSpec { this: AkkaSpec with ImplicitSender with DefaultTimeout
|
|||
|
||||
failed ! Kill
|
||||
val result = receiveWhile(3 seconds, messages = 3) {
|
||||
case FF(Failed(_, _: ActorKilledException, _)) if lastSender eq failed ⇒ 1
|
||||
case FF(Failed(_, DeathPactException(`failed`), _)) if lastSender eq brother ⇒ 2
|
||||
case WrappedTerminated(Terminated(`brother`)) ⇒ 3
|
||||
case FF(Failed(_, _: ActorKilledException, _)) if lastSender eq failed => 1
|
||||
case FF(Failed(_, DeathPactException(`failed`), _)) if lastSender eq brother => 2
|
||||
case WrappedTerminated(Terminated(`brother`)) => 3
|
||||
}
|
||||
testActor.isTerminated should not be true
|
||||
result should ===(Seq(1, 2, 3))
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ object DeployerSpec {
|
|||
""", ConfigParseOptions.defaults)
|
||||
|
||||
class RecipeActor extends Actor {
|
||||
def receive = { case _ ⇒ }
|
||||
def receive = { case _ => }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -227,8 +227,8 @@ class DeployerSpec extends AkkaSpec(DeployerSpec.deployerConf) {
|
|||
deployment.get.routerConfig.getClass should ===(expected.getClass)
|
||||
deployment.get.scope should ===(NoScopeGiven)
|
||||
expected match {
|
||||
case pool: Pool ⇒ deployment.get.routerConfig.asInstanceOf[Pool].resizer should ===(pool.resizer)
|
||||
case _ ⇒
|
||||
case pool: Pool => deployment.get.routerConfig.asInstanceOf[Pool].resizer should ===(pool.resizer)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,37 +34,37 @@ object FSMActorSpec {
|
|||
class Lock(code: String, timeout: FiniteDuration, latches: Latches) extends Actor with FSM[LockState, CodeState] {
|
||||
|
||||
import latches._
|
||||
import FSM.`→`
|
||||
import FSM.`->`
|
||||
|
||||
startWith(Locked, CodeState("", code))
|
||||
|
||||
when(Locked) {
|
||||
case Event(digit: Char, CodeState(soFar, code)) ⇒ {
|
||||
case Event(digit: Char, CodeState(soFar, code)) => {
|
||||
soFar + digit match {
|
||||
case incomplete if incomplete.length < code.length ⇒
|
||||
case incomplete if incomplete.length < code.length =>
|
||||
stay using CodeState(incomplete, code)
|
||||
case codeTry if (codeTry == code) ⇒ {
|
||||
case codeTry if (codeTry == code) => {
|
||||
doUnlock()
|
||||
goto(Open) using CodeState("", code) forMax timeout
|
||||
}
|
||||
case wrong ⇒ {
|
||||
case wrong => {
|
||||
stay using CodeState("", code)
|
||||
}
|
||||
}
|
||||
}
|
||||
case Event("hello", _) ⇒ stay replying "world"
|
||||
case Event("bye", _) ⇒ stop(FSM.Shutdown)
|
||||
case Event("hello", _) => stay replying "world"
|
||||
case Event("bye", _) => stop(FSM.Shutdown)
|
||||
}
|
||||
|
||||
when(Open) {
|
||||
case Event(StateTimeout, _) ⇒ {
|
||||
case Event(StateTimeout, _) => {
|
||||
doLock()
|
||||
goto(Locked)
|
||||
}
|
||||
}
|
||||
|
||||
whenUnhandled {
|
||||
case Event(msg, _) ⇒ {
|
||||
case Event(msg, _) => {
|
||||
log.warning("unhandled event " + msg + " in state " + stateName + " with data " + stateData)
|
||||
unhandledLatch.open
|
||||
stay
|
||||
|
|
@ -72,7 +72,7 @@ object FSMActorSpec {
|
|||
}
|
||||
|
||||
onTransition {
|
||||
case Locked → Open ⇒ transitionLatch.open
|
||||
case Locked -> Open => transitionLatch.open
|
||||
}
|
||||
|
||||
// verify that old-style does still compile
|
||||
|
|
@ -83,7 +83,7 @@ object FSMActorSpec {
|
|||
}
|
||||
|
||||
onTermination {
|
||||
case StopEvent(FSM.Shutdown, Locked, _) ⇒
|
||||
case StopEvent(FSM.Shutdown, Locked, _) =>
|
||||
// stop is called from lockstate with shutdown as reason...
|
||||
terminatedLatch.open()
|
||||
}
|
||||
|
|
@ -99,9 +99,9 @@ object FSMActorSpec {
|
|||
final case class CodeState(soFar: String, code: String)
|
||||
}
|
||||
|
||||
class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with ImplicitSender {
|
||||
class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" -> true)) with ImplicitSender {
|
||||
import FSMActorSpec._
|
||||
import FSM.`→`
|
||||
import FSM.`->`
|
||||
|
||||
val timeout = Timeout(2 seconds)
|
||||
|
||||
|
|
@ -119,8 +119,8 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
|
||||
val transitionTester = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case Transition(_, _, _) ⇒ transitionCallBackLatch.open
|
||||
case CurrentState(_, s: LockState) if s eq Locked ⇒ initialStateLatch.open // SI-5900 workaround
|
||||
case Transition(_, _, _) => transitionCallBackLatch.open
|
||||
case CurrentState(_, s: LockState) if s eq Locked => initialStateLatch.open // SI-5900 workaround
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -146,9 +146,9 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
val answerLatch = TestLatch()
|
||||
val tester = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case Hello ⇒ lock ! "hello"
|
||||
case "world" ⇒ answerLatch.open
|
||||
case Bye ⇒ lock ! "bye"
|
||||
case Hello => lock ! "hello"
|
||||
case "world" => answerLatch.open
|
||||
case Bye => lock ! "bye"
|
||||
}
|
||||
}))
|
||||
tester ! Hello
|
||||
|
|
@ -162,7 +162,7 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
val fsm = TestActorRef(new Actor with FSM[Int, Null] {
|
||||
startWith(1, null)
|
||||
when(1) {
|
||||
case Event("go", _) ⇒ goto(2)
|
||||
case Event("go", _) => goto(2)
|
||||
}
|
||||
})
|
||||
val name = fsm.path.toString
|
||||
|
|
@ -170,7 +170,7 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
system.eventStream.subscribe(testActor, classOf[Logging.Error])
|
||||
fsm ! "go"
|
||||
expectMsgPF(1 second, hint = "Next state 2 does not exist") {
|
||||
case Logging.Error(_, `name`, _, "Next state 2 does not exist") ⇒ true
|
||||
case Logging.Error(_, `name`, _, "Next state 2 does not exist") => true
|
||||
}
|
||||
system.eventStream.unsubscribe(testActor)
|
||||
}
|
||||
|
|
@ -187,7 +187,7 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
startWith(1, null)
|
||||
when(1) { FSM.NullFunction }
|
||||
onTermination {
|
||||
case x ⇒ testActor ! x
|
||||
case x => testActor ! x
|
||||
}
|
||||
}
|
||||
val ref = system.actorOf(Props(fsm))
|
||||
|
|
@ -201,10 +201,10 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
val actor = system.actorOf(Props(new Actor with FSM[Int, String] {
|
||||
startWith(1, null)
|
||||
when(1) {
|
||||
case Event(2, null) ⇒ stop(FSM.Normal, expected)
|
||||
case Event(2, null) => stop(FSM.Normal, expected)
|
||||
}
|
||||
onTermination {
|
||||
case StopEvent(FSM.Normal, 1, `expected`) ⇒ testActor ! "green"
|
||||
case StopEvent(FSM.Normal, 1, `expected`) => testActor ! "green"
|
||||
}
|
||||
}))
|
||||
actor ! 2
|
||||
|
|
@ -218,17 +218,17 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
lazy val fsmref = TestFSMRef(new Actor with FSM[String, Null] {
|
||||
startWith("not-started", null)
|
||||
when("not-started") {
|
||||
case Event("start", _) ⇒ goto("started") replying "starting"
|
||||
case Event("start", _) => goto("started") replying "starting"
|
||||
}
|
||||
when("started", stateTimeout = 10 seconds) {
|
||||
case Event("stop", _) ⇒ stop()
|
||||
case Event("stop", _) => stop()
|
||||
}
|
||||
onTransition {
|
||||
case "not-started" → "started" ⇒
|
||||
for (timerName ← timerNames) setTimer(timerName, (), 10 seconds, false)
|
||||
case "not-started" -> "started" =>
|
||||
for (timerName <- timerNames) setTimer(timerName, (), 10 seconds, false)
|
||||
}
|
||||
onTermination {
|
||||
case _ ⇒ {
|
||||
case _ => {
|
||||
checkTimersActive(false)
|
||||
testActor ! "stopped"
|
||||
}
|
||||
|
|
@ -236,7 +236,7 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
})
|
||||
|
||||
def checkTimersActive(active: Boolean): Unit = {
|
||||
for (timer ← timerNames) fsmref.isTimerActive(timer) should ===(active)
|
||||
for (timer <- timerNames) fsmref.isTimerActive(timer) should ===(active)
|
||||
fsmref.isStateTimerActive should ===(active)
|
||||
}
|
||||
|
||||
|
|
@ -252,8 +252,8 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
|
||||
"log events and transitions if asked to do so" in {
|
||||
import scala.collection.JavaConverters._
|
||||
val config = ConfigFactory.parseMap(Map("akka.loglevel" → "DEBUG", "akka.actor.serialize-messages" → "off",
|
||||
"akka.actor.debug.fsm" → true).asJava).withFallback(system.settings.config)
|
||||
val config = ConfigFactory.parseMap(Map("akka.loglevel" -> "DEBUG", "akka.actor.serialize-messages" -> "off",
|
||||
"akka.actor.debug.fsm" -> true).asJava).withFallback(system.settings.config)
|
||||
val fsmEventSystem = ActorSystem("fsmEvent", config)
|
||||
try {
|
||||
new TestKit(fsmEventSystem) {
|
||||
|
|
@ -261,17 +261,17 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
val fsm = TestActorRef(new Actor with LoggingFSM[Int, Null] {
|
||||
startWith(1, null)
|
||||
when(1) {
|
||||
case Event("go", _) ⇒
|
||||
case Event("go", _) =>
|
||||
setTimer("t", FSM.Shutdown, 1.5 seconds, false)
|
||||
goto(2)
|
||||
}
|
||||
when(2) {
|
||||
case Event("stop", _) ⇒
|
||||
case Event("stop", _) =>
|
||||
cancelTimer("t")
|
||||
stop
|
||||
}
|
||||
onTermination {
|
||||
case StopEvent(r, _, _) ⇒ testActor ! r
|
||||
case StopEvent(r, _, _) => testActor ! r
|
||||
}
|
||||
})
|
||||
val name = fsm.path.toString
|
||||
|
|
@ -279,13 +279,13 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
system.eventStream.subscribe(testActor, classOf[Logging.Debug])
|
||||
fsm ! "go"
|
||||
expectMsgPF(1 second, hint = "processing Event(go,null)") {
|
||||
case Logging.Debug(`name`, `fsmClass`, s: String) if s.startsWith("processing Event(go,null) from Actor[") ⇒ true
|
||||
case Logging.Debug(`name`, `fsmClass`, s: String) if s.startsWith("processing Event(go,null) from Actor[") => true
|
||||
}
|
||||
expectMsg(1 second, Logging.Debug(name, fsmClass, "setting timer 't'/1500 milliseconds: Shutdown"))
|
||||
expectMsg(1 second, Logging.Debug(name, fsmClass, "transition 1 -> 2"))
|
||||
fsm ! "stop"
|
||||
expectMsgPF(1 second, hint = "processing Event(stop,null)") {
|
||||
case Logging.Debug(`name`, `fsmClass`, s: String) if s.startsWith("processing Event(stop,null) from Actor[") ⇒ true
|
||||
case Logging.Debug(`name`, `fsmClass`, s: String) if s.startsWith("processing Event(stop,null) from Actor[") => true
|
||||
}
|
||||
expectMsgAllOf(1 second, Logging.Debug(name, fsmClass, "canceling timer 't'"), FSM.Normal)
|
||||
expectNoMsg(1 second)
|
||||
|
|
@ -302,8 +302,8 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
override def logDepth = 3
|
||||
startWith(1, 0)
|
||||
when(1) {
|
||||
case Event("count", c) ⇒ stay using (c + 1)
|
||||
case Event("log", _) ⇒ stay replying getLog
|
||||
case Event("count", c) => stay using (c + 1)
|
||||
case Event("log", _) => stay replying getLog
|
||||
}
|
||||
})
|
||||
fsmref ! "log"
|
||||
|
|
@ -323,12 +323,12 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
val fsmref = system.actorOf(Props(new Actor with FSM[Int, Int] {
|
||||
startWith(0, 0)
|
||||
when(0)(transform {
|
||||
case Event("go", _) ⇒ stay
|
||||
case Event("go", _) => stay
|
||||
} using {
|
||||
case x ⇒ goto(1)
|
||||
case x => goto(1)
|
||||
})
|
||||
when(1) {
|
||||
case _ ⇒ stay
|
||||
case _ => stay
|
||||
}
|
||||
}))
|
||||
fsmref ! SubscribeTransitionCallBack(testActor)
|
||||
|
|
@ -348,11 +348,11 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" → true)) with I
|
|||
startWith("init", "")
|
||||
|
||||
when("init", stateTimeout = 300.millis) {
|
||||
case Event(StateTimeout, _) ⇒
|
||||
case Event(StateTimeout, _) =>
|
||||
p.ref ! StateTimeout
|
||||
stay()
|
||||
|
||||
case Event(OverrideTimeoutToInf, _) ⇒
|
||||
case Event(OverrideTimeoutToInf, _) =>
|
||||
p.ref ! OverrideTimeoutToInf
|
||||
stay() forMax Duration.Inf
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ class FSMTimingSpec extends AkkaSpec with ImplicitSender {
|
|||
expectMsg(1 second, CurrentState(fsm, Initial))
|
||||
|
||||
ignoreMsg {
|
||||
case Transition(_, bs: FSMTimingSpec.State, _) if bs eq Initial ⇒ true // SI-5900 workaround
|
||||
case Transition(_, bs: FSMTimingSpec.State, _) if bs eq Initial => true // SI-5900 workaround
|
||||
}
|
||||
|
||||
"A Finite State Machine" must {
|
||||
|
|
@ -120,7 +120,7 @@ class FSMTimingSpec extends AkkaSpec with ImplicitSender {
|
|||
"receive and cancel a repeated timer" taggedAs TimingTest in {
|
||||
fsm ! TestRepeatedTimer
|
||||
val seq = receiveWhile(2 seconds) {
|
||||
case Tick ⇒ Tick
|
||||
case Tick => Tick
|
||||
}
|
||||
seq should have length 5
|
||||
within(500 millis) {
|
||||
|
|
@ -152,13 +152,13 @@ class FSMTimingSpec extends AkkaSpec with ImplicitSender {
|
|||
object FSMTimingSpec {
|
||||
|
||||
def suspend(actorRef: ActorRef): Unit = actorRef match {
|
||||
case l: ActorRefWithCell ⇒ l.suspend()
|
||||
case _ ⇒
|
||||
case l: ActorRefWithCell => l.suspend()
|
||||
case _ =>
|
||||
}
|
||||
|
||||
def resume(actorRef: ActorRef): Unit = actorRef match {
|
||||
case l: ActorRefWithCell ⇒ l.resume(causedByFailure = null)
|
||||
case _ ⇒
|
||||
case l: ActorRefWithCell => l.resume(causedByFailure = null)
|
||||
case _ =>
|
||||
}
|
||||
|
||||
trait State
|
||||
|
|
@ -189,54 +189,54 @@ object FSMTimingSpec {
|
|||
|
||||
startWith(Initial, 0)
|
||||
when(Initial) {
|
||||
case Event(TestSingleTimer, _) ⇒
|
||||
case Event(TestSingleTimer, _) =>
|
||||
setTimer("tester", Tick, 500.millis.dilated, false)
|
||||
goto(TestSingleTimer)
|
||||
case Event(TestRepeatedTimer, _) ⇒
|
||||
case Event(TestRepeatedTimer, _) =>
|
||||
setTimer("tester", Tick, 100.millis.dilated, true)
|
||||
goto(TestRepeatedTimer) using 4
|
||||
case Event(TestStateTimeoutOverride, _) ⇒
|
||||
case Event(TestStateTimeoutOverride, _) =>
|
||||
goto(TestStateTimeout) forMax (Duration.Inf)
|
||||
case Event(x: FSMTimingSpec.State, _) ⇒ goto(x)
|
||||
case Event(x: FSMTimingSpec.State, _) => goto(x)
|
||||
}
|
||||
when(TestStateTimeout, stateTimeout = 800.millis.dilated) {
|
||||
case Event(StateTimeout, _) ⇒ goto(Initial)
|
||||
case Event(Cancel, _) ⇒ goto(Initial) replying (Cancel)
|
||||
case Event(StateTimeout, _) => goto(Initial)
|
||||
case Event(Cancel, _) => goto(Initial) replying (Cancel)
|
||||
}
|
||||
when(TestSingleTimer) {
|
||||
case Event(Tick, _) ⇒
|
||||
case Event(Tick, _) =>
|
||||
tester ! Tick
|
||||
goto(Initial)
|
||||
}
|
||||
onTransition {
|
||||
case Initial → TestSingleTimerResubmit ⇒ setTimer("blah", Tick, 500.millis.dilated)
|
||||
case Initial -> TestSingleTimerResubmit => setTimer("blah", Tick, 500.millis.dilated)
|
||||
}
|
||||
when(TestSingleTimerResubmit) {
|
||||
case Event(Tick, _) ⇒
|
||||
case Event(Tick, _) =>
|
||||
tester ! Tick
|
||||
setTimer("blah", Tock, 500.millis.dilated)
|
||||
stay()
|
||||
case Event(Tock, _) ⇒
|
||||
case Event(Tock, _) =>
|
||||
tester ! Tock
|
||||
goto(Initial)
|
||||
}
|
||||
when(TestCancelTimer) {
|
||||
case Event(Tick, _) ⇒
|
||||
case Event(Tick, _) =>
|
||||
setTimer("hallo", Tock, 1.milli.dilated)
|
||||
TestKit.awaitCond(context.asInstanceOf[ActorCell].mailbox.hasMessages, 1.second.dilated)
|
||||
cancelTimer("hallo")
|
||||
sender() ! Tick
|
||||
setTimer("hallo", Tock, 500.millis.dilated)
|
||||
stay
|
||||
case Event(Tock, _) ⇒
|
||||
case Event(Tock, _) =>
|
||||
tester ! Tock
|
||||
stay
|
||||
case Event(Cancel, _) ⇒
|
||||
case Event(Cancel, _) =>
|
||||
cancelTimer("hallo")
|
||||
goto(Initial)
|
||||
}
|
||||
when(TestRepeatedTimer) {
|
||||
case Event(Tick, remaining) ⇒
|
||||
case Event(Tick, remaining) =>
|
||||
tester ! Tick
|
||||
if (remaining == 0) {
|
||||
cancelTimer("tester")
|
||||
|
|
@ -247,29 +247,29 @@ object FSMTimingSpec {
|
|||
}
|
||||
when(TestCancelStateTimerInNamedTimerMessage) {
|
||||
// FSM is suspended after processing this message and resumed 500ms later
|
||||
case Event(Tick, _) ⇒
|
||||
case Event(Tick, _) =>
|
||||
suspend(self)
|
||||
setTimer("named", Tock, 1.millis.dilated)
|
||||
TestKit.awaitCond(context.asInstanceOf[ActorCell].mailbox.hasMessages, 1.second.dilated)
|
||||
stay forMax (1.millis.dilated) replying Tick
|
||||
case Event(Tock, _) ⇒
|
||||
case Event(Tock, _) =>
|
||||
goto(TestCancelStateTimerInNamedTimerMessage2)
|
||||
}
|
||||
when(TestCancelStateTimerInNamedTimerMessage2) {
|
||||
case Event(StateTimeout, _) ⇒
|
||||
case Event(StateTimeout, _) =>
|
||||
goto(Initial)
|
||||
case Event(Cancel, _) ⇒
|
||||
case Event(Cancel, _) =>
|
||||
goto(Initial) replying Cancel
|
||||
}
|
||||
when(TestUnhandled) {
|
||||
case Event(SetHandler, _) ⇒
|
||||
case Event(SetHandler, _) =>
|
||||
whenUnhandled {
|
||||
case Event(Tick, _) ⇒
|
||||
case Event(Tick, _) =>
|
||||
tester ! Unhandled(Tick)
|
||||
stay
|
||||
}
|
||||
stay
|
||||
case Event(Cancel, _) ⇒
|
||||
case Event(Cancel, _) =>
|
||||
whenUnhandled(NullFunction)
|
||||
goto(Initial)
|
||||
}
|
||||
|
|
@ -279,7 +279,7 @@ object FSMTimingSpec {
|
|||
startWith(Initial, 0)
|
||||
|
||||
when(Initial, 200 millis) {
|
||||
case Event(TestStoppingActorStateTimeout, _) ⇒
|
||||
case Event(TestStoppingActorStateTimeout, _) =>
|
||||
context.stop(self)
|
||||
stay
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,19 +10,19 @@ import scala.concurrent.duration._
|
|||
import scala.language.postfixOps
|
||||
|
||||
object FSMTransitionSpec {
|
||||
import FSM.`→`
|
||||
import FSM.`->`
|
||||
|
||||
class Supervisor extends Actor {
|
||||
def receive = { case _ ⇒ }
|
||||
def receive = { case _ => }
|
||||
}
|
||||
|
||||
class SendAnyTransitionFSM(target: ActorRef) extends Actor with FSM[Int, Int] {
|
||||
startWith(0, 0)
|
||||
when(0) {
|
||||
case Event("stay", _) ⇒ stay()
|
||||
case Event(_, _) ⇒ goto(0)
|
||||
case Event("stay", _) => stay()
|
||||
case Event(_, _) => goto(0)
|
||||
}
|
||||
onTransition { case from → to ⇒ target ! (from → to) }
|
||||
onTransition { case from -> to => target ! (from -> to) }
|
||||
|
||||
initialize()
|
||||
}
|
||||
|
|
@ -30,13 +30,13 @@ object FSMTransitionSpec {
|
|||
class MyFSM(target: ActorRef) extends Actor with FSM[Int, Unit] {
|
||||
startWith(0, Unit)
|
||||
when(0) {
|
||||
case Event("tick", _) ⇒ goto(1)
|
||||
case Event("tick", _) => goto(1)
|
||||
}
|
||||
when(1) {
|
||||
case Event("tick", _) ⇒ goto(0)
|
||||
case Event("tick", _) => goto(0)
|
||||
}
|
||||
whenUnhandled {
|
||||
case Event("reply", _) ⇒ stay replying "reply"
|
||||
case Event("reply", _) => stay replying "reply"
|
||||
}
|
||||
initialize()
|
||||
override def preRestart(reason: Throwable, msg: Option[Any]): Unit = { target ! "restarted" }
|
||||
|
|
@ -45,20 +45,20 @@ object FSMTransitionSpec {
|
|||
class OtherFSM(target: ActorRef) extends Actor with FSM[Int, Int] {
|
||||
startWith(0, 0)
|
||||
when(0) {
|
||||
case Event("tick", _) ⇒ goto(1) using 1
|
||||
case Event("stay", _) ⇒ stay()
|
||||
case Event("tick", _) => goto(1) using 1
|
||||
case Event("stay", _) => stay()
|
||||
}
|
||||
when(1) {
|
||||
case _ ⇒ goto(1)
|
||||
case _ => goto(1)
|
||||
}
|
||||
onTransition {
|
||||
case 0 → 1 ⇒ target ! ((stateData, nextStateData))
|
||||
case 1 → 1 ⇒ target ! ((stateData, nextStateData))
|
||||
case 0 -> 1 => target ! ((stateData, nextStateData))
|
||||
case 1 -> 1 => target ! ((stateData, nextStateData))
|
||||
}
|
||||
}
|
||||
|
||||
class Forwarder(target: ActorRef) extends Actor {
|
||||
def receive = { case x ⇒ target ! x }
|
||||
def receive = { case x => target ! x }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -66,17 +66,17 @@ object FSMTransitionSpec {
|
|||
class FSMTransitionSpec extends AkkaSpec with ImplicitSender {
|
||||
|
||||
import FSMTransitionSpec._
|
||||
import FSM.`→`
|
||||
import FSM.`->`
|
||||
|
||||
"A FSM transition notifier" must {
|
||||
|
||||
"not trigger onTransition for stay" in {
|
||||
val fsm = system.actorOf(Props(new SendAnyTransitionFSM(testActor)))
|
||||
expectMsg(0 → 0) // caused by initialize(), OK.
|
||||
expectMsg(0 -> 0) // caused by initialize(), OK.
|
||||
fsm ! "stay" // no transition event
|
||||
expectNoMsg(500.millis)
|
||||
fsm ! "goto" // goto(current state)
|
||||
expectMsg(0 → 0)
|
||||
expectMsg(0 -> 0)
|
||||
}
|
||||
|
||||
"notify listeners" in {
|
||||
|
|
@ -150,17 +150,17 @@ class FSMTransitionSpec extends AkkaSpec with ImplicitSender {
|
|||
val fsmref = system.actorOf(Props(new Actor with FSM[Int, ActorRef] {
|
||||
startWith(0, null)
|
||||
when(0) {
|
||||
case Event("switch", _) ⇒ goto(1) using sender()
|
||||
case Event("switch", _) => goto(1) using sender()
|
||||
}
|
||||
onTransition {
|
||||
case x → y ⇒ nextStateData ! (x → y)
|
||||
case x -> y => nextStateData ! (x -> y)
|
||||
}
|
||||
when(1) {
|
||||
case Event("test", _) ⇒
|
||||
case Event("test", _) =>
|
||||
try {
|
||||
sender() ! s"failed: $nextStateData"
|
||||
} catch {
|
||||
case _: IllegalStateException ⇒ sender() ! "ok"
|
||||
case _: IllegalStateException => sender() ! "ok"
|
||||
}
|
||||
stay()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,12 +15,12 @@ object ForwardActorSpec {
|
|||
|
||||
def createForwardingChain(system: ActorSystem): ActorRef = {
|
||||
val replier = system.actorOf(Props(new Actor {
|
||||
def receive = { case x ⇒ sender() ! x }
|
||||
def receive = { case x => sender() ! x }
|
||||
}))
|
||||
|
||||
def mkforwarder(forwardTo: ActorRef) = system.actorOf(Props(
|
||||
new Actor {
|
||||
def receive = { case x ⇒ forwardTo forward x }
|
||||
def receive = { case x => forwardTo forward x }
|
||||
}))
|
||||
|
||||
mkforwarder(mkforwarder(mkforwarder(replier)))
|
||||
|
|
@ -33,7 +33,7 @@ class ForwardActorSpec extends AkkaSpec {
|
|||
"A Forward Actor" must {
|
||||
|
||||
"forward actor reference when invoking forward on tell" in {
|
||||
val replyTo = system.actorOf(Props(new Actor { def receive = { case ExpectedMessage ⇒ testActor ! ExpectedMessage } }))
|
||||
val replyTo = system.actorOf(Props(new Actor { def receive = { case ExpectedMessage => testActor ! ExpectedMessage } }))
|
||||
|
||||
val chain = createForwardingChain(system)
|
||||
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ object FunctionRefSpec {
|
|||
|
||||
class Super extends Actor {
|
||||
def receive = {
|
||||
case GetForwarder(replyTo) ⇒
|
||||
case GetForwarder(replyTo) =>
|
||||
val cell = context.asInstanceOf[ActorCell]
|
||||
val ref = cell.addFunctionRef((sender, msg) ⇒ replyTo ! Forwarded(msg, sender))
|
||||
val ref = cell.addFunctionRef((sender, msg) => replyTo ! Forwarded(msg, sender))
|
||||
replyTo ! ref
|
||||
case DropForwarder(ref) ⇒
|
||||
case DropForwarder(ref) =>
|
||||
val cell = context.asInstanceOf[ActorCell]
|
||||
cell.removeFunctionRef(ref)
|
||||
}
|
||||
|
|
@ -31,7 +31,7 @@ object FunctionRefSpec {
|
|||
class SupSuper extends Actor {
|
||||
val s = context.actorOf(Props[Super], "super")
|
||||
def receive = {
|
||||
case msg ⇒ s ! msg
|
||||
case msg => s ! msg
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ class FunctionRefSpec extends AkkaSpec with ImplicitSender {
|
|||
"not registered" must {
|
||||
"not be found" in {
|
||||
val provider = system.asInstanceOf[ExtendedActorSystem].provider
|
||||
val ref = new FunctionRef(testActor.path / "blabla", provider, system, (_, _) ⇒ ())
|
||||
val ref = new FunctionRef(testActor.path / "blabla", provider, system, (_, _) => ())
|
||||
EventFilter[SerializationCheckFailedException](start = "Failed to serialize and deserialize message of type akka.actor.FunctionRefSpec", occurrences = 1) intercept {
|
||||
// needs to be something that fails when the deserialized form is not a FunctionRef
|
||||
// this relies upon serialize-messages during tests
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ class HotSwapSpec extends AkkaSpec with ImplicitSender {
|
|||
"An Actor" must {
|
||||
"be able to become in its constructor" in {
|
||||
val a = system.actorOf(Props(new Becomer {
|
||||
context.become { case always ⇒ sender() ! always }
|
||||
def receive = { case _ ⇒ sender() ! "FAILURE" }
|
||||
context.become { case always => sender() ! always }
|
||||
def receive = { case _ => sender() ! "FAILURE" }
|
||||
}))
|
||||
a ! "pigdog"
|
||||
expectMsg("pigdog")
|
||||
|
|
@ -27,8 +27,8 @@ class HotSwapSpec extends AkkaSpec with ImplicitSender {
|
|||
|
||||
"be able to become multiple times in its constructor" in {
|
||||
val a = system.actorOf(Props(new Becomer {
|
||||
for (i ← 1 to 4) context.become({ case always ⇒ sender() ! i + ":" + always })
|
||||
def receive = { case _ ⇒ sender() ! "FAILURE" }
|
||||
for (i <- 1 to 4) context.become({ case always => sender() ! i + ":" + always })
|
||||
def receive = { case _ => sender() ! "FAILURE" }
|
||||
}))
|
||||
a ! "pigdog"
|
||||
expectMsg("4:pigdog")
|
||||
|
|
@ -36,8 +36,8 @@ class HotSwapSpec extends AkkaSpec with ImplicitSender {
|
|||
|
||||
"be able to become with stacking in its constructor" in {
|
||||
val a = system.actorOf(Props(new Becomer {
|
||||
context.become({ case always ⇒ sender() ! "pigdog:" + always; context.unbecome() }, false)
|
||||
def receive = { case always ⇒ sender() ! "badass:" + always }
|
||||
context.become({ case always => sender() ! "pigdog:" + always; context.unbecome() }, false)
|
||||
def receive = { case always => sender() ! "badass:" + always }
|
||||
}))
|
||||
a ! "pigdog"
|
||||
expectMsg("pigdog:pigdog")
|
||||
|
|
@ -47,8 +47,8 @@ class HotSwapSpec extends AkkaSpec with ImplicitSender {
|
|||
|
||||
"be able to become, with stacking, multiple times in its constructor" in {
|
||||
val a = system.actorOf(Props(new Becomer {
|
||||
for (i ← 1 to 4) context.become({ case always ⇒ sender() ! i + ":" + always; context.unbecome() }, false)
|
||||
def receive = { case _ ⇒ sender() ! "FAILURE" }
|
||||
for (i <- 1 to 4) context.become({ case always => sender() ! i + ":" + always; context.unbecome() }, false)
|
||||
def receive = { case _ => sender() ! "FAILURE" }
|
||||
}))
|
||||
a ! "pigdog"
|
||||
a ! "pigdog"
|
||||
|
|
@ -63,8 +63,8 @@ class HotSwapSpec extends AkkaSpec with ImplicitSender {
|
|||
"be able to hotswap its behavior with become(..)" in {
|
||||
val a = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "init" ⇒ sender() ! "init"
|
||||
case "swap" ⇒ context.become({ case x: String ⇒ context.sender() ! x })
|
||||
case "init" => sender() ! "init"
|
||||
case "swap" => context.become({ case x: String => context.sender() ! x })
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -78,10 +78,10 @@ class HotSwapSpec extends AkkaSpec with ImplicitSender {
|
|||
"be able to revert hotswap its behavior with unbecome" in {
|
||||
val a = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "init" ⇒ sender() ! "init"
|
||||
case "swap" ⇒ context.become({
|
||||
case "swapped" ⇒ sender() ! "swapped"
|
||||
case "revert" ⇒ context.unbecome()
|
||||
case "init" => sender() ! "init"
|
||||
case "swap" => context.become({
|
||||
case "swapped" => sender() ! "swapped"
|
||||
case "revert" => context.unbecome()
|
||||
})
|
||||
}
|
||||
}))
|
||||
|
|
@ -102,12 +102,12 @@ class HotSwapSpec extends AkkaSpec with ImplicitSender {
|
|||
|
||||
val a = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "state" ⇒ sender() ! "0"
|
||||
case "swap" ⇒
|
||||
case "state" => sender() ! "0"
|
||||
case "swap" =>
|
||||
context.become({
|
||||
case "state" ⇒ sender() ! "1"
|
||||
case "swapped" ⇒ sender() ! "swapped"
|
||||
case "crash" ⇒ throw new Exception("Crash (expected)!")
|
||||
case "state" => sender() ! "1"
|
||||
case "swapped" => sender() ! "swapped"
|
||||
case "crash" => throw new Exception("Crash (expected)!")
|
||||
})
|
||||
sender() ! "swapped"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class LocalActorRefProviderSpec extends AkkaSpec(LocalActorRefProviderSpec.confi
|
|||
"An LocalActorRefProvider" must {
|
||||
|
||||
"find actor refs using actorFor" in {
|
||||
val a = system.actorOf(Props(new Actor { def receive = { case _ ⇒ } }))
|
||||
val a = system.actorOf(Props(new Actor { def receive = { case _ => } }))
|
||||
val b = system.actorFor(a.path)
|
||||
a should ===(b)
|
||||
}
|
||||
|
|
@ -44,7 +44,7 @@ class LocalActorRefProviderSpec extends AkkaSpec(LocalActorRefProviderSpec.confi
|
|||
val a = system.actorOf(Props(new Actor {
|
||||
val child = context.actorOf(Props.empty, name = childName)
|
||||
def receive = {
|
||||
case "lookup" ⇒
|
||||
case "lookup" =>
|
||||
if (childName == child.path.name) sender() ! context.actorFor(childName)
|
||||
else sender() ! s"$childName is not ${child.path.name}!"
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ class LocalActorRefProviderSpec extends AkkaSpec(LocalActorRefProviderSpec.confi
|
|||
val GetChild = "GetChild"
|
||||
val a = watch(system.actorOf(Props(new Actor {
|
||||
val child = context.actorOf(Props.empty)
|
||||
def receive = { case `GetChild` ⇒ sender() ! child }
|
||||
def receive = { case `GetChild` => sender() ! child }
|
||||
})))
|
||||
a.tell(GetChild, testActor)
|
||||
val child = expectMsgType[ActorRef]
|
||||
|
|
@ -128,14 +128,14 @@ class LocalActorRefProviderSpec extends AkkaSpec(LocalActorRefProviderSpec.confi
|
|||
|
||||
provider.isInstanceOf[LocalActorRefProvider] should ===(true)
|
||||
|
||||
for (i ← 0 until 100) {
|
||||
for (i <- 0 until 100) {
|
||||
val address = "new-actor" + i
|
||||
implicit val timeout = Timeout(5 seconds)
|
||||
val actors = for (j ← 1 to 4) yield Future(system.actorOf(Props(new Actor { def receive = { case _ ⇒ } }), address))
|
||||
val set = Set() ++ actors.map(a ⇒ Await.ready(a, timeout.duration).value match {
|
||||
case Some(Success(a: ActorRef)) ⇒ 1
|
||||
case Some(Failure(ex: InvalidActorNameException)) ⇒ 2
|
||||
case x ⇒ x
|
||||
val actors = for (j <- 1 to 4) yield Future(system.actorOf(Props(new Actor { def receive = { case _ => } }), address))
|
||||
val set = Set() ++ actors.map(a => Await.ready(a, timeout.duration).value match {
|
||||
case Some(Success(a: ActorRef)) => 1
|
||||
case Some(Failure(ex: InvalidActorNameException)) => 2
|
||||
case x => x
|
||||
})
|
||||
set should ===(Set[Any](1, 2))
|
||||
}
|
||||
|
|
@ -144,7 +144,7 @@ class LocalActorRefProviderSpec extends AkkaSpec(LocalActorRefProviderSpec.confi
|
|||
"only create one instance of an actor from within the same message invocation" in {
|
||||
val supervisor = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "" ⇒
|
||||
case "" =>
|
||||
val a, b = context.actorOf(Props.empty, "duplicate")
|
||||
}
|
||||
}))
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
context.setReceiveTimeout(500 milliseconds)
|
||||
|
||||
def receive = {
|
||||
case ReceiveTimeout ⇒ timeoutLatch.open
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -43,8 +43,8 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
context.setReceiveTimeout(500 milliseconds)
|
||||
|
||||
def receive = {
|
||||
case Tick ⇒ ()
|
||||
case ReceiveTimeout ⇒ timeoutLatch.open
|
||||
case Tick => ()
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -62,8 +62,8 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
context.setReceiveTimeout(500 milliseconds)
|
||||
|
||||
def receive = {
|
||||
case Tick ⇒ ()
|
||||
case ReceiveTimeout ⇒
|
||||
case Tick => ()
|
||||
case ReceiveTimeout =>
|
||||
count.incrementAndGet
|
||||
timeoutLatch.open
|
||||
context.setReceiveTimeout(Duration.Undefined)
|
||||
|
|
@ -82,7 +82,7 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
|
||||
val timeoutActor = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case ReceiveTimeout ⇒ timeoutLatch.open
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -97,8 +97,8 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
context.setReceiveTimeout(1 second)
|
||||
|
||||
def receive = {
|
||||
case ReceiveTimeout ⇒ timeoutLatch.open
|
||||
case TransperentTick ⇒
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
case TransperentTick =>
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -121,10 +121,10 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
context.setReceiveTimeout(1 second)
|
||||
|
||||
def receive = {
|
||||
case ReceiveTimeout ⇒
|
||||
case ReceiveTimeout =>
|
||||
self ! TransperentTick
|
||||
timeoutLatch.countDown()
|
||||
case TransperentTick ⇒
|
||||
case TransperentTick =>
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -142,9 +142,9 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
|
||||
context.setReceiveTimeout(1 second)
|
||||
def receive: Receive = {
|
||||
case ReceiveTimeout ⇒
|
||||
case ReceiveTimeout =>
|
||||
timeoutLatch.open
|
||||
case TransperentTick ⇒
|
||||
case TransperentTick =>
|
||||
count.incrementAndGet()
|
||||
}
|
||||
}
|
||||
|
|
@ -161,8 +161,8 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
|
||||
val timeoutActor = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case TransperentTick ⇒ context.setReceiveTimeout(500 milliseconds)
|
||||
case ReceiveTimeout ⇒ timeoutLatch.open
|
||||
case TransperentTick => context.setReceiveTimeout(500 milliseconds)
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -179,8 +179,8 @@ class ReceiveTimeoutSpec extends AkkaSpec {
|
|||
context.setReceiveTimeout(500 milliseconds)
|
||||
|
||||
def receive = {
|
||||
case TransperentTick ⇒ context.setReceiveTimeout(Duration.Inf)
|
||||
case ReceiveTimeout ⇒ timeoutLatch.open
|
||||
case TransperentTick => context.setReceiveTimeout(Duration.Inf)
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ class RestartStrategySpec extends AkkaSpec("akka.actor.serialize-messages = off"
|
|||
val slaveProps = Props(new Actor {
|
||||
|
||||
def receive = {
|
||||
case Ping ⇒ countDownLatch.countDown()
|
||||
case Crash ⇒ throw new Exception("Crashing...")
|
||||
case Ping => countDownLatch.countDown()
|
||||
case Crash => throw new Exception("Crashing...")
|
||||
}
|
||||
|
||||
override def postRestart(reason: Throwable) = {
|
||||
|
|
@ -82,7 +82,7 @@ class RestartStrategySpec extends AkkaSpec("akka.actor.serialize-messages = off"
|
|||
val slaveProps = Props(new Actor {
|
||||
|
||||
def receive = {
|
||||
case Crash ⇒ throw new Exception("Crashing...")
|
||||
case Crash => throw new Exception("Crashing...")
|
||||
}
|
||||
|
||||
override def postRestart(reason: Throwable) = {
|
||||
|
|
@ -91,7 +91,7 @@ class RestartStrategySpec extends AkkaSpec("akka.actor.serialize-messages = off"
|
|||
})
|
||||
val slave = Await.result((boss ? slaveProps).mapTo[ActorRef], timeout.duration)
|
||||
|
||||
(1 to 100) foreach { _ ⇒ slave ! Crash }
|
||||
(1 to 100) foreach { _ => slave ! Crash }
|
||||
Await.ready(countDownLatch, 2 minutes)
|
||||
assert(!slave.isTerminated)
|
||||
}
|
||||
|
|
@ -109,9 +109,9 @@ class RestartStrategySpec extends AkkaSpec("akka.actor.serialize-messages = off"
|
|||
val slaveProps = Props(new Actor {
|
||||
|
||||
def receive = {
|
||||
case Ping ⇒
|
||||
case Ping =>
|
||||
if (!pingLatch.isOpen) pingLatch.open else secondPingLatch.open
|
||||
case Crash ⇒ throw new Exception("Crashing...")
|
||||
case Crash => throw new Exception("Crashing...")
|
||||
}
|
||||
override def postRestart(reason: Throwable) = {
|
||||
if (!restartLatch.isOpen)
|
||||
|
|
@ -165,8 +165,8 @@ class RestartStrategySpec extends AkkaSpec("akka.actor.serialize-messages = off"
|
|||
val slaveProps = Props(new Actor {
|
||||
|
||||
def receive = {
|
||||
case Ping ⇒ countDownLatch.countDown()
|
||||
case Crash ⇒ throw new Exception("Crashing...")
|
||||
case Ping => countDownLatch.countDown()
|
||||
case Crash => throw new Exception("Crashing...")
|
||||
}
|
||||
override def postRestart(reason: Throwable) = {
|
||||
if (!restartLatch.isOpen)
|
||||
|
|
@ -212,16 +212,16 @@ class RestartStrategySpec extends AkkaSpec("akka.actor.serialize-messages = off"
|
|||
val boss = system.actorOf(Props(new Actor {
|
||||
override val supervisorStrategy = OneForOneStrategy(withinTimeRange = 1 second)(List(classOf[Throwable]))
|
||||
def receive = {
|
||||
case p: Props ⇒ sender() ! context.watch(context.actorOf(p))
|
||||
case t: Terminated ⇒ maxNoOfRestartsLatch.open()
|
||||
case p: Props => sender() ! context.watch(context.actorOf(p))
|
||||
case t: Terminated => maxNoOfRestartsLatch.open()
|
||||
}
|
||||
}))
|
||||
|
||||
val slaveProps = Props(new Actor {
|
||||
|
||||
def receive = {
|
||||
case Ping ⇒ countDownLatch.countDown()
|
||||
case Crash ⇒ throw new Exception("Crashing...")
|
||||
case Ping => countDownLatch.countDown()
|
||||
case Crash => throw new Exception("Crashing...")
|
||||
}
|
||||
|
||||
override def postRestart(reason: Throwable) = {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ object SchedulerSpec {
|
|||
""").withFallback(AkkaSpec.testConf)
|
||||
}
|
||||
|
||||
trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with ImplicitSender { this: AkkaSpec ⇒
|
||||
trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with ImplicitSender { this: AkkaSpec =>
|
||||
import system.dispatcher
|
||||
|
||||
def collectCancellable(c: Cancellable): Cancellable
|
||||
|
|
@ -41,7 +41,7 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit
|
|||
val tickActor, tickActor2 = system.actorOf(Props(new Actor {
|
||||
var ticks = 0
|
||||
def receive = {
|
||||
case Tick ⇒
|
||||
case Tick =>
|
||||
if (ticks < 3) {
|
||||
sender() ! Tock
|
||||
ticks += 1
|
||||
|
|
@ -67,7 +67,7 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit
|
|||
}
|
||||
|
||||
"stop continuous scheduling if the receiving actor has been terminated" taggedAs TimingTest in {
|
||||
val actor = system.actorOf(Props(new Actor { def receive = { case x ⇒ sender() ! x } }))
|
||||
val actor = system.actorOf(Props(new Actor { def receive = { case x => sender() ! x } }))
|
||||
|
||||
// run immediately and then every 100 milliseconds
|
||||
collectCancellable(system.scheduler.schedule(0 milliseconds, 100 milliseconds, actor, "msg"))
|
||||
|
|
@ -96,7 +96,7 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit
|
|||
case object Tick
|
||||
val countDownLatch = new CountDownLatch(3)
|
||||
val tickActor = system.actorOf(Props(new Actor {
|
||||
def receive = { case Tick ⇒ countDownLatch.countDown() }
|
||||
def receive = { case Tick => countDownLatch.countDown() }
|
||||
}))
|
||||
|
||||
// run after 300 millisec
|
||||
|
|
@ -117,7 +117,7 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit
|
|||
* ticket #372
|
||||
*/
|
||||
"be cancellable" taggedAs TimingTest in {
|
||||
for (_ ← 1 to 10) system.scheduler.scheduleOnce(1 second, testActor, "fail").cancel()
|
||||
for (_ <- 1 to 10) system.scheduler.scheduleOnce(1 second, testActor, "fail").cancel()
|
||||
|
||||
expectNoMsg(2 seconds)
|
||||
}
|
||||
|
|
@ -184,8 +184,8 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit
|
|||
val supervisor = system.actorOf(Props(new Supervisor(AllForOneStrategy(3, 1 second)(List(classOf[Exception])))))
|
||||
val props = Props(new Actor {
|
||||
def receive = {
|
||||
case Ping ⇒ pingLatch.countDown()
|
||||
case Crash ⇒ throw new Exception("CRASH")
|
||||
case Ping => pingLatch.countDown()
|
||||
case Crash => throw new Exception("CRASH")
|
||||
}
|
||||
|
||||
override def postRestart(reason: Throwable) = restartLatch.open
|
||||
|
|
@ -210,7 +210,7 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit
|
|||
|
||||
val actor = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case Msg(ts) ⇒
|
||||
case Msg(ts) =>
|
||||
val now = System.nanoTime
|
||||
// Make sure that no message has been dispatched before the scheduled time (10ms) has occurred
|
||||
if (now < ts) throw new RuntimeException("Interval is too small: " + (now - ts))
|
||||
|
|
@ -218,7 +218,7 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit
|
|||
}
|
||||
}))
|
||||
|
||||
(1 to 300).foreach { i ⇒
|
||||
(1 to 300).foreach { i =>
|
||||
collectCancellable(system.scheduler.scheduleOnce(20 milliseconds, actor, Msg(System.nanoTime)))
|
||||
Thread.sleep(5)
|
||||
}
|
||||
|
|
@ -232,7 +232,7 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit
|
|||
case object Msg
|
||||
|
||||
val actor = system.actorOf(Props(new Actor {
|
||||
def receive = { case Msg ⇒ ticks.countDown() }
|
||||
def receive = { case Msg => ticks.countDown() }
|
||||
}))
|
||||
|
||||
val startTime = System.nanoTime()
|
||||
|
|
@ -283,7 +283,7 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit
|
|||
"survive being stressed without cancellation" taggedAs TimingTest in {
|
||||
val r = ThreadLocalRandom.current()
|
||||
val N = 100000
|
||||
for (_ ← 1 to N) {
|
||||
for (_ <- 1 to N) {
|
||||
val next = r.nextInt(3000)
|
||||
val now = System.nanoTime
|
||||
system.scheduler.scheduleOnce(next.millis) {
|
||||
|
|
@ -292,12 +292,12 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit
|
|||
}
|
||||
}
|
||||
val latencies = within(10.seconds) {
|
||||
for (i ← 1 to N) yield try expectMsgType[Long] catch {
|
||||
case NonFatal(e) ⇒ throw new Exception(s"failed expecting the $i-th latency", e)
|
||||
for (i <- 1 to N) yield try expectMsgType[Long] catch {
|
||||
case NonFatal(e) => throw new Exception(s"failed expecting the $i-th latency", e)
|
||||
}
|
||||
}
|
||||
val histogram = latencies groupBy (_ / 100000000L)
|
||||
for (k ← histogram.keys.toSeq.sorted) {
|
||||
for (k <- histogram.keys.toSeq.sorted) {
|
||||
system.log.info(f"${k * 100}%3d: ${histogram(k).size}")
|
||||
}
|
||||
}
|
||||
|
|
@ -345,7 +345,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
import system.dispatcher
|
||||
val r = ThreadLocalRandom.current
|
||||
val N = 1000000
|
||||
val tasks = for (_ ← 1 to N) yield {
|
||||
val tasks = for (_ <- 1 to N) yield {
|
||||
val next = r.nextInt(3000)
|
||||
val now = System.nanoTime
|
||||
system.scheduler.scheduleOnce(next.millis) {
|
||||
|
|
@ -355,26 +355,26 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
}
|
||||
// get somewhat into the middle of things
|
||||
Thread.sleep(500)
|
||||
val cancellations = for (t ← tasks) yield {
|
||||
val cancellations = for (t <- tasks) yield {
|
||||
t.cancel()
|
||||
if (t.isCancelled) 1 else 0
|
||||
}
|
||||
val cancelled = cancellations.sum
|
||||
println(cancelled)
|
||||
val latencies = within(10.seconds) {
|
||||
for (i ← 1 to (N - cancelled)) yield try expectMsgType[Long] catch {
|
||||
case NonFatal(e) ⇒ throw new Exception(s"failed expecting the $i-th latency", e)
|
||||
for (i <- 1 to (N - cancelled)) yield try expectMsgType[Long] catch {
|
||||
case NonFatal(e) => throw new Exception(s"failed expecting the $i-th latency", e)
|
||||
}
|
||||
}
|
||||
val histogram = latencies groupBy (_ / 100000000L)
|
||||
for (k ← histogram.keys.toSeq.sorted) {
|
||||
for (k <- histogram.keys.toSeq.sorted) {
|
||||
system.log.info(f"${k * 100}%3d: ${histogram(k).size}")
|
||||
}
|
||||
expectNoMsg(1.second)
|
||||
}
|
||||
|
||||
"survive vicious enqueueing" taggedAs TimingTest in {
|
||||
withScheduler(config = ConfigFactory.parseString("akka.scheduler.ticks-per-wheel=2")) { (sched, driver) ⇒
|
||||
withScheduler(config = ConfigFactory.parseString("akka.scheduler.ticks-per-wheel=2")) { (sched, driver) =>
|
||||
import driver._
|
||||
import system.dispatcher
|
||||
val counter = new AtomicInteger
|
||||
|
|
@ -389,7 +389,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
}
|
||||
def delay = if (ThreadLocalRandom.current.nextBoolean) step * 2 else step
|
||||
val N = 1000000
|
||||
(1 to N) foreach (_ ⇒ sched.scheduleOnce(delay)(counter.incrementAndGet()))
|
||||
(1 to N) foreach (_ => sched.scheduleOnce(delay)(counter.incrementAndGet()))
|
||||
sched.close()
|
||||
Await.result(terminated, 3.seconds.dilated) should be > 10
|
||||
awaitCond(counter.get == N)
|
||||
|
|
@ -397,22 +397,22 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
}
|
||||
|
||||
"execute multiple jobs at once when expiring multiple buckets" taggedAs TimingTest in {
|
||||
withScheduler() { (sched, driver) ⇒
|
||||
withScheduler() { (sched, driver) =>
|
||||
implicit def ec = localEC
|
||||
import driver._
|
||||
val start = step / 2
|
||||
(0 to 3) foreach (i ⇒ sched.scheduleOnce(start + step * i, testActor, "hello"))
|
||||
(0 to 3) foreach (i => sched.scheduleOnce(start + step * i, testActor, "hello"))
|
||||
expectNoMsg(step)
|
||||
wakeUp(step)
|
||||
expectWait(step)
|
||||
wakeUp(step * 4 + step / 2)
|
||||
expectWait(step / 2)
|
||||
(0 to 3) foreach (_ ⇒ expectMsg(Duration.Zero, "hello"))
|
||||
(0 to 3) foreach (_ => expectMsg(Duration.Zero, "hello"))
|
||||
}
|
||||
}
|
||||
|
||||
"properly defer jobs even when the timer thread oversleeps" taggedAs TimingTest in {
|
||||
withScheduler() { (sched, driver) ⇒
|
||||
withScheduler() { (sched, driver) =>
|
||||
implicit def ec = localEC
|
||||
import driver._
|
||||
sched.scheduleOnce(step * 3, probe.ref, "hello")
|
||||
|
|
@ -427,11 +427,11 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
}
|
||||
|
||||
"correctly wrap around wheel rounds" taggedAs TimingTest in {
|
||||
withScheduler(config = ConfigFactory.parseString("akka.scheduler.ticks-per-wheel=2")) { (sched, driver) ⇒
|
||||
withScheduler(config = ConfigFactory.parseString("akka.scheduler.ticks-per-wheel=2")) { (sched, driver) =>
|
||||
implicit def ec = localEC
|
||||
import driver._
|
||||
val start = step / 2
|
||||
(0 to 3) foreach (i ⇒ sched.scheduleOnce(start + step * i, probe.ref, "hello"))
|
||||
(0 to 3) foreach (i => sched.scheduleOnce(start + step * i, probe.ref, "hello"))
|
||||
probe.expectNoMsg(step)
|
||||
wakeUp(step)
|
||||
expectWait(step)
|
||||
|
|
@ -454,11 +454,11 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
}
|
||||
|
||||
"correctly execute jobs when clock wraps around" taggedAs TimingTest in {
|
||||
withScheduler(Long.MaxValue - 200000000L) { (sched, driver) ⇒
|
||||
withScheduler(Long.MaxValue - 200000000L) { (sched, driver) =>
|
||||
implicit def ec = localEC
|
||||
import driver._
|
||||
val start = step / 2
|
||||
(0 to 3) foreach (i ⇒ sched.scheduleOnce(start + step * i, testActor, "hello"))
|
||||
(0 to 3) foreach (i => sched.scheduleOnce(start + step * i, testActor, "hello"))
|
||||
expectNoMsg(step)
|
||||
wakeUp(step)
|
||||
expectWait(step)
|
||||
|
|
@ -484,7 +484,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
val numEvents = 40
|
||||
val targetTicks = Int.MaxValue - numEvents + 20
|
||||
|
||||
withScheduler(_startTick = Int.MaxValue - 100) { (sched, driver) ⇒
|
||||
withScheduler(_startTick = Int.MaxValue - 100) { (sched, driver) =>
|
||||
implicit def ec = localEC
|
||||
import driver._
|
||||
|
||||
|
|
@ -494,12 +494,12 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
probe.expectMsgType[Long]
|
||||
|
||||
val nums = 0 until numEvents
|
||||
nums foreach (i ⇒ sched.scheduleOnce(start + step * i, testActor, "hello-" + i))
|
||||
nums foreach (i => sched.scheduleOnce(start + step * i, testActor, "hello-" + i))
|
||||
expectNoMsg(step)
|
||||
wakeUp(step)
|
||||
expectWait(step)
|
||||
|
||||
nums foreach { i ⇒
|
||||
nums foreach { i =>
|
||||
wakeUp(step)
|
||||
expectMsg("hello-" + i)
|
||||
expectWait(step)
|
||||
|
|
@ -508,7 +508,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
}
|
||||
|
||||
"reliably reject jobs when shutting down" taggedAs TimingTest in {
|
||||
withScheduler() { (sched, driver) ⇒
|
||||
withScheduler() { (sched, driver) =>
|
||||
import system.dispatcher
|
||||
val counter = new AtomicInteger
|
||||
Future { Thread.sleep(5); driver.close(); sched.close() }
|
||||
|
|
@ -542,8 +542,8 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
def reportFailure(t: Throwable): Unit = { t.printStackTrace() }
|
||||
}
|
||||
|
||||
def withScheduler(start: Long = 0L, _startTick: Int = 0, config: Config = ConfigFactory.empty)(thunk: (Scheduler with Closeable, Driver) ⇒ Unit): Unit = {
|
||||
import akka.actor.{ LightArrayRevolverScheduler ⇒ LARS }
|
||||
def withScheduler(start: Long = 0L, _startTick: Int = 0, config: Config = ConfigFactory.empty)(thunk: (Scheduler with Closeable, Driver) => Unit): Unit = {
|
||||
import akka.actor.{ LightArrayRevolverScheduler => LARS }
|
||||
val lbq = new AtomicReference[LinkedBlockingQueue[Long]](new LinkedBlockingQueue[Long])
|
||||
val prb = TestProbe()
|
||||
val tf = system.asInstanceOf[ActorSystemImpl].threadFactory
|
||||
|
|
@ -560,11 +560,11 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
// println(s"waiting $ns")
|
||||
prb.ref ! ns
|
||||
try time += (lbq.get match {
|
||||
case q: LinkedBlockingQueue[Long] ⇒ q.take()
|
||||
case _ ⇒ 0L
|
||||
case q: LinkedBlockingQueue[Long] => q.take()
|
||||
case _ => 0L
|
||||
})
|
||||
catch {
|
||||
case _: InterruptedException ⇒ Thread.currentThread.interrupt()
|
||||
case _: InterruptedException => Thread.currentThread.interrupt()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -572,25 +572,25 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
}
|
||||
val driver = new Driver {
|
||||
def wakeUp(d: FiniteDuration) = lbq.get match {
|
||||
case q: LinkedBlockingQueue[Long] ⇒ q.offer(d.toNanos)
|
||||
case _ ⇒
|
||||
case q: LinkedBlockingQueue[Long] => q.offer(d.toNanos)
|
||||
case _ =>
|
||||
}
|
||||
def expectWait(): FiniteDuration = probe.expectMsgType[Long].nanos
|
||||
def probe = prb
|
||||
def step = sched.TickDuration
|
||||
def close() = lbq.getAndSet(null) match {
|
||||
case q: LinkedBlockingQueue[Long] ⇒ q.offer(0L)
|
||||
case _ ⇒
|
||||
case q: LinkedBlockingQueue[Long] => q.offer(0L)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
driver.expectWait()
|
||||
try thunk(sched, driver)
|
||||
catch {
|
||||
case NonFatal(ex) ⇒
|
||||
case NonFatal(ex) =>
|
||||
try {
|
||||
driver.close()
|
||||
sched.close()
|
||||
} catch { case _: Exception ⇒ }
|
||||
} catch { case _: Exception => }
|
||||
throw ex
|
||||
}
|
||||
driver.close()
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ package akka.actor
|
|||
class Supervisor(override val supervisorStrategy: SupervisorStrategy) extends Actor {
|
||||
|
||||
def receive = {
|
||||
case x: Props ⇒ sender() ! context.actorOf(x)
|
||||
case x: Props => sender() ! context.actorOf(x)
|
||||
}
|
||||
// need to override the default of stopping all children upon restart, tests rely on keeping them around
|
||||
override def preRestart(cause: Throwable, msg: Option[Any]): Unit = {}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import akka.util.Helpers.ConfigOps
|
|||
import akka.testkit.LongRunningTest
|
||||
|
||||
object SupervisorHierarchySpec {
|
||||
import FSM.`→`
|
||||
import FSM.`->`
|
||||
|
||||
class FireWorkerException(msg: String) extends Exception(msg)
|
||||
|
||||
|
|
@ -38,7 +38,7 @@ object SupervisorHierarchySpec {
|
|||
class CountDownActor(countDown: CountDownLatch, override val supervisorStrategy: SupervisorStrategy) extends Actor {
|
||||
|
||||
def receive = {
|
||||
case p: Props ⇒ sender() ! context.actorOf(p)
|
||||
case p: Props => sender() ! context.actorOf(p)
|
||||
}
|
||||
// test relies on keeping children around during restart
|
||||
override def preRestart(cause: Throwable, msg: Option[Any]): Unit = {}
|
||||
|
|
@ -48,11 +48,11 @@ object SupervisorHierarchySpec {
|
|||
}
|
||||
|
||||
class Resumer extends Actor {
|
||||
override def supervisorStrategy = OneForOneStrategy() { case _ ⇒ SupervisorStrategy.Resume }
|
||||
override def supervisorStrategy = OneForOneStrategy() { case _ => SupervisorStrategy.Resume }
|
||||
def receive = {
|
||||
case "spawn" ⇒ sender() ! context.actorOf(Props[Resumer])
|
||||
case "fail" ⇒ throw new Exception("expected")
|
||||
case "ping" ⇒ sender() ! "pong"
|
||||
case "spawn" => sender() ! context.actorOf(Props[Resumer])
|
||||
case "fail" => throw new Exception("expected")
|
||||
case "ping" => sender() ! "pong"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,8 +92,8 @@ object SupervisorHierarchySpec {
|
|||
|
||||
override def suspend(cell: ActorCell): Unit = {
|
||||
cell.actor match {
|
||||
case h: Hierarchy ⇒ h.log :+= Event("suspended " + cell.mailbox.suspendCount, identityHashCode(cell.actor))
|
||||
case _ ⇒
|
||||
case h: Hierarchy => h.log :+= Event("suspended " + cell.mailbox.suspendCount, identityHashCode(cell.actor))
|
||||
case _ =>
|
||||
}
|
||||
super.suspend(cell)
|
||||
}
|
||||
|
|
@ -101,8 +101,8 @@ object SupervisorHierarchySpec {
|
|||
override def resume(cell: ActorCell): Unit = {
|
||||
super.resume(cell)
|
||||
cell.actor match {
|
||||
case h: Hierarchy ⇒ h.log :+= Event("resumed " + cell.mailbox.suspendCount, identityHashCode(cell.actor))
|
||||
case _ ⇒
|
||||
case h: Hierarchy => h.log :+= Event("resumed " + cell.mailbox.suspendCount, identityHashCode(cell.actor))
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,11 +125,11 @@ object SupervisorHierarchySpec {
|
|||
var log = Vector.empty[Event]
|
||||
|
||||
stateCache.get(self.path) match {
|
||||
case hs @ HierarchyState(l: Vector[Event], _, f: Failure) if f.failConstr > 0 && !ignoreFailConstr ⇒
|
||||
case hs @ HierarchyState(l: Vector[Event], _, f: Failure) if f.failConstr > 0 && !ignoreFailConstr =>
|
||||
val log = l :+ Event("Failed in constructor", identityHashCode(this))
|
||||
stateCache.put(self.path, hs.copy(log = log, failConstr = f.copy(failConstr = f.failConstr - 1)))
|
||||
throw f
|
||||
case _ ⇒
|
||||
case _ =>
|
||||
}
|
||||
|
||||
var failed = false
|
||||
|
|
@ -143,9 +143,9 @@ object SupervisorHierarchySpec {
|
|||
}
|
||||
|
||||
def setFlags(directive: Directive): Unit = directive match {
|
||||
case Restart ⇒ failed = true
|
||||
case Resume ⇒ suspended = true
|
||||
case _ ⇒
|
||||
case Restart => failed = true
|
||||
case Resume => suspended = true
|
||||
case _ =>
|
||||
}
|
||||
|
||||
def suspendCount = context.asInstanceOf[ActorCell].mailbox.suspendCount
|
||||
|
|
@ -160,7 +160,7 @@ object SupervisorHierarchySpec {
|
|||
val sizes = s / kids
|
||||
var rest = s % kids
|
||||
val propsTemplate = Props.empty.withDispatcher("hierarchy")
|
||||
(1 to kids).iterator.map { (id) ⇒
|
||||
(1 to kids).iterator.map { (id) =>
|
||||
val kidSize = if (rest > 0) { rest -= 1; sizes + 1 } else sizes
|
||||
val props = Props(new Hierarchy(kidSize, breadth, listener, myLevel + 1, random)).withDeploy(propsTemplate.deploy)
|
||||
(context.watch(context.actorOf(props, id.toString)).path, kidSize)
|
||||
|
|
@ -177,8 +177,8 @@ object SupervisorHierarchySpec {
|
|||
log :+= Event("preRestart " + cause, identityHashCode(this))
|
||||
preRestartCalled = true
|
||||
cause match {
|
||||
case f: Failure ⇒
|
||||
context.children.take(f.stopKids) foreach { child ⇒
|
||||
case f: Failure =>
|
||||
context.children.take(f.stopKids) foreach { child =>
|
||||
log :+= Event("killing " + child, identityHashCode(this))
|
||||
context.unwatch(child)
|
||||
context.stop(child)
|
||||
|
|
@ -188,33 +188,33 @@ object SupervisorHierarchySpec {
|
|||
f.failPre -= 1
|
||||
throw f
|
||||
}
|
||||
case _ ⇒ stateCache.put(self.path, stateCache.get(self.path).copy(log = log))
|
||||
case _ => stateCache.put(self.path, stateCache.get(self.path).copy(log = log))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val unwrap: PartialFunction[Throwable, (Throwable, Throwable)] = {
|
||||
case x @ PostRestartException(_, f: Failure, _) ⇒ (f, x)
|
||||
case x @ ActorInitializationException(_, _, f: Failure) ⇒ (f, x)
|
||||
case x ⇒ (x, x)
|
||||
case x @ PostRestartException(_, f: Failure, _) => (f, x)
|
||||
case x @ ActorInitializationException(_, _, f: Failure) => (f, x)
|
||||
case x => (x, x)
|
||||
}
|
||||
override val supervisorStrategy = OneForOneStrategy()(unwrap andThen {
|
||||
case (_: Failure, _) if pongsToGo > 0 ⇒
|
||||
case (_: Failure, _) if pongsToGo > 0 =>
|
||||
log :+= Event("pongOfDeath resuming " + sender(), identityHashCode(this))
|
||||
Resume
|
||||
case (f: Failure, orig) ⇒
|
||||
case (f: Failure, orig) =>
|
||||
if (f.depth > 0) {
|
||||
setFlags(f.directive)
|
||||
log :+= Event("escalating " + f + " from " + sender(), identityHashCode(this))
|
||||
throw f.copy(depth = f.depth - 1)
|
||||
}
|
||||
val prefix = orig match {
|
||||
case f: Failure ⇒ "applying "
|
||||
case _ ⇒ "re-applying "
|
||||
case f: Failure => "applying "
|
||||
case _ => "re-applying "
|
||||
}
|
||||
log :+= Event(prefix + f + " to " + sender(), identityHashCode(this))
|
||||
if (myLevel > 3 && f.failPost == 0 && f.stop) Stop else f.directive
|
||||
case (_, x) ⇒
|
||||
case (_, x) =>
|
||||
log :+= Event("unhandled exception from " + sender() + Logging.stackTraceFor(x), identityHashCode(this))
|
||||
sender() ! Dump(0)
|
||||
context.system.scheduler.scheduleOnce(1 second, self, Dump(0))(context.dispatcher)
|
||||
|
|
@ -226,7 +226,7 @@ object SupervisorHierarchySpec {
|
|||
log = state.log
|
||||
log :+= Event("restarted " + suspendCount + " " + cause, identityHashCode(this))
|
||||
state.kids foreach {
|
||||
case (childPath, kidSize) ⇒
|
||||
case (childPath, kidSize) =>
|
||||
val name = childPath.name
|
||||
if (context.child(name).isEmpty) {
|
||||
listener ! Died(childPath)
|
||||
|
|
@ -238,9 +238,9 @@ object SupervisorHierarchySpec {
|
|||
abort("invariant violated: " + state.kids.size + " != " + context.children.size)
|
||||
}
|
||||
cause match {
|
||||
case f: Failure if f.failPost > 0 ⇒ { f.failPost -= 1; throw f }
|
||||
case PostRestartException(`self`, f: Failure, _) if f.failPost > 0 ⇒ { f.failPost -= 1; throw f }
|
||||
case _ ⇒
|
||||
case f: Failure if f.failPost > 0 => { f.failPost -= 1; throw f }
|
||||
case PostRestartException(`self`, f: Failure, _) if f.failPost > 0 => { f.failPost -= 1; throw f }
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -275,14 +275,14 @@ object SupervisorHierarchySpec {
|
|||
|
||||
def receive = new Receive {
|
||||
val handler: Receive = {
|
||||
case f: Failure ⇒
|
||||
case f: Failure =>
|
||||
setFlags(f.directive)
|
||||
stateCache.put(self.path, stateCache.get(self.path).copy(failConstr = f.copy()))
|
||||
throw f
|
||||
case "ping" ⇒ { Thread.sleep((random.nextFloat * 1.03).toLong); sender() ! "pong" }
|
||||
case Dump(0) ⇒ abort("dump")
|
||||
case Dump(level) ⇒ context.children foreach (_ ! Dump(level - 1))
|
||||
case Terminated(ref) ⇒
|
||||
case "ping" => { Thread.sleep((random.nextFloat * 1.03).toLong); sender() ! "pong" }
|
||||
case Dump(0) => abort("dump")
|
||||
case Dump(level) => context.children foreach (_ ! Dump(level - 1))
|
||||
case Terminated(ref) =>
|
||||
/*
|
||||
* It might be that we acted upon this death already in postRestart
|
||||
* (if the unwatch() came too late), so just ignore in this case.
|
||||
|
|
@ -301,8 +301,8 @@ object SupervisorHierarchySpec {
|
|||
// an indication of duplicate Terminate messages
|
||||
log :+= Event(sender() + " terminated while pongOfDeath", identityHashCode(Hierarchy.this))
|
||||
}
|
||||
case Abort ⇒ abort("terminating")
|
||||
case PingOfDeath ⇒
|
||||
case Abort => abort("terminating")
|
||||
case PingOfDeath =>
|
||||
if (size > 1) {
|
||||
pongsToGo = context.children.size
|
||||
log :+= Event("sending " + pongsToGo + " pingOfDeath", identityHashCode(Hierarchy.this))
|
||||
|
|
@ -311,7 +311,7 @@ object SupervisorHierarchySpec {
|
|||
context stop self
|
||||
context.parent ! PongOfDeath
|
||||
}
|
||||
case PongOfDeath ⇒
|
||||
case PongOfDeath =>
|
||||
pongsToGo -= 1
|
||||
if (pongsToGo == 0) {
|
||||
context stop self
|
||||
|
|
@ -406,10 +406,10 @@ object SupervisorHierarchySpec {
|
|||
|
||||
// don’t escalate from this one!
|
||||
override val supervisorStrategy = OneForOneStrategy() {
|
||||
case f: Failure ⇒ f.directive
|
||||
case OriginalRestartException(f: Failure) ⇒ f.directive
|
||||
case ActorInitializationException(_, _, f: Failure) ⇒ f.directive
|
||||
case _ ⇒ Stop
|
||||
case f: Failure => f.directive
|
||||
case OriginalRestartException(f: Failure) => f.directive
|
||||
case ActorInitializationException(_, _, f: Failure) => f.directive
|
||||
case _ => Stop
|
||||
}
|
||||
|
||||
var children = Vector.empty[ActorRef]
|
||||
|
|
@ -418,14 +418,14 @@ object SupervisorHierarchySpec {
|
|||
var pingChildren = Set.empty[ActorRef]
|
||||
|
||||
val nextJob = Iterator.continually(random.nextFloat match {
|
||||
case x if x >= 0.5 ⇒
|
||||
case x if x >= 0.5 =>
|
||||
// ping one child
|
||||
val pick = ((x - 0.5) * 2 * idleChildren.size).toInt
|
||||
val ref = idleChildren(pick)
|
||||
idleChildren = idleChildren.take(pick) ++ idleChildren.drop(pick + 1)
|
||||
pingChildren += ref
|
||||
Ping(ref)
|
||||
case x ⇒
|
||||
case x =>
|
||||
// fail one child
|
||||
val pick = ((if (x >= 0.25) x - 0.25 else x) * 4 * activeChildren.size).toInt
|
||||
Fail(activeChildren(pick), if (x > 0.25) Restart else Resume)
|
||||
|
|
@ -449,14 +449,14 @@ object SupervisorHierarchySpec {
|
|||
startWith(Idle, size * 1000)
|
||||
|
||||
when(Idle) {
|
||||
case Event(Init, _) ⇒
|
||||
case Event(Init, _) =>
|
||||
hierarchy = context.watch(context.actorOf(Props(new Hierarchy(size, breadth, self, 0, random)).withDispatcher("hierarchy"), "head"))
|
||||
setTimer("phase", StateTimeout, 5 seconds, false)
|
||||
goto(Init)
|
||||
}
|
||||
|
||||
when(Init) {
|
||||
case Event(Ready(ref), _) ⇒
|
||||
case Event(Ready(ref), _) =>
|
||||
if (children contains ref) {
|
||||
testActor ! "children not unique"
|
||||
stop()
|
||||
|
|
@ -465,13 +465,13 @@ object SupervisorHierarchySpec {
|
|||
if (children.size == size) goto(Stress)
|
||||
else stay
|
||||
}
|
||||
case Event(StateTimeout, _) ⇒
|
||||
case Event(StateTimeout, _) =>
|
||||
testActor ! "did not get children list"
|
||||
stop()
|
||||
}
|
||||
|
||||
onTransition {
|
||||
case Init → Stress ⇒
|
||||
case Init -> Stress =>
|
||||
self ! Work
|
||||
idleChildren = children
|
||||
activeChildren = children
|
||||
|
|
@ -482,14 +482,14 @@ object SupervisorHierarchySpec {
|
|||
val workSchedule = 50.millis
|
||||
|
||||
private def random012: Int = random.nextFloat match {
|
||||
case x if x > 0.1 ⇒ 0
|
||||
case x if x > 0.03 ⇒ 1
|
||||
case _ ⇒ 2
|
||||
case x if x > 0.1 => 0
|
||||
case x if x > 0.03 => 1
|
||||
case _ => 2
|
||||
}
|
||||
private def bury(path: ActorPath): Unit = {
|
||||
val deadGuy = path.elements
|
||||
val deadGuySize = deadGuy.size
|
||||
val isChild = (other: ActorRef) ⇒ other.path.elements.take(deadGuySize) == deadGuy
|
||||
val isChild = (other: ActorRef) => other.path.elements.take(deadGuySize) == deadGuy
|
||||
activeChildren = activeChildren filterNot isChild
|
||||
idleChildren = idleChildren filterNot isChild
|
||||
pingChildren = pingChildren filterNot isChild
|
||||
|
|
@ -498,33 +498,33 @@ object SupervisorHierarchySpec {
|
|||
var ignoreNotResumedLogs = true
|
||||
|
||||
when(Stress) {
|
||||
case Event(Work, _) if idleChildren.isEmpty ⇒
|
||||
case Event(Work, _) if idleChildren.isEmpty =>
|
||||
context.system.scheduler.scheduleOnce(workSchedule, self, Work)(context.dispatcher)
|
||||
stay
|
||||
case Event(Work, x) if x > 0 ⇒
|
||||
case Event(Work, x) if x > 0 =>
|
||||
nextJob.next match {
|
||||
case Ping(ref) ⇒ ref ! "ping"
|
||||
case Fail(ref, dir) ⇒
|
||||
case Ping(ref) => ref ! "ping"
|
||||
case Fail(ref, dir) =>
|
||||
val f = Failure(dir, stop = random012 > 0, depth = random012, failPre = random012, failPost = random012, failConstr = random012,
|
||||
stopKids = random012 match {
|
||||
case 0 ⇒ 0
|
||||
case 1 ⇒ random.nextInt(breadth / 2)
|
||||
case 2 ⇒ 1000
|
||||
case 0 => 0
|
||||
case 1 => random.nextInt(breadth / 2)
|
||||
case 2 => 1000
|
||||
})
|
||||
ref ! f
|
||||
}
|
||||
if (idleChildren.nonEmpty) self ! Work
|
||||
else context.system.scheduler.scheduleOnce(workSchedule, self, Work)(context.dispatcher)
|
||||
stay using (x - 1)
|
||||
case Event(Work, _) ⇒ if (pingChildren.isEmpty) goto(LastPing) else goto(Finishing)
|
||||
case Event(Died(path), _) ⇒
|
||||
case Event(Work, _) => if (pingChildren.isEmpty) goto(LastPing) else goto(Finishing)
|
||||
case Event(Died(path), _) =>
|
||||
bury(path)
|
||||
stay
|
||||
case Event("pong", _) ⇒
|
||||
case Event("pong", _) =>
|
||||
pingChildren -= sender()
|
||||
idleChildren :+= sender()
|
||||
stay
|
||||
case Event(StateTimeout, todo) ⇒
|
||||
case Event(StateTimeout, todo) =>
|
||||
log.info("dumping state due to StateTimeout")
|
||||
log.info("children: " + children.size + " pinged: " + pingChildren.size + " idle: " + idleChildren.size + " work: " + todo)
|
||||
pingChildren foreach println
|
||||
|
|
@ -536,45 +536,45 @@ object SupervisorHierarchySpec {
|
|||
}
|
||||
|
||||
onTransition {
|
||||
case Stress → Finishing ⇒ ignoreFailConstr = true
|
||||
case Stress -> Finishing => ignoreFailConstr = true
|
||||
}
|
||||
|
||||
when(Finishing) {
|
||||
case Event("pong", _) ⇒
|
||||
case Event("pong", _) =>
|
||||
pingChildren -= sender()
|
||||
idleChildren :+= sender()
|
||||
if (pingChildren.isEmpty) goto(LastPing) else stay
|
||||
case Event(Died(ref), _) ⇒
|
||||
case Event(Died(ref), _) =>
|
||||
bury(ref)
|
||||
if (pingChildren.isEmpty) goto(LastPing) else stay
|
||||
}
|
||||
|
||||
onTransition {
|
||||
case _ → LastPing ⇒
|
||||
case _ -> LastPing =>
|
||||
idleChildren foreach (_ ! "ping")
|
||||
pingChildren ++= idleChildren
|
||||
idleChildren = Vector.empty
|
||||
}
|
||||
|
||||
when(LastPing) {
|
||||
case Event("pong", _) ⇒
|
||||
case Event("pong", _) =>
|
||||
pingChildren -= sender()
|
||||
idleChildren :+= sender()
|
||||
if (pingChildren.isEmpty) goto(Stopping) else stay
|
||||
case Event(Died(ref), _) ⇒
|
||||
case Event(Died(ref), _) =>
|
||||
bury(ref)
|
||||
if (pingChildren.isEmpty) goto(Stopping) else stay
|
||||
}
|
||||
|
||||
onTransition {
|
||||
case _ → Stopping ⇒
|
||||
case _ -> Stopping =>
|
||||
ignoreNotResumedLogs = false
|
||||
hierarchy ! PingOfDeath
|
||||
}
|
||||
|
||||
when(Stopping, stateTimeout = 5.seconds.dilated) {
|
||||
case Event(PongOfDeath, _) ⇒ stay
|
||||
case Event(Terminated(r), _) if r == hierarchy ⇒
|
||||
case Event(PongOfDeath, _) => stay
|
||||
case Event(Terminated(r), _) if r == hierarchy =>
|
||||
val undead = children filterNot (_.isTerminated)
|
||||
if (undead.nonEmpty) {
|
||||
log.info("undead:\n" + undead.mkString("\n"))
|
||||
|
|
@ -599,21 +599,21 @@ object SupervisorHierarchySpec {
|
|||
testActor ! "stressTestSuccessful"
|
||||
stop
|
||||
}
|
||||
case Event(StateTimeout, _) ⇒
|
||||
errors :+= self → ErrorLog("timeout while Stopping", Vector.empty)
|
||||
case Event(StateTimeout, _) =>
|
||||
errors :+= self -> ErrorLog("timeout while Stopping", Vector.empty)
|
||||
println(system.asInstanceOf[ActorSystemImpl].printTree)
|
||||
getErrors(hierarchy, 10)
|
||||
printErrors()
|
||||
idleChildren foreach println
|
||||
testActor ! "timeout in Stopping"
|
||||
stop
|
||||
case Event(e: ErrorLog, _) ⇒
|
||||
errors :+= sender() → e
|
||||
case Event(e: ErrorLog, _) =>
|
||||
errors :+= sender() -> e
|
||||
goto(Failed)
|
||||
}
|
||||
|
||||
when(GC, stateTimeout = 10 seconds) {
|
||||
case Event(GCcheck(weak), _) ⇒
|
||||
case Event(GCcheck(weak), _) =>
|
||||
val next = weak filter (_.get ne null)
|
||||
if (next.nonEmpty) {
|
||||
println(next.size + " left")
|
||||
|
|
@ -624,7 +624,7 @@ object SupervisorHierarchySpec {
|
|||
testActor ! "stressTestSuccessful"
|
||||
stop
|
||||
}
|
||||
case Event(StateTimeout, _) ⇒
|
||||
case Event(StateTimeout, _) =>
|
||||
testActor ! "timeout in GC"
|
||||
stop
|
||||
}
|
||||
|
|
@ -632,30 +632,30 @@ object SupervisorHierarchySpec {
|
|||
var errors = Vector.empty[(ActorRef, ErrorLog)]
|
||||
|
||||
when(Failed, stateTimeout = 5.seconds.dilated) {
|
||||
case Event(e: ErrorLog, _) ⇒
|
||||
case Event(e: ErrorLog, _) =>
|
||||
if (!e.msg.startsWith("not resumed") || !ignoreNotResumedLogs)
|
||||
errors :+= sender() → e
|
||||
errors :+= sender() -> e
|
||||
stay
|
||||
case Event(Terminated(r), _) if r == hierarchy ⇒
|
||||
case Event(Terminated(r), _) if r == hierarchy =>
|
||||
printErrors()
|
||||
testActor ! "stressTestFailed"
|
||||
stop
|
||||
case Event(StateTimeout, _) ⇒
|
||||
case Event(StateTimeout, _) =>
|
||||
getErrors(hierarchy, 10)
|
||||
printErrors()
|
||||
testActor ! "timeout in Failed"
|
||||
stop
|
||||
case Event("pong", _) ⇒ stay // don’t care?
|
||||
case Event(Work, _) ⇒ stay
|
||||
case Event(Died(_), _) ⇒ stay
|
||||
case Event("pong", _) => stay // don’t care?
|
||||
case Event(Work, _) => stay
|
||||
case Event(Died(_), _) => stay
|
||||
}
|
||||
|
||||
def getErrors(target: ActorRef, depth: Int): Unit = {
|
||||
target match {
|
||||
case l: LocalActorRef ⇒
|
||||
case l: LocalActorRef =>
|
||||
l.underlying.actor match {
|
||||
case h: Hierarchy ⇒ errors :+= target → ErrorLog("forced", h.log)
|
||||
case _ ⇒ errors :+= target → ErrorLog("fetched", stateCache.get(target.path).log)
|
||||
case h: Hierarchy => errors :+= target -> ErrorLog("forced", h.log)
|
||||
case _ => errors :+= target -> ErrorLog("fetched", stateCache.get(target.path).log)
|
||||
}
|
||||
if (depth > 0) {
|
||||
l.underlying.children foreach (getErrors(_, depth - 1))
|
||||
|
|
@ -665,10 +665,10 @@ object SupervisorHierarchySpec {
|
|||
|
||||
def getErrorsUp(target: ActorRef): Unit = {
|
||||
target match {
|
||||
case l: LocalActorRef ⇒
|
||||
case l: LocalActorRef =>
|
||||
l.underlying.actor match {
|
||||
case h: Hierarchy ⇒ errors :+= target → ErrorLog("forced", h.log)
|
||||
case _ ⇒ errors :+= target → ErrorLog("fetched", stateCache.get(target.path).log)
|
||||
case h: Hierarchy => errors :+= target -> ErrorLog("forced", h.log)
|
||||
case _ => errors :+= target -> ErrorLog("fetched", stateCache.get(target.path).log)
|
||||
}
|
||||
if (target != hierarchy) getErrorsUp(l.getParent)
|
||||
}
|
||||
|
|
@ -676,32 +676,32 @@ object SupervisorHierarchySpec {
|
|||
|
||||
def printErrors(): Unit = {
|
||||
errors collect {
|
||||
case (origin, ErrorLog("dump", _)) ⇒ getErrors(origin, 1)
|
||||
case (origin, ErrorLog(msg, _)) if msg startsWith "not resumed" ⇒ getErrorsUp(origin)
|
||||
case (origin, ErrorLog("dump", _)) => getErrors(origin, 1)
|
||||
case (origin, ErrorLog(msg, _)) if msg startsWith "not resumed" => getErrorsUp(origin)
|
||||
}
|
||||
val merged = errors.sortBy(_._1.toString) flatMap {
|
||||
case (ref, ErrorLog(msg, log)) ⇒
|
||||
case (ref, ErrorLog(msg, log)) =>
|
||||
println("Error: " + ref + " " + msg)
|
||||
log map (l ⇒ (l.time, ref, l.identity, l.msg.toString))
|
||||
log map (l => (l.time, ref, l.identity, l.msg.toString))
|
||||
}
|
||||
println("random seed: " + randomSeed)
|
||||
merged.sorted.distinct foreach println
|
||||
}
|
||||
|
||||
whenUnhandled {
|
||||
case Event(Ready(ref), _) ⇒
|
||||
case Event(Ready(ref), _) =>
|
||||
activeChildren :+= ref
|
||||
children :+= ref
|
||||
idleChildren :+= ref
|
||||
stay
|
||||
case Event(e: ErrorLog, _) ⇒
|
||||
case Event(e: ErrorLog, _) =>
|
||||
if (e.msg.startsWith("not resumed")) stay
|
||||
else {
|
||||
errors :+= sender() → e
|
||||
errors :+= sender() -> e
|
||||
// don’t stop the hierarchy, that is going to happen all by itself and in the right order
|
||||
goto(Failed)
|
||||
}
|
||||
case Event(StateTimeout, _) ⇒
|
||||
case Event(StateTimeout, _) =>
|
||||
println("pingChildren:\n" + pingChildren.view.map(_.path.toString).toSeq.sorted.mkString("\n"))
|
||||
ignoreNotResumedLogs = false
|
||||
// make sure that we get the logs of the remaining pingChildren
|
||||
|
|
@ -709,10 +709,10 @@ object SupervisorHierarchySpec {
|
|||
// this will ensure that the error logs get printed and we stop the test
|
||||
context stop hierarchy
|
||||
goto(Failed)
|
||||
case Event(Abort, _) ⇒
|
||||
case Event(Abort, _) =>
|
||||
log.info("received Abort")
|
||||
goto(Failed)
|
||||
case Event(msg, _) ⇒
|
||||
case Event(msg, _) =>
|
||||
testActor ! ("received unexpected msg: " + msg)
|
||||
stop
|
||||
}
|
||||
|
|
@ -760,8 +760,8 @@ class SupervisorHierarchySpec extends AkkaSpec(SupervisorHierarchySpec.config) w
|
|||
val crasher = context.watch(context.actorOf(Props(new CountDownActor(countDownMessages, SupervisorStrategy.defaultStrategy))))
|
||||
|
||||
def receive = {
|
||||
case "killCrasher" ⇒ crasher ! Kill
|
||||
case Terminated(_) ⇒ countDownMax.countDown()
|
||||
case "killCrasher" => crasher ! Kill
|
||||
case Terminated(_) => countDownMax.countDown()
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -794,9 +794,9 @@ class SupervisorHierarchySpec extends AkkaSpec(SupervisorHierarchySpec.config) w
|
|||
"suspend children while failing" taggedAs LongRunningTest in {
|
||||
val latch = TestLatch()
|
||||
val slowResumer = system.actorOf(Props(new Actor {
|
||||
override def supervisorStrategy = OneForOneStrategy() { case _ ⇒ Await.ready(latch, 4.seconds.dilated); SupervisorStrategy.Resume }
|
||||
override def supervisorStrategy = OneForOneStrategy() { case _ => Await.ready(latch, 4.seconds.dilated); SupervisorStrategy.Resume }
|
||||
def receive = {
|
||||
case "spawn" ⇒ sender() ! context.actorOf(Props[Resumer])
|
||||
case "spawn" => sender() ! context.actorOf(Props[Resumer])
|
||||
}
|
||||
}), "slowResumer")
|
||||
slowResumer ! "spawn"
|
||||
|
|
@ -830,7 +830,7 @@ class SupervisorHierarchySpec extends AkkaSpec(SupervisorHierarchySpec.config) w
|
|||
EventFilter.error(start = "changing Resume into Create")) {
|
||||
val failResumer = system.actorOf(Props(new Actor {
|
||||
override def supervisorStrategy = OneForOneStrategy() {
|
||||
case e: ActorInitializationException ⇒
|
||||
case e: ActorInitializationException =>
|
||||
if (createAttempt.get % 2 == 0) SupervisorStrategy.Resume else SupervisorStrategy.Restart
|
||||
}
|
||||
|
||||
|
|
@ -838,7 +838,7 @@ class SupervisorHierarchySpec extends AkkaSpec(SupervisorHierarchySpec.config) w
|
|||
val ca = createAttempt.incrementAndGet()
|
||||
|
||||
if (ca <= 6 && ca % 3 == 0)
|
||||
context.actorOf(Props(new Actor { override def receive = { case _ ⇒ } }), "workingChild")
|
||||
context.actorOf(Props(new Actor { override def receive = { case _ => } }), "workingChild")
|
||||
|
||||
if (ca < 6) {
|
||||
throw new IllegalArgumentException("OH NO!")
|
||||
|
|
@ -850,12 +850,12 @@ class SupervisorHierarchySpec extends AkkaSpec(SupervisorHierarchySpec.config) w
|
|||
postRestartCalled.incrementAndGet()
|
||||
}
|
||||
override def receive = {
|
||||
case m ⇒ sender() ! m
|
||||
case m => sender() ! m
|
||||
}
|
||||
}), "failChild")
|
||||
|
||||
override def receive = {
|
||||
case m ⇒ child.forward(m)
|
||||
case m => child.forward(m)
|
||||
}
|
||||
}), "failResumer")
|
||||
|
||||
|
|
@ -882,8 +882,8 @@ class SupervisorHierarchySpec extends AkkaSpec(SupervisorHierarchySpec.config) w
|
|||
|
||||
fsm ! FSM.SubscribeTransitionCallBack(system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case s: FSM.CurrentState[_] ⇒ log.info("{}", s)
|
||||
case t: FSM.Transition[_] ⇒ log.info("{}", t)
|
||||
case s: FSM.CurrentState[_] => log.info("{}", s)
|
||||
case t: FSM.Transition[_] => log.info("{}", t)
|
||||
}
|
||||
})))
|
||||
|
||||
|
|
|
|||
|
|
@ -41,8 +41,8 @@ class SupervisorMiscSpec extends AkkaSpec(SupervisorMiscSpec.config) with Defaul
|
|||
val workerProps = Props(new Actor {
|
||||
override def postRestart(cause: Throwable): Unit = { countDownLatch.countDown() }
|
||||
def receive = {
|
||||
case "status" ⇒ this.sender() ! "OK"
|
||||
case _ ⇒ this.context.stop(self)
|
||||
case "status" => this.sender() ! "OK"
|
||||
case _ => this.context.stop(self)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -59,10 +59,10 @@ class SupervisorMiscSpec extends AkkaSpec(SupervisorMiscSpec.config) with Defaul
|
|||
|
||||
countDownLatch.await(10, TimeUnit.SECONDS)
|
||||
|
||||
Seq("actor1" → actor1, "actor2" → actor2, "actor3" → actor3, "actor4" → actor4) map {
|
||||
case (id, ref) ⇒ (id, ref ? "status")
|
||||
Seq("actor1" -> actor1, "actor2" -> actor2, "actor3" -> actor3, "actor4" -> actor4) map {
|
||||
case (id, ref) => (id, ref ? "status")
|
||||
} foreach {
|
||||
case (id, f) ⇒ (id, Await.result(f, timeout.duration)) should ===((id, "OK"))
|
||||
case (id, f) => (id, Await.result(f, timeout.duration)) should ===((id, "OK"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ class SupervisorMiscSpec extends AkkaSpec(SupervisorMiscSpec.config) with Defaul
|
|||
"be able to create named children in its constructor" in {
|
||||
val a = system.actorOf(Props(new Actor {
|
||||
context.actorOf(Props.empty, "bob")
|
||||
def receive = { case x: Exception ⇒ throw x }
|
||||
def receive = { case x: Exception => throw x }
|
||||
override def preStart(): Unit = testActor ! "preStart"
|
||||
}))
|
||||
val m = "weird message"
|
||||
|
|
@ -86,7 +86,7 @@ class SupervisorMiscSpec extends AkkaSpec(SupervisorMiscSpec.config) with Defaul
|
|||
val parent = system.actorOf(Props(new Actor {
|
||||
val kid = context.watch(context.actorOf(Props.empty, "foo"))
|
||||
def receive = {
|
||||
case Terminated(`kid`) ⇒
|
||||
case Terminated(`kid`) =>
|
||||
try {
|
||||
val newKid = context.actorOf(Props.empty, "foo")
|
||||
val result =
|
||||
|
|
@ -97,9 +97,9 @@ class SupervisorMiscSpec extends AkkaSpec(SupervisorMiscSpec.config) with Defaul
|
|||
else "green"
|
||||
testActor ! result
|
||||
} catch {
|
||||
case NonFatal(e) ⇒ testActor ! e
|
||||
case NonFatal(e) => testActor ! e
|
||||
}
|
||||
case "engage" ⇒ context.stop(kid)
|
||||
case "engage" => context.stop(kid)
|
||||
}
|
||||
}))
|
||||
parent ! "engage"
|
||||
|
|
@ -109,14 +109,14 @@ class SupervisorMiscSpec extends AkkaSpec(SupervisorMiscSpec.config) with Defaul
|
|||
"not be able to recreate child when old child is alive" in {
|
||||
val parent = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "engage" ⇒
|
||||
case "engage" =>
|
||||
try {
|
||||
val kid = context.actorOf(Props.empty, "foo")
|
||||
context.stop(kid)
|
||||
context.actorOf(Props.empty, "foo")
|
||||
testActor ! "red"
|
||||
} catch {
|
||||
case e: InvalidActorNameException ⇒ testActor ! "green"
|
||||
case e: InvalidActorNameException => testActor ! "green"
|
||||
}
|
||||
}
|
||||
}))
|
||||
|
|
@ -133,7 +133,7 @@ class SupervisorMiscSpec extends AkkaSpec(SupervisorMiscSpec.config) with Defaul
|
|||
}
|
||||
}
|
||||
|
||||
def receive = { case "engage" ⇒ context.stop(context.actorOf(Props.empty, "Robert")) }
|
||||
def receive = { case "engage" => context.stop(context.actorOf(Props.empty, "Robert")) }
|
||||
}))
|
||||
parent ! "engage"
|
||||
expectMsg("green")
|
||||
|
|
@ -145,10 +145,10 @@ class SupervisorMiscSpec extends AkkaSpec(SupervisorMiscSpec.config) with Defaul
|
|||
"have access to the failing child’s reference in supervisorStrategy" in {
|
||||
val parent = system.actorOf(Props(new Actor {
|
||||
override val supervisorStrategy = OneForOneStrategy() {
|
||||
case _: Exception ⇒ testActor ! sender(); SupervisorStrategy.Stop
|
||||
case _: Exception => testActor ! sender(); SupervisorStrategy.Stop
|
||||
}
|
||||
def receive = {
|
||||
case "doit" ⇒ context.actorOf(Props.empty, "child") ! Kill
|
||||
case "doit" => context.actorOf(Props.empty, "child") ! Kill
|
||||
}
|
||||
}))
|
||||
EventFilter[ActorKilledException](occurrences = 1) intercept {
|
||||
|
|
|
|||
|
|
@ -39,13 +39,13 @@ object SupervisorSpec {
|
|||
|
||||
class PingPongActor(sendTo: ActorRef) extends Actor {
|
||||
def receive = {
|
||||
case Ping ⇒
|
||||
case Ping =>
|
||||
sendTo ! PingMessage
|
||||
if (sender() != sendTo)
|
||||
sender() ! PongMessage
|
||||
case Die ⇒
|
||||
case Die =>
|
||||
throw new RuntimeException(ExceptionMessage)
|
||||
case DieReply ⇒
|
||||
case DieReply =>
|
||||
val e = new RuntimeException(ExceptionMessage)
|
||||
sender() ! Status.Failure(e)
|
||||
throw e
|
||||
|
|
@ -64,20 +64,20 @@ object SupervisorSpec {
|
|||
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 0)(List(classOf[Exception]))
|
||||
|
||||
def receive = {
|
||||
case Die ⇒ temp forward Die
|
||||
case Terminated(`temp`) ⇒ sendTo ! "terminated"
|
||||
case Status.Failure(_) ⇒ /*Ignore*/
|
||||
case Die => temp forward Die
|
||||
case Terminated(`temp`) => sendTo ! "terminated"
|
||||
case Status.Failure(_) => /*Ignore*/
|
||||
}
|
||||
}
|
||||
|
||||
class Creator(target: ActorRef) extends Actor {
|
||||
override val supervisorStrategy = OneForOneStrategy() {
|
||||
case ex ⇒
|
||||
case ex =>
|
||||
target ! ((self, sender(), ex))
|
||||
SupervisorStrategy.Stop
|
||||
}
|
||||
def receive = {
|
||||
case p: Props ⇒ sender() ! context.actorOf(p)
|
||||
case p: Props => sender() ! context.actorOf(p)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -211,15 +211,15 @@ class SupervisorSpec extends AkkaSpec(SupervisorSpec.config) with BeforeAndAfter
|
|||
override def preStart(): Unit = { preStarts += 1; testActor ! ("preStart" + preStarts) }
|
||||
override def postStop(): Unit = { postStops += 1; testActor ! ("postStop" + postStops) }
|
||||
def receive = {
|
||||
case "crash" ⇒ { testActor ! "crashed"; throw new RuntimeException("Expected") }
|
||||
case "ping" ⇒ sender() ! "pong"
|
||||
case "crash" => { testActor ! "crashed"; throw new RuntimeException("Expected") }
|
||||
case "ping" => sender() ! "pong"
|
||||
}
|
||||
}
|
||||
val master = system.actorOf(Props(new Actor {
|
||||
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = restarts)(List(classOf[Exception]))
|
||||
val child = context.actorOf(Props(childInstance))
|
||||
def receive = {
|
||||
case msg ⇒ child forward msg
|
||||
case msg => child forward msg
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -230,7 +230,7 @@ class SupervisorSpec extends AkkaSpec(SupervisorSpec.config) with BeforeAndAfter
|
|||
|
||||
filterEvents(EventFilter[RuntimeException]("Expected", occurrences = restarts + 1)) {
|
||||
(1 to restarts) foreach {
|
||||
i ⇒
|
||||
i =>
|
||||
master ! "crash"
|
||||
expectMsg("crashed")
|
||||
|
||||
|
|
@ -389,8 +389,8 @@ class SupervisorSpec extends AkkaSpec(SupervisorSpec.config) with BeforeAndAfter
|
|||
}
|
||||
|
||||
def receive = {
|
||||
case Ping ⇒ sender() ! PongMessage
|
||||
case DieReply ⇒
|
||||
case Ping => sender() ! PongMessage
|
||||
case DieReply =>
|
||||
val e = new RuntimeException("Expected")
|
||||
sender() ! Status.Failure(e)
|
||||
throw e
|
||||
|
|
@ -419,14 +419,14 @@ class SupervisorSpec extends AkkaSpec(SupervisorSpec.config) with BeforeAndAfter
|
|||
"not lose system messages when a NonFatal exception occurs when processing a system message" in {
|
||||
val parent = system.actorOf(Props(new Actor {
|
||||
override val supervisorStrategy = OneForOneStrategy()({
|
||||
case e: IllegalStateException if e.getMessage == "OHNOES" ⇒ throw e
|
||||
case _ ⇒ SupervisorStrategy.Restart
|
||||
case e: IllegalStateException if e.getMessage == "OHNOES" => throw e
|
||||
case _ => SupervisorStrategy.Restart
|
||||
})
|
||||
val child = context.watch(context.actorOf(Props(new Actor {
|
||||
override def postRestart(reason: Throwable): Unit = testActor ! "child restarted"
|
||||
def receive = {
|
||||
case l: TestLatch ⇒ { Await.ready(l, 5 seconds); throw new IllegalStateException("OHNOES") }
|
||||
case "test" ⇒ sender() ! "child green"
|
||||
case l: TestLatch => { Await.ready(l, 5 seconds); throw new IllegalStateException("OHNOES") }
|
||||
case "test" => sender() ! "child green"
|
||||
}
|
||||
}), "child"))
|
||||
|
||||
|
|
@ -439,11 +439,11 @@ class SupervisorSpec extends AkkaSpec(SupervisorSpec.config) with BeforeAndAfter
|
|||
}
|
||||
|
||||
def receive = {
|
||||
case Terminated(a) if a.path == child.path ⇒ testActor ! "child terminated"
|
||||
case l: TestLatch ⇒ child ! l
|
||||
case "test" ⇒ sender() ! "green"
|
||||
case "testchild" ⇒ child forward "test"
|
||||
case "testchildAndAck" ⇒ child forward "test"; sender() ! "ack"
|
||||
case Terminated(a) if a.path == child.path => testActor ! "child terminated"
|
||||
case l: TestLatch => child ! l
|
||||
case "test" => sender() ! "green"
|
||||
case "testchild" => child forward "test"
|
||||
case "testchildAndAck" => child forward "test"; sender() ! "ack"
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -478,7 +478,7 @@ class SupervisorSpec extends AkkaSpec(SupervisorSpec.config) with BeforeAndAfter
|
|||
val middle = expectMsgType[ActorRef]
|
||||
middle ! creator(testActor, fail = true)
|
||||
expectMsgPF(hint = "ConfigurationException") {
|
||||
case (top, middle, ex: ConfigurationException) ⇒
|
||||
case (top, middle, ex: ConfigurationException) =>
|
||||
ex.getCause should ===(failure)
|
||||
}
|
||||
}
|
||||
|
|
@ -495,7 +495,7 @@ class SupervisorSpec extends AkkaSpec(SupervisorSpec.config) with BeforeAndAfter
|
|||
val middle = expectMsgType[ActorRef]
|
||||
middle ! creator(testActor, fail = true).withRouter(RoundRobinPool(1))
|
||||
expectMsgPF(hint = "ConfigurationException") {
|
||||
case (top, middle, ex: ConfigurationException) ⇒
|
||||
case (top, middle, ex: ConfigurationException) =>
|
||||
ex.getCause should ===(failure)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class SupervisorTreeSpec extends AkkaSpec("akka.actor.serialize-messages = off")
|
|||
val p = Props(new Actor {
|
||||
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 3, withinTimeRange = 1 second)(List(classOf[Exception]))
|
||||
def receive = {
|
||||
case p: Props ⇒ sender() ! context.actorOf(p)
|
||||
case p: Props => sender() ! context.actorOf(p)
|
||||
}
|
||||
override def preRestart(cause: Throwable, msg: Option[Any]): Unit = { testActor ! self.path }
|
||||
})
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class Ticket669Spec extends AkkaSpec with BeforeAndAfterAll with ImplicitSender
|
|||
object Ticket669Spec {
|
||||
class Supervised extends Actor {
|
||||
def receive = {
|
||||
case msg ⇒ throw new Exception("test")
|
||||
case msg => throw new Exception("test")
|
||||
}
|
||||
|
||||
override def preRestart(reason: scala.Throwable, msg: Option[Any]): Unit = {
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ object TimerSpec {
|
|||
|
||||
class Exc extends RuntimeException("simulated exc") with NoStackTrace
|
||||
|
||||
def target(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () ⇒ Int): Props =
|
||||
def target(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () => Int): Props =
|
||||
Props(new Target(monitor, interval, repeat, initial))
|
||||
|
||||
class Target(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () ⇒ Int) extends Actor with Timers {
|
||||
class Target(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () => Int) extends Actor with Timers {
|
||||
private var bumpCount = initial()
|
||||
|
||||
if (repeat)
|
||||
|
|
@ -61,32 +61,32 @@ object TimerSpec {
|
|||
}
|
||||
|
||||
override def receive = {
|
||||
case Tick(n) ⇒
|
||||
case Tick(n) =>
|
||||
monitor ! Tock(n)
|
||||
case Bump ⇒
|
||||
case Bump =>
|
||||
bump()
|
||||
case SlowThenBump(latch) ⇒
|
||||
case SlowThenBump(latch) =>
|
||||
Await.ready(latch, 10.seconds)
|
||||
bump()
|
||||
case End ⇒
|
||||
case End =>
|
||||
context.stop(self)
|
||||
case Cancel ⇒
|
||||
case Cancel =>
|
||||
timers.cancel("T")
|
||||
case Throw(e) ⇒
|
||||
case Throw(e) =>
|
||||
throw e
|
||||
case SlowThenThrow(latch, e) ⇒
|
||||
case SlowThenThrow(latch, e) =>
|
||||
Await.ready(latch, 10.seconds)
|
||||
throw e
|
||||
case AutoReceive ⇒ autoReceive()
|
||||
case AutoReceive => autoReceive()
|
||||
}
|
||||
}
|
||||
|
||||
def fsmTarget(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () ⇒ Int): Props =
|
||||
def fsmTarget(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () => Int): Props =
|
||||
Props(new FsmTarget(monitor, interval, repeat, initial))
|
||||
|
||||
object TheState
|
||||
|
||||
class FsmTarget(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () ⇒ Int) extends FSM[TheState.type, Int] {
|
||||
class FsmTarget(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () => Int) extends FSM[TheState.type, Int] {
|
||||
|
||||
private var restarting = false
|
||||
|
||||
|
|
@ -119,25 +119,25 @@ object TimerSpec {
|
|||
}
|
||||
|
||||
when(TheState) {
|
||||
case Event(Tick(n), _) ⇒
|
||||
case Event(Tick(n), _) =>
|
||||
monitor ! Tock(n)
|
||||
stay
|
||||
case Event(Bump, bumpCount) ⇒
|
||||
case Event(Bump, bumpCount) =>
|
||||
bump(bumpCount)
|
||||
case Event(SlowThenBump(latch), bumpCount) ⇒
|
||||
case Event(SlowThenBump(latch), bumpCount) =>
|
||||
Await.ready(latch, 10.seconds)
|
||||
bump(bumpCount)
|
||||
case Event(End, _) ⇒
|
||||
case Event(End, _) =>
|
||||
stop()
|
||||
case Event(Cancel, _) ⇒
|
||||
case Event(Cancel, _) =>
|
||||
cancelTimer("T")
|
||||
stay
|
||||
case Event(Throw(e), _) ⇒
|
||||
case Event(Throw(e), _) =>
|
||||
throw e
|
||||
case Event(SlowThenThrow(latch, e), _) ⇒
|
||||
case Event(SlowThenThrow(latch, e), _) =>
|
||||
Await.ready(latch, 10.seconds)
|
||||
throw e
|
||||
case Event(AutoReceive, _) ⇒
|
||||
case Event(AutoReceive, _) =>
|
||||
autoReceive()
|
||||
}
|
||||
|
||||
|
|
@ -148,13 +148,13 @@ object TimerSpec {
|
|||
|
||||
class TimerSpec extends AbstractTimerSpec {
|
||||
override def testName: String = "Timers"
|
||||
override def target(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () ⇒ Int = () ⇒ 1): Props =
|
||||
override def target(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () => Int = () => 1): Props =
|
||||
TimerSpec.target(monitor, interval, repeat, initial)
|
||||
}
|
||||
|
||||
class FsmTimerSpec extends AbstractTimerSpec {
|
||||
override def testName: String = "FSM Timers"
|
||||
override def target(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () ⇒ Int = () ⇒ 1): Props =
|
||||
override def target(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () => Int = () => 1): Props =
|
||||
TimerSpec.fsmTarget(monitor, interval, repeat, initial)
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ abstract class AbstractTimerSpec extends AkkaSpec {
|
|||
val interval = 1.second
|
||||
val dilatedInterval = interval.dilated
|
||||
|
||||
def target(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () ⇒ Int = () ⇒ 1): Props
|
||||
def target(monitor: ActorRef, interval: FiniteDuration, repeat: Boolean, initial: () => Int = () => 1): Props
|
||||
|
||||
def testName: String
|
||||
|
||||
|
|
@ -233,7 +233,7 @@ abstract class AbstractTimerSpec extends AkkaSpec {
|
|||
val probe = TestProbe()
|
||||
val startCounter = new AtomicInteger(0)
|
||||
val ref = system.actorOf(target(probe.ref, dilatedInterval, repeat = true,
|
||||
initial = () ⇒ startCounter.incrementAndGet()))
|
||||
initial = () => startCounter.incrementAndGet()))
|
||||
probe.expectMsg(Tock(1))
|
||||
|
||||
val latch = new TestLatch(1)
|
||||
|
|
@ -300,14 +300,14 @@ class TimersAndStashSpec extends AkkaSpec {
|
|||
timers.startSingleTimer("key", "scheduled", 50.millis)
|
||||
def receive: Receive = stashing
|
||||
def notStashing: Receive = {
|
||||
case msg ⇒ probe ! msg
|
||||
case msg => probe ! msg
|
||||
}
|
||||
|
||||
def stashing: Receive = {
|
||||
case StopStashing ⇒
|
||||
case StopStashing =>
|
||||
context.become(notStashing)
|
||||
unstashAll()
|
||||
case "scheduled" ⇒
|
||||
case "scheduled" =>
|
||||
probe ! "saw-scheduled"
|
||||
stash()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicReference
|
|||
import java.util.concurrent.{ CountDownLatch, TimeUnit, TimeoutException }
|
||||
|
||||
import akka.actor.TypedActor._
|
||||
import akka.japi.{ Option ⇒ JOption }
|
||||
import akka.japi.{ Option => JOption }
|
||||
import akka.pattern.ask
|
||||
import akka.routing.RoundRobinGroup
|
||||
import akka.serialization.{ JavaSerializer, SerializerWithStringManifest }
|
||||
|
|
@ -48,8 +48,8 @@ object TypedActorSpec {
|
|||
def findNext: T = {
|
||||
val currentItems = current.get
|
||||
val newItems = currentItems match {
|
||||
case Nil ⇒ items
|
||||
case xs ⇒ xs
|
||||
case Nil => items
|
||||
case xs => xs
|
||||
}
|
||||
|
||||
if (current.compareAndSet(currentItems, newItems.tail)) newItems.head
|
||||
|
|
@ -59,7 +59,7 @@ object TypedActorSpec {
|
|||
findNext
|
||||
}
|
||||
|
||||
override def exists(f: T ⇒ Boolean): Boolean = items exists f
|
||||
override def exists(f: T => Boolean): Boolean = items exists f
|
||||
}
|
||||
|
||||
trait Foo {
|
||||
|
|
@ -179,25 +179,25 @@ object TypedActorSpec {
|
|||
|
||||
class LifeCyclesImpl(val latch: CountDownLatch) extends PreStart with PostStop with PreRestart with PostRestart with LifeCycles with Receiver {
|
||||
|
||||
private def ensureContextAvailable[T](f: ⇒ T): T = TypedActor.context match {
|
||||
case null ⇒ throw new IllegalStateException("TypedActor.context is null!")
|
||||
case some ⇒ f
|
||||
private def ensureContextAvailable[T](f: => T): T = TypedActor.context match {
|
||||
case null => throw new IllegalStateException("TypedActor.context is null!")
|
||||
case some => f
|
||||
}
|
||||
|
||||
override def crash(): Unit = throw new IllegalStateException("Crash!")
|
||||
|
||||
override def preStart(): Unit = ensureContextAvailable(latch.countDown())
|
||||
|
||||
override def postStop(): Unit = ensureContextAvailable(for (i ← 1 to 3) latch.countDown())
|
||||
override def postStop(): Unit = ensureContextAvailable(for (i <- 1 to 3) latch.countDown())
|
||||
|
||||
override def preRestart(reason: Throwable, message: Option[Any]): Unit = ensureContextAvailable(for (i ← 1 to 5) latch.countDown())
|
||||
override def preRestart(reason: Throwable, message: Option[Any]): Unit = ensureContextAvailable(for (i <- 1 to 5) latch.countDown())
|
||||
|
||||
override def postRestart(reason: Throwable): Unit = ensureContextAvailable(for (i ← 1 to 7) latch.countDown())
|
||||
override def postRestart(reason: Throwable): Unit = ensureContextAvailable(for (i <- 1 to 7) latch.countDown())
|
||||
|
||||
override def onReceive(msg: Any, sender: ActorRef): Unit = {
|
||||
ensureContextAvailable(
|
||||
msg match {
|
||||
case "pigdog" ⇒ sender ! "dogpig"
|
||||
case "pigdog" => sender ! "dogpig"
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -219,13 +219,13 @@ object TypedActorSpec {
|
|||
override def manifest(o: AnyRef): String = manifest
|
||||
|
||||
override def toBinary(o: AnyRef): Array[Byte] = o match {
|
||||
case _: WithStringSerializedClass ⇒ Array(255.toByte)
|
||||
case _ ⇒ throw new IllegalArgumentException(s"Cannot serialize object of type [${o.getClass.getName}]")
|
||||
case _: WithStringSerializedClass => Array(255.toByte)
|
||||
case _ => throw new IllegalArgumentException(s"Cannot serialize object of type [${o.getClass.getName}]")
|
||||
}
|
||||
|
||||
override def fromBinary(bytes: Array[Byte], manifest: String): AnyRef = manifest match {
|
||||
case manifest if bytes.length == 1 && bytes(0) == 255.toByte ⇒ WithStringSerializedClass()
|
||||
case _ ⇒ throw new IllegalArgumentException(s"Cannot deserialize object with manifest $manifest")
|
||||
case manifest if bytes.length == 1 && bytes(0) == 255.toByte => WithStringSerializedClass()
|
||||
case _ => throw new IllegalArgumentException(s"Cannot deserialize object with manifest $manifest")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -336,8 +336,8 @@ class TypedActorSpec extends AkkaSpec(TypedActorSpec.config)
|
|||
|
||||
"be able to call multiple Future-returning methods non-blockingly" in within(timeout.duration) {
|
||||
val t = newFooBar
|
||||
val futures = for (i ← 1 to 20) yield (i, t.futurePigdog(20 millis, i))
|
||||
for ((i, f) ← futures) {
|
||||
val futures = for (i <- 1 to 20) yield (i, t.futurePigdog(20 millis, i))
|
||||
for ((i, f) <- futures) {
|
||||
Await.result(f, remaining) should ===("Pigdog" + i)
|
||||
}
|
||||
mustStop(t)
|
||||
|
|
@ -376,10 +376,10 @@ class TypedActorSpec extends AkkaSpec(TypedActorSpec.config)
|
|||
filterEvents(EventFilter[IllegalStateException]("expected")) {
|
||||
val boss = system.actorOf(Props(new Actor {
|
||||
override val supervisorStrategy = OneForOneStrategy() {
|
||||
case e: IllegalStateException if e.getMessage == "expected" ⇒ SupervisorStrategy.Resume
|
||||
case e: IllegalStateException if e.getMessage == "expected" => SupervisorStrategy.Resume
|
||||
}
|
||||
def receive = {
|
||||
case p: TypedProps[_] ⇒ context.sender() ! TypedActor(context).typedActorOf(p)
|
||||
case p: TypedProps[_] => context.sender() ! TypedActor(context).typedActorOf(p)
|
||||
}
|
||||
}))
|
||||
val t = Await.result((boss ? TypedProps[Bar](classOf[Foo], classOf[Bar]).withTimeout(2 seconds)).mapTo[Foo], timeout.duration)
|
||||
|
|
@ -442,14 +442,14 @@ class TypedActorSpec extends AkkaSpec(TypedActorSpec.config)
|
|||
}
|
||||
|
||||
"be able to use balancing dispatcher" in within(timeout.duration) {
|
||||
val thais = for (i ← 1 to 60) yield newFooBar("pooled-dispatcher", 6 seconds)
|
||||
val thais = for (i <- 1 to 60) yield newFooBar("pooled-dispatcher", 6 seconds)
|
||||
val iterator = new CyclicIterator(thais)
|
||||
|
||||
val results = for (i ← 1 to 120) yield (i, iterator.next.futurePigdog(200 millis, i))
|
||||
val results = for (i <- 1 to 120) yield (i, iterator.next.futurePigdog(200 millis, i))
|
||||
|
||||
for ((i, r) ← results) Await.result(r, remaining) should ===("Pigdog" + i)
|
||||
for ((i, r) <- results) Await.result(r, remaining) should ===("Pigdog" + i)
|
||||
|
||||
for (t ← thais) mustStop(t)
|
||||
for (t <- thais) mustStop(t)
|
||||
}
|
||||
|
||||
"be able to serialize and deserialize invocations" in {
|
||||
|
|
@ -564,7 +564,7 @@ class TypedActorRouterSpec extends AkkaSpec(TypedActorSpec.config)
|
|||
val t2 = newFooBar
|
||||
val t3 = newFooBar
|
||||
val t4 = newFooBar
|
||||
val routees = List(t1, t2, t3, t4) map { t ⇒ TypedActor(system).getActorRefFor(t).path.toStringWithoutAddress }
|
||||
val routees = List(t1, t2, t3, t4) map { t => TypedActor(system).getActorRefFor(t).path.toStringWithoutAddress }
|
||||
|
||||
TypedActor(system).isTypedActor(t1) should ===(true)
|
||||
TypedActor(system).isTypedActor(t2) should ===(true)
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ object UidClashTest {
|
|||
class RestartedActor extends Actor {
|
||||
|
||||
def receive = {
|
||||
case PleaseRestart ⇒ throw new Exception("restart")
|
||||
case Terminated(ref) ⇒ throw new TerminatedForNonWatchedActor
|
||||
case PleaseRestart => throw new Exception("restart")
|
||||
case Terminated(ref) => throw new TerminatedForNonWatchedActor
|
||||
// This is the tricky part to make this test a positive one (avoid expectNoMsg).
|
||||
// Since anything enqueued in postRestart will arrive before the Terminated
|
||||
// the bug triggers, there needs to be a bounce:
|
||||
|
|
@ -47,12 +47,12 @@ object UidClashTest {
|
|||
// 2. As a response to pint, RestartedSafely is sent to self
|
||||
// 3a. if Terminated was enqueued during the restart procedure it will arrive before the RestartedSafely message
|
||||
// 3b. otherwise only the RestartedSafely message arrives
|
||||
case PingMyself ⇒ self ! RestartedSafely
|
||||
case RestartedSafely ⇒ context.parent ! RestartedSafely
|
||||
case PingMyself => self ! RestartedSafely
|
||||
case RestartedSafely => context.parent ! RestartedSafely
|
||||
}
|
||||
|
||||
override def preRestart(reason: Throwable, message: Option[Any]): Unit = {
|
||||
context.children foreach { child ⇒
|
||||
context.children foreach { child =>
|
||||
oldActor = child
|
||||
context.unwatch(child)
|
||||
context.stop(child)
|
||||
|
|
@ -69,16 +69,16 @@ object UidClashTest {
|
|||
|
||||
class RestartingActor(probe: ActorRef) extends Actor {
|
||||
override val supervisorStrategy = OneForOneStrategy(loggingEnabled = false) {
|
||||
case _: TerminatedForNonWatchedActor ⇒
|
||||
case _: TerminatedForNonWatchedActor =>
|
||||
context.stop(self)
|
||||
Stop
|
||||
case _ ⇒ Restart
|
||||
case _ => Restart
|
||||
}
|
||||
val theRestartedOne = context.actorOf(Props[RestartedActor], "theRestartedOne")
|
||||
|
||||
def receive = {
|
||||
case PleaseRestart ⇒ theRestartedOne ! PleaseRestart
|
||||
case RestartedSafely ⇒ probe ! RestartedSafely
|
||||
case PleaseRestart => theRestartedOne ! PleaseRestart
|
||||
case RestartedSafely => probe ! RestartedSafely
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -80,21 +80,21 @@ object ActorModelSpec {
|
|||
}
|
||||
|
||||
def receive = {
|
||||
case AwaitLatch(latch) ⇒ { ack(); latch.await(); busy.switchOff(()) }
|
||||
case Meet(sign, wait) ⇒ { ack(); sign.countDown(); wait.await(); busy.switchOff(()) }
|
||||
case Wait(time) ⇒ { ack(); Thread.sleep(time); busy.switchOff(()) }
|
||||
case WaitAck(time, l) ⇒ { ack(); Thread.sleep(time); l.countDown(); busy.switchOff(()) }
|
||||
case Reply(msg) ⇒ { ack(); sender() ! msg; busy.switchOff(()) }
|
||||
case TryReply(msg) ⇒ { ack(); sender().tell(msg, null); busy.switchOff(()) }
|
||||
case Forward(to, msg) ⇒ { ack(); to.forward(msg); busy.switchOff(()) }
|
||||
case CountDown(latch) ⇒ { ack(); latch.countDown(); busy.switchOff(()) }
|
||||
case Increment(count) ⇒ { ack(); count.incrementAndGet(); busy.switchOff(()) }
|
||||
case CountDownNStop(l) ⇒ { ack(); l.countDown(); context.stop(self); busy.switchOff(()) }
|
||||
case Restart ⇒ { ack(); busy.switchOff(()); throw new Exception("Restart requested") }
|
||||
case Interrupt ⇒ { ack(); sender() ! Status.Failure(new ActorInterruptedException(new InterruptedException("Ping!"))); busy.switchOff(()); throw new InterruptedException("Ping!") }
|
||||
case InterruptNicely(msg) ⇒ { ack(); sender() ! msg; busy.switchOff(()); Thread.currentThread().interrupt() }
|
||||
case ThrowException(e: Throwable) ⇒ { ack(); busy.switchOff(()); throw e }
|
||||
case DoubleStop ⇒ { ack(); context.stop(self); context.stop(self); busy.switchOff }
|
||||
case AwaitLatch(latch) => { ack(); latch.await(); busy.switchOff(()) }
|
||||
case Meet(sign, wait) => { ack(); sign.countDown(); wait.await(); busy.switchOff(()) }
|
||||
case Wait(time) => { ack(); Thread.sleep(time); busy.switchOff(()) }
|
||||
case WaitAck(time, l) => { ack(); Thread.sleep(time); l.countDown(); busy.switchOff(()) }
|
||||
case Reply(msg) => { ack(); sender() ! msg; busy.switchOff(()) }
|
||||
case TryReply(msg) => { ack(); sender().tell(msg, null); busy.switchOff(()) }
|
||||
case Forward(to, msg) => { ack(); to.forward(msg); busy.switchOff(()) }
|
||||
case CountDown(latch) => { ack(); latch.countDown(); busy.switchOff(()) }
|
||||
case Increment(count) => { ack(); count.incrementAndGet(); busy.switchOff(()) }
|
||||
case CountDownNStop(l) => { ack(); l.countDown(); context.stop(self); busy.switchOff(()) }
|
||||
case Restart => { ack(); busy.switchOff(()); throw new Exception("Restart requested") }
|
||||
case Interrupt => { ack(); sender() ! Status.Failure(new ActorInterruptedException(new InterruptedException("Ping!"))); busy.switchOff(()); throw new InterruptedException("Ping!") }
|
||||
case InterruptNicely(msg) => { ack(); sender() ! msg; busy.switchOff(()); Thread.currentThread().interrupt() }
|
||||
case ThrowException(e: Throwable) => { ack(); busy.switchOff(()); throw e }
|
||||
case DoubleStop => { ack(); context.stop(self); context.stop(self); busy.switchOff }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -117,13 +117,13 @@ object ActorModelSpec {
|
|||
|
||||
def getStats(actorRef: ActorRef) = {
|
||||
stats.get(actorRef) match {
|
||||
case null ⇒
|
||||
case null =>
|
||||
val is = new InterceptorStats
|
||||
stats.putIfAbsent(actorRef, is) match {
|
||||
case null ⇒ is
|
||||
case other ⇒ other
|
||||
case null => is
|
||||
case other => other
|
||||
}
|
||||
case existing ⇒ existing
|
||||
case existing => existing
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -166,7 +166,7 @@ object ActorModelSpec {
|
|||
try {
|
||||
await(deadline)(stops == dispatcher.stops.get)
|
||||
} catch {
|
||||
case e: Throwable ⇒
|
||||
case e: Throwable =>
|
||||
system.eventStream.publish(Error(e, dispatcher.toString, dispatcher.getClass, "actual: stops=" + dispatcher.stops.get +
|
||||
" required: stops=" + stops))
|
||||
throw e
|
||||
|
|
@ -223,7 +223,7 @@ object ActorModelSpec {
|
|||
await(deadline)(stats.msgsProcessed.get() == msgsProcessed)
|
||||
await(deadline)(stats.restarts.get() == restarts)
|
||||
} catch {
|
||||
case e: Throwable ⇒
|
||||
case e: Throwable =>
|
||||
system.eventStream.publish(Error(
|
||||
e,
|
||||
Option(dispatcher).toString,
|
||||
|
|
@ -235,14 +235,14 @@ object ActorModelSpec {
|
|||
}
|
||||
}
|
||||
|
||||
@tailrec def await(until: Long)(condition: ⇒ Boolean): Unit =
|
||||
@tailrec def await(until: Long)(condition: => Boolean): Unit =
|
||||
if (System.currentTimeMillis() <= until) {
|
||||
var done = false
|
||||
try {
|
||||
done = condition
|
||||
if (!done) Thread.sleep(25)
|
||||
} catch {
|
||||
case _: InterruptedException ⇒
|
||||
case _: InterruptedException =>
|
||||
}
|
||||
if (!done) await(until)(condition)
|
||||
} else throw new AssertionError("await failed")
|
||||
|
|
@ -256,8 +256,8 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
|
||||
def awaitStarted(ref: ActorRef): Unit = {
|
||||
awaitCond(ref match {
|
||||
case r: RepointableRef ⇒ r.isStarted
|
||||
case _ ⇒ true
|
||||
case r: RepointableRef => r.isStarted
|
||||
case _ => true
|
||||
}, 1 second, 10 millis)
|
||||
}
|
||||
|
||||
|
|
@ -282,11 +282,11 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
msgsProcessed = 0,
|
||||
restarts = 0)
|
||||
|
||||
for (i ← 1 to 10) yield Future { i }
|
||||
for (i <- 1 to 10) yield Future { i }
|
||||
assertDispatcher(dispatcher)(stops = 2)
|
||||
|
||||
val a2 = newTestActor(dispatcher.id)
|
||||
for (i ← 1 to 10) yield Future { i }
|
||||
for (i <- 1 to 10) yield Future { i }
|
||||
|
||||
assertDispatcher(dispatcher)(stops = 2)
|
||||
|
||||
|
|
@ -319,9 +319,9 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
val counter = new CountDownLatch(200)
|
||||
val a = newTestActor(dispatcher.id)
|
||||
|
||||
for (_ ← 1 to 10) {
|
||||
for (_ <- 1 to 10) {
|
||||
spawn {
|
||||
for (_ ← 1 to 20) {
|
||||
for (_ <- 1 to 20) {
|
||||
a ! WaitAck(1, counter)
|
||||
}
|
||||
}
|
||||
|
|
@ -332,11 +332,11 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
system.stop(a)
|
||||
}
|
||||
|
||||
def spawn(f: ⇒ Unit): Unit = {
|
||||
def spawn(f: => Unit): Unit = {
|
||||
(new Thread {
|
||||
override def run(): Unit =
|
||||
try f catch {
|
||||
case e: Throwable ⇒ system.eventStream.publish(Error(e, "spawn", this.getClass, "error in spawned thread"))
|
||||
case e: Throwable => system.eventStream.publish(Error(e, "spawn", this.getClass, "error in spawned thread"))
|
||||
}
|
||||
}).start()
|
||||
}
|
||||
|
|
@ -372,8 +372,8 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
val waitTime = (20 seconds).dilated.toMillis
|
||||
val boss = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "run" ⇒ for (_ ← 1 to num) context.watch(context.actorOf(props)) ! cachedMessage
|
||||
case Terminated(_) ⇒ stopLatch.countDown()
|
||||
case "run" => for (_ <- 1 to num) context.watch(context.actorOf(props)) ! cachedMessage
|
||||
case Terminated(_) => stopLatch.countDown()
|
||||
}
|
||||
}).withDispatcher("boss"))
|
||||
try {
|
||||
|
|
@ -389,9 +389,9 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
try {
|
||||
assertCountDown(cachedMessage.latch, waitTime, "Counting down from " + num)
|
||||
} catch {
|
||||
case e: Throwable ⇒
|
||||
case e: Throwable =>
|
||||
dispatcher match {
|
||||
case dispatcher: BalancingDispatcher ⇒
|
||||
case dispatcher: BalancingDispatcher =>
|
||||
val team = dispatcher.team
|
||||
val mq = dispatcher.messageQueue
|
||||
|
||||
|
|
@ -400,14 +400,14 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
import scala.collection.JavaConverters._
|
||||
team.asScala.toList
|
||||
.sortBy(_.self.path)
|
||||
.foreach { cell: ActorCell ⇒
|
||||
.foreach { cell: ActorCell =>
|
||||
System.err.println(" - " + cell.self.path + " " + cell.isTerminated + " " + cell.mailbox.currentStatus + " "
|
||||
+ cell.mailbox.numberOfMessages + " " + cell.mailbox.systemDrain(SystemMessageList.LNil).size)
|
||||
}
|
||||
|
||||
System.err.println("Mailbox: " + mq.numberOfMessages + " " + mq.hasMessages)
|
||||
Iterator.continually(mq.dequeue) takeWhile (_ ne null) foreach System.err.println
|
||||
case _ ⇒
|
||||
case _ =>
|
||||
}
|
||||
|
||||
throw e
|
||||
|
|
@ -418,7 +418,7 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
system.stop(boss)
|
||||
}
|
||||
}
|
||||
for (run ← 1 to 3) {
|
||||
for (run <- 1 to 3) {
|
||||
flood(10000)
|
||||
assertDispatcher(dispatcher)(stops = run)
|
||||
}
|
||||
|
|
@ -443,9 +443,9 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
val c = system.scheduler.scheduleOnce(2.seconds) {
|
||||
import collection.JavaConverters._
|
||||
Thread.getAllStackTraces().asScala foreach {
|
||||
case (thread, stack) ⇒
|
||||
case (thread, stack) =>
|
||||
println(s"$thread:")
|
||||
stack foreach (s ⇒ println(s"\t$s"))
|
||||
stack foreach (s => println(s"\t$s"))
|
||||
}
|
||||
}
|
||||
assert(Await.result(f1, timeout.duration) === "foo")
|
||||
|
|
@ -503,7 +503,7 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
|
||||
"not double-deregister" in {
|
||||
implicit val dispatcher = interceptedDispatcher()
|
||||
for (_ ← 1 to 1000) system.actorOf(Props.empty)
|
||||
for (_ <- 1 to 1000) system.actorOf(Props.empty)
|
||||
val a = newTestActor(dispatcher.id)
|
||||
a ! DoubleStop
|
||||
awaitCond(statsFor(a, dispatcher).registers.get == 1)
|
||||
|
|
@ -523,7 +523,7 @@ object DispatcherModelSpec {
|
|||
}
|
||||
""" +
|
||||
// use unique dispatcher id for each test, since MessageDispatcherInterceptor holds state
|
||||
(for (n ← 1 to 30) yield """
|
||||
(for (n <- 1 to 30) yield """
|
||||
test-dispatcher-%s {
|
||||
type = "akka.actor.dispatch.DispatcherModelSpec$MessageDispatcherInterceptorConfigurator"
|
||||
}""".format(n)).mkString
|
||||
|
|
@ -596,7 +596,7 @@ object BalancingDispatcherModelSpec {
|
|||
}
|
||||
""" +
|
||||
// use unique dispatcher id for each test, since MessageDispatcherInterceptor holds state
|
||||
(for (n ← 1 to 30) yield """
|
||||
(for (n <- 1 to 30) yield """
|
||||
test-balancing-dispatcher-%s {
|
||||
type = "akka.actor.dispatch.BalancingDispatcherModelSpec$BalancingMessageDispatcherInterceptorConfigurator"
|
||||
throughput=1
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class BalancingDispatcherSpec extends AkkaSpec(BalancingDispatcherSpec.config) {
|
|||
var invocationCount = 0
|
||||
|
||||
def receive = {
|
||||
case x: Int ⇒ {
|
||||
case x: Int => {
|
||||
Thread.sleep(delay)
|
||||
invocationCount += 1
|
||||
finishedCounter.countDown()
|
||||
|
|
@ -37,15 +37,15 @@ class BalancingDispatcherSpec extends AkkaSpec(BalancingDispatcherSpec.config) {
|
|||
}
|
||||
|
||||
class FirstActor extends Actor {
|
||||
def receive = { case _ ⇒ {} }
|
||||
def receive = { case _ => {} }
|
||||
}
|
||||
|
||||
class SecondActor extends Actor {
|
||||
def receive = { case _ ⇒ {} }
|
||||
def receive = { case _ => {} }
|
||||
}
|
||||
|
||||
class ParentActor extends Actor {
|
||||
def receive = { case _ ⇒ {} }
|
||||
def receive = { case _ => {} }
|
||||
}
|
||||
|
||||
class ChildActor extends ParentActor {
|
||||
|
|
@ -60,7 +60,7 @@ class BalancingDispatcherSpec extends AkkaSpec(BalancingDispatcherSpec.config) {
|
|||
|
||||
var sentToFast = 0
|
||||
|
||||
for (i ← 1 to 100) {
|
||||
for (i <- 1 to 100) {
|
||||
// send most work to slow actor
|
||||
if (i % 20 == 0) {
|
||||
fast ! i
|
||||
|
|
@ -70,7 +70,7 @@ class BalancingDispatcherSpec extends AkkaSpec(BalancingDispatcherSpec.config) {
|
|||
}
|
||||
|
||||
// now send some messages to actors to keep the dispatcher dispatching messages
|
||||
for (i ← 1 to 10) {
|
||||
for (i <- 1 to 10) {
|
||||
Thread.sleep(150)
|
||||
if (i % 2 == 0) {
|
||||
fast ! i
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ object DispatcherActorSpec {
|
|||
"""
|
||||
class TestActor extends Actor {
|
||||
def receive = {
|
||||
case "Hello" ⇒ sender() ! "World"
|
||||
case "Failure" ⇒ throw new RuntimeException("Expected exception; to test fault-tolerance")
|
||||
case "Hello" => sender() ! "World"
|
||||
case "Failure" => throw new RuntimeException("Expected exception; to test fault-tolerance")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ object DispatcherActorSpec {
|
|||
}
|
||||
class OneWayTestActor extends Actor {
|
||||
def receive = {
|
||||
case "OneWay" ⇒ OneWayTestActor.oneWay.countDown()
|
||||
case "OneWay" => OneWayTestActor.oneWay.countDown()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -80,19 +80,19 @@ class DispatcherActorSpec extends AkkaSpec(DispatcherActorSpec.config) with Defa
|
|||
val latch = new CountDownLatch(100)
|
||||
val start = new CountDownLatch(1)
|
||||
val fastOne = system.actorOf(
|
||||
Props(new Actor { def receive = { case "sabotage" ⇒ works.set(false) } })
|
||||
Props(new Actor { def receive = { case "sabotage" => works.set(false) } })
|
||||
.withDispatcher(throughputDispatcher))
|
||||
|
||||
val slowOne = system.actorOf(
|
||||
Props(new Actor {
|
||||
def receive = {
|
||||
case "hogexecutor" ⇒ { sender() ! "OK"; start.await }
|
||||
case "ping" ⇒ if (works.get) latch.countDown()
|
||||
case "hogexecutor" => { sender() ! "OK"; start.await }
|
||||
case "ping" => if (works.get) latch.countDown()
|
||||
}
|
||||
}).withDispatcher(throughputDispatcher))
|
||||
|
||||
assert(Await.result(slowOne ? "hogexecutor", timeout.duration) === "OK")
|
||||
(1 to 100) foreach { _ ⇒ slowOne ! "ping" }
|
||||
(1 to 100) foreach { _ => slowOne ! "ping" }
|
||||
fastOne ! "sabotage"
|
||||
start.countDown()
|
||||
latch.await(10, TimeUnit.SECONDS)
|
||||
|
|
@ -113,15 +113,15 @@ class DispatcherActorSpec extends AkkaSpec(DispatcherActorSpec.config) with Defa
|
|||
val fastOne = system.actorOf(
|
||||
Props(new Actor {
|
||||
def receive = {
|
||||
case "ping" ⇒ if (works.get) latch.countDown(); context.stop(self)
|
||||
case "ping" => if (works.get) latch.countDown(); context.stop(self)
|
||||
}
|
||||
}).withDispatcher(throughputDispatcher))
|
||||
|
||||
val slowOne = system.actorOf(
|
||||
Props(new Actor {
|
||||
def receive = {
|
||||
case "hogexecutor" ⇒ { ready.countDown(); start.await }
|
||||
case "ping" ⇒ { works.set(false); context.stop(self) }
|
||||
case "hogexecutor" => { ready.countDown(); start.await }
|
||||
case "ping" => { works.set(false); context.stop(self) }
|
||||
}
|
||||
}).withDispatcher(throughputDispatcher))
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class DispatcherActorsSpec extends AkkaSpec {
|
|||
class SlowActor(finishedCounter: CountDownLatch) extends Actor {
|
||||
|
||||
def receive = {
|
||||
case x: Int ⇒ {
|
||||
case x: Int => {
|
||||
Thread.sleep(50) // slow actor
|
||||
finishedCounter.countDown()
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ class DispatcherActorsSpec extends AkkaSpec {
|
|||
|
||||
class FastActor(finishedCounter: CountDownLatch) extends Actor {
|
||||
def receive = {
|
||||
case x: Int ⇒ {
|
||||
case x: Int => {
|
||||
finishedCounter.countDown()
|
||||
}
|
||||
}
|
||||
|
|
@ -38,12 +38,12 @@ class DispatcherActorsSpec extends AkkaSpec {
|
|||
val f = system.actorOf(Props(new FastActor(fFinished)))
|
||||
|
||||
// send a lot of stuff to s
|
||||
for (i ← 1 to 50) {
|
||||
for (i <- 1 to 50) {
|
||||
s ! i
|
||||
}
|
||||
|
||||
// send some messages to f
|
||||
for (i ← 1 to 10) {
|
||||
for (i <- 1 to 10) {
|
||||
f ! i
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ object DispatchersSpec {
|
|||
|
||||
class ThreadNameEcho extends Actor {
|
||||
def receive = {
|
||||
case _ ⇒ sender() ! Thread.currentThread.getName
|
||||
case _ => sender() ! Thread.currentThread.getName
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,19 +107,19 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
val throughput = "throughput"
|
||||
val id = "id"
|
||||
|
||||
def instance(dispatcher: MessageDispatcher): (MessageDispatcher) ⇒ Boolean = _ == dispatcher
|
||||
def ofType[T <: MessageDispatcher: ClassTag]: (MessageDispatcher) ⇒ Boolean = _.getClass == implicitly[ClassTag[T]].runtimeClass
|
||||
def instance(dispatcher: MessageDispatcher): (MessageDispatcher) => Boolean = _ == dispatcher
|
||||
def ofType[T <: MessageDispatcher: ClassTag]: (MessageDispatcher) => Boolean = _.getClass == implicitly[ClassTag[T]].runtimeClass
|
||||
|
||||
def typesAndValidators: Map[String, (MessageDispatcher) ⇒ Boolean] = Map(
|
||||
"PinnedDispatcher" → ofType[PinnedDispatcher],
|
||||
"Dispatcher" → ofType[Dispatcher])
|
||||
def typesAndValidators: Map[String, (MessageDispatcher) => Boolean] = Map(
|
||||
"PinnedDispatcher" -> ofType[PinnedDispatcher],
|
||||
"Dispatcher" -> ofType[Dispatcher])
|
||||
|
||||
def validTypes = typesAndValidators.keys.toList
|
||||
|
||||
val defaultDispatcherConfig = settings.config.getConfig("akka.actor.default-dispatcher")
|
||||
|
||||
lazy val allDispatchers: Map[String, MessageDispatcher] = {
|
||||
validTypes.map(t ⇒ (t, from(ConfigFactory.parseMap(Map(tipe → t, id → t).asJava).
|
||||
validTypes.map(t => (t, from(ConfigFactory.parseMap(Map(tipe -> t, id -> t).asJava).
|
||||
withFallback(defaultDispatcherConfig)))).toMap
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
actor ! "what's the name?"
|
||||
val Expected = R("(DispatchersSpec-myapp.mydispatcher-[1-9][0-9]*)")
|
||||
expectMsgPF() {
|
||||
case Expected(x) ⇒
|
||||
case Expected(x) =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,14 +157,14 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
|
||||
"throw ConfigurationException if type does not exist" in {
|
||||
intercept[ConfigurationException] {
|
||||
from(ConfigFactory.parseMap(Map(tipe → "typedoesntexist", id → "invalid-dispatcher").asJava).
|
||||
from(ConfigFactory.parseMap(Map(tipe -> "typedoesntexist", id -> "invalid-dispatcher").asJava).
|
||||
withFallback(defaultDispatcherConfig))
|
||||
}
|
||||
}
|
||||
|
||||
"get the correct types of dispatchers" in {
|
||||
//All created/obtained dispatchers are of the expected type/instance
|
||||
assert(typesAndValidators.forall(tuple ⇒ tuple._2(allDispatchers(tuple._1))))
|
||||
assert(typesAndValidators.forall(tuple => tuple._2(allDispatchers(tuple._1))))
|
||||
}
|
||||
|
||||
"provide lookup of dispatchers by id" in {
|
||||
|
|
@ -181,7 +181,7 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
system.actorOf(Props[ThreadNameEcho].withDispatcher("myapp.thread-pool-dispatcher")) ! "what's the name?"
|
||||
val Expected = R("(DispatchersSpec-myapp.thread-pool-dispatcher-[1-9][0-9]*)")
|
||||
expectMsgPF() {
|
||||
case Expected(x) ⇒
|
||||
case Expected(x) =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +189,7 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
system.actorOf(Props[ThreadNameEcho]) ! "what's the name?"
|
||||
val Expected = R("(DispatchersSpec-akka.actor.default-dispatcher-[1-9][0-9]*)")
|
||||
expectMsgPF() {
|
||||
case Expected(x) ⇒
|
||||
case Expected(x) =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -197,7 +197,7 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
system.actorOf(Props[ThreadNameEcho].withDispatcher("myapp.my-pinned-dispatcher")) ! "what's the name?"
|
||||
val Expected = R("(DispatchersSpec-myapp.my-pinned-dispatcher-[1-9][0-9]*)")
|
||||
expectMsgPF() {
|
||||
case Expected(x) ⇒
|
||||
case Expected(x) =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -205,7 +205,7 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
system.actorOf(Props[ThreadNameEcho].withDispatcher("myapp.balancing-dispatcher")) ! "what's the name?"
|
||||
val Expected = R("(DispatchersSpec-myapp.balancing-dispatcher-[1-9][0-9]*)")
|
||||
expectMsgPF() {
|
||||
case Expected(x) ⇒
|
||||
case Expected(x) =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -225,7 +225,7 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
routee ! "what's the name?"
|
||||
val Expected = R("""(DispatchersSpec-akka\.actor\.deployment\./pool1\.pool-dispatcher-[1-9][0-9]*)""")
|
||||
expectMsgPF() {
|
||||
case Expected(x) ⇒
|
||||
case Expected(x) =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,10 +233,10 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
system.actorOf(FromConfig.props(Props[ThreadNameEcho]), name = "balanced") ! "what's the name?"
|
||||
val Expected = R("""(DispatchersSpec-BalancingPool-/balanced-[1-9][0-9]*)""")
|
||||
expectMsgPF() {
|
||||
case Expected(x) ⇒
|
||||
case Expected(x) =>
|
||||
}
|
||||
expectMsgPF() {
|
||||
case Expected(x) ⇒
|
||||
case Expected(x) =>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ object PinnedActorSpec {
|
|||
|
||||
class TestActor extends Actor {
|
||||
def receive = {
|
||||
case "Hello" ⇒ sender() ! "World"
|
||||
case "Failure" ⇒ throw new RuntimeException("Expected exception; to test fault-tolerance")
|
||||
case "Hello" => sender() ! "World"
|
||||
case "Failure" => throw new RuntimeException("Expected exception; to test fault-tolerance")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -38,7 +38,7 @@ class PinnedActorSpec extends AkkaSpec(PinnedActorSpec.config) with BeforeAndAft
|
|||
|
||||
"support tell" in {
|
||||
var oneWay = new CountDownLatch(1)
|
||||
val actor = system.actorOf(Props(new Actor { def receive = { case "OneWay" ⇒ oneWay.countDown() } }).withDispatcher("pinned-dispatcher"))
|
||||
val actor = system.actorOf(Props(new Actor { def receive = { case "OneWay" => oneWay.countDown() } }).withDispatcher("pinned-dispatcher"))
|
||||
val result = actor ! "OneWay"
|
||||
assert(oneWay.await(1, TimeUnit.SECONDS))
|
||||
system.stop(actor)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ object DispatchSpec {
|
|||
class UnserializableMessageClass
|
||||
class EmptyActor extends Actor {
|
||||
override def receive = {
|
||||
case _: UnserializableMessageClass ⇒ // OK
|
||||
case _: UnserializableMessageClass => // OK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,16 +21,16 @@ class ListenerSpec extends AkkaSpec {
|
|||
|
||||
val broadcast = system.actorOf(Props(new Actor with Listeners {
|
||||
def receive = listenerManagement orElse {
|
||||
case "foo" ⇒ gossip("bar")
|
||||
case "foo" => gossip("bar")
|
||||
}
|
||||
}))
|
||||
|
||||
def newListener = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "bar" ⇒
|
||||
case "bar" =>
|
||||
barCount.incrementAndGet
|
||||
barLatch.countDown()
|
||||
case "foo" ⇒
|
||||
case "foo" =>
|
||||
fooLatch.countDown()
|
||||
}
|
||||
}))
|
||||
|
|
@ -53,7 +53,7 @@ class ListenerSpec extends AkkaSpec {
|
|||
|
||||
Await.ready(fooLatch, TestLatch.DefaultTimeout)
|
||||
|
||||
for (a ← List(broadcast, a1, a2, a3)) system.stop(a)
|
||||
for (a <- List(broadcast, a1, a2, a3)) system.stop(a)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ class Future2ActorSpec extends AkkaSpec with DefaultTimeout {
|
|||
"support reply via sender" in {
|
||||
val actor = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "do" ⇒ Future(31) pipeTo context.sender()
|
||||
case "ex" ⇒ Future(throw new AssertionError) pipeTo context.sender()
|
||||
case "do" => Future(31) pipeTo context.sender()
|
||||
case "ex" => Future(throw new AssertionError) pipeTo context.sender()
|
||||
}
|
||||
}))
|
||||
Await.result(actor ? "do", timeout.duration) should ===(31)
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class ControlAwareDispatcherSpec extends AkkaSpec(ControlAwareDispatcherSpec.con
|
|||
self ! ImportantMessage
|
||||
|
||||
def receive = {
|
||||
case x ⇒ testActor ! x
|
||||
case x => testActor ! x
|
||||
}
|
||||
}).withDispatcher(dispatcherKey))
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
import system.dispatcher
|
||||
|
||||
def batchable[T](f: ⇒ T)(implicit ec: ExecutionContext): Unit = ec.execute(new Batchable {
|
||||
def batchable[T](f: => T)(implicit ec: ExecutionContext): Unit = ec.execute(new Batchable {
|
||||
override def isBatchable = true
|
||||
override def run: Unit = f
|
||||
})
|
||||
|
|
@ -54,7 +54,7 @@ class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
|||
batchable {
|
||||
val lock, callingThreadLock, count = new AtomicInteger(0)
|
||||
callingThreadLock.compareAndSet(0, 1) // Enable the lock
|
||||
(1 to 100) foreach { i ⇒
|
||||
(1 to 100) foreach { i =>
|
||||
batchable {
|
||||
if (callingThreadLock.get != 0) p.tryFailure(new IllegalStateException("Batch was executed inline!"))
|
||||
else if (count.incrementAndGet == 100) p.trySuccess(()) //Done
|
||||
|
|
@ -72,14 +72,14 @@ class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
|||
system.dispatcher.isInstanceOf[BatchingExecutor] should ===(true)
|
||||
import system.dispatcher
|
||||
|
||||
def batchable[T](f: ⇒ T)(implicit ec: ExecutionContext): Unit = ec.execute(new Batchable {
|
||||
def batchable[T](f: => T)(implicit ec: ExecutionContext): Unit = ec.execute(new Batchable {
|
||||
override def isBatchable = true
|
||||
override def run: Unit = f
|
||||
})
|
||||
|
||||
val latch = TestLatch(101)
|
||||
batchable {
|
||||
(1 to 100) foreach { i ⇒
|
||||
(1 to 100) foreach { i =>
|
||||
batchable {
|
||||
val deadlock = TestLatch(1)
|
||||
batchable { deadlock.open() }
|
||||
|
|
@ -96,12 +96,12 @@ class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
|||
system.dispatcher.isInstanceOf[BatchingExecutor] should be(true)
|
||||
import system.dispatcher
|
||||
|
||||
val f = Future(()).flatMap { _ ⇒
|
||||
val f = Future(()).flatMap { _ =>
|
||||
// this needs to be within an OnCompleteRunnable so that things are added to the batch
|
||||
val p = Future.successful(42)
|
||||
// we need the callback list to be non-empty when the blocking{} call is executing
|
||||
p.onComplete { _ ⇒ () }
|
||||
val r = p.map { _ ⇒
|
||||
p.onComplete { _ => () }
|
||||
val r = p.map { _ =>
|
||||
// trigger the resubmitUnbatched() call
|
||||
blocking { () }
|
||||
// make sure that the other task runs to completion before continuing
|
||||
|
|
@ -109,7 +109,7 @@ class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
|||
// now try again to blockOn()
|
||||
blocking { () }
|
||||
}
|
||||
p.onComplete { _ ⇒ () }
|
||||
p.onComplete { _ => () }
|
||||
r
|
||||
}
|
||||
Await.result(f, 3.seconds) should be(())
|
||||
|
|
@ -119,7 +119,7 @@ class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
|||
system.dispatcher.isInstanceOf[BatchingExecutor] should be(true)
|
||||
import system.dispatcher
|
||||
|
||||
val f = Future(()).flatMap { _ ⇒
|
||||
val f = Future(()).flatMap { _ =>
|
||||
blocking {
|
||||
blocking {
|
||||
blocking {
|
||||
|
|
@ -149,7 +149,7 @@ class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
|||
"work with same-thread dispatcher plus blocking" in {
|
||||
val a = TestActorRef(Props(new Actor {
|
||||
def receive = {
|
||||
case msg ⇒
|
||||
case msg =>
|
||||
blocking {
|
||||
sender() ! msg
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
|||
}))
|
||||
val b = TestActorRef(Props(new Actor {
|
||||
def receive = {
|
||||
case msg ⇒ a forward msg
|
||||
case msg => a forward msg
|
||||
}
|
||||
}))
|
||||
val p = TestProbe()
|
||||
|
|
@ -193,9 +193,9 @@ class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
|||
"be suspendable and resumable" in {
|
||||
val sec = SerializedSuspendableExecutionContext(1)(ExecutionContext.global)
|
||||
val counter = new AtomicInteger(0)
|
||||
def perform(f: Int ⇒ Int) = sec execute new Runnable { def run = counter.set(f(counter.get)) }
|
||||
def perform(f: Int => Int) = sec execute new Runnable { def run = counter.set(f(counter.get)) }
|
||||
perform(_ + 1)
|
||||
perform(x ⇒ { sec.suspend(); x * 2 })
|
||||
perform(x => { sec.suspend(); x * 2 })
|
||||
awaitCond(counter.get == 2)
|
||||
perform(_ + 4)
|
||||
perform(_ * 2)
|
||||
|
|
@ -220,10 +220,10 @@ class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
|||
val throughput = 25
|
||||
val sec = SerializedSuspendableExecutionContext(throughput)(underlying)
|
||||
sec.suspend()
|
||||
def perform(f: Int ⇒ Int) = sec execute new Runnable { def run = counter.set(f(counter.get)) }
|
||||
def perform(f: Int => Int) = sec execute new Runnable { def run = counter.set(f(counter.get)) }
|
||||
|
||||
val total = 1000
|
||||
1 to total foreach { _ ⇒ perform(_ + 1) }
|
||||
1 to total foreach { _ => perform(_ + 1) }
|
||||
sec.size() should ===(total)
|
||||
sec.resume()
|
||||
awaitCond(counter.get == total)
|
||||
|
|
@ -235,9 +235,9 @@ class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
|||
val sec = SerializedSuspendableExecutionContext(1)(ExecutionContext.global)
|
||||
val total = 10000
|
||||
val counter = new AtomicInteger(0)
|
||||
def perform(f: Int ⇒ Int) = sec execute new Runnable { def run = counter.set(f(counter.get)) }
|
||||
def perform(f: Int => Int) = sec execute new Runnable { def run = counter.set(f(counter.get)) }
|
||||
|
||||
1 to total foreach { i ⇒ perform(c ⇒ if (c == (i - 1)) c + 1 else c) }
|
||||
1 to total foreach { i => perform(c => if (c == (i - 1)) c + 1 else c) }
|
||||
awaitCond(counter.get == total)
|
||||
sec.isEmpty should ===(true)
|
||||
}
|
||||
|
|
@ -252,10 +252,10 @@ class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
|||
val throughput = 25
|
||||
val sec = SerializedSuspendableExecutionContext(throughput)(underlying)
|
||||
sec.suspend()
|
||||
def perform(f: Int ⇒ Int) = sec execute new Runnable { def run = counter.set(f(counter.get)) }
|
||||
def perform(f: Int => Int) = sec execute new Runnable { def run = counter.set(f(counter.get)) }
|
||||
perform(_ + 1)
|
||||
1 to 10 foreach { _ ⇒ perform(identity) }
|
||||
perform(x ⇒ { sec.suspend(); x * 2 })
|
||||
1 to 10 foreach { _ => perform(identity) }
|
||||
perform(x => { sec.suspend(); x * 2 })
|
||||
perform(_ + 8)
|
||||
sec.size should ===(13)
|
||||
sec.resume()
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ object ForkJoinPoolStarvationSpec {
|
|||
self ! "tick"
|
||||
|
||||
override def receive = {
|
||||
case "tick" ⇒
|
||||
case "tick" =>
|
||||
self ! "tick"
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ object ForkJoinPoolStarvationSpec {
|
|||
class InnocentActor extends Actor {
|
||||
|
||||
override def receive = {
|
||||
case "ping" ⇒
|
||||
case "ping" =>
|
||||
sender ! "All fine"
|
||||
}
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ class ForkJoinPoolStarvationSpec extends AkkaSpec(ForkJoinPoolStarvationSpec.con
|
|||
|
||||
val innocentActor = system.actorOf(Props(new InnocentActor).withDispatcher("actorhang.task-dispatcher"))
|
||||
|
||||
for (_ ← 1 to Iterations) {
|
||||
for (_ <- 1 to Iterations) {
|
||||
// External task submission via the default dispatcher
|
||||
innocentActor ! "ping"
|
||||
expectMsg("All fine")
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import scala.concurrent.duration._
|
|||
abstract class MailboxSpec extends AkkaSpec with BeforeAndAfterAll with BeforeAndAfterEach {
|
||||
def name: String
|
||||
|
||||
def factory: MailboxType ⇒ MessageQueue
|
||||
def factory: MailboxType => MessageQueue
|
||||
|
||||
def supportsBeingBounded = true
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ abstract class MailboxSpec extends AkkaSpec with BeforeAndAfterAll with BeforeAn
|
|||
val q = factory(config)
|
||||
ensureInitialMailboxState(config, q)
|
||||
|
||||
for (i ← 1 to config.capacity) q.enqueue(testActor, exampleMessage)
|
||||
for (i <- 1 to config.capacity) q.enqueue(testActor, exampleMessage)
|
||||
|
||||
q.numberOfMessages should ===(config.capacity)
|
||||
q.hasMessages should ===(true)
|
||||
|
|
@ -80,14 +80,14 @@ abstract class MailboxSpec extends AkkaSpec with BeforeAndAfterAll with BeforeAn
|
|||
}
|
||||
|
||||
//CANDIDATE FOR TESTKIT
|
||||
def spawn[T <: AnyRef](fun: ⇒ T): Future[T] = Future(fun)(ExecutionContext.global)
|
||||
def spawn[T <: AnyRef](fun: => T): Future[T] = Future(fun)(ExecutionContext.global)
|
||||
|
||||
def createMessageInvocation(msg: Any): Envelope = Envelope(msg, system.deadLetters, system)
|
||||
|
||||
def ensureMailboxSize(q: MessageQueue, expected: Int): Unit = q.numberOfMessages match {
|
||||
case -1 | `expected` ⇒
|
||||
case -1 | `expected` =>
|
||||
q.hasMessages should ===(expected != 0)
|
||||
case other ⇒
|
||||
case other =>
|
||||
other should ===(expected)
|
||||
q.hasMessages should ===(expected != 0)
|
||||
}
|
||||
|
|
@ -96,14 +96,14 @@ abstract class MailboxSpec extends AkkaSpec with BeforeAndAfterAll with BeforeAn
|
|||
val q = factory(config)
|
||||
ensureMailboxSize(q, 0)
|
||||
q.dequeue should ===(null)
|
||||
for (i ← 1 to 100) {
|
||||
for (i <- 1 to 100) {
|
||||
q.enqueue(testActor, exampleMessage)
|
||||
ensureMailboxSize(q, i)
|
||||
}
|
||||
|
||||
ensureMailboxSize(q, 100)
|
||||
|
||||
for (i ← 99 to 0 by -1) {
|
||||
for (i <- 99 to 0 by -1) {
|
||||
q.dequeue() should ===(exampleMessage)
|
||||
ensureMailboxSize(q, i)
|
||||
}
|
||||
|
|
@ -115,12 +115,12 @@ abstract class MailboxSpec extends AkkaSpec with BeforeAndAfterAll with BeforeAn
|
|||
def ensureInitialMailboxState(config: MailboxType, q: MessageQueue): Unit = {
|
||||
q should not be null
|
||||
q match {
|
||||
case aQueue: BlockingQueue[_] ⇒
|
||||
case aQueue: BlockingQueue[_] =>
|
||||
config match {
|
||||
case BoundedMailbox(capacity, _) ⇒ aQueue.remainingCapacity should ===(capacity)
|
||||
case UnboundedMailbox() ⇒ aQueue.remainingCapacity should ===(Int.MaxValue)
|
||||
case BoundedMailbox(capacity, _) => aQueue.remainingCapacity should ===(capacity)
|
||||
case UnboundedMailbox() => aQueue.remainingCapacity should ===(Int.MaxValue)
|
||||
}
|
||||
case _ ⇒
|
||||
case _ =>
|
||||
}
|
||||
q.numberOfMessages should ===(0)
|
||||
q.hasMessages should ===(false)
|
||||
|
|
@ -139,14 +139,14 @@ abstract class MailboxSpec extends AkkaSpec with BeforeAndAfterAll with BeforeAn
|
|||
occurrences = (enqueueN - dequeueN)) intercept {
|
||||
|
||||
def createProducer(fromNum: Int, toNum: Int): Future[Vector[Envelope]] = spawn {
|
||||
val messages = Vector() ++ (for (i ← fromNum to toNum) yield createMessageInvocation(i))
|
||||
for (i ← messages) q.enqueue(testActor, i)
|
||||
val messages = Vector() ++ (for (i <- fromNum to toNum) yield createMessageInvocation(i))
|
||||
for (i <- messages) q.enqueue(testActor, i)
|
||||
messages
|
||||
}
|
||||
|
||||
val producers = {
|
||||
val step = 500
|
||||
val ps = for (i ← (1 to enqueueN by step).toList) yield createProducer(i, Math.min(enqueueN, i + step - 1))
|
||||
val ps = for (i <- (1 to enqueueN by step).toList) yield createProducer(i, Math.min(enqueueN, i + step - 1))
|
||||
|
||||
if (parallel == false)
|
||||
ps foreach { Await.ready(_, remainingOrDefault) }
|
||||
|
|
@ -158,7 +158,7 @@ abstract class MailboxSpec extends AkkaSpec with BeforeAndAfterAll with BeforeAn
|
|||
var r = Vector[Envelope]()
|
||||
|
||||
while (producers.exists(_.isCompleted == false) || q.hasMessages)
|
||||
Option(q.dequeue) foreach { message ⇒ r = r :+ message }
|
||||
Option(q.dequeue) foreach { message => r = r :+ message }
|
||||
|
||||
r
|
||||
}
|
||||
|
|
@ -183,8 +183,8 @@ abstract class MailboxSpec extends AkkaSpec with BeforeAndAfterAll with BeforeAn
|
|||
class DefaultMailboxSpec extends MailboxSpec {
|
||||
lazy val name = "The default mailbox implementation"
|
||||
def factory = {
|
||||
case u: UnboundedMailbox ⇒ u.create(None, None)
|
||||
case b: BoundedMailbox ⇒ b.create(None, None)
|
||||
case u: UnboundedMailbox => u.create(None, None)
|
||||
case b: BoundedMailbox => b.create(None, None)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -192,8 +192,8 @@ class PriorityMailboxSpec extends MailboxSpec {
|
|||
val comparator = PriorityGenerator(_.##)
|
||||
lazy val name = "The priority mailbox implementation"
|
||||
def factory = {
|
||||
case UnboundedMailbox() ⇒ new UnboundedPriorityMailbox(comparator).create(None, None)
|
||||
case BoundedMailbox(capacity, pushTimeOut) ⇒ new BoundedPriorityMailbox(comparator, capacity, pushTimeOut).create(None, None)
|
||||
case UnboundedMailbox() => new UnboundedPriorityMailbox(comparator).create(None, None)
|
||||
case BoundedMailbox(capacity, pushTimeOut) => new BoundedPriorityMailbox(comparator, capacity, pushTimeOut).create(None, None)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -201,16 +201,16 @@ class StablePriorityMailboxSpec extends MailboxSpec {
|
|||
val comparator = PriorityGenerator(_.##)
|
||||
lazy val name = "The stable priority mailbox implementation"
|
||||
def factory = {
|
||||
case UnboundedMailbox() ⇒ new UnboundedStablePriorityMailbox(comparator).create(None, None)
|
||||
case BoundedMailbox(capacity, pushTimeOut) ⇒ new BoundedStablePriorityMailbox(comparator, capacity, pushTimeOut).create(None, None)
|
||||
case UnboundedMailbox() => new UnboundedStablePriorityMailbox(comparator).create(None, None)
|
||||
case BoundedMailbox(capacity, pushTimeOut) => new BoundedStablePriorityMailbox(comparator, capacity, pushTimeOut).create(None, None)
|
||||
}
|
||||
}
|
||||
|
||||
class ControlAwareMailboxSpec extends MailboxSpec {
|
||||
lazy val name = "The control aware mailbox implementation"
|
||||
def factory = {
|
||||
case UnboundedMailbox() ⇒ new UnboundedControlAwareMailbox().create(None, None)
|
||||
case BoundedMailbox(capacity, pushTimeOut) ⇒ new BoundedControlAwareMailbox(capacity, pushTimeOut).create(None, None)
|
||||
case UnboundedMailbox() => new UnboundedControlAwareMailbox().create(None, None)
|
||||
case BoundedMailbox(capacity, pushTimeOut) => new BoundedControlAwareMailbox(capacity, pushTimeOut).create(None, None)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -223,8 +223,8 @@ object CustomMailboxSpec {
|
|||
|
||||
class MyMailboxType(settings: ActorSystem.Settings, config: Config) extends MailboxType {
|
||||
override def create(owner: Option[ActorRef], system: Option[ActorSystem]) = owner match {
|
||||
case Some(o) ⇒ new MyMailbox(o)
|
||||
case None ⇒ throw new Exception("no mailbox owner given")
|
||||
case Some(o) => new MyMailbox(o)
|
||||
case None => throw new Exception("no mailbox owner given")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -238,8 +238,8 @@ class CustomMailboxSpec extends AkkaSpec(CustomMailboxSpec.config) {
|
|||
"support custom mailboxType" in {
|
||||
val actor = system.actorOf(Props.empty.withDispatcher("my-dispatcher"))
|
||||
awaitCond(actor match {
|
||||
case r: RepointableRef ⇒ r.isStarted
|
||||
case _ ⇒ true
|
||||
case r: RepointableRef => r.isStarted
|
||||
case _ => true
|
||||
}, 1 second, 10 millis)
|
||||
val queue = actor.asInstanceOf[ActorRefWithCell].underlying.asInstanceOf[ActorCell].mailbox.messageQueue
|
||||
queue.getClass should ===(classOf[CustomMailboxSpec.MyMailbox])
|
||||
|
|
@ -251,8 +251,8 @@ class SingleConsumerOnlyMailboxSpec extends MailboxSpec {
|
|||
lazy val name = "The single-consumer-only mailbox implementation"
|
||||
override def maxConsumers = 1
|
||||
def factory = {
|
||||
case u: UnboundedMailbox ⇒ SingleConsumerOnlyUnboundedMailbox().create(None, None)
|
||||
case b @ BoundedMailbox(capacity, _) ⇒ NonBlockingBoundedMailbox(capacity).create(None, None)
|
||||
case u: UnboundedMailbox => SingleConsumerOnlyUnboundedMailbox().create(None, None)
|
||||
case b @ BoundedMailbox(capacity, _) => NonBlockingBoundedMailbox(capacity).create(None, None)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -281,7 +281,7 @@ class SingleConsumerOnlyMailboxVerificationSpec extends AkkaSpec(SingleConsumerO
|
|||
context.actorOf(Props(new Actor {
|
||||
var n = total / 2
|
||||
def receive = {
|
||||
case Ping ⇒
|
||||
case Ping =>
|
||||
n -= 1
|
||||
sender() ! Ping
|
||||
if (n == 0)
|
||||
|
|
@ -289,8 +289,8 @@ class SingleConsumerOnlyMailboxVerificationSpec extends AkkaSpec(SingleConsumerO
|
|||
}
|
||||
}).withDispatcher(dispatcherId)))
|
||||
def receive = {
|
||||
case Ping ⇒ a.tell(Ping, b)
|
||||
case Terminated(`a` | `b`) ⇒ if (context.children.isEmpty) context stop self
|
||||
case Ping => a.tell(Ping, b)
|
||||
case Terminated(`a` | `b`) => if (context.children.isEmpty) context stop self
|
||||
}
|
||||
}))
|
||||
watch(runner)
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@ object PriorityDispatcherSpec {
|
|||
"""
|
||||
|
||||
class Unbounded(settings: ActorSystem.Settings, config: Config) extends UnboundedPriorityMailbox(PriorityGenerator({
|
||||
case i: Int ⇒ i //Reverse order
|
||||
case 'Result ⇒ Int.MaxValue
|
||||
}: Any ⇒ Int))
|
||||
case i: Int => i //Reverse order
|
||||
case 'Result => Int.MaxValue
|
||||
}: Any => Int))
|
||||
|
||||
class Bounded(settings: ActorSystem.Settings, config: Config) extends BoundedPriorityMailbox(PriorityGenerator({
|
||||
case i: Int ⇒ i //Reverse order
|
||||
case 'Result ⇒ Int.MaxValue
|
||||
}: Any ⇒ Int), 1000, 10 seconds)
|
||||
case i: Int => i //Reverse order
|
||||
case 'Result => Int.MaxValue
|
||||
}: Any => Int), 1000, 10 seconds)
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -60,13 +60,13 @@ class PriorityDispatcherSpec extends AkkaSpec(PriorityDispatcherSpec.config) wit
|
|||
|
||||
val acc = scala.collection.mutable.ListBuffer[Int]()
|
||||
|
||||
scala.util.Random.shuffle(msgs) foreach { m ⇒ self ! m }
|
||||
scala.util.Random.shuffle(msgs) foreach { m => self ! m }
|
||||
|
||||
self.tell('Result, testActor)
|
||||
|
||||
def receive = {
|
||||
case i: Int ⇒ acc += i
|
||||
case 'Result ⇒ sender() ! acc.toList
|
||||
case i: Int => acc += i
|
||||
case 'Result => sender() ! acc.toList
|
||||
}
|
||||
}).withDispatcher(dispatcherKey))
|
||||
|
||||
|
|
|
|||
|
|
@ -23,16 +23,16 @@ object StablePriorityDispatcherSpec {
|
|||
"""
|
||||
|
||||
class Unbounded(settings: ActorSystem.Settings, config: Config) extends UnboundedStablePriorityMailbox(PriorityGenerator({
|
||||
case i: Int if i <= 100 ⇒ i // Small integers have high priority
|
||||
case i: Int ⇒ 101 // Don't care for other integers
|
||||
case 'Result ⇒ Int.MaxValue
|
||||
}: Any ⇒ Int))
|
||||
case i: Int if i <= 100 => i // Small integers have high priority
|
||||
case i: Int => 101 // Don't care for other integers
|
||||
case 'Result => Int.MaxValue
|
||||
}: Any => Int))
|
||||
|
||||
class Bounded(settings: ActorSystem.Settings, config: Config) extends BoundedStablePriorityMailbox(PriorityGenerator({
|
||||
case i: Int if i <= 100 ⇒ i // Small integers have high priority
|
||||
case i: Int ⇒ 101 // Don't care for other integers
|
||||
case 'Result ⇒ Int.MaxValue
|
||||
}: Any ⇒ Int), 1000, 10 seconds)
|
||||
case i: Int if i <= 100 => i // Small integers have high priority
|
||||
case i: Int => 101 // Don't care for other integers
|
||||
case 'Result => Int.MaxValue
|
||||
}: Any => Int), 1000, 10 seconds)
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -64,13 +64,13 @@ class StablePriorityDispatcherSpec extends AkkaSpec(StablePriorityDispatcherSpec
|
|||
|
||||
val acc = scala.collection.mutable.ListBuffer[Int]()
|
||||
|
||||
shuffled foreach { m ⇒ self ! m }
|
||||
shuffled foreach { m => self ! m }
|
||||
|
||||
self.tell('Result, testActor)
|
||||
|
||||
def receive = {
|
||||
case i: Int ⇒ acc += i
|
||||
case 'Result ⇒ sender() ! acc.toList
|
||||
case i: Int => acc += i
|
||||
case 'Result => sender() ! acc.toList
|
||||
}
|
||||
}).withDispatcher(dispatcherKey))
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import com.typesafe.config.{ Config, ConfigFactory }
|
|||
object EventBusSpec {
|
||||
class TestActorWrapperActor(testActor: ActorRef) extends Actor {
|
||||
def receive = {
|
||||
case x ⇒ testActor forward x
|
||||
case x => testActor forward x
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -74,11 +74,11 @@ abstract class EventBusSpec(busName: String, conf: Config = ConfigFactory.empty(
|
|||
}
|
||||
|
||||
"allow to add multiple subscribers" in {
|
||||
val subscribers = (1 to 10) map { _ ⇒ createNewSubscriber() }
|
||||
val subscribers = (1 to 10) map { _ => createNewSubscriber() }
|
||||
val events = createEvents(10)
|
||||
val classifiers = events map getClassifierFor
|
||||
subscribers.zip(classifiers) forall { case (s, c) ⇒ bus.subscribe(s, c) } should ===(true)
|
||||
subscribers.zip(classifiers) forall { case (s, c) ⇒ bus.unsubscribe(s, c) } should ===(true)
|
||||
subscribers.zip(classifiers) forall { case (s, c) => bus.subscribe(s, c) } should ===(true)
|
||||
subscribers.zip(classifiers) forall { case (s, c) => bus.unsubscribe(s, c) } should ===(true)
|
||||
|
||||
subscribers foreach (disposeSubscriber(system, _))
|
||||
}
|
||||
|
|
@ -109,11 +109,11 @@ abstract class EventBusSpec(busName: String, conf: Config = ConfigFactory.empty(
|
|||
|
||||
"publish the given event to all intended subscribers" in {
|
||||
val range = 0 until 10
|
||||
val subscribers = range map (_ ⇒ createNewSubscriber())
|
||||
subscribers foreach { s ⇒ bus.subscribe(s, classifier) should ===(true) }
|
||||
val subscribers = range map (_ => createNewSubscriber())
|
||||
subscribers foreach { s => bus.subscribe(s, classifier) should ===(true) }
|
||||
bus.publish(event)
|
||||
range foreach { _ ⇒ expectMsg(event) }
|
||||
subscribers foreach { s ⇒ bus.unsubscribe(s, classifier) should ===(true); disposeSubscriber(system, s) }
|
||||
range foreach { _ => expectMsg(event) }
|
||||
subscribers foreach { s => bus.unsubscribe(s, classifier) should ===(true); disposeSubscriber(system, s) }
|
||||
}
|
||||
|
||||
"not publish the given event to any other subscribers than the intended ones" in {
|
||||
|
|
@ -261,16 +261,16 @@ class ActorEventBusSpec(conf: Config) extends EventBusSpec("ActorEventBus", conf
|
|||
private def expectUnsubscribedByUnsubscriber(p: TestProbe, a: ActorRef): Unit = {
|
||||
val expectedMsg = s"actor $a has terminated, unsubscribing it from $bus"
|
||||
p.fishForMessage(1 second, hint = expectedMsg) {
|
||||
case Logging.Debug(_, _, msg) if msg equals expectedMsg ⇒ true
|
||||
case other ⇒ false
|
||||
case Logging.Debug(_, _, msg) if msg equals expectedMsg => true
|
||||
case other => false
|
||||
}
|
||||
}
|
||||
|
||||
private def expectUnregisterFromUnsubscriber(p: TestProbe, a: ActorRef): Unit = {
|
||||
val expectedMsg = s"unregistered watch of $a in $bus"
|
||||
p.fishForMessage(1 second, hint = expectedMsg) {
|
||||
case Logging.Debug(_, _, msg) if msg equals expectedMsg ⇒ true
|
||||
case other ⇒ false
|
||||
case Logging.Debug(_, _, msg) if msg equals expectedMsg => true
|
||||
case other => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,13 +42,13 @@ object EventStreamSpec {
|
|||
class MyLog extends Actor {
|
||||
var dst: ActorRef = context.system.deadLetters
|
||||
def receive = {
|
||||
case Logging.InitializeLogger(bus) ⇒
|
||||
case Logging.InitializeLogger(bus) =>
|
||||
bus.subscribe(context.self, classOf[SetTarget])
|
||||
bus.subscribe(context.self, classOf[UnhandledMessage])
|
||||
sender() ! Logging.LoggerInitialized
|
||||
case SetTarget(ref) ⇒ { dst = ref; dst ! "OK" }
|
||||
case e: Logging.LogEvent ⇒ dst ! e
|
||||
case u: UnhandledMessage ⇒ dst ! u
|
||||
case SetTarget(ref) => { dst = ref; dst ! "OK" }
|
||||
case e: Logging.LogEvent => dst ! e
|
||||
case u: UnhandledMessage => dst ! u
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -289,7 +289,7 @@ class EventStreamSpec extends AkkaSpec(EventStreamSpec.config) {
|
|||
val tm = new A
|
||||
|
||||
val target = sys.actorOf(Props(new Actor {
|
||||
def receive = { case in ⇒ a1.ref forward in }
|
||||
def receive = { case in => a1.ref forward in }
|
||||
}), "to-be-killed")
|
||||
|
||||
es.subscribe(a2.ref, classOf[Any])
|
||||
|
|
@ -317,7 +317,7 @@ class EventStreamSpec extends AkkaSpec(EventStreamSpec.config) {
|
|||
val a1, a2 = TestProbe()
|
||||
|
||||
val target = system.actorOf(Props(new Actor {
|
||||
def receive = { case in ⇒ a1.ref forward in }
|
||||
def receive = { case in => a1.ref forward in }
|
||||
}), "to-be-killed")
|
||||
|
||||
watch(target)
|
||||
|
|
@ -416,8 +416,8 @@ class EventStreamSpec extends AkkaSpec(EventStreamSpec.config) {
|
|||
|
||||
private def fishForDebugMessage(a: TestProbe, messagePrefix: String, max: Duration = 3 seconds): Unit = {
|
||||
a.fishForMessage(max, hint = "expected debug message prefix: " + messagePrefix) {
|
||||
case Logging.Debug(_, _, msg: String) if msg startsWith messagePrefix ⇒ true
|
||||
case other ⇒ false
|
||||
case Logging.Debug(_, _, msg: String) if msg startsWith messagePrefix => true
|
||||
case other => false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,16 +89,16 @@ object LoggerSpec {
|
|||
abstract class TestLogger(qualifier: Int) extends Actor with Logging.StdOutLogger {
|
||||
var target: Option[ActorRef] = None
|
||||
override def receive: Receive = {
|
||||
case InitializeLogger(bus) ⇒
|
||||
case InitializeLogger(bus) =>
|
||||
bus.subscribe(context.self, classOf[SetTarget])
|
||||
sender() ! LoggerInitialized
|
||||
case SetTarget(ref, `qualifier`) ⇒
|
||||
case SetTarget(ref, `qualifier`) =>
|
||||
target = Some(ref)
|
||||
ref ! ("OK")
|
||||
case event: LogEvent if !event.mdc.isEmpty ⇒
|
||||
case event: LogEvent if !event.mdc.isEmpty =>
|
||||
print(event)
|
||||
target foreach { _ ! event }
|
||||
case event: LogEvent ⇒
|
||||
case event: LogEvent =>
|
||||
print(event)
|
||||
target foreach { _ ! event.message }
|
||||
}
|
||||
|
|
@ -107,11 +107,11 @@ object LoggerSpec {
|
|||
class SlowLogger extends Logging.DefaultLogger {
|
||||
override def aroundReceive(r: Receive, msg: Any): Unit = {
|
||||
msg match {
|
||||
case event: LogEvent ⇒
|
||||
case event: LogEvent =>
|
||||
if (event.message.toString.startsWith("msg1"))
|
||||
Thread.sleep(500) // slow
|
||||
super.aroundReceive(r, msg)
|
||||
case _ ⇒ super.aroundReceive(r, msg)
|
||||
case _ => super.aroundReceive(r, msg)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -122,17 +122,17 @@ object LoggerSpec {
|
|||
|
||||
override def mdc(currentMessage: Any): MDC = {
|
||||
reqId += 1
|
||||
val always = Map("requestId" → reqId)
|
||||
val always = Map("requestId" -> reqId)
|
||||
val cmim = "Current Message in MDC"
|
||||
val perMessage = currentMessage match {
|
||||
case `cmim` ⇒ Map[String, Any]("currentMsg" → cmim, "currentMsgLength" → cmim.length)
|
||||
case _ ⇒ Map()
|
||||
case `cmim` => Map[String, Any]("currentMsg" -> cmim, "currentMsgLength" -> cmim.length)
|
||||
case _ => Map()
|
||||
}
|
||||
always ++ perMessage
|
||||
}
|
||||
|
||||
def receive: Receive = {
|
||||
case m: String ⇒ log.warning(m)
|
||||
case m: String => log.warning(m)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -154,8 +154,8 @@ class LoggerSpec extends WordSpec with Matchers {
|
|||
// since logging is asynchronous ensure that it propagates
|
||||
if (shouldLog) {
|
||||
probe.fishForMessage(0.5.seconds.dilated) {
|
||||
case "Danger! Danger!" ⇒ true
|
||||
case _ ⇒ false
|
||||
case "Danger! Danger!" => true
|
||||
case _ => false
|
||||
}
|
||||
} else {
|
||||
probe.expectNoMsg(0.5.seconds.dilated)
|
||||
|
|
@ -238,12 +238,12 @@ class LoggerSpec extends WordSpec with Matchers {
|
|||
|
||||
ref ! "Processing new Request"
|
||||
probe.expectMsgPF(max = 3.seconds) {
|
||||
case w @ Warning(_, _, "Processing new Request") if w.mdc.size == 1 && w.mdc("requestId") == 1 ⇒
|
||||
case w @ Warning(_, _, "Processing new Request") if w.mdc.size == 1 && w.mdc("requestId") == 1 =>
|
||||
}
|
||||
|
||||
ref ! "Processing another Request"
|
||||
probe.expectMsgPF(max = 3.seconds) {
|
||||
case w @ Warning(_, _, "Processing another Request") if w.mdc.size == 1 && w.mdc("requestId") == 2 ⇒
|
||||
case w @ Warning(_, _, "Processing another Request") if w.mdc.size == 1 && w.mdc("requestId") == 2 =>
|
||||
}
|
||||
|
||||
ref ! "Current Message in MDC"
|
||||
|
|
@ -251,12 +251,12 @@ class LoggerSpec extends WordSpec with Matchers {
|
|||
case w @ Warning(_, _, "Current Message in MDC") if w.mdc.size == 3 &&
|
||||
w.mdc("requestId") == 3 &&
|
||||
w.mdc("currentMsg") == "Current Message in MDC" &&
|
||||
w.mdc("currentMsgLength") == 22 ⇒
|
||||
w.mdc("currentMsgLength") == 22 =>
|
||||
}
|
||||
|
||||
ref ! "Current Message removed from MDC"
|
||||
probe.expectMsgPF(max = 3.seconds) {
|
||||
case w @ Warning(_, _, "Current Message removed from MDC") if w.mdc.size == 1 && w.mdc("requestId") == 4 ⇒
|
||||
case w @ Warning(_, _, "Current Message removed from MDC") if w.mdc.size == 1 && w.mdc("requestId") == 4 =>
|
||||
}
|
||||
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ object LoggingReceiveSpec {
|
|||
class TestLogActor extends Actor {
|
||||
override val supervisorStrategy =
|
||||
OneForOneStrategy(maxNrOfRetries = 5, withinTimeRange = 5 seconds)(List(classOf[Throwable]))
|
||||
def receive = { case _ ⇒ }
|
||||
def receive = { case _ => }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -30,14 +30,14 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
akka.loglevel=DEBUG # test verifies debug
|
||||
akka.actor.serialize-messages = off # debug noise from serialization
|
||||
""").withFallback(AkkaSpec.testConf)
|
||||
val appLogging = ActorSystem("logging", ConfigFactory.parseMap(Map("akka.actor.debug.receive" → true).asJava).withFallback(config))
|
||||
val appAuto = ActorSystem("autoreceive", ConfigFactory.parseMap(Map("akka.actor.debug.autoreceive" → true).asJava).withFallback(config))
|
||||
val appLifecycle = ActorSystem("lifecycle", ConfigFactory.parseMap(Map("akka.actor.debug.lifecycle" → true).asJava).withFallback(config))
|
||||
val appLogging = ActorSystem("logging", ConfigFactory.parseMap(Map("akka.actor.debug.receive" -> true).asJava).withFallback(config))
|
||||
val appAuto = ActorSystem("autoreceive", ConfigFactory.parseMap(Map("akka.actor.debug.autoreceive" -> true).asJava).withFallback(config))
|
||||
val appLifecycle = ActorSystem("lifecycle", ConfigFactory.parseMap(Map("akka.actor.debug.lifecycle" -> true).asJava).withFallback(config))
|
||||
|
||||
val filter = TestEvent.Mute(EventFilter.custom {
|
||||
case _: Logging.Debug ⇒ true
|
||||
case _: Logging.Info ⇒ true
|
||||
case _ ⇒ false
|
||||
case _: Logging.Debug => true
|
||||
case _: Logging.Info => true
|
||||
case _ => false
|
||||
})
|
||||
appLogging.eventStream.publish(filter)
|
||||
appAuto.eventStream.publish(filter)
|
||||
|
|
@ -45,7 +45,7 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
|
||||
def ignoreMute(t: TestKit): Unit = {
|
||||
t.ignoreMsg {
|
||||
case (_: TestEvent.Mute | _: TestEvent.UnMute) ⇒ true
|
||||
case (_: TestEvent.Mute | _: TestEvent.UnMute) => true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
system.eventStream.subscribe(testActor, classOf[UnhandledMessage])
|
||||
val a = system.actorOf(Props(new Actor {
|
||||
def receive = new LoggingReceive(Some("funky"), {
|
||||
case null ⇒
|
||||
case null =>
|
||||
})
|
||||
}))
|
||||
a ! "hallo"
|
||||
|
|
@ -80,13 +80,13 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
system.eventStream.subscribe(testActor, classOf[UnhandledMessage])
|
||||
|
||||
val r: Actor.Receive = {
|
||||
case null ⇒
|
||||
case null =>
|
||||
}
|
||||
|
||||
val actor = TestActorRef(new Actor {
|
||||
def switch: Actor.Receive = { case "becomenull" ⇒ context.become(r, false) }
|
||||
def switch: Actor.Receive = { case "becomenull" => context.become(r, false) }
|
||||
def receive = switch orElse LoggingReceive {
|
||||
case x ⇒ sender() ! "x"
|
||||
case x => sender() ! "x"
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
|
||||
actor ! "bah"
|
||||
expectMsgPF() {
|
||||
case UnhandledMessage("bah", testActor, `actor`) ⇒ true
|
||||
case UnhandledMessage("bah", testActor, `actor`) => true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
system.eventStream.subscribe(testActor, classOf[Logging.Debug])
|
||||
val actor = TestActorRef(new Actor {
|
||||
def receive = LoggingReceive(LoggingReceive {
|
||||
case _ ⇒ sender() ! "x"
|
||||
case _ => sender() ! "x"
|
||||
})
|
||||
})
|
||||
actor ! "buh"
|
||||
|
|
@ -123,16 +123,16 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
"log with MDC" in {
|
||||
new TestKit(appLogging) {
|
||||
system.eventStream.subscribe(testActor, classOf[Logging.Debug])
|
||||
val myMDC = Map("hello" → "mdc")
|
||||
val myMDC = Map("hello" -> "mdc")
|
||||
val a = system.actorOf(Props(new Actor with DiagnosticActorLogging {
|
||||
override def mdc(currentMessage: Any) = myMDC
|
||||
def receive = LoggingReceive {
|
||||
case "hello" ⇒
|
||||
case "hello" =>
|
||||
}
|
||||
}))
|
||||
a ! "hello"
|
||||
expectMsgPF(hint = "Logging.Debug2") {
|
||||
case m: Logging.Debug2 if m.mdc == myMDC ⇒ ()
|
||||
case m: Logging.Debug2 if m.mdc == myMDC => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
system.eventStream.subscribe(testActor, classOf[Logging.Info])
|
||||
val actor = TestActorRef(new Actor {
|
||||
def receive = LoggingReceive(Logging.InfoLevel) {
|
||||
case _ ⇒ sender() ! "x"
|
||||
case _ => sender() ! "x"
|
||||
}
|
||||
})
|
||||
actor ! "buh"
|
||||
|
|
@ -161,14 +161,14 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
system.eventStream.subscribe(testActor, classOf[Logging.Debug])
|
||||
val actor = TestActorRef(new Actor {
|
||||
def receive = {
|
||||
case _ ⇒
|
||||
case _ =>
|
||||
}
|
||||
})
|
||||
val name = actor.path.toString
|
||||
actor ! PoisonPill
|
||||
fishForMessage(hint = "received AutoReceiveMessage Envelope(PoisonPill") {
|
||||
case Logging.Debug(`name`, _, msg: String) if msg startsWith "received AutoReceiveMessage Envelope(PoisonPill" ⇒ true
|
||||
case _ ⇒ false
|
||||
case Logging.Debug(`name`, _, msg: String) if msg startsWith "received AutoReceiveMessage Envelope(PoisonPill" => true
|
||||
case _ => false
|
||||
}
|
||||
awaitCond(actor.isTerminated)
|
||||
}
|
||||
|
|
@ -184,15 +184,15 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
val sname = supervisor.path.toString
|
||||
|
||||
fishForMessage(hint = "now supervising") {
|
||||
case Logging.Debug(`lname`, _, msg: String) if msg startsWith "now supervising" ⇒ true
|
||||
case _ ⇒ false
|
||||
case Logging.Debug(`lname`, _, msg: String) if msg startsWith "now supervising" => true
|
||||
case _ => false
|
||||
}
|
||||
|
||||
TestActorRef[TestLogActor](Props[TestLogActor], supervisor, "none")
|
||||
|
||||
fishForMessage(hint = "now supervising") {
|
||||
case Logging.Debug(`sname`, _, msg: String) if msg startsWith "now supervising" ⇒ true
|
||||
case _ ⇒ false
|
||||
case Logging.Debug(`sname`, _, msg: String) if msg startsWith "now supervising" => true
|
||||
case _ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -209,14 +209,14 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
|
||||
supervisor watch actor
|
||||
fishForMessage(hint = "now watched by") {
|
||||
case Logging.Debug(`aname`, `sclass`, msg: String) if msg.startsWith("now watched by") ⇒ true
|
||||
case m ⇒ false
|
||||
case Logging.Debug(`aname`, `sclass`, msg: String) if msg.startsWith("now watched by") => true
|
||||
case m => false
|
||||
}
|
||||
|
||||
supervisor unwatch actor
|
||||
fishForMessage(hint = "no longer watched by") {
|
||||
case Logging.Debug(`aname`, `sclass`, msg: String) if msg.startsWith("no longer watched by") ⇒ true
|
||||
case _ ⇒ false
|
||||
case Logging.Debug(`aname`, `sclass`, msg: String) if msg.startsWith("no longer watched by") => true
|
||||
case _ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -232,8 +232,8 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
val sclass = classOf[TestLogActor]
|
||||
|
||||
expectMsgAllPF(messages = 2) {
|
||||
case Logging.Debug(`sname`, `sclass`, msg: String) if msg startsWith "started" ⇒ 0
|
||||
case Logging.Debug(_, _, msg: String) if msg startsWith "now supervising" ⇒ 1
|
||||
case Logging.Debug(`sname`, `sclass`, msg: String) if msg startsWith "started" => 0
|
||||
case Logging.Debug(_, _, msg: String) if msg startsWith "now supervising" => 1
|
||||
}
|
||||
|
||||
val actor = TestActorRef[TestLogActor](Props[TestLogActor], supervisor, "none")
|
||||
|
|
@ -241,16 +241,16 @@ class LoggingReceiveSpec extends WordSpec with BeforeAndAfterAll {
|
|||
val aclass = classOf[TestLogActor]
|
||||
|
||||
expectMsgAllPF(messages = 2) {
|
||||
case Logging.Debug(`aname`, `aclass`, msg: String) if msg.startsWith("started (" + classOf[TestLogActor].getName) ⇒ 0
|
||||
case Logging.Debug(`sname`, `sclass`, msg: String) if msg == s"now supervising TestActor[$aname]" ⇒ 1
|
||||
case Logging.Debug(`aname`, `aclass`, msg: String) if msg.startsWith("started (" + classOf[TestLogActor].getName) => 0
|
||||
case Logging.Debug(`sname`, `sclass`, msg: String) if msg == s"now supervising TestActor[$aname]" => 1
|
||||
}
|
||||
|
||||
EventFilter[ActorKilledException](occurrences = 1) intercept {
|
||||
actor ! Kill
|
||||
expectMsgAllPF(messages = 3) {
|
||||
case Logging.Error(_: ActorKilledException, `aname`, _, "Kill") ⇒ 0
|
||||
case Logging.Debug(`aname`, `aclass`, "restarting") ⇒ 1
|
||||
case Logging.Debug(`aname`, `aclass`, "restarted") ⇒ 2
|
||||
case Logging.Error(_: ActorKilledException, `aname`, _, "Kill") => 0
|
||||
case Logging.Debug(`aname`, `aclass`, "restarting") => 1
|
||||
case Logging.Debug(`aname`, `aclass`, "restarted") => 2
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import akka.testkit._
|
|||
|
||||
class MarkerLoggingSpec extends AkkaSpec with ImplicitSender {
|
||||
"A MarkerLoggerAdapter" should {
|
||||
val markerLogging = new MarkerLoggingAdapter(system.eventStream, getClass.getName, this.getClass, new DefaultLoggingFilter(() ⇒ Logging.InfoLevel))
|
||||
val markerLogging = new MarkerLoggingAdapter(system.eventStream, getClass.getName, this.getClass, new DefaultLoggingFilter(() => Logging.InfoLevel))
|
||||
|
||||
"add markers to logging" in {
|
||||
system.eventStream.subscribe(self, classOf[Info])
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ object JavaLoggerSpec {
|
|||
|
||||
class LogProducer extends Actor with ActorLogging {
|
||||
def receive = {
|
||||
case e: Exception ⇒
|
||||
case e: Exception =>
|
||||
log.error(e, e.getMessage)
|
||||
case (s: String, x: Int) ⇒
|
||||
case (s: String, x: Int) =>
|
||||
log.info(s, x)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class InetAddressDnsResolverSpec extends AkkaSpec("""
|
|||
akka.io.dns.inet-address.positive-ttl = default
|
||||
akka.io.dns.inet-address.negative-ttl = default
|
||||
akka.actor.serialize-creators = on
|
||||
""") { thisSpecs ⇒
|
||||
""") { thisSpecs =>
|
||||
|
||||
"The DNS resolver default ttl's" must {
|
||||
"use the default value for positive caching if it is not overridden" in {
|
||||
|
|
@ -96,23 +96,23 @@ class InetAddressDnsResolverSpec extends AkkaSpec("""
|
|||
actorRef.underlyingActor
|
||||
}
|
||||
|
||||
private def withNewSystemProperty[T](property: String, testValue: String)(test: ⇒ T): T = {
|
||||
private def withNewSystemProperty[T](property: String, testValue: String)(test: => T): T = {
|
||||
val oldValue = Option(System.getProperty(property))
|
||||
try {
|
||||
System.setProperty(property, testValue)
|
||||
test
|
||||
} finally {
|
||||
oldValue.foreach(v ⇒ System.setProperty(property, v))
|
||||
oldValue.foreach(v => System.setProperty(property, v))
|
||||
}
|
||||
}
|
||||
|
||||
private def withNewSecurityProperty[T](property: String, testValue: String)(test: ⇒ T): T = {
|
||||
private def withNewSecurityProperty[T](property: String, testValue: String)(test: => T): T = {
|
||||
val oldValue = Option(Security.getProperty(property))
|
||||
try {
|
||||
Security.setProperty(property, testValue)
|
||||
test
|
||||
} finally {
|
||||
oldValue.foreach(v ⇒ Security.setProperty(property, v))
|
||||
oldValue.foreach(v => Security.setProperty(property, v))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ class InetAddressDnsResolverConfigSpec extends AkkaSpec(
|
|||
akka.io.dns.inet-address.negative-ttl = never
|
||||
akka.actor.serialize-creators = on
|
||||
""") {
|
||||
thisSpecs ⇒
|
||||
thisSpecs =>
|
||||
|
||||
"The DNS resolver parsed ttl's" must {
|
||||
"use ttl=Long.MaxValue if user provides 'forever' " in {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
akka.io.tcp.trace-logging = on
|
||||
akka.io.tcp.register-timeout = 500ms
|
||||
akka.actor.serialize-creators = on
|
||||
""") with WithLogCapturing { thisSpecs ⇒
|
||||
""") with WithLogCapturing { thisSpecs =>
|
||||
import TcpConnectionSpec._
|
||||
|
||||
// Helper to avoid Windows localization specific differences
|
||||
|
|
@ -67,7 +67,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
clientSocket.read(ByteBuffer.allocate(1))
|
||||
null
|
||||
} catch {
|
||||
case NonFatal(e) ⇒ e.getMessage
|
||||
case NonFatal(e) => e.getMessage
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
clientSocket.write(ByteBuffer.allocate(1))
|
||||
null
|
||||
} catch {
|
||||
case NonFatal(e) ⇒ e.getMessage.take(15)
|
||||
case NonFatal(e) => e.getMessage.take(15)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -248,7 +248,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
val writer = Files.newBufferedWriter(tmpFile)
|
||||
val oneKByteOfF = Array.fill[Char](1000)('F')
|
||||
// 10 mb of f:s in a file
|
||||
for (_ ← 0 to 10000) {
|
||||
for (_ <- 0 to 10000) {
|
||||
writer.write(oneKByteOfF)
|
||||
}
|
||||
writer.flush()
|
||||
|
|
@ -718,7 +718,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
}
|
||||
// dump the NACKs
|
||||
writer.receiveWhile(1.second) {
|
||||
case CommandFailed(write) ⇒ written -= 1
|
||||
case CommandFailed(write) => written -= 1
|
||||
}
|
||||
writer.msgAvailable should ===(false)
|
||||
|
||||
|
|
@ -756,7 +756,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
}
|
||||
// dump the NACKs
|
||||
writer.receiveWhile(1.second) {
|
||||
case CommandFailed(write) ⇒ written -= 1
|
||||
case CommandFailed(write) => written -= 1
|
||||
}
|
||||
|
||||
// drain the queue until it works again
|
||||
|
|
@ -792,7 +792,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
}
|
||||
// dump the NACKs
|
||||
writer.receiveWhile(1.second) {
|
||||
case CommandFailed(write) ⇒ written -= 1
|
||||
case CommandFailed(write) => written -= 1
|
||||
}
|
||||
writer.msgAvailable should ===(false)
|
||||
|
||||
|
|
@ -825,7 +825,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
}
|
||||
// dump the NACKs
|
||||
writer.receiveWhile(1.second) {
|
||||
case CommandFailed(write) ⇒ written -= 1
|
||||
case CommandFailed(write) => written -= 1
|
||||
}
|
||||
|
||||
// drain the queue until it works again
|
||||
|
|
@ -859,7 +859,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
expectTerminated(connectionActor)
|
||||
an[IOException] should be thrownBy { socket.getInputStream.read() }
|
||||
} catch {
|
||||
case e: SocketTimeoutException ⇒
|
||||
case e: SocketTimeoutException =>
|
||||
// thrown by serverSocket.accept, this may happen if network is offline
|
||||
info(e.getMessage)
|
||||
pending
|
||||
|
|
@ -895,7 +895,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
if (Helpers.isWindows) interestCallReceiver.expectMsg(OP_CONNECT)
|
||||
}
|
||||
|
||||
def run(body: ⇒ Unit): Unit = {
|
||||
def run(body: => Unit): Unit = {
|
||||
try {
|
||||
setServerSocketOptions()
|
||||
localServerChannel.socket.bind(serverAddress)
|
||||
|
|
@ -923,10 +923,10 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
new ChannelRegistration {
|
||||
def enableInterest(op: Int): Unit = interestCallReceiver.ref ! op
|
||||
def disableInterest(op: Int): Unit = interestCallReceiver.ref ! -op
|
||||
def cancelAndClose(andThen: () ⇒ Unit): Unit = onCancelAndClose(andThen)
|
||||
def cancelAndClose(andThen: () => Unit): Unit = onCancelAndClose(andThen)
|
||||
}
|
||||
|
||||
protected def onCancelAndClose(andThen: () ⇒ Unit): Unit = andThen()
|
||||
protected def onCancelAndClose(andThen: () => Unit): Unit = andThen()
|
||||
|
||||
def createConnectionActorWithoutRegistration(
|
||||
serverAddress: InetSocketAddress = serverAddress,
|
||||
|
|
@ -940,7 +940,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
})
|
||||
}
|
||||
|
||||
trait SmallRcvBuffer { _: LocalServerTest ⇒
|
||||
trait SmallRcvBuffer { _: LocalServerTest =>
|
||||
override def setServerSocketOptions(): Unit = localServerChannel.socket.setReceiveBufferSize(1024)
|
||||
}
|
||||
|
||||
|
|
@ -950,7 +950,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
// calling .underlyingActor ensures that the actor is actually created at this point
|
||||
lazy val clientSideChannel = connectionActor.underlyingActor.channel
|
||||
|
||||
override def run(body: ⇒ Unit): Unit = super.run {
|
||||
override def run(body: => Unit): Unit = super.run {
|
||||
registerCallReceiver.expectMsg(Registration(clientSideChannel, 0))
|
||||
registerCallReceiver.sender should ===(connectionActor)
|
||||
body
|
||||
|
|
@ -984,7 +984,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
if (Helpers.isWindows) clientSelectionKey.interestOps(OP_CONNECT)
|
||||
}
|
||||
|
||||
override def run(body: ⇒ Unit): Unit = super.run {
|
||||
override def run(body: => Unit): Unit = super.run {
|
||||
try {
|
||||
serverSideChannel.configureBlocking(false)
|
||||
serverSideChannel should not be (null)
|
||||
|
|
@ -1039,7 +1039,7 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
(sel, key)
|
||||
}
|
||||
|
||||
override protected def onCancelAndClose(andThen: () ⇒ Unit): Unit =
|
||||
override protected def onCancelAndClose(andThen: () => Unit): Unit =
|
||||
try {
|
||||
if (clientSideChannel.isOpen) clientSideChannel.close()
|
||||
if (nioSelector.isOpen) {
|
||||
|
|
@ -1072,9 +1072,9 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
if (nioSelector.selectedKeys().contains(serverSelectionKey)) {
|
||||
if (into eq defaultbuffer) into.clear()
|
||||
serverSideChannel.read(into) match {
|
||||
case -1 ⇒ throw new IllegalStateException("Connection was closed unexpectedly with remaining bytes " + remaining)
|
||||
case 0 ⇒ throw new IllegalStateException("Made no progress")
|
||||
case other ⇒ other
|
||||
case -1 => throw new IllegalStateException("Connection was closed unexpectedly with remaining bytes " + remaining)
|
||||
case 0 => throw new IllegalStateException("Made no progress")
|
||||
case other => other
|
||||
}
|
||||
} else 0
|
||||
|
||||
|
|
@ -1111,14 +1111,14 @@ class TcpConnectionSpec extends AkkaSpec("""
|
|||
}
|
||||
|
||||
val interestsNames =
|
||||
Seq(OP_ACCEPT → "accepting", OP_CONNECT → "connecting", OP_READ → "reading", OP_WRITE → "writing")
|
||||
Seq(OP_ACCEPT -> "accepting", OP_CONNECT -> "connecting", OP_READ -> "reading", OP_WRITE -> "writing")
|
||||
def interestsDesc(interests: Int): String =
|
||||
interestsNames.filter(i ⇒ (i._1 & interests) != 0).map(_._2).mkString(", ")
|
||||
interestsNames.filter(i => (i._1 & interests) != 0).map(_._2).mkString(", ")
|
||||
|
||||
def abortClose(channel: SocketChannel): Unit = {
|
||||
try channel.socket.setSoLinger(true, 0) // causes the following close() to send TCP RST
|
||||
catch {
|
||||
case NonFatal(e) ⇒
|
||||
case NonFatal(e) =>
|
||||
// setSoLinger can fail due to http://bugs.sun.com/view_bug.do?bug_id=6799574
|
||||
// (also affected: OS/X Java 1.6.0_37)
|
||||
log.debug("setSoLinger(true, 0) failed with {}", e)
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ class TcpIntegrationSpec extends AkkaSpec("""
|
|||
val endpoint = new InetSocketAddress("192.0.2.1", 23825)
|
||||
connectCommander.send(IO(Tcp), Connect(endpoint))
|
||||
// expecting CommandFailed or no reply (within timeout)
|
||||
val replies = connectCommander.receiveWhile(1.second) { case m: Connected ⇒ m }
|
||||
val replies = connectCommander.receiveWhile(1.second) { case m: Connected => m }
|
||||
replies should ===(Nil)
|
||||
}
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ class TcpIntegrationSpec extends AkkaSpec("""
|
|||
try {
|
||||
accept.getInputStream.read() should ===(-1)
|
||||
} catch {
|
||||
case e: IOException ⇒ // this is also fine
|
||||
case e: IOException => // this is also fine
|
||||
}
|
||||
}
|
||||
verifyActorTermination(connectionActor)
|
||||
|
|
@ -203,7 +203,7 @@ class TcpIntegrationSpec extends AkkaSpec("""
|
|||
rounds: Int = 100) = {
|
||||
|
||||
val testData = ByteString(0)
|
||||
(1 to rounds) foreach { _ ⇒
|
||||
(1 to rounds) foreach { _ =>
|
||||
clientHandler.send(clientConnection, Write(testData))
|
||||
serverHandler.expectMsg(Received(testData))
|
||||
serverHandler.send(serverConnection, Write(testData))
|
||||
|
|
|
|||
|
|
@ -14,14 +14,14 @@ import Tcp._
|
|||
import akka.actor.ActorSystem
|
||||
import akka.dispatch.ExecutionContexts
|
||||
|
||||
trait TcpIntegrationSpecSupport { _: AkkaSpec ⇒
|
||||
trait TcpIntegrationSpecSupport { _: AkkaSpec =>
|
||||
|
||||
class TestSetup(shouldBindServer: Boolean = true, runClientInExtraSystem: Boolean = true) {
|
||||
val clientSystem =
|
||||
if (runClientInExtraSystem) {
|
||||
val res = ActorSystem("TcpIntegrationSpec-client", system.settings.config)
|
||||
// terminate clientSystem after server system
|
||||
system.whenTerminated.onComplete { _ ⇒ res.terminate() }(ExecutionContexts.sameThreadExecutionContext)
|
||||
system.whenTerminated.onComplete { _ => res.terminate() }(ExecutionContexts.sameThreadExecutionContext)
|
||||
res
|
||||
} else system
|
||||
val bindHandler = TestProbe()
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class TcpListenerSpec extends AkkaSpec("""
|
|||
listener ! new ChannelRegistration {
|
||||
def disableInterest(op: Int) = ()
|
||||
def enableInterest(op: Int) = ()
|
||||
def cancelAndClose(andThen: () ⇒ Unit): Unit = ()
|
||||
def cancelAndClose(andThen: () => Unit): Unit = ()
|
||||
}
|
||||
bindCommander.expectMsgType[Bound]
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ class TcpListenerSpec extends AkkaSpec("""
|
|||
listener ! new ChannelRegistration {
|
||||
def enableInterest(op: Int): Unit = interestCallReceiver.ref ! op
|
||||
def disableInterest(op: Int): Unit = interestCallReceiver.ref ! -op
|
||||
def cancelAndClose(andThen: () ⇒ Unit): Unit = {
|
||||
def cancelAndClose(andThen: () => Unit): Unit = {
|
||||
register.channel.close()
|
||||
require(!register.channel.isRegistered)
|
||||
andThen()
|
||||
|
|
@ -167,7 +167,7 @@ class TcpListenerSpec extends AkkaSpec("""
|
|||
|
||||
def expectWorkerForCommand: SocketChannel =
|
||||
selectorRouter.expectMsgPF() {
|
||||
case WorkerForCommand(RegisterIncoming(chan), commander, _) ⇒
|
||||
case WorkerForCommand(RegisterIncoming(chan), commander, _) =>
|
||||
chan.isOpen should ===(true)
|
||||
commander should ===(listener)
|
||||
chan
|
||||
|
|
@ -180,7 +180,7 @@ class TcpListenerSpec extends AkkaSpec("""
|
|||
name = "test-listener-" + counter.next())
|
||||
parent.watch(listener)
|
||||
def receive: Receive = {
|
||||
case msg ⇒ parent.ref forward msg
|
||||
case msg => parent.ref forward msg
|
||||
}
|
||||
override def supervisorStrategy = SupervisorStrategy.stoppingStrategy
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class UdpConnectedIntegrationSpec extends AkkaSpec("""
|
|||
connectUdp(localAddress = None, serverAddress, testActor) ! UdpConnected.Send(data1)
|
||||
|
||||
val clientAddress = expectMsgPF() {
|
||||
case Udp.Received(d, a) ⇒
|
||||
case Udp.Received(d, a) =>
|
||||
d should ===(data1)
|
||||
a
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ class UdpConnectedIntegrationSpec extends AkkaSpec("""
|
|||
connectUdp(Some(clientAddress), serverAddress, testActor) ! UdpConnected.Send(data1)
|
||||
|
||||
expectMsgPF() {
|
||||
case Udp.Received(d, a) ⇒
|
||||
case Udp.Received(d, a) =>
|
||||
d should ===(data1)
|
||||
a should ===(clientAddress)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class UdpIntegrationSpec extends AkkaSpec("""
|
|||
def checkSendingToClient(): Unit = {
|
||||
server ! Send(data, clientAddress)
|
||||
expectMsgPF() {
|
||||
case Received(d, a) ⇒
|
||||
case Received(d, a) =>
|
||||
d should ===(data)
|
||||
a should ===(serverAddress)
|
||||
}
|
||||
|
|
@ -81,15 +81,15 @@ class UdpIntegrationSpec extends AkkaSpec("""
|
|||
def checkSendingToServer(): Unit = {
|
||||
client ! Send(data, serverAddress)
|
||||
expectMsgPF() {
|
||||
case Received(d, a) ⇒
|
||||
case Received(d, a) =>
|
||||
d should ===(data)
|
||||
a should ===(clientAddress)
|
||||
}
|
||||
}
|
||||
|
||||
(0 until 20).foreach(_ ⇒ checkSendingToServer())
|
||||
(0 until 20).foreach(_ ⇒ checkSendingToClient())
|
||||
(0 until 20).foreach { i ⇒
|
||||
(0 until 20).foreach(_ => checkSendingToServer())
|
||||
(0 until 20).foreach(_ => checkSendingToClient())
|
||||
(0 until 20).foreach { i =>
|
||||
if (i % 2 == 0) checkSendingToServer()
|
||||
else checkSendingToClient()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,12 +90,12 @@ class AsyncDnsResolverIntegrationSpec extends AkkaSpec(
|
|||
val answer = resolve(name)
|
||||
answer.name shouldEqual name
|
||||
|
||||
answer.records.collect { case r: ARecord ⇒ r.ip }.toSet shouldEqual Set(
|
||||
answer.records.collect { case r: ARecord => r.ip }.toSet shouldEqual Set(
|
||||
InetAddress.getByName("192.168.1.23"),
|
||||
InetAddress.getByName("192.168.1.24")
|
||||
)
|
||||
|
||||
answer.records.collect { case r: AAAARecord ⇒ r.ip }.toSet shouldEqual Set(
|
||||
answer.records.collect { case r: AAAARecord => r.ip }.toSet shouldEqual Set(
|
||||
InetAddress.getByName("fd4d:36b2:3eca:a2d8:0:0:0:4"),
|
||||
InetAddress.getByName("fd4d:36b2:3eca:a2d8:0:0:0:5")
|
||||
)
|
||||
|
|
@ -105,10 +105,10 @@ class AsyncDnsResolverIntegrationSpec extends AkkaSpec(
|
|||
val name = "cname-ext.foo.test"
|
||||
val answer = (IO(Dns) ? DnsProtocol.Resolve(name)).mapTo[DnsProtocol.Resolved].futureValue
|
||||
answer.name shouldEqual name
|
||||
answer.records.collect { case r: CNameRecord ⇒ r.canonicalName }.toSet shouldEqual Set(
|
||||
answer.records.collect { case r: CNameRecord => r.canonicalName }.toSet shouldEqual Set(
|
||||
"a-single.bar.example"
|
||||
)
|
||||
answer.records.collect { case r: ARecord ⇒ r.ip }.toSet shouldEqual Set(
|
||||
answer.records.collect { case r: ARecord => r.ip }.toSet shouldEqual Set(
|
||||
InetAddress.getByName("192.168.2.20")
|
||||
)
|
||||
}
|
||||
|
|
@ -117,10 +117,10 @@ class AsyncDnsResolverIntegrationSpec extends AkkaSpec(
|
|||
val name = "cname-in.foo.test"
|
||||
val answer = resolve(name)
|
||||
answer.name shouldEqual name
|
||||
answer.records.collect { case r: CNameRecord ⇒ r.canonicalName }.toSet shouldEqual Set(
|
||||
answer.records.collect { case r: CNameRecord => r.canonicalName }.toSet shouldEqual Set(
|
||||
"a-double.foo.test"
|
||||
)
|
||||
answer.records.collect { case r: ARecord ⇒ r.ip }.toSet shouldEqual Set(
|
||||
answer.records.collect { case r: ARecord => r.ip }.toSet shouldEqual Set(
|
||||
InetAddress.getByName("192.168.1.21"),
|
||||
InetAddress.getByName("192.168.1.22")
|
||||
)
|
||||
|
|
@ -131,7 +131,7 @@ class AsyncDnsResolverIntegrationSpec extends AkkaSpec(
|
|||
val answer = resolve(name, Srv)
|
||||
|
||||
answer.name shouldEqual name
|
||||
answer.records.collect { case r: SRVRecord ⇒ r }.toSet shouldEqual Set(
|
||||
answer.records.collect { case r: SRVRecord => r }.toSet shouldEqual Set(
|
||||
SRVRecord("_service._tcp.foo.test", Ttl.fromPositive(86400.seconds), 10, 65534, 5060, "a-single.foo.test"),
|
||||
SRVRecord("_service._tcp.foo.test", Ttl.fromPositive(86400.seconds), 65533, 40, 65535, "a-double.foo.test")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import scala.concurrent.duration._
|
|||
import scala.util.Try
|
||||
import scala.util.control.NonFatal
|
||||
|
||||
trait DockerBindDnsService extends Eventually { self: AkkaSpec ⇒
|
||||
trait DockerBindDnsService extends Eventually { self: AkkaSpec =>
|
||||
val client = DefaultDockerClient.fromEnv().build()
|
||||
|
||||
val hostPort: Int
|
||||
|
|
@ -33,7 +33,7 @@ trait DockerBindDnsService extends Eventually { self: AkkaSpec ⇒
|
|||
try {
|
||||
client.pull(image)
|
||||
} catch {
|
||||
case NonFatal(_) ⇒
|
||||
case NonFatal(_) =>
|
||||
log.warning(s"Failed to pull docker image [$image], is docker running?")
|
||||
return
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ trait DockerBindDnsService extends Eventually { self: AkkaSpec ⇒
|
|||
val containerName = "akka-test-dns-" + getClass.getCanonicalName
|
||||
|
||||
client.listContainers(ListContainersParam.allContainers()).asScala
|
||||
.find(_.names().asScala.exists(_.contains(containerName))).foreach(c ⇒ {
|
||||
.find(_.names().asScala.exists(_.contains(containerName))).foreach(c => {
|
||||
if ("running" == c.state()) {
|
||||
client.killContainer(c.id)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import akka.testkit.{ AkkaSpec, TestProbe }
|
|||
import com.typesafe.config.ConfigFactory
|
||||
import akka.testkit.WithLogCapturing
|
||||
|
||||
import scala.collection.{ immutable ⇒ im }
|
||||
import scala.collection.{ immutable => im }
|
||||
import scala.concurrent.duration._
|
||||
|
||||
class AsyncDnsResolverSpec extends AkkaSpec(
|
||||
|
|
@ -77,7 +77,7 @@ class AsyncDnsResolverSpec extends AkkaSpec(
|
|||
"fails if all dns clients timeout" in new Setup {
|
||||
r ! Resolve("cats.com", Ip(ipv4 = true, ipv6 = false))
|
||||
senderProbe.expectMsgPF(remainingOrDefault) {
|
||||
case Failure(ResolveFailedException(_)) ⇒
|
||||
case Failure(ResolveFailedException(_)) =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ class AsyncDnsResolverSpec extends AkkaSpec(
|
|||
dnsClient2.expectMsg(Question4(2, "cats.com"))
|
||||
dnsClient2.reply(Failure(new RuntimeException("Yet another fail")))
|
||||
senderProbe.expectMsgPF(remainingOrDefault) {
|
||||
case Failure(ResolveFailedException(_)) ⇒
|
||||
case Failure(ResolveFailedException(_)) =>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ class AsyncDnsResolverSpec extends AkkaSpec(
|
|||
r ! Resolve(name)
|
||||
dnsClient1.expectNoMessage(50.millis)
|
||||
val answer = senderProbe.expectMsgType[Resolved]
|
||||
answer.records.collect { case r: ARecord ⇒ r }.toSet shouldEqual Set(
|
||||
answer.records.collect { case r: ARecord => r }.toSet shouldEqual Set(
|
||||
ARecord("127.0.0.1", Ttl.effectivelyForever, InetAddress.getByName("127.0.0.1"))
|
||||
)
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ class AsyncDnsResolverSpec extends AkkaSpec(
|
|||
r ! Resolve(name)
|
||||
dnsClient1.expectNoMessage(50.millis)
|
||||
val answer = senderProbe.expectMsgType[Resolved]
|
||||
val Seq(AAAARecord("1:2:3:0:0:0:0:0", Ttl.effectivelyForever, _)) = answer.records.collect { case r: AAAARecord ⇒ r }
|
||||
val Seq(AAAARecord("1:2:3:0:0:0:0:0", Ttl.effectivelyForever, _)) = answer.records.collect { case r: AAAARecord => r }
|
||||
}
|
||||
|
||||
"return additional records for SRV requests" in new Setup {
|
||||
|
|
@ -141,7 +141,7 @@ class AsyncDnsResolverSpec extends AkkaSpec(
|
|||
search-domains = []
|
||||
ndots = 1
|
||||
"""))
|
||||
system.actorOf(Props(new AsyncDnsResolver(settings, new AsyncDnsCache(), (_, _) ⇒ {
|
||||
system.actorOf(Props(new AsyncDnsResolver(settings, new AsyncDnsCache(), (_, _) => {
|
||||
clients
|
||||
})))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class AskSpec extends AkkaSpec {
|
|||
"The “ask” pattern" must {
|
||||
"send request to actor and wrap the answer in Future" in {
|
||||
implicit val timeout = Timeout(5.seconds)
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x ⇒ sender() ! x } }))
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x => sender() ! x } }))
|
||||
val f = echo ? "ping"
|
||||
f.futureValue should ===("ping")
|
||||
}
|
||||
|
|
@ -30,8 +30,8 @@ class AskSpec extends AkkaSpec {
|
|||
val f = dead.ask(42)(1 second)
|
||||
f.isCompleted should ===(true)
|
||||
f.value.get match {
|
||||
case Failure(_: AskTimeoutException) ⇒
|
||||
case v ⇒ fail(v + " was not Failure(AskTimeoutException)")
|
||||
case Failure(_: AskTimeoutException) =>
|
||||
case v => fail(v + " was not Failure(AskTimeoutException)")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -41,8 +41,8 @@ class AskSpec extends AkkaSpec {
|
|||
val f = empty ? 3.14
|
||||
f.isCompleted should ===(true)
|
||||
f.value.get match {
|
||||
case Failure(_: AskTimeoutException) ⇒
|
||||
case v ⇒ fail(v + " was not Failure(AskTimeoutException)")
|
||||
case Failure(_: AskTimeoutException) =>
|
||||
case v => fail(v + " was not Failure(AskTimeoutException)")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ class AskSpec extends AkkaSpec {
|
|||
|
||||
"return broken promises on 0 timeout" in {
|
||||
implicit val timeout = Timeout(0 seconds)
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x ⇒ sender() ! x } }))
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x => sender() ! x } }))
|
||||
val f = echo ? "foo"
|
||||
val expectedMsg = s"Timeout length must be positive, question not sent to [$echo]. Message of type [java.lang.String]."
|
||||
intercept[IllegalArgumentException] {
|
||||
|
|
@ -68,7 +68,7 @@ class AskSpec extends AkkaSpec {
|
|||
|
||||
"return broken promises on < 0 timeout" in {
|
||||
implicit val timeout = Timeout(-1000 seconds)
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x ⇒ sender() ! x } }))
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x => sender() ! x } }))
|
||||
val f = echo ? "foo"
|
||||
val expectedMsg = s"Timeout length must be positive, question not sent to [$echo]. Message of type [java.lang.String]."
|
||||
intercept[IllegalArgumentException] {
|
||||
|
|
@ -113,7 +113,7 @@ class AskSpec extends AkkaSpec {
|
|||
"work for ActorSelection" in {
|
||||
implicit val timeout = Timeout(5 seconds)
|
||||
import system.dispatcher
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x ⇒ sender() ! x } }), "select-echo")
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x => sender() ! x } }), "select-echo")
|
||||
val identityFuture = (system.actorSelection("/user/select-echo") ? Identify(None))
|
||||
.mapTo[ActorIdentity].map(_.ref.get)
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ class AskSpec extends AkkaSpec {
|
|||
val deadListener = TestProbe()
|
||||
system.eventStream.subscribe(deadListener.ref, classOf[DeadLetter])
|
||||
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x ⇒ context.actorSelection(sender().path) ! x } }), "select-echo2")
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x => context.actorSelection(sender().path) ! x } }), "select-echo2")
|
||||
val f = echo ? "hi"
|
||||
|
||||
Await.result(f, 1 seconds) should ===("hi")
|
||||
|
|
@ -138,7 +138,7 @@ class AskSpec extends AkkaSpec {
|
|||
val deadListener = TestProbe()
|
||||
system.eventStream.subscribe(deadListener.ref, classOf[DeadLetter])
|
||||
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x ⇒ context.actorSelection("/temp/*") ! x } }), "select-echo3")
|
||||
val echo = system.actorOf(Props(new Actor { def receive = { case x => context.actorSelection("/temp/*") ! x } }), "select-echo3")
|
||||
val f = echo ? "hi"
|
||||
intercept[AskTimeoutException] {
|
||||
Await.result(f, 1 seconds)
|
||||
|
|
@ -154,7 +154,7 @@ class AskSpec extends AkkaSpec {
|
|||
|
||||
val echo = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case x ⇒
|
||||
case x =>
|
||||
val name = sender.path.name
|
||||
val parent = sender.path.parent
|
||||
context.actorSelection(parent / ".." / "temp" / name) ! x
|
||||
|
|
@ -175,7 +175,7 @@ class AskSpec extends AkkaSpec {
|
|||
|
||||
val echo = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case x ⇒
|
||||
case x =>
|
||||
val name = sender.path.name
|
||||
val parent = sender.path.parent
|
||||
context.actorSelection(parent / "missing") ! x
|
||||
|
|
@ -195,7 +195,7 @@ class AskSpec extends AkkaSpec {
|
|||
|
||||
val echo = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case x ⇒
|
||||
case x =>
|
||||
context.actorSelection(sender().path / "missing") ! x
|
||||
}
|
||||
}), "select-echo6")
|
||||
|
|
@ -212,7 +212,7 @@ class AskSpec extends AkkaSpec {
|
|||
|
||||
val act = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case msg ⇒ p.ref ! sender() → msg
|
||||
case msg => p.ref ! sender() -> msg
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ class TestActor(probe: ActorRef) extends Actor {
|
|||
probe ! "STARTED"
|
||||
|
||||
def receive = {
|
||||
case "DIE" ⇒ context.stop(self)
|
||||
case "THROW" ⇒ throw new TestActor.NormalException
|
||||
case "THROW_STOPPING_EXCEPTION" ⇒ throw new TestActor.StoppingException
|
||||
case ("TO_PARENT", msg) ⇒ context.parent ! msg
|
||||
case other ⇒ probe ! other
|
||||
case "DIE" => context.stop(self)
|
||||
case "THROW" => throw new TestActor.NormalException
|
||||
case "THROW_STOPPING_EXCEPTION" => throw new TestActor.StoppingException
|
||||
case ("TO_PARENT", msg) => context.parent ! msg
|
||||
case other => probe ! other
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ class TestParentActor(probe: ActorRef, supervisorProps: Props) extends Actor {
|
|||
val supervisor = context.actorOf(supervisorProps)
|
||||
|
||||
def receive = {
|
||||
case other ⇒ probe.forward(other)
|
||||
case other => probe.forward(other)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ class BackoffOnRestartSupervisorSpec extends AkkaSpec with ImplicitSender {
|
|||
def supervisorProps(probeRef: ActorRef) = {
|
||||
val options = Backoff.onFailure(TestActor.props(probeRef), "someChildName", 200 millis, 10 seconds, 0.0, maxNrOfRetries = -1)
|
||||
.withSupervisorStrategy(OneForOneStrategy(maxNrOfRetries = 4, withinTimeRange = 30 seconds) {
|
||||
case _: TestActor.StoppingException ⇒ SupervisorStrategy.Stop
|
||||
case _: TestActor.StoppingException => SupervisorStrategy.Stop
|
||||
})
|
||||
BackoffSupervisor.props(options)
|
||||
}
|
||||
|
|
@ -125,10 +125,10 @@ class BackoffOnRestartSupervisorSpec extends AkkaSpec with ImplicitSender {
|
|||
|
||||
class SlowlyFailingActor(latch: CountDownLatch) extends Actor {
|
||||
def receive = {
|
||||
case "THROW" ⇒
|
||||
case "THROW" =>
|
||||
sender ! "THROWN"
|
||||
throw new NormalException
|
||||
case "PING" ⇒
|
||||
case "PING" =>
|
||||
sender ! "PONG"
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +141,7 @@ class BackoffOnRestartSupervisorSpec extends AkkaSpec with ImplicitSender {
|
|||
val postStopLatch = new CountDownLatch(1)
|
||||
val options = Backoff.onFailure(Props(new SlowlyFailingActor(postStopLatch)), "someChildName", 1 nanos, 1 nanos, 0.0, maxNrOfRetries = -1)
|
||||
.withSupervisorStrategy(OneForOneStrategy(loggingEnabled = false) {
|
||||
case _: TestActor.StoppingException ⇒ SupervisorStrategy.Stop
|
||||
case _: TestActor.StoppingException => SupervisorStrategy.Stop
|
||||
})
|
||||
val supervisor = system.actorOf(BackoffSupervisor.props(options))
|
||||
|
||||
|
|
@ -179,7 +179,7 @@ class BackoffOnRestartSupervisorSpec extends AkkaSpec with ImplicitSender {
|
|||
filterException[TestActor.TestException] {
|
||||
probe.watch(supervisor)
|
||||
// Have the child throw an exception 5 times, which is more than the max restarts allowed.
|
||||
for (i ← 1 to 5) {
|
||||
for (i <- 1 to 5) {
|
||||
supervisor ! "THROW"
|
||||
if (i < 5) {
|
||||
// Since we should've died on this throw, don't expect to be started.
|
||||
|
|
@ -199,14 +199,14 @@ class BackoffOnRestartSupervisorSpec extends AkkaSpec with ImplicitSender {
|
|||
// that is acceptable.
|
||||
val options = Backoff.onFailure(TestActor.props(probe.ref), "someChildName", 300 millis, 10 seconds, 0.0, maxNrOfRetries = -1)
|
||||
.withSupervisorStrategy(OneForOneStrategy(withinTimeRange = 1 seconds, maxNrOfRetries = 3) {
|
||||
case _: TestActor.StoppingException ⇒ SupervisorStrategy.Stop
|
||||
case _: TestActor.StoppingException => SupervisorStrategy.Stop
|
||||
})
|
||||
val supervisor = system.actorOf(BackoffSupervisor.props(options))
|
||||
probe.expectMsg("STARTED")
|
||||
filterException[TestActor.TestException] {
|
||||
probe.watch(supervisor)
|
||||
// Throw three times rapidly
|
||||
for (_ ← 1 to 3) {
|
||||
for (_ <- 1 to 3) {
|
||||
supervisor ! "THROW"
|
||||
probe.expectMsg("STARTED")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ object BackoffSupervisorSpec {
|
|||
|
||||
class Child(probe: ActorRef) extends Actor {
|
||||
def receive = {
|
||||
case "boom" ⇒ throw new TestException
|
||||
case msg ⇒ probe ! msg
|
||||
case "boom" => throw new TestException
|
||||
case msg => probe ! msg
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -35,8 +35,8 @@ object BackoffSupervisorSpec {
|
|||
|
||||
class ManualChild(probe: ActorRef) extends Actor {
|
||||
def receive = {
|
||||
case "boom" ⇒ throw new TestException
|
||||
case msg ⇒
|
||||
case "boom" => throw new TestException
|
||||
case msg =>
|
||||
probe ! msg
|
||||
context.parent ! BackoffSupervisor.Reset
|
||||
}
|
||||
|
|
@ -89,10 +89,10 @@ class BackoffSupervisorSpec extends AkkaSpec with ImplicitSender with Eventually
|
|||
}
|
||||
filterException[TestException] {
|
||||
val stoppingStrategy = OneForOneStrategy() {
|
||||
case _: TestException ⇒ SupervisorStrategy.Stop
|
||||
case _: TestException => SupervisorStrategy.Stop
|
||||
}
|
||||
val restartingStrategy = OneForOneStrategy() {
|
||||
case _: TestException ⇒ SupervisorStrategy.Restart
|
||||
case _: TestException => SupervisorStrategy.Restart
|
||||
}
|
||||
|
||||
assertCustomStrategy(
|
||||
|
|
@ -159,10 +159,10 @@ class BackoffSupervisorSpec extends AkkaSpec with ImplicitSender with Eventually
|
|||
}
|
||||
|
||||
val stoppingStrategy = OneForOneStrategy() {
|
||||
case _: TestException ⇒ SupervisorStrategy.Stop
|
||||
case _: TestException => SupervisorStrategy.Stop
|
||||
}
|
||||
val restartingStrategy = OneForOneStrategy() {
|
||||
case _: TestException ⇒ SupervisorStrategy.Restart
|
||||
case _: TestException => SupervisorStrategy.Restart
|
||||
}
|
||||
|
||||
assertManualReset(
|
||||
|
|
@ -237,7 +237,7 @@ class BackoffSupervisorSpec extends AkkaSpec with ImplicitSender with Eventually
|
|||
minBackoff: FiniteDuration,
|
||||
maxBackoff: FiniteDuration,
|
||||
randomFactor: Double,
|
||||
expectedResult: FiniteDuration) ⇒
|
||||
expectedResult: FiniteDuration) =>
|
||||
|
||||
val calculatedValue = BackoffSupervisor.calculateDelay(restartCount, minBackoff, maxBackoff, randomFactor)
|
||||
assert(calculatedValue === expectedResult)
|
||||
|
|
|
|||
|
|
@ -22,24 +22,24 @@ class CircuitBreakerMTSpec extends AkkaSpec {
|
|||
// returns true if the breaker is open
|
||||
def failingCall(): Boolean =
|
||||
Await.result(breaker.withCircuitBreaker(Future(throw new RuntimeException("FAIL"))) recover {
|
||||
case _: CircuitBreakerOpenException ⇒ true
|
||||
case _ ⇒ false
|
||||
case _: CircuitBreakerOpenException => true
|
||||
case _ => false
|
||||
}, remainingOrDefault)
|
||||
|
||||
// fire some failing calls
|
||||
1 to (maxFailures + 1) foreach { _ ⇒ failingCall() }
|
||||
1 to (maxFailures + 1) foreach { _ => failingCall() }
|
||||
// and then continue with failing calls until the breaker is open
|
||||
awaitCond(failingCall())
|
||||
}
|
||||
|
||||
def testCallsWithBreaker(): immutable.IndexedSeq[Future[String]] = {
|
||||
val aFewActive = new TestLatch(5)
|
||||
for (_ ← 1 to numberOfTestCalls) yield breaker.withCircuitBreaker(Future {
|
||||
for (_ <- 1 to numberOfTestCalls) yield breaker.withCircuitBreaker(Future {
|
||||
aFewActive.countDown()
|
||||
Await.ready(aFewActive, 5.seconds.dilated)
|
||||
"succeed"
|
||||
}) recoverWith {
|
||||
case _: CircuitBreakerOpenException ⇒
|
||||
case _: CircuitBreakerOpenException =>
|
||||
aFewActive.countDown()
|
||||
Future.successful("CBO")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,24 +28,24 @@ object CircuitBreakerSpec {
|
|||
val callTimeoutLatch = new TestLatch(1)
|
||||
val callBreakerOpenLatch = new TestLatch(1)
|
||||
|
||||
val callSuccessConsumerMock = mock[Long ⇒ Unit]
|
||||
val callFailureConsumerMock = mock[Long ⇒ Unit]
|
||||
val callTimeoutConsumerMock = mock[Long ⇒ Unit]
|
||||
val callSuccessConsumerMock = mock[Long => Unit]
|
||||
val callFailureConsumerMock = mock[Long => Unit]
|
||||
val callTimeoutConsumerMock = mock[Long => Unit]
|
||||
|
||||
def apply(): CircuitBreaker = instance
|
||||
instance
|
||||
.onClose(closedLatch.countDown())
|
||||
.onHalfOpen(halfOpenLatch.countDown())
|
||||
.onOpen(openLatch.countDown())
|
||||
.onCallSuccess(value ⇒ {
|
||||
.onCallSuccess(value => {
|
||||
callSuccessConsumerMock(value)
|
||||
callSuccessLatch.countDown()
|
||||
})
|
||||
.onCallFailure(value ⇒ {
|
||||
.onCallFailure(value => {
|
||||
callFailureConsumerMock(value)
|
||||
callFailureLatch.countDown()
|
||||
})
|
||||
.onCallTimeout(value ⇒ {
|
||||
.onCallTimeout(value => {
|
||||
callTimeoutConsumerMock(value)
|
||||
callTimeoutLatch.countDown()
|
||||
})
|
||||
|
|
@ -73,9 +73,9 @@ object CircuitBreakerSpec {
|
|||
def nonOneFactorCb()(implicit system: ActorSystem, ec: ExecutionContext): Breaker =
|
||||
new Breaker(new CircuitBreaker(system.scheduler, 1, 2000.millis.dilated, 1000.millis.dilated, 1.day.dilated, 5))
|
||||
|
||||
val evenNumberIsFailure: Try[Int] ⇒ Boolean = {
|
||||
case Success(i) ⇒ i % 2 == 0
|
||||
case _ ⇒ true
|
||||
val evenNumberIsFailure: Try[Int] => Boolean = {
|
||||
case Success(i) => i % 2 == 0
|
||||
case _ => true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ class CircuitBreakerSpec extends AkkaSpec with BeforeAndAfter with MockitoSugar
|
|||
intercept[TestException] { breaker().withSyncCircuitBreaker(throwException) }
|
||||
checkLatch(breaker.halfOpenLatch)
|
||||
|
||||
val allReturnIsSuccess: Try[String] ⇒ Boolean = _ ⇒ false
|
||||
val allReturnIsSuccess: Try[String] => Boolean = _ => false
|
||||
|
||||
intercept[TestException] { breaker().withSyncCircuitBreaker(throwException, allReturnIsSuccess) }
|
||||
checkLatch(breaker.closedLatch)
|
||||
|
|
@ -343,9 +343,9 @@ class CircuitBreakerSpec extends AkkaSpec with BeforeAndAfter with MockitoSugar
|
|||
breaker().currentFailureCount should ===(1)
|
||||
|
||||
val harmlessException = new TestException
|
||||
val harmlessExceptionAsSuccess: Try[String] ⇒ Boolean = {
|
||||
case Success(_) ⇒ false
|
||||
case Failure(ex) ⇒ ex != harmlessException
|
||||
val harmlessExceptionAsSuccess: Try[String] => Boolean = {
|
||||
case Success(_) => false
|
||||
case Failure(ex) => ex != harmlessException
|
||||
}
|
||||
|
||||
intercept[TestException] {
|
||||
|
|
@ -517,7 +517,7 @@ class CircuitBreakerSpec extends AkkaSpec with BeforeAndAfter with MockitoSugar
|
|||
val breaker = CircuitBreakerSpec.shortResetTimeoutCb()
|
||||
breaker().withCircuitBreaker(Future(throwException))
|
||||
checkLatch(breaker.halfOpenLatch)
|
||||
val allReturnIsSuccess: Try[String] ⇒ Boolean = _ ⇒ false
|
||||
val allReturnIsSuccess: Try[String] => Boolean = _ => false
|
||||
Await.ready(breaker().withCircuitBreaker(Future(throwException), allReturnIsSuccess), awaitTimeout)
|
||||
checkLatch(breaker.closedLatch)
|
||||
}
|
||||
|
|
@ -658,7 +658,7 @@ class CircuitBreakerSpec extends AkkaSpec with BeforeAndAfter with MockitoSugar
|
|||
"reset failure count after success" in {
|
||||
val breaker = CircuitBreakerSpec.multiFailureCb()
|
||||
breaker().withCircuitBreaker(Future(sayHi))
|
||||
for (_ ← 1 to 4) breaker().withCircuitBreaker(Future(throwException))
|
||||
for (_ <- 1 to 4) breaker().withCircuitBreaker(Future(throwException))
|
||||
awaitCond(breaker().currentFailureCount == 4, awaitTimeout)
|
||||
breaker().withCircuitBreaker(Future(sayHi))
|
||||
awaitCond(breaker().currentFailureCount == 0, awaitTimeout)
|
||||
|
|
@ -668,13 +668,13 @@ class CircuitBreakerSpec extends AkkaSpec with BeforeAndAfter with MockitoSugar
|
|||
"exception is defined as Success" in {
|
||||
val breaker: CircuitBreakerSpec.Breaker = CircuitBreakerSpec.multiFailureCb()
|
||||
|
||||
for (_ ← 1 to 4) breaker().withCircuitBreaker(Future(throwException))
|
||||
for (_ <- 1 to 4) breaker().withCircuitBreaker(Future(throwException))
|
||||
awaitCond(breaker().currentFailureCount == 4, awaitTimeout, message = s"Current failure count: ${breaker().currentFailureCount}")
|
||||
|
||||
val harmlessException = new TestException
|
||||
val harmlessExceptionAsSuccess: Try[String] ⇒ Boolean = {
|
||||
case Success(_) ⇒ false
|
||||
case Failure(ex) ⇒ ex != harmlessException
|
||||
val harmlessExceptionAsSuccess: Try[String] => Boolean = {
|
||||
case Success(_) => false
|
||||
case Failure(ex) => ex != harmlessException
|
||||
}
|
||||
|
||||
breaker().withCircuitBreaker(Future(throw harmlessException), harmlessExceptionAsSuccess)
|
||||
|
|
|
|||
|
|
@ -39,19 +39,19 @@ object CircuitBreakerStressSpec {
|
|||
}
|
||||
|
||||
override def receive = {
|
||||
case JobDone ⇒
|
||||
case JobDone =>
|
||||
doneCount += 1
|
||||
breaker.withCircuitBreaker(job).pipeTo(self)
|
||||
case Failure(_: CircuitBreakerOpenException) ⇒
|
||||
case Failure(_: CircuitBreakerOpenException) =>
|
||||
circCount += 1
|
||||
breaker.withCircuitBreaker(job).pipeTo(self)
|
||||
case Failure(_: TimeoutException) ⇒
|
||||
case Failure(_: TimeoutException) =>
|
||||
timeoutCount += 1
|
||||
breaker.withCircuitBreaker(job).pipeTo(self)
|
||||
case Failure(_) ⇒
|
||||
case Failure(_) =>
|
||||
failCount += 1
|
||||
breaker.withCircuitBreaker(job).pipeTo(self)
|
||||
case GetResult ⇒
|
||||
case GetResult =>
|
||||
sender() ! Result(doneCount, timeoutCount, failCount, circCount)
|
||||
}
|
||||
}
|
||||
|
|
@ -68,12 +68,12 @@ class CircuitBreakerStressSpec extends AkkaSpec with ImplicitSender {
|
|||
val stressActors = Vector.fill(3) {
|
||||
system.actorOf(Props(classOf[StressActor], breaker))
|
||||
}
|
||||
for (_ ← 0 to 1000; a ← stressActors) {
|
||||
for (_ <- 0 to 1000; a <- stressActors) {
|
||||
a ! JobDone
|
||||
}
|
||||
// let them work for a while
|
||||
Thread.sleep(3000)
|
||||
stressActors.foreach { a ⇒
|
||||
stressActors.foreach { a =>
|
||||
a ! GetResult
|
||||
val result = expectMsgType[Result]
|
||||
result.failCount should be(0)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ object PatternSpec {
|
|||
final case class Work(duration: Duration)
|
||||
class TargetActor extends Actor {
|
||||
def receive = {
|
||||
case (testLatch: TestLatch, duration: FiniteDuration) ⇒
|
||||
case (testLatch: TestLatch, duration: FiniteDuration) =>
|
||||
Await.ready(testLatch, duration)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class PromiseRefSpec extends AkkaSpec with ImplicitSender {
|
|||
val promiseRef = PromiseRef(5.seconds)
|
||||
|
||||
val target = system.actorOf(Props(new Actor {
|
||||
def receive = { case Request(replyTo) ⇒ replyTo ! Response }
|
||||
def receive = { case Request(replyTo) => replyTo ! Response }
|
||||
}))
|
||||
|
||||
target ! Request(promiseRef.ref)
|
||||
|
|
@ -57,13 +57,13 @@ class PromiseRefSpec extends AkkaSpec with ImplicitSender {
|
|||
val promise = Promise[Int]()
|
||||
|
||||
val alice = system.actorOf(Props(new Actor {
|
||||
def receive = { case Response ⇒ promise.success(42) }
|
||||
def receive = { case Response => promise.success(42) }
|
||||
}))
|
||||
|
||||
val promiseRef = PromiseRef.wrap(alice, promise)
|
||||
|
||||
val bob = system.actorOf(Props(new Actor {
|
||||
def receive = { case Request(replyTo) ⇒ replyTo ! Response }
|
||||
def receive = { case Request(replyTo) => replyTo ! Response }
|
||||
}))
|
||||
|
||||
bob ! Request(promiseRef.ref)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class RetrySpec extends AkkaSpec with RetrySupport {
|
|||
"pattern.retry" must {
|
||||
"run a successful Future immediately" in {
|
||||
val retried = retry(
|
||||
() ⇒ Future.successful(5),
|
||||
() => Future.successful(5),
|
||||
5,
|
||||
1 second
|
||||
)
|
||||
|
|
@ -32,7 +32,7 @@ class RetrySpec extends AkkaSpec with RetrySupport {
|
|||
"run a successful Future only once" in {
|
||||
@volatile var counter = 0
|
||||
val retried = retry(
|
||||
() ⇒ Future.successful({
|
||||
() => Future.successful({
|
||||
counter += 1
|
||||
counter
|
||||
}),
|
||||
|
|
@ -47,7 +47,7 @@ class RetrySpec extends AkkaSpec with RetrySupport {
|
|||
|
||||
"eventually return a failure for a Future that will never succeed" in {
|
||||
val retried = retry(
|
||||
() ⇒ Future.failed(new IllegalStateException("Mexico")),
|
||||
() => Future.failed(new IllegalStateException("Mexico")),
|
||||
5,
|
||||
100 milliseconds
|
||||
)
|
||||
|
|
@ -68,7 +68,7 @@ class RetrySpec extends AkkaSpec with RetrySupport {
|
|||
}
|
||||
|
||||
val retried = retry(
|
||||
() ⇒ attempt,
|
||||
() => attempt,
|
||||
10,
|
||||
100 milliseconds
|
||||
)
|
||||
|
|
@ -89,7 +89,7 @@ class RetrySpec extends AkkaSpec with RetrySupport {
|
|||
}
|
||||
|
||||
val retried = retry(
|
||||
() ⇒ attempt,
|
||||
() => attempt,
|
||||
5,
|
||||
100 milliseconds
|
||||
)
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ class ExplicitAskSpec extends AkkaSpec {
|
|||
|
||||
val target = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case Request(respondTo) ⇒ respondTo ! Response(self)
|
||||
case Request(respondTo) => respondTo ! Response(self)
|
||||
}
|
||||
}))
|
||||
|
||||
val f = target ? (respondTo ⇒ Request(respondTo))
|
||||
val f = target ? (respondTo => Request(respondTo))
|
||||
f.futureValue should ===(Response(target))
|
||||
}
|
||||
|
||||
|
|
@ -36,12 +36,12 @@ class ExplicitAskSpec extends AkkaSpec {
|
|||
|
||||
val target = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case Request(respondTo) ⇒ respondTo ! Response(self)
|
||||
case Request(respondTo) => respondTo ! Response(self)
|
||||
}
|
||||
}), "select-echo")
|
||||
|
||||
val selection = system.actorSelection("/user/select-echo")
|
||||
val f = selection ? (respondTo ⇒ Request(respondTo))
|
||||
val f = selection ? (respondTo => Request(respondTo))
|
||||
f.futureValue should ===(Response(target))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ object BalancingSpec {
|
|||
override def preStart(): Unit = latch.countDown()
|
||||
|
||||
def receive = {
|
||||
case msg: Int ⇒
|
||||
case msg: Int =>
|
||||
if (id != 1)
|
||||
Await.ready(latch, 1.minute)
|
||||
else if (msg <= 10)
|
||||
|
|
@ -36,7 +36,7 @@ object BalancingSpec {
|
|||
Props(classOf[Worker], TestLatch(0)(context.system))))
|
||||
|
||||
def receive = {
|
||||
case msg ⇒ pool.forward(msg)
|
||||
case msg => pool.forward(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -75,7 +75,7 @@ class BalancingSpec extends AkkaSpec(
|
|||
latch.reset()
|
||||
val iterationCount = 100
|
||||
|
||||
for (i ← 1 to iterationCount) {
|
||||
for (i <- 1 to iterationCount) {
|
||||
pool ! i
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import akka.pattern.ask
|
|||
|
||||
object BroadcastSpec {
|
||||
class TestActor extends Actor {
|
||||
def receive = { case _ ⇒ }
|
||||
def receive = { case _ => }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -26,16 +26,16 @@ class BroadcastSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
|||
val counter1 = new AtomicInteger
|
||||
val actor1 = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒ counter1.addAndGet(msg)
|
||||
case "end" => doneLatch.countDown()
|
||||
case msg: Int => counter1.addAndGet(msg)
|
||||
}
|
||||
}))
|
||||
|
||||
val counter2 = new AtomicInteger
|
||||
val actor2 = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒ counter2.addAndGet(msg)
|
||||
case "end" => doneLatch.countDown()
|
||||
case msg: Int => counter2.addAndGet(msg)
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -56,8 +56,8 @@ class BroadcastSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
|||
val counter1 = new AtomicInteger
|
||||
val actor1 = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒
|
||||
case "end" => doneLatch.countDown()
|
||||
case msg: Int =>
|
||||
counter1.addAndGet(msg)
|
||||
sender() ! "ack"
|
||||
}
|
||||
|
|
@ -66,8 +66,8 @@ class BroadcastSpec extends AkkaSpec with DefaultTimeout with ImplicitSender {
|
|||
val counter2 = new AtomicInteger
|
||||
val actor2 = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case "end" ⇒ doneLatch.countDown()
|
||||
case msg: Int ⇒ counter2.addAndGet(msg)
|
||||
case "end" => doneLatch.countDown()
|
||||
case msg: Int => counter2.addAndGet(msg)
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue