当前位置: 首页>>代码示例>>Scala>>正文


Scala TestKitBase类代码示例

本文整理汇总了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)
    }
  }
} 
开发者ID:99Taxis,项目名称:common-sqs,代码行数:50,代码来源:package.scala

示例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)
    }
  }
} 
开发者ID:99Taxis,项目名称:common-sqs,代码行数:41,代码来源:package.scala

示例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 =>
} 
开发者ID:Lastik,项目名称:money-transfer-sample,代码行数:17,代码来源:ActorSpecBase.scala

示例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()
  }
} 
开发者ID:uryyyyyyy,项目名称:kamon-stackdriver,代码行数:20,代码来源:SrackdriverMetricSenderSpec.scala

示例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)
  }
} 
开发者ID:blbradley,项目名称:kafka-cryptocoin,代码行数:47,代码来源:WebsocketActorSpec.scala


注:本文中的akka.testkit.TestKitBase类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。