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


Scala RouteTestTimeout类代码示例

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


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

示例1: BaseRouteTest

//设置package包名称以及导入依赖的类
package com.flipkart.connekt.receptors.tests.routes

import java.util.concurrent.TimeUnit

import akka.http.scaladsl.model.headers.RawHeader
import akka.http.scaladsl.server
import akka.http.scaladsl.testkit.{RouteTestTimeout, ScalatestRouteTest}
import com.flipkart.connekt.commons.entities.AppUser
import com.flipkart.connekt.receptors.routes.common.ClientRoute
import com.flipkart.connekt.receptors.routes.master.{RegistrationRoute, SendRoute}
import com.flipkart.connekt.receptors.routes.stencils.StencilsRoute
import org.scalatest.Matchers

import scala.concurrent.duration.FiniteDuration

abstract class BaseRouteTest extends BaseReceptorsTest with Matchers with ScalatestRouteTest {

  implicit val routeTestTimeout = RouteTestTimeout(FiniteDuration.apply(30, TimeUnit.SECONDS))
  var stencilRoute: server.Route = null
  var registrationRoute: server.Route = null
  var sendRoute: server.Route = null
  var clientRoute: server.Route = null

  implicit val am = system
  val header = RawHeader("x-api-key", "sandbox-key-01")
  implicit var user: AppUser = null

  override def beforeAll() = {
    super.beforeAll()
    user = new AppUser("test", "test", "", "")
    stencilRoute = new StencilsRoute().route
    registrationRoute = new RegistrationRoute().route
    sendRoute = new SendRoute().route
    clientRoute = new ClientRoute().route
  }
} 
开发者ID:ayush03agarwal,项目名称:connekt,代码行数:37,代码来源:BaseRouteTest.scala

示例2: mapCbs

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

import akka.http.scaladsl.testkit.{RouteTestTimeout, ScalatestRouteTest}
import com.acromancer.acromancer.common.api.JsonSupport
import com.acromancer.acromancer.user.application.Session
import com.softwaremill.session.{SessionConfig, SessionManager}
import com.typesafe.config.ConfigFactory
import org.scalatest.Matchers
import scala.concurrent.duration._

trait BaseRoutesSpec extends FlatSpecWithDb with ScalatestRouteTest with Matchers with JsonSupport { spec =>

  lazy val sessionConfig = SessionConfig.fromConfig(ConfigFactory.load()).copy(sessionEncryptData = true)

  implicit def mapCbs = CanBeSerialized[Map[String, String]]

  implicit val timeout = RouteTestTimeout(10 second span)

  trait TestRoutesSupport {
    lazy val sessionConfig = spec.sessionConfig
    implicit def materializer = spec.materializer
    implicit def ec = spec.executor
    implicit def sessionManager = new SessionManager[Session](sessionConfig)
    implicit def refreshTokenStorage = null
  }
} 
开发者ID:GitsAndGlamour,项目名称:acromancer-game,代码行数:27,代码来源:BaseRoutesSpec.scala

示例3: PaginationSpec

//设置package包名称以及导入依赖的类
package com.lonelyplanet.akka.http.extensions

import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.testkit.{RouteTestTimeout, ScalatestRouteTest}
import org.scalatest.{FlatSpec, Matchers}

import scala.concurrent.duration.FiniteDuration

class PaginationSpec extends FlatSpec with PaginationDirectives with Matchers with ScalatestRouteTest {
  implicit val routeTestTimeout: RouteTestTimeout = RouteTestTimeout(FiniteDuration(10, "s"))
  val config = testConfig

  def paginationRoute =
    path("filter-test") {
      withOptionalPagination { page =>
        complete {
          page match {
            case Some(p) => p.toString
            case None    => "NoPage"
          }
        }
      }
    }

  def paginationOrDefaultsRoute =
    path("filter-test") {
      withPagination { page =>
        complete {
          page.toString
        }
      }
    }
} 
开发者ID:lonelyplanet,项目名称:akka-http-extensions,代码行数:34,代码来源:PaginationSpec.scala

示例4: ServiceTestBase

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

import akka.http.scaladsl.server.Route
import akka.http.scaladsl.testkit.{RouteTestTimeout, ScalatestRouteTest}
import com.typesafe.config.{Config, ConfigFactory}
import de.choffmeister.microserviceutils.http.JsonWebTokenAuthenticator
import de.choffmeister.microserviceutils.json.JsonHome
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{Millis, Seconds, Span}
import org.scalatest.{FunSpec, Matchers}

import scala.concurrent.duration._

abstract class ServiceTestBase extends FunSpec with ScalatestRouteTest with Matchers with ScalaFutures with JsonProtocol {
  // configure timeouts
  implicit val timeout: RouteTestTimeout = RouteTestTimeout(3.seconds)
  implicit val defaultPatience: PatienceConfig = PatienceConfig(timeout = Span(5, Seconds), interval = Span(100, Millis))

  // common needed values
  val config: Config = ConfigFactory.load()
  val authenticator: JsonWebTokenAuthenticator = new JsonWebTokenAuthenticator()
  val service: Service = new Service()
  val jsonHome: JsonHome = HttpServer.jsonHome
  def routes: Route = service.httpServer.routes
} 
开发者ID:choffmeister,项目名称:akka-microservice.g8,代码行数:26,代码来源:ServiceTestBase.scala

