• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala TestKitBase类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala SimpleRouter类代码示例发布时间:2022-05-23
下一篇:
Scala Consumer类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap