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

Scala DefaultTimeout类代码示例

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

本文整理汇总了Scala中akka.testkit.DefaultTimeout的典型用法代码示例。如果您正苦于以下问题:Scala DefaultTimeout类的具体用法?Scala DefaultTimeout怎么用?Scala DefaultTimeout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DefaultTimeout类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: AbstractActorSpec

//设置package包名称以及导入依赖的类
package name.mikulskibartosz.demo.akka.actors

import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, DefaultTimeout, TestKit}
import name.mikulskibartosz.demo.akka.service.Service
import org.mockito.Mockito._
import org.scalatest.mock.MockitoSugar
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.util.Try


abstract class AbstractActorSpec extends TestKit(ActorSystem()) with DefaultTimeout with ImplicitSender
with WordSpecLike with Matchers with BeforeAndAfterAll with MockitoSugar {
  override def afterAll() = {
    super.afterAll()
    shutdown()
  }

  def createServiceReturning(value: Try[Int]) = {
    val service = mock[Service]
    when(service.generate()).thenReturn(value)
    service
  }
} 
开发者ID:mikulskibartosz,项目名称:demoAkkaAccessingUnreliableService,代码行数:26,代码来源:AbstractActorSpec.scala


示例2:

//设置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


示例3: DataKeeperSpec

//设置package包名称以及导入依赖的类
package com.github.mijicd.waes.domain

import akka.actor.ActorSystem
import akka.testkit.{DefaultTimeout, ImplicitSender, TestKit}
import com.github.mijicd.waes.TestSpec
import com.github.mijicd.waes.domain.DataKeeper.{Compare, StoreLeft, StoreRight}
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class DataKeeperSpec extends TestKit(ActorSystem())
  with DefaultTimeout with ImplicitSender with TestSpec {

  override def afterAll() = TestKit.shutdownActorSystem(system)

  val actor = system.actorOf(DataKeeper.props())

  trait TestValues {
    val id = "test-id"
    val test = "test"
    val text = "text"
    val empty = ""
  }

  "DataKeeper" should "respond with 'EQUAL' when comparing same values" in {
    new TestValues {
      actor ! StoreLeft(id, test)
      actor ! StoreRight(id, test)

      actor ! Compare(id)
      expectMsg(DiffResult.forEqual)
    }
  }

  it should "respond with 'DIFFERENT_LENGTHS' when comparing non-empty with an empty value" in {
    new TestValues {
      actor ! StoreLeft(id, test)
      actor ! StoreRight(id, empty)

      actor ! Compare(id)
      expectMsg(DiffResult.forDifferentLengths)
    }
  }

  it should "respond with 'DIFFERENT_AT' and a list of diffs when comparing different values" in {
    new TestValues {
      actor ! StoreLeft(id, test)
      actor ! StoreRight(id, text)

      actor ! Compare(id)
      expectMsg(DiffResult.forDifferences(Seq(2)))
    }
  }

  it should "treat non-existent values as empty ones" in {
    val id = "empty-id"
    actor ! Compare(id)
    expectMsg(DiffResult.forEqual)
  }
} 
开发者ID:mijicd,项目名称:spray-akka-demo,代码行数:61,代码来源:DataKeeperSpec.scala


示例4: MandrillClientSpec

//设置package包名称以及导入依赖的类
package testutils

import akka.actor.{Props, ActorSystem}
import akka.pattern.AskSupport
import akka.stream.ActorMaterializer
import akka.testkit.{ImplicitSender, DefaultTimeout, TestKit}
import mandrillclient.api.JsonFormats
import mandrillclient.core.{MandrillAPIActor, MandrillClientSettings, Settings}
import org.scalatest._
import scala.concurrent.duration._

class MandrillClientSpec extends TestKit(ActorSystem("mandrill")) with DefaultTimeout with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll with AskSupport with EitherValues with OptionValues {

  implicit val materializer = ActorMaterializer()