示例5: mapCbs

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

import akka.http.scaladsl.testkit.{RouteTestTimeout, ScalatestRouteTest}
import com.softwaremill.bootzooka.common.api.JsonSupport
import com.softwaremill.bootzooka.user.application.Session
import com.softwaremill.session.{SessionConfig, SessionManager}
import com.typesafe.config.ConfigFactory
import org.scalatest.Matchers
import scala.concurrent.duration._

trait BaseRoutesSpec extends FlatSpecWithDb with ScalatestRouteTest with Matchers with JsonSupport { spec =>

  lazy val sessionConfig = SessionConfig.fromConfig(ConfigFactory.load()).copy(sessionEncryptData = true)

  implicit def mapCbs = CanBeSerialized[Map[String, String]]

  implicit val timeout = RouteTestTimeout(10 second span)

  trait TestRoutesSupport {
    lazy val sessionConfig           = spec.sessionConfig
    implicit def materializer        = spec.materializer
    implicit def ec                  = spec.executor
    implicit def sessionManager      = new SessionManager[Session](sessionConfig)
    implicit def refreshTokenStorage = null
  }
} 
开发者ID:Bii03,项目名称:students-clustering,代码行数:27,代码来源:BaseRoutesSpec.scala

示例6: OrchestratorRestServiceSpec

//设置package包名称以及导入依赖的类
package net.hvieira.orchestrator.service

import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{HttpRequest, StatusCodes}
import akka.http.scaladsl.testkit.{RouteTestTimeout, ScalatestRouteTest}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpec}

import scala.concurrent.duration._

class OrchestratorRestServiceSpec
  extends WordSpec
    with Matchers
    with BeforeAndAfterAll
    with ScalatestRouteTest {

  val route = new OrchestratorRestService().route

  "The service" should {

    "orchestrate requests in as a transaction" in {

      implicit val explicitTimeout = RouteTestTimeout(3 seconds)

      val request: HttpRequest = Get("/orchestrate/transaction")
      request ~> route ~> check {
        status shouldBe StatusCodes.OK
        handled shouldBe true
        entityAs[String]  should include regex "Google|DuckDuckGo|Yahoo"
      }
    }

    "orchestrate requests in parallel" in {

      implicit val explicitTimeout = RouteTestTimeout(3 seconds)

      val request: HttpRequest = Get("/orchestrate/parallel")
      request ~> route ~> check {
        status shouldBe StatusCodes.OK
        handled shouldBe true
        entityAs[String]  should include regex "<title>Google<\\/title>|<title>DuckDuckGo<\\/title>|<title>Yahoo<\\/title>"
      }
    }
  }

  override def afterAll(): Unit = {
    Http().shutdownAllConnectionPools()
  }

} 
开发者ID:hvieira,项目名称:akka-request-orchestrator,代码行数:50,代码来源:OrchestratorRestServiceSpec.scala

示例7: WebSocketRoutesHeartbeatTest

//设置package包名称以及导入依赖的类
package com.landoop.kafka.ws.routes

import akka.actor.ActorSystem
import akka.http.scaladsl.model.ws.TextMessage
import akka.http.scaladsl.testkit.{RouteTestTimeout, WSProbe}
import akka.util.Timeout
import com.landoop.kafka.ws.cluster.ClusterTestingCapabilities
import com.landoop.kafka.ws.core.ExtractValue
import com.landoop.kafka.ws.domain.responses._
import com.landoop.kafka.ws.{KafkaWSConfig, KafkaWSContext}

import scala.concurrent.duration._

class WebSocketRoutesHeartbeatTest extends BaseRouteTesting with ClusterTestingCapabilities {
  implicit val timeout = Timeout(10.seconds)
  implicit val routeTestTimeout = RouteTestTimeout(10.seconds)


  "WS heartbeat" should {

    "send heartbeat messages every 1 second" in {

      implicit val config: KafkaWSConfig = new KafkaWSConfig(
        "subscription-test",
        kafkaCluster.ZookeeperConnection,
        kafkaCluster.BrokersList,
        kafkaCluster.SchemaRegistryService.get.Endpoint,
        8787,
        heartbeatIntervalMs = 1000)

      implicit val context: KafkaWSContext = KafkaWSContext(config)
      implicit val extract = new ExtractValue()

      implicit val system = ActorSystem("testingActors")
      val wsClient = WSProbe()


      WS(s"/api/kafka/client1", wsClient.flow) ~>
        WebSocketRoutes().routes ~> check {
        isWebSocketUpgrade shouldEqual true

        val probe = wsClient.inProbe
        probe.ensureSubscription()


        val messages = probe.request(2).receiveWithin(2500.millis, 2)
        messages.size >=2  shouldBe true
        messages.foreach {
          case m: TextMessage.Strict =>
            m.text shouldBe HeartBeatResponse.Message.getStrictText
          case _ => fail("should have received heartbeats")
        }
      }

    }
  }
} 
开发者ID:Landoop,项目名称:kafka-ws,代码行数:58,代码来源:WebSocketRoutesHeartbeatTest.scala


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