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

Scala Timeout类代码示例

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

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



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

示例1: MonitoringEndpointsSpec

//设置package包名称以及导入依赖的类
package org.danielwojda.obfuscator.functionaltests

import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{HttpRequest, HttpResponse, StatusCodes}
import org.danielwojda.obfuscator.functionaltests.dsl.AkkaImplicits
import org.danielwojda.obfuscator.functionaltests.dsl.HttpEntityImplicitConverters._
import org.scalatest.concurrent.PatienceConfiguration.Timeout
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{FlatSpec, GivenWhenThen, Matchers}

import scala.concurrent.Future
import scala.concurrent.duration._
import scala.language.postfixOps

class MonitoringEndpointsSpec extends FlatSpec with Matchers with GivenWhenThen with ScalaFutures with AkkaImplicits {

  override implicit val patienceConfig = PatienceConfig(timeout = 2 seconds)
  implicit val timeout = Timeout(patienceConfig.timeout)

  "Service" should "expose the 'status' endpoint which always returns OK" in {
    When("a 'status' endpoint is called")
    val responseFuture: Future[HttpResponse] = Http().singleRequest(HttpRequest(uri = "http://localhost:8080/private/status"))

    Then("Http status 200 and OK body is returned")
    whenReady(responseFuture) { response =>
      response.status shouldBe StatusCodes.OK
      response.entity.asString shouldBe "OK"
    }
  }

} 
开发者ID:wojda,项目名称:obfuscate,代码行数:32,代码来源:MonitoringEndpointsSpec.scala


示例2: SingleThreadOrderExecutorSpec

//设置package包名称以及导入依赖的类
package ru.tolsi.matcher.naive

import scala.concurrent.Future
import org.scalatest.concurrent.PatienceConfiguration.Timeout
import org.scalatest.time.{Seconds, Span}
import ru.tolsi.matcher.{ClientInfo, Order, OrderType, ReverseOrders, UnitSpec}

class SingleThreadOrderExecutorSpec extends UnitSpec {
  describe("execute method") {
    implicit val ec = scala.concurrent.ExecutionContext.global
    it("should execure reverse orders on users from repo") {
      val executor = new SingleThreadOrderExecutor
      val repo = ThreadUnsafeClientRepository(Seq(ClientInfo("1", 0L, 0L, 0L, 0L, 0L), ClientInfo("2", 0L, 0L, 0L, 0L,
        0L)).map(ThreadUnsafeClient.fromClientInfo))
      val future = executor.execute(ReverseOrders(Order(1, "1", OrderType.Buy, "A", 1, 1), Order(1, "2", OrderType.Sell,
        "A", 1, 1)), repo)
      val balancesFuture = for {
        _ <- future
        users <- repo.getAll
        userBalances <- Future.sequence(users.map(u => u.getAllBalances.map(b => u.id -> b)))
      } yield userBalances
      whenReady(balancesFuture, Timeout(Span(10, Seconds))) { case userBalances =>
        val userBalancesMap = userBalances.toMap
        userBalancesMap("1")("A") should be(1)
        userBalancesMap("1")("USD") should be(-1)
        userBalancesMap("2")("A") should be(-1)
        userBalancesMap("2")("USD") should be(1)
      }
    }
    it("should fail on execure orders on unexisted users from repo") {
      val executor = new SingleThreadOrderExecutor
      val repo = ThreadUnsafeClientRepository(Seq(ClientInfo("1", 0L, 0L, 0L, 0L, 0L)).map(ThreadUnsafeClient.fromClientInfo))
      val future = executor.execute(ReverseOrders(Order(1, "1", OrderType.Buy, "A", 1, 1), Order(1, "2", OrderType.Sell,
        "A", 1, 1)), repo)
      future.failed.futureValue shouldBe an[IllegalStateException]
    }
    it("should execure reverse orders of the same user") {
      val executor = new SingleThreadOrderExecutor
      val repo = ThreadUnsafeClientRepository(Seq(ClientInfo("1", 0L, 0L, 0L, 0L, 0L), ClientInfo("1", 0L, 0L, 0L, 0L,
        0L)).map(ThreadUnsafeClient.fromClientInfo))
      val future = executor.execute(ReverseOrders(Order(1, "1", OrderType.Buy, "A", 1, 1), Order(1, "1", OrderType.Sell,
        "A", 1, 1)), repo)
      val balancesFuture = for {
        _ <- future
        users <- repo.getAll
        userBalances <- Future.sequence(users.map(u => u.getAllBalances.map(b => u.id -> b)))
      } yield userBalances
      whenReady(balancesFuture, Timeout(Span(10, Seconds))) { case userBalances =>
        val userBalancesMap = userBalances.toMap
        userBalancesMap("1")("A") should be(0)
        userBalancesMap("1")("USD") should be(0)
      }
    }
  }
} 
开发者ID:Tolsi,项目名称:matcher,代码行数:56,代码来源:SingleThreadOrderExecutorSpec.scala


