Merge master into re feature branch (#29135)
* Merge master into feature branch * Formatting * Remove redundant fixme * Remove files that snuck in * Fix backoff supervisor test
This commit is contained in:
parent
7dfb34f37e
commit
b463a1adbd
2032 changed files with 24805 additions and 11402 deletions
|
|
@ -1,3 +1,5 @@
|
|||
pullRequests.frequency = "@monthly"
|
||||
|
||||
updates.ignore = [
|
||||
{ groupId = "com.google.protobuf", artifactId = "protobuf-java" },
|
||||
{ groupId = "org.scalameta", artifactId = "scalafmt-core" },
|
||||
|
|
@ -17,3 +19,4 @@ updates.ignore = [
|
|||
{ groupId = "org.mockito", artifactId = "mockito-core" }
|
||||
]
|
||||
|
||||
updatePullRequests = false
|
||||
|
|
|
|||
|
|
@ -1,7 +1,17 @@
|
|||
// .scalafix.conf
|
||||
rules = [
|
||||
RemoveUnused
|
||||
SortImports
|
||||
ExplicitResultTypes
|
||||
"github:ohze/scalafix-rules/ExplicitNonNullaryApply"
|
||||
"github:ohze/scalafix-rules/ConstructorProcedureSyntax"
|
||||
"github:ohze/scalafix-rules/FinalObject"
|
||||
"github:ohze/scalafix-rules/Any2StringAdd"
|
||||
]
|
||||
ExplicitResultTypes {
|
||||
memberVisibility = [] # only rewrite implicit members
|
||||
skipSimpleDefinitions = []
|
||||
}
|
||||
RemoveUnused.imports = true
|
||||
RemoveUnused.privates = false
|
||||
RemoveUnused.locals = false
|
||||
|
|
@ -12,11 +22,26 @@ ignored-files = [
|
|||
"FlowPrependSpec.scala",
|
||||
"FlowZipSpec.scala",
|
||||
"FlowZipWithSpec.scala",
|
||||
"FlowZipWithIndexSpec.scala"
|
||||
"FlowZipWithIndexSpec.scala",
|
||||
"SourceSpec.scala",
|
||||
"StatsSampleSpec.scala",
|
||||
"ActorFlowSpec.scala",
|
||||
"FSMTimingSpec.scala"
|
||||
]
|
||||
|
||||
//ignored packages
|
||||
ignored-packages = [
|
||||
"docs",
|
||||
"doc",
|
||||
"jdoc"
|
||||
]
|
||||
|
||||
//sort imports, see https://github.com/NeQuissimus/sort-imports
|
||||
SortImports.asciiSort = false
|
||||
SortImports.blocks = [
|
||||
"re:javax?\\.",
|
||||
"scala.",
|
||||
"*",
|
||||
"com.sun."
|
||||
"akka."
|
||||
]
|
||||
|
|
@ -205,8 +205,8 @@ target PR branch you can do so by setting the PR_TARGET_BRANCH environment varia
|
|||
PR_TARGET_BRANCH=origin/example sbt validatePullRequest
|
||||
```
|
||||
|
||||
If you have already run all tests and now just need to check that everything is formatted and or mima passes there
|
||||
are a set of `all*` commands aliases for running `test:compile` (also formats), `mimaReportBinaryIssues`, and `validateCompile`
|
||||
If you already ran all tests and just need to check formatting and mima, there
|
||||
is a set of `all*` command aliases that run `test:compile` (also formats), `mimaReportBinaryIssues`, and `validateCompile`
|
||||
(compiles `multi-jvm` if enabled for that project). See `build.sbt` or use completion to find the most appropriate one
|
||||
e.g. `allCluster`, `allTyped`.
|
||||
|
||||
|
|
|
|||
21
RELEASING.md
21
RELEASING.md
|
|
@ -60,6 +60,27 @@ copied over to a maven server. If you have access, the Jenkins job at
|
|||
https://jenkins.akka.io:8498/job/akka-publish-wip/ can be used to publish
|
||||
a snapshot to https://repo.akka.io/snapshots from any branch.
|
||||
|
||||
## Releasing only updated docs
|
||||
|
||||
It is possible to release a revised documentation to the already existing release.
|
||||
|
||||
1. Create a new branch from a release tag. If a revised documentation is for the `v2.6.4` release, then the name of the new branch should be `docs/v2.6.4`.
|
||||
1. Add and commit `version.sbt` file that pins the version to the one that is being revised. Also set `isSnapshot` to `false` for the stable documentation links. For example:
|
||||
```scala
|
||||
ThisBuild / version := "2.6.4"
|
||||
ThisBuild / isSnapshot := false
|
||||
```
|
||||
1. Make all of the required changes to the documentation.
|
||||
1. Build documentation locally with:
|
||||
```sh
|
||||
sbt akka-docs/paradoxBrowse
|
||||
```
|
||||
1. If the generated documentation looks good, send it to Gustav:
|
||||
```sh
|
||||
sbt akka-docs/publishRsync
|
||||
```
|
||||
1. Do not forget to push the new branch back to GitHub.
|
||||
|
||||
## Release steps
|
||||
|
||||
* Tag the release: `git tag -am "Version 2.6.x" v2.6.x`
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
# #27338 allow passing ActorSystem to ActorTestKit
|
||||
ProblemFilters.exclude[IncompatibleSignatureProblem]("akka.actor.testkit.typed.scaladsl.ActorTestKit.internalSystem")
|
||||
ProblemFilters.exclude[IncompatibleMethTypeProblem]("akka.actor.testkit.typed.scaladsl.ActorTestKit.this")
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# testkit not bc
|
||||
ProblemFilters.exclude[ReversedMissingMethodProblem]("akka.actor.testkit.typed.scaladsl.TestProbe.asJava")
|
||||
|
|
@ -6,13 +6,14 @@ package akka.actor.testkit.typed
|
|||
|
||||
import java.util.Optional
|
||||
|
||||
import akka.annotation.InternalApi
|
||||
import akka.util.OptionVal
|
||||
import scala.compat.java8.OptionConverters._
|
||||
|
||||
import org.slf4j.Marker
|
||||
import org.slf4j.event.Level
|
||||
|
||||
import akka.annotation.InternalApi
|
||||
import akka.util.OptionVal
|
||||
|
||||
/**
|
||||
* Representation of a Log Event issued by a [[akka.actor.typed.Behavior]]
|
||||
* when testing with [[akka.actor.testkit.typed.scaladsl.BehaviorTestKit]]
|
||||
|
|
@ -28,37 +29,32 @@ final case class CapturedLogEvent(level: Level, message: String, cause: Option[T
|
|||
message: String,
|
||||
errorCause: Optional[Throwable],
|
||||
marker: Optional[Marker],
|
||||
mdc: java.util.Map[String, Any]) {
|
||||
mdc: java.util.Map[String, Any]) =
|
||||
this(level, message, errorCause.asScala, marker.asScala)
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for Java API
|
||||
*/
|
||||
def this(level: Level, message: String) {
|
||||
def this(level: Level, message: String) =
|
||||
this(level, message, Option.empty, Option.empty)
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for Java API
|
||||
*/
|
||||
def this(level: Level, message: String, errorCause: Throwable) {
|
||||
def this(level: Level, message: String, errorCause: Throwable) =
|
||||
this(level, message, Some(errorCause), Option.empty[Marker])
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for Java API
|
||||
*/
|
||||
def this(level: Level, message: String, marker: Marker) {
|
||||
def this(level: Level, message: String, marker: Marker) =
|
||||
this(level, message, Option.empty[Throwable], Some(marker))
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for Java API
|
||||
*/
|
||||
def this(level: Level, message: String, errorCause: Throwable, marker: Marker) {
|
||||
def this(level: Level, message: String, errorCause: Throwable, marker: Marker) =
|
||||
this(level, message, Some(errorCause), Some(marker))
|
||||
}
|
||||
|
||||
def getErrorCause: Optional[Throwable] = cause.asJava
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@
|
|||
|
||||
package akka.actor.testkit.typed
|
||||
|
||||
import scala.compat.java8.FunctionConverters._
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
|
||||
import akka.actor.typed.{ ActorRef, Behavior, Props }
|
||||
import akka.annotation.{ DoNotInherit, InternalApi }
|
||||
import akka.util.JavaDurationConverters._
|
||||
import akka.util.unused
|
||||
|
||||
import scala.compat.java8.FunctionConverters._
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
|
||||
/**
|
||||
* All tracked effects for the [[akka.actor.testkit.typed.scaladsl.BehaviorTestKit]] and
|
||||
* [[akka.actor.testkit.typed.javadsl.BehaviorTestKit]] must extend this type.
|
||||
|
|
@ -191,7 +191,7 @@ object Effect {
|
|||
def duration(): java.time.Duration = d.asJava
|
||||
}
|
||||
|
||||
final case object ReceiveTimeoutCancelled extends ReceiveTimeoutCancelled
|
||||
case object ReceiveTimeoutCancelled extends ReceiveTimeoutCancelled
|
||||
|
||||
sealed abstract class ReceiveTimeoutCancelled extends Effect
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,15 @@
|
|||
|
||||
package akka.actor.testkit.typed
|
||||
|
||||
import scala.compat.java8.OptionConverters._
|
||||
import akka.util.ccompat.JavaConverters._
|
||||
|
||||
import java.util.Optional
|
||||
|
||||
import scala.compat.java8.OptionConverters._
|
||||
|
||||
import org.slf4j.Marker
|
||||
import org.slf4j.event.Level
|
||||
|
||||
import akka.util.ccompat.JavaConverters._
|
||||
|
||||
object LoggingEvent {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,14 +4,15 @@
|
|||
|
||||
package akka.actor.testkit.typed
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import scala.concurrent.duration.{ Duration, FiniteDuration }
|
||||
|
||||
import akka.util.JavaDurationConverters._
|
||||
import akka.util.Timeout
|
||||
import com.typesafe.config.Config
|
||||
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.Extension
|
||||
import akka.actor.typed.ExtensionId
|
||||
import akka.util.JavaDurationConverters._
|
||||
import akka.util.Timeout
|
||||
|
||||
object TestKitSettings {
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,17 @@ package akka.actor.testkit.typed.internal
|
|||
|
||||
import java.util.concurrent.{ CompletionStage, ThreadFactory }
|
||||
|
||||
import akka.actor.typed.internal.ActorRefImpl
|
||||
import scala.compat.java8.FutureConverters
|
||||
import scala.concurrent._
|
||||
|
||||
import com.github.ghik.silencer.silent
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import akka.{ actor => classic }
|
||||
import akka.Done
|
||||
import akka.actor.{ ActorPath, ActorRefProvider, Address, ReflectiveDynamicAccess }
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.Behavior
|
||||
|
|
@ -17,18 +27,9 @@ import akka.actor.typed.ExtensionId
|
|||
import akka.actor.typed.Props
|
||||
import akka.actor.typed.Scheduler
|
||||
import akka.actor.typed.Settings
|
||||
import akka.annotation.InternalApi
|
||||
import akka.{ actor => classic }
|
||||
import akka.Done
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
import scala.compat.java8.FutureConverters
|
||||
import scala.concurrent._
|
||||
import akka.actor.{ ActorPath, ActorRefProvider, Address, ReflectiveDynamicAccess }
|
||||
import akka.actor.typed.internal.ActorRefImpl
|
||||
import akka.actor.typed.internal.InternalRecipientRef
|
||||
import com.github.ghik.silencer.silent
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
|
|
@ -66,7 +67,7 @@ import org.slf4j.LoggerFactory
|
|||
override def provider: ActorRefProvider = throw new UnsupportedOperationException("no provider")
|
||||
|
||||
// stream materialization etc. using stub not supported
|
||||
override private[akka] def classicSystem =
|
||||
override def classicSystem =
|
||||
throw new UnsupportedOperationException("no classic actor system available")
|
||||
|
||||
// impl InternalRecipientRef
|
||||
|
|
@ -90,7 +91,7 @@ import org.slf4j.LoggerFactory
|
|||
|
||||
override def scheduler: Scheduler = throw new UnsupportedOperationException("no scheduler")
|
||||
|
||||
private val terminationPromise = Promise[Done]
|
||||
private val terminationPromise = Promise[Done]()
|
||||
override def terminate(): Unit = terminationPromise.trySuccess(Done)
|
||||
override def whenTerminated: Future[Done] = terminationPromise.future
|
||||
override def getWhenTerminated: CompletionStage[Done] = FutureConverters.toJava(whenTerminated)
|
||||
|
|
|
|||
|
|
@ -6,19 +6,19 @@ package akka.actor.testkit.typed.internal
|
|||
|
||||
import java.util
|
||||
|
||||
import akka.actor.ActorPath
|
||||
import akka.actor.typed.{ ActorRef, Behavior, PostStop, Signal }
|
||||
import akka.annotation.InternalApi
|
||||
import akka.actor.testkit.typed.{ CapturedLogEvent, Effect }
|
||||
import akka.actor.testkit.typed.Effect._
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import akka.util.ccompat.JavaConverters._
|
||||
import scala.collection.immutable
|
||||
import scala.reflect.ClassTag
|
||||
import scala.util.control.Exception.Catcher
|
||||
import scala.util.control.NonFatal
|
||||
|
||||
import akka.actor.ActorPath
|
||||
import akka.actor.testkit.typed.{ CapturedLogEvent, Effect }
|
||||
import akka.actor.testkit.typed.Effect._
|
||||
import akka.actor.typed.{ ActorRef, Behavior, PostStop, Signal }
|
||||
import akka.annotation.InternalApi
|
||||
import akka.util.ccompat.JavaConverters._
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
|
|
@ -33,7 +33,14 @@ private[akka] final class BehaviorTestKitImpl[T](_path: ActorPath, _initialBehav
|
|||
private[akka] def as[U]: BehaviorTestKitImpl[U] = this.asInstanceOf[BehaviorTestKitImpl[U]]
|
||||
|
||||
private var currentUncanonical = _initialBehavior
|
||||
private var current = Behavior.validateAsInitial(Behavior.start(_initialBehavior, context))
|
||||
private var current = {
|
||||
try {
|
||||
context.setCurrentActorThread()
|
||||
Behavior.validateAsInitial(Behavior.start(_initialBehavior, context))
|
||||
} finally {
|
||||
context.clearCurrentActorThread()
|
||||
}
|
||||
}
|
||||
|
||||
// execute any future tasks scheduled in Actor's constructor
|
||||
runAllTasks()
|
||||
|
|
@ -122,13 +129,18 @@ private[akka] final class BehaviorTestKitImpl[T](_path: ActorPath, _initialBehav
|
|||
|
||||
override def run(message: T): Unit = {
|
||||
try {
|
||||
currentUncanonical = Behavior.interpretMessage(current, context, message)
|
||||
current = Behavior.canonicalize(currentUncanonical, current, context)
|
||||
context.setCurrentActorThread()
|
||||
try {
|
||||
currentUncanonical = Behavior.interpretMessage(current, context, message)
|
||||
current = Behavior.canonicalize(currentUncanonical, current, context)
|
||||
} finally {
|
||||
context.clearCurrentActorThread()
|
||||
}
|
||||
runAllTasks()
|
||||
} catch handleException
|
||||
}
|
||||
|
||||
override def runOne(): Unit = run(selfInbox.receiveMessage())
|
||||
override def runOne(): Unit = run(selfInbox().receiveMessage())
|
||||
|
||||
override def signal(signal: Signal): Unit = {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@
|
|||
|
||||
package akka.actor.testkit.typed.internal
|
||||
|
||||
import akka.annotation.InternalApi
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent
|
||||
import ch.qos.logback.core.AppenderBase
|
||||
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ package akka.actor.testkit.typed.internal
|
|||
|
||||
import java.util.LinkedList
|
||||
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
import scala.concurrent.ExecutionContextExecutor
|
||||
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -6,14 +6,14 @@ package akka.actor.testkit.typed.internal
|
|||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue
|
||||
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.actor.typed.internal.{ ActorRefImpl, SystemMessage }
|
||||
import akka.annotation.InternalApi
|
||||
import akka.{ actor => classic }
|
||||
import scala.annotation.tailrec
|
||||
|
||||
import akka.{ actor => classic }
|
||||
import akka.actor.ActorRefProvider
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.actor.typed.internal.{ ActorRefImpl, SystemMessage }
|
||||
import akka.actor.typed.internal.InternalRecipientRef
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
|
|
|
|||
|
|
@ -6,15 +6,15 @@ package akka.actor.testkit.typed.internal
|
|||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue
|
||||
|
||||
import akka.actor.{ ActorPath, Cancellable }
|
||||
import akka.actor.typed.{ ActorRef, Behavior, Props }
|
||||
import akka.annotation.InternalApi
|
||||
import akka.actor.testkit.typed.Effect
|
||||
import akka.actor.testkit.typed.Effect._
|
||||
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
import akka.actor.{ ActorPath, Cancellable }
|
||||
import akka.actor.testkit.typed.Effect
|
||||
import akka.actor.testkit.typed.Effect._
|
||||
import akka.actor.typed.{ ActorRef, Behavior, Props }
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@
|
|||
|
||||
package akka.actor.testkit.typed.internal
|
||||
|
||||
import akka.annotation.InternalApi
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.slf4j.event.Level
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
|
|
@ -15,9 +17,17 @@ import org.slf4j.event.Level
|
|||
def loggerNameOrRoot(loggerName: String): String =
|
||||
if (loggerName == "") org.slf4j.Logger.ROOT_LOGGER_NAME else loggerName
|
||||
|
||||
def getLogbackLogger(loggerName: String): ch.qos.logback.classic.Logger = {
|
||||
def getLogbackLogger(loggerName: String): ch.qos.logback.classic.Logger =
|
||||
getLogbackLoggerInternal(loggerName, 50)
|
||||
|
||||
@tailrec
|
||||
private def getLogbackLoggerInternal(loggerName: String, count: Int): ch.qos.logback.classic.Logger = {
|
||||
LoggerFactory.getLogger(loggerNameOrRoot(loggerName)) match {
|
||||
case logger: ch.qos.logback.classic.Logger => logger
|
||||
case logger: ch.qos.logback.classic.Logger => logger
|
||||
case _: org.slf4j.helpers.SubstituteLogger if count > 0 =>
|
||||
// Wait for logging initialisation http://www.slf4j.org/codes.html#substituteLogger
|
||||
Thread.sleep(50)
|
||||
getLogbackLoggerInternal(loggerName, count - 1)
|
||||
case null =>
|
||||
throw new IllegalArgumentException(s"Couldn't find logger for [$loggerName].")
|
||||
case other =>
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ import scala.concurrent.duration.Duration
|
|||
import scala.reflect.ClassTag
|
||||
import scala.util.matching.Regex
|
||||
|
||||
import org.slf4j.event.Level
|
||||
|
||||
import akka.actor.testkit.typed.LoggingEvent
|
||||
import akka.actor.testkit.typed.TestKitSettings
|
||||
import akka.actor.testkit.typed.javadsl
|
||||
|
|
@ -17,7 +19,6 @@ import akka.actor.testkit.typed.scaladsl
|
|||
import akka.actor.typed.ActorSystem
|
||||
import akka.annotation.InternalApi
|
||||
import akka.testkit.TestKit
|
||||
import org.slf4j.event.Level
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
|
|
|
|||
|
|
@ -4,25 +4,26 @@
|
|||
|
||||
package akka.actor.testkit.typed.internal
|
||||
|
||||
import akka.actor.typed._
|
||||
import akka.actor.typed.internal._
|
||||
import akka.actor.testkit.typed.CapturedLogEvent
|
||||
import akka.actor.testkit.typed.scaladsl.TestInbox
|
||||
import akka.actor.{ ActorPath, InvalidMessageException }
|
||||
import akka.annotation.InternalApi
|
||||
import akka.util.Helpers
|
||||
import akka.{ actor => classic }
|
||||
import java.util.concurrent.ThreadLocalRandom.{ current => rnd }
|
||||
|
||||
import scala.collection.immutable.TreeMap
|
||||
import scala.concurrent.ExecutionContextExecutor
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
|
||||
import akka.actor.ActorRefProvider
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.helpers.MessageFormatter
|
||||
import org.slf4j.helpers.SubstituteLoggerFactory
|
||||
|
||||
import akka.{ actor => classic }
|
||||
import akka.actor.{ ActorPath, InvalidMessageException }
|
||||
import akka.actor.ActorRefProvider
|
||||
import akka.actor.testkit.typed.CapturedLogEvent
|
||||
import akka.actor.testkit.typed.scaladsl.TestInbox
|
||||
import akka.actor.typed._
|
||||
import akka.actor.typed.internal._
|
||||
import akka.annotation.InternalApi
|
||||
import akka.util.Helpers
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*
|
||||
|
|
@ -86,17 +87,25 @@ private[akka] final class FunctionRef[-T](override val path: ActorPath, send: (T
|
|||
throw new UnsupportedOperationException(
|
||||
"No classic ActorContext available with the stubbed actor context, to spawn materializers and run streams you will need a real actor")
|
||||
|
||||
override def children: Iterable[ActorRef[Nothing]] = _children.values.map(_.context.self)
|
||||
override def children: Iterable[ActorRef[Nothing]] = {
|
||||
checkCurrentActorThread()
|
||||
_children.values.map(_.context.self)
|
||||
}
|
||||
def childrenNames: Iterable[String] = _children.keys
|
||||
|
||||
override def child(name: String): Option[ActorRef[Nothing]] = _children.get(name).map(_.context.self)
|
||||
override def child(name: String): Option[ActorRef[Nothing]] = {
|
||||
checkCurrentActorThread()
|
||||
_children.get(name).map(_.context.self)
|
||||
}
|
||||
|
||||
override def spawnAnonymous[U](behavior: Behavior[U], props: Props = Props.empty): ActorRef[U] = {
|
||||
checkCurrentActorThread()
|
||||
val btk = new BehaviorTestKitImpl[U]((path / childName.next()).withUid(rnd().nextInt()), behavior)
|
||||
_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] =
|
||||
override def spawn[U](behavior: Behavior[U], name: String, props: Props = Props.empty): ActorRef[U] = {
|
||||
checkCurrentActorThread()
|
||||
_children.get(name) match {
|
||||
case Some(_) => throw classic.InvalidActorNameException(s"actor name $name is already taken")
|
||||
case None =>
|
||||
|
|
@ -104,12 +113,14 @@ private[akka] final class FunctionRef[-T](override val path: ActorPath, send: (T
|
|||
_children += name -> btk
|
||||
btk.context.self
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not actually stop the child inbox, only simulate the liveness check.
|
||||
* Removal is asynchronous, explicit removeInbox is needed from outside afterwards.
|
||||
*/
|
||||
override def stop[U](child: ActorRef[U]): Unit = {
|
||||
checkCurrentActorThread()
|
||||
if (child.path.parent != self.path)
|
||||
throw new IllegalArgumentException(
|
||||
"Only direct children of an actor can be stopped through the actor context, " +
|
||||
|
|
@ -119,11 +130,21 @@ private[akka] final class FunctionRef[-T](override val path: ActorPath, send: (T
|
|||
_children -= child.path.name
|
||||
}
|
||||
}
|
||||
override def watch[U](other: ActorRef[U]): Unit = ()
|
||||
override def watchWith[U](other: ActorRef[U], message: T): Unit = ()
|
||||
override def unwatch[U](other: ActorRef[U]): Unit = ()
|
||||
override def setReceiveTimeout(d: FiniteDuration, message: T): Unit = ()
|
||||
override def cancelReceiveTimeout(): Unit = ()
|
||||
override def watch[U](other: ActorRef[U]): Unit = {
|
||||
checkCurrentActorThread()
|
||||
}
|
||||
override def watchWith[U](other: ActorRef[U], message: T): Unit = {
|
||||
checkCurrentActorThread()
|
||||
}
|
||||
override def unwatch[U](other: ActorRef[U]): Unit = {
|
||||
checkCurrentActorThread()
|
||||
}
|
||||
override def setReceiveTimeout(d: FiniteDuration, message: T): Unit = {
|
||||
checkCurrentActorThread()
|
||||
}
|
||||
override def cancelReceiveTimeout(): Unit = {
|
||||
checkCurrentActorThread()
|
||||
}
|
||||
|
||||
override def scheduleOnce[U](delay: FiniteDuration, target: ActorRef[U], message: U): classic.Cancellable =
|
||||
new classic.Cancellable {
|
||||
|
|
@ -147,7 +168,7 @@ private[akka] final class FunctionRef[-T](override val path: ActorPath, send: (T
|
|||
new FunctionRef[U](p, (message, _) => {
|
||||
val m = f(message);
|
||||
if (m != null) {
|
||||
selfInbox.ref ! m; i.selfInbox.ref ! message
|
||||
selfInbox.ref ! m; i.selfInbox().ref ! message
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -185,11 +206,20 @@ private[akka] final class FunctionRef[-T](override val path: ActorPath, send: (T
|
|||
|
||||
override def toString: String = s"Inbox($self)"
|
||||
|
||||
override def log: Logger = logger
|
||||
override def log: Logger = {
|
||||
checkCurrentActorThread()
|
||||
logger
|
||||
}
|
||||
|
||||
override def setLoggerName(name: String): Unit = () // nop as we don't track logger
|
||||
override def setLoggerName(name: String): Unit = {
|
||||
// nop as we don't track logger
|
||||
checkCurrentActorThread()
|
||||
}
|
||||
|
||||
override def setLoggerName(clazz: Class[_]): Unit = () // nop as we don't track logger
|
||||
override def setLoggerName(clazz: Class[_]): Unit = {
|
||||
// nop as we don't track logger
|
||||
checkCurrentActorThread()
|
||||
}
|
||||
|
||||
/**
|
||||
* The log entries logged through context.log.{debug, info, warn, error} are captured and can be inspected through
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@
|
|||
|
||||
package akka.actor.testkit.typed.internal
|
||||
|
||||
import akka.actor.testkit.typed.LoggingEvent
|
||||
import akka.annotation.InternalApi
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent
|
||||
import ch.qos.logback.classic.spi.ThrowableProxy
|
||||
import ch.qos.logback.core.AppenderBase
|
||||
|
||||
import akka.actor.testkit.typed.LoggingEvent
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ package akka.actor.testkit.typed.internal
|
|||
|
||||
import java.util.concurrent.ConcurrentLinkedQueue
|
||||
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.actor.ActorPath
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.immutable
|
||||
|
||||
import akka.actor.ActorPath
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,13 +4,15 @@
|
|||
|
||||
package akka.actor.testkit.typed.internal
|
||||
|
||||
import java.lang.reflect.Modifier
|
||||
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
import akka.actor.typed.{ ActorRef, ActorSystem, Behavior, Props }
|
||||
import akka.annotation.InternalApi
|
||||
import scala.concurrent.{ Await, TimeoutException }
|
||||
import scala.concurrent.duration.Duration
|
||||
import scala.util.control.Exception.Catcher
|
||||
import scala.util.control.NonFatal
|
||||
|
||||
import akka.actor.typed.{ ActorRef, ActorSystem, Behavior, Props }
|
||||
import akka.actor.typed.scaladsl.ActorContext
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
|
|
@ -25,15 +27,19 @@ private[akka] object ActorTestKitGuardian {
|
|||
final case class StopActor[T](ref: ActorRef[T], replyTo: ActorRef[Ack.type]) extends TestKitCommand
|
||||
final case class ActorStopped[T](replyTo: ActorRef[Ack.type]) extends TestKitCommand
|
||||
|
||||
final case object Ack
|
||||
case object Ack
|
||||
|
||||
val testKitGuardian: Behavior[TestKitCommand] = Behaviors.receive[TestKitCommand] {
|
||||
case (context, SpawnActor(name, behavior, reply, props)) =>
|
||||
reply ! context.spawn(behavior, name, props)
|
||||
Behaviors.same
|
||||
try {
|
||||
reply ! context.spawn(behavior, name, props)
|
||||
Behaviors.same
|
||||
} catch handleSpawnException(context, reply, props)
|
||||
case (context, SpawnActorAnonymous(behavior, reply, props)) =>
|
||||
reply ! context.spawnAnonymous(behavior, props)
|
||||
Behaviors.same
|
||||
try {
|
||||
reply ! context.spawnAnonymous(behavior, props)
|
||||
Behaviors.same
|
||||
} catch handleSpawnException(context, reply, props)
|
||||
case (context, StopActor(ref, reply)) =>
|
||||
context.watchWith(ref, ActorStopped(reply))
|
||||
context.stop(ref)
|
||||
|
|
@ -42,6 +48,16 @@ private[akka] object ActorTestKitGuardian {
|
|||
reply ! Ack
|
||||
Behaviors.same
|
||||
}
|
||||
|
||||
private def handleSpawnException[T](
|
||||
context: ActorContext[ActorTestKitGuardian.TestKitCommand],
|
||||
reply: ActorRef[ActorRef[T]],
|
||||
props: Props): Catcher[Behavior[TestKitCommand]] = {
|
||||
case NonFatal(e) =>
|
||||
context.log.error(s"Spawn failed, props [$props]", e)
|
||||
reply ! context.spawnAnonymous(Behaviors.stopped)
|
||||
Behaviors.same
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,48 +69,16 @@ private[akka] object TestKitUtils {
|
|||
// common internal utility impls for Java and Scala
|
||||
private val TestKitRegex = """akka\.testkit\.typed\.(?:javadsl|scaladsl)\.ActorTestKit(?:\$.*)?""".r
|
||||
|
||||
def testNameFromCallStack(classToStartFrom: Class[_]): String = {
|
||||
|
||||
def isAbstractClass(className: String): Boolean = {
|
||||
try {
|
||||
Modifier.isAbstract(Class.forName(className).getModifiers)
|
||||
} catch {
|
||||
case _: Throwable => false // yes catch everything, best effort check
|
||||
}
|
||||
}
|
||||
|
||||
val startFrom = classToStartFrom.getName
|
||||
val filteredStack = Thread.currentThread.getStackTrace.iterator
|
||||
.map(_.getClassName)
|
||||
// drop until we find the first occurrence of classToStartFrom
|
||||
.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
|
||||
}
|
||||
|
||||
if (filteredStack.isEmpty)
|
||||
throw new IllegalArgumentException(s"Couldn't find [${classToStartFrom.getName}] in call stack")
|
||||
|
||||
// sanitize for actor system name
|
||||
scrubActorSystemName(filteredStack.next())
|
||||
}
|
||||
def testNameFromCallStack(classToStartFrom: Class[_]): String =
|
||||
akka.testkit.TestKitUtils.testNameFromCallStack(classToStartFrom, TestKitRegex)
|
||||
|
||||
/**
|
||||
* Sanitize the `name` to be used as valid actor system name by
|
||||
* replacing invalid characters. `name` may for example be a fully qualified
|
||||
* class name and then the short class name will be used.
|
||||
*/
|
||||
def scrubActorSystemName(name: String): String = {
|
||||
name
|
||||
.replaceFirst("""^.*\.""", "") // drop package name
|
||||
.replaceAll("""\$\$?\w+""", "") // drop scala anonymous functions/classes
|
||||
.replaceAll("[^a-zA-Z_0-9]", "_")
|
||||
}
|
||||
def scrubActorSystemName(name: String): String =
|
||||
akka.testkit.TestKitUtils.scrubActorSystemName(name)
|
||||
|
||||
def shutdown(system: ActorSystem[_], timeout: Duration, throwIfShutdownTimesOut: Boolean): Unit = {
|
||||
system.terminate()
|
||||
|
|
|
|||
|
|
@ -5,23 +5,22 @@
|
|||
package akka.actor.testkit.typed.internal
|
||||
|
||||
import java.time.{ Duration => JDuration }
|
||||
import java.util.{ List => JList }
|
||||
import java.util.concurrent.BlockingDeque
|
||||
import java.util.concurrent.LinkedBlockingDeque
|
||||
import java.util.function.Supplier
|
||||
import java.util.{ List => JList }
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import akka.util.ccompat.JavaConverters._
|
||||
|
||||
import scala.collection.immutable
|
||||
import scala.concurrent.duration._
|
||||
import scala.reflect.ClassTag
|
||||
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.scaladsl.TestDuration
|
||||
import akka.actor.testkit.typed.scaladsl.{ TestProbe => ScalaTestProbe }
|
||||
import akka.actor.testkit.typed.scaladsl.TestDuration
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.Behavior
|
||||
|
|
@ -32,6 +31,7 @@ import akka.annotation.InternalApi
|
|||
import akka.util.BoxedType
|
||||
import akka.util.JavaDurationConverters._
|
||||
import akka.util.PrettyDuration._
|
||||
import akka.util.ccompat.JavaConverters._
|
||||
|
||||
@InternalApi
|
||||
private[akka] object TestProbeImpl {
|
||||
|
|
@ -389,4 +389,5 @@ private[akka] final class TestProbeImpl[M](name: String, system: ActorSystem[_])
|
|||
testActor.asInstanceOf[ActorRef[AnyRef]] ! Stop
|
||||
}
|
||||
|
||||
override private[akka] def asJava: JavaTestProbe[M] = this
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,25 +6,27 @@ package akka.actor.testkit.typed.javadsl
|
|||
|
||||
import java.time.Duration
|
||||
|
||||
import com.typesafe.config.Config
|
||||
|
||||
import akka.actor.DeadLetter
|
||||
import akka.actor.Dropped
|
||||
import akka.actor.UnhandledMessage
|
||||
import akka.actor.testkit.typed.TestKitSettings
|
||||
import akka.actor.testkit.typed.internal.TestKitUtils
|
||||
import akka.actor.testkit.typed.scaladsl
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.Behavior
|
||||
import akka.actor.typed.Props
|
||||
import akka.actor.typed.Scheduler
|
||||
import akka.actor.testkit.typed.TestKitSettings
|
||||
import akka.actor.testkit.typed.internal.TestKitUtils
|
||||
import akka.actor.testkit.typed.scaladsl
|
||||
import akka.util.Timeout
|
||||
import com.typesafe.config.Config
|
||||
import akka.util.JavaDurationConverters._
|
||||
import akka.util.Timeout
|
||||
|
||||
object ActorTestKit {
|
||||
|
||||
/**
|
||||
* Create a testkit named from the class that is calling this method.
|
||||
* Create a testkit named from the ActorTestKit class.
|
||||
*
|
||||
* It will create an [[akka.actor.typed.ActorSystem]] with this name,
|
||||
* e.g. threads will include the name.
|
||||
* When the test has completed you should terminate the `ActorSystem` and
|
||||
* the testkit with [[ActorTestKit#shutdownTestKit]].
|
||||
*
|
||||
|
|
@ -36,7 +38,19 @@ object ActorTestKit {
|
|||
new ActorTestKit(scaladsl.ActorTestKit(TestKitUtils.testNameFromCallStack(classOf[ActorTestKit])))
|
||||
|
||||
/**
|
||||
* Create a named testkit.
|
||||
* Create a testkit from the provided actor system.
|
||||
*
|
||||
* When the test has completed you should terminate the `ActorSystem` and
|
||||
* the testkit with [[ActorTestKit#shutdownTestKit]].
|
||||
*
|
||||
* Config loaded from the provided actor if that exists, otherwise
|
||||
* using default configuration from the reference.conf resources that ship with the Akka libraries.
|
||||
*/
|
||||
def create(system: ActorSystem[_]): ActorTestKit =
|
||||
new ActorTestKit(scaladsl.ActorTestKit(system))
|
||||
|
||||
/**
|
||||
* Create a testkit using the provided name.
|
||||
*
|
||||
* It will create an [[akka.actor.typed.ActorSystem]] with this name,
|
||||
* e.g. threads will include the name.
|
||||
|
|
@ -51,11 +65,11 @@ object ActorTestKit {
|
|||
new ActorTestKit(scaladsl.ActorTestKit(name))
|
||||
|
||||
/**
|
||||
* Create a testkit named from the class that is calling this method,
|
||||
* Create a testkit named from the ActorTestKit class,
|
||||
* and use a custom config for the actor system.
|
||||
*
|
||||
* It will create an [[akka.actor.typed.ActorSystem]] with this name,
|
||||
* e.g. threads will include the name.
|
||||
* It will also used the provided customConfig provided to create the `ActorSystem`
|
||||
*
|
||||
* When the test has completed you should terminate the `ActorSystem` and
|
||||
* the testkit with [[ActorTestKit#shutdownTestKit]].
|
||||
*/
|
||||
|
|
@ -63,10 +77,14 @@ object ActorTestKit {
|
|||
new ActorTestKit(scaladsl.ActorTestKit(TestKitUtils.testNameFromCallStack(classOf[ActorTestKit]), customConfig))
|
||||
|
||||
/**
|
||||
* Create a named testkit, and use a custom config for the actor system.
|
||||
* Create a test kit named based on the provided name,
|
||||
* and uses the provided custom config for the actor system.
|
||||
*
|
||||
* It will create an [[akka.actor.typed.ActorSystem]] with this name,
|
||||
* e.g. threads will include the name.
|
||||
*
|
||||
* It will also used the provided customConfig provided to create the `ActorSystem`
|
||||
*
|
||||
* When the test has completed you should terminate the `ActorSystem` and
|
||||
* the testkit with [[ActorTestKit#shutdownTestKit]].
|
||||
*/
|
||||
|
|
@ -74,11 +92,14 @@ object ActorTestKit {
|
|||
new ActorTestKit(scaladsl.ActorTestKit(name, customConfig))
|
||||
|
||||
/**
|
||||
* Create a named testkit, and use a custom config for the actor system,
|
||||
* and a custom [[akka.actor.testkit.typed.TestKitSettings]]
|
||||
* Create an [[akka.actor.typed.ActorSystem]] named based on the provided name,
|
||||
* use the provided custom config for the actor system, and the testkit will use the provided setting.
|
||||
*
|
||||
* It will create an [[akka.actor.typed.ActorSystem]] with this name,
|
||||
* e.g. threads will include the name.
|
||||
*
|
||||
* It will also used the provided customConfig provided to create the `ActorSystem`, and provided setting.
|
||||
*
|
||||
* When the test has completed you should terminate the `ActorSystem` and
|
||||
* the testkit with [[ActorTestKit#shutdownTestKit]].
|
||||
*/
|
||||
|
|
@ -217,6 +238,25 @@ final class ActorTestKit private[akka] (delegate: akka.actor.testkit.typed.scala
|
|||
*/
|
||||
def createTestProbe[M](name: String, clazz: Class[M]): TestProbe[M] = TestProbe.create(name, clazz, system)
|
||||
|
||||
/**
|
||||
* @return A test probe that is subscribed to dropped letters from the system event bus. Subscription
|
||||
* will be completed and verified so any dropped letter after it will be caught by the probe.
|
||||
*/
|
||||
def createDroppedMessageProbe(): TestProbe[Dropped] =
|
||||
delegate.createDroppedMessageProbe().asJava
|
||||
|
||||
/**
|
||||
* @return A test probe that is subscribed to dead letters from the system event bus. Subscription
|
||||
* will be completed and verified so any dead letter after it will be caught by the probe.
|
||||
*/
|
||||
def createDeadLetterProbe(): TestProbe[DeadLetter] = delegate.createDeadLetterProbe().asJava
|
||||
|
||||
/**
|
||||
* @return A test probe that is subscribed to unhandled messages from the system event bus. Subscription
|
||||
* will be completed and verified so any unhandled message after it will be caught by the probe.
|
||||
*/
|
||||
def createUnhandledMessageProbe(): TestProbe[UnhandledMessage] = delegate.createUnhandledMessageProbe().asJava
|
||||
|
||||
// Note that if more methods are added here they should also be added to TestKitJunitResource
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@
|
|||
|
||||
package akka.actor.testkit.typed.javadsl
|
||||
|
||||
import akka.actor.testkit.typed.internal.BehaviorTestKitImpl
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
import akka.actor.testkit.typed.{ CapturedLogEvent, Effect }
|
||||
import akka.actor.testkit.typed.internal.BehaviorTestKitImpl
|
||||
import akka.actor.typed.{ ActorRef, Behavior, Signal }
|
||||
import akka.annotation.{ ApiMayChange, DoNotInherit }
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
object BehaviorTestKit {
|
||||
import akka.actor.testkit.typed.scaladsl.TestInbox.address
|
||||
|
|
@ -75,7 +76,7 @@ abstract class BehaviorTestKit[T] {
|
|||
/**
|
||||
* The self reference of the actor living inside this testkit.
|
||||
*/
|
||||
def getRef(): ActorRef[T] = selfInbox.getRef()
|
||||
def getRef(): ActorRef[T] = selfInbox().getRef()
|
||||
|
||||
/**
|
||||
* Requests all the effects. The effects are consumed, subsequent calls will only
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@ package akka.actor.testkit.typed.javadsl
|
|||
|
||||
import scala.util.control.NonFatal
|
||||
|
||||
import akka.actor.testkit.typed.internal.CapturingAppender
|
||||
import org.junit.rules.TestRule
|
||||
import org.junit.runner.Description
|
||||
import org.junit.runners.model.Statement
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import akka.actor.testkit.typed.internal.CapturingAppender
|
||||
|
||||
/**
|
||||
* JUnit `TestRule` to make log lines appear only when the test failed.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ package akka.actor.testkit.typed.javadsl
|
|||
|
||||
import java.util.function.Supplier
|
||||
|
||||
import org.slf4j.event.Level
|
||||
|
||||
import akka.actor.testkit.typed.LoggingEvent
|
||||
import akka.actor.testkit.typed.internal.LoggingTestKitImpl
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.annotation.DoNotInherit
|
||||
import org.slf4j.event.Level
|
||||
|
||||
/**
|
||||
* Facilities for verifying logs.
|
||||
|
|
|
|||
|
|
@ -6,13 +6,14 @@ package akka.actor.testkit.typed.javadsl
|
|||
|
||||
import java.time.Duration
|
||||
|
||||
import scala.annotation.varargs
|
||||
|
||||
import com.typesafe.config.Config
|
||||
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.internal.adapter.SchedulerAdapter
|
||||
import com.typesafe.config.Config
|
||||
import akka.util.JavaDurationConverters._
|
||||
|
||||
import scala.annotation.varargs
|
||||
|
||||
/**
|
||||
* Manual time allows you to do async tests while controlling the scheduler of the system.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -4,15 +4,15 @@
|
|||
|
||||
package akka.actor.testkit.typed.javadsl
|
||||
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.annotation.DoNotInherit
|
||||
import akka.actor.testkit.typed.internal.TestInboxImpl
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
import akka.util.ccompat.JavaConverters._
|
||||
import scala.collection.immutable
|
||||
|
||||
import akka.actor.testkit.typed.internal.TestInboxImpl
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.annotation.DoNotInherit
|
||||
import akka.util.ccompat.JavaConverters._
|
||||
|
||||
object TestInbox {
|
||||
import akka.actor.testkit.typed.scaladsl.TestInbox.address
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,14 @@ package akka.actor.testkit.typed.javadsl
|
|||
|
||||
import java.time.Duration
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.ExternalResource
|
||||
|
||||
import akka.actor.DeadLetter
|
||||
import akka.actor.Dropped
|
||||
import akka.actor.UnhandledMessage
|
||||
import akka.actor.testkit.typed.TestKitSettings
|
||||
import akka.actor.testkit.typed.internal.TestKitUtils
|
||||
import akka.actor.typed.ActorRef
|
||||
|
|
@ -14,10 +22,6 @@ import akka.actor.typed.Behavior
|
|||
import akka.actor.typed.Props
|
||||
import akka.actor.typed.Scheduler
|
||||
import akka.util.Timeout
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.ExternalResource
|
||||
|
||||
/**
|
||||
* A Junit external resource for the [[ActorTestKit]], making it possible to have Junit manage the lifecycle of the testkit.
|
||||
|
|
@ -54,6 +58,11 @@ final class TestKitJunitResource(_kit: ActorTestKit) extends ExternalResource {
|
|||
*/
|
||||
def this() = this(ActorTestKit.create(TestKitUtils.testNameFromCallStack(classOf[TestKitJunitResource])))
|
||||
|
||||
/**
|
||||
* Use a custom [[akka.actor.typed.ActorSystem]] for the actor system.
|
||||
*/
|
||||
def this(system: ActorSystem[_]) = this(ActorTestKit.create(system))
|
||||
|
||||
/**
|
||||
* Use a custom config for the actor system.
|
||||
*/
|
||||
|
|
@ -144,6 +153,21 @@ final class TestKitJunitResource(_kit: ActorTestKit) extends ExternalResource {
|
|||
*/
|
||||
def stop[T](ref: ActorRef[T], max: Duration): Unit = testKit.stop(ref, max)
|
||||
|
||||
/**
|
||||
* See corresponding method on [[ActorTestKit]]
|
||||
*/
|
||||
def createUnhandledMessageProbe(): TestProbe[UnhandledMessage] = testKit.createUnhandledMessageProbe()
|
||||
|
||||
/**
|
||||
* See corresponding method on [[ActorTestKit]]
|
||||
*/
|
||||
def createDeadLetterProbe(): TestProbe[DeadLetter] = testKit.createDeadLetterProbe()
|
||||
|
||||
/**
|
||||
* See corresponding method on [[ActorTestKit]]
|
||||
*/
|
||||
def createDroppedMessageProbe(): TestProbe[Dropped] = testKit.createDroppedMessageProbe()
|
||||
|
||||
/**
|
||||
* See corresponding method on [[ActorTestKit]]
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
package akka.actor.testkit.typed.javadsl
|
||||
|
||||
import java.time.Duration
|
||||
import java.util.function.Supplier
|
||||
import java.util.{ List => JList }
|
||||
import java.util.function.Supplier
|
||||
|
||||
import akka.actor.testkit.typed.FishingOutcome
|
||||
import akka.actor.testkit.typed.TestKitSettings
|
||||
|
|
|
|||
|
|
@ -5,9 +5,20 @@
|
|||
package akka.actor.testkit.typed.scaladsl
|
||||
|
||||
import java.util.concurrent.TimeoutException
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import akka.actor.DeadLetter
|
||||
import akka.actor.DeadLetterSuppression
|
||||
import akka.actor.Dropped
|
||||
import akka.actor.UnhandledMessage
|
||||
import akka.actor.testkit.typed.TestKitSettings
|
||||
import akka.actor.testkit.typed.internal.ActorTestKitGuardian
|
||||
import akka.actor.testkit.typed.internal.TestKitUtils
|
||||
|
|
@ -16,17 +27,55 @@ import akka.actor.typed.ActorSystem
|
|||
import akka.actor.typed.Behavior
|
||||
import akka.actor.typed.Props
|
||||
import akka.actor.typed.Scheduler
|
||||
import akka.actor.typed.eventstream.EventStream
|
||||
import akka.actor.typed.scaladsl.AskPattern._
|
||||
import akka.actor.typed.scaladsl.adapter._
|
||||
import akka.annotation.InternalApi
|
||||
import akka.util.Timeout
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
object ActorTestKit {
|
||||
|
||||
private val testKitGuardianCounter = new AtomicInteger(0)
|
||||
|
||||
/**
|
||||
* Create a testkit named from the class that is calling this method.
|
||||
* Create a testkit named from the ActorTestKit class.
|
||||
*
|
||||
* When the test has completed you should terminate the `ActorSystem` and
|
||||
* the testkit with [[ActorTestKit#shutdownTestKit]].
|
||||
*
|
||||
* Config loaded from `application-test.conf` if that exists, otherwise
|
||||
* using default configuration from the reference.conf resources that ship with the Akka libraries.
|
||||
* The application.conf of your project is not used in this case.
|
||||
*/
|
||||
def apply(): ActorTestKit = {
|
||||
val system = ActorSystem(
|
||||
ActorTestKitGuardian.testKitGuardian,
|
||||
TestKitUtils.testNameFromCallStack(classOf[ActorTestKit]),
|
||||
ApplicationTestConfig)
|
||||
new ActorTestKit(system, system, settings = None)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a testkit from the provided actor system.
|
||||
*
|
||||
* When the test has completed you should terminate the `ActorSystem` and
|
||||
* the testkit with [[ActorTestKit#shutdownTestKit]].
|
||||
*
|
||||
* Config loaded from the provided actor if that exists, otherwise
|
||||
* using default configuration from the reference.conf resources that ship with the Akka libraries.
|
||||
*/
|
||||
def apply(system: ActorSystem[_]): ActorTestKit = {
|
||||
val name = testKitGuardianCounter.incrementAndGet() match {
|
||||
case 1 => "test"
|
||||
case n => s"test-$n"
|
||||
}
|
||||
val testKitGuardian =
|
||||
system.systemActorOf(ActorTestKitGuardian.testKitGuardian, name)
|
||||
new ActorTestKit(system, testKitGuardian, settings = None)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a testkit using the provided name.
|
||||
*
|
||||
* It will create an [[akka.actor.typed.ActorSystem]] with this name,
|
||||
* e.g. threads will include the name.
|
||||
|
|
@ -37,64 +86,64 @@ object ActorTestKit {
|
|||
* using default configuration from the reference.conf resources that ship with the Akka libraries.
|
||||
* The application.conf of your project is not used in this case.
|
||||
*/
|
||||
def apply(): ActorTestKit =
|
||||
new ActorTestKit(
|
||||
name = TestKitUtils.testNameFromCallStack(classOf[ActorTestKit]),
|
||||
config = ApplicationTestConfig,
|
||||
settings = None)
|
||||
def apply(name: String): ActorTestKit = {
|
||||
val system =
|
||||
ActorSystem(ActorTestKitGuardian.testKitGuardian, TestKitUtils.scrubActorSystemName(name), ApplicationTestConfig)
|
||||
new ActorTestKit(system, system, settings = None)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a named testkit.
|
||||
*
|
||||
* It will create an [[akka.actor.typed.ActorSystem]] with this name,
|
||||
* e.g. threads will include the name.
|
||||
* When the test has completed you should terminate the `ActorSystem` and
|
||||
* the testkit with [[ActorTestKit#shutdownTestKit]].
|
||||
*
|
||||
* Config loaded from `application-test.conf` if that exists, otherwise
|
||||
* using default configuration from the reference.conf resources that ship with the Akka libraries.
|
||||
* The application.conf of your project is not used in this case.
|
||||
*/
|
||||
def apply(name: String): ActorTestKit =
|
||||
new ActorTestKit(name = TestKitUtils.scrubActorSystemName(name), config = ApplicationTestConfig, settings = None)
|
||||
|
||||
/**
|
||||
* Create a testkit named from the class that is calling this method,
|
||||
* Create a testkit named from the ActorTestKit class,
|
||||
* and use a custom config for the actor system.
|
||||
*
|
||||
* It will create an [[akka.actor.typed.ActorSystem]] with this name,
|
||||
* e.g. threads will include the name.
|
||||
* It will also used the provided customConfig provided to create the `ActorSystem`
|
||||
*
|
||||
* When the test has completed you should terminate the `ActorSystem` and
|
||||
* the testkit with [[ActorTestKit#shutdownTestKit]].
|
||||
*/
|
||||
def apply(customConfig: Config): ActorTestKit =
|
||||
new ActorTestKit(
|
||||
name = TestKitUtils.testNameFromCallStack(classOf[ActorTestKit]),
|
||||
config = customConfig,
|
||||
settings = None)
|
||||
def apply(customConfig: Config): ActorTestKit = {
|
||||
val system = ActorSystem(
|
||||
ActorTestKitGuardian.testKitGuardian,
|
||||
TestKitUtils.testNameFromCallStack(classOf[ActorTestKit]),
|
||||
customConfig)
|
||||
new ActorTestKit(system, system, settings = None)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a named testkit, and use a custom config for the actor system.
|
||||
* Create a test kit named based on the provided name,
|
||||
* and uses the provided custom config for the actor system.
|
||||
*
|
||||
* It will create an [[akka.actor.typed.ActorSystem]] with this name,
|
||||
* e.g. threads will include the name.
|
||||
*
|
||||
* It will also used the provided customConfig provided to create the `ActorSystem`
|
||||
*
|
||||
* When the test has completed you should terminate the `ActorSystem` and
|
||||
* the testkit with [[ActorTestKit#shutdownTestKit]].
|
||||
*/
|
||||
def apply(name: String, customConfig: Config): ActorTestKit =
|
||||
new ActorTestKit(name = TestKitUtils.scrubActorSystemName(name), config = customConfig, settings = None)
|
||||
def apply(name: String, customConfig: Config): ActorTestKit = {
|
||||
val system =
|
||||
ActorSystem(ActorTestKitGuardian.testKitGuardian, TestKitUtils.scrubActorSystemName(name), customConfig)
|
||||
new ActorTestKit(system, system, settings = None)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a named testkit, and use a custom config for the actor system,
|
||||
* and a custom [[akka.actor.testkit.typed.TestKitSettings]]
|
||||
* Create an [[akka.actor.typed.ActorSystem]] named based on the provided name,
|
||||
* use the provided custom config for the actor system, and the testkit will use the provided setting.
|
||||
*
|
||||
* It will create an [[akka.actor.typed.ActorSystem]] with this name,
|
||||
* e.g. threads will include the name.
|
||||
*
|
||||
* It will also used the provided customConfig provided to create the `ActorSystem`, and provided setting.
|
||||
*
|
||||
* When the test has completed you should terminate the `ActorSystem` and
|
||||
* the testkit with [[ActorTestKit#shutdownTestKit]].
|
||||
*/
|
||||
def apply(name: String, customConfig: Config, settings: TestKitSettings): ActorTestKit =
|
||||
new ActorTestKit(name = TestKitUtils.scrubActorSystemName(name), config = customConfig, settings = Some(settings))
|
||||
def apply(name: String, customConfig: Config, settings: TestKitSettings): ActorTestKit = {
|
||||
val system =
|
||||
ActorSystem(ActorTestKitGuardian.testKitGuardian, TestKitUtils.scrubActorSystemName(name), customConfig)
|
||||
new ActorTestKit(system, system, settings = Some(settings))
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the given [[akka.actor.typed.ActorSystem]] and block until it shuts down,
|
||||
|
|
@ -117,6 +166,7 @@ object ActorTestKit {
|
|||
*/
|
||||
val ApplicationTestConfig: Config = ConfigFactory.load("application-test")
|
||||
|
||||
private val dummyMessage = new DeadLetterSuppression {}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -131,10 +181,17 @@ object ActorTestKit {
|
|||
*
|
||||
* For synchronous testing of a `Behavior` see [[BehaviorTestKit]]
|
||||
*/
|
||||
final class ActorTestKit private[akka] (val name: String, val config: Config, settings: Option[TestKitSettings]) {
|
||||
final class ActorTestKit private[akka] (
|
||||
val internalSystem: ActorSystem[_],
|
||||
internalTestKitGuardian: ActorRef[ActorTestKitGuardian.TestKitCommand],
|
||||
settings: Option[TestKitSettings]) {
|
||||
|
||||
val name = internalSystem.name
|
||||
|
||||
val config = internalSystem.settings.config
|
||||
|
||||
// avoid slf4j noise by touching it first from single thread #28673
|
||||
LoggerFactory.getLogger(name).debug("Starting ActorTestKit")
|
||||
LoggerFactory.getLogger(internalSystem.name).debug("Starting ActorTestKit")
|
||||
|
||||
implicit def testKitSettings: TestKitSettings =
|
||||
settings.getOrElse(TestKitSettings(system))
|
||||
|
|
@ -142,9 +199,6 @@ final class ActorTestKit private[akka] (val name: String, val config: Config, se
|
|||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
@InternalApi private[akka] val internalSystem: ActorSystem[ActorTestKitGuardian.TestKitCommand] =
|
||||
ActorSystem(ActorTestKitGuardian.testKitGuardian, name, config)
|
||||
|
||||
implicit def system: ActorSystem[Nothing] = internalSystem
|
||||
|
||||
private val childName: Iterator[String] = Iterator.from(0).map(_.toString)
|
||||
|
|
@ -172,7 +226,9 @@ final class ActorTestKit private[akka] (val name: String, val config: Config, se
|
|||
* guardian
|
||||
*/
|
||||
def spawn[T](behavior: Behavior[T], props: Props): ActorRef[T] =
|
||||
Await.result(internalSystem.ask(ActorTestKitGuardian.SpawnActorAnonymous(behavior, _, props)), timeout.duration)
|
||||
Await.result(
|
||||
internalTestKitGuardian.ask(ActorTestKitGuardian.SpawnActorAnonymous(behavior, _, props)),
|
||||
timeout.duration)
|
||||
|
||||
/**
|
||||
* Spawn the given behavior. This is created as a child of the test kit
|
||||
|
|
@ -186,7 +242,9 @@ final class ActorTestKit private[akka] (val name: String, val config: Config, se
|
|||
* guardian
|
||||
*/
|
||||
def spawn[T](behavior: Behavior[T], name: String, props: Props): ActorRef[T] =
|
||||
Await.result(internalSystem.ask(ActorTestKitGuardian.SpawnActor(name, behavior, _, props)), timeout.duration)
|
||||
Await.result(
|
||||
internalTestKitGuardian.ask(ActorTestKitGuardian.SpawnActor(name, behavior, _, props)),
|
||||
timeout.duration)
|
||||
|
||||
/**
|
||||
* Stop the actor under test and wait until it terminates.
|
||||
|
|
@ -195,7 +253,7 @@ final class ActorTestKit private[akka] (val name: String, val config: Config, se
|
|||
*/
|
||||
def stop[T](ref: ActorRef[T], max: FiniteDuration = timeout.duration): Unit =
|
||||
try {
|
||||
Await.result(internalSystem.ask { x: ActorRef[ActorTestKitGuardian.Ack.type] =>
|
||||
Await.result(internalTestKitGuardian.ask { x: ActorRef[ActorTestKitGuardian.Ack.type] =>
|
||||
ActorTestKitGuardian.StopActor(ref, x)
|
||||
}, max)
|
||||
} catch {
|
||||
|
|
@ -215,6 +273,44 @@ final class ActorTestKit private[akka] (val name: String, val config: Config, se
|
|||
*/
|
||||
def createTestProbe[M](name: String): TestProbe[M] = TestProbe(name)(system)
|
||||
|
||||
/**
|
||||
* @return A test probe that is subscribed to unhandled messages from the system event bus. Subscription
|
||||
* will be completed and verified so any unhandled message after it will be caught by the probe.
|
||||
*/
|
||||
def createUnhandledMessageProbe(): TestProbe[UnhandledMessage] =
|
||||
subscribeEventBusAndVerifySubscribed[UnhandledMessage](() =>
|
||||
UnhandledMessage(ActorTestKit.dummyMessage, system.deadLetters.toClassic, system.deadLetters.toClassic))
|
||||
|
||||
/**
|
||||
* @return A test probe that is subscribed to dead letters from the system event bus. Subscription
|
||||
* will be completed and verified so any dead letter after it will be caught by the probe.
|
||||
*/
|
||||
def createDeadLetterProbe(): TestProbe[DeadLetter] =
|
||||
subscribeEventBusAndVerifySubscribed[DeadLetter](() =>
|
||||
DeadLetter(ActorTestKit.dummyMessage, system.deadLetters.toClassic, system.deadLetters.toClassic))
|
||||
|
||||
/**
|
||||
* @return A test probe that is subscribed to dropped letters from the system event bus. Subscription
|
||||
* will be completed and verified so any dropped letter after it will be caught by the probe.
|
||||
*/
|
||||
def createDroppedMessageProbe(): TestProbe[Dropped] =
|
||||
subscribeEventBusAndVerifySubscribed[Dropped](() =>
|
||||
Dropped(ActorTestKit.dummyMessage, "no reason", system.deadLetters.toClassic, system.deadLetters.toClassic))
|
||||
|
||||
private def subscribeEventBusAndVerifySubscribed[M <: AnyRef: ClassTag](createTestEvent: () => M): TestProbe[M] = {
|
||||
val probe = createTestProbe[M]()
|
||||
system.eventStream ! EventStream.Subscribe(probe.ref)
|
||||
probe.awaitAssert {
|
||||
val testEvent = createTestEvent()
|
||||
system.eventStream ! EventStream.Publish(testEvent)
|
||||
probe.fishForMessage(probe.remainingOrDefault) {
|
||||
case m: AnyRef if m eq testEvent => FishingOutcomes.complete
|
||||
case _ => FishingOutcomes.continue
|
||||
}
|
||||
}
|
||||
probe
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional testing utilities for serialization.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,6 +4,12 @@
|
|||
|
||||
package akka.actor.testkit.typed.scaladsl
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
import akka.actor.DeadLetter
|
||||
import akka.actor.Dropped
|
||||
import akka.actor.UnhandledMessage
|
||||
import akka.actor.testkit.typed.TestKitSettings
|
||||
import akka.actor.testkit.typed.internal.TestKitUtils
|
||||
import akka.actor.typed.ActorRef
|
||||
|
|
@ -11,8 +17,6 @@ import akka.actor.typed.ActorSystem
|
|||
import akka.actor.typed.Behavior
|
||||
import akka.actor.typed.Props
|
||||
import akka.util.Timeout
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
object ActorTestKitBase {
|
||||
def testNameFromCallStack(): String = TestKitUtils.testNameFromCallStack(classOf[ActorTestKitBase])
|
||||
|
|
@ -94,6 +98,21 @@ abstract class ActorTestKitBase(val testKit: ActorTestKit) {
|
|||
*/
|
||||
def createTestProbe[M](name: String): TestProbe[M] = testKit.createTestProbe(name)
|
||||
|
||||
/**
|
||||
* See corresponding method on [[ActorTestKit]]
|
||||
*/
|
||||
def createDroppedMessageProbe(): TestProbe[Dropped] = testKit.createDroppedMessageProbe()
|
||||
|
||||
/**
|
||||
* See corresponding method on [[ActorTestKit]]
|
||||
*/
|
||||
def createDeadLetterProbe(): TestProbe[DeadLetter] = testKit.createDeadLetterProbe()
|
||||
|
||||
/**
|
||||
* See corresponding method on [[ActorTestKit]]
|
||||
*/
|
||||
def createUnhandledMessageProbe(): TestProbe[UnhandledMessage] = testKit.createUnhandledMessageProbe()
|
||||
|
||||
/**
|
||||
* Additional testing utilities for serialization.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,15 +4,16 @@
|
|||
|
||||
package akka.actor.testkit.typed.scaladsl
|
||||
|
||||
import akka.actor.testkit.typed.internal.BehaviorTestKitImpl
|
||||
import akka.actor.testkit.typed.{ CapturedLogEvent, Effect }
|
||||
import akka.actor.typed.{ ActorRef, Behavior, Signal, TypedActorContext }
|
||||
import akka.annotation.{ ApiMayChange, DoNotInherit }
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
import scala.collection.immutable
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
import akka.actor.testkit.typed.{ CapturedLogEvent, Effect }
|
||||
import akka.actor.testkit.typed.internal.BehaviorTestKitImpl
|
||||
import akka.actor.typed.{ ActorRef, Behavior, Signal, TypedActorContext }
|
||||
import akka.annotation.{ ApiMayChange, DoNotInherit }
|
||||
|
||||
@ApiMayChange
|
||||
object BehaviorTestKit {
|
||||
import akka.actor.testkit.typed.scaladsl.TestInbox.address
|
||||
|
|
@ -72,7 +73,7 @@ trait BehaviorTestKit[T] {
|
|||
/**
|
||||
* The self reference of the actor living inside this testkit.
|
||||
*/
|
||||
def ref: ActorRef[T] = selfInbox.ref
|
||||
def ref: ActorRef[T] = selfInbox().ref
|
||||
|
||||
/**
|
||||
* Requests all the effects. The effects are consumed, subsequent calls will only
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
package akka.actor.testkit.typed.scaladsl
|
||||
|
||||
import akka.actor.typed.{ ActorRef, Behavior, Props }
|
||||
|
||||
import scala.concurrent.duration.FiniteDuration
|
||||
|
||||
import akka.actor.typed.{ ActorRef, Behavior, Props }
|
||||
|
||||
/**
|
||||
* Factories for behavior effects for [[BehaviorTestKit]], each effect has a suitable equals and can be used to compare
|
||||
* actual effects to expected ones.
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@ package akka.actor.testkit.typed.scaladsl
|
|||
|
||||
import scala.util.control.NonFatal
|
||||
|
||||
import akka.actor.testkit.typed.internal.CapturingAppender
|
||||
import org.scalatest.BeforeAndAfterAll
|
||||
import org.scalatest.Outcome
|
||||
import org.scalatest.TestSuite
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import akka.actor.testkit.typed.internal.CapturingAppender
|
||||
|
||||
/**
|
||||
* Mixin this trait to a ScalaTest test to make log lines appear only when the test failed.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -6,11 +6,12 @@ package akka.actor.testkit.typed.scaladsl
|
|||
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
import org.slf4j.event.Level
|
||||
|
||||
import akka.actor.testkit.typed.LoggingEvent
|
||||
import akka.actor.testkit.typed.internal.LoggingTestKitImpl
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.annotation.DoNotInherit
|
||||
import org.slf4j.event.Level
|
||||
|
||||
/**
|
||||
* Facilities for verifying logs.
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@
|
|||
|
||||
package akka.actor.testkit.typed.scaladsl
|
||||
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.internal.adapter.SchedulerAdapter
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
|
||||
import scala.annotation.varargs
|
||||
import scala.concurrent.duration.{ Duration, FiniteDuration }
|
||||
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.internal.adapter.SchedulerAdapter
|
||||
|
||||
/**
|
||||
* Manual time allows you to do async tests while controlling the scheduler of the system.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -4,14 +4,16 @@
|
|||
|
||||
package akka.actor.testkit.typed.scaladsl
|
||||
|
||||
import akka.actor.testkit.typed.TestKitSettings
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.scalatest.{ BeforeAndAfterAll, TestSuite }
|
||||
import org.scalatest.concurrent.Eventually
|
||||
import org.scalatest.concurrent.ScalaFutures
|
||||
import org.scalatest.time.Span
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.time.Span
|
||||
|
||||
import akka.actor.testkit.typed.TestKitSettings
|
||||
import akka.actor.typed.ActorSystem
|
||||
|
||||
/**
|
||||
* A ScalaTest base class for the [[ActorTestKit]], making it possible to have ScalaTest manage the lifecycle of the testkit.
|
||||
|
|
@ -41,6 +43,11 @@ abstract class ScalaTestWithActorTestKit(testKit: ActorTestKit)
|
|||
*/
|
||||
def this() = this(ActorTestKit(ActorTestKitBase.testNameFromCallStack()))
|
||||
|
||||
/**
|
||||
* Use a custom [[akka.actor.typed.ActorSystem]] for the actor system.
|
||||
*/
|
||||
def this(system: ActorSystem[_]) = this(ActorTestKit(system))
|
||||
|
||||
/**
|
||||
* Use a custom config for the actor system.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
package akka.actor.testkit.typed.scaladsl
|
||||
|
||||
import akka.actor.typed.scaladsl.adapter._
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.scaladsl.adapter._
|
||||
import akka.serialization.SerializationExtension
|
||||
import akka.serialization.Serializers
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,15 @@
|
|||
|
||||
package akka.actor.testkit.typed.scaladsl
|
||||
|
||||
import akka.actor.{ Address, RootActorPath }
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.annotation.{ ApiMayChange, DoNotInherit }
|
||||
import akka.actor.testkit.typed.internal.TestInboxImpl
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
import scala.collection.immutable
|
||||
|
||||
import akka.actor.{ Address, RootActorPath }
|
||||
import akka.actor.testkit.typed.internal.TestInboxImpl
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.annotation.{ ApiMayChange, DoNotInherit }
|
||||
|
||||
@ApiMayChange
|
||||
object TestInbox {
|
||||
def apply[T](name: String = "inbox"): TestInbox[T] = {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import akka.actor.testkit.typed.internal.TestProbeImpl
|
|||
import akka.actor.typed.ActorRef
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.annotation.DoNotInherit
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
object FishingOutcomes {
|
||||
|
||||
|
|
@ -241,4 +242,10 @@ object TestProbe {
|
|||
* Stops the [[TestProbe.ref]], which is useful when testing watch and termination.
|
||||
*/
|
||||
def stop(): Unit
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
@InternalApi
|
||||
private[akka] def asJava: akka.actor.testkit.typed.javadsl.TestProbe[M]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<level>INFO</level>
|
||||
</filter>
|
||||
<encoder>
|
||||
<pattern>%date{ISO8601} %-5level %logger %marker - %msg {%mdc}%n</pattern>
|
||||
<pattern>%date{ISO8601} %-5level %logger %marker - %msg MDC: {%mdc}%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,15 +4,21 @@
|
|||
|
||||
package akka.actor.testkit.typed.scaladsl
|
||||
|
||||
import akka.Done
|
||||
import scala.concurrent.Promise
|
||||
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.scalatest.BeforeAndAfterAll
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.{ AnyWordSpec, AnyWordSpecLike }
|
||||
|
||||
import akka.Done
|
||||
import akka.actor.Dropped
|
||||
import akka.actor.UnhandledMessage
|
||||
import akka.actor.testkit.typed.internal.ActorTestKitGuardian
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.eventstream.EventStream
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
|
||||
class ActorTestKitSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike with LogCapturing {
|
||||
|
||||
"the Scala testkit" should {
|
||||
|
|
@ -21,6 +27,16 @@ class ActorTestKitSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike wi
|
|||
system.name should ===("ActorTestKitSpec")
|
||||
}
|
||||
|
||||
"generate a test kit from the provided actor system" in {
|
||||
val config = ConfigFactory.parseString("test.specific-config = yes")
|
||||
val system = ActorSystem(ActorTestKitGuardian.testKitGuardian, "TestActor", config)
|
||||
val testkit2 = ActorTestKit(system)
|
||||
try {
|
||||
testkit2.internalSystem should ===(system)
|
||||
testkit2.system should ===(system)
|
||||
} finally testkit2.shutdownTestKit()
|
||||
}
|
||||
|
||||
"generate a default name from the test class" in {
|
||||
val testkit2 = ActorTestKit()
|
||||
try {
|
||||
|
|
@ -64,23 +80,18 @@ class ActorTestKitSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike wi
|
|||
}
|
||||
|
||||
"load application-test.conf by default" in {
|
||||
testKit.config.getString("test.from-application-test") should ===("yes")
|
||||
testKit.system.settings.config.getString("test.from-application-test") should ===("yes")
|
||||
testKit.system.settings.config.hasPath("test.from-application") should ===(false)
|
||||
}
|
||||
|
||||
"not load application-test.conf if specific Config given" in {
|
||||
val testKit2 = ActorTestKit(ConfigFactory.parseString("test.specific-config = yes"))
|
||||
testKit2.config.getString("test.specific-config") should ===("yes")
|
||||
testKit2.system.settings.config.getString("test.specific-config") should ===("yes")
|
||||
testKit2.config.hasPath("test.from-application-test") should ===(false)
|
||||
testKit2.system.settings.config.hasPath("test.from-application-test") should ===(false)
|
||||
testKit2.system.settings.config.hasPath("test.from-application") should ===(false)
|
||||
|
||||
// same if via ScalaTestWithActorTestKit
|
||||
val scalaTestWithActorTestKit2 = new ScalaTestWithActorTestKit("test.specific-config = yes") {}
|
||||
scalaTestWithActorTestKit2.testKit.config.getString("test.specific-config") should ===("yes")
|
||||
scalaTestWithActorTestKit2.testKit.config.hasPath("test.from-application-test") should ===(false)
|
||||
scalaTestWithActorTestKit2.system.settings.config.hasPath("test.from-application-test") should ===(false)
|
||||
scalaTestWithActorTestKit2.testKit.system.settings.config.hasPath("test.from-application") should ===(false)
|
||||
}
|
||||
|
|
@ -92,6 +103,25 @@ class ActorTestKitSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike wi
|
|||
// not throw
|
||||
}
|
||||
|
||||
"allow subscriptions for unhandled" in {
|
||||
import akka.actor.typed.scaladsl.adapter._
|
||||
val probe = testKit.createUnhandledMessageProbe()
|
||||
system.eventStream ! EventStream.Publish(UnhandledMessage("message", probe.ref.toClassic, probe.ref.toClassic))
|
||||
probe.receiveMessage().message should ===("message")
|
||||
}
|
||||
|
||||
"allow subscriptions for dead letters" in {
|
||||
val probe = testKit.createDeadLetterProbe()
|
||||
system.deadLetters ! "message"
|
||||
probe.receiveMessage().message should ===("message")
|
||||
}
|
||||
|
||||
"allow subscriptions for dropped messages" in {
|
||||
val probe = testKit.createDroppedMessageProbe()
|
||||
system.eventStream ! EventStream.Publish(Dropped("message", "it had gone bad", akka.actor.ActorRef.noSender))
|
||||
probe.receiveMessage().message should ===("message")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,19 +4,20 @@
|
|||
|
||||
package akka.actor.testkit.typed.scaladsl
|
||||
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
import org.slf4j.event.Level
|
||||
|
||||
import akka.Done
|
||||
import akka.actor.Address
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
import akka.actor.typed.{ ActorRef, Behavior, Props }
|
||||
import akka.actor.testkit.typed.{ CapturedLogEvent, Effect }
|
||||
import akka.actor.testkit.typed.Effect._
|
||||
import akka.actor.testkit.typed.scaladsl.BehaviorTestKitSpec.{ Child, Parent }
|
||||
import akka.actor.testkit.typed.scaladsl.BehaviorTestKitSpec.Parent._
|
||||
|
||||
import scala.reflect.ClassTag
|
||||
import org.slf4j.event.Level
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
import akka.actor.typed.{ ActorRef, Behavior, Props }
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
|
||||
object BehaviorTestKitSpec {
|
||||
object Parent {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
package akka.actor.testkit.typed.scaladsl
|
||||
|
||||
import akka.actor.testkit.typed.LoggingEvent
|
||||
import org.slf4j.event.Level
|
||||
import org.scalatest.wordspec.AnyWordSpecLike
|
||||
import org.slf4j.event.Level
|
||||
|
||||
import akka.actor.testkit.typed.LoggingEvent
|
||||
|
||||
class LoggingTestKitSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike with LogCapturing {
|
||||
|
||||
|
|
|
|||
|
|
@ -8,9 +8,10 @@ import java.util.concurrent.atomic.AtomicInteger
|
|||
|
||||
import scala.concurrent.Future
|
||||
|
||||
import akka.actor.testkit.typed.TestException
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.scalatest.wordspec.AnyWordSpecLike
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import akka.actor.testkit.typed.TestException
|
||||
|
||||
class TestAppenderSpec
|
||||
extends ScalaTestWithActorTestKit(
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@
|
|||
|
||||
package akka.actor.testkit.typed.scaladsl
|
||||
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.scalatest.wordspec.AnyWordSpecLike
|
||||
|
||||
import akka.actor.typed.scaladsl.Behaviors
|
||||
|
||||
class TestProbeSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike with LogCapturing {
|
||||
|
||||
import TestProbeSpec._
|
||||
|
|
@ -148,7 +149,7 @@ class TestProbeSpec extends ScalaTestWithActorTestKit with AnyWordSpecLike with
|
|||
val probe = createTestProbe[EventT]()
|
||||
eventsT(10).forall { e =>
|
||||
probe.ref ! e
|
||||
probe.receiveMessage == e
|
||||
probe.receiveMessage() == e
|
||||
} should ===(true)
|
||||
|
||||
probe.expectNoMessage()
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@
|
|||
|
||||
package akka
|
||||
|
||||
import akka.actor._
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
import akka.actor._
|
||||
|
||||
/**
|
||||
* A spec that verified that the AkkaException has at least a single argument constructor of type String.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -4,15 +4,16 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import language.postfixOps
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import language.postfixOps
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
|
||||
import akka.ConfigurationException
|
||||
import akka.routing._
|
||||
import akka.testkit._
|
||||
import akka.testkit.DefaultTimeout
|
||||
import akka.testkit.TestEvent._
|
||||
import scala.concurrent.duration._
|
||||
import akka.routing._
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
import akka.ConfigurationException
|
||||
|
||||
object ActorConfigurationVerificationSpec {
|
||||
|
||||
|
|
@ -47,22 +48,22 @@ class ActorConfigurationVerificationSpec
|
|||
"An Actor configured with a BalancingDispatcher" must {
|
||||
"fail verification with a ConfigurationException if also configured with a RoundRobinPool" in {
|
||||
intercept[ConfigurationException] {
|
||||
system.actorOf(RoundRobinPool(2).withDispatcher("balancing-dispatcher").props(Props[TestActor]))
|
||||
system.actorOf(RoundRobinPool(2).withDispatcher("balancing-dispatcher").props(Props[TestActor]()))
|
||||
}
|
||||
}
|
||||
"fail verification with a ConfigurationException if also configured with a BroadcastPool" in {
|
||||
intercept[ConfigurationException] {
|
||||
system.actorOf(BroadcastPool(2).withDispatcher("balancing-dispatcher").props(Props[TestActor]))
|
||||
system.actorOf(BroadcastPool(2).withDispatcher("balancing-dispatcher").props(Props[TestActor]()))
|
||||
}
|
||||
}
|
||||
"fail verification with a ConfigurationException if also configured with a RandomPool" in {
|
||||
intercept[ConfigurationException] {
|
||||
system.actorOf(RandomPool(2).withDispatcher("balancing-dispatcher").props(Props[TestActor]))
|
||||
system.actorOf(RandomPool(2).withDispatcher("balancing-dispatcher").props(Props[TestActor]()))
|
||||
}
|
||||
}
|
||||
"fail verification with a ConfigurationException if also configured with a SmallestMailboxPool" in {
|
||||
intercept[ConfigurationException] {
|
||||
system.actorOf(SmallestMailboxPool(2).withDispatcher("balancing-dispatcher").props(Props[TestActor]))
|
||||
system.actorOf(SmallestMailboxPool(2).withDispatcher("balancing-dispatcher").props(Props[TestActor]()))
|
||||
}
|
||||
}
|
||||
"fail verification with a ConfigurationException if also configured with a ScatterGatherFirstCompletedPool" in {
|
||||
|
|
@ -70,33 +71,33 @@ class ActorConfigurationVerificationSpec
|
|||
system.actorOf(
|
||||
ScatterGatherFirstCompletedPool(nrOfInstances = 2, within = 2 seconds)
|
||||
.withDispatcher("balancing-dispatcher")
|
||||
.props(Props[TestActor]))
|
||||
.props(Props[TestActor]()))
|
||||
}
|
||||
}
|
||||
"not fail verification with a ConfigurationException also not configured with a Router" in {
|
||||
system.actorOf(Props[TestActor].withDispatcher("balancing-dispatcher"))
|
||||
system.actorOf(Props[TestActor]().withDispatcher("balancing-dispatcher"))
|
||||
}
|
||||
}
|
||||
"An Actor configured with a non-balancing dispatcher" must {
|
||||
"not fail verification with a ConfigurationException if also configured with a Router" in {
|
||||
system.actorOf(RoundRobinPool(2).props(Props[TestActor].withDispatcher("pinned-dispatcher")))
|
||||
system.actorOf(RoundRobinPool(2).props(Props[TestActor]().withDispatcher("pinned-dispatcher")))
|
||||
}
|
||||
|
||||
"fail verification if the dispatcher cannot be found" in {
|
||||
intercept[ConfigurationException] {
|
||||
system.actorOf(Props[TestActor].withDispatcher("does not exist"))
|
||||
system.actorOf(Props[TestActor]().withDispatcher("does not exist"))
|
||||
}
|
||||
}
|
||||
|
||||
"fail verification if the dispatcher cannot be found for the head of a router" in {
|
||||
intercept[ConfigurationException] {
|
||||
system.actorOf(RoundRobinPool(1, routerDispatcher = "does not exist").props(Props[TestActor]))
|
||||
system.actorOf(RoundRobinPool(1, routerDispatcher = "does not exist").props(Props[TestActor]()))
|
||||
}
|
||||
}
|
||||
|
||||
"fail verification if the dispatcher cannot be found for the routees of a router" in {
|
||||
intercept[ConfigurationException] {
|
||||
system.actorOf(RoundRobinPool(1).props(Props[TestActor].withDispatcher("does not exist")))
|
||||
system.actorOf(RoundRobinPool(1).props(Props[TestActor]().withDispatcher("does not exist")))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,15 +4,16 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import scala.language.postfixOps
|
||||
|
||||
import akka.testkit.{ AkkaSpec, ImplicitSender, PerformanceTest }
|
||||
import scala.concurrent.duration._
|
||||
import akka.testkit.metrics._
|
||||
import org.scalatest.BeforeAndAfterAll
|
||||
import akka.testkit.metrics.HeapMemoryUsage
|
||||
import com.codahale.metrics.{ Histogram }
|
||||
import com.codahale.metrics.Histogram
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.scalatest.BeforeAndAfterAll
|
||||
|
||||
import akka.testkit.{ AkkaSpec, ImplicitSender, PerformanceTest }
|
||||
import akka.testkit.metrics._
|
||||
import akka.testkit.metrics.HeapMemoryUsage
|
||||
|
||||
object ActorCreationPerfSpec {
|
||||
|
||||
|
|
@ -218,9 +219,9 @@ class ActorCreationPerfSpec
|
|||
|
||||
"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]
|
||||
val props1 = Props[EmptyActor]()
|
||||
registerTests("Props[EmptyActor] with same Props", () => props1)
|
||||
|
||||
registerTests("Props(new EmptyActor) new", () => { Props(new EmptyActor) })
|
||||
|
|
|
|||
|
|
@ -4,20 +4,21 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
|
||||
import akka.actor.Actor._
|
||||
import akka.testkit._
|
||||
import java.util.concurrent.atomic._
|
||||
import scala.concurrent.Await
|
||||
import akka.pattern.ask
|
||||
import java.util.UUID.{ randomUUID => newUuid }
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.atomic._
|
||||
|
||||
import scala.concurrent.{ Await, Future }
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
import akka.actor.Actor._
|
||||
import akka.pattern.ask
|
||||
import akka.testkit._
|
||||
|
||||
object ActorLifeCycleSpec {
|
||||
|
||||
class LifeCycleTestActor(testActor: ActorRef, id: String, generationProvider: AtomicInteger) extends Actor {
|
||||
def report(msg: Any) = testActor ! message(msg)
|
||||
def message(msg: Any): Tuple3[Any, String, Int] = (msg, id, currentGen)
|
||||
def message(msg: Any): (Any, String, Int) = (msg, id, currentGen)
|
||||
val currentGen = generationProvider.getAndIncrement()
|
||||
override def preStart(): Unit = { report("preStart") }
|
||||
override def postStop(): Unit = { report("postStop") }
|
||||
|
|
@ -149,4 +150,41 @@ class ActorLifeCycleSpec extends AkkaSpec with BeforeAndAfterEach with ImplicitS
|
|||
}
|
||||
}
|
||||
|
||||
"have a non null context after termination" in {
|
||||
class StopBeforeFutureFinishes(val latch: CountDownLatch) extends Actor {
|
||||
import context.dispatcher
|
||||
import akka.pattern._
|
||||
|
||||
override def receive: Receive = {
|
||||
case "ping" =>
|
||||
val replyTo = sender()
|
||||
|
||||
context.stop(self)
|
||||
|
||||
Future {
|
||||
latch.await()
|
||||
Thread.sleep(50)
|
||||
"po"
|
||||
}
|
||||
// Here, we implicitly close over the actor instance and access the context
|
||||
// when the flatMap thunk is run. Previously, the context was nulled when the actor
|
||||
// was terminated. This isn't done any more. Still, the pattern of `import context.dispatcher`
|
||||
// is discouraged as closing over `context` is unsafe in general.
|
||||
.flatMap(x => Future { x + "ng" } /* implicitly: (this.context.dispatcher) */ )
|
||||
.recover { case _: NullPointerException => "npe" }
|
||||
.pipeTo(replyTo)
|
||||
}
|
||||
}
|
||||
|
||||
val latch = new CountDownLatch(1)
|
||||
val actor = system.actorOf(Props(new StopBeforeFutureFinishes(latch)))
|
||||
watch(actor)
|
||||
|
||||
actor ! "ping"
|
||||
|
||||
expectTerminated(actor)
|
||||
latch.countDown()
|
||||
|
||||
expectMsg("pong")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import akka.testkit._
|
||||
import akka.dispatch._
|
||||
|
||||
import scala.concurrent.duration.{ Duration, FiniteDuration }
|
||||
import akka.ConfigurationException
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
import akka.ConfigurationException
|
||||
import akka.dispatch._
|
||||
import akka.testkit._
|
||||
import akka.util.Helpers.ConfigOps
|
||||
import akka.util.unused
|
||||
|
||||
|
|
@ -242,22 +243,22 @@ class ActorMailboxSpec(conf: Config) extends AkkaSpec(conf) with DefaultTimeout
|
|||
"An Actor" must {
|
||||
|
||||
"get an unbounded message queue by default" in {
|
||||
checkMailboxQueue(Props[QueueReportingActor], "default-default", UnboundedMailboxTypes)
|
||||
checkMailboxQueue(Props[QueueReportingActor](), "default-default", UnboundedMailboxTypes)
|
||||
}
|
||||
|
||||
"get an unbounded deque message queue when it is only configured on the props" in {
|
||||
checkMailboxQueue(
|
||||
Props[QueueReportingActor].withMailbox("akka.actor.mailbox.unbounded-deque-based"),
|
||||
Props[QueueReportingActor]().withMailbox("akka.actor.mailbox.unbounded-deque-based"),
|
||||
"default-override-from-props",
|
||||
UnboundedDeqMailboxTypes)
|
||||
}
|
||||
|
||||
"get an bounded message queue when it's only configured with RequiresMailbox" in {
|
||||
checkMailboxQueue(Props[BoundedQueueReportingActor], "default-override-from-trait", BoundedMailboxTypes)
|
||||
checkMailboxQueue(Props[BoundedQueueReportingActor](), "default-override-from-trait", BoundedMailboxTypes)
|
||||
}
|
||||
|
||||
"get an unbounded deque message queue when it's only mixed with Stash" in {
|
||||
checkMailboxQueue(Props[StashQueueReportingActor], "default-override-from-stash", UnboundedDeqMailboxTypes)
|
||||
checkMailboxQueue(Props[StashQueueReportingActor](), "default-override-from-stash", UnboundedDeqMailboxTypes)
|
||||
checkMailboxQueue(Props(new StashQueueReportingActor), "default-override-from-stash2", UnboundedDeqMailboxTypes)
|
||||
checkMailboxQueue(
|
||||
Props(classOf[StashQueueReportingActorWithParams], 17, "hello"),
|
||||
|
|
@ -270,99 +271,99 @@ class ActorMailboxSpec(conf: Config) extends AkkaSpec(conf) with DefaultTimeout
|
|||
}
|
||||
|
||||
"get a bounded message queue when it's configured as mailbox" in {
|
||||
checkMailboxQueue(Props[QueueReportingActor], "default-bounded", BoundedMailboxTypes)
|
||||
checkMailboxQueue(Props[QueueReportingActor](), "default-bounded", BoundedMailboxTypes)
|
||||
}
|
||||
|
||||
"get an unbounded deque message queue when it's configured as mailbox" in {
|
||||
checkMailboxQueue(Props[QueueReportingActor], "default-unbounded-deque", UnboundedDeqMailboxTypes)
|
||||
checkMailboxQueue(Props[QueueReportingActor](), "default-unbounded-deque", UnboundedDeqMailboxTypes)
|
||||
}
|
||||
|
||||
"get a bounded control aware message queue when it's configured as mailbox" in {
|
||||
checkMailboxQueue(Props[QueueReportingActor], "default-bounded-control-aware", BoundedControlAwareMailboxTypes)
|
||||
checkMailboxQueue(Props[QueueReportingActor](), "default-bounded-control-aware", BoundedControlAwareMailboxTypes)
|
||||
}
|
||||
|
||||
"get an unbounded control aware message queue when it's configured as mailbox" in {
|
||||
checkMailboxQueue(
|
||||
Props[QueueReportingActor],
|
||||
Props[QueueReportingActor](),
|
||||
"default-unbounded-control-aware",
|
||||
UnboundedControlAwareMailboxTypes)
|
||||
}
|
||||
|
||||
"get an bounded control aware message queue when it's only configured with RequiresMailbox" in {
|
||||
checkMailboxQueue(
|
||||
Props[BoundedControlAwareQueueReportingActor],
|
||||
Props[BoundedControlAwareQueueReportingActor](),
|
||||
"default-override-from-trait-bounded-control-aware",
|
||||
BoundedControlAwareMailboxTypes)
|
||||
}
|
||||
|
||||
"get an unbounded control aware message queue when it's only configured with RequiresMailbox" in {
|
||||
checkMailboxQueue(
|
||||
Props[UnboundedControlAwareQueueReportingActor],
|
||||
Props[UnboundedControlAwareQueueReportingActor](),
|
||||
"default-override-from-trait-unbounded-control-aware",
|
||||
UnboundedControlAwareMailboxTypes)
|
||||
}
|
||||
|
||||
"fail to create actor when an unbounded dequeu message queue is configured as mailbox overriding RequestMailbox" in {
|
||||
intercept[ConfigurationException](
|
||||
system.actorOf(Props[BoundedQueueReportingActor], "default-unbounded-deque-override-trait"))
|
||||
system.actorOf(Props[BoundedQueueReportingActor](), "default-unbounded-deque-override-trait"))
|
||||
}
|
||||
|
||||
"get an unbounded message queue when defined in dispatcher" in {
|
||||
checkMailboxQueue(Props[QueueReportingActor], "unbounded-default", UnboundedMailboxTypes)
|
||||
checkMailboxQueue(Props[QueueReportingActor](), "unbounded-default", UnboundedMailboxTypes)
|
||||
}
|
||||
|
||||
"fail to create actor when an unbounded message queue is defined in dispatcher overriding RequestMailbox" in {
|
||||
intercept[ConfigurationException](
|
||||
system.actorOf(Props[BoundedQueueReportingActor], "unbounded-default-override-trait"))
|
||||
system.actorOf(Props[BoundedQueueReportingActor](), "unbounded-default-override-trait"))
|
||||
}
|
||||
|
||||
"get a bounded message queue when it's configured as mailbox overriding unbounded in dispatcher" in {
|
||||
checkMailboxQueue(Props[QueueReportingActor], "unbounded-bounded", BoundedMailboxTypes)
|
||||
checkMailboxQueue(Props[QueueReportingActor](), "unbounded-bounded", BoundedMailboxTypes)
|
||||
}
|
||||
|
||||
"get a bounded message queue when defined in dispatcher" in {
|
||||
checkMailboxQueue(Props[QueueReportingActor], "bounded-default", BoundedMailboxTypes)
|
||||
checkMailboxQueue(Props[QueueReportingActor](), "bounded-default", BoundedMailboxTypes)
|
||||
}
|
||||
|
||||
"get a bounded message queue with 0 push timeout when defined in dispatcher" in {
|
||||
val q = checkMailboxQueue(
|
||||
Props[QueueReportingActor],
|
||||
Props[QueueReportingActor](),
|
||||
"default-bounded-mailbox-with-zero-pushtimeout",
|
||||
BoundedMailboxTypes)
|
||||
q.asInstanceOf[BoundedMessageQueueSemantics].pushTimeOut should ===(Duration.Zero)
|
||||
}
|
||||
|
||||
"get an unbounded message queue when it's configured as mailbox overriding bounded in dispatcher" in {
|
||||
checkMailboxQueue(Props[QueueReportingActor], "bounded-unbounded", UnboundedMailboxTypes)
|
||||
checkMailboxQueue(Props[QueueReportingActor](), "bounded-unbounded", UnboundedMailboxTypes)
|
||||
}
|
||||
|
||||
"get an unbounded message queue overriding configuration on the props" in {
|
||||
checkMailboxQueue(
|
||||
Props[QueueReportingActor].withMailbox("akka.actor.mailbox.unbounded-deque-based"),
|
||||
Props[QueueReportingActor]().withMailbox("akka.actor.mailbox.unbounded-deque-based"),
|
||||
"bounded-unbounded-override-props",
|
||||
UnboundedMailboxTypes)
|
||||
}
|
||||
|
||||
"get a bounded deque-based message queue if configured and required" in {
|
||||
checkMailboxQueue(
|
||||
Props[StashQueueReportingActor],
|
||||
Props[StashQueueReportingActor](),
|
||||
"bounded-deque-requirements-configured",
|
||||
BoundedDeqMailboxTypes)
|
||||
}
|
||||
|
||||
"fail with a unbounded deque-based message queue if configured and required" in {
|
||||
intercept[ConfigurationException](
|
||||
system.actorOf(Props[StashQueueReportingActor], "bounded-deque-require-unbounded-configured"))
|
||||
system.actorOf(Props[StashQueueReportingActor](), "bounded-deque-require-unbounded-configured"))
|
||||
}
|
||||
|
||||
"fail with a bounded deque-based message queue if not configured" in {
|
||||
intercept[ConfigurationException](
|
||||
system.actorOf(Props[StashQueueReportingActor], "bounded-deque-require-unbounded-unconfigured"))
|
||||
system.actorOf(Props[StashQueueReportingActor](), "bounded-deque-require-unbounded-unconfigured"))
|
||||
}
|
||||
|
||||
"get a bounded deque-based message queue if configured and required with Props" in {
|
||||
checkMailboxQueue(
|
||||
Props[StashQueueReportingActor]
|
||||
Props[StashQueueReportingActor]()
|
||||
.withDispatcher("requiring-bounded-dispatcher")
|
||||
.withMailbox("akka.actor.mailbox.bounded-deque-based"),
|
||||
"bounded-deque-requirements-configured-props",
|
||||
|
|
@ -372,7 +373,7 @@ class ActorMailboxSpec(conf: Config) extends AkkaSpec(conf) with DefaultTimeout
|
|||
"fail with a unbounded deque-based message queue if configured and required with Props" in {
|
||||
intercept[ConfigurationException](
|
||||
system.actorOf(
|
||||
Props[StashQueueReportingActor]
|
||||
Props[StashQueueReportingActor]()
|
||||
.withDispatcher("requiring-bounded-dispatcher")
|
||||
.withMailbox("akka.actor.mailbox.unbounded-deque-based"),
|
||||
"bounded-deque-require-unbounded-configured-props"))
|
||||
|
|
@ -381,13 +382,13 @@ class ActorMailboxSpec(conf: Config) extends AkkaSpec(conf) with DefaultTimeout
|
|||
"fail with a bounded deque-based message queue if not configured with Props" in {
|
||||
intercept[ConfigurationException](
|
||||
system.actorOf(
|
||||
Props[StashQueueReportingActor].withDispatcher("requiring-bounded-dispatcher"),
|
||||
Props[StashQueueReportingActor]().withDispatcher("requiring-bounded-dispatcher"),
|
||||
"bounded-deque-require-unbounded-unconfigured-props"))
|
||||
}
|
||||
|
||||
"get a bounded deque-based message queue if configured and required with Props (dispatcher)" in {
|
||||
checkMailboxQueue(
|
||||
Props[StashQueueReportingActor].withDispatcher("requiring-bounded-dispatcher"),
|
||||
Props[StashQueueReportingActor]().withDispatcher("requiring-bounded-dispatcher"),
|
||||
"bounded-deque-requirements-configured-props-disp",
|
||||
BoundedDeqMailboxTypes)
|
||||
}
|
||||
|
|
@ -395,20 +396,20 @@ class ActorMailboxSpec(conf: Config) extends AkkaSpec(conf) with DefaultTimeout
|
|||
"fail with a unbounded deque-based message queue if configured and required with Props (dispatcher)" in {
|
||||
intercept[ConfigurationException](
|
||||
system.actorOf(
|
||||
Props[StashQueueReportingActor].withDispatcher("requiring-bounded-dispatcher"),
|
||||
Props[StashQueueReportingActor]().withDispatcher("requiring-bounded-dispatcher"),
|
||||
"bounded-deque-require-unbounded-configured-props-disp"))
|
||||
}
|
||||
|
||||
"fail with a bounded deque-based message queue if not configured with Props (dispatcher)" in {
|
||||
intercept[ConfigurationException](
|
||||
system.actorOf(
|
||||
Props[StashQueueReportingActor].withDispatcher("requiring-bounded-dispatcher"),
|
||||
Props[StashQueueReportingActor]().withDispatcher("requiring-bounded-dispatcher"),
|
||||
"bounded-deque-require-unbounded-unconfigured-props-disp"))
|
||||
}
|
||||
|
||||
"get a bounded deque-based message queue if configured and required with Props (mailbox)" in {
|
||||
checkMailboxQueue(
|
||||
Props[StashQueueReportingActor].withMailbox("akka.actor.mailbox.bounded-deque-based"),
|
||||
Props[StashQueueReportingActor]().withMailbox("akka.actor.mailbox.bounded-deque-based"),
|
||||
"bounded-deque-requirements-configured-props-mail",
|
||||
BoundedDeqMailboxTypes)
|
||||
}
|
||||
|
|
@ -416,32 +417,32 @@ class ActorMailboxSpec(conf: Config) extends AkkaSpec(conf) with DefaultTimeout
|
|||
"fail with a unbounded deque-based message queue if configured and required with Props (mailbox)" in {
|
||||
intercept[ConfigurationException](
|
||||
system.actorOf(
|
||||
Props[StashQueueReportingActor].withMailbox("akka.actor.mailbox.unbounded-deque-based"),
|
||||
Props[StashQueueReportingActor]().withMailbox("akka.actor.mailbox.unbounded-deque-based"),
|
||||
"bounded-deque-require-unbounded-configured-props-mail"))
|
||||
}
|
||||
|
||||
"fail with a bounded deque-based message queue if not configured with Props (mailbox)" in {
|
||||
intercept[ConfigurationException](
|
||||
system.actorOf(Props[StashQueueReportingActor], "bounded-deque-require-unbounded-unconfigured-props-mail"))
|
||||
system.actorOf(Props[StashQueueReportingActor](), "bounded-deque-require-unbounded-unconfigured-props-mail"))
|
||||
}
|
||||
|
||||
"get an unbounded message queue with a balancing dispatcher" in {
|
||||
checkMailboxQueue(
|
||||
Props[QueueReportingActor].withDispatcher("balancing-dispatcher"),
|
||||
Props[QueueReportingActor]().withDispatcher("balancing-dispatcher"),
|
||||
"unbounded-balancing",
|
||||
UnboundedMailboxTypes)
|
||||
}
|
||||
|
||||
"get a bounded message queue with a balancing bounded dispatcher" in {
|
||||
checkMailboxQueue(
|
||||
Props[QueueReportingActor].withDispatcher("balancing-bounded-dispatcher"),
|
||||
Props[QueueReportingActor]().withDispatcher("balancing-bounded-dispatcher"),
|
||||
"bounded-balancing",
|
||||
BoundedMailboxTypes)
|
||||
}
|
||||
|
||||
"get a bounded message queue with a requiring balancing bounded dispatcher" in {
|
||||
checkMailboxQueue(
|
||||
Props[QueueReportingActor].withDispatcher("requiring-balancing-bounded-dispatcher"),
|
||||
Props[QueueReportingActor]().withDispatcher("requiring-balancing-bounded-dispatcher"),
|
||||
"requiring-bounded-balancing",
|
||||
BoundedMailboxTypes)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,16 +4,18 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.Promise
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import language.postfixOps
|
||||
|
||||
import akka.testkit._
|
||||
import akka.util.Timeout
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.Await
|
||||
import java.lang.IllegalStateException
|
||||
import scala.concurrent.Promise
|
||||
import akka.pattern.ask
|
||||
import akka.serialization.JavaSerializer
|
||||
import akka.testkit._
|
||||
import akka.util.Timeout
|
||||
|
||||
object ActorRefSpec {
|
||||
|
||||
|
|
@ -25,11 +27,11 @@ object ActorRefSpec {
|
|||
def receive = {
|
||||
case "complexRequest" => {
|
||||
replyTo = sender()
|
||||
val worker = context.actorOf(Props[WorkerActor])
|
||||
val worker = context.actorOf(Props[WorkerActor]())
|
||||
worker ! "work"
|
||||
}
|
||||
case "complexRequest2" =>
|
||||
val worker = context.actorOf(Props[WorkerActor])
|
||||
val worker = context.actorOf(Props[WorkerActor]())
|
||||
worker ! ReplyTo(sender())
|
||||
case "workDone" => replyTo ! "complexReply"
|
||||
case "simpleRequest" => sender() ! "simpleReply"
|
||||
|
|
@ -278,7 +280,7 @@ class ActorRefSpec extends AkkaSpec("""
|
|||
}
|
||||
|
||||
"be serializable using Java Serialization on local node" in {
|
||||
val a = system.actorOf(Props[InnerActor])
|
||||
val a = system.actorOf(Props[InnerActor]())
|
||||
val esys = system.asInstanceOf[ExtendedActorSystem]
|
||||
|
||||
import java.io._
|
||||
|
|
@ -309,7 +311,7 @@ class ActorRefSpec extends AkkaSpec("""
|
|||
}
|
||||
|
||||
"throw an exception on deserialize if no system in scope" in {
|
||||
val a = system.actorOf(Props[InnerActor])
|
||||
val a = system.actorOf(Props[InnerActor]())
|
||||
|
||||
import java.io._
|
||||
|
||||
|
|
@ -337,7 +339,7 @@ class ActorRefSpec extends AkkaSpec("""
|
|||
val out = new ObjectOutputStream(baos)
|
||||
|
||||
val sysImpl = system.asInstanceOf[ActorSystemImpl]
|
||||
val ref = system.actorOf(Props[ReplyActor], "non-existing")
|
||||
val ref = system.actorOf(Props[ReplyActor](), "non-existing")
|
||||
val serialized = SerializedActorRef(ref)
|
||||
|
||||
out.writeObject(serialized)
|
||||
|
|
@ -381,7 +383,7 @@ class ActorRefSpec extends AkkaSpec("""
|
|||
|
||||
"support reply via sender" in {
|
||||
val latch = new TestLatch(4)
|
||||
val serverRef = system.actorOf(Props[ReplyActor])
|
||||
val serverRef = system.actorOf(Props[ReplyActor]())
|
||||
val clientRef = system.actorOf(Props(new SenderActor(serverRef, latch)))
|
||||
|
||||
clientRef ! "complex"
|
||||
|
|
@ -391,7 +393,7 @@ class ActorRefSpec extends AkkaSpec("""
|
|||
|
||||
Await.ready(latch, timeout.duration)
|
||||
|
||||
latch.reset
|
||||
latch.reset()
|
||||
|
||||
clientRef ! "complex2"
|
||||
clientRef ! "simple"
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import akka.testkit._
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import akka.pattern.ask
|
||||
import akka.testkit._
|
||||
|
||||
object ActorSelectionSpec {
|
||||
|
||||
|
|
@ -19,7 +20,7 @@ object ActorSelectionSpec {
|
|||
final case class GetSender(to: ActorRef) extends Query
|
||||
final case class Forward(path: String, msg: Any) extends Query
|
||||
|
||||
val p = Props[Node]
|
||||
val p = Props[Node]()
|
||||
|
||||
class Node extends Actor {
|
||||
def receive = {
|
||||
|
|
@ -355,7 +356,7 @@ class ActorSelectionSpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
"identify actors with wildcard selection correctly" in {
|
||||
val creator = TestProbe()
|
||||
implicit def self = creator.ref
|
||||
implicit def self: ActorRef = creator.ref
|
||||
val top = system.actorOf(p, "a")
|
||||
val b1 = Await.result((top ? Create("b1")).mapTo[ActorRef], timeout.duration)
|
||||
val b2 = Await.result((top ? Create("b2")).mapTo[ActorRef], timeout.duration)
|
||||
|
|
|
|||
|
|
@ -4,14 +4,15 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import scala.concurrent.ExecutionContext
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
import akka.ConfigurationException
|
||||
import akka.actor.setup.ActorSystemSetup
|
||||
import akka.dispatch.{ Dispatchers, ExecutionContexts }
|
||||
import akka.testkit.{ AkkaSpec, ImplicitSender, TestActors, TestProbe }
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
import scala.concurrent.ExecutionContext
|
||||
import scala.concurrent.duration._
|
||||
|
||||
object ActorSystemDispatchersSpec {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,22 +4,23 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.util.concurrent.{ ConcurrentLinkedQueue, RejectedExecutionException }
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import scala.concurrent.{ Await, Future }
|
||||
import scala.concurrent.duration._
|
||||
import scala.language.postfixOps
|
||||
|
||||
import com.github.ghik.silencer.silent
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
|
||||
import akka.actor.setup.ActorSystemSetup
|
||||
import akka.dispatch._
|
||||
import akka.japi.Util.immutableSeq
|
||||
import akka.pattern.ask
|
||||
import akka.testkit.{ TestKit, _ }
|
||||
import akka.util.Helpers.ConfigOps
|
||||
import akka.util.{ Switch, Timeout }
|
||||
import com.github.ghik.silencer.silent
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.{ Await, Future }
|
||||
import scala.language.postfixOps
|
||||
import akka.util.Helpers.ConfigOps
|
||||
|
||||
object ActorSystemSpec {
|
||||
|
||||
|
|
@ -31,7 +32,7 @@ object ActorSystemSpec {
|
|||
case n: Int =>
|
||||
master = sender()
|
||||
terminaters = Set() ++ (for (_ <- 1 to n) yield {
|
||||
val man = context.watch(context.system.actorOf(Props[Terminater]))
|
||||
val man = context.watch(context.system.actorOf(Props[Terminater]()))
|
||||
man ! "run"
|
||||
man
|
||||
})
|
||||
|
|
@ -142,7 +143,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
ActorSystem("LogDeadLetters", ConfigFactory.parseString("akka.loglevel=INFO").withFallback(AkkaSpec.testConf))
|
||||
try {
|
||||
val probe = TestProbe()(sys)
|
||||
val a = sys.actorOf(Props[ActorSystemSpec.Terminater])
|
||||
val a = sys.actorOf(Props[ActorSystemSpec.Terminater]())
|
||||
probe.watch(a)
|
||||
a.tell("run", probe.ref)
|
||||
probe.expectTerminated(a)
|
||||
|
|
@ -166,7 +167,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
ActorSystem("LogDeadLetters", ConfigFactory.parseString("akka.loglevel=INFO").withFallback(AkkaSpec.testConf))
|
||||
try {
|
||||
val probe = TestProbe()(sys)
|
||||
val a = sys.actorOf(Props[ActorSystemSpec.Terminater])
|
||||
val a = sys.actorOf(Props[ActorSystemSpec.Terminater]())
|
||||
probe.watch(a)
|
||||
a.tell("run", probe.ref)
|
||||
probe.expectTerminated(a)
|
||||
|
|
@ -263,8 +264,8 @@ 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 (_ <- 1 to 3) yield system.actorOf(Props[ActorSystemSpec.Waves]) ? 50000
|
||||
implicit val timeout: Timeout = Timeout((20 seconds).dilated)
|
||||
val waves = for (_ <- 1 to 3) yield system.actorOf(Props[ActorSystemSpec.Waves]()) ? 50000
|
||||
Await.result(Future.sequence(waves), timeout.duration + 5.seconds) should ===(Vector("done", "done", "done"))
|
||||
}
|
||||
|
||||
|
|
@ -281,7 +282,7 @@ class ActorSystemSpec extends AkkaSpec(ActorSystemSpec.config) with ImplicitSend
|
|||
var created = Vector.empty[ActorRef]
|
||||
while (!system.whenTerminated.isCompleted) {
|
||||
try {
|
||||
val t = system.actorOf(Props[ActorSystemSpec.Terminater])
|
||||
val t = system.actorOf(Props[ActorSystemSpec.Terminater]())
|
||||
failing should not be true // because once failing => always failing (it’s due to shutdown)
|
||||
created :+= t
|
||||
if (created.size % 1000 == 0) Thread.sleep(50) // in case of unfair thread scheduling
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import akka.pattern.{ ask, AskTimeoutException }
|
||||
import akka.testkit._
|
||||
import akka.testkit.TestEvent._
|
||||
import scala.concurrent.Await
|
||||
import akka.util.Timeout
|
||||
import akka.pattern.{ ask, AskTimeoutException }
|
||||
|
||||
class ActorTimeoutSpec extends AkkaSpec {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,17 +4,18 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
import language.postfixOps
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
|
||||
import akka.actor.ActorSystem.Settings
|
||||
import akka.dispatch.BoundedDequeBasedMailbox
|
||||
import akka.testkit._
|
||||
import akka.testkit.DefaultTimeout
|
||||
import akka.testkit.TestEvent._
|
||||
import akka.dispatch.BoundedDequeBasedMailbox
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import akka.actor.ActorSystem.Settings
|
||||
import akka.util.unused
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
|
||||
object ActorWithBoundedStashSpec {
|
||||
|
||||
|
|
@ -135,22 +136,22 @@ class ActorWithBoundedStashSpec
|
|||
"An Actor with Stash" must {
|
||||
|
||||
"end up in DeadLetters in case of a capacity violation when configured via dispatcher" in {
|
||||
val stasher = system.actorOf(Props[StashingActor].withDispatcher(dispatcherId1))
|
||||
val stasher = system.actorOf(Props[StashingActor]().withDispatcher(dispatcherId1))
|
||||
testDeadLetters(stasher)
|
||||
}
|
||||
|
||||
"end up in DeadLetters in case of a capacity violation when configured via mailbox" in {
|
||||
val stasher = system.actorOf(Props[StashingActor].withMailbox(mailboxId1))
|
||||
val stasher = system.actorOf(Props[StashingActor]().withMailbox(mailboxId1))
|
||||
testDeadLetters(stasher)
|
||||
}
|
||||
|
||||
"throw a StashOverflowException in case of a stash capacity violation when configured via dispatcher" in {
|
||||
val stasher = system.actorOf(Props[StashingActorWithOverflow].withDispatcher(dispatcherId2))
|
||||
val stasher = system.actorOf(Props[StashingActorWithOverflow]().withDispatcher(dispatcherId2))
|
||||
testStashOverflowException(stasher)
|
||||
}
|
||||
|
||||
"throw a StashOverflowException in case of a stash capacity violation when configured via mailbox" in {
|
||||
val stasher = system.actorOf(Props[StashingActorWithOverflow].withMailbox(mailboxId2))
|
||||
val stasher = system.actorOf(Props[StashingActorWithOverflow]().withMailbox(mailboxId2))
|
||||
testStashOverflowException(stasher)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,19 +4,19 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.github.ghik.silencer.silent
|
||||
import language.postfixOps
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
import org.scalatestplus.junit.JUnitSuiteLike
|
||||
|
||||
import akka.pattern.ask
|
||||
import akka.testkit._
|
||||
import akka.testkit.DefaultTimeout
|
||||
import akka.testkit.TestEvent._
|
||||
|
||||
import scala.concurrent.Await
|
||||
import akka.pattern.ask
|
||||
import com.github.ghik.silencer.silent
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
import org.scalatestplus.junit.JUnitSuiteLike
|
||||
|
||||
object ActorWithStashSpec {
|
||||
|
||||
class StashingActor extends Actor with Stash {
|
||||
|
|
@ -24,7 +24,7 @@ object ActorWithStashSpec {
|
|||
def greeted: Receive = {
|
||||
case "bye" =>
|
||||
state.s = "bye"
|
||||
state.finished.await
|
||||
state.finished.await()
|
||||
case _ => // do nothing
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ object ActorWithStashSpec {
|
|||
context.unbecome()
|
||||
case _ => stash()
|
||||
}
|
||||
case "done" => state.finished.await
|
||||
case "done" => state.finished.await()
|
||||
case _ => stash()
|
||||
}
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ object ActorWithStashSpec {
|
|||
}
|
||||
|
||||
class TerminatedMessageStashingActor(probe: ActorRef) extends Actor with Stash {
|
||||
val watched = context.watch(context.actorOf(Props[WatchedActor]))
|
||||
val watched = context.watch(context.actorOf(Props[WatchedActor]()))
|
||||
var stashed = false
|
||||
|
||||
context.stop(watched)
|
||||
|
|
@ -109,7 +109,7 @@ class ActorWithStashSpec extends AkkaSpec with DefaultTimeout with BeforeAndAfte
|
|||
system.eventStream.publish(Mute(EventFilter[Exception]("Crashing...")))
|
||||
}
|
||||
|
||||
override def beforeEach() = state.finished.reset
|
||||
override def beforeEach() = state.finished.reset()
|
||||
|
||||
"An Actor with Stash" must {
|
||||
|
||||
|
|
@ -117,12 +117,12 @@ class ActorWithStashSpec extends AkkaSpec with DefaultTimeout with BeforeAndAfte
|
|||
val stasher = system.actorOf(Props(new StashingActor))
|
||||
stasher ! "bye"
|
||||
stasher ! "hello"
|
||||
state.finished.await
|
||||
state.finished.await()
|
||||
state.s should ===("bye")
|
||||
}
|
||||
|
||||
"support protocols" in {
|
||||
val protoActor = system.actorOf(Props[ActorWithProtocol])
|
||||
val protoActor = system.actorOf(Props[ActorWithProtocol]())
|
||||
protoActor ! "open"
|
||||
protoActor ! "write"
|
||||
protoActor ! "open"
|
||||
|
|
@ -130,12 +130,12 @@ class ActorWithStashSpec extends AkkaSpec with DefaultTimeout with BeforeAndAfte
|
|||
protoActor ! "write"
|
||||
protoActor ! "close"
|
||||
protoActor ! "done"
|
||||
state.finished.await
|
||||
state.finished.await()
|
||||
}
|
||||
|
||||
"throw an IllegalStateException if the same messages is stashed twice" in {
|
||||
state.expectedException = new TestLatch
|
||||
val stasher = system.actorOf(Props[StashingTwiceActor])
|
||||
val stasher = system.actorOf(Props[StashingTwiceActor]())
|
||||
stasher ! "hello"
|
||||
stasher ! "hello"
|
||||
Await.ready(state.expectedException, 10 seconds)
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import language.postfixOps
|
||||
|
||||
import akka.dispatch.ThreadPoolConfig
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.dispatch.{ ThreadPoolConfig }
|
||||
import scala.concurrent.duration._
|
||||
|
||||
object ConsistencySpec {
|
||||
val minThreads = 1
|
||||
|
|
@ -60,7 +61,7 @@ class ConsistencySpec extends AkkaSpec(ConsistencySpec.config) {
|
|||
"The Akka actor model implementation" must {
|
||||
"provide memory consistency" in {
|
||||
val noOfActors = threads + 1
|
||||
val props = Props[ConsistencyCheckingActor].withDispatcher("consistency-dispatcher")
|
||||
val props = Props[ConsistencyCheckingActor]().withDispatcher("consistency-dispatcher")
|
||||
val actors = Vector.fill(noOfActors)(system.actorOf(props))
|
||||
|
||||
for (i <- 0L until 10000L) {
|
||||
|
|
|
|||
|
|
@ -5,19 +5,20 @@
|
|||
package akka.actor
|
||||
|
||||
import java.util
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.{ Await, ExecutionContext, Future, Promise }
|
||||
|
||||
import akka.Done
|
||||
import akka.testkit.{ AkkaSpec, EventFilter, TestKit, TestProbe }
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
import akka.actor.CoordinatedShutdown.Phase
|
||||
import akka.actor.CoordinatedShutdown.UnknownReason
|
||||
import akka.util.ccompat.JavaConverters._
|
||||
import java.util.concurrent.{ Executors, TimeoutException }
|
||||
|
||||
import scala.concurrent.{ Await, ExecutionContext, Future, Promise }
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
|
||||
import akka.ConfigurationException
|
||||
import akka.Done
|
||||
import akka.actor.CoordinatedShutdown.Phase
|
||||
import akka.actor.CoordinatedShutdown.UnknownReason
|
||||
import akka.dispatch.ExecutionContexts
|
||||
import akka.testkit.{ AkkaSpec, EventFilter, TestKit, TestProbe }
|
||||
import akka.util.ccompat.JavaConverters._
|
||||
|
||||
class CoordinatedShutdownSpec
|
||||
extends AkkaSpec(ConfigFactory.parseString("""
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import akka.event.Logging
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.testkit.ImplicitSender
|
||||
import akka.testkit.TestActors
|
||||
import akka.testkit.TestProbe
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
object DeadLetterSupressionSpec {
|
||||
|
||||
case object NormalMsg
|
||||
|
|
|
|||
|
|
@ -4,16 +4,16 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import akka.actor.Props.EmptyActor
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.github.ghik.silencer.silent
|
||||
import language.postfixOps
|
||||
|
||||
import akka.actor.Props.EmptyActor
|
||||
import akka.dispatch.sysmsg.{ DeathWatchNotification, Failed }
|
||||
import akka.pattern.ask
|
||||
import akka.testkit._
|
||||
import com.github.ghik.silencer.silent
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.Await
|
||||
|
||||
class LocalDeathWatchSpec extends AkkaSpec with ImplicitSender with DefaultTimeout with DeathWatchSpec
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ object DeathWatchSpec {
|
|||
context.become {
|
||||
case Terminated(`currentKid`) =>
|
||||
testActor ! "GREEN"
|
||||
context unbecome
|
||||
context.unbecome()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -83,7 +83,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") {
|
||||
expectMsgPF(5 seconds, "" + actorRef + ": Stopped or Already terminated when linking") {
|
||||
case WrappedTerminated(Terminated(`actorRef`)) => true
|
||||
}
|
||||
|
||||
|
|
@ -217,7 +217,7 @@ trait DeathWatchSpec { this: AkkaSpec with ImplicitSender with DefaultTimeout =>
|
|||
.sendSystemMessage(DeathWatchNotification(subject, existenceConfirmed = true, addressTerminated = false))
|
||||
|
||||
// the testActor is not watching subject and will not receive a Terminated msg
|
||||
expectNoMessage
|
||||
expectNoMessage()
|
||||
}
|
||||
|
||||
"discard Terminated when unwatched between sysmsg and processing" in {
|
||||
|
|
|
|||
|
|
@ -4,13 +4,14 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import language.postfixOps
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import akka.testkit.AkkaSpec
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import com.typesafe.config.ConfigParseOptions
|
||||
import language.postfixOps
|
||||
|
||||
import akka.routing._
|
||||
import scala.concurrent.duration._
|
||||
import akka.testkit.AkkaSpec
|
||||
|
||||
object DeployerSpec {
|
||||
val deployerConf = ConfigFactory.parseString(
|
||||
|
|
|
|||
|
|
@ -4,15 +4,15 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import org.scalatest.BeforeAndAfterAll
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
import scala.collection.immutable
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
import scala.util.{ Failure, Success, Try }
|
||||
|
||||
import org.scalatest.BeforeAndAfterAll
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
abstract class TestSuperclass {
|
||||
def name: String
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,15 +6,16 @@ package akka.actor
|
|||
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import akka.testkit.EventFilter
|
||||
import akka.testkit.TestKit._
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
import scala.util.control.NoStackTrace
|
||||
|
||||
import com.github.ghik.silencer.silent
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
import org.scalatestplus.junit.JUnitSuiteLike
|
||||
|
||||
import akka.testkit.EventFilter
|
||||
import akka.testkit.TestKit._
|
||||
@silent
|
||||
class JavaExtensionSpec extends JavaExtension with JUnitSuiteLike
|
||||
|
||||
|
|
@ -33,16 +34,17 @@ object FailingTestExtension extends ExtensionId[FailingTestExtension] with Exten
|
|||
class TestException extends IllegalArgumentException("ERR") with NoStackTrace
|
||||
}
|
||||
|
||||
object InstanceCountingExtension extends ExtensionId[DummyExtensionImpl] with ExtensionIdProvider {
|
||||
object InstanceCountingExtension extends ExtensionId[InstanceCountingExtension] with ExtensionIdProvider {
|
||||
val createCount = new AtomicInteger(0)
|
||||
override def createExtension(system: ExtendedActorSystem): DummyExtensionImpl = {
|
||||
createCount.addAndGet(1)
|
||||
new DummyExtensionImpl
|
||||
override def createExtension(system: ExtendedActorSystem): InstanceCountingExtension = {
|
||||
new InstanceCountingExtension
|
||||
}
|
||||
override def lookup(): ExtensionId[_ <: Extension] = this
|
||||
}
|
||||
|
||||
class DummyExtensionImpl extends Extension
|
||||
class InstanceCountingExtension extends Extension {
|
||||
InstanceCountingExtension.createCount.incrementAndGet()
|
||||
}
|
||||
|
||||
// Dont't place inside ActorSystemSpec object, since it will not be garbage collected and reference to system remains
|
||||
class FailingTestExtension(val system: ExtendedActorSystem) extends Extension {
|
||||
|
|
@ -110,12 +112,33 @@ class ExtensionSpec extends AnyWordSpec with Matchers {
|
|||
shutdownActorSystem(system)
|
||||
}
|
||||
|
||||
"allow for auto-loading of library-extensions" in {
|
||||
"allow for auto-loading of library-extensions from reference.conf" in {
|
||||
import akka.util.ccompat.JavaConverters._
|
||||
// could be initialized by other tests, but assuming tests are not running in parallel
|
||||
val countBefore = InstanceCountingExtension.createCount.get()
|
||||
val system = ActorSystem("extensions")
|
||||
val listedExtensions = system.settings.config.getStringList("akka.library-extensions")
|
||||
listedExtensions.size should be > 0
|
||||
// could be initialized by other tests, so at least once
|
||||
InstanceCountingExtension.createCount.get() should be > 0
|
||||
val listedExtensions = system.settings.config.getStringList("akka.library-extensions").asScala
|
||||
listedExtensions.count(_.contains("InstanceCountingExtension")) should ===(1)
|
||||
|
||||
InstanceCountingExtension.createCount.get() - countBefore should ===(1)
|
||||
|
||||
shutdownActorSystem(system)
|
||||
}
|
||||
|
||||
"not create duplicate instances when auto-loading of library-extensions" in {
|
||||
import akka.util.ccompat.JavaConverters._
|
||||
// could be initialized by other tests, but assuming tests are not running in parallel
|
||||
val countBefore = InstanceCountingExtension.createCount.get()
|
||||
val system = ActorSystem(
|
||||
"extensions",
|
||||
ConfigFactory.parseString(
|
||||
"""
|
||||
akka.library-extensions = ["akka.actor.InstanceCountingExtension", "akka.actor.InstanceCountingExtension", "akka.actor.InstanceCountingExtension$"]
|
||||
"""))
|
||||
val listedExtensions = system.settings.config.getStringList("akka.library-extensions").asScala
|
||||
listedExtensions.count(_.contains("InstanceCountingExtension")) should ===(3) // testing duplicate names
|
||||
|
||||
InstanceCountingExtension.createCount.get() - countBefore should ===(1)
|
||||
|
||||
shutdownActorSystem(system)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import language.postfixOps
|
||||
import akka.testkit._
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import akka.event._
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import language.postfixOps
|
||||
|
||||
import akka.event._
|
||||
import akka.testkit._
|
||||
import akka.util.{ unused, Timeout }
|
||||
|
||||
object FSMActorSpec {
|
||||
|
|
@ -43,17 +43,17 @@ object FSMActorSpec {
|
|||
case Event(digit: Char, CodeState(soFar, code)) => {
|
||||
soFar + digit match {
|
||||
case incomplete if incomplete.length < code.length =>
|
||||
stay.using(CodeState(incomplete, code))
|
||||
stay().using(CodeState(incomplete, code))
|
||||
case codeTry if (codeTry == code) => {
|
||||
doUnlock()
|
||||
goto(Open).using(CodeState("", code)).forMax(timeout)
|
||||
}
|
||||
case _ => {
|
||||
stay.using(CodeState("", code))
|
||||
stay().using(CodeState("", code))
|
||||
}
|
||||
}
|
||||
}
|
||||
case Event("hello", _) => stay.replying("world")
|
||||
case Event("hello", _) => stay().replying("world")
|
||||
case Event("bye", _) => stop(FSM.Shutdown)
|
||||
}
|
||||
|
||||
|
|
@ -67,13 +67,13 @@ object FSMActorSpec {
|
|||
whenUnhandled {
|
||||
case Event(msg, _) => {
|
||||
log.warning("unhandled event " + msg + " in state " + stateName + " with data " + stateData)
|
||||
unhandledLatch.open
|
||||
stay
|
||||
unhandledLatch.open()
|
||||
stay()
|
||||
}
|
||||
}
|
||||
|
||||
onTransition {
|
||||
case Locked -> Open => transitionLatch.open
|
||||
case Locked -> Open => transitionLatch.open()
|
||||
}
|
||||
|
||||
// verify that old-style does still compile
|
||||
|
|
@ -119,8 +119,8 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" -> true)) with Im
|
|||
|
||||
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
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -147,7 +147,7 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" -> true)) with Im
|
|||
val tester = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case Hello => lock ! "hello"
|
||||
case "world" => answerLatch.open
|
||||
case "world" => answerLatch.open()
|
||||
case Bye => lock ! "bye"
|
||||
}
|
||||
}))
|
||||
|
|
@ -183,7 +183,7 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" -> true)) with Im
|
|||
* It is necessary here because of the path-dependent type fsm.StopEvent.
|
||||
*/
|
||||
lazy val fsm = new Actor with FSM[Int, Null] {
|
||||
override def preStart = { started.countDown }
|
||||
override def preStart = { started.countDown() }
|
||||
startWith(1, null)
|
||||
when(1) { FSM.NullFunction }
|
||||
onTermination {
|
||||
|
|
@ -269,7 +269,7 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" -> true)) with Im
|
|||
when(2) {
|
||||
case Event("stop", _) =>
|
||||
cancelTimer("t")
|
||||
stop
|
||||
stop()
|
||||
}
|
||||
onTermination {
|
||||
case StopEvent(r, _, _) => testActor ! r
|
||||
|
|
@ -307,8 +307,8 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" -> true)) with Im
|
|||
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"
|
||||
|
|
@ -327,12 +327,12 @@ class FSMActorSpec extends AkkaSpec(Map("akka.actor.debug.fsm" -> true)) with Im
|
|||
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 _ => goto(1)
|
||||
})
|
||||
when(1) {
|
||||
case _ => stay
|
||||
case _ => stay()
|
||||
}
|
||||
}))
|
||||
fsmref ! SubscribeTransitionCallBack(testActor)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class FSMTimingSpec extends AkkaSpec with ImplicitSender {
|
|||
}
|
||||
|
||||
"cancel a StateTimeout when actor is stopped" taggedAs TimingTest in {
|
||||
val stoppingActor = system.actorOf(Props[StoppingActor])
|
||||
val stoppingActor = system.actorOf(Props[StoppingActor]())
|
||||
system.eventStream.subscribe(testActor, classOf[DeadLetter])
|
||||
stoppingActor ! TestStoppingActorStateTimeout
|
||||
within(400 millis) {
|
||||
|
|
@ -56,7 +56,7 @@ class FSMTimingSpec extends AkkaSpec with ImplicitSender {
|
|||
// the timeout in state TestStateTimeout is 800 ms, then it will change to Initial
|
||||
within(400 millis) {
|
||||
fsm ! TestStateTimeoutOverride
|
||||
expectNoMessage
|
||||
expectNoMessage()
|
||||
}
|
||||
within(1 second) {
|
||||
fsm ! Cancel
|
||||
|
|
@ -72,7 +72,7 @@ class FSMTimingSpec extends AkkaSpec with ImplicitSender {
|
|||
expectMsg(Tick)
|
||||
expectMsg(Transition(fsm, TestSingleTimer, Initial))
|
||||
}
|
||||
expectNoMessage
|
||||
expectNoMessage()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ class FSMTimingSpec extends AkkaSpec with ImplicitSender {
|
|||
expectMsg(Tock)
|
||||
expectMsg(Transition(fsm, TestSingleTimerResubmit, Initial))
|
||||
}
|
||||
expectNoMessage
|
||||
expectNoMessage()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -232,10 +232,10 @@ object FSMTimingSpec {
|
|||
cancelTimer("hallo")
|
||||
sender() ! Tick
|
||||
startSingleTimer("hallo", Tock, 500.millis.dilated)
|
||||
stay
|
||||
stay()
|
||||
case Event(Tock, _) =>
|
||||
tester ! Tock
|
||||
stay
|
||||
stay()
|
||||
case Event(Cancel, _) =>
|
||||
cancelTimer("hallo")
|
||||
goto(Initial)
|
||||
|
|
@ -247,7 +247,7 @@ object FSMTimingSpec {
|
|||
cancelTimer("tester")
|
||||
goto(Initial)
|
||||
} else {
|
||||
stay.using(remaining - 1)
|
||||
stay().using(remaining - 1)
|
||||
}
|
||||
}
|
||||
when(TestCancelStateTimerInNamedTimerMessage) {
|
||||
|
|
@ -256,7 +256,7 @@ object FSMTimingSpec {
|
|||
suspend(self)
|
||||
startSingleTimer("named", Tock, 1.millis.dilated)
|
||||
TestKit.awaitCond(context.asInstanceOf[ActorCell].mailbox.hasMessages, 1.second.dilated)
|
||||
stay.forMax(1.millis.dilated).replying(Tick)
|
||||
stay().forMax(1.millis.dilated).replying(Tick)
|
||||
case Event(Tock, _) =>
|
||||
goto(TestCancelStateTimerInNamedTimerMessage2)
|
||||
}
|
||||
|
|
@ -271,9 +271,9 @@ object FSMTimingSpec {
|
|||
whenUnhandled {
|
||||
case Event(Tick, _) =>
|
||||
tester ! Unhandled(Tick)
|
||||
stay
|
||||
stay()
|
||||
}
|
||||
stay
|
||||
stay()
|
||||
case Event(Cancel, _) =>
|
||||
whenUnhandled(NullFunction)
|
||||
goto(Initial)
|
||||
|
|
@ -286,7 +286,7 @@ object FSMTimingSpec {
|
|||
when(Initial, 200 millis) {
|
||||
case Event(TestStoppingActorStateTimeout, _) =>
|
||||
context.stop(self)
|
||||
stay
|
||||
stay()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import akka.testkit._
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import scala.language.postfixOps
|
||||
|
||||
import akka.testkit._
|
||||
|
||||
object FSMTransitionSpec {
|
||||
|
||||
class Supervisor extends Actor {
|
||||
|
|
@ -35,7 +35,7 @@ object FSMTransitionSpec {
|
|||
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" }
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import scala.concurrent.ExecutionContextExecutor
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import language.postfixOps
|
||||
|
||||
import akka.testkit._
|
||||
import scala.concurrent.duration._
|
||||
import akka.pattern.{ ask, pipe }
|
||||
import akka.testkit._
|
||||
|
||||
object ForwardActorSpec {
|
||||
val ExpectedMessage = "FOO"
|
||||
|
|
@ -29,7 +31,7 @@ object ForwardActorSpec {
|
|||
|
||||
class ForwardActorSpec extends AkkaSpec {
|
||||
import ForwardActorSpec._
|
||||
implicit val ec = system.dispatcher
|
||||
implicit val ec: ExecutionContextExecutor = system.dispatcher
|
||||
"A Forward Actor" must {
|
||||
|
||||
"forward actor reference when invoking forward on tell" in {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.testkit.ImplicitSender
|
||||
import akka.testkit.EventFilter
|
||||
import akka.actor.dungeon.SerializationCheckFailedException
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.testkit.EventFilter
|
||||
import akka.testkit.ImplicitSender
|
||||
|
||||
object FunctionRefSpec {
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ object FunctionRefSpec {
|
|||
}
|
||||
|
||||
class SupSuper extends Actor {
|
||||
val s = context.actorOf(Props[Super], "super")
|
||||
val s = context.actorOf(Props[Super](), "super")
|
||||
def receive = {
|
||||
case msg => s ! msg
|
||||
}
|
||||
|
|
@ -86,12 +86,12 @@ class FunctionRefSpec extends AkkaSpec("""
|
|||
"A FunctionRef" when {
|
||||
|
||||
"created by a toplevel actor" must {
|
||||
val s = system.actorOf(Props[Super], "super")
|
||||
val s = system.actorOf(Props[Super](), "super")
|
||||
commonTests(s)
|
||||
}
|
||||
|
||||
"created by a non-toplevel actor" must {
|
||||
val s = system.actorOf(Props[SupSuper], "supsuper")
|
||||
val s = system.actorOf(Props[SupSuper](), "supsuper")
|
||||
commonTests(s)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import language.postfixOps
|
||||
import akka.testkit._
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
import akka.util.Timeout
|
||||
import com.github.ghik.silencer.silent
|
||||
|
||||
import scala.concurrent.Future
|
||||
import scala.util.Success
|
||||
import scala.concurrent.duration._
|
||||
import scala.util.Failure
|
||||
import scala.util.Success
|
||||
|
||||
import com.github.ghik.silencer.silent
|
||||
import language.postfixOps
|
||||
|
||||
import akka.testkit._
|
||||
import akka.util.Timeout
|
||||
|
||||
object LocalActorRefProviderSpec {
|
||||
val config = """
|
||||
|
|
@ -130,7 +130,7 @@ class LocalActorRefProviderSpec extends AkkaSpec(LocalActorRefProviderSpec.confi
|
|||
|
||||
for (i <- 0 until 100) {
|
||||
val address = "new-actor" + i
|
||||
implicit val timeout = Timeout(5 seconds)
|
||||
implicit val timeout: Timeout = Timeout(5 seconds)
|
||||
val actors =
|
||||
for (_ <- 1 to 4)
|
||||
yield Future(system.actorOf(Props(new Actor { def receive = { case _ => } }), address))
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import com.github.ghik.silencer.silent
|
||||
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.util.unused
|
||||
import com.github.ghik.silencer.silent
|
||||
|
||||
object PropsCreationSpec {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
import akka.actor.ActorSystem.Settings
|
||||
import akka.actor.ActorSystem.findClassLoader
|
||||
import akka.actor.setup.ActorSystemSetup
|
||||
import akka.testkit.AbstractSpec
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
class ProviderSelectionSpec extends AbstractSpec {
|
||||
import ProviderSelection.{ ClusterActorRefProvider, RemoteActorRefProvider }
|
||||
|
|
|
|||
|
|
@ -4,15 +4,16 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import language.postfixOps
|
||||
import akka.testkit._
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import java.util.concurrent.TimeoutException
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import scala.concurrent.Await
|
||||
import java.util.concurrent.TimeoutException
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import language.postfixOps
|
||||
|
||||
import akka.testkit._
|
||||
|
||||
object ReceiveTimeoutSpec {
|
||||
case object Tick
|
||||
|
|
@ -66,7 +67,7 @@ class ReceiveTimeoutSpec extends AkkaSpec() {
|
|||
context.setReceiveTimeout(500 milliseconds)
|
||||
|
||||
def receive = {
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
case ReceiveTimeout => timeoutLatch.open()
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -82,7 +83,7 @@ class ReceiveTimeoutSpec extends AkkaSpec() {
|
|||
|
||||
def receive = {
|
||||
case Tick => ()
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
case ReceiveTimeout => timeoutLatch.open()
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -103,7 +104,7 @@ class ReceiveTimeoutSpec extends AkkaSpec() {
|
|||
case Tick => ()
|
||||
case ReceiveTimeout =>
|
||||
count.incrementAndGet
|
||||
timeoutLatch.open
|
||||
timeoutLatch.open()
|
||||
context.setReceiveTimeout(Duration.Undefined)
|
||||
}
|
||||
}))
|
||||
|
|
@ -120,7 +121,7 @@ class ReceiveTimeoutSpec extends AkkaSpec() {
|
|||
|
||||
val timeoutActor = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
case ReceiveTimeout => timeoutLatch.open()
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -135,7 +136,7 @@ class ReceiveTimeoutSpec extends AkkaSpec() {
|
|||
context.setReceiveTimeout(1 second)
|
||||
|
||||
def receive = {
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
case ReceiveTimeout => timeoutLatch.open()
|
||||
case TransparentTick =>
|
||||
}
|
||||
}))
|
||||
|
|
@ -179,7 +180,7 @@ class ReceiveTimeoutSpec extends AkkaSpec() {
|
|||
context.setReceiveTimeout(1 second)
|
||||
def receive: Receive = {
|
||||
case ReceiveTimeout =>
|
||||
timeoutLatch.open
|
||||
timeoutLatch.open()
|
||||
case TransparentTick =>
|
||||
count.incrementAndGet()
|
||||
}
|
||||
|
|
@ -198,7 +199,7 @@ class ReceiveTimeoutSpec extends AkkaSpec() {
|
|||
val timeoutActor = system.actorOf(Props(new Actor {
|
||||
def receive = {
|
||||
case TransparentTick => context.setReceiveTimeout(500 milliseconds)
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
case ReceiveTimeout => timeoutLatch.open()
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -216,7 +217,7 @@ class ReceiveTimeoutSpec extends AkkaSpec() {
|
|||
|
||||
def receive = {
|
||||
case TransparentTick => context.setReceiveTimeout(Duration.Inf)
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
case ReceiveTimeout => timeoutLatch.open()
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
@ -235,7 +236,7 @@ class ReceiveTimeoutSpec extends AkkaSpec() {
|
|||
|
||||
def receive: Receive = {
|
||||
case TransparentTick => context.setReceiveTimeout(Duration.Undefined)
|
||||
case ReceiveTimeout => timeoutLatch.open
|
||||
case ReceiveTimeout => timeoutLatch.open()
|
||||
}
|
||||
}))
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@
|
|||
package akka.actor
|
||||
|
||||
import java.net.URLEncoder
|
||||
|
||||
import scala.collection.immutable
|
||||
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
|
|
|
|||
|
|
@ -4,20 +4,21 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import language.postfixOps
|
||||
import java.lang.Thread.sleep
|
||||
|
||||
import scala.concurrent.Await
|
||||
import akka.testkit.TestEvent._
|
||||
import akka.testkit.EventFilter
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.github.ghik.silencer.silent
|
||||
import language.postfixOps
|
||||
|
||||
import akka.pattern.ask
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.testkit.DefaultTimeout
|
||||
import akka.testkit.EventFilter
|
||||
import akka.testkit.TestEvent._
|
||||
import akka.testkit.TestLatch
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import akka.pattern.ask
|
||||
import com.github.ghik.silencer.silent
|
||||
|
||||
@silent
|
||||
class RestartStrategySpec extends AkkaSpec with DefaultTimeout {
|
||||
|
||||
|
|
@ -116,7 +117,7 @@ class RestartStrategySpec extends AkkaSpec with DefaultTimeout {
|
|||
|
||||
def receive = {
|
||||
case Ping =>
|
||||
if (!pingLatch.isOpen) pingLatch.open else secondPingLatch.open
|
||||
if (!pingLatch.isOpen) pingLatch.open() else secondPingLatch.open()
|
||||
case Crash => throw new Exception("Crashing...")
|
||||
}
|
||||
override def postRestart(reason: Throwable) = {
|
||||
|
|
|
|||
|
|
@ -4,24 +4,24 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import language.postfixOps
|
||||
import java.io.Closeable
|
||||
import java.util.concurrent._
|
||||
import atomic.{ AtomicInteger, AtomicReference }
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
import scala.concurrent.{ Await, ExecutionContext, Future }
|
||||
import scala.concurrent.duration._
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
import scala.util.Try
|
||||
import scala.util.control.NoStackTrace
|
||||
import scala.util.control.NonFatal
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
|
||||
import atomic.{ AtomicInteger, AtomicReference }
|
||||
import com.github.ghik.silencer.silent
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
import language.postfixOps
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
|
||||
import akka.pattern.ask
|
||||
import akka.testkit._
|
||||
import com.github.ghik.silencer.silent
|
||||
|
||||
import scala.util.control.NoStackTrace
|
||||
|
||||
object SchedulerSpec {
|
||||
val testConfRevolver =
|
||||
|
|
@ -330,7 +330,7 @@ trait SchedulerSpec extends BeforeAndAfterEach with DefaultTimeout with Implicit
|
|||
case Crash => throw new Exception("CRASH")
|
||||
}
|
||||
|
||||
override def postRestart(reason: Throwable) = restartLatch.open
|
||||
override def postRestart(reason: Throwable) = restartLatch.open()
|
||||
})
|
||||
val actor = Await.result((supervisor ? props).mapTo[ActorRef], timeout.duration)
|
||||
|
||||
|
|
@ -496,7 +496,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
|
||||
"execute multiple jobs at once when expiring multiple buckets" taggedAs TimingTest in {
|
||||
withScheduler() { (sched, driver) =>
|
||||
implicit def ec = localEC
|
||||
implicit def ec: ExecutionContext = localEC
|
||||
import driver._
|
||||
val start = step / 2
|
||||
(0 to 3).foreach(i => sched.scheduleOnce(start + step * i, testActor, "hello"))
|
||||
|
|
@ -511,7 +511,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
|
||||
"properly defer jobs even when the timer thread oversleeps" taggedAs TimingTest in {
|
||||
withScheduler() { (sched, driver) =>
|
||||
implicit def ec = localEC
|
||||
implicit def ec: ExecutionContext = localEC
|
||||
import driver._
|
||||
sched.scheduleOnce(step * 3, probe.ref, "hello")
|
||||
wakeUp(step * 5)
|
||||
|
|
@ -526,7 +526,7 @@ 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) =>
|
||||
implicit def ec = localEC
|
||||
implicit def ec: ExecutionContext = localEC
|
||||
import driver._
|
||||
val start = step / 2
|
||||
(0 to 3).foreach(i => sched.scheduleOnce(start + step * i, probe.ref, "hello"))
|
||||
|
|
@ -553,7 +553,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
|
||||
"correctly execute jobs when clock wraps around" taggedAs TimingTest in {
|
||||
withScheduler(Long.MaxValue - 200000000L) { (sched, driver) =>
|
||||
implicit def ec = localEC
|
||||
implicit def ec: ExecutionContext = localEC
|
||||
import driver._
|
||||
val start = step / 2
|
||||
(0 to 3).foreach(i => sched.scheduleOnce(start + step * i, testActor, "hello"))
|
||||
|
|
@ -583,7 +583,7 @@ class LightArrayRevolverSchedulerSpec extends AkkaSpec(SchedulerSpec.testConfRev
|
|||
val targetTicks = Int.MaxValue - numEvents + 20
|
||||
|
||||
withScheduler(_startTick = Int.MaxValue - 100) { (sched, driver) =>
|
||||
implicit def ec = localEC
|
||||
implicit def ec: ExecutionContext = localEC
|
||||
import driver._
|
||||
|
||||
val start = step / 2
|
||||
|
|
|
|||
|
|
@ -4,31 +4,31 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import language.postfixOps
|
||||
import java.lang.System.identityHashCode
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.concurrent.{ CountDownLatch, TimeUnit }
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
import scala.util.Random
|
||||
import scala.util.control.NoStackTrace
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
|
||||
import SupervisorStrategy.{ Directive, Restart, Resume, Stop }
|
||||
import com.github.ghik.silencer.silent
|
||||
import com.typesafe.config.{ Config, ConfigFactory }
|
||||
import language.postfixOps
|
||||
|
||||
import akka.actor.SupervisorStrategy.seqThrowable2Decider
|
||||
import akka.dispatch.{ Dispatcher, DispatcherConfigurator, DispatcherPrerequisites, MessageDispatcher }
|
||||
import akka.event.Logging
|
||||
import akka.pattern.ask
|
||||
import akka.testkit.{ AkkaSpec, DefaultTimeout, EventFilter, ImplicitSender }
|
||||
import akka.testkit.{ filterEvents, filterException, TestDuration, TestLatch }
|
||||
import akka.testkit.TestEvent.Mute
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
import akka.event.Logging
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import java.lang.System.identityHashCode
|
||||
|
||||
import akka.util.Helpers.ConfigOps
|
||||
import akka.testkit.LongRunningTest
|
||||
import com.github.ghik.silencer.silent
|
||||
import akka.testkit.TestEvent.Mute
|
||||
import akka.util.Helpers.ConfigOps
|
||||
|
||||
object SupervisorHierarchySpec {
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ object SupervisorHierarchySpec {
|
|||
class Resumer extends Actor {
|
||||
override def supervisorStrategy = OneForOneStrategy() { case _ => SupervisorStrategy.Resume }
|
||||
def receive = {
|
||||
case "spawn" => sender() ! context.actorOf(Props[Resumer])
|
||||
case "spawn" => sender() ! context.actorOf(Props[Resumer]())
|
||||
case "fail" => throw new Exception("expected")
|
||||
case "ping" => sender() ! "pong"
|
||||
}
|
||||
|
|
@ -294,7 +294,7 @@ object SupervisorHierarchySpec {
|
|||
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 "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) =>
|
||||
|
|
@ -432,7 +432,7 @@ object SupervisorHierarchySpec {
|
|||
var idleChildren = Vector.empty[ActorRef]
|
||||
var pingChildren = Set.empty[ActorRef]
|
||||
|
||||
val nextJob = Iterator.continually(random.nextFloat match {
|
||||
val nextJob = Iterator.continually(random.nextFloat() match {
|
||||
case x if x >= 0.5 =>
|
||||
// ping one child
|
||||
val pick = ((x - 0.5) * 2 * idleChildren.size).toInt
|
||||
|
|
@ -479,7 +479,7 @@ object SupervisorHierarchySpec {
|
|||
} else {
|
||||
children :+= ref
|
||||
if (children.size == size) goto(Stress)
|
||||
else stay
|
||||
else stay()
|
||||
}
|
||||
case Event(StateTimeout, _) =>
|
||||
testActor ! "did not get children list"
|
||||
|
|
@ -497,7 +497,7 @@ object SupervisorHierarchySpec {
|
|||
|
||||
val workSchedule = 50.millis
|
||||
|
||||
private def random012: Int = random.nextFloat match {
|
||||
private def random012: Int = random.nextFloat() match {
|
||||
case x if x > 0.1 => 0
|
||||
case x if x > 0.03 => 1
|
||||
case _ => 2
|
||||
|
|
@ -516,9 +516,9 @@ object SupervisorHierarchySpec {
|
|||
when(Stress) {
|
||||
case Event(Work, _) if idleChildren.isEmpty =>
|
||||
context.system.scheduler.scheduleOnce(workSchedule, self, Work)(context.dispatcher)
|
||||
stay
|
||||
stay()
|
||||
case Event(Work, x) if x > 0 =>
|
||||
nextJob.next match {
|
||||
nextJob.next() match {
|
||||
case Ping(ref) => ref ! "ping"
|
||||
case Fail(ref, dir) =>
|
||||
val f = Failure(
|
||||
|
|
@ -537,15 +537,15 @@ object SupervisorHierarchySpec {
|
|||
}
|
||||
if (idleChildren.nonEmpty) self ! Work
|
||||
else context.system.scheduler.scheduleOnce(workSchedule, self, Work)(context.dispatcher)
|
||||
stay.using(x - 1)
|
||||
stay().using(x - 1)
|
||||
case Event(Work, _) => if (pingChildren.isEmpty) goto(LastPing) else goto(Finishing)
|
||||
case Event(Died(path), _) =>
|
||||
bury(path)
|
||||
stay
|
||||
stay()
|
||||
case Event("pong", _) =>
|
||||
pingChildren -= sender()
|
||||
idleChildren :+= sender()
|
||||
stay
|
||||
stay()
|
||||
case Event(StateTimeout, todo) =>
|
||||
log.info("dumping state due to StateTimeout")
|
||||
log.info(
|
||||
|
|
@ -566,10 +566,10 @@ object SupervisorHierarchySpec {
|
|||
case Event("pong", _) =>
|
||||
pingChildren -= sender()
|
||||
idleChildren :+= sender()
|
||||
if (pingChildren.isEmpty) goto(LastPing) else stay
|
||||
if (pingChildren.isEmpty) goto(LastPing) else stay()
|
||||
case Event(Died(ref), _) =>
|
||||
bury(ref)
|
||||
if (pingChildren.isEmpty) goto(LastPing) else stay
|
||||
if (pingChildren.isEmpty) goto(LastPing) else stay()
|
||||
}
|
||||
|
||||
onTransition {
|
||||
|
|
@ -583,10 +583,10 @@ object SupervisorHierarchySpec {
|
|||
case Event("pong", _) =>
|
||||
pingChildren -= sender()
|
||||
idleChildren :+= sender()
|
||||
if (pingChildren.isEmpty) goto(Stopping) else stay
|
||||
if (pingChildren.isEmpty) goto(Stopping) else stay()
|
||||
case Event(Died(ref), _) =>
|
||||
bury(ref)
|
||||
if (pingChildren.isEmpty) goto(Stopping) else stay
|
||||
if (pingChildren.isEmpty) goto(Stopping) else stay()
|
||||
}
|
||||
|
||||
onTransition {
|
||||
|
|
@ -596,14 +596,14 @@ object SupervisorHierarchySpec {
|
|||
}
|
||||
|
||||
when(Stopping, stateTimeout = 5.seconds.dilated) {
|
||||
case Event(PongOfDeath, _) => stay
|
||||
case Event(PongOfDeath, _) => stay()
|
||||
case Event(Terminated(r), _) if r == hierarchy =>
|
||||
@silent
|
||||
val undead = children.filterNot(_.isTerminated)
|
||||
if (undead.nonEmpty) {
|
||||
log.info("undead:\n" + undead.mkString("\n"))
|
||||
testActor ! "stressTestFailed (" + undead.size + " undead)"
|
||||
stop
|
||||
stop()
|
||||
} else if (false) {
|
||||
/*
|
||||
* This part of the test is normally disabled, because it does not
|
||||
|
|
@ -621,7 +621,7 @@ object SupervisorHierarchySpec {
|
|||
goto(GC)
|
||||
} else {
|
||||
testActor ! "stressTestSuccessful"
|
||||
stop
|
||||
stop()
|
||||
}
|
||||
case Event(StateTimeout, _) =>
|
||||
errors :+= self -> ErrorLog("timeout while Stopping", Vector.empty)
|
||||
|
|
@ -630,7 +630,7 @@ object SupervisorHierarchySpec {
|
|||
printErrors()
|
||||
idleChildren.foreach(println)
|
||||
testActor ! "timeout in Stopping"
|
||||
stop
|
||||
stop()
|
||||
case Event(e: ErrorLog, _) =>
|
||||
errors :+= sender() -> e
|
||||
goto(Failed)
|
||||
|
|
@ -642,14 +642,14 @@ object SupervisorHierarchySpec {
|
|||
if (next.nonEmpty) {
|
||||
context.system.scheduler.scheduleOnce(workSchedule, self, GCcheck(next))(context.dispatcher)
|
||||
System.gc()
|
||||
stay
|
||||
stay()
|
||||
} else {
|
||||
testActor ! "stressTestSuccessful"
|
||||
stop
|
||||
stop()
|
||||
}
|
||||
case Event(StateTimeout, _) =>
|
||||
testActor ! "timeout in GC"
|
||||
stop
|
||||
stop()
|
||||
}
|
||||
|
||||
var errors = Vector.empty[(ActorRef, ErrorLog)]
|
||||
|
|
@ -658,19 +658,19 @@ object SupervisorHierarchySpec {
|
|||
case Event(e: ErrorLog, _) =>
|
||||
if (!e.msg.startsWith("not resumed") || !ignoreNotResumedLogs)
|
||||
errors :+= sender() -> e
|
||||
stay
|
||||
stay()
|
||||
case Event(Terminated(r), _) if r == hierarchy =>
|
||||
printErrors()
|
||||
testActor ! "stressTestFailed"
|
||||
stop
|
||||
stop()
|
||||
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
|
||||
stop()
|
||||
case Event("pong", _) => stay() // don’t care?
|
||||
case Event(Work, _) => stay()
|
||||
case Event(Died(_), _) => stay()
|
||||
}
|
||||
|
||||
def getErrors(target: ActorRef, depth: Int): Unit = {
|
||||
|
|
@ -716,9 +716,9 @@ object SupervisorHierarchySpec {
|
|||
activeChildren :+= ref
|
||||
children :+= ref
|
||||
idleChildren :+= ref
|
||||
stay
|
||||
stay()
|
||||
case Event(e: ErrorLog, _) =>
|
||||
if (e.msg.startsWith("not resumed")) stay
|
||||
if (e.msg.startsWith("not resumed")) stay()
|
||||
else {
|
||||
errors :+= sender() -> e
|
||||
// don’t stop the hierarchy, that is going to happen all by itself and in the right order
|
||||
|
|
@ -737,7 +737,7 @@ object SupervisorHierarchySpec {
|
|||
goto(Failed)
|
||||
case Event(msg, _) =>
|
||||
testActor ! ("received unexpected msg: " + msg)
|
||||
stop
|
||||
stop()
|
||||
}
|
||||
|
||||
initialize()
|
||||
|
|
@ -801,7 +801,7 @@ class SupervisorHierarchySpec extends AkkaSpec(SupervisorHierarchySpec.config) w
|
|||
}
|
||||
|
||||
"resume children after Resume" taggedAs LongRunningTest in {
|
||||
val boss = system.actorOf(Props[Resumer], "resumer")
|
||||
val boss = system.actorOf(Props[Resumer](), "resumer")
|
||||
boss ! "spawn"
|
||||
val middle = expectMsgType[ActorRef]
|
||||
middle ! "spawn"
|
||||
|
|
@ -824,7 +824,7 @@ class SupervisorHierarchySpec extends AkkaSpec(SupervisorHierarchySpec.config) w
|
|||
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"
|
||||
|
|
|
|||
|
|
@ -4,20 +4,20 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import language.postfixOps
|
||||
import akka.testkit.{ filterEvents, EventFilter }
|
||||
|
||||
import scala.concurrent.Await
|
||||
import java.util.concurrent.{ CountDownLatch, TimeUnit }
|
||||
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.testkit.DefaultTimeout
|
||||
import akka.pattern.ask
|
||||
import com.github.ghik.silencer.silent
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
import scala.util.control.NonFatal
|
||||
|
||||
import com.github.ghik.silencer.silent
|
||||
import language.postfixOps
|
||||
|
||||
import akka.pattern.ask
|
||||
import akka.testkit.{ filterEvents, EventFilter }
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.testkit.DefaultTimeout
|
||||
|
||||
object SupervisorMiscSpec {
|
||||
val config = """
|
||||
pinned-dispatcher {
|
||||
|
|
|
|||
|
|
@ -4,23 +4,24 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import language.postfixOps
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import akka.{ Die, Ping }
|
||||
import akka.testkit.TestEvent._
|
||||
import akka.testkit._
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import scala.concurrent.Await
|
||||
import akka.pattern.ask
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import language.postfixOps
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
|
||||
import akka.{ Die, Ping }
|
||||
import akka.ConfigurationException
|
||||
import akka.dispatch.MailboxType
|
||||
import akka.dispatch.MessageQueue
|
||||
import com.typesafe.config.Config
|
||||
import akka.ConfigurationException
|
||||
import akka.pattern.ask
|
||||
import akka.routing.RoundRobinPool
|
||||
import akka.testkit._
|
||||
import akka.testkit.TestEvent._
|
||||
import akka.util.unused
|
||||
|
||||
object SupervisorSpec {
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import language.postfixOps
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
import akka.testkit.{ AkkaSpec, DefaultTimeout, EventFilter, ImplicitSender }
|
||||
|
||||
import language.postfixOps
|
||||
|
||||
import akka.pattern.ask
|
||||
import akka.testkit.{ AkkaSpec, DefaultTimeout, EventFilter, ImplicitSender }
|
||||
|
||||
class SupervisorTreeSpec extends AkkaSpec with ImplicitSender with DefaultTimeout {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,16 +4,17 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import language.postfixOps
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import language.postfixOps
|
||||
import org.scalatest.BeforeAndAfterAll
|
||||
|
||||
import akka.pattern.ask
|
||||
import akka.testkit.{ filterEvents, EventFilter }
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.testkit.ImplicitSender
|
||||
import akka.testkit.DefaultTimeout
|
||||
import scala.concurrent.Await
|
||||
import akka.pattern.ask
|
||||
import scala.concurrent.duration._
|
||||
import akka.testkit.ImplicitSender
|
||||
|
||||
class Ticket669Spec extends AkkaSpec with BeforeAndAfterAll with ImplicitSender with DefaultTimeout {
|
||||
import Ticket669Spec._
|
||||
|
|
@ -28,7 +29,7 @@ class Ticket669Spec extends AkkaSpec with BeforeAndAfterAll with ImplicitSender
|
|||
filterEvents(EventFilter[Exception]("test", occurrences = 1)) {
|
||||
val supervisor =
|
||||
system.actorOf(Props(new Supervisor(AllForOneStrategy(5, 10 seconds)(List(classOf[Exception])))))
|
||||
val supervised = Await.result((supervisor ? Props[Supervised]).mapTo[ActorRef], timeout.duration)
|
||||
val supervised = Await.result((supervisor ? Props[Supervised]()).mapTo[ActorRef], timeout.duration)
|
||||
|
||||
supervised.!("test")(testActor)
|
||||
expectMsg("failure1")
|
||||
|
|
@ -40,7 +41,7 @@ class Ticket669Spec extends AkkaSpec with BeforeAndAfterAll with ImplicitSender
|
|||
filterEvents(EventFilter[Exception]("test", occurrences = 1)) {
|
||||
val supervisor =
|
||||
system.actorOf(Props(new Supervisor(AllForOneStrategy(maxNrOfRetries = 0)(List(classOf[Exception])))))
|
||||
val supervised = Await.result((supervisor ? Props[Supervised]).mapTo[ActorRef], timeout.duration)
|
||||
val supervised = Await.result((supervisor ? Props[Supervised]()).mapTo[ActorRef], timeout.duration)
|
||||
|
||||
supervised.!("test")(testActor)
|
||||
expectMsg("failure2")
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@ package akka.actor
|
|||
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
import scala.util.control.NoStackTrace
|
||||
|
||||
import akka.testkit._
|
||||
import scala.concurrent.Await
|
||||
|
||||
object TimerSpec {
|
||||
sealed trait Command
|
||||
|
|
@ -108,7 +109,7 @@ object TimerSpec {
|
|||
startTimerWithFixedDelay("T", Tick(bumpCount + 1), interval)
|
||||
else
|
||||
startSingleTimer("T", Tick(bumpCount + 1), interval)
|
||||
stay.using(bumpCount + 1)
|
||||
stay().using(bumpCount + 1)
|
||||
}
|
||||
|
||||
def autoReceive(): State = {
|
||||
|
|
@ -116,7 +117,7 @@ object TimerSpec {
|
|||
startTimerWithFixedDelay("A", PoisonPill, interval)
|
||||
else
|
||||
startSingleTimer("A", PoisonPill, interval)
|
||||
stay
|
||||
stay()
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -131,7 +132,7 @@ object TimerSpec {
|
|||
when(TheState) {
|
||||
case Event(Tick(n), _) =>
|
||||
monitor ! Tock(n)
|
||||
stay
|
||||
stay()
|
||||
case Event(Bump, bumpCount) =>
|
||||
bump(bumpCount)
|
||||
case Event(SlowThenBump(latch), bumpCount) =>
|
||||
|
|
@ -141,7 +142,7 @@ object TimerSpec {
|
|||
stop()
|
||||
case Event(Cancel, _) =>
|
||||
cancelTimer("T")
|
||||
stay
|
||||
stay()
|
||||
case Event(Throw(e), _) =>
|
||||
throw e
|
||||
case Event(SlowThenThrow(latch, e), _) =>
|
||||
|
|
|
|||
|
|
@ -4,8 +4,17 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import java.util.concurrent.{ CountDownLatch, TimeUnit, TimeoutException }
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.immutable
|
||||
import scala.concurrent.{ Await, Future }
|
||||
import scala.concurrent.duration._
|
||||
import scala.language.postfixOps
|
||||
|
||||
import com.github.ghik.silencer.silent
|
||||
import org.scalatest.{ BeforeAndAfterAll, BeforeAndAfterEach }
|
||||
|
||||
import akka.actor.TypedActor._
|
||||
import akka.japi.{ Option => JOption }
|
||||
|
|
@ -14,14 +23,6 @@ import akka.routing.RoundRobinGroup
|
|||
import akka.serialization.{ JavaSerializer, SerializerWithStringManifest }
|
||||
import akka.testkit.{ filterEvents, AkkaSpec, DefaultTimeout, EventFilter, TimingTest }
|
||||
import akka.util.Timeout
|
||||
import com.github.ghik.silencer.silent
|
||||
import org.scalatest.{ BeforeAndAfterAll, BeforeAndAfterEach }
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.immutable
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.{ Await, Future }
|
||||
import scala.language.postfixOps
|
||||
|
||||
object TypedActorSpec {
|
||||
|
||||
|
|
@ -123,11 +124,11 @@ object TypedActorSpec {
|
|||
|
||||
def pigdog = "Pigdog"
|
||||
|
||||
def futurePigdog(): Future[String] = Future.successful(pigdog)
|
||||
def futurePigdog(): Future[String] = Future.successful(pigdog())
|
||||
|
||||
def futurePigdog(delay: FiniteDuration): Future[String] = {
|
||||
Thread.sleep(delay.toMillis)
|
||||
futurePigdog
|
||||
futurePigdog()
|
||||
}
|
||||
|
||||
def futurePigdog(delay: FiniteDuration, numbered: Int): Future[String] = {
|
||||
|
|
@ -140,16 +141,16 @@ object TypedActorSpec {
|
|||
foo.futurePigdog(500 millis).map(_.toUpperCase)
|
||||
}
|
||||
|
||||
def optionPigdog(): Option[String] = Some(pigdog)
|
||||
def optionPigdog(): Option[String] = Some(pigdog())
|
||||
|
||||
def optionPigdog(delay: FiniteDuration): Option[String] = {
|
||||
Thread.sleep(delay.toMillis)
|
||||
Some(pigdog)
|
||||
Some(pigdog())
|
||||
}
|
||||
|
||||
def joptionPigdog(delay: FiniteDuration): JOption[String] = {
|
||||
Thread.sleep(delay.toMillis)
|
||||
JOption.some(pigdog)
|
||||
JOption.some(pigdog())
|
||||
}
|
||||
|
||||
var internalNumber = 0
|
||||
|
|
@ -408,14 +409,14 @@ class TypedActorSpec
|
|||
t.failingPigdog()
|
||||
t.read() should ===(1) //Make sure state is not reset after failure
|
||||
|
||||
intercept[IllegalStateException] { Await.result(t.failingFuturePigdog, 2 seconds) }.getMessage should ===(
|
||||
intercept[IllegalStateException] { Await.result(t.failingFuturePigdog(), 2 seconds) }.getMessage should ===(
|
||||
"expected")
|
||||
t.read() should ===(1) //Make sure state is not reset after failure
|
||||
|
||||
intercept[IllegalStateException] { t.failingJOptionPigdog }.getMessage should ===("expected")
|
||||
intercept[IllegalStateException] { t.failingJOptionPigdog() }.getMessage should ===("expected")
|
||||
t.read() should ===(1) //Make sure state is not reset after failure
|
||||
|
||||
intercept[IllegalStateException] { t.failingOptionPigdog }.getMessage should ===("expected")
|
||||
intercept[IllegalStateException] { t.failingOptionPigdog() }.getMessage should ===("expected")
|
||||
|
||||
t.read() should ===(1) //Make sure state is not reset after failure
|
||||
|
||||
|
|
@ -466,7 +467,7 @@ class TypedActorSpec
|
|||
val thais = for (_ <- 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)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import akka.testkit.{ AkkaSpec, TestProbe }
|
||||
import scala.util.control.NoStackTrace
|
||||
|
||||
import akka.actor.SupervisorStrategy.{ Restart, Stop }
|
||||
import akka.dispatch.sysmsg.SystemMessage
|
||||
import akka.event.EventStream
|
||||
import scala.util.control.NoStackTrace
|
||||
import akka.testkit.{ AkkaSpec, TestProbe }
|
||||
|
||||
object UidClashTest {
|
||||
|
||||
|
|
@ -76,7 +77,7 @@ object UidClashTest {
|
|||
Stop
|
||||
case _ => Restart
|
||||
}
|
||||
val theRestartedOne = context.actorOf(Props[RestartedActor], "theRestartedOne")
|
||||
val theRestartedOne = context.actorOf(Props[RestartedActor](), "theRestartedOne")
|
||||
|
||||
def receive = {
|
||||
case PleaseRestart => theRestartedOne ! PleaseRestart
|
||||
|
|
|
|||
|
|
@ -4,25 +4,26 @@
|
|||
|
||||
package akka.actor.dispatch
|
||||
|
||||
import language.postfixOps
|
||||
import java.rmi.RemoteException
|
||||
import java.util.concurrent.{ ConcurrentHashMap, CountDownLatch, TimeUnit }
|
||||
import java.util.concurrent.atomic.{ AtomicInteger, AtomicLong }
|
||||
|
||||
import org.scalatest.Assertions._
|
||||
import scala.annotation.tailrec
|
||||
import scala.concurrent.{ Await, Future }
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.github.ghik.silencer.silent
|
||||
import com.typesafe.config.Config
|
||||
import language.postfixOps
|
||||
import org.scalatest.Assertions._
|
||||
|
||||
import akka.actor._
|
||||
import akka.dispatch.sysmsg.SystemMessageList
|
||||
import akka.dispatch._
|
||||
import akka.dispatch.sysmsg.SystemMessageList
|
||||
import akka.event.Logging.Error
|
||||
import akka.pattern.ask
|
||||
import akka.testkit._
|
||||
import akka.util.Switch
|
||||
import com.github.ghik.silencer.silent
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent.{ Await, Future }
|
||||
import scala.annotation.tailrec
|
||||
|
||||
object ActorModelSpec {
|
||||
|
||||
|
|
@ -257,7 +258,7 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
|
||||
import ActorModelSpec._
|
||||
|
||||
def newTestActor(dispatcher: String) = system.actorOf(Props[DispatcherActor].withDispatcher(dispatcher))
|
||||
def newTestActor(dispatcher: String) = system.actorOf(Props[DispatcherActor]().withDispatcher(dispatcher))
|
||||
|
||||
def awaitStarted(ref: ActorRef): Unit = {
|
||||
awaitCond(ref match {
|
||||
|
|
@ -352,7 +353,7 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
val a = newTestActor(dispatcher.id).asInstanceOf[InternalActorRef]
|
||||
awaitStarted(a)
|
||||
val done = new CountDownLatch(1)
|
||||
a.suspend
|
||||
a.suspend()
|
||||
a ! CountDown(done)
|
||||
assertNoCountDown(done, 1000, "Should not process messages while suspended")
|
||||
assertRefDefaultZero(a)(registers = 1, msgsReceived = 1, suspensions = 1)
|
||||
|
|
@ -373,7 +374,7 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
|
||||
"handle waves of actors" in {
|
||||
val dispatcher = interceptedDispatcher()
|
||||
val props = Props[DispatcherActor].withDispatcher(dispatcher.id)
|
||||
val props = Props[DispatcherActor]().withDispatcher(dispatcher.id)
|
||||
|
||||
def flood(num: Int): Unit = {
|
||||
val cachedMessage = CountDownNStop(new CountDownLatch(num))
|
||||
|
|
@ -417,7 +418,7 @@ abstract class ActorModelSpec(config: String) extends AkkaSpec(config) with Defa
|
|||
}
|
||||
|
||||
System.err.println("Mailbox: " + mq.numberOfMessages + " " + mq.hasMessages)
|
||||
Iterator.continually(mq.dequeue).takeWhile(_ ne null).foreach(System.err.println)
|
||||
Iterator.continually(mq.dequeue()).takeWhile(_ ne null).foreach(System.err.println)
|
||||
case _ =>
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,16 +4,18 @@
|
|||
|
||||
package akka.actor.dispatch
|
||||
|
||||
import language.postfixOps
|
||||
|
||||
import java.util.concurrent.{ CountDownLatch, TimeUnit }
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.actor.{ Actor, Props }
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
import akka.testkit.DefaultTimeout
|
||||
|
||||
import language.postfixOps
|
||||
|
||||
import akka.actor.{ Actor, Props }
|
||||
import akka.pattern.ask
|
||||
import akka.testkit.AkkaSpec
|
||||
import akka.testkit.DefaultTimeout
|
||||
|
||||
object DispatcherActorSpec {
|
||||
val config = """
|
||||
|
|
@ -59,14 +61,14 @@ class DispatcherActorSpec extends AkkaSpec(DispatcherActorSpec.config) with Defa
|
|||
"A Dispatcher and an Actor" must {
|
||||
|
||||
"support tell" in {
|
||||
val actor = system.actorOf(Props[OneWayTestActor].withDispatcher("test-dispatcher"))
|
||||
val actor = system.actorOf(Props[OneWayTestActor]().withDispatcher("test-dispatcher"))
|
||||
actor ! "OneWay"
|
||||
assert(OneWayTestActor.oneWay.await(1, TimeUnit.SECONDS))
|
||||
system.stop(actor)
|
||||
}
|
||||
|
||||
"support ask/reply" in {
|
||||
val actor = system.actorOf(Props[TestActor].withDispatcher("test-dispatcher"))
|
||||
val actor = system.actorOf(Props[TestActor]().withDispatcher("test-dispatcher"))
|
||||
assert("World" === Await.result(actor ? "Hello", timeout.duration))
|
||||
system.stop(actor)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
package akka.actor.dispatch
|
||||
|
||||
import java.util.concurrent.CountDownLatch
|
||||
|
||||
import akka.actor._
|
||||
import akka.testkit.AkkaSpec
|
||||
|
||||
|
|
|
|||
|
|
@ -4,17 +4,19 @@
|
|||
|
||||
package akka.actor.dispatch
|
||||
|
||||
import scala.reflect.ClassTag
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import akka.ConfigurationException
|
||||
import akka.actor._
|
||||
import akka.dispatch._
|
||||
import akka.testkit.{ AkkaSpec, ImplicitSender }
|
||||
import akka.routing.FromConfig
|
||||
import java.util.concurrent.ConcurrentLinkedQueue
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
import scala.reflect.ClassTag
|
||||
|
||||
import com.typesafe.config.Config
|
||||
import com.typesafe.config.ConfigFactory
|
||||
|
||||
import akka.ConfigurationException
|
||||
import akka.actor._
|
||||
import akka.dispatch._
|
||||
import akka.routing.FromConfig
|
||||
import akka.testkit.{ AkkaSpec, ImplicitSender }
|
||||
import akka.util.unused
|
||||
|
||||
object DispatchersSpec {
|
||||
|
|
@ -182,11 +184,11 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
}
|
||||
|
||||
"include system name and dispatcher id in thread names for fork-join-executor" in {
|
||||
assertMyDispatcherIsUsed(system.actorOf(Props[ThreadNameEcho].withDispatcher("myapp.mydispatcher")))
|
||||
assertMyDispatcherIsUsed(system.actorOf(Props[ThreadNameEcho]().withDispatcher("myapp.mydispatcher")))
|
||||
}
|
||||
|
||||
"include system name and dispatcher id in thread names for thread-pool-executor" in {
|
||||
system.actorOf(Props[ThreadNameEcho].withDispatcher("myapp.thread-pool-dispatcher")) ! "what's the name?"
|
||||
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(_) =>
|
||||
|
|
@ -194,7 +196,7 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
}
|
||||
|
||||
"include system name and dispatcher id in thread names for default-dispatcher" in {
|
||||
system.actorOf(Props[ThreadNameEcho]) ! "what's the name?"
|
||||
system.actorOf(Props[ThreadNameEcho]()) ! "what's the name?"
|
||||
val Expected = R("(DispatchersSpec-akka.actor.default-dispatcher-[1-9][0-9]*)")
|
||||
expectMsgPF() {
|
||||
case Expected(_) =>
|
||||
|
|
@ -202,7 +204,7 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
}
|
||||
|
||||
"include system name and dispatcher id in thread names for pinned dispatcher" in {
|
||||
system.actorOf(Props[ThreadNameEcho].withDispatcher("myapp.my-pinned-dispatcher")) ! "what's the name?"
|
||||
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(_) =>
|
||||
|
|
@ -210,7 +212,7 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
}
|
||||
|
||||
"include system name and dispatcher id in thread names for balancing dispatcher" in {
|
||||
system.actorOf(Props[ThreadNameEcho].withDispatcher("myapp.balancing-dispatcher")) ! "what's the name?"
|
||||
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(_) =>
|
||||
|
|
@ -218,16 +220,16 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
}
|
||||
|
||||
"use dispatcher in deployment config" in {
|
||||
assertMyDispatcherIsUsed(system.actorOf(Props[ThreadNameEcho], name = "echo1"))
|
||||
assertMyDispatcherIsUsed(system.actorOf(Props[ThreadNameEcho](), name = "echo1"))
|
||||
}
|
||||
|
||||
"use dispatcher in deployment config, trumps code" in {
|
||||
assertMyDispatcherIsUsed(
|
||||
system.actorOf(Props[ThreadNameEcho].withDispatcher("myapp.my-pinned-dispatcher"), name = "echo2"))
|
||||
system.actorOf(Props[ThreadNameEcho]().withDispatcher("myapp.my-pinned-dispatcher"), name = "echo2"))
|
||||
}
|
||||
|
||||
"use pool-dispatcher router of deployment config" in {
|
||||
val pool = system.actorOf(FromConfig.props(Props[ThreadNameEcho]), name = "pool1")
|
||||
val pool = system.actorOf(FromConfig.props(Props[ThreadNameEcho]()), name = "pool1")
|
||||
pool ! Identify(None)
|
||||
val routee = expectMsgType[ActorIdentity].ref.get
|
||||
routee ! "what's the name?"
|
||||
|
|
@ -238,7 +240,7 @@ class DispatchersSpec extends AkkaSpec(DispatchersSpec.config) with ImplicitSend
|
|||
}
|
||||
|
||||
"use balancing-pool router with special routees mailbox of deployment config" in {
|
||||
system.actorOf(FromConfig.props(Props[ThreadNameEcho]), name = "balanced") ! "what's the name?"
|
||||
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(_) =>
|
||||
|
|
|
|||
|
|
@ -6,12 +6,14 @@ package akka.actor.dispatch
|
|||
|
||||
import java.util.concurrent.{ CountDownLatch, TimeUnit }
|
||||
|
||||
import akka.testkit._
|
||||
import akka.actor.{ Actor, Props }
|
||||
import akka.testkit.AkkaSpec
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
import scala.concurrent.Await
|
||||
|
||||
import org.scalatest.BeforeAndAfterEach
|
||||
|
||||
import akka.actor.{ Actor, Props }
|
||||
import akka.pattern.ask
|
||||
import akka.testkit._
|
||||
import akka.testkit.AkkaSpec
|
||||
|
||||
object PinnedActorSpec {
|
||||
val config = """
|
||||
|
|
@ -44,7 +46,7 @@ class PinnedActorSpec extends AkkaSpec(PinnedActorSpec.config) with BeforeAndAft
|
|||
}
|
||||
|
||||
"support ask/reply" in {
|
||||
val actor = system.actorOf(Props[TestActor].withDispatcher("pinned-dispatcher"))
|
||||
val actor = system.actorOf(Props[TestActor]().withDispatcher("pinned-dispatcher"))
|
||||
assert("World" === Await.result(actor ? "Hello", timeout.duration))
|
||||
system.stop(actor)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ package akka.actor.dungeon
|
|||
|
||||
import akka.actor.Actor
|
||||
import akka.actor.Props
|
||||
|
||||
import akka.testkit._
|
||||
|
||||
object DispatchSpec {
|
||||
|
|
@ -25,7 +24,7 @@ class DispatchSpec extends AkkaSpec("""
|
|||
|
||||
"The dispatcher" should {
|
||||
"log an appropriate message when akka.actor.serialize-messages triggers a serialization error" in {
|
||||
val actor = system.actorOf(Props[EmptyActor])
|
||||
val actor = system.actorOf(Props[EmptyActor]())
|
||||
EventFilter[Exception](pattern = ".*NoSerializationVerificationNeeded.*", occurrences = 1).intercept {
|
||||
actor ! new UnserializableMessageClass
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@
|
|||
|
||||
package akka.actor.routing
|
||||
|
||||
import akka.testkit._
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import scala.concurrent.Await
|
||||
|
||||
import akka.actor._
|
||||
import akka.routing._
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import scala.concurrent.Await
|
||||
import akka.testkit._
|
||||
|
||||
class ListenerSpec extends AkkaSpec {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,12 @@
|
|||
|
||||
package akka.actor.setup
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.testkit.TestKit
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.testkit.TestKit
|
||||
|
||||
case class DummySetup(name: String) extends Setup
|
||||
case class DummySetup2(name: String) extends Setup
|
||||
case class DummySetup3(name: String) extends Setup
|
||||
|
|
|
|||
|
|
@ -6,15 +6,16 @@ package akka.config
|
|||
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.scalatest.Assertions
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.actor.ExtendedActorSystem
|
||||
import akka.event.DefaultLoggingFilter
|
||||
import akka.event.Logging.DefaultLogger
|
||||
import akka.testkit.AkkaSpec
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.scalatest.Assertions
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import akka.actor.ExtendedActorSystem
|
||||
|
||||
class ConfigSpec extends AkkaSpec(ConfigFactory.defaultReference(ActorSystem.findClassLoader())) with Assertions {
|
||||
|
||||
|
|
|
|||
|
|
@ -4,18 +4,21 @@
|
|||
|
||||
package akka.dataflow
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.ExecutionContextExecutor
|
||||
import scala.concurrent.ExecutionException
|
||||
import scala.concurrent.Future
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import language.postfixOps
|
||||
|
||||
import akka.actor.{ Actor, Props }
|
||||
import scala.concurrent.Future
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
import akka.testkit.{ AkkaSpec, DefaultTimeout }
|
||||
import akka.actor.ActorRef
|
||||
import akka.pattern.{ ask, pipe }
|
||||
import scala.concurrent.ExecutionException
|
||||
import akka.testkit.{ AkkaSpec, DefaultTimeout }
|
||||
|
||||
class Future2ActorSpec extends AkkaSpec with DefaultTimeout {
|
||||
implicit val ec = system.dispatcher
|
||||
implicit val ec: ExecutionContextExecutor = system.dispatcher
|
||||
"The Future2Actor bridge" must {
|
||||
|
||||
"support convenient sending to multiple destinations" in {
|
||||
|
|
@ -24,7 +27,7 @@ class Future2ActorSpec extends AkkaSpec with DefaultTimeout {
|
|||
}
|
||||
|
||||
"support convenient sending to multiple destinations with implicit sender" in {
|
||||
implicit val someActor = system.actorOf(Props(new Actor { def receive = Actor.emptyBehavior }))
|
||||
implicit val someActor: ActorRef = system.actorOf(Props(new Actor { def receive = Actor.emptyBehavior }))
|
||||
Future(42).pipeTo(testActor).pipeTo(testActor)
|
||||
expectMsgAllOf(1 second, 42, 42)
|
||||
lastSender should ===(someActor)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
package akka.dispatch
|
||||
|
||||
import akka.testkit.{ AkkaSpec, DefaultTimeout }
|
||||
import akka.actor.{ Actor, Props }
|
||||
import akka.testkit.{ AkkaSpec, DefaultTimeout }
|
||||
|
||||
object ControlAwareDispatcherSpec {
|
||||
val config = """
|
||||
|
|
|
|||
|
|
@ -4,14 +4,17 @@
|
|||
|
||||
package akka.dispatch
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.testkit.TestKit
|
||||
import java.lang.management.ManagementFactory
|
||||
|
||||
import scala.concurrent.{ Await, Future }
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.testkit.TestKit
|
||||
|
||||
class DispatcherShutdownSpec extends AnyWordSpec with Matchers {
|
||||
|
||||
"akka dispatcher" should {
|
||||
|
|
|
|||
|
|
@ -6,16 +6,18 @@ package akka.dispatch
|
|||
|
||||
import java.util.concurrent.{ Executor, ExecutorService, Executors }
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import scala.concurrent.{ ExecutionContext, ExecutionContextExecutor, ExecutionContextExecutorService }
|
||||
import scala.concurrent.{ blocking, Await, Future, Promise }
|
||||
import scala.concurrent.duration._
|
||||
import akka.testkit.{ AkkaSpec, DefaultTimeout, TestLatch }
|
||||
import akka.util.SerializedSuspendableExecutionContext
|
||||
import akka.testkit.TestActorRef
|
||||
import akka.actor.Props
|
||||
|
||||
import akka.actor.Actor
|
||||
import akka.testkit.TestProbe
|
||||
import akka.actor.Props
|
||||
import akka.testkit.{ AkkaSpec, DefaultTimeout, TestLatch }
|
||||
import akka.testkit.CallingThreadDispatcher
|
||||
import akka.testkit.TestActorRef
|
||||
import akka.testkit.TestProbe
|
||||
import akka.util.SerializedSuspendableExecutionContext
|
||||
|
||||
class ExecutionContextSpec extends AkkaSpec with DefaultTimeout {
|
||||
|
||||
|
|
|
|||
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