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

Scala Span类代码示例

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

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



在下文中一共展示了Span类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
      }
  }
} 
开发者ID:zalando-incubator,项目名称:hutmann,代码行数:29,代码来源:PlayUnitSpec.scala


示例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")
    }
  }
} 
开发者ID:xiaozai512,项目名称:marathon,代码行数:29,代码来源:WaitTestSupport.scala


示例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 }
} 
开发者ID:jtonic,项目名称:handson-slick,代码行数:50,代码来源:TablesSuite.scala


示例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]
    }
  }
} 
开发者ID:akka,项目名称:alpakka,代码行数:49,代码来源:MemoryBufferSpec.scala


示例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))
      )
    )
  }

} 
开发者ID:akka,项目名称:alpakka,代码行数:56,代码来源:SplitAfterSizeSpec.scala


示例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()
  }

} 
开发者ID:AppMinistry,项目名称:scathon,代码行数:32,代码来源:TestBase.scala


示例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)
    }
  }
} 
开发者ID:99Taxis,项目名称:common-sqs,代码行数:41,代码来源:package.scala


示例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 =>
    }
  }

} 
开发者ID:zearom32,项目名称:Courses,代码行数:46,代码来源:SimulationSuite.scala


示例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)
      }
    }
  }
} 
开发者ID:VATBox,项目名称:polyjuicelib,代码行数:32,代码来源:Benchmarks.scala


示例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
    }
  }

} 
开发者ID:piotrglazar,项目名称:receipt-lottery,代码行数:33,代码来源:ResultFetcherTest.scala


示例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)
      }
    }
  }
} 
开发者ID:Tolsi,项目名称:matcher,代码行数:56,代码来源:SingleThreadOrderExecutorSpec.scala


示例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)
    }
  }
} 
开发者ID:markus1189,项目名称:sftp-integration,代码行数:28,代码来源:SftpSpec.scala


示例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
  }
} 
开发者ID:wex5,项目名称:dangchat-server,代码行数:56,代码来源:BaseAppSuite.scala


示例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"
    }
  }
} 
开发者ID:wex5,项目名称:dangchat-server,代码行数:38,代码来源:DownloadManagerSpec.scala


示例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()
    }
  }
} 
开发者ID:bazzo03,项目名称:users-api,代码行数:22,代码来源:Embedded.scala


示例16: TablesSuite

//设置package包名称以及导入依赖的类
import org.scalatest._
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{Seconds, Span}
import slick.jdbc.PostgresProfile.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 }
} 
开发者ID:flyours,项目名称:slick,代码行数:50,代码来源:TablesSuite.scala


示例17: PgSnapshotStoreSpec

//设置package包名称以及导入依赖的类
package akka.persistence.pg.testkit

import akka.persistence.pg.snapshot.PgSnapshotStore
import akka.persistence.pg.{PgExtension, PgConfig}
import akka.persistence.pg.util.RecreateSchema
import akka.persistence.snapshot.SnapshotStoreSpec
import akka.serialization.{Serialization, SerializationExtension}
import com.typesafe.config.ConfigFactory
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{Milliseconds, Second, Span}

import scala.language.postfixOps

class PgSnapshotStoreSpec extends SnapshotStoreSpec(ConfigFactory.load("pg-application.conf"))
  with PgSnapshotStore
  with RecreateSchema
  with ScalaFutures
  with PgConfig {

  override implicit val patienceConfig = PatienceConfig(timeout = Span(1, Second), interval = Span(100, Milliseconds))

  override lazy val pluginConfig = PgExtension(system).pluginConfig
  override val serialization: Serialization = SerializationExtension(system)

  import driver.api._

  override def beforeAll() {
    database.run(recreateSchema.andThen(snapshots.schema.create)).futureValue
    super.beforeAll()
  }

  override protected def afterAll(): Unit = {
    system.terminate()
    system.whenTerminated.futureValue
    ()
  }


} 
开发者ID:WegenenVerkeer,项目名称:akka-persistence-postgresql,代码行数:40,代码来源:PgSnapshotStoreSpec.scala


示例18: PgAsyncJournalSpec

//设置package包名称以及导入依赖的类
package akka.persistence.pg.testkit

import akka.persistence.CapabilityFlag
import akka.persistence.journal.JournalSpec
import akka.persistence.pg.journal.JournalTable
import akka.persistence.pg.util.{CreateTables, RecreateSchema}
import akka.persistence.pg.{PgConfig, PgExtension}
import com.typesafe.config.ConfigFactory
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{Milliseconds, Second, Span}

import scala.language.postfixOps