  override def afterAll() = {
    info.apply("shutdown actor system")
    system.shutdown()
    super.afterAll()
  }

  val settings = new Settings with MandrillClientSettings with MandrillClientTestSettings
  val apiKey = settings.testKey

  val duration = 5 seconds
  val apiActor = system.actorOf(Props(classOf[MandrillAPIActor], settings, system, JsonFormats.formats), "Test-MandrillAPIActor")

} 
开发者ID:btomala,项目名称:mandrill-akka-client,代码行数:30,代码来源:MandrillClientSpec.scala


示例5: EchoUsageSpec

//设置package包名称以及导入依赖的类
import akka.actor.ActorSystem
import akka.testkit.{DefaultTimeout, ImplicitSender, TestActors, TestKit}
import com.typesafe.config.ConfigFactory
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.concurrent.duration._


class EchoUsageSpec extends TestKit(ActorSystem(
  "EchoUsageSpec",
  ConfigFactory.parseString(EchoUsageSpec.config))) with DefaultTimeout with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {


  val echoRef = system.actorOf(TestActors.echoActorProps)

  override def afterAll {
    shutdown()
  }

  "An EchoActor" should {
    "Respond with the same message it receives" in {
      within(50 millis) {
        echoRef ! "test"
        expectMsg("test")
      }
    }
  }
}


object EchoUsageSpec {
  // Define your test specific configuration here
  val config =
  """
    akka {
      loglevel = "WARNING"
    }
  """

} 
开发者ID:PuspenduBanerjee,项目名称:ScalaAkkaBlah,代码行数:42,代码来源:EchoUsageSpec.scala


示例6: BoxOfficeSpec

//设置package包名称以及导入依赖的类
package com.goticks

import akka.actor.{ ActorRef, Props, ActorSystem }

import akka.testkit.{ TestKit, ImplicitSender, DefaultTimeout }

import org.scalatest.{ WordSpecLike, MustMatchers }

class BoxOfficeSpec extends TestKit(ActorSystem("testBoxOffice"))
    with WordSpecLike
    with MustMatchers
    with ImplicitSender
    with DefaultTimeout
    with StopSystemAfterAll {
  "The BoxOffice" must {

    "Create an event and get tickets from the correct Ticket Seller" in {
      import BoxOffice._
      import TicketSeller._

      val boxOffice = system.actorOf(BoxOffice.props)
      val eventName = "RHCP"
      boxOffice ! CreateEvent(eventName, 10)
      expectMsg(EventCreated(Event(eventName, 10)))

      boxOffice ! GetTickets(eventName, 1)
      expectMsg(Tickets(eventName, Vector(Ticket(1))))

      boxOffice ! GetTickets("DavidBowie", 1)
      expectMsg(Tickets("DavidBowie"))
    }

    "Create a child actor when an event is created and sends it a Tickets message" in {
      import BoxOffice._
      import TicketSeller._

      val boxOffice = system.actorOf(Props(
          new BoxOffice  {
            override def createTicketSeller(name: String): ActorRef = testActor
          }
        )
      )

      val tickets = 3
      val eventName = "RHCP"
      val expectedTickets = (1 to tickets).map(Ticket).toVector
      boxOffice ! CreateEvent(eventName, tickets)
      expectMsg(Add(expectedTickets))
      expectMsg(EventCreated(Event(eventName, tickets)))
    }
  }
} 
开发者ID:gilbutITbook,项目名称:006877,代码行数:53,代码来源:BoxOfficeSpec.scala


示例7: Base

//设置package包名称以及导入依赖的类
package changestream.helpers

import akka.actor.ActorSystem
import akka.testkit.{DefaultTimeout, ImplicitSender, TestKit}
import com.typesafe.config.ConfigFactory
import org.scalatest._