示例3: ModifyTests

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

import java.text.SimpleDateFormat
import carads.backend._
import carads.frontend._
import com.typesafe.config.ConfigFactory
import org.json4s.{DefaultFormats, Formats}
import org.scalatest.concurrent.PatienceConfiguration.Timeout
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.SpanSugar._
import org.scalatest.{FreeSpec, Matchers}
import spray.client.pipelining._
import spray.http._
import spray.httpx.Json4sJacksonSupport

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

class ModifyTests extends FreeSpec with Matchers with ScalaFutures with Json4sJacksonSupport {
  override implicit def json4sJacksonFormats: Formats = DefaultFormats.withBigDecimal

  val format = new SimpleDateFormat("yyyy-MM-dd")
  val config = ConfigFactory.load()
  val storage = {
    val s = new MemStorage()
    s.put(Record(3, "Freelander", Diesel(), 50000, true, None, None))
    s
  }
  val settings = Settings(storage)
  val service = new Service(config, settings)

  class Fixture(val pipeline: HttpRequest => Future[ModifyResp]) {
    val reqTimeout = Timeout(2.seconds)
    def send(request: ModifyReq): Future[ModifyResp] =
      pipeline(Post(s"http://localhost:${service.actualPort.get}/modify", request))
  }

  def withFixture(testCode: Fixture => Any): Unit = {
    implicit val system = service.start()
    val pipeline: HttpRequest => Future[ModifyResp] = sendReceive ~> unmarshal[ModifyResp]
    try {
      testCode(new Fixture(pipeline))
    }
    finally {
      service.shutdown(system)
    }
  }

  "Modify the ad with" - {
    " new car" in withFixture { fixture => import fixture._
      val request = ModifyReq(id = 3, title = Some("Freelander 2"), None, None, None, None,None)

      whenReady(send(request), reqTimeout) { resp =>
        resp.isSuccess shouldBe true
        resp.error shouldBe None
        storage.get(3).get.title shouldBe "Freelander 2"
      }
    }
  }
} 
开发者ID:MaxGekk,项目名称:CarAds,代码行数:61,代码来源:ModifyTests.scala


示例4: HealthCheck

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

import akka.actor.ActorSystem
import carads.frontend.Settings
import com.typesafe.config.ConfigFactory
import org.scalatest.concurrent.PatienceConfiguration.Timeout
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.Span
import org.scalatest.time.SpanSugar._
import org.scalatest.{FreeSpec, Matchers}
import spray.client.pipelining._
import spray.http._

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{Await, Future}

class HealthCheck extends FreeSpec with Matchers with ScalaFutures {
  val config = ConfigFactory.load()
  val settings = Settings(storage = new MemStorage())
  val service = new Service(config, settings)

  "Service should" - {
    "return status in 300 milliseconds" in {
      implicit val tester = ActorSystem()

      val carAdsActors = service.start()
      def get(timeout: Span) = {
        implicit val reqTimeout = Timeout(timeout)
        val pipeline: HttpRequest => Future[HttpResponse] = sendReceive
        val response = pipeline(Get(s"http://localhost:${service.actualPort.get}/status"))

        Await.result(response, timeout).status.isSuccess shouldBe true
      }
      try {
        get(1000.milliseconds)
        for (i <- 0 until 2) {
          get(300.milliseconds)
        }
      } finally {
        service.shutdown(carAdsActors)
      }
    }
  }
} 
开发者ID:MaxGekk,项目名称:CarAds,代码行数:45,代码来源:HealthCheck.scala


