本文整理汇总了Scala中akka.stream.testkit.scaladsl.TestSource类的典型用法代码示例。如果您正苦于以下问题:Scala TestSource类的具体用法?Scala TestSource怎么用?Scala TestSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestSource类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: HomeControllerSpec
//设置package包名称以及导入依赖的类
package controllers
import actors.TestKitSpec
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Keep
import akka.stream.testkit.scaladsl.{TestSink, TestSource}
import akka.testkit.TestProbe
import org.scalatest.MustMatchers
import play.api.libs.json.{JsValue, Json}
import scala.concurrent.ExecutionContext
class HomeControllerSpec extends TestKitSpec with MustMatchers {
"createWebSocketFlow" should {
"create a websocket flow and send a message through" in {
implicit val materializer = ActorMaterializer()(system)
implicit val ec: ExecutionContext = system.dispatcher
val stocksActor = TestProbe("stocksActor")
val userParentActor = TestProbe("userParentActor")
val userActor = TestProbe("userActor")
// http://doc.akka.io/docs/akka/2.4.4/scala/stream/stream-testkit.html
val publisher = akka.stream.testkit.TestPublisher.probe[JsValue]()
// instantiate the controller...
val controller = new HomeController(stocksActor.ref, userParentActor.ref)
// call method under test...
val flowUnderTest = controller.createWebSocketFlow(publisher, userActor.ref)
// create a test source and sink around the flow
val (pub, sub) = TestSource.probe[JsValue]
.via(flowUnderTest)
.toMat(TestSink.probe[JsValue])(Keep.both)
.run()
val jsvalue = Json.obj("herp" -> "derp")
// check that a message sent in will come out the other end
sub.request(n = 1)
publisher.sendNext(jsvalue)
sub.expectNext(jsvalue)
}
}
}
开发者ID:ChrisCooper,项目名称:customer-feedback-screen,代码行数:52,代码来源:HomeControllerSpec.scala
示例2: HTTPPollingActorSpec
//设置package包名称以及导入依赖的类
package polling
import java.time.Instant
import akka.NotUsed
import akka.actor.ActorSystem
import akka.http.scaladsl.model.ResponseEntity
import akka.stream.scaladsl.{Flow, Keep}
import akka.stream.testkit.scaladsl.{TestSink, TestSource}
import akka.testkit.TestKit
import org.json4s.JsonAST.JValue
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike}
class HTTPPollingActorSpec(_system: ActorSystem) extends TestKit(_system)
with FlatSpecLike with BeforeAndAfterAll {
override def afterAll = {
TestKit.shutdownActorSystem(system)
}
def testExchangeFlowPubSub(flow: Flow[(Instant, ResponseEntity), (String, JValue), NotUsed]) =
TestSource.probe[(Instant, ResponseEntity)]
.via(flow)
.toMat(TestSink.probe[(String, JValue)])(Keep.both)
}
开发者ID:blbradley,项目名称:kafka-cryptocoin,代码行数:27,代码来源:HTTPPollingActorSpec.scala
示例3: AccumulateSpecAutoFusingOn
//设置package包名称以及导入依赖的类
package akka.stream.contrib
import akka.stream.scaladsl.{ Keep, Source }
import akka.stream.testkit.scaladsl.{ TestSink, TestSource }
class AccumulateSpecAutoFusingOn extends { val autoFusing = true } with AccumulateSpec
class AccumulateSpecAutoFusingOff extends { val autoFusing = false } with AccumulateSpec
trait AccumulateSpec extends BaseStreamSpec {
"Accumulate" should {
"emit folded vaules starting with the result of applying the given function to the given zero and the first pushed element" in {
val (source, sink) = TestSource.probe[Int]
.via(Accumulate(0)(_ + _))
.toMat(TestSink.probe)(Keep.both)
.run()
sink.request(99)
source.sendNext(1)
source.sendNext(2)
source.sendNext(3)
sink.expectNext(1, 3, 6)
source.sendComplete()
sink.expectComplete()
}
"not emit any value for an empty source" in {
Source(Vector.empty[Int])
.via(Accumulate(0)(_ + _))
.runWith(TestSink.probe)
.request(99)
.expectComplete()
}
"fail on upstream failure" in {
val (source, sink) = TestSource.probe[Int]
.via(Accumulate(0)(_ + _))
.toMat(TestSink.probe)(Keep.both)
.run()
sink.request(99)
source.sendError(new Exception)
sink.expectError()
}
}
}
开发者ID:akka,项目名称:akka-stream-contrib,代码行数:45,代码来源:AccumulateSpec.scala
示例4: TimeWindowSpecAutoFusingOn
//设置package包名称以及导入依赖的类
package akka.stream.contrib
import akka.stream.scaladsl.Keep
import akka.stream.testkit.scaladsl.{ TestSink, TestSource }
import akka.testkit.TestDuration
import org.scalatest.concurrent.ScalaFutures
import scala.concurrent.duration._
class TimeWindowSpecAutoFusingOn extends { val autoFusing = true } with TimeWindowSpec
trait TimeWindowSpec extends BaseStreamSpec with ScalaFutures {
private val timeWindow = 100.milliseconds
"TimeWindow flow" should {
"aggregate data for predefined amount of time" in {
val summingWindow = TimeWindow(timeWindow.dilated, eager = false)(identity[Int])(_ + _)
val (pub, sub) = TestSource.probe[Int]
.via(summingWindow)
.toMat(TestSink.probe)(Keep.both)
.run
sub.request(2)
pub.sendNext(1)
pub.sendNext(1)
pub.sendNext(1)
pub.sendNext(1)
pub.sendNext(1)
sub.expectNext(timeWindow * 2, 5)
pub.sendNext(1)
pub.sendNext(1)
pub.sendNext(1)
pub.sendNext(1)
pub.sendNext(1)
sub.expectNext(timeWindow * 2, 5)
}
"emit the first seed if eager" in {
val summingWindow = TimeWindow(timeWindow.dilated, eager = true)(identity[Int])(_ + _)
val (pub, sub) = TestSource.probe[Int]
.via(summingWindow)
.toMat(TestSink.probe)(Keep.both)
.run
sub.request(2)
pub.sendNext(1)
sub.expectNext(1)
pub.sendNext(1)
pub.sendNext(1)
pub.sendNext(1)
pub.sendNext(1)
pub.sendNext(1)
sub.expectNext(5)
}
}
}
开发者ID:akka,项目名称:akka-stream-contrib,代码行数:62,代码来源:TimeWindowSpec.scala
注:本文中的akka.stream.testkit.scaladsl.TestSource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论