Stream Testkit: new-API-friendly (#29831)

This commit is contained in:
Enno Runne 2020-12-01 12:06:09 +01:00 committed by GitHub
parent 5db6a3a491
commit ffb21da246
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 86 additions and 26 deletions

View file

@ -328,8 +328,8 @@ class GraphStageDocSpec extends AkkaSpec {
val switch = Promise[Unit]()
val duplicator = Flow.fromGraph(new KillSwitch[Int](switch.future))
val in = TestPublisher.probe[Int]()
val out = TestSubscriber.probe[Int]()
val in = TestPublisher.Probe[Int]()
val out = TestSubscriber.Probe[Int]()
Source
.fromPublisher(in)
@ -524,8 +524,8 @@ class GraphStageDocSpec extends AkkaSpec {
Await.result(result1, 3.seconds) should ===(Vector(1, 2, 3))
val subscriber = TestSubscriber.manualProbe[Int]()
val publisher = TestPublisher.probe[Int]()
val subscriber = TestSubscriber.ManualProbe[Int]()
val publisher = TestPublisher.Probe[Int]()
val flow2 =
Source.fromPublisher(publisher).via(new TwoBuffer).to(Sink.fromSubscriber(subscriber))

View file

@ -88,7 +88,7 @@ class RateTransformationDocSpec extends AkkaSpec {
case (d, _) => latch.countDown(); Iterator.from(1).map(d -> _)
}
val (pub, sub) = TestSource.probe[Double].via(realDriftFlow).toMat(TestSink.probe[(Double, Int)])(Keep.both).run()
val (pub, sub) = TestSource.probe[Double].via(realDriftFlow).toMat(TestSink[(Double, Int)]())(Keep.both).run()
sub.request(1)
pub.sendNext(1.0)
@ -109,7 +109,7 @@ class RateTransformationDocSpec extends AkkaSpec {
val latch = TestLatch(2)
val realDriftFlow = Flow[Double].expand(d => { latch.countDown(); Iterator.from(0).map(d -> _) })
val (pub, sub) = TestSource.probe[Double].via(realDriftFlow).toMat(TestSink.probe[(Double, Int)])(Keep.both).run()
val (pub, sub) = TestSource.probe[Double].via(realDriftFlow).toMat(TestSink[(Double, Int)]())(Keep.both).run()
sub.request(1)
pub.sendNext(1.0)

View file

@ -112,7 +112,7 @@ class StreamTestKitDocSpec extends AkkaSpec {
//#test-sink-probe
val sourceUnderTest = Source(1 to 4).filter(_ % 2 == 0).map(_ * 2)
sourceUnderTest.runWith(TestSink.probe[Int]).request(2).expectNext(4, 8).expectComplete()
sourceUnderTest.runWith(TestSink[Int]()).request(2).expectNext(4, 8).expectComplete()
//#test-sink-probe
}
@ -142,7 +142,7 @@ class StreamTestKitDocSpec extends AkkaSpec {
pattern.after(10.millis * sleep, using = system.scheduler)(Future.successful(sleep))
}
val (pub, sub) = TestSource.probe[Int].via(flowUnderTest).toMat(TestSink.probe[Int])(Keep.both).run()
val (pub, sub) = TestSource.probe[Int].via(flowUnderTest).toMat(TestSink[Int]())(Keep.both).run()
sub.request(n = 3)
pub.sendNext(3)

View file

@ -32,13 +32,13 @@ class RecipeAdhocSource extends RecipeSpec {
"not start the source if there is no demand" taggedAs TimingTest in {
val isStarted = new AtomicBoolean()
adhocSource(Source.empty.mapMaterializedValue(_ => isStarted.set(true)), 200.milliseconds, 3)
.runWith(TestSink.probe[Int])
.runWith(TestSink[Int]())
Thread.sleep(300)
isStarted.get() should be(false)
}
"start the source when there is a demand" taggedAs TimingTest in {
val sink = adhocSource(Source.repeat("a"), 200.milliseconds, 3).runWith(TestSink.probe[String])
val sink = adhocSource(Source.repeat("a"), 200.milliseconds, 3).runWith(TestSink[String]())
sink.requestNext("a")
}
@ -46,7 +46,7 @@ class RecipeAdhocSource extends RecipeSpec {
val shutdown = Promise[Done]()
val sink = adhocSource(Source.repeat("a").watchTermination() { (_, term) =>
shutdown.completeWith(term)
}, 200.milliseconds, 3).runWith(TestSink.probe[String])
}, 200.milliseconds, 3).runWith(TestSink[String]())
sink.requestNext("a")
Thread.sleep(200)
@ -57,7 +57,7 @@ class RecipeAdhocSource extends RecipeSpec {
val shutdown = Promise[Done]()
val sink = adhocSource(Source.repeat("a").watchTermination() { (_, term) =>
shutdown.completeWith(term)
}, 200.milliseconds, 3).runWith(TestSink.probe[String])
}, 200.milliseconds, 3).runWith(TestSink[String]())
sink.requestNext("a")
Thread.sleep(100)
@ -81,7 +81,7 @@ class RecipeAdhocSource extends RecipeSpec {
val sink = adhocSource(source.watchTermination() { (_, term) =>
shutdown.completeWith(term)
}, 200.milliseconds, 3).runWith(TestSink.probe[String])
}, 200.milliseconds, 3).runWith(TestSink[String]())
sink.requestNext("a")
startedCount.get() should be(1)
@ -97,7 +97,7 @@ class RecipeAdhocSource extends RecipeSpec {
val sink = adhocSource(source.watchTermination() { (_, term) =>
shutdown.completeWith(term)
}, 200.milliseconds, 3).runWith(TestSink.probe[String])
}, 200.milliseconds, 3).runWith(TestSink[String]())
sink.requestNext("a")
startedCount.get() should be(1)

View file

@ -12,12 +12,12 @@ class RecipeDroppyBroadcast extends RecipeSpec {
"Recipe for a droppy broadcast" must {
"work" in {
val pub = TestPublisher.probe[Int]()
val pub = TestPublisher.Probe[Int]()
val myElements = Source.fromPublisher(pub)
val sub1 = TestSubscriber.manualProbe[Int]()
val sub2 = TestSubscriber.manualProbe[Int]()
val sub3 = TestSubscriber.probe[Int]()
val sub1 = TestSubscriber.ManualProbe[Int]()
val sub2 = TestSubscriber.ManualProbe[Int]()
val sub3 = TestSubscriber.Probe[Int]()
val futureSink = Sink.head[Seq[Int]]
val mySink1 = Sink.fromSubscriber(sub1)
val mySink2 = Sink.fromSubscriber(sub2)