pekko/akka-actor-tests/src/test/scala/akka/dispatch/ForkJoinPoolStarvationSpec.scala
kerr 0e4d41ad33
+build Add sort imports support. (#28780)
* Add scalafix plugin for jdk 9.
* Add command alias sortImports.
* Excludes some sources from SortImports.
* Update SortImports to 0.4.0
* Sort imports with `sortImports` command.
2020-04-27 14:32:18 +02:00

69 lines
1.8 KiB
Scala

/*
* Copyright (C) 2018-2020 Lightbend Inc. <https://www.lightbend.com>
*/
package akka.dispatch
import com.typesafe.config.ConfigFactory
import akka.actor.{ Actor, Props }
import akka.testkit.{ AkkaSpec, ImplicitSender }
object ForkJoinPoolStarvationSpec {
val config = ConfigFactory.parseString("""
|actorhang {
| task-dispatcher {
| mailbox-type = "akka.dispatch.SingleConsumerOnlyUnboundedMailbox"
| throughput = 5
| fork-join-executor {
| parallelism-factor = 2
| parallelism-max = 2
| parallelism-min = 2
| }
| }
|}
""".stripMargin)
class SelfBusyActor extends Actor {
self ! "tick"
override def receive = {
case "tick" =>
self ! "tick"
}
}
class InnocentActor extends Actor {
override def receive = {
case "ping" =>
sender ! "All fine"
}
}
}
class ForkJoinPoolStarvationSpec extends AkkaSpec(ForkJoinPoolStarvationSpec.config) with ImplicitSender {
import ForkJoinPoolStarvationSpec._
val Iterations = 1000
"AkkaForkJoinPool" must {
"not starve tasks arriving from external dispatchers under high internal traffic" in {
// Two busy actors that will occupy the threads of the dispatcher
// Since they submit to the local task queue via fork, they can starve external submissions
system.actorOf(Props(new SelfBusyActor).withDispatcher("actorhang.task-dispatcher"))
system.actorOf(Props(new SelfBusyActor).withDispatcher("actorhang.task-dispatcher"))
val innocentActor = system.actorOf(Props(new InnocentActor).withDispatcher("actorhang.task-dispatcher"))
for (_ <- 1 to Iterations) {
// External task submission via the default dispatcher
innocentActor ! "ping"
expectMsg("All fine")
}
}
}
}