示例5: CheckJobStatusInteractorSpec

//设置package包名称以及导入依赖的类
package xyz.joaovasques.sparkapi.tests.unit

import akka.actor.ActorSystem
import akka.testkit.TestKit
import org.scalatest._
import org.scalatest.concurrent.ScalaFutures
import xyz.joaovasques.sparkapi.tests.helpers.InteractorHelpers
import org.scalatest.concurrent.PatienceConfiguration.Timeout
import org.scalatest.time._
import xyz.joaovasques.sparkapi.api.standalone.interactors._
import xyz.joaovasques.sparkapi.actors.SparkActor._

class CheckJobStatusInteractorSpec extends TestKit(ActorSystem("SubmitJobInteractorSpec"))
    with InteractorHelpers
    with FunSpecLike
    with RecoverMethods
    with ScalaFutures
    with Matchers
    with BeforeAndAfterAll {

  private val validJob = SubmitJob("name", "main-class" ,Set(), "jar", Map())
  private val invalidJob = SubmitJob("invalid-name", "main-class", Set(), "no-jar", Map())

  private val submitInteractor = new SubmitJobInteractor(apiRequest, masterIp)
  private val checkStatusInteractor = new CheckJobStatusInteractor(apiRequest, masterIp)

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

  describe("a CheckJobStatusInteractor") {
    describe("when having a running job") {
      it("should be able to get it's it's status as RUNNING") {
        pending
      }
    }

    describe("when having a job that ended") {
      it("should be able to get it's it's status as FINISHED") {
        pending
      }
    }

    describe("when having a job that failed") {
      it("should be able to get it's it's status as ERROR") {
        val submissionIdFuture = submitInteractor.call(invalidJob).map(_.submissionId)

        Thread.sleep(2000)

        val futureResult = for {
          submissionId <- submissionIdFuture
          status <- checkStatusInteractor.call(submissionId)
        } yield status.driverState

        whenReady(futureResult, Timeout(Span(5, Seconds))) { _ should be ("ERROR") }
      }
    }
  }
} 
开发者ID:JoaoVasques,项目名称:spark-api,代码行数:58,代码来源:CheckJobStatusInteractorSpec.scala


示例6: SubmitJobInteractorSpec

//设置package包名称以及导入依赖的类
package xyz.joaovasques.sparkapi.tests.unit

import akka.actor.ActorSystem
import akka.testkit.TestKit
import org.scalatest._
import org.scalatest.concurrent._
import org.scalatest.concurrent.PatienceConfiguration.Timeout
import org.scalatest.concurrent.AbstractPatienceConfiguration
import org.scalatest.time._
import xyz.joaovasques.sparkapi.tests.helpers._
import scala.concurrent._, duration._
import xyz.joaovasques.sparkapi.api.standalone.interactors._
import xyz.joaovasques.sparkapi.actors.SparkActor._

class SubmitJobInteractorSpec extends TestKit(ActorSystem("KillJobInteractorSpec"))
    with InteractorHelpers
    with JobHelpers
    with FunSpecLike
    with ScalaFutures
    with RecoverMethods
    with Matchers
    with BeforeAndAfterAll {

  private val validJob = SubmitJob("Hello World", "com.example.TestBatchJob" ,Set(), dummyJobJarLocation, Map())

  private val interactor = new SubmitJobInteractor(apiRequest, masterIp)

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

  describe("a SubmitJobInteractor") {
    describe("when having an existing job") {
      it("should be able to submit it") {
        val future = interactor.call(validJob).map(_.success)
        whenReady(future, Timeout(Span(5, Seconds))) { _ should be (true) }
      }
    }
  }
} 
开发者ID:JoaoVasques,项目名称:spark-api,代码行数:39,代码来源:SubmitJobInteractorSpec.scala


示例7: SchemaCreateInitializerSpec

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



import org.scalatest.concurrent.PatienceConfiguration.Timeout
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{FlatSpec, Matchers}
import slick.dbio.Effect.{Read, Write}
import slick.dbio.{DBIOAction, NoStream}

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._

class SchemaCreateInitializerSpec extends FlatSpec with Matchers with ScalaFutures {
  import testdatabase._

