本文整理汇总了Scala中org.scalatest.time.Span类的典型用法代码示例。如果您正苦于以下问题:Scala Span类的具体用法?Scala Span怎么用?Scala Span使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Span类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: myPublicAddress
//设置package包名称以及导入依赖的类
package org.zalando.hutmann.spec
import org.scalatest.concurrent.PatienceConfiguration.Interval
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{ Seconds, Span }
import org.scalatestplus.play.{ PlaySpec, PortNumber, WsScalaTestClient }
import play.api.Application
import play.api.http.{ HeaderNames, MimeTypes }
import play.api.libs.ws.{ WSClient, WSResponse }
trait PlayUnitSpec extends PlaySpec with ScalaFutures with WsScalaTestClient {
def myPublicAddress(): String
implicit val portNumber: PortNumber
def callWs(testPaymentGatewayURL: String)(implicit app: Application): WSResponse = {
implicit val wSClient = app.injector.instanceOf[WSClient]
val callbackURL = s"http://${myPublicAddress()}/callback"
whenReady(
wsUrl(testPaymentGatewayURL)
.withQueryStringParameters("callbackURL" -> callbackURL)
.withHttpHeaders(HeaderNames.ACCEPT -> MimeTypes.TEXT)
.get(),
Interval(Span(10, Seconds))
) { result =>
result
}
}
}
示例2: WaitTestSupport
//设置package包名称以及导入依赖的类
package mesosphere.marathon
package integration.setup
import org.scalatest.concurrent.Eventually
import org.scalatest.time.{ Milliseconds, Span }
import scala.concurrent.duration._
object WaitTestSupport extends Eventually {
def validFor(description: String, until: FiniteDuration)(valid: => Boolean): Boolean = {
val deadLine = until.fromNow
def checkValid(): Boolean = {
if (!valid) throw new IllegalStateException(s"$description not valid for $until. Give up.")
if (deadLine.isOverdue()) true else {
Thread.sleep(100)
checkValid()
}
}
checkValid()
}
def waitUntil(description: String, maxWait: FiniteDuration)(fn: => Boolean): Unit = {
eventually(timeout(Span(maxWait.toMillis, Milliseconds))) {
if (!fn) throw new RuntimeException(s"$description not satisfied")
}
}
}
示例3: TablesSuite
//设置package包名称以及导入依赖的类
import org.scalatest._
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{Seconds, Span}
import slick.driver.H2Driver.api._
import slick.jdbc.meta._
class TablesSuite extends FunSuite with BeforeAndAfter with ScalaFutures {
implicit override val patienceConfig = PatienceConfig(timeout = Span(5, Seconds))
val suppliers = TableQuery[Suppliers]
val coffees = TableQuery[Coffees]
var db: Database = _
def createSchema() =
db.run((suppliers.schema ++ coffees.schema).create).futureValue
def insertSupplier(): Int =
db.run(suppliers += (101, "Acme, Inc.", "99 Market Street", "Groundsville", "CA", "95199")).futureValue
before { db = Database.forConfig("h2mem1") }
test("Creating the Schema works") {
createSchema()
val tables = db.run(MTable.getTables).futureValue
assert(tables.size == 2)
assert(tables.count(_.name.name.equalsIgnoreCase("suppliers")) == 1)
assert(tables.count(_.name.name.equalsIgnoreCase("coffees")) == 1)
}
test("Inserting a Supplier works") {
createSchema()
val insertCount = insertSupplier()
assert(insertCount == 1)
}
test("Query Suppliers works") {
createSchema()
insertSupplier()
val results = db.run(suppliers.result).futureValue
assert(results.size == 1)
assert(results.head._1 == 101)
}
after { db.close }
}
示例4: MemoryBufferSpec
//设置package包名称以及导入依赖的类
package akka.stream.alpakka.s3.impl
import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, ActorMaterializerSettings}
import akka.stream.scaladsl.{Sink, Source}
import akka.testkit.TestKit
import akka.util.ByteString
import org.scalatest.time.{Millis, Seconds, Span}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import org.scalatest.concurrent.ScalaFutures
class MemoryBufferSpec(_system: ActorSystem)
extends TestKit(_system)
with FlatSpecLike
with Matchers
with BeforeAndAfterAll
with ScalaFutures {
def this() = this(ActorSystem("MemoryBufferSpec"))
implicit val defaultPatience =
PatienceConfig(timeout = Span(5, Seconds), interval = Span(30, Millis))
implicit val materializer = ActorMaterializer(ActorMaterializerSettings(system).withDebugLogging(true))
"MemoryBuffer" should "emit a chunk on its output containg the concatenation of all input values" in {
val result = Source(Vector(ByteString(1, 2, 3, 4, 5), ByteString(6, 7, 8, 9, 10, 11, 12), ByteString(13, 14)))
.via(new MemoryBuffer(200))
.runWith(Sink.seq)
.futureValue
result should have size (1)
val chunk = result.head
chunk.size should be(14)
chunk.data.runWith(Sink.seq).futureValue should be(Seq(ByteString(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)))
}
it should "fail if more than maxSize bytes are fed into it" in {
whenReady(
Source(Vector(ByteString(1, 2, 3, 4, 5), ByteString(6, 7, 8, 9, 10, 11, 12), ByteString(13, 14)))
.via(new MemoryBuffer(10))
.runWith(Sink.seq)
.failed
) { e =>
e shouldBe a[IllegalStateException]
}
}
}
示例5: SplitAfterSizeSpec
//设置package包名称以及导入依赖的类
package akka.stream.alpakka.s3.impl
import akka.testkit.TestKit
import akka.stream.ActorMaterializerSettings
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import akka.stream.ActorMaterializer
import akka.actor.ActorSystem
import org.scalatest.Matchers
import org.scalatest.FlatSpecLike
import akka.stream.scaladsl.Source
import akka.stream.scaladsl.Flow
import akka.util.ByteString
import akka.stream.scaladsl.Sink
import org.scalatest.time.{Millis, Seconds, Span}
import scala.concurrent.duration._
class SplitAfterSizeSpec(_system: ActorSystem)
extends TestKit(_system)
with FlatSpecLike
with Matchers
with BeforeAndAfterAll
with ScalaFutures {
def this() = this(ActorSystem("SplitAfterSizeSpec"))
implicit val defaultPatience =
PatienceConfig(timeout = Span(5, Seconds), interval = Span(30, Millis))
implicit val materializer = ActorMaterializer(ActorMaterializerSettings(system).withDebugLogging(true))
"SplitAfterSize" should "yield a single empty substream on no input" in {
Source
.empty[ByteString]
.via(
SplitAfterSize(10)(Flow[ByteString]).concatSubstreams
)
.runWith(Sink.seq)
.futureValue should be(Seq.empty)
}
it should "start a new stream after the element that makes it reach a maximum, but not split the element itself" in {
Source(Vector(ByteString(1, 2, 3, 4, 5), ByteString(6, 7, 8, 9, 10, 11, 12), ByteString(13, 14)))
.via(
SplitAfterSize(10)(Flow[ByteString]).prefixAndTail(10).map { case (prefix, tail) => prefix }.concatSubstreams
)
.runWith(Sink.seq)
.futureValue should be(
Seq(
Seq(ByteString(1, 2, 3, 4, 5), ByteString(6, 7, 8, 9, 10, 11, 12)),
Seq(ByteString(13, 14))
)
)
}
}
示例6: TestBase
//设置package包名称以及导入依赖的类
package uk.co.appministry.scathon.client
import org.scalatest.concurrent._
import org.scalatest.time.{Millis, Seconds, Span}
import org.scalatest.{BeforeAndAfterAll, Inside, Matchers, WordSpec}
import uk.co.appministry.scathon.testServer.TestMarathon
class TestBase extends WordSpec
with Eventually
with ScalaFutures
with Inside
with Matchers
with BeforeAndAfterAll
with AsyncAssertions {
implicit override val patienceConfig = PatienceConfig(timeout = scaled(Span(10, Seconds)), interval = scaled(Span(100, Millis)))
var client: Client = _
var server: TestMarathon = _
override def beforeAll: Unit = {
server = new TestMarathon
server.start()
client = new Client(port = server.port.get)
}
override def afterAll: Unit = {
server.stop()
}
}
示例7: 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)
}
}
}
示例8: SimulationSuite
//设置package包名称以及导入依赖的类
package practice
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.exceptions.{TestCanceledException, TestFailedDueToTimeoutException}
import org.scalatest.junit.JUnitRunner
import org.scalatest.time.{Millis, Span, Seconds}
import org.scalatest.concurrent.Timeouts._
@RunWith(classOf[JUnitRunner])
class SimulationSuite extends FunSuite{
object sim extends Circuits with Parameters
import sim._
test("a simple test"){
val in1, in2, sum, carry = new Wire
probe("sum", sum)
probe("carry", carry)
halfAdder(in1, in2, sum, carry)
in1.setSignal(true)
sim.run()
in2.setSignal(true)
sim.run()
assert(carry.getSignal == true)
assert(sum.getSignal == false)
}
test("will not terminate") {
try {
cancelAfter(Span(10, Seconds)) {
val in3 = new Wire
probe("in3", in3)
inverter(in3, in3)
sim.run()
}
}
catch {
case x:TestCanceledException =>
}
}
}
示例9: Benchmarks
//设置package包名称以及导入依赖的类
package com.vatbox.polyjuice
import com.vatbox.polyjuice.internal.PolyjuiceMapper
import generators.Generator
import org.json4s.native.Serialization
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.time.{Millis, Minutes, Span}
import org.scalatest.{FreeSpec, Matchers, OptionValues, TryValues}
import scala.concurrent.ExecutionContext.Implicits.global
class Benchmarks extends FreeSpec with TryValues with OptionValues with Matchers with ScalaFutures with GeneratorDrivenPropertyChecks {
implicit val formats = org.json4s.DefaultFormats
val amount = 10000
override implicit val patienceConfig = PatienceConfig(Span(1, Minutes), Span(10, Millis))
val mapper: PolyjuiceMapper = Polyjuice.createMapper(varName = "model", userCode = s"""if (model.bool) return model.int; else return model.str;""")
"Map many" in {
forAll(Generator.modelGen, minSuccessful(amount)) { model =>
val json = Serialization.write(model)
if (model.bool) {
val result = mapper.map[Int](json).futureValue.get
assert(result === model.int)
}
else {
val result = mapper.map[String](json).futureValue.get
assert(result === model.str)
}
}
}
}
示例10: ResultFetcherTest
//设置package包名称以及导入依赖的类
package com.piotrglazar.receiptlottery.core
import com.piotrglazar.receiptlottery.Token
import com.piotrglazar.receiptlottery.utils.ScalajHttpAdapter
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.prop.TableDrivenPropertyChecks._
import org.scalatest.time.{Seconds, Span}
import org.scalatest.{FlatSpec, Matchers}
import scala.concurrent.ExecutionContext.Implicits.global
class ResultFetcherTest extends FlatSpec with Matchers with ScalaFutures {
implicit val timeout = PatienceConfig(Span(1, Seconds))
val resultFetcher = new ResultFetcher("https://loteriaparagonowa.gov.pl/wyniki", new ScalajHttpAdapter(2000), global)
val tokens = Table(("token", "result"),
(Token("D2T1UGL9M34"), true),
(Token("C91B2MGBM5F"), false))
"ResultFetcher" should "find result for token" in {
forAll(tokens) { (token: Token, expectedResult: Boolean) =>
// when
val result = resultFetcher.hasResult(token)
// then
result.futureValue shouldBe expectedResult
}
}
}
示例11: 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)
}
}
}
}
示例12: SftpSpec
//设置package包名称以及导入依赖的类
package org.markushauck.sftp
import com.whisk.docker.impl.spotify.DockerKitSpotify
import org.scalatest._
import org.scalactic._
import com.whisk.docker.scalatest._
import org.scalatest.time.{Second, Seconds, Span}
class SftpSpec
extends WordSpec
with Matchers
with TypeCheckedTripleEquals
with DockerTestKit
with DockerKitSpotify
with DockerSftpService {
implicit val pc = PatienceConfig(Span(20, Seconds), Span(1, Second))
"Sftp example" should {
"use the docker container" in {
val result = Main.listSftp(SftpConfig(sftpUser, sftpPassword, "localhost", exposedSftpPort))
result should have length 3
result.exists(lsEntry => lsEntry.getFilename == sftpDirectory) should ===(true)
}
}
}
示例13: BaseAppSuite
//设置package包名称以及导入依赖的类
package im.actor.server
import java.time.Instant
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{ Seconds, Span }
import org.scalatest.{ FlatSpecLike, Inside, Matchers }
import scala.concurrent.ExecutionContext
import im.actor.server.db.DbExtension
import im.actor.server.migrations.v2.{ MigrationNameList, MigrationTsActions }
abstract class BaseAppSuite(_system: ActorSystem = {
ActorSpecification.createSystem()
})
extends ActorSuite(_system)
with FlatSpecLike
with ScalaFutures
with MessagingSpecHelpers
with Matchers
with Inside
with ServiceSpecMatchers
with ServiceSpecHelpers
with ActorSerializerPrepare {
protected implicit val materializer: ActorMaterializer = ActorMaterializer()
implicit lazy val ec: ExecutionContext = _system.dispatcher
protected implicit lazy val (db, conn) = {
DbExtension(_system).clean()
DbExtension(_system).migrate()
val ext = DbExtension(_system)
(ext.db, ext.connector)
}
system.log.debug("Writing migration timestamps")
MigrationTsActions.insertTimestamp(
MigrationNameList.MultiSequence,
Instant.now.toEpochMilli
)(conn)
MigrationTsActions.insertTimestamp(
MigrationNameList.GroupsV2,
Instant.now.toEpochMilli
)(conn)
override implicit def patienceConfig: PatienceConfig =
new PatienceConfig(timeout = Span(15, Seconds))
override protected def beforeAll(): Unit = {
super.beforeAll()
db
}
}
示例14: DownloadManagerSpec
//设置package包名称以及导入依赖的类
package im.actor.util.http
import java.math.BigInteger
import java.nio.file.Files
import java.security.MessageDigest
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{ Span, Seconds }
import org.scalatest.{ FlatSpec, Matchers }
class DownloadManagerSpec extends FlatSpec with ScalaFutures with Matchers {
it should "Download https files" in e1
override implicit def patienceConfig: PatienceConfig =
new PatienceConfig(timeout = Span(10, Seconds))
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
val downloadManager = new DownloadManager()
def e1() = {
whenReady(downloadManager.download("https://ajax.googleapis.com/ajax/libs/webfont/1.5.18/webfont.js")) {
case (path, size) ?
val fileBytes = Files.readAllBytes(path)
fileBytes.length shouldEqual size
val md = MessageDigest.getInstance("MD5")
val hexDigest = new BigInteger(1, md.digest(fileBytes)) toString (16)
hexDigest shouldEqual "593e60ad549e46f8ca9a60755336c7df"
}
}
}
示例15: aultPatientConfig
//设置package包名称以及导入依赖的类
package co.s4n.infrastructure.database
import org.cassandraunit.utils.EmbeddedCassandraServerHelper
import org.scalatest.time.{ Millis, Seconds, Span }
import scala.concurrent.duration._
trait CassandraSpec extends TestSuite {
implicit val defaultPatientConfig =
PatienceConfig(timeout = Span(15, Seconds), interval = Span(500, Millis))
override def beforeAll(): Unit = {
synchronized {
EmbeddedCassandraServerHelper
.startEmbeddedCassandra("embedded-cassandra.yaml", 120.seconds.toMillis)
database.create(5.seconds)
super.beforeAll()
}
}
}