本文整理汇总了Scala中org.scalatest.FlatSpecLike类的典型用法代码示例。如果您正苦于以下问题:Scala FlatSpecLike类的具体用法?Scala FlatSpecLike怎么用?Scala FlatSpecLike使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FlatSpecLike类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: S3ClientSpec
//设置package包名称以及导入依赖的类
package akka.stream.alpakka.s3.scaladsl
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import com.typesafe.config.ConfigFactory
import org.scalatest.{FlatSpecLike, Matchers}
import akka.stream.alpakka.s3.Proxy
import scala.collection.JavaConverters._
class S3ClientSpec extends FlatSpecLike with Matchers {
it should "reuse application config from actor system" in {
val config = ConfigFactory.parseMap(
Map(
"akka.stream.alpakka.s3.proxy.host" -> "localhost",
"akka.stream.alpakka.s3.proxy.port" -> 8001,
"akka.stream.alpakka.s3.proxy.secure" -> false,
"akka.stream.alpakka.s3.path-style-access" -> true
).asJava
)
implicit val system = ActorSystem.create("s3", config)
implicit val materializer = ActorMaterializer()
val client = S3Client()
client.s3Settings.proxy shouldBe Some(Proxy("localhost", 8001, "http"))
client.s3Settings.pathStyleAccess shouldBe true
}
}
开发者ID:akka,项目名称:alpakka,代码行数:28,代码来源:S3ClientSpec.scala
示例2: 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
示例3: 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
示例4: AbstractSpec
//设置package包名称以及导入依赖的类
package core
import actors.Receptionist
import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, MustMatchers}
class AbstractSpec extends TestKit(ActorSystem("test-system"))
with FlatSpecLike
with ImplicitSender
with BeforeAndAfterAll
with MustMatchers {
val receptionist = system.actorOf(Receptionist.props(), "receptionist")
override def afterAll = {
TestKit.shutdownActorSystem(system)
}
}
开发者ID:Sengab-platform,项目名称:backend,代码行数:22,代码来源:AbstractSpec.scala
示例5: ReaperUTest
//设置package包名称以及导入依赖的类
package com.example.util
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import com.example.StopSystemAfterAll
import org.scalatest.{FlatSpecLike, ShouldMatchers}
class ReaperUTest
extends TestKit(ActorSystem("testsystem"))
with FlatSpecLike
with ShouldMatchers
with StopSystemAfterAll
with ImplicitSender {
import Reaper._
override def afterAll(): Unit = {
system.shutdown()
super.afterAll()
}
trait ReaperFixture {
val reaper = system.actorOf(Props(new TestReaper(testActor)))
val actor1 = TestProbe()
val actor2 = TestProbe()
val actor3 = TestProbe()
val actor4 = TestProbe()
}
"The Reaper" should "call the allSoulsReaped method after all watched actors are dead" in new ReaperFixture {
reaper ! WatchMe(actor3.ref)
reaper ! WatchMe(actor1.ref)
system.stop(actor1.ref)
system.stop(actor3.ref)
expectMsg("Dead")
}
it should "fail to call the allSoulsReaped method if not all watched actors are dead" in new ReaperFixture {
reaper ! WatchMe(actor3.ref)
reaper ! WatchMe(actor1.ref)
system.stop(actor1.ref)
expectNoMsg()
}
}
开发者ID:shafiquejamal,项目名称:akka-scala-reaper-seed,代码行数:49,代码来源:ReaperUTest.scala
示例6: JsonParsingSpec
//设置package包名称以及导入依赖的类
import com.fasterxml.jackson.core.JsonParseException
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import play.api.libs.json._
class JsonParsingSpec
extends Matchers
with FlatSpecLike
with BeforeAndAfterAll {
"A json parser" should "be able to parse valid json" in {
val input = """{
"foo": "bar",
"tags": [1,2,3],
"nested": [{
"fooz": "baz",
"id": 1
}]
}"""
val baz: JsValue = Json.parse(input)
}
it should "choke on invalid json" in {
val input = """{
"foo": "bar",
"tags": [1,2,3],
"nested": [{
"fooz": unquoted text,
"id": 1
}]
}"""
intercept[JsonParseException] {
val baz: JsValue = Json.parse(input)
}
}
}
开发者ID:rzrelyea,项目名称:scala-akka-web-crawler,代码行数:37,代码来源:JsonParsingSpec.scala
示例7: HelloAkkaSpec
//设置package包名称以及导入依赖的类
import org.scalatest.{ BeforeAndAfterAll, FlatSpecLike, Matchers }
import akka.actor.{ Actor, Props, ActorSystem }
import akka.testkit.{ ImplicitSender, TestKit, TestActorRef }
import scala.concurrent.duration._
class HelloAkkaSpec(_system: ActorSystem)
extends TestKit(_system)
with ImplicitSender
with Matchers
with FlatSpecLike
with BeforeAndAfterAll {
def this() = this(ActorSystem("HelloAkkaSpec"))
override def afterAll: Unit = {
system.shutdown()
system.awaitTermination(10.seconds)
}
"An HelloAkkaActor" should "be able to set a new greeting" in {
val greeter = TestActorRef(Props[Greeter])
greeter ! WhoToGreet("testkit")
greeter.underlyingActor.asInstanceOf[Greeter].greeting should be("hello, testkit")
}
it should "be able to get a new greeting" in {
val greeter = system.actorOf(Props[Greeter], "greeter")
greeter ! WhoToGreet("testkit")
greeter ! Greet
expectMsgType[Greeting].message.toString should be("hello, testkit")
}
}
开发者ID:rzrelyea,项目名称:scala-akka-web-crawler,代码行数:33,代码来源:HelloAkkaSpec.scala
示例8: UnhandledMessageWatcherSpec
//设置package包名称以及导入依赖的类
package com.tpalanga.newsletter.utils
import akka.actor.{Actor, ActorSystem, Props}
import akka.event.Logging.LogEvent
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import com.tpalanga.newsletter.util.UnhandledMessageWatcher
import org.scalatest.{FlatSpecLike, Matchers}
object UnhandledMessageWatcherSpec {
abstract class Test(implicit system: ActorSystem) {
val watcher = system.actorOf(UnhandledMessageWatcher.props())
val logProbe = TestProbe()
system.eventStream.subscribe(logProbe.ref, classOf[LogEvent])
val destination = system.actorOf(Props(new Actor {
override def receive: Receive = {
case 'Handled =>
}
}))
}
}
class UnhandledMessageWatcherSpec extends TestKit(ActorSystem("UnhandledMessageWatcherSpec")) with FlatSpecLike with Matchers with ImplicitSender {
import UnhandledMessageWatcherSpec._
"UnhandledMessageWatcher" should "log unhandled messages" in new Test {
destination ! 'Unhandled
val event = logProbe.fishForMessage() {
case akka.event.Logging.Error(_, _, _, msg) if msg.toString startsWith "UnhandledMessage:" =>
true
case _ =>
false
}
}
it should "log DeadLetters" in new Test {
system.stop(destination)
Thread.sleep(100)
destination ! 'Handled
val event = logProbe.fishForMessage() {
case akka.event.Logging.Warning(_, _, msg) if msg.toString startsWith "DeadLetter:" =>
true
case _ =>
false
}
}
}
开发者ID:tpalanga,项目名称:akka-http-microservice,代码行数:52,代码来源:UnhandledMessageWatcherSpec.scala
示例9: AmazonFineFoodManagerSpec
//设置package包名称以及导入依赖的类
package com.taintech.aff.actor
import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import com.taintech.aff.actor.AmazonFineFoodManager.{Review, ReviewParser}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, MustMatchers}
class AmazonFineFoodManagerSpec extends TestKit(ActorSystem("test-system"))
with FlatSpecLike
with ImplicitSender
with BeforeAndAfterAll
with MustMatchers {
import AmazonFineFoodManagerSpec._
"ReviewParser" should "parse test line with values test" in {
val rp = new ReviewParser()
rp.parse(testLine) must equal(Review("test3", "test2", "test10"))
}
}
object AmazonFineFoodManagerSpec {
val testLine = "test1,test2,test3,test4,test5,test6,test7,test8,test9,test10"
val mockReview: String => Review = _ => Review("test user", "test product", "test text")
}
开发者ID:taintech,项目名称:AmazonFineFoods,代码行数:29,代码来源:AmazonFineFoodManagerSpec.scala
示例10: StringCounterSpec
//设置package包名称以及导入依赖的类
package com.taintech.common.actor
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import StringCounter.{GetTopStrings, StringCount}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, MustMatchers}
class StringCounterSpec extends TestKit(ActorSystem("test-system"))
with FlatSpecLike
with ImplicitSender
with BeforeAndAfterAll
with MustMatchers {
override def afterAll {
TestKit.shutdownActorSystem(system)
}
"Counter Actor" should "handle GetTopString message with using TestProbe" in {
val sender = TestProbe()
val counter = system.actorOf(Props[StringCounter])
sender.send(counter, "a")
sender.send(counter, "c")
sender.send(counter, "c")
sender.send(counter, "b")
sender.send(counter, "b")
sender.send(counter, "c")
sender.send(counter, GetTopStrings(2))
val state = sender.expectMsgType[List[StringCount]]
state must equal(List(StringCount("c", 3), StringCount("b", 2)))
}
}
开发者ID:taintech,项目名称:AmazonFineFoods,代码行数:35,代码来源:StringCounterSpec.scala
示例11: 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
示例12: Parser
//设置package包名称以及导入依赖的类
package im.actor.util
import im.actor.server.api.rpc.service.messaging.CommandParser
import org.scalatest.{ Matchers, FlatSpecLike }
object Parser extends CommandParser
class CommandParserSpec extends FlatSpecLike with Matchers {
"Command parser" should "split command and text" in e1()
import Parser._
def e1() = {
parseCommand("/task kill") shouldEqual Some("task" ? Some("kill"))
parseCommand(" /task kill") shouldEqual Some("task" ? Some("kill"))
parseCommand(" /task kill all humans ") shouldEqual Some("task" ? Some("kill all humans"))
parseCommand("/task_fatal kill") shouldEqual Some("task_fatal" ? Some("kill"))
parseCommand("/task-fatal kill") shouldEqual Some("task-fatal" ? Some("kill"))
parseCommand("/sleep all day") shouldEqual Some("sleep" ? Some("all day"))
parseCommand("/task") shouldEqual Some("task" ? None)
parseCommand("/task: kill") shouldEqual None
parseCommand("this is not a /task") shouldEqual None
parseCommand("http://example.com") shouldEqual None
parseCommand("/home/rockjam/projectds") shouldEqual None
parseCommand(" / task kill") shouldEqual None
parseCommand(" task kill") shouldEqual None
parseCommand("Some text") shouldEqual None
parseCommand("#Some other text") shouldEqual None
parseCommand("\\Some text again") shouldEqual None
}
}
开发者ID:wex5,项目名称:dangchat-server,代码行数:35,代码来源:CommandParserSpec.scala
示例13: StringUtilsSpec
//设置package包名称以及导入依赖的类
package im.actor.util
import im.actor.util.misc.StringUtils.{ transliterate, validGlobalName }
import org.scalatest.{ Matchers, FlatSpecLike }
class StringUtilsSpec extends FlatSpecLike with Matchers {
"validNickName" should "validate nicknames" in nicknames
"transliterate" should "transform string to lower-cased string with only latin chars" in translit
def nicknames() = {
validGlobalName("rockjam") shouldEqual true
validGlobalName("abcde") shouldEqual true
validGlobalName("rock_jam") shouldEqual true
validGlobalName("r0ck_jaM___") shouldEqual true
//too long
val tooLong = 0 to 35 map (e ? ".") mkString ""
validGlobalName(tooLong) shouldEqual false
//too short
validGlobalName("roc") shouldEqual false
//wrong symbols
validGlobalName("rock-jam") shouldEqual false
validGlobalName("rock&^^jam") shouldEqual false
}
def translit() = {
transliterate("actor") shouldEqual "actor"
transliterate("?????") shouldEqual "akter"
transliterate("?????") shouldEqual "akter"
transliterate("??") shouldEqual "pai you"
transliterate("näyttelijä") shouldEqual "nayttelija"
transliterate("??") shouldEqual "yan yuan"
transliterate("??????") shouldEqual "almmthl"
transliterate("actor ????? ?? näyttelijä ?? ??????") shouldEqual "actor akter pai you nayttelija yan yuan almmthl"
}
}
开发者ID:wex5,项目名称:dangchat-server,代码行数:44,代码来源:StringUtilsSpec.scala
示例14: ReviewerActorSpec
//设置package包名称以及导入依赖的类
package io.github.jlprat.akka.http.workshop.bookstore.actor
import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import io.github.jlprat.akka.http.workshop.bookstore.model.{Author, Book, Review}
import Review._
import io.github.jlprat.akka.http.workshop.bookstore.actor.ReviewerActor._
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
class ReviewerActorSpec extends TestKit(ActorSystem("ReviewerActorSpec"))
with ImplicitSender with FlatSpecLike with Matchers with BeforeAndAfterAll {
override def afterAll {
TestKit.shutdownActorSystem(system)
}
"ReviewerActor" should "accept new reviews" in {
val reviewerActor = system.actorOf(ReviewerActor.props)
val book = Book("1234567", "The art of Doe", 321, Author("Jane Doe"))
val review = Review(author = Author("John Doe"), comment = "I liked it", stars = `*****`)
reviewerActor ! AddReview(review, book)
expectMsg(Success)
}
it should "return the reviews for a given book" in {
val reviewerActor = system.actorOf(ReviewerActor.props)
val book = Book("1234567", "The art of Doe", 321, Author("Jane Doe"))
val review = Review(author = Author("John Doe"), comment = "I liked it", stars = `*****`)
reviewerActor ! AddReview(review, book)
expectMsg(Success)
reviewerActor ! ListReviews(book)
expectMsg(Reviews(Seq(review)))
}
it should "return empty reviews if the book has none" in {
val reviewerActor = system.actorOf(ReviewerActor.props)
val book = Book("1234567", "The art of Doe", 321, Author("Jane Doe"))
reviewerActor ! ListReviews(book)
expectMsg(Reviews(Seq.empty))
}
it should "accept and return more than one review per book" in {
val reviewerActor = system.actorOf(ReviewerActor.props)
val book = Book("1234567", "The art of Doe", 321, Author("Jane Doe"))
val review1 = Review(author = Author("John Doe"), comment = "I liked it", stars = `*****`)
val review2 = Review(author = Author("Alice"), comment = "I liked it not", stars = `*`)
reviewerActor ! AddReview(review1, book)
expectMsg(Success)
reviewerActor ! AddReview(review2, book)
expectMsg(Success)
reviewerActor ! ListReviews(book)
expectMsg(Reviews(Seq(review2, review1)))
}
}
开发者ID:jlprat,项目名称:akka-http-workshop,代码行数:55,代码来源:ReviewerActorSpec.scala
示例15: LongActorRefPublisherSpec
//设置package包名称以及导入依赖的类
package com.example
import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, ActorMaterializerSettings, Supervision}
import akka.testkit.TestKit
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
class LongActorRefPublisherSpec extends TestKit(ActorSystem("test-system")) with FlatSpecLike with Matchers with BeforeAndAfterAll {
override def afterAll(): Unit = {
super.afterAll()
TestKit.shutdownActorSystem(system)
}
val decider: Supervision.Decider = {
case e => {
println(s"Stopping Stream.. ${e.getMessage}")
Supervision.Stop
}
}
implicit val materializer = ActorMaterializer.create(ActorMaterializerSettings.create(system)
.withDebugLogging(true)
.withSupervisionStrategy(decider)
.withAutoFusing(true), system)
"Advert ID Actor" should "work" in {
}
}
开发者ID:tonymurphy,项目名称:actor-publisher,代码行数:33,代码来源:LongActorRefPublisherSpec.scala
示例16: MessageBrokerMessageDispatcherUTest
//设置package包名称以及导入依赖的类
package plumbing
import akka.actor.ActorSystem
import akka.testkit.TestKit
import org.scalamock.scalatest.MockFactory
import org.scalatest.{FlatSpecLike, ShouldMatchers, Suite, BeforeAndAfterAll}
class MessageBrokerMessageDispatcherUTest
extends TestKit(ActorSystem("TestSystem"))
with FlatSpecLike
with ShouldMatchers
with StopSystemAfterAll
with MockFactory {
}
trait StopSystemAfterAll extends BeforeAndAfterAll {
this: TestKit with Suite =>
override protected def afterAll(): Unit = {
super.afterAll()
system.terminate()
}
}
开发者ID:shafiquejamal,项目名称:microservice-template-play,代码行数:27,代码来源:MessageBrokerMessageDispatcherUTest.scala
示例17: StreamUtilsSpec
//设置package包名称以及导入依赖的类
package com.bluelabs.akkaaws
import java.security.{DigestInputStream, MessageDigest}
import akka.actor.ActorSystem
import akka.stream.scaladsl.{Source, StreamConverters}
import akka.stream.{ActorMaterializer, ActorMaterializerSettings}
import akka.testkit.TestKit
import akka.util.ByteString
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{Millis, Seconds, Span}
import org.scalatest.{FlatSpecLike, Matchers}
import scala.concurrent.Future
class StreamUtilsSpec(_system: ActorSystem) extends TestKit(_system) with FlatSpecLike with Matchers with ScalaFutures {
def this() = this(ActorSystem("StreamUtilsSpec"))
implicit val materializer = ActorMaterializer(ActorMaterializerSettings(system).withDebugLogging(true))
implicit val defaultPatience =
PatienceConfig(timeout = Span(5, Seconds), interval = Span(30, Millis))
"digest" should "calculate the digest of a short string" in {
val bytes: Array[Byte] = "abcdefghijklmnopqrstuvwxyz".getBytes()
val flow: Future[ByteString] = Source.single(ByteString(bytes)).runWith(StreamUtils.digest())
val testDigest = MessageDigest.getInstance("SHA-256").digest(bytes)
whenReady(flow) { result =>
result should contain theSameElementsInOrderAs testDigest
}
}
it should "calculate the digest of a file" in {
val input = StreamConverters.fromInputStream(() => getClass.getResourceAsStream("/testdata.txt"))
val flow: Future[ByteString] = input.runWith(StreamUtils.digest())
val testDigest = MessageDigest.getInstance("SHA-256")
val dis: DigestInputStream = new DigestInputStream(getClass.getResourceAsStream("/testdata.txt"), testDigest)
val buffer = new Array[Byte](1024)
var bytesRead: Int = dis.read(buffer)
while (bytesRead > -1) {
bytesRead = dis.read(buffer)
}
whenReady(flow) { result =>
result should contain theSameElementsInOrderAs dis.getMessageDigest.digest()
}
}
}
开发者ID:bluelabsio,项目名称:s3-stream,代码行数:56,代码来源:StreamUtilsSpec.scala
示例18: TestKitSpec
//设置package包名称以及导入依赖的类
package suite
import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.{FlatSpecLike, BeforeAndAfterAll}
import org.scalatest.matchers.MustMatchers
abstract class TestKitSpec(name: String)
extends TestKit(ActorSystem(name))
with FlatSpecLike
with MustMatchers
with BeforeAndAfterAll
with ImplicitSender {
override def afterAll() {
system.shutdown()
}
}
开发者ID:byu-oit,项目名称:paul-akka-training-sandbox,代码行数:19,代码来源:TestKitSpec.scala
示例19: TestBase
//设置package包名称以及导入依赖的类
package io.github.maxkorolev
import akka.actor.ActorSystem
import akka.event.{ Logging, LoggingAdapter }
import akka.persistence.inmemory.extension.{ InMemoryJournalStorage, InMemorySnapshotStorage, StorageExtension }
import akka.testkit.{ ImplicitSender, TestKit, TestProbe }
import com.typesafe.config.ConfigFactory
import org.scalatest.{ BeforeAndAfterAll, BeforeAndAfterEach, FlatSpecLike, Matchers }
import scala.concurrent.ExecutionContext
class TestBase extends TestKit(ActorSystem("main", ConfigFactory.parseString(TestConfig.config)))
with FlatSpecLike with Matchers with BeforeAndAfterEach with BeforeAndAfterAll with ImplicitSender {
protected def log: LoggingAdapter = Logging(system, "app")
implicit lazy val ec: ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global
override def afterEach {
val probe = TestProbe()
probe.send(StorageExtension(system).journalStorage, InMemoryJournalStorage.ClearJournal)
probe.expectMsg(akka.actor.Status.Success(""))
probe.send(StorageExtension(system).snapshotStorage, InMemorySnapshotStorage.ClearSnapshots)
probe.expectMsg(akka.actor.Status.Success(""))
super.afterEach()
}
override def afterAll {
super.afterAll()
shutdown()
}
}
开发者ID:maxkorolev,项目名称:pix,代码行数:32,代码来源:TestBase.scala
示例20: ReaderTest
//设置package包名称以及导入依赖的类
package x7c1.chaff.reader
import org.scalatest.{FlatSpecLike, Matchers}
import scala.collection.mutable.ArrayBuffer
class ReaderTest extends FlatSpecLike with Matchers {
val getLength: Reader[String, Int] = Reader(_.length)
"Reader" can "behave like function" in {
val length = getLength run "hello"
length shouldBe 5
}
it should "have map" in {
val doubled = getLength map (_ * 2)
doubled run "hello" shouldBe 10
}
it should "have flatMap" in {
val doubled = getLength flatMap (n => Reader(_ => n * 2))
doubled run "hello" shouldBe 10
}
"Reader[A, Unit]" should "have append" in {
val buffer = ArrayBuffer[Int]()
val print: Int => Unit = buffer += _
val store1 = getLength map (n => print(n))
val store2 = getLength map (n => print(n * 2))
store1 append store2 run "hello"
buffer shouldBe Seq(5, 10)
}
"Seq[Reader[A, Unit]]" should "have uniteAll" in {
val buffer = ArrayBuffer[Int]()
val print: Int => Unit = buffer += _
val store1 = getLength map (n => print(n))
val store2 = getLength map (n => print(n * 2))
Seq(store1, store2).uniteAll run "hello"
buffer shouldBe Seq(5, 10)
}
}
开发者ID:x7c1,项目名称:Chaff,代码行数:48,代码来源:ReaderTest.scala
注:本文中的org.scalatest.FlatSpecLike类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论