  def insertAndQueryExampleDataFromTable(ctx: TestDatabaseContext with DatabaseCommandExecution): DBIOAction[Seq[Int], NoStream, Write with Read] = {
    import ctx.api._
    for {
      _ <- ctx.table +=(1, "foo")
      id <- ctx.table.filter(_.name === "foo").map(_.id).result
    } yield id
  }
  "the schema creating initializer" should "create a  usable schema" in {
    val context = new TestDatabaseContext with DatabaseCommandExecution

    whenReady(SchemaCreateInitializer(context), Timeout(5.seconds)) { _ =>
      val actions = insertAndQueryExampleDataFromTable(context)
      whenReady(context.database.run(actions)) { foundIDs =>
        foundIDs should contain theSameElementsAs List(1)
      }
    }
  }
  it should "be idempotent" in {
    val context = new TestDatabaseContext with DatabaseCommandExecution
    val createTwice = for {
      _ <- SchemaCreateInitializer(context)
      _ <- SchemaCreateInitializer(context)
    } yield ()

    whenReady(createTwice, Timeout(5.seconds)) { _ =>
      val actions = insertAndQueryExampleDataFromTable(context)

      whenReady(context.database.run(actions)) { foundIDs =>
        foundIDs should contain theSameElementsAs List(1)
      }
    }
  }
} 
开发者ID:Norwae,项目名称:oriana,代码行数:50,代码来源:SchemaCreateInitializerSpec.scala


示例8: GettingFittingSentenceSpec

//设置package包名称以及导入依赖的类
package org.danielwojda.obfuscator.functionaltests

import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import org.danielwojda.obfuscator.functionaltests.dsl.AkkaImplicits
import org.danielwojda.obfuscator.functionaltests.dsl.HttpEntityImplicitConverters._
import org.scalatest.concurrent.Eventually
import org.scalatest.concurrent.PatienceConfiguration.Timeout
import org.scalatest.{FlatSpec, GivenWhenThen, Matchers}

import scala.concurrent.Await
import scala.concurrent.duration._
import scala.language.postfixOps


class GettingFittingSentenceSpec extends FlatSpec with Matchers with GivenWhenThen with AkkaImplicits with Eventually {

  implicit val requestTimeout = Timeout(3 seconds)
  implicit val patienceconfig = PatienceConfig(timeout = requestTimeout.value)
  implicit val formats = org.json4s.DefaultFormats

  "The service" should "provide sentences containing words from given set of words" in {
    Given("the warmed up service")
    ObfuscateClient.warmUpWith(sentence = "Thank you very much.")
    ObfuscateClient.warmUpWith(sentence = "Thank you for taking the trouble to help me. I do appreciate it.")
    ObfuscateClient.warmUpWith(sentence = "Not related sentence. It's here just to prove that not all of the sentences will be returned.")

    When("a user ask for fitting sentences")
    val response: HttpResponse = ObfuscateClient.get("thank you")

    Then("service returns a list of fitted sentences")
    response.status shouldBe StatusCodes.OK
    response.entity.contentType shouldBe ContentTypes.`application/json`

    val responseSentences = (response.entity.asJValue \ "sentences").extract[List[String]]
    responseSentences should contain theSameElementsAs List("Thank you very much.", "Thank you for taking the trouble to help me. I do appreciate it.")
  }

  object ObfuscateClient {

    def get(sentenceToObfuscate: String)(implicit timeout: Timeout): HttpResponse = {
      val uri = Uri("http://localhost:8080/obfuscate").withQuery(Uri.Query(Map("sentence" -> sentenceToObfuscate)))
      val futureResponse = Http().singleRequest(HttpRequest(
        uri = uri,
        method = HttpMethods.GET
      ))
      Await.result(futureResponse, atMost = timeout.value)
    }

    def warmUpWith(sentence: String)(implicit timeout: Timeout): HttpResponse = {
      val futureResponse = Http().singleRequest(HttpRequest(
        uri = "http://localhost:8080/sentences",
        method = HttpMethods.POST,
        entity = HttpEntity(sentence)))
      Await.result(futureResponse, atMost = timeout.value)
    }
  }

} 
开发者ID:wojda,项目名称:obfuscate,代码行数:60,代码来源:GettingFittingSentenceSpec.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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