class Base extends TestKit(ActorSystem("changestream_test", ConfigFactory.load("test.conf")))
    with DefaultTimeout
    with ImplicitSender
    with Matchers
    with Inside
    with WordSpecLike
    with BeforeAndAfterAll
    with BeforeAndAfter {
  implicit val ec = system.dispatcher

  override def afterAll() = {
    TestKit.shutdownActorSystem(system)
  }
} 
开发者ID:mavenlink,项目名称:changestream,代码行数:22,代码来源:Base.scala


示例8: mockedAddressRef

//设置package包名称以及导入依赖的类
package com.evolutiongaming.cluster

import akka.TestDummyActorRef
import akka.actor.{ActorRef, Address, ChildActorPath, RootActorPath}
import akka.testkit.DefaultTimeout
import com.evolutiongaming.util.ActorSpec
import org.scalatest.{FlatSpec, Matchers, OptionValues}
import org.scalatest.concurrent.{Eventually, PatienceConfiguration, ScalaFutures}
import org.scalatest.mockito.MockitoSugar

import scala.concurrent.duration._

trait AllocationStrategySpec extends FlatSpec
  with ActorSpec
  with Matchers
  with MockitoSugar
  with OptionValues
  with ScalaFutures
  with Eventually
  with PatienceConfiguration {

  override implicit val patienceConfig: PatienceConfig = PatienceConfig(5.seconds, 500.millis)

  trait AllocationStrategyScope extends ActorScope with DefaultTimeout {

    implicit val ec = system.dispatcher

    def mockedAddressRef(addr: Address): ActorRef = {
      val rootPath = RootActorPath(addr)
      val path = new ChildActorPath(rootPath, "test")
      new TestDummyActorRef(path)
    }

    def mockedHostRef(host: String): ActorRef =
      mockedAddressRef(testAddress(host))

    def testAddress(host: String): Address = Address(
      protocol = "http",
      system = "System",
      host = host,
      port = 2552)
  }
} 
开发者ID:evolution-gaming,项目名称:akka-tools,代码行数:44,代码来源:AllocationStrategySpec.scala


示例9: EmailSpec

//设置package包名称以及导入依赖的类
package com.contact.spec

import akka.testkit.TestKit
import akka.testkit.ImplicitSender
import akka.actor.Props
import com.contact.email.successEmail
import org.scalatest.BeforeAndAfterAll
import com.contact.email.EmailActor
import akka.testkit.DefaultTimeout
import org.scalatest.Matchers
import scala.util.Try
import scala.io.Source
import org.scalatest.WordSpecLike
import akka.actor.ActorSystem
import com.contact.email.sendGMail
import scala.concurrent.duration._

class EmailSpec extends TestKit(ActorSystem("TestKitUsageSpec")) with DefaultTimeout with ImplicitSender with WordSpecLike with BeforeAndAfterAll with Matchers {
  //You didn't think I was silly enough to put my password here did you?
  lazy val passwordFile = "/home/ra41p/workspace/TusharContact/ContactTusharLib/password"
  val emailActor = system.actorOf(Props(classOf[EmailActor], "testEmailActor"))
  val password =
    Try(Source.fromFile(passwordFile)
      .getLines()
      .toList(0))
      .toOption
      .getOrElse(throw new Exception("Create a non-empty password file noob"))

  override def afterAll = shutdown()
  
  "An EmailActor" should {
    "Respond with the a success message after sending e-mail" in {
      within(15 seconds) {
        emailActor ! sendGMail("[email protected]",
          password,
          "ramith.honeypot",
          "Hey, trying to contact you via contact-lib",
          "Test Email from contact-lib. I can contact you via e-mail now :D. -Ramith")
        expectMsg(successEmail)
      }
    }
  }
} 
开发者ID:Ra41P,项目名称:contact-lib,代码行数:44,代码来源:EmailSpec.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala ClusterSharding类代码示例发布时间:2022-05-23
下一篇:
Scala Error类代码示例发布时间: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