class PgAsyncJournalSpec extends JournalSpec(ConfigFactory.load("pg-application.conf"))
  with JournalTable
  with RecreateSchema
  with ScalaFutures
  with CreateTables
  with PgConfig {

  override implicit val patienceConfig = PatienceConfig(timeout = Span(1, Second), interval = Span(100, Milliseconds))

  override lazy val pluginConfig = PgExtension(system).pluginConfig

  import driver.api._

  override def beforeAll() {
    pluginConfig.database.run(recreateSchema
      .andThen(journals.schema.create)
    ).futureValue
    super.beforeAll()
  }

  override protected def afterAll(): Unit = {
    system.terminate()
    system.whenTerminated.futureValue
    ()
  }

  override protected def supportsRejectingNonSerializableObjects: CapabilityFlag = false
} 
开发者ID:WegenenVerkeer,项目名称:akka-persistence-postgresql,代码行数:42,代码来源:PgAsyncJournalSpec.scala


示例19: PgAsyncJournalPerfSpec

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

import akka.persistence.CapabilityFlag
import akka.persistence.journal.JournalPerfSpec
import akka.persistence.pg.util.{CreateTables, RecreateSchema}
import akka.persistence.pg.{PgConfig, PgExtension}
import com.typesafe.config.ConfigFactory
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{Milliseconds, Second, Span}
import org.slf4j.LoggerFactory

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

class PgAsyncJournalPerfSpec extends JournalPerfSpec(ConfigFactory.load("pg-perf-spec.conf"))
with RecreateSchema
with ScalaFutures
with CreateTables
with PgConfig {

  val logger = LoggerFactory.getLogger(getClass)

  override implicit val patienceConfig = PatienceConfig(timeout = Span(1, Second), interval = Span(100, Milliseconds))
  private val pgExtension: PgExtension = PgExtension(system)
  override lazy val pluginConfig = pgExtension.pluginConfig

  override def eventsCount = 5000
  override def awaitDurationMillis: Long = 30.seconds toMillis

  override def beforeAll() {
    database.run(recreateSchema
      .andThen(createTables)).futureValue
    super.beforeAll()
  }

  override def afterEach() = {
    pgExtension.whenDone(Future.successful(())).futureValue
    ()
  }

  override def afterAll() = {
    pgExtension.terminateWhenReady().futureValue
    ()
  }

  override protected def supportsRejectingNonSerializableObjects: CapabilityFlag = false
} 
开发者ID:WegenenVerkeer,项目名称:akka-persistence-postgresql,代码行数:49,代码来源:PgAsyncJournalPerfSpec.scala


示例20: BankProductRepositoryTest

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

import org.scalatest.concurrent.ScalaFutures
import com.knol.db.connection.H2DBComponent
import org.scalatest.FunSuite
import org.scalatest.time.Seconds
import org.scalatest.time.Millis
import org.scalatest.time.Span


class BankProductRepositoryTest extends FunSuite with BankProductRepository with H2DBComponent with ScalaFutures {

  implicit val defaultPatience = PatienceConfig(timeout = Span(5, Seconds), interval = Span(500, Millis))

  test("Add new Product ") {
    val response = create(BankProduct("car loan", 1))
    whenReady(response) { productId =>
      assert(productId === 3)
    }
  }

  test("Update bank product ") {
    val response = update(BankProduct("Home Loan", 1, Some(1)))
    whenReady(response) { res =>
      assert(res === 1)
    }
  }

  test("Delete  bank info  ") {
    val response = delete(1)
    whenReady(response) { res =>
      assert(res === 1)
    }
  }

  test("Get product list") {
    val products = getAll()
    whenReady(products) { result =>
      assert(result === List(BankProduct("home loan", 1, Some(1)), BankProduct("eduction loan", 1, Some(2))))
    }
  }

  test("Get bank and their product list") {
    val bankProduct = getBankWithProduct()
    whenReady(bankProduct) { result =>
      assert(result === List((Bank("SBI bank", Some(1)), BankProduct("home loan", 1, Some(1))), (Bank("SBI bank", Some(1)), BankProduct("eduction loan", 1, Some(2)))))
    }
  }

  test("Get all bank and  product list") {
    val bankProduct = getAllBankWithProduct()
    whenReady(bankProduct) { result =>
      assert(result === List((Bank("SBI bank", Some(1)), Some(BankProduct("home loan", 1, Some(1)))), (Bank("SBI bank", Some(1)), Some(BankProduct("eduction loan", 1, Some(2)))), (Bank("PNB bank", Some(2)), None)))
    }
  }
} 
开发者ID:satendrakumar,项目名称:generic-slick,代码行数:57,代码来源:BankProductRepositoryTest.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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