本文整理汇总了Scala中org.scalatest.concurrent.PatienceConfiguration类的典型用法代码示例。如果您正苦于以下问题:Scala PatienceConfiguration类的具体用法?Scala PatienceConfiguration怎么用?Scala PatienceConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PatienceConfiguration类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: LayerClientIntegrationSpec
//设置package包名称以及导入依赖的类
package com.jatescher.layer
import akka.actor.ActorSystem
import akka.http.scaladsl.model.{ HttpMethods, HttpRequest, HttpResponse, StatusCodes }
import akka.stream.ActorMaterializer
import com.typesafe.config.{ Config, ConfigFactory }
import org.scalatest.concurrent.{ IntegrationPatience, PatienceConfiguration, ScalaFutures }
import org.scalatest.{ Matchers, WordSpec }
import scala.concurrent.Future
class LayerClientIntegrationSpec extends WordSpec with Matchers with PatienceConfiguration with IntegrationPatience with ScalaFutures {
val testConfig = ConfigFactory.load("test-application.conf")
val router = new LayerRouter(testConfig)
implicit val system = ActorSystem("LayerClientIntegrationSpecSystem")
implicit val materializer = ActorMaterializer()
implicit val ec = system.dispatcher
class IntegrationLayerClient(router: LayerRouter, config: Config) extends LayerClient(router, config) {
def testRequest(httpRequest: HttpRequest): Future[HttpResponse] = executeRequest(httpRequest)
}
"#executeRequest" should {
"complete the request" in {
val request = HttpRequest(HttpMethods.GET, uri = "https://layer.com")
val client = new IntegrationLayerClient(router, testConfig)
client.testRequest(request).futureValue.status shouldBe StatusCodes.OK
}
}
}
示例4: HealthCheckFeature
//设置package包名称以及导入依赖的类
package com.reactivecore.quotes.workshop.api.feature
import com.reactivecore.quotes.workshop.api.QuotesWorkshopApiService
import org.scalatest.concurrent.{PatienceConfiguration, ScalaFutures}
import org.scalatest.time.{Seconds, Span}
import org.scalatest.{FeatureSpec, GivenWhenThen, Matchers}
import play.api.http.Status
class HealthCheckFeature extends FeatureSpec with GivenWhenThen with Matchers with ScalaFutures with PatienceConfiguration {
override implicit val patienceConfig = PatienceConfig(
timeout = scaled(Span(1, Seconds))
)
feature("health check") {
scenario("service is healthy") {
Given("a service")
val service = QuotesWorkshopApiService()
When("getting the /health endpoint")
val response = get(s"http://localhost:${service.port}/health").futureValue
Then("the response status should be OK")
response.status should be(Status.OK)
service.stop()
}
}
}
示例5: OptionsFeature
//设置package包名称以及导入依赖的类
package com.reactivecore.quotes.workshop.api.feature
import com.reactivecore.quotes.workshop.api.QuotesWorkshopApiService
import org.scalatest.concurrent.{PatienceConfiguration, ScalaFutures}
import org.scalatest.time.{Seconds, Span}
import org.scalatest.{FeatureSpec, GivenWhenThen, Matchers}
import play.api.http.Status
class OptionsFeature extends FeatureSpec with GivenWhenThen with Matchers with ScalaFutures with PatienceConfiguration {
override implicit val patienceConfig = PatienceConfig(
timeout = scaled(Span(1, Seconds))
)
feature("options") {
scenario("requests options of /items") {
Given("a service")
val service = QuotesWorkshopApiService()
When("requesting for the options of /items endpoint")
val response = options(s"http://localhost:${service.port}/items").futureValue
Then("the response status should be OK")
response.status should be(Status.OK)
service.stop()
}
}
}
示例6: HttpEntityImplicitConverters
//设置package包名称以及导入依赖的类
package org.danielwojda.obfuscator.functionaltests.dsl
import akka.http.scaladsl.model.HttpEntity
import akka.stream.Materializer
import org.json4s.JValue
import org.scalatest.concurrent.PatienceConfiguration
import scala.concurrent.{Await, ExecutionContext}
import org.json4s.jackson.JsonMethods._
object HttpEntityImplicitConverters {
implicit class HttpEntityOps(entity: HttpEntity) {
def asString()(implicit timeout: PatienceConfiguration.Timeout, mat: Materializer, ec: ExecutionContext): String = {
Await.result(
entity.toStrict(timeout.value).map(_.data.decodeString("UTF-8")), atMost = timeout.value
)
}
def asJValue()(implicit timeout: PatienceConfiguration.Timeout, mat: Materializer, ec: ExecutionContext): JValue = {
parse(asString())
}
}
}
示例7: LogonDirectiveSpec
//设置package包名称以及导入依赖的类
package io.igu.cityindex.authentication
import io.igu.cityindex.authentication.model.LogOnRequest
import io.igu.cityindex.fixture.SessionFixture
import io.igu.cityindex.{CityIndexDirective, WsClient, WsTestClient}
import org.scalatest.concurrent.{PatienceConfiguration, ScalaFutures}
import org.scalatest.{MustMatchers, OptionValues, WordSpec}
import scala.concurrent.ExecutionContext
class LogonDirectiveSpec extends WordSpec with MustMatchers with OptionValues with ScalaFutures with PatienceConfiguration {
private implicit val executionContext: ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global
"LogonDirective" should {
"logOn(LogonRequest)" should {
"perform authentication" in withLogonDirective { directive =>
val x = directive.logOn(LogOnRequest("", "")).futureValue
}
}
}
private def withLogonDirective[T](block: LogonDirective => T): T = withWsClient { wsClient =>
val directive = new CityIndexDirective with LogonDirective {
def environment = ""
def client: WsClient = wsClient
}
block(directive)
}
private def withWsClient[T](block: WsClient => T) = {
val wsClient = WsTestClient.withRouter {
case "/TradingAPI/session" => WsTestClient.respond(SessionFixture.validSession)
}
block(wsClient)
}
}
示例8: emptyComponent
//设置package包名称以及导入依赖的类
package io.udash.testing
import com.github.ghik.silencer.silent
import org.scalajs.dom
import org.scalatest.{Assertion, Succeeded}
import org.scalatest.concurrent.PatienceConfiguration
import org.scalatest.time.{Millis, Span}
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.scalajs.concurrent.JSExecutionContext
import scala.scalajs.js.Date
import scala.util.{Failure, Success}
trait FrontendTestUtils {
import scalatags.JsDom.all.div
def emptyComponent() = div().render
}
trait UdashFrontendTest extends UdashSharedTest with FrontendTestUtils {
@silent
implicit val testExecutionContext = JSExecutionContext.runNow
}
trait AsyncUdashFrontendTest extends AsyncUdashSharedTest with FrontendTestUtils with PatienceConfiguration {
case object EventuallyTimeout extends Exception
@silent
override implicit def executionContext: ExecutionContext = JSExecutionContext.runNow
override implicit val patienceConfig = PatienceConfig(scaled(Span(5000, Millis)), scaled(Span(100, Millis)))
def eventually(code: => Any)(implicit patienceConfig: PatienceConfig): Future[Assertion] = {
val start = Date.now()
val p = Promise[Assertion]
def startTest(): Unit = {
dom.window.setTimeout(() => {
if (patienceConfig.timeout.toMillis > Date.now() - start) {
try {
code
p.complete(Success(Succeeded))
} catch {
case _: Exception => startTest()
}
} else {
p.complete(Failure(EventuallyTimeout))
}
}, patienceConfig.interval.toMillis)
}
startTest()
p.future
}
}
示例9: 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)
}
}