本文整理汇总了Scala中akka.testkit.EventFilter类的典型用法代码示例。如果您正苦于以下问题:Scala EventFilter类的具体用法?Scala EventFilter怎么用?Scala EventFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventFilter类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: SnapshotDirectoryFailureSpec
//设置package包名称以及导入依赖的类
package akka.persistence
import akka.testkit.{ ImplicitSender, EventFilter, TestEvent, AkkaSpec }
import java.io.{ IOException, File }
import akka.actor.{ ActorInitializationException, Props, ActorRef }
object SnapshotDirectoryFailureSpec {
val inUseSnapshotPath = "target/inUseSnapshotPath"
class TestProcessor(name: String, probe: ActorRef) extends Processor {
override def persistenceId: String = name
override def preStart(): Unit = ()
def receive = {
case s: String ? saveSnapshot(s)
case SaveSnapshotSuccess(md) ? probe ! md.sequenceNr
case other ? probe ! other
}
}
}
class SnapshotDirectoryFailureSpec extends AkkaSpec(PersistenceSpec.config("leveldb", "SnapshotDirectoryFailureSpec", extraConfig = Some(
s"""
|akka.persistence.snapshot-store.local.dir = "${SnapshotDirectoryFailureSpec.inUseSnapshotPath}"
""".stripMargin))) with ImplicitSender {
import SnapshotDirectoryFailureSpec._
val file = new File(inUseSnapshotPath)
override protected def atStartup() {
if (!file.createNewFile()) throw new IOException(s"Failed to create test file [${file.getCanonicalFile}]")
}
override protected def afterTermination() {
if (!file.delete()) throw new IOException(s"Failed to delete test file [${file.getCanonicalFile}]")
}
"A local snapshot store configured with an failing directory name " must {
"throw an exception at startup" in {
EventFilter[ActorInitializationException](occurrences = 1).intercept {
val processor = system.actorOf(Props(classOf[TestProcessor], "SnapshotDirectoryFailureSpec-1", testActor))
processor ! "blahonga"
}
}
}
}
示例2: BackOffSupervisorActorSpec
//设置package包名称以及导入依赖的类
package ex1
import akka.actor.ActorSystem
import akka.testkit.{EventFilter, TestActorRef}
import org.scalatest.{BeforeAndAfterAll, FunSpec}
import scala.concurrent.Await
import scala.concurrent.duration.Duration
class BackOffSupervisorActorSpec extends FunSpec with BeforeAndAfterAll {
implicit val system = ActorSystem("testsystem")
override def afterAll = {
Await.result(system.terminate(), Duration.Inf)
}
describe("when it starts with 0") {
it("throws exceptions until state up to 10") {
val actor = TestActorRef(BackOffSupervisorActor.props)
EventFilter[RuntimeException](occurrences = 10) intercept {
(1 to 11).foreach{ actor ! _ }
}
}
}
}
示例3: Greeter01Test
//设置package包名称以及导入依赖的类
package aia.testdriven
import akka.testkit.{ CallingThreadDispatcher, EventFilter, TestKit }
import akka.actor.{ Props, ActorSystem }
import com.typesafe.config.ConfigFactory
import org.scalatest.WordSpecLike
import Greeter01Test._
class Greeter01Test extends TestKit(testSystem)
with WordSpecLike
with StopSystemAfterAll {
"The Greeter" must {
"say Hello World! when a Greeting(\"World\") is sent to it" in {
val dispatcherId = CallingThreadDispatcher.Id
val props = Props[Greeter].withDispatcher(dispatcherId)
val greeter = system.actorOf(props)
EventFilter.info(message = "Hello World!",
occurrences = 1).intercept {
greeter ! Greeting("World")
}
}
}
}
object Greeter01Test {
val testSystem = {
val config = ConfigFactory.parseString(
"""
akka.loggers = [akka.testkit.TestEventListener]
""")
ActorSystem("testsystem", config)
}
}
示例4: DbConnectionPoolExtensionTest
//设置package包名称以及导入依赖的类
package org.guangwenz.akka.db.connpool
import akka.actor.ActorSystem
import akka.testkit.{EventFilter, TestKit}
import org.guangwenz.akka.db.connpool.ConnectionPool.PrintDbStats
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
class DbConnectionPoolExtensionTest extends TestKit(ActorSystem("akkaconntest")) with FlatSpecLike with Matchers with BeforeAndAfterAll {
override def afterAll(): Unit = {
TestKit.shutdownActorSystem(system)
}
"An Akka Connection Pool Extension " should "return a connection when asked " in {
val conn = DbConnectionPoolExtension(system).getConnection
conn.isDefined shouldBe true
}
it should "print db stat" in {
val actor = DbConnectionPoolExtension(system).getConnectionPoolActor.get
EventFilter.info(pattern = "TotalLeased:.*", occurrences = 1).intercept {
actor ! PrintDbStats("test")
}
}
it should "return connection" in {
DbConnectionPoolExtension(system).connect {
case Right(connection) =>
connection.isValid(20) shouldBe true
case Left(reason) =>
fail(reason)
}
}
}