本文整理汇总了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"
}
}
}
}
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:50,代码来源:SnapshotDirectoryFailureSpec.scala
示例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 ! _ }
}
}
}
}
开发者ID:matsu-chara,项目名称:AkkaSandbox,代码行数:27,代码来源:BackOffSupervisorActorSpec.scala
示例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)
}
}
开发者ID:gilbutITbook,项目名称:006877,代码行数:36,代码来源:Greeter01Test.scala
示例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)
}
}
}
开发者ID:zgwmike,项目名称:akka-db-connpool,代码行数:33,代码来源:DbConnectionPoolExtensionTest.scala
注:本文中的akka.testkit.EventFilter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论