本文整理汇总了Scala中akka.testkit.TestKitBase类的典型用法代码示例。如果您正苦于以下问题:Scala TestKitBase类的具体用法?Scala TestKitBase怎么用?Scala TestKitBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestKitBase类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: aultPatience
//设置package包名称以及导入依赖的类
import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, ActorMaterializerSettings, Supervision}
import akka.testkit.{ImplicitSender, TestKit, TestKitBase}
import com.amazonaws.services.sqs.AmazonSQSAsync
import com.taxis99.amazon.sqs.SqsClientFactory
import com.typesafe.config.ConfigFactory
import org.scalatest._
import org.scalatest.concurrent.PatienceConfiguration
import org.scalatest.time._
import scala.concurrent.{ExecutionContext, Future}
package object test {
trait BaseSpec extends FlatSpec with Matchers with OptionValues with PatienceConfiguration with RecoverMethods {
implicit val defaultPatience =
PatienceConfig(timeout = Span(3, Seconds), interval = Span(5, Millis))
}
trait StreamSpec extends AsyncFlatSpec with Matchers with OptionValues with PatienceConfiguration
with TestKitBase with ImplicitSender with BeforeAndAfterAll {
implicit lazy val system: ActorSystem = ActorSystem("test", ConfigFactory.parseString("""
akka.actor.deployment.default.dispatcher = "akka.test.calling-thread-dispatcher"
"""))
override implicit def executionContext: ExecutionContext = system.dispatcher
override implicit def patienceConfig = PatienceConfig(timeout = Span(1, Minute), interval = Span(5, Millis))
val decider: Supervision.Decider = {
case _ => Supervision.Stop
}
val settings = ActorMaterializerSettings(system).withSupervisionStrategy(decider)
implicit lazy val materializer = ActorMaterializer(settings)
def withInMemoryQueue(testCode: (AmazonSQSAsync) => Future[Assertion]): Future[Assertion] = {
val (server, aws) = SqsClientFactory.inMemory(Some(system))
// "loan" the fixture to the test
testCode(aws) andThen {
case _ => server.stopAndWait()
}
}
override def afterAll {
TestKit.shutdownActorSystem(system)
}
}
}
示例2: executionContext
//设置package包名称以及导入依赖的类
import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, ActorMaterializerSettings, Supervision}
import akka.testkit.{TestKit, TestKitBase}
import com.taxis99.amazon.sns.SnsClientFactory
import com.taxis99.amazon.sqs.SqsClientFactory
import com.typesafe.config.ConfigFactory
import org.scalatest._
import org.scalatest.concurrent.PatienceConfiguration
import org.scalatest.time.{Millis, Minute, Span}
import scala.concurrent.ExecutionContext
package object it {
trait IntegrationSpec extends AsyncFlatSpec with Matchers with OptionValues with PatienceConfiguration
with TestKitBase with BeforeAndAfterAll {
implicit lazy val system: ActorSystem = ActorSystem("test", ConfigFactory.parseString("""
akka.actor.deployment.default.dispatcher = "akka.test.calling-thread-dispatcher"
"""))
override implicit def executionContext: ExecutionContext = system.dispatcher
override implicit def patienceConfig = PatienceConfig(timeout = Span(1, Minute), interval = Span(5, Millis))
implicit lazy val amazonSqsConn = SqsClientFactory.atLocalhost(9324)
implicit lazy val amazonSnsConn = SnsClientFactory.atLocalhost(9292)
val decider: Supervision.Decider = {
case _ => Supervision.Stop
}
val settings = ActorMaterializerSettings(system).withSupervisionStrategy(decider)
implicit lazy val materializer = ActorMaterializer(settings)
override def afterAll {
TestKit.shutdownActorSystem(system)
}
}
}
示例3:
//设置package包名称以及导入依赖的类
package util
import akka.testkit.{DefaultTimeout, ImplicitSender, TestKitBase}
import core.{Core, CoreActors}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
trait ActorSpecBase
extends ImplicitSender
with Core
with WordSpecLike
with Matchers
with BeforeAndAfterAll
with AwaitHelper
with DefaultTimeout {
self: TestKitBase =>
}
示例4: SrackdriverMetricSenderSpec
//设置package包名称以及导入依赖的类
package com.github.uryyyyyyy.kamon.stackdriver
import akka.actor.ActorSystem
import akka.testkit.TestKitBase
import kamon.Kamon
import org.scalatest.{Matchers, WordSpecLike}
class SrackdriverMetricSenderSpec extends TestKitBase with Matchers with WordSpecLike {
"the DataDogMetricSender" should {
"send latency measurements" in {
println("TBD")
}
}
override implicit lazy val system: ActorSystem = {
Kamon.start()
ActorSystem()
}
}
示例5: EchoEndpoint
//设置package包名称以及导入依赖的类
package streaming
import java.time.Instant
import javax.websocket.server.ServerEndpoint
import javax.websocket.{OnMessage, Session}
import akka.actor.ActorSystem
import akka.testkit.{TestActorRef, TestKitBase, TestProbe}
import co.coinsmith.kafka.cryptocoin.streaming.{Connect, WebsocketActor}
import org.glassfish.tyrus.test.tools.TestContainer
import org.json4s.JsonAST.JObject
import org.json4s.JsonDSL.WithBigDecimal._
import org.json4s.jackson.JsonMethods._
import org.scalatest.FlatSpecLike
@ServerEndpoint("/WebsocketActorSpec/echoEndpoint")
class EchoEndpoint {
@OnMessage
def onMessage(message: String, session: Session) = message
}
class WebsocketActorSpec extends TestContainer with TestKitBase with FlatSpecLike {
implicit lazy val system = ActorSystem("WebsocketActorSpecSystem")
val serverEndpoint = new EchoEndpoint
val uri = getURI(serverEndpoint.getClass)
"WebsocketActor" should "forward received messages to receiver" in {
val server = startServer(serverEndpoint.getClass)
val actorRef = TestActorRef(WebsocketActor.props(uri))
val probe = TestProbe("probe")
val json = List.empty
val expected = JObject(json)
actorRef ! probe.ref
actorRef ! Connect
actorRef ! compact(render(json))
probe.expectMsgPF() {
case (_: Instant, expected) => true
case _ => false
}
stopServer(server)
}
}