diff --git a/akka-bench-jmh-dev/src/main/scala/akka/stream/FlowMapBenchmark.scala b/akka-bench-jmh-dev/src/main/scala/akka/stream/FlowMapBenchmark.scala index ea94481982..f318f53910 100644 --- a/akka-bench-jmh-dev/src/main/scala/akka/stream/FlowMapBenchmark.scala +++ b/akka-bench-jmh-dev/src/main/scala/akka/stream/FlowMapBenchmark.scala @@ -99,7 +99,7 @@ class FlowMapBenchmark { } } - flow = mkMaps(Source(syncTestPublisher), numberOfMapOps) { + flow = mkMaps(Source.fromPublisher(syncTestPublisher), numberOfMapOps) { if (UseGraphStageIdentity) GraphStages.identity[Int] else diff --git a/akka-bench-jmh-dev/src/main/scala/akka/stream/io/FileSourcesBenchmark.scala b/akka-bench-jmh-dev/src/main/scala/akka/stream/io/FileSourcesBenchmark.scala index a043908b43..f437ef41ad 100644 --- a/akka-bench-jmh-dev/src/main/scala/akka/stream/io/FileSourcesBenchmark.scala +++ b/akka-bench-jmh-dev/src/main/scala/akka/stream/io/FileSourcesBenchmark.scala @@ -34,7 +34,7 @@ class FileSourcesBenchmark { val f = File.createTempFile(getClass.getName, ".bench.tmp") f.deleteOnExit() - val ft = Source(() ⇒ Iterator.continually(line)) + val ft = Source.fromIterator(() ⇒ Iterator.continually(line)) .take(10 * 39062) // adjust as needed .runWith(Sink.file(f)) Await.result(ft, 30.seconds) @@ -53,7 +53,7 @@ class FileSourcesBenchmark { def setup() { fileChannelSource = Source.file(file, bufSize) fileInputStreamSource = Source.inputStream(() ⇒ new FileInputStream(file), bufSize) - ioSourceLinesIterator = Source(() ⇒ scala.io.Source.fromFile(file).getLines()).map(ByteString(_)) + ioSourceLinesIterator = Source.fromIterator(() ⇒ scala.io.Source.fromFile(file).getLines()).map(ByteString(_)) } @TearDown diff --git a/akka-docs-dev/rst/java/code/docs/MigrationsJava.java b/akka-docs-dev/rst/java/code/docs/MigrationsJava.java index ca3ffe0559..b4d7ab5133 100644 --- a/akka-docs-dev/rst/java/code/docs/MigrationsJava.java +++ b/akka-docs-dev/rst/java/code/docs/MigrationsJava.java @@ -1,12 +1,16 @@ package docs; +import akka.actor.ActorSystem; import akka.actor.Cancellable; import akka.http.javadsl.model.Uri; +import akka.dispatch.Futures; import akka.japi.function.Creator; import akka.japi.Pair; import akka.japi.function.Function; import akka.stream.*; import akka.stream.javadsl.*; +import akka.stream.testkit.TestPublisher; +import akka.stream.testkit.TestSubscriber; import akka.util.ByteString; import scala.Option; import scala.concurrent.Future; @@ -14,6 +18,9 @@ import scala.concurrent.duration.FiniteDuration; import scala.concurrent.Promise; import scala.runtime.BoxedUnit; +import org.reactivestreams.Publisher; +import org.reactivestreams.Subscriber; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -25,6 +32,7 @@ public class MigrationsJava { // This is compile-only code, no need for actually running anything. public static ActorMaterializer mat = null; + public static ActorSystem sys = null; public static class SomeInputStream extends InputStream { public SomeInputStream() {} @@ -133,12 +141,34 @@ public class MigrationsJava { // Complete the promise with an empty option to emulate the old lazyEmpty promise.trySuccess(scala.Option.empty()); - final Source sourceUnderTest = Source.tick( + final Source ticks = Source.tick( FiniteDuration.create(0, TimeUnit.MILLISECONDS), FiniteDuration.create(200, TimeUnit.MILLISECONDS), "tick"); + + final Source pubSource = + Source.fromPublisher(TestPublisher.manualProbe(true, sys)); + + final Source futSource = + Source.fromFuture(Futures.successful(42)); + + final Source> subSource = + Source.asSubscriber(); //#source-creators + //#sink-creators + final Sink subSink = + Sink.fromSubscriber(TestSubscriber.manualProbe(sys)); + //#sink-creators + + //#sink-as-publisher + final Sink> pubSink = + Sink.asPublisher(false); + + final Sink> pubSinkFanout = + Sink.asPublisher(true); + //#sink-as-publisher + //#empty-flow Flow emptyFlow = Flow.create(); // or diff --git a/akka-docs-dev/rst/java/migration-guide-1.0-2.x-java.rst b/akka-docs-dev/rst/java/migration-guide-1.0-2.x-java.rst index b68e833a3f..8799dfdfac 100644 --- a/akka-docs-dev/rst/java/migration-guide-1.0-2.x-java.rst +++ b/akka-docs-dev/rst/java/migration-guide-1.0-2.x-java.rst @@ -224,13 +224,14 @@ should be replaced by Source constructor name changes =============================== -``Source.lazyEmpty`` have been replaced by ``Source.maybe`` which returns a ``Promise`` that can be completed by one or +``Source.lazyEmpty`` has been replaced by ``Source.maybe`` which returns a ``Promise`` that can be completed by one or zero elements by providing an ``Option``. This is different from ``lazyEmpty`` which only allowed completion to be sent, but no elements. -The ``from()`` overload on ``Source`` that provide a tick source (``Source.from(delay,interval,tick)``) -is replaced by the named method ``Source.tick()`` to reduce the number of overloads and to make the function more -discoverable. +The ``from()`` overload on ``Source`` has been refactored to separate methods to reduce the number of overloads and +make source creation more discoverable. + +``Source.subscriber`` has been renamed to ``Source.asSubscriber``. Update procedure ---------------- @@ -238,6 +239,9 @@ Update procedure 1. All uses of ``Source.lazyEmpty`` should be replaced by ``Source.maybe`` and the returned ``Promise`` completed with a ``None`` (an empty ``Option``) 2. Replace all uses of ``Source.from(delay,interval,tick)`` with the method ``Source.tick(delay,interval,tick)`` +3. Replace all uses of ``Source.from(publisher)`` with the method ``Source.fromPublisher(publisher)`` +4. Replace all uses of ``Source.from(future)`` with the method ``Source.fromFuture(future))`` +5. Replace all uses of ``Source.subscriber`` with the method ``Source.asSubscriber`` Example ^^^^^^^ @@ -250,15 +254,51 @@ Example promise.trySuccess(BoxedUnit.UNIT); // This no longer works! - final Source sourceUnderTest = Source.from( + final Source ticks = Source.from( FiniteDuration.create(0, TimeUnit.MILLISECONDS), FiniteDuration.create(200, TimeUnit.MILLISECONDS), "tick"); + // This no longer works! + final Source pubSource = + Source.from(TestPublisher.manualProbe(true, sys)); + + // This no longer works! + final Source futSource = + Source.from(Futures.successful(42)); + + // This no longer works! + final Source> subSource = + Source.subscriber(); + should be replaced by .. includecode:: code/docs/MigrationsJava.java#source-creators +Sink constructor name changes +============================= + +``Sink.create(subscriber)`` has been renamed to ``Sink.fromSubscriber(subscriber)`` to reduce the number of overloads and +make sink creation more discoverable. + +Update procedure +---------------- + +1. Replace all uses of ``Sink.create(subscriber)`` with the method ``Sink.fromSubscriber(subscriber)`` + +Example +^^^^^^^ + +:: + + // This no longer works! + final Sink subSink = + Sink.create(TestSubscriber.manualProbe(sys)); + +should be replaced by + +.. includecode:: code/docs/MigrationsJava.java#sink-creators + ``Flow.empty()`` have been removed ================================== @@ -308,16 +348,30 @@ should be replaced by It was a common user mistake to use ``Sink.publisher`` and get into trouble since it would only support a single ``Subscriber``, and the discoverability of the apprpriate fix was non-obvious (Sink.fanoutPublisher). To make the decision whether to support fanout or not an active one, the aforementioned methods have been -replaced with a single method: ``Sink.publisher(fanout: Boolean)``. +replaced with a single method: ``Sink.asPublisher(fanout: Boolean)``. Update procedure ---------------- -1. Replace all occurences of ``Sink.publisher`` with ``Sink.publisher(false)`` -2. Replace all occurences of ``Sink.fanoutPublisher`` with ``Sink.publisher(true)`` +1. Replace all occurences of ``Sink.publisher`` with ``Sink.asPublisher(false)`` +2. Replace all occurences of ``Sink.fanoutPublisher`` with ``Sink.asPublisher(true)`` -TODO: code example +Example +^^^^^^^ +:: + + // This no longer works! + final Sink> pubSink = + Sink.publisher(); + + // This no longer works! + final Sink> pubSink = + Sink.fanoutPublisher(2, 8); + +should be replaced by + +.. includecode:: code/docs/MigrationsJava.java#sink-as-publisher FlexiMerge an FlexiRoute has been replaced by GraphStage ======================================================== diff --git a/akka-docs-dev/rst/java/stream-integrations.rst b/akka-docs-dev/rst/java/stream-integrations.rst index 5284de1dd0..3383f57eb1 100644 --- a/akka-docs-dev/rst/java/stream-integrations.rst +++ b/akka-docs-dev/rst/java/stream-integrations.rst @@ -8,7 +8,7 @@ Integrating with Actors ======================= For piping the elements of a stream as messages to an ordinary actor you can use the -``Sink.actorRef``. Messages can be sent to a stream via the :class:`ActorRef` that is +``Sink.actorRef``. Messages can be sent to a stream via the :class:`ActorRef` that is materialized by ``Source.actorRef``. For more advanced use cases the :class:`ActorPublisher` and :class:`ActorSubscriber` traits are @@ -32,8 +32,8 @@ Akka Streams :class:`Source` or :class:`Sink`. Source.actorRef ^^^^^^^^^^^^^^^ -Messages sent to the actor that is materialized by ``Source.actorRef`` will be emitted to the -stream if there is demand from downstream, otherwise they will be buffered until request for +Messages sent to the actor that is materialized by ``Source.actorRef`` will be emitted to the +stream if there is demand from downstream, otherwise they will be buffered until request for demand is received. Depending on the defined :class:`OverflowStrategy` it might drop elements if there is no space @@ -44,7 +44,7 @@ actor interface. The stream can be completed successfully by sending ``akka.actor.PoisonPill`` or ``akka.actor.Status.Success`` to the actor reference. -The stream can be completed with failure by sending ``akka.actor.Status.Failure`` to the +The stream can be completed with failure by sending ``akka.actor.Status.Failure`` to the actor reference. The actor will be stopped when the stream is completed, failed or cancelled from downstream, @@ -108,12 +108,12 @@ This is how it can be used as input :class:`Source` to a :class:`Flow`: .. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/stream/ActorPublisherDocTest.java#actor-publisher-usage You can only attach one subscriber to this publisher. Use a ``Broadcast``-element or -attach a ``Sink.publisher(true)`` to enable multiple subscribers. +attach a ``Sink.asPublisher(true)`` to enable multiple subscribers. ActorSubscriber ^^^^^^^^^^^^^^^ -Extend :class:`akka.stream.actor.AbstractActorSubscriber` to make your class a stream subscriber with +Extend :class:`akka.stream.actor.AbstractActorSubscriber` to make your class a stream subscriber with full control of stream back pressure. It will receive ``ActorSubscriberMessage.OnNext``, ``ActorSubscriberMessage.OnComplete`` and ``ActorSubscriberMessage.OnError`` messages from the stream. It can also receive other, non-stream messages, in the same way as any actor. @@ -414,7 +414,7 @@ by using the Publisher-:class:`Sink`: .. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/stream/ReactiveStreamsDocTest.java#source-publisher -A publisher that is created with ``Sink.publisher(false)`` supports only a single subscription. +A publisher that is created with ``Sink.asPublisher(false)`` supports only a single subscription. Additional subscription attempts will be rejected with an :class:`IllegalStateException`. A publisher that supports multiple subscribers using fan-out/broadcasting is created as follows: diff --git a/akka-docs-dev/rst/scala/code/docs/MigrationsScala.scala b/akka-docs-dev/rst/scala/code/docs/MigrationsScala.scala index 0fd0baf3fa..0dd05867d8 100644 --- a/akka-docs-dev/rst/scala/code/docs/MigrationsScala.scala +++ b/akka-docs-dev/rst/scala/code/docs/MigrationsScala.scala @@ -6,11 +6,11 @@ import akka.http.scaladsl.model.Uri import akka.stream.scaladsl._ import akka.stream._ import akka.stream.stage.{ OutHandler, InHandler, GraphStageLogic, GraphStage } -import akka.stream.testkit.AkkaSpec +import akka.stream.testkit.{ AkkaSpec, TestPublisher, TestSubscriber } import scala.concurrent.{ Future, ExecutionContext, Promise } import scala.concurrent.duration._ -import scala.util.{ Failure, Success, Try } +import scala.util.{ Failure, Random, Success, Try } class MigrationsScala extends AkkaSpec { @@ -110,8 +110,26 @@ class MigrationsScala extends AkkaSpec { promise.trySuccess(Some(())) val ticks = Source.tick(1.second, 3.seconds, "tick") + + val pubSource = Source.fromPublisher(TestPublisher.manualProbe[Int]()) + + val itSource = Source.fromIterator(() => Iterator.continually(Random.nextGaussian)) + + val futSource = Source.fromFuture(Future.successful(42)) + + val subSource = Source.asSubscriber //#source-creators + //#sink-creators + val subSink = Sink.fromSubscriber(TestSubscriber.manualProbe[Int]()) + //#sink-creators + + //#sink-as-publisher + val pubSink = Sink.asPublisher(fanout = false) + + val pubSinkFanout = Sink.asPublisher(fanout = true) + //#sink-as-publisher + //#flatMapConcat Flow[Source[Int, Any]].flatMapConcat(identity) //#flatMapConcat diff --git a/akka-docs-dev/rst/scala/code/docs/stream/FlowDocSpec.scala b/akka-docs-dev/rst/scala/code/docs/stream/FlowDocSpec.scala index 5b983e43d2..9ba042651c 100644 --- a/akka-docs-dev/rst/scala/code/docs/stream/FlowDocSpec.scala +++ b/akka-docs-dev/rst/scala/code/docs/stream/FlowDocSpec.scala @@ -100,7 +100,7 @@ class FlowDocSpec extends AkkaSpec { Source(List(1, 2, 3)) // Create a source from a Future - Source(Future.successful("Hello Streams!")) + Source.fromFuture(Future.successful("Hello Streams!")) // Create a source from a single element Source.single("only one element") diff --git a/akka-docs-dev/rst/scala/code/docs/stream/GraphCyclesSpec.scala b/akka-docs-dev/rst/scala/code/docs/stream/GraphCyclesSpec.scala index c13f5e937c..a2961a8904 100644 --- a/akka-docs-dev/rst/scala/code/docs/stream/GraphCyclesSpec.scala +++ b/akka-docs-dev/rst/scala/code/docs/stream/GraphCyclesSpec.scala @@ -9,7 +9,7 @@ class GraphCyclesSpec extends AkkaSpec { implicit val materializer = ActorMaterializer() "Cycle demonstration" must { - val source = Source(() => Iterator.from(0)) + val source = Source.fromIterator(() => Iterator.from(0)) "include a deadlocked cycle" in { diff --git a/akka-docs-dev/rst/scala/code/docs/stream/RateTransformationDocSpec.scala b/akka-docs-dev/rst/scala/code/docs/stream/RateTransformationDocSpec.scala index 322d54594f..6b428a262a 100644 --- a/akka-docs-dev/rst/scala/code/docs/stream/RateTransformationDocSpec.scala +++ b/akka-docs-dev/rst/scala/code/docs/stream/RateTransformationDocSpec.scala @@ -33,7 +33,7 @@ class RateTransformationDocSpec extends AkkaSpec { } //#conflate-summarize - val fut = Source(() => Iterator.continually(Random.nextGaussian)) + val fut = Source.fromIterator(() => Iterator.continually(Random.nextGaussian)) .via(statsFlow) .grouped(10) .runWith(Sink.head) diff --git a/akka-docs-dev/rst/scala/code/docs/stream/ReactiveStreamsDocSpec.scala b/akka-docs-dev/rst/scala/code/docs/stream/ReactiveStreamsDocSpec.scala index 1c3ef615b6..763d0e112b 100644 --- a/akka-docs-dev/rst/scala/code/docs/stream/ReactiveStreamsDocSpec.scala +++ b/akka-docs-dev/rst/scala/code/docs/stream/ReactiveStreamsDocSpec.scala @@ -41,7 +41,7 @@ class ReactiveStreamsDocSpec extends AkkaSpec { val impl = new Fixture { override def tweets: Publisher[Tweet] = - TwitterStreamQuickstartDocSpec.tweets.runWith(Sink.publisher(false)) + TwitterStreamQuickstartDocSpec.tweets.runWith(Sink.asPublisher(false)) override def storage = TestSubscriber.manualProbe[Author] @@ -66,7 +66,7 @@ class ReactiveStreamsDocSpec extends AkkaSpec { val storage = impl.storage //#connect-all - Source(tweets).via(authors).to(Sink(storage)).run() + Source.fromPublisher(tweets).via(authors).to(Sink.fromSubscriber(storage)).run() //#connect-all assertResult(storage) @@ -92,7 +92,7 @@ class ReactiveStreamsDocSpec extends AkkaSpec { //#source-publisher val authorPublisher: Publisher[Author] = - Source(tweets).via(authors).runWith(Sink.publisher(fanout = false)) + Source.fromPublisher(tweets).via(authors).runWith(Sink.asPublisher(fanout = false)) authorPublisher.subscribe(storage) //#source-publisher @@ -107,8 +107,8 @@ class ReactiveStreamsDocSpec extends AkkaSpec { //#source-fanoutPublisher val authorPublisher: Publisher[Author] = - Source(tweets).via(authors) - .runWith(Sink.publisher(fanout = true)) + Source.fromPublisher(tweets).via(authors) + .runWith(Sink.asPublisher(fanout = true)) authorPublisher.subscribe(storage) authorPublisher.subscribe(alert) @@ -125,7 +125,7 @@ class ReactiveStreamsDocSpec extends AkkaSpec { //#sink-subscriber val tweetSubscriber: Subscriber[Tweet] = - authors.to(Sink(storage)).runWith(Source.subscriber[Tweet]) + authors.to(Sink.fromSubscriber(storage)).runWith(Source.asSubscriber[Tweet]) tweets.subscribe(tweetSubscriber) //#sink-subscriber diff --git a/akka-docs-dev/rst/scala/code/docs/stream/StreamPartialFlowGraphDocSpec.scala b/akka-docs-dev/rst/scala/code/docs/stream/StreamPartialFlowGraphDocSpec.scala index 9851f27d15..4bc2dc4d0f 100644 --- a/akka-docs-dev/rst/scala/code/docs/stream/StreamPartialFlowGraphDocSpec.scala +++ b/akka-docs-dev/rst/scala/code/docs/stream/StreamPartialFlowGraphDocSpec.scala @@ -57,7 +57,7 @@ class StreamPartialFlowGraphDocSpec extends AkkaSpec { // prepare graph elements val zip = b.add(Zip[Int, Int]()) - def ints = Source(() => Iterator.from(1)) + def ints = Source.fromIterator(() => Iterator.from(1)) // connect the graph ints.filter(_ % 2 != 0) ~> zip.in0 diff --git a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeCollectingMetrics.scala b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeCollectingMetrics.scala index 2fe19805e2..3203890b08 100644 --- a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeCollectingMetrics.scala +++ b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeCollectingMetrics.scala @@ -19,8 +19,8 @@ class RecipeCollectingMetrics extends RecipeSpec { // // val loadPub = TestPublisher.manualProbe[Int]() // val tickPub = TestPublisher.manualProbe[Tick]() - // val reportTicks = Source(tickPub) - // val loadUpdates = Source(loadPub) + // val reportTicks = Source.fromPublisher(tickPub) + // val loadUpdates = Source.fromPublisher(loadPub) // val futureSink = Sink.head[immutable.Seq[String]] // val sink = Flow[String].grouped(10).to(futureSink) // diff --git a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeDroppyBroadcast.scala b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeDroppyBroadcast.scala index 71a26693b9..7c779de869 100644 --- a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeDroppyBroadcast.scala +++ b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeDroppyBroadcast.scala @@ -13,15 +13,15 @@ class RecipeDroppyBroadcast extends RecipeSpec { "Recipe for a droppy broadcast" must { "work" in { val pub = TestPublisher.probe[Int]() - val myElements = Source(pub) + val myElements = Source.fromPublisher(pub) val sub1 = TestSubscriber.manualProbe[Int]() val sub2 = TestSubscriber.manualProbe[Int]() val sub3 = TestSubscriber.probe[Int]() val futureSink = Sink.head[Seq[Int]] - val mySink1 = Sink(sub1) - val mySink2 = Sink(sub2) - val mySink3 = Sink(sub3) + val mySink1 = Sink.fromSubscriber(sub1) + val mySink2 = Sink.fromSubscriber(sub2) + val mySink3 = Sink.fromSubscriber(sub3) //#droppy-bcast val graph = RunnableGraph.fromGraph(GraphDSL.create(mySink1, mySink2, mySink3)((_, _, _)) { implicit b => diff --git a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeGlobalRateLimit.scala b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeGlobalRateLimit.scala index 81f96ea400..dc28c2a75d 100644 --- a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeGlobalRateLimit.scala +++ b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeGlobalRateLimit.scala @@ -94,15 +94,15 @@ class RecipeGlobalRateLimit extends RecipeSpec { // Use a large period and emulate the timer by hand instead val limiter = system.actorOf(Limiter.props(2, 100.days, 1), "limiter") - val source1 = Source(() => Iterator.continually("E1")).via(limitGlobal(limiter, 2.seconds)) - val source2 = Source(() => Iterator.continually("E2")).via(limitGlobal(limiter, 2.seconds)) + val source1 = Source.fromIterator(() => Iterator.continually("E1")).via(limitGlobal(limiter, 2.seconds)) + val source2 = Source.fromIterator(() => Iterator.continually("E2")).via(limitGlobal(limiter, 2.seconds)) val probe = TestSubscriber.manualProbe[String]() RunnableGraph.fromGraph(GraphDSL.create() { implicit b => import GraphDSL.Implicits._ val merge = b.add(Merge[String](2)) - source1 ~> merge ~> Sink(probe) + source1 ~> merge ~> Sink.fromSubscriber(probe) source2 ~> merge ClosedShape }).run() diff --git a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeHold.scala b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeHold.scala index 61f341469a..928392e8ca 100644 --- a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeHold.scala +++ b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeHold.scala @@ -54,8 +54,8 @@ class RecipeHold extends RecipeSpec { val pub = TestPublisher.probe[Int]() val sub = TestSubscriber.manualProbe[Int]() - val source = Source(pub) - val sink = Sink(sub) + val source = Source.fromPublisher(pub) + val sink = Sink.fromSubscriber(sub) source.transform(() => new HoldWithInitial(0)).to(sink).run() @@ -84,8 +84,8 @@ class RecipeHold extends RecipeSpec { val pub = TestPublisher.probe[Int]() val sub = TestSubscriber.manualProbe[Int]() - val source = Source(pub) - val sink = Sink(sub) + val source = Source.fromPublisher(pub) + val sink = Sink.fromSubscriber(sub) source.transform(() => new HoldWithWait).to(sink).run() diff --git a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeManualTrigger.scala b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeManualTrigger.scala index 36255071d2..3bb4cfa2a8 100644 --- a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeManualTrigger.scala +++ b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeManualTrigger.scala @@ -14,8 +14,8 @@ class RecipeManualTrigger extends RecipeSpec { val elements = Source(List("1", "2", "3", "4")) val pub = TestPublisher.probe[Trigger]() val sub = TestSubscriber.manualProbe[Message]() - val triggerSource = Source(pub) - val sink = Sink(sub) + val triggerSource = Source.fromPublisher(pub) + val sink = Sink.fromSubscriber(sub) //#manually-triggered-stream val graph = RunnableGraph.fromGraph(GraphDSL.create() { implicit builder => @@ -53,8 +53,8 @@ class RecipeManualTrigger extends RecipeSpec { val elements = Source(List("1", "2", "3", "4")) val pub = TestPublisher.probe[Trigger]() val sub = TestSubscriber.manualProbe[Message]() - val triggerSource = Source(pub) - val sink = Sink(sub) + val triggerSource = Source.fromPublisher(pub) + val sink = Sink.fromSubscriber(sub) //#manually-triggered-stream-zipwith val graph = RunnableGraph.fromGraph(GraphDSL.create() { implicit builder => diff --git a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeMissedTicks.scala b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeMissedTicks.scala index 1829655862..1ea6f7bada 100644 --- a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeMissedTicks.scala +++ b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeMissedTicks.scala @@ -15,8 +15,8 @@ class RecipeMissedTicks extends RecipeSpec { val pub = TestPublisher.probe[Tick]() val sub = TestSubscriber.manualProbe[Int]() - val tickStream = Source(pub) - val sink = Sink(sub) + val tickStream = Source.fromPublisher(pub) + val sink = Sink.fromSubscriber(sub) //#missed-ticks val missedTicks: Flow[Tick, Int, Unit] = diff --git a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeSimpleDrop.scala b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeSimpleDrop.scala index f8509d29f6..135d61c0a9 100644 --- a/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeSimpleDrop.scala +++ b/akka-docs-dev/rst/scala/code/docs/stream/cookbook/RecipeSimpleDrop.scala @@ -22,8 +22,8 @@ class RecipeSimpleDrop extends RecipeSpec { val pub = TestPublisher.probe[Message]() val sub = TestSubscriber.manualProbe[Message]() - val messageSource = Source(pub) - val sink = Sink(sub) + val messageSource = Source.fromPublisher(pub) + val sink = Sink.fromSubscriber(sub) messageSource.via(realDroppyStream).to(sink).run() diff --git a/akka-docs-dev/rst/scala/migration-guide-1.0-2.x-scala.rst b/akka-docs-dev/rst/scala/migration-guide-1.0-2.x-scala.rst index bf6d15b48a..23664831ab 100644 --- a/akka-docs-dev/rst/scala/migration-guide-1.0-2.x-scala.rst +++ b/akka-docs-dev/rst/scala/migration-guide-1.0-2.x-scala.rst @@ -220,13 +220,14 @@ should be replaced by Source constructor name changes =============================== -``Source.lazyEmpty`` have been replaced by ``Source.maybe`` which returns a ``Promise`` that can be completed by one or +``Source.lazyEmpty`` has been replaced by ``Source.maybe`` which returns a ``Promise`` that can be completed by one or zero elements by providing an ``Option``. This is different from ``lazyEmpty`` which only allowed completion to be sent, but no elements. -The ``apply()`` overload on ``Source`` that provide a tick source (``Source(delay,interval,tick)``) -is replaced by the named method ``Source.tick()`` to reduce the number of overloads and to make the function more -discoverable. +The ``apply()`` overload on ``Source`` has been refactored to separate methods to reduce the number of overloads and +make source creation more discoverable. + +``Source.subscriber`` has been renamed to ``Source.asSubscriber``. Update procedure ---------------- @@ -234,6 +235,10 @@ Update procedure 1. All uses of ``Source.lazyEmpty`` should be replaced by ``Source.maybe`` and the returned ``Promise`` completed with a ``None`` (an empty ``Option``) 2. Replace all uses of ``Source(delay,interval,tick)`` with the method ``Source.tick(delay,interval,tick)`` +3. Replace all uses of ``Source(publisher)`` with the method ``Source.fromPublisher(publisher)`` +4. Replace all uses of ``Source(() => iterator)`` with the method ``Source.fromIterator(() => iterator))`` +5. Replace all uses of ``Source(future)`` with the method ``Source.fromFuture(future))`` +6. Replace all uses of ``Source.subscriber`` with the method ``Source.asSubscriber`` Example ^^^^^^^ @@ -248,10 +253,45 @@ Example // This no longer works! val ticks = Source(1.second, 3.seconds, "tick") + // This no longer works! + val pubSource = Source(TestPublisher.manualProbe[Int]()) + + // This no longer works! + val itSource = Source(() => Iterator.continually(Random.nextGaussian)) + + // This no longer works! + val futSource = Source(Future.successful(42)) + + // This no longer works! + val subSource = Source.subscriber + should be replaced by .. includecode:: code/docs/MigrationsScala.scala#source-creators +Sink constructor name changes +============================= + +``Sink.apply(subscriber)`` has been renamed to ``Sink.fromSubscriber(subscriber)`` to reduce the number of overloads and +make sink creation more discoverable. + +Update procedure +---------------- + +1. Replace all uses of ``Sink(subscriber)`` with the method ``Sink.fromSubscriber(subscriber)`` + +Example +^^^^^^^ + +:: + + // This no longer works! + val subSink = Sink(TestSubscriber.manualProbe[Int]()) + +should be replaced by + +.. includecode:: code/docs/MigrationsScala.scala#sink-creators + ``flatten(FlattenStrategy)`` has been replaced by named counterparts ==================================================================== @@ -276,6 +316,35 @@ should be replaced by .. includecode:: code/docs/MigrationsScala.scala#flatMapConcat +`Sink.fanoutPublisher() and Sink.publisher() is now a single method` +==================================================================== + +It was a common user mistake to use ``Sink.publisher`` and get into trouble since it would only support +a single ``Subscriber``, and the discoverability of the apprpriate fix was non-obvious (Sink.fanoutPublisher). +To make the decision whether to support fanout or not an active one, the aforementioned methods have been +replaced with a single method: ``Sink.asPublisher(fanout: Boolean)``. + +Update procedure +---------------- + +1. Replace all occurences of ``Sink.publisher`` with ``Sink.asPublisher(false)`` +2. Replace all occurences of ``Sink.fanoutPublisher`` with ``Sink.asPublisher(true)`` + +Example +^^^^^^^ + +:: + + // This no longer works! + val subSink = Sink.publisher + + // This no longer works! + val subSink = Sink.fanoutPublisher(2, 8) + +should be replaced by + +.. includecode:: code/docs/MigrationsScala.scala#sink-as-publisher + FlexiMerge an FlexiRoute has been replaced by GraphStage ======================================================== diff --git a/akka-docs-dev/rst/scala/stream-integrations.rst b/akka-docs-dev/rst/scala/stream-integrations.rst index 9e541c096d..ba63fcd1f4 100644 --- a/akka-docs-dev/rst/scala/stream-integrations.rst +++ b/akka-docs-dev/rst/scala/stream-integrations.rst @@ -8,7 +8,7 @@ Integrating with Actors ======================= For piping the elements of a stream as messages to an ordinary actor you can use the -``Sink.actorRef``. Messages can be sent to a stream via the :class:`ActorRef` that is +``Sink.actorRef``. Messages can be sent to a stream via the :class:`ActorRef` that is materialized by ``Source.actorRef``. For more advanced use cases the :class:`ActorPublisher` and :class:`ActorSubscriber` traits are @@ -27,8 +27,8 @@ Akka Streams :class:`Source` or :class:`Sink`. Source.actorRef ^^^^^^^^^^^^^^^ -Messages sent to the actor that is materialized by ``Source.actorRef`` will be emitted to the -stream if there is demand from downstream, otherwise they will be buffered until request for +Messages sent to the actor that is materialized by ``Source.actorRef`` will be emitted to the +stream if there is demand from downstream, otherwise they will be buffered until request for demand is received. Depending on the defined :class:`OverflowStrategy` it might drop elements if there is no space @@ -39,7 +39,7 @@ actor interface. The stream can be completed successfully by sending ``akka.actor.PoisonPill`` or ``akka.actor.Status.Success`` to the actor reference. -The stream can be completed with failure by sending ``akka.actor.Status.Failure`` to the +The stream can be completed with failure by sending ``akka.actor.Status.Failure`` to the actor reference. The actor will be stopped when the stream is completed, failed or cancelled from downstream, @@ -102,7 +102,7 @@ This is how it can be used as input :class:`Source` to a :class:`Flow`: .. includecode:: code/docs/stream/ActorPublisherDocSpec.scala#actor-publisher-usage -A publisher that is created with ``Sink.publisher`` supports a specified number of subscribers. Additional +A publisher that is created with ``Sink.asPublisher`` supports a specified number of subscribers. Additional subscription attempts will be rejected with an :class:`IllegalStateException`. ActorSubscriber @@ -409,7 +409,7 @@ by using the Publisher-:class:`Sink`: .. includecode:: code/docs/stream/ReactiveStreamsDocSpec.scala#source-publisher -A publisher that is created with ``Sink.publisher(false)`` supports only a single subscription. +A publisher that is created with ``Sink.asPublisher(false)`` supports only a single subscription. Additional subscription attempts will be rejected with an :class:`IllegalStateException`. A publisher that supports multiple subscribers using fan-out/broadcasting is created as follows: @@ -433,4 +433,3 @@ passing a factory function that will create the :class:`Processor` instances: .. includecode:: code/docs/stream/ReactiveStreamsDocSpec.scala#use-processor Please note that a factory is necessary to achieve reusability of the resulting :class:`Flow`. - diff --git a/akka-docs-dev/rst/stream-design.rst b/akka-docs-dev/rst/stream-design.rst index 85bc4263eb..cfea2c5cd1 100644 --- a/akka-docs-dev/rst/stream-design.rst +++ b/akka-docs-dev/rst/stream-design.rst @@ -32,11 +32,11 @@ The process of materialization will often create specific objects that are usefu Interoperation with other Reactive Streams implementations ---------------------------------------------------------- -Akka Streams fully implement the Reactive Streams specification and interoperate with all other conformant implementations. We chose to completely separate the Reactive Streams interfaces from the user-level API because we regard them to be an SPI that is not targeted at endusers. In order to obtain a :class:`Publisher` or :class:`Subscriber` from an Akka Stream topology, a corresponding ``Sink.publisher`` or ``Source.subscriber`` element must be used. +Akka Streams fully implement the Reactive Streams specification and interoperate with all other conformant implementations. We chose to completely separate the Reactive Streams interfaces from the user-level API because we regard them to be an SPI that is not targeted at endusers. In order to obtain a :class:`Publisher` or :class:`Subscriber` from an Akka Stream topology, a corresponding ``Sink.asPublisher`` or ``Source.asSubscriber`` element must be used. All stream Processors produced by the default materialization of Akka Streams are restricted to having a single Subscriber, additional Subscribers will be rejected. The reason for this is that the stream topologies described using our DSL never require fan-out behavior from the Publisher sides of the elements, all fan-out is done using explicit elements like :class:`Broadcast[T]`. -This means that ``Sink.publisher(true)`` (for enabling fan-out support) must be used where broadcast behavior is needed for interoperation with other Reactive Streams implementations. +This means that ``Sink.asPublisher(true)`` (for enabling fan-out support) must be used where broadcast behavior is needed for interoperation with other Reactive Streams implementations. What shall users of streaming libraries expect? ----------------------------------------------- @@ -53,7 +53,7 @@ The second rule allows a library to additionally provide nice sugar for the comm .. note:: One important consequence of this is that a reusable flow description cannot be bound to “live” resources, any connection to or allocation of such resources must be deferred until materialization time. Examples of “live” resources are already existing TCP connections, a multicast Publisher, etc.; a TickSource does not fall into this category if its timer is created only upon materialization (as is the case for our implementation). - + Exceptions from this need to be well-justified and carefully documented. Resulting Implementation Constraints diff --git a/akka-http-core/src/main/scala/akka/http/impl/engine/client/PoolInterfaceActor.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/client/PoolInterfaceActor.scala index 89dc6834cc..51317681f8 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/engine/client/PoolInterfaceActor.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/client/PoolInterfaceActor.scala @@ -73,7 +73,7 @@ private class PoolInterfaceActor(hcps: HostConnectionPoolSetup, new InetSocketAddress(host, port), settings, setup.log) .named("PoolFlow") - Source(ActorPublisher(self)).via(poolFlow).runWith(Sink(ActorSubscriber[ResponseContext](self))) + Source.fromPublisher(ActorPublisher(self)).via(poolFlow).runWith(Sink.fromSubscriber(ActorSubscriber[ResponseContext](self))) } activateIdleTimeoutIfNecessary() diff --git a/akka-http-core/src/main/scala/akka/http/impl/engine/server/HttpServerBluePrint.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/server/HttpServerBluePrint.scala index 99836bd515..029c537548 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/engine/server/HttpServerBluePrint.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/server/HttpServerBluePrint.scala @@ -372,9 +372,9 @@ private[http] object HttpServerBluePrint { def websocketFlow: Flow[ByteString, ByteString, Any] = flow def installHandler(handlerFlow: Flow[FrameEvent, FrameEvent, Any])(implicit mat: Materializer): Unit = - Source(sinkCell.value) + Source.fromPublisher(sinkCell.value) .via(handlerFlow) - .to(Sink(sourceCell.value)) + .to(Sink.fromSubscriber(sourceCell.value)) .run() } } diff --git a/akka-http-core/src/main/scala/akka/http/impl/util/StreamUtils.scala b/akka-http-core/src/main/scala/akka/http/impl/util/StreamUtils.scala index 1aae759a8d..7a79a1726a 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/util/StreamUtils.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/util/StreamUtils.scala @@ -159,14 +159,14 @@ private[http] object StreamUtils { case Nil ⇒ Nil case Seq(one) ⇒ Vector(input.via(one)) case multiple ⇒ - val (fanoutSub, fanoutPub) = Source.subscriber[ByteString].toMat(Sink.publisher(true))(Keep.both).run() + val (fanoutSub, fanoutPub) = Source.asSubscriber[ByteString].toMat(Sink.asPublisher(true))(Keep.both).run() val sources = transformers.map { flow ⇒ // Doubly wrap to ensure that subscription to the running publisher happens before the final sources // are exposed, so there is no race - Source(Source(fanoutPub).viaMat(flow)(Keep.right).runWith(Sink.publisher(false))) + Source.fromPublisher(Source.fromPublisher(fanoutPub).viaMat(flow)(Keep.right).runWith(Sink.asPublisher(false))) } // The fanout publisher must be wired to the original source after all fanout subscribers have been subscribed - input.runWith(Sink(fanoutSub)) + input.runWith(Sink.fromSubscriber(fanoutSub)) sources } @@ -315,7 +315,7 @@ private[http] object StreamUtils { object OneTimeValve { def apply(): OneTimeValve = new OneTimeValve { val promise = Promise[Unit]() - val _source = Source(promise.future).drop(1) // we are only interested in the completion event + val _source = Source.fromFuture(promise.future).drop(1) // we are only interested in the completion event def source[T]: Source[T, Unit] = _source.asInstanceOf[Source[T, Unit]] // safe, because source won't generate any elements def open(): Unit = promise.success(()) @@ -331,4 +331,4 @@ private[http] class EnhancedByteStringSource[Mat](val byteStringStream: Source[B byteStringStream.runFold(ByteString.empty)(_ ++ _) def utf8String(implicit materializer: Materializer, ec: ExecutionContext): Future[String] = join.map(_.utf8String) -} \ No newline at end of file +} diff --git a/akka-http-core/src/test/java/akka/http/javadsl/WSEchoTestClientApp.java b/akka-http-core/src/test/java/akka/http/javadsl/WSEchoTestClientApp.java index 5a58759de6..dc28db6798 100644 --- a/akka-http-core/src/test/java/akka/http/javadsl/WSEchoTestClientApp.java +++ b/akka-http-core/src/test/java/akka/http/javadsl/WSEchoTestClientApp.java @@ -54,7 +54,7 @@ public class WSEchoTestClientApp { TextMessage.create("abc"), TextMessage.create("def"), TextMessage.create("ghi") - )).concat(Source.from(delayedCompletion).drop(1)); + )).concat(Source.fromFuture(delayedCompletion).drop(1)); Sink>> echoSink = Flow.of(Message.class) diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/client/ClientCancellationSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/client/ClientCancellationSpec.scala index 0d02eb6aca..49a498602a 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/client/ClientCancellationSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/client/ClientCancellationSpec.scala @@ -33,7 +33,7 @@ class ClientCancellationSpec extends AkkaSpec(""" def testCase(connection: Flow[HttpRequest, HttpResponse, Any]): Unit = Utils.assertAllStagesStopped { val requests = TestPublisher.probe[HttpRequest]() val responses = TestSubscriber.probe[HttpResponse]() - Source(requests).via(connection).runWith(Sink(responses)) + Source.fromPublisher(requests).via(connection).runWith(Sink.fromSubscriber(responses)) responses.request(1) requests.sendNext(HttpRequest()) responses.expectNext().entity.dataBytes.runWith(Sink.cancelled) diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/client/ConnectionPoolSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/client/ConnectionPoolSpec.scala index 02ba7a5d94..ae88bb343c 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/client/ConnectionPoolSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/client/ConnectionPoolSpec.scala @@ -89,7 +89,7 @@ class ConnectionPoolSpec extends AkkaSpec(""" override def testServerHandler(connNr: Int): HttpRequest ⇒ HttpResponse = { case request @ HttpRequest(_, Uri.Path("/a"), _, _, _) ⇒ - val entity = HttpEntity.Chunked.fromData(ContentTypes.`text/plain(UTF-8)`, Source(responseEntityPub)) + val entity = HttpEntity.Chunked.fromData(ContentTypes.`text/plain(UTF-8)`, Source.fromPublisher(responseEntityPub)) super.testServerHandler(connNr)(request) withEntity entity case x ⇒ super.testServerHandler(connNr)(x) } @@ -99,7 +99,7 @@ class ConnectionPoolSpec extends AkkaSpec(""" acceptIncomingConnection() val (Success(r1), 42) = responseOut.expectNext() val responseEntityProbe = TestSubscriber.probe[ByteString]() - r1.entity.dataBytes.runWith(Sink(responseEntityProbe)) + r1.entity.dataBytes.runWith(Sink.fromSubscriber(responseEntityProbe)) responseEntityProbe.expectSubscription().request(2) responseEntityPub.sendNext(ByteString("YEAH")) responseEntityProbe.expectNext(ByteString("YEAH")) @@ -131,7 +131,7 @@ class ConnectionPoolSpec extends AkkaSpec(""" val poolFlow = Http().cachedHostConnectionPool[Int](serverHostName, serverPort, settings = settings) val N = 500 - val requestIds = Source(() ⇒ Iterator.from(1)).take(N) + val requestIds = Source.fromIterator(() ⇒ Iterator.from(1)).take(N) val idSum = requestIds.map(id ⇒ HttpRequest(uri = s"/r$id") -> id).via(poolFlow).map { case (Success(response), id) ⇒ requestUri(response) should endWith(s"/r$id") @@ -301,7 +301,7 @@ class ConnectionPoolSpec extends AkkaSpec(""" Flow[SslTlsOutbound].collect[ByteString] { case SendBytes(x) ⇒ mapServerSideOutboundRawBytes(x) } .transform(StreamUtils.recover { case NoErrorComplete ⇒ ByteString.empty }), Flow[ByteString].map(SessionBytes(null, _))) - val sink = if (autoAccept) Sink.foreach[Http.IncomingConnection](handleConnection) else Sink(incomingConnections) + val sink = if (autoAccept) Sink.foreach[Http.IncomingConnection](handleConnection) else Sink.fromSubscriber(incomingConnections) // TODO getHostString in Java7 Tcp().bind(serverEndpoint.getHostName, serverEndpoint.getPort, idleTimeout = serverSettings.timeouts.idleTimeout) .map { c ⇒ @@ -345,7 +345,7 @@ class ConnectionPoolSpec extends AkkaSpec(""" def flowTestBench[T, Mat](poolFlow: Flow[(HttpRequest, T), (Try[HttpResponse], T), Mat]) = { val requestIn = TestPublisher.probe[(HttpRequest, T)]() val responseOut = TestSubscriber.manualProbe[(Try[HttpResponse], T)] - val hcp = Source(requestIn).viaMat(poolFlow)(Keep.right).to(Sink(responseOut)).run() + val hcp = Source.fromPublisher(requestIn).viaMat(poolFlow)(Keep.right).to(Sink.fromSubscriber(responseOut)).run() val responseOutSub = responseOut.expectSubscription() (requestIn, responseOut, responseOutSub, hcp) } diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/client/HighLevelOutgoingConnectionSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/client/HighLevelOutgoingConnectionSpec.scala index 462b534fe1..32c659eb2d 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/client/HighLevelOutgoingConnectionSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/client/HighLevelOutgoingConnectionSpec.scala @@ -24,7 +24,7 @@ class HighLevelOutgoingConnectionSpec extends AkkaSpec { serverHostName, serverPort) val N = 100 - val result = Source(() ⇒ Iterator.from(1)) + val result = Source.fromIterator(() ⇒ Iterator.from(1)) .take(N) .map(id ⇒ HttpRequest(uri = s"/r$id")) .via(Http().outgoingConnection(serverHostName, serverPort)) @@ -56,7 +56,7 @@ class HighLevelOutgoingConnectionSpec extends AkkaSpec { }) val N = 100 - val result = Source(() ⇒ Iterator.from(1)) + val result = Source.fromIterator(() ⇒ Iterator.from(1)) .take(N) .map(id ⇒ HttpRequest(uri = s"/r$id")) .via(doubleConnection) diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/client/LowLevelOutgoingConnectionSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/client/LowLevelOutgoingConnectionSpec.scala index 486a9b1539..8c172608f4 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/client/LowLevelOutgoingConnectionSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/client/LowLevelOutgoingConnectionSpec.scala @@ -45,7 +45,7 @@ class LowLevelOutgoingConnectionSpec extends AkkaSpec("akka.loggers = []\n akka. "has a request with default entity" in new TestSetup { val probe = TestPublisher.manualProbe[ByteString]() - requestsSub.sendNext(HttpRequest(PUT, entity = HttpEntity(ContentTypes.`application/octet-stream`, 8, Source(probe)))) + requestsSub.sendNext(HttpRequest(PUT, entity = HttpEntity(ContentTypes.`application/octet-stream`, 8, Source.fromPublisher(probe)))) expectWireData( """PUT / HTTP/1.1 |Host: example.com @@ -90,7 +90,7 @@ class LowLevelOutgoingConnectionSpec extends AkkaSpec("akka.loggers = []\n akka. ct shouldEqual ContentTypes.`application/octet-stream` val probe = TestSubscriber.manualProbe[ChunkStreamPart]() - chunks.runWith(Sink(probe)) + chunks.runWith(Sink.fromSubscriber(probe)) val sub = probe.expectSubscription() sendWireData("3\nABC\n") @@ -155,7 +155,7 @@ class LowLevelOutgoingConnectionSpec extends AkkaSpec("akka.loggers = []\n akka. val HttpResponse(_, _, HttpEntity.Chunked(ct, chunks), _) = expectResponse() val probe = TestSubscriber.manualProbe[ChunkStreamPart]() - chunks.runWith(Sink(probe)) + chunks.runWith(Sink.fromSubscriber(probe)) val sub = probe.expectSubscription() sendWireData("3\nABC\n") @@ -196,7 +196,7 @@ class LowLevelOutgoingConnectionSpec extends AkkaSpec("akka.loggers = []\n akka. "catch the request entity stream being shorter than the Content-Length" in new TestSetup { val probe = TestPublisher.manualProbe[ByteString]() - requestsSub.sendNext(HttpRequest(PUT, entity = HttpEntity(ContentTypes.`application/octet-stream`, 8, Source(probe)))) + requestsSub.sendNext(HttpRequest(PUT, entity = HttpEntity(ContentTypes.`application/octet-stream`, 8, Source.fromPublisher(probe)))) expectWireData( """PUT / HTTP/1.1 |Host: example.com @@ -222,7 +222,7 @@ class LowLevelOutgoingConnectionSpec extends AkkaSpec("akka.loggers = []\n akka. "catch the request entity stream being longer than the Content-Length" in new TestSetup { val probe = TestPublisher.manualProbe[ByteString]() - requestsSub.sendNext(HttpRequest(PUT, entity = HttpEntity(ContentTypes.`application/octet-stream`, 8, Source(probe)))) + requestsSub.sendNext(HttpRequest(PUT, entity = HttpEntity(ContentTypes.`application/octet-stream`, 8, Source.fromPublisher(probe)))) expectWireData( """PUT / HTTP/1.1 |Host: example.com @@ -274,7 +274,7 @@ class LowLevelOutgoingConnectionSpec extends AkkaSpec("akka.loggers = []\n akka. ct shouldEqual ContentTypes.`application/octet-stream` val probe = TestSubscriber.manualProbe[ChunkStreamPart]() - chunks.runWith(Sink(probe)) + chunks.runWith(Sink.fromSubscriber(probe)) val sub = probe.expectSubscription() sendWireData("3\nABC\n") @@ -531,10 +531,10 @@ class LowLevelOutgoingConnectionSpec extends AkkaSpec("akka.loggers = []\n akka. RunnableGraph.fromGraph(GraphDSL.create(OutgoingConnectionBlueprint(Host("example.com"), settings, NoLogging)) { implicit b ⇒ client ⇒ import GraphDSL.Implicits._ - Source(netIn) ~> Flow[ByteString].map(SessionBytes(null, _)) ~> client.in2 - client.out1 ~> Flow[SslTlsOutbound].collect { case SendBytes(x) ⇒ x } ~> Sink(netOut) - Source(requests) ~> client.in1 - client.out2 ~> Sink(responses) + Source.fromPublisher(netIn) ~> Flow[ByteString].map(SessionBytes(null, _)) ~> client.in2 + client.out1 ~> Flow[SslTlsOutbound].collect { case SendBytes(x) ⇒ x } ~> Sink.fromSubscriber(netOut) + Source.fromPublisher(requests) ~> client.in1 + client.out2 ~> Sink.fromSubscriber(responses) ClosedShape }).run() diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/RequestParserSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/RequestParserSpec.scala index 94b54bad0c..ae45bc59cb 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/RequestParserSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/RequestParserSpec.scala @@ -484,7 +484,7 @@ class RequestParserSpec extends FreeSpec with Matchers with BeforeAndAfterAll { } .concatSubstreams .flatMapConcat { x ⇒ - Source { + Source.fromFuture { x match { case Right(request) ⇒ compactEntity(request.entity).fast.map(x ⇒ Right(request.withEntity(x))) case Left(error) ⇒ FastFuture.successful(Left(error)) diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/server/HttpServerSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/server/HttpServerSpec.scala index f4751b05cf..ad6687a147 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/server/HttpServerSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/server/HttpServerSpec.scala @@ -46,7 +46,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") inside(expectRequest()) { case HttpRequest(POST, _, _, HttpEntity.Default(_, 12, data), _) ⇒ val dataProbe = TestSubscriber.manualProbe[ByteString] - data.to(Sink(dataProbe)).run() + data.to(Sink.fromSubscriber(dataProbe)).run() val sub = dataProbe.expectSubscription() sub.request(10) dataProbe.expectNoMsg(50.millis) @@ -89,7 +89,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") inside(expectRequest()) { case HttpRequest(POST, _, _, HttpEntity.Chunked(_, data), _) ⇒ val dataProbe = TestSubscriber.manualProbe[ChunkStreamPart] - data.to(Sink(dataProbe)).run() + data.to(Sink.fromSubscriber(dataProbe)).run() val sub = dataProbe.expectSubscription() sub.request(10) dataProbe.expectNext(Chunk(ByteString("abcdef"))) @@ -140,7 +140,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") inside(expectRequest()) { case HttpRequest(POST, _, _, HttpEntity.Default(_, 12, data), _) ⇒ val dataProbe = TestSubscriber.manualProbe[ByteString] - data.to(Sink(dataProbe)).run() + data.to(Sink.fromSubscriber(dataProbe)).run() val sub = dataProbe.expectSubscription() sub.request(10) dataProbe.expectNext(ByteString("abcdef")) @@ -163,7 +163,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") inside(expectRequest()) { case HttpRequest(POST, _, _, HttpEntity.Chunked(_, data), _) ⇒ val dataProbe = TestSubscriber.manualProbe[ChunkStreamPart] - data.to(Sink(dataProbe)).run() + data.to(Sink.fromSubscriber(dataProbe)).run() val sub = dataProbe.expectSubscription() sub.request(10) dataProbe.expectNext(Chunk(ByteString("abcdef"))) @@ -212,7 +212,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") inside(expectRequest()) { case HttpRequest(POST, _, _, HttpEntity.Default(_, 12, data), _) ⇒ val dataProbe = TestSubscriber.manualProbe[ByteString] - data.to(Sink(dataProbe)).run() + data.to(Sink.fromSubscriber(dataProbe)).run() val sub = dataProbe.expectSubscription() sub.request(10) dataProbe.expectNext(ByteString("abcdef")) @@ -249,7 +249,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") inside(expectRequest()) { case HttpRequest(POST, _, _, HttpEntity.Chunked(_, data), _) ⇒ val dataProbe = TestSubscriber.manualProbe[ChunkStreamPart] - data.to(Sink(dataProbe)).run() + data.to(Sink.fromSubscriber(dataProbe)).run() val sub = dataProbe.expectSubscription() sub.request(10) dataProbe.expectNext(Chunk(ByteString("abcdef"))) @@ -285,7 +285,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") inside(expectRequest()) { case HttpRequest(POST, _, _, HttpEntity.Default(_, 12, data), _) ⇒ val dataProbe = TestSubscriber.manualProbe[ByteString] - data.to(Sink(dataProbe)).run() + data.to(Sink.fromSubscriber(dataProbe)).run() val sub = dataProbe.expectSubscription() sub.request(10) dataProbe.expectNext(ByteString("abcdef")) @@ -308,7 +308,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") inside(expectRequest()) { case HttpRequest(POST, _, _, HttpEntity.Chunked(_, data), _) ⇒ val dataProbe = TestSubscriber.manualProbe[ChunkStreamPart] - data.to(Sink(dataProbe)).run() + data.to(Sink.fromSubscriber(dataProbe)).run() val sub = dataProbe.expectSubscription() sub.request(10) dataProbe.expectNext(Chunk(ByteString("abcdef"))) @@ -329,7 +329,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") inside(expectRequest()) { case HttpRequest(POST, _, _, HttpEntity.Default(_, 12, data), _) ⇒ val dataProbe = TestSubscriber.manualProbe[ByteString] - data.to(Sink(dataProbe)).run() + data.to(Sink.fromSubscriber(dataProbe)).run() val sub = dataProbe.expectSubscription() sub.request(10) dataProbe.expectNext(ByteString("abcdef")) @@ -350,7 +350,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") inside(expectRequest()) { case HttpRequest(POST, _, _, HttpEntity.Chunked(_, data), _) ⇒ val dataProbe = TestSubscriber.manualProbe[ChunkStreamPart] - data.to(Sink(dataProbe)).run() + data.to(Sink.fromSubscriber(dataProbe)).run() val sub = dataProbe.expectSubscription() sub.request(10) dataProbe.expectNext(Chunk(ByteString("abcdef"))) @@ -405,7 +405,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") val data = TestPublisher.manualProbe[ByteString]() inside(expectRequest()) { case HttpRequest(GET, _, _, _, _) ⇒ - responses.sendNext(HttpResponse(entity = HttpEntity.Default(ContentTypes.`text/plain(UTF-8)`, 4, Source(data)))) + responses.sendNext(HttpResponse(entity = HttpEntity.Default(ContentTypes.`text/plain(UTF-8)`, 4, Source.fromPublisher(data)))) val dataSub = data.expectSubscription() dataSub.expectCancellation() expectResponseWithWipedDate( @@ -427,7 +427,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") val data = TestPublisher.manualProbe[ByteString]() inside(expectRequest()) { case HttpRequest(GET, _, _, _, _) ⇒ - responses.sendNext(HttpResponse(entity = HttpEntity.CloseDelimited(ContentTypes.`text/plain(UTF-8)`, Source(data)))) + responses.sendNext(HttpResponse(entity = HttpEntity.CloseDelimited(ContentTypes.`text/plain(UTF-8)`, Source.fromPublisher(data)))) val dataSub = data.expectSubscription() dataSub.expectCancellation() expectResponseWithWipedDate( @@ -450,7 +450,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") val data = TestPublisher.manualProbe[ChunkStreamPart]() inside(expectRequest()) { case HttpRequest(GET, _, _, _, _) ⇒ - responses.sendNext(HttpResponse(entity = HttpEntity.Chunked(ContentTypes.`text/plain(UTF-8)`, Source(data)))) + responses.sendNext(HttpResponse(entity = HttpEntity.Chunked(ContentTypes.`text/plain(UTF-8)`, Source.fromPublisher(data)))) val dataSub = data.expectSubscription() dataSub.expectCancellation() expectResponseWithWipedDate( @@ -473,7 +473,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") val data = TestPublisher.manualProbe[ByteString]() inside(expectRequest()) { case HttpRequest(GET, _, _, _, _) ⇒ - responses.sendNext(HttpResponse(entity = CloseDelimited(ContentTypes.`text/plain(UTF-8)`, Source(data)))) + responses.sendNext(HttpResponse(entity = CloseDelimited(ContentTypes.`text/plain(UTF-8)`, Source.fromPublisher(data)))) val dataSub = data.expectSubscription() dataSub.expectCancellation() netOut.expectBytes(1) @@ -491,7 +491,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") inside(expectRequest()) { case HttpRequest(POST, _, _, Default(ContentType(`application/octet-stream`, None), 16, data), _) ⇒ val dataProbe = TestSubscriber.manualProbe[ByteString] - data.to(Sink(dataProbe)).run() + data.to(Sink.fromSubscriber(dataProbe)).run() val dataSub = dataProbe.expectSubscription() netOut.expectNoBytes(50.millis) dataSub.request(1) // triggers `100 Continue` response @@ -527,7 +527,7 @@ class HttpServerSpec extends AkkaSpec("akka.loggers = []\n akka.loglevel = OFF") inside(expectRequest()) { case HttpRequest(POST, _, _, Chunked(ContentType(`application/octet-stream`, None), data), _) ⇒ val dataProbe = TestSubscriber.manualProbe[ChunkStreamPart] - data.to(Sink(dataProbe)).run() + data.to(Sink.fromSubscriber(dataProbe)).run() val dataSub = dataProbe.expectSubscription() netOut.expectNoBytes(50.millis) dataSub.request(2) // triggers `100 Continue` response diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/server/HttpServerTestSetupBase.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/server/HttpServerTestSetupBase.scala index aa599f574a..407adcbbda 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/server/HttpServerTestSetupBase.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/server/HttpServerTestSetupBase.scala @@ -38,10 +38,10 @@ abstract class HttpServerTestSetupBase { RunnableGraph.fromGraph(GraphDSL.create(HttpServerBluePrint(settings, remoteAddress = remoteAddress, log = NoLogging)) { implicit b ⇒ server ⇒ import GraphDSL.Implicits._ - Source(netIn) ~> Flow[ByteString].map(SessionBytes(null, _)) ~> server.in2 + Source.fromPublisher(netIn) ~> Flow[ByteString].map(SessionBytes(null, _)) ~> server.in2 server.out1 ~> Flow[SslTlsOutbound].collect { case SendBytes(x) ⇒ x }.buffer(1, OverflowStrategy.backpressure) ~> netOut.sink - server.out2 ~> Sink(requests) - Source(responses) ~> server.in1 + server.out2 ~> Sink.fromSubscriber(requests) + Source.fromPublisher(responses) ~> server.in1 ClosedShape }).run() diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/ws/ByteStringSinkProbe.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/ws/ByteStringSinkProbe.scala index b1ea76ffd1..d3e4abb030 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/ws/ByteStringSinkProbe.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/ws/ByteStringSinkProbe.scala @@ -35,7 +35,7 @@ object ByteStringSinkProbe { def apply()(implicit system: ActorSystem): ByteStringSinkProbe = new ByteStringSinkProbe { val probe = TestSubscriber.probe[ByteString]() - val sink: Sink[ByteString, Unit] = Sink(probe) + val sink: Sink[ByteString, Unit] = Sink.fromSubscriber(probe) def expectNoBytes(): Unit = { probe.ensureSubscription() diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/ws/MessageSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/ws/MessageSpec.scala index eee6e23920..c0ed97a449 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/ws/MessageSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/ws/MessageSpec.scala @@ -47,7 +47,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { pushInput(header ++ data1) val dataSource = expectBinaryMessage().dataStream val sub = TestSubscriber.manualProbe[ByteString]() - dataSource.runWith(Sink(sub)) + dataSource.runWith(Sink.fromSubscriber(sub)) val s = sub.expectSubscription() s.request(2) sub.expectNext(data1) @@ -59,7 +59,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { pushInput(header) val dataSource = expectBinaryMessage().dataStream val sub = TestSubscriber.manualProbe[ByteString]() - dataSource.runWith(Sink(sub)) + dataSource.runWith(Sink.fromSubscriber(sub)) val s = sub.expectSubscription() s.request(2) pushInput(data1) @@ -78,7 +78,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { pushInput(header1 ++ data1) val dataSource = expectBinaryMessage().dataStream val sub = TestSubscriber.manualProbe[ByteString]() - dataSource.runWith(Sink(sub)) + dataSource.runWith(Sink.fromSubscriber(sub)) val s = sub.expectSubscription() s.request(2) sub.expectNext(data1) @@ -96,7 +96,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { pushInput(header1 ++ data1) val dataSource = expectBinaryMessage().dataStream val sub = TestSubscriber.manualProbe[ByteString]() - dataSource.runWith(Sink(sub)) + dataSource.runWith(Sink.fromSubscriber(sub)) val s = sub.expectSubscription() s.request(2) sub.expectNext(data1) @@ -111,7 +111,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { val dataSource2 = expectBinaryMessage().dataStream val sub2 = TestSubscriber.manualProbe[ByteString]() - dataSource2.runWith(Sink(sub2)) + dataSource2.runWith(Sink.fromSubscriber(sub2)) val s2 = sub2.expectSubscription() s2.request(2) sub2.expectNext(data3) @@ -131,7 +131,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { pushInput(header ++ data1) val dataSource = expectBinaryMessage().dataStream val sub = TestSubscriber.manualProbe[ByteString]() - dataSource.runWith(Sink(sub)) + dataSource.runWith(Sink.fromSubscriber(sub)) val s = sub.expectSubscription() s.request(2) sub.expectNext(ByteString("abc", "ASCII")) @@ -174,7 +174,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { pushInput(input) val parts = expectTextMessage().textStream val sub = TestSubscriber.manualProbe[String]() - parts.runWith(Sink(sub)) + parts.runWith(Sink.fromSubscriber(sub)) val s = sub.expectSubscription() s.request(4) sub.expectNext("b") @@ -192,7 +192,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { pushInput(header0 ++ data0) val parts = expectTextMessage().textStream val sub = TestSubscriber.manualProbe[String]() - parts.runWith(Sink(sub)) + parts.runWith(Sink.fromSubscriber(sub)) val s = sub.expectSubscription() s.request(4) sub.expectNoMsg(100.millis) @@ -211,7 +211,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { pushInput(header ++ data1) val dataSource = expectBinaryMessage().dataStream val sub = TestSubscriber.manualProbe[ByteString]() - dataSource.runWith(Sink(sub)) + dataSource.runWith(Sink.fromSubscriber(sub)) val s = sub.expectSubscription() s.request(2) sub.expectNext(ByteString("äb", "UTF-8")) @@ -242,7 +242,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { "for a streamed message" in new ServerTestSetup { val data = ByteString("abcdefg", "ASCII") val pub = TestPublisher.manualProbe[ByteString]() - val msg = BinaryMessage(Source(pub)) + val msg = BinaryMessage(Source.fromPublisher(pub)) pushMessage(msg) val sub = pub.expectSubscription() @@ -264,7 +264,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { "and mask input on the client side" in new ClientTestSetup { val data = ByteString("abcdefg", "ASCII") val pub = TestPublisher.manualProbe[ByteString]() - val msg = BinaryMessage(Source(pub)) + val msg = BinaryMessage(Source.fromPublisher(pub)) pushMessage(msg) val sub = pub.expectSubscription() @@ -299,7 +299,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { "for a streamed message" in new ServerTestSetup { val text = "äbcd€fg" val pub = TestPublisher.manualProbe[String]() - val msg = TextMessage(Source(pub)) + val msg = TextMessage(Source.fromPublisher(pub)) pushMessage(msg) val sub = pub.expectSubscription() @@ -328,7 +328,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { val half2 = gclef.drop(1) val pub = TestPublisher.manualProbe[String]() - val msg = TextMessage(Source(pub)) + val msg = TextMessage(Source.fromPublisher(pub)) pushMessage(msg) val sub = pub.expectSubscription() @@ -344,7 +344,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { "and mask input on the client side" in new ClientTestSetup { val text = "abcdefg" val pub = TestPublisher.manualProbe[String]() - val msg = TextMessage(Source(pub)) + val msg = TextMessage(Source.fromPublisher(pub)) pushMessage(msg) val sub = pub.expectSubscription() @@ -394,13 +394,13 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { val dataSource = expectBinaryMessage().dataStream val sub = TestSubscriber.manualProbe[ByteString]() - dataSource.runWith(Sink(sub)) + dataSource.runWith(Sink.fromSubscriber(sub)) val s = sub.expectSubscription() s.request(2) sub.expectNext(ByteString("123", "ASCII")) val outPub = TestPublisher.manualProbe[ByteString]() - val msg = BinaryMessage(Source(outPub)) + val msg = BinaryMessage(Source.fromPublisher(outPub)) pushMessage(msg) expectFrameHeaderOnNetwork(Opcode.Binary, 0, fin = false) @@ -467,7 +467,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { // sending another message is allowed before closing (inherently racy) val pub = TestPublisher.manualProbe[ByteString]() - val msg = BinaryMessage(Source(pub)) + val msg = BinaryMessage(Source.fromPublisher(pub)) pushMessage(msg) expectFrameOnNetwork(Opcode.Binary, ByteString.empty, fin = false) @@ -487,7 +487,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { pushInput(frameHeader(Protocol.Opcode.Binary, 0, fin = false, mask = Some(Random.nextInt()))) val dataSource = expectBinaryMessage().dataStream val inSubscriber = TestSubscriber.manualProbe[ByteString]() - dataSource.runWith(Sink(inSubscriber)) + dataSource.runWith(Sink.fromSubscriber(inSubscriber)) val inSub = inSubscriber.expectSubscription() val outData = ByteString("def", "ASCII") @@ -508,7 +508,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { // sending another message is allowed before closing (inherently racy) val pub = TestPublisher.manualProbe[ByteString]() - val msg = BinaryMessage(Source(pub)) + val msg = BinaryMessage(Source.fromPublisher(pub)) pushMessage(msg) expectFrameOnNetwork(Opcode.Binary, ByteString.empty, fin = false) @@ -572,7 +572,7 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { "when user handler closes main stream and substream only afterwards" in new ServerTestSetup { // send half a message val pub = TestPublisher.manualProbe[ByteString]() - val msg = BinaryMessage(Source(pub)) + val msg = BinaryMessage(Source.fromPublisher(pub)) pushMessage(msg) expectFrameOnNetwork(Opcode.Binary, ByteString.empty, fin = false) @@ -823,10 +823,10 @@ class MessageSpec extends FreeSpec with Matchers with WithMaterializerSpec { val messageHandler: Flow[Message, Message, Unit] = Flow.fromSinkAndSource( - Flow[Message].buffer(1, OverflowStrategy.backpressure).to(Sink(messageIn)), // alternatively need to request(1) before expectComplete - Source(messageOut)) + Flow[Message].buffer(1, OverflowStrategy.backpressure).to(Sink.fromSubscriber(messageIn)), // alternatively need to request(1) before expectComplete + Source.fromPublisher(messageOut)) - Source(netIn) + Source.fromPublisher(netIn) .via(printEvent("netIn")) .via(FrameEventParser) .via(Websocket diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/ws/WebsocketClientSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/ws/WebsocketClientSpec.scala index 40244f2612..461c04833e 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/ws/WebsocketClientSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/ws/WebsocketClientSpec.scala @@ -315,7 +315,7 @@ class WebsocketClientSpec extends FreeSpec with Matchers with WithMaterializerSp RunnableGraph.fromGraph(GraphDSL.create(clientLayer) { implicit b ⇒ client ⇒ import GraphDSL.Implicits._ - Source(netIn) ~> Flow[ByteString].map(SessionBytes(null, _)) ~> client.in2 + Source.fromPublisher(netIn) ~> Flow[ByteString].map(SessionBytes(null, _)) ~> client.in2 client.out1 ~> Flow[SslTlsOutbound].collect { case SendBytes(x) ⇒ x } ~> netOut.sink client.out2 ~> clientImplementation ~> client.in1 ClosedShape @@ -370,6 +370,6 @@ class WebsocketClientSpec extends FreeSpec with Matchers with WithMaterializerSp lazy val messagesIn = TestSubscriber.probe[Message]() override def clientImplementation: Flow[Message, Message, Unit] = - Flow.fromSinkAndSourceMat(Sink(messagesIn), Source(messagesOut))(Keep.none) + Flow.fromSinkAndSourceMat(Sink.fromSubscriber(messagesIn), Source.fromPublisher(messagesOut))(Keep.none) } } diff --git a/akka-http-core/src/test/scala/akka/http/scaladsl/ClientServerSpec.scala b/akka-http-core/src/test/scala/akka/http/scaladsl/ClientServerSpec.scala index 26705d52a6..da6d955260 100644 --- a/akka-http-core/src/test/scala/akka/http/scaladsl/ClientServerSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/scaladsl/ClientServerSpec.scala @@ -49,7 +49,7 @@ class ClientServerSpec extends WordSpec with Matchers with BeforeAndAfterAll { "properly bind a server" in { val (_, hostname, port) = TestUtils.temporaryServerHostnameAndPort() val probe = TestSubscriber.manualProbe[Http.IncomingConnection]() - val binding = Http().bind(hostname, port).toMat(Sink(probe))(Keep.left).run() + val binding = Http().bind(hostname, port).toMat(Sink.fromSubscriber(probe))(Keep.left).run() val sub = probe.expectSubscription() // if we get it we are bound val address = Await.result(binding, 1.second).localAddress sub.cancel() @@ -60,15 +60,15 @@ class ClientServerSpec extends WordSpec with Matchers with BeforeAndAfterAll { val binding = Http().bind(hostname, port) val probe1 = TestSubscriber.manualProbe[Http.IncomingConnection]() // Bind succeeded, we have a local address - val b1 = Await.result(binding.to(Sink(probe1)).run(), 3.seconds) + val b1 = Await.result(binding.to(Sink.fromSubscriber(probe1)).run(), 3.seconds) probe1.expectSubscription() val probe2 = TestSubscriber.manualProbe[Http.IncomingConnection]() - an[BindFailedException] shouldBe thrownBy { Await.result(binding.to(Sink(probe2)).run(), 3.seconds) } + an[BindFailedException] shouldBe thrownBy { Await.result(binding.to(Sink.fromSubscriber(probe2)).run(), 3.seconds) } probe2.expectSubscriptionAndError() val probe3 = TestSubscriber.manualProbe[Http.IncomingConnection]() - an[BindFailedException] shouldBe thrownBy { Await.result(binding.to(Sink(probe3)).run(), 3.seconds) } + an[BindFailedException] shouldBe thrownBy { Await.result(binding.to(Sink.fromSubscriber(probe3)).run(), 3.seconds) } probe3.expectSubscriptionAndError() // Now unbind the first @@ -78,7 +78,7 @@ class ClientServerSpec extends WordSpec with Matchers with BeforeAndAfterAll { if (!akka.util.Helpers.isWindows) { val probe4 = TestSubscriber.manualProbe[Http.IncomingConnection]() // Bind succeeded, we have a local address - val b2 = Await.result(binding.to(Sink(probe4)).run(), 3.seconds) + val b2 = Await.result(binding.to(Sink.fromSubscriber(probe4)).run(), 3.seconds) probe4.expectSubscription() // clean up @@ -448,7 +448,7 @@ class ClientServerSpec extends WordSpec with Matchers with BeforeAndAfterAll { val settings = configOverrides.toOption.fold(ServerSettings(system))(ServerSettings(_)) val connections = Http().bind(hostname, port, settings = settings) val probe = TestSubscriber.manualProbe[Http.IncomingConnection] - val binding = connections.toMat(Sink(probe))(Keep.left).run() + val binding = connections.toMat(Sink.fromSubscriber(probe))(Keep.left).run() (probe, binding) } val connSourceSub = connSource.expectSubscription() @@ -457,9 +457,9 @@ class ClientServerSpec extends WordSpec with Matchers with BeforeAndAfterAll { val requestPublisherProbe = TestPublisher.manualProbe[HttpRequest]() val responseSubscriberProbe = TestSubscriber.manualProbe[HttpResponse]() - val connectionFuture = Source(requestPublisherProbe) + val connectionFuture = Source.fromPublisher(requestPublisherProbe) .viaMat(Http().outgoingConnection(hostname, port, settings = settings))(Keep.right) - .to(Sink(responseSubscriberProbe)).run() + .to(Sink.fromSubscriber(responseSubscriberProbe)).run() val connection = Await.result(connectionFuture, 3.seconds) @@ -471,8 +471,8 @@ class ClientServerSpec extends WordSpec with Matchers with BeforeAndAfterAll { def acceptConnection(): (TestSubscriber.ManualProbe[HttpRequest], TestPublisher.ManualProbe[HttpResponse]) = { connSourceSub.request(1) val incomingConnection = connSource.expectNext() - val sink = Sink.publisher[HttpRequest](false) - val source = Source.subscriber[HttpResponse] + val sink = Sink.asPublisher[HttpRequest](false) + val source = Source.asSubscriber[HttpResponse] val handler = Flow.fromSinkAndSourceMat(sink, source)(Keep.both) diff --git a/akka-http-core/src/test/scala/akka/http/scaladsl/model/HttpEntitySpec.scala b/akka-http-core/src/test/scala/akka/http/scaladsl/model/HttpEntitySpec.scala index e8fe77e9df..5275399d48 100755 --- a/akka-http-core/src/test/scala/akka/http/scaladsl/model/HttpEntitySpec.scala +++ b/akka-http-core/src/test/scala/akka/http/scaladsl/model/HttpEntitySpec.scala @@ -89,7 +89,7 @@ class HttpEntitySpec extends FreeSpec with MustMatchers with BeforeAndAfterAll { "Infinite data stream" in { val neverCompleted = Promise[ByteString]() intercept[TimeoutException] { - Await.result(Default(tpe, 42, Source(neverCompleted.future)).toStrict(100.millis), 150.millis) + Await.result(Default(tpe, 42, Source.fromFuture(neverCompleted.future)).toStrict(100.millis), 150.millis) }.getMessage must be("HttpEntity.toStrict timed out after 100 milliseconds while still waiting for outstanding data") } } diff --git a/akka-http-testkit/src/main/scala/akka/http/scaladsl/testkit/WSProbe.scala b/akka-http-testkit/src/main/scala/akka/http/scaladsl/testkit/WSProbe.scala index dc93cbe2cb..671f68c762 100644 --- a/akka-http-testkit/src/main/scala/akka/http/scaladsl/testkit/WSProbe.scala +++ b/akka-http-testkit/src/main/scala/akka/http/scaladsl/testkit/WSProbe.scala @@ -104,7 +104,7 @@ object WSProbe { val subscriber = TestSubscriber.probe[Message]() val publisher = TestPublisher.probe[Message]() - def flow: Flow[Message, Message, Unit] = Flow.fromSinkAndSourceMat(Sink(subscriber), Source(publisher))(Keep.none) + def flow: Flow[Message, Message, Unit] = Flow.fromSinkAndSourceMat(Sink.fromSubscriber(subscriber), Source.fromPublisher(publisher))(Keep.none) def sendMessage(message: Message): Unit = publisher.sendNext(message) def sendMessage(text: String): Unit = sendMessage(TextMessage(text)) @@ -139,4 +139,4 @@ object WSProbe { .awaitResult(maxChunkCollectionMills.millis) .reduce(reduce) } -} \ No newline at end of file +} diff --git a/akka-http-tests/src/test/scala/akka/http/scaladsl/coding/CoderSpec.scala b/akka-http-tests/src/test/scala/akka/http/scaladsl/coding/CoderSpec.scala index 3529f58cd3..4927987f78 100644 --- a/akka-http-tests/src/test/scala/akka/http/scaladsl/coding/CoderSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/scaladsl/coding/CoderSpec.scala @@ -138,7 +138,7 @@ abstract class CoderSpec extends WordSpec with CodecSpecSupport with Inspectors ByteString(Array.fill(size)(1.toByte)) val sizesAfterRoundtrip = - Source(() ⇒ sizes.toIterator.map(createByteString)) + Source.fromIterator(() ⇒ sizes.toIterator.map(createByteString)) .via(Coder.encoderFlow) .via(Coder.decoderFlow) .runFold(Seq.empty[Int])(_ :+ _.size) @@ -186,5 +186,5 @@ abstract class CoderSpec extends WordSpec with CodecSpecSupport with Inspectors input.via(Coder.decoderFlow).join.awaitResult(3.seconds) def decodeFromIterator(iterator: () ⇒ Iterator[ByteString]): ByteString = - Await.result(Source(iterator).via(Coder.decoderFlow).join, 3.seconds) + Await.result(Source.fromIterator(iterator).via(Coder.decoderFlow).join, 3.seconds) } diff --git a/akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives/CodingDirectivesSpec.scala b/akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives/CodingDirectivesSpec.scala index 9a9487153c..1a6f92debc 100644 --- a/akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives/CodingDirectivesSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/scaladsl/server/directives/CodingDirectivesSpec.scala @@ -201,7 +201,7 @@ class CodingDirectivesSpec extends RoutingSpec with Inside { () ⇒ text.grouped(8).map { chars ⇒ Chunk(chars.mkString): ChunkStreamPart } - val chunkedTextEntity = HttpEntity.Chunked(ContentTypes.`text/plain(UTF-8)`, Source(textChunks)) + val chunkedTextEntity = HttpEntity.Chunked(ContentTypes.`text/plain(UTF-8)`, Source.fromIterator(textChunks)) Post() ~> `Accept-Encoding`(gzip) ~> { encodeResponseWith(Gzip) { diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/ConcatTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/ConcatTest.scala index fda7efcd7b..138a0be139 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/ConcatTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/ConcatTest.scala @@ -10,7 +10,7 @@ import org.reactivestreams.Publisher class ConcatTest extends AkkaPublisherVerification[Int] { def createPublisher(elements: Long): Publisher[Int] = { - Source(iterable(elements / 2)).concat(Source(iterable((elements + 1) / 2))).runWith(Sink.publisher(false)) + Source(iterable(elements / 2)).concat(Source(iterable((elements + 1) / 2))).runWith(Sink.asPublisher(false)) } } diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/FanoutPublisherTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/FanoutPublisherTest.scala index 1668a9a31c..2a71a2f650 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/FanoutPublisherTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/FanoutPublisherTest.scala @@ -15,7 +15,7 @@ class FanoutPublisherTest extends AkkaPublisherVerification[Int] { if (elements == 0) new immutable.Iterable[Int] { override def iterator = Iterator from 0 } else 0 until elements.toInt - Source(iterable).runWith(Sink.publisher(true)) + Source(iterable).runWith(Sink.asPublisher(true)) } } diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/FilePublisherTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/FilePublisherTest.scala index f8dd790fb0..ed1da8da97 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/FilePublisherTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/FilePublisherTest.scala @@ -38,7 +38,7 @@ class FilePublisherTest extends AkkaPublisherVerification[ByteString] { def createPublisher(elements: Long): Publisher[ByteString] = Source.file(file, chunkSize = 512) .take(elements) - .runWith(Sink.publisher(false)) + .runWith(Sink.asPublisher(false)) @AfterClass def after = file.delete() diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/FlattenTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/FlattenTest.scala index 5257cd018c..5e81535058 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/FlattenTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/FlattenTest.scala @@ -13,7 +13,7 @@ class FlattenTest extends AkkaPublisherVerification[Int] { def createPublisher(elements: Long): Publisher[Int] = { val s1 = Source(iterable(elements / 2)) val s2 = Source(iterable((elements + 1) / 2)) - Source(List(s1, s2)).flatMapConcat(ConstantFun.scalaIdentityFunction).runWith(Sink.publisher(false)) + Source(List(s1, s2)).flatMapConcat(ConstantFun.scalaIdentityFunction).runWith(Sink.asPublisher(false)) } } diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/FoldSinkSubscriberTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/FoldSinkSubscriberTest.scala index bd8c303767..c4cd4c4476 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/FoldSinkSubscriberTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/FoldSinkSubscriberTest.scala @@ -9,7 +9,7 @@ import org.reactivestreams.Subscriber class FoldSinkSubscriberTest extends AkkaSubscriberBlackboxVerification[Int] { override def createSubscriber(): Subscriber[Int] = - Flow[Int].to(Sink.fold(0)(_ + _)).runWith(Source.subscriber) + Flow[Int].to(Sink.fold(0)(_ + _)).runWith(Source.asSubscriber) override def createElement(element: Int): Int = element } diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/ForeachSinkSubscriberTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/ForeachSinkSubscriberTest.scala index 4f999bcd21..7a6a9722fa 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/ForeachSinkSubscriberTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/ForeachSinkSubscriberTest.scala @@ -9,7 +9,7 @@ import org.reactivestreams.Subscriber class ForeachSinkSubscriberTest extends AkkaSubscriberBlackboxVerification[Int] { override def createSubscriber(): Subscriber[Int] = - Flow[Int].to(Sink.foreach { _ ⇒ }).runWith(Source.subscriber) + Flow[Int].to(Sink.foreach { _ ⇒ }).runWith(Source.asSubscriber) override def createElement(element: Int): Int = element } diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/FuturePublisherTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/FuturePublisherTest.scala index 7c72dc7d88..c22553f6fd 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/FuturePublisherTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/FuturePublisherTest.scala @@ -13,7 +13,7 @@ class FuturePublisherTest extends AkkaPublisherVerification[Int] { def createPublisher(elements: Long): Publisher[Int] = { val p = Promise[Int]() - val pub = Source(p.future).runWith(Sink.publisher(false)) + val pub = Source.fromFuture(p.future).runWith(Sink.asPublisher(false)) p.success(0) pub } diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/GroupByTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/GroupByTest.scala index dcffd2e1fe..a8aafc44a8 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/GroupByTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/GroupByTest.scala @@ -24,7 +24,7 @@ class GroupByTest extends AkkaPublisherVerification[Int] { .concatSubstreams .runWith(Sink.head) val groupSource = Await.result(futureGroupSource, 3.seconds) - groupSource.runWith(Sink.publisher(false)) + groupSource.runWith(Sink.asPublisher(false)) } diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/IterablePublisherTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/IterablePublisherTest.scala index ec107f078c..756ef13b70 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/IterablePublisherTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/IterablePublisherTest.scala @@ -11,7 +11,7 @@ import org.reactivestreams._ class IterablePublisherTest extends AkkaPublisherVerification[Int] { override def createPublisher(elements: Long): Publisher[Int] = { - Source(iterable(elements)).runWith(Sink.publisher(false)) + Source(iterable(elements)).runWith(Sink.asPublisher(false)) } } diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/MaybeSourceTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/MaybeSourceTest.scala index bc02853256..b7b08edfa9 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/MaybeSourceTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/MaybeSourceTest.scala @@ -10,7 +10,7 @@ import akka.stream.scaladsl.{ Keep, Source, Sink } class MaybeSourceTest extends AkkaPublisherVerification[Int] { def createPublisher(elements: Long): Publisher[Int] = { - val (p, pub) = Source.maybe[Int].toMat(Sink.publisher(false))(Keep.both).run() + val (p, pub) = Source.maybe[Int].toMat(Sink.asPublisher(false))(Keep.both).run() p success Some(1) pub } diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/PrefixAndTailTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/PrefixAndTailTest.scala index 0262ccc6dd..d7a9a3e623 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/PrefixAndTailTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/PrefixAndTailTest.scala @@ -15,7 +15,7 @@ class PrefixAndTailTest extends AkkaPublisherVerification[Int] { def createPublisher(elements: Long): Publisher[Int] = { val futureTailSource = Source(iterable(elements)).prefixAndTail(0).map { case (_, tail) ⇒ tail }.runWith(Sink.head) val tailSource = Await.result(futureTailSource, 3.seconds) - tailSource.runWith(Sink.publisher(false)) + tailSource.runWith(Sink.asPublisher(false)) } } diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/SingleElementSourceTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/SingleElementSourceTest.scala index 4267e602a4..d2701cf474 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/SingleElementSourceTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/SingleElementSourceTest.scala @@ -11,7 +11,7 @@ import org.reactivestreams.Publisher class SingleElementSourceTest extends AkkaPublisherVerification[Int] { def createPublisher(elements: Long): Publisher[Int] = - Source.single(1).runWith(Sink.publisher(false)) + Source.single(1).runWith(Sink.asPublisher(false)) override def maxElementsFromPublisher(): Long = 1 } diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/SplitWhenTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/SplitWhenTest.scala index ff8d490131..1d1c44489b 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/SplitWhenTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/SplitWhenTest.scala @@ -24,7 +24,7 @@ class SplitWhenTest extends AkkaPublisherVerification[Int] { .concatSubstreams .runWith(Sink.head) val source = Await.result(futureSource, 3.seconds) - source.runWith(Sink.publisher(false)) + source.runWith(Sink.asPublisher(false)) } } diff --git a/akka-stream-testkit/src/test/scala/akka/stream/testkit/BaseTwoStreamsSetup.scala b/akka-stream-testkit/src/test/scala/akka/stream/testkit/BaseTwoStreamsSetup.scala index 72e36764d7..21df5cd02e 100644 --- a/akka-stream-testkit/src/test/scala/akka/stream/testkit/BaseTwoStreamsSetup.scala +++ b/akka-stream-testkit/src/test/scala/akka/stream/testkit/BaseTwoStreamsSetup.scala @@ -27,7 +27,7 @@ abstract class BaseTwoStreamsSetup extends AkkaSpec { def completedPublisher[T]: Publisher[T] = TestPublisher.empty[T] - def nonemptyPublisher[T](elems: immutable.Iterable[T]): Publisher[T] = Source(elems).runWith(Sink.publisher(false)) + def nonemptyPublisher[T](elems: immutable.Iterable[T]): Publisher[T] = Source(elems).runWith(Sink.asPublisher(false)) def soonToFailPublisher[T]: Publisher[T] = TestPublisher.lazyError[T](TestException) diff --git a/akka-stream-testkit/src/test/scala/akka/stream/testkit/ChainSetup.scala b/akka-stream-testkit/src/test/scala/akka/stream/testkit/ChainSetup.scala index 25935ad95a..344583b0f9 100644 --- a/akka-stream-testkit/src/test/scala/akka/stream/testkit/ChainSetup.scala +++ b/akka-stream-testkit/src/test/scala/akka/stream/testkit/ChainSetup.scala @@ -24,7 +24,7 @@ class ChainSetup[In, Out, M]( val upstream = TestPublisher.manualProbe[In]() val downstream = TestSubscriber.probe[Out]() - private val s = Source(upstream).via(stream(Flow[In].map(x ⇒ x).named("buh"))) + private val s = Source.fromPublisher(upstream).via(stream(Flow[In].map(x ⇒ x).named("buh"))) val publisher = toPublisher(s, materializer) val upstreamSubscription = upstream.expectSubscription() publisher.subscribe(downstream) diff --git a/akka-stream-testkit/src/test/scala/akka/stream/testkit/ScriptedTest.scala b/akka-stream-testkit/src/test/scala/akka/stream/testkit/ScriptedTest.scala index 8258485c86..73c6402c80 100644 --- a/akka-stream-testkit/src/test/scala/akka/stream/testkit/ScriptedTest.scala +++ b/akka-stream-testkit/src/test/scala/akka/stream/testkit/ScriptedTest.scala @@ -20,7 +20,7 @@ trait ScriptedTest extends Matchers { class ScriptException(msg: String) extends RuntimeException(msg) def toPublisher[In, Out]: (Source[Out, _], ActorMaterializer) ⇒ Publisher[Out] = - (f, m) ⇒ f.runWith(Sink.publisher(false))(m) + (f, m) ⇒ f.runWith(Sink.asPublisher(false))(m) object Script { def apply[In, Out](phases: (Seq[In], Seq[Out])*): Script[In, Out] = { diff --git a/akka-stream-testkit/src/test/scala/akka/stream/testkit/StreamTestKitSpec.scala b/akka-stream-testkit/src/test/scala/akka/stream/testkit/StreamTestKitSpec.scala index ef26568677..9bdc027770 100644 --- a/akka-stream-testkit/src/test/scala/akka/stream/testkit/StreamTestKitSpec.scala +++ b/akka-stream-testkit/src/test/scala/akka/stream/testkit/StreamTestKitSpec.scala @@ -23,7 +23,7 @@ class StreamTestKitSpec extends AkkaSpec { "#toStrict with failing source" in { val msg = intercept[AssertionError] { - Source(() ⇒ new Iterator[Int] { + Source.fromIterator(() ⇒ new Iterator[Int] { var i = 0 override def hasNext: Boolean = true override def next(): Int = { diff --git a/akka-stream-testkit/src/test/scala/akka/stream/testkit/TestPublisherSubscriberSpec.scala b/akka-stream-testkit/src/test/scala/akka/stream/testkit/TestPublisherSubscriberSpec.scala index f500d6c45b..83230f3596 100644 --- a/akka-stream-testkit/src/test/scala/akka/stream/testkit/TestPublisherSubscriberSpec.scala +++ b/akka-stream-testkit/src/test/scala/akka/stream/testkit/TestPublisherSubscriberSpec.scala @@ -22,7 +22,7 @@ class TestPublisherSubscriberSpec extends AkkaSpec { "have all events accessible from manual probes" in assertAllStagesStopped { val upstream = TestPublisher.manualProbe[Int]() val downstream = TestSubscriber.manualProbe[Int]() - Source(upstream).runWith(Sink.publisher(false))(materializer).subscribe(downstream) + Source.fromPublisher(upstream).runWith(Sink.asPublisher(false))(materializer).subscribe(downstream) val upstreamSubscription = upstream.expectSubscription() val downstreamSubscription: Subscription = downstream.expectEventPF { case OnSubscribe(sub) ⇒ sub } @@ -46,7 +46,7 @@ class TestPublisherSubscriberSpec extends AkkaSpec { "handle gracefully partial function that is not suitable" in assertAllStagesStopped { val upstream = TestPublisher.manualProbe[Int]() val downstream = TestSubscriber.manualProbe[Int]() - Source(upstream).runWith(Sink.publisher(false))(materializer).subscribe(downstream) + Source.fromPublisher(upstream).runWith(Sink.asPublisher(false))(materializer).subscribe(downstream) val upstreamSubscription = upstream.expectSubscription() val downstreamSubscription: Subscription = downstream.expectEventPF { case OnSubscribe(sub) ⇒ sub } diff --git a/akka-stream-testkit/src/test/scala/akka/stream/testkit/TwoStreamsSetup.scala b/akka-stream-testkit/src/test/scala/akka/stream/testkit/TwoStreamsSetup.scala index 69d515c258..9c0785a167 100644 --- a/akka-stream-testkit/src/test/scala/akka/stream/testkit/TwoStreamsSetup.scala +++ b/akka-stream-testkit/src/test/scala/akka/stream/testkit/TwoStreamsSetup.scala @@ -23,9 +23,9 @@ abstract class TwoStreamsSetup extends BaseTwoStreamsSetup { import GraphDSL.Implicits._ val f = fixture(b) - Source(p1) ~> f.left - Source(p2) ~> f.right - f.out ~> Sink(subscriber) + Source.fromPublisher(p1) ~> f.left + Source.fromPublisher(p2) ~> f.right + f.out ~> Sink.fromSubscriber(subscriber) ClosedShape }).run() diff --git a/akka-stream-tests/src/test/java/akka/stream/actor/ActorPublisherTest.java b/akka-stream-tests/src/test/java/akka/stream/actor/ActorPublisherTest.java index b6a6fdf0a1..d5672555d6 100644 --- a/akka-stream-tests/src/test/java/akka/stream/actor/ActorPublisherTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/actor/ActorPublisherTest.java @@ -42,7 +42,7 @@ public class ActorPublisherTest extends StreamTest { final ActorRef ref = system .actorOf(Props.create(TestPublisher.class).withDispatcher("akka.test.stream-dispatcher")); final Publisher publisher = UntypedActorPublisher.create(ref); - Source.from(publisher) + Source.fromPublisher(publisher) .runForeach(new akka.japi.function.Procedure() { @Override public void apply(Integer elem) throws Exception { diff --git a/akka-stream-tests/src/test/java/akka/stream/actor/ActorSubscriberTest.java b/akka-stream-tests/src/test/java/akka/stream/actor/ActorSubscriberTest.java index 84cef63ceb..9e8b875888 100644 --- a/akka-stream-tests/src/test/java/akka/stream/actor/ActorSubscriberTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/actor/ActorSubscriberTest.java @@ -63,7 +63,7 @@ public class ActorSubscriberTest extends StreamTest { final Subscriber subscriber = UntypedActorSubscriber.create(ref); final java.lang.Iterable input = Arrays.asList(1, 2, 3); - Source.from(input).runWith(Sink.create(subscriber), materializer); + Source.from(input).runWith(Sink.fromSubscriber(subscriber), materializer); ref.tell("run", null); probe.expectMsgEquals(1); diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowGraphTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowGraphTest.java index 0ddede4ec3..f20564ae2b 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowGraphTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowGraphTest.java @@ -67,8 +67,8 @@ public class FlowGraphTest extends StreamTest { final Source in1 = Source.from(Arrays.asList("a", "b", "c")); final Source in2 = Source.from(Arrays.asList("d", "e", "f")); - final Sink> publisher = Sink.publisher(false); - + final Sink> publisher = Sink.asPublisher(false); + final Source source = Source.fromGraph( GraphDSL.create(new Function, SourceShape>() { @Override @@ -82,7 +82,7 @@ public class FlowGraphTest extends StreamTest { // collecting final Publisher pub = source.runWith(publisher, materializer); - final Future> all = Source.from(pub).grouped(100).runWith(Sink.>head(), materializer); + final Future> all = Source.fromPublisher(pub).grouped(100).runWith(Sink.>head(), materializer); final List result = Await.result(all, Duration.apply(200, TimeUnit.MILLISECONDS)); assertEquals(new HashSet(Arrays.asList("a", "b", "c", "d", "e", "f")), new HashSet(result)); @@ -257,7 +257,7 @@ public class FlowGraphTest extends StreamTest { return l + r; } }); - + final Future future = RunnableGraph.fromGraph(GraphDSL.create(Sink.head(), new Function2>, SinkShape, ClosedShape>() { @Override diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowTest.java index b4b00096ba..a2cdf5e950 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/FlowTest.java @@ -249,7 +249,7 @@ public class FlowTest extends StreamTest { }) .grouped(10) .mergeSubstreams(); - + final Future>> future = Source.from(input).via(flow).grouped(10).runWith(Sink.>> head(), materializer); final Object[] result = Await.result(future, Duration.create(1, TimeUnit.SECONDS)).toArray(); @@ -335,7 +335,7 @@ public class FlowTest extends StreamTest { final Source in1 = Source.from(Arrays.asList("a", "b", "c")); final Source in2 = Source.from(Arrays.asList("d", "e", "f")); - final Sink> publisher = Sink.publisher(false); + final Sink> publisher = Sink.asPublisher(false); final Source source = Source.fromGraph( GraphDSL.create(new Function, SourceShape>() { @@ -350,7 +350,7 @@ public class FlowTest extends StreamTest { // collecting final Publisher pub = source.runWith(publisher, materializer); - final Future> all = Source.from(pub).grouped(100).runWith(Sink.>head(), materializer); + final Future> all = Source.fromPublisher(pub).grouped(100).runWith(Sink.>head(), materializer); final List result = Await.result(all, Duration.apply(200, TimeUnit.MILLISECONDS)); assertEquals(new HashSet(Arrays.asList("a", "b", "c", "d", "e", "f")), new HashSet(result)); @@ -443,7 +443,7 @@ public class FlowTest extends StreamTest { assertEquals(Arrays.asList(1, 2, 3, 4, 5), result); } - + @Test public void mustBeAbleToUseFlatMapMerge() throws Exception { final JavaTestKit probe = new JavaTestKit(system); @@ -558,7 +558,7 @@ public class FlowTest extends StreamTest { final TestPublisher.ManualProbe publisherProbe = TestPublisher.manualProbe(true,system); final JavaTestKit probe = new JavaTestKit(system); - final Source source = Source.from(publisherProbe); + final Source source = Source.fromPublisher(publisherProbe); final Flow flow = Flow.of(Integer.class).map( new Function() { public Integer apply(Integer elem) { diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/SinkTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/SinkTest.java index 4cc982c71c..b0bbb22a13 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/SinkTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/SinkTest.java @@ -39,7 +39,7 @@ public class SinkTest extends StreamTest { @Test public void mustBeAbleToUseFanoutPublisher() throws Exception { - final Sink> pubSink = Sink.publisher(true); + final Sink> pubSink = Sink.asPublisher(true); @SuppressWarnings("unused") final Publisher publisher = Source.from(new ArrayList()).runWith(pubSink, materializer); } diff --git a/akka-stream-tests/src/test/java/akka/stream/javadsl/SourceTest.java b/akka-stream-tests/src/test/java/akka/stream/javadsl/SourceTest.java index 3f7164b580..b934c21be8 100644 --- a/akka-stream-tests/src/test/java/akka/stream/javadsl/SourceTest.java +++ b/akka-stream-tests/src/test/java/akka/stream/javadsl/SourceTest.java @@ -176,7 +176,7 @@ public class SourceTest extends StreamTest { }) .grouped(10) .mergeSubstreams(); - + final Future>> future = source.grouped(10).runWith(Sink.>> head(), materializer); final Object[] result = Await.result(future, Duration.create(1, TimeUnit.SECONDS)).toArray(); @@ -478,7 +478,7 @@ public class SourceTest extends StreamTest { final JavaTestKit probe = new JavaTestKit(system); final Iterable input = Arrays.asList("A", "B", "C"); Future future1 = Source.from(input).runWith(Sink.head(), materializer); - Future future2 = Source.from(future1).runWith(Sink.head(), materializer); + Future future2 = Source.fromFuture(future1).runWith(Sink.head(), materializer); String result = Await.result(future2, probe.dilated(FiniteDuration.create(3, TimeUnit.SECONDS))); assertEquals("A", result); } @@ -579,7 +579,7 @@ public class SourceTest extends StreamTest { final ManualProbe publisherProbe = TestPublisher.manualProbe(true,system); final JavaTestKit probe = new JavaTestKit(system); - final Source source = Source.from(publisherProbe).map( + final Source source = Source.fromPublisher(publisherProbe).map( new Function() { public Integer apply(Integer elem) { if (elem == 1) throw new RuntimeException("ex"); diff --git a/akka-stream-tests/src/test/scala/akka/stream/actor/ActorPublisherSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/actor/ActorPublisherSpec.scala index 73b7b9392d..aeebcc0090 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/actor/ActorPublisherSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/actor/ActorPublisherSpec.scala @@ -345,9 +345,9 @@ class ActorPublisherSpec extends AkkaSpec(ActorPublisherSpec.config) with Implic val probe2 = TestProbe() val senderRef1 = system.actorOf(senderProps) - val source1 = Source(ActorPublisher[Int](senderRef1)) + val source1 = Source.fromPublisher(ActorPublisher[Int](senderRef1)) - val sink1 = Sink(ActorSubscriber[String](system.actorOf(receiverProps(probe1.ref)))) + val sink1 = Sink.fromSubscriber(ActorSubscriber[String](system.actorOf(receiverProps(probe1.ref)))) val sink2: Sink[String, ActorRef] = Sink.actorSubscriber(receiverProps(probe2.ref)) val senderRef2 = RunnableGraph.fromGraph(GraphDSL.create(Source.actorPublisher[Int](senderProps)) { implicit b ⇒ @@ -420,7 +420,7 @@ class ActorPublisherSpec extends AkkaSpec(ActorPublisherSpec.config) with Implic implicit val materializer = ActorMaterializer( ActorMaterializerSettings(system).withDispatcher("my-dispatcher1")) val s = TestSubscriber.manualProbe[String]() - val ref = Source.actorPublisher(testPublisherProps(testActor, useTestDispatcher = false)).to(Sink(s)).run() + val ref = Source.actorPublisher(testPublisherProps(testActor, useTestDispatcher = false)).to(Sink.fromSubscriber(s)).run() ref ! ThreadName expectMsgType[String] should include("my-dispatcher1") } @@ -430,7 +430,7 @@ class ActorPublisherSpec extends AkkaSpec(ActorPublisherSpec.config) with Implic val s = TestSubscriber.manualProbe[String]() val ref = Source.actorPublisher(testPublisherProps(testActor, useTestDispatcher = false)) .withAttributes(ActorAttributes.dispatcher("my-dispatcher1")) - .to(Sink(s)).run() + .to(Sink.fromSubscriber(s)).run() ref ! ThreadName expectMsgType[String] should include("my-dispatcher1") } @@ -440,7 +440,7 @@ class ActorPublisherSpec extends AkkaSpec(ActorPublisherSpec.config) with Implic val s = TestSubscriber.manualProbe[String]() val ref = Source.actorPublisher(testPublisherProps(testActor, useTestDispatcher = false).withDispatcher("my-dispatcher1")) .withAttributes(ActorAttributes.dispatcher("my-dispatcher2")) - .to(Sink(s)).run() + .to(Sink.fromSubscriber(s)).run() ref ! ThreadName expectMsgType[String] should include("my-dispatcher1") } diff --git a/akka-stream-tests/src/test/scala/akka/stream/actor/ActorSubscriberSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/actor/ActorSubscriberSpec.scala index 51f43e4099..32132014fe 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/actor/ActorSubscriberSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/actor/ActorSubscriberSpec.scala @@ -125,7 +125,7 @@ class ActorSubscriberSpec extends AkkaSpec with ImplicitSender { "signal error" in { val e = new RuntimeException("simulated") with NoStackTrace - val ref = Source(() ⇒ throw e).runWith(Sink.actorSubscriber(manualSubscriberProps(testActor))) + val ref = Source.fromIterator(() ⇒ throw e).runWith(Sink.actorSubscriber(manualSubscriberProps(testActor))) ref ! "ready" expectMsg(OnError(e)) } @@ -133,7 +133,7 @@ class ActorSubscriberSpec extends AkkaSpec with ImplicitSender { "remember requested after restart" in { // creating actor with default supervision, because stream supervisor default strategy is to stop val ref = system.actorOf(manualSubscriberProps(testActor)) - Source(1 to 7).runWith(Sink(ActorSubscriber[Int](ref))) + Source(1 to 7).runWith(Sink.fromSubscriber(ActorSubscriber[Int](ref))) ref ! "ready" expectMsg(OnNext(1)) expectMsg(OnNext(2)) diff --git a/akka-stream-tests/src/test/scala/akka/stream/extra/FlowTimedSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/extra/FlowTimedSpec.scala index 3c08de4171..c61a38888f 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/extra/FlowTimedSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/extra/FlowTimedSpec.scala @@ -79,7 +79,7 @@ class FlowTimedSpec extends AkkaSpec with ScriptedTest { val flow: Flow[Int, Long, _] = Flow[Int].map(_.toLong).timedIntervalBetween(in ⇒ in % 2 == 1, d ⇒ probe.ref ! d) val c1 = TestSubscriber.manualProbe[Long]() - Source(List(1, 2, 3)).via(flow).runWith(Sink(c1)) + Source(List(1, 2, 3)).via(flow).runWith(Sink.fromSubscriber(c1)) val s = c1.expectSubscription() s.request(100) @@ -104,12 +104,12 @@ class FlowTimedSpec extends AkkaSpec with ScriptedTest { map(_.toString), duration ⇒ probe.ref ! duration). map { s: String ⇒ s + "!" } - val (flowIn: Subscriber[Int], flowOut: Publisher[String]) = flow.runWith(Source.subscriber[Int], Sink.publisher[String](false)) + val (flowIn: Subscriber[Int], flowOut: Publisher[String]) = flow.runWith(Source.asSubscriber[Int], Sink.asPublisher[String](false)) val c1 = TestSubscriber.manualProbe[String]() val c2 = flowOut.subscribe(c1) - val p = Source(0 to 100).runWith(Sink.publisher(false)) + val p = Source(0 to 100).runWith(Sink.asPublisher(false)) p.subscribe(flowIn) val s = c1.expectSubscription() diff --git a/akka-stream-tests/src/test/scala/akka/stream/impl/TimeoutsSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/impl/TimeoutsSpec.scala index ba380006db..fdd1dfae06 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/impl/TimeoutsSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/impl/TimeoutsSpec.scala @@ -41,7 +41,7 @@ class TimeoutsSpec extends AkkaSpec { val downstreamProbe = TestSubscriber.probe[Int]() Source.maybe[Int] .initialTimeout(1.second) - .runWith(Sink(downstreamProbe)) + .runWith(Sink.fromSubscriber(downstreamProbe)) downstreamProbe.expectSubscription() downstreamProbe.expectNoMsg(500.millis) @@ -73,9 +73,9 @@ class TimeoutsSpec extends AkkaSpec { "fail if not completed until timeout" in assertAllStagesStopped { val upstreamProbe = TestPublisher.probe[Int]() val downstreamProbe = TestSubscriber.probe[Int]() - Source(upstreamProbe) + Source.fromPublisher(upstreamProbe) .completionTimeout(2.seconds) - .runWith(Sink(downstreamProbe)) + .runWith(Sink.fromSubscriber(downstreamProbe)) upstreamProbe.sendNext(1) downstreamProbe.requestNext(1) @@ -112,9 +112,9 @@ class TimeoutsSpec extends AkkaSpec { "fail if time between elements is too large" in assertAllStagesStopped { val upstreamProbe = TestPublisher.probe[Int]() val downstreamProbe = TestSubscriber.probe[Int]() - Source(upstreamProbe) + Source.fromPublisher(upstreamProbe) .idleTimeout(1.seconds) - .runWith(Sink(downstreamProbe)) + .runWith(Sink.fromSubscriber(downstreamProbe)) // Two seconds in overall, but won't timeout until time between elements is large enough // (i.e. this works differently from completionTimeout) @@ -144,8 +144,8 @@ class TimeoutsSpec extends AkkaSpec { val upstreamWriter = TestPublisher.probe[Int]() val downstreamWriter = TestPublisher.probe[String]() - val upstream = Flow.fromSinkAndSourceMat(Sink.ignore, Source(upstreamWriter))(Keep.left) - val downstream = Flow.fromSinkAndSourceMat(Sink.ignore, Source(downstreamWriter))(Keep.left) + val upstream = Flow.fromSinkAndSourceMat(Sink.ignore, Source.fromPublisher(upstreamWriter))(Keep.left) + val downstream = Flow.fromSinkAndSourceMat(Sink.ignore, Source.fromPublisher(downstreamWriter))(Keep.left) val assembly: RunnableGraph[(Future[Unit], Future[Unit])] = upstream .joinMat(BidiFlow.bidirectionalIdleTimeout[Int, String](2.seconds))(Keep.left) @@ -177,10 +177,10 @@ class TimeoutsSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ import GraphDSL.Implicits._ val timeoutStage = b.add(BidiFlow.bidirectionalIdleTimeout[String, Int](2.seconds)) - Source(upWrite) ~> timeoutStage.in1; - timeoutStage.out1 ~> Sink(downRead) - Sink(upRead) <~ timeoutStage.out2; - timeoutStage.in2 <~ Source(downWrite) + Source.fromPublisher(upWrite) ~> timeoutStage.in1; + timeoutStage.out1 ~> Sink.fromSubscriber(downRead) + Sink.fromSubscriber(upRead) <~ timeoutStage.out2; + timeoutStage.in2 <~ Source.fromPublisher(downWrite) ClosedShape }).run() @@ -225,10 +225,10 @@ class TimeoutsSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ import GraphDSL.Implicits._ val timeoutStage = b.add(BidiFlow.bidirectionalIdleTimeout[String, Int](2.seconds)) - Source(upWrite) ~> timeoutStage.in1; - timeoutStage.out1 ~> Sink(downRead) - Sink(upRead) <~ timeoutStage.out2; - timeoutStage.in2 <~ Source(downWrite) + Source.fromPublisher(upWrite) ~> timeoutStage.in1; + timeoutStage.out1 ~> Sink.fromSubscriber(downRead) + Sink.fromSubscriber(upRead) <~ timeoutStage.out2; + timeoutStage.in2 <~ Source.fromPublisher(downWrite) ClosedShape }).run() diff --git a/akka-stream-tests/src/test/scala/akka/stream/io/FileSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/io/FileSinkSpec.scala index 2c6f58fa9a..03d5ebe839 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io/FileSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io/FileSinkSpec.scala @@ -98,7 +98,7 @@ class FileSinkSpec extends AkkaSpec(UnboundedMailboxConfig) { implicit val timeout = Timeout(3.seconds) try { - Source(() ⇒ Iterator.continually(TestByteStrings.head)).runWith(Sink.file(f))(materializer) + Source.fromIterator(() ⇒ Iterator.continually(TestByteStrings.head)).runWith(Sink.file(f))(materializer) materializer.asInstanceOf[ActorMaterializerImpl].supervisor.tell(StreamSupervisor.GetChildren, testActor) val ref = expectMsgType[Children].children.find(_.path.toString contains "fileSource").get @@ -116,7 +116,7 @@ class FileSinkSpec extends AkkaSpec(UnboundedMailboxConfig) { implicit val timeout = Timeout(3.seconds) try { - Source(() ⇒ Iterator.continually(TestByteStrings.head)) + Source.fromIterator(() ⇒ Iterator.continually(TestByteStrings.head)) .to(Sink.file(f)) .withAttributes(ActorAttributes.dispatcher("akka.actor.default-dispatcher")) .run()(materializer) diff --git a/akka-stream-tests/src/test/scala/akka/stream/io/FileSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/io/FileSourceSpec.scala index 68bb762a75..09dc04b5cc 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io/FileSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io/FileSourceSpec.scala @@ -76,7 +76,7 @@ class FileSourceSpec extends AkkaSpec(UnboundedMailboxConfig) { val p = Source.file(testFile, chunkSize) .withAttributes(bufferAttributes) - .runWith(Sink.publisher(false)) + .runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[ByteString]() p.subscribe(c) val sub = c.expectSubscription() @@ -113,7 +113,7 @@ class FileSourceSpec extends AkkaSpec(UnboundedMailboxConfig) { val p = Source.file(testFile, chunkSize) .withAttributes(bufferAttributes) - .runWith(Sink.publisher(false)) + .runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[ByteString]() p.subscribe(c) @@ -140,7 +140,7 @@ class FileSourceSpec extends AkkaSpec(UnboundedMailboxConfig) { } "onError whent trying to read from file which does not exist" in assertAllStagesStopped { - val p = Source.file(notExistingFile).runWith(Sink.publisher(false)) + val p = Source.file(notExistingFile).runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[ByteString]() p.subscribe(c) diff --git a/akka-stream-tests/src/test/scala/akka/stream/io/TcpSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/io/TcpSpec.scala index 0bf1e8f879..620398bfdb 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io/TcpSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io/TcpSpec.scala @@ -31,7 +31,7 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val tcpReadProbe = new TcpReadProbe() val tcpWriteProbe = new TcpWriteProbe() - Source(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink(tcpReadProbe.subscriberProbe)).run() + Source.fromPublisher(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink.fromSubscriber(tcpReadProbe.subscriberProbe)).run() val serverConnection = server.waitAccept() validateServerClientCommunication(testData, serverConnection, tcpReadProbe, tcpWriteProbe) @@ -61,7 +61,7 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val idle = new TcpWriteProbe() // Just register an idle upstream val resultFuture = - Source(idle.publisherProbe) + Source.fromPublisher(idle.publisherProbe) .via(Tcp().outgoingConnection(server.address)) .runFold(ByteString.empty)((acc, in) ⇒ acc ++ in) val serverConnection = server.waitAccept() @@ -81,7 +81,7 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val tcpWriteProbe = new TcpWriteProbe() val tcpReadProbe = new TcpReadProbe() - Source(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink(tcpReadProbe.subscriberProbe)).run() + Source.fromPublisher(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink.fromSubscriber(tcpReadProbe.subscriberProbe)).run() val serverConnection = server.waitAccept() // Client can still write @@ -111,7 +111,7 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val tcpWriteProbe = new TcpWriteProbe() val tcpReadProbe = new TcpReadProbe() - Source(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink(tcpReadProbe.subscriberProbe)).run() + Source.fromPublisher(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink.fromSubscriber(tcpReadProbe.subscriberProbe)).run() val serverConnection = server.waitAccept() // Server can still write @@ -139,7 +139,7 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val tcpWriteProbe = new TcpWriteProbe() val tcpReadProbe = new TcpReadProbe() - Source(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink(tcpReadProbe.subscriberProbe)).run() + Source.fromPublisher(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink.fromSubscriber(tcpReadProbe.subscriberProbe)).run() val serverConnection = server.waitAccept() // Server can still write @@ -171,7 +171,7 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val tcpWriteProbe = new TcpWriteProbe() val tcpReadProbe = new TcpReadProbe() - Source(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink(tcpReadProbe.subscriberProbe)).run() + Source.fromPublisher(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink.fromSubscriber(tcpReadProbe.subscriberProbe)).run() val serverConnection = server.waitAccept() // Client can still write @@ -204,7 +204,7 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val tcpWriteProbe = new TcpWriteProbe() val tcpReadProbe = new TcpReadProbe() - Source(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink(tcpReadProbe.subscriberProbe)).run() + Source.fromPublisher(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink.fromSubscriber(tcpReadProbe.subscriberProbe)).run() val serverConnection = server.waitAccept() // Server can still write @@ -234,7 +234,7 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val tcpWriteProbe = new TcpWriteProbe() val tcpReadProbe = new TcpReadProbe() - Source(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink(tcpReadProbe.subscriberProbe)).run() + Source.fromPublisher(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink.fromSubscriber(tcpReadProbe.subscriberProbe)).run() val serverConnection = server.waitAccept() // Server can still write @@ -261,7 +261,7 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val tcpWriteProbe = new TcpWriteProbe() val tcpReadProbe = new TcpReadProbe() - Source(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink(tcpReadProbe.subscriberProbe)).run() + Source.fromPublisher(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink.fromSubscriber(tcpReadProbe.subscriberProbe)).run() val serverConnection = server.waitAccept() // Server can still write @@ -290,7 +290,7 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val tcpWriteProbe = new TcpWriteProbe() val tcpReadProbe = new TcpReadProbe() - Source(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink(tcpReadProbe.subscriberProbe)).run() + Source.fromPublisher(tcpWriteProbe.publisherProbe).via(Tcp().outgoingConnection(server.address)).to(Sink.fromSubscriber(tcpReadProbe.subscriberProbe)).run() val serverConnection = server.waitAccept() serverConnection.abort() @@ -312,14 +312,14 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val outgoingConnection = Tcp().outgoingConnection(server.address) val conn1F = - Source(tcpWriteProbe1.publisherProbe) + Source.fromPublisher(tcpWriteProbe1.publisherProbe) .viaMat(outgoingConnection)(Keep.right) - .to(Sink(tcpReadProbe1.subscriberProbe)).run() + .to(Sink.fromSubscriber(tcpReadProbe1.subscriberProbe)).run() val serverConnection1 = server.waitAccept() val conn2F = - Source(tcpWriteProbe2.publisherProbe) + Source.fromPublisher(tcpWriteProbe2.publisherProbe) .viaMat(outgoingConnection)(Keep.right) - .to(Sink(tcpReadProbe2.subscriberProbe)) + .to(Sink.fromSubscriber(tcpReadProbe2.subscriberProbe)) .run() val serverConnection2 = server.waitAccept() @@ -465,16 +465,16 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val probe1 = TestSubscriber.manualProbe[Tcp.IncomingConnection]() val bind = Tcp(system).bind(address.getHostName, address.getPort) // TODO getHostString in Java7 // Bind succeeded, we have a local address - val binding1 = Await.result(bind.to(Sink(probe1)).run(), 3.second) + val binding1 = Await.result(bind.to(Sink.fromSubscriber(probe1)).run(), 3.second) probe1.expectSubscription() val probe2 = TestSubscriber.manualProbe[Tcp.IncomingConnection]() - val binding2F = bind.to(Sink(probe2)).run() + val binding2F = bind.to(Sink.fromSubscriber(probe2)).run() probe2.expectSubscriptionAndError(BindFailedException) val probe3 = TestSubscriber.manualProbe[Tcp.IncomingConnection]() - val binding3F = bind.to(Sink(probe3)).run() + val binding3F = bind.to(Sink.fromSubscriber(probe3)).run() probe3.expectSubscriptionAndError() a[BindFailedException] shouldBe thrownBy { Await.result(binding2F, 1.second) } @@ -486,7 +486,7 @@ class TcpSpec extends AkkaSpec("akka.stream.materializer.subscription-timeout.ti val probe4 = TestSubscriber.manualProbe[Tcp.IncomingConnection]() // Bind succeeded, we have a local address - val binding4 = Await.result(bind.to(Sink(probe4)).run(), 3.second) + val binding4 = Await.result(bind.to(Sink.fromSubscriber(probe4)).run(), 3.second) probe4.expectSubscription() // clean up diff --git a/akka-stream-tests/src/test/scala/akka/stream/io/TlsSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/io/TlsSpec.scala index 25999308dd..1458253a83 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io/TlsSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io/TlsSpec.scala @@ -399,7 +399,7 @@ class TlsSpec extends AkkaSpec("akka.loglevel=INFO\nakka.actor.debug.receive=off "reliably cancel subscriptions when TransportIn fails early" in assertAllStagesStopped { val ex = new Exception("hello") val (sub, out1, out2) = - RunnableGraph.fromGraph(GraphDSL.create(Source.subscriber[SslTlsOutbound], Sink.head[ByteString], Sink.head[SslTlsInbound])((_, _, _)) { implicit b ⇒ + RunnableGraph.fromGraph(GraphDSL.create(Source.asSubscriber[SslTlsOutbound], Sink.head[ByteString], Sink.head[SslTlsInbound])((_, _, _)) { implicit b ⇒ (s, o1, o2) ⇒ val tls = b.add(clientTls(EagerClose)) s ~> tls.in1; tls.out1 ~> o1 @@ -417,7 +417,7 @@ class TlsSpec extends AkkaSpec("akka.loglevel=INFO\nakka.actor.debug.receive=off "reliably cancel subscriptions when UserIn fails early" in assertAllStagesStopped { val ex = new Exception("hello") val (sub, out1, out2) = - RunnableGraph.fromGraph(GraphDSL.create(Source.subscriber[ByteString], Sink.head[ByteString], Sink.head[SslTlsInbound])((_, _, _)) { implicit b ⇒ + RunnableGraph.fromGraph(GraphDSL.create(Source.asSubscriber[ByteString], Sink.head[ByteString], Sink.head[SslTlsInbound])((_, _, _)) { implicit b ⇒ (s, o1, o2) ⇒ val tls = b.add(clientTls(EagerClose)) Source.failed[SslTlsOutbound](ex) ~> tls.in1; tls.out1 ~> o1 diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/AcknowledgeSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/AcknowledgeSinkSpec.scala index 1b32bdceec..288457c0e8 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/AcknowledgeSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/AcknowledgeSinkSpec.scala @@ -34,7 +34,7 @@ class AcknowledgeSinkSpec extends AkkaSpec { "allow to have only one future waiting for result in each point of time" in assertAllStagesStopped { val probe = TestPublisher.manualProbe[Int]() - val queue = Source(probe).runWith(Sink.queue(3)) + val queue = Source.fromPublisher(probe).runWith(Sink.queue(3)) val sub = probe.expectSubscription() val future = queue.pull() val future2 = queue.pull() @@ -49,7 +49,7 @@ class AcknowledgeSinkSpec extends AkkaSpec { "wait for next element from upstream" in assertAllStagesStopped { val probe = TestPublisher.manualProbe[Int]() - val queue = Source(probe).runWith(Sink.queue(3)) + val queue = Source.fromPublisher(probe).runWith(Sink.queue(3)) val sub = probe.expectSubscription() queue.pull().pipeTo(testActor) @@ -62,7 +62,7 @@ class AcknowledgeSinkSpec extends AkkaSpec { "fail future on stream failure" in assertAllStagesStopped { val probe = TestPublisher.manualProbe[Int]() - val queue = Source(probe).runWith(Sink.queue(3)) + val queue = Source.fromPublisher(probe).runWith(Sink.queue(3)) val sub = probe.expectSubscription() queue.pull().pipeTo(testActor) @@ -74,7 +74,7 @@ class AcknowledgeSinkSpec extends AkkaSpec { "fail future when stream failed" in assertAllStagesStopped { val probe = TestPublisher.manualProbe[Int]() - val queue = Source(probe).runWith(Sink.queue(3, 100.millis)) + val queue = Source.fromPublisher(probe).runWith(Sink.queue(3, 100.millis)) val sub = probe.expectSubscription() sub.sendError(ex) // potential race condition @@ -83,7 +83,7 @@ class AcknowledgeSinkSpec extends AkkaSpec { "timeout future when stream cannot provide data" in assertAllStagesStopped { val probe = TestPublisher.manualProbe[Int]() - val queue = Source(probe).runWith(Sink.queue(3)) + val queue = Source.fromPublisher(probe).runWith(Sink.queue(3)) val sub = probe.expectSubscription() queue.pull().pipeTo(testActor) @@ -96,7 +96,7 @@ class AcknowledgeSinkSpec extends AkkaSpec { "work when buffer is 0" in assertAllStagesStopped { val probe = TestPublisher.manualProbe[Int]() - val queue = Source(probe).runWith(Sink.queue(0)) + val queue = Source.fromPublisher(probe).runWith(Sink.queue(0)) val sub = probe.expectSubscription() sub.sendNext(1) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/AcknowledgeSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/AcknowledgeSourceSpec.scala index 61a1077249..8c394c9b5c 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/AcknowledgeSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/AcknowledgeSourceSpec.scala @@ -22,7 +22,7 @@ class AcknowledgeSourceSpec extends AkkaSpec { "emit received messages to the stream" in { val s = TestSubscriber.manualProbe[Int]() - val queue = Source.queue(10, OverflowStrategy.fail).to(Sink(s)).run() + val queue = Source.queue(10, OverflowStrategy.fail).to(Sink.fromSubscriber(s)).run() val sub = s.expectSubscription sub.request(2) assertSuccess(true, queue.offer(1)) @@ -35,7 +35,7 @@ class AcknowledgeSourceSpec extends AkkaSpec { "buffer when needed" in { val s = TestSubscriber.manualProbe[Int]() - val queue = Source.queue(100, OverflowStrategy.dropHead).to(Sink(s)).run() + val queue = Source.queue(100, OverflowStrategy.dropHead).to(Sink.fromSubscriber(s)).run() val sub = s.expectSubscription for (n ← 1 to 20) assertSuccess(true, queue.offer(n)) sub.request(10) @@ -51,7 +51,7 @@ class AcknowledgeSourceSpec extends AkkaSpec { "not fail when 0 buffer space and demand is signalled" in assertAllStagesStopped { val s = TestSubscriber.manualProbe[Int]() - val queue = Source.queue(0, OverflowStrategy.dropHead).to(Sink(s)).run() + val queue = Source.queue(0, OverflowStrategy.dropHead).to(Sink.fromSubscriber(s)).run() val sub = s.expectSubscription sub.request(1) assertSuccess(true, queue.offer(1)) @@ -61,7 +61,7 @@ class AcknowledgeSourceSpec extends AkkaSpec { "return false when can reject element to buffer" in assertAllStagesStopped { val s = TestSubscriber.manualProbe[Int]() - val queue = Source.queue(1, OverflowStrategy.dropNew).to(Sink(s)).run() + val queue = Source.queue(1, OverflowStrategy.dropNew).to(Sink.fromSubscriber(s)).run() val sub = s.expectSubscription assertSuccess(true, queue.offer(1)) assertSuccess(false, queue.offer(2)) @@ -72,7 +72,7 @@ class AcknowledgeSourceSpec extends AkkaSpec { "wait when buffer is full and backpressure is on" in assertAllStagesStopped { val s = TestSubscriber.manualProbe[Int]() - val queue = Source.queue(2, OverflowStrategy.backpressure).to(Sink(s)).run() + val queue = Source.queue(2, OverflowStrategy.backpressure).to(Sink.fromSubscriber(s)).run() val sub = s.expectSubscription assertSuccess(true, queue.offer(1)) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefSourceSpec.scala index 32058691d6..012a812eee 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ActorRefSourceSpec.scala @@ -19,7 +19,7 @@ class ActorRefSourceSpec extends AkkaSpec { "emit received messages to the stream" in { val s = TestSubscriber.manualProbe[Int]() - val ref = Source.actorRef(10, OverflowStrategy.fail).to(Sink(s)).run() + val ref = Source.actorRef(10, OverflowStrategy.fail).to(Sink.fromSubscriber(s)).run() val sub = s.expectSubscription sub.request(2) ref ! 1 @@ -32,7 +32,7 @@ class ActorRefSourceSpec extends AkkaSpec { "buffer when needed" in { val s = TestSubscriber.manualProbe[Int]() - val ref = Source.actorRef(100, OverflowStrategy.dropHead).to(Sink(s)).run() + val ref = Source.actorRef(100, OverflowStrategy.dropHead).to(Sink.fromSubscriber(s)).run() val sub = s.expectSubscription for (n ← 1 to 20) ref ! n sub.request(10) @@ -61,7 +61,7 @@ class ActorRefSourceSpec extends AkkaSpec { "terminate when the stream is cancelled" in assertAllStagesStopped { val s = TestSubscriber.manualProbe[Int]() - val ref = Source.actorRef(0, OverflowStrategy.fail).to(Sink(s)).run() + val ref = Source.actorRef(0, OverflowStrategy.fail).to(Sink.fromSubscriber(s)).run() watch(ref) val sub = s.expectSubscription sub.cancel() @@ -70,7 +70,7 @@ class ActorRefSourceSpec extends AkkaSpec { "not fail when 0 buffer space and demand is signalled" in assertAllStagesStopped { val s = TestSubscriber.manualProbe[Int]() - val ref = Source.actorRef(0, OverflowStrategy.dropHead).to(Sink(s)).run() + val ref = Source.actorRef(0, OverflowStrategy.dropHead).to(Sink.fromSubscriber(s)).run() watch(ref) val sub = s.expectSubscription sub.request(100) @@ -80,7 +80,7 @@ class ActorRefSourceSpec extends AkkaSpec { "complete the stream immediatly when receiving PoisonPill" in assertAllStagesStopped { val s = TestSubscriber.manualProbe[Int]() - val ref = Source.actorRef(10, OverflowStrategy.fail).to(Sink(s)).run() + val ref = Source.actorRef(10, OverflowStrategy.fail).to(Sink.fromSubscriber(s)).run() val sub = s.expectSubscription ref ! PoisonPill s.expectComplete() @@ -88,7 +88,7 @@ class ActorRefSourceSpec extends AkkaSpec { "signal buffered elements and complete the stream after receiving Status.Success" in assertAllStagesStopped { val s = TestSubscriber.manualProbe[Int]() - val ref = Source.actorRef(3, OverflowStrategy.fail).to(Sink(s)).run() + val ref = Source.actorRef(3, OverflowStrategy.fail).to(Sink.fromSubscriber(s)).run() val sub = s.expectSubscription ref ! 1 ref ! 2 @@ -101,7 +101,7 @@ class ActorRefSourceSpec extends AkkaSpec { "not buffer elements after receiving Status.Success" in assertAllStagesStopped { val s = TestSubscriber.manualProbe[Int]() - val ref = Source.actorRef(3, OverflowStrategy.dropBuffer).to(Sink(s)).run() + val ref = Source.actorRef(3, OverflowStrategy.dropBuffer).to(Sink.fromSubscriber(s)).run() val sub = s.expectSubscription ref ! 1 ref ! 2 @@ -117,7 +117,7 @@ class ActorRefSourceSpec extends AkkaSpec { "after receiving Status.Success, allow for earlier completion with PoisonPill" in assertAllStagesStopped { val s = TestSubscriber.manualProbe[Int]() - val ref = Source.actorRef(3, OverflowStrategy.dropBuffer).to(Sink(s)).run() + val ref = Source.actorRef(3, OverflowStrategy.dropBuffer).to(Sink.fromSubscriber(s)).run() val sub = s.expectSubscription ref ! 1 ref ! 2 @@ -131,7 +131,7 @@ class ActorRefSourceSpec extends AkkaSpec { "fail the stream when receiving Status.Failure" in assertAllStagesStopped { val s = TestSubscriber.manualProbe[Int]() - val ref = Source.actorRef(10, OverflowStrategy.fail).to(Sink(s)).run() + val ref = Source.actorRef(10, OverflowStrategy.fail).to(Sink.fromSubscriber(s)).run() val sub = s.expectSubscription val exc = TE("testfailure") ref ! Status.Failure(exc) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAppendSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAppendSpec.scala index f4f7f7bba2..17dc1bf538 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAppendSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAppendSpec.scala @@ -18,11 +18,11 @@ class FlowAppendSpec extends AkkaSpec with River { "Flow" should { "append Flow" in riverOf[String] { subscriber ⇒ val flow = Flow[Int].via(otherFlow) - Source(elements).via(flow).to(Sink(subscriber)).run() + Source(elements).via(flow).to(Sink.fromSubscriber(subscriber)).run() } "append Sink" in riverOf[String] { subscriber ⇒ - val sink = Flow[Int].to(otherFlow.to(Sink(subscriber))) + val sink = Flow[Int].to(otherFlow.to(Sink.fromSubscriber(subscriber))) Source(elements).to(sink).run() } } @@ -31,12 +31,12 @@ class FlowAppendSpec extends AkkaSpec with River { "append Flow" in riverOf[String] { subscriber ⇒ Source(elements) .via(otherFlow) - .to(Sink(subscriber)).run() + .to(Sink.fromSubscriber(subscriber)).run() } "append Sink" in riverOf[String] { subscriber ⇒ Source(elements) - .to(otherFlow.to(Sink(subscriber))) + .to(otherFlow.to(Sink.fromSubscriber(subscriber))) .run() } } diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowBufferSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowBufferSpec.scala index afa5219ddc..283a907360 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowBufferSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowBufferSpec.scala @@ -51,7 +51,7 @@ class FlowBufferSpec extends AkkaSpec { val publisher = TestPublisher.probe[Int]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).buffer(100, overflowStrategy = OverflowStrategy.backpressure).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).buffer(100, overflowStrategy = OverflowStrategy.backpressure).to(Sink.fromSubscriber(subscriber)).run() val sub = subscriber.expectSubscription() // Fill up buffer @@ -69,7 +69,7 @@ class FlowBufferSpec extends AkkaSpec { val publisher = TestPublisher.probe[Int]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).buffer(100, overflowStrategy = OverflowStrategy.dropHead).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).buffer(100, overflowStrategy = OverflowStrategy.dropHead).to(Sink.fromSubscriber(subscriber)).run() val sub = subscriber.expectSubscription() // Fill up buffer @@ -98,7 +98,7 @@ class FlowBufferSpec extends AkkaSpec { val publisher = TestPublisher.probe[Int]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).buffer(100, overflowStrategy = OverflowStrategy.dropTail).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).buffer(100, overflowStrategy = OverflowStrategy.dropTail).to(Sink.fromSubscriber(subscriber)).run() val sub = subscriber.expectSubscription() // Fill up buffer @@ -130,7 +130,7 @@ class FlowBufferSpec extends AkkaSpec { val publisher = TestPublisher.probe[Int]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).buffer(100, overflowStrategy = OverflowStrategy.dropBuffer).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).buffer(100, overflowStrategy = OverflowStrategy.dropBuffer).to(Sink.fromSubscriber(subscriber)).run() val sub = subscriber.expectSubscription() // Fill up buffer @@ -184,7 +184,7 @@ class FlowBufferSpec extends AkkaSpec { val publisher = TestPublisher.probe[Int]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).buffer(100, overflowStrategy = OverflowStrategy.fail).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).buffer(100, overflowStrategy = OverflowStrategy.fail).to(Sink.fromSubscriber(subscriber)).run() val sub = subscriber.expectSubscription() // Fill up buffer @@ -211,7 +211,7 @@ class FlowBufferSpec extends AkkaSpec { val publisher = TestPublisher.probe[Int]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).buffer(1, overflowStrategy = strategy).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).buffer(1, overflowStrategy = strategy).to(Sink.fromSubscriber(subscriber)).run() val sub = subscriber.expectSubscription() // Fill up buffer diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCompileSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCompileSpec.scala index 3b03852a34..54356b41d0 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCompileSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCompileSpec.scala @@ -18,7 +18,7 @@ class FlowCompileSpec extends AkkaSpec { val strSeq = Source(Seq("a", "b", "c")) import scala.concurrent.ExecutionContext.Implicits.global - val intFut = Source(Future { 3 }) + val intFut = Source.fromFuture(Future { 3 }) implicit val materializer = ActorMaterializer(ActorMaterializerSettings(system)) "Flow" should { @@ -41,15 +41,15 @@ class FlowCompileSpec extends AkkaSpec { val closedSource: Source[Int, _] = intSeq.via(open3) "closedSource.run()" shouldNot compile - val closedSink: Sink[Int, _] = open3.to(Sink.publisher[Int](false)) + val closedSink: Sink[Int, _] = open3.to(Sink.asPublisher[Int](false)) "closedSink.run()" shouldNot compile - closedSource.to(Sink.publisher[Int](false)).run() + closedSource.to(Sink.asPublisher[Int](false)).run() intSeq.to(closedSink).run() } "append Sink" in { val open: Flow[Int, String, _] = Flow[Int].map(_.toString) - val closedSink: Sink[String, _] = Flow[String].map(_.hashCode).to(Sink.publisher[Int](false)) + val closedSink: Sink[String, _] = Flow[String].map(_.hashCode).to(Sink.asPublisher[Int](false)) val appended: Sink[Int, _] = open.to(closedSink) "appended.run()" shouldNot compile "appended.connect(Sink.head[Int])" shouldNot compile @@ -61,13 +61,13 @@ class FlowCompileSpec extends AkkaSpec { val closedSource2: Source[String, _] = closedSource.via(open) "closedSource2.run()" shouldNot compile "strSeq.connect(closedSource2)" shouldNot compile - closedSource2.to(Sink.publisher[String](false)).run + closedSource2.to(Sink.asPublisher[String](false)).run } } "Sink" should { val openSource: Sink[Int, _] = - Flow[Int].map(_.toString).to(Sink.publisher[String](false)) + Flow[Int].map(_.toString).to(Sink.asPublisher[String](false)) "accept Source" in { intSeq.to(openSource) } @@ -83,7 +83,7 @@ class FlowCompileSpec extends AkkaSpec { val openSource: Source[String, _] = Source(Seq(1, 2, 3)).map(_.toString) "accept Sink" in { - openSource.to(Sink.publisher[String](false)) + openSource.to(Sink.asPublisher[String](false)) } "not be accepted by Source" in { "openSource.connect(intSeq)" shouldNot compile @@ -96,7 +96,7 @@ class FlowCompileSpec extends AkkaSpec { "RunnableGraph" should { Sink.head[String] val closed: RunnableGraph[Publisher[String]] = - Source(Seq(1, 2, 3)).map(_.toString).toMat(Sink.publisher[String](false))(Keep.right) + Source(Seq(1, 2, 3)).map(_.toString).toMat(Sink.asPublisher[String](false))(Keep.right) "run" in { closed.run() } diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConcatAllSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConcatAllSpec.scala index 511ef3510d..7c4881d9eb 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConcatAllSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConcatAllSpec.scala @@ -33,7 +33,7 @@ class FlowConcatAllSpec extends AkkaSpec { val main = Source(List(s1, s2, s3, s4, s5)) val subscriber = TestSubscriber.manualProbe[Int]() - main.flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink(subscriber)).run() + main.flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink.fromSubscriber(subscriber)).run() val subscription = subscriber.expectSubscription() subscription.request(10) for (i ← 1 to 10) @@ -50,7 +50,7 @@ class FlowConcatAllSpec extends AkkaSpec { .map(_._2) .concatSubstreams .flatMapConcat(ConstantFun.scalaIdentityFunction) - .runWith(Sink(subscriber)) + .runWith(Sink.fromSubscriber(subscriber)) val subscription = subscriber.expectSubscription() subscription.request(10) for (i ← (1 to 10)) @@ -62,14 +62,14 @@ class FlowConcatAllSpec extends AkkaSpec { "on onError on master stream cancel the current open substream and signal error" in assertAllStagesStopped { val publisher = TestPublisher.manualProbe[Source[Int, Unit]]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink.fromSubscriber(subscriber)).run() val upstream = publisher.expectSubscription() val downstream = subscriber.expectSubscription() downstream.request(1000) val substreamPublisher = TestPublisher.manualProbe[Int]() - val substreamFlow = Source(substreamPublisher) + val substreamFlow = Source.fromPublisher(substreamPublisher) upstream.expectRequest() upstream.sendNext(substreamFlow) val subUpstream = substreamPublisher.expectSubscription() @@ -82,14 +82,14 @@ class FlowConcatAllSpec extends AkkaSpec { "on onError on master stream cancel the currently opening substream and signal error" in assertAllStagesStopped { val publisher = TestPublisher.manualProbe[Source[Int, Unit]]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink.fromSubscriber(subscriber)).run() val upstream = publisher.expectSubscription() val downstream = subscriber.expectSubscription() downstream.request(1000) val substreamPublisher = TestPublisher.manualProbe[Int](autoOnSubscribe = false) - val substreamFlow = Source(substreamPublisher) + val substreamFlow = Source.fromPublisher(substreamPublisher) upstream.expectRequest() upstream.sendNext(substreamFlow) val subUpstream = substreamPublisher.expectSubscription() @@ -105,14 +105,14 @@ class FlowConcatAllSpec extends AkkaSpec { "on onError on opening substream, cancel the master stream and signal error " in assertAllStagesStopped { val publisher = TestPublisher.manualProbe[Source[Int, _]]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).flatMapConcat(_ ⇒ throw testException).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).flatMapConcat(_ ⇒ throw testException).to(Sink.fromSubscriber(subscriber)).run() val upstream = publisher.expectSubscription() val downstream = subscriber.expectSubscription() downstream.request(1000) val substreamPublisher = TestPublisher.manualProbe[Int]() - val substreamFlow = Source(substreamPublisher) + val substreamFlow = Source.fromPublisher(substreamPublisher) upstream.expectRequest() upstream.sendNext(substreamFlow) subscriber.expectError(testException) @@ -122,14 +122,14 @@ class FlowConcatAllSpec extends AkkaSpec { "on onError on open substream, cancel the master stream and signal error " in assertAllStagesStopped { val publisher = TestPublisher.manualProbe[Source[Int, Unit]]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink.fromSubscriber(subscriber)).run() val upstream = publisher.expectSubscription() val downstream = subscriber.expectSubscription() downstream.request(1000) val substreamPublisher = TestPublisher.manualProbe[Int]() - val substreamFlow = Source(substreamPublisher) + val substreamFlow = Source.fromPublisher(substreamPublisher) upstream.expectRequest() upstream.sendNext(substreamFlow) val subUpstream = substreamPublisher.expectSubscription() @@ -142,14 +142,14 @@ class FlowConcatAllSpec extends AkkaSpec { "on cancellation cancel the current open substream and the master stream" in assertAllStagesStopped { val publisher = TestPublisher.manualProbe[Source[Int, Unit]]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink.fromSubscriber(subscriber)).run() val upstream = publisher.expectSubscription() val downstream = subscriber.expectSubscription() downstream.request(1000) val substreamPublisher = TestPublisher.manualProbe[Int]() - val substreamFlow = Source(substreamPublisher) + val substreamFlow = Source.fromPublisher(substreamPublisher) upstream.expectRequest() upstream.sendNext(substreamFlow) val subUpstream = substreamPublisher.expectSubscription() @@ -163,14 +163,14 @@ class FlowConcatAllSpec extends AkkaSpec { "on cancellation cancel the currently opening substream and the master stream" in assertAllStagesStopped { val publisher = TestPublisher.manualProbe[Source[Int, Unit]]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink.fromSubscriber(subscriber)).run() val upstream = publisher.expectSubscription() val downstream = subscriber.expectSubscription() downstream.request(1000) val substreamPublisher = TestPublisher.manualProbe[Int](autoOnSubscribe = false) - val substreamFlow = Source(substreamPublisher) + val substreamFlow = Source.fromPublisher(substreamPublisher) upstream.expectRequest() upstream.sendNext(substreamFlow) val subUpstream = substreamPublisher.expectSubscription() @@ -188,9 +188,9 @@ class FlowConcatAllSpec extends AkkaSpec { val down = TestSubscriber.manualProbe[Int]() val flowSubscriber = Source - .subscriber[Source[Int, Unit]] + .asSubscriber[Source[Int, Unit]] .flatMapConcat(ConstantFun.scalaIdentityFunction) - .to(Sink(down)) + .to(Sink.fromSubscriber(down)) .run() val downstream = down.expectSubscription() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConcatSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConcatSpec.scala index cc813df46b..8b33351d74 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConcatSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConcatSpec.scala @@ -17,7 +17,7 @@ class FlowConcatSpec extends BaseTwoStreamsSetup { override def setup(p1: Publisher[Int], p2: Publisher[Int]) = { val subscriber = TestSubscriber.probe[Outputs]() - Source(p1).concat(Source(p2)).runWith(Sink(subscriber)) + Source.fromPublisher(p1).concat(Source.fromPublisher(p2)).runWith(Sink.fromSubscriber(subscriber)) subscriber } @@ -29,7 +29,7 @@ class FlowConcatSpec extends BaseTwoStreamsSetup { val s2: Source[String, _] = Source(List(4, 5, 6)).map(_.toString + "-s") val subs = TestSubscriber.manualProbe[Any]() - val subSink = Sink.publisher[Any](false) + val subSink = Sink.asPublisher[Any](false) val (_, res) = f1.concat(s2).runWith(s1, subSink) @@ -101,7 +101,7 @@ class FlowConcatSpec extends BaseTwoStreamsSetup { "correctly handle async errors in secondary upstream" in assertAllStagesStopped { val promise = Promise[Int]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(List(1, 2, 3)).concat(Source(promise.future)).runWith(Sink(subscriber)) + Source(List(1, 2, 3)).concat(Source.fromFuture(promise.future)).runWith(Sink.fromSubscriber(subscriber)) val subscription = subscriber.expectSubscription() subscription.request(4) @@ -152,7 +152,7 @@ class FlowConcatSpec extends BaseTwoStreamsSetup { "subscribe at once to initial source and to one that it's concat to" in { val publisher1 = TestPublisher.probe[Int]() val publisher2 = TestPublisher.probe[Int]() - val probeSink = Source(publisher1).concat(Source(publisher2)) + val probeSink = Source.fromPublisher(publisher1).concat(Source.fromPublisher(publisher2)) .runWith(TestSink.probe[Int]) val sub1 = publisher1.expectSubscription() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConflateSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConflateSpec.scala index 3e2055b78f..3f9304608b 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConflateSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConflateSpec.scala @@ -22,7 +22,7 @@ class FlowConflateSpec extends AkkaSpec { val publisher = TestPublisher.probe[Int]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).conflate(seed = i ⇒ i)(aggregate = (sum, i) ⇒ sum + i).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).conflate(seed = i ⇒ i)(aggregate = (sum, i) ⇒ sum + i).to(Sink.fromSubscriber(subscriber)).run() val sub = subscriber.expectSubscription() for (i ← 1 to 100) { @@ -38,7 +38,7 @@ class FlowConflateSpec extends AkkaSpec { val publisher = TestPublisher.probe[Int]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).conflate(seed = i ⇒ i)(aggregate = (sum, i) ⇒ sum + i).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).conflate(seed = i ⇒ i)(aggregate = (sum, i) ⇒ sum + i).to(Sink.fromSubscriber(subscriber)).run() val sub = subscriber.expectSubscription() for (i ← 1 to 100) { @@ -62,7 +62,7 @@ class FlowConflateSpec extends AkkaSpec { val publisher = TestPublisher.probe[Int]() val subscriber = TestSubscriber.manualProbe[Int]() - Source(publisher).conflate(seed = i ⇒ i)(aggregate = (sum, i) ⇒ sum + i).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).conflate(seed = i ⇒ i)(aggregate = (sum, i) ⇒ sum + i).to(Sink.fromSubscriber(subscriber)).run() val sub = subscriber.expectSubscription() sub.request(1) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDelaySpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDelaySpec.scala index 72939734b4..0cb262bbd9 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDelaySpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDelaySpec.scala @@ -49,7 +49,7 @@ class FlowDelaySpec extends AkkaSpec { val c = TestSubscriber.manualProbe[Int]() val p = TestPublisher.manualProbe[Int]() - Source(p).delay(300.millis).to(Sink(c)).run() + Source.fromPublisher(p).delay(300.millis).to(Sink.fromSubscriber(c)).run() val cSub = c.expectSubscription() val pSub = p.expectSubscription() cSub.request(100) @@ -111,7 +111,7 @@ class FlowDelaySpec extends AkkaSpec { val c = TestSubscriber.manualProbe[Int]() val p = TestPublisher.manualProbe[Int]() - Source(p).delay(10.seconds, DelayOverflowStrategy.emitEarly).withAttributes(inputBuffer(16, 16)).to(Sink(c)).run() + Source.fromPublisher(p).delay(10.seconds, DelayOverflowStrategy.emitEarly).withAttributes(inputBuffer(16, 16)).to(Sink.fromSubscriber(c)).run() val cSub = c.expectSubscription() val pSub = p.expectSubscription() cSub.request(20) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropSpec.scala index 937d670e3d..af7d4b9559 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropSpec.scala @@ -28,7 +28,7 @@ class FlowDropSpec extends AkkaSpec with ScriptedTest { "not drop anything for negative n" in { val probe = TestSubscriber.manualProbe[Int]() - Source(List(1, 2, 3)).drop(-1).to(Sink(probe)).run() + Source(List(1, 2, 3)).drop(-1).to(Sink.fromSubscriber(probe)).run() probe.expectSubscription().request(10) probe.expectNext(1) probe.expectNext(2) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWithinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWithinSpec.scala index c96e8400be..8743cba05f 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWithinSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWithinSpec.scala @@ -18,7 +18,7 @@ class FlowDropWithinSpec extends AkkaSpec { val input = Iterator.from(1) val p = TestPublisher.manualProbe[Int]() val c = TestSubscriber.manualProbe[Int]() - Source(p).dropWithin(1.second).to(Sink(c)).run() + Source.fromPublisher(p).dropWithin(1.second).to(Sink.fromSubscriber(c)).run() val pSub = p.expectSubscription val cSub = c.expectSubscription cSub.request(100) @@ -39,7 +39,7 @@ class FlowDropWithinSpec extends AkkaSpec { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).dropWithin(1.day).runWith(Sink(downstream)) + Source.fromPublisher(upstream).dropWithin(1.day).runWith(Sink.fromSubscriber(downstream)) upstream.sendComplete() downstream.expectSubscriptionAndComplete() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowExpandSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowExpandSpec.scala index 0509e13d6f..2dbab7fb8b 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowExpandSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowExpandSpec.scala @@ -28,7 +28,7 @@ class FlowExpandSpec extends AkkaSpec { val subscriber = TestSubscriber.probe[Int]() // Simply repeat the last element as an extrapolation step - Source(publisher).expand(seed = i ⇒ i)(extrapolate = i ⇒ (i, i)).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).expand(seed = i ⇒ i)(extrapolate = i ⇒ (i, i)).to(Sink.fromSubscriber(subscriber)).run() for (i ← 1 to 100) { // Order is important here: If the request comes first it will be extrapolated! @@ -44,7 +44,7 @@ class FlowExpandSpec extends AkkaSpec { val subscriber = TestSubscriber.probe[Int]() // Simply repeat the last element as an extrapolation step - Source(publisher).expand(seed = i ⇒ i)(extrapolate = i ⇒ (i, i)).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).expand(seed = i ⇒ i)(extrapolate = i ⇒ (i, i)).to(Sink.fromSubscriber(subscriber)).run() publisher.sendNext(42) @@ -66,7 +66,7 @@ class FlowExpandSpec extends AkkaSpec { val subscriber = TestSubscriber.probe[Int]() // Simply repeat the last element as an extrapolation step - Source(publisher).expand(seed = i ⇒ i)(extrapolate = i ⇒ (i, i)).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).expand(seed = i ⇒ i)(extrapolate = i ⇒ (i, i)).to(Sink.fromSubscriber(subscriber)).run() publisher.sendNext(1) subscriber.requestNext(1) @@ -94,7 +94,7 @@ class FlowExpandSpec extends AkkaSpec { val publisher = TestPublisher.probe[Int]() val subscriber = TestSubscriber.probe[Int]() - Source(publisher).expand(seed = i ⇒ i)(extrapolate = i ⇒ (i, i)).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).expand(seed = i ⇒ i)(extrapolate = i ⇒ (i, i)).to(Sink.fromSubscriber(subscriber)).run() publisher.sendNext(1) subscriber.requestNext(1) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFilterSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFilterSpec.scala index 0ed829f002..56bd98e39f 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFilterSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFilterSpec.scala @@ -27,7 +27,7 @@ class FlowFilterSpec extends AkkaSpec with ScriptedTest { implicit val materializer = ActorMaterializer(settings) val probe = TestSubscriber.manualProbe[Int]() - Source(List.fill(1000)(0) ::: List(1)).filter(_ != 0).runWith(Sink(probe)) + Source(List.fill(1000)(0) ::: List(1)).filter(_ != 0).runWith(Sink.fromSubscriber(probe)) val subscription = probe.expectSubscription() for (_ ← 1 to 10000) { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFlattenMergeSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFlattenMergeSpec.scala index ce3b696133..331d0c9048 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFlattenMergeSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFlattenMergeSpec.scala @@ -19,7 +19,7 @@ class FlowFlattenMergeSpec extends AkkaSpec with ScalaFutures with ConversionChe import system.dispatcher def src10(i: Int) = Source(i until (i + 10)) - def blocked = Source(Promise[Int].future) + def blocked = Source.fromFuture(Promise[Int].future) val toSeq = Flow[Int].grouped(1000).toMat(Sink.head)(Keep.right) val toSet = toSeq.mapMaterializedValue(_.map(_.toSet)) @@ -98,7 +98,7 @@ class FlowFlattenMergeSpec extends AkkaSpec with ScalaFutures with ConversionChe val p1, p2 = TestPublisher.probe[Int]() val ex = new Exception("buh") val p = Promise[Source[Int, Unit]] - (Source(List(Source(p1), Source(p2))) ++ Source(p.future)) + (Source(List(Source.fromPublisher(p1), Source.fromPublisher(p2))) ++ Source.fromFuture(p.future)) .flatMapMerge(5, identity) .runWith(Sink.head) p1.expectRequest() @@ -112,7 +112,7 @@ class FlowFlattenMergeSpec extends AkkaSpec with ScalaFutures with ConversionChe val p1, p2 = TestPublisher.probe[Int]() val ex = new Exception("buh") val p = Promise[Int] - Source(List(Source(p1), Source(p2), Source(p.future))) + Source(List(Source.fromPublisher(p1), Source.fromPublisher(p2), Source.fromFuture(p.future))) .flatMapMerge(5, identity) .runWith(Sink.head) p1.expectRequest() @@ -128,8 +128,8 @@ class FlowFlattenMergeSpec extends AkkaSpec with ScalaFutures with ConversionChe val latch = TestLatch() Source(1 to 3) .flatMapMerge(10, { - case 1 ⇒ Source(p1) - case 2 ⇒ Source(p2) + case 1 ⇒ Source.fromPublisher(p1) + case 2 ⇒ Source.fromPublisher(p2) case 3 ⇒ Await.ready(latch, 3.seconds) throw ex @@ -145,7 +145,7 @@ class FlowFlattenMergeSpec extends AkkaSpec with ScalaFutures with ConversionChe "cancel substreams when being cancelled" in { val p1, p2 = TestPublisher.probe[Int]() val ex = new Exception("buh") - val sink = Source(List(Source(p1), Source(p2))) + val sink = Source(List(Source.fromPublisher(p1), Source.fromPublisher(p2))) .flatMapMerge(5, identity) .runWith(TestSink.probe) sink.request(1) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowForeachSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowForeachSpec.scala index e75a6e0648..053bb4e320 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowForeachSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowForeachSpec.scala @@ -36,7 +36,7 @@ class FlowForeachSpec extends AkkaSpec { "yield the first error" in assertAllStagesStopped { val p = TestPublisher.manualProbe[Int]() - Source(p).runForeach(testActor ! _) onFailure { + Source.fromPublisher(p).runForeach(testActor ! _) onFailure { case ex ⇒ testActor ! ex } val proc = p.expectSubscription() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFromFutureSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFromFutureSpec.scala index 16353457b6..96e56fd5dc 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFromFutureSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFromFutureSpec.scala @@ -21,7 +21,7 @@ class FlowFromFutureSpec extends AkkaSpec { "A Flow based on a Future" must { "produce one element from already successful Future" in assertAllStagesStopped { val c = TestSubscriber.manualProbe[Int]() - val p = Source(Future.successful(1)).runWith(Sink.publisher(true)).subscribe(c) + val p = Source.fromFuture(Future.successful(1)).runWith(Sink.asPublisher(true)).subscribe(c) val sub = c.expectSubscription() c.expectNoMsg(100.millis) sub.request(1) @@ -32,14 +32,14 @@ class FlowFromFutureSpec extends AkkaSpec { "produce error from already failed Future" in assertAllStagesStopped { val ex = new RuntimeException("test") with NoStackTrace val c = TestSubscriber.manualProbe[Int]() - Source(Future.failed[Int](ex)).runWith(Sink.publisher(false)).subscribe(c) + Source.fromFuture(Future.failed[Int](ex)).runWith(Sink.asPublisher(false)).subscribe(c) c.expectSubscriptionAndError(ex) } "produce one element when Future is completed" in assertAllStagesStopped { val promise = Promise[Int]() val c = TestSubscriber.manualProbe[Int]() - Source(promise.future).runWith(Sink.publisher(true)).subscribe(c) + Source.fromFuture(promise.future).runWith(Sink.asPublisher(true)).subscribe(c) val sub = c.expectSubscription() sub.request(1) c.expectNoMsg(100.millis) @@ -52,7 +52,7 @@ class FlowFromFutureSpec extends AkkaSpec { "produce one element when Future is completed but not before request" in { val promise = Promise[Int]() val c = TestSubscriber.manualProbe[Int]() - Source(promise.future).runWith(Sink.publisher(true)).subscribe(c) + Source.fromFuture(promise.future).runWith(Sink.asPublisher(true)).subscribe(c) val sub = c.expectSubscription() promise.success(1) c.expectNoMsg(200.millis) @@ -63,7 +63,7 @@ class FlowFromFutureSpec extends AkkaSpec { "produce elements with multiple subscribers" in assertAllStagesStopped { val promise = Promise[Int]() - val p = Source(promise.future).runWith(Sink.publisher(true)) + val p = Source.fromFuture(promise.future).runWith(Sink.asPublisher(true)) val c1 = TestSubscriber.manualProbe[Int]() val c2 = TestSubscriber.manualProbe[Int]() p.subscribe(c1) @@ -81,7 +81,7 @@ class FlowFromFutureSpec extends AkkaSpec { "allow cancel before receiving element" in { val promise = Promise[Int]() - val p = Source(promise.future).runWith(Sink.publisher(true)) + val p = Source.fromFuture(promise.future).runWith(Sink.asPublisher(true)) val keepAlive = TestSubscriber.manualProbe[Int]() val c = TestSubscriber.manualProbe[Int]() p.subscribe(keepAlive) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGraphCompileSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGraphCompileSpec.scala index b64788a7a0..2f9645137c 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGraphCompileSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGraphCompileSpec.scala @@ -36,7 +36,7 @@ class FlowGraphCompileSpec extends AkkaSpec { val in1 = Source(List("a", "b", "c")) val in2 = Source(List("d", "e", "f")) - val out1 = Sink.publisher[String](false) + val out1 = Sink.asPublisher[String](false) val out2 = Sink.head[String] "A Graph" should { @@ -165,9 +165,9 @@ class FlowGraphCompileSpec extends AkkaSpec { val in3 = Source(List("b")) val in5 = Source(List("b")) val in7 = Source(List("a")) - val out2 = Sink.publisher[String](false) - val out9 = Sink.publisher[String](false) - val out10 = Sink.publisher[String](false) + val out2 = Sink.asPublisher[String](false) + val out9 = Sink.asPublisher[String](false) + val out10 = Sink.asPublisher[String](false) def f(s: String) = Flow[String].transform(op[String, String]).named(s) import GraphDSL.Implicits._ @@ -198,7 +198,7 @@ class FlowGraphCompileSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val zip = b.add(Zip[Int, String]()) val unzip = b.add(Unzip[Int, String]()) - val out = Sink.publisher[(Int, String)](false) + val out = Sink.asPublisher[(Int, String)](false) import GraphDSL.Implicits._ Source(List(1 -> "a", 2 -> "b", 3 -> "c")) ~> unzip.in unzip.out0 ~> Flow[Int].map(_ * 2) ~> zip.in0 @@ -213,8 +213,8 @@ class FlowGraphCompileSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val zip = b.add(Zip[Int, String]()) val unzip = b.add(Unzip[Int, String]()) - val wrongOut = Sink.publisher[(Int, Int)](false) - val whatever = Sink.publisher[Any](false) + val wrongOut = Sink.asPublisher[(Int, Int)](false) + val whatever = Sink.asPublisher[Any](false) "Flow(List(1, 2, 3)) ~> zip.left ~> wrongOut" shouldNot compile """Flow(List("a", "b", "c")) ~> zip.left""" shouldNot compile """Flow(List("a", "b", "c")) ~> zip.out""" shouldNot compile @@ -230,9 +230,9 @@ class FlowGraphCompileSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ import GraphDSL.Implicits._ val merge = b.add(Merge[Fruit](2)) - Source[Fruit](apples) ~> Flow[Fruit] ~> merge.in(0) - Source[Apple](apples) ~> Flow[Apple] ~> merge.in(1) - merge.out ~> Flow[Fruit].map(identity) ~> Sink(TestSubscriber.manualProbe[Fruit]()) + Source.fromIterator[Fruit](apples) ~> Flow[Fruit] ~> merge.in(0) + Source.fromIterator[Apple](apples) ~> Flow[Apple] ~> merge.in(1) + merge.out ~> Flow[Fruit].map(identity) ~> Sink.fromSubscriber(TestSubscriber.manualProbe[Fruit]()) ClosedShape }) } @@ -241,31 +241,31 @@ class FlowGraphCompileSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ import GraphDSL.Implicits._ val fruitMerge = b.add(Merge[Fruit](2)) - Source[Fruit](apples) ~> fruitMerge - Source[Apple](apples) ~> fruitMerge + Source.fromIterator[Fruit](apples) ~> fruitMerge + Source.fromIterator[Apple](apples) ~> fruitMerge fruitMerge ~> Sink.head[Fruit] "fruitMerge ~> Sink.head[Apple]" shouldNot compile val appleMerge = b.add(Merge[Apple](2)) "Source[Fruit](apples) ~> appleMerge" shouldNot compile Source.empty[Apple] ~> appleMerge - Source[Apple](apples) ~> appleMerge + Source.fromIterator[Apple](apples) ~> appleMerge appleMerge ~> Sink.head[Fruit] val appleMerge2 = b.add(Merge[Apple](2)) Source.empty[Apple] ~> appleMerge2 - Source[Apple](apples) ~> appleMerge2 + Source.fromIterator[Apple](apples) ~> appleMerge2 appleMerge2 ~> Sink.head[Apple] val fruitBcast = b.add(Broadcast[Fruit](2)) - Source[Apple](apples) ~> fruitBcast + Source.fromIterator[Apple](apples) ~> fruitBcast fruitBcast ~> Sink.head[Fruit] fruitBcast ~> Sink.ignore "fruitBcast ~> Sink.head[Apple]" shouldNot compile val appleBcast = b.add(Broadcast[Apple](2)) "Source[Fruit](apples) ~> appleBcast" shouldNot compile - Source[Apple](apples) ~> appleBcast + Source.fromIterator[Apple](apples) ~> appleBcast appleBcast ~> Sink.head[Fruit] appleBcast ~> Sink.head[Apple] ClosedShape @@ -274,33 +274,33 @@ class FlowGraphCompileSpec extends AkkaSpec { "build with implicits and variance" in { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ - def appleSource = b.add(Source(TestPublisher.manualProbe[Apple]())) - def fruitSource = b.add(Source(TestPublisher.manualProbe[Fruit]())) - val outA = b add Sink(TestSubscriber.manualProbe[Fruit]()) - val outB = b add Sink(TestSubscriber.manualProbe[Fruit]()) + def appleSource = b.add(Source.fromPublisher(TestPublisher.manualProbe[Apple]())) + def fruitSource = b.add(Source.fromPublisher(TestPublisher.manualProbe[Fruit]())) + val outA = b add Sink.fromSubscriber(TestSubscriber.manualProbe[Fruit]()) + val outB = b add Sink.fromSubscriber(TestSubscriber.manualProbe[Fruit]()) val merge = b add Merge[Fruit](11) val unzip = b add Unzip[Int, String]() - val whatever = b add Sink.publisher[Any](false) + val whatever = b add Sink.asPublisher[Any](false) import GraphDSL.Implicits._ - b.add(Source[Fruit](apples)) ~> merge.in(0) + b.add(Source.fromIterator[Fruit](apples)) ~> merge.in(0) appleSource ~> merge.in(1) appleSource ~> merge.in(2) fruitSource ~> merge.in(3) fruitSource ~> Flow[Fruit].map(identity) ~> merge.in(4) appleSource ~> Flow[Apple].map(identity) ~> merge.in(5) - b.add(Source(apples)) ~> merge.in(6) - b.add(Source(apples)) ~> Flow[Fruit].map(identity) ~> merge.in(7) - b.add(Source(apples)) ~> Flow[Apple].map(identity) ~> merge.in(8) + b.add(Source.fromIterator(apples)) ~> merge.in(6) + b.add(Source.fromIterator(apples)) ~> Flow[Fruit].map(identity) ~> merge.in(7) + b.add(Source.fromIterator(apples)) ~> Flow[Apple].map(identity) ~> merge.in(8) merge.out ~> Flow[Fruit].map(identity) ~> outA - b.add(Source(apples)) ~> Flow[Apple] ~> merge.in(9) - b.add(Source(apples)) ~> Flow[Apple] ~> outB - b.add(Source(apples)) ~> Flow[Apple] ~> b.add(Sink.publisher[Fruit](false)) + b.add(Source.fromIterator(apples)) ~> Flow[Apple] ~> merge.in(9) + b.add(Source.fromIterator(apples)) ~> Flow[Apple] ~> outB + b.add(Source.fromIterator(apples)) ~> Flow[Apple] ~> b.add(Sink.asPublisher[Fruit](false)) appleSource ~> Flow[Apple] ~> merge.in(10) Source(List(1 -> "a", 2 -> "b", 3 -> "c")) ~> unzip.in unzip.out1 ~> whatever - unzip.out0 ~> b.add(Sink.publisher[Any](false)) + unzip.out0 ~> b.add(Sink.asPublisher[Any](false)) "merge.out ~> b.add(Broadcast[Apple](2))" shouldNot compile "merge.out ~> Flow[Fruit].map(identity) ~> b.add(Broadcast[Apple](2))" shouldNot compile diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupBySpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupBySpec.scala index 47652cc5ce..f58095f745 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupBySpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupBySpec.scala @@ -50,9 +50,9 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT } class SubstreamsSupport(groupCount: Int = 2, elementCount: Int = 6, maxSubstreams: Int = -1) { - val source = Source(1 to elementCount).runWith(Sink.publisher(false)) + val source = Source(1 to elementCount).runWith(Sink.asPublisher(false)) val max = if (maxSubstreams > 0) maxSubstreams else groupCount - val groupStream = Source(source).groupBy(max, _ % groupCount).lift(_ % groupCount).runWith(Sink.publisher(false)) + val groupStream = Source.fromPublisher(source).groupBy(max, _ % groupCount).lift(_ % groupCount).runWith(Sink.asPublisher(false)) val masterSubscriber = TestSubscriber.manualProbe[(Int, Source[Int, _])]() groupStream.subscribe(masterSubscriber) @@ -74,7 +74,7 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT "groupBy" must { "work in the happy case" in assertAllStagesStopped { new SubstreamsSupport(groupCount = 2) { - val s1 = StreamPuppet(getSubFlow(1).runWith(Sink.publisher(false))) + val s1 = StreamPuppet(getSubFlow(1).runWith(Sink.asPublisher(false))) masterSubscriber.expectNoMsg(100.millis) s1.expectNoMsg(100.millis) @@ -82,7 +82,7 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT s1.expectNext(1) s1.expectNoMsg(100.millis) - val s2 = StreamPuppet(getSubFlow(0).runWith(Sink.publisher(false))) + val s2 = StreamPuppet(getSubFlow(0).runWith(Sink.asPublisher(false))) s2.expectNoMsg(100.millis) s2.request(2) @@ -123,9 +123,9 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT "accept cancellation of substreams" in assertAllStagesStopped { new SubstreamsSupport(groupCount = 2) { - StreamPuppet(getSubFlow(1).runWith(Sink.publisher(false))).cancel() + StreamPuppet(getSubFlow(1).runWith(Sink.asPublisher(false))).cancel() - val substream = StreamPuppet(getSubFlow(0).runWith(Sink.publisher(false))) + val substream = StreamPuppet(getSubFlow(0).runWith(Sink.asPublisher(false))) substream.request(2) substream.expectNext(2) substream.expectNext(4) @@ -142,7 +142,7 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT "accept cancellation of master stream when not consumed anything" in assertAllStagesStopped { val publisherProbeProbe = TestPublisher.manualProbe[Int]() - val publisher = Source(publisherProbeProbe).groupBy(2, _ % 2).lift(_ % 2).runWith(Sink.publisher(false)) + val publisher = Source.fromPublisher(publisherProbeProbe).groupBy(2, _ % 2).lift(_ % 2).runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[(Int, Source[Int, _])]() publisher.subscribe(subscriber) @@ -153,7 +153,7 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT } "work with empty input stream" in assertAllStagesStopped { - val publisher = Source(List.empty[Int]).groupBy(2, _ % 2).lift(_ % 2).runWith(Sink.publisher(false)) + val publisher = Source(List.empty[Int]).groupBy(2, _ % 2).lift(_ % 2).runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[(Int, Source[Int, _])]() publisher.subscribe(subscriber) @@ -162,7 +162,7 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT "abort on onError from upstream" in assertAllStagesStopped { val publisherProbeProbe = TestPublisher.manualProbe[Int]() - val publisher = Source(publisherProbeProbe).groupBy(2, _ % 2).lift(_ % 2).runWith(Sink.publisher(false)) + val publisher = Source.fromPublisher(publisherProbeProbe).groupBy(2, _ % 2).lift(_ % 2).runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[(Int, Source[Int, _])]() publisher.subscribe(subscriber) @@ -179,7 +179,7 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT "abort on onError from upstream when substreams are running" in assertAllStagesStopped { val publisherProbeProbe = TestPublisher.manualProbe[Int]() - val publisher = Source(publisherProbeProbe).groupBy(2, _ % 2).lift(_ % 2).runWith(Sink.publisher(false)) + val publisher = Source.fromPublisher(publisherProbeProbe).groupBy(2, _ % 2).lift(_ % 2).runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[(Int, Source[Int, _])]() publisher.subscribe(subscriber) @@ -191,7 +191,7 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT upstreamSubscription.sendNext(1) val (_, substream) = subscriber.expectNext() - val substreamPuppet = StreamPuppet(substream.runWith(Sink.publisher(false))) + val substreamPuppet = StreamPuppet(substream.runWith(Sink.asPublisher(false))) substreamPuppet.request(1) substreamPuppet.expectNext(1) @@ -207,10 +207,10 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT "fail stream when groupBy function throws" in assertAllStagesStopped { val publisherProbeProbe = TestPublisher.manualProbe[Int]() val exc = TE("test") - val publisher = Source(publisherProbeProbe) + val publisher = Source.fromPublisher(publisherProbeProbe) .groupBy(2, elem ⇒ if (elem == 2) throw exc else elem % 2) .lift(_ % 2) - .runWith(Sink.publisher(false)) + .runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[(Int, Source[Int, Unit])]() publisher.subscribe(subscriber) @@ -222,7 +222,7 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT upstreamSubscription.sendNext(1) val (_, substream) = subscriber.expectNext() - val substreamPuppet = StreamPuppet(substream.runWith(Sink.publisher(false))) + val substreamPuppet = StreamPuppet(substream.runWith(Sink.asPublisher(false))) substreamPuppet.request(1) substreamPuppet.expectNext(1) @@ -237,11 +237,11 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT "resume stream when groupBy function throws" in { val publisherProbeProbe = TestPublisher.manualProbe[Int]() val exc = TE("test") - val publisher = Source(publisherProbeProbe) + val publisher = Source.fromPublisher(publisherProbeProbe) .groupBy(2, elem ⇒ if (elem == 2) throw exc else elem % 2) .lift(_ % 2) .withAttributes(ActorAttributes.supervisionStrategy(resumingDecider)) - .runWith(Sink.publisher(false)) + .runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[(Int, Source[Int, Unit])]() publisher.subscribe(subscriber) @@ -253,7 +253,7 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT upstreamSubscription.sendNext(1) val (_, substream1) = subscriber.expectNext() - val substreamPuppet1 = StreamPuppet(substream1.runWith(Sink.publisher(false))) + val substreamPuppet1 = StreamPuppet(substream1.runWith(Sink.asPublisher(false))) substreamPuppet1.request(10) substreamPuppet1.expectNext(1) @@ -261,7 +261,7 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT upstreamSubscription.sendNext(4) val (_, substream2) = subscriber.expectNext() - val substreamPuppet2 = StreamPuppet(substream2.runWith(Sink.publisher(false))) + val substreamPuppet2 = StreamPuppet(substream2.runWith(Sink.asPublisher(false))) substreamPuppet2.request(10) substreamPuppet2.expectNext(4) // note that 2 was dropped @@ -281,7 +281,7 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT val up = TestPublisher.manualProbe[Int]() val down = TestSubscriber.manualProbe[(Int, Source[Int, Unit])]() - val flowSubscriber = Source.subscriber[Int].groupBy(2, _ % 2).lift(_ % 2).to(Sink(down)).run() + val flowSubscriber = Source.asSubscriber[Int].groupBy(2, _ % 2).lift(_ % 2).to(Sink.fromSubscriber(down)).run() val downstream = down.expectSubscription() downstream.cancel() @@ -299,7 +299,7 @@ class FlowGroupBySpec extends AkkaSpec with ScalaFutures with ConversionCheckedT up.sendNext(1) val first = down.expectNext() - val s1 = StreamPuppet(first._2.runWith(Sink.publisher(false))) + val s1 = StreamPuppet(first._2.runWith(Sink.asPublisher(false))) s1.request(1) s1.expectNext(1) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedWithinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedWithinSpec.scala index 1057257364..c39911d7a8 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedWithinSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedWithinSpec.scala @@ -24,7 +24,7 @@ class FlowGroupedWithinSpec extends AkkaSpec with ScriptedTest { val input = Iterator.from(1) val p = TestPublisher.manualProbe[Int]() val c = TestSubscriber.manualProbe[immutable.Seq[Int]]() - Source(p).groupedWithin(1000, 1.second).to(Sink(c)).run() + Source.fromPublisher(p).groupedWithin(1000, 1.second).to(Sink.fromSubscriber(c)).run() val pSub = p.expectSubscription val cSub = c.expectSubscription cSub.request(100) @@ -49,7 +49,7 @@ class FlowGroupedWithinSpec extends AkkaSpec with ScriptedTest { "deliver bufferd elements onComplete before the timeout" in { val c = TestSubscriber.manualProbe[immutable.Seq[Int]]() - Source(1 to 3).groupedWithin(1000, 10.second).to(Sink(c)).run() + Source(1 to 3).groupedWithin(1000, 10.second).to(Sink.fromSubscriber(c)).run() val cSub = c.expectSubscription cSub.request(100) c.expectNext((1 to 3).toList) @@ -61,7 +61,7 @@ class FlowGroupedWithinSpec extends AkkaSpec with ScriptedTest { val input = Iterator.from(1) val p = TestPublisher.manualProbe[Int]() val c = TestSubscriber.manualProbe[immutable.Seq[Int]]() - Source(p).groupedWithin(1000, 1.second).to(Sink(c)).run() + Source.fromPublisher(p).groupedWithin(1000, 1.second).to(Sink.fromSubscriber(c)).run() val pSub = p.expectSubscription val cSub = c.expectSubscription cSub.request(1) @@ -81,7 +81,7 @@ class FlowGroupedWithinSpec extends AkkaSpec with ScriptedTest { "drop empty groups" in { val p = TestPublisher.manualProbe[Int]() val c = TestSubscriber.manualProbe[immutable.Seq[Int]]() - Source(p).groupedWithin(1000, 500.millis).to(Sink(c)).run() + Source.fromPublisher(p).groupedWithin(1000, 500.millis).to(Sink.fromSubscriber(c)).run() val pSub = p.expectSubscription val cSub = c.expectSubscription cSub.request(2) @@ -103,7 +103,7 @@ class FlowGroupedWithinSpec extends AkkaSpec with ScriptedTest { val inputs = Iterator.from(1) val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[immutable.Seq[Int]]() - Source(upstream).groupedWithin(3, 2.second).to(Sink(downstream)).run() + Source.fromPublisher(upstream).groupedWithin(3, 2.second).to(Sink.fromSubscriber(downstream)).run() downstream.request(2) downstream.expectNoMsg(1000.millis) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIdleInjectSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIdleInjectSpec.scala index f0ba3e27f0..4b2c239e3a 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIdleInjectSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIdleInjectSpec.scala @@ -33,7 +33,7 @@ class FlowIdleInjectSpec extends AkkaSpec { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).keepAlive(1.second, () ⇒ 0).runWith(Sink(downstream)) + Source.fromPublisher(upstream).keepAlive(1.second, () ⇒ 0).runWith(Sink.fromSubscriber(downstream)) downstream.request(1) @@ -48,7 +48,7 @@ class FlowIdleInjectSpec extends AkkaSpec { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - (Source(1 to 10) ++ Source(upstream)).keepAlive(1.second, () ⇒ 0).runWith(Sink(downstream)) + (Source(1 to 10) ++ Source.fromPublisher(upstream)).keepAlive(1.second, () ⇒ 0).runWith(Sink.fromSubscriber(downstream)) downstream.request(10) downstream.expectNextN(1 to 10) @@ -66,7 +66,7 @@ class FlowIdleInjectSpec extends AkkaSpec { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).keepAlive(1.second, () ⇒ 0).runWith(Sink(downstream)) + Source.fromPublisher(upstream).keepAlive(1.second, () ⇒ 0).runWith(Sink.fromSubscriber(downstream)) downstream.ensureSubscription() downstream.expectNoMsg(1.5.second) @@ -81,7 +81,7 @@ class FlowIdleInjectSpec extends AkkaSpec { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - (Source(1 to 10) ++ Source(upstream)).keepAlive(1.second, () ⇒ 0).runWith(Sink(downstream)) + (Source(1 to 10) ++ Source.fromPublisher(upstream)).keepAlive(1.second, () ⇒ 0).runWith(Sink.fromSubscriber(downstream)) downstream.request(10) downstream.expectNextN(1 to 10) @@ -98,7 +98,7 @@ class FlowIdleInjectSpec extends AkkaSpec { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).keepAlive(1.second, () ⇒ 0).runWith(Sink(downstream)) + Source.fromPublisher(upstream).keepAlive(1.second, () ⇒ 0).runWith(Sink.fromSubscriber(downstream)) downstream.ensureSubscription() downstream.expectNoMsg(1.5.second) @@ -115,7 +115,7 @@ class FlowIdleInjectSpec extends AkkaSpec { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - (Source(1 to 10) ++ Source(upstream)).keepAlive(1.second, () ⇒ 0).runWith(Sink(downstream)) + (Source(1 to 10) ++ Source.fromPublisher(upstream)).keepAlive(1.second, () ⇒ 0).runWith(Sink.fromSubscriber(downstream)) downstream.request(10) downstream.expectNextN(1 to 10) @@ -134,7 +134,7 @@ class FlowIdleInjectSpec extends AkkaSpec { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).keepAlive(1.second, () ⇒ 0).runWith(Sink(downstream)) + Source.fromPublisher(upstream).keepAlive(1.second, () ⇒ 0).runWith(Sink.fromSubscriber(downstream)) downstream.request(2) downstream.expectNoMsg(500.millis) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowInitialDelaySpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowInitialDelaySpec.scala index c6b278c322..e758cdbbea 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowInitialDelaySpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowInitialDelaySpec.scala @@ -37,7 +37,7 @@ class FlowInitialDelaySpec extends AkkaSpec { "properly ignore timer while backpressured" in Utils.assertAllStagesStopped { val probe = TestSubscriber.probe[Int]() - Source(1 to 10).initialDelay(0.5.second).runWith(Sink(probe)) + Source(1 to 10).initialDelay(0.5.second).runWith(Sink.fromSubscriber(probe)) probe.ensureSubscription() probe.expectNoMsg(1.5.second) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowInterleaveSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowInterleaveSpec.scala index 80d43c7ad4..913e64479f 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowInterleaveSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowInterleaveSpec.scala @@ -13,7 +13,7 @@ class FlowInterleaveSpec extends BaseTwoStreamsSetup { override def setup(p1: Publisher[Int], p2: Publisher[Int]) = { val subscriber = TestSubscriber.probe[Outputs]() - Source(p1).interleave(Source(p2), 2).runWith(Sink(subscriber)) + Source.fromPublisher(p1).interleave(Source.fromPublisher(p2), 2).runWith(Sink.fromSubscriber(subscriber)) subscriber } @@ -21,7 +21,7 @@ class FlowInterleaveSpec extends BaseTwoStreamsSetup { "work in the happy case" in assertAllStagesStopped { val probe = TestSubscriber.manualProbe[Int]() - Source(0 to 3).interleave(Source(4 to 6), 2).interleave(Source(7 to 11), 3).runWith(Sink(probe)) + Source(0 to 3).interleave(Source(4 to 6), 2).interleave(Source(7 to 11), 3).runWith(Sink.fromSubscriber(probe)) val subscription = probe.expectSubscription() @@ -38,7 +38,7 @@ class FlowInterleaveSpec extends BaseTwoStreamsSetup { "work when segmentSize is not equal elements in stream" in assertAllStagesStopped { val probe = TestSubscriber.manualProbe[Int]() - Source(0 to 2).interleave(Source(3 to 5), 2).runWith(Sink(probe)) + Source(0 to 2).interleave(Source(3 to 5), 2).runWith(Sink.fromSubscriber(probe)) probe.expectSubscription().request(10) probe.expectNext(0, 1, 3, 4, 2, 5) probe.expectComplete() @@ -47,7 +47,7 @@ class FlowInterleaveSpec extends BaseTwoStreamsSetup { "work with segmentSize = 1" in assertAllStagesStopped { val probe = TestSubscriber.manualProbe[Int]() - Source(0 to 2).interleave(Source(3 to 5), 1).runWith(Sink(probe)) + Source(0 to 2).interleave(Source(3 to 5), 1).runWith(Sink.fromSubscriber(probe)) probe.expectSubscription().request(10) probe.expectNext(0, 3, 1, 4, 2, 5) probe.expectComplete() @@ -59,13 +59,13 @@ class FlowInterleaveSpec extends BaseTwoStreamsSetup { "not work when segmentSize > than stream elements" in assertAllStagesStopped { val probe = TestSubscriber.manualProbe[Int]() - Source(0 to 2).interleave(Source(3 to 15), 10).runWith(Sink(probe)) + Source(0 to 2).interleave(Source(3 to 15), 10).runWith(Sink.fromSubscriber(probe)) probe.expectSubscription().request(25) (0 to 15).foreach(probe.expectNext) probe.expectComplete() val probe2 = TestSubscriber.manualProbe[Int]() - Source(1 to 20).interleave(Source(21 to 25), 10).runWith(Sink(probe2)) + Source(1 to 20).interleave(Source(21 to 25), 10).runWith(Sink.fromSubscriber(probe2)) probe2.expectSubscription().request(100) (1 to 10).foreach(probe2.expectNext) (21 to 25).foreach(probe2.expectNext) @@ -126,8 +126,8 @@ class FlowInterleaveSpec extends BaseTwoStreamsSetup { val up2 = TestPublisher.manualProbe[Int]() val down = TestSubscriber.manualProbe[Int]() - val (graphSubscriber1, graphSubscriber2) = Source.subscriber[Int] - .interleaveMat(Source.subscriber[Int], 2)((_, _)).toMat(Sink(down))(Keep.left).run + val (graphSubscriber1, graphSubscriber2) = Source.asSubscriber[Int] + .interleaveMat(Source.asSubscriber[Int], 2)((_, _)).toMat(Sink.fromSubscriber(down))(Keep.left).run val downstream = down.expectSubscription() downstream.cancel() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIteratorSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIteratorSpec.scala index d87bedc551..266503cc90 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIteratorSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIteratorSpec.scala @@ -16,7 +16,7 @@ import org.reactivestreams.Subscriber class FlowIteratorSpec extends AbstractFlowIteratorSpec { override def testName = "A Flow based on an iterator producing function" override def createSource(elements: Int): Source[Int, Unit] = - Source(() ⇒ (1 to elements).iterator) + Source.fromIterator(() ⇒ (1 to elements).iterator) } class FlowIterableSpec extends AbstractFlowIteratorSpec { @@ -31,7 +31,7 @@ class FlowIterableSpec extends AbstractFlowIteratorSpec { override def iterator: Iterator[Int] = (1 to 3).iterator.map(x ⇒ if (x == 2) throw new IllegalStateException("not two") else x) } - val p = Source(iterable).runWith(Sink.publisher(false)) + val p = Source(iterable).runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[Int]() p.subscribe(c) val sub = c.expectSubscription() @@ -48,7 +48,7 @@ class FlowIterableSpec extends AbstractFlowIteratorSpec { val iterable = new immutable.Iterable[Int] { override def iterator: Iterator[Int] = throw new IllegalStateException("no good iterator") } - val p = Source(iterable).runWith(Sink.publisher(false)) + val p = Source(iterable).runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[Int]() p.subscribe(c) c.expectSubscriptionAndError().getMessage should be("no good iterator") @@ -62,7 +62,7 @@ class FlowIterableSpec extends AbstractFlowIteratorSpec { override def next(): Int = -1 } } - val p = Source(iterable).runWith(Sink.publisher(false)) + val p = Source(iterable).runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[Int]() p.subscribe(c) c.expectSubscriptionAndError().getMessage should be("no next") @@ -84,7 +84,7 @@ abstract class AbstractFlowIteratorSpec extends AkkaSpec { testName must { "produce elements" in assertAllStagesStopped { - val p = createSource(3).runWith(Sink.publisher(false)) + val p = createSource(3).runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[Int]() p.subscribe(c) val sub = c.expectSubscription() @@ -98,7 +98,7 @@ abstract class AbstractFlowIteratorSpec extends AkkaSpec { } "complete empty" in assertAllStagesStopped { - val p = createSource(0).runWith(Sink.publisher(false)) + val p = createSource(0).runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[Int]() p.subscribe(c) c.expectSubscriptionAndComplete() @@ -106,7 +106,7 @@ abstract class AbstractFlowIteratorSpec extends AkkaSpec { } "produce elements with multiple subscribers" in assertAllStagesStopped { - val p = createSource(3).runWith(Sink.publisher(true)) + val p = createSource(3).runWith(Sink.asPublisher(true)) val c1 = TestSubscriber.manualProbe[Int]() val c2 = TestSubscriber.manualProbe[Int]() p.subscribe(c1) @@ -130,7 +130,7 @@ abstract class AbstractFlowIteratorSpec extends AkkaSpec { } "produce elements to later subscriber" in assertAllStagesStopped { - val p = createSource(3).runWith(Sink.publisher(true)) + val p = createSource(3).runWith(Sink.asPublisher(true)) val c1 = TestSubscriber.manualProbe[Int]() val c2 = TestSubscriber.manualProbe[Int]() p.subscribe(c1) @@ -153,7 +153,7 @@ abstract class AbstractFlowIteratorSpec extends AkkaSpec { } "produce elements with one transformation step" in assertAllStagesStopped { - val p = createSource(3).map(_ * 2).runWith(Sink.publisher(false)) + val p = createSource(3).map(_ * 2).runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[Int]() p.subscribe(c) val sub = c.expectSubscription() @@ -165,7 +165,7 @@ abstract class AbstractFlowIteratorSpec extends AkkaSpec { } "produce elements with two transformation steps" in assertAllStagesStopped { - val p = createSource(4).filter(_ % 2 == 0).map(_ * 2).runWith(Sink.publisher(false)) + val p = createSource(4).filter(_ % 2 == 0).map(_ * 2).runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[Int]() p.subscribe(c) val sub = c.expectSubscription() @@ -176,7 +176,7 @@ abstract class AbstractFlowIteratorSpec extends AkkaSpec { } "not produce after cancel" in assertAllStagesStopped { - val p = createSource(3).runWith(Sink.publisher(false)) + val p = createSource(3).runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[Int]() p.subscribe(c) val sub = c.expectSubscription() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowJoinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowJoinSpec.scala index 3b5f3022e7..061826c017 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowJoinSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowJoinSpec.scala @@ -32,7 +32,7 @@ class FlowJoinSpec extends AkkaSpec(ConfigFactory.parseString("akka.loglevel=INF val broadcast = b.add(Broadcast[Int](2)) source ~> merge.in(0) merge.out ~> broadcast.in - broadcast.out(0).grouped(1000) ~> Sink(probe) + broadcast.out(0).grouped(1000) ~> Sink.fromSubscriber(probe) FlowShape(merge.in(1), broadcast.out(1)) }) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncSpec.scala index 40a84c37b1..8e1d6e3b94 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncSpec.scala @@ -36,7 +36,7 @@ class FlowMapAsyncSpec extends AkkaSpec with ScalaFutures { "produce future elements" in assertAllStagesStopped { val c = TestSubscriber.manualProbe[Int]() implicit val ec = system.dispatcher - val p = Source(1 to 3).mapAsync(4)(n ⇒ Future(n)).runWith(Sink(c)) + val p = Source(1 to 3).mapAsync(4)(n ⇒ Future(n)).runWith(Sink.fromSubscriber(c)) val sub = c.expectSubscription() sub.request(2) c.expectNext(1) @@ -53,7 +53,7 @@ class FlowMapAsyncSpec extends AkkaSpec with ScalaFutures { val p = Source(1 to 50).mapAsync(4)(n ⇒ Future { Thread.sleep(ThreadLocalRandom.current().nextInt(1, 10)) n - }).to(Sink(c)).run() + }).to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(1000) for (n ← 1 to 50) c.expectNext(n) @@ -67,7 +67,7 @@ class FlowMapAsyncSpec extends AkkaSpec with ScalaFutures { val p = Source(1 to 20).mapAsync(8)(n ⇒ Future { probe.ref ! n n - }).to(Sink(c)).run() + }).to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() probe.expectNoMsg(500.millis) sub.request(1) @@ -94,7 +94,7 @@ class FlowMapAsyncSpec extends AkkaSpec with ScalaFutures { Await.ready(latch, 10.seconds) n } - }).to(Sink(c)).run() + }).to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(10) c.expectError().getMessage should be("err1") @@ -113,7 +113,7 @@ class FlowMapAsyncSpec extends AkkaSpec with ScalaFutures { n } }). - to(Sink(c)).run() + to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(10) c.expectError().getMessage should be("err2") @@ -129,7 +129,7 @@ class FlowMapAsyncSpec extends AkkaSpec with ScalaFutures { else n }) .withAttributes(supervisionStrategy(resumingDecider)) - .to(Sink(c)).run() + .to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(10) for (n ← List(1, 2, 4, 5)) c.expectNext(n) @@ -169,7 +169,7 @@ class FlowMapAsyncSpec extends AkkaSpec with ScalaFutures { if (n == 3) throw new RuntimeException("err4") with NoStackTrace else Future(n)) .withAttributes(supervisionStrategy(resumingDecider)) - .to(Sink(c)).run() + .to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(10) for (n ← List(1, 2, 4, 5)) c.expectNext(n) @@ -178,7 +178,7 @@ class FlowMapAsyncSpec extends AkkaSpec with ScalaFutures { "signal NPE when future is completed with null" in { val c = TestSubscriber.manualProbe[String]() - val p = Source(List("a", "b")).mapAsync(4)(elem ⇒ Future.successful(null)).to(Sink(c)).run() + val p = Source(List("a", "b")).mapAsync(4)(elem ⇒ Future.successful(null)).to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(10) c.expectError().getMessage should be(ReactiveStreamsCompliance.ElementMustNotBeNullMsg) @@ -189,7 +189,7 @@ class FlowMapAsyncSpec extends AkkaSpec with ScalaFutures { val p = Source(List("a", "b", "c")) .mapAsync(4)(elem ⇒ if (elem == "b") Future.successful(null) else Future.successful(elem)) .withAttributes(supervisionStrategy(resumingDecider)) - .to(Sink(c)).run() + .to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(10) for (elem ← List("a", "c")) c.expectNext(elem) @@ -200,7 +200,7 @@ class FlowMapAsyncSpec extends AkkaSpec with ScalaFutures { val pub = TestPublisher.manualProbe[Int]() val sub = TestSubscriber.manualProbe[Int]() - Source(pub).mapAsync(4)(Future.successful).runWith(Sink(sub)) + Source.fromPublisher(pub).mapAsync(4)(Future.successful).runWith(Sink.fromSubscriber(sub)) val upstream = pub.expectSubscription() upstream.expectRequest() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncUnorderedSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncUnorderedSpec.scala index ce82d80096..89ec80f447 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncUnorderedSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncUnorderedSpec.scala @@ -37,7 +37,7 @@ class FlowMapAsyncUnorderedSpec extends AkkaSpec with ScalaFutures with Conversi val p = Source(1 to 4).mapAsyncUnordered(4)(n ⇒ Future { Await.ready(latch(n), 5.seconds) n - }).to(Sink(c)).run() + }).to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(5) latch(2).countDown() @@ -58,7 +58,7 @@ class FlowMapAsyncUnorderedSpec extends AkkaSpec with ScalaFutures with Conversi val p = Source(1 to 20).mapAsyncUnordered(4)(n ⇒ Future { probe.ref ! n n - }).to(Sink(c)).run() + }).to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() c.expectNoMsg(200.millis) probe.expectNoMsg(Duration.Zero) @@ -86,7 +86,7 @@ class FlowMapAsyncUnorderedSpec extends AkkaSpec with ScalaFutures with Conversi Await.ready(latch, 10.seconds) n } - }).to(Sink(c)).run() + }).to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(10) c.expectError.getMessage should be("err1") @@ -105,7 +105,7 @@ class FlowMapAsyncUnorderedSpec extends AkkaSpec with ScalaFutures with Conversi n } }). - to(Sink(c)).run() + to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(10) c.expectError.getMessage should be("err2") @@ -166,7 +166,7 @@ class FlowMapAsyncUnorderedSpec extends AkkaSpec with ScalaFutures with Conversi "signal NPE when future is completed with null" in { val c = TestSubscriber.manualProbe[String]() - val p = Source(List("a", "b")).mapAsyncUnordered(4)(elem ⇒ Future.successful(null)).to(Sink(c)).run() + val p = Source(List("a", "b")).mapAsyncUnordered(4)(elem ⇒ Future.successful(null)).to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(10) c.expectError.getMessage should be(ReactiveStreamsCompliance.ElementMustNotBeNullMsg) @@ -177,7 +177,7 @@ class FlowMapAsyncUnorderedSpec extends AkkaSpec with ScalaFutures with Conversi val p = Source(List("a", "b", "c")) .mapAsyncUnordered(4)(elem ⇒ if (elem == "b") Future.successful(null) else Future.successful(elem)) .withAttributes(supervisionStrategy(resumingDecider)) - .to(Sink(c)).run() + .to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(10) c.expectNextUnordered("a", "c") @@ -188,7 +188,7 @@ class FlowMapAsyncUnorderedSpec extends AkkaSpec with ScalaFutures with Conversi val pub = TestPublisher.manualProbe[Int]() val sub = TestSubscriber.manualProbe[Int]() - Source(pub).mapAsyncUnordered(4)(Future.successful).runWith(Sink(sub)) + Source.fromPublisher(pub).mapAsyncUnordered(4)(Future.successful).runWith(Sink.fromSubscriber(sub)) val upstream = pub.expectSubscription() upstream.expectRequest() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapConcatSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapConcatSpec.scala index 2f5383d0d7..13a9b7c5e6 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapConcatSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapConcatSpec.scala @@ -34,7 +34,7 @@ class FlowMapConcatSpec extends AkkaSpec with ScriptedTest { assertAllStagesStopped { val s = TestSubscriber.manualProbe[Int] val input = (1 to 20).grouped(5).toList - Source(input).mapConcat(identity).map(x ⇒ { Thread.sleep(10); x }).runWith(Sink(s)) + Source(input).mapConcat(identity).map(x ⇒ { Thread.sleep(10); x }).runWith(Sink.fromSubscriber(s)) val sub = s.expectSubscription() sub.request(100) for (i ← 1 to 20) s.expectNext(i) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapSpec.scala index ea9bb2dcf5..505b61d271 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapSpec.scala @@ -27,7 +27,7 @@ class FlowMapSpec extends AkkaSpec with ScriptedTest { val probe = TestSubscriber.manualProbe[Int]() Source(List(1)). map(_ + 1).map(_ + 1).map(_ + 1).map(_ + 1).map(_ + 1). - runWith(Sink.publisher(false)).subscribe(probe) + runWith(Sink.asPublisher(false)).subscribe(probe) val subscription = probe.expectSubscription() for (_ ← 1 to 10000) { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMergeSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMergeSpec.scala index 41f3259c7a..cc0864f0cc 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMergeSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMergeSpec.scala @@ -13,7 +13,7 @@ class FlowMergeSpec extends BaseTwoStreamsSetup { override def setup(p1: Publisher[Int], p2: Publisher[Int]) = { val subscriber = TestSubscriber.probe[Outputs]() - Source(p1).merge(Source(p2)).runWith(Sink(subscriber)) + Source.fromPublisher(p1).merge(Source.fromPublisher(p2)).runWith(Sink.fromSubscriber(subscriber)) subscriber } @@ -27,7 +27,7 @@ class FlowMergeSpec extends BaseTwoStreamsSetup { val probe = TestSubscriber.manualProbe[Int]() source1.merge(source2).merge(source3) - .map(_ * 2).map(_ / 2).map(_ + 1).runWith(Sink(probe)) + .map(_ * 2).map(_ / 2).map(_ + 1).runWith(Sink.fromSubscriber(probe)) val subscription = probe.expectSubscription() @@ -86,8 +86,8 @@ class FlowMergeSpec extends BaseTwoStreamsSetup { val up2 = TestPublisher.manualProbe[Int]() val down = TestSubscriber.manualProbe[Int]() - val (graphSubscriber1, graphSubscriber2) = Source.subscriber[Int] - .mergeMat(Source.subscriber[Int])((_, _)).toMat(Sink(down))(Keep.left).run + val (graphSubscriber1, graphSubscriber2) = Source.asSubscriber[Int] + .mergeMat(Source.asSubscriber[Int])((_, _)).toMat(Sink.fromSubscriber(down))(Keep.left).run val downstream = down.expectSubscription() downstream.cancel() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowOnCompleteSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowOnCompleteSpec.scala index 01ecb2fe69..b9f8176f7d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowOnCompleteSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowOnCompleteSpec.scala @@ -25,7 +25,7 @@ class FlowOnCompleteSpec extends AkkaSpec with ScriptedTest { "invoke callback on normal completion" in assertAllStagesStopped { val onCompleteProbe = TestProbe() val p = TestPublisher.manualProbe[Int]() - Source(p).to(Sink.onComplete[Int](onCompleteProbe.ref ! _)).run() + Source.fromPublisher(p).to(Sink.onComplete[Int](onCompleteProbe.ref ! _)).run() val proc = p.expectSubscription proc.expectRequest() proc.sendNext(42) @@ -37,7 +37,7 @@ class FlowOnCompleteSpec extends AkkaSpec with ScriptedTest { "yield the first error" in assertAllStagesStopped { val onCompleteProbe = TestProbe() val p = TestPublisher.manualProbe[Int]() - Source(p).to(Sink.onComplete[Int](onCompleteProbe.ref ! _)).run() + Source.fromPublisher(p).to(Sink.onComplete[Int](onCompleteProbe.ref ! _)).run() val proc = p.expectSubscription proc.expectRequest() val ex = new RuntimeException("ex") with NoStackTrace @@ -49,7 +49,7 @@ class FlowOnCompleteSpec extends AkkaSpec with ScriptedTest { "invoke callback for an empty stream" in assertAllStagesStopped { val onCompleteProbe = TestProbe() val p = TestPublisher.manualProbe[Int]() - Source(p).to(Sink.onComplete[Int](onCompleteProbe.ref ! _)).run() + Source.fromPublisher(p).to(Sink.onComplete[Int](onCompleteProbe.ref ! _)).run() val proc = p.expectSubscription proc.expectRequest() proc.sendComplete() @@ -64,7 +64,7 @@ class FlowOnCompleteSpec extends AkkaSpec with ScriptedTest { val foreachSink = Sink.foreach[Int] { x ⇒ onCompleteProbe.ref ! ("foreach-" + x) } - val future = Source(p).map { x ⇒ + val future = Source.fromPublisher(p).map { x ⇒ onCompleteProbe.ref ! ("map-" + x) x }.runWith(foreachSink) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowPrefixAndTailSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowPrefixAndTailSpec.scala index c7c37eaa28..7f98e9365a 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowPrefixAndTailSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowPrefixAndTailSpec.scala @@ -32,7 +32,7 @@ class FlowPrefixAndTailSpec extends AkkaSpec { val (prefix, tailFlow) = Await.result(fut, 3.seconds) prefix should be(Nil) val tailSubscriber = TestSubscriber.manualProbe[Int] - tailFlow.to(Sink(tailSubscriber)).run() + tailFlow.to(Sink.fromSubscriber(tailSubscriber)).run() tailSubscriber.expectSubscriptionAndComplete() } @@ -42,7 +42,7 @@ class FlowPrefixAndTailSpec extends AkkaSpec { val (prefix, tailFlow) = Await.result(fut, 3.seconds) prefix should be(List(1, 2, 3)) val tailSubscriber = TestSubscriber.manualProbe[Int] - tailFlow.to(Sink(tailSubscriber)).run() + tailFlow.to(Sink.fromSubscriber(tailSubscriber)).run() tailSubscriber.expectSubscriptionAndComplete() } @@ -86,7 +86,7 @@ class FlowPrefixAndTailSpec extends AkkaSpec { takes should be(1 to 10) val subscriber = TestSubscriber.manualProbe[Int]() - tail.to(Sink(subscriber)).run() + tail.to(Sink.fromSubscriber(subscriber)).run() subscriber.expectSubscriptionAndComplete() } @@ -97,10 +97,10 @@ class FlowPrefixAndTailSpec extends AkkaSpec { takes should be(Seq(1)) val subscriber1 = TestSubscriber.probe[Int]() - tail.to(Sink(subscriber1)).run() + tail.to(Sink.fromSubscriber(subscriber1)).run() val subscriber2 = TestSubscriber.probe[Int]() - tail.to(Sink(subscriber2)).run() + tail.to(Sink.fromSubscriber(subscriber2)).run() subscriber2.expectSubscriptionAndError().getMessage should ===("Tail Source cannot be materialized more than once.") subscriber1.requestNext(2).expectComplete() @@ -121,7 +121,7 @@ class FlowPrefixAndTailSpec extends AkkaSpec { val subscriber = TestSubscriber.probe[Int]() Thread.sleep(1000) - tail.to(Sink(subscriber)).run()(tightTimeoutMaterializer) + tail.to(Sink.fromSubscriber(subscriber)).run()(tightTimeoutMaterializer) subscriber.expectSubscriptionAndError().getMessage should ===("Tail Source has not been materialized in 500 milliseconds.") } @@ -136,7 +136,7 @@ class FlowPrefixAndTailSpec extends AkkaSpec { val publisher = TestPublisher.manualProbe[Int]() val subscriber = TestSubscriber.manualProbe[(immutable.Seq[Int], Source[Int, _])]() - Source(publisher).prefixAndTail(3).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).prefixAndTail(3).to(Sink.fromSubscriber(subscriber)).run() val upstream = publisher.expectSubscription() val downstream = subscriber.expectSubscription() @@ -154,7 +154,7 @@ class FlowPrefixAndTailSpec extends AkkaSpec { val publisher = TestPublisher.manualProbe[Int]() val subscriber = TestSubscriber.manualProbe[(immutable.Seq[Int], Source[Int, _])]() - Source(publisher).prefixAndTail(1).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).prefixAndTail(1).to(Sink.fromSubscriber(subscriber)).run() val upstream = publisher.expectSubscription() val downstream = subscriber.expectSubscription() @@ -169,7 +169,7 @@ class FlowPrefixAndTailSpec extends AkkaSpec { subscriber.expectComplete() val substreamSubscriber = TestSubscriber.manualProbe[Int]() - tail.to(Sink(substreamSubscriber)).run() + tail.to(Sink.fromSubscriber(substreamSubscriber)).run() substreamSubscriber.expectSubscription() upstream.sendError(testException) @@ -181,7 +181,7 @@ class FlowPrefixAndTailSpec extends AkkaSpec { val publisher = TestPublisher.manualProbe[Int]() val subscriber = TestSubscriber.manualProbe[(immutable.Seq[Int], Source[Int, _])]() - Source(publisher).prefixAndTail(3).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).prefixAndTail(3).to(Sink.fromSubscriber(subscriber)).run() val upstream = publisher.expectSubscription() val downstream = subscriber.expectSubscription() @@ -199,7 +199,7 @@ class FlowPrefixAndTailSpec extends AkkaSpec { val publisher = TestPublisher.manualProbe[Int]() val subscriber = TestSubscriber.manualProbe[(immutable.Seq[Int], Source[Int, _])]() - Source(publisher).prefixAndTail(1).to(Sink(subscriber)).run() + Source.fromPublisher(publisher).prefixAndTail(1).to(Sink.fromSubscriber(subscriber)).run() val upstream = publisher.expectSubscription() val downstream = subscriber.expectSubscription() @@ -214,7 +214,7 @@ class FlowPrefixAndTailSpec extends AkkaSpec { subscriber.expectComplete() val substreamSubscriber = TestSubscriber.manualProbe[Int]() - tail.to(Sink(substreamSubscriber)).run() + tail.to(Sink.fromSubscriber(substreamSubscriber)).run() substreamSubscriber.expectSubscription().cancel() upstream.expectCancellation() @@ -225,7 +225,7 @@ class FlowPrefixAndTailSpec extends AkkaSpec { val up = TestPublisher.manualProbe[Int]() val down = TestSubscriber.manualProbe[(immutable.Seq[Int], Source[Int, _])]() - val flowSubscriber = Source.subscriber[Int].prefixAndTail(1).to(Sink(down)).run() + val flowSubscriber = Source.asSubscriber[Int].prefixAndTail(1).to(Sink.fromSubscriber(down)).run() val downstream = down.expectSubscription() downstream.cancel() @@ -238,13 +238,13 @@ class FlowPrefixAndTailSpec extends AkkaSpec { val pub = TestPublisher.manualProbe[Int]() val sub = TestSubscriber.manualProbe[Int]() - val f = Source(pub).prefixAndTail(1).runWith(Sink.head) + val f = Source.fromPublisher(pub).prefixAndTail(1).runWith(Sink.head) val s = pub.expectSubscription() s.sendNext(0) val (_, tail) = Await.result(f, 3.seconds) - val tailPub = tail.runWith(Sink.publisher(false)) + val tailPub = tail.runWith(Sink.asPublisher(false)) s.sendComplete() tailPub.subscribe(sub) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowRecoverSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowRecoverSpec.scala index cf725815a5..ed9f543099 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowRecoverSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowRecoverSpec.scala @@ -23,7 +23,7 @@ class FlowRecoverSpec extends AkkaSpec { Source(1 to 4).map { a ⇒ if (a == 3) throw ex else a } .recover { case t: Throwable ⇒ 0 } - .runWith(Sink(subscriber)) + .runWith(Sink.fromSubscriber(subscriber)) subscriber.requestNext(1) subscriber.requestNext(2) @@ -40,7 +40,7 @@ class FlowRecoverSpec extends AkkaSpec { Source(1 to 3).map { a ⇒ if (a == 2) throw ex else a } .recover { case t: IndexOutOfBoundsException ⇒ 0 } - .runWith(Sink(subscriber)) + .runWith(Sink.fromSubscriber(subscriber)) subscriber.requestNext(1) subscriber.request(1) @@ -52,7 +52,7 @@ class FlowRecoverSpec extends AkkaSpec { val k = Source(1 to 3).map(identity) .recover { case t: Throwable ⇒ 0 } - .runWith(Sink(subscriber)) + .runWith(Sink.fromSubscriber(subscriber)) subscriber.requestNext(1) subscriber.requestNext(2) @@ -64,7 +64,7 @@ class FlowRecoverSpec extends AkkaSpec { val subscriber = TestSubscriber.probe[Int]() Source.empty.map(identity) .recover { case t: Throwable ⇒ 0 } - .runWith(Sink(subscriber)) + .runWith(Sink.fromSubscriber(subscriber)) subscriber.request(1) subscriber.expectComplete() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSlidingSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSlidingSpec.scala index 18c96d4fe3..993c76930d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSlidingSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSlidingSpec.scala @@ -24,8 +24,8 @@ class FlowSlidingSpec extends AkkaSpec with GeneratorDrivenPropertyChecks { def check(gen: Gen[(Int, Int, Int)]): Unit = forAll(gen, MinSize(1000), MaxSize(1000)) { case (len, win, step) ⇒ - val af = Source(() ⇒ Iterator.from(0).take(len)).sliding(win, step).runFold(Seq.empty[Seq[Int]])(_ :+ _) - val cf = Source(() ⇒ Iterator.from(0).take(len).sliding(win, step)).runFold(Seq.empty[Seq[Int]])(_ :+ _) + val af = Source.fromIterator(() ⇒ Iterator.from(0).take(len)).sliding(win, step).runFold(Seq.empty[Seq[Int]])(_ :+ _) + val cf = Source.fromIterator(() ⇒ Iterator.from(0).take(len).sliding(win, step)).runFold(Seq.empty[Seq[Int]])(_ :+ _) Await.result(af, remaining) should be(Await.result(cf, remaining)) } diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSpec.scala index 43a049d01e..bd4a43a80e 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSpec.scala @@ -86,17 +86,17 @@ class FlowSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug.rece impl ! ActorGraphInterpreter.ExposedPublisher(0, publisher) - Flow.fromSinkAndSource(Sink(subscriber), Source(publisher)) + Flow.fromSinkAndSource(Sink.fromSubscriber(subscriber), Source.fromPublisher(publisher)) }) val toPublisher: (Source[Any, _], ActorMaterializer) ⇒ Publisher[Any] = - (f, m) ⇒ f.runWith(Sink.publisher(false))(m) + (f, m) ⇒ f.runWith(Sink.asPublisher(false))(m) def toFanoutPublisher[In, Out](elasticity: Int): (Source[Out, _], ActorMaterializer) ⇒ Publisher[Out] = - (f, m) ⇒ f.runWith(Sink.publisher(true).withAttributes(Attributes.inputBuffer(elasticity, elasticity)))(m) + (f, m) ⇒ f.runWith(Sink.asPublisher(true).withAttributes(Attributes.inputBuffer(elasticity, elasticity)))(m) def materializeIntoSubscriberAndPublisher[In, Out](flow: Flow[In, Out, _]): (Subscriber[In], Publisher[Out]) = { - flow.runWith(Source.subscriber[In], Sink.publisher[Out](false)) + flow.runWith(Source.asSubscriber[In], Sink.asPublisher[Out](false)) } "A Flow" must { @@ -177,7 +177,7 @@ class FlowSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug.rece val c1 = TestSubscriber.manualProbe[String]() flowOut.subscribe(c1) - val source: Publisher[String] = Source(List("1", "2", "3")).runWith(Sink.publisher(false)) + val source: Publisher[String] = Source(List("1", "2", "3")).runWith(Sink.asPublisher(false)) source.subscribe(flowIn) val sub1 = c1.expectSubscription() @@ -198,7 +198,7 @@ class FlowSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug.rece sub1.request(3) c1.expectNoMsg(200.millis) - val source: Publisher[Int] = Source(List(1, 2, 3)).runWith(Sink.publisher(false)) + val source: Publisher[Int] = Source(List(1, 2, 3)).runWith(Sink.asPublisher(false)) source.subscribe(flowIn) c1.expectNext("1") @@ -217,7 +217,7 @@ class FlowSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug.rece sub1.request(3) c1.expectNoMsg(200.millis) - val source: Publisher[Int] = Source(List(1, 2, 3)).runWith(Sink.publisher(false)) + val source: Publisher[Int] = Source(List(1, 2, 3)).runWith(Sink.asPublisher(false)) source.subscribe(flowIn) c1.expectNext("elem-1") @@ -229,9 +229,9 @@ class FlowSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug.rece "subscribe Subscriber" in { val flow: Flow[String, String, _] = Flow[String] val c1 = TestSubscriber.manualProbe[String]() - val sink: Sink[String, _] = flow.to(Sink(c1)) - val publisher: Publisher[String] = Source(List("1", "2", "3")).runWith(Sink.publisher(false)) - Source(publisher).to(sink).run() + val sink: Sink[String, _] = flow.to(Sink.fromSubscriber(c1)) + val publisher: Publisher[String] = Source(List("1", "2", "3")).runWith(Sink.asPublisher(false)) + Source.fromPublisher(publisher).to(sink).run() val sub1 = c1.expectSubscription() sub1.request(3) @@ -244,8 +244,8 @@ class FlowSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug.rece "perform transformation operation" in { val flow = Flow[Int].map(i ⇒ { testActor ! i.toString; i.toString }) - val publisher = Source(List(1, 2, 3)).runWith(Sink.publisher(false)) - Source(publisher).via(flow).to(Sink.ignore).run() + val publisher = Source(List(1, 2, 3)).runWith(Sink.asPublisher(false)) + Source.fromPublisher(publisher).via(flow).to(Sink.ignore).run() expectMsg("1") expectMsg("2") @@ -255,9 +255,9 @@ class FlowSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug.rece "perform transformation operation and subscribe Subscriber" in { val flow = Flow[Int].map(_.toString) val c1 = TestSubscriber.manualProbe[String]() - val sink: Sink[Int, _] = flow.to(Sink(c1)) - val publisher: Publisher[Int] = Source(List(1, 2, 3)).runWith(Sink.publisher(false)) - Source(publisher).to(sink).run() + val sink: Sink[Int, _] = flow.to(Sink.fromSubscriber(c1)) + val publisher: Publisher[Int] = Source(List(1, 2, 3)).runWith(Sink.asPublisher(false)) + Source.fromPublisher(publisher).to(sink).run() val sub1 = c1.expectSubscription() sub1.request(3) @@ -269,8 +269,8 @@ class FlowSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug.rece "be materializable several times with fanout publisher" in assertAllStagesStopped { val flow = Source(List(1, 2, 3)).map(_.toString) - val p1 = flow.runWith(Sink.publisher(true)) - val p2 = flow.runWith(Sink.publisher(true)) + val p1 = flow.runWith(Sink.asPublisher(true)) + val p2 = flow.runWith(Sink.asPublisher(true)) val s1 = TestSubscriber.manualProbe[String]() val s2 = TestSubscriber.manualProbe[String]() val s3 = TestSubscriber.manualProbe[String]() @@ -301,11 +301,11 @@ class FlowSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug.rece } "be covariant" in { - val f1: Source[Fruit, _] = Source[Fruit](apples) - val p1: Publisher[Fruit] = Source[Fruit](apples).runWith(Sink.publisher(false)) - val f2: SubFlow[Fruit, _, Source[Fruit, Unit]#Repr, _] = Source[Fruit](apples).splitWhen(_ ⇒ true) - val f3: SubFlow[Fruit, _, Source[Fruit, Unit]#Repr, _] = Source[Fruit](apples).groupBy(2, _ ⇒ true) - val f4: Source[(immutable.Seq[Fruit], Source[Fruit, _]), _] = Source[Fruit](apples).prefixAndTail(1) + val f1: Source[Fruit, _] = Source.fromIterator[Fruit](apples) + val p1: Publisher[Fruit] = Source.fromIterator[Fruit](apples).runWith(Sink.asPublisher(false)) + val f2: SubFlow[Fruit, _, Source[Fruit, Unit]#Repr, _] = Source.fromIterator[Fruit](apples).splitWhen(_ ⇒ true) + val f3: SubFlow[Fruit, _, Source[Fruit, Unit]#Repr, _] = Source.fromIterator[Fruit](apples).groupBy(2, _ ⇒ true) + val f4: Source[(immutable.Seq[Fruit], Source[Fruit, _]), _] = Source.fromIterator[Fruit](apples).prefixAndTail(1) val d1: SubFlow[Fruit, _, Flow[String, Fruit, Unit]#Repr, _] = Flow[String].map(_ ⇒ new Apple).splitWhen(_ ⇒ true) val d2: SubFlow[Fruit, _, Flow[String, Fruit, Unit]#Repr, _] = Flow[String].map(_ ⇒ new Apple).groupBy(2, _ ⇒ true) val d3: Flow[String, (immutable.Seq[Apple], Source[Fruit, _]), _] = Flow[String].map(_ ⇒ new Apple).prefixAndTail(1) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSplitAfterSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSplitAfterSpec.scala index 5d962aac3d..86ecc240ed 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSplitAfterSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSplitAfterSpec.scala @@ -49,7 +49,7 @@ class FlowSplitAfterSpec extends AkkaSpec { class SubstreamsSupport(splitAfter: Int = 3, elementCount: Int = 6) { val source = Source(1 to elementCount) - val groupStream = source.splitAfter(_ == splitAfter).lift.runWith(Sink.publisher(false)) + val groupStream = source.splitAfter(_ == splitAfter).lift.runWith(Sink.asPublisher(false)) val masterSubscriber = TestSubscriber.manualProbe[Source[Int, _]]() groupStream.subscribe(masterSubscriber) @@ -71,7 +71,7 @@ class FlowSplitAfterSpec extends AkkaSpec { "work in the happy case" in assertAllStagesStopped { new SubstreamsSupport(3, elementCount = 5) { - val s1 = StreamPuppet(expectSubFlow().runWith(Sink.publisher(false))) + val s1 = StreamPuppet(expectSubFlow().runWith(Sink.asPublisher(false))) masterSubscriber.expectNoMsg(100.millis) s1.request(2) @@ -82,7 +82,7 @@ class FlowSplitAfterSpec extends AkkaSpec { s1.request(1) s1.expectComplete() - val s2 = StreamPuppet(expectSubFlow().runWith(Sink.publisher(false))) + val s2 = StreamPuppet(expectSubFlow().runWith(Sink.asPublisher(false))) s2.request(2) s2.expectNext(4) @@ -96,14 +96,14 @@ class FlowSplitAfterSpec extends AkkaSpec { "work when first element is split-by" in assertAllStagesStopped { new SubstreamsSupport(splitAfter = 1, elementCount = 3) { - val s1 = StreamPuppet(expectSubFlow().runWith(Sink.publisher(false))) + val s1 = StreamPuppet(expectSubFlow().runWith(Sink.asPublisher(false))) masterSubscriber.expectNoMsg(100.millis) s1.request(3) s1.expectNext(1) s1.expectComplete() - val s2 = StreamPuppet(expectSubFlow().runWith(Sink.publisher(false))) + val s2 = StreamPuppet(expectSubFlow().runWith(Sink.asPublisher(false))) s2.request(3) s2.expectNext(2) @@ -117,9 +117,9 @@ class FlowSplitAfterSpec extends AkkaSpec { "support cancelling substreams" in assertAllStagesStopped { new SubstreamsSupport(splitAfter = 5, elementCount = 8) { - val s1 = StreamPuppet(expectSubFlow().runWith(Sink.publisher(false))) + val s1 = StreamPuppet(expectSubFlow().runWith(Sink.asPublisher(false))) s1.cancel() - val s2 = StreamPuppet(expectSubFlow().runWith(Sink.publisher(false))) + val s2 = StreamPuppet(expectSubFlow().runWith(Sink.asPublisher(false))) s2.request(4) s2.expectNext(6) @@ -134,7 +134,7 @@ class FlowSplitAfterSpec extends AkkaSpec { "support cancelling the master stream" in assertAllStagesStopped { new SubstreamsSupport(splitAfter = 5, elementCount = 8) { - val s1 = StreamPuppet(expectSubFlow().runWith(Sink.publisher(false))) + val s1 = StreamPuppet(expectSubFlow().runWith(Sink.asPublisher(false))) masterSubscription.cancel() s1.request(5) s1.expectNext(1) @@ -150,10 +150,10 @@ class FlowSplitAfterSpec extends AkkaSpec { "fail stream when splitAfter function throws" in assertAllStagesStopped { val publisherProbeProbe = TestPublisher.manualProbe[Int]() val exc = TE("test") - val publisher = Source(publisherProbeProbe) + val publisher = Source.fromPublisher(publisherProbeProbe) .splitAfter(elem ⇒ if (elem == 3) throw exc else elem % 3 == 0) .lift - .runWith(Sink.publisher(false)) + .runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[Source[Int, Unit]]() publisher.subscribe(subscriber) @@ -165,7 +165,7 @@ class FlowSplitAfterSpec extends AkkaSpec { upstreamSubscription.sendNext(1) val substream = subscriber.expectNext() - val substreamPuppet = StreamPuppet(substream.runWith(Sink.publisher(false))) + val substreamPuppet = StreamPuppet(substream.runWith(Sink.asPublisher(false))) substreamPuppet.request(10) substreamPuppet.expectNext(1) @@ -183,11 +183,11 @@ class FlowSplitAfterSpec extends AkkaSpec { "resume stream when splitAfter function throws" in assertAllStagesStopped { val publisherProbeProbe = TestPublisher.manualProbe[Int]() val exc = TE("test") - val publisher = Source(publisherProbeProbe) + val publisher = Source.fromPublisher(publisherProbeProbe) .splitAfter(elem ⇒ if (elem == 3) throw exc else elem % 3 == 0) .lift .withAttributes(ActorAttributes.supervisionStrategy(resumingDecider)) - .runWith(Sink.publisher(false)) + .runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[Source[Int, Unit]]() publisher.subscribe(subscriber) @@ -199,7 +199,7 @@ class FlowSplitAfterSpec extends AkkaSpec { upstreamSubscription.sendNext(1) val substream1 = subscriber.expectNext() - val substreamPuppet1 = StreamPuppet(substream1.runWith(Sink.publisher(false))) + val substreamPuppet1 = StreamPuppet(substream1.runWith(Sink.asPublisher(false))) substreamPuppet1.request(10) substreamPuppet1.expectNext(1) @@ -218,7 +218,7 @@ class FlowSplitAfterSpec extends AkkaSpec { substreamPuppet1.expectNext(6) substreamPuppet1.expectComplete() val substream2 = subscriber.expectNext() - val substreamPuppet2 = StreamPuppet(substream2.runWith(Sink.publisher(false))) + val substreamPuppet2 = StreamPuppet(substream2.runWith(Sink.asPublisher(false))) substreamPuppet2.request(10) upstreamSubscription.sendNext(7) substreamPuppet2.expectNext(7) @@ -232,7 +232,7 @@ class FlowSplitAfterSpec extends AkkaSpec { val up = TestPublisher.manualProbe[Int]() val down = TestSubscriber.manualProbe[Source[Int, Unit]]() - val flowSubscriber = Source.subscriber[Int].splitAfter(_ % 3 == 0).lift.to(Sink(down)).run() + val flowSubscriber = Source.asSubscriber[Int].splitAfter(_ % 3 == 0).lift.to(Sink.fromSubscriber(down)).run() val downstream = down.expectSubscription() downstream.cancel() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSplitWhenSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSplitWhenSpec.scala index 83b353811b..8b9667dbf3 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSplitWhenSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSplitWhenSpec.scala @@ -38,7 +38,7 @@ class FlowSplitWhenSpec extends AkkaSpec { class SubstreamsSupport(splitWhen: Int = 3, elementCount: Int = 6) { val source = Source(1 to elementCount) - val groupStream = source.splitWhen(_ == splitWhen).lift.runWith(Sink.publisher(false)) + val groupStream = source.splitWhen(_ == splitWhen).lift.runWith(Sink.asPublisher(false)) val masterSubscriber = TestSubscriber.manualProbe[Source[Int, _]]() groupStream.subscribe(masterSubscriber) @@ -60,7 +60,7 @@ class FlowSplitWhenSpec extends AkkaSpec { "work in the happy case" in assertAllStagesStopped { new SubstreamsSupport(elementCount = 4) { - val s1 = StreamPuppet(getSubFlow().runWith(Sink.publisher(false))) + val s1 = StreamPuppet(getSubFlow().runWith(Sink.asPublisher(false))) masterSubscriber.expectNoMsg(100.millis) s1.request(2) @@ -69,7 +69,7 @@ class FlowSplitWhenSpec extends AkkaSpec { s1.request(1) s1.expectComplete() - val s2 = StreamPuppet(getSubFlow().runWith(Sink.publisher(false))) + val s2 = StreamPuppet(getSubFlow().runWith(Sink.asPublisher(false))) s2.request(1) s2.expectNext(3) @@ -87,7 +87,7 @@ class FlowSplitWhenSpec extends AkkaSpec { "work when first element is split-by" in assertAllStagesStopped { new SubstreamsSupport(1, elementCount = 3) { - val s1 = StreamPuppet(getSubFlow().runWith(Sink.publisher(false))) + val s1 = StreamPuppet(getSubFlow().runWith(Sink.asPublisher(false))) s1.request(5) s1.expectNext(1) @@ -102,9 +102,9 @@ class FlowSplitWhenSpec extends AkkaSpec { "support cancelling substreams" in assertAllStagesStopped { new SubstreamsSupport(splitWhen = 5, elementCount = 8) { - val s1 = StreamPuppet(getSubFlow().runWith(Sink.publisher(false))) + val s1 = StreamPuppet(getSubFlow().runWith(Sink.asPublisher(false))) s1.cancel() - val s2 = StreamPuppet(getSubFlow().runWith(Sink.publisher(false))) + val s2 = StreamPuppet(getSubFlow().runWith(Sink.asPublisher(false))) s2.request(4) s2.expectNext(5) @@ -125,11 +125,11 @@ class FlowSplitWhenSpec extends AkkaSpec { val substream = TestSubscriber.probe[Int]() val masterStream = TestSubscriber.probe[Any]() - Source(inputs) + Source.fromPublisher(inputs) .splitWhen(_ == 2) .lift - .map(_.runWith(Sink(substream))) - .runWith(Sink(masterStream)) + .map(_.runWith(Sink.fromSubscriber(substream))) + .runWith(Sink.fromSubscriber(masterStream)) masterStream.request(1) inputs.sendNext(1) @@ -142,7 +142,7 @@ class FlowSplitWhenSpec extends AkkaSpec { inputs.expectCancellation() val inputs2 = TestPublisher.probe[Int]() - Source(inputs2) + Source.fromPublisher(inputs2) .splitWhen(_ == 2) .lift .map(_.runWith(Sink.cancelled)) @@ -155,10 +155,10 @@ class FlowSplitWhenSpec extends AkkaSpec { val substream3 = TestSubscriber.probe[Int]() val masterStream3 = TestSubscriber.probe[Source[Int, Any]]() - Source(inputs3) + Source.fromPublisher(inputs3) .splitWhen(_ == 2) .lift - .runWith(Sink(masterStream3)) + .runWith(Sink.fromSubscriber(masterStream3)) masterStream3.request(1) inputs3.sendNext(1) @@ -170,7 +170,7 @@ class FlowSplitWhenSpec extends AkkaSpec { inputs3.sendNext(2) val src2 = masterStream3.expectNext() val substream4 = TestSubscriber.probe[Int]() - src2.runWith(Sink(substream4)) + src2.runWith(Sink.fromSubscriber(substream4)) substream4.requestNext(2) substream4.expectNoMsg(1.second) @@ -191,7 +191,7 @@ class FlowSplitWhenSpec extends AkkaSpec { "support cancelling the master stream" in assertAllStagesStopped { new SubstreamsSupport(splitWhen = 5, elementCount = 8) { - val s1 = StreamPuppet(getSubFlow().runWith(Sink.publisher(false))) + val s1 = StreamPuppet(getSubFlow().runWith(Sink.asPublisher(false))) masterSubscription.cancel() s1.request(4) s1.expectNext(1) @@ -206,10 +206,10 @@ class FlowSplitWhenSpec extends AkkaSpec { "fail stream when splitWhen function throws" in assertAllStagesStopped { val publisherProbeProbe = TestPublisher.manualProbe[Int]() val exc = TE("test") - val publisher = Source(publisherProbeProbe) + val publisher = Source.fromPublisher(publisherProbeProbe) .splitWhen(elem ⇒ if (elem == 3) throw exc else elem % 3 == 0) .lift - .runWith(Sink.publisher(false)) + .runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[Source[Int, Unit]]() publisher.subscribe(subscriber) @@ -221,7 +221,7 @@ class FlowSplitWhenSpec extends AkkaSpec { upstreamSubscription.sendNext(1) val substream = subscriber.expectNext() - val substreamPuppet = StreamPuppet(substream.runWith(Sink.publisher(false))) + val substreamPuppet = StreamPuppet(substream.runWith(Sink.asPublisher(false))) substreamPuppet.request(10) substreamPuppet.expectNext(1) @@ -239,11 +239,11 @@ class FlowSplitWhenSpec extends AkkaSpec { "resume stream when splitWhen function throws" in assertAllStagesStopped { val publisherProbeProbe = TestPublisher.manualProbe[Int]() val exc = TE("test") - val publisher = Source(publisherProbeProbe) + val publisher = Source.fromPublisher(publisherProbeProbe) .splitWhen(elem ⇒ if (elem == 3) throw exc else elem % 3 == 0) .lift .withAttributes(ActorAttributes.supervisionStrategy(resumingDecider)) - .runWith(Sink.publisher(false)) + .runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[Source[Int, Unit]]() publisher.subscribe(subscriber) @@ -255,7 +255,7 @@ class FlowSplitWhenSpec extends AkkaSpec { upstreamSubscription.sendNext(1) val substream1 = subscriber.expectNext() - val substreamPuppet1 = StreamPuppet(substream1.runWith(Sink.publisher(false))) + val substreamPuppet1 = StreamPuppet(substream1.runWith(Sink.asPublisher(false))) substreamPuppet1.request(10) substreamPuppet1.expectNext(1) @@ -273,7 +273,7 @@ class FlowSplitWhenSpec extends AkkaSpec { upstreamSubscription.sendNext(6) substreamPuppet1.expectComplete() val substream2 = subscriber.expectNext() - val substreamPuppet2 = StreamPuppet(substream2.runWith(Sink.publisher(false))) + val substreamPuppet2 = StreamPuppet(substream2.runWith(Sink.asPublisher(false))) substreamPuppet2.request(10) substreamPuppet2.expectNext(6) @@ -286,7 +286,7 @@ class FlowSplitWhenSpec extends AkkaSpec { val up = TestPublisher.manualProbe[Int]() val down = TestSubscriber.manualProbe[Source[Int, Unit]]() - val flowSubscriber = Source.subscriber[Int].splitWhen(_ % 3 == 0).lift.to(Sink(down)).run() + val flowSubscriber = Source.asSubscriber[Int].splitWhen(_ % 3 == 0).lift.to(Sink.fromSubscriber(down)).run() val downstream = down.expectSubscription() downstream.cancel() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowStageSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowStageSpec.scala index cf2920aad0..14de445e84 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowStageSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowStageSpec.scala @@ -29,8 +29,8 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug "A Flow with transform operations" must { "produce one-to-one transformation as expected" in assertAllStagesStopped { - val p = Source(List(1, 2, 3)).runWith(Sink.publisher(false)) - val p2 = Source(p). + val p = Source(List(1, 2, 3)).runWith(Sink.asPublisher(false)) + val p2 = Source.fromPublisher(p). transform(() ⇒ new PushStage[Int, Int] { var tot = 0 override def onPush(elem: Int, ctx: Context[Int]) = { @@ -38,7 +38,7 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug ctx.push(tot) } }). - runWith(Sink.publisher(false)) + runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[Int]() p2.subscribe(subscriber) val subscription = subscriber.expectSubscription() @@ -52,8 +52,8 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug } "produce one-to-several transformation as expected" in assertAllStagesStopped { - val p = Source(List(1, 2, 3)).runWith(Sink.publisher(false)) - val p2 = Source(p). + val p = Source(List(1, 2, 3)).runWith(Sink.asPublisher(false)) + val p2 = Source.fromPublisher(p). transform(() ⇒ new StatefulStage[Int, Int] { var tot = 0 @@ -72,7 +72,7 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug } }). - runWith(Sink.publisher(false)) + runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[Int]() p2.subscribe(subscriber) val subscription = subscriber.expectSubscription() @@ -109,7 +109,7 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug ctx.pull() } else ctx.push(elem) } - }).runWith(Sink.publisher(false)) + }).runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[Int]() p.subscribe(subscriber) @@ -135,8 +135,8 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug } "produce dropping transformation as expected" in { - val p = Source(List(1, 2, 3, 4)).runWith(Sink.publisher(false)) - val p2 = Source(p). + val p = Source(List(1, 2, 3, 4)).runWith(Sink.asPublisher(false)) + val p2 = Source.fromPublisher(p). transform(() ⇒ new PushStage[Int, Int] { var tot = 0 override def onPush(elem: Int, ctx: Context[Int]) = { @@ -147,7 +147,7 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug ctx.push(tot) } }). - runWith(Sink.publisher(false)) + runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[Int]() p2.subscribe(subscriber) val subscription = subscriber.expectSubscription() @@ -161,8 +161,8 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug } "produce multi-step transformation as expected" in { - val p = Source(List("a", "bc", "def")).runWith(Sink.publisher(false)) - val p2 = Source(p). + val p = Source(List("a", "bc", "def")).runWith(Sink.asPublisher(false)) + val p2 = Source.fromPublisher(p). transform(() ⇒ new PushStage[String, Int] { var concat = "" override def onPush(elem: String, ctx: Context[Int]) = { @@ -177,7 +177,7 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug ctx.push(tot) } }). - runWith(Sink.publisher(true)) + runWith(Sink.asPublisher(true)) val c1 = TestSubscriber.manualProbe[Int]() p2.subscribe(c1) val sub1 = c1.expectSubscription() @@ -200,8 +200,8 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug } "support emit onUpstreamFinish" in assertAllStagesStopped { - val p = Source(List("a")).runWith(Sink.publisher(false)) - val p2 = Source(p). + val p = Source(List("a")).runWith(Sink.asPublisher(false)) + val p2 = Source.fromPublisher(p). transform(() ⇒ new StatefulStage[String, String] { var s = "" override def initial = new State { @@ -213,7 +213,7 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug override def onUpstreamFinish(ctx: Context[String]) = terminationEmit(Iterator.single(s + "B"), ctx) }). - runWith(Sink.publisher(false)) + runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[String]() p2.subscribe(c) val s = c.expectSubscription() @@ -244,8 +244,8 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug } "report error when exception is thrown" in assertAllStagesStopped { - val p = Source(List(1, 2, 3)).runWith(Sink.publisher(false)) - val p2 = Source(p). + val p = Source(List(1, 2, 3)).runWith(Sink.asPublisher(false)) + val p2 = Source.fromPublisher(p). transform(() ⇒ new StatefulStage[Int, Int] { override def initial = new State { override def onPush(elem: Int, ctx: Context[Int]) = { @@ -268,8 +268,8 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug } "support emit of final elements when onUpstreamFailure" in assertAllStagesStopped { - val p = Source(List(1, 2, 3)).runWith(Sink.publisher(false)) - val p2 = Source(p). + val p = Source(List(1, 2, 3)).runWith(Sink.asPublisher(false)) + val p2 = Source.fromPublisher(p). map(elem ⇒ if (elem == 2) throw new IllegalArgumentException("two not allowed") else elem). transform(() ⇒ new StatefulStage[Int, Int] { override def initial = new State { @@ -292,8 +292,8 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug } "support cancel as expected" in assertAllStagesStopped { - val p = Source(1 to 100).runWith(Sink.publisher(false)) - val received = Source(p). + val p = Source(1 to 100).runWith(Sink.asPublisher(false)) + val received = Source.fromPublisher(p). transform(() ⇒ new StatefulStage[Int, Int] { override def initial = new State { override def onPush(elem: Int, ctx: Context[Int]) = @@ -312,8 +312,8 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug } "support producing elements from empty inputs" in assertAllStagesStopped { - val p = Source(List.empty[Int]).runWith(Sink.publisher(false)) - Source(p). + val p = Source(List.empty[Int]).runWith(Sink.asPublisher(false)) + Source.fromPublisher(p). transform(() ⇒ new StatefulStage[Int, Int] { override def initial = new State { override def onPush(elem: Int, ctx: Context[Int]) = ctx.pull() @@ -382,7 +382,7 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug "handle early cancelation" in assertAllStagesStopped { val onDownstreamFinishProbe = TestProbe() val down = TestSubscriber.manualProbe[Int]() - val s = Source.subscriber[Int]. + val s = Source.asSubscriber[Int]. transform(() ⇒ new PushStage[Int, Int] { override def onPush(elem: Int, ctx: Context[Int]) = ctx.push(elem) @@ -391,7 +391,7 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug ctx.finish() } }). - to(Sink(down)).run() + to(Sink.fromSubscriber(down)).run() val downstream = down.expectSubscription() downstream.cancel() @@ -406,7 +406,7 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug "not trigger onUpstreamFinished after pushAndFinish" in assertAllStagesStopped { val in = TestPublisher.manualProbe[Int]() val flow = - Source(in) + Source.fromPublisher(in) .transform(() ⇒ new StatefulStage[Int, Int] { def initial: StageState[Int, Int] = new State { @@ -416,7 +416,7 @@ class FlowStageSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug override def onUpstreamFinish(ctx: Context[Int]): TerminationDirective = terminationEmit(Iterator(42), ctx) }) - .runWith(Sink.publisher(false)) + .runWith(Sink.asPublisher(false)) val inSub = in.expectSubscription() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeSpec.scala index 866a7f9b48..95ce21d549 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeSpec.scala @@ -35,7 +35,7 @@ class FlowTakeSpec extends AkkaSpec with ScriptedTest { "not take anything for negative n" in { val probe = TestSubscriber.manualProbe[Int]() - Source(List(1, 2, 3)).take(-1).to(Sink(probe)).run() + Source(List(1, 2, 3)).take(-1).to(Sink.fromSubscriber(probe)).run() probe.expectSubscription().request(10) probe.expectComplete() } diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWithinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWithinSpec.scala index 25f63ea9ad..ceab747a23 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWithinSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWithinSpec.scala @@ -19,7 +19,7 @@ class FlowTakeWithinSpec extends AkkaSpec { val input = Iterator.from(1) val p = TestPublisher.manualProbe[Int]() val c = TestSubscriber.manualProbe[Int]() - Source(p).takeWithin(1.second).to(Sink(c)).run() + Source.fromPublisher(p).takeWithin(1.second).to(Sink.fromSubscriber(c)).run() val pSub = p.expectSubscription() val cSub = c.expectSubscription() cSub.request(100) @@ -39,7 +39,7 @@ class FlowTakeWithinSpec extends AkkaSpec { "deliver buffered elements onComplete before the timeout" in assertAllStagesStopped { val c = TestSubscriber.manualProbe[Int]() - Source(1 to 3).takeWithin(1.second).to(Sink(c)).run() + Source(1 to 3).takeWithin(1.second).to(Sink.fromSubscriber(c)).run() val cSub = c.expectSubscription() c.expectNoMsg(200.millis) cSub.request(100) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowThrottleSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowThrottleSpec.scala index 792ff7efb4..d2159f4d55 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowThrottleSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowThrottleSpec.scala @@ -33,7 +33,7 @@ class FlowThrottleSpec extends AkkaSpec { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).throttle(1, 300.millis, 0, Shaping).runWith(Sink(downstream)) + Source.fromPublisher(upstream).throttle(1, 300.millis, 0, Shaping).runWith(Sink.fromSubscriber(downstream)) downstream.request(20) upstream.sendNext(1) @@ -51,7 +51,7 @@ class FlowThrottleSpec extends AkkaSpec { "not send downstream if upstream does not emit element" in Utils.assertAllStagesStopped { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).throttle(1, 300.millis, 0, Shaping).runWith(Sink(downstream)) + Source.fromPublisher(upstream).throttle(1, 300.millis, 0, Shaping).runWith(Sink.fromSubscriber(downstream)) downstream.request(2) upstream.sendNext(1) @@ -66,7 +66,7 @@ class FlowThrottleSpec extends AkkaSpec { "cancel when downstream cancels" in Utils.assertAllStagesStopped { val downstream = TestSubscriber.probe[Int]() - Source(1 to 10).throttle(1, 300.millis, 0, Shaping).runWith(Sink(downstream)) + Source(1 to 10).throttle(1, 300.millis, 0, Shaping).runWith(Sink.fromSubscriber(downstream)) downstream.cancel() } @@ -84,7 +84,7 @@ class FlowThrottleSpec extends AkkaSpec { "burst according to its maximum if enough time passed" in Utils.assertAllStagesStopped { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).throttle(1, 200.millis, 5, Shaping).runWith(Sink(downstream)) + Source.fromPublisher(upstream).throttle(1, 200.millis, 5, Shaping).runWith(Sink.fromSubscriber(downstream)) downstream.request(1) upstream.sendNext(1) downstream.expectNoMsg(100.millis) @@ -99,7 +99,7 @@ class FlowThrottleSpec extends AkkaSpec { "burst some elements if have enough time" in Utils.assertAllStagesStopped { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).throttle(1, 200.millis, 5, Shaping).runWith(Sink(downstream)) + Source.fromPublisher(upstream).throttle(1, 200.millis, 5, Shaping).runWith(Sink.fromSubscriber(downstream)) downstream.request(1) upstream.sendNext(1) downstream.expectNoMsg(100.millis) @@ -156,7 +156,7 @@ class FlowThrottleSpec extends AkkaSpec { "not send downstream if upstream does not emit element" in Utils.assertAllStagesStopped { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).throttle(2, 300.millis, 0, identity, Shaping).runWith(Sink(downstream)) + Source.fromPublisher(upstream).throttle(2, 300.millis, 0, identity, Shaping).runWith(Sink.fromSubscriber(downstream)) downstream.request(2) upstream.sendNext(1) @@ -171,7 +171,7 @@ class FlowThrottleSpec extends AkkaSpec { "cancel when downstream cancels" in Utils.assertAllStagesStopped { val downstream = TestSubscriber.probe[Int]() - Source(1 to 10).throttle(2, 200.millis, 0, identity, Shaping).runWith(Sink(downstream)) + Source(1 to 10).throttle(2, 200.millis, 0, identity, Shaping).runWith(Sink.fromSubscriber(downstream)) downstream.cancel() } @@ -189,7 +189,7 @@ class FlowThrottleSpec extends AkkaSpec { "burst according to its maximum if enough time passed" in Utils.assertAllStagesStopped { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).throttle(2, 400.millis, 5, (_) ⇒ 1, Shaping).runWith(Sink(downstream)) + Source.fromPublisher(upstream).throttle(2, 400.millis, 5, (_) ⇒ 1, Shaping).runWith(Sink.fromSubscriber(downstream)) downstream.request(1) upstream.sendNext(1) downstream.expectNoMsg(100.millis) @@ -204,7 +204,7 @@ class FlowThrottleSpec extends AkkaSpec { "burst some elements if have enough time" in Utils.assertAllStagesStopped { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).throttle(2, 400.millis, 5, (e) ⇒ if (e < 4) 1 else 20, Shaping).runWith(Sink(downstream)) + Source.fromPublisher(upstream).throttle(2, 400.millis, 5, (e) ⇒ if (e < 4) 1 else 20, Shaping).runWith(Sink.fromSubscriber(downstream)) downstream.request(1) upstream.sendNext(1) downstream.expectNoMsg(100.millis) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowZipSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowZipSpec.scala index 345c4783b0..ae3853a2ac 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowZipSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowZipSpec.scala @@ -13,7 +13,7 @@ class FlowZipSpec extends BaseTwoStreamsSetup { override def setup(p1: Publisher[Int], p2: Publisher[Int]) = { val subscriber = TestSubscriber.probe[Outputs]() - Source(p1).zip(Source(p2)).runWith(Sink(subscriber)) + Source.fromPublisher(p1).zip(Source.fromPublisher(p2)).runWith(Sink.fromSubscriber(subscriber)) subscriber } @@ -21,7 +21,7 @@ class FlowZipSpec extends BaseTwoStreamsSetup { "work in the happy case" in assertAllStagesStopped { val probe = TestSubscriber.manualProbe[(Int, String)]() - Source(1 to 4).zip(Source(List("A", "B", "C", "D", "E", "F"))).runWith(Sink(probe)) + Source(1 to 4).zip(Source(List("A", "B", "C", "D", "E", "F"))).runWith(Sink.fromSubscriber(probe)) val subscription = probe.expectSubscription() subscription.request(2) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowZipWithSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowZipWithSpec.scala index 0f0a246696..e961d1cf2d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowZipWithSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowZipWithSpec.scala @@ -13,7 +13,7 @@ class FlowZipWithSpec extends BaseTwoStreamsSetup { override def setup(p1: Publisher[Int], p2: Publisher[Int]) = { val subscriber = TestSubscriber.probe[Outputs]() - Source(p1).zipWith(Source(p2))(_ + _).runWith(Sink(subscriber)) + Source.fromPublisher(p1).zipWith(Source.fromPublisher(p2))(_ + _).runWith(Sink.fromSubscriber(subscriber)) subscriber } @@ -21,7 +21,7 @@ class FlowZipWithSpec extends BaseTwoStreamsSetup { "work in the happy case" in { val probe = TestSubscriber.manualProbe[Outputs]() - Source(1 to 4).zipWith(Source(10 to 40 by 10))((_: Int) + (_: Int)).runWith(Sink(probe)) + Source(1 to 4).zipWith(Source(10 to 40 by 10))((_: Int) + (_: Int)).runWith(Sink.fromSubscriber(probe)) val subscription = probe.expectSubscription() @@ -39,7 +39,7 @@ class FlowZipWithSpec extends BaseTwoStreamsSetup { "work in the sad case" in { val probe = TestSubscriber.manualProbe[Outputs]() - Source(1 to 4).zipWith(Source(-2 to 2))((_: Int) / (_: Int)).runWith(Sink(probe)) + Source(1 to 4).zipWith(Source(-2 to 2))((_: Int) / (_: Int)).runWith(Sink.fromSubscriber(probe)) val subscription = probe.expectSubscription() subscription.request(2) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBackedFlowSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBackedFlowSpec.scala index c6a92aefa7..98682339ed 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBackedFlowSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBackedFlowSpec.scala @@ -68,7 +68,7 @@ class GraphFlowSpec extends AkkaSpec { FlowShape(partial.in, partial.out.map(_.toInt).outlet) }) - source1.via(flow).to(Sink(probe)).run() + source1.via(flow).to(Sink.fromSubscriber(probe)).run() validateProbe(probe, stdRequests, stdResult) } @@ -80,7 +80,7 @@ class GraphFlowSpec extends AkkaSpec { partial ⇒ FlowShape(partial.in, partial.out) }) - source1.via(flow).map(_.toInt).to(Sink(probe)).run() + source1.via(flow).map(_.toInt).to(Sink.fromSubscriber(probe)).run() validateProbe(probe, stdRequests, stdResult) } @@ -98,7 +98,7 @@ class GraphFlowSpec extends AkkaSpec { FlowShape(importFlow.in, importFlow.out) }) - source1.via(flow1).via(flow2).to(Sink(probe)).run() + source1.via(flow1).via(flow2).to(Sink.fromSubscriber(probe)).run() validateProbe(probe, stdRequests, stdResult) } @@ -112,7 +112,7 @@ class GraphFlowSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ import GraphDSL.Implicits._ - Source(1 to 5) ~> flow ~> flow ~> Sink(probe) + Source(1 to 5) ~> flow ~> flow ~> Sink.fromSubscriber(probe) ClosedShape }).run() @@ -131,16 +131,16 @@ class GraphFlowSpec extends AkkaSpec { SourceShape(partial.out.map(_.toInt).outlet) }) - source.to(Sink(probe)).run() + source.to(Sink.fromSubscriber(probe)).run() validateProbe(probe, stdRequests, stdResult) } "work with a Sink when having KeyedSource inside" in { val probe = TestSubscriber.manualProbe[Int]() - val source = Source.subscriber[Int] - val mm: Subscriber[Int] = source.to(Sink(probe)).run() - source1.to(Sink(mm)).run() + val source = Source.asSubscriber[Int] + val mm: Subscriber[Int] = source.to(Sink.fromSubscriber(probe)).run() + source1.to(Sink.fromSubscriber(mm)).run() validateProbe(probe, 4, (0 to 3).toSet) } @@ -156,7 +156,7 @@ class GraphFlowSpec extends AkkaSpec { SourceShape(partial.out) }) - source.map(_.toInt).to(Sink(probe)).run() + source.map(_.toInt).to(Sink.fromSubscriber(probe)).run() validateProbe(probe, stdRequests, stdResult) } @@ -176,7 +176,7 @@ class GraphFlowSpec extends AkkaSpec { FlowShape(importFlow.in, importFlow.out) }) - source.via(flow).to(Sink(probe)).run() + source.via(flow).to(Sink.fromSubscriber(probe)).run() validateProbe(probe, stdRequests, stdResult) } @@ -195,7 +195,7 @@ class GraphFlowSpec extends AkkaSpec { import GraphDSL.Implicits._ val merge = b.add(Merge[Int](2)) s1.out ~> merge.in(0) - merge.out ~> Sink(probe) + merge.out ~> Sink.fromSubscriber(probe) s2.out.map(_ * 10) ~> merge.in(1) ClosedShape }).run() @@ -211,7 +211,7 @@ class GraphFlowSpec extends AkkaSpec { val sink = Sink.fromGraph(GraphDSL.create(partialGraph) { implicit b ⇒ partial ⇒ import GraphDSL.Implicits._ - partial.out.map(_.toInt) ~> Sink(probe) + partial.out.map(_.toInt) ~> Sink.fromSubscriber(probe) SinkShape(partial.in) }) @@ -222,14 +222,14 @@ class GraphFlowSpec extends AkkaSpec { "work with a Source when having KeyedSink inside" in { val probe = TestSubscriber.manualProbe[Int]() - val pubSink = Sink.publisher[Int](false) + val pubSink = Sink.asPublisher[Int](false) val sink = Sink.fromGraph(GraphDSL.create(pubSink) { implicit b ⇒ p ⇒ SinkShape(p.in) }) val mm = source1.runWith(sink) - Source(mm).to(Sink(probe)).run() + Source.fromPublisher(mm).to(Sink.fromSubscriber(probe)).run() validateProbe(probe, 4, (0 to 3).toSet) } @@ -241,7 +241,7 @@ class GraphFlowSpec extends AkkaSpec { (partial, flow) ⇒ import GraphDSL.Implicits._ flow.out ~> partial.in - partial.out.map(_.toInt) ~> Sink(probe) + partial.out.map(_.toInt) ~> Sink.fromSubscriber(probe) SinkShape(flow.in) }) @@ -263,7 +263,7 @@ class GraphFlowSpec extends AkkaSpec { val sink = Sink.fromGraph(GraphDSL.create(Flow[String].map(_.toInt)) { implicit b ⇒ flow ⇒ import GraphDSL.Implicits._ - flow.out ~> Sink(probe) + flow.out ~> Sink.fromSubscriber(probe) SinkShape(flow.in) }) @@ -276,8 +276,8 @@ class GraphFlowSpec extends AkkaSpec { "used together" should { "materialize properly" in { val probe = TestSubscriber.manualProbe[Int]() - val inSource = Source.subscriber[Int] - val outSink = Sink.publisher[Int](false) + val inSource = Source.asSubscriber[Int] + val outSink = Sink.asPublisher[Int](false) val flow = Flow.fromGraph(GraphDSL.create(partialGraph) { implicit b ⇒ partial ⇒ @@ -309,7 +309,7 @@ class GraphFlowSpec extends AkkaSpec { val subscriber = m1 val publisher = m3 - source1.runWith(Sink.publisher(false)).subscribe(subscriber) + source1.runWith(Sink.asPublisher(false)).subscribe(subscriber) publisher.subscribe(probe) validateProbe(probe, stdRequests, stdResult) @@ -317,8 +317,8 @@ class GraphFlowSpec extends AkkaSpec { "allow connecting source to sink directly" in { val probe = TestSubscriber.manualProbe[Int]() - val inSource = Source.subscriber[Int] - val outSink = Sink.publisher[Int](false) + val inSource = Source.asSubscriber[Int] + val outSink = Sink.asPublisher[Int](false) val source = Source.fromGraph(GraphDSL.create(inSource) { implicit b ⇒ src ⇒ @@ -340,7 +340,7 @@ class GraphFlowSpec extends AkkaSpec { val subscriber = m1 val publisher = m2 - source1.runWith(Sink.publisher(false)).subscribe(subscriber) + source1.runWith(Sink.asPublisher(false)).subscribe(subscriber) publisher.subscribe(probe) validateProbe(probe, 4, (0 to 3).toSet) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBalanceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBalanceSpec.scala index 42d563f148..4cae284754 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBalanceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBalanceSpec.scala @@ -26,8 +26,8 @@ class GraphBalanceSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val balance = b.add(Balance[Int](2)) Source(List(1, 2, 3)) ~> balance.in - balance.out(0) ~> Sink(c1) - balance.out(1) ~> Sink(c2) + balance.out(0) ~> Sink.fromSubscriber(c1) + balance.out(1) ~> Sink.fromSubscriber(c2) ClosedShape }).run() @@ -47,11 +47,11 @@ class GraphBalanceSpec extends AkkaSpec { "support waiting for demand from all downstream subscriptions" in { val s1 = TestSubscriber.manualProbe[Int]() - val p2 = RunnableGraph.fromGraph(GraphDSL.create(Sink.publisher[Int](false)) { implicit b ⇒ + val p2 = RunnableGraph.fromGraph(GraphDSL.create(Sink.asPublisher[Int](false)) { implicit b ⇒ p2Sink ⇒ val balance = b.add(Balance[Int](2, waitForAllDownstreams = true)) Source(List(1, 2, 3)) ~> balance.in - balance.out(0) ~> Sink(s1) + balance.out(0) ~> Sink.fromSubscriber(s1) balance.out(1) ~> p2Sink ClosedShape }).run() @@ -78,11 +78,11 @@ class GraphBalanceSpec extends AkkaSpec { "support waiting for demand from all non-cancelled downstream subscriptions" in assertAllStagesStopped { val s1 = TestSubscriber.manualProbe[Int]() - val (p2, p3) = RunnableGraph.fromGraph(GraphDSL.create(Sink.publisher[Int](false), Sink.publisher[Int](false))(Keep.both) { implicit b ⇒ + val (p2, p3) = RunnableGraph.fromGraph(GraphDSL.create(Sink.asPublisher[Int](false), Sink.asPublisher[Int](false))(Keep.both) { implicit b ⇒ (p2Sink, p3Sink) ⇒ val balance = b.add(Balance[Int](3, waitForAllDownstreams = true)) Source(List(1, 2, 3)) ~> balance.in - balance.out(0) ~> Sink(s1) + balance.out(0) ~> Sink.fromSubscriber(s1) balance.out(1) ~> p2Sink balance.out(2) ~> p3Sink ClosedShape @@ -183,8 +183,8 @@ class GraphBalanceSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val balance = b.add(Balance[Int](2)) Source(List(1, 2, 3)) ~> balance.in - balance.out(0) ~> Sink(c1) - balance.out(1) ~> Sink(c2) + balance.out(0) ~> Sink.fromSubscriber(c1) + balance.out(1) ~> Sink.fromSubscriber(c2) ClosedShape }).run() @@ -205,8 +205,8 @@ class GraphBalanceSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val balance = b.add(Balance[Int](2)) Source(List(1, 2, 3)) ~> balance.in - balance.out(0) ~> Sink(c1) - balance.out(1) ~> Sink(c2) + balance.out(0) ~> Sink.fromSubscriber(c1) + balance.out(1) ~> Sink.fromSubscriber(c2) ClosedShape }).run() @@ -227,9 +227,9 @@ class GraphBalanceSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val balance = b.add(Balance[Int](2)) - Source(p1.getPublisher) ~> balance.in - balance.out(0) ~> Sink(c1) - balance.out(1) ~> Sink(c2) + Source.fromPublisher(p1.getPublisher) ~> balance.in + balance.out(0) ~> Sink.fromSubscriber(c1) + balance.out(1) ~> Sink.fromSubscriber(c2) ClosedShape }).run() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBroadcastSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBroadcastSpec.scala index c94ed1c69b..7f9bc8b454 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBroadcastSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBroadcastSpec.scala @@ -26,8 +26,8 @@ class GraphBroadcastSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val bcast = b.add(Broadcast[Int](2)) Source(List(1, 2, 3)) ~> bcast.in - bcast.out(0) ~> Flow[Int].buffer(16, OverflowStrategy.backpressure) ~> Sink(c1) - bcast.out(1) ~> Flow[Int].buffer(16, OverflowStrategy.backpressure) ~> Sink(c2) + bcast.out(0) ~> Flow[Int].buffer(16, OverflowStrategy.backpressure) ~> Sink.fromSubscriber(c1) + bcast.out(1) ~> Flow[Int].buffer(16, OverflowStrategy.backpressure) ~> Sink.fromSubscriber(c2) ClosedShape }).run() @@ -129,8 +129,8 @@ class GraphBroadcastSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val bcast = b.add(Broadcast[Int](2)) Source(List(1, 2, 3)) ~> bcast.in - bcast.out(0) ~> Flow[Int] ~> Sink(c1) - bcast.out(1) ~> Flow[Int] ~> Sink(c2) + bcast.out(0) ~> Flow[Int] ~> Sink.fromSubscriber(c1) + bcast.out(1) ~> Flow[Int] ~> Sink.fromSubscriber(c2) ClosedShape }).run() @@ -151,8 +151,8 @@ class GraphBroadcastSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val bcast = b.add(Broadcast[Int](2)) Source(List(1, 2, 3)) ~> bcast.in - bcast.out(0) ~> Flow[Int].named("identity-a") ~> Sink(c1) - bcast.out(1) ~> Flow[Int].named("identity-b") ~> Sink(c2) + bcast.out(0) ~> Flow[Int].named("identity-a") ~> Sink.fromSubscriber(c1) + bcast.out(1) ~> Flow[Int].named("identity-b") ~> Sink.fromSubscriber(c2) ClosedShape }).run() @@ -173,9 +173,9 @@ class GraphBroadcastSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val bcast = b.add(Broadcast[Int](2)) - Source(p1.getPublisher) ~> bcast.in - bcast.out(0) ~> Flow[Int] ~> Sink(c1) - bcast.out(1) ~> Flow[Int] ~> Sink(c2) + Source.fromPublisher(p1.getPublisher) ~> bcast.in + bcast.out(0) ~> Flow[Int] ~> Sink.fromSubscriber(c1) + bcast.out(1) ~> Flow[Int] ~> Sink.fromSubscriber(c2) ClosedShape }).run() @@ -202,12 +202,12 @@ class GraphBroadcastSpec extends AkkaSpec { val sink = Sink.fromGraph(GraphDSL.create() { implicit b ⇒ val bcast = b.add(Broadcast[Int](2)) - bcast.out(0) ~> Sink(c1) - bcast.out(1) ~> Sink(c2) + bcast.out(0) ~> Sink.fromSubscriber(c1) + bcast.out(1) ~> Sink.fromSubscriber(c2) SinkShape(bcast.in) }) - val s = Source.subscriber[Int].to(sink).run() + val s = Source.asSubscriber[Int].to(sink).run() val up = TestPublisher.manualProbe[Int]() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphConcatSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphConcatSpec.scala index babee44add..4087e1a00c 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphConcatSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphConcatSpec.scala @@ -41,7 +41,7 @@ class GraphConcatSpec extends TwoStreamsSetup { concat1.out ~> concat2.in(0) Source(5 to 10) ~> concat2.in(1) - concat2.out ~> Sink(probe) + concat2.out ~> Sink.fromSubscriber(probe) ClosedShape }).run() @@ -136,8 +136,8 @@ class GraphConcatSpec extends TwoStreamsSetup { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val concat = b add Concat[Int]() Source(List(1, 2, 3)) ~> concat.in(0) - Source(promise.future) ~> concat.in(1) - concat.out ~> Sink(subscriber) + Source.fromFuture(promise.future) ~> concat.in(1) + concat.out ~> Sink.fromSubscriber(subscriber) ClosedShape }).run() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphMatValueSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphMatValueSpec.scala index 600eb758a8..7403c10c82 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphMatValueSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphMatValueSpec.scala @@ -28,7 +28,7 @@ class GraphMatValueSpec extends AkkaSpec { val f = RunnableGraph.fromGraph(GraphDSL.create(foldSink) { implicit b ⇒ fold ⇒ Source(1 to 10) ~> fold - b.materializedValue.mapAsync(4)(identity) ~> Sink(sub) + b.materializedValue.mapAsync(4)(identity) ~> Sink.fromSubscriber(sub) ClosedShape }).run() @@ -49,7 +49,7 @@ class GraphMatValueSpec extends AkkaSpec { b.materializedValue.mapAsync(4)(identity) ~> zip.in0 b.materializedValue.mapAsync(4)(identity) ~> zip.in1 - zip.out ~> Sink(sub) + zip.out ~> Sink.fromSubscriber(sub) ClosedShape }).run() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphMergeSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphMergeSpec.scala index 7e28a490ae..91eb669251 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphMergeSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphMergeSpec.scala @@ -39,7 +39,7 @@ class GraphMergeSpec extends TwoStreamsSetup { source1 ~> m1.in(0) m1.out ~> Flow[Int].map(_ * 2) ~> m2.in(0) - m2.out ~> Flow[Int].map(_ / 2).map(_ + 1) ~> Sink(probe) + m2.out ~> Flow[Int].map(_ / 2).map(_ + 1) ~> Sink.fromSubscriber(probe) source2 ~> m1.in(1) source3 ~> m2.in(1) @@ -77,7 +77,7 @@ class GraphMergeSpec extends TwoStreamsSetup { source4 ~> merge.in(3) source5 ~> merge.in(4) source6 ~> merge.in(5) - merge.out ~> Sink(probe) + merge.out ~> Sink.fromSubscriber(probe) ClosedShape }).run() @@ -151,15 +151,15 @@ class GraphMergeSpec extends TwoStreamsSetup { val up2 = TestPublisher.manualProbe[Int]() val down = TestSubscriber.manualProbe[Int]() - val src1 = Source.subscriber[Int] - val src2 = Source.subscriber[Int] + val src1 = Source.asSubscriber[Int] + val src2 = Source.asSubscriber[Int] val (graphSubscriber1, graphSubscriber2) = RunnableGraph.fromGraph(GraphDSL.create(src1, src2)((_, _)) { implicit b ⇒ (s1, s2) ⇒ val merge = b.add(Merge[Int](2)) s1.out ~> merge.in(0) s2.out ~> merge.in(1) - merge.out ~> Sink(down) + merge.out ~> Sink.fromSubscriber(down) ClosedShape }).run() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphOpsIntegrationSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphOpsIntegrationSpec.scala index ab46d81982..6367b2ae23 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphOpsIntegrationSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphOpsIntegrationSpec.scala @@ -155,11 +155,11 @@ class GraphOpsIntegrationSpec extends AkkaSpec with ConversionCheckedTripleEqual } "be able to run plain flow" in { - val p = Source(List(1, 2, 3)).runWith(Sink.publisher(false)) + val p = Source(List(1, 2, 3)).runWith(Sink.asPublisher(false)) val s = TestSubscriber.manualProbe[Int] val flow = Flow[Int].map(_ * 2) RunnableGraph.fromGraph(GraphDSL.create() { implicit builder ⇒ - Source(p) ~> flow ~> Sink(s) + Source.fromPublisher(p) ~> flow ~> Sink.fromSubscriber(s) ClosedShape }).run() val sub = s.expectSubscription() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphStageTimersSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphStageTimersSpec.scala index ed0b04c4d6..7172299bf1 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphStageTimersSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphStageTimersSpec.scala @@ -180,7 +180,7 @@ class GraphStageTimersSpec extends AkkaSpec { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).via(new TestStage2).runWith(Sink(downstream)) + Source.fromPublisher(upstream).via(new TestStage2).runWith(Sink.fromSubscriber(downstream)) downstream.request(5) downstream.expectNext(1) @@ -198,7 +198,7 @@ class GraphStageTimersSpec extends AkkaSpec { val upstream = TestPublisher.probe[Int]() val downstream = TestSubscriber.probe[Int]() - Source(upstream).via(new SimpleLinearGraphStage[Int] { + Source.fromPublisher(upstream).via(new SimpleLinearGraphStage[Int] { override def createLogic(inheritedAttributes: Attributes) = new TimerGraphStageLogic(shape) { override def preStart(): Unit = scheduleOnce("tick", 100.millis) @@ -212,7 +212,7 @@ class GraphStageTimersSpec extends AkkaSpec { override def onTimer(timerKey: Any) = throw exception } - }).runWith(Sink(downstream)) + }).runWith(Sink.fromSubscriber(downstream)) downstream.request(1) downstream.expectError(exception) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphUnzipSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphUnzipSpec.scala index bb7c6329b1..d438ddf37f 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphUnzipSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphUnzipSpec.scala @@ -26,8 +26,8 @@ class GraphUnzipSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val unzip = b.add(Unzip[Int, String]()) Source(List(1 -> "a", 2 -> "b", 3 -> "c")) ~> unzip.in - unzip.out1 ~> Flow[String].buffer(16, OverflowStrategy.backpressure) ~> Sink(c2) - unzip.out0 ~> Flow[Int].buffer(16, OverflowStrategy.backpressure).map(_ * 2) ~> Sink(c1) + unzip.out1 ~> Flow[String].buffer(16, OverflowStrategy.backpressure) ~> Sink.fromSubscriber(c2) + unzip.out0 ~> Flow[Int].buffer(16, OverflowStrategy.backpressure).map(_ * 2) ~> Sink.fromSubscriber(c1) ClosedShape }).run() @@ -56,8 +56,8 @@ class GraphUnzipSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val unzip = b.add(Unzip[Int, String]()) Source(List(1 -> "a", 2 -> "b", 3 -> "c")) ~> unzip.in - unzip.out0 ~> Sink(c1) - unzip.out1 ~> Sink(c2) + unzip.out0 ~> Sink.fromSubscriber(c1) + unzip.out1 ~> Sink.fromSubscriber(c2) ClosedShape }).run() @@ -78,8 +78,8 @@ class GraphUnzipSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val unzip = b.add(Unzip[Int, String]()) Source(List(1 -> "a", 2 -> "b", 3 -> "c")) ~> unzip.in - unzip.out0 ~> Sink(c1) - unzip.out1 ~> Sink(c2) + unzip.out0 ~> Sink.fromSubscriber(c1) + unzip.out1 ~> Sink.fromSubscriber(c2) ClosedShape }).run() @@ -100,9 +100,9 @@ class GraphUnzipSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val unzip = b.add(Unzip[Int, String]()) - Source(p1.getPublisher) ~> unzip.in - unzip.out0 ~> Sink(c1) - unzip.out1 ~> Sink(c2) + Source.fromPublisher(p1.getPublisher) ~> unzip.in + unzip.out0 ~> Sink.fromSubscriber(c1) + unzip.out1 ~> Sink.fromSubscriber(c2) ClosedShape }).run() @@ -131,7 +131,7 @@ class GraphUnzipSpec extends AkkaSpec { Source(List(1 -> "a", 2 -> "b", 3 -> "c")) ~> unzip.in unzip.out0 ~> zip.in0 unzip.out1 ~> zip.in1 - zip.out ~> Sink(c1) + zip.out ~> Sink.fromSubscriber(c1) ClosedShape }).run() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphUnzipWithSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphUnzipWithSpec.scala index 43d3715fe0..7a4a013626 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphUnzipWithSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphUnzipWithSpec.scala @@ -51,9 +51,9 @@ class GraphUnzipWithSpec extends AkkaSpec { RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ val f = fixture(b) - Source(p) ~> f.in - f.left ~> Sink(leftSubscriber) - f.right ~> Sink(rightSubscriber) + Source.fromPublisher(p) ~> f.in + f.left ~> Sink.fromSubscriber(leftSubscriber) + f.right ~> Sink.fromSubscriber(rightSubscriber) ClosedShape }).run() @@ -101,8 +101,8 @@ class GraphUnzipWithSpec extends AkkaSpec { val unzip = b.add(UnzipWith(f)) Source(1 to 4) ~> unzip.in - unzip.out0 ~> Flow[LeftOutput].buffer(4, OverflowStrategy.backpressure) ~> Sink(leftProbe) - unzip.out1 ~> Flow[RightOutput].buffer(4, OverflowStrategy.backpressure) ~> Sink(rightProbe) + unzip.out0 ~> Flow[LeftOutput].buffer(4, OverflowStrategy.backpressure) ~> Sink.fromSubscriber(leftProbe) + unzip.out1 ~> Flow[RightOutput].buffer(4, OverflowStrategy.backpressure) ~> Sink.fromSubscriber(rightProbe) ClosedShape }).run() @@ -152,8 +152,8 @@ class GraphUnzipWithSpec extends AkkaSpec { Source(-2 to 2) ~> unzip.in - unzip.out0 ~> Sink(leftProbe) - unzip.out1 ~> Sink(rightProbe) + unzip.out0 ~> Sink.fromSubscriber(leftProbe) + unzip.out1 ~> Sink.fromSubscriber(rightProbe) ClosedShape }).run() @@ -197,9 +197,9 @@ class GraphUnzipWithSpec extends AkkaSpec { Source.single(Person("Caplin", "Capybara", 3)) ~> unzip.in - unzip.out0 ~> Sink(probe0) - unzip.out1 ~> Sink(probe1) - unzip.out2 ~> Sink(probe2) + unzip.out0 ~> Sink.fromSubscriber(probe0) + unzip.out1 ~> Sink.fromSubscriber(probe1) + unzip.out2 ~> Sink.fromSubscriber(probe2) ClosedShape }).run() @@ -248,32 +248,32 @@ class GraphUnzipWithSpec extends AkkaSpec { Source.single((0 to 19).toList) ~> unzip.in def createSink[T](o: Outlet[T]) = - o ~> Flow[T].buffer(1, OverflowStrategy.backpressure) ~> Sink(TestSubscriber.manualProbe[T]()) + o ~> Flow[T].buffer(1, OverflowStrategy.backpressure) ~> Sink.fromSubscriber(TestSubscriber.manualProbe[T]()) - unzip.out0 ~> Sink(probe0) + unzip.out0 ~> Sink.fromSubscriber(probe0) createSink(unzip.out1) createSink(unzip.out2) createSink(unzip.out3) createSink(unzip.out4) - unzip.out5 ~> Sink(probe5) + unzip.out5 ~> Sink.fromSubscriber(probe5) createSink(unzip.out6) createSink(unzip.out7) createSink(unzip.out8) createSink(unzip.out9) - unzip.out10 ~> Sink(probe10) + unzip.out10 ~> Sink.fromSubscriber(probe10) createSink(unzip.out11) createSink(unzip.out12) createSink(unzip.out13) createSink(unzip.out14) - unzip.out15 ~> Sink(probe15) + unzip.out15 ~> Sink.fromSubscriber(probe15) createSink(unzip.out16) createSink(unzip.out17) createSink(unzip.out18) - unzip.out19 ~> Sink(probe19) + unzip.out19 ~> Sink.fromSubscriber(probe19) ClosedShape }).run() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipSpec.scala index 0d253b375f..e4987e386c 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipSpec.scala @@ -34,7 +34,7 @@ class GraphZipSpec extends TwoStreamsSetup { Source(1 to 4) ~> zip.in0 Source(List("A", "B", "C", "D", "E", "F")) ~> zip.in1 - zip.out ~> Sink(probe) + zip.out ~> Sink.fromSubscriber(probe) ClosedShape }).run() @@ -61,8 +61,8 @@ class GraphZipSpec extends TwoStreamsSetup { out ⇒ val zip = b.add(Zip[Int, String]()) - Source(upstream1) ~> zip.in0 - Source(upstream2) ~> zip.in1 + Source.fromPublisher(upstream1) ~> zip.in0 + Source.fromPublisher(upstream2) ~> zip.in1 zip.out ~> out ClosedShape @@ -83,12 +83,12 @@ class GraphZipSpec extends TwoStreamsSetup { val upstream2 = TestPublisher.probe[String]() val downstream = TestSubscriber.probe[(Int, String)]() - RunnableGraph.fromGraph(GraphDSL.create(Sink(downstream)) { implicit b ⇒ + RunnableGraph.fromGraph(GraphDSL.create(Sink.fromSubscriber(downstream)) { implicit b ⇒ out ⇒ val zip = b.add(Zip[Int, String]()) - Source(upstream1) ~> zip.in0 - Source(upstream2) ~> zip.in1 + Source.fromPublisher(upstream1) ~> zip.in0 + Source.fromPublisher(upstream2) ~> zip.in1 zip.out ~> out ClosedShape @@ -110,12 +110,12 @@ class GraphZipSpec extends TwoStreamsSetup { val upstream2 = TestPublisher.probe[String]() val downstream = TestSubscriber.probe[(Int, String)]() - RunnableGraph.fromGraph(GraphDSL.create(Sink(downstream)) { implicit b ⇒ + RunnableGraph.fromGraph(GraphDSL.create(Sink.fromSubscriber(downstream)) { implicit b ⇒ out ⇒ val zip = b.add(Zip[Int, String]()) - Source(upstream1) ~> zip.in0 - Source(upstream2) ~> zip.in1 + Source.fromPublisher(upstream1) ~> zip.in0 + Source.fromPublisher(upstream2) ~> zip.in1 zip.out ~> out ClosedShape @@ -139,12 +139,12 @@ class GraphZipSpec extends TwoStreamsSetup { val upstream2 = TestPublisher.probe[String]() val downstream = TestSubscriber.probe[(Int, String)]() - RunnableGraph.fromGraph(GraphDSL.create(Sink(downstream)) { implicit b ⇒ + RunnableGraph.fromGraph(GraphDSL.create(Sink.fromSubscriber(downstream)) { implicit b ⇒ out ⇒ val zip = b.add(Zip[Int, String]()) - Source(upstream1) ~> zip.in0 - Source(upstream2) ~> zip.in1 + Source.fromPublisher(upstream1) ~> zip.in0 + Source.fromPublisher(upstream2) ~> zip.in1 zip.out ~> out ClosedShape @@ -169,12 +169,12 @@ class GraphZipSpec extends TwoStreamsSetup { val upstream2 = TestPublisher.probe[String]() val downstream = TestSubscriber.probe[(Int, String)]() - RunnableGraph.fromGraph(GraphDSL.create(Sink(downstream)) { implicit b ⇒ + RunnableGraph.fromGraph(GraphDSL.create(Sink.fromSubscriber(downstream)) { implicit b ⇒ out ⇒ val zip = b.add(Zip[Int, String]()) - Source(upstream1) ~> zip.in0 - Source(upstream2) ~> zip.in1 + Source.fromPublisher(upstream1) ~> zip.in0 + Source.fromPublisher(upstream2) ~> zip.in1 zip.out ~> out ClosedShape diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipWithSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipWithSpec.scala index da7d6b8f61..af77a0f652 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipWithSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipWithSpec.scala @@ -26,7 +26,7 @@ class GraphZipWithSpec extends TwoStreamsSetup { Source(1 to 4) ~> zip.in0 Source(10 to 40 by 10) ~> zip.in1 - zip.out ~> Sink(probe) + zip.out ~> Sink.fromSubscriber(probe) ClosedShape }).run() @@ -54,7 +54,7 @@ class GraphZipWithSpec extends TwoStreamsSetup { Source(1 to 4) ~> zip.in0 Source(-2 to 2) ~> zip.in1 - zip.out ~> Sink(probe) + zip.out ~> Sink.fromSubscriber(probe) ClosedShape }).run() @@ -118,7 +118,7 @@ class GraphZipWithSpec extends TwoStreamsSetup { Source.single("Capybara") ~> zip.in1 Source.single(3) ~> zip.in2 - zip.out ~> Sink(probe) + zip.out ~> Sink.fromSubscriber(probe) ClosedShape }).run() @@ -164,7 +164,7 @@ class GraphZipWithSpec extends TwoStreamsSetup { Source.single(18).map(_.toString) ~> zip.in17 Source.single(19) ~> zip.in18 - zip.out ~> Sink(probe) + zip.out ~> Sink.fromSubscriber(probe) ClosedShape }).run() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/HeadSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/HeadSinkSpec.scala index cdc32b4d55..ce8dfc658c 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/HeadSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/HeadSinkSpec.scala @@ -25,7 +25,7 @@ class HeadSinkSpec extends AkkaSpec with ScriptedTest { "yield the first value" in assertAllStagesStopped { val p = TestPublisher.manualProbe[Int]() - val f: Future[Int] = Source(p).map(identity).runWith(Sink.head) + val f: Future[Int] = Source.fromPublisher(p).map(identity).runWith(Sink.head) val proc = p.expectSubscription() proc.expectRequest() proc.sendNext(42) @@ -36,7 +36,7 @@ class HeadSinkSpec extends AkkaSpec with ScriptedTest { "yield the first value when actively constructing" in { val p = TestPublisher.manualProbe[Int]() val f = Sink.head[Int] - val s = Source.subscriber[Int] + val s = Source.asSubscriber[Int] val (subscriber, future) = s.toMat(f)(Keep.both).run() p.subscribe(subscriber) @@ -65,7 +65,7 @@ class HeadSinkSpec extends AkkaSpec with ScriptedTest { "yield the first value" in assertAllStagesStopped { val p = TestPublisher.manualProbe[Int]() - val f: Future[Option[Int]] = Source(p).map(identity).runWith(Sink.headOption) + val f: Future[Option[Int]] = Source.fromPublisher(p).map(identity).runWith(Sink.headOption) val proc = p.expectSubscription() proc.expectRequest() proc.sendNext(42) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/One2OneBidiFlowSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/One2OneBidiFlowSpec.scala index 883a724ab0..a8f6b70769 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/One2OneBidiFlowSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/One2OneBidiFlowSpec.scala @@ -68,7 +68,7 @@ class One2OneBidiFlowSpec extends AkkaSpec with ConversionCheckedTripleEquals { Source(1 to 1000) .log("", seen.set) - .via(One2OneBidiFlow[Int, Int](MAX_PENDING) join Flow.fromSinkAndSourceMat(Sink.ignore, Source(out))(Keep.left)) + .via(One2OneBidiFlow[Int, Int](MAX_PENDING) join Flow.fromSinkAndSourceMat(Sink.ignore, Source.fromPublisher(out))(Keep.left)) .runWith(Sink.ignore) Thread.sleep(50) @@ -85,6 +85,6 @@ class One2OneBidiFlowSpec extends AkkaSpec with ConversionCheckedTripleEquals { val outIn = TestPublisher.probe[Int]() val outOut = TestSubscriber.probe[Int]() - Source(inIn).via(One2OneBidiFlow[Int, Int](maxPending) join Flow.fromSinkAndSourceMat(Sink(inOut), Source(outIn))(Keep.left)).runWith(Sink(outOut)) + Source.fromPublisher(inIn).via(One2OneBidiFlow[Int, Int](maxPending) join Flow.fromSinkAndSourceMat(Sink.fromSubscriber(inOut), Source.fromPublisher(outIn))(Keep.left)).runWith(Sink.fromSubscriber(outOut)) } } diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/PublisherSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/PublisherSinkSpec.scala index d413fd44b0..8404ba4948 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/PublisherSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/PublisherSinkSpec.scala @@ -19,7 +19,7 @@ class PublisherSinkSpec extends AkkaSpec { "be unique when created twice" in assertAllStagesStopped { - val (pub1, pub2) = RunnableGraph.fromGraph(GraphDSL.create(Sink.publisher[Int](false), Sink.publisher[Int](false))(Keep.both) { implicit b ⇒ + val (pub1, pub2) = RunnableGraph.fromGraph(GraphDSL.create(Sink.asPublisher[Int](false), Sink.asPublisher[Int](false))(Keep.both) { implicit b ⇒ (p1, p2) ⇒ import GraphDSL.Implicits._ @@ -31,8 +31,8 @@ class PublisherSinkSpec extends AkkaSpec { ClosedShape }).run() - val f1 = Source(pub1).map(identity).runFold(0)(_ + _) - val f2 = Source(pub2).map(identity).runFold(0)(_ + _) + val f1 = Source.fromPublisher(pub1).map(identity).runFold(0)(_ + _) + val f2 = Source.fromPublisher(pub2).map(identity).runFold(0)(_ + _) Await.result(f1, 3.seconds) should be(30) Await.result(f2, 3.seconds) should be(15) @@ -40,14 +40,14 @@ class PublisherSinkSpec extends AkkaSpec { } "work with SubscriberSource" in { - val (sub, pub) = Source.subscriber[Int].toMat(Sink.publisher(false))(Keep.both).run() - Source(1 to 100).to(Sink(sub)).run() - Await.result(Source(pub).grouped(1000).runWith(Sink.head), 3.seconds) should ===(1 to 100) + val (sub, pub) = Source.asSubscriber[Int].toMat(Sink.asPublisher(false))(Keep.both).run() + Source(1 to 100).to(Sink.fromSubscriber(sub)).run() + Await.result(Source.fromPublisher(pub).grouped(1000).runWith(Sink.head), 3.seconds) should ===(1 to 100) } "be able to use Publisher in materialized value transformation" in { val f = Source(1 to 3).runWith( - Sink.publisher[Int](false).mapMaterializedValue(p ⇒ Source(p).runFold(0)(_ + _))) + Sink.asPublisher[Int](false).mapMaterializedValue(p ⇒ Source.fromPublisher(p).runFold(0)(_ + _))) Await.result(f, 3.seconds) should be(6) } diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ReverseArrowSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ReverseArrowSpec.scala index c5ba42bcd8..15461a56e1 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ReverseArrowSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ReverseArrowSpec.scala @@ -34,7 +34,7 @@ class ReverseArrowSpec extends AkkaSpec with ConversionCheckedTripleEquals { "work from Sink" in { val sub = TestSubscriber.manualProbe[Int] RunnableGraph.fromGraph(GraphDSL.create() { implicit b ⇒ - Sink(sub) <~ source + Sink.fromSubscriber(sub) <~ source ClosedShape }).run() sub.expectSubscription().request(10) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkSpec.scala index ce9ff20af6..708c6ee431 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SinkSpec.scala @@ -19,7 +19,7 @@ class SinkSpec extends AkkaSpec { val probes = Array.fill(3)(TestSubscriber.manualProbe[Int]) val sink = Sink.fromGraph(GraphDSL.create() { implicit b ⇒ val bcast = b.add(Broadcast[Int](3)) - for (i ← 0 to 2) bcast.out(i).filter(_ == i) ~> Sink(probes(i)) + for (i ← 0 to 2) bcast.out(i).filter(_ == i) ~> Sink.fromSubscriber(probes(i)) SinkShape(bcast.in) }) Source(List(0, 1, 2)).runWith(sink) @@ -32,11 +32,11 @@ class SinkSpec extends AkkaSpec { "be composable with importing 1 module" in { val probes = Array.fill(3)(TestSubscriber.manualProbe[Int]) - val sink = Sink.fromGraph(GraphDSL.create(Sink(probes(0))) { implicit b ⇒ + val sink = Sink.fromGraph(GraphDSL.create(Sink.fromSubscriber(probes(0))) { implicit b ⇒ s0 ⇒ val bcast = b.add(Broadcast[Int](3)) bcast.out(0) ~> Flow[Int].filter(_ == 0) ~> s0.in - for (i ← 1 to 2) bcast.out(i).filter(_ == i) ~> Sink(probes(i)) + for (i ← 1 to 2) bcast.out(i).filter(_ == i) ~> Sink.fromSubscriber(probes(i)) SinkShape(bcast.in) }) Source(List(0, 1, 2)).runWith(sink) @@ -49,12 +49,12 @@ class SinkSpec extends AkkaSpec { "be composable with importing 2 modules" in { val probes = Array.fill(3)(TestSubscriber.manualProbe[Int]) - val sink = Sink.fromGraph(GraphDSL.create(Sink(probes(0)), Sink(probes(1)))(List(_, _)) { implicit b ⇒ + val sink = Sink.fromGraph(GraphDSL.create(Sink.fromSubscriber(probes(0)), Sink.fromSubscriber(probes(1)))(List(_, _)) { implicit b ⇒ (s0, s1) ⇒ val bcast = b.add(Broadcast[Int](3)) bcast.out(0).filter(_ == 0) ~> s0.in bcast.out(1).filter(_ == 1) ~> s1.in - bcast.out(2).filter(_ == 2) ~> Sink(probes(2)) + bcast.out(2).filter(_ == 2) ~> Sink.fromSubscriber(probes(2)) SinkShape(bcast.in) }) Source(List(0, 1, 2)).runWith(sink) @@ -67,7 +67,7 @@ class SinkSpec extends AkkaSpec { "be composable with importing 3 modules" in { val probes = Array.fill(3)(TestSubscriber.manualProbe[Int]) - val sink = Sink.fromGraph(GraphDSL.create(Sink(probes(0)), Sink(probes(1)), Sink(probes(2)))(List(_, _, _)) { implicit b ⇒ + val sink = Sink.fromGraph(GraphDSL.create(Sink.fromSubscriber(probes(0)), Sink.fromSubscriber(probes(1)), Sink.fromSubscriber(probes(2)))(List(_, _, _)) { implicit b ⇒ (s0, s1, s2) ⇒ val bcast = b.add(Broadcast[Int](3)) bcast.out(0).filter(_ == 0) ~> s0.in @@ -85,7 +85,7 @@ class SinkSpec extends AkkaSpec { "combine to many outputs with simplified API" in { val probes = Seq.fill(3)(TestSubscriber.manualProbe[Int]()) - val sink = Sink.combine(Sink(probes(0)), Sink(probes(1)), Sink(probes(2)))(Broadcast[Int](_)) + val sink = Sink.combine(Sink.fromSubscriber(probes(0)), Sink.fromSubscriber(probes(1)), Sink.fromSubscriber(probes(2)))(Broadcast[Int](_)) Source(List(0, 1, 2)).runWith(sink) @@ -103,7 +103,7 @@ class SinkSpec extends AkkaSpec { "combine to two sinks with simplified API" in { val probes = Seq.fill(2)(TestSubscriber.manualProbe[Int]()) - val sink = Sink.combine(Sink(probes(0)), Sink(probes(1)))(Broadcast[Int](_)) + val sink = Sink.combine(Sink.fromSubscriber(probes(0)), Sink.fromSubscriber(probes(1)))(Broadcast[Int](_)) Source(List(0, 1, 2)).runWith(sink) @@ -121,4 +121,4 @@ class SinkSpec extends AkkaSpec { } -} \ No newline at end of file +} diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceSpec.scala index 08f138727b..21a8bdac02 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceSpec.scala @@ -18,7 +18,7 @@ class SourceSpec extends AkkaSpec { "Single Source" must { "produce element" in { - val p = Source.single(1).runWith(Sink.publisher(false)) + val p = Source.single(1).runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[Int]() p.subscribe(c) val sub = c.expectSubscription() @@ -28,7 +28,7 @@ class SourceSpec extends AkkaSpec { } "reject later subscriber" in { - val p = Source.single(1).runWith(Sink.publisher(false)) + val p = Source.single(1).runWith(Sink.asPublisher(false)) val c1 = TestSubscriber.manualProbe[Int]() val c2 = TestSubscriber.manualProbe[Int]() p.subscribe(c1) @@ -46,7 +46,7 @@ class SourceSpec extends AkkaSpec { "Empty Source" must { "complete immediately" in { - val p = Source.empty.runWith(Sink.publisher(false)) + val p = Source.empty.runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[Int]() p.subscribe(c) c.expectSubscriptionAndComplete() @@ -61,7 +61,7 @@ class SourceSpec extends AkkaSpec { "Failed Source" must { "emit error immediately" in { val ex = new RuntimeException with NoStackTrace - val p = Source.failed(ex).runWith(Sink.publisher(false)) + val p = Source.failed(ex).runWith(Sink.asPublisher(false)) val c = TestSubscriber.manualProbe[Int]() p.subscribe(c) c.expectSubscriptionAndError(ex) @@ -76,7 +76,7 @@ class SourceSpec extends AkkaSpec { "Maybe Source" must { "complete materialized future with None when stream cancels" in Utils.assertAllStagesStopped { val neverSource = Source.maybe[Int] - val pubSink = Sink.publisher[Int](false) + val pubSink = Sink.asPublisher[Int](false) val (f, neverPub) = neverSource.toMat(pubSink)(Keep.both).run() @@ -134,7 +134,7 @@ class SourceSpec extends AkkaSpec { "Composite Source" must { "merge from many inputs" in { val probes = Seq.fill(5)(TestPublisher.manualProbe[Int]()) - val source = Source.subscriber[Int] + val source = Source.asSubscriber[Int] val out = TestSubscriber.manualProbe[Int] val s = Source.fromGraph(GraphDSL.create(source, source, source, source, source)(Seq(_, _, _, _, _)) { implicit b ⇒ @@ -147,7 +147,7 @@ class SourceSpec extends AkkaSpec { i3.out ~> m.in(3) i4.out ~> m.in(4) SourceShape(m.out) - }).to(Sink(out)).run() + }).to(Sink.fromSubscriber(out)).run() for (i ← 0 to 4) probes(i).subscribe(s(i)) val sub = out.expectSubscription() @@ -167,10 +167,10 @@ class SourceSpec extends AkkaSpec { "combine from many inputs with simplified API" in { val probes = Seq.fill(3)(TestPublisher.manualProbe[Int]()) - val source = for (i ← 0 to 2) yield Source(probes(i)) + val source = for (i ← 0 to 2) yield Source.fromPublisher(probes(i)) val out = TestSubscriber.manualProbe[Int] - Source.combine(source(0), source(1), source(2))(Merge(_)).to(Sink(out)).run() + Source.combine(source(0), source(1), source(2))(Merge(_)).to(Sink.fromSubscriber(out)).run() val sub = out.expectSubscription() sub.request(3) @@ -189,10 +189,10 @@ class SourceSpec extends AkkaSpec { "combine from two inputs with simplified API" in { val probes = Seq.fill(2)(TestPublisher.manualProbe[Int]()) - val source = Source(probes(0)) :: Source(probes(1)) :: Nil + val source = Source.fromPublisher(probes(0)) :: Source.fromPublisher(probes(1)) :: Nil val out = TestSubscriber.manualProbe[Int] - Source.combine(source(0), source(1))(Merge(_)).to(Sink(out)).run() + Source.combine(source(0), source(1))(Merge(_)).to(Sink.fromSubscriber(out)).run() val sub = out.expectSubscription() sub.request(3) @@ -252,7 +252,7 @@ class SourceSpec extends AkkaSpec { "Iterator Source" must { "properly iterate" in { - val result = Await.result(Source(() ⇒ Iterator.iterate(false)(!_)).grouped(10).runWith(Sink.head), 1.second) + val result = Await.result(Source.fromIterator(() ⇒ Iterator.iterate(false)(!_)).grouped(10).runWith(Sink.head), 1.second) result should ===(Seq(false, true, false, true, false, true, false, true, false, true)) } } diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSinkSpec.scala index be3d8939b3..e74fd1ac3c 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSinkSpec.scala @@ -19,7 +19,7 @@ class SubscriberSinkSpec extends AkkaSpec { "publish elements to the subscriber" in assertAllStagesStopped { val c = TestSubscriber.manualProbe[Int]() - Source(List(1, 2, 3)).to(Sink(c)).run() + Source(List(1, 2, 3)).to(Sink.fromSubscriber(c)).run() val s = c.expectSubscription() s.request(3) c.expectNext(1) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSourceSpec.scala index 4bed273a0d..d4b2f5880d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSourceSpec.scala @@ -19,7 +19,7 @@ class SubscriberSourceSpec extends AkkaSpec { "be able to use Subscriber in materialized value transformation" in { val f = - Source.subscriber[Int].mapMaterializedValue(s ⇒ Source(1 to 3).runWith(Sink(s))) + Source.asSubscriber[Int].mapMaterializedValue(s ⇒ Source(1 to 3).runWith(Sink.fromSubscriber(s))) .runWith(Sink.fold[Int, Int](0)(_ + _)) Await.result(f, 3.seconds) should be(6) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubstreamSubscriptionTimeoutSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubstreamSubscriptionTimeoutSpec.scala index 6771dbde22..54d36bb7b1 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubstreamSubscriptionTimeoutSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubstreamSubscriptionTimeoutSpec.scala @@ -42,7 +42,7 @@ class SubstreamSubscriptionTimeoutSpec(conf: String) extends AkkaSpec(conf) { "timeout and cancel substream publishers when no-one subscribes to them after some time (time them out)" in assertAllStagesStopped { val publisherProbe = TestPublisher.probe[Int]() - val publisher = Source(publisherProbe).groupBy(3, _ % 3).lift(_ % 3).runWith(Sink.publisher(false)) + val publisher = Source.fromPublisher(publisherProbe).groupBy(3, _ % 3).lift(_ % 3).runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[(Int, Source[Int, _])]() publisher.subscribe(subscriber) @@ -56,7 +56,7 @@ class SubstreamSubscriptionTimeoutSpec(conf: String) extends AkkaSpec(conf) { val (_, s1) = subscriber.expectNext() // should not break normal usage val s1SubscriberProbe = TestSubscriber.manualProbe[Int]() - s1.runWith(Sink.publisher(false)).subscribe(s1SubscriberProbe) + s1.runWith(Sink.asPublisher(false)).subscribe(s1SubscriberProbe) val s1Subscription = s1SubscriberProbe.expectSubscription() s1Subscription.request(100) s1SubscriberProbe.expectNext(1) @@ -64,7 +64,7 @@ class SubstreamSubscriptionTimeoutSpec(conf: String) extends AkkaSpec(conf) { val (_, s2) = subscriber.expectNext() // should not break normal usage val s2SubscriberProbe = TestSubscriber.manualProbe[Int]() - s2.runWith(Sink.publisher(false)).subscribe(s2SubscriberProbe) + s2.runWith(Sink.asPublisher(false)).subscribe(s2SubscriberProbe) val s2Subscription = s2SubscriberProbe.expectSubscription() s2Subscription.request(100) s2SubscriberProbe.expectNext(2) @@ -82,7 +82,7 @@ class SubstreamSubscriptionTimeoutSpec(conf: String) extends AkkaSpec(conf) { "timeout and stop groupBy parent actor if none of the substreams are actually consumed" in assertAllStagesStopped { val publisherProbe = TestPublisher.probe[Int]() - val publisher = Source(publisherProbe).groupBy(2, _ % 2).lift(_ % 2).runWith(Sink.publisher(false)) + val publisher = Source.fromPublisher(publisherProbe).groupBy(2, _ % 2).lift(_ % 2).runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[(Int, Source[Int, _])]() publisher.subscribe(subscriber) @@ -100,7 +100,7 @@ class SubstreamSubscriptionTimeoutSpec(conf: String) extends AkkaSpec(conf) { "not timeout and cancel substream publishers when they have been subscribed to" in { val publisherProbe = TestPublisher.probe[Int]() - val publisher = Source(publisherProbe).groupBy(2, _ % 2).lift(_ % 2).runWith(Sink.publisher(false)) + val publisher = Source.fromPublisher(publisherProbe).groupBy(2, _ % 2).lift(_ % 2).runWith(Sink.asPublisher(false)) val subscriber = TestSubscriber.manualProbe[(Int, Source[Int, _])]() publisher.subscribe(subscriber) @@ -113,7 +113,7 @@ class SubstreamSubscriptionTimeoutSpec(conf: String) extends AkkaSpec(conf) { val (_, s1) = subscriber.expectNext() // should not break normal usage val s1SubscriberProbe = TestSubscriber.manualProbe[Int]() - s1.runWith(Sink.publisher(false)).subscribe(s1SubscriberProbe) + s1.runWith(Sink.asPublisher(false)).subscribe(s1SubscriberProbe) val s1Sub = s1SubscriberProbe.expectSubscription() s1Sub.request(1) s1SubscriberProbe.expectNext(1) @@ -121,7 +121,7 @@ class SubstreamSubscriptionTimeoutSpec(conf: String) extends AkkaSpec(conf) { val (_, s2) = subscriber.expectNext() // should not break normal usage val s2SubscriberProbe = TestSubscriber.manualProbe[Int]() - s2.runWith(Sink.publisher(false)).subscribe(s2SubscriberProbe) + s2.runWith(Sink.asPublisher(false)).subscribe(s2SubscriberProbe) val s2Sub = s2SubscriberProbe.expectSubscription() // sleep long enough for timeout to trigger if not canceled diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/TickSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/TickSourceSpec.scala index be6329fd12..d241efa175 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl/TickSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/TickSourceSpec.scala @@ -18,7 +18,7 @@ class TickSourceSpec extends AkkaSpec { "A Flow based on tick publisher" must { "produce ticks" in assertAllStagesStopped { val c = TestSubscriber.manualProbe[String]() - Source.tick(1.second, 500.millis, "tick").to(Sink(c)).run() + Source.tick(1.second, 500.millis, "tick").to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(3) c.expectNoMsg(600.millis) @@ -33,7 +33,7 @@ class TickSourceSpec extends AkkaSpec { "drop ticks when not requested" in { val c = TestSubscriber.manualProbe[String]() - Source.tick(1.second, 1.second, "tick").to(Sink(c)).run() + Source.tick(1.second, 1.second, "tick").to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(2) c.expectNext("tick") @@ -49,7 +49,7 @@ class TickSourceSpec extends AkkaSpec { } "reject multiple subscribers, but keep the first" in { - val p = Source.tick(1.second, 1.second, "tick").runWith(Sink.publisher(false)) + val p = Source.tick(1.second, 1.second, "tick").runWith(Sink.asPublisher(false)) val c1 = TestSubscriber.manualProbe[String]() val c2 = TestSubscriber.manualProbe[String]() p.subscribe(c1) @@ -72,7 +72,7 @@ class TickSourceSpec extends AkkaSpec { val zip = b.add(Zip[Int, String]()) Source(1 to 100) ~> zip.in0 Source.tick(1.second, 1.second, "tick") ~> zip.in1 - zip.out ~> Flow[(Int, String)].map { case (n, _) ⇒ n } ~> Sink(c) + zip.out ~> Flow[(Int, String)].map { case (n, _) ⇒ n } ~> Sink.fromSubscriber(c) ClosedShape }).run() @@ -88,7 +88,7 @@ class TickSourceSpec extends AkkaSpec { "be possible to cancel" in assertAllStagesStopped { val c = TestSubscriber.manualProbe[String]() val tickSource = Source.tick(1.second, 500.millis, "tick") - val cancellable = tickSource.to(Sink(c)).run() + val cancellable = tickSource.to(Sink.fromSubscriber(c)).run() val sub = c.expectSubscription() sub.request(3) c.expectNoMsg(600.millis) diff --git a/akka-stream/src/main/scala/akka/stream/impl/GroupByProcessorImpl.scala b/akka-stream/src/main/scala/akka/stream/impl/GroupByProcessorImpl.scala index b7ed578f02..33f89c898c 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/GroupByProcessorImpl.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/GroupByProcessorImpl.scala @@ -72,7 +72,7 @@ private[akka] class GroupByProcessorImpl(settings: ActorMaterializerSettings, va if (keyToSubstreamOutput.size == maxSubstreams) throw new IllegalStateException(s"cannot open substream for key '$key': too many substreams open") val substreamOutput = createSubstreamOutput() - val substreamFlow = Source(substreamOutput) // substreamOutput is a Publisher + val substreamFlow = Source.fromPublisher(substreamOutput) primaryOutputs.enqueueOutputElement(substreamFlow) keyToSubstreamOutput(key) = substreamOutput nextPhase(dispatchToSubstream(elem, substreamOutput)) diff --git a/akka-stream/src/main/scala/akka/stream/impl/SplitWhereProcessorImpl.scala b/akka-stream/src/main/scala/akka/stream/impl/SplitWhereProcessorImpl.scala index 44c814956b..a9cc9bfb56 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/SplitWhereProcessorImpl.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/SplitWhereProcessorImpl.scala @@ -69,7 +69,7 @@ private[akka] class SplitWhereProcessorImpl(_settings: ActorMaterializerSettings private def openSubstream(andThen: SubstreamOutput ⇒ TransferPhase): TransferPhase = TransferPhase(primaryOutputs.NeedsDemand) { () ⇒ val substreamOutput = createSubstreamOutput() - val substreamFlow = Source(substreamOutput) // substreamOutput is a Publisher + val substreamFlow = Source.fromPublisher(substreamOutput) primaryOutputs.enqueueOutputElement(substreamFlow) currentSubstream = substreamOutput diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala b/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala index ff2ee432ad..a8709764d6 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala @@ -229,7 +229,7 @@ final class Flow[-In, +Out, +Mat](delegate: scaladsl.Flow[In, Out, Mat]) extends * Connect the `Source` to this `Flow` and then connect it to the `Sink` and run it. * * The returned tuple contains the materialized values of the `Source` and `Sink`, - * e.g. the `Subscriber` of a `Source.subscriber` and `Publisher` of a `Sink.publisher`. + * e.g. the `Subscriber` of a `Source.asSubscriber` and `Publisher` of a `Sink.asPublisher`. * * @tparam T materialized type of given Source * @tparam U materialized type of given Sink diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/Sink.scala b/akka-stream/src/main/scala/akka/stream/javadsl/Sink.scala index b190a514a8..0b3b72a018 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/Sink.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/Sink.scala @@ -33,8 +33,8 @@ object Sink { /** * Helper to create [[Sink]] from `Subscriber`. */ - def create[In](subs: Subscriber[In]): Sink[In, Unit] = - new Sink(scaladsl.Sink(subs)) + def fromSubscriber[In](subs: Subscriber[In]): Sink[In, Unit] = + new Sink(scaladsl.Sink.fromSubscriber(subs)) /** * A `Sink` that immediately cancels its upstream after materialization. @@ -59,8 +59,8 @@ object Sink { * If `fanout` is `false` then the materialized `Publisher` will only support a single `Subscriber` and * reject any additional `Subscriber`s. */ - def publisher[T](fanout: Boolean): Sink[T, Publisher[T]] = - new Sink(scaladsl.Sink.publisher(fanout)) + def asPublisher[T](fanout: Boolean): Sink[T, Publisher[T]] = + new Sink(scaladsl.Sink.asPublisher(fanout)) /** * A `Sink` that will invoke the given procedure for each received element. The sink is materialized diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala b/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala index 0e2ca2e000..c28ffdf5e6 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala @@ -56,8 +56,8 @@ object Source { * that mediate the flow of elements downstream and the propagation of * back-pressure upstream. */ - def from[O](publisher: Publisher[O]): javadsl.Source[O, Unit] = - new Source(scaladsl.Source.apply(publisher)) + def fromPublisher[O](publisher: Publisher[O]): javadsl.Source[O, Unit] = + new Source(scaladsl.Source.fromPublisher(publisher)) /** * Helper to create [[Source]] from `Iterator`. @@ -78,7 +78,7 @@ object Source { * steps. */ def fromIterator[O](f: function.Creator[java.util.Iterator[O]]): javadsl.Source[O, Unit] = - new Source(scaladsl.Source(() ⇒ f.create().asScala)) + new Source(scaladsl.Source.fromIterator(() ⇒ f.create().asScala)) /** * Helper to create [[Source]] from `Iterable`. @@ -145,8 +145,8 @@ object Source { * may happen before or after materializing the `Flow`. * The stream terminates with a failure if the `Future` is completed with a failure. */ - def from[O](future: Future[O]): javadsl.Source[O, Unit] = - new Source(scaladsl.Source(future)) + def fromFuture[O](future: Future[O]): javadsl.Source[O, Unit] = + new Source(scaladsl.Source.fromFuture(future)) /** * Elements are emitted periodically with the specified interval. @@ -200,8 +200,8 @@ object Source { /** * Creates a `Source` that is materialized as a [[org.reactivestreams.Subscriber]] */ - def subscriber[T](): Source[T, Subscriber[T]] = - new Source(scaladsl.Source.subscriber) + def asSubscriber[T](): Source[T, Subscriber[T]] = + new Source(scaladsl.Source.asSubscriber) /** * Creates a `Source` that is materialized to an [[akka.actor.ActorRef]] which points to an Actor @@ -469,7 +469,7 @@ final class Source[+Out, +Mat](delegate: scaladsl.Source[Out, Mat]) extends Grap /** * Connect this `Source` to a `Sink` and run it. The returned value is the materialized value - * of the `Sink`, e.g. the `Publisher` of a `Sink.publisher`. + * of the `Sink`, e.g. the `Publisher` of a `Sink.asPublisher`. */ def runWith[M](sink: Graph[SinkShape[Out], M], materializer: Materializer): M = delegate.runWith(sink)(materializer) diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala index e76e34c6d1..975129f056 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala @@ -228,7 +228,7 @@ final class Flow[-In, +Out, +Mat](private[stream] override val module: Module) * @return A [[RunnableGraph]] that materializes to a Processor when run() is called on it. */ def toProcessor: RunnableGraph[Processor[In @uncheckedVariance, Out @uncheckedVariance]] = - Source.subscriber[In].via(this).toMat(Sink.publisher[Out](false))(Keep.both[Subscriber[In], Publisher[Out]]) + Source.asSubscriber[In].via(this).toMat(Sink.asPublisher[Out](false))(Keep.both[Subscriber[In], Publisher[Out]]) .mapMaterializedValue { case (sub, pub) ⇒ new Processor[In, Out] { override def onError(t: Throwable): Unit = sub.onError(t) diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl/Sink.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/Sink.scala index 03e98123c3..eee4cfce87 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl/Sink.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/Sink.scala @@ -68,7 +68,7 @@ object Sink { /** * Helper to create [[Sink]] from `Subscriber`. */ - def apply[T](subscriber: Subscriber[T]): Sink[T, Unit] = + def fromSubscriber[T](subscriber: Subscriber[T]): Sink[T, Unit] = new Sink(new SubscriberSink(subscriber, DefaultAttributes.subscriberSink, shape("SubscriberSink"))) /** @@ -128,7 +128,7 @@ object Sink { * If `fanout` is `false` then the materialized `Publisher` will only support a single `Subscriber` and * reject any additional `Subscriber`s. */ - def publisher[T](fanout: Boolean): Sink[T, Publisher[T]] = + def asPublisher[T](fanout: Boolean): Sink[T, Publisher[T]] = new Sink( if (fanout) new FanoutPublisherSink[T](DefaultAttributes.fanoutPublisherSink, shape("FanoutPublisherSink")) else new PublisherSink[T](DefaultAttributes.publisherSink, shape("PublisherSink"))) diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala index dd3e17d1b1..7d4479dc93 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala @@ -154,12 +154,12 @@ object Source { * that mediate the flow of elements downstream and the propagation of * back-pressure upstream. */ - def apply[T](publisher: Publisher[T]): Source[T, Unit] = + def fromPublisher[T](publisher: Publisher[T]): Source[T, Unit] = new Source(new PublisherSource(publisher, DefaultAttributes.publisherSource, shape("PublisherSource"))) /** * Helper to create [[Source]] from `Iterator`. - * Example usage: `Source(() => Iterator.from(0))` + * Example usage: `Source.fromIterator(() => Iterator.from(0))` * * Start a new `Source` from the given function that produces anIterator. * The produced stream of elements will continue until the iterator runs empty @@ -167,7 +167,7 @@ object Source { * Elements are pulled out of the iterator in accordance with the demand coming * from the downstream transformation steps. */ - def apply[T](f: () ⇒ Iterator[T]): Source[T, Unit] = + def fromIterator[T](f: () ⇒ Iterator[T]): Source[T, Unit] = apply(new immutable.Iterable[T] { override def iterator: Iterator[T] = f() override def toString: String = "() => Iterator" @@ -201,7 +201,7 @@ object Source { * may happen before or after materializing the `Flow`. * The stream terminates with a failure if the `Future` is completed with a failure. */ - def apply[T](future: Future[T]): Source[T, Unit] = + def fromFuture[T](future: Future[T]): Source[T, Unit] = single(future).mapAsyncUnordered(1)(ConstantFun.scalaIdentityFunction).withAttributes(DefaultAttributes.futureSource) /** @@ -329,7 +329,7 @@ object Source { /** * Creates a `Source` that is materialized as a [[org.reactivestreams.Subscriber]] */ - def subscriber[T]: Source[T, Subscriber[T]] = + def asSubscriber[T]: Source[T, Subscriber[T]] = new Source(new SubscriberSource[T](DefaultAttributes.subscriberSource, shape("SubscriberSource"))) /**