From 7c0c6187913a1bf9d158097cf170ade74c6edcca Mon Sep 17 00:00:00 2001 From: Patrik Nordwall Date: Mon, 27 Oct 2014 14:35:41 +0100 Subject: [PATCH] !str #16039 Remove old scaladsl, rename scaladsl2 * and impl2, testkit2 * keeping io2 for now --- .../docs/http/HttpServerExampleSpec.scala | 11 +- .../akka/http/model/japi/HttpEntities.java | 2 +- .../java/akka/http/model/japi/HttpEntity.java | 2 +- .../http/model/japi/HttpEntityChunked.java | 2 +- .../model/japi/HttpEntityCloseDelimited.java | 2 +- .../http/model/japi/HttpEntityDefault.java | 2 +- .../japi/HttpEntityIndefiniteLength.java | 2 +- .../main/java/akka/http/model/japi/Util.java | 2 +- .../main/scala/akka/http/HttpManager.scala | 3 +- .../engine/client/HttpClientPipeline.scala | 4 +- .../http/engine/parsing/BodyPartParser.scala | 2 +- .../engine/parsing/HttpMessageParser.scala | 2 +- .../engine/parsing/HttpRequestParser.scala | 2 +- .../engine/parsing/HttpResponseParser.scala | 2 +- .../http/engine/parsing/ParserOutput.scala | 2 +- .../engine/rendering/BodyPartRenderer.scala | 2 +- .../HttpRequestRendererFactory.scala | 2 +- .../HttpResponseRendererFactory.scala | 2 +- .../http/engine/rendering/RenderSupport.scala | 4 +- .../engine/server/HttpServerPipeline.scala | 4 +- .../scala/akka/http/model/HttpEntity.scala | 4 +- .../scala/akka/http/model/HttpMessage.scala | 2 +- .../akka/http/model/MultipartContent.scala | 3 +- .../scala/akka/http/util/StreamUtils.scala | 3 +- .../main/scala/akka/http/util/package.scala | 3 +- .../akka/http/model/japi/JavaTestServer.java | 2 +- .../scala/akka/http/ClientServerSpec.scala | 3 +- .../src/test/scala/akka/http/TestClient.scala | 3 +- .../src/test/scala/akka/http/TestServer.scala | 3 +- .../engine/parsing/RequestParserSpec.scala | 4 +- .../engine/parsing/ResponseParserSpec.scala | 4 +- .../rendering/RequestRendererSpec.scala | 3 +- .../rendering/ResponseRendererSpec.scala | 3 +- .../server/HttpServerPipelineSpec.scala | 3 +- .../akka/http/model/HttpEntitySpec.scala | 3 +- .../http/HttpModelIntegrationSpec.scala | 4 +- .../scala/akka/http/testkit/RouteTest.scala | 2 +- .../testkit/RouteTestResultComponent.scala | 3 +- .../test/scala/akka/http/FormDataSpec.scala | 2 +- .../http/marshalling/MarshallingSpec.scala | 2 +- .../scala/akka/http/server/TestServer.scala | 2 +- .../directives/CodingDirectivesSpec.scala | 2 +- .../unmarshalling/UnmarshallingSpec.scala | 3 +- .../marshalling/MultipartMarshallers.scala | 3 +- .../akka/http/server/ScalaRoutingDSL.scala | 3 +- .../MultipartUnmarshallers.scala | 3 +- .../PredefinedFromEntityUnmarshallers.scala | 3 +- .../AkkaIdentityProcessorVerification.scala | 6 +- .../tck/AkkaPublisherVerification.scala | 2 +- .../tck/AkkaSubscriberVerification.scala | 6 +- .../akka/stream/tck/FanoutPublisherTest.scala | 4 +- .../stream/tck/IterablePublisherTest.scala | 4 +- .../stream/tck/IteratorPublisherTest.scala | 4 +- .../tck/SimpleCallbackPublisherTest.scala | 4 +- .../stream/tck/TransformProcessorTest.scala | 6 +- .../akka/stream/testkit/ChainSetup.scala | 31 +- .../akka/stream/testkit/ScriptedTest.scala | 22 +- .../testkit/StreamTestDefaultMailbox.scala | 23 +- .../TwoStreamsSetup.scala | 7 +- .../akka/stream/testkit2/ChainSetup.scala | 28 - .../akka/stream/testkit2/ScriptedTest.scala | 197 ----- .../akka/stream/actor/ActorPublisherTest.java | 2 +- .../stream/actor/ActorSubscriberTest.java | 2 +- .../java/akka/stream/javadsl/FlowTest.java | 250 +++---- .../stream/PersistentSourceSpec.scala | 12 +- .../akka/stream/DslConsistencySpec.scala | 10 +- .../stream/DslFactoriesConsistencySpec.scala | 16 +- .../src/test/scala/akka/stream/DuctSpec.scala | 218 ------ .../scala/akka/stream/FlowBroadcastSpec.scala | 83 --- .../scala/akka/stream/FlowBufferSpec.scala | 182 ----- .../scala/akka/stream/FlowCollectSpec.scala | 27 - .../scala/akka/stream/FlowConcatAllSpec.scala | 103 --- .../scala/akka/stream/FlowConcatSpec.scala | 108 --- .../scala/akka/stream/FlowConflateSpec.scala | 99 --- .../akka/stream/FlowDispatcherSpec.scala | 26 - .../test/scala/akka/stream/FlowDropSpec.scala | 42 -- .../akka/stream/FlowDropWithinSpec.scala | 41 -- .../scala/akka/stream/FlowExpandSpec.scala | 118 --- .../scala/akka/stream/FlowFilterSpec.scala | 46 -- .../test/scala/akka/stream/FlowFoldSpec.scala | 25 - .../scala/akka/stream/FlowForeachSpec.scala | 50 -- .../akka/stream/FlowFromFutureSpec.scala | 120 --- .../scala/akka/stream/FlowGroupBySpec.scala | 196 ----- .../scala/akka/stream/FlowGroupedSpec.scala | 32 - .../akka/stream/FlowGroupedWithinSpec.scala | 139 ---- .../scala/akka/stream/FlowIterableSpec.scala | 155 ---- .../scala/akka/stream/FlowIteratorSpec.scala | 138 ---- .../scala/akka/stream/FlowMapConcatSpec.scala | 29 - .../scala/akka/stream/FlowMapFutureSpec.scala | 113 --- .../test/scala/akka/stream/FlowMapSpec.scala | 44 -- .../scala/akka/stream/FlowMergeSpec.scala | 95 --- .../akka/stream/FlowOnCompleteSpec.scala | 82 --- .../akka/stream/FlowPrefixAndTailSpec.scala | 152 ---- .../stream/FlowProduceToSubscriberSpec.scala | 32 - .../src/test/scala/akka/stream/FlowSpec.scala | 335 --------- .../scala/akka/stream/FlowSplitWhenSpec.scala | 110 --- .../test/scala/akka/stream/FlowTakeSpec.scala | 45 -- .../akka/stream/FlowTakeWithinSpec.scala | 53 -- .../stream/FlowTimerTransformerSpec.scala | 85 --- .../scala/akka/stream/FlowToFutureSpec.scala | 60 -- .../stream/FlowTransformRecoverSpec.scala | 389 ---------- .../scala/akka/stream/FlowTransformSpec.scala | 402 ---------- .../test/scala/akka/stream/FlowZipSpec.scala | 75 -- .../stream/ImplicitFlowMaterializerSpec.scala | 43 -- .../scala/akka/stream/TickPublisherSpec.scala | 98 --- .../akka/stream/TimerTransformerSpec.scala | 132 ---- .../scala/akka/stream/TwoStreamsSetup.scala | 83 --- .../stream/actor/ActorPublisherSpec.scala | 16 +- .../stream/actor/ActorSubscriberSpec.scala | 6 +- .../akka/stream/extra/FlowTimedSpec.scala | 28 +- .../scala/akka/stream/io/SslTlsFlowSpec.scala | 17 +- .../scala/akka/stream/io/TcpFlowSpec.scala | 16 +- .../test/scala/akka/stream/io/TcpHelper.scala | 4 +- .../scala/akka/stream/io2/TcpFlowSpec.scala | 5 +- .../scala/akka/stream/io2/TcpHelper.scala | 10 +- .../FlowAppendSpec.scala | 3 +- .../FlowBufferSpec.scala | 10 +- .../FlowCollectSpec.scala | 8 +- .../FlowCompileSpec.scala | 8 +- .../FlowConcatAllSpec.scala | 8 +- .../FlowConflateSpec.scala | 7 +- .../FlowDispatcherSpec.scala | 3 +- .../FlowDropSpec.scala | 10 +- .../FlowDropWithinSpec.scala | 4 +- .../FlowExpandSpec.scala | 9 +- .../FlowFilterSpec.scala | 11 +- .../FlowFoldSpec.scala | 4 +- .../FlowForeachSpec.scala | 8 +- .../FlowFromFutureSpec.scala | 9 +- .../FlowGraphCompileSpec.scala | 3 +- .../FlowGraphInitSpec.scala | 11 +- .../FlowGroupBySpec.scala | 8 +- .../FlowGroupedSpec.scala | 7 +- .../FlowGroupedWithinSpec.scala | 10 +- .../FlowIterableSpec.scala | 9 +- .../FlowIteratorSpec.scala | 10 +- .../FlowMapAsyncSpec.scala | 10 +- .../FlowMapAsyncUnorderedSpec.scala | 17 +- .../FlowMapConcatSpec.scala | 4 +- .../{scaladsl2 => scaladsl}/FlowMapSpec.scala | 11 +- .../FlowOnCompleteSpec.scala | 15 +- .../FlowPrefixAndTailSpec.scala | 7 +- .../{scaladsl2 => scaladsl}/FlowSpec.scala | 27 +- .../FlowSplitWhenSpec.scala | 10 +- .../FlowTakeSpec.scala | 10 +- .../FlowTakeWithinSpec.scala | 4 +- .../FlowThunkSpec.scala | 4 +- .../FlowTimerTransformerSpec.scala | 9 +- .../FlowTransformRecoverSpec.scala | 16 +- .../FlowTransformSpec.scala | 12 +- .../FutureSinkSpec.scala | 15 +- .../GraphBalanceSpec.scala | 12 +- .../GraphBroadcastSpec.scala | 8 +- .../GraphConcatSpec.scala | 11 +- .../GraphFlexiMergeSpec.scala | 12 +- .../GraphFlowSpec.scala | 6 +- .../GraphMergeSpec.scala | 7 +- .../GraphOpsIntegrationSpec.scala | 17 +- .../GraphPreferredMergeSpec.scala | 8 +- .../GraphUnzipSpec.scala | 9 +- .../GraphZipSpec.scala | 6 +- .../ImplicitFlowMaterializerSpec.scala | 6 +- .../PublisherSinkSpec.scala | 4 +- .../{scaladsl2 => scaladsl}/SourceSpec.scala | 4 +- .../SubscriberSinkSpec.scala | 5 +- .../TickSourceSpec.scala | 6 +- .../TimerTransformerSpec.scala | 5 +- .../persistence/stream/PersistentSource.scala | 7 +- .../scala/akka/stream/FlattenStrategy.scala | 8 +- .../scala/akka/stream/FlowMaterializer.scala | 36 +- .../scala/akka/stream/extra/Implicits.scala | 20 +- .../main/scala/akka/stream/extra/Timed.scala | 20 +- .../impl/ActorBasedFlowMaterializer.scala | 291 +++++--- .../akka/stream/impl/ActorProcessor.scala | 27 +- .../akka/stream/impl/ActorPublisher.scala | 8 +- .../akka/stream/impl/ConcatAllImpl.scala | 14 +- .../main/scala/akka/stream/impl/Extract.scala | 20 +- .../akka/stream/{impl2 => impl}/FanIn.scala | 9 +- .../akka/stream/{impl2 => impl}/FanOut.scala | 16 +- .../{impl2 => impl}/FlexiMergeImpl.scala | 6 +- .../scala/akka/stream/impl/FlowImpl.scala | 335 --------- .../akka/stream/impl/FuturePublisher.scala | 12 +- .../stream/impl/GroupByProcessorImpl.scala | 10 +- .../akka/stream/impl/IterablePublisher.scala | 8 +- .../MapAsyncUnorderedProcessorImpl.scala | 8 +- .../akka/stream/impl/PrefixAndTailImpl.scala | 8 +- .../stream/impl/SplitWhenProcessorImpl.scala | 5 +- .../scala/akka/stream/impl/StaticFanins.scala | 60 -- .../akka/stream/impl/StaticFanouts.scala | 51 -- .../impl2/ActorBasedFlowMaterializer.scala | 330 --------- .../akka/stream/impl2/ConcatAllImpl.scala | 34 - .../stream/impl2/GroupByProcessorImpl.scala | 74 -- .../akka/stream/impl2/PrefixAndTailImpl.scala | 60 -- .../stream/impl2/SplitWhenProcessorImpl.scala | 62 -- .../scala/akka/stream/io2/StreamTcp.scala | 6 +- .../akka/stream/io2/TcpConnectionStream.scala | 5 +- .../stream/io2/TcpListenStreamActor.scala | 8 +- .../akka/stream/javadsl/FlattenStrategy.scala | 5 +- .../main/scala/akka/stream/javadsl/Flow.scala | 27 +- .../scala/akka/stream/javadsl/FlowGraph.scala | 164 +++-- .../akka/stream/javadsl/MaterializedMap.scala | 10 +- .../main/scala/akka/stream/javadsl/Sink.scala | 44 +- .../scala/akka/stream/javadsl/Source.scala | 49 +- .../ActorFlowSink.scala | 31 +- .../ActorFlowSource.scala | 26 +- .../scala/akka/stream/scaladsl/Duct.scala | 370 ---------- .../{scaladsl2 => scaladsl}/FlexiMerge.scala | 8 +- .../scala/akka/stream/scaladsl/Flow.scala | 686 ++++++++++-------- .../{scaladsl2 => scaladsl}/FlowGraph.scala | 44 +- .../{scaladsl2 => scaladsl}/GraphFlow.scala | 34 +- .../scaladsl/ImplicitFlowMaterializer.scala | 2 +- .../JavaConverters.scala | 26 +- .../MaterializedMap.scala | 2 +- .../stream/{scaladsl2 => scaladsl}/Pipe.scala | 10 +- .../stream/{scaladsl2 => scaladsl}/Sink.scala | 3 +- .../{scaladsl2 => scaladsl}/Source.scala | 4 +- .../{scaladsl2 => scaladsl}/package.scala | 2 +- .../stream/scaladsl2/FlattenStrategy.scala | 19 - .../scala/akka/stream/scaladsl2/Flow.scala | 486 ------------- .../stream/scaladsl2/FlowMaterializer.scala | 156 ---- .../scaladsl2/ImplicitFlowMaterializer.scala | 25 - 221 files changed, 1540 insertions(+), 7985 deletions(-) rename akka-stream-testkit/src/test/scala/akka/stream/{testkit2 => testkit}/TwoStreamsSetup.scala (96%) delete mode 100644 akka-stream-testkit/src/test/scala/akka/stream/testkit2/ChainSetup.scala delete mode 100644 akka-stream-testkit/src/test/scala/akka/stream/testkit2/ScriptedTest.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/DuctSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowBroadcastSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowBufferSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowCollectSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowConcatAllSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowConcatSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowConflateSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowDispatcherSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowDropSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowDropWithinSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowExpandSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowFilterSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowFoldSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowForeachSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowFromFutureSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowGroupBySpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowGroupedSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowGroupedWithinSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowIterableSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowIteratorSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowMapConcatSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowMapFutureSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowMapSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowMergeSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowOnCompleteSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowPrefixAndTailSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowProduceToSubscriberSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowSplitWhenSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowTakeSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowTakeWithinSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowTimerTransformerSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowToFutureSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowTransformRecoverSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowTransformSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/FlowZipSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/ImplicitFlowMaterializerSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/TickPublisherSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/TimerTransformerSpec.scala delete mode 100644 akka-stream-tests/src/test/scala/akka/stream/TwoStreamsSetup.scala rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowAppendSpec.scala (96%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowBufferSpec.scala (99%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowCollectSpec.scala (90%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowCompileSpec.scala (98%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowConcatAllSpec.scala (97%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowConflateSpec.scala (97%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowDispatcherSpec.scala (91%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowDropSpec.scala (91%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowDropWithinSpec.scala (95%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowExpandSpec.scala (98%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowFilterSpec.scala (92%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowFoldSpec.scala (92%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowForeachSpec.scala (91%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowFromFutureSpec.scala (98%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowGraphCompileSpec.scala (99%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowGraphInitSpec.scala (93%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowGroupBySpec.scala (99%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowGroupedSpec.scala (93%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowGroupedWithinSpec.scala (97%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowIterableSpec.scala (98%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowIteratorSpec.scala (98%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowMapAsyncSpec.scala (98%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowMapAsyncUnorderedSpec.scala (97%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowMapConcatSpec.scala (91%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowMapSpec.scala (91%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowOnCompleteSpec.scala (94%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowPrefixAndTailSpec.scala (98%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowSpec.scala (98%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowSplitWhenSpec.scala (97%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowTakeSpec.scala (92%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowTakeWithinSpec.scala (96%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowThunkSpec.scala (96%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowTimerTransformerSpec.scala (97%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowTransformRecoverSpec.scala (99%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FlowTransformSpec.scala (99%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/FutureSinkSpec.scala (93%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/GraphBalanceSpec.scala (98%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/GraphBroadcastSpec.scala (98%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/GraphConcatSpec.scala (96%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/GraphFlexiMergeSpec.scala (99%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/GraphFlowSpec.scala (98%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/GraphMergeSpec.scala (96%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/GraphOpsIntegrationSpec.scala (97%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/GraphPreferredMergeSpec.scala (91%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/GraphUnzipSpec.scala (97%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/GraphZipSpec.scala (95%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/ImplicitFlowMaterializerSpec.scala (93%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/PublisherSinkSpec.scala (92%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/SourceSpec.scala (96%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/SubscriberSinkSpec.scala (92%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/TickSourceSpec.scala (98%) rename akka-stream-tests/src/test/scala/akka/stream/{scaladsl2 => scaladsl}/TimerTransformerSpec.scala (99%) rename akka-stream/src/main/scala/akka/stream/{impl2 => impl}/FanIn.scala (98%) rename akka-stream/src/main/scala/akka/stream/{impl2 => impl}/FanOut.scala (96%) rename akka-stream/src/main/scala/akka/stream/{impl2 => impl}/FlexiMergeImpl.scala (96%) delete mode 100644 akka-stream/src/main/scala/akka/stream/impl/FlowImpl.scala rename akka-stream/src/main/scala/akka/stream/{impl2 => impl}/MapAsyncUnorderedProcessorImpl.scala (91%) delete mode 100644 akka-stream/src/main/scala/akka/stream/impl/StaticFanins.scala delete mode 100644 akka-stream/src/main/scala/akka/stream/impl/StaticFanouts.scala delete mode 100644 akka-stream/src/main/scala/akka/stream/impl2/ActorBasedFlowMaterializer.scala delete mode 100644 akka-stream/src/main/scala/akka/stream/impl2/ConcatAllImpl.scala delete mode 100644 akka-stream/src/main/scala/akka/stream/impl2/GroupByProcessorImpl.scala delete mode 100644 akka-stream/src/main/scala/akka/stream/impl2/PrefixAndTailImpl.scala delete mode 100644 akka-stream/src/main/scala/akka/stream/impl2/SplitWhenProcessorImpl.scala rename akka-stream/src/main/scala/akka/stream/{scaladsl2 => scaladsl}/ActorFlowSink.scala (88%) rename akka-stream/src/main/scala/akka/stream/{scaladsl2 => scaladsl}/ActorFlowSource.scala (88%) delete mode 100644 akka-stream/src/main/scala/akka/stream/scaladsl/Duct.scala rename akka-stream/src/main/scala/akka/stream/{scaladsl2 => scaladsl}/FlexiMerge.scala (97%) rename akka-stream/src/main/scala/akka/stream/{scaladsl2 => scaladsl}/FlowGraph.scala (97%) rename akka-stream/src/main/scala/akka/stream/{scaladsl2 => scaladsl}/GraphFlow.scala (63%) rename akka-stream/src/main/scala/akka/stream/{scaladsl2 => scaladsl}/JavaConverters.scala (69%) rename akka-stream/src/main/scala/akka/stream/{scaladsl2 => scaladsl}/MaterializedMap.scala (95%) rename akka-stream/src/main/scala/akka/stream/{scaladsl2 => scaladsl}/Pipe.scala (92%) rename akka-stream/src/main/scala/akka/stream/{scaladsl2 => scaladsl}/Sink.scala (98%) rename akka-stream/src/main/scala/akka/stream/{scaladsl2 => scaladsl}/Source.scala (99%) rename akka-stream/src/main/scala/akka/stream/{scaladsl2 => scaladsl}/package.scala (99%) delete mode 100644 akka-stream/src/main/scala/akka/stream/scaladsl2/FlattenStrategy.scala delete mode 100644 akka-stream/src/main/scala/akka/stream/scaladsl2/Flow.scala delete mode 100644 akka-stream/src/main/scala/akka/stream/scaladsl2/FlowMaterializer.scala delete mode 100644 akka-stream/src/main/scala/akka/stream/scaladsl2/ImplicitFlowMaterializer.scala diff --git a/akka-docs-dev/rst/scala/code/docs/http/HttpServerExampleSpec.scala b/akka-docs-dev/rst/scala/code/docs/http/HttpServerExampleSpec.scala index 07b0e16ff8..5678fcbc82 100644 --- a/akka-docs-dev/rst/scala/code/docs/http/HttpServerExampleSpec.scala +++ b/akka-docs-dev/rst/scala/code/docs/http/HttpServerExampleSpec.scala @@ -21,7 +21,7 @@ class HttpServerExampleSpec import akka.io.IO import akka.pattern.ask import akka.stream.FlowMaterializer - import akka.stream.scaladsl.Flow + import akka.stream.scaladsl.Source implicit val system = ActorSystem() import system.dispatcher @@ -31,7 +31,7 @@ class HttpServerExampleSpec val bindingFuture = IO(Http) ? Http.Bind(interface = "localhost", port = 8080) bindingFuture foreach { case Http.ServerBinding(localAddress, connectionStream) ⇒ - Flow(connectionStream).foreach({ + Source(connectionStream).foreach({ case Http.IncomingConnection(remoteAddress, requestProducer, responseConsumer) ⇒ println("Accepted new connection from " + remoteAddress) @@ -45,7 +45,8 @@ class HttpServerExampleSpec import akka.io.IO import akka.pattern.ask import akka.stream.FlowMaterializer - import akka.stream.scaladsl.Flow + import akka.stream.scaladsl.Source + import akka.stream.scaladsl.Sink implicit val system = ActorSystem() import system.dispatcher @@ -71,11 +72,11 @@ class HttpServerExampleSpec // ... bindingFuture foreach { case Http.ServerBinding(localAddress, connectionStream) ⇒ - Flow(connectionStream).foreach({ + Source(connectionStream).foreach({ case Http.IncomingConnection(remoteAddress, requestProducer, responseConsumer) ⇒ println("Accepted new connection from " + remoteAddress) - Flow(requestProducer).map(requestHandler).produceTo(responseConsumer) + Source(requestProducer).map(requestHandler).connect(Sink(responseConsumer)).run() }) } //#full-server-example diff --git a/akka-http-core/src/main/java/akka/http/model/japi/HttpEntities.java b/akka-http-core/src/main/java/akka/http/model/japi/HttpEntities.java index 58a5e196cc..6b801503f6 100644 --- a/akka-http-core/src/main/java/akka/http/model/japi/HttpEntities.java +++ b/akka-http-core/src/main/java/akka/http/model/japi/HttpEntities.java @@ -7,7 +7,7 @@ package akka.http.model.japi; import java.io.File; import akka.util.ByteString; -import akka.stream.scaladsl2.Source; +import akka.stream.scaladsl.Source; import akka.http.model.HttpEntity$; /** Constructors for HttpEntity instances */ diff --git a/akka-http-core/src/main/java/akka/http/model/japi/HttpEntity.java b/akka-http-core/src/main/java/akka/http/model/japi/HttpEntity.java index 6d8f25cc8c..470bddd930 100644 --- a/akka-http-core/src/main/java/akka/http/model/japi/HttpEntity.java +++ b/akka-http-core/src/main/java/akka/http/model/japi/HttpEntity.java @@ -5,7 +5,7 @@ package akka.http.model.japi; import akka.http.model.HttpEntity$; -import akka.stream.scaladsl2.Source; +import akka.stream.scaladsl.Source; import akka.util.ByteString; /** diff --git a/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityChunked.java b/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityChunked.java index f0243499a8..b06cdab407 100644 --- a/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityChunked.java +++ b/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityChunked.java @@ -4,7 +4,7 @@ package akka.http.model.japi; -import akka.stream.scaladsl2.Source; +import akka.stream.scaladsl.Source; /** * Represents an entity transferred using `Transfer-Encoding: chunked`. It consists of a diff --git a/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityCloseDelimited.java b/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityCloseDelimited.java index 6127f263fa..12232121f1 100644 --- a/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityCloseDelimited.java +++ b/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityCloseDelimited.java @@ -5,7 +5,7 @@ package akka.http.model.japi; import akka.util.ByteString; -import akka.stream.scaladsl2.Source; +import akka.stream.scaladsl.Source; /** * Represents an entity without a predetermined content-length. Its length is implicitly diff --git a/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityDefault.java b/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityDefault.java index 47b7df52b5..7f74d4acd1 100644 --- a/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityDefault.java +++ b/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityDefault.java @@ -5,7 +5,7 @@ package akka.http.model.japi; import akka.util.ByteString; -import akka.stream.scaladsl2.Source; +import akka.stream.scaladsl.Source; /** * The default entity type which has a predetermined length and a stream of data bytes. diff --git a/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityIndefiniteLength.java b/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityIndefiniteLength.java index f79c3e8d55..fe6093253c 100644 --- a/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityIndefiniteLength.java +++ b/akka-http-core/src/main/java/akka/http/model/japi/HttpEntityIndefiniteLength.java @@ -5,7 +5,7 @@ package akka.http.model.japi; import akka.util.ByteString; -import akka.stream.scaladsl2.Source; +import akka.stream.scaladsl.Source; /** * Represents an entity without a predetermined content-length to use in a BodyParts. diff --git a/akka-http-core/src/main/java/akka/http/model/japi/Util.java b/akka-http-core/src/main/java/akka/http/model/japi/Util.java index 332d958cc7..15267b723a 100644 --- a/akka-http-core/src/main/java/akka/http/model/japi/Util.java +++ b/akka-http-core/src/main/java/akka/http/model/japi/Util.java @@ -9,7 +9,7 @@ import akka.japi.Option; import scala.None$; import scala.collection.immutable.Map$; import scala.collection.immutable.Seq; -import akka.stream.scaladsl2.Source; +import akka.stream.scaladsl.Source; import java.util.Arrays; import java.util.Map; diff --git a/akka-http-core/src/main/scala/akka/http/HttpManager.scala b/akka-http-core/src/main/scala/akka/http/HttpManager.scala index 0b57ac2254..f741bdbe5f 100644 --- a/akka-http-core/src/main/scala/akka/http/HttpManager.scala +++ b/akka-http-core/src/main/scala/akka/http/HttpManager.scala @@ -11,7 +11,8 @@ import akka.http.engine.client._ import akka.http.engine.server.{ HttpServerPipeline, ServerSettings } import akka.io.IO import akka.pattern.ask -import akka.stream.scaladsl2.{ Sink, Source, FlowMaterializer } +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.{ Sink, Source } import akka.stream.io.StreamTcp import akka.util.Timeout diff --git a/akka-http-core/src/main/scala/akka/http/engine/client/HttpClientPipeline.scala b/akka-http-core/src/main/scala/akka/http/engine/client/HttpClientPipeline.scala index 807c0f06cb..8c3a9145e1 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/client/HttpClientPipeline.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/client/HttpClientPipeline.scala @@ -8,8 +8,10 @@ import java.net.InetSocketAddress import akka.util.ByteString import scala.collection.immutable.Queue -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ import akka.event.LoggingAdapter +import akka.stream.FlowMaterializer +import akka.stream.FlattenStrategy import akka.stream.io.StreamTcp import akka.http.Http import akka.http.model.{ HttpMethod, HttpRequest, ErrorInfo, HttpResponse } diff --git a/akka-http-core/src/main/scala/akka/http/engine/parsing/BodyPartParser.scala b/akka-http-core/src/main/scala/akka/http/engine/parsing/BodyPartParser.scala index 8ed31ffa0b..df2a355a67 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/parsing/BodyPartParser.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/parsing/BodyPartParser.scala @@ -9,7 +9,7 @@ import scala.collection.mutable.ListBuffer import akka.event.LoggingAdapter import akka.parboiled2.CharPredicate import akka.stream.Transformer -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Source import akka.util.ByteString import akka.http.model._ import akka.http.util._ diff --git a/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpMessageParser.scala b/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpMessageParser.scala index a05c5f3aa1..7f8bbf271a 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpMessageParser.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpMessageParser.scala @@ -10,7 +10,7 @@ import scala.collection.immutable import akka.parboiled2.CharUtils import akka.util.ByteString import akka.stream.Transformer -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Source import akka.http.model.parser.CharacterClasses import akka.http.model._ import headers._ diff --git a/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpRequestParser.scala b/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpRequestParser.scala index 530fc47993..582bc49dd3 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpRequestParser.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpRequestParser.scala @@ -7,7 +7,7 @@ package akka.http.engine.parsing import java.lang.{ StringBuilder ⇒ JStringBuilder } import scala.annotation.tailrec import akka.http.model.parser.CharacterClasses -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Source import akka.util.ByteString import akka.http.model._ import headers._ diff --git a/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpResponseParser.scala b/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpResponseParser.scala index 8b4f4e38af..09ba3a58ee 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpResponseParser.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpResponseParser.scala @@ -6,7 +6,7 @@ package akka.http.engine.parsing import scala.annotation.tailrec import akka.http.model.parser.CharacterClasses -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Source import akka.util.ByteString import akka.http.model._ import headers._ diff --git a/akka-http-core/src/main/scala/akka/http/engine/parsing/ParserOutput.scala b/akka-http-core/src/main/scala/akka/http/engine/parsing/ParserOutput.scala index c4e756c21c..aeec8b25c4 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/parsing/ParserOutput.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/parsing/ParserOutput.scala @@ -6,7 +6,7 @@ package akka.http.engine.parsing import akka.http.model._ import akka.util.ByteString -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Source /** * INTERNAL API diff --git a/akka-http-core/src/main/scala/akka/http/engine/rendering/BodyPartRenderer.scala b/akka-http-core/src/main/scala/akka/http/engine/rendering/BodyPartRenderer.scala index 4fea05fe39..a6cf660013 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/rendering/BodyPartRenderer.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/rendering/BodyPartRenderer.scala @@ -11,7 +11,7 @@ import akka.http.model._ import akka.http.model.headers._ import akka.http.engine.rendering.RenderSupport._ import akka.http.util._ -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Source import akka.stream.Transformer import akka.util.ByteString import HttpEntity._ diff --git a/akka-http-core/src/main/scala/akka/http/engine/rendering/HttpRequestRendererFactory.scala b/akka-http-core/src/main/scala/akka/http/engine/rendering/HttpRequestRendererFactory.scala index 36eb789802..759b3eab91 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/rendering/HttpRequestRendererFactory.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/rendering/HttpRequestRendererFactory.scala @@ -8,7 +8,7 @@ import java.net.InetSocketAddress import scala.annotation.tailrec import akka.event.LoggingAdapter import akka.util.ByteString -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Source import akka.stream.Transformer import akka.http.model._ import akka.http.util._ diff --git a/akka-http-core/src/main/scala/akka/http/engine/rendering/HttpResponseRendererFactory.scala b/akka-http-core/src/main/scala/akka/http/engine/rendering/HttpResponseRendererFactory.scala index 215a53d430..608e8d4073 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/rendering/HttpResponseRendererFactory.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/rendering/HttpResponseRendererFactory.scala @@ -7,7 +7,7 @@ package akka.http.engine.rendering import scala.annotation.tailrec import akka.event.LoggingAdapter import akka.util.ByteString -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Source import akka.stream.Transformer import akka.http.model._ import akka.http.util._ diff --git a/akka-http-core/src/main/scala/akka/http/engine/rendering/RenderSupport.scala b/akka-http-core/src/main/scala/akka/http/engine/rendering/RenderSupport.scala index ef54fa28ee..05f01f2980 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/rendering/RenderSupport.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/rendering/RenderSupport.scala @@ -5,10 +5,10 @@ package akka.http.engine.rendering import akka.parboiled2.CharUtils -import akka.stream.impl2.ActorBasedFlowMaterializer +import akka.stream.impl.ActorBasedFlowMaterializer import akka.util.ByteString import akka.event.LoggingAdapter -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ import akka.stream.Transformer import akka.http.model._ import akka.http.util._ diff --git a/akka-http-core/src/main/scala/akka/http/engine/server/HttpServerPipeline.scala b/akka-http-core/src/main/scala/akka/http/engine/server/HttpServerPipeline.scala index 83149b0255..bb9f99f52c 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/server/HttpServerPipeline.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/server/HttpServerPipeline.scala @@ -6,8 +6,10 @@ package akka.http.engine.server import akka.event.LoggingAdapter import akka.stream.io.StreamTcp +import akka.stream.FlattenStrategy +import akka.stream.FlowMaterializer import akka.stream.Transformer -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ import akka.http.engine.parsing.HttpRequestParser import akka.http.engine.rendering.{ ResponseRenderingContext, HttpResponseRendererFactory } import akka.http.model.{ StatusCode, ErrorInfo, HttpRequest, HttpResponse, HttpMethods } diff --git a/akka-http-core/src/main/scala/akka/http/model/HttpEntity.scala b/akka-http-core/src/main/scala/akka/http/model/HttpEntity.scala index c6b5dc6229..f6bfe07d25 100644 --- a/akka-http-core/src/main/scala/akka/http/model/HttpEntity.scala +++ b/akka-http-core/src/main/scala/akka/http/model/HttpEntity.scala @@ -11,8 +11,8 @@ import scala.concurrent.{ Future, ExecutionContext } import scala.concurrent.duration.FiniteDuration import scala.collection.immutable import akka.util.ByteString -import akka.stream.{ TimerTransformer, Transformer } -import akka.stream.scaladsl2._ +import akka.stream.{ FlowMaterializer, TimerTransformer, Transformer } +import akka.stream.scaladsl._ import akka.stream.impl.{ EmptyPublisher, SynchronousPublisherFromIterable } import akka.http.util._ import japi.JavaMapping.Implicits._ diff --git a/akka-http-core/src/main/scala/akka/http/model/HttpMessage.scala b/akka-http-core/src/main/scala/akka/http/model/HttpMessage.scala index 3ef117024e..190eb612e0 100644 --- a/akka-http-core/src/main/scala/akka/http/model/HttpMessage.scala +++ b/akka-http-core/src/main/scala/akka/http/model/HttpMessage.scala @@ -9,7 +9,7 @@ import scala.concurrent.duration.FiniteDuration import scala.concurrent.{ Future, ExecutionContext } import scala.collection.immutable import scala.reflect.{ classTag, ClassTag } -import akka.stream.scaladsl2.FlowMaterializer +import akka.stream.FlowMaterializer import akka.util.ByteString import akka.http.util._ import headers._ diff --git a/akka-http-core/src/main/scala/akka/http/model/MultipartContent.scala b/akka-http-core/src/main/scala/akka/http/model/MultipartContent.scala index 5977988185..3b8e1a4f6b 100644 --- a/akka-http-core/src/main/scala/akka/http/model/MultipartContent.scala +++ b/akka-http-core/src/main/scala/akka/http/model/MultipartContent.scala @@ -7,7 +7,8 @@ package akka.http.model import java.io.File import scala.concurrent.{ Future, ExecutionContext } import scala.collection.immutable -import akka.stream.scaladsl2.{ FlowMaterializer, Sink, Source } +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.{ Sink, Source } import akka.stream.impl.SynchronousPublisherFromIterable import akka.http.util.FastFuture import FastFuture._ diff --git a/akka-http-core/src/main/scala/akka/http/util/StreamUtils.scala b/akka-http-core/src/main/scala/akka/http/util/StreamUtils.scala index 46c459c536..d9a8cbba18 100644 --- a/akka-http-core/src/main/scala/akka/http/util/StreamUtils.scala +++ b/akka-http-core/src/main/scala/akka/http/util/StreamUtils.scala @@ -7,7 +7,8 @@ package akka.http.util import akka.http.model.RequestEntity import akka.stream.impl.ErrorPublisher import akka.stream.Transformer -import akka.stream.scaladsl2.{ Source, FlowMaterializer } +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.Source import akka.util.ByteString import org.reactivestreams.Publisher diff --git a/akka-http-core/src/main/scala/akka/http/util/package.scala b/akka-http-core/src/main/scala/akka/http/util/package.scala index 8d3884dcde..82e52c7070 100644 --- a/akka-http-core/src/main/scala/akka/http/util/package.scala +++ b/akka-http-core/src/main/scala/akka/http/util/package.scala @@ -8,7 +8,8 @@ import language.implicitConversions import language.higherKinds import java.nio.charset.Charset import com.typesafe.config.Config -import akka.stream.scaladsl2.{ Flow, Source, FlattenStrategy } +import akka.stream.FlattenStrategy +import akka.stream.scaladsl.{ Flow, Source } import scala.util.matching.Regex import akka.event.LoggingAdapter import akka.util.ByteString diff --git a/akka-http-core/src/test/java/akka/http/model/japi/JavaTestServer.java b/akka-http-core/src/test/java/akka/http/model/japi/JavaTestServer.java index f4a7b117cc..7a24c95d5b 100644 --- a/akka-http-core/src/test/java/akka/http/model/japi/JavaTestServer.java +++ b/akka-http-core/src/test/java/akka/http/model/japi/JavaTestServer.java @@ -11,7 +11,7 @@ import akka.actor.ActorSystem; import akka.dispatch.Foreach; import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; -import akka.stream.scaladsl2.FlowMaterializer; +import akka.stream.FlowMaterializer; import scala.concurrent.Future; import java.io.BufferedReader; diff --git a/akka-http-core/src/test/scala/akka/http/ClientServerSpec.scala b/akka-http-core/src/test/scala/akka/http/ClientServerSpec.scala index a9c08b1464..4f91ad896e 100644 --- a/akka-http-core/src/test/scala/akka/http/ClientServerSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/ClientServerSpec.scala @@ -15,10 +15,11 @@ import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpec } import akka.actor.{ Status, ActorSystem } import akka.io.IO import akka.testkit.TestProbe +import akka.stream.FlowMaterializer import akka.stream.impl.SynchronousPublisherFromIterable import akka.stream.testkit.StreamTestKit import akka.stream.testkit.StreamTestKit.{ PublisherProbe, SubscriberProbe } -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ import akka.http.engine.client.ClientConnectionSettings import akka.http.engine.server.ServerSettings import akka.http.model._ diff --git a/akka-http-core/src/test/scala/akka/http/TestClient.scala b/akka-http-core/src/test/scala/akka/http/TestClient.scala index 1ce610bd97..44150d4fc2 100644 --- a/akka-http-core/src/test/scala/akka/http/TestClient.scala +++ b/akka-http-core/src/test/scala/akka/http/TestClient.scala @@ -12,7 +12,8 @@ import scala.util.{ Failure, Success } import akka.actor.ActorSystem import akka.pattern.ask import akka.util.Timeout -import akka.stream.scaladsl2.{ FlowMaterializer, Sink, Source } +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.{ Sink, Source } import akka.io.IO import akka.http.model.HttpMethods._ import akka.http.model._ diff --git a/akka-http-core/src/test/scala/akka/http/TestServer.scala b/akka-http-core/src/test/scala/akka/http/TestServer.scala index 44cda92e5a..da15eaa9f2 100644 --- a/akka-http-core/src/test/scala/akka/http/TestServer.scala +++ b/akka-http-core/src/test/scala/akka/http/TestServer.scala @@ -6,7 +6,8 @@ package akka.http import com.typesafe.config.{ ConfigFactory, Config } import scala.concurrent.duration._ -import akka.stream.scaladsl2.{ Sink, Source, FlowMaterializer } +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.{ Sink, Source } import akka.io.IO import akka.util.Timeout import akka.actor.ActorSystem diff --git a/akka-http-core/src/test/scala/akka/http/engine/parsing/RequestParserSpec.scala b/akka-http-core/src/test/scala/akka/http/engine/parsing/RequestParserSpec.scala index 3a81af9f8f..e010153160 100644 --- a/akka-http-core/src/test/scala/akka/http/engine/parsing/RequestParserSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/engine/parsing/RequestParserSpec.scala @@ -9,7 +9,9 @@ import scala.concurrent.{ Future, Await } import scala.concurrent.duration._ import org.scalatest.{ BeforeAndAfterAll, FreeSpec, Matchers } import org.scalatest.matchers.Matcher -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ +import akka.stream.FlattenStrategy +import akka.stream.FlowMaterializer import akka.util.ByteString import akka.actor.ActorSystem import akka.http.util._ diff --git a/akka-http-core/src/test/scala/akka/http/engine/parsing/ResponseParserSpec.scala b/akka-http-core/src/test/scala/akka/http/engine/parsing/ResponseParserSpec.scala index a0ecb5dbdf..05d66318e8 100644 --- a/akka-http-core/src/test/scala/akka/http/engine/parsing/ResponseParserSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/engine/parsing/ResponseParserSpec.scala @@ -9,7 +9,9 @@ import scala.concurrent.{ Future, Await } import scala.concurrent.duration._ import org.scalatest.{ BeforeAndAfterAll, FreeSpec, Matchers } import org.scalatest.matchers.Matcher -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ +import akka.stream.FlattenStrategy +import akka.stream.FlowMaterializer import akka.util.ByteString import akka.actor.ActorSystem import akka.http.util._ diff --git a/akka-http-core/src/test/scala/akka/http/engine/rendering/RequestRendererSpec.scala b/akka-http-core/src/test/scala/akka/http/engine/rendering/RequestRendererSpec.scala index ba153c725e..e4f0714ea2 100644 --- a/akka-http-core/src/test/scala/akka/http/engine/rendering/RequestRendererSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/engine/rendering/RequestRendererSpec.scala @@ -15,7 +15,8 @@ import akka.event.NoLogging import akka.http.model._ import akka.http.model.headers._ import akka.http.util._ -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ +import akka.stream.FlowMaterializer import akka.stream.impl.SynchronousPublisherFromIterable import HttpEntity._ import HttpMethods._ diff --git a/akka-http-core/src/test/scala/akka/http/engine/rendering/ResponseRendererSpec.scala b/akka-http-core/src/test/scala/akka/http/engine/rendering/ResponseRendererSpec.scala index 27bfc788e4..3915bcb42e 100644 --- a/akka-http-core/src/test/scala/akka/http/engine/rendering/ResponseRendererSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/engine/rendering/ResponseRendererSpec.scala @@ -15,7 +15,8 @@ import akka.http.model._ import akka.http.model.headers._ import akka.http.util._ import akka.util.ByteString -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ +import akka.stream.FlowMaterializer import akka.stream.impl.SynchronousPublisherFromIterable import HttpEntity._ diff --git a/akka-http-core/src/test/scala/akka/http/engine/server/HttpServerPipelineSpec.scala b/akka-http-core/src/test/scala/akka/http/engine/server/HttpServerPipelineSpec.scala index 02c5d198a8..8183ed3b7c 100644 --- a/akka-http-core/src/test/scala/akka/http/engine/server/HttpServerPipelineSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/engine/server/HttpServerPipelineSpec.scala @@ -11,7 +11,8 @@ import akka.http.model._ import akka.http.model.headers.{ ProductVersion, Server, Host } import akka.http.util._ import akka.http.Http -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ +import akka.stream.FlowMaterializer import akka.stream.io.StreamTcp import akka.stream.testkit.{ AkkaSpec, StreamTestKit } import akka.util.ByteString diff --git a/akka-http-core/src/test/scala/akka/http/model/HttpEntitySpec.scala b/akka-http-core/src/test/scala/akka/http/model/HttpEntitySpec.scala index d1de8fa71d..9e39d2efee 100644 --- a/akka-http-core/src/test/scala/akka/http/model/HttpEntitySpec.scala +++ b/akka-http-core/src/test/scala/akka/http/model/HttpEntitySpec.scala @@ -14,7 +14,8 @@ import org.scalatest.{ BeforeAndAfterAll, MustMatchers, FreeSpec } import org.scalatest.matchers.Matcher import akka.util.ByteString import akka.actor.ActorSystem -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ +import akka.stream.FlowMaterializer import akka.stream.Transformer import akka.http.model.HttpEntity._ diff --git a/akka-http-core/src/test/scala/io/akka/integrationtest/http/HttpModelIntegrationSpec.scala b/akka-http-core/src/test/scala/io/akka/integrationtest/http/HttpModelIntegrationSpec.scala index 0fbeb900b3..400021445f 100644 --- a/akka-http-core/src/test/scala/io/akka/integrationtest/http/HttpModelIntegrationSpec.scala +++ b/akka-http-core/src/test/scala/io/akka/integrationtest/http/HttpModelIntegrationSpec.scala @@ -12,8 +12,9 @@ import akka.util.ByteString import akka.actor.ActorSystem import akka.http.model.parser.HeaderParser import akka.http.model._ -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ import headers._ +import akka.stream.FlowMaterializer /** * Integration test for external HTTP libraries that are built on top of @@ -43,7 +44,6 @@ class HttpModelIntegrationSpec extends WordSpec with Matchers with BeforeAndAfte override def afterAll() = system.shutdown() implicit val materializer = FlowMaterializer() - implicit val materializer1 = akka.stream.FlowMaterializer() // Needed by HttpEntity.toStrict "External HTTP libraries" should { diff --git a/akka-http-testkit/src/main/scala/akka/http/testkit/RouteTest.scala b/akka-http-testkit/src/main/scala/akka/http/testkit/RouteTest.scala index 9c565bc1fa..a1da02ef6e 100644 --- a/akka-http-testkit/src/main/scala/akka/http/testkit/RouteTest.scala +++ b/akka-http-testkit/src/main/scala/akka/http/testkit/RouteTest.scala @@ -12,7 +12,7 @@ import scala.util.DynamicVariable import scala.reflect.ClassTag import org.scalatest.Suite import akka.actor.ActorSystem -import akka.stream.scaladsl2.FlowMaterializer +import akka.stream.FlowMaterializer import akka.http.client.RequestBuilding import akka.http.util.FastFuture import akka.http.server._ diff --git a/akka-http-testkit/src/main/scala/akka/http/testkit/RouteTestResultComponent.scala b/akka-http-testkit/src/main/scala/akka/http/testkit/RouteTestResultComponent.scala index 5ca76d8e13..93ec823ba6 100644 --- a/akka-http-testkit/src/main/scala/akka/http/testkit/RouteTestResultComponent.scala +++ b/akka-http-testkit/src/main/scala/akka/http/testkit/RouteTestResultComponent.scala @@ -8,7 +8,8 @@ import java.util.concurrent.CountDownLatch import scala.collection.immutable import scala.concurrent.duration._ import scala.concurrent.{ Await, ExecutionContext } -import akka.stream.scaladsl2._ +import akka.stream.FlowMaterializer +import akka.stream.scaladsl._ import akka.http.model.HttpEntity.ChunkStreamPart import akka.http.server._ import akka.http.model._ diff --git a/akka-http-tests/src/test/scala/akka/http/FormDataSpec.scala b/akka-http-tests/src/test/scala/akka/http/FormDataSpec.scala index 62957d1e9e..81b2efb471 100644 --- a/akka-http-tests/src/test/scala/akka/http/FormDataSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/FormDataSpec.scala @@ -8,7 +8,7 @@ import scala.concurrent.duration._ import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpec } import org.scalatest.concurrent.ScalaFutures import akka.actor.ActorSystem -import akka.stream.scaladsl2.FlowMaterializer +import akka.stream.FlowMaterializer import akka.http.unmarshalling.Unmarshal import akka.http.marshalling.Marshal import akka.http.model._ diff --git a/akka-http-tests/src/test/scala/akka/http/marshalling/MarshallingSpec.scala b/akka-http-tests/src/test/scala/akka/http/marshalling/MarshallingSpec.scala index cd663aec54..98d838c343 100644 --- a/akka-http-tests/src/test/scala/akka/http/marshalling/MarshallingSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/marshalling/MarshallingSpec.scala @@ -9,7 +9,7 @@ import scala.concurrent.Await import scala.concurrent.duration._ import org.scalatest.{ BeforeAndAfterAll, FreeSpec, Matchers } import akka.actor.ActorSystem -import akka.stream.scaladsl2.FlowMaterializer +import akka.stream.FlowMaterializer import akka.http.util._ import akka.http.model._ import headers._ diff --git a/akka-http-tests/src/test/scala/akka/http/server/TestServer.scala b/akka-http-tests/src/test/scala/akka/http/server/TestServer.scala index 4fbac9bf17..3538dd3200 100644 --- a/akka-http-tests/src/test/scala/akka/http/server/TestServer.scala +++ b/akka-http-tests/src/test/scala/akka/http/server/TestServer.scala @@ -8,7 +8,7 @@ import com.typesafe.config.{ ConfigFactory, Config } import scala.concurrent.duration._ import akka.actor.ActorSystem import akka.io.IO -import akka.stream.scaladsl2.FlowMaterializer +import akka.stream.FlowMaterializer import akka.util.Timeout import akka.pattern.ask import akka.http.Http diff --git a/akka-http-tests/src/test/scala/akka/http/server/directives/CodingDirectivesSpec.scala b/akka-http-tests/src/test/scala/akka/http/server/directives/CodingDirectivesSpec.scala index 28ef16f172..2f6576ec30 100644 --- a/akka-http-tests/src/test/scala/akka/http/server/directives/CodingDirectivesSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/server/directives/CodingDirectivesSpec.scala @@ -9,7 +9,7 @@ import org.scalatest.Tag import org.scalatest.matchers.Matcher import akka.util.ByteString -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Source import akka.http.util._ diff --git a/akka-http-tests/src/test/scala/akka/http/unmarshalling/UnmarshallingSpec.scala b/akka-http-tests/src/test/scala/akka/http/unmarshalling/UnmarshallingSpec.scala index 3d349723d6..df07ae9cb6 100644 --- a/akka-http-tests/src/test/scala/akka/http/unmarshalling/UnmarshallingSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/unmarshalling/UnmarshallingSpec.scala @@ -10,7 +10,8 @@ import scala.concurrent.{ Future, Await } import org.scalatest.matchers.Matcher import org.scalatest.{ BeforeAndAfterAll, FreeSpec, Matchers } import akka.actor.ActorSystem -import akka.stream.scaladsl2._ +import akka.stream.FlowMaterializer +import akka.stream.scaladsl._ import akka.http.model._ import akka.http.util._ import headers._ diff --git a/akka-http/src/main/scala/akka/http/marshalling/MultipartMarshallers.scala b/akka-http/src/main/scala/akka/http/marshalling/MultipartMarshallers.scala index 9be6266ea7..53bc3e1174 100644 --- a/akka-http/src/main/scala/akka/http/marshalling/MultipartMarshallers.scala +++ b/akka-http/src/main/scala/akka/http/marshalling/MultipartMarshallers.scala @@ -8,7 +8,8 @@ import scala.concurrent.ExecutionContext import scala.concurrent.forkjoin.ThreadLocalRandom import akka.actor.ActorRefFactory import akka.parboiled2.util.Base64 -import akka.stream.scaladsl2._ +import akka.stream.FlattenStrategy +import akka.stream.scaladsl._ import akka.http.engine.rendering.BodyPartRenderer import akka.http.util.actorSystem import akka.http.util.FastFuture._ diff --git a/akka-http/src/main/scala/akka/http/server/ScalaRoutingDSL.scala b/akka-http/src/main/scala/akka/http/server/ScalaRoutingDSL.scala index ab31474805..5f63dfac63 100644 --- a/akka-http/src/main/scala/akka/http/server/ScalaRoutingDSL.scala +++ b/akka-http/src/main/scala/akka/http/server/ScalaRoutingDSL.scala @@ -5,7 +5,8 @@ package akka.http.server import scala.concurrent.{ ExecutionContext, Future } -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ +import akka.stream.FlowMaterializer import akka.http.util.FastFuture import akka.http.model.{ HttpRequest, HttpResponse } import akka.http.Http diff --git a/akka-http/src/main/scala/akka/http/unmarshalling/MultipartUnmarshallers.scala b/akka-http/src/main/scala/akka/http/unmarshalling/MultipartUnmarshallers.scala index f4b6943630..51bb68b7d7 100644 --- a/akka-http/src/main/scala/akka/http/unmarshalling/MultipartUnmarshallers.scala +++ b/akka-http/src/main/scala/akka/http/unmarshalling/MultipartUnmarshallers.scala @@ -5,7 +5,8 @@ package akka.http.unmarshalling import akka.actor.ActorRefFactory -import akka.stream.scaladsl2._ +import akka.stream.FlowMaterializer +import akka.stream.scaladsl._ import akka.http.engine.parsing.BodyPartParser import akka.http.model._ import akka.http.util._ diff --git a/akka-http/src/main/scala/akka/http/unmarshalling/PredefinedFromEntityUnmarshallers.scala b/akka-http/src/main/scala/akka/http/unmarshalling/PredefinedFromEntityUnmarshallers.scala index 30a47b9d35..c7502c24a4 100644 --- a/akka-http/src/main/scala/akka/http/unmarshalling/PredefinedFromEntityUnmarshallers.scala +++ b/akka-http/src/main/scala/akka/http/unmarshalling/PredefinedFromEntityUnmarshallers.scala @@ -7,7 +7,8 @@ package akka.http.unmarshalling import java.io.{ ByteArrayInputStream, InputStreamReader } import scala.concurrent.ExecutionContext import scala.xml.{ XML, NodeSeq } -import akka.stream.scaladsl2._ +import akka.stream.FlowMaterializer +import akka.stream.scaladsl._ import akka.util.ByteString import akka.http.util.FastFuture import akka.http.model._ diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/AkkaIdentityProcessorVerification.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/AkkaIdentityProcessorVerification.scala index 2e903fec63..c7e942e068 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/AkkaIdentityProcessorVerification.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/AkkaIdentityProcessorVerification.scala @@ -5,9 +5,9 @@ package akka.stream.tck import scala.collection.immutable import akka.actor.ActorSystem -import akka.stream.scaladsl2.FlowMaterializer -import akka.stream.scaladsl2.Sink -import akka.stream.scaladsl2.Source +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit import akka.testkit.EventFilter diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/AkkaPublisherVerification.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/AkkaPublisherVerification.scala index 35575ae11f..4c0a11b528 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/AkkaPublisherVerification.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/AkkaPublisherVerification.scala @@ -7,7 +7,7 @@ import scala.concurrent.duration._ import akka.actor.ActorSystem import akka.stream.MaterializerSettings -import akka.stream.scaladsl2.FlowMaterializer +import akka.stream.FlowMaterializer import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit import org.reactivestreams.Publisher diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/AkkaSubscriberVerification.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/AkkaSubscriberVerification.scala index cda58e13a4..88f824ead7 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/AkkaSubscriberVerification.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/AkkaSubscriberVerification.scala @@ -7,9 +7,9 @@ import scala.collection.immutable import scala.concurrent.duration._ import akka.actor.ActorSystem import akka.stream.MaterializerSettings -import akka.stream.scaladsl2.FlowMaterializer -import akka.stream.scaladsl2.Sink -import akka.stream.scaladsl2.Source +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source import akka.stream.testkit.AkkaSpec import org.reactivestreams.Publisher import org.reactivestreams.tck.SubscriberBlackboxVerification 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 af3ff862d1..f142ef6192 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 @@ -4,8 +4,8 @@ package akka.stream.tck import scala.collection.immutable -import akka.stream.scaladsl2.Sink -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source import org.reactivestreams.Publisher class FanoutPublisherTest extends AkkaPublisherVerification[Int] { 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 71101dd2d8..7d39ee4549 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 @@ -4,8 +4,8 @@ package akka.stream.tck import scala.collection.immutable -import akka.stream.scaladsl2.Sink -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source import org.reactivestreams._ class IterablePublisherTest extends AkkaPublisherVerification[Int] { diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/IteratorPublisherTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/IteratorPublisherTest.scala index 184c060c59..1d47443dfc 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/IteratorPublisherTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/IteratorPublisherTest.scala @@ -4,8 +4,8 @@ package akka.stream.tck import scala.collection.immutable -import akka.stream.scaladsl2.Sink -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source import org.reactivestreams.Publisher class IteratorPublisherTest extends AkkaPublisherVerification[Int](true) { diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/SimpleCallbackPublisherTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/SimpleCallbackPublisherTest.scala index 4b854373b7..5e6066e468 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/SimpleCallbackPublisherTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/SimpleCallbackPublisherTest.scala @@ -3,8 +3,8 @@ */ package akka.stream.tck -import akka.stream.scaladsl2.Sink -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source import org.reactivestreams._ class SimpleCallbackPublisherTest extends AkkaPublisherVerification[Int] { diff --git a/akka-stream-tck/src/test/scala/akka/stream/tck/TransformProcessorTest.scala b/akka-stream-tck/src/test/scala/akka/stream/tck/TransformProcessorTest.scala index bba51007cb..391a82eaa2 100644 --- a/akka-stream-tck/src/test/scala/akka/stream/tck/TransformProcessorTest.scala +++ b/akka-stream-tck/src/test/scala/akka/stream/tck/TransformProcessorTest.scala @@ -5,9 +5,9 @@ package akka.stream.tck import akka.stream.MaterializerSettings import akka.stream.Transformer -import akka.stream.impl2.ActorBasedFlowMaterializer -import akka.stream.impl2.Ast -import akka.stream.scaladsl2.FlowMaterializer +import akka.stream.impl.ActorBasedFlowMaterializer +import akka.stream.impl.Ast +import akka.stream.FlowMaterializer import java.util.concurrent.atomic.AtomicInteger import org.reactivestreams.Processor import org.reactivestreams.Publisher 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 a53af89f38..660aabd86c 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 @@ -1,18 +1,27 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ package akka.stream.testkit -import akka.stream.{ MaterializerSettings, FlowMaterializer } -import akka.actor.ActorSystem -import akka.stream.scaladsl.Flow +import akka.actor.{ ActorRefFactory, ActorSystem } +import akka.stream.MaterializerSettings +import akka.stream.scaladsl._ +import org.reactivestreams.Publisher +import akka.stream.FlowMaterializer -class ChainSetup[I, O](stream: Flow[I] ⇒ Flow[O], val settings: MaterializerSettings)(implicit val system: ActorSystem) { - val upstream = StreamTestKit.PublisherProbe[I]() - val downstream = StreamTestKit.SubscriberProbe[O]() +class ChainSetup[In, Out]( + stream: Flow[In, In] ⇒ Flow[In, Out], + val settings: MaterializerSettings, + materializer: FlowMaterializer, + toPublisher: (Source[Out], FlowMaterializer) ⇒ Publisher[Out])(implicit val system: ActorSystem) { - private val s = stream(Flow(upstream)) - val publisher = s.toPublisher()(FlowMaterializer(settings)) + def this(stream: Flow[In, In] ⇒ Flow[In, Out], settings: MaterializerSettings, toPublisher: (Source[Out], FlowMaterializer) ⇒ Publisher[Out])(implicit system: ActorSystem) = + this(stream, settings, FlowMaterializer(settings)(system), toPublisher)(system) + + def this(stream: Flow[In, In] ⇒ Flow[In, Out], settings: MaterializerSettings, materializerCreator: (MaterializerSettings, ActorRefFactory) ⇒ FlowMaterializer, toPublisher: (Source[Out], FlowMaterializer) ⇒ Publisher[Out])(implicit system: ActorSystem) = + this(stream, settings, materializerCreator(settings, system), toPublisher)(system) + + val upstream = StreamTestKit.PublisherProbe[In]() + val downstream = StreamTestKit.SubscriberProbe[Out]() + private val s = Source(upstream).connect(stream(Flow[In])) + val publisher = toPublisher(s, materializer) val upstreamSubscription = upstream.expectSubscription() publisher.subscribe(downstream) val downstreamSubscription = downstream.expectSubscription() 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 8c1c0bbe1d..7ca842da18 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 @@ -5,18 +5,22 @@ package akka.stream.testkit import akka.actor.ActorSystem import akka.stream.MaterializerSettings -import akka.stream.scaladsl.Flow +import akka.stream.scaladsl.{ Sink, Source, Flow } import akka.stream.testkit.StreamTestKit._ +import org.reactivestreams.Publisher import org.scalatest.Matchers - import scala.annotation.tailrec import scala.concurrent.duration._ import scala.concurrent.forkjoin.ThreadLocalRandom +import akka.stream.FlowMaterializer trait ScriptedTest extends Matchers { class ScriptException(msg: String) extends RuntimeException(msg) + def toPublisher[In, Out]: (Source[Out], FlowMaterializer) ⇒ Publisher[Out] = + (f, m) ⇒ f.runWith(Sink.publisher)(m) + object Script { def apply[In, Out](phases: (Seq[In], Seq[Out])*): Script[In, Out] = { var providedInputs = Vector[In]() @@ -77,23 +81,23 @@ trait ScriptedTest extends Matchers { } class ScriptRunner[In, Out]( - op: Flow[In] ⇒ Flow[Out], + op: Flow[In, In] ⇒ Flow[In, Out], settings: MaterializerSettings, script: Script[In, Out], maximumOverrun: Int, maximumRequest: Int, maximumBuffer: Int)(implicit _system: ActorSystem) - extends ChainSetup(op, settings) { + extends ChainSetup(op, settings, toPublisher) { var _debugLog = Vector.empty[String] var currentScript = script var remainingDemand = script.expectedOutputs.size + ThreadLocalRandom.current().nextInt(1, maximumOverrun) debugLog(s"starting with remainingDemand=$remainingDemand") - var pendingRequests: Long = 0 - var outstandingDemand: Long = 0 + var pendingRequests = 0L + var outstandingDemand = 0L var completed = false - def getNextDemand(): Long = { + def getNextDemand(): Int = { val max = Math.min(remainingDemand, maximumRequest) if (max == 1) { remainingDemand = 0 @@ -107,7 +111,7 @@ trait ScriptedTest extends Matchers { def debugLog(msg: String): Unit = _debugLog :+= msg - def request(demand: Long): Unit = { + def request(demand: Int): Unit = { debugLog(s"test environment requests $demand") downstreamSubscription.request(demand) outstandingDemand += demand @@ -187,7 +191,7 @@ trait ScriptedTest extends Matchers { } def runScript[In, Out](script: Script[In, Out], settings: MaterializerSettings, maximumOverrun: Int = 3, maximumRequest: Int = 3, maximumBuffer: Int = 3)( - op: Flow[In] ⇒ Flow[Out])(implicit system: ActorSystem): Unit = { + op: Flow[In, In] ⇒ Flow[In, Out])(implicit system: ActorSystem): Unit = { new ScriptRunner(op, settings, script, maximumOverrun, maximumRequest, maximumBuffer).run() } diff --git a/akka-stream-testkit/src/test/scala/akka/stream/testkit/StreamTestDefaultMailbox.scala b/akka-stream-testkit/src/test/scala/akka/stream/testkit/StreamTestDefaultMailbox.scala index 3983900175..04a514a9e4 100644 --- a/akka-stream-testkit/src/test/scala/akka/stream/testkit/StreamTestDefaultMailbox.scala +++ b/akka-stream-testkit/src/test/scala/akka/stream/testkit/StreamTestDefaultMailbox.scala @@ -23,14 +23,21 @@ private[akka] case class StreamTestDefaultMailbox() extends MailboxType with Pro final override def create(owner: Option[ActorRef], system: Option[ActorSystem]): MessageQueue = { owner match { case Some(r: ActorRefWithCell) ⇒ - val actorClass = r.underlying.props.actorClass - assert(actorClass != classOf[Actor], s"Don't use anonymous actor classes, actor class for $r was [${actorClass.getName}]") - // StreamTcpManager is allowed to use another dispatcher - assert(!actorClass.getName.startsWith("akka.stream.") || actorClass == classOf[StreamTcpManager] || actorClass == classOf[akka.stream.io2.StreamTcpManager], - s"$r with actor class [${actorClass.getName}] must not run on default dispatcher in tests. " + - "Did you forget to define `props.withDispatcher` when creating the actor? " + - "Or did you forget to configure the `akka.stream.materializer` setting accordingly or force the " + - """dispatcher using `MaterializerSettings(sys).withDispatcher("akka.test.stream-dispatcher")` in the test?""") + try { + val actorClass = r.underlying.props.actorClass + assert(actorClass != classOf[Actor], s"Don't use anonymous actor classes, actor class for $r was [${actorClass.getName}]") + // StreamTcpManager is allowed to use another dispatcher + assert(!actorClass.getName.startsWith("akka.stream.") || actorClass == classOf[StreamTcpManager] || actorClass == classOf[akka.stream.io2.StreamTcpManager], + s"$r with actor class [${actorClass.getName}] must not run on default dispatcher in tests. " + + "Did you forget to define `props.withDispatcher` when creating the actor? " + + "Or did you forget to configure the `akka.stream.materializer` setting accordingly or force the " + + """dispatcher using `MaterializerSettings(sys).withDispatcher("akka.test.stream-dispatcher")` in the test?""") + } catch { + // this logging should not be needed when issue #15947 has been fixed + case e: AssertionError ⇒ + system.foreach(_.log.error(e, s"StreamTestDefaultMailbox assertion failed: ${e.getMessage}")) + throw e + } case _ ⇒ } new UnboundedMailbox.MessageQueue diff --git a/akka-stream-testkit/src/test/scala/akka/stream/testkit2/TwoStreamsSetup.scala b/akka-stream-testkit/src/test/scala/akka/stream/testkit/TwoStreamsSetup.scala similarity index 96% rename from akka-stream-testkit/src/test/scala/akka/stream/testkit2/TwoStreamsSetup.scala rename to akka-stream-testkit/src/test/scala/akka/stream/testkit/TwoStreamsSetup.scala index 314be53990..1213d9a2e2 100644 --- a/akka-stream-testkit/src/test/scala/akka/stream/testkit2/TwoStreamsSetup.scala +++ b/akka-stream-testkit/src/test/scala/akka/stream/testkit/TwoStreamsSetup.scala @@ -1,11 +1,10 @@ -package akka.stream.testkit2 +package akka.stream.testkit import akka.stream.MaterializerSettings -import akka.stream.scaladsl2._ -import akka.stream.testkit.{ StreamTestKit, AkkaSpec } +import akka.stream.scaladsl._ import org.reactivestreams.Publisher - import scala.util.control.NoStackTrace +import akka.stream.FlowMaterializer abstract class TwoStreamsSetup extends AkkaSpec { diff --git a/akka-stream-testkit/src/test/scala/akka/stream/testkit2/ChainSetup.scala b/akka-stream-testkit/src/test/scala/akka/stream/testkit2/ChainSetup.scala deleted file mode 100644 index 0a640abc2e..0000000000 --- a/akka-stream-testkit/src/test/scala/akka/stream/testkit2/ChainSetup.scala +++ /dev/null @@ -1,28 +0,0 @@ -package akka.stream.testkit2 - -import akka.actor.{ ActorRefFactory, ActorSystem } -import akka.stream.MaterializerSettings -import akka.stream.scaladsl2._ -import akka.stream.testkit.StreamTestKit -import org.reactivestreams.Publisher - -class ChainSetup[In, Out]( - stream: Flow[In, In] ⇒ Flow[In, Out], - val settings: MaterializerSettings, - materializer: FlowMaterializer, - toPublisher: (Source[Out], FlowMaterializer) ⇒ Publisher[Out])(implicit val system: ActorSystem) { - - def this(stream: Flow[In, In] ⇒ Flow[In, Out], settings: MaterializerSettings, toPublisher: (Source[Out], FlowMaterializer) ⇒ Publisher[Out])(implicit system: ActorSystem) = - this(stream, settings, FlowMaterializer(settings)(system), toPublisher)(system) - - def this(stream: Flow[In, In] ⇒ Flow[In, Out], settings: MaterializerSettings, materializerCreator: (MaterializerSettings, ActorRefFactory) ⇒ FlowMaterializer, toPublisher: (Source[Out], FlowMaterializer) ⇒ Publisher[Out])(implicit system: ActorSystem) = - this(stream, settings, materializerCreator(settings, system), toPublisher)(system) - - val upstream = StreamTestKit.PublisherProbe[In]() - val downstream = StreamTestKit.SubscriberProbe[Out]() - private val s = Source(upstream).connect(stream(Flow[In])) - val publisher = toPublisher(s, materializer) - val upstreamSubscription = upstream.expectSubscription() - publisher.subscribe(downstream) - val downstreamSubscription = downstream.expectSubscription() -} diff --git a/akka-stream-testkit/src/test/scala/akka/stream/testkit2/ScriptedTest.scala b/akka-stream-testkit/src/test/scala/akka/stream/testkit2/ScriptedTest.scala deleted file mode 100644 index c77b0d5d82..0000000000 --- a/akka-stream-testkit/src/test/scala/akka/stream/testkit2/ScriptedTest.scala +++ /dev/null @@ -1,197 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream.testkit2 - -import akka.actor.ActorSystem -import akka.stream.MaterializerSettings -import akka.stream.scaladsl2.{ FlowMaterializer, Sink, Source, Flow } -import akka.stream.testkit.StreamTestKit._ -import org.reactivestreams.Publisher -import org.scalatest.Matchers -import scala.annotation.tailrec -import scala.concurrent.duration._ -import scala.concurrent.forkjoin.ThreadLocalRandom - -trait ScriptedTest extends Matchers { - - class ScriptException(msg: String) extends RuntimeException(msg) - - def toPublisher[In, Out]: (Source[Out], FlowMaterializer) ⇒ Publisher[Out] = - (f, m) ⇒ f.runWith(Sink.publisher)(m) - - object Script { - def apply[In, Out](phases: (Seq[In], Seq[Out])*): Script[In, Out] = { - var providedInputs = Vector[In]() - var expectedOutputs = Vector[Out]() - var jumps = Vector[Int]() - - for ((ins, outs) ← phases) { - providedInputs ++= ins - expectedOutputs ++= outs - jumps ++= Vector.fill(ins.size - 1)(0) ++ Vector(outs.size) - } - - Script(providedInputs, expectedOutputs, jumps, inputCursor = 0, outputCursor = 0, outputEndCursor = 0, completed = false) - } - } - - case class Script[In, Out]( - providedInputs: Vector[In], - expectedOutputs: Vector[Out], - jumps: Vector[Int], - inputCursor: Int, - outputCursor: Int, - outputEndCursor: Int, - completed: Boolean) { - require(jumps.size == providedInputs.size) - - def provideInput: (In, Script[In, Out]) = - if (noInsPending) - throw new ScriptException("Script cannot provide more input.") - else - (providedInputs(inputCursor), this.copy(inputCursor = inputCursor + 1, outputEndCursor = outputEndCursor + jumps(inputCursor))) - - def consumeOutput(out: Out): Script[In, Out] = { - if (noOutsPending) - throw new ScriptException(s"Tried to produce element ${out} but no elements should be produced right now.") - out should be(expectedOutputs(outputCursor)) - this.copy(outputCursor = outputCursor + 1) - } - - def complete(): Script[In, Out] = { - if (finished) copy(completed = true) - else fail("received onComplete prematurely") - } - - def finished: Boolean = outputCursor == expectedOutputs.size - - def error(e: Throwable): Script[In, Out] = throw e - - def pendingOuts: Int = outputEndCursor - outputCursor - def noOutsPending: Boolean = pendingOuts == 0 - def someOutsPending: Boolean = !noOutsPending - - def pendingIns: Int = providedInputs.size - inputCursor - def noInsPending: Boolean = pendingIns == 0 - def someInsPending: Boolean = !noInsPending - - def debug: String = s"Script(pending=($pendingIns in, $pendingOuts out), remainingIns=${providedInputs.drop(inputCursor).mkString("/")}, remainingOuts=${expectedOutputs.drop(outputCursor).mkString("/")})" - } - - class ScriptRunner[In, Out]( - op: Flow[In, In] ⇒ Flow[In, Out], - settings: MaterializerSettings, - script: Script[In, Out], - maximumOverrun: Int, - maximumRequest: Int, - maximumBuffer: Int)(implicit _system: ActorSystem) - extends ChainSetup(op, settings, toPublisher) { - - var _debugLog = Vector.empty[String] - var currentScript = script - var remainingDemand = script.expectedOutputs.size + ThreadLocalRandom.current().nextInt(1, maximumOverrun) - debugLog(s"starting with remainingDemand=$remainingDemand") - var pendingRequests = 0L - var outstandingDemand = 0L - var completed = false - - def getNextDemand(): Int = { - val max = Math.min(remainingDemand, maximumRequest) - if (max == 1) { - remainingDemand = 0 - 1 - } else { - val demand = ThreadLocalRandom.current().nextInt(1, max) - remainingDemand -= demand - demand - } - } - - def debugLog(msg: String): Unit = _debugLog :+= msg - - def request(demand: Int): Unit = { - debugLog(s"test environment requests $demand") - downstreamSubscription.request(demand) - outstandingDemand += demand - } - - def mayProvideInput: Boolean = currentScript.someInsPending && (pendingRequests > 0) && (currentScript.pendingOuts <= maximumBuffer) - def mayRequestMore: Boolean = remainingDemand > 0 - - def shakeIt(): Boolean = { - val u = upstream.probe.receiveWhile(1.milliseconds) { - case RequestMore(_, n) ⇒ - debugLog(s"operation requests $n") - pendingRequests += n - true - case _ ⇒ false // Ignore - } - val d = downstream.probe.receiveWhile(1.milliseconds) { - case OnNext(elem: Out) ⇒ - debugLog(s"operation produces [$elem]") - if (outstandingDemand == 0) fail("operation produced while there was no demand") - outstandingDemand -= 1 - currentScript = currentScript.consumeOutput(elem) - true - case OnComplete ⇒ - currentScript = currentScript.complete() - true - case OnError(e) ⇒ - currentScript = currentScript.error(e) - true - case _ ⇒ false // Ignore - } - (u ++ d) exists (x ⇒ x) - } - - def run(): Unit = { - - @tailrec def doRun(idleRounds: Int): Unit = { - if (idleRounds > 250) fail("too many idle rounds") - if (!currentScript.completed) { - val nextIdle = if (shakeIt()) 0 else idleRounds + 1 - - val tieBreak = ThreadLocalRandom.current().nextBoolean() - if (mayProvideInput && (!mayRequestMore || tieBreak)) { - val (input, nextScript) = currentScript.provideInput - debugLog(s"test environment produces [${input}]") - pendingRequests -= 1 - currentScript = nextScript - upstreamSubscription.sendNext(input) - doRun(nextIdle) - } else if (mayRequestMore && (!mayProvideInput || !tieBreak)) { - request(getNextDemand()) - doRun(nextIdle) - } else { - if (currentScript.noInsPending && !completed) { - debugLog("test environment completes") - upstreamSubscription.sendComplete() - completed = true - } - doRun(nextIdle) - } - - } - } - - try { - debugLog(s"running $script") - request(getNextDemand()) - doRun(0) - } catch { - case e: Throwable ⇒ - println(_debugLog.mkString("Steps leading to failure:\n", "\n", "\nCurrentScript: " + currentScript.debug)) - throw e - } - - } - - } - - def runScript[In, Out](script: Script[In, Out], settings: MaterializerSettings, maximumOverrun: Int = 3, maximumRequest: Int = 3, maximumBuffer: Int = 3)( - op: Flow[In, In] ⇒ Flow[In, Out])(implicit system: ActorSystem): Unit = { - new ScriptRunner(op, settings, script, maximumOverrun, maximumRequest, maximumBuffer).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 8054ab6284..e8f60bf02b 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 @@ -6,7 +6,7 @@ import akka.actor.Props; import akka.stream.MaterializerSettings; import akka.stream.javadsl.AkkaJUnitActorSystemResource; import akka.stream.javadsl.Source; -import akka.stream.scaladsl2.FlowMaterializer; +import akka.stream.FlowMaterializer; import akka.stream.testkit.AkkaSpec; import akka.testkit.JavaTestKit; import org.junit.ClassRule; 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 cadaf53c48..8947bf4058 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 @@ -7,7 +7,7 @@ import akka.stream.MaterializerSettings; import akka.stream.javadsl.AkkaJUnitActorSystemResource; import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; -import akka.stream.scaladsl2.FlowMaterializer; +import akka.stream.FlowMaterializer; import akka.stream.testkit.AkkaSpec; import akka.testkit.JavaTestKit; import org.junit.ClassRule; 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 29d63b7956..685823549e 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 @@ -7,11 +7,8 @@ import akka.dispatch.Futures; import akka.dispatch.OnSuccess; import akka.japi.Pair; import akka.japi.Util; -import akka.stream.MaterializerSettings; -import akka.stream.OverflowStrategy; -import akka.stream.Transformer; +import akka.stream.*; import akka.stream.javadsl.japi.*; -import akka.stream.scaladsl2.FlowMaterializer; import akka.stream.testkit.AkkaSpec; import akka.testkit.JavaTestKit; import org.junit.ClassRule; @@ -35,26 +32,26 @@ import static org.junit.Assert.assertEquals; public class FlowTest { @ClassRule - public static AkkaJUnitActorSystemResource actorSystemResource = new AkkaJUnitActorSystemResource("FlowTest", AkkaSpec.testConf()); + public static AkkaJUnitActorSystemResource actorSystemResource = new AkkaJUnitActorSystemResource("FlowTest", + AkkaSpec.testConf()); final ActorSystem system = actorSystemResource.getSystem(); final MaterializerSettings settings = new MaterializerSettings(2, 4, 2, 4, "akka.test.stream-dispatcher"); - final FlowMaterializer materializer = akka.stream.scaladsl2.FlowMaterializer.create(settings, system); + final FlowMaterializer materializer = FlowMaterializer.create(settings, system); @Test public void mustBeAbleToUseSimpleOperators() { final JavaTestKit probe = new JavaTestKit(system); - final String[] lookup = {"a", "b", "c", "d", "e", "f"}; + final String[] lookup = { "a", "b", "c", "d", "e", "f" }; final java.util.Iterator input = Arrays.asList(0, 1, 2, 3, 4, 5).iterator(); final Source ints = Source.from(input); - ints.drop(2).take(3).takeWithin(FiniteDuration.create(10, TimeUnit.SECONDS)) - .map(new Function() { - public String apply(Integer elem) { - return lookup[elem]; - } - }).filter(new Predicate() { + ints.drop(2).take(3).takeWithin(FiniteDuration.create(10, TimeUnit.SECONDS)).map(new Function() { + public String apply(Integer elem) { + return lookup[elem]; + } + }).filter(new Predicate() { public boolean test(String elem) { return !elem.equals("c"); } @@ -63,20 +60,19 @@ public class FlowTest { return elem; } }).groupedWithin(100, FiniteDuration.create(50, TimeUnit.MILLISECONDS)) - .mapConcat(new Function, java.util.List>() { - public java.util.List apply(java.util.List elem) { - return elem; - } - }).fold("", new Function2() { - public String apply(String acc, String elem) { - return acc + elem; - } - }, materializer) - .foreach(new Foreach() { // Scala Future - public void each(String elem) { - probe.getRef().tell(elem, ActorRef.noSender()); - } - }, system.dispatcher()); + .mapConcat(new Function, java.util.List>() { + public java.util.List apply(java.util.List elem) { + return elem; + } + }).fold("", new Function2() { + public String apply(String acc, String elem) { + return acc + elem; + } + }, materializer).foreach(new Foreach() { // Scala Future + public void each(String elem) { + probe.getRef().tell(elem, ActorRef.noSender()); + } + }, system.dispatcher()); probe.expectMsgEquals("de"); @@ -88,15 +84,15 @@ public class FlowTest { final java.util.Iterator input = Arrays.asList("a", "b", "c").iterator(); Source ints = Source.from(input); - Future completion = ints - .foreach(new Procedure() { - public void apply(String elem) { - probe.getRef().tell(elem, ActorRef.noSender()); - } - }, materializer); + Future completion = ints.foreach(new Procedure() { + public void apply(String elem) { + probe.getRef().tell(elem, ActorRef.noSender()); + } + }, materializer); completion.onSuccess(new OnSuccess() { - @Override public void onSuccess(BoxedUnit elem) throws Throwable { + @Override + public void onSuccess(BoxedUnit elem) throws Throwable { probe.getRef().tell(String.valueOf(elem), ActorRef.noSender()); } }, system.dispatcher()); @@ -124,7 +120,7 @@ public class FlowTest { public scala.collection.immutable.Seq onNext(Integer element) { sum += element; count += 1; - return Util.immutableSeq(new Integer[]{element, element}); + return Util.immutableSeq(new Integer[] { element, element }); } @Override @@ -229,9 +225,11 @@ public class FlowTest { return elem.substring(0, 1); } }).foreach(new Procedure>>() { - @Override public void apply(final Pair> pair) throws Exception { + @Override + public void apply(final Pair> pair) throws Exception { pair.second().foreach(new Procedure() { - @Override public void apply(String elem) throws Exception { + @Override + public void apply(String elem) throws Exception { probe.getRef().tell(new Pair(pair.first(), elem), ActorRef.noSender()); } }, materializer); @@ -263,19 +261,19 @@ public class FlowTest { return elem.equals("\n"); } }).foreach(new Procedure>() { - @Override public void apply(Source subStream) throws Exception { - subStream - .filter(new Predicate() { - @Override public boolean test(String elem) { - return !elem.equals("\n"); - } - }) - .grouped(10) - .foreach(new Procedure>() { - @Override public void apply(List chunk) throws Exception { - probe.getRef().tell(chunk, ActorRef.noSender()); - } - }, materializer); + @Override + public void apply(Source subStream) throws Exception { + subStream.filter(new Predicate() { + @Override + public boolean test(String elem) { + return !elem.equals("\n"); + } + }).grouped(10).foreach(new Procedure>() { + @Override + public void apply(List chunk) throws Exception { + probe.getRef().tell(chunk, ActorRef.noSender()); + } + }, materializer); } }, materializer); @@ -297,7 +295,8 @@ public class FlowTest { public Creator> op() { return new akka.stream.javadsl.japi.Creator>() { - @Override public Transformer create() throws Exception { + @Override + public Transformer create() throws Exception { return new Transformer() { @Override public Seq onNext(In element) { @@ -320,18 +319,13 @@ public class FlowTest { final KeyedSink> publisher = Sink.publisher(); // this is red in intellij, but actually valid, scalac generates bridge methods for Java, so inference *works* - final Merge merge = Merge.create(); - MaterializedMap m = FlowGraph. - builder(). - addEdge(in1, f1, merge). - addEdge(in2, f2, merge). - addEdge(merge, f3, publisher). - build(). - run(materializer); + final Merge merge = Merge. create(); + MaterializedMap m = FlowGraph.builder().addEdge(in1, f1, merge).addEdge(in2, f2, merge) + .addEdge(merge, f3, publisher).build().run(materializer); // collecting final Publisher pub = m.get(publisher); - final Future> all = Source.from(pub).grouped(100).runWith(Sink.>future(), materializer); + final Future> all = Source.from(pub).grouped(100).runWith(Sink.> future(), 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)); @@ -346,26 +340,20 @@ public class FlowTest { final Source in1 = Source.from(input1); final Source in2 = Source.from(input2); final Zip zip = Zip.create(); - final KeyedSink, Future> out = Sink.foreach(new Procedure>() { - @Override - public void apply(Pair param) throws Exception { - probe.getRef().tell(param, ActorRef.noSender()); - } - }); + final KeyedSink, Future> out = Sink + .foreach(new Procedure>() { + @Override + public void apply(Pair param) throws Exception { + probe.getRef().tell(param, ActorRef.noSender()); + } + }); - FlowGraph. - builder(). - addEdge(in1, zip.left()). - addEdge(in2, zip.right()). - addEdge(zip.out(), out). - run(materializer); + FlowGraph.builder().addEdge(in1, zip.left()).addEdge(in2, zip.right()).addEdge(zip.out(), out).run(materializer); List output = Arrays.asList(probe.receiveN(3)); @SuppressWarnings("unchecked") - List> expected = Arrays.asList( - new Pair("A", 1), - new Pair("B", 2), - new Pair("C", 3)); + List> expected = Arrays.asList(new Pair("A", 1), new Pair( + "B", 2), new Pair("C", 3)); assertEquals(expected, output); } @@ -375,10 +363,8 @@ public class FlowTest { final JavaTestKit probe2 = new JavaTestKit(system); @SuppressWarnings("unchecked") - final List> input = Arrays.asList( - new Pair("A", 1), - new Pair("B", 2), - new Pair("C", 3)); + final List> input = Arrays.asList(new Pair("A", 1), + new Pair("B", 2), new Pair("C", 3)); final Iterable expected1 = Arrays.asList("A", "B", "C"); final Iterable expected2 = Arrays.asList(1, 2, 3); @@ -399,12 +385,8 @@ public class FlowTest { } }); - FlowGraph. - builder(). - addEdge(in, unzip.in()). - addEdge(unzip.left(), out1). - addEdge(unzip.right(), out2). - run(materializer); + FlowGraph.builder().addEdge(in, unzip.in()).addEdge(unzip.left(), out1).addEdge(unzip.right(), out2) + .run(materializer); List output1 = Arrays.asList(probe1.receiveN(3)); List output2 = Arrays.asList(probe2.receiveN(3)); @@ -463,13 +445,12 @@ public class FlowTest { final JavaTestKit probe = new JavaTestKit(system); final Iterable input = Arrays.asList("A", "B", "C"); - Source.from(input) - .runWith(Sink.onComplete(new Procedure() { - @Override public void apply(BoxedUnit param) throws Exception { - probe.getRef().tell(param, ActorRef.noSender()); - } - }), - materializer); + Source.from(input).runWith(Sink. onComplete(new Procedure() { + @Override + public void apply(BoxedUnit param) throws Exception { + probe.getRef().tell(param, ActorRef.noSender()); + } + }), materializer); probe.expectMsgClass(BoxedUnit.class); } @@ -483,16 +464,16 @@ public class FlowTest { public String apply(String arg0) throws Exception { throw new RuntimeException("simulated err"); } - }).runWith(Sink.future(), materializer) - .onComplete(new OnSuccess>() { - @Override public void onSuccess(Try e) throws Throwable { - if (e == null) { - probe.getRef().tell("done", ActorRef.noSender()); - } else { - probe.getRef().tell(e.failed().get().getMessage(), ActorRef.noSender()); - } + }).runWith(Sink. future(), materializer).onComplete(new OnSuccess>() { + @Override + public void onSuccess(Try e) throws Throwable { + if (e == null) { + probe.getRef().tell("done", ActorRef.noSender()); + } else { + probe.getRef().tell(e.failed().get().getMessage(), ActorRef.noSender()); } - }, system.dispatcher()); + } + }, system.dispatcher()); probe.expectMsgEquals("simulated err"); } @@ -501,7 +482,7 @@ public class FlowTest { public void mustBeAbleToUseToFuture() throws Exception { final JavaTestKit probe = new JavaTestKit(system); final Iterable input = Arrays.asList("A", "B", "C"); - Future future = Source.from(input).runWith(Sink.future(), materializer); + Future future = Source.from(input).runWith(Sink. future(), materializer); String result = Await.result(future, probe.dilated(FiniteDuration.create(3, TimeUnit.SECONDS))); assertEquals("A", result); } @@ -510,14 +491,13 @@ public class FlowTest { public void mustBeAbleToUsePrefixAndTail() throws Exception { final JavaTestKit probe = new JavaTestKit(system); final Iterable input = Arrays.asList(1, 2, 3, 4, 5, 6); - Future, Source>> future = Source - .from(input) - .prefixAndTail(3) - .runWith(Sink., Source>>future(), materializer); - Pair, Source> result = Await.result(future, probe.dilated(FiniteDuration.create(3, TimeUnit.SECONDS))); + Future, Source>> future = Source.from(input).prefixAndTail(3) + .runWith(Sink., Source>> future(), materializer); + Pair, Source> result = Await.result(future, + probe.dilated(FiniteDuration.create(3, TimeUnit.SECONDS))); assertEquals(Arrays.asList(1, 2, 3), result.first()); - Future> tailFuture = result.second().grouped(4).runWith(Sink.>future(), materializer); + Future> tailFuture = result.second().grouped(4).runWith(Sink.> future(), materializer); List tailResult = Await.result(tailFuture, probe.dilated(FiniteDuration.create(3, TimeUnit.SECONDS))); assertEquals(Arrays.asList(4, 5, 6), tailResult); } @@ -528,15 +508,11 @@ public class FlowTest { final Iterable input1 = Arrays.asList(1, 2, 3); final Iterable input2 = Arrays.asList(4, 5); - final List> mainInputs = Arrays.asList( - Source.from(input1), - Source.from(input2)); + final List> mainInputs = Arrays.asList(Source.from(input1), Source.from(input2)); - Future> future = Source - .from(mainInputs) - .flatten(akka.stream.javadsl.FlattenStrategy.concat()) - .grouped(6) - .runWith(Sink.>future(), materializer); + Future> future = Source.from(mainInputs) + .flatten(akka.stream.javadsl.FlattenStrategy. concat()).grouped(6) + .runWith(Sink.> future(), materializer); List result = Await.result(future, probe.dilated(FiniteDuration.create(3, TimeUnit.SECONDS))); @@ -547,9 +523,8 @@ public class FlowTest { public void mustBeAbleToUseBuffer() throws Exception { final JavaTestKit probe = new JavaTestKit(system); final List input = Arrays.asList("A", "B", "C"); - Future> future = Source.from(input) - .buffer(2, OverflowStrategy.backpressure()).grouped(4) - .runWith(Sink.>future(), materializer); + Future> future = Source.from(input).buffer(2, OverflowStrategy.backpressure()).grouped(4) + .runWith(Sink.> future(), materializer); List result = Await.result(future, probe.dilated(FiniteDuration.create(3, TimeUnit.SECONDS))); assertEquals(input, result); @@ -558,7 +533,7 @@ public class FlowTest { @Test public void mustBeAbleToUseConflate() throws Exception { final JavaTestKit probe = new JavaTestKit(system); -// final List input = Arrays.asList("A", "B", "C"); // test was fleaky // TODO FIXME, test was fleaky! + // final List input = Arrays.asList("A", "B", "C"); // test was fleaky // TODO FIXME, test was fleaky! final List input = Arrays.asList("C"); Future future = Source.from(input).conflate(new Function() { @Override @@ -584,18 +559,17 @@ public class FlowTest { public void mustBeAbleToUseExpand() throws Exception { final JavaTestKit probe = new JavaTestKit(system); final List input = Arrays.asList("A", "B", "C"); - Future future = Source.from(input) - .expand(new Function() { - @Override - public String apply(String in) throws Exception { - return in; - } - }, new Function>() { - @Override - public Pair apply(String in) throws Exception { - return new Pair(in, in); - } - }).runWith(Sink.future(), materializer); + Future future = Source.from(input).expand(new Function() { + @Override + public String apply(String in) throws Exception { + return in; + } + }, new Function>() { + @Override + public Pair apply(String in) throws Exception { + return new Pair(in, in); + } + }).runWith(Sink. future(), materializer); String result = Await.result(future, probe.dilated(FiniteDuration.create(3, TimeUnit.SECONDS))); assertEquals("A", result); } @@ -612,11 +586,11 @@ public class FlowTest { } }; Source.from(FiniteDuration.create(1, TimeUnit.SECONDS), FiniteDuration.create(500, TimeUnit.MILLISECONDS), tick) - .foreach(new Procedure() { - public void apply(String elem) { - probe.getRef().tell(elem, ActorRef.noSender()); - } - }, materializer); + .foreach(new Procedure() { + public void apply(String elem) { + probe.getRef().tell(elem, ActorRef.noSender()); + } + }, materializer); probe.expectNoMsg(FiniteDuration.create(600, TimeUnit.MILLISECONDS)); probe.expectMsgEquals("tick-1"); probe.expectNoMsg(FiniteDuration.create(200, TimeUnit.MILLISECONDS)); diff --git a/akka-stream-tests/src/test/scala/akka/persistence/stream/PersistentSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/persistence/stream/PersistentSourceSpec.scala index c51c8b8952..71419c3de8 100644 --- a/akka-stream-tests/src/test/scala/akka/persistence/stream/PersistentSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/persistence/stream/PersistentSourceSpec.scala @@ -6,12 +6,12 @@ package akka.persistence.stream import akka.actor.ActorRef import akka.actor.Props import akka.persistence.RecoveryCompleted -import akka.stream.scaladsl2.FlowGraph -import akka.stream.scaladsl2.FlowGraphImplicits -import akka.stream.scaladsl2.FlowMaterializer -import akka.stream.scaladsl2.Merge -import akka.stream.scaladsl2.Sink -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.FlowGraph +import akka.stream.scaladsl.FlowGraphImplicits +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.Merge +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source import akka.stream.testkit.AkkaSpec import akka.testkit.TestProbe diff --git a/akka-stream-tests/src/test/scala/akka/stream/DslConsistencySpec.scala b/akka-stream-tests/src/test/scala/akka/stream/DslConsistencySpec.scala index a8282c6fff..c31d71e57d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/DslConsistencySpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/DslConsistencySpec.scala @@ -11,20 +11,20 @@ import org.scalatest.WordSpec @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class DslConsistencySpec extends WordSpec with Matchers { - val sFlowClass = classOf[akka.stream.scaladsl2.Flow[_, _]] + val sFlowClass = classOf[akka.stream.scaladsl.Flow[_, _]] val jFlowClass = classOf[akka.stream.javadsl.Flow[_, _]] - val sSourceClass = classOf[akka.stream.scaladsl2.Source[_]] + val sSourceClass = classOf[akka.stream.scaladsl.Source[_]] val jSourceClass = classOf[akka.stream.javadsl.Source[_]] - val sSinkClass = classOf[akka.stream.scaladsl2.Sink[_]] + val sSinkClass = classOf[akka.stream.scaladsl.Sink[_]] val jSinkClass = classOf[akka.stream.javadsl.Sink[_]] val jFlowGraphClass = classOf[akka.stream.javadsl.FlowGraph] - val sFlowGraphClass = classOf[akka.stream.scaladsl2.FlowGraph] + val sFlowGraphClass = classOf[akka.stream.scaladsl.FlowGraph] val jPartialFlowGraphClass = classOf[akka.stream.javadsl.PartialFlowGraph] - val sPartialFlowGraphClass = classOf[akka.stream.scaladsl2.PartialFlowGraph] + val sPartialFlowGraphClass = classOf[akka.stream.scaladsl.PartialFlowGraph] val ignore = Set("equals", "hashCode", "notify", "notifyAll", "wait", "toString", "getClass") ++ diff --git a/akka-stream-tests/src/test/scala/akka/stream/DslFactoriesConsistencySpec.scala b/akka-stream-tests/src/test/scala/akka/stream/DslFactoriesConsistencySpec.scala index ea1dd75af7..ac21f82639 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/DslFactoriesConsistencySpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/DslFactoriesConsistencySpec.scala @@ -35,18 +35,18 @@ class DslFactoriesConsistencySpec extends WordSpec with Matchers { (classOf[scala.Function1[_, _]], classOf[akka.stream.javadsl.japi.Function[_, _]]) :: (classOf[scala.Function1[_, _]], classOf[akka.stream.javadsl.japi.Creator[_]]) :: (classOf[scala.Function2[_, _, _]], classOf[akka.stream.javadsl.japi.Function2[_, _, _]]) :: - (classOf[akka.stream.scaladsl2.Source[_]], classOf[akka.stream.javadsl.Source[_]]) :: - (classOf[akka.stream.scaladsl2.Sink[_]], classOf[akka.stream.javadsl.Sink[_]]) :: - (classOf[akka.stream.scaladsl2.Flow[_, _]], classOf[akka.stream.javadsl.Flow[_, _]]) :: - (classOf[akka.stream.scaladsl2.FlowGraph], classOf[akka.stream.javadsl.FlowGraph]) :: - (classOf[akka.stream.scaladsl2.PartialFlowGraph], classOf[akka.stream.javadsl.PartialFlowGraph]) :: + (classOf[akka.stream.scaladsl.Source[_]], classOf[akka.stream.javadsl.Source[_]]) :: + (classOf[akka.stream.scaladsl.Sink[_]], classOf[akka.stream.javadsl.Sink[_]]) :: + (classOf[akka.stream.scaladsl.Flow[_, _]], classOf[akka.stream.javadsl.Flow[_, _]]) :: + (classOf[akka.stream.scaladsl.FlowGraph], classOf[akka.stream.javadsl.FlowGraph]) :: + (classOf[akka.stream.scaladsl.PartialFlowGraph], classOf[akka.stream.javadsl.PartialFlowGraph]) :: Nil // format: ON "Java DSL" must provide { "Source" which { "allows creating the same Sources as Scala DSL" in { - val sClass = akka.stream.scaladsl2.Source.getClass + val sClass = akka.stream.scaladsl.Source.getClass val jClass = akka.stream.javadsl.Source.getClass runSpec(sClass, jClass) @@ -54,7 +54,7 @@ class DslFactoriesConsistencySpec extends WordSpec with Matchers { } "Flow" which { "allows creating the same Sources as Scala DSL" in { - val sClass = akka.stream.scaladsl2.Flow.getClass + val sClass = akka.stream.scaladsl.Flow.getClass val jClass = akka.stream.javadsl.Flow.getClass runSpec(sClass, jClass) @@ -62,7 +62,7 @@ class DslFactoriesConsistencySpec extends WordSpec with Matchers { } "Sink" which { "allows creating the same Sources as Scala DSL" in { - val sClass = akka.stream.scaladsl2.Sink.getClass + val sClass = akka.stream.scaladsl.Sink.getClass val jClass = akka.stream.javadsl.Sink.getClass runSpec(sClass, jClass) diff --git a/akka-stream-tests/src/test/scala/akka/stream/DuctSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/DuctSpec.scala deleted file mode 100644 index 7c48917d57..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/DuctSpec.scala +++ /dev/null @@ -1,218 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import scala.collection.immutable -import scala.concurrent.duration._ -import org.reactivestreams.{ Publisher, Subscriber } -import akka.stream.scaladsl.Duct -import akka.stream.scaladsl.Flow -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit -import scala.util.Success -import scala.util.Failure - -object DuctSpec { - class Fruit - class Apple extends Fruit -} - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class DuctSpec extends AkkaSpec { - import DuctSpec._ - - implicit val materializer = FlowMaterializer() - - "A Duct" must { - - "materialize into Publisher/Subscriber" in { - val duct: Duct[String, String] = Duct[String] - val (ductIn: Subscriber[String], ductOut: Publisher[String]) = duct.build() - - val c1 = StreamTestKit.SubscriberProbe[String]() - ductOut.subscribe(c1) - - val source: Publisher[String] = Flow(List("1", "2", "3")).toPublisher() - source.subscribe(ductIn) - - val sub1 = c1.expectSubscription - sub1.request(3) - c1.expectNext("1") - c1.expectNext("2") - c1.expectNext("3") - c1.expectComplete - } - - "materialize into Publisher/Subscriber and transformation processor" in { - val duct: Duct[Int, String] = Duct[Int].map((i: Int) ⇒ i.toString) - val (ductIn: Subscriber[Int], ductOut: Publisher[String]) = duct.build() - - val c1 = StreamTestKit.SubscriberProbe[String]() - ductOut.subscribe(c1) - val sub1 = c1.expectSubscription - sub1.request(3) - c1.expectNoMsg(200.millis) - - val source: Publisher[Int] = Flow(List(1, 2, 3)).toPublisher() - source.subscribe(ductIn) - - c1.expectNext("1") - c1.expectNext("2") - c1.expectNext("3") - c1.expectComplete - } - - "materialize into Publisher/Subscriber and multiple transformation processors" in { - val duct = Duct[Int].map(_.toString).map("elem-" + _) - val (ductIn, ductOut) = duct.build() - - val c1 = StreamTestKit.SubscriberProbe[String]() - ductOut.subscribe(c1) - val sub1 = c1.expectSubscription - sub1.request(3) - c1.expectNoMsg(200.millis) - - val source: Publisher[Int] = Flow(List(1, 2, 3)).toPublisher() - source.subscribe(ductIn) - - c1.expectNext("elem-1") - c1.expectNext("elem-2") - c1.expectNext("elem-3") - c1.expectComplete - } - - "subscribe Subscriber" in { - val duct: Duct[String, String] = Duct[String] - val c1 = StreamTestKit.SubscriberProbe[String]() - val c2: Subscriber[String] = duct.produceTo(c1) - val source: Publisher[String] = Flow(List("1", "2", "3")).toPublisher() - source.subscribe(c2) - - val sub1 = c1.expectSubscription - sub1.request(3) - c1.expectNext("1") - c1.expectNext("2") - c1.expectNext("3") - c1.expectComplete - } - - "perform transformation operation" in { - val duct = Duct[Int].map(i ⇒ { testActor ! i.toString; i.toString }) - val c = duct.consume() - - val source = Flow(List(1, 2, 3)).toPublisher() - source.subscribe(c) - - expectMsg("1") - expectMsg("2") - expectMsg("3") - } - - "perform multiple transformation operations" in { - val (in, fut) = Duct[Int].map(_.toString).map("elem-" + _).foreach(testActor ! _) - - val source = Flow(List(1, 2, 3)).toPublisher() - source.subscribe(in) - - expectMsg("elem-1") - expectMsg("elem-2") - expectMsg("elem-3") - } - - "perform transformation operation and subscribe Subscriber" in { - val duct = Duct[Int].map(_.toString) - val c1 = StreamTestKit.SubscriberProbe[String]() - val c2: Subscriber[Int] = duct.produceTo(c1) - - val sub1 = c1.expectSubscription - sub1.request(3) - c1.expectNoMsg(200.millis) - - val source: Publisher[Int] = Flow(List(1, 2, 3)).toPublisher() - source.subscribe(c2) - - c1.expectNext("1") - c1.expectNext("2") - c1.expectNext("3") - c1.expectComplete - } - - "perform multiple transformation operations and subscribe Subscriber" in { - val duct = Duct[Int].map(_.toString).map("elem-" + _) - val c1 = StreamTestKit.SubscriberProbe[String]() - val c2 = duct.produceTo(c1) - - val sub1 = c1.expectSubscription - sub1.request(3) - c1.expectNoMsg(200.millis) - - val source: Publisher[Int] = Flow(List(1, 2, 3)).toPublisher() - source.subscribe(c2) - - c1.expectNext("elem-1") - c1.expectNext("elem-2") - c1.expectNext("elem-3") - c1.expectComplete - } - - "call onComplete callback when done" in { - val duct = Duct[Int].map(i ⇒ { testActor ! i.toString; i.toString }) - val c = duct.onComplete { - case Success(_) ⇒ testActor ! "DONE" - case Failure(e) ⇒ testActor ! e - } - - val source = Flow(List(1, 2, 3)).toPublisher() - source.subscribe(c) - - expectMsg("1") - expectMsg("2") - expectMsg("3") - expectMsg("DONE") - } - - "be appendable to a Flow" in { - val c = StreamTestKit.SubscriberProbe[String]() - val duct = Duct[Int].map(_ + 10).map(_.toString) - Flow(List(1, 2, 3)).map(_ * 2).append(duct).map((s: String) ⇒ "elem-" + s).produceTo(c) - - val sub = c.expectSubscription - sub.request(3) - c.expectNext("elem-12") - c.expectNext("elem-14") - c.expectNext("elem-16") - c.expectComplete - } - - "be appendable to a Duct" in { - val c = StreamTestKit.SubscriberProbe[String]() - val duct1 = Duct[String].map(Integer.parseInt) - val ductInSubscriber = Duct[Int] - .map { i ⇒ (i * 2).toString } - .append(duct1) - .map { i ⇒ "elem-" + (i + 10) } - .produceTo(c) - - Flow(List(1, 2, 3)).produceTo(ductInSubscriber) - - val sub = c.expectSubscription - sub.request(3) - c.expectNext("elem-12") - c.expectNext("elem-14") - c.expectNext("elem-16") - c.expectComplete - } - - "be covariant" in { - val d1: Duct[String, Publisher[Fruit]] = Duct[String].map(_ ⇒ new Apple).splitWhen(_ ⇒ true) - val d2: Duct[String, (Boolean, Publisher[Fruit])] = Duct[String].map(_ ⇒ new Apple).groupBy(_ ⇒ true) - val d3: Duct[String, (immutable.Seq[Apple], Publisher[Fruit])] = Duct[String].map(_ ⇒ new Apple).prefixAndTail(1) - val s1: Subscriber[Fruit] = StreamTestKit.SubscriberProbe[Fruit]() - val s2: Subscriber[String] = Duct[String].map(_ ⇒ new Apple).produceTo(s1) - val t: Tuple2[Subscriber[String], Publisher[Fruit]] = Duct[String].map(_ ⇒ new Apple).build() - } - - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowBroadcastSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowBroadcastSpec.scala deleted file mode 100644 index c6b6e38c60..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowBroadcastSpec.scala +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import scala.concurrent.duration._ -import akka.stream.scaladsl.Flow -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowBroadcastSpec extends AkkaSpec { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 1, maxSize = 16) - - implicit val materializer = FlowMaterializer(settings) - - "A broadcast" must { - - "broadcast to other subscriber" in { - val c1 = StreamTestKit.SubscriberProbe[Int]() - val c2 = StreamTestKit.SubscriberProbe[Int]() - val p = Flow(List(1, 2, 3)). - broadcast(c2). - toPublisher() - p.subscribe(c1) - val sub1 = c1.expectSubscription() - val sub2 = c2.expectSubscription() - sub1.request(1) - sub2.request(2) - c1.expectNext(1) - c1.expectNoMsg(100.millis) - c2.expectNext(1) - c2.expectNext(2) - c2.expectNoMsg(100.millis) - sub1.request(3) - c1.expectNext(2) - c1.expectNext(3) - c1.expectComplete() - sub2.request(3) - c2.expectNext(3) - c2.expectComplete() - } - - "produce to other even though downstream cancels" in { - val c1 = StreamTestKit.SubscriberProbe[Int]() - val c2 = StreamTestKit.SubscriberProbe[Int]() - val p = Flow(List(1, 2, 3)). - broadcast(c2). - toPublisher() - p.subscribe(c1) - val sub1 = c1.expectSubscription() - sub1.cancel() - val sub2 = c2.expectSubscription() - sub2.request(3) - c2.expectNext(1) - c2.expectNext(2) - c2.expectNext(3) - c2.expectComplete() - } - - "produce to downstream even though other cancels" in { - val c1 = StreamTestKit.SubscriberProbe[Int]() - val c2 = StreamTestKit.SubscriberProbe[Int]() - val p = Flow(List(1, 2, 3)). - broadcast(c1). - toPublisher() - p.subscribe(c2) - val sub1 = c1.expectSubscription() - sub1.cancel() - val sub2 = c2.expectSubscription() - sub2.request(3) - c2.expectNext(1) - c2.expectNext(2) - c2.expectNext(3) - c2.expectComplete() - } - - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowBufferSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowBufferSpec.scala deleted file mode 100644 index b58684778b..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowBufferSpec.scala +++ /dev/null @@ -1,182 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } - -import scala.concurrent.Await -import scala.concurrent.duration._ - -class FlowBufferSpec extends AkkaSpec { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 1, maxSize = 1) - .withFanOutBuffer(initialSize = 1, maxSize = 1) - - implicit val materializer = FlowMaterializer(settings) - - "Buffer" must { - - "pass elements through normally in backpressured mode" in { - val future = Flow((1 to 1000).iterator).buffer(100, overflowStrategy = OverflowStrategy.backpressure).grouped(1001).toFuture() - Await.result(future, 3.seconds) should be(1 to 1000) - } - - "pass elements through normally in backpressured mode with buffer size one" in { - val future = Flow((1 to 1000).iterator).buffer(1, overflowStrategy = OverflowStrategy.backpressure).grouped(1001).toFuture() - Await.result(future, 3.seconds) should be(1 to 1000) - } - - "pass elements through a chain of backpressured buffers of different size" in { - val future = Flow((1 to 1000).iterator) - .buffer(1, overflowStrategy = OverflowStrategy.backpressure) - .buffer(10, overflowStrategy = OverflowStrategy.backpressure) - .buffer(256, overflowStrategy = OverflowStrategy.backpressure) - .buffer(1, overflowStrategy = OverflowStrategy.backpressure) - .buffer(5, overflowStrategy = OverflowStrategy.backpressure) - .buffer(128, overflowStrategy = OverflowStrategy.backpressure) - .grouped(1001) - .toFuture() - Await.result(future, 3.seconds) should be(1 to 1000) - } - - "accept elements that fit in the buffer while downstream is silent" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - - Flow(publisher).buffer(100, overflowStrategy = OverflowStrategy.backpressure).produceTo(subscriber) - - val autoPublisher = new StreamTestKit.AutoPublisher(publisher) - val sub = subscriber.expectSubscription() - - // Fill up buffer - for (i ← 1 to 100) autoPublisher.sendNext(i) - - // drain - for (i ← 1 to 100) { - sub.request(1) - subscriber.expectNext(i) - } - sub.cancel() - } - - "drop head elements if buffer is full and configured so" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - - Flow(publisher).buffer(100, overflowStrategy = OverflowStrategy.dropHead).produceTo(subscriber) - - val autoPublisher = new StreamTestKit.AutoPublisher(publisher) - val sub = subscriber.expectSubscription() - - // Fill up buffer - for (i ← 1 to 200) autoPublisher.sendNext(i) - - // drain - for (i ← 101 to 200) { - sub.request(1) - subscriber.expectNext(i) - } - - sub.request(1) - subscriber.expectNoMsg(1.seconds) - - autoPublisher.sendNext(-1) - sub.request(1) - subscriber.expectNext(-1) - - sub.cancel() - } - - "drop tail elements if buffer is full and configured so" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - - Flow(publisher).buffer(100, overflowStrategy = OverflowStrategy.dropTail).produceTo(subscriber) - - val autoPublisher = new StreamTestKit.AutoPublisher(publisher) - val sub = subscriber.expectSubscription() - - // Fill up buffer - for (i ← 1 to 200) autoPublisher.sendNext(i) - - // drain - for (i ← 1 to 99) { - sub.request(1) - subscriber.expectNext(i) - } - - sub.request(1) - subscriber.expectNext(200) - - sub.request(1) - subscriber.expectNoMsg(1.seconds) - - autoPublisher.sendNext(-1) - sub.request(1) - subscriber.expectNext(-1) - - sub.cancel() - } - - "drop all elements if buffer is full and configured so" in { - val publisher = StreamTestKit.PublisherProbe[Int] - val subscriber = StreamTestKit.SubscriberProbe[Int]() - - Flow(publisher).buffer(100, overflowStrategy = OverflowStrategy.dropBuffer).produceTo(subscriber) - - val autoPublisher = new StreamTestKit.AutoPublisher(publisher) - val sub = subscriber.expectSubscription() - - // Fill up buffer - for (i ← 1 to 150) autoPublisher.sendNext(i) - - // drain - for (i ← 101 to 150) { - sub.request(1) - subscriber.expectNext(i) - } - - sub.request(1) - subscriber.expectNoMsg(1.seconds) - - autoPublisher.sendNext(-1) - sub.request(1) - subscriber.expectNext(-1) - - sub.cancel() - } - - for (strategy ← List(OverflowStrategy.dropHead, OverflowStrategy.dropTail, OverflowStrategy.dropBuffer)) { - - s"work with $strategy if buffer size of one" in { - - val publisher = StreamTestKit.PublisherProbe[Int] - val subscriber = StreamTestKit.SubscriberProbe[Int]() - - Flow(publisher).buffer(1, overflowStrategy = strategy).produceTo(subscriber) - - val autoPublisher = new StreamTestKit.AutoPublisher(publisher) - val sub = subscriber.expectSubscription() - - // Fill up buffer - for (i ← 1 to 200) autoPublisher.sendNext(i) - - sub.request(1) - subscriber.expectNext(200) - - sub.request(1) - subscriber.expectNoMsg(1.seconds) - - autoPublisher.sendNext(-1) - sub.request(1) - subscriber.expectNext(-1) - - sub.cancel() - } - } - - } -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowCollectSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowCollectSpec.scala deleted file mode 100644 index 474b83e0d1..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowCollectSpec.scala +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.testkit.{ AkkaSpec, ScriptedTest } - -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } - -class FlowCollectSpec extends AkkaSpec with ScriptedTest { - - val settings = MaterializerSettings(system) - - "A Collect" must { - - "collect" in { - val range = 1 to 50 - def script = Script(range map { _ ⇒ - val x = random.nextInt(0, 10000) - Seq(x) -> (if ((x & 1) == 0) Seq((x * x).toString) else Seq.empty[String]) - }: _*) - range foreach (_ ⇒ runScript(script, settings)(_.collect { case x if x % 2 == 0 ⇒ (x * x).toString })) - } - - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowConcatAllSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowConcatAllSpec.scala deleted file mode 100644 index bee140b39f..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowConcatAllSpec.scala +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.testkit.{ StreamTestKit, AkkaSpec } -import akka.stream.scaladsl.Flow -import scala.concurrent.duration._ -import scala.concurrent.Await -import org.reactivestreams.Publisher -import scala.util.control.NoStackTrace - -class FlowConcatAllSpec extends AkkaSpec { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 2) - .withFanOutBuffer(initialSize = 2, maxSize = 2) - - implicit val materializer = FlowMaterializer(settings) - - "ConcatAll" must { - - val testException = new Exception("test") with NoStackTrace - - "work in the happy case" in { - val s1 = Flow((1 to 2).iterator).toPublisher() - val s2 = Flow(List.empty[Int]).toPublisher() - val s3 = Flow(List(3)).toPublisher() - val s4 = Flow((4 to 6).iterator).toPublisher() - val s5 = Flow((7 to 10).iterator).toPublisher() - - val main: Flow[Publisher[Int]] = Flow(List(s1, s2, s3, s4, s5)) - - Await.result(main.flatten(FlattenStrategy.concat).grouped(10).toFuture(), 3.seconds) should be(1 to 10) - } - - "work together with SplitWhen" in { - Await.result( - Flow((1 to 10).iterator).splitWhen(_ % 2 == 0).flatten(FlattenStrategy.concat).grouped(10).toFuture(), - 3.seconds) should be(1 to 10) - } - - "on onError on master stream cancel the current open substream and signal error" in { - val publisher = StreamTestKit.PublisherProbe[Publisher[Int]]() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - Flow(publisher).flatten(FlattenStrategy.concat).produceTo(subscriber) - - val upstream = publisher.expectSubscription() - val downstream = subscriber.expectSubscription() - downstream.request(1000) - - val substreamPublisher = StreamTestKit.PublisherProbe[Int]() - upstream.expectRequest() - upstream.sendNext(substreamPublisher) - val subUpstream = substreamPublisher.expectSubscription() - - upstream.sendError(testException) - subscriber.expectError(testException) - subUpstream.expectCancellation() - } - - "on onError on open substream, cancel the master stream and signal error " in { - val publisher = StreamTestKit.PublisherProbe[Publisher[Int]]() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - Flow(publisher).flatten(FlattenStrategy.concat).produceTo(subscriber) - - val upstream = publisher.expectSubscription() - val downstream = subscriber.expectSubscription() - downstream.request(1000) - - val substreamPublisher = StreamTestKit.PublisherProbe[Int]() - upstream.expectRequest() - upstream.sendNext(substreamPublisher) - val subUpstream = substreamPublisher.expectSubscription() - - subUpstream.sendError(testException) - subscriber.expectError(testException) - upstream.expectCancellation() - } - - "on cancellation cancel the current open substream and the master stream" in { - val publisher = StreamTestKit.PublisherProbe[Publisher[Int]]() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - Flow(publisher).flatten(FlattenStrategy.concat).produceTo(subscriber) - - val upstream = publisher.expectSubscription() - val downstream = subscriber.expectSubscription() - downstream.request(1000) - - val substreamPublisher = StreamTestKit.PublisherProbe[Int]() - upstream.expectRequest() - upstream.sendNext(substreamPublisher) - val subUpstream = substreamPublisher.expectSubscription() - - downstream.cancel() - - subUpstream.expectCancellation() - upstream.expectCancellation() - } - - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowConcatSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowConcatSpec.scala deleted file mode 100644 index b835cbb7ea..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowConcatSpec.scala +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.testkit.StreamTestKit -import akka.stream.scaladsl.Flow -import org.reactivestreams.Publisher -import scala.concurrent.Promise - -class FlowConcatSpec extends TwoStreamsSetup { - - type Outputs = Int - override def operationUnderTest(in1: Flow[Int], in2: Publisher[Int]) = in1.concat(in2) - - "Concat" must { - - "work in the happy case" in { - val source0 = Flow(List.empty[Int].iterator).toPublisher() - val source1 = Flow((1 to 4).iterator).toPublisher() - val source2 = Flow((5 to 10).iterator).toPublisher() - val p = Flow(source0).concat(source1).concat(source2).toPublisher() - - val probe = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(probe) - val subscription = probe.expectSubscription() - - for (i ← 1 to 10) { - subscription.request(1) - probe.expectNext(i) - } - - probe.expectComplete() - } - - commonTests() - - "work with one immediately completed and one nonempty publisher" in { - val subscriber1 = setup(completedPublisher, nonemptyPublisher((1 to 4).iterator)) - val subscription1 = subscriber1.expectSubscription() - subscription1.request(5) - subscriber1.expectNext(1) - subscriber1.expectNext(2) - subscriber1.expectNext(3) - subscriber1.expectNext(4) - subscriber1.expectComplete() - - val subscriber2 = setup(nonemptyPublisher((1 to 4).iterator), completedPublisher) - val subscription2 = subscriber2.expectSubscription() - subscription2.request(5) - subscriber2.expectNext(1) - subscriber2.expectNext(2) - subscriber2.expectNext(3) - subscriber2.expectNext(4) - subscriber2.expectComplete() - } - - "work with one delayed completed and one nonempty publisher" in { - val subscriber1 = setup(soonToCompletePublisher, nonemptyPublisher((1 to 4).iterator)) - val subscription1 = subscriber1.expectSubscription() - subscription1.request(5) - subscriber1.expectNext(1) - subscriber1.expectNext(2) - subscriber1.expectNext(3) - subscriber1.expectNext(4) - subscriber1.expectComplete() - - val subscriber2 = setup(nonemptyPublisher((1 to 4).iterator), soonToCompletePublisher) - val subscription2 = subscriber2.expectSubscription() - subscription2.request(5) - subscriber2.expectNext(1) - subscriber2.expectNext(2) - subscriber2.expectNext(3) - subscriber2.expectNext(4) - subscriber2.expectComplete() - } - - "work with one immediately failed and one nonempty publisher" in { - val subscriber1 = setup(failedPublisher, nonemptyPublisher((1 to 4).iterator)) - subscriber1.expectErrorOrSubscriptionFollowedByError(TestException) - - val subscriber2 = setup(nonemptyPublisher((1 to 4).iterator), failedPublisher) - subscriber2.expectErrorOrSubscriptionFollowedByError(TestException) - } - - "work with one delayed failed and one nonempty publisher" in { - val subscriber1 = setup(soonToFailPublisher, nonemptyPublisher((1 to 4).iterator)) - subscriber1.expectErrorOrSubscriptionFollowedByError(TestException) - - val subscriber2 = setup(nonemptyPublisher((1 to 4).iterator), soonToFailPublisher) - subscriber2.expectErrorOrSubscriptionFollowedByError(TestException) - } - - "correctly handle async errors in secondary upstream" in { - val promise = Promise[Int]() - val flow = Flow(List(1, 2, 3)).concat(Flow(promise.future).toPublisher()) - val subscriber = StreamTestKit.SubscriberProbe[Int]() - flow.produceTo(subscriber) - val subscription = subscriber.expectSubscription() - subscription.request(4) - subscriber.expectNext(1) - subscriber.expectNext(2) - subscriber.expectNext(3) - promise.failure(TestException) - subscriber.expectError(TestException) - } - } -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowConflateSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowConflateSpec.scala deleted file mode 100644 index ce0c3cc699..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowConflateSpec.scala +++ /dev/null @@ -1,99 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.testkit.{ StreamTestKit, AkkaSpec } -import akka.stream.scaladsl.Flow -import scala.concurrent.forkjoin.ThreadLocalRandom -import scala.concurrent.Await -import scala.concurrent.duration._ - -class FlowConflateSpec extends AkkaSpec { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 2) - .withFanOutBuffer(initialSize = 2, maxSize = 2) - - implicit val materializer = FlowMaterializer(settings) - - "Conflate" must { - - "pass-through elements unchanged when there is no rate difference" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - - Flow(publisher).conflate[Int](seed = i ⇒ i, aggregate = (sum, i) ⇒ sum + i).produceTo(subscriber) - - val autoPublisher = new StreamTestKit.AutoPublisher(publisher) - val sub = subscriber.expectSubscription() - - for (i ← 1 to 100) { - sub.request(1) - autoPublisher.sendNext(i) - subscriber.expectNext(i) - } - - sub.cancel() - } - - "conflate elements while downstream is silent" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - - Flow(publisher).conflate[Int](seed = i ⇒ i, aggregate = (sum, i) ⇒ sum + i).produceTo(subscriber) - - val autoPublisher = new StreamTestKit.AutoPublisher(publisher) - val sub = subscriber.expectSubscription() - - for (i ← 1 to 100) { - autoPublisher.sendNext(i) - } - subscriber.expectNoMsg(1.second) - sub.request(1) - subscriber.expectNext(5050) - sub.cancel() - } - - "work on a variable rate chain" in { - val future = Flow((1 to 1000).iterator) - .conflate[Int](seed = i ⇒ i, aggregate = (sum, i) ⇒ sum + i) - .map { i ⇒ if (ThreadLocalRandom.current().nextBoolean()) Thread.sleep(10); i } - .fold(0)(_ + _) - .toFuture() - - Await.result(future, 10.seconds) should be(500500) - } - - "backpressure subscriber when upstream is slower" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - - Flow(publisher).conflate[Int](seed = i ⇒ i, aggregate = (sum, i) ⇒ sum + i).produceTo(subscriber) - - val autoPublisher = new StreamTestKit.AutoPublisher(publisher) - val sub = subscriber.expectSubscription() - - sub.request(1) - autoPublisher.sendNext(1) - subscriber.expectNext(1) - - sub.request(1) - subscriber.expectNoMsg(1.second) - autoPublisher.sendNext(2) - subscriber.expectNext(2) - - autoPublisher.sendNext(3) - autoPublisher.sendNext(4) - sub.request(1) - subscriber.expectNext(7) - - sub.request(1) - subscriber.expectNoMsg(1.second) - sub.cancel() - - } - - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowDispatcherSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowDispatcherSpec.scala deleted file mode 100644 index bfd070a2f2..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowDispatcherSpec.scala +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.testkit.TestProbe -import akka.stream.testkit.AkkaSpec - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowDispatcherSpec extends AkkaSpec { - - implicit val materializer = FlowMaterializer() - - "Flow with dispatcher setting" must { - "use the specified dispatcher" in { - val probe = TestProbe() - val p = Flow(List(1, 2, 3)).map(i ⇒ - { probe.ref ! Thread.currentThread().getName(); i }). - consume() - probe.receiveN(3) foreach { - case s: String ⇒ s should startWith(system.name + "-akka.test.stream-dispatcher") - } - } - } -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowDropSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowDropSpec.scala deleted file mode 100644 index 2f477fe034..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowDropSpec.scala +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.testkit.{ AkkaSpec, ScriptedTest } - -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } -import akka.stream.testkit.StreamTestKit -import akka.stream.scaladsl.Flow - -class FlowDropSpec extends AkkaSpec with ScriptedTest { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 1, maxSize = 16) - - implicit val materializer = FlowMaterializer(settings) - - "A Drop" must { - - "drop" in { - def script(d: Int) = Script((1 to 50) map { n ⇒ Seq(n) -> (if (n <= d) Nil else Seq(n)) }: _*) - (1 to 50) foreach { _ ⇒ - val d = Math.min(Math.max(random.nextInt(-10, 60), 0), 50) - runScript(script(d), settings)(_.drop(d)) - } - } - - "not drop anything for negative n" in { - val probe = StreamTestKit.SubscriberProbe[Int]() - Flow(List(1, 2, 3)).drop(-1).produceTo(probe) - probe.expectSubscription().request(10) - probe.expectNext(1) - probe.expectNext(2) - probe.expectNext(3) - probe.expectComplete() - } - - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowDropWithinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowDropWithinSpec.scala deleted file mode 100644 index 19311ae41c..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowDropWithinSpec.scala +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import scala.concurrent.duration._ -import akka.stream.scaladsl.Flow -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowDropWithinSpec extends AkkaSpec { - - implicit val materializer = FlowMaterializer() - - "A DropWithin" must { - - "deliver elements after the duration, but not before" in { - val input = Iterator.from(1) - val p = StreamTestKit.PublisherProbe[Int]() - val c = StreamTestKit.SubscriberProbe[Int]() - Flow(p).dropWithin(1.second).produceTo(c) - val pSub = p.expectSubscription() - val cSub = c.expectSubscription() - cSub.request(100) - val demand1 = pSub.expectRequest() - (1 to demand1.toInt) foreach { _ ⇒ pSub.sendNext(input.next()) } - val demand2 = pSub.expectRequest() - (1 to demand2.toInt) foreach { _ ⇒ pSub.sendNext(input.next()) } - val demand3 = pSub.expectRequest() - c.expectNoMsg(1500.millis) - (1 to demand3.toInt) foreach { _ ⇒ pSub.sendNext(input.next()) } - ((demand1 + demand2 + 1).toInt to (demand1 + demand2 + demand3).toInt) foreach { n ⇒ c.expectNext(n) } - pSub.sendComplete() - c.expectComplete() - c.expectNoMsg(200.millis) - } - - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowExpandSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowExpandSpec.scala deleted file mode 100644 index f1848f7071..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowExpandSpec.scala +++ /dev/null @@ -1,118 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.testkit.{ StreamTestKit, AkkaSpec } -import akka.stream.scaladsl.Flow -import scala.concurrent.forkjoin.ThreadLocalRandom -import scala.concurrent.Await -import scala.concurrent.duration._ - -class FlowExpandSpec extends AkkaSpec { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 2) - .withFanOutBuffer(initialSize = 2, maxSize = 2) - - implicit val materializer = FlowMaterializer(settings) - - "Expand" must { - - "pass-through elements unchanged when there is no rate difference" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - - // Simply repeat the last element as an extrapolation step - Flow(publisher).expand[Int, Int](seed = i ⇒ i, extrapolate = i ⇒ (i, i)).produceTo(subscriber) - - val autoPublisher = new StreamTestKit.AutoPublisher(publisher) - val sub = subscriber.expectSubscription() - - for (i ← 1 to 100) { - // Order is important here: If the request comes first it will be extrapolated! - autoPublisher.sendNext(i) - sub.request(1) - subscriber.expectNext(i) - } - - sub.cancel() - } - - "expand elements while upstream is silent" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - - // Simply repeat the last element as an extrapolation step - Flow(publisher).expand[Int, Int](seed = i ⇒ i, extrapolate = i ⇒ (i, i)).produceTo(subscriber) - - val autoPublisher = new StreamTestKit.AutoPublisher(publisher) - val sub = subscriber.expectSubscription() - - autoPublisher.sendNext(42) - - for (i ← 1 to 100) { - sub.request(1) - subscriber.expectNext(42) - } - - autoPublisher.sendNext(-42) - sub.request(1) - subscriber.expectNext(-42) - - sub.cancel() - } - - "work on a variable rate chain" in { - val future = Flow((1 to 100).iterator) - .map { i ⇒ if (ThreadLocalRandom.current().nextBoolean()) Thread.sleep(10); i } - .expand[Int, Int](seed = i ⇒ i, extrapolate = i ⇒ (i, i)) - .fold(Set.empty[Int])(_ + _) - .toFuture() - - Await.result(future, 10.seconds) should be(Set.empty[Int] ++ (1 to 100)) - } - - "backpressure publisher when subscriber is slower" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - - Flow(publisher).expand[Int, Int](seed = i ⇒ i, extrapolate = i ⇒ (i, i)).produceTo(subscriber) - - val autoPublisher = new StreamTestKit.AutoPublisher(publisher) - val sub = subscriber.expectSubscription() - - autoPublisher.sendNext(1) - sub.request(1) - subscriber.expectNext(1) - sub.request(1) - subscriber.expectNext(1) - - var pending = autoPublisher.pendingRequests - // Deplete pending requests coming from input buffer - while (pending > 0) { - autoPublisher.subscription.sendNext(2) - pending -= 1 - } - - // The above sends are absorbed in the input buffer, and will result in two one-sized batch requests - pending += autoPublisher.subscription.expectRequest() - pending += autoPublisher.subscription.expectRequest() - while (pending > 0) { - autoPublisher.subscription.sendNext(2) - pending -= 1 - } - - publisher.expectNoMsg(1.second) - - sub.request(2) - subscriber.expectNext(2) - subscriber.expectNext(2) - - // Now production is resumed - autoPublisher.subscription.expectRequest() - - } - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowFilterSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowFilterSpec.scala deleted file mode 100644 index e24d640e32..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowFilterSpec.scala +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, ScriptedTest, StreamTestKit } - -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } - -class FlowFilterSpec extends AkkaSpec with ScriptedTest { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 1, maxSize = 16) - - "A Filter" must { - - "filter" in { - def script = Script((1 to 50) map { _ ⇒ val x = random.nextInt(); Seq(x) -> (if ((x & 1) == 0) Seq(x) else Seq()) }: _*) - (1 to 50) foreach (_ ⇒ runScript(script, settings)(_.filter(_ % 2 == 0))) - } - - "not blow up with high request counts" in { - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 1, maxSize = 1) - .withFanOutBuffer(initialSize = 1, maxSize = 1) - implicit val materializer = FlowMaterializer(settings) - - val probe = StreamTestKit.SubscriberProbe[Int]() - Flow(Iterator.fill(1000)(0) ++ List(1)).filter(_ != 0). - toPublisher().subscribe(probe) - - val subscription = probe.expectSubscription() - for (_ ← 1 to 10000) { - subscription.request(Int.MaxValue) - } - - probe.expectNext(1) - probe.expectComplete() - - } - - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowFoldSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowFoldSpec.scala deleted file mode 100644 index 01eb050fd4..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowFoldSpec.scala +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.testkit.{ AkkaSpec, ScriptedTest } - -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } - -class FlowFoldSpec extends AkkaSpec with ScriptedTest { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 2, maxSize = 16) - - "A Fold" must { - - "fold" in { - def script = Script((1 to 50).toSeq -> Seq(25 * 51)) - (1 to 50) foreach (_ ⇒ runScript(script, settings)(_.fold(0)(_ + _))) - } - - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowForeachSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowForeachSpec.scala deleted file mode 100644 index 8052ef6fa0..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowForeachSpec.scala +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } - -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } -import scala.util.control.NoStackTrace - -class FlowForeachSpec extends AkkaSpec { - - implicit val mat = FlowMaterializer() - import system.dispatcher - - "A Foreach" must { - - "call the procedure for each element" in { - Flow(1 to 3).foreach(testActor ! _).onSuccess { - case _ ⇒ testActor ! "done" - } - expectMsg(1) - expectMsg(2) - expectMsg(3) - expectMsg("done") - } - - "complete the future for an empty stream" in { - Flow(Nil).foreach(testActor ! _).onSuccess { - case _ ⇒ testActor ! "done" - } - expectMsg("done") - } - - "yield the first error" in { - val p = StreamTestKit.PublisherProbe[Int]() - Flow(p).foreach(testActor ! _).onFailure { - case ex ⇒ testActor ! ex - } - val proc = p.expectSubscription - proc.expectRequest() - val ex = new RuntimeException("ex") with NoStackTrace - proc.sendError(ex) - expectMsg(ex) - } - - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowFromFutureSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowFromFutureSpec.scala deleted file mode 100644 index 0e9b43f765..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowFromFutureSpec.scala +++ /dev/null @@ -1,120 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } - -import scala.concurrent.{ Future, Promise } -import scala.concurrent.duration._ - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowFromFutureSpec extends AkkaSpec { - - val settings = MaterializerSettings(system) - - implicit val materializer = FlowMaterializer(settings) - - "A Flow based on a Future" must { - "produce one element from already successful Future" in { - val p = Flow(Future.successful(1)).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - val sub = c.expectSubscription() - c.expectNoMsg(100.millis) - sub.request(1) - c.expectNext(1) - c.expectComplete() - } - - "produce error from already failed Future" in { - val ex = new RuntimeException("test") - val p = Flow(Future.failed[Int](ex)).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - c.expectError(ex) - } - - "produce one element when Future is completed" in { - val promise = Promise[Int]() - val p = Flow(promise.future).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - val sub = c.expectSubscription() - sub.request(1) - c.expectNoMsg(100.millis) - promise.success(1) - c.expectNext(1) - c.expectComplete() - c.expectNoMsg(100.millis) - } - - "produce one element when Future is completed but not before request" in { - val promise = Promise[Int]() - val p = Flow(promise.future).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - val sub = c.expectSubscription() - promise.success(1) - c.expectNoMsg(200.millis) - sub.request(1) - c.expectNext(1) - c.expectComplete() - } - - "produce elements with multiple subscribers" in { - val promise = Promise[Int]() - val p = Flow(promise.future).toPublisher() - val c1 = StreamTestKit.SubscriberProbe[Int]() - val c2 = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c1) - p.subscribe(c2) - val sub1 = c1.expectSubscription() - val sub2 = c2.expectSubscription() - sub1.request(1) - promise.success(1) - sub2.request(2) - c1.expectNext(1) - c2.expectNext(1) - c1.expectComplete() - c2.expectComplete() - } - - "produce elements to later subscriber" in { - val promise = Promise[Int]() - val p = Flow(promise.future).toPublisher() - val keepAlive = StreamTestKit.SubscriberProbe[Int]() - val c1 = StreamTestKit.SubscriberProbe[Int]() - val c2 = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(keepAlive) - p.subscribe(c1) - - val sub1 = c1.expectSubscription() - sub1.request(1) - promise.success(1) - c1.expectNext(1) - c1.expectComplete() - p.subscribe(c2) - val sub2 = c2.expectSubscription() - sub2.request(1) - c2.expectNext(1) - c2.expectComplete() - } - - "allow cancel before receiving element" in { - val promise = Promise[Int]() - val p = Flow(promise.future).toPublisher() - val keepAlive = StreamTestKit.SubscriberProbe[Int]() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(keepAlive) - p.subscribe(c) - val sub = c.expectSubscription() - sub.request(1) - sub.cancel() - c.expectNoMsg(500.millis) - promise.success(1) - c.expectNoMsg(200.millis) - } - } -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowGroupBySpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowGroupBySpec.scala deleted file mode 100644 index a2b9acd0f0..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowGroupBySpec.scala +++ /dev/null @@ -1,196 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream - -import scala.concurrent.duration._ -import akka.stream.testkit._ -import org.reactivestreams.Publisher -import akka.stream.scaladsl.Flow -import scala.util.control.NoStackTrace - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowGroupBySpec extends AkkaSpec { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 2) - .withFanOutBuffer(initialSize = 2, maxSize = 2) - - implicit val materializer = FlowMaterializer(settings) - - case class StreamPuppet(p: Publisher[Int]) { - val probe = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(probe) - val subscription = probe.expectSubscription() - - def request(demand: Long): Unit = subscription.request(demand) - def expectNext(elem: Int): Unit = probe.expectNext(elem) - def expectNoMsg(max: FiniteDuration): Unit = probe.expectNoMsg(max) - def expectComplete(): Unit = probe.expectComplete() - def expectError(e: Throwable) = probe.expectError(e) - def cancel(): Unit = subscription.cancel() - } - - class SubstreamsSupport(groupCount: Int = 2, elementCount: Int = 6) { - val source = Flow((1 to elementCount).iterator).toPublisher() - val groupStream = Flow(source).groupBy(_ % groupCount).toPublisher() - val masterSubscriber = StreamTestKit.SubscriberProbe[(Int, Publisher[Int])]() - - groupStream.subscribe(masterSubscriber) - val masterSubscription = masterSubscriber.expectSubscription() - - def getSubPublisher(expectedKey: Int): Publisher[Int] = { - masterSubscription.request(1) - expectSubPublisher(expectedKey: Int) - } - - def expectSubPublisher(expectedKey: Int): Publisher[Int] = { - val (key, substream) = masterSubscriber.expectNext() - key should be(expectedKey) - substream - } - - } - - case class TE(message: String) extends RuntimeException(message) with NoStackTrace - - "groupBy" must { - "work in the happy case" in new SubstreamsSupport(groupCount = 2) { - val s1 = StreamPuppet(getSubPublisher(1)) - masterSubscriber.expectNoMsg(100.millis) - - s1.expectNoMsg(100.millis) - s1.request(1) - s1.expectNext(1) - s1.expectNoMsg(100.millis) - - val s2 = StreamPuppet(getSubPublisher(0)) - - s2.expectNoMsg(100.millis) - s2.request(2) - s2.expectNext(2) - - // Important to request here on the OTHER stream because the buffer space is exactly one without the fanout box - s1.request(1) - s2.expectNext(4) - - s2.expectNoMsg(100.millis) - - s1.expectNext(3) - - s2.request(1) - // Important to request here on the OTHER stream because the buffer space is exactly one without the fanout box - s1.request(1) - s2.expectNext(6) - s2.expectComplete() - - s1.expectNext(5) - s1.expectComplete() - - masterSubscriber.expectComplete() - - } - - "accept cancellation of substreams" in new SubstreamsSupport(groupCount = 2) { - StreamPuppet(getSubPublisher(1)).cancel() - - val substream = StreamPuppet(getSubPublisher(0)) - substream.request(2) - substream.expectNext(2) - substream.expectNext(4) - substream.expectNoMsg(100.millis) - - substream.request(2) - substream.expectNext(6) - substream.expectComplete() - - masterSubscriber.expectComplete() - - } - - "accept cancellation of master stream when not consumed anything" in { - val publisherProbeProbe = StreamTestKit.PublisherProbe[Int]() - val publisher = Flow(publisherProbeProbe).groupBy(_ % 2).toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[(Int, Publisher[Int])]() - publisher.subscribe(subscriber) - - val upstreamSubscription = publisherProbeProbe.expectSubscription() - val downstreamSubscription = subscriber.expectSubscription() - downstreamSubscription.cancel() - upstreamSubscription.expectCancellation() - } - - "accept cancellation of master stream when substreams are open" in new SubstreamsSupport(groupCount = 3, elementCount = 13) { - pending - // FIXME: Needs handling of loose substreams that no one refers to anymore. - // val substream = StreamPuppet(getSubproducer(1)) - // - // substream.request(1) - // substream.expectNext(1) - // - // masterSubscription.cancel() - // masterSubscriber.expectNoMsg(100.millis) - // - // // Open substreams still work, others are discarded - // substream.request(4) - // substream.expectNext(4) - // substream.expectNext(7) - // substream.expectNext(10) - // substream.expectNext(13) - // substream.expectComplete() - } - - "work with empty input stream" in { - val publisher = Flow(List.empty[Int]).groupBy(_ % 2).toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[(Int, Publisher[Int])]() - publisher.subscribe(subscriber) - - subscriber.expectCompletedOrSubscriptionFollowedByComplete() - } - - "abort on onError from upstream" in { - val publisherProbeProbe = StreamTestKit.PublisherProbe[Int]() - val publisher = Flow(publisherProbeProbe).groupBy(_ % 2).toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[(Int, Publisher[Int])]() - publisher.subscribe(subscriber) - - val upstreamSubscription = publisherProbeProbe.expectSubscription() - - val downstreamSubscription = subscriber.expectSubscription() - downstreamSubscription.request(100) - - val e = TE("test") - upstreamSubscription.sendError(e) - - subscriber.expectError(e) - } - - "abort on onError from upstream when substreams are running" in { - val publisherProbeProbe = StreamTestKit.PublisherProbe[Int]() - val publisher = Flow(publisherProbeProbe).groupBy(_ % 2).toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[(Int, Publisher[Int])]() - publisher.subscribe(subscriber) - - val upstreamSubscription = publisherProbeProbe.expectSubscription() - - val downstreamSubscription = subscriber.expectSubscription() - downstreamSubscription.request(100) - - upstreamSubscription.sendNext(1) - - val (_, substream) = subscriber.expectNext() - val substreamPuppet = StreamPuppet(substream) - - substreamPuppet.request(1) - substreamPuppet.expectNext(1) - - val e = TE("test") - upstreamSubscription.sendError(e) - - substreamPuppet.expectError(e) - subscriber.expectError(e) - - } - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowGroupedSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowGroupedSpec.scala deleted file mode 100644 index bd505ba283..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowGroupedSpec.scala +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.testkit.{ AkkaSpec, ScriptedTest } - -import scala.collection.immutable -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } - -class FlowGroupedSpec extends AkkaSpec with ScriptedTest { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 1, maxSize = 16) - - "A Grouped" must { - - "group evenly" in { - def script = Script((1 to 20) map { _ ⇒ val x, y, z = random.nextInt(); Seq(x, y, z) -> Seq(immutable.Seq(x, y, z)) }: _*) - (1 to 30) foreach (_ ⇒ runScript(script, settings)(_.grouped(3))) - } - - "group with rest" in { - def script = Script(((1 to 20).map { _ ⇒ val x, y, z = random.nextInt(); Seq(x, y, z) -> Seq(immutable.Seq(x, y, z)) } - :+ { val x = random.nextInt(); Seq(x) -> Seq(immutable.Seq(x)) }): _*) - (1 to 30) foreach (_ ⇒ runScript(script, settings)(_.grouped(3))) - } - - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowGroupedWithinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowGroupedWithinSpec.scala deleted file mode 100644 index 451334aa16..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowGroupedWithinSpec.scala +++ /dev/null @@ -1,139 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import scala.collection.immutable -import scala.concurrent.duration._ -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit -import akka.stream.scaladsl.Flow -import akka.stream.testkit.ScriptedTest - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowGroupedWithinSpec extends AkkaSpec with ScriptedTest { - - val settings = MaterializerSettings(system) - - implicit val materializer = FlowMaterializer() - - "A GroupedWithin" must { - - "group elements within the duration" in { - val input = Iterator.from(1) - val p = StreamTestKit.PublisherProbe[Int]() - val c = StreamTestKit.SubscriberProbe[immutable.Seq[Int]]() - Flow(p).groupedWithin(1000, 1.second).produceTo(c) - val pSub = p.expectSubscription() - val cSub = c.expectSubscription() - cSub.request(100) - val demand1 = pSub.expectRequest() - (1 to demand1.toInt) foreach { _ ⇒ pSub.sendNext(input.next()) } - val demand2 = pSub.expectRequest() - (1 to demand2.toInt) foreach { _ ⇒ pSub.sendNext(input.next()) } - val demand3 = pSub.expectRequest() - c.expectNext((1 to (demand1 + demand2).toInt).toVector) - (1 to demand3.toInt) foreach { _ ⇒ pSub.sendNext(input.next()) } - c.expectNoMsg(300.millis) - c.expectNext(((demand1 + demand2 + 1).toInt to (demand1 + demand2 + demand3).toInt).toVector) - c.expectNoMsg(300.millis) - pSub.expectRequest() - val last = input.next() - pSub.sendNext(last) - pSub.sendComplete() - c.expectNext(List(last)) - c.expectComplete() - c.expectNoMsg(200.millis) - } - - "deliver bufferd elements onComplete before the timeout" in { - val c = StreamTestKit.SubscriberProbe[immutable.Seq[Int]]() - Flow(1 to 3).groupedWithin(1000, 10.second).produceTo(c) - val cSub = c.expectSubscription() - cSub.request(100) - c.expectNext((1 to 3).toList) - c.expectComplete() - c.expectNoMsg(200.millis) - } - - "buffer groups until requested from downstream" in { - val input = Iterator.from(1) - val p = StreamTestKit.PublisherProbe[Int]() - val c = StreamTestKit.SubscriberProbe[immutable.Seq[Int]]() - Flow(p).groupedWithin(1000, 1.second).produceTo(c) - val pSub = p.expectSubscription() - val cSub = c.expectSubscription() - cSub.request(1) - val demand1 = pSub.expectRequest() - (1 to demand1.toInt) foreach { _ ⇒ pSub.sendNext(input.next()) } - c.expectNext((1 to demand1.toInt).toVector) - val demand2 = pSub.expectRequest() - (1 to demand2.toInt) foreach { _ ⇒ pSub.sendNext(input.next()) } - c.expectNoMsg(300.millis) - cSub.request(1) - c.expectNext(((demand1 + 1).toInt to (demand1 + demand2).toInt).toVector) - pSub.sendComplete() - c.expectComplete() - c.expectNoMsg(100.millis) - } - - "drop empty groups" in { - val p = StreamTestKit.PublisherProbe[Int]() - val c = StreamTestKit.SubscriberProbe[immutable.Seq[Int]]() - Flow(p).groupedWithin(1000, 500.millis).produceTo(c) - val pSub = p.expectSubscription() - val cSub = c.expectSubscription() - cSub.request(2) - pSub.expectRequest() - c.expectNoMsg(600.millis) - pSub.sendNext(1) - pSub.sendNext(2) - c.expectNext(List(1, 2)) - // nothing more requested - c.expectNoMsg(1100.millis) - cSub.request(3) - c.expectNoMsg(600.millis) - pSub.sendComplete() - c.expectComplete() - c.expectNoMsg(100.millis) - } - - "reset time window when max elements reached" in { - val input = Iterator.from(1) - val p = StreamTestKit.PublisherProbe[Int]() - val c = StreamTestKit.SubscriberProbe[immutable.Seq[Int]]() - Flow(p).groupedWithin(3, 2.second).produceTo(c) - val pSub = p.expectSubscription() - val cSub = c.expectSubscription() - cSub.request(4) - val demand1 = pSub.expectRequest() - demand1 should be(4) - c.expectNoMsg(1000.millis) - (1 to demand1.toInt) foreach { _ ⇒ pSub.sendNext(input.next()) } - c.probe.within(1000.millis) { - c.expectNext((1 to 3).toVector) - } - c.expectNoMsg(1500.millis) - c.probe.within(1000.millis) { - c.expectNext(List(4)) - } - pSub.sendComplete() - c.expectComplete() - c.expectNoMsg(100.millis) - } - - "group evenly" in { - def script = Script((1 to 20) map { _ ⇒ val x, y, z = random.nextInt(); Seq(x, y, z) -> Seq(immutable.Seq(x, y, z)) }: _*) - (1 to 30) foreach (_ ⇒ runScript(script, settings)(_.groupedWithin(3, 10.minutes))) - } - - "group with rest" in { - def script = Script(((1 to 20).map { _ ⇒ val x, y, z = random.nextInt(); Seq(x, y, z) -> Seq(immutable.Seq(x, y, z)) } - :+ { val x = random.nextInt(); Seq(x) -> Seq(immutable.Seq(x)) }): _*) - (1 to 30) foreach (_ ⇒ runScript(script, settings)(_.groupedWithin(3, 10.minutes))) - } - - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowIterableSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowIterableSpec.scala deleted file mode 100644 index 8831561b32..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowIterableSpec.scala +++ /dev/null @@ -1,155 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } -import akka.stream.testkit.StreamTestKit.{ OnComplete, OnError, OnNext } - -import scala.concurrent.duration._ - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowIterableSpec extends AkkaSpec { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 512) - - implicit val materializer = FlowMaterializer(settings) - - "A Flow based on an iterable" must { - "produce elements" in { - val p = Flow(List(1, 2, 3)).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - val sub = c.expectSubscription() - sub.request(1) - c.expectNext(1) - c.expectNoMsg(100.millis) - sub.request(2) - c.expectNext(2) - c.expectNext(3) - c.expectComplete() - } - - "complete empty" in { - val p = Flow(List.empty[Int]).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - c.expectComplete() - c.expectNoMsg(100.millis) - - val c2 = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c2) - c2.expectComplete() - } - - "produce elements with multiple subscribers" in { - val p = Flow(List(1, 2, 3)).toPublisher() - val c1 = StreamTestKit.SubscriberProbe[Int]() - val c2 = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c1) - p.subscribe(c2) - val sub1 = c1.expectSubscription() - val sub2 = c2.expectSubscription() - sub1.request(1) - sub2.request(2) - c1.expectNext(1) - c2.expectNext(1) - c2.expectNext(2) - c1.expectNoMsg(100.millis) - c2.expectNoMsg(100.millis) - sub1.request(2) - sub2.request(2) - c1.expectNext(2) - c1.expectNext(3) - c2.expectNext(3) - c1.expectComplete() - c2.expectComplete() - } - - "produce elements to later subscriber" in { - val p = Flow(List(1, 2, 3)).toPublisher() - val c1 = StreamTestKit.SubscriberProbe[Int]() - val c2 = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c1) - - val sub1 = c1.expectSubscription() - sub1.request(1) - c1.expectNext(1) - c1.expectNoMsg(100.millis) - p.subscribe(c2) - val sub2 = c2.expectSubscription() - sub2.request(2) - // starting from first element, new iterator per subscriber - c2.expectNext(1) - c2.expectNext(2) - c2.expectNoMsg(100.millis) - sub2.request(1) - c2.expectNext(3) - c2.expectComplete() - sub1.request(2) - c1.expectNext(2) - c1.expectNext(3) - c1.expectComplete() - } - - "produce elements with one transformation step" in { - val p = Flow(List(1, 2, 3)).map(_ * 2).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - val sub = c.expectSubscription() - sub.request(10) - c.expectNext(2) - c.expectNext(4) - c.expectNext(6) - c.expectComplete() - } - - "produce elements with two transformation steps" in { - val p = Flow(List(1, 2, 3, 4)).filter(_ % 2 == 0).map(_ * 2).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - val sub = c.expectSubscription() - sub.request(10) - c.expectNext(4) - c.expectNext(8) - c.expectComplete() - } - - "allow cancel before receiving all elements" in { - val count = 100000 - val p = Flow(1 to count).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - val sub = c.expectSubscription() - sub.request(count) - c.expectNext(1) - sub.cancel() - val got = c.probe.receiveWhile(3.seconds) { - case _: OnNext[_] ⇒ - case OnComplete ⇒ fail("Cancel expected before OnComplete") - case OnError(e) ⇒ fail(e) - } - got.size should be < (count - 1) - } - - "have value equality of publisher" in { - val p1 = Flow(List(1, 2, 3)).toPublisher() - val p2 = Flow(List(1, 2, 3)).toPublisher() - p1 should be(p2) - p2 should be(p1) - val p3 = Flow(List(1, 2, 3, 4)).toPublisher() - p1 should not be (p3) - p3 should not be (p1) - val p4 = Flow(Vector.empty[String]).toPublisher() - val p5 = Flow(Set.empty[String]).toPublisher() - p1 should not be (p4) - p4 should be(p5) - p5 should be(p4) - val p6 = Flow(List(1, 2, 3).iterator).toPublisher() - p1 should not be (p6) - p6 should not be (p1) - } - } -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowIteratorSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowIteratorSpec.scala deleted file mode 100644 index 0d3fe5d080..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowIteratorSpec.scala +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import scala.concurrent.duration._ -import akka.stream.testkit.StreamTestKit -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit.OnNext -import akka.stream.testkit.StreamTestKit.OnComplete -import akka.stream.testkit.StreamTestKit.OnError -import akka.stream.scaladsl.Flow - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowIteratorSpec extends AkkaSpec { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 2) - .withFanOutBuffer(initialSize = 4, maxSize = 4) - - implicit val materializer = FlowMaterializer(settings) - - "A Flow based on an iterator" must { - "produce elements" in { - val p = Flow(List(1, 2, 3).iterator).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - val sub = c.expectSubscription() - sub.request(1) - c.expectNext(1) - c.expectNoMsg(100.millis) - sub.request(3) - c.expectNext(2) - c.expectNext(3) - c.expectComplete() - } - - "complete empty" in { - val p = Flow(List.empty[Int].iterator).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - c.expectComplete() - c.expectNoMsg(100.millis) - - val c2 = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c2) - c2.expectComplete() - } - - "produce elements with multiple subscribers" in { - val p = Flow(List(1, 2, 3).iterator).toPublisher() - val c1 = StreamTestKit.SubscriberProbe[Int]() - val c2 = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c1) - p.subscribe(c2) - val sub1 = c1.expectSubscription() - val sub2 = c2.expectSubscription() - sub1.request(1) - sub2.request(2) - c1.expectNext(1) - c2.expectNext(1) - c2.expectNext(2) - c1.expectNoMsg(100.millis) - c2.expectNoMsg(100.millis) - sub1.request(2) - sub2.request(2) - c1.expectNext(2) - c1.expectNext(3) - c2.expectNext(3) - c1.expectComplete() - c2.expectComplete() - } - - "produce elements to later subscriber" in { - val p = Flow(List(1, 2, 3).iterator).toPublisher() - val c1 = StreamTestKit.SubscriberProbe[Int]() - val c2 = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c1) - - val sub1 = c1.expectSubscription() - sub1.request(1) - c1.expectNext(1) - c1.expectNoMsg(100.millis) - p.subscribe(c2) - val sub2 = c2.expectSubscription() - sub2.request(3) - // element 1 is already gone - c2.expectNext(2) - c2.expectNext(3) - c2.expectComplete() - sub1.request(3) - c1.expectNext(2) - c1.expectNext(3) - c1.expectComplete() - } - - "produce elements with one transformation step" in { - val p = Flow(List(1, 2, 3).iterator).map(_ * 2).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - val sub = c.expectSubscription() - sub.request(10) - c.expectNext(2) - c.expectNext(4) - c.expectNext(6) - c.expectComplete() - } - - "produce elements with two transformation steps" in { - val p = Flow(List(1, 2, 3, 4).iterator).filter(_ % 2 == 0).map(_ * 2).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - val sub = c.expectSubscription() - sub.request(10) - c.expectNext(4) - c.expectNext(8) - c.expectComplete() - } - - "allow cancel before receiving all elements" in { - val count = 100000 - val p = Flow((1 to count).iterator).toPublisher() - val c = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(c) - val sub = c.expectSubscription() - sub.request(count) - c.expectNext(1) - sub.cancel() - val got = c.probe.receiveWhile(3.seconds) { - case _: OnNext[_] ⇒ - case OnComplete ⇒ fail("Cancel expected before OnComplete") - case OnError(e) ⇒ fail(e) - } - got.size should be < (count - 1) - } - - } -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowMapConcatSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowMapConcatSpec.scala deleted file mode 100644 index 7a1bcb7ca9..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowMapConcatSpec.scala +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.testkit.{ AkkaSpec, ScriptedTest } - -class FlowMapConcatSpec extends AkkaSpec with ScriptedTest { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 1, maxSize = 16) - - "A MapConcat" must { - - "map and concat" in { - val script = Script( - Seq(0) -> Seq(), - Seq(1) -> Seq(1), - Seq(2) -> Seq(2, 2), - Seq(3) -> Seq(3, 3, 3), - Seq(2) -> Seq(2, 2), - Seq(1) -> Seq(1)) - (1 to 100) foreach (_ ⇒ runScript(script, settings)(_.mapConcat(x ⇒ (1 to x) map (_ ⇒ x)))) - } - - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowMapFutureSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowMapFutureSpec.scala deleted file mode 100644 index bad853cf64..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowMapFutureSpec.scala +++ /dev/null @@ -1,113 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import scala.concurrent.Future -import scala.concurrent.duration._ -import scala.concurrent.forkjoin.ThreadLocalRandom -import scala.util.control.NoStackTrace -import akka.stream.scaladsl.Flow -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit -import akka.testkit.TestProbe -import akka.testkit.TestLatch -import scala.concurrent.Await - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowMapFutureSpec extends AkkaSpec { - - implicit val materializer = FlowMaterializer() - - "A Flow with mapFuture" must { - - "produce future elements" in { - val c = StreamTestKit.SubscriberProbe[Int]() - implicit val ec = system.dispatcher - val p = Flow(1 to 3).mapFuture(n ⇒ Future(n)).produceTo(c) - val sub = c.expectSubscription() - sub.request(2) - c.expectNext(1) - c.expectNext(2) - c.expectNoMsg(200.millis) - sub.request(2) - c.expectNext(3) - c.expectComplete() - } - - "produce future elements in order" in { - val c = StreamTestKit.SubscriberProbe[Int]() - implicit val ec = system.dispatcher - val p = Flow(1 to 50).mapFuture(n ⇒ Future { - Thread.sleep(ThreadLocalRandom.current().nextInt(1, 10)) - n - }).produceTo(c) - val sub = c.expectSubscription() - sub.request(1000) - for (n ← 1 to 50) c.expectNext(n) - c.expectComplete() - } - - "not run more futures than requested elements" in { - val probe = TestProbe() - val c = StreamTestKit.SubscriberProbe[Int]() - implicit val ec = system.dispatcher - val p = Flow(1 to 20).mapFuture(n ⇒ Future { - probe.ref ! n - n - }).produceTo(c) - val sub = c.expectSubscription() - // nothing before requested - probe.expectNoMsg(500.millis) - sub.request(1) - probe.expectMsg(1) - probe.expectNoMsg(500.millis) - sub.request(2) - probe.receiveN(2).toSet should be(Set(2, 3)) - probe.expectNoMsg(500.millis) - sub.request(10) - probe.receiveN(10).toSet should be((4 to 13).toSet) - probe.expectNoMsg(200.millis) - - for (n ← 1 to 13) c.expectNext(n) - c.expectNoMsg(200.millis) - } - - "signal future failure" in { - val latch = TestLatch(1) - val c = StreamTestKit.SubscriberProbe[Int]() - implicit val ec = system.dispatcher - val p = Flow(1 to 5).mapFuture(n ⇒ Future { - if (n == 3) throw new RuntimeException("err1") with NoStackTrace - else { - Await.ready(latch, 10.seconds) - n - } - }).produceTo(c) - val sub = c.expectSubscription() - sub.request(10) - c.expectError.getMessage should be("err1") - latch.countDown() - } - - "signal error from mapFuture" in { - val latch = TestLatch(1) - val c = StreamTestKit.SubscriberProbe[Int]() - implicit val ec = system.dispatcher - val p = Flow(1 to 5).mapFuture(n ⇒ - if (n == 3) throw new RuntimeException("err2") with NoStackTrace - else { - Future { - Await.ready(latch, 10.seconds) - n - } - }). - produceTo(c) - val sub = c.expectSubscription() - sub.request(10) - c.expectError.getMessage should be("err2") - latch.countDown() - } - - } -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowMapSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowMapSpec.scala deleted file mode 100644 index 8edb0c2762..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowMapSpec.scala +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, ScriptedTest, StreamTestKit } - -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } - -class FlowMapSpec extends AkkaSpec with ScriptedTest { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 1, maxSize = 16) - - implicit val materializer = FlowMaterializer(settings) - - "A Map" must { - - "map" in { - def script = Script((1 to 50) map { _ ⇒ val x = random.nextInt(); Seq(x) -> Seq(x.toString) }: _*) - (1 to 50) foreach (_ ⇒ runScript(script, settings)(_.map(_.toString))) - } - - "not blow up with high request counts" in { - val probe = StreamTestKit.SubscriberProbe[Int]() - Flow(List(1).iterator). - map(_ + 1).map(_ + 1).map(_ + 1).map(_ + 1).map(_ + 1). - toPublisher().subscribe(probe) - - val subscription = probe.expectSubscription() - for (_ ← 1 to 10000) { - subscription.request(Int.MaxValue) - } - - probe.expectNext(6) - probe.expectComplete() - - } - - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowMergeSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowMergeSpec.scala deleted file mode 100644 index 6d5a747d09..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowMergeSpec.scala +++ /dev/null @@ -1,95 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream - -import org.reactivestreams.Publisher - -import scala.concurrent.duration._ -import akka.stream.testkit.StreamTestKit -import akka.stream.testkit.AkkaSpec -import akka.stream.scaladsl.Flow - -class FlowMergeSpec extends TwoStreamsSetup { - - type Outputs = Int - override def operationUnderTest(in1: Flow[Int], in2: Publisher[Int]) = in1.merge(in2) - - "merge" must { - - "work in the happy case" in { - // Different input sizes (4 and 6) - val source1 = Flow((1 to 4).iterator).toPublisher() - val source2 = Flow((5 to 10).iterator).toPublisher() - val source3 = Flow(List.empty[Int].iterator).toPublisher() - val p = Flow(source1).merge(source2).merge(source3).toPublisher() - - val probe = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(probe) - val subscription = probe.expectSubscription() - - var collected = Set.empty[Int] - for (_ ← 1 to 10) { - subscription.request(1) - collected += probe.expectNext() - } - - collected should be(Set(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) - probe.expectComplete() - } - - commonTests() - - "work with one immediately completed and one nonempty publisher" in { - val subscriber1 = setup(completedPublisher, nonemptyPublisher((1 to 4).iterator)) - val subscription1 = subscriber1.expectSubscription() - subscription1.request(4) - subscriber1.expectNext(1) - subscriber1.expectNext(2) - subscriber1.expectNext(3) - subscriber1.expectNext(4) - subscriber1.expectComplete() - - val subscriber2 = setup(nonemptyPublisher((1 to 4).iterator), completedPublisher) - val subscription2 = subscriber2.expectSubscription() - subscription2.request(4) - subscriber2.expectNext(1) - subscriber2.expectNext(2) - subscriber2.expectNext(3) - subscriber2.expectNext(4) - subscriber2.expectComplete() - } - - "work with one delayed completed and one nonempty publisher" in { - val subscriber1 = setup(soonToCompletePublisher, nonemptyPublisher((1 to 4).iterator)) - val subscription1 = subscriber1.expectSubscription() - subscription1.request(4) - subscriber1.expectNext(1) - subscriber1.expectNext(2) - subscriber1.expectNext(3) - subscriber1.expectNext(4) - subscriber1.expectComplete() - - val subscriber2 = setup(nonemptyPublisher((1 to 4).iterator), soonToCompletePublisher) - val subscription2 = subscriber2.expectSubscription() - subscription2.request(4) - subscriber2.expectNext(1) - subscriber2.expectNext(2) - subscriber2.expectNext(3) - subscriber2.expectNext(4) - subscriber2.expectComplete() - } - - "work with one immediately failed and one nonempty publisher" in { - // This is nondeterministic, multiple scenarios can happen - pending - } - - "work with one delayed failed and one nonempty publisher" in { - // This is nondeterministic, multiple scenarios can happen - pending - } - - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowOnCompleteSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowOnCompleteSpec.scala deleted file mode 100644 index 9a50190cea..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowOnCompleteSpec.scala +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, ScriptedTest, StreamTestKit } -import akka.testkit.TestProbe - -import scala.concurrent.duration._ -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } -import scala.util.control.NoStackTrace -import scala.util.{ Failure, Success } - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowOnCompleteSpec extends AkkaSpec with ScriptedTest { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 1, maxSize = 16) - - implicit val materializer = FlowMaterializer(settings) - - "A Flow with onComplete" must { - - "invoke callback on normal completion" in { - val onCompleteProbe = TestProbe() - val p = StreamTestKit.PublisherProbe[Int]() - Flow(p).onComplete { onCompleteProbe.ref ! _ } - val proc = p.expectSubscription - proc.expectRequest() - proc.sendNext(42) - onCompleteProbe.expectNoMsg(100.millis) - proc.sendComplete() - onCompleteProbe.expectMsg(Success(())) - } - - "yield the first error" in { - val onCompleteProbe = TestProbe() - val p = StreamTestKit.PublisherProbe[Int]() - Flow(p).onComplete { onCompleteProbe.ref ! _ } - val proc = p.expectSubscription - proc.expectRequest() - val ex = new RuntimeException("ex") with NoStackTrace - proc.sendError(ex) - onCompleteProbe.expectMsg(Failure(ex)) - onCompleteProbe.expectNoMsg(100.millis) - } - - "invoke callback for an empty stream" in { - val onCompleteProbe = TestProbe() - val p = StreamTestKit.PublisherProbe[Int]() - Flow(p).onComplete { onCompleteProbe.ref ! _ } - val proc = p.expectSubscription - proc.expectRequest() - proc.sendComplete() - onCompleteProbe.expectMsg(Success(())) - onCompleteProbe.expectNoMsg(100.millis) - } - - "invoke callback after transform and foreach steps " in { - val onCompleteProbe = TestProbe() - val p = StreamTestKit.PublisherProbe[Int]() - import system.dispatcher // for the Future.onComplete - Flow(p).map { x ⇒ - onCompleteProbe.ref ! ("map-" + x) - x - }.foreach { - x ⇒ onCompleteProbe.ref ! ("foreach-" + x) - }.onComplete { onCompleteProbe.ref ! _ } - val proc = p.expectSubscription - proc.expectRequest() - proc.sendNext(42) - proc.sendComplete() - onCompleteProbe.expectMsg("map-42") - onCompleteProbe.expectMsg("foreach-42") - onCompleteProbe.expectMsg(Success(())) - } - - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowPrefixAndTailSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowPrefixAndTailSpec.scala deleted file mode 100644 index 291e8e1593..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowPrefixAndTailSpec.scala +++ /dev/null @@ -1,152 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.impl.EmptyPublisher -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } -import org.reactivestreams.Publisher - -import scala.concurrent.Await -import scala.concurrent.duration._ -import scala.util.control.NoStackTrace - -class FlowPrefixAndTailSpec extends AkkaSpec { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 2) - .withFanOutBuffer(initialSize = 2, maxSize = 2) - - implicit val materializer = FlowMaterializer(settings) - - "PrefixAndTail" must { - - val testException = new Exception("test") with NoStackTrace - - "work on empty input" in { - Await.result(Flow(Nil).prefixAndTail(10).toFuture(), 3.seconds) should be((Nil, EmptyPublisher)) - } - - "work on short input" in { - Await.result(Flow(List(1, 2, 3)).prefixAndTail(10).toFuture(), 3.seconds) should be((List(1, 2, 3), EmptyPublisher)) - } - - "work on longer inputs" in { - val (takes, tail) = Await.result(Flow((1 to 10).iterator).prefixAndTail(5).toFuture(), 3.seconds) - takes should be(1 to 5) - Await.result(Flow(tail).grouped(6).toFuture(), 3.seconds) should be(6 to 10) - } - - "handle zero take count" in { - val (takes, tail) = Await.result(Flow((1 to 10).iterator).prefixAndTail(0).toFuture(), 3.seconds) - takes should be(Nil) - Await.result(Flow(tail).grouped(11).toFuture(), 3.seconds) should be(1 to 10) - } - - "handle negative take count" in { - val (takes, tail) = Await.result(Flow((1 to 10).iterator).prefixAndTail(-1).toFuture(), 3.seconds) - takes should be(Nil) - Await.result(Flow(tail).grouped(11).toFuture(), 3.seconds) should be(1 to 10) - } - - "work if size of take is equal to stream size" in { - val (takes, tail) = Await.result(Flow((1 to 10).iterator).prefixAndTail(10).toFuture(), 3.seconds) - takes should be(1 to 10) - val subscriber = StreamTestKit.SubscriberProbe[Int]() - Flow(tail).produceTo(subscriber) - subscriber.expectCompletedOrSubscriptionFollowedByComplete() - } - - "handle onError when no substream open" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[(Seq[Int], Publisher[Int])]() - - Flow(publisher).prefixAndTail(3).produceTo(subscriber) - - val upstream = publisher.expectSubscription() - val downstream = subscriber.expectSubscription() - - downstream.request(1) - - upstream.expectRequest() - upstream.sendNext(1) - upstream.sendError(testException) - - subscriber.expectError(testException) - } - - "handle onError when substream is open" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[(Seq[Int], Publisher[Int])]() - - Flow(publisher).prefixAndTail(1).produceTo(subscriber) - - val upstream = publisher.expectSubscription() - val downstream = subscriber.expectSubscription() - - downstream.request(1000) - - upstream.expectRequest() - upstream.sendNext(1) - - val (head, tail) = subscriber.expectNext() - head should be(List(1)) - subscriber.expectComplete() - - val substreamSubscriber = StreamTestKit.SubscriberProbe[Int]() - Flow(tail).produceTo(substreamSubscriber) - substreamSubscriber.expectSubscription() - - upstream.sendError(testException) - substreamSubscriber.expectError(testException) - - } - - "handle master stream cancellation" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[(Seq[Int], Publisher[Int])]() - - Flow(publisher).prefixAndTail(3).produceTo(subscriber) - - val upstream = publisher.expectSubscription() - val downstream = subscriber.expectSubscription() - - downstream.request(1) - - upstream.expectRequest() - upstream.sendNext(1) - - downstream.cancel() - upstream.expectCancellation() - } - - "handle substream cancellation" in { - val publisher = StreamTestKit.PublisherProbe[Int]() - val subscriber = StreamTestKit.SubscriberProbe[(Seq[Int], Publisher[Int])]() - - Flow(publisher).prefixAndTail(1).produceTo(subscriber) - - val upstream = publisher.expectSubscription() - val downstream = subscriber.expectSubscription() - - downstream.request(1000) - - upstream.expectRequest() - upstream.sendNext(1) - - val (head, tail) = subscriber.expectNext() - head should be(List(1)) - subscriber.expectComplete() - - val substreamSubscriber = StreamTestKit.SubscriberProbe[Int]() - Flow(tail).produceTo(substreamSubscriber) - substreamSubscriber.expectSubscription().cancel() - - upstream.expectCancellation() - - } - - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowProduceToSubscriberSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowProduceToSubscriberSpec.scala deleted file mode 100644 index 57efdd25d9..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowProduceToSubscriberSpec.scala +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit - -class FlowProduceToSubscriberSpec extends AkkaSpec { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 1, maxSize = 16) - - implicit val materializer = FlowMaterializer(settings) - - "A Flow with toPublisher" must { - - "produce elements to the subscriber" in { - val c = StreamTestKit.SubscriberProbe[Int]() - Flow(List(1, 2, 3)).produceTo(c) - val s = c.expectSubscription() - s.request(3) - c.expectNext(1) - c.expectNext(2) - c.expectNext(3) - c.expectComplete() - } - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowSpec.scala deleted file mode 100644 index ff9c9666bf..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowSpec.scala +++ /dev/null @@ -1,335 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, ChainSetup, StreamTestKit } -import akka.testkit._ -import com.typesafe.config.ConfigFactory -import org.reactivestreams.Publisher - -import scala.collection.immutable -import scala.concurrent.duration._ - -object FlowSpec { - class Fruit - class Apple extends Fruit -} - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug.receive=off\nakka.loglevel=INFO")) { - import FlowSpec._ - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 1, maxSize = 16) - - implicit val mat = FlowMaterializer(settings) - - val identity: Flow[Any] ⇒ Flow[Any] = in ⇒ in.map(e ⇒ e) - val identity2: Flow[Any] ⇒ Flow[Any] = in ⇒ identity(in) - def identityWithFanout(initialBufferSize: Int, maximumBufferSize: Int): Flow[Any] ⇒ Flow[Any] = - in ⇒ in.fanout(initialBufferSize, maximumBufferSize) - - "A Flow" must { - - for ((name, op) ← List("identity" -> identity, "identity2" -> identity2); n ← List(1, 2, 4)) { - s"requests initial elements from upstream ($name, $n)" in { - new ChainSetup(op, settings.withInputBuffer(initialSize = n, maxSize = settings.maxInputBufferSize)) { - upstream.expectRequest(upstreamSubscription, settings.initialInputBufferSize) - } - } - } - - "requests more elements from upstream when downstream requests more elements" in { - new ChainSetup(identity, settings) { - upstream.expectRequest(upstreamSubscription, settings.initialInputBufferSize) - downstreamSubscription.request(1) - upstream.expectNoMsg(100.millis) - downstreamSubscription.request(2) - upstream.expectNoMsg(100.millis) - upstreamSubscription.sendNext("a") - downstream.expectNext("a") - upstream.expectRequest(upstreamSubscription, 1) - upstream.expectNoMsg(100.millis) - upstreamSubscription.sendNext("b") - upstreamSubscription.sendNext("c") - upstreamSubscription.sendNext("d") - downstream.expectNext("b") - downstream.expectNext("c") - } - } - - "deliver events when publisher sends elements and then completes" in { - new ChainSetup(identity, settings) { - downstreamSubscription.request(1) - upstreamSubscription.sendNext("test") - upstreamSubscription.sendComplete() - downstream.expectNext("test") - downstream.expectComplete() - } - } - - "deliver complete signal when publisher immediately completes" in { - new ChainSetup(identity, settings) { - upstreamSubscription.sendComplete() - downstream.expectComplete() - } - } - - "deliver error signal when publisher immediately fails" in { - new ChainSetup(identity, settings) { - object WeirdError extends RuntimeException("weird test exception") - EventFilter[WeirdError.type](occurrences = 1) intercept { - upstreamSubscription.sendError(WeirdError) - downstream.expectError(WeirdError) - } - } - } - - "single subscriber cancels subscription while receiving data" in { - new ChainSetup(identity, settings.withInputBuffer(initialSize = 1, maxSize = settings.maxInputBufferSize)) { - downstreamSubscription.request(5) - upstreamSubscription.expectRequest(1) - upstreamSubscription.sendNext("test") - upstreamSubscription.expectRequest(1) - upstreamSubscription.sendNext("test2") - upstreamSubscription.expectRequest(1) - downstream.expectNext("test") - downstream.expectNext("test2") - downstreamSubscription.cancel() - - // because of the "must cancel its upstream Subscription if its last downstream Subscription has been cancelled" rule - upstreamSubscription.expectCancellation() - } - } - - } - - "A Flow with multiple subscribers (FanOutBox)" must { - "adapt speed to the currently slowest subscriber" in { - new ChainSetup(identityWithFanout(initialBufferSize = 1, maximumBufferSize = 1), settings.copy(initialInputBufferSize = 1)) { - val downstream2 = StreamTestKit.SubscriberProbe[Any]() - publisher.subscribe(downstream2) - val downstream2Subscription = downstream2.expectSubscription() - - downstreamSubscription.request(5) - upstream.expectRequest(upstreamSubscription, 1) // because initialInputBufferSize=1 - - upstreamSubscription.sendNext("firstElement") - downstream.expectNext("firstElement") - - upstream.expectRequest(upstreamSubscription, 1) - upstreamSubscription.sendNext("element2") - - downstream.expectNoMsg(1.second) - downstream2Subscription.request(1) - downstream2.expectNext("firstElement") - - downstream.expectNext("element2") - - downstream2Subscription.request(1) - downstream2.expectNext("element2") - } - } - - "support slow subscriber with fan-out 2" in { - new ChainSetup(identityWithFanout(initialBufferSize = 2, maximumBufferSize = 2), settings.copy(initialInputBufferSize = 1)) { - val downstream2 = StreamTestKit.SubscriberProbe[Any]() - publisher.subscribe(downstream2) - val downstream2Subscription = downstream2.expectSubscription() - - downstreamSubscription.request(5) - - upstream.expectRequest(upstreamSubscription, 1) // because initialInputBufferSize=1 - upstreamSubscription.sendNext("element1") - downstream.expectNext("element1") - upstreamSubscription.expectRequest(1) - upstreamSubscription.sendNext("element2") - downstream.expectNext("element2") - upstreamSubscription.expectRequest(1) - upstreamSubscription.sendNext("element3") - // downstream2 has not requested anything, fan-out buffer 2 - downstream.expectNoMsg(100.millis.dilated) - - downstream2Subscription.request(2) - downstream.expectNext("element3") - downstream2.expectNext("element1") - downstream2.expectNext("element2") - downstream2.expectNoMsg(100.millis.dilated) - - upstreamSubscription.expectRequest(1) - upstreamSubscription.sendNext("element4") - downstream.expectNext("element4") - - downstream2Subscription.request(2) - downstream2.expectNext("element3") - downstream2.expectNext("element4") - - upstreamSubscription.sendComplete() - downstream.expectComplete() - downstream2.expectComplete() - } - } - - "incoming subscriber while elements were requested before" in { - new ChainSetup(identityWithFanout(initialBufferSize = 1, maximumBufferSize = 1), settings.copy(initialInputBufferSize = 1)) { - downstreamSubscription.request(5) - upstream.expectRequest(upstreamSubscription, 1) - upstreamSubscription.sendNext("a1") - downstream.expectNext("a1") - - upstream.expectRequest(upstreamSubscription, 1) - upstreamSubscription.sendNext("a2") - downstream.expectNext("a2") - - upstream.expectRequest(upstreamSubscription, 1) - - // link now while an upstream element is already requested - val downstream2 = StreamTestKit.SubscriberProbe[Any]() - publisher.subscribe(downstream2) - val downstream2Subscription = downstream2.expectSubscription() - - // situation here: - // downstream 1 now has 3 outstanding - // downstream 2 has 0 outstanding - - upstreamSubscription.sendNext("a3") - downstream.expectNext("a3") - downstream2.expectNoMsg(100.millis.dilated) // as nothing was requested yet, fanOutBox needs to cache element in this case - - downstream2Subscription.request(1) - downstream2.expectNext("a3") - - // d1 now has 2 outstanding - // d2 now has 0 outstanding - // buffer should be empty so we should be requesting one new element - - upstream.expectRequest(upstreamSubscription, 1) // because of buffer size 1 - } - } - - "blocking subscriber cancels subscription" in { - new ChainSetup(identityWithFanout(initialBufferSize = 1, maximumBufferSize = 1), settings.copy(initialInputBufferSize = 1)) { - val downstream2 = StreamTestKit.SubscriberProbe[Any]() - publisher.subscribe(downstream2) - val downstream2Subscription = downstream2.expectSubscription() - - downstreamSubscription.request(5) - upstreamSubscription.expectRequest(1) - upstreamSubscription.sendNext("firstElement") - downstream.expectNext("firstElement") - - downstream2Subscription.request(1) - downstream2.expectNext("firstElement") - upstreamSubscription.expectRequest(1) - upstreamSubscription.sendNext("element2") - - downstream.expectNext("element2") - upstreamSubscription.expectRequest(1) - upstreamSubscription.sendNext("element3") - downstream2.expectNoMsg(100.millis.dilated) - - downstream.expectNoMsg(200.millis.dilated) - upstream.expectNoMsg(100.millis.dilated) - // should unblock fanoutbox - downstream2Subscription.cancel() - upstreamSubscription.expectRequest(1) - downstream.expectNext("element3") - upstreamSubscription.sendNext("element4") - downstream.expectNext("element4") - - upstreamSubscription.sendComplete() - downstream.expectComplete() - } - } - - "after initial upstream was completed future subscribers' onComplete should be called instead of onSubscribed" in { - new ChainSetup(identityWithFanout(initialBufferSize = 1, maximumBufferSize = 1), settings.copy(initialInputBufferSize = 1)) { - val downstream2 = StreamTestKit.SubscriberProbe[Any]() - // don't link it just yet - - downstreamSubscription.request(5) - upstream.expectRequest(upstreamSubscription, 1) - upstreamSubscription.sendNext("a1") - downstream.expectNext("a1") - - upstream.expectRequest(upstreamSubscription, 1) - upstreamSubscription.sendNext("a2") - downstream.expectNext("a2") - - upstream.expectRequest(upstreamSubscription, 1) - - // link now while an upstream element is already requested - publisher.subscribe(downstream2) - val downstream2Subscription = downstream2.expectSubscription() - - upstreamSubscription.sendNext("a3") - upstreamSubscription.sendComplete() - downstream.expectNext("a3") - downstream.expectComplete() - - downstream2.expectNoMsg(100.millis.dilated) // as nothing was requested yet, fanOutBox needs to cache element in this case - - downstream2Subscription.request(1) - downstream2.expectNext("a3") - downstream2.expectComplete() - - // FIXME when adding a sleep before the following link this will fail with IllegalStateExc shut-down - // what is the expected shutdown behavior? Is the title of this test wrong? - // val downstream3 = StreamTestKit.SubscriberProbe[Any]() - // publisher.subscribe(downstream3) - // downstream3.expectComplete() - } - } - - "after initial upstream reported an error future subscribers' onError should be called instead of onSubscribed" in { - new ChainSetup[Int, String]( - _.map(_ ⇒ throw TestException).fanout(initialBufferSize = 1, maximumBufferSize = 1), settings.copy(initialInputBufferSize = 1)) { - downstreamSubscription.request(1) - upstreamSubscription.expectRequest(1) - - EventFilter[TestException.type](occurrences = 2) intercept { - upstreamSubscription.sendNext(5) - upstreamSubscription.expectRequest(1) - upstreamSubscription.expectCancellation() - downstream.expectError(TestException) - } - - val downstream2 = StreamTestKit.SubscriberProbe[String]() - publisher.subscribe(downstream2) - downstream2.expectError() should be(TestException) - } - } - - "when all subscriptions were cancelled future subscribers' onError should be called" in { - new ChainSetup(identityWithFanout(initialBufferSize = 1, maximumBufferSize = 16), settings.copy(initialInputBufferSize = 1)) { - upstreamSubscription.expectRequest(1) - downstreamSubscription.cancel() - upstreamSubscription.expectCancellation() - - val downstream2 = StreamTestKit.SubscriberProbe[Any]() - publisher.subscribe(downstream2) - // IllegalStateException shut down - downstream2.expectError().isInstanceOf[IllegalStateException] should be(true) - } - } - - "if an internal error occurs upstream should be cancelled" in pending - "if an internal error occurs subscribers' onError method should be called" in pending - "if an internal error occurs future subscribers' onError should be called instead of onSubscribed" in pending - - "be covariant" in { - val f1: Flow[Fruit] = Flow(() ⇒ Some(new Apple)) - val p1: Publisher[Fruit] = Flow(() ⇒ Some(new Apple)).toPublisher() - val f2: Flow[Publisher[Fruit]] = Flow(() ⇒ Some(new Apple)).splitWhen(_ ⇒ true) - val f3: Flow[(Boolean, Publisher[Fruit])] = Flow(() ⇒ Some(new Apple)).groupBy(_ ⇒ true) - val f4: Flow[(immutable.Seq[Apple], Publisher[Fruit])] = Flow(() ⇒ Some(new Apple)).prefixAndTail(1) - } - - } - - object TestException extends RuntimeException - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowSplitWhenSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowSplitWhenSpec.scala deleted file mode 100644 index 894739e53b..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowSplitWhenSpec.scala +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream - -import scala.concurrent.duration._ -import akka.stream.testkit.StreamTestKit -import akka.stream.testkit.AkkaSpec -import org.reactivestreams.Publisher -import akka.stream.scaladsl.Flow - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowSplitWhenSpec extends AkkaSpec { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 2) - .withFanOutBuffer(initialSize = 2, maxSize = 2) - - implicit val materializer = FlowMaterializer(settings) - - case class StreamPuppet(p: Publisher[Int]) { - val probe = StreamTestKit.SubscriberProbe[Int]() - p.subscribe(probe) - val subscription = probe.expectSubscription() - - def request(demand: Long): Unit = subscription.request(demand) - def expectNext(elem: Int): Unit = probe.expectNext(elem) - def expectNoMsg(max: FiniteDuration): Unit = probe.expectNoMsg(max) - def expectComplete(): Unit = probe.expectComplete() - def cancel(): Unit = subscription.cancel() - } - - class SubstreamsSupport(splitWhen: Int = 3, elementCount: Int = 6) { - val source = Flow((1 to elementCount).iterator).toPublisher() - val groupStream = Flow(source).splitWhen(_ == splitWhen).toPublisher() - val masterSubscriber = StreamTestKit.SubscriberProbe[Publisher[Int]]() - - groupStream.subscribe(masterSubscriber) - val masterSubscription = masterSubscriber.expectSubscription() - - def getSubPublisher(): Publisher[Int] = { - masterSubscription.request(1) - expectSubPublisher() - } - - def expectSubPublisher(): Publisher[Int] = { - val substream = masterSubscriber.expectNext() - substream - } - - } - - "splitWhen" must { - - "work in the happy case" in new SubstreamsSupport(elementCount = 4) { - val s1 = StreamPuppet(getSubPublisher()) - masterSubscriber.expectNoMsg(100.millis) - - s1.request(2) - s1.expectNext(1) - s1.expectNext(2) - s1.request(1) - s1.expectComplete() - - val s2 = StreamPuppet(getSubPublisher()) - - s2.request(1) - s2.expectNext(3) - s2.expectNoMsg(100.millis) - - s2.request(1) - s2.expectNext(4) - s2.request(1) - s2.expectComplete() - - masterSubscriber.expectComplete() - } - - "support cancelling substreams" in new SubstreamsSupport(splitWhen = 5, elementCount = 8) { - val s1 = StreamPuppet(getSubPublisher()) - s1.cancel() - val s2 = StreamPuppet(getSubPublisher()) - - s2.request(4) - s2.expectNext(5) - s2.expectNext(6) - s2.expectNext(7) - s2.expectNext(8) - s2.request(1) - s2.expectComplete() - - masterSubscription.request(1) - masterSubscriber.expectComplete() - } - - "support cancelling the master stream" in new SubstreamsSupport(splitWhen = 5, elementCount = 8) { - val s1 = StreamPuppet(getSubPublisher()) - masterSubscription.cancel() - s1.request(4) - s1.expectNext(1) - s1.expectNext(2) - s1.expectNext(3) - s1.expectNext(4) - s1.request(1) - s1.expectComplete() - } - - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowTakeSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowTakeSpec.scala deleted file mode 100644 index 391e16ef0d..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowTakeSpec.scala +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.actor.ActorSubscriberMessage.OnComplete -import akka.stream.actor.ActorSubscriberMessage.OnNext -import akka.stream.impl.RequestMore -import akka.stream.scaladsl.Flow -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.ScriptedTest -import akka.stream.testkit.StreamTestKit - -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } - -class FlowTakeSpec extends AkkaSpec with ScriptedTest { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 1, maxSize = 16) - - implicit val materializer = FlowMaterializer(settings) - - muteDeadLetters(classOf[OnNext], OnComplete.getClass, classOf[RequestMore])() - - "A Take" must { - - "take" in { - def script(d: Int) = Script((1 to 50) map { n ⇒ Seq(n) -> (if (n > d) Nil else Seq(n)) }: _*) - (1 to 50) foreach { _ ⇒ - val d = Math.min(Math.max(random.nextInt(-10, 60), 0), 50) - runScript(script(d), settings)(_.take(d)) - } - } - - "not take anything for negative n" in { - val probe = StreamTestKit.SubscriberProbe[Int]() - Flow(List(1, 2, 3)).take(-1).produceTo(probe) - probe.expectSubscription().request(10) - probe.expectComplete() - } - - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowTakeWithinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowTakeWithinSpec.scala deleted file mode 100644 index 0201520e78..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowTakeWithinSpec.scala +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import scala.concurrent.duration._ -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit -import akka.stream.scaladsl.Flow - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowTakeWithinSpec extends AkkaSpec { - - implicit val materializer = FlowMaterializer() - - "A TakeWithin" must { - - "deliver elements within the duration, but not afterwards" in { - val input = Iterator.from(1) - val p = StreamTestKit.PublisherProbe[Int]() - val c = StreamTestKit.SubscriberProbe[Int]() - Flow(p).takeWithin(1.second).produceTo(c) - val pSub = p.expectSubscription() - val cSub = c.expectSubscription() - cSub.request(100) - val demand1 = pSub.expectRequest() - (1 to demand1.toInt) foreach { _ ⇒ pSub.sendNext(input.next()) } - val demand2 = pSub.expectRequest() - (1 to demand2.toInt) foreach { _ ⇒ pSub.sendNext(input.next()) } - val demand3 = pSub.expectRequest() - val sentN = demand1.toInt + demand2.toInt - (1 to sentN) foreach { n ⇒ c.expectNext(n) } - within(2.seconds) { - c.expectComplete() - } - (1 to demand3.toInt) foreach { _ ⇒ pSub.sendNext(input.next()) } - c.expectNoMsg(200.millis) - } - - "deliver bufferd elements onComplete before the timeout" in { - val c = StreamTestKit.SubscriberProbe[Int]() - Flow(1 to 3).takeWithin(1.second).produceTo(c) - val cSub = c.expectSubscription() - c.expectNoMsg(200.millis) - cSub.request(100) - (1 to 3) foreach { n ⇒ c.expectNext(n) } - c.expectComplete() - c.expectNoMsg(200.millis) - } - - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowTimerTransformerSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowTimerTransformerSpec.scala deleted file mode 100644 index 19ff93c994..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowTimerTransformerSpec.scala +++ /dev/null @@ -1,85 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } - -import scala.concurrent.duration._ -import scala.util.control.NoStackTrace - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowTimerTransformerSpec extends AkkaSpec { - - implicit val materializer = FlowMaterializer() - - "A Flow with TimerTransformer operations" must { - "produce scheduled ticks as expected" in { - val p = StreamTestKit.PublisherProbe[Int]() - val p2 = Flow(p). - timerTransform("timer", () ⇒ new TimerTransformer[Int, Int] { - schedulePeriodically("tick", 100.millis) - var tickCount = 0 - override def onNext(elem: Int) = List(elem) - override def onTimer(timerKey: Any) = { - tickCount += 1 - if (tickCount == 3) cancelTimer("tick") - List(tickCount) - } - override def isComplete: Boolean = !isTimerActive("tick") - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - subscription.request(5) - subscriber.expectNext(1) - subscriber.expectNext(2) - subscriber.expectNext(3) - subscriber.expectComplete() - } - - "schedule ticks when last transformation step (consume)" in { - val p = StreamTestKit.PublisherProbe[Int]() - val p2 = Flow(p). - timerTransform("timer", () ⇒ new TimerTransformer[Int, Int] { - schedulePeriodically("tick", 100.millis) - var tickCount = 0 - override def onNext(elem: Int) = List(elem) - override def onTimer(timerKey: Any) = { - tickCount += 1 - if (tickCount == 3) cancelTimer("tick") - testActor ! "tick-" + tickCount - List(tickCount) - } - override def isComplete: Boolean = !isTimerActive("tick") - }). - consume() - val pSub = p.expectSubscription() - expectMsg("tick-1") - expectMsg("tick-2") - expectMsg("tick-3") - pSub.sendComplete() - } - - "propagate error if onTimer throws an exception" in { - val exception = new Exception("Expected exception to the rule") with NoStackTrace - val p = StreamTestKit.PublisherProbe[Int]() - val p2 = Flow(p). - timerTransform("timer", () ⇒ new TimerTransformer[Int, Int] { - scheduleOnce("tick", 100.millis) - - def onNext(element: Int) = Nil - override def onTimer(timerKey: Any) = - throw exception - }).toPublisher() - - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - subscription.request(5) - subscriber.expectError(exception) - } - } -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowToFutureSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowToFutureSpec.scala deleted file mode 100644 index ec2097c081..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowToFutureSpec.scala +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, ScriptedTest, StreamTestKit } - -import scala.concurrent.Await -import scala.concurrent.duration._ -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } -import scala.util.Failure - -class FlowToFutureSpec extends AkkaSpec with ScriptedTest { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 1, maxSize = 16) - - implicit val materializer = FlowMaterializer(settings) - - "A Flow with toFuture" must { - - "yield the first value" in { - val p = StreamTestKit.PublisherProbe[Int]() - val f = Flow(p).toFuture() - val proc = p.expectSubscription - proc.expectRequest() - proc.sendNext(42) - Await.result(f, 100.millis) should be(42) - proc.expectCancellation() - } - - "yield the first error" in { - val p = StreamTestKit.PublisherProbe[Int]() - val f = Flow(p).toFuture() - val proc = p.expectSubscription - proc.expectRequest() - val ex = new RuntimeException("ex") - proc.sendError(ex) - Await.ready(f, 100.millis) - f.value.get should be(Failure(ex)) - } - - "yield NoSuchElementExcption for empty stream" in { - val p = StreamTestKit.PublisherProbe[Int]() - val f = Flow(p).toFuture() - val proc = p.expectSubscription - proc.expectRequest() - proc.sendComplete() - Await.ready(f, 100.millis) - f.value.get match { - case Failure(e: NoSuchElementException) ⇒ e.getMessage() should be("empty stream") - case x ⇒ fail("expected NoSuchElementException, got " + x) - } - } - - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowTransformRecoverSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowTransformRecoverSpec.scala deleted file mode 100644 index 1fe59fc710..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowTransformRecoverSpec.scala +++ /dev/null @@ -1,389 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import scala.collection.immutable -import scala.concurrent.duration._ -import akka.stream.testkit.StreamTestKit -import akka.stream.testkit.AkkaSpec -import akka.testkit.EventFilter -import scala.util.Failure -import scala.util.control.NoStackTrace -import akka.stream.scaladsl.Flow -import scala.util.Try -import scala.util.Success - -object FlowTransformRecoverSpec { - abstract class TryRecoveryTransformer[T, U] extends Transformer[T, U] { - def onNext(element: Try[T]): immutable.Seq[U] - - override def onNext(element: T): immutable.Seq[U] = onNext(Success(element)) - override def onError(cause: Throwable) = () - override def onTermination(cause: Option[Throwable]): immutable.Seq[U] = cause match { - case None ⇒ Nil - case Some(e) ⇒ onNext(Failure(e)) - } - } -} - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowTransformRecoverSpec extends AkkaSpec { - import FlowTransformRecoverSpec._ - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 2) - .withFanOutBuffer(initialSize = 2, maxSize = 2) - - implicit val materializer = FlowMaterializer(settings) - - "A Flow with transformRecover operations" must { - "produce one-to-one transformation as expected" in { - val p = Flow(List(1, 2, 3).iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - var tot = 0 - override def onNext(elem: Int) = { - tot += elem - List(tot) - } - override def onError(e: Throwable) = () - override def onTermination(e: Option[Throwable]) = e match { - case None ⇒ Nil - case Some(_) ⇒ List(-1) - } - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - subscription.request(1) - subscriber.expectNext(1) - subscriber.expectNoMsg(200.millis) - subscription.request(2) - subscriber.expectNext(3) - subscriber.expectNext(6) - subscriber.expectComplete() - } - - "produce one-to-several transformation as expected" in { - val p = Flow(List(1, 2, 3).iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - var tot = 0 - override def onNext(elem: Int) = { - tot += elem - Vector.fill(elem)(tot) - } - override def onError(e: Throwable) = () - override def onTermination(e: Option[Throwable]) = e match { - case None ⇒ Nil - case Some(_) ⇒ List(-1) - } - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - subscription.request(4) - subscriber.expectNext(1) - subscriber.expectNext(3) - subscriber.expectNext(3) - subscriber.expectNext(6) - subscriber.expectNoMsg(200.millis) - subscription.request(100) - subscriber.expectNext(6) - subscriber.expectNext(6) - subscriber.expectComplete() - } - - "produce dropping transformation as expected" in { - val p = Flow(List(1, 2, 3, 4).iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - var tot = 0 - override def onNext(elem: Int) = { - tot += elem - if (elem % 2 == 0) Nil else List(tot) - } - override def onError(e: Throwable) = () - override def onTermination(e: Option[Throwable]) = e match { - case None ⇒ Nil - case Some(_) ⇒ List(-1) - } - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - subscription.request(1) - subscriber.expectNext(1) - subscriber.expectNoMsg(200.millis) - subscription.request(1) - subscriber.expectNext(6) - subscription.request(1) - subscriber.expectComplete() - } - - "produce multi-step transformation as expected" in { - val p = Flow(List("a", "bc", "def").iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new TryRecoveryTransformer[String, Int] { - var concat = "" - override def onNext(element: Try[String]) = { - concat += element - List(concat.length) - } - }). - transform("transform", () ⇒ new Transformer[Int, Int] { - var tot = 0 - override def onNext(length: Int) = { - tot += length - List(tot) - } - override def onError(e: Throwable) = () - override def onTermination(e: Option[Throwable]) = e match { - case None ⇒ Nil - case Some(_) ⇒ List(-1) - } - }).fanout(1, 1). - toPublisher() - val c1 = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(c1) - val sub1 = c1.expectSubscription() - val c2 = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(c2) - val sub2 = c2.expectSubscription() - sub1.request(1) - sub2.request(2) - c1.expectNext(10) - c2.expectNext(10) - c2.expectNext(31) - c1.expectNoMsg(200.millis) - sub1.request(2) - sub2.request(2) - c1.expectNext(31) - c1.expectNext(64) - c2.expectNext(64) - c1.expectComplete() - c2.expectComplete() - } - - "invoke onComplete when done" in { - val p = Flow(List("a").iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new TryRecoveryTransformer[String, String] { - var s = "" - override def onNext(element: Try[String]) = { - s += element - Nil - } - override def onTermination(e: Option[Throwable]) = List(s + "B") - }). - toPublisher() - val c = StreamTestKit.SubscriberProbe[String]() - p2.subscribe(c) - val s = c.expectSubscription() - s.request(1) - c.expectNext("Success(a)B") - c.expectComplete() - } - - "allow cancellation using isComplete" in { - val p = StreamTestKit.PublisherProbe[Int]() - val p2 = Flow(p). - transform("transform", () ⇒ new TryRecoveryTransformer[Int, Int] { - var s = "" - override def onNext(element: Try[Int]) = { - s += element - List(element.get) - } - override def isComplete = s == "Success(1)" - }). - toPublisher() - val proc = p.expectSubscription - val c = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(c) - val s = c.expectSubscription() - s.request(10) - proc.sendNext(1) - proc.sendNext(2) - c.expectNext(1) - c.expectComplete() - proc.expectCancellation() - } - - "call onComplete after isComplete signaled completion" in { - val p = StreamTestKit.PublisherProbe[Int]() - val p2 = Flow(p). - transform("transform", () ⇒ new TryRecoveryTransformer[Int, Int] { - var s = "" - override def onNext(element: Try[Int]) = { - s += element - List(element.get) - } - override def isComplete = s == "Success(1)" - override def onTermination(e: Option[Throwable]) = List(s.length + 10) - }). - toPublisher() - val proc = p.expectSubscription - val c = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(c) - val s = c.expectSubscription() - s.request(10) - proc.sendNext(1) - proc.sendNext(2) - c.expectNext(1) - c.expectNext(20) - c.expectComplete() - proc.expectCancellation() - } - - "report error when exception is thrown" in { - val p = Flow(List(1, 2, 3).iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - override def onNext(elem: Int) = { - if (elem == 2) throw new IllegalArgumentException("two not allowed") - else List(elem, elem) - } - override def onError(e: Throwable) = List(-1) - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - EventFilter[IllegalArgumentException]("two not allowed") intercept { - subscription.request(1) - subscriber.expectNext(1) - subscriber.expectNoMsg(200.millis) - subscription.request(100) - subscriber.expectNext(1) - subscriber.expectError().getMessage should be("two not allowed") - subscriber.expectNoMsg(200.millis) - } - } - - "report error after emitted elements" in { - EventFilter[IllegalArgumentException]("two not allowed") intercept { - val p2 = Flow(List(1, 2, 3).iterator). - mapConcat { elem ⇒ - if (elem == 2) throw new IllegalArgumentException("two not allowed") - else (1 to 5).map(elem * 100 + _) - }. - transform("transform", () ⇒ new Transformer[Int, Int] { - override def onNext(elem: Int) = List(elem) - override def onError(e: Throwable) = () - override def onTermination(e: Option[Throwable]) = e match { - case None ⇒ Nil - case Some(_) ⇒ List(-1, -2, -3) - } - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - - subscription.request(1) - subscriber.expectNext(101) - subscriber.expectNoMsg(100.millis) - subscription.request(1) - subscriber.expectNext(102) - subscriber.expectNoMsg(100.millis) - subscription.request(1) - subscriber.expectNext(103) - subscriber.expectNoMsg(100.millis) - subscription.request(1) - subscriber.expectNext(104) - subscriber.expectNoMsg(100.millis) - subscription.request(1) - subscriber.expectNext(105) - subscriber.expectNoMsg(100.millis) - - subscription.request(1) - subscriber.expectNext(-1) - subscriber.expectNoMsg(100.millis) - subscription.request(10) - subscriber.expectNext(-2) - subscriber.expectNext(-3) - subscriber.expectComplete() - subscriber.expectNoMsg(200.millis) - } - } - - case class TE(message: String) extends RuntimeException(message) with NoStackTrace - - "transform errors in sequence with normal messages" in { - val p = StreamTestKit.PublisherProbe[Int]() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, String] { - var s = "" - override def onNext(element: Int) = { - s += element.toString - List(s) - } - override def onError(ex: Throwable) = () - override def onTermination(ex: Option[Throwable]) = { - ex match { - case None ⇒ Nil - case Some(e) ⇒ - s += e.getMessage - List(s) - } - } - }). - toPublisher() - val proc = p.expectSubscription() - val c = StreamTestKit.SubscriberProbe[String]() - p2.subscribe(c) - val s = c.expectSubscription() - proc.sendNext(0) - proc.sendError(TE("1")) - // Request late to prove the in-sequence nature - s.request(10) - c.expectNext("0") - c.expectNext("01") - c.expectComplete() - } - - "forward errors when received and thrown" in { - val p = StreamTestKit.PublisherProbe[Int]() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - override def onNext(in: Int) = List(in) - override def onError(e: Throwable) = throw e - }). - toPublisher() - val proc = p.expectSubscription() - val c = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(c) - val s = c.expectSubscription() - s.request(10) - EventFilter[TE](occurrences = 1) intercept { - proc.sendError(TE("1")) - c.expectError(TE("1")) - } - } - - "support cancel as expected" in { - val p = Flow(List(1, 2, 3).iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - override def onNext(elem: Int) = List(elem, elem) - override def onError(e: Throwable) = List(-1) - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - subscription.request(2) - subscriber.expectNext(1) - subscription.cancel() - subscriber.expectNext(1) - subscriber.expectNoMsg(500.millis) - subscription.request(2) - subscriber.expectNoMsg(200.millis) - } - } - -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowTransformSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowTransformSpec.scala deleted file mode 100644 index f2a60ff558..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowTransformSpec.scala +++ /dev/null @@ -1,402 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } -import akka.testkit.{ EventFilter, TestProbe } -import com.typesafe.config.ConfigFactory - -import scala.collection.immutable.Seq -import scala.concurrent.duration._ -import scala.util.control.NoStackTrace - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class FlowTransformSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug.receive=off\nakka.loglevel=INFO")) { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 2) - .withFanOutBuffer(initialSize = 2, maxSize = 2) - - implicit val materializer = FlowMaterializer(settings) - - "A Flow with transform operations" must { - "produce one-to-one transformation as expected" in { - val p = Flow(List(1, 2, 3).iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - var tot = 0 - override def onNext(elem: Int) = { - tot += elem - List(tot) - } - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - subscription.request(1) - subscriber.expectNext(1) - subscriber.expectNoMsg(200.millis) - subscription.request(2) - subscriber.expectNext(3) - subscriber.expectNext(6) - subscriber.expectComplete() - } - - "produce one-to-several transformation as expected" in { - val p = Flow(List(1, 2, 3).iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - var tot = 0 - override def onNext(elem: Int) = { - tot += elem - Vector.fill(elem)(tot) - } - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - subscription.request(4) - subscriber.expectNext(1) - subscriber.expectNext(3) - subscriber.expectNext(3) - subscriber.expectNext(6) - subscriber.expectNoMsg(200.millis) - subscription.request(100) - subscriber.expectNext(6) - subscriber.expectNext(6) - subscriber.expectComplete() - } - - "produce dropping transformation as expected" in { - val p = Flow(List(1, 2, 3, 4).iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - var tot = 0 - override def onNext(elem: Int) = { - tot += elem - if (elem % 2 == 0) { - Nil - } else { - List(tot) - } - } - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - subscription.request(1) - subscriber.expectNext(1) - subscriber.expectNoMsg(200.millis) - subscription.request(1) - subscriber.expectNext(6) - subscription.request(1) - subscriber.expectComplete() - } - - "produce multi-step transformation as expected" in { - val p = Flow(List("a", "bc", "def").iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[String, Int] { - var concat = "" - override def onNext(elem: String) = { - concat += elem - List(concat.length) - } - }). - transform("transform", () ⇒ new Transformer[Int, Int] { - var tot = 0 - override def onNext(length: Int) = { - tot += length - List(tot) - } - }).fanout(2, 2). - toPublisher() - val c1 = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(c1) - val sub1 = c1.expectSubscription() - val c2 = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(c2) - val sub2 = c2.expectSubscription() - sub1.request(1) - sub2.request(2) - c1.expectNext(1) - c2.expectNext(1) - c2.expectNext(4) - c1.expectNoMsg(200.millis) - sub1.request(2) - sub2.request(2) - c1.expectNext(4) - c1.expectNext(10) - c2.expectNext(10) - c1.expectComplete() - c2.expectComplete() - } - - "invoke onComplete when done" in { - val p = Flow(List("a").iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[String, String] { - var s = "" - override def onNext(element: String) = { - s += element - Nil - } - override def onTermination(e: Option[Throwable]) = List(s + "B") - }). - toPublisher() - val c = StreamTestKit.SubscriberProbe[String]() - p2.subscribe(c) - val s = c.expectSubscription() - s.request(1) - c.expectNext("aB") - c.expectComplete() - } - - "invoke cleanup when done" in { - val cleanupProbe = TestProbe() - val p = Flow(List("a").iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[String, String] { - var s = "" - override def onNext(element: String) = { - s += element - Nil - } - override def onTermination(e: Option[Throwable]) = List(s + "B") - override def cleanup() = cleanupProbe.ref ! s - }). - toPublisher() - val c = StreamTestKit.SubscriberProbe[String]() - p2.subscribe(c) - val s = c.expectSubscription() - s.request(1) - c.expectNext("aB") - c.expectComplete() - cleanupProbe.expectMsg("a") - } - - "invoke cleanup when done consume" in { - val cleanupProbe = TestProbe() - val p = Flow(List("a").iterator).toPublisher() - Flow(p). - transform("transform", () ⇒ new Transformer[String, String] { - var s = "x" - override def onNext(element: String) = { - s = element - List(element) - } - override def cleanup() = cleanupProbe.ref ! s - }). - consume() - cleanupProbe.expectMsg("a") - } - - "invoke cleanup when done after error" in { - val cleanupProbe = TestProbe() - val p = Flow(List("a", "b", "c").iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[String, String] { - var s = "" - override def onNext(in: String) = { - if (in == "b") { - throw new IllegalArgumentException("Not b") with NoStackTrace - } else { - val out = s + in - s += in.toUpperCase - List(out) - } - } - override def onTermination(e: Option[Throwable]) = List(s + "B") - override def cleanup() = cleanupProbe.ref ! s - }). - toPublisher() - val c = StreamTestKit.SubscriberProbe[String]() - p2.subscribe(c) - val s = c.expectSubscription() - s.request(1) - c.expectNext("a") - s.request(1) - c.expectError() - cleanupProbe.expectMsg("A") - } - - "allow cancellation using isComplete" in { - val p = StreamTestKit.PublisherProbe[Int]() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - var s = "" - override def onNext(element: Int) = { - s += element - List(element) - } - override def isComplete = s == "1" - }). - toPublisher() - val proc = p.expectSubscription - val c = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(c) - val s = c.expectSubscription() - s.request(10) - proc.sendNext(1) - proc.sendNext(2) - c.expectNext(1) - c.expectComplete() - proc.expectCancellation() - } - - "call onComplete after isComplete signaled completion" in { - val cleanupProbe = TestProbe() - val p = StreamTestKit.PublisherProbe[Int]() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - var s = "" - override def onNext(element: Int) = { - s += element - List(element) - } - override def isComplete = s == "1" - override def onTermination(e: Option[Throwable]) = List(s.length + 10) - override def cleanup() = cleanupProbe.ref ! s - }). - toPublisher() - val proc = p.expectSubscription - val c = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(c) - val s = c.expectSubscription() - s.request(10) - proc.sendNext(1) - proc.sendNext(2) - c.expectNext(1) - c.expectNext(11) - c.expectComplete() - proc.expectCancellation() - cleanupProbe.expectMsg("1") - } - - "report error when exception is thrown" in { - val p = Flow(List(1, 2, 3).iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - override def onNext(elem: Int) = { - if (elem == 2) { - throw new IllegalArgumentException("two not allowed") - } else { - List(elem, elem) - } - } - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - EventFilter[IllegalArgumentException]("two not allowed") intercept { - subscription.request(100) - subscriber.expectNext(1) - subscriber.expectNext(1) - subscriber.expectError().getMessage should be("two not allowed") - subscriber.expectNoMsg(200.millis) - } - } - - "support cancel as expected" in { - val p = Flow(List(1, 2, 3).iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - override def onNext(elem: Int) = List(elem, elem) - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - subscription.request(2) - subscriber.expectNext(1) - subscription.cancel() - subscriber.expectNext(1) - subscriber.expectNoMsg(500.millis) - subscription.request(2) - subscriber.expectNoMsg(200.millis) - } - - "support producing elements from empty inputs" in { - val p = Flow(List.empty[Int].iterator).toPublisher() - val p2 = Flow(p). - transform("transform", () ⇒ new Transformer[Int, Int] { - override def onNext(elem: Int) = Nil - override def onTermination(e: Option[Throwable]) = List(1, 2, 3) - }). - toPublisher() - val subscriber = StreamTestKit.SubscriberProbe[Int]() - p2.subscribe(subscriber) - val subscription = subscriber.expectSubscription() - subscription.request(4) - subscriber.expectNext(1) - subscriber.expectNext(2) - subscriber.expectNext(3) - subscriber.expectComplete() - - } - - "support converting onComplete into onError" in { - val subscriber = StreamTestKit.SubscriberProbe[Int]() - Flow(List(5, 1, 2, 3)).transform("transform", () ⇒ new Transformer[Int, Int] { - var expectedNumberOfElements: Option[Int] = None - var count = 0 - override def onNext(elem: Int) = - if (expectedNumberOfElements.isEmpty) { - expectedNumberOfElements = Some(elem) - Nil - } else { - count += 1 - List(elem) - } - override def onTermination(err: Option[Throwable]) = err match { - case Some(e) ⇒ Nil - case None ⇒ - expectedNumberOfElements match { - case Some(expected) if count != expected ⇒ - throw new RuntimeException(s"Expected $expected, got $count") with NoStackTrace - case _ ⇒ Nil - } - } - }).produceTo(subscriber) - - val subscription = subscriber.expectSubscription() - subscription.request(10) - - subscriber.expectNext(1) - subscriber.expectNext(2) - subscriber.expectNext(3) - subscriber.expectError().getMessage should be("Expected 5, got 3") - } - - "be safe to reuse" in { - val flow = Flow(1 to 3).transform("transform", () ⇒ - new Transformer[Int, Int] { - var count = 0 - - override def onNext(elem: Int): Seq[Int] = { - count += 1 - List(count) - } - }) - - val s1 = StreamTestKit.SubscriberProbe[Int]() - flow.produceTo(s1) - s1.expectSubscription().request(3) - s1.expectNext(1, 2, 3) - s1.expectComplete() - - val s2 = StreamTestKit.SubscriberProbe[Int]() - flow.produceTo(s2) - s2.expectSubscription().request(3) - s2.expectNext(1, 2, 3) - s2.expectComplete() - } - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/FlowZipSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/FlowZipSpec.scala deleted file mode 100644 index 32c32a5aca..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/FlowZipSpec.scala +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.StreamTestKit -import org.reactivestreams.Publisher - -class FlowZipSpec extends TwoStreamsSetup { - - type Outputs = (Int, Int) - override def operationUnderTest(in1: Flow[Int], in2: Publisher[Int]) = in1.zip(in2) - - "Zip" must { - - "work in the happy case" in { - // Different input sizes (4 and 6) - val source1 = Flow((1 to 4).iterator).toPublisher() - val source2 = Flow(List("A", "B", "C", "D", "E", "F").iterator).toPublisher() - val p = Flow(source1).zip(source2).toPublisher() - - val probe = StreamTestKit.SubscriberProbe[(Int, String)]() - p.subscribe(probe) - val subscription = probe.expectSubscription() - - subscription.request(2) - probe.expectNext((1, "A")) - probe.expectNext((2, "B")) - - subscription.request(1) - probe.expectNext((3, "C")) - subscription.request(1) - probe.expectNext((4, "D")) - - probe.expectComplete() - } - - commonTests() - - "work with one immediately completed and one nonempty publisher" in { - val subscriber1 = setup(completedPublisher, nonemptyPublisher((1 to 4).iterator)) - subscriber1.expectCompletedOrSubscriptionFollowedByComplete() - - val subscriber2 = setup(nonemptyPublisher((1 to 4).iterator), completedPublisher) - subscriber2.expectCompletedOrSubscriptionFollowedByComplete() - } - - "work with one delayed completed and one nonempty publisher" in { - val subscriber1 = setup(soonToCompletePublisher, nonemptyPublisher((1 to 4).iterator)) - subscriber1.expectCompletedOrSubscriptionFollowedByComplete() - - val subscriber2 = setup(nonemptyPublisher((1 to 4).iterator), soonToCompletePublisher) - subscriber2.expectCompletedOrSubscriptionFollowedByComplete() - } - - "work with one immediately failed and one nonempty publisher" in { - val subscriber1 = setup(failedPublisher, nonemptyPublisher((1 to 4).iterator)) - subscriber1.expectErrorOrSubscriptionFollowedByError(TestException) - - val subscriber2 = setup(nonemptyPublisher((1 to 4).iterator), failedPublisher) - subscriber2.expectErrorOrSubscriptionFollowedByError(TestException) - } - - "work with one delayed failed and one nonempty publisher" in { - val subscriber1 = setup(soonToFailPublisher, nonemptyPublisher((1 to 4).iterator)) - subscriber1.expectErrorOrSubscriptionFollowedByError(TestException) - - val subscriber2 = setup(nonemptyPublisher((1 to 4).iterator), soonToFailPublisher) - val subscription2 = subscriber2.expectErrorOrSubscriptionFollowedByError(TestException) - } - - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/ImplicitFlowMaterializerSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/ImplicitFlowMaterializerSpec.scala deleted file mode 100644 index d281e134d0..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/ImplicitFlowMaterializerSpec.scala +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import akka.actor.{ Actor, Props } -import akka.pattern.pipe -import akka.stream.scaladsl.{ Flow, ImplicitFlowMaterializer } -import akka.stream.testkit.AkkaSpec -import akka.testkit._ - -object ImplicitFlowMaterializerSpec { - class SomeActor(input: List[String]) extends Actor with ImplicitFlowMaterializer { - - override def flowMaterializerSettings = MaterializerSettings(context.system) - .withInputBuffer(initialSize = 2, maxSize = 16) - .withFanOutBuffer(initialSize = 1, maxSize = 16) - - val flow = Flow(input).map(_.toUpperCase()).fold("")(_ + _) - - def receive = { - case "run" ⇒ - // toFuture takes an implicit FlowMaterializer parameter, which is provided by ImplicitFlowMaterializer - import context.dispatcher - val futureResult = flow.toFuture() - futureResult pipeTo sender() - } - } -} - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class ImplicitFlowMaterializerSpec extends AkkaSpec with ImplicitSender { - import akka.stream.ImplicitFlowMaterializerSpec._ - - "An ImplicitFlowMaterializer" must { - - "provide implicit FlowMaterializer" in { - val actor = system.actorOf(Props(classOf[SomeActor], List("a", "b", "c")).withDispatcher("akka.test.stream-dispatcher")) - actor ! "run" - expectMsg("ABC") - } - } -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/TickPublisherSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/TickPublisherSpec.scala deleted file mode 100644 index 4a2d20e64b..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/TickPublisherSpec.scala +++ /dev/null @@ -1,98 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import scala.concurrent.duration._ -import akka.stream.scaladsl.Flow -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit -import scala.util.control.NoStackTrace - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class TickPublisherSpec extends AkkaSpec { - - implicit val materializer = FlowMaterializer() - - "A Flow based on tick publisher" must { - "produce ticks" in { - val tickGen = Iterator from 1 - val c = StreamTestKit.SubscriberProbe[String]() - Flow(1.second, 500.millis, () ⇒ "tick-" + tickGen.next()).produceTo(c) - val sub = c.expectSubscription() - sub.request(3) - c.expectNoMsg(600.millis) - c.expectNext("tick-1") - c.expectNoMsg(200.millis) - c.expectNext("tick-2") - c.expectNoMsg(200.millis) - c.expectNext("tick-3") - sub.cancel() - c.expectNoMsg(200.millis) - } - - "drop ticks when not requested" in { - val tickGen = Iterator from 1 - val c = StreamTestKit.SubscriberProbe[String]() - Flow(1.second, 1.second, () ⇒ "tick-" + tickGen.next()).produceTo(c) - val sub = c.expectSubscription() - sub.request(2) - c.expectNext("tick-1") - c.expectNoMsg(200.millis) - c.expectNext("tick-2") - c.expectNoMsg(1400.millis) - sub.request(2) - c.expectNext("tick-4") - c.expectNoMsg(200.millis) - c.expectNext("tick-5") - sub.cancel() - c.expectNoMsg(200.millis) - } - - "produce ticks with multiple subscribers" in { - val tickGen = Iterator from 1 - val p = Flow(1.second, 1.second, () ⇒ "tick-" + tickGen.next()).toPublisher() - val c1 = StreamTestKit.SubscriberProbe[String]() - val c2 = StreamTestKit.SubscriberProbe[String]() - p.subscribe(c1) - p.subscribe(c2) - val sub1 = c1.expectSubscription() - val sub2 = c2.expectSubscription() - sub1.request(1) - sub2.request(2) - c1.expectNext("tick-1") - c2.expectNext("tick-1") - c2.expectNoMsg(200.millis) - c2.expectNext("tick-2") - c1.expectNoMsg(200.millis) - sub1.request(2) - sub2.request(2) - c1.expectNext("tick-3") - c2.expectNext("tick-3") - sub1.cancel() - sub2.cancel() - } - - "signal onError when tick closure throws" in { - val c = StreamTestKit.SubscriberProbe[String]() - Flow(1.second, 1.second, () ⇒ throw new RuntimeException("tick err") with NoStackTrace).produceTo(c) - val sub = c.expectSubscription() - sub.request(3) - c.expectError.getMessage should be("tick err") - } - - "be usable with zip for a simple form of rate limiting" in { - val c = StreamTestKit.SubscriberProbe[Int]() - val rate = Flow(1.second, 1.second, () ⇒ "tick").toPublisher() - Flow(1 to 100).zip(rate).map { case (n, _) ⇒ n }.produceTo(c) - val sub = c.expectSubscription() - sub.request(1000) - c.expectNext(1) - c.expectNoMsg(200.millis) - c.expectNext(2) - c.expectNoMsg(200.millis) - sub.cancel() - } - - } -} \ No newline at end of file diff --git a/akka-stream-tests/src/test/scala/akka/stream/TimerTransformerSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/TimerTransformerSpec.scala deleted file mode 100644 index 8053bdc737..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/TimerTransformerSpec.scala +++ /dev/null @@ -1,132 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream - -import language.postfixOps -import scala.collection.immutable -import scala.concurrent.duration._ -import akka.actor.Actor -import akka.actor.ActorCell -import akka.actor.ActorRef -import akka.actor.Props -import akka.stream.TimerTransformer.Scheduled -import akka.stream.testkit.AkkaSpec -import akka.testkit.TestDuration -import akka.testkit.TestKit - -object TimerTransformerSpec { - case object TestSingleTimer - case object TestSingleTimerResubmit - case object TestCancelTimer - case object TestCancelTimerAck - case object TestRepeatedTimer - case class Tick(n: Int) - - def driverProps(probe: ActorRef): Props = - Props(classOf[Driver], probe).withDispatcher("akka.test.stream-dispatcher") - - class Driver(probe: ActorRef) extends Actor { - - // need implicit system for dilated - import context.system - - val tickCount = Iterator from 1 - - val transformer = new TimerTransformer[Int, Int] { - override def onNext(elem: Int): immutable.Seq[Int] = List(elem) - override def onTimer(timerKey: Any): immutable.Seq[Int] = { - val tick = Tick(tickCount.next()) - probe ! tick - if (timerKey == "TestSingleTimerResubmit" && tick.n == 1) - scheduleOnce("TestSingleTimerResubmit", 500.millis.dilated) - else if (timerKey == "TestRepeatedTimer" && tick.n == 5) - cancelTimer("TestRepeatedTimer") - Nil - } - } - - override def preStart(): Unit = { - super.preStart() - transformer.start(context) - } - - override def postStop(): Unit = { - super.postStop() - transformer.stop() - } - - def receive = { - case TestSingleTimer ⇒ - transformer.scheduleOnce("TestSingleTimer", 500.millis.dilated) - case TestSingleTimerResubmit ⇒ - transformer.scheduleOnce("TestSingleTimerResubmit", 500.millis.dilated) - case TestCancelTimer ⇒ - transformer.scheduleOnce("TestCancelTimer", 1.milli.dilated) - TestKit.awaitCond(context.asInstanceOf[ActorCell].mailbox.hasMessages, 1.second.dilated) - transformer.cancelTimer("TestCancelTimer") - probe ! TestCancelTimerAck - transformer.scheduleOnce("TestCancelTimer", 500.milli.dilated) - case TestRepeatedTimer ⇒ - transformer.schedulePeriodically("TestRepeatedTimer", 100.millis.dilated) - case s: Scheduled ⇒ transformer.onScheduled(s) - } - } -} - -@org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) -class TimerTransformerSpec extends AkkaSpec { - import TimerTransformerSpec._ - - "A TimerTransformer" must { - - "receive single-shot timer" in { - val driver = system.actorOf(driverProps(testActor)) - within(2 seconds) { - within(500 millis, 1 second) { - driver ! TestSingleTimer - expectMsg(Tick(1)) - } - expectNoMsg(1 second) - } - } - - "resubmit single-shot timer" in { - val driver = system.actorOf(driverProps(testActor)) - within(2.5 seconds) { - within(500 millis, 1 second) { - driver ! TestSingleTimerResubmit - expectMsg(Tick(1)) - } - within(1 second) { - expectMsg(Tick(2)) - } - expectNoMsg(1 second) - } - } - - "correctly cancel a named timer" in { - val driver = system.actorOf(driverProps(testActor)) - driver ! TestCancelTimer - within(500 millis) { - expectMsg(TestCancelTimerAck) - } - within(300 millis, 1 second) { - expectMsg(Tick(1)) - } - expectNoMsg(1 second) - } - - "receive and cancel a repeated timer" in { - val driver = system.actorOf(driverProps(testActor)) - driver ! TestRepeatedTimer - val seq = receiveWhile(2 seconds) { - case t: Tick ⇒ t - } - seq should have length 5 - expectNoMsg(1 second) - } - - } - -} diff --git a/akka-stream-tests/src/test/scala/akka/stream/TwoStreamsSetup.scala b/akka-stream-tests/src/test/scala/akka/stream/TwoStreamsSetup.scala deleted file mode 100644 index a3a7f4f891..0000000000 --- a/akka-stream-tests/src/test/scala/akka/stream/TwoStreamsSetup.scala +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream - -import akka.stream.scaladsl.Flow -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } -import org.reactivestreams.Publisher - -import scala.util.control.NoStackTrace - -abstract class TwoStreamsSetup extends AkkaSpec { - - val settings = MaterializerSettings(system) - .withInputBuffer(initialSize = 2, maxSize = 2) - .withFanOutBuffer(initialSize = 2, maxSize = 2) - - implicit val materializer = FlowMaterializer(settings) - - case class TE(message: String) extends RuntimeException(message) with NoStackTrace - - val TestException = TE("test") - - type Outputs - - def operationUnderTest(in1: Flow[Int], in2: Publisher[Int]): Flow[Outputs] - - def setup(p1: Publisher[Int], p2: Publisher[Int]) = { - val subscriber = StreamTestKit.SubscriberProbe[Outputs]() - operationUnderTest(Flow(p1), p2).toPublisher().subscribe(subscriber) - subscriber - } - - def failedPublisher[T]: Publisher[T] = StreamTestKit.errorPublisher[T](TestException) - - def completedPublisher[T]: Publisher[T] = StreamTestKit.emptyPublisher[T] - - def nonemptyPublisher[T](elems: Iterator[T]): Publisher[T] = Flow(elems).toPublisher() - - def soonToFailPublisher[T]: Publisher[T] = StreamTestKit.lazyErrorPublisher[T](TestException) - - def soonToCompletePublisher[T]: Publisher[T] = StreamTestKit.lazyEmptyPublisher[T] - - def commonTests() = { - "work with two immediately completed publishers" in { - val subscriber = setup(completedPublisher, completedPublisher) - subscriber.expectCompletedOrSubscriptionFollowedByComplete() - } - - "work with two delayed completed publishers" in { - val subscriber = setup(soonToCompletePublisher, soonToCompletePublisher) - subscriber.expectCompletedOrSubscriptionFollowedByComplete() - } - - "work with one immediately completed and one delayed completed publisher" in { - val subscriber = setup(completedPublisher, soonToCompletePublisher) - subscriber.expectCompletedOrSubscriptionFollowedByComplete() - } - - "work with two immediately failed publishers" in { - val subscriber = setup(failedPublisher, failedPublisher) - subscriber.expectErrorOrSubscriptionFollowedByError(TestException) - } - - "work with two delayed failed publishers" in { - val subscriber = setup(soonToFailPublisher, soonToFailPublisher) - subscriber.expectErrorOrSubscriptionFollowedByError(TestException) - } - - // Warning: The two test cases below are somewhat implementation specific and might fail if the implementation - // is changed. They are here to be an early warning though. - "work with one immediately failed and one delayed failed publisher (case 1)" in { - val subscriber = setup(soonToFailPublisher, failedPublisher) - subscriber.expectErrorOrSubscriptionFollowedByError(TestException) - } - - "work with one immediately failed and one delayed failed publisher (case 2)" in { - val subscriber = setup(failedPublisher, soonToFailPublisher) - subscriber.expectErrorOrSubscriptionFollowedByError(TestException) - } - } - -} 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 310ead43c3..c15c3e9dab 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 @@ -6,14 +6,14 @@ package akka.stream.actor import akka.actor.ActorRef import akka.actor.PoisonPill import akka.actor.Props -import akka.stream.scaladsl2.Broadcast -import akka.stream.scaladsl2.Flow -import akka.stream.scaladsl2.FlowGraph -import akka.stream.scaladsl2.FlowGraphImplicits -import akka.stream.scaladsl2.Merge -import akka.stream.scaladsl2.FlowMaterializer -import akka.stream.scaladsl2.Sink -import akka.stream.scaladsl2.Source +import akka.stream.scaladsl.Broadcast +import akka.stream.scaladsl.Flow +import akka.stream.scaladsl.FlowGraph +import akka.stream.scaladsl.FlowGraphImplicits +import akka.stream.scaladsl.Merge +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit import akka.testkit.EventFilter 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 2eb1ac4eb0..7c2c6fd0b2 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 @@ -5,9 +5,9 @@ package akka.stream.actor import akka.actor.{ Actor, ActorRef, Props } import akka.routing.{ ActorRefRoutee, RoundRobinRoutingLogic, Router } -import akka.stream.scaladsl2.FlowMaterializer -import akka.stream.scaladsl2.Sink -import akka.stream.scaladsl2.Source +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source import akka.stream.testkit.AkkaSpec import akka.testkit.ImplicitSender 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 5867c5763f..24171808cc 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 @@ -4,7 +4,8 @@ package akka.stream.extra import akka.stream.{ MaterializerSettings, FlowMaterializer } -import akka.stream.scaladsl.{ Duct, Flow } +import akka.stream.scaladsl.{ Source, Flow } +import akka.stream.scaladsl.Sink import akka.stream.testkit.{ AkkaSpec, ScriptedTest, StreamTestKit } import akka.testkit.TestProbe import org.reactivestreams.{ Publisher, Subscriber } @@ -19,7 +20,7 @@ class FlowTimedSpec extends AkkaSpec with ScriptedTest { implicit val materializer = FlowMaterializer(settings) - "Timed Flow" must { + "Timed Source" must { import akka.stream.extra.Implicits.TimedFlowDsl @@ -69,19 +70,16 @@ class FlowTimedSpec extends AkkaSpec with ScriptedTest { "have a Java API" in pending } - "Timed Duct" must { - import akka.stream.extra.Implicits.TimedDuctDsl + "Timed Flow" must { + import akka.stream.extra.Implicits.TimedFlowDsl "measure time it between elements matching a predicate" in { val probe = TestProbe() - val duct: Duct[Int, Long] = Duct[Int].map(_.toLong).timedIntervalBetween(in ⇒ in % 2 == 1, d ⇒ probe.ref ! d) + val flow: Flow[Int, Long] = Flow[Int].map(_.toLong).timedIntervalBetween(in ⇒ in % 2 == 1, d ⇒ probe.ref ! d) val c1 = StreamTestKit.SubscriberProbe[Long]() - val c2: Subscriber[Int] = duct.produceTo(c1) - - val p = Flow(List(1, 2, 3)).toPublisher() - p.subscribe(c2) + Source(List(1, 2, 3)).connect(flow).connect(Sink(c1)).run() val s = c1.expectSubscription() s.request(100) @@ -98,21 +96,21 @@ class FlowTimedSpec extends AkkaSpec with ScriptedTest { val probe = TestProbe() // making sure the types come out as expected - val duct: Duct[Int, String] = - Duct[Int]. + val flow: Flow[Int, String] = + Flow[Int]. timed(_. map(_.toDouble). map(_.toInt). map(_.toString), duration ⇒ probe.ref ! duration). map { s: String ⇒ s + "!" } - val (ductIn: Subscriber[Int], ductOut: Publisher[String]) = duct.build() + val (flowIn: Subscriber[Int], flowOut: Publisher[String]) = flow.runWith(Source.subscriber[Int], Sink.publisher[String]) val c1 = StreamTestKit.SubscriberProbe[String]() - val c2 = ductOut.subscribe(c1) + val c2 = flowOut.subscribe(c1) - val p = Flow(0 to 100).toPublisher() - p.subscribe(ductIn) + val p = Source(0 to 100).runWith(Sink.publisher) + p.subscribe(flowIn) val s = c1.expectSubscription() s.request(200) diff --git a/akka-stream-tests/src/test/scala/akka/stream/io/SslTlsFlowSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/io/SslTlsFlowSpec.scala index b17035589d..67d45907c5 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io/SslTlsFlowSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io/SslTlsFlowSpec.scala @@ -5,7 +5,6 @@ package akka.stream.io import java.io.{ OutputStreamWriter, BufferedWriter, InputStreamReader, BufferedReader } import java.net.InetSocketAddress - import akka.actor.{ ActorSystem, Props } import akka.stream.io.SslTlsCipher.SessionNegotiation import akka.stream.io.StreamTcp.{ OutgoingTcpConnection, TcpServerBinding } @@ -17,9 +16,10 @@ import java.security.{ KeyStore, SecureRandom } import java.util.concurrent.atomic.AtomicInteger import javax.net.ssl._ import sun.rmi.transport.tcp.TCPConnection - import scala.concurrent.{ Future, Await } import scala.concurrent.duration._ +import akka.stream.scaladsl.Source +import akka.stream.scaladsl.Sink object SslTlsFlowSpec { @@ -116,10 +116,11 @@ class SslTlsFlowSpec extends AkkaSpec("akka.actor.default-mailbox.mailbox-type = } def replyFirstLineInUpperCase(scipher: SslTlsCipher): Unit = { - val ssessionf = Flow(scipher.sessionInbound).toFuture() + val ssessionf = Source(scipher.sessionInbound).runWith(Sink.future) val ssession = Await.result(ssessionf, duration) val sdata = ssession.data - Flow(sdata).map(bs ⇒ ByteString(bs.decodeString("utf-8").split('\n').head.toUpperCase + '\n')).produceTo(scipher.plainTextOutbound) + Source(sdata).map(bs ⇒ ByteString(bs.decodeString("utf-8").split('\n').head.toUpperCase + '\n')). + connect(Sink(scipher.plainTextOutbound)).run() } def replyFirstLineInUpperCase(clientConnection: JavaSslConnection): Unit = { @@ -127,11 +128,11 @@ class SslTlsFlowSpec extends AkkaSpec("akka.actor.default-mailbox.mailbox-type = } def sendLineAndReceiveResponse(ccipher: SslTlsCipher, message: String): String = { - val csessionf = Flow(ccipher.sessionInbound).toFuture() - Flow(List(ByteString(message + '\n'))).produceTo(ccipher.plainTextOutbound) + val csessionf = Source(ccipher.sessionInbound).runWith(Sink.future) + Source(List(ByteString(message + '\n'))).connect(Sink(ccipher.plainTextOutbound)).run() val csession = Await.result(csessionf, duration) val cdata = csession.data - Await.result(Flow(cdata).map(_.decodeString("utf-8").split('\n').head).toFuture(), duration) + Await.result(Source(cdata).map(_.decodeString("utf-8").split('\n').head).runWith(Sink.future), duration) } def sendLineAndReceiveResponse(connection: JavaSslConnection, message: String): String = { @@ -147,7 +148,7 @@ class SslTlsFlowSpec extends AkkaSpec("akka.actor.default-mailbox.mailbox-type = def connectIncomingConnection(serverBinding: TcpServerBinding, scipher: SslTlsCipher): Unit = { // connect the incoming tcp stream to the server cipher - Flow(serverBinding.connectionStream).foreach { + Source(serverBinding.connectionStream).foreach { case StreamTcp.IncomingTcpConnection(remoteAddress, inputStream, outputStream) ⇒ scipher.cipherTextOutbound.subscribe(outputStream) inputStream.subscribe(scipher.cipherTextInbound) diff --git a/akka-stream-tests/src/test/scala/akka/stream/io/TcpFlowSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/io/TcpFlowSpec.scala index 414df44b2a..5689f25bd6 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io/TcpFlowSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io/TcpFlowSpec.scala @@ -8,6 +8,8 @@ import akka.stream.testkit.AkkaSpec import akka.util.ByteString import scala.concurrent.Await import scala.concurrent.duration._ +import akka.stream.scaladsl.Source +import akka.stream.scaladsl.Sink class TcpFlowSpec extends AkkaSpec with TcpHelper { import akka.stream.io.TcpHelper._ @@ -46,9 +48,9 @@ class TcpFlowSpec extends AkkaSpec with TcpHelper { val expectedOutput = ByteString(Array.tabulate(256)(_.asInstanceOf[Byte])) serverConnection.read(256) - Flow(tcpProcessor).consume() + Source(tcpProcessor).connect(Sink.ignore).run() - Flow(testInput).toPublisher().subscribe(tcpProcessor) + Source(testInput).runWith(Sink.publisher).subscribe(tcpProcessor) serverConnection.waitRead() should be(expectedOutput) } @@ -63,7 +65,7 @@ class TcpFlowSpec extends AkkaSpec with TcpHelper { for (in ← testInput) serverConnection.write(in) new TcpWriteProbe(tcpProcessor) // Just register an idle upstream - val resultFuture = Flow(tcpProcessor).fold(ByteString.empty)((acc, in) ⇒ acc ++ in).toFuture() + val resultFuture = Source(tcpProcessor).fold(ByteString.empty)((acc, in) ⇒ acc ++ in) serverConnection.confirmedClose() Await.result(resultFuture, 3.seconds) should be(expectedOutput) @@ -156,8 +158,8 @@ class TcpFlowSpec extends AkkaSpec with TcpHelper { val testInput = Iterator.range(0, 256).map(ByteString(_)) val expectedOutput = ByteString(Array.tabulate(256)(_.asInstanceOf[Byte])) - Flow(testInput).toPublisher().subscribe(conn.outputStream) - val resultFuture = Flow(conn.inputStream).fold(ByteString.empty)((acc, in) ⇒ acc ++ in).toFuture() + Source(testInput).connect(Sink(conn.outputStream)).run() + val resultFuture = Source(conn.inputStream).fold(ByteString.empty)((acc, in) ⇒ acc ++ in) Await.result(resultFuture, 3.seconds) should be(expectedOutput) server.close() @@ -176,10 +178,10 @@ class TcpFlowSpec extends AkkaSpec with TcpHelper { val testInput = Iterator.range(0, 256).map(ByteString(_)) val expectedOutput = ByteString(Array.tabulate(256)(_.asInstanceOf[Byte])) - Flow(testInput).toPublisher().subscribe(conn1.outputStream) + Source(testInput).connect(Sink(conn1.outputStream)).run() conn1.inputStream.subscribe(conn2.outputStream) conn2.inputStream.subscribe(conn3.outputStream) - val resultFuture = Flow(conn3.inputStream).fold(ByteString.empty)((acc, in) ⇒ acc ++ in).toFuture() + val resultFuture = Source(conn3.inputStream).fold(ByteString.empty)((acc, in) ⇒ acc ++ in) Await.result(resultFuture, 3.seconds) should be(expectedOutput) server.close() diff --git a/akka-stream-tests/src/test/scala/akka/stream/io/TcpHelper.scala b/akka-stream-tests/src/test/scala/akka/stream/io/TcpHelper.scala index bc5593c750..1b3e7614c4 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io/TcpHelper.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io/TcpHelper.scala @@ -4,7 +4,6 @@ package akka.stream.io import java.io.Closeable - import akka.actor.{ Actor, ActorRef, Props } import akka.io.{ IO, Tcp } import akka.stream.scaladsl.Flow @@ -18,6 +17,7 @@ import org.reactivestreams.Processor import scala.collection.immutable.Queue import scala.concurrent.{ Await, Future } import scala.concurrent.duration.Duration +import akka.stream.scaladsl.Source object TcpHelper { case class ClientWrite(bytes: ByteString) @@ -204,7 +204,7 @@ trait TcpHelper { this: TestKitBase ⇒ def echoServer(serverAddress: InetSocketAddress = temporaryServerAddress): EchoServer = { val binding = bind(serverAddress) - new EchoServer(Flow(binding.connectionStream).foreach { conn ⇒ + new EchoServer(Source(binding.connectionStream).foreach { conn ⇒ conn.inputStream.subscribe(conn.outputStream) }, binding) } diff --git a/akka-stream-tests/src/test/scala/akka/stream/io2/TcpFlowSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/io2/TcpFlowSpec.scala index 10a56d2ecd..cb60015d0d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io2/TcpFlowSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io2/TcpFlowSpec.scala @@ -3,12 +3,13 @@ */ package akka.stream.io2 -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ import akka.stream.testkit.AkkaSpec import akka.util.ByteString - import scala.concurrent.{ Await, Future } import scala.concurrent.duration._ +import akka.stream.scaladsl.Source +import akka.stream.scaladsl.Sink class TcpFlowSpec extends AkkaSpec with TcpHelper { import akka.stream.io2.TcpHelper._ diff --git a/akka-stream-tests/src/test/scala/akka/stream/io2/TcpHelper.scala b/akka-stream-tests/src/test/scala/akka/stream/io2/TcpHelper.scala index ba1b3a6e99..1e3e2f74e5 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io2/TcpHelper.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io2/TcpHelper.scala @@ -4,11 +4,9 @@ package akka.stream.io2 import java.io.Closeable - import akka.actor.{ Actor, ActorRef, Props } import akka.io.{ IO, Tcp } import akka.stream.io2.StreamTcp.IncomingTcpConnection -import akka.stream.scaladsl2._ import akka.stream.testkit.StreamTestKit import akka.stream.MaterializerSettings import akka.testkit.{ TestKitBase, TestProbe } @@ -19,6 +17,10 @@ import org.reactivestreams.{ Subscriber, Publisher } import scala.collection.immutable.Queue import scala.concurrent.{ Await, Future } import scala.concurrent.duration._ +import akka.stream.scaladsl.Sink +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.Source +import akka.stream.scaladsl.Flow object TcpHelper { case class ClientWrite(bytes: ByteString) @@ -134,7 +136,9 @@ trait TcpHelper { this: TestKitBase ⇒ val serverRef = system.actorOf(testServerProps(address, serverProbe.ref)) serverProbe.expectMsgType[Tcp.Bound] - def waitAccept(): ServerConnection = new ServerConnection(serverProbe.expectMsgType[ActorRef]) + def waitAccept(): ServerConnection = { + new ServerConnection(serverProbe.expectMsgType[ActorRef]) + } def close(): Unit = serverRef ! ServerClose } diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowAppendSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAppendSpec.scala similarity index 96% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowAppendSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAppendSpec.scala index 322f6aa116..466ea64dcf 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowAppendSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowAppendSpec.scala @@ -1,9 +1,10 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import akka.actor.ActorSystem +import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings import akka.stream.testkit.{ AkkaSpec, StreamTestKit } import org.reactivestreams.Subscriber diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowBufferSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowBufferSpec.scala similarity index 99% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowBufferSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowBufferSpec.scala index 621b20b2e8..6ae529673c 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowBufferSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowBufferSpec.scala @@ -1,15 +1,17 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.OverflowStrategy.Error.BufferOverflowException -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } import scala.concurrent.Await +import scala.concurrent.Future import scala.concurrent.duration._ + +import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings import akka.stream.OverflowStrategy -import scala.concurrent.Future +import akka.stream.OverflowStrategy.Error.BufferOverflowException +import akka.stream.testkit.{ AkkaSpec, StreamTestKit } class FlowBufferSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowCollectSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCollectSpec.scala similarity index 90% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowCollectSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCollectSpec.scala index fdb90090d1..50cc146342 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowCollectSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCollectSpec.scala @@ -1,13 +1,13 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl + +import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } import akka.stream.MaterializerSettings import akka.stream.testkit.AkkaSpec -import akka.stream.testkit2.ScriptedTest - -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } +import akka.stream.testkit.ScriptedTest class FlowCollectSpec extends AkkaSpec with ScriptedTest { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowCompileSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCompileSpec.scala similarity index 98% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowCompileSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCompileSpec.scala index 84df7d4fb0..53659a40f7 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowCompileSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowCompileSpec.scala @@ -1,13 +1,15 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.MaterializerSettings -import akka.stream.testkit.AkkaSpec import scala.collection.immutable.Seq import scala.concurrent.Future +import akka.stream.FlowMaterializer +import akka.stream.MaterializerSettings +import akka.stream.testkit.AkkaSpec + class FlowCompileSpec extends AkkaSpec { val intSeq = Source(Seq(1, 2, 3)) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowConcatAllSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConcatAllSpec.scala similarity index 97% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowConcatAllSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConcatAllSpec.scala index a4beb51b29..4b6a853828 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowConcatAllSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConcatAllSpec.scala @@ -1,14 +1,14 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.testkit.{ StreamTestKit, AkkaSpec } import scala.concurrent.duration._ -import scala.concurrent.Await -import org.reactivestreams.Publisher import scala.util.control.NoStackTrace +import akka.stream.FlattenStrategy +import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings +import akka.stream.testkit.{ StreamTestKit, AkkaSpec } class FlowConcatAllSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowConflateSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConflateSpec.scala similarity index 97% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowConflateSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConflateSpec.scala index 46b82ce734..ffad9cfb0a 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowConflateSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowConflateSpec.scala @@ -1,13 +1,14 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.testkit.{ StreamTestKit, AkkaSpec } -import scala.concurrent.forkjoin.ThreadLocalRandom import scala.concurrent.Await import scala.concurrent.duration._ +import scala.concurrent.forkjoin.ThreadLocalRandom +import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings +import akka.stream.testkit.{ StreamTestKit, AkkaSpec } class FlowConflateSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowDispatcherSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDispatcherSpec.scala similarity index 91% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowDispatcherSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDispatcherSpec.scala index aeccc75bdc..f3b5a96399 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowDispatcherSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDispatcherSpec.scala @@ -1,10 +1,11 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import akka.testkit.TestProbe import akka.stream.testkit.AkkaSpec +import akka.stream.FlowMaterializer @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class FlowDispatcherSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowDropSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropSpec.scala similarity index 91% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowDropSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropSpec.scala index c56d68b47f..06f0723b26 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowDropSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropSpec.scala @@ -1,13 +1,15 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit2.ScriptedTest import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } -import akka.stream.testkit.StreamTestKit + +import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings +import akka.stream.testkit.AkkaSpec +import akka.stream.testkit.ScriptedTest +import akka.stream.testkit.StreamTestKit class FlowDropSpec extends AkkaSpec with ScriptedTest { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowDropWithinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWithinSpec.scala similarity index 95% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowDropWithinSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWithinSpec.scala index a157d0f429..cfc6b0e7e3 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowDropWithinSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowDropWithinSpec.scala @@ -1,9 +1,11 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.concurrent.duration._ + +import akka.stream.FlowMaterializer import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowExpandSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowExpandSpec.scala similarity index 98% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowExpandSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowExpandSpec.scala index c4eb2f46e3..a6f1d9b3ac 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowExpandSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowExpandSpec.scala @@ -1,14 +1,17 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.testkit.{ StreamTestKit, AkkaSpec } -import scala.concurrent.forkjoin.ThreadLocalRandom import scala.concurrent.Await import scala.concurrent.duration._ +import scala.concurrent.forkjoin.ThreadLocalRandom + +import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings +import akka.stream.testkit.{ StreamTestKit, AkkaSpec } + class FlowExpandSpec extends AkkaSpec { val settings = MaterializerSettings(system) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowFilterSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFilterSpec.scala similarity index 92% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowFilterSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFilterSpec.scala index 22c6a6f9b1..b43b4cd33e 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowFilterSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFilterSpec.scala @@ -1,14 +1,15 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 - -import akka.stream.MaterializerSettings -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } -import akka.stream.testkit2.ScriptedTest +package akka.stream.scaladsl import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } +import akka.stream.FlowMaterializer +import akka.stream.MaterializerSettings +import akka.stream.testkit.{ AkkaSpec, StreamTestKit } +import akka.stream.testkit.ScriptedTest + class FlowFilterSpec extends AkkaSpec with ScriptedTest { val settings = MaterializerSettings(system) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowFoldSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFoldSpec.scala similarity index 92% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowFoldSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFoldSpec.scala index 70df9730d7..e400013866 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowFoldSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFoldSpec.scala @@ -1,10 +1,12 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.concurrent.Await import scala.util.control.NoStackTrace + +import akka.stream.FlowMaterializer import akka.stream.testkit.AkkaSpec import akka.testkit.DefaultTimeout diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowForeachSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowForeachSpec.scala similarity index 91% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowForeachSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowForeachSpec.scala index 549bf1c22d..35654b5198 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowForeachSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowForeachSpec.scala @@ -1,13 +1,13 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } - -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } import scala.util.control.NoStackTrace +import akka.stream.FlowMaterializer +import akka.stream.testkit.{ AkkaSpec, StreamTestKit } + class FlowForeachSpec extends AkkaSpec { implicit val mat = FlowMaterializer() diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowFromFutureSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFromFutureSpec.scala similarity index 98% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowFromFutureSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFromFutureSpec.scala index 3043af52be..3f38ba53a6 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowFromFutureSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowFromFutureSpec.scala @@ -1,14 +1,17 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } import scala.concurrent.{ Future, Promise } import scala.concurrent.duration._ -import akka.stream.MaterializerSettings import scala.util.control.NoStackTrace +import akka.stream.FlowMaterializer +import akka.stream.MaterializerSettings + +import akka.stream.testkit.{ AkkaSpec, StreamTestKit } + class FlowFromFutureSpec extends AkkaSpec { val settings = MaterializerSettings(system) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGraphCompileSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGraphCompileSpec.scala similarity index 99% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGraphCompileSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGraphCompileSpec.scala index 42c01f7ef2..953de8a882 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGraphCompileSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGraphCompileSpec.scala @@ -1,9 +1,10 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import akka.stream.{ OverflowStrategy, Transformer } +import akka.stream.FlowMaterializer import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit.{ PublisherProbe, SubscriberProbe } diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGraphInitSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGraphInitSpec.scala similarity index 93% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGraphInitSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGraphInitSpec.scala index ae2a5e0c0a..db0d91fd72 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGraphInitSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGraphInitSpec.scala @@ -1,13 +1,14 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import scala.concurrent.duration._ -import akka.stream.{ OverflowStrategy, Transformer } -import scala.concurrent.Future -import akka.stream.testkit.AkkaSpec import scala.concurrent.Await +import scala.concurrent.Future +import scala.concurrent.duration._ + +import akka.stream.FlowMaterializer +import akka.stream.testkit.AkkaSpec class FlowGraphInitSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGroupBySpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupBySpec.scala similarity index 99% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGroupBySpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupBySpec.scala index 0dd6570471..1e8bbee842 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGroupBySpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupBySpec.scala @@ -1,13 +1,15 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.concurrent.duration._ +import scala.util.control.NoStackTrace + +import akka.stream.FlowMaterializer +import akka.stream.MaterializerSettings import akka.stream.testkit._ import org.reactivestreams.Publisher -import scala.util.control.NoStackTrace -import akka.stream.MaterializerSettings @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class FlowGroupBySpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGroupedSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedSpec.scala similarity index 93% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGroupedSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedSpec.scala index 2b9d715820..52d6f1ee8d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGroupedSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedSpec.scala @@ -1,13 +1,14 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.collection.immutable -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit2.ScriptedTest import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } + import akka.stream.MaterializerSettings +import akka.stream.testkit.AkkaSpec +import akka.stream.testkit.ScriptedTest class FlowGroupedSpec extends AkkaSpec with ScriptedTest { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGroupedWithinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedWithinSpec.scala similarity index 97% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGroupedWithinSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedWithinSpec.scala index b39519e2bf..c1b23ebd22 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowGroupedWithinSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowGroupedWithinSpec.scala @@ -1,15 +1,17 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.collection.immutable import scala.concurrent.duration._ import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit -import akka.stream.testkit2.ScriptedTest + +import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings +import akka.stream.testkit.AkkaSpec +import akka.stream.testkit.ScriptedTest +import akka.stream.testkit.StreamTestKit @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class FlowGroupedWithinSpec extends AkkaSpec with ScriptedTest { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowIterableSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIterableSpec.scala similarity index 98% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowIterableSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIterableSpec.scala index 57e6d14e45..1142978c84 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowIterableSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIterableSpec.scala @@ -1,12 +1,15 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl + +import scala.concurrent.duration._ + +import akka.stream.FlowMaterializer +import akka.stream.MaterializerSettings import akka.stream.testkit.{ AkkaSpec, StreamTestKit } import akka.stream.testkit.StreamTestKit.{ OnComplete, OnError, OnNext } -import scala.concurrent.duration._ -import akka.stream.MaterializerSettings @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class FlowIterableSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowIteratorSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIteratorSpec.scala similarity index 98% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowIteratorSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIteratorSpec.scala index fdf5a37d63..33f7e78808 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowIteratorSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowIteratorSpec.scala @@ -1,15 +1,17 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.concurrent.duration._ -import akka.stream.testkit.StreamTestKit + +import akka.stream.FlowMaterializer +import akka.stream.MaterializerSettings import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit.OnNext +import akka.stream.testkit.StreamTestKit import akka.stream.testkit.StreamTestKit.OnComplete import akka.stream.testkit.StreamTestKit.OnError -import akka.stream.MaterializerSettings +import akka.stream.testkit.StreamTestKit.OnNext @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class FlowIteratorSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowMapAsyncSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncSpec.scala similarity index 98% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowMapAsyncSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncSpec.scala index e11b6f9ea9..18d5d757fd 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowMapAsyncSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncSpec.scala @@ -1,17 +1,19 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl +import scala.concurrent.Await +import scala.concurrent.Future import scala.concurrent.duration._ import scala.concurrent.forkjoin.ThreadLocalRandom import scala.util.control.NoStackTrace + +import akka.stream.FlowMaterializer import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit -import akka.testkit.TestProbe import akka.testkit.TestLatch -import scala.concurrent.Await -import scala.concurrent.Future +import akka.testkit.TestProbe @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class FlowMapAsyncSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowMapAsyncUnorderedSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncUnorderedSpec.scala similarity index 97% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowMapAsyncUnorderedSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncUnorderedSpec.scala index 4ba9eb84ab..fa34c8df0f 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowMapAsyncUnorderedSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapAsyncUnorderedSpec.scala @@ -1,17 +1,18 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import scala.concurrent.duration._ -import scala.concurrent.forkjoin.ThreadLocalRandom -import scala.util.control.NoStackTrace -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit -import akka.testkit.TestProbe -import akka.testkit.TestLatch import scala.concurrent.Await import scala.concurrent.Future +import scala.concurrent.duration._ +import scala.util.control.NoStackTrace + +import akka.stream.FlowMaterializer +import akka.stream.testkit.AkkaSpec +import akka.stream.testkit.StreamTestKit +import akka.testkit.TestLatch +import akka.testkit.TestProbe class FlowMapAsyncUnorderedSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowMapConcatSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapConcatSpec.scala similarity index 91% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowMapConcatSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapConcatSpec.scala index bb1a5e6fa3..87aa84a0c0 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowMapConcatSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapConcatSpec.scala @@ -1,11 +1,11 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import akka.stream.MaterializerSettings import akka.stream.testkit.AkkaSpec -import akka.stream.testkit2.ScriptedTest +import akka.stream.testkit.ScriptedTest class FlowMapConcatSpec extends AkkaSpec with ScriptedTest { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowMapSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapSpec.scala similarity index 91% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowMapSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapSpec.scala index c29bd6343a..a76de7df93 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowMapSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowMapSpec.scala @@ -1,14 +1,15 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 - -import akka.stream.MaterializerSettings -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } -import akka.stream.testkit2.ScriptedTest +package akka.stream.scaladsl import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } +import akka.stream.FlowMaterializer +import akka.stream.MaterializerSettings +import akka.stream.testkit.{ AkkaSpec, StreamTestKit } +import akka.stream.testkit.ScriptedTest + class FlowMapSpec extends AkkaSpec with ScriptedTest { val settings = MaterializerSettings(system) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowOnCompleteSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowOnCompleteSpec.scala similarity index 94% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowOnCompleteSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowOnCompleteSpec.scala index e36653ef22..44504bdb64 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowOnCompleteSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowOnCompleteSpec.scala @@ -1,17 +1,18 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl +import scala.concurrent.duration._ +import scala.util.{ Failure, Success } +import scala.util.control.NoStackTrace + +import akka.stream.FlowMaterializer +import akka.stream.MaterializerSettings import akka.stream.testkit.{ AkkaSpec, StreamTestKit } import akka.stream.testkit.AkkaSpec -import akka.stream.testkit2.ScriptedTest +import akka.stream.testkit.ScriptedTest import akka.testkit.TestProbe -import scala.concurrent.duration._ -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } -import scala.util.control.NoStackTrace -import scala.util.{ Failure, Success } -import akka.stream.MaterializerSettings @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class FlowOnCompleteSpec extends AkkaSpec with ScriptedTest { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowPrefixAndTailSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowPrefixAndTailSpec.scala similarity index 98% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowPrefixAndTailSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowPrefixAndTailSpec.scala index a47579eaea..1e337a0282 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowPrefixAndTailSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowPrefixAndTailSpec.scala @@ -1,15 +1,16 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.collection.immutable -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } -import org.reactivestreams.Publisher import scala.concurrent.Await import scala.concurrent.duration._ import scala.util.control.NoStackTrace + +import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings +import akka.stream.testkit.{ AkkaSpec, StreamTestKit } import akka.stream.testkit.StreamTestKit.SubscriberProbe class FlowPrefixAndTailSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSpec.scala similarity index 98% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSpec.scala index aaa0871e51..3ef2b6213d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSpec.scala @@ -1,23 +1,26 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.actor.{ Props, ActorRefFactory, ActorRef } -import akka.stream.impl.TransformProcessorImpl -import akka.stream.impl2.Ast.{ Transform, AstNode } -import akka.stream.impl2.{ ActorProcessorFactory, StreamSupervisor, ActorBasedFlowMaterializer } -import akka.stream.testkit.{ StreamTestKit, AkkaSpec } -import akka.stream.testkit2.ChainSetup -import akka.stream.{ TransformerLike, MaterializerSettings } -import akka.testkit.TestEvent.{ UnMute, Mute } -import akka.testkit._ -import com.typesafe.config.ConfigFactory import java.util.concurrent.atomic.AtomicLong -import org.reactivestreams.{ Processor, Subscriber, Publisher } + import scala.collection.immutable import scala.concurrent.duration._ +import akka.actor.{ Props, ActorRefFactory, ActorRef } +import akka.stream.{ TransformerLike, MaterializerSettings } +import akka.stream.FlowMaterializer +import akka.stream.impl.{ ActorProcessorFactory, StreamSupervisor, ActorBasedFlowMaterializer } +import akka.stream.impl.Ast.{ Transform, AstNode } +import akka.stream.impl.TransformProcessorImpl +import akka.stream.testkit.{ StreamTestKit, AkkaSpec } +import akka.stream.testkit.ChainSetup +import akka.testkit._ +import akka.testkit.TestEvent.{ UnMute, Mute } +import com.typesafe.config.ConfigFactory +import org.reactivestreams.{ Processor, Subscriber, Publisher } + object FlowSpec { class Fruit class Apple extends Fruit diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowSplitWhenSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSplitWhenSpec.scala similarity index 97% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowSplitWhenSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSplitWhenSpec.scala index 2ef905e0b0..a838cd6052 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowSplitWhenSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowSplitWhenSpec.scala @@ -1,13 +1,15 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.concurrent.duration._ -import akka.stream.testkit.StreamTestKit -import akka.stream.testkit.AkkaSpec -import org.reactivestreams.Publisher + +import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings +import akka.stream.testkit.AkkaSpec +import akka.stream.testkit.StreamTestKit +import org.reactivestreams.Publisher @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class FlowSplitWhenSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTakeSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeSpec.scala similarity index 92% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTakeSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeSpec.scala index 590b1704fa..fb789f3285 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTakeSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeSpec.scala @@ -1,16 +1,18 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl +import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } + +import akka.stream.FlowMaterializer +import akka.stream.MaterializerSettings import akka.stream.actor.ActorSubscriberMessage.OnComplete import akka.stream.actor.ActorSubscriberMessage.OnNext import akka.stream.impl.RequestMore import akka.stream.testkit.AkkaSpec -import akka.stream.testkit2.ScriptedTest +import akka.stream.testkit.ScriptedTest import akka.stream.testkit.StreamTestKit -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } -import akka.stream.MaterializerSettings class FlowTakeSpec extends AkkaSpec with ScriptedTest { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTakeWithinSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWithinSpec.scala similarity index 96% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTakeWithinSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWithinSpec.scala index 155f910a2e..858656ed81 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTakeWithinSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTakeWithinSpec.scala @@ -1,9 +1,11 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.concurrent.duration._ + +import akka.stream.FlowMaterializer import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowThunkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowThunkSpec.scala similarity index 96% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowThunkSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowThunkSpec.scala index ae02222048..2c9d4f2ab4 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowThunkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowThunkSpec.scala @@ -1,9 +1,11 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.concurrent.duration._ + +import akka.stream.FlowMaterializer import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit import akka.stream.testkit.StreamTestKit.OnComplete diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTimerTransformerSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTimerTransformerSpec.scala similarity index 97% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTimerTransformerSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTimerTransformerSpec.scala index 70c9bc371e..e31b3a6d85 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTimerTransformerSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTimerTransformerSpec.scala @@ -1,13 +1,16 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } -import akka.stream.TimerTransformer import scala.concurrent.duration._ import scala.util.control.NoStackTrace +import akka.stream.FlowMaterializer +import akka.stream.TimerTransformer + +import akka.stream.testkit.{ AkkaSpec, StreamTestKit } + @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class FlowTimerTransformerSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTransformRecoverSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTransformRecoverSpec.scala similarity index 99% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTransformRecoverSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTransformRecoverSpec.scala index 8ea079cbc0..8b86135bf5 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTransformRecoverSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTransformRecoverSpec.scala @@ -1,19 +1,21 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl +import scala.collection.immutable +import scala.concurrent.duration._ +import scala.util.Failure +import scala.util.Success +import scala.util.Try +import scala.util.control.NoStackTrace + +import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings import akka.stream.Transformer import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit import akka.testkit.EventFilter -import scala.collection.immutable -import scala.concurrent.duration._ -import scala.util.control.NoStackTrace -import scala.util.Failure -import scala.util.Success -import scala.util.Try object FlowTransformRecoverSpec { abstract class TryRecoveryTransformer[T, U] extends Transformer[T, U] { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTransformSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTransformSpec.scala similarity index 99% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTransformSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTransformSpec.scala index 62e306bd74..86b55bb639 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FlowTransformSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FlowTransformSpec.scala @@ -1,16 +1,18 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } -import akka.testkit.{ EventFilter, TestProbe } -import com.typesafe.config.ConfigFactory import scala.collection.immutable.Seq import scala.concurrent.duration._ import scala.util.control.NoStackTrace -import akka.stream.Transformer + +import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings +import akka.stream.Transformer +import akka.stream.testkit.{ AkkaSpec, StreamTestKit } +import akka.testkit.{ EventFilter, TestProbe } +import com.typesafe.config.ConfigFactory @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class FlowTransformSpec extends AkkaSpec(ConfigFactory.parseString("akka.actor.debug.receive=off\nakka.loglevel=INFO")) { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FutureSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FutureSinkSpec.scala similarity index 93% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FutureSinkSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/FutureSinkSpec.scala index 084818c732..b0de2f32a2 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/FutureSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/FutureSinkSpec.scala @@ -1,16 +1,17 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } -import akka.stream.testkit2.ScriptedTest import scala.concurrent.Await -import scala.concurrent.duration._ -import scala.concurrent.forkjoin.ThreadLocalRandom.{ current ⇒ random } -import scala.util.Failure -import akka.stream.MaterializerSettings import scala.concurrent.Future +import scala.concurrent.duration._ +import scala.util.Failure + +import akka.stream.FlowMaterializer +import akka.stream.MaterializerSettings +import akka.stream.testkit.{ AkkaSpec, StreamTestKit } +import akka.stream.testkit.ScriptedTest class FutureSinkSpec extends AkkaSpec with ScriptedTest { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphBalanceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBalanceSpec.scala similarity index 98% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphBalanceSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBalanceSpec.scala index f5c03e663d..0ce2501492 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphBalanceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBalanceSpec.scala @@ -1,12 +1,14 @@ -package akka.stream.scaladsl2 - -import akka.stream.MaterializerSettings -import FlowGraphImplicits._ -import akka.stream.testkit.{ AkkaSpec, StreamTestKit } +package akka.stream.scaladsl import scala.concurrent.Await import scala.concurrent.duration._ +import FlowGraphImplicits._ +import akka.stream.FlowMaterializer + +import akka.stream.MaterializerSettings +import akka.stream.testkit.{ AkkaSpec, StreamTestKit } + class GraphBalanceSpec extends AkkaSpec { val settings = MaterializerSettings(system) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphBroadcastSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBroadcastSpec.scala similarity index 98% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphBroadcastSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBroadcastSpec.scala index 864c1f872c..8cfb990dbb 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphBroadcastSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphBroadcastSpec.scala @@ -1,10 +1,12 @@ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.{ OverflowStrategy, MaterializerSettings } -import akka.stream.testkit.{ StreamTestKit, AkkaSpec } import scala.concurrent.Await import scala.concurrent.duration._ + import FlowGraphImplicits._ +import akka.stream.{ OverflowStrategy, MaterializerSettings } +import akka.stream.FlowMaterializer +import akka.stream.testkit.{ StreamTestKit, AkkaSpec } class GraphBroadcastSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphConcatSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphConcatSpec.scala similarity index 96% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphConcatSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphConcatSpec.scala index 26d8fce583..aa7c4f3543 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphConcatSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphConcatSpec.scala @@ -1,14 +1,15 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.testkit.StreamTestKit -import akka.stream.scaladsl2._ -import akka.stream.scaladsl2.FlowGraphImplicits._ -import akka.stream.testkit2.TwoStreamsSetup import scala.concurrent.Promise +import akka.stream.scaladsl._ +import akka.stream.scaladsl.FlowGraphImplicits._ +import akka.stream.testkit.StreamTestKit +import akka.stream.testkit.TwoStreamsSetup + class GraphConcatSpec extends TwoStreamsSetup { override type Outputs = Int diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphFlexiMergeSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphFlexiMergeSpec.scala similarity index 99% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphFlexiMergeSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphFlexiMergeSpec.scala index ced3dfc9a8..27d9544116 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphFlexiMergeSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphFlexiMergeSpec.scala @@ -1,12 +1,14 @@ -package akka.stream.scaladsl2 +package akka.stream.scaladsl + +import scala.util.control.NoStackTrace -import akka.stream.testkit.AkkaSpec import FlowGraphImplicits._ -import akka.stream.testkit.StreamTestKit.SubscriberProbe +import akka.stream.FlowMaterializer +import akka.stream.testkit.AkkaSpec +import akka.stream.testkit.StreamTestKit.AutoPublisher import akka.stream.testkit.StreamTestKit.OnNext import akka.stream.testkit.StreamTestKit.PublisherProbe -import akka.stream.testkit.StreamTestKit.AutoPublisher -import scala.util.control.NoStackTrace +import akka.stream.testkit.StreamTestKit.SubscriberProbe object GraphFlexiMergeSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphFlowSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphFlowSpec.scala similarity index 98% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphFlowSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphFlowSpec.scala index 1ff27c4746..f216b141f3 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphFlowSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphFlowSpec.scala @@ -1,11 +1,13 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl +import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings +import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit.SubscriberProbe -import akka.stream.testkit.{ StreamTestKit, AkkaSpec } +import akka.stream.testkit.StreamTestKit object GraphFlowSpec { val source1 = Source(0 to 3) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphMergeSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphMergeSpec.scala similarity index 96% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphMergeSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphMergeSpec.scala index 359b7288f5..4eb55fd436 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphMergeSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphMergeSpec.scala @@ -1,12 +1,13 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.concurrent.duration._ + +import akka.stream.scaladsl.FlowGraphImplicits._ import akka.stream.testkit.StreamTestKit -import akka.stream.testkit2.TwoStreamsSetup -import akka.stream.scaladsl2.FlowGraphImplicits._ +import akka.stream.testkit.TwoStreamsSetup class GraphMergeSpec extends TwoStreamsSetup { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphOpsIntegrationSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphOpsIntegrationSpec.scala similarity index 97% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphOpsIntegrationSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphOpsIntegrationSpec.scala index 8668b93c33..df86443004 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphOpsIntegrationSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphOpsIntegrationSpec.scala @@ -1,14 +1,15 @@ -package akka.stream.scaladsl2 - -import akka.stream.MaterializerSettings -import akka.stream.scaladsl2.FlowGraphImplicits._ -import akka.stream.testkit.AkkaSpec -import akka.stream.testkit.StreamTestKit.{ OnNext, SubscriberProbe } -import akka.util.ByteString +package akka.stream.scaladsl import scala.concurrent.Await import scala.concurrent.duration._ +import akka.stream.FlowMaterializer +import akka.stream.MaterializerSettings +import akka.stream.scaladsl.FlowGraphImplicits._ +import akka.stream.testkit.AkkaSpec +import akka.stream.testkit.StreamTestKit.{ OnNext, SubscriberProbe } +import akka.util.ByteString + object GraphOpsIntegrationSpec { object Lego { @@ -52,7 +53,7 @@ object GraphOpsIntegrationSpec { } class GraphOpsIntegrationSpec extends AkkaSpec { - import akka.stream.scaladsl2.GraphOpsIntegrationSpec._ + import akka.stream.scaladsl.GraphOpsIntegrationSpec._ val settings = MaterializerSettings(system) .withInputBuffer(initialSize = 2, maxSize = 16) diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphPreferredMergeSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphPreferredMergeSpec.scala similarity index 91% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphPreferredMergeSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphPreferredMergeSpec.scala index 2073214ac9..b16978af63 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphPreferredMergeSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphPreferredMergeSpec.scala @@ -1,14 +1,14 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 - -import akka.stream.scaladsl2.FlowGraphImplicits._ -import akka.stream.testkit2.TwoStreamsSetup +package akka.stream.scaladsl import scala.concurrent.Await import scala.concurrent.duration._ +import akka.stream.scaladsl.FlowGraphImplicits._ +import akka.stream.testkit.TwoStreamsSetup + class GraphPreferredMergeSpec extends TwoStreamsSetup { override type Outputs = Int diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphUnzipSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphUnzipSpec.scala similarity index 97% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphUnzipSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphUnzipSpec.scala index 8f0391ef20..2c5f632f6a 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphUnzipSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphUnzipSpec.scala @@ -1,10 +1,11 @@ -package akka.stream.scaladsl2 +package akka.stream.scaladsl + +import scala.concurrent.duration._ import akka.stream.{ OverflowStrategy, MaterializerSettings } +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.FlowGraphImplicits._ import akka.stream.testkit.{ StreamTestKit, AkkaSpec } -import scala.concurrent.Await -import scala.concurrent.duration._ -import akka.stream.scaladsl2.FlowGraphImplicits._ class GraphUnzipSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphZipSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipSpec.scala similarity index 95% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphZipSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipSpec.scala index 4e0cc8bd48..ef4b80e09d 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/GraphZipSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/GraphZipSpec.scala @@ -1,8 +1,8 @@ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.scaladsl2.FlowGraphImplicits._ +import akka.stream.scaladsl.FlowGraphImplicits._ import akka.stream.testkit.StreamTestKit -import akka.stream.testkit2.TwoStreamsSetup +import akka.stream.testkit.TwoStreamsSetup class GraphZipSpec extends TwoStreamsSetup { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/ImplicitFlowMaterializerSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ImplicitFlowMaterializerSpec.scala similarity index 93% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/ImplicitFlowMaterializerSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/ImplicitFlowMaterializerSpec.scala index a71141528f..139998e1f6 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/ImplicitFlowMaterializerSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/ImplicitFlowMaterializerSpec.scala @@ -1,13 +1,13 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import akka.actor.{ Actor, Props } -import akka.pattern.pipe import akka.stream.MaterializerSettings import akka.stream.testkit.AkkaSpec import akka.testkit._ +import akka.pattern.pipe object ImplicitFlowMaterializerSpec { class SomeActor(input: List[String]) extends Actor with ImplicitFlowMaterializer { @@ -29,7 +29,7 @@ object ImplicitFlowMaterializerSpec { @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class ImplicitFlowMaterializerSpec extends AkkaSpec with ImplicitSender { - import akka.stream.ImplicitFlowMaterializerSpec._ + import ImplicitFlowMaterializerSpec._ "An ImplicitFlowMaterializer" must { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/PublisherSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/PublisherSinkSpec.scala similarity index 92% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/PublisherSinkSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/PublisherSinkSpec.scala index 64af33698e..957848316e 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/PublisherSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/PublisherSinkSpec.scala @@ -1,7 +1,9 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl + +import akka.stream.FlowMaterializer import akka.stream.testkit.AkkaSpec import org.scalatest.concurrent.ScalaFutures._ diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/SourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceSpec.scala similarity index 96% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/SourceSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceSpec.scala index 63c844bee7..6fd38b64bd 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/SourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SourceSpec.scala @@ -1,10 +1,12 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.concurrent.duration._ import scala.util.control.NoStackTrace + +import akka.stream.FlowMaterializer import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/SubscriberSinkSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSinkSpec.scala similarity index 92% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/SubscriberSinkSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSinkSpec.scala index 6fe3f24c23..8888210ba4 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/SubscriberSinkSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/SubscriberSinkSpec.scala @@ -1,11 +1,12 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl +import akka.stream.FlowMaterializer +import akka.stream.MaterializerSettings import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit -import akka.stream.MaterializerSettings class SubscriberSinkSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/TickSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/TickSourceSpec.scala similarity index 98% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/TickSourceSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/TickSourceSpec.scala index 3eec3ad0c9..999f1322b8 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/TickSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/TickSourceSpec.scala @@ -1,12 +1,14 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.concurrent.duration._ +import scala.util.control.NoStackTrace + +import akka.stream.FlowMaterializer import akka.stream.testkit.AkkaSpec import akka.stream.testkit.StreamTestKit -import scala.util.control.NoStackTrace @org.junit.runner.RunWith(classOf[org.scalatest.junit.JUnitRunner]) class TickSourceSpec extends AkkaSpec { diff --git a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/TimerTransformerSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/TimerTransformerSpec.scala similarity index 99% rename from akka-stream-tests/src/test/scala/akka/stream/scaladsl2/TimerTransformerSpec.scala rename to akka-stream-tests/src/test/scala/akka/stream/scaladsl/TimerTransformerSpec.scala index 8070bd835b..11285c1e9e 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/scaladsl2/TimerTransformerSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/scaladsl/TimerTransformerSpec.scala @@ -1,20 +1,21 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import language.postfixOps import scala.collection.immutable import scala.concurrent.duration._ + import akka.actor.Actor import akka.actor.ActorCell import akka.actor.ActorRef import akka.actor.Props +import akka.stream.TimerTransformer import akka.stream.TimerTransformer.Scheduled import akka.stream.testkit.AkkaSpec import akka.testkit.TestDuration import akka.testkit.TestKit -import akka.stream.TimerTransformer object TimerTransformerSpec { case object TestSingleTimer diff --git a/akka-stream/src/main/scala/akka/persistence/stream/PersistentSource.scala b/akka-stream/src/main/scala/akka/persistence/stream/PersistentSource.scala index 80eec192d1..4ce7cadfdf 100644 --- a/akka-stream/src/main/scala/akka/persistence/stream/PersistentSource.scala +++ b/akka-stream/src/main/scala/akka/persistence/stream/PersistentSource.scala @@ -15,8 +15,8 @@ import akka.stream.impl.SoftShutdown import akka.stream.impl.Stop import akka.stream.impl.SubscribePending import akka.stream.impl.SubscriberManagement -import akka.stream.impl2.ActorBasedFlowMaterializer -import akka.stream.scaladsl2.KeyedActorFlowSource +import akka.stream.impl.ActorBasedFlowMaterializer +import akka.stream.scaladsl.KeyedActorFlowSource import org.reactivestreams.Subscriber import scala.concurrent.duration._ @@ -115,7 +115,8 @@ private class PersistentSourceImpl(persistenceId: String, sourceSettings: Persis try { ps.foreach(pushToDownstream) } catch { - case Stop ⇒ completeDownstream(); shutdownReason = None + case Stop ⇒ + completeDownstream(); shutdownReason = None case NonFatal(e) ⇒ abortDownstream(e); shutdownReason = Some(e) } } diff --git a/akka-stream/src/main/scala/akka/stream/FlattenStrategy.scala b/akka-stream/src/main/scala/akka/stream/FlattenStrategy.scala index e301b589c3..8f56fb8773 100644 --- a/akka-stream/src/main/scala/akka/stream/FlattenStrategy.scala +++ b/akka-stream/src/main/scala/akka/stream/FlattenStrategy.scala @@ -17,9 +17,7 @@ object FlattenStrategy { * emitting its elements directly to the output until it completes and then taking the next stream. This has the * consequence that if one of the input stream is infinite, no other streams after that will be consumed from. */ - @deprecated("This is old API, instead use APIs using Source (akka.stream.scaladsl2 / akka.stream.javadsl)", since = "0.9") - def concat[T]: FlattenStrategy[Publisher[T], T] = Concat[T]() + def concat[T]: FlattenStrategy[scaladsl.Source[T], T] = Concat[T]() - @deprecated("This is old API, instead use APIs using Source (akka.stream.scaladsl2 / akka.stream.javadsl)", since = "0.9") - private[akka] case class Concat[T]() extends FlattenStrategy[Publisher[T], T] -} \ No newline at end of file + private[akka] case class Concat[T]() extends FlattenStrategy[scaladsl.Source[T], T] +} diff --git a/akka-stream/src/main/scala/akka/stream/FlowMaterializer.scala b/akka-stream/src/main/scala/akka/stream/FlowMaterializer.scala index e877a89598..3635f89251 100644 --- a/akka-stream/src/main/scala/akka/stream/FlowMaterializer.scala +++ b/akka-stream/src/main/scala/akka/stream/FlowMaterializer.scala @@ -3,10 +3,13 @@ */ package akka.stream -import akka.actor._ +import scala.collection.immutable + +import akka.actor.{ ActorContext, ActorRefFactory, ActorSystem, ExtendedActorSystem } import akka.stream.impl.{ ActorBasedFlowMaterializer, Ast, FlowNameCounter, StreamSupervisor } import com.typesafe.config.Config -import org.reactivestreams.{ Publisher, Subscriber } +import org.reactivestreams.Publisher +import org.reactivestreams.Subscriber object FlowMaterializer { @@ -124,26 +127,25 @@ object FlowMaterializer { abstract class FlowMaterializer(val settings: MaterializerSettings) { /** - * The `namePrefix` is used as the first part of the names of the actors running - * the processing steps. + * The `namePrefix` shall be used for deriving the names of processing + * entities that are created during materialization. This is meant to aid + * logging and error reporting both during materialization and while the + * stream is running. */ def withNamePrefix(name: String): FlowMaterializer + // FIXME this is scaladsl specific /** - * INTERNAL API - * ops are stored in reverse order + * This method interprets the given Flow description and creates the running + * stream. The result can be highly implementation specific, ranging from + * local actor chains to remote-deployed processing networks. */ - private[akka] def toPublisher[I, O](publisherNode: Ast.PublisherNode[I], ops: List[Ast.AstNode]): Publisher[O] + def materialize[In, Out](source: scaladsl.Source[In], sink: scaladsl.Sink[Out], ops: List[Ast.AstNode]): scaladsl.MaterializedMap /** - * INTERNAL API + * Create publishers and subscribers for fan-in and fan-out operations. */ - private[akka] def ductProduceTo[In, Out](subscriber: Subscriber[Out], ops: List[Ast.AstNode]): Subscriber[In] - - /** - * INTERNAL API - */ - private[akka] def ductBuild[In, Out](ops: List[Ast.AstNode]): (Subscriber[In], Publisher[Out]) + def materializeJunction[In, Out](op: Ast.JunctionAstNode, inputCount: Int, outputCount: Int): (immutable.Seq[Subscriber[In]], immutable.Seq[Publisher[Out]]) } @@ -190,6 +192,12 @@ object MaterializerSettings { apply(config) } +/** + * This exception or subtypes thereof should be used to signal materialization + * failures. + */ +class MaterializationException(msg: String, cause: Throwable = null) extends RuntimeException(msg, cause) + /** * The buffers employed by the generated Processors can be configured by * creating an appropriate instance of this class. diff --git a/akka-stream/src/main/scala/akka/stream/extra/Implicits.scala b/akka-stream/src/main/scala/akka/stream/extra/Implicits.scala index aa6a5b07c1..efb3a4d461 100644 --- a/akka-stream/src/main/scala/akka/stream/extra/Implicits.scala +++ b/akka-stream/src/main/scala/akka/stream/extra/Implicits.scala @@ -4,12 +4,12 @@ package akka.stream.extra import scala.language.implicitConversions -import akka.stream.scaladsl.Duct import akka.stream.scaladsl.Flow +import akka.stream.scaladsl.Source import scala.concurrent.duration.FiniteDuration /** - * Additional [[akka.stream.scaladsl.Flow]] and [[akka.stream.scaladsl.Duct]] operators. + * Additional [[akka.stream.scaladsl.Flow]] and [[akka.stream.scaladsl.Flow]] operators. */ object Implicits { @@ -18,18 +18,18 @@ object Implicits { * * See [[Timed]] */ - implicit class TimedFlowDsl[I](val flow: Flow[I]) extends AnyVal { + implicit class TimedSourceDsl[I](val flow: Source[I]) extends AnyVal { /** * Measures time from receieving the first element and completion events - one for each subscriber of this `Flow`. */ - def timed[O](measuredOps: Flow[I] ⇒ Flow[O], onComplete: FiniteDuration ⇒ Unit): Flow[O] = + def timed[O](measuredOps: Source[I] ⇒ Source[O], onComplete: FiniteDuration ⇒ Unit): Source[O] = Timed.timed[I, O](flow, measuredOps, onComplete) /** * Measures rolling interval between immediatly subsequent `matching(o: O)` elements. */ - def timedIntervalBetween(matching: I ⇒ Boolean, onInterval: FiniteDuration ⇒ Unit): Flow[I] = + def timedIntervalBetween(matching: I ⇒ Boolean, onInterval: FiniteDuration ⇒ Unit): Source[I] = Timed.timedIntervalBetween[I](flow, matching, onInterval) } @@ -38,19 +38,19 @@ object Implicits { * * See [[Timed]] */ - implicit class TimedDuctDsl[I, O](val duct: Duct[I, O]) extends AnyVal { + implicit class TimedFlowDsl[I, O](val flow: Flow[I, O]) extends AnyVal { /** * Measures time from receieving the first element and completion events - one for each subscriber of this `Flow`. */ - def timed[Out](measuredOps: Duct[I, O] ⇒ Duct[O, Out], onComplete: FiniteDuration ⇒ Unit): Duct[O, Out] = - Timed.timed[I, O, Out](duct, measuredOps, onComplete) + def timed[Out](measuredOps: Flow[I, O] ⇒ Flow[O, Out], onComplete: FiniteDuration ⇒ Unit): Flow[O, Out] = + Timed.timed[I, O, Out](flow, measuredOps, onComplete) /** * Measures rolling interval between immediatly subsequent `matching(o: O)` elements. */ - def timedIntervalBetween(matching: O ⇒ Boolean, onInterval: FiniteDuration ⇒ Unit): Duct[I, O] = - Timed.timedIntervalBetween[I, O](duct, matching, onInterval) + def timedIntervalBetween(matching: O ⇒ Boolean, onInterval: FiniteDuration ⇒ Unit): Flow[I, O] = + Timed.timedIntervalBetween[I, O](flow, matching, onInterval) } } \ No newline at end of file diff --git a/akka-stream/src/main/scala/akka/stream/extra/Timed.scala b/akka-stream/src/main/scala/akka/stream/extra/Timed.scala index 1995b2d5d0..39f9de0215 100644 --- a/akka-stream/src/main/scala/akka/stream/extra/Timed.scala +++ b/akka-stream/src/main/scala/akka/stream/extra/Timed.scala @@ -3,14 +3,14 @@ */ package akka.stream.extra -import akka.stream.scaladsl.{ Duct, Flow } import scala.collection.immutable import java.util.concurrent.atomic.AtomicLong import scala.concurrent.duration._ - import scala.language.implicitConversions import scala.language.existentials import akka.stream.Transformer +import akka.stream.scaladsl.Source +import akka.stream.scaladsl.Flow /** * Provides operations needed to implement the `timed` DSL @@ -24,7 +24,7 @@ private[akka] trait TimedOps { * * Measures time from receieving the first element and completion events - one for each subscriber of this `Flow`. */ - def timed[I, O](flow: Flow[I], measuredOps: Flow[I] ⇒ Flow[O], onComplete: FiniteDuration ⇒ Unit): Flow[O] = { + def timed[I, O](flow: Source[I], measuredOps: Source[I] ⇒ Source[O], onComplete: FiniteDuration ⇒ Unit): Source[O] = { val ctx = new TimedFlowContext val startWithTime = flow.transform("startTimed", () ⇒ new StartTimedFlow(ctx)) @@ -37,12 +37,12 @@ private[akka] trait TimedOps { * * Measures time from receieving the first element and completion events - one for each subscriber of this `Flow`. */ - def timed[I, O, Out](duct: Duct[I, O], measuredOps: Duct[I, O] ⇒ Duct[O, Out], onComplete: FiniteDuration ⇒ Unit): Duct[O, Out] = { - // todo is there any other way to provide this for Flow / Duct, without duplicating impl? (they don't share any super-type) + def timed[I, O, Out](flow: Flow[I, O], measuredOps: Flow[I, O] ⇒ Flow[O, Out], onComplete: FiniteDuration ⇒ Unit): Flow[O, Out] = { + // todo is there any other way to provide this for Flow, without duplicating impl? (they don't share any super-type) val ctx = new TimedFlowContext - val startWithTime: Duct[I, O] = duct.transform("startTimed", () ⇒ new StartTimedFlow(ctx)) - val userFlow: Duct[O, Out] = measuredOps(startWithTime) + val startWithTime: Flow[I, O] = flow.transform("startTimed", () ⇒ new StartTimedFlow(ctx)) + val userFlow: Flow[O, Out] = measuredOps(startWithTime) userFlow.transform("stopTimed", () ⇒ new StopTimed(ctx, onComplete)) } @@ -60,16 +60,16 @@ private[akka] trait TimedIntervalBetweenOps { /** * Measures rolling interval between immediatly subsequent `matching(o: O)` elements. */ - def timedIntervalBetween[O](flow: Flow[O], matching: O ⇒ Boolean, onInterval: FiniteDuration ⇒ Unit): Flow[O] = { + def timedIntervalBetween[O](flow: Source[O], matching: O ⇒ Boolean, onInterval: FiniteDuration ⇒ Unit): Source[O] = { flow.transform("timedInterval", () ⇒ new TimedIntervalTransformer[O](matching, onInterval)) } /** * Measures rolling interval between immediatly subsequent `matching(o: O)` elements. */ - def timedIntervalBetween[I, O](duct: Duct[I, O], matching: O ⇒ Boolean, onInterval: FiniteDuration ⇒ Unit): Duct[I, O] = { + def timedIntervalBetween[I, O](flow: Flow[I, O], matching: O ⇒ Boolean, onInterval: FiniteDuration ⇒ Unit): Flow[I, O] = { // todo is there any other way to provide this for Flow / Duct, without duplicating impl? (they don't share any super-type) - duct.transform("timedInterval", () ⇒ new TimedIntervalTransformer[O](matching, onInterval)) + flow.transform("timedInterval", () ⇒ new TimedIntervalTransformer[O](matching, onInterval)) } } diff --git a/akka-stream/src/main/scala/akka/stream/impl/ActorBasedFlowMaterializer.scala b/akka-stream/src/main/scala/akka/stream/impl/ActorBasedFlowMaterializer.scala index fb3781c411..56d3dc2dd4 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/ActorBasedFlowMaterializer.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/ActorBasedFlowMaterializer.scala @@ -5,16 +5,29 @@ package akka.stream.impl import java.util.concurrent.atomic.AtomicLong -import akka.actor.{ Actor, ActorCell, ActorRef, ActorSystem, ExtendedActorSystem, Extension, ExtensionId, ExtensionIdProvider, LocalActorRef, Props, RepointableActorRef } -import akka.pattern.ask -import akka.stream._ -import org.reactivestreams.{ Processor, Publisher, Subscriber } - import scala.annotation.tailrec import scala.collection.immutable import scala.concurrent.{ Await, Future } -import scala.concurrent.duration._ -import scala.util.{ Failure, Success } + +import akka.actor.Actor +import akka.actor.ActorCell +import akka.actor.ActorRef +import akka.actor.ActorSystem +import akka.actor.ExtendedActorSystem +import akka.actor.Extension +import akka.actor.ExtensionId +import akka.actor.ExtensionIdProvider +import akka.actor.LocalActorRef +import akka.actor.Props +import akka.actor.RepointableActorRef +import akka.actor.SupervisorStrategy +import akka.stream.{ FlowMaterializer, MaterializerSettings, OverflowStrategy, TimerTransformer, Transformer } +import akka.stream.MaterializationException +import akka.stream.actor.ActorSubscriber +import akka.stream.impl.Zip.ZipAs +import akka.stream.scaladsl._ +import akka.pattern.ask +import org.reactivestreams.{ Processor, Publisher, Subscriber } /** * INTERNAL API @@ -24,35 +37,30 @@ private[akka] object Ast { def name: String } - case class FanoutBox(initialBufferSize: Int, maximumBufferSize: Int) extends AstNode { - override def name = "fanoutBox" - } case class Transform(name: String, mkTransformer: () ⇒ Transformer[Any, Any]) extends AstNode + case class TimerTransform(name: String, mkTransformer: () ⇒ TimerTransformer[Any, Any]) extends AstNode - case class MapFuture(f: Any ⇒ Future[Any]) extends AstNode { - override def name = "mapFuture" + + case class MapAsync(f: Any ⇒ Future[Any]) extends AstNode { + override def name = "mapAsync" } + + case class MapAsyncUnordered(f: Any ⇒ Future[Any]) extends AstNode { + override def name = "mapAsyncUnordered" + } + case class GroupBy(f: Any ⇒ Any) extends AstNode { override def name = "groupBy" } - case class SplitWhen(p: Any ⇒ Boolean) extends AstNode { - override def name = "splitWhen" - } - case class Merge(other: Publisher[Any]) extends AstNode { - override def name = "merge" - } - case class Zip(other: Publisher[Any]) extends AstNode { - override def name = "zip" - } - case class Concat(next: Publisher[Any]) extends AstNode { - override def name = "concat" - } - case class Broadcast(other: Subscriber[Any]) extends AstNode { - override def name = "broadcast" - } + case class PrefixAndTail(n: Int) extends AstNode { override def name = "prefixAndTail" } + + case class SplitWhen(p: Any ⇒ Boolean) extends AstNode { + override def name = "splitWhen" + } + case object ConcatAll extends AstNode { override def name = "concatFlatten" } @@ -69,61 +77,58 @@ private[akka] object Ast { override def name = "buffer" } - trait PublisherNode[I] { - private[akka] def createPublisher(materializer: ActorBasedFlowMaterializer, flowName: String): Publisher[I] + sealed trait JunctionAstNode { + def name: String } - final case class ExistingPublisher[I](publisher: Publisher[I]) extends PublisherNode[I] { - def createPublisher(materializer: ActorBasedFlowMaterializer, flowName: String) = publisher + // FIXME: Try to eliminate these + sealed trait FanInAstNode extends JunctionAstNode + sealed trait FanOutAstNode extends JunctionAstNode + + case object Merge extends FanInAstNode { + override def name = "merge" } - final case class IteratorPublisherNode[I](iterator: Iterator[I]) extends PublisherNode[I] { - final def createPublisher(materializer: ActorBasedFlowMaterializer, flowName: String): Publisher[I] = - if (iterator.isEmpty) EmptyPublisher[I] - else ActorPublisher[I](materializer.actorOf(IteratorPublisher.props(iterator, materializer.settings), - name = s"$flowName-0-iterator")) + case object MergePreferred extends FanInAstNode { + override def name = "mergePreferred" } - final case class IterablePublisherNode[I](iterable: immutable.Iterable[I]) extends PublisherNode[I] { - def createPublisher(materializer: ActorBasedFlowMaterializer, flowName: String): Publisher[I] = - if (iterable.isEmpty) EmptyPublisher[I] - else ActorPublisher[I](materializer.actorOf(IterablePublisher.props(iterable, materializer.settings), - name = s"$flowName-0-iterable"), Some(iterable)) + + case object Broadcast extends FanOutAstNode { + override def name = "broadcast" } - final case class ThunkPublisherNode[I](f: () ⇒ I) extends PublisherNode[I] { - def createPublisher(materializer: ActorBasedFlowMaterializer, flowName: String): Publisher[I] = - ActorPublisher[I](materializer.actorOf(SimpleCallbackPublisher.props(materializer.settings, f), - name = s"$flowName-0-thunk")) + + case object Balance extends FanOutAstNode { + override def name = "balance" } - final case class FuturePublisherNode[I](future: Future[I]) extends PublisherNode[I] { - def createPublisher(materializer: ActorBasedFlowMaterializer, flowName: String): Publisher[I] = - future.value match { - case Some(Success(element)) ⇒ - ActorPublisher[I](materializer.actorOf(IterablePublisher.props(List(element), materializer.settings), - name = s"$flowName-0-future"), Some(future)) - case Some(Failure(t)) ⇒ - ErrorPublisher(t).asInstanceOf[Publisher[I]] - case None ⇒ - ActorPublisher[I](materializer.actorOf(FuturePublisher.props(future, materializer.settings), - name = s"$flowName-0-future"), Some(future)) - } + + final case class Zip(as: ZipAs) extends FanInAstNode { + override def name = "zip" } - final case class TickPublisherNode[I](initialDelay: FiniteDuration, interval: FiniteDuration, tick: () ⇒ I) extends PublisherNode[I] { - def createPublisher(materializer: ActorBasedFlowMaterializer, flowName: String): Publisher[I] = - ActorPublisher[I](materializer.actorOf(TickPublisher.props(initialDelay, interval, tick, materializer.settings), - name = s"$flowName-0-tick")) + + case object Unzip extends FanOutAstNode { + override def name = "unzip" } + + case object Concat extends FanInAstNode { + override def name = "concat" + } + + case class FlexiMergeNode(merger: FlexiMerge[Any]) extends FanInAstNode { + override def name = merger.name.getOrElse("") + } + } /** * INTERNAL API */ -private[akka] case class ActorBasedFlowMaterializer( - override val settings: MaterializerSettings, - supervisor: ActorRef, - flowNameCounter: AtomicLong, - namePrefix: String) +case class ActorBasedFlowMaterializer(override val settings: MaterializerSettings, + supervisor: ActorRef, + flowNameCounter: AtomicLong, + namePrefix: String) extends FlowMaterializer(settings) { - import akka.stream.impl.Ast._ + + import Ast.AstNode def withNamePrefix(name: String): FlowMaterializer = this.copy(namePrefix = name) @@ -143,26 +148,67 @@ private[akka] case class ActorBasedFlowMaterializer( } // Ops come in reverse order - override def toPublisher[I, O](publisherNode: PublisherNode[I], ops: List[AstNode]): Publisher[O] = { + override def materialize[In, Out](source: Source[In], sink: Sink[Out], ops: List[Ast.AstNode]): MaterializedMap = { val flowName = createFlowName() - if (ops.isEmpty) publisherNode.createPublisher(this, flowName).asInstanceOf[Publisher[O]] - else { - val opsSize = ops.size - val opProcessor = processorForNode(ops.head, flowName, opsSize) - val topSubscriber = processorChain(opProcessor, ops.tail, flowName, opsSize - 1) - publisherNode.createPublisher(this, flowName).subscribe(topSubscriber.asInstanceOf[Subscriber[I]]) - opProcessor.asInstanceOf[Publisher[O]] + + def throwUnknownType(typeName: String, s: Any): Nothing = + throw new MaterializationException(s"unknown $typeName type " + s.getClass) + + def attachSink(pub: Publisher[Out]) = sink match { + case s: ActorFlowSink[Out] ⇒ s.attach(pub, this, flowName) + case s ⇒ throwUnknownType("Sink", s) } + def attachSource(sub: Subscriber[In]) = source match { + case s: ActorFlowSource[In] ⇒ s.attach(sub, this, flowName) + case s ⇒ throwUnknownType("Source", s) + } + def createSink() = sink match { + case s: ActorFlowSink[In] ⇒ s.create(this, flowName) + case s ⇒ throwUnknownType("Sink", s) + } + def createSource() = source match { + case s: ActorFlowSource[Out] ⇒ s.create(this, flowName) + case s ⇒ throwUnknownType("Source", s) + } + def isActive(s: AnyRef) = s match { + case s: ActorFlowSource[_] ⇒ s.isActive + case s: ActorFlowSink[_] ⇒ s.isActive + case s: Source[_] ⇒ throwUnknownType("Source", s) + case s: Sink[_] ⇒ throwUnknownType("Sink", s) + } + + val (sourceValue, sinkValue) = + if (ops.isEmpty) { + if (isActive(sink)) { + val (sub, value) = createSink() + (attachSource(sub), value) + } else if (isActive(source)) { + val (pub, value) = createSource() + (value, attachSink(pub)) + } else { + val id: Processor[In, Out] = processorForNode(identityTransform, flowName, 1).asInstanceOf[Processor[In, Out]] + (attachSource(id), attachSink(id)) + } + } else { + val opsSize = ops.size + val last = processorForNode(ops.head, flowName, opsSize).asInstanceOf[Processor[Any, Out]] + val first = processorChain(last, ops.tail, flowName, opsSize - 1).asInstanceOf[Processor[In, Any]] + (attachSource(first), attachSink(last)) + } + new MaterializedPipe(source, sourceValue, sink, sinkValue) } - private val identityTransform = Transform("identity", () ⇒ + private val identityTransform = Ast.Transform("identity", () ⇒ new Transformer[Any, Any] { override def onNext(element: Any) = List(element) }) - def processorForNode(op: AstNode, flowName: String, n: Int): Processor[Any, Any] = { - val impl = actorOf(ActorProcessor.props(settings, op), s"$flowName-$n-${op.name}") - ActorProcessor(impl) + /** + * INTERNAL API + */ + private[akka] def processorForNode(op: AstNode, flowName: String, n: Int): Processor[Any, Any] = { + val impl = actorOf(ActorProcessorFactory.props(this, op), s"$flowName-$n-${op.name}") + ActorProcessorFactory(impl) } def actorOf(props: Props, name: String): ActorRef = supervisor match { @@ -180,20 +226,49 @@ private[akka] case class ActorBasedFlowMaterializer( throw new IllegalStateException(s"Stream supervisor must be a local actor, was [${supervisor.getClass.getName}]") } - override def ductProduceTo[In, Out](subscriber: Subscriber[Out], ops: List[Ast.AstNode]): Subscriber[In] = - processorChain(subscriber, ops, createFlowName(), ops.size).asInstanceOf[Subscriber[In]] - - override def ductBuild[In, Out](ops: List[Ast.AstNode]): (Subscriber[In], Publisher[Out]) = { + override def materializeJunction[In, Out](op: Ast.JunctionAstNode, inputCount: Int, outputCount: Int): (immutable.Seq[Subscriber[In]], immutable.Seq[Publisher[Out]]) = { val flowName = createFlowName() - if (ops.isEmpty) { - val identityProcessor: Processor[In, Out] = processorForNode(identityTransform, flowName, 1).asInstanceOf[Processor[In, Out]] - (identityProcessor, identityProcessor) - } else { - val opsSize = ops.size - val outProcessor = processorForNode(ops.head, flowName, opsSize).asInstanceOf[Processor[In, Out]] - val topSubscriber = processorChain(outProcessor, ops.tail, flowName, opsSize - 1).asInstanceOf[Processor[In, Out]] - (topSubscriber, outProcessor) + val actorName = s"$flowName-${op.name}" + + op match { + case fanin: Ast.FanInAstNode ⇒ + val impl = op match { + case Ast.Merge ⇒ + actorOf(FairMerge.props(settings, inputCount).withDispatcher(settings.dispatcher), actorName) + case Ast.MergePreferred ⇒ + actorOf(UnfairMerge.props(settings, inputCount).withDispatcher(settings.dispatcher), actorName) + case zip: Ast.Zip ⇒ + actorOf(Zip.props(settings, zip.as).withDispatcher(settings.dispatcher), actorName) + case Ast.Concat ⇒ + actorOf(Concat.props(settings).withDispatcher(settings.dispatcher), actorName) + case Ast.FlexiMergeNode(merger) ⇒ + actorOf(FlexiMergeImpl.props(settings, inputCount, merger.createMergeLogic()). + withDispatcher(settings.dispatcher), actorName) + } + + val publisher = new ActorPublisher[Out](impl, equalityValue = None) + impl ! ExposedPublisher(publisher.asInstanceOf[ActorPublisher[Any]]) + val subscribers = Vector.tabulate(inputCount)(FanIn.SubInput[In](impl, _)) + (subscribers, List(publisher)) + + case fanout: Ast.FanOutAstNode ⇒ + val impl = op match { + case Ast.Broadcast ⇒ + actorOf(Broadcast.props(settings, outputCount).withDispatcher(settings.dispatcher), actorName) + case Ast.Balance ⇒ + actorOf(Balance.props(settings, outputCount).withDispatcher(settings.dispatcher), actorName) + case Ast.Unzip ⇒ + actorOf(Unzip.props(settings).withDispatcher(settings.dispatcher), actorName) + } + + val publishers = Vector.tabulate(outputCount)(id ⇒ new ActorPublisher[Out](impl, equalityValue = None) { + override val wakeUpMsg = FanOut.SubstreamSubscribePending(id) + }) + impl ! FanOut.ExposedPublishers(publishers.asInstanceOf[immutable.Seq[ActorPublisher[Any]]]) + val subscriber = ActorSubscriber[In](impl) + (List(subscriber), publishers) } + } } @@ -226,9 +301,41 @@ private[akka] object StreamSupervisor { private[akka] class StreamSupervisor(settings: MaterializerSettings) extends Actor { import StreamSupervisor._ + override def supervisorStrategy = SupervisorStrategy.stoppingStrategy + def receive = { case Materialize(props, name) ⇒ val impl = context.actorOf(props, name) sender() ! impl } -} \ No newline at end of file +} + +/** + * INTERNAL API + */ +private[akka] object ActorProcessorFactory { + + import Ast._ + def props(materializer: FlowMaterializer, op: AstNode): Props = { + val settings = materializer.settings + (op match { + case t: Transform ⇒ Props(new TransformProcessorImpl(settings, t.mkTransformer())) + case t: TimerTransform ⇒ Props(new TimerTransformerProcessorsImpl(settings, t.mkTransformer())) + case m: MapAsync ⇒ Props(new MapAsyncProcessorImpl(settings, m.f)) + case m: MapAsyncUnordered ⇒ Props(new MapAsyncUnorderedProcessorImpl(settings, m.f)) + case g: GroupBy ⇒ Props(new GroupByProcessorImpl(settings, g.f)) + case tt: PrefixAndTail ⇒ Props(new PrefixAndTailImpl(settings, tt.n)) + case s: SplitWhen ⇒ Props(new SplitWhenProcessorImpl(settings, s.p)) + case ConcatAll ⇒ Props(new ConcatAllImpl(materializer)) + case cf: Conflate ⇒ Props(new ConflateImpl(settings, cf.seed, cf.aggregate)) + case ex: Expand ⇒ Props(new ExpandImpl(settings, ex.seed, ex.extrapolate)) + case bf: Buffer ⇒ Props(new BufferImpl(settings, bf.size, bf.overflowStrategy)) + }).withDispatcher(settings.dispatcher) + } + + def apply[I, O](impl: ActorRef): ActorProcessor[I, O] = { + val p = new ActorProcessor[I, O](impl) + impl ! ExposedPublisher(p.asInstanceOf[ActorPublisher[Any]]) + p + } +} diff --git a/akka-stream/src/main/scala/akka/stream/impl/ActorProcessor.scala b/akka-stream/src/main/scala/akka/stream/impl/ActorProcessor.scala index 1819081830..9c5cf0ff54 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/ActorProcessor.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/ActorProcessor.scala @@ -3,38 +3,19 @@ */ package akka.stream.impl -import org.reactivestreams.{ Publisher, Subscriber, Subscription, Processor } +import java.util.Arrays + import akka.actor._ -import akka.stream.{ ReactiveStreamsConstants, MaterializerSettings, TimerTransformer } +import akka.stream.{ ReactiveStreamsConstants, MaterializerSettings } import akka.stream.actor.ActorSubscriber.OnSubscribe import akka.stream.actor.ActorSubscriberMessage.{ OnNext, OnComplete, OnError } -import java.util.Arrays +import org.reactivestreams.{ Subscriber, Subscription, Processor } /** * INTERNAL API */ private[akka] object ActorProcessor { - import Ast._ - def props(settings: MaterializerSettings, op: AstNode): Props = - (op match { - case fb: FanoutBox ⇒ Props(new FanoutProcessorImpl(settings, fb.initialBufferSize, fb.maximumBufferSize)) - case t: TimerTransform ⇒ Props(new TimerTransformerProcessorsImpl(settings, t.mkTransformer())) - case t: Transform ⇒ Props(new TransformProcessorImpl(settings, t.mkTransformer())) - case s: SplitWhen ⇒ Props(new SplitWhenProcessorImpl(settings, s.p)) - case g: GroupBy ⇒ Props(new GroupByProcessorImpl(settings, g.f)) - case m: Merge ⇒ Props(new MergeImpl(settings, m.other)) - case z: Zip ⇒ Props(new ZipImpl(settings, z.other)) - case c: Concat ⇒ Props(new ConcatImpl(settings, c.next)) - case b: Broadcast ⇒ Props(new BroadcastImpl(settings, b.other)) - case cf: Conflate ⇒ Props(new ConflateImpl(settings, cf.seed, cf.aggregate)) - case ex: Expand ⇒ Props(new ExpandImpl(settings, ex.seed, ex.extrapolate)) - case bf: Buffer ⇒ Props(new BufferImpl(settings, bf.size, bf.overflowStrategy)) - case tt: PrefixAndTail ⇒ Props(new PrefixAndTailImpl(settings, tt.n)) - case ConcatAll ⇒ Props(new ConcatAllImpl(settings)) - case m: MapFuture ⇒ Props(new MapAsyncProcessorImpl(settings, m.f)) - }).withDispatcher(settings.dispatcher) - def apply[I, O](impl: ActorRef): ActorProcessor[I, O] = { val p = new ActorProcessor[I, O](impl) impl ! ExposedPublisher(p.asInstanceOf[ActorPublisher[Any]]) diff --git a/akka-stream/src/main/scala/akka/stream/impl/ActorPublisher.scala b/akka-stream/src/main/scala/akka/stream/impl/ActorPublisher.scala index c0de87bd5f..40c8867361 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/ActorPublisher.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/ActorPublisher.scala @@ -5,14 +5,14 @@ package akka.stream.impl import java.util.concurrent.atomic.AtomicReference -import akka.actor.{ Actor, ActorLogging, ActorRef, Props, Terminated } -import akka.stream.{ ReactiveStreamsConstants, MaterializerSettings } -import org.reactivestreams.{ Publisher, Subscriber } - import scala.annotation.tailrec import scala.collection.immutable import scala.util.control.{ NoStackTrace, NonFatal } +import akka.actor.{ Actor, ActorLogging, ActorRef, Props, Terminated } +import akka.stream.{ ReactiveStreamsConstants, MaterializerSettings } +import org.reactivestreams.{ Publisher, Subscriber } + /** * INTERNAL API */ diff --git a/akka-stream/src/main/scala/akka/stream/impl/ConcatAllImpl.scala b/akka-stream/src/main/scala/akka/stream/impl/ConcatAllImpl.scala index 651e9718c9..a60bf5783d 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/ConcatAllImpl.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/ConcatAllImpl.scala @@ -3,19 +3,21 @@ */ package akka.stream.impl -import akka.stream.MaterializerSettings -import org.reactivestreams.Publisher -import akka.stream.impl.MultiStreamInputProcessor.SubstreamKey +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.Sink /** * INTERNAL API */ -private[akka] class ConcatAllImpl(_settings: MaterializerSettings) extends MultiStreamInputProcessor(_settings) { +private[akka] class ConcatAllImpl(materializer: FlowMaterializer) + extends MultiStreamInputProcessor(materializer.settings) { - import MultiStreamInputProcessor._ + import akka.stream.impl.MultiStreamInputProcessor._ val takeNextSubstream = TransferPhase(primaryInputs.NeedsInput && primaryOutputs.NeedsDemand) { () ⇒ - val publisher = primaryInputs.dequeueInputElement().asInstanceOf[Publisher[Any]] + val Extract.Source(source) = primaryInputs.dequeueInputElement() + val publisher = source.runWith(Sink.publisher)(materializer) + // FIXME we can pass the flow to createSubstreamInput (but avoiding copy impl now) val inputs = createAndSubscribeSubstreamInput(publisher) nextPhase(streamSubstream(inputs)) } diff --git a/akka-stream/src/main/scala/akka/stream/impl/Extract.scala b/akka-stream/src/main/scala/akka/stream/impl/Extract.scala index be3a766325..af64881e78 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/Extract.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/Extract.scala @@ -3,30 +3,30 @@ */ package akka.stream.impl -import akka.stream.scaladsl2 +import akka.stream.scaladsl import akka.stream.javadsl /** * INTERNAL API * * Unapply methods aware of both DSLs. - * Use these instead of manually casting to [[scaladsl2.Source]]. + * Use these instead of manually casting to [[scaladsl.Source]]. */ private[akka] object Extract { object Source { - def unapply(a: Any): Option[scaladsl2.Source[Any]] = a match { - case s: scaladsl2.Source[Any] ⇒ Some(s) - case s: javadsl.Source[Any] ⇒ Some(s.asScala) - case _ ⇒ None + def unapply(a: Any): Option[scaladsl.Source[Any]] = a match { + case s: scaladsl.Source[Any] ⇒ Some(s) + case s: javadsl.Source[Any] ⇒ Some(s.asScala) + case _ ⇒ None } } object Sink { - def unapply(a: Any): Option[scaladsl2.Sink[Any]] = a match { - case s: scaladsl2.Sink[Any] ⇒ Some(s) - case s: javadsl.Sink[Any] ⇒ Some(s.asScala) - case _ ⇒ None + def unapply(a: Any): Option[scaladsl.Sink[Any]] = a match { + case s: scaladsl.Sink[Any] ⇒ Some(s) + case s: javadsl.Sink[Any] ⇒ Some(s.asScala) + case _ ⇒ None } } diff --git a/akka-stream/src/main/scala/akka/stream/impl2/FanIn.scala b/akka-stream/src/main/scala/akka/stream/impl/FanIn.scala similarity index 98% rename from akka-stream/src/main/scala/akka/stream/impl2/FanIn.scala rename to akka-stream/src/main/scala/akka/stream/impl/FanIn.scala index 95ac455062..afe6d56199 100644 --- a/akka-stream/src/main/scala/akka/stream/impl2/FanIn.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/FanIn.scala @@ -1,17 +1,14 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.impl2 +package akka.stream.impl import akka.actor.{ ActorRef, ActorLogging, Actor } +import akka.actor.Props import akka.stream.MaterializerSettings import akka.stream.actor.{ ActorSubscriberMessage, ActorSubscriber } -import akka.stream.impl._ -import akka.stream.impl2.Zip.ZipAs +import akka.stream.impl.Zip.ZipAs import org.reactivestreams.{ Subscription, Subscriber } -import akka.actor.Props -import akka.stream.scaladsl2.FlexiMerge -import scala.language.higherKinds /** * INTERNAL API diff --git a/akka-stream/src/main/scala/akka/stream/impl2/FanOut.scala b/akka-stream/src/main/scala/akka/stream/impl/FanOut.scala similarity index 96% rename from akka-stream/src/main/scala/akka/stream/impl2/FanOut.scala rename to akka-stream/src/main/scala/akka/stream/impl/FanOut.scala index 463c158a52..d285367964 100644 --- a/akka-stream/src/main/scala/akka/stream/impl2/FanOut.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/FanOut.scala @@ -1,23 +1,17 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.impl2 +package akka.stream.impl + +import scala.collection.immutable -import akka.actor.Props import akka.actor.Actor import akka.actor.ActorLogging import akka.actor.ActorRef +import akka.actor.Props import akka.stream.MaterializerSettings -import akka.stream.impl.BatchingInputBuffer -import akka.stream.impl.Pump -import akka.stream.impl.SimpleOutputs -import akka.stream.impl.SubReceive -import akka.stream.impl.TransferState -import akka.stream.impl._ import org.reactivestreams.Subscription -import scala.collection.immutable - /** * INTERNAL API */ @@ -179,7 +173,7 @@ private[akka] object FanOut { * INTERNAL API */ private[akka] abstract class FanOut(val settings: MaterializerSettings, val outputPorts: Int) extends Actor with ActorLogging with Pump { - import akka.stream.impl2.FanOut._ + import FanOut._ protected val outputBunch = new OutputBunch(outputPorts, self, this) protected val primaryInputs: Inputs = new BatchingInputBuffer(settings.maxInputBufferSize, this) { diff --git a/akka-stream/src/main/scala/akka/stream/impl2/FlexiMergeImpl.scala b/akka-stream/src/main/scala/akka/stream/impl/FlexiMergeImpl.scala similarity index 96% rename from akka-stream/src/main/scala/akka/stream/impl2/FlexiMergeImpl.scala rename to akka-stream/src/main/scala/akka/stream/impl/FlexiMergeImpl.scala index 18f69fa2b7..e8bef7c87f 100644 --- a/akka-stream/src/main/scala/akka/stream/impl2/FlexiMergeImpl.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/FlexiMergeImpl.scala @@ -1,13 +1,11 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.impl2 +package akka.stream.impl import scala.collection.breakOut -import akka.stream.impl.TransferPhase -import akka.stream.scaladsl2.FlexiMerge +import akka.stream.scaladsl.FlexiMerge import akka.stream.MaterializerSettings -import akka.stream.impl.TransferState import akka.actor.Props /** diff --git a/akka-stream/src/main/scala/akka/stream/impl/FlowImpl.scala b/akka-stream/src/main/scala/akka/stream/impl/FlowImpl.scala deleted file mode 100644 index 1832d614f3..0000000000 --- a/akka-stream/src/main/scala/akka/stream/impl/FlowImpl.scala +++ /dev/null @@ -1,335 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream.impl - -import akka.stream.scaladsl.{ Duct, Flow } -import akka.stream.{ FlattenStrategy, FlowMaterializer, OverflowStrategy, TimerTransformer, Transformer } -import akka.util.Collections.EmptyImmutableSeq -import org.reactivestreams.{ Publisher, Subscriber } - -import scala.collection.immutable -import scala.concurrent.duration.{ Duration, FiniteDuration } -import scala.concurrent.{ Future, Promise } -import scala.util.{ Failure, Success, Try } - -/** - * INTERNAL API - */ -private[akka] case class FlowImpl[I, O](publisherNode: Ast.PublisherNode[I], ops: List[Ast.AstNode]) extends Flow[O] with Builder[O] { - - type Thing[T] = Flow[T] - - // Storing ops in reverse order - override protected def andThen[U](op: Ast.AstNode): Flow[U] = this.copy(ops = op :: ops) - - override def append[U](duct: Duct[_ >: O, U]): Flow[U] = - copy(ops = duct.ops ++: ops) - - override def toFuture()(implicit materializer: FlowMaterializer): Future[O] = { - val p = Promise[O]() - transform("toFuture", () ⇒ new Transformer[O, Unit] { - var done = false - override def onNext(in: O) = { p success in; done = true; Nil } - override def onError(e: Throwable) = { p failure e } - override def isComplete = done - override def onTermination(e: Option[Throwable]) = { p.tryFailure(new NoSuchElementException("empty stream")); Nil } - }).consume() - p.future - } - - override def consume()(implicit materializer: FlowMaterializer): Unit = - produceTo(new BlackholeSubscriber[Any](materializer.settings.maxInputBufferSize)) - - override def onComplete(callback: Try[Unit] ⇒ Unit)(implicit materializer: FlowMaterializer): Unit = - transform("onComplete", () ⇒ new Transformer[O, Unit] { - override def onNext(in: O) = Nil - override def onError(e: Throwable) = { - callback(Failure(e)) - throw e - } - override def onTermination(e: Option[Throwable]) = { - callback(Builder.SuccessUnit) - Nil - } - }).consume() - - override def toPublisher[U >: O]()(implicit materializer: FlowMaterializer): Publisher[U] = materializer.toPublisher(publisherNode, ops) - - override def produceTo(subscriber: Subscriber[_ >: O])(implicit materializer: FlowMaterializer): Unit = - toPublisher().subscribe(subscriber.asInstanceOf[Subscriber[O]]) - - override def foreach(c: O ⇒ Unit)(implicit materializer: FlowMaterializer): Future[Unit] = - foreachTransform(c).toFuture() -} - -/** - * INTERNAL API - */ -private[akka] case class DuctImpl[In, Out](ops: List[Ast.AstNode]) extends Duct[In, Out] with Builder[Out] { - - type Thing[T] = Duct[In, T] - - // Storing ops in reverse order - override protected def andThen[U](op: Ast.AstNode): Duct[In, U] = this.copy(ops = op :: ops) - - override def append[U](duct: Duct[_ >: Out, U]): Duct[In, U] = - copy(ops = duct.ops ++: ops) - - override def produceTo[U >: Out](subscriber: Subscriber[U])(implicit materializer: FlowMaterializer): Subscriber[In] = - materializer.ductProduceTo(subscriber, ops) - - override def consume()(implicit materializer: FlowMaterializer): Subscriber[In] = - produceTo(new BlackholeSubscriber[Any](materializer.settings.maxInputBufferSize)) - - override def onComplete(callback: Try[Unit] ⇒ Unit)(implicit materializer: FlowMaterializer): Subscriber[In] = - transform("onComplete", () ⇒ new Transformer[Out, Unit] { - override def onNext(in: Out) = Nil - override def onError(e: Throwable) = { - callback(Failure(e)) - throw e - } - override def onTermination(e: Option[Throwable]) = { - callback(Builder.SuccessUnit) - Nil - } - }).consume() - - override def build[U >: Out]()(implicit materializer: FlowMaterializer): (Subscriber[In], Publisher[U]) = - materializer.ductBuild(ops) - - override def foreach(c: Out ⇒ Unit)(implicit materializer: FlowMaterializer): (Subscriber[In], Future[Unit]) = { - val p = Promise[Unit]() - val s = foreachTransform(c).onComplete { - case Success(_) ⇒ p.success(()) - case Failure(e) ⇒ p.failure(e) - } - (s, p.future) - } - -} - -/** - * INTERNAL API - */ -private[akka] object Builder { - val SuccessUnit = Success[Unit](()) - private val ListOfUnit = List(()) - private case object TakeWithinTimerKey - private case object DropWithinTimerKey - private case object GroupedWithinTimerKey - - private val takeCompletedTransformer: Transformer[Any, Any] = new Transformer[Any, Any] { - override def onNext(elem: Any) = Nil - override def isComplete = true - } - - private val identityTransformer: Transformer[Any, Any] = new Transformer[Any, Any] { - override def onNext(elem: Any) = List(elem) - } -} - -/** - * INTERNAL API - * Builder of `Flow` or `Duct` things - */ -private[akka] trait Builder[Out] { - import akka.stream.impl.Ast._ - import akka.stream.impl.Builder._ - - import scala.language.higherKinds - - type Thing[T] - - protected def andThen[U](op: Ast.AstNode): Thing[U] - - def map[U](f: Out ⇒ U): Thing[U] = - transform("map", () ⇒ new Transformer[Out, U] { - override def onNext(in: Out) = List(f(in)) - }) - - def mapFuture[U](f: Out ⇒ Future[U]): Thing[U] = - andThen(MapFuture(f.asInstanceOf[Any ⇒ Future[Any]])) - - def filter(p: Out ⇒ Boolean): Thing[Out] = - transform("filter", () ⇒ new Transformer[Out, Out] { - override def onNext(in: Out) = if (p(in)) List(in) else Nil - }) - - def collect[U](pf: PartialFunction[Out, U]): Thing[U] = - transform("collect", () ⇒ new Transformer[Out, U] { - override def onNext(in: Out) = if (pf.isDefinedAt(in)) List(pf(in)) else Nil - }) - - def foreachTransform(c: Out ⇒ Unit): Thing[Unit] = - transform("foreach", () ⇒ new Transformer[Out, Unit] { - override def onNext(in: Out) = { c(in); Nil } - override def onTermination(e: Option[Throwable]) = ListOfUnit - }) - - def fold[U](zero: U)(f: (U, Out) ⇒ U): Thing[U] = - transform("fold", () ⇒ new FoldTransformer[U](zero, f)) - - // Without this class compiler complains about - // "Parameter type in structural refinement may not refer to an abstract type defined outside that refinement" - class FoldTransformer[S](var state: S, f: (S, Out) ⇒ S) extends Transformer[Out, S] { - override def onNext(in: Out): immutable.Seq[S] = { state = f(state, in); Nil } - override def onTermination(e: Option[Throwable]): immutable.Seq[S] = List(state) - } - - def drop(n: Int): Thing[Out] = - transform("drop", () ⇒ new Transformer[Out, Out] { - var delegate: Transformer[Out, Out] = - if (n <= 0) identityTransformer.asInstanceOf[Transformer[Out, Out]] - else new Transformer[Out, Out] { - var c = n - override def onNext(in: Out) = { - c -= 1 - if (c == 0) - delegate = identityTransformer.asInstanceOf[Transformer[Out, Out]] - Nil - } - } - - override def onNext(in: Out) = delegate.onNext(in) - }) - - def dropWithin(d: FiniteDuration): Thing[Out] = - timerTransform("dropWithin", () ⇒ new TimerTransformer[Out, Out] { - scheduleOnce(DropWithinTimerKey, d) - - var delegate: Transformer[Out, Out] = - new Transformer[Out, Out] { - override def onNext(in: Out) = Nil - } - - override def onNext(in: Out) = delegate.onNext(in) - override def onTimer(timerKey: Any) = { - delegate = identityTransformer.asInstanceOf[Transformer[Out, Out]] - Nil - } - }) - - def take(n: Int): Thing[Out] = - transform("take", () ⇒ new Transformer[Out, Out] { - var delegate: Transformer[Out, Out] = - if (n <= 0) takeCompletedTransformer.asInstanceOf[Transformer[Out, Out]] - else new Transformer[Out, Out] { - var c = n - override def onNext(in: Out) = { - c -= 1 - if (c == 0) - delegate = takeCompletedTransformer.asInstanceOf[Transformer[Out, Out]] - List(in) - } - } - - override def onNext(in: Out) = delegate.onNext(in) - override def isComplete = delegate.isComplete - }) - - def takeWithin(d: FiniteDuration): Thing[Out] = - timerTransform("takeWithin", () ⇒ new TimerTransformer[Out, Out] { - scheduleOnce(TakeWithinTimerKey, d) - - var delegate: Transformer[Out, Out] = identityTransformer.asInstanceOf[Transformer[Out, Out]] - - override def onNext(in: Out) = delegate.onNext(in) - override def isComplete = delegate.isComplete - override def onTimer(timerKey: Any) = { - delegate = takeCompletedTransformer.asInstanceOf[Transformer[Out, Out]] - Nil - } - }) - - def prefixAndTail[U >: Out](n: Int): Thing[(immutable.Seq[Out], Publisher[U])] = andThen(PrefixAndTail(n)) - - def grouped(n: Int): Thing[immutable.Seq[Out]] = { - require(n > 0, "n must be greater than 0") - transform("grouped", () ⇒ new Transformer[Out, immutable.Seq[Out]] { - var buf: Vector[Out] = Vector.empty - override def onNext(in: Out) = { - buf :+= in - if (buf.size == n) { - val group = buf - buf = Vector.empty - List(group) - } else - Nil - } - override def onTermination(e: Option[Throwable]) = if (buf.isEmpty) Nil else List(buf) - }) - } - - def groupedWithin(n: Int, d: FiniteDuration): Thing[immutable.Seq[Out]] = { - require(n > 0, "n must be greater than 0") - require(d > Duration.Zero) - timerTransform("groupedWithin", () ⇒ new TimerTransformer[Out, immutable.Seq[Out]] { - schedulePeriodically(GroupedWithinTimerKey, d) - var buf: Vector[Out] = Vector.empty - - override def onNext(in: Out) = { - buf :+= in - if (buf.size == n) { - // start new time window - schedulePeriodically(GroupedWithinTimerKey, d) - emitGroup() - } else Nil - } - override def onTermination(e: Option[Throwable]) = if (buf.isEmpty) Nil else List(buf) - override def onTimer(timerKey: Any) = emitGroup() - private def emitGroup(): immutable.Seq[immutable.Seq[Out]] = - if (buf.isEmpty) EmptyImmutableSeq - else { - val group = buf - buf = Vector.empty - List(group) - } - }) - } - - def mapConcat[U](f: Out ⇒ immutable.Seq[U]): Thing[U] = - transform("mapConcat", () ⇒ new Transformer[Out, U] { - override def onNext(in: Out) = f(in) - }) - - def transform[U](name: String, mkTransformer: () ⇒ Transformer[Out, U]): Thing[U] = - andThen(Transform(name, mkTransformer.asInstanceOf[() ⇒ Transformer[Any, Any]])) - - def timerTransform[U](name: String, mkTransformer: () ⇒ TimerTransformer[Out, U]): Thing[U] = - andThen(TimerTransform(name, mkTransformer.asInstanceOf[() ⇒ TimerTransformer[Any, Any]])) - - def zip[O2](other: Publisher[O2]): Thing[(Out, O2)] = andThen(Zip(other.asInstanceOf[Publisher[Any]])) - - def concat[U >: Out](next: Publisher[U]): Thing[U] = andThen(Concat(next.asInstanceOf[Publisher[Any]])) - - def merge[U >: Out](other: Publisher[_ <: U]): Thing[U] = andThen(Merge(other.asInstanceOf[Publisher[Any]])) - - def splitWhen[U >: Out](p: (Out) ⇒ Boolean): Thing[Publisher[U]] = andThen(SplitWhen(p.asInstanceOf[Any ⇒ Boolean])) - - def groupBy[K, U >: Out](f: (Out) ⇒ K): Thing[(K, Publisher[U])] = andThen(GroupBy(f.asInstanceOf[Any ⇒ Any])) - - def broadcast(other: Subscriber[_ >: Out]): Thing[Out] = andThen(Broadcast(other.asInstanceOf[Subscriber[Any]])) - - def conflate[S](seed: Out ⇒ S, aggregate: (S, Out) ⇒ S): Thing[S] = - andThen(Conflate(seed.asInstanceOf[Any ⇒ Any], aggregate.asInstanceOf[(Any, Any) ⇒ Any])) - - def expand[S, U](seed: Out ⇒ S, extrapolate: S ⇒ (U, S)): Thing[U] = - andThen(Expand(seed.asInstanceOf[Any ⇒ Any], extrapolate.asInstanceOf[Any ⇒ (Any, Any)])) - - def buffer(size: Int, overflowStrategy: OverflowStrategy): Thing[Out] = { - require(size > 0, s"Buffer size must be larger than zero but was [$size]") - andThen(Buffer(size, overflowStrategy)) - } - - def fanout(initialBufferSize: Int, maximumBufferSize: Int): Thing[Out] = { - andThen(FanoutBox(initialBufferSize, maximumBufferSize)) - } - - def flatten[U](strategy: FlattenStrategy[Out, U]): Thing[U] = strategy match { - case _: FlattenStrategy.Concat[Out] ⇒ andThen(ConcatAll) - case _ ⇒ throw new IllegalArgumentException(s"Unsupported flattening strategy [${strategy.getClass.getSimpleName}]") - } - -} - diff --git a/akka-stream/src/main/scala/akka/stream/impl/FuturePublisher.scala b/akka-stream/src/main/scala/akka/stream/impl/FuturePublisher.scala index 30d7b79b0d..fcedcab827 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/FuturePublisher.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/FuturePublisher.scala @@ -3,22 +3,22 @@ */ package akka.stream.impl +import scala.concurrent.Future +import scala.util.Failure +import scala.util.Success +import scala.util.Try + import akka.actor.Actor import akka.actor.ActorRef import akka.actor.Props import akka.actor.Status import akka.actor.SupervisorStrategy -import akka.pattern.pipe import akka.stream.MaterializerSettings import akka.stream.ReactiveStreamsConstants +import akka.pattern.pipe import org.reactivestreams.Subscriber import org.reactivestreams.Subscription -import scala.concurrent.Future -import scala.util.Failure -import scala.util.Success -import scala.util.Try - /** * INTERNAL API */ 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 eacd4e6343..07a4ff8d26 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/GroupByProcessorImpl.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/GroupByProcessorImpl.scala @@ -3,14 +3,15 @@ */ package akka.stream.impl -import akka.actor.{ Terminated, Props, ActorRef } import akka.stream.MaterializerSettings -import akka.stream.impl.MultiStreamOutputProcessor.SubstreamKey +import akka.stream.scaladsl.Source /** * INTERNAL API */ -private[akka] class GroupByProcessorImpl(settings: MaterializerSettings, val keyFor: Any ⇒ Any) extends MultiStreamOutputProcessor(settings) { +private[akka] class GroupByProcessorImpl(settings: MaterializerSettings, val keyFor: Any ⇒ Any) + extends MultiStreamOutputProcessor(settings) { + import MultiStreamOutputProcessor._ var keyToSubstreamOutput = collection.mutable.Map.empty[Any, SubstreamOutput] @@ -42,7 +43,8 @@ private[akka] class GroupByProcessorImpl(settings: MaterializerSettings, val key nextPhase(waitNext) } else { val substreamOutput = createSubstreamOutput() - primaryOutputs.enqueueOutputElement((key, substreamOutput)) + val substreamFlow = Source(substreamOutput) // substreamOutput is a Publisher + primaryOutputs.enqueueOutputElement((key, substreamFlow)) keyToSubstreamOutput(key) = substreamOutput nextPhase(dispatchToSubstream(elem, substreamOutput)) } diff --git a/akka-stream/src/main/scala/akka/stream/impl/IterablePublisher.scala b/akka-stream/src/main/scala/akka/stream/impl/IterablePublisher.scala index 3ebfc484a9..9ca213e351 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/IterablePublisher.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/IterablePublisher.scala @@ -3,14 +3,14 @@ */ package akka.stream.impl -import akka.actor.{ Actor, ActorRef, Props, SupervisorStrategy, Terminated } -import akka.stream.{ MaterializerSettings, ReactiveStreamsConstants } -import org.reactivestreams.{ Subscriber, Subscription } - import scala.annotation.tailrec import scala.collection.immutable import scala.util.control.NonFatal +import akka.actor.{ Actor, ActorRef, Props, SupervisorStrategy, Terminated } +import akka.stream.{ MaterializerSettings, ReactiveStreamsConstants } +import org.reactivestreams.{ Subscriber, Subscription } + /** * INTERNAL API */ diff --git a/akka-stream/src/main/scala/akka/stream/impl2/MapAsyncUnorderedProcessorImpl.scala b/akka-stream/src/main/scala/akka/stream/impl/MapAsyncUnorderedProcessorImpl.scala similarity index 91% rename from akka-stream/src/main/scala/akka/stream/impl2/MapAsyncUnorderedProcessorImpl.scala rename to akka-stream/src/main/scala/akka/stream/impl/MapAsyncUnorderedProcessorImpl.scala index 4445c299c1..b173baa980 100644 --- a/akka-stream/src/main/scala/akka/stream/impl2/MapAsyncUnorderedProcessorImpl.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/MapAsyncUnorderedProcessorImpl.scala @@ -1,16 +1,12 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.impl2 +package akka.stream.impl -import scala.collection.immutable import scala.concurrent.Future import scala.util.control.NonFatal import akka.stream.MaterializerSettings -import akka.stream.impl.ActorProcessorImpl -import akka.stream.impl.Emit -import akka.stream.impl.TransferPhase -import akka.stream.impl.TransferState +import akka.stream.MaterializerSettings import akka.pattern.pipe /** diff --git a/akka-stream/src/main/scala/akka/stream/impl/PrefixAndTailImpl.scala b/akka-stream/src/main/scala/akka/stream/impl/PrefixAndTailImpl.scala index a520d731cc..8f35efd52d 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/PrefixAndTailImpl.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/PrefixAndTailImpl.scala @@ -3,8 +3,9 @@ */ package akka.stream.impl -import akka.stream.MaterializerSettings import scala.collection.immutable +import akka.stream.MaterializerSettings +import akka.stream.scaladsl.Source /** * INTERNAL API @@ -40,13 +41,14 @@ private[akka] class PrefixAndTailImpl(_settings: MaterializerSettings, val takeM } def emitEmptyTail(): Unit = { - primaryOutputs.enqueueOutputElement((taken, EmptyPublisher)) + primaryOutputs.enqueueOutputElement((taken, Source(EmptyPublisher[Any]))) nextPhase(completedPhase) } def emitNonEmptyTail(): Unit = { val substreamOutput = createSubstreamOutput() - primaryOutputs.enqueueOutputElement((taken, substreamOutput)) + val substreamFlow = Source(substreamOutput) // substreamOutput is a Publisher + primaryOutputs.enqueueOutputElement((taken, substreamFlow)) primaryOutputs.complete() nextPhase(streamTailPhase(substreamOutput)) } diff --git a/akka-stream/src/main/scala/akka/stream/impl/SplitWhenProcessorImpl.scala b/akka-stream/src/main/scala/akka/stream/impl/SplitWhenProcessorImpl.scala index af6e952500..e983a3b494 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/SplitWhenProcessorImpl.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/SplitWhenProcessorImpl.scala @@ -4,7 +4,7 @@ package akka.stream.impl import akka.stream.MaterializerSettings -import akka.stream.impl.MultiStreamOutputProcessor.SubstreamKey +import akka.stream.scaladsl.Source /** * INTERNAL API @@ -22,7 +22,8 @@ private[akka] class SplitWhenProcessorImpl(_settings: MaterializerSettings, val def openSubstream(elem: Any): TransferPhase = TransferPhase(primaryOutputs.NeedsDemand) { () ⇒ val substreamOutput = createSubstreamOutput() - primaryOutputs.enqueueOutputElement(substreamOutput) + val substreamFlow = Source(substreamOutput) // substreamOutput is a Publisher + primaryOutputs.enqueueOutputElement(substreamFlow) currentSubstream = substreamOutput nextPhase(serveSubstreamFirst(currentSubstream, elem)) } diff --git a/akka-stream/src/main/scala/akka/stream/impl/StaticFanins.scala b/akka-stream/src/main/scala/akka/stream/impl/StaticFanins.scala deleted file mode 100644 index 6c8f22fe83..0000000000 --- a/akka-stream/src/main/scala/akka/stream/impl/StaticFanins.scala +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream.impl - -import akka.stream.MaterializerSettings -import org.reactivestreams.Publisher -import scala.concurrent.forkjoin.ThreadLocalRandom - -/** - * INTERNAL API - */ -private[akka] class MergeImpl(_settings: MaterializerSettings, _other: Publisher[Any]) - extends TwoStreamInputProcessor(_settings, _other) { - - val runningPhase = TransferPhase( - (primaryInputs.NeedsInput || secondaryInputs.NeedsInput) && primaryOutputs.NeedsDemand) { () ⇒ - def tieBreak = ThreadLocalRandom.current().nextBoolean() - if (primaryInputs.inputsAvailable && (!secondaryInputs.inputsAvailable || tieBreak)) { - primaryOutputs.enqueueOutputElement(primaryInputs.dequeueInputElement()) - } else { - primaryOutputs.enqueueOutputElement(secondaryInputs.dequeueInputElement()) - } - } - - nextPhase(runningPhase) -} - -/** - * INTERNAL API - */ -private[akka] class ZipImpl(_settings: MaterializerSettings, _other: Publisher[Any]) - extends TwoStreamInputProcessor(_settings, _other) { - - val runningPhase = TransferPhase(primaryInputs.NeedsInput && secondaryInputs.NeedsInput && primaryOutputs.NeedsDemand) { () ⇒ - primaryOutputs.enqueueOutputElement((primaryInputs.dequeueInputElement(), secondaryInputs.dequeueInputElement())) - } - - nextPhase(runningPhase) - -} - -/** - * INTERNAL API - */ -private[akka] class ConcatImpl(_settings: MaterializerSettings, _other: Publisher[Any]) - extends TwoStreamInputProcessor(_settings, _other) { - - val processingPrimary = TransferPhase(primaryInputs.NeedsInputOrComplete && primaryOutputs.NeedsDemand) { () ⇒ - if (primaryInputs.inputsDepleted) nextPhase(processingSecondary) - else primaryOutputs.enqueueOutputElement(primaryInputs.dequeueInputElement()) - } - - val processingSecondary = TransferPhase(secondaryInputs.NeedsInput && primaryOutputs.NeedsDemand) { () ⇒ - primaryOutputs.enqueueOutputElement(secondaryInputs.dequeueInputElement()) - } - - nextPhase(processingPrimary) - -} diff --git a/akka-stream/src/main/scala/akka/stream/impl/StaticFanouts.scala b/akka-stream/src/main/scala/akka/stream/impl/StaticFanouts.scala deleted file mode 100644 index b213b59dd7..0000000000 --- a/akka-stream/src/main/scala/akka/stream/impl/StaticFanouts.scala +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream.impl - -import akka.stream.MaterializerSettings -import org.reactivestreams.Subscriber - -/** - * INTERNAL API - */ -private[akka] class BroadcastImpl(_settings: MaterializerSettings, other: Subscriber[Any]) - extends ActorProcessorImpl(_settings) { - - override val primaryOutputs = new FanoutOutputs(settings.maxFanOutBufferSize, settings.initialFanOutBufferSize, self, pump = this) { - var secondarySubscribed = false - - override def registerSubscriber(subscriber: Subscriber[_ >: Any]): Unit = { - if (!secondarySubscribed) { - super.registerSubscriber(other) - secondarySubscribed = true - } - super.registerSubscriber(subscriber) - } - - override def afterShutdown(): Unit = afterFlush() - } - - override def fail(e: Throwable): Unit = { - log.error(e, "failure during processing") // FIXME: escalate to supervisor instead - primaryInputs.cancel() - primaryOutputs.cancel(e) - // Stopping will happen after flush - } - - override def pumpFinished(): Unit = { - primaryInputs.cancel() - primaryOutputs.complete() - } - - def afterFlush(): Unit = context.stop(self) - - val running = TransferPhase(primaryInputs.NeedsInput && primaryOutputs.NeedsDemand) { () ⇒ - val in = primaryInputs.dequeueInputElement() - primaryOutputs.enqueueOutputElement(in) - } - - nextPhase(running) - -} - diff --git a/akka-stream/src/main/scala/akka/stream/impl2/ActorBasedFlowMaterializer.scala b/akka-stream/src/main/scala/akka/stream/impl2/ActorBasedFlowMaterializer.scala deleted file mode 100644 index 373d55161f..0000000000 --- a/akka-stream/src/main/scala/akka/stream/impl2/ActorBasedFlowMaterializer.scala +++ /dev/null @@ -1,330 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream.impl2 - -import java.util.concurrent.atomic.AtomicLong - -import akka.actor._ -import akka.pattern.ask -import akka.stream.actor.ActorSubscriber -import akka.stream.impl.{ ActorProcessor, ActorPublisher, BufferImpl, ConflateImpl, ExpandImpl, ExposedPublisher, MapAsyncProcessorImpl, TimerTransformerProcessorsImpl, TransformProcessorImpl } -import akka.stream.impl2.Zip.ZipAs -import akka.stream.scaladsl2._ -import akka.stream.{ MaterializerSettings, OverflowStrategy, TimerTransformer, Transformer } -import org.reactivestreams.{ Processor, Publisher, Subscriber } - -import scala.annotation.tailrec -import scala.collection.immutable -import scala.concurrent.{ Await, Future } - -/** - * INTERNAL API - */ -private[akka] object Ast { - sealed trait AstNode { - def name: String - } - - case class Transform(name: String, mkTransformer: () ⇒ Transformer[Any, Any]) extends AstNode - - case class TimerTransform(name: String, mkTransformer: () ⇒ TimerTransformer[Any, Any]) extends AstNode - - case class MapAsync(f: Any ⇒ Future[Any]) extends AstNode { - override def name = "mapAsync" - } - - case class MapAsyncUnordered(f: Any ⇒ Future[Any]) extends AstNode { - override def name = "mapAsyncUnordered" - } - - case class GroupBy(f: Any ⇒ Any) extends AstNode { - override def name = "groupBy" - } - - case class PrefixAndTail(n: Int) extends AstNode { - override def name = "prefixAndTail" - } - - case class SplitWhen(p: Any ⇒ Boolean) extends AstNode { - override def name = "splitWhen" - } - - case object ConcatAll extends AstNode { - override def name = "concatFlatten" - } - - case class Conflate(seed: Any ⇒ Any, aggregate: (Any, Any) ⇒ Any) extends AstNode { - override def name = "conflate" - } - - case class Expand(seed: Any ⇒ Any, extrapolate: Any ⇒ (Any, Any)) extends AstNode { - override def name = "expand" - } - - case class Buffer(size: Int, overflowStrategy: OverflowStrategy) extends AstNode { - override def name = "buffer" - } - - sealed trait JunctionAstNode { - def name: String - } - - // FIXME: Try to eliminate these - sealed trait FanInAstNode extends JunctionAstNode - sealed trait FanOutAstNode extends JunctionAstNode - - case object Merge extends FanInAstNode { - override def name = "merge" - } - - case object MergePreferred extends FanInAstNode { - override def name = "mergePreferred" - } - - case object Broadcast extends FanOutAstNode { - override def name = "broadcast" - } - - case object Balance extends FanOutAstNode { - override def name = "balance" - } - - final case class Zip(as: ZipAs) extends FanInAstNode { - override def name = "zip" - } - - case object Unzip extends FanOutAstNode { - override def name = "unzip" - } - - case object Concat extends FanInAstNode { - override def name = "concat" - } - - case class FlexiMergeNode(merger: FlexiMerge[Any]) extends FanInAstNode { - override def name = merger.name.getOrElse("") - } - -} - -/** - * INTERNAL API - */ -case class ActorBasedFlowMaterializer(override val settings: MaterializerSettings, - supervisor: ActorRef, - flowNameCounter: AtomicLong, - namePrefix: String) - extends FlowMaterializer(settings) { - - import Ast.AstNode - - def withNamePrefix(name: String): FlowMaterializer = this.copy(namePrefix = name) - - private def nextFlowNameCount(): Long = flowNameCounter.incrementAndGet() - - private def createFlowName(): String = s"$namePrefix-${nextFlowNameCount()}" - - @tailrec private def processorChain(topSubscriber: Subscriber[_], ops: immutable.Seq[AstNode], - flowName: String, n: Int): Subscriber[_] = { - ops match { - case op :: tail ⇒ - val opProcessor: Processor[Any, Any] = processorForNode(op, flowName, n) - opProcessor.subscribe(topSubscriber.asInstanceOf[Subscriber[Any]]) - processorChain(opProcessor, tail, flowName, n - 1) - case _ ⇒ topSubscriber - } - } - - // Ops come in reverse order - override def materialize[In, Out](source: Source[In], sink: Sink[Out], ops: List[Ast.AstNode]): MaterializedMap = { - val flowName = createFlowName() - - def throwUnknownType(typeName: String, s: Any): Nothing = - throw new MaterializationException(s"unknown $typeName type " + s.getClass) - - def attachSink(pub: Publisher[Out]) = sink match { - case s: ActorFlowSink[Out] ⇒ s.attach(pub, this, flowName) - case s ⇒ throwUnknownType("Sink", s) - } - def attachSource(sub: Subscriber[In]) = source match { - case s: ActorFlowSource[In] ⇒ s.attach(sub, this, flowName) - case s ⇒ throwUnknownType("Source", s) - } - def createSink() = sink match { - case s: ActorFlowSink[In] ⇒ s.create(this, flowName) - case s ⇒ throwUnknownType("Sink", s) - } - def createSource() = source match { - case s: ActorFlowSource[Out] ⇒ s.create(this, flowName) - case s ⇒ throwUnknownType("Source", s) - } - def isActive(s: AnyRef) = s match { - case s: ActorFlowSource[_] ⇒ s.isActive - case s: ActorFlowSink[_] ⇒ s.isActive - case s: Source[_] ⇒ throwUnknownType("Source", s) - case s: Sink[_] ⇒ throwUnknownType("Sink", s) - } - - val (sourceValue, sinkValue) = - if (ops.isEmpty) { - if (isActive(sink)) { - val (sub, value) = createSink() - (attachSource(sub), value) - } else if (isActive(source)) { - val (pub, value) = createSource() - (value, attachSink(pub)) - } else { - val id: Processor[In, Out] = processorForNode(identityTransform, flowName, 1).asInstanceOf[Processor[In, Out]] - (attachSource(id), attachSink(id)) - } - } else { - val opsSize = ops.size - val last = processorForNode(ops.head, flowName, opsSize).asInstanceOf[Processor[Any, Out]] - val first = processorChain(last, ops.tail, flowName, opsSize - 1).asInstanceOf[Processor[In, Any]] - (attachSource(first), attachSink(last)) - } - new MaterializedPipe(source, sourceValue, sink, sinkValue) - } - - private val identityTransform = Ast.Transform("identity", () ⇒ - new Transformer[Any, Any] { - override def onNext(element: Any) = List(element) - }) - - /** - * INTERNAL API - */ - private[akka] def processorForNode(op: AstNode, flowName: String, n: Int): Processor[Any, Any] = { - val impl = actorOf(ActorProcessorFactory.props(this, op), s"$flowName-$n-${op.name}") - ActorProcessorFactory(impl) - } - - def actorOf(props: Props, name: String): ActorRef = supervisor match { - case ref: LocalActorRef ⇒ - ref.underlying.attachChild(props, name, systemService = false) - case ref: RepointableActorRef ⇒ - if (ref.isStarted) - ref.underlying.asInstanceOf[ActorCell].attachChild(props, name, systemService = false) - else { - implicit val timeout = ref.system.settings.CreationTimeout - val f = (supervisor ? StreamSupervisor.Materialize(props, name)).mapTo[ActorRef] - Await.result(f, timeout.duration) - } - case _ ⇒ - throw new IllegalStateException(s"Stream supervisor must be a local actor, was [${supervisor.getClass.getName}]") - } - - override def materializeJunction[In, Out](op: Ast.JunctionAstNode, inputCount: Int, outputCount: Int): (immutable.Seq[Subscriber[In]], immutable.Seq[Publisher[Out]]) = { - val flowName = createFlowName() - val actorName = s"$flowName-${op.name}" - - op match { - case fanin: Ast.FanInAstNode ⇒ - val impl = op match { - case Ast.Merge ⇒ - actorOf(FairMerge.props(settings, inputCount).withDispatcher(settings.dispatcher), actorName) - case Ast.MergePreferred ⇒ - actorOf(UnfairMerge.props(settings, inputCount).withDispatcher(settings.dispatcher), actorName) - case zip: Ast.Zip ⇒ - actorOf(Zip.props(settings, zip.as).withDispatcher(settings.dispatcher), actorName) - case Ast.Concat ⇒ - actorOf(Concat.props(settings).withDispatcher(settings.dispatcher), actorName) - case Ast.FlexiMergeNode(merger) ⇒ - actorOf(FlexiMergeImpl.props(settings, inputCount, merger.createMergeLogic()). - withDispatcher(settings.dispatcher), actorName) - } - - val publisher = new ActorPublisher[Out](impl, equalityValue = None) - impl ! ExposedPublisher(publisher.asInstanceOf[ActorPublisher[Any]]) - val subscribers = Vector.tabulate(inputCount)(FanIn.SubInput[In](impl, _)) - (subscribers, List(publisher)) - - case fanout: Ast.FanOutAstNode ⇒ - val impl = op match { - case Ast.Broadcast ⇒ - actorOf(Broadcast.props(settings, outputCount).withDispatcher(settings.dispatcher), actorName) - case Ast.Balance ⇒ - actorOf(Balance.props(settings, outputCount).withDispatcher(settings.dispatcher), actorName) - case Ast.Unzip ⇒ - actorOf(Unzip.props(settings).withDispatcher(settings.dispatcher), actorName) - } - - val publishers = Vector.tabulate(outputCount)(id ⇒ new ActorPublisher[Out](impl, equalityValue = None) { - override val wakeUpMsg = FanOut.SubstreamSubscribePending(id) - }) - impl ! FanOut.ExposedPublishers(publishers.asInstanceOf[immutable.Seq[ActorPublisher[Any]]]) - val subscriber = ActorSubscriber[In](impl) - (List(subscriber), publishers) - } - - } - -} - -/** - * INTERNAL API - */ -private[akka] object FlowNameCounter extends ExtensionId[FlowNameCounter] with ExtensionIdProvider { - override def get(system: ActorSystem): FlowNameCounter = super.get(system) - override def lookup = FlowNameCounter - override def createExtension(system: ExtendedActorSystem): FlowNameCounter = new FlowNameCounter -} - -/** - * INTERNAL API - */ -private[akka] class FlowNameCounter extends Extension { - val counter = new AtomicLong(0) -} - -/** - * INTERNAL API - */ -private[akka] object StreamSupervisor { - def props(settings: MaterializerSettings): Props = Props(new StreamSupervisor(settings)) - - case class Materialize(props: Props, name: String) -} - -private[akka] class StreamSupervisor(settings: MaterializerSettings) extends Actor { - import StreamSupervisor._ - - override def supervisorStrategy = SupervisorStrategy.stoppingStrategy - - def receive = { - case Materialize(props, name) ⇒ - val impl = context.actorOf(props, name) - sender() ! impl - } -} - -/** - * INTERNAL API - */ -private[akka] object ActorProcessorFactory { - - import Ast._ - def props(materializer: FlowMaterializer, op: AstNode): Props = { - val settings = materializer.settings - (op match { - case t: Transform ⇒ Props(new TransformProcessorImpl(settings, t.mkTransformer())) - case t: TimerTransform ⇒ Props(new TimerTransformerProcessorsImpl(settings, t.mkTransformer())) - case m: MapAsync ⇒ Props(new MapAsyncProcessorImpl(settings, m.f)) - case m: MapAsyncUnordered ⇒ Props(new MapAsyncUnorderedProcessorImpl(settings, m.f)) - case g: GroupBy ⇒ Props(new GroupByProcessorImpl(settings, g.f)) - case tt: PrefixAndTail ⇒ Props(new PrefixAndTailImpl(settings, tt.n)) - case s: SplitWhen ⇒ Props(new SplitWhenProcessorImpl(settings, s.p)) - case ConcatAll ⇒ Props(new ConcatAllImpl(materializer)) - case cf: Conflate ⇒ Props(new ConflateImpl(settings, cf.seed, cf.aggregate)) - case ex: Expand ⇒ Props(new ExpandImpl(settings, ex.seed, ex.extrapolate)) - case bf: Buffer ⇒ Props(new BufferImpl(settings, bf.size, bf.overflowStrategy)) - }).withDispatcher(settings.dispatcher) - } - - def apply[I, O](impl: ActorRef): ActorProcessor[I, O] = { - val p = new ActorProcessor[I, O](impl) - impl ! ExposedPublisher(p.asInstanceOf[ActorPublisher[Any]]) - p - } -} diff --git a/akka-stream/src/main/scala/akka/stream/impl2/ConcatAllImpl.scala b/akka-stream/src/main/scala/akka/stream/impl2/ConcatAllImpl.scala deleted file mode 100644 index 7f5cf43dbd..0000000000 --- a/akka-stream/src/main/scala/akka/stream/impl2/ConcatAllImpl.scala +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream.impl2 - -import akka.stream.impl.{ Extract, MultiStreamInputProcessor, TransferPhase } -import akka.stream.scaladsl2.{ Sink, FlowMaterializer } - -/** - * INTERNAL API - */ -private[akka] class ConcatAllImpl(materializer: FlowMaterializer) - extends MultiStreamInputProcessor(materializer.settings) { - - import akka.stream.impl.MultiStreamInputProcessor._ - - val takeNextSubstream = TransferPhase(primaryInputs.NeedsInput && primaryOutputs.NeedsDemand) { () ⇒ - val Extract.Source(source) = primaryInputs.dequeueInputElement() - val publisher = source.runWith(Sink.publisher)(materializer) - // FIXME we can pass the flow to createSubstreamInput (but avoiding copy impl now) - val inputs = createAndSubscribeSubstreamInput(publisher) - nextPhase(streamSubstream(inputs)) - } - - def streamSubstream(substream: SubstreamInput): TransferPhase = - TransferPhase(substream.NeedsInputOrComplete && primaryOutputs.NeedsDemand) { () ⇒ - if (substream.inputsDepleted) nextPhase(takeNextSubstream) - else primaryOutputs.enqueueOutputElement(substream.dequeueInputElement()) - } - - nextPhase(takeNextSubstream) - - override def invalidateSubstreamInput(substream: SubstreamKey, e: Throwable): Unit = fail(e) -} diff --git a/akka-stream/src/main/scala/akka/stream/impl2/GroupByProcessorImpl.scala b/akka-stream/src/main/scala/akka/stream/impl2/GroupByProcessorImpl.scala deleted file mode 100644 index a37c76d06f..0000000000 --- a/akka-stream/src/main/scala/akka/stream/impl2/GroupByProcessorImpl.scala +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream.impl2 - -import akka.stream.MaterializerSettings -import akka.stream.impl.TransferPhase -import akka.stream.scaladsl2.Source -import akka.stream.impl.MultiStreamOutputProcessor - -/** - * INTERNAL API - */ -private[akka] class GroupByProcessorImpl(settings: MaterializerSettings, val keyFor: Any ⇒ Any) - extends MultiStreamOutputProcessor(settings) { - - import MultiStreamOutputProcessor._ - - var keyToSubstreamOutput = collection.mutable.Map.empty[Any, SubstreamOutput] - - var pendingSubstreamOutput: SubstreamOutput = _ - - // No substream is open yet. If downstream cancels now, we are complete - val waitFirst = TransferPhase(primaryInputs.NeedsInput && primaryOutputs.NeedsDemand) { () ⇒ - val elem = primaryInputs.dequeueInputElement() - val key = keyFor(elem) - nextPhase(openSubstream(elem, key)) - } - - // some substreams are open now. If downstream cancels, we still continue until the substreams are closed - val waitNext = TransferPhase(primaryInputs.NeedsInput) { () ⇒ - val elem = primaryInputs.dequeueInputElement() - val key = keyFor(elem) - - keyToSubstreamOutput.get(key) match { - case Some(substream) if substream.isOpen ⇒ nextPhase(dispatchToSubstream(elem, keyToSubstreamOutput(key))) - case None if primaryOutputs.isOpen ⇒ nextPhase(openSubstream(elem, key)) - case _ ⇒ // stay - } - } - - def openSubstream(elem: Any, key: Any): TransferPhase = TransferPhase(primaryOutputs.NeedsDemand) { () ⇒ - if (primaryOutputs.isClosed) { - // Just drop, we do not open any more substreams - nextPhase(waitNext) - } else { - val substreamOutput = createSubstreamOutput() - val substreamFlow = Source(substreamOutput) // substreamOutput is a Publisher - primaryOutputs.enqueueOutputElement((key, substreamFlow)) - keyToSubstreamOutput(key) = substreamOutput - nextPhase(dispatchToSubstream(elem, substreamOutput)) - } - } - - def dispatchToSubstream(elem: Any, substream: SubstreamOutput): TransferPhase = { - pendingSubstreamOutput = substream - TransferPhase(substream.NeedsDemand) { () ⇒ - substream.enqueueOutputElement(elem) - pendingSubstreamOutput = null - nextPhase(waitNext) - } - } - - nextPhase(waitFirst) - - override def invalidateSubstreamOutput(substream: SubstreamKey): Unit = { - if ((pendingSubstreamOutput ne null) && substream == pendingSubstreamOutput.key) { - pendingSubstreamOutput = null - nextPhase(waitNext) - } - super.invalidateSubstreamOutput(substream) - } - -} diff --git a/akka-stream/src/main/scala/akka/stream/impl2/PrefixAndTailImpl.scala b/akka-stream/src/main/scala/akka/stream/impl2/PrefixAndTailImpl.scala deleted file mode 100644 index 6d8d6fb3d1..0000000000 --- a/akka-stream/src/main/scala/akka/stream/impl2/PrefixAndTailImpl.scala +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream.impl2 - -import akka.stream.MaterializerSettings -import scala.collection.immutable -import akka.stream.impl.TransferPhase -import akka.stream.impl.EmptyPublisher -import akka.stream.impl.MultiStreamOutputProcessor -import akka.stream.scaladsl2.Source - -/** - * INTERNAL API - */ -private[akka] class PrefixAndTailImpl(_settings: MaterializerSettings, val takeMax: Int) - extends MultiStreamOutputProcessor(_settings) { - - import MultiStreamOutputProcessor._ - - var taken = immutable.Vector.empty[Any] - var left = takeMax - - val take = TransferPhase(primaryInputs.NeedsInputOrComplete && primaryOutputs.NeedsDemand) { () ⇒ - if (primaryInputs.inputsDepleted) emitEmptyTail() - else { - val elem = primaryInputs.dequeueInputElement() - taken :+= elem - left -= 1 - if (left <= 0) { - if (primaryInputs.inputsDepleted) emitEmptyTail() - else emitNonEmptyTail() - } - } - } - - def streamTailPhase(substream: SubstreamOutput) = TransferPhase(primaryInputs.NeedsInput && substream.NeedsDemand) { () ⇒ - substream.enqueueOutputElement(primaryInputs.dequeueInputElement()) - } - - val takeEmpty = TransferPhase(primaryOutputs.NeedsDemand) { () ⇒ - if (primaryInputs.inputsDepleted) emitEmptyTail() - else emitNonEmptyTail() - } - - def emitEmptyTail(): Unit = { - primaryOutputs.enqueueOutputElement((taken, Source(EmptyPublisher[Any]))) - nextPhase(completedPhase) - } - - def emitNonEmptyTail(): Unit = { - val substreamOutput = createSubstreamOutput() - val substreamFlow = Source(substreamOutput) // substreamOutput is a Publisher - primaryOutputs.enqueueOutputElement((taken, substreamFlow)) - primaryOutputs.complete() - nextPhase(streamTailPhase(substreamOutput)) - } - - if (takeMax > 0) nextPhase(take) else nextPhase(takeEmpty) -} diff --git a/akka-stream/src/main/scala/akka/stream/impl2/SplitWhenProcessorImpl.scala b/akka-stream/src/main/scala/akka/stream/impl2/SplitWhenProcessorImpl.scala deleted file mode 100644 index bdceaaf2c2..0000000000 --- a/akka-stream/src/main/scala/akka/stream/impl2/SplitWhenProcessorImpl.scala +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream.impl2 - -import akka.stream.MaterializerSettings -import akka.stream.impl.TransferPhase -import akka.stream.impl.MultiStreamOutputProcessor -import akka.stream.scaladsl2.Source - -/** - * INTERNAL API - */ -private[akka] class SplitWhenProcessorImpl(_settings: MaterializerSettings, val splitPredicate: Any ⇒ Boolean) - extends MultiStreamOutputProcessor(_settings) { - - import MultiStreamOutputProcessor._ - - var currentSubstream: SubstreamOutput = _ - - val waitFirst = TransferPhase(primaryInputs.NeedsInput && primaryOutputs.NeedsDemand) { () ⇒ - nextPhase(openSubstream(primaryInputs.dequeueInputElement())) - } - - def openSubstream(elem: Any): TransferPhase = TransferPhase(primaryOutputs.NeedsDemand) { () ⇒ - val substreamOutput = createSubstreamOutput() - val substreamFlow = Source(substreamOutput) // substreamOutput is a Publisher - primaryOutputs.enqueueOutputElement(substreamFlow) - currentSubstream = substreamOutput - nextPhase(serveSubstreamFirst(currentSubstream, elem)) - } - - // Serving the substream is split into two phases to minimize elements "held in hand" - def serveSubstreamFirst(substream: SubstreamOutput, elem: Any) = TransferPhase(substream.NeedsDemand) { () ⇒ - substream.enqueueOutputElement(elem) - nextPhase(serveSubstreamRest(substream)) - } - - // Note that this phase is allocated only once per _slice_ and not per element - def serveSubstreamRest(substream: SubstreamOutput) = TransferPhase(primaryInputs.NeedsInput && substream.NeedsDemand) { () ⇒ - val elem = primaryInputs.dequeueInputElement() - if (splitPredicate(elem)) { - currentSubstream.complete() - currentSubstream = null - nextPhase(openSubstream(elem)) - } else substream.enqueueOutputElement(elem) - } - - // Ignore elements for a cancelled substream until a new substream needs to be opened - val ignoreUntilNewSubstream = TransferPhase(primaryInputs.NeedsInput) { () ⇒ - val elem = primaryInputs.dequeueInputElement() - if (splitPredicate(elem)) nextPhase(openSubstream(elem)) - } - - nextPhase(waitFirst) - - override def invalidateSubstreamOutput(substream: SubstreamKey): Unit = { - if ((currentSubstream ne null) && substream == currentSubstream.key) nextPhase(ignoreUntilNewSubstream) - super.invalidateSubstreamOutput(substream) - } - -} diff --git a/akka-stream/src/main/scala/akka/stream/io2/StreamTcp.scala b/akka-stream/src/main/scala/akka/stream/io2/StreamTcp.scala index 8d5fa38ed7..d892c57703 100644 --- a/akka-stream/src/main/scala/akka/stream/io2/StreamTcp.scala +++ b/akka-stream/src/main/scala/akka/stream/io2/StreamTcp.scala @@ -9,13 +9,17 @@ import akka.io.Inet.SocketOption import akka.io.{ Tcp, IO } import akka.japi.Util import akka.stream.MaterializerSettings -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ import akka.util.ByteString import java.io.Closeable import java.net.InetSocketAddress import java.net.URLEncoder import scala.collection._ import scala.concurrent.duration.{ Duration, FiniteDuration } +import akka.stream.scaladsl.MaterializedMap +import akka.stream.scaladsl.Sink +import akka.stream.scaladsl.Source +import akka.stream.FlowMaterializer object StreamTcp extends ExtensionId[StreamTcpExt] with ExtensionIdProvider { diff --git a/akka-stream/src/main/scala/akka/stream/io2/TcpConnectionStream.scala b/akka-stream/src/main/scala/akka/stream/io2/TcpConnectionStream.scala index d8dbd6611b..b465bfc298 100644 --- a/akka-stream/src/main/scala/akka/stream/io2/TcpConnectionStream.scala +++ b/akka-stream/src/main/scala/akka/stream/io2/TcpConnectionStream.scala @@ -4,7 +4,7 @@ package akka.stream.io2 import akka.io.{ IO, Tcp } -import akka.stream.scaladsl2._ +import akka.stream.scaladsl._ import scala.util.control.NoStackTrace import akka.actor._ import akka.stream.impl._ @@ -12,6 +12,9 @@ import akka.util.ByteString import akka.io.Tcp._ import akka.stream.MaterializerSettings import org.reactivestreams.Processor +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.Source +import akka.stream.scaladsl.Sink /** * INTERNAL API diff --git a/akka-stream/src/main/scala/akka/stream/io2/TcpListenStreamActor.scala b/akka-stream/src/main/scala/akka/stream/io2/TcpListenStreamActor.scala index 31dc7ed7bd..1307999af0 100644 --- a/akka-stream/src/main/scala/akka/stream/io2/TcpListenStreamActor.scala +++ b/akka-stream/src/main/scala/akka/stream/io2/TcpListenStreamActor.scala @@ -9,13 +9,17 @@ import akka.actor._ import akka.io.Tcp._ import akka.io.{ IO, Tcp } import akka.stream.impl._ -import akka.stream.impl2.ActorBasedFlowMaterializer +import akka.stream.impl.ActorBasedFlowMaterializer import akka.stream.io2.StreamTcp.IncomingTcpConnection import akka.stream.io2.TcpListenStreamActor.TCPSinkSource -import akka.stream.scaladsl2._ import akka.util.ByteString import org.reactivestreams.{ Subscriber, Publisher } import scala.util.control.NoStackTrace +import akka.stream.scaladsl.Sink +import akka.stream.FlowMaterializer +import akka.stream.scaladsl.Source +import akka.stream.scaladsl.SimpleActorFlowSource +import akka.stream.scaladsl.SimpleActorFlowSink /** * INTERNAL API diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/FlattenStrategy.scala b/akka-stream/src/main/scala/akka/stream/javadsl/FlattenStrategy.scala index 7197c8a557..69aa49d007 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/FlattenStrategy.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/FlattenStrategy.scala @@ -3,7 +3,6 @@ */ package akka.stream.javadsl -import akka.stream.FlattenStrategy import akka.stream.javadsl object FlattenStrategy { @@ -13,8 +12,8 @@ object FlattenStrategy { * emitting its elements directly to the output until it completes and then taking the next stream. This has the * consequence that if one of the input stream is infinite, no other streams after that will be consumed from. */ - def concat[T]: FlattenStrategy[javadsl.Source[T], T] = - akka.stream.scaladsl2.FlattenStrategy.Concat[T]().asInstanceOf[FlattenStrategy[javadsl.Source[T], T]] + def concat[T]: akka.stream.FlattenStrategy[javadsl.Source[T], T] = + akka.stream.FlattenStrategy.Concat[T]().asInstanceOf[akka.stream.FlattenStrategy[javadsl.Source[T], T]] // TODO so in theory this should be safe, but let's rethink the design later } 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 1688723928..7a3ae31455 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/Flow.scala @@ -6,8 +6,7 @@ package akka.stream.javadsl import akka.stream._ import akka.japi.Util -import akka.stream.scaladsl2 -import scaladsl2.FlowMaterializer +import akka.stream.scaladsl import scala.annotation.unchecked.uncheckedVariance import scala.concurrent.Future @@ -15,15 +14,15 @@ import scala.concurrent.duration.FiniteDuration object Flow { - import akka.stream.scaladsl2.JavaConverters._ + import akka.stream.scaladsl.JavaConverters._ - /** Adapt [[scaladsl2.Flow]] for use within Java DSL */ - def adapt[I, O](flow: scaladsl2.Flow[I, O]): javadsl.Flow[I, O] = + /** Adapt [[scaladsl.Flow]] for use within Java DSL */ + def adapt[I, O](flow: scaladsl.Flow[I, O]): javadsl.Flow[I, O] = new Flow(flow) /** Create a `Flow` which can process elements of type `T`. */ def create[T](): javadsl.Flow[T, T] = - Flow.adapt[T, T](scaladsl2.Pipe.empty[T]) + Flow.adapt[T, T](scaladsl.Pipe.empty[T]) /** Create a `Flow` which can process elements of type `T`. */ def of[T](clazz: Class[T]): javadsl.Flow[T, T] = @@ -34,7 +33,7 @@ object Flow { * returns the `UndefinedSource` and `UndefinedSink`. */ def apply[I, O](block: japi.Function[FlowGraphBuilder, akka.japi.Pair[UndefinedSource[I], UndefinedSink[O]]]): Flow[I, O] = { - val sFlow = scaladsl2.Flow() { b ⇒ + val sFlow = scaladsl.Flow() { b ⇒ val pair = block.apply(b.asJava) pair.first.asScala → pair.second.asScala } @@ -46,7 +45,7 @@ object Flow { * a [[FlowGraphBuilder]] and returns the `UndefinedSource` and `UndefinedSink`. */ def create[I, O](graph: PartialFlowGraph, block: japi.Function[javadsl.FlowGraphBuilder, akka.japi.Pair[UndefinedSource[I], UndefinedSink[O]]]): Flow[I, O] = { - val sFlow = scaladsl2.Flow(graph.asScala) { b ⇒ + val sFlow = scaladsl.Flow(graph.asScala) { b ⇒ val pair = block.apply(b.asJava) pair.first.asScala → pair.second.asScala } @@ -56,12 +55,12 @@ object Flow { } /** Create a `Flow` which can process elements of type `T`. */ -class Flow[-In, +Out](delegate: scaladsl2.Flow[In, Out]) { +class Flow[-In, +Out](delegate: scaladsl.Flow[In, Out]) { import scala.collection.JavaConverters._ - import akka.stream.scaladsl2.JavaConverters._ + import akka.stream.scaladsl.JavaConverters._ /** Converts this Flow to it's Scala DSL counterpart */ - def asScala: scaladsl2.Flow[In, Out] = delegate + def asScala: scaladsl.Flow[In, Out] = delegate // CONNECT // @@ -384,11 +383,11 @@ class Flow[-In, +Out](delegate: scaladsl2.Flow[In, Out]) { * Flow with attached input and output, can be executed. */ trait RunnableFlow { - def run(materializer: scaladsl2.FlowMaterializer): javadsl.MaterializedMap + def run(materializer: FlowMaterializer): javadsl.MaterializedMap } /** INTERNAL API */ -private[akka] class RunnableFlowAdapter(runnable: scaladsl2.RunnableFlow) extends RunnableFlow { - override def run(materializer: scaladsl2.FlowMaterializer): MaterializedMap = +private[akka] class RunnableFlowAdapter(runnable: scaladsl.RunnableFlow) extends RunnableFlow { + override def run(materializer: FlowMaterializer): MaterializedMap = new MaterializedMap(runnable.run()(materializer)) } diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/FlowGraph.scala b/akka-stream/src/main/scala/akka/stream/javadsl/FlowGraph.scala index 9554a33731..1fc0f7a5fb 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/FlowGraph.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/FlowGraph.scala @@ -4,35 +4,33 @@ package akka.stream.javadsl import akka.stream._ -import akka.stream.scaladsl2 -import akka.stream.scaladsl2 -import akka.stream.scaladsl2 -import impl2.Ast +import akka.stream.scaladsl +import akka.stream.impl.Ast import akka.stream._ // elements // trait JunctionInPort[-T] { - /** Convert this element to it's `scaladsl2` equivalent. */ - def asScala: scaladsl2.JunctionInPort[T] + /** Convert this element to it's `scaladsl` equivalent. */ + def asScala: scaladsl.JunctionInPort[T] } trait JunctionOutPort[T] { - /** Convert this element to it's `scaladsl2` equivalent. */ - def asScala: scaladsl2.JunctionOutPort[T] + /** Convert this element to it's `scaladsl` equivalent. */ + def asScala: scaladsl.JunctionOutPort[T] } abstract class Junction[T] extends JunctionInPort[T] with JunctionOutPort[T] { - /** Convert this element to it's `scaladsl2` equivalent. */ - def asScala: scaladsl2.Junction[T] + /** Convert this element to it's `scaladsl` equivalent. */ + def asScala: scaladsl.Junction[T] } /** INTERNAL API */ private object JunctionPortAdapter { - def apply[T](delegate: scaladsl2.JunctionInPort[T]): javadsl.JunctionInPort[T] = - new JunctionInPort[T] { override def asScala: scaladsl2.JunctionInPort[T] = delegate } + def apply[T](delegate: scaladsl.JunctionInPort[T]): javadsl.JunctionInPort[T] = + new JunctionInPort[T] { override def asScala: scaladsl.JunctionInPort[T] = delegate } - def apply[T](delegate: scaladsl2.JunctionOutPort[T]): javadsl.JunctionOutPort[T] = - new JunctionOutPort[T] { override def asScala: scaladsl2.JunctionOutPort[T] = delegate } + def apply[T](delegate: scaladsl.JunctionOutPort[T]): javadsl.JunctionOutPort[T] = + new JunctionOutPort[T] { override def asScala: scaladsl.JunctionOutPort[T] = delegate } } object Merge { @@ -42,7 +40,7 @@ object Merge { * in the `FlowGraph`. This method creates a new instance every time it * is called and those instances are not `equal`. */ - def create[T](): Merge[T] = new Merge(new scaladsl2.Merge[T](None)) + def create[T](): Merge[T] = new Merge(new scaladsl.Merge[T](None)) /** * Create a new anonymous `Merge` vertex with the specified output type. @@ -58,7 +56,7 @@ object Merge { * in the `FlowGraph`. Calling this method several times with the same name * returns instances that are `equal`. */ - def create[T](name: String): Merge[T] = new Merge(new scaladsl2.Merge[T](Some(name))) + def create[T](name: String): Merge[T] = new Merge(new scaladsl.Merge[T](Some(name))) /** * Create a named `Merge` vertex with the specified output type. @@ -76,8 +74,8 @@ object Merge { * When building the [[FlowGraph]] you must connect one or more input sources * and one output sink to the `Merge` vertex. */ -class Merge[T] private (delegate: scaladsl2.Merge[T]) extends javadsl.Junction[T] { - override def asScala: scaladsl2.Merge[T] = delegate +class Merge[T] private (delegate: scaladsl.Merge[T]) extends javadsl.Junction[T] { + override def asScala: scaladsl.Merge[T] = delegate } object MergePreferred { @@ -87,7 +85,7 @@ object MergePreferred { * in the `FlowGraph`. This method creates a new instance every time it * is called and those instances are not `equal`. */ - def create[T](): MergePreferred[T] = new MergePreferred(new scaladsl2.MergePreferred[T](None)) + def create[T](): MergePreferred[T] = new MergePreferred(new scaladsl.MergePreferred[T](None)) /** * Create a new anonymous `MergePreferred` vertex with the specified output type. @@ -95,7 +93,7 @@ object MergePreferred { * in the `FlowGraph`. This method creates a new instance every time it * is called and those instances are not `equal`. */ - def create[T](clazz: Class[T]): MergePreferred[T] = new MergePreferred(new scaladsl2.MergePreferred[T](None)) + def create[T](clazz: Class[T]): MergePreferred[T] = new MergePreferred(new scaladsl.MergePreferred[T](None)) /** * Create a named `MergePreferred` vertex with the specified output type. @@ -103,7 +101,7 @@ object MergePreferred { * in the `FlowGraph`. Calling this method several times with the same name * returns instances that are `equal`. */ - def create[T](name: String): MergePreferred[T] = new MergePreferred(new scaladsl2.MergePreferred[T](Some(name))) + def create[T](name: String): MergePreferred[T] = new MergePreferred(new scaladsl.MergePreferred[T](Some(name))) /** * Create a named `MergePreferred` vertex with the specified output type. @@ -111,7 +109,7 @@ object MergePreferred { * in the `FlowGraph`. Calling this method several times with the same name * returns instances that are `equal`. */ - def create[T](clazz: Class[T], name: String): MergePreferred[T] = new MergePreferred(new scaladsl2.MergePreferred[T](Some(name))) + def create[T](clazz: Class[T], name: String): MergePreferred[T] = new MergePreferred(new scaladsl.MergePreferred[T](Some(name))) } /** @@ -121,8 +119,8 @@ object MergePreferred { * When building the [[FlowGraph]] you must connect one or more input streams * and one output sink to the `Merge` vertex. */ -class MergePreferred[T](delegate: scaladsl2.MergePreferred[T]) extends javadsl.Junction[T] { - override def asScala: scaladsl2.MergePreferred[T] = delegate +class MergePreferred[T](delegate: scaladsl.MergePreferred[T]) extends javadsl.Junction[T] { + override def asScala: scaladsl.MergePreferred[T] = delegate } object Broadcast { @@ -132,7 +130,7 @@ object Broadcast { * in the `FlowGraph`. This method creates a new instance every time it * is called and those instances are not `equal`. */ - def create[T](): Broadcast[T] = new Broadcast(new scaladsl2.Broadcast(None)) + def create[T](): Broadcast[T] = new Broadcast(new scaladsl.Broadcast(None)) /** * Create a new anonymous `Broadcast` vertex with the specified input type. @@ -148,7 +146,7 @@ object Broadcast { * in the `FlowGraph`. Calling this method several times with the same name * returns instances that are `equal`. */ - def create[T](name: String): Broadcast[T] = new Broadcast(new scaladsl2.Broadcast(Some(name))) + def create[T](name: String): Broadcast[T] = new Broadcast(new scaladsl.Broadcast(Some(name))) /** * Create a named `Broadcast` vertex with the specified input type. @@ -164,8 +162,8 @@ object Broadcast { * the other streams. It will not shutdown until the subscriptions for at least * two downstream subscribers have been established. */ -class Broadcast[T](delegate: scaladsl2.Broadcast[T]) extends javadsl.Junction[T] { - override def asScala: scaladsl2.Broadcast[T] = delegate +class Broadcast[T](delegate: scaladsl.Broadcast[T]) extends javadsl.Junction[T] { + override def asScala: scaladsl.Broadcast[T] = delegate } object Balance { @@ -175,7 +173,7 @@ object Balance { * in the `FlowGraph`. This method creates a new instance every time it * is called and those instances are not `equal`. */ - def create[T](): Balance[T] = new Balance(new scaladsl2.Balance(None)) + def create[T](): Balance[T] = new Balance(new scaladsl.Balance(None)) /** * Create a new anonymous `Balance` vertex with the specified input type. @@ -191,7 +189,7 @@ object Balance { * in the `FlowGraph`. Calling this method several times with the same name * returns instances that are `equal`. */ - def create[T](name: String): Balance[T] = new Balance(new scaladsl2.Balance(Some(name))) + def create[T](name: String): Balance[T] = new Balance(new scaladsl.Balance(Some(name))) /** * Create a named `Balance` vertex with the specified input type. @@ -207,8 +205,8 @@ object Balance { * one of the other streams. It will not shutdown until the subscriptions for at least * two downstream subscribers have been established. */ -class Balance[T](delegate: scaladsl2.Balance[T]) extends javadsl.Junction[T] { - override def asScala: scaladsl2.Balance[T] = delegate +class Balance[T](delegate: scaladsl.Balance[T]) extends javadsl.Junction[T] { + override def asScala: scaladsl.Balance[T] = delegate } object Zip { @@ -236,8 +234,8 @@ object Zip { * is called and those instances are not `equal`.* */ def create[A, B](name: String): Zip[A, B] = - new Zip(new scaladsl2.Zip[A, B](Option(name)) { - override private[akka] def astNode: Ast.FanInAstNode = Ast.Zip(impl2.Zip.AsJavaPair) + new Zip(new scaladsl.Zip[A, B](Option(name)) { + override private[akka] def astNode: Ast.FanInAstNode = Ast.Zip(impl.Zip.AsJavaPair) }) /** @@ -250,15 +248,15 @@ object Zip { create[A, B](name) class Left[A, B](private val zip: Zip[A, B]) extends JunctionInPort[A] { - override def asScala: scaladsl2.JunctionInPort[A] = zip.asScala.left + override def asScala: scaladsl.JunctionInPort[A] = zip.asScala.left } class Right[A, B](private val zip: Zip[A, B]) extends JunctionInPort[B] { - override def asScala: scaladsl2.JunctionInPort[B] = zip.asScala.right + override def asScala: scaladsl.JunctionInPort[B] = zip.asScala.right } class Out[A, B](private val zip: Zip[A, B]) extends JunctionOutPort[akka.japi.Pair[A, B]] { // this cast is safe thanks to using `ZipAs` in the Ast element, Zip will emit the expected type (Pair) - override def asScala: scaladsl2.JunctionOutPort[akka.japi.Pair[A, B]] = - zip.asScala.out.asInstanceOf[scaladsl2.JunctionOutPort[akka.japi.Pair[A, B]]] + override def asScala: scaladsl.JunctionOutPort[akka.japi.Pair[A, B]] = + zip.asScala.out.asInstanceOf[scaladsl.JunctionOutPort[akka.japi.Pair[A, B]]] } } @@ -267,9 +265,9 @@ object Zip { * by combining corresponding elements in pairs. If one of the two streams is * longer than the other, its remaining elements are ignored. */ -final class Zip[A, B] private (delegate: scaladsl2.Zip[A, B]) { +final class Zip[A, B] private (delegate: scaladsl.Zip[A, B]) { - /** Convert this element to it's `scaladsl2` equivalent. */ + /** Convert this element to it's `scaladsl` equivalent. */ def asScala = delegate val left = new Zip.Left(this) @@ -282,7 +280,7 @@ object Unzip { create(null) def create[A, B](name: String): Unzip[A, B] = - new Unzip[A, B](new scaladsl2.Unzip[A, B](Option(name))) + new Unzip[A, B](new scaladsl.Unzip[A, B](Option(name))) def create[A, B](left: Class[A], right: Class[B]): Unzip[A, B] = create[A, B]() @@ -292,22 +290,22 @@ object Unzip { class In[A, B](private val unzip: Unzip[A, B]) extends JunctionInPort[akka.japi.Pair[A, B]] { // this cast is safe thanks to using `ZipAs` in the Ast element, Zip will emit the expected type (Pair) - override def asScala: scaladsl2.JunctionInPort[akka.japi.Pair[A, B]] = - unzip.asScala.in.asInstanceOf[scaladsl2.JunctionInPort[akka.japi.Pair[A, B]]] + override def asScala: scaladsl.JunctionInPort[akka.japi.Pair[A, B]] = + unzip.asScala.in.asInstanceOf[scaladsl.JunctionInPort[akka.japi.Pair[A, B]]] } class Left[A, B](private val unzip: Unzip[A, B]) extends JunctionOutPort[A] { - override def asScala: scaladsl2.JunctionOutPort[A] = + override def asScala: scaladsl.JunctionOutPort[A] = unzip.asScala.left } class Right[A, B](private val unzip: Unzip[A, B]) extends JunctionOutPort[B] { - override def asScala: scaladsl2.JunctionOutPort[B] = + override def asScala: scaladsl.JunctionOutPort[B] = unzip.asScala.right } } -final class Unzip[A, B] private (delegate: scaladsl2.Unzip[A, B]) { +final class Unzip[A, B] private (delegate: scaladsl.Unzip[A, B]) { - /** Convert this element to it's `scaladsl2` equivalent. */ + /** Convert this element to it's `scaladsl` equivalent. */ def asScala = delegate val in = new Unzip.In(this) @@ -322,7 +320,7 @@ object Concat { * in the `FlowGraph`. This method creates a new instance every time it * is called and those instances are not `equal`. */ - def create[T](): Concat[T] = new Concat(scaladsl2.Concat[T]) + def create[T](): Concat[T] = new Concat(scaladsl.Concat[T]) /** * Create a new anonymous `Concat` vertex with the specified input types. @@ -338,7 +336,7 @@ object Concat { * in the `FlowGraph`. This method creates a new instance every time it * is called and those instances are not `equal`.* */ - def create[T](name: String): Concat[T] = new Concat(scaladsl2.Concat[T](name)) + def create[T](name: String): Concat[T] = new Concat(scaladsl.Concat[T](name)) /** * Create a named `Concat` vertex with the specified input types. @@ -348,14 +346,14 @@ object Concat { */ def create[T](name: String, clazz: Class[T]): Concat[T] = create(name) - class First[T] private[akka] (delegate: scaladsl2.Concat.First[T]) extends JunctionInPort[T] { - override def asScala: scaladsl2.JunctionInPort[T] = delegate + class First[T] private[akka] (delegate: scaladsl.Concat.First[T]) extends JunctionInPort[T] { + override def asScala: scaladsl.JunctionInPort[T] = delegate } - class Second[T] private[akka] (delegate: scaladsl2.Concat.Second[T]) extends JunctionInPort[T] { - override def asScala: scaladsl2.JunctionInPort[T] = delegate + class Second[T] private[akka] (delegate: scaladsl.Concat.Second[T]) extends JunctionInPort[T] { + override def asScala: scaladsl.JunctionInPort[T] = delegate } - class Out[T] private[akka] (delegate: scaladsl2.Concat.Out[T]) extends JunctionOutPort[T] { - override def asScala: scaladsl2.JunctionOutPort[T] = delegate + class Out[T] private[akka] (delegate: scaladsl.Concat.Out[T]) extends JunctionOutPort[T] { + override def asScala: scaladsl.JunctionOutPort[T] = delegate } } @@ -365,9 +363,9 @@ object Concat { * by consuming one stream first emitting all of its elements, then consuming the * second stream emitting all of its elements. */ -class Concat[T] private (delegate: scaladsl2.Concat[T]) { +class Concat[T] private (delegate: scaladsl.Concat[T]) { - /** Convert this element to it's `scaladsl2` equivalent. */ + /** Convert this element to it's `scaladsl` equivalent. */ def asScala = delegate val first = new Concat.First[T](delegate.first) @@ -384,7 +382,7 @@ object UndefinedSource { * in the `FlowGraph`. This method creates a new instance every time it * is called and those instances are not `equal`. */ - def create[T](): UndefinedSource[T] = new UndefinedSource[T](new scaladsl2.UndefinedSource[T](None)) + def create[T](): UndefinedSource[T] = new UndefinedSource[T](new scaladsl.UndefinedSource[T](None)) /** * Create a new anonymous `Undefinedsource` vertex with the specified input type. @@ -392,7 +390,7 @@ object UndefinedSource { * in the `FlowGraph`. This method creates a new instance every time it * is called and those instances are not `equal`. */ - def create[T](clazz: Class[T]): UndefinedSource[T] = new UndefinedSource[T](new scaladsl2.UndefinedSource[T](None)) + def create[T](clazz: Class[T]): UndefinedSource[T] = new UndefinedSource[T](new scaladsl.UndefinedSource[T](None)) /** * Create a named `Undefinedsource` vertex with the specified input type. @@ -400,7 +398,7 @@ object UndefinedSource { * in the `FlowGraph`. Calling this method several times with the same name * returns instances that are `equal`. */ - def create[T](name: String): UndefinedSource[T] = new UndefinedSource[T](new scaladsl2.UndefinedSource[T](Some(name))) + def create[T](name: String): UndefinedSource[T] = new UndefinedSource[T](new scaladsl.UndefinedSource[T](Some(name))) /** * Create a named `Undefinedsource` vertex with the specified input type. @@ -408,7 +406,7 @@ object UndefinedSource { * in the `FlowGraph`. Calling this method several times with the same name * returns instances that are `equal`. */ - def create[T](clazz: Class[T], name: String): UndefinedSource[T] = new UndefinedSource[T](new scaladsl2.UndefinedSource[T](Some(name))) + def create[T](clazz: Class[T], name: String): UndefinedSource[T] = new UndefinedSource[T](new scaladsl.UndefinedSource[T](Some(name))) } /** @@ -416,8 +414,8 @@ object UndefinedSource { * yet by using this placeholder instead of the real [[Source]]. Later the placeholder can * be replaced with [[akka.stream.javadsl.FlowGraphBuilder#attachSource]]. */ -final class UndefinedSource[+T](delegate: scaladsl2.UndefinedSource[T]) { - def asScala: scaladsl2.UndefinedSource[T] = delegate +final class UndefinedSource[+T](delegate: scaladsl.UndefinedSource[T]) { + def asScala: scaladsl.UndefinedSource[T] = delegate } object UndefinedSink { @@ -427,7 +425,7 @@ object UndefinedSink { * in the `FlowGraph`. This method creates a new instance every time it * is called and those instances are not `equal`. */ - def create[T](): UndefinedSink[T] = new UndefinedSink[T](new scaladsl2.UndefinedSink[T](None)) + def create[T](): UndefinedSink[T] = new UndefinedSink[T](new scaladsl.UndefinedSink[T](None)) /** * Create a new anonymous `Undefinedsink` vertex with the specified input type. @@ -435,7 +433,7 @@ object UndefinedSink { * in the `FlowGraph`. This method creates a new instance every time it * is called and those instances are not `equal`. */ - def create[T](clazz: Class[T]): UndefinedSink[T] = new UndefinedSink[T](new scaladsl2.UndefinedSink[T](None)) + def create[T](clazz: Class[T]): UndefinedSink[T] = new UndefinedSink[T](new scaladsl.UndefinedSink[T](None)) /** * Create a named `Undefinedsink` vertex with the specified input type. @@ -443,7 +441,7 @@ object UndefinedSink { * in the `FlowGraph`. Calling this method several times with the same name * returns instances that are `equal`. */ - def create[T](name: String): UndefinedSink[T] = new UndefinedSink[T](new scaladsl2.UndefinedSink[T](Some(name))) + def create[T](name: String): UndefinedSink[T] = new UndefinedSink[T](new scaladsl.UndefinedSink[T](Some(name))) /** * Create a named `Undefinedsink` vertex with the specified input type. @@ -451,7 +449,7 @@ object UndefinedSink { * in the `FlowGraph`. Calling this method several times with the same name * returns instances that are `equal`. */ - def create[T](clazz: Class[T], name: String): UndefinedSink[T] = new UndefinedSink[T](new scaladsl2.UndefinedSink[T](Some(name))) + def create[T](clazz: Class[T], name: String): UndefinedSink[T] = new UndefinedSink[T](new scaladsl.UndefinedSink[T](Some(name))) } /** @@ -459,8 +457,8 @@ object UndefinedSink { * yet by using this placeholder instead of the real [[Sink]]. Later the placeholder can * be replaced with [[akka.stream.javadsl.FlowGraphBuilder#attachSink]]. */ -final class UndefinedSink[-T](delegate: scaladsl2.UndefinedSink[T]) { - def asScala: scaladsl2.UndefinedSink[T] = delegate +final class UndefinedSink[-T](delegate: scaladsl.UndefinedSink[T]) { + def asScala: scaladsl.UndefinedSink[T] = delegate } // flow graph // @@ -482,15 +480,15 @@ object FlowGraph { * Java API * Builder of [[FlowGraph]] and [[PartialFlowGraph]]. */ -class FlowGraphBuilder(b: scaladsl2.FlowGraphBuilder) { - import akka.stream.scaladsl2.JavaConverters._ +class FlowGraphBuilder(b: scaladsl.FlowGraphBuilder) { + import akka.stream.scaladsl.JavaConverters._ def this() { - this(new scaladsl2.FlowGraphBuilder()) + this(new scaladsl.FlowGraphBuilder()) } /** Converts this Java DSL element to it's Scala DSL counterpart. */ - def asScala: scaladsl2.FlowGraphBuilder = b + def asScala: scaladsl.FlowGraphBuilder = b def addEdge[In, Out](source: javadsl.UndefinedSource[In], flow: javadsl.Flow[In, Out], junctionIn: javadsl.JunctionInPort[Out]) = { b.addEdge(source.asScala, flow.asScala, junctionIn.asScala) @@ -568,11 +566,11 @@ class FlowGraphBuilder(b: scaladsl2.FlowGraphBuilder) { } /** - * Import all edges from another [[akka.stream.scaladsl2.PartialFlowGraph]] to this builder. + * Import all edges from another [[akka.stream.scaladsl.PartialFlowGraph]] to this builder. * After importing you can [[#connect]] undefined sources and sinks in * two different `PartialFlowGraph` instances. */ - def importPartialFlowGraph(partialFlowGraph: scaladsl2.PartialFlowGraph): FlowGraphBuilder = { + def importPartialFlowGraph(partialFlowGraph: scaladsl.PartialFlowGraph): FlowGraphBuilder = { b.importPartialFlowGraph(partialFlowGraph) this } @@ -597,18 +595,18 @@ class FlowGraphBuilder(b: scaladsl2.FlowGraphBuilder) { new PartialFlowGraph(b.partialBuild()) /** Build the [[FlowGraph]] and materialize it. */ - def run(materializer: scaladsl2.FlowMaterializer): javadsl.MaterializedMap = + def run(materializer: FlowMaterializer): javadsl.MaterializedMap = new MaterializedMap(b.build().run()(materializer)) } object PartialFlowGraphBuilder extends FlowGraphBuilder -class PartialFlowGraph(delegate: scaladsl2.PartialFlowGraph) { +class PartialFlowGraph(delegate: scaladsl.PartialFlowGraph) { import collection.JavaConverters._ - import akka.stream.scaladsl2.JavaConverters._ + import akka.stream.scaladsl.JavaConverters._ - def asScala: scaladsl2.PartialFlowGraph = delegate + def asScala: scaladsl.PartialFlowGraph = delegate def undefinedSources(): java.util.Set[UndefinedSource[Any]] = delegate.undefinedSources.map(s ⇒ s.asJava).asJava @@ -639,12 +637,12 @@ class PartialFlowGraph(delegate: scaladsl2.PartialFlowGraph) { } -class FlowGraph(delegate: scaladsl2.FlowGraph) extends RunnableFlow { +class FlowGraph(delegate: scaladsl.FlowGraph) extends RunnableFlow { - /** Convert this element to it's `scaladsl2` equivalent. */ - def asScala: scaladsl2.FlowGraph = delegate + /** Convert this element to it's `scaladsl` equivalent. */ + def asScala: scaladsl.FlowGraph = delegate - override def run(materializer: scaladsl2.FlowMaterializer): javadsl.MaterializedMap = + override def run(materializer: FlowMaterializer): javadsl.MaterializedMap = new MaterializedMap(delegate.run()(materializer)) } diff --git a/akka-stream/src/main/scala/akka/stream/javadsl/MaterializedMap.scala b/akka-stream/src/main/scala/akka/stream/javadsl/MaterializedMap.scala index a964a835be..290901d273 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/MaterializedMap.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/MaterializedMap.scala @@ -4,24 +4,24 @@ package akka.stream.javadsl import akka.stream.javadsl -import akka.stream.scaladsl2 +import akka.stream.scaladsl /** * Java API * * Returned by [[RunnableFlow#run]] and can be used as parameter to the * accessor method to retrieve the materialized `Source` or `Sink`, e.g. - * [[akka.stream.scaladsl2.SubscriberSource#subscriber]] or [[akka.stream.scaladsl2.PublisherSink#publisher]]. + * [[akka.stream.scaladsl.SubscriberSource#subscriber]] or [[akka.stream.scaladsl.PublisherSink#publisher]]. */ -class MaterializedMap(delegate: scaladsl2.MaterializedMap) { +class MaterializedMap(delegate: scaladsl.MaterializedMap) { /** - * Retrieve a materialized `Source`, e.g. the `Subscriber` of a [[akka.stream.scaladsl2.SubscriberSource]]. + * Retrieve a materialized `Source`, e.g. the `Subscriber` of a [[akka.stream.scaladsl.SubscriberSource]]. */ def get[T](key: javadsl.KeyedSource[_, T]): T = delegate.get(key.asScala).asInstanceOf[T] /** - * Retrieve a materialized `Sink`, e.g. the `Publisher` of a [[akka.stream.scaladsl2.PublisherSink]]. + * Retrieve a materialized `Sink`, e.g. the `Publisher` of a [[akka.stream.scaladsl.PublisherSink]]. */ def get[D](key: javadsl.KeyedSink[_, D]): D = delegate.get(key.asScala).asInstanceOf[D] 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 11f7ba0153..5579b38c8d 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/Sink.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/Sink.scala @@ -6,20 +6,20 @@ package akka.stream.javadsl import akka.actor.ActorRef import akka.actor.Props import akka.stream.javadsl -import akka.stream.scaladsl2 +import akka.stream.scaladsl +import akka.stream.FlowMaterializer import org.reactivestreams.Publisher import org.reactivestreams.Subscriber -import scaladsl2.FlowMaterializer import scala.concurrent.Future /** Java API */ object Sink { - import akka.stream.scaladsl2.JavaConverters._ + import akka.stream.scaladsl.JavaConverters._ - /** Adapt [[scaladsl2.Sink]] for use within Java DSL */ - def adapt[O](sink: scaladsl2.Sink[O]): javadsl.Sink[O] = + /** Adapt [[scaladsl.Sink]] for use within Java DSL */ + def adapt[O](sink: scaladsl.Sink[O]): javadsl.Sink[O] = new Sink(sink) /** @@ -30,27 +30,27 @@ object Sink { * if there is an error is signaled in the stream. */ def fold[U, In](zero: U, f: japi.Function2[U, In, U]): javadsl.KeyedSink[In, Future[U]] = - new KeyedSink(scaladsl2.Sink.fold[U, In](zero)(f.apply)) + new KeyedSink(scaladsl.Sink.fold[U, In](zero)(f.apply)) /** * Helper to create [[Sink]] from `Subscriber`. */ def create[In](subs: Subscriber[In]): Sink[In] = - new Sink[In](scaladsl2.Sink(subs)) + new Sink[In](scaladsl.Sink(subs)) /** * Creates a `Sink` by using an empty [[FlowGraphBuilder]] on a block that expects a [[FlowGraphBuilder]] and * returns the `UndefinedSource`. */ def create[T]()(block: japi.Function[FlowGraphBuilder, UndefinedSource[T]]): Sink[T] = - new Sink(scaladsl2.Sink.apply() { b ⇒ block.apply(b.asJava).asScala }) + new Sink(scaladsl.Sink.apply() { b ⇒ block.apply(b.asJava).asScala }) /** * Creates a `Sink` by using a FlowGraphBuilder from this [[PartialFlowGraph]] on a block that expects * a [[FlowGraphBuilder]] and returns the `UndefinedSource`. */ def create[T](graph: PartialFlowGraph, block: japi.Function[FlowGraphBuilder, UndefinedSource[T]]): Sink[T] = - new Sink[T](scaladsl2.Sink.apply(graph.asScala) { b ⇒ block.apply(b.asJava).asScala }) + new Sink[T](scaladsl.Sink.apply(graph.asScala) { b ⇒ block.apply(b.asJava).asScala }) /** * Creates a `Sink` that is materialized to an [[akka.actor.ActorRef]] which points to an Actor @@ -58,26 +58,26 @@ object Sink { * be [[akka.stream.actor.ActorSubscriber]]. */ def create[T](props: Props): KeyedSink[T, ActorRef] = - new KeyedSink(scaladsl2.Sink.apply(props)) + new KeyedSink(scaladsl.Sink.apply(props)) /** * A `Sink` that immediately cancels its upstream after materialization. */ def cancelled[T]: Sink[T] = - new Sink(scaladsl2.Sink.cancelled) + new Sink(scaladsl.Sink.cancelled) /** * A `Sink` that will consume the stream and discard the elements. */ def ignore[T](): Sink[T] = - new Sink(scaladsl2.Sink.ignore) + new Sink(scaladsl.Sink.ignore) /** * A `Sink` that materializes into a [[org.reactivestreams.Publisher]]. * that can handle one [[org.reactivestreams.Subscriber]]. */ def publisher[In](): KeyedSink[In, Publisher[In]] = - new KeyedSink(scaladsl2.Sink.publisher) + new KeyedSink(scaladsl.Sink.publisher) /** * A `Sink` that will invoke the given procedure for each received element. The sink is materialized @@ -86,14 +86,14 @@ object Sink { * the stream.. */ def foreach[T](f: japi.Procedure[T]): KeyedSink[T, Future[Unit]] = - new KeyedSink(scaladsl2.Sink.foreach(f.apply)) + new KeyedSink(scaladsl.Sink.foreach(f.apply)) /** * A `Sink` that materializes into a [[org.reactivestreams.Publisher]] * that can handle more than one [[org.reactivestreams.Subscriber]]. */ def fanoutPublisher[T](initialBufferSize: Int, maximumBufferSize: Int): KeyedSink[Publisher[T], T] = - new KeyedSink(scaladsl2.Sink.fanoutPublisher(initialBufferSize, maximumBufferSize)) + new KeyedSink(scaladsl.Sink.fanoutPublisher(initialBufferSize, maximumBufferSize)) /** * A `Sink` that when the flow is completed, either through an error or normal @@ -101,13 +101,13 @@ object Sink { * or [[scala.util.Failure]]. */ def onComplete[In](onComplete: japi.Procedure[Unit]): Sink[In] = - new Sink(scaladsl2.Sink.onComplete[In](x ⇒ onComplete.apply(x))) + new Sink(scaladsl.Sink.onComplete[In](x ⇒ onComplete.apply(x))) /** * A `Sink` that materializes into a `Future` of the first value received. */ def future[In]: KeyedSink[In, Future[In]] = - new KeyedSink(scaladsl2.Sink.future[In]) + new KeyedSink(scaladsl.Sink.future[In]) /** * A `Sink` that will invoke the given function for every received element, giving it its previous @@ -117,7 +117,7 @@ object Sink { * if there is an error is signaled in the stream. */ def fold[U, T](zero: U, f: Function[akka.japi.Pair[U, T], U]): KeyedSink[T, U] = { - val sSink = scaladsl2.Sink.fold[U, T](zero) { case (a, b) ⇒ f.apply(akka.japi.Pair(a, b)) } + val sSink = scaladsl.Sink.fold[U, T](zero) { case (a, b) ⇒ f.apply(akka.japi.Pair(a, b)) } new KeyedSink(sSink) } @@ -129,10 +129,10 @@ object Sink { * A `Sink` is a set of stream processing steps that has one open input and an attached output. * Can be used as a `Subscriber` */ -class Sink[-In](delegate: scaladsl2.Sink[In]) { +class Sink[-In](delegate: scaladsl.Sink[In]) { /** Converts this Sink to it's Scala DSL counterpart */ - def asScala: scaladsl2.Sink[In] = delegate + def asScala: scaladsl.Sink[In] = delegate // RUN WITH // @@ -160,6 +160,6 @@ class Sink[-In](delegate: scaladsl2.Sink[In]) { * to retrieve in order to access aspects of this sink (could be a completion Future * or a cancellation handle, etc.) */ -final class KeyedSink[-In, M](delegate: scaladsl2.KeyedSink[In]) extends javadsl.Sink[In](delegate) { - override def asScala: scaladsl2.KeyedSink[In] = super.asScala.asInstanceOf[scaladsl2.KeyedSink[In]] +final class KeyedSink[-In, M](delegate: scaladsl.KeyedSink[In]) extends javadsl.Sink[In](delegate) { + override def asScala: scaladsl.KeyedSink[In] = super.asScala.asInstanceOf[scaladsl.KeyedSink[In]] } 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 944a403b55..cd18aa5bed 100644 --- a/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala +++ b/akka-stream/src/main/scala/akka/stream/javadsl/Source.scala @@ -9,10 +9,9 @@ import akka.actor.ActorRef import akka.actor.Props import akka.japi.Util import akka.stream._ +import akka.stream.scaladsl.PropsSource import org.reactivestreams.Publisher import org.reactivestreams.Subscriber -import scaladsl2.FlowMaterializer -import scaladsl2.PropsSource import scala.annotation.unchecked.uncheckedVariance import scala.collection.JavaConverters._ @@ -24,14 +23,14 @@ import scala.language.implicitConversions /** Java API */ object Source { - import scaladsl2.JavaConverters._ + import scaladsl.JavaConverters._ - /** Adapt [[scaladsl2.Source]] for use within JavaDSL */ - def adapt[O](source: scaladsl2.Source[O]): Source[O] = + /** Adapt [[scaladsl.Source]] for use within JavaDSL */ + def adapt[O](source: scaladsl.Source[O]): Source[O] = new Source(source) - /** Adapt [[scaladsl2.SourcePipe]] for use within JavaDSL */ - def adapt[O](source: scaladsl2.SourcePipe[O]): Source[O] = + /** Adapt [[scaladsl.SourcePipe]] for use within JavaDSL */ + def adapt[O](source: scaladsl.SourcePipe[O]): Source[O] = new Source(source) /** @@ -39,7 +38,7 @@ object Source { * for every connected `Sink`. */ def empty[O](): Source[O] = - new Source(scaladsl2.Source.empty()) + new Source(scaladsl.Source.empty()) /** * Helper to create [[Source]] from `Publisher`. @@ -50,7 +49,7 @@ object Source { * back-pressure upstream. */ def from[O](publisher: Publisher[O]): javadsl.Source[O] = - new Source(scaladsl2.Source.apply(publisher)) + new Source(scaladsl.Source.apply(publisher)) /** * Helper to create [[Source]] from `Iterator`. @@ -71,7 +70,7 @@ object Source { * steps. */ def from[O](iterator: java.util.Iterator[O]): javadsl.Source[O] = - new Source(scaladsl2.Source(iterator.asScala)) + new Source(scaladsl.Source(iterator.asScala)) /** * Helper to create [[Source]] from `Iterable`. @@ -90,7 +89,7 @@ object Source { * beginning) regardless of when they subscribed. */ def from[O](iterable: java.lang.Iterable[O]): javadsl.Source[O] = - new Source(scaladsl2.Source(akka.stream.javadsl.japi.Util.immutableIterable(iterable))) + new Source(scaladsl.Source(akka.stream.javadsl.japi.Util.immutableIterable(iterable))) /** * Define the sequence of elements to be produced by the given closure. @@ -98,7 +97,7 @@ object Source { * The stream ends exceptionally when an exception is thrown from the closure. */ def from[O](f: japi.Creator[akka.japi.Option[O]]): javadsl.Source[O] = - new Source(scaladsl2.Source(() ⇒ f.create().asScala)) + new Source(scaladsl.Source(() ⇒ f.create().asScala)) /** * Start a new `Source` from the given `Future`. The stream will consist of @@ -107,7 +106,7 @@ object Source { * The stream terminates with an error if the `Future` is completed with a failure. */ def from[O](future: Future[O]): javadsl.Source[O] = - new Source(scaladsl2.Source(future)) + new Source(scaladsl.Source(future)) /** * Elements are produced from the tick closure periodically with the specified interval. @@ -117,14 +116,14 @@ object Source { * receive new tick elements as soon as it has requested more elements. */ def from[O](initialDelay: FiniteDuration, interval: FiniteDuration, tick: Callable[O]): javadsl.Source[O] = - new Source(scaladsl2.Source(initialDelay, interval, () ⇒ tick.call())) + new Source(scaladsl.Source(initialDelay, interval, () ⇒ tick.call())) /** * Creates a `Source` by using a [[FlowGraphBuilder]] from this [[PartialFlowGraph]] on a block that expects * a [[FlowGraphBuilder]] and returns the `UndefinedSink`. */ def from[T](graph: PartialFlowGraph, block: japi.Function[FlowGraphBuilder, UndefinedSink[T]]): Source[T] = - new Source(scaladsl2.Source(graph.asScala)(x ⇒ block.apply(x.asJava).asScala)) + new Source(scaladsl.Source(graph.asScala)(x ⇒ block.apply(x.asJava).asScala)) /** * Creates a `Source` that is materialized to an [[akka.actor.ActorRef]] which points to an Actor @@ -132,26 +131,26 @@ object Source { * be [[akka.stream.actor.ActorPublisher]]. */ def from[T](props: Props): KeyedSource[T, ActorRef] = - new KeyedSource(scaladsl2.Source.apply(props)) + new KeyedSource(scaladsl.Source.apply(props)) /** * Create a `Source` with one element. * Every connected `Sink` of this stream will see an individual stream consisting of one element. */ def singleton[T](element: T): Source[T] = - new Source(scaladsl2.Source.singleton(element)) + new Source(scaladsl.Source.singleton(element)) /** * Create a `Source` that immediately ends the stream with the `cause` error to every connected `Sink`. */ def failed[T](cause: Throwable): Source[T] = - new Source(scaladsl2.Source.failed(cause)) + new Source(scaladsl.Source.failed(cause)) /** * Creates a `Source` that is materialized as a [[org.reactivestreams.Subscriber]] */ def subscriber[T](): KeyedSource[Subscriber[T], T] = - new KeyedSource(scaladsl2.Source.subscriber) + new KeyedSource(scaladsl.Source.subscriber) /** * Concatenates two sources so that the first element @@ -159,7 +158,7 @@ object Source { * source. */ def concat[T](first: Source[T], second: Source[T]): Source[T] = - new KeyedSource(scaladsl2.Source.concat(first.asScala, second.asScala)) + new KeyedSource(scaladsl.Source.concat(first.asScala, second.asScala)) } /** @@ -168,13 +167,13 @@ object Source { * A `Source` is a set of stream processing steps that has one open output and an attached input. * Can be used as a `Publisher` */ -class Source[+Out](delegate: scaladsl2.Source[Out]) { - import akka.stream.scaladsl2.JavaConverters._ +class Source[+Out](delegate: scaladsl.Source[Out]) { + import akka.stream.scaladsl.JavaConverters._ import scala.collection.JavaConverters._ /** Converts this Java DSL element to it's Scala DSL counterpart. */ - def asScala: scaladsl2.Source[Out] = delegate + def asScala: scaladsl.Source[Out] = delegate // CONNECT // @@ -501,6 +500,6 @@ class Source[+Out](delegate: scaladsl2.Source[Out]) { * A `Source` that will create an object during materialization that the user will need * to retrieve in order to access aspects of this source (could be a Subscriber, a Future/Promise, etc.). */ -final class KeyedSource[+Out, T](delegate: scaladsl2.Source[Out]) extends Source[Out](delegate) { - override def asScala: scaladsl2.KeyedActorFlowSource[Out] = super.asScala.asInstanceOf[scaladsl2.KeyedActorFlowSource[Out]] +final class KeyedSource[+Out, T](delegate: scaladsl.Source[Out]) extends Source[Out](delegate) { + override def asScala: scaladsl.KeyedActorFlowSource[Out] = super.asScala.asInstanceOf[scaladsl.KeyedActorFlowSource[Out]] } diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/ActorFlowSink.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/ActorFlowSink.scala similarity index 88% rename from akka-stream/src/main/scala/akka/stream/scaladsl2/ActorFlowSink.scala rename to akka-stream/src/main/scala/akka/stream/scaladsl/ActorFlowSink.scala index f0f79f4f7b..14cdbc1672 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/ActorFlowSink.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/ActorFlowSink.scala @@ -1,7 +1,7 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import akka.actor.ActorRef import akka.actor.Props @@ -12,8 +12,7 @@ import scala.concurrent.{ Future, Promise } import scala.util.{ Failure, Success, Try } import org.reactivestreams.{ Publisher, Subscriber, Subscription } import akka.stream.Transformer -import akka.stream.impl.{ FanoutProcessorImpl, BlackholeSubscriber } -import akka.stream.impl2.{ ActorProcessorFactory, ActorBasedFlowMaterializer } +import akka.stream.impl.{ ActorBasedFlowMaterializer, ActorProcessorFactory, FanoutProcessorImpl, BlackholeSubscriber } import java.util.concurrent.atomic.AtomicReference sealed trait ActorFlowSink[-In] extends Sink[In] { @@ -65,7 +64,7 @@ trait SimpleActorFlowSink[-In] extends ActorFlowSink[In] { */ trait KeyedActorFlowSink[-In] extends ActorFlowSink[In] with KeyedSink[In] -private[scaladsl2] object PublisherSink { +private[scaladsl] object PublisherSink { def apply[T](): PublisherSink[T] = new PublisherSink[T] def withFanout[T](initialBufferSize: Int, maximumBufferSize: Int): FanoutPublisherSink[T] = new FanoutPublisherSink[T](initialBufferSize, maximumBufferSize) @@ -77,7 +76,7 @@ private[scaladsl2] object PublisherSink { * elements to fill the internal buffers it will assert back-pressure until * a subscriber connects and creates demand for elements to be emitted. */ -private[scaladsl2] class PublisherSink[In] extends KeyedActorFlowSink[In] { +private[scaladsl] class PublisherSink[In] extends KeyedActorFlowSink[In] { type MaterializedType = Publisher[In] override def attach(flowPublisher: Publisher[In], materializer: ActorBasedFlowMaterializer, flowName: String) = flowPublisher @@ -85,7 +84,7 @@ private[scaladsl2] class PublisherSink[In] extends KeyedActorFlowSink[In] { override def toString: String = "PublisherSink" } -private[scaladsl2] final case class FanoutPublisherSink[In](initialBufferSize: Int, maximumBufferSize: Int) extends KeyedActorFlowSink[In] { +private[scaladsl] final case class FanoutPublisherSink[In](initialBufferSize: Int, maximumBufferSize: Int) extends KeyedActorFlowSink[In] { type MaterializedType = Publisher[In] override def attach(flowPublisher: Publisher[In], materializer: ActorBasedFlowMaterializer, flowName: String) = { @@ -97,7 +96,7 @@ private[scaladsl2] final case class FanoutPublisherSink[In](initialBufferSize: I } } -private[scaladsl2] object FutureSink { +private[scaladsl] object FutureSink { def apply[T](): FutureSink[T] = new FutureSink[T] } @@ -108,7 +107,7 @@ private[scaladsl2] object FutureSink { * the Future into the corresponding failed state) or the end-of-stream * (failing the Future with a NoSuchElementException). */ -private[scaladsl2] class FutureSink[In] extends KeyedActorFlowSink[In] { +private[scaladsl] class FutureSink[In] extends KeyedActorFlowSink[In] { type MaterializedType = Future[In] @@ -139,7 +138,7 @@ private[scaladsl2] class FutureSink[In] extends KeyedActorFlowSink[In] { * Attaches a subscriber to this stream which will just discard all received * elements. */ -private[scaladsl2] final case object BlackholeSink extends SimpleActorFlowSink[Any] { +private[scaladsl] final case object BlackholeSink extends SimpleActorFlowSink[Any] { override def attach(flowPublisher: Publisher[Any], materializer: ActorBasedFlowMaterializer, flowName: String): Unit = flowPublisher.subscribe(create(materializer, flowName)._1) override def isActive: Boolean = true @@ -150,14 +149,14 @@ private[scaladsl2] final case object BlackholeSink extends SimpleActorFlowSink[A /** * Attaches a subscriber to this stream. */ -private[scaladsl2] final case class SubscriberSink[In](subscriber: Subscriber[In]) extends SimpleActorFlowSink[In] { +private[scaladsl] final case class SubscriberSink[In](subscriber: Subscriber[In]) extends SimpleActorFlowSink[In] { override def attach(flowPublisher: Publisher[In], materializer: ActorBasedFlowMaterializer, flowName: String) = flowPublisher.subscribe(subscriber) override def isActive: Boolean = true override def create(materializer: ActorBasedFlowMaterializer, flowName: String) = (subscriber, ()) } -private[scaladsl2] object OnCompleteSink { +private[scaladsl] object OnCompleteSink { private val SuccessUnit = Success[Unit](()) } @@ -166,7 +165,7 @@ private[scaladsl2] object OnCompleteSink { * completion, apply the provided function with [[scala.util.Success]] * or [[scala.util.Failure]]. */ -private[scaladsl2] final case class OnCompleteSink[In](callback: Try[Unit] ⇒ Unit) extends SimpleActorFlowSink[In] { +private[scaladsl] final case class OnCompleteSink[In](callback: Try[Unit] ⇒ Unit) extends SimpleActorFlowSink[In] { override def attach(flowPublisher: Publisher[In], materializer: ActorBasedFlowMaterializer, flowName: String) = Source(flowPublisher).transform("onCompleteSink", () ⇒ new Transformer[In, Unit] { @@ -187,7 +186,7 @@ private[scaladsl2] final case class OnCompleteSink[In](callback: Try[Unit] ⇒ U * that will be completed with `Success` when reaching the normal end of the stream, or completed * with `Failure` if there is an error is signaled in the stream. */ -private[scaladsl2] final case class ForeachSink[In](f: In ⇒ Unit) extends KeyedActorFlowSink[In] { +private[scaladsl] final case class ForeachSink[In](f: In ⇒ Unit) extends KeyedActorFlowSink[In] { override type MaterializedType = Future[Unit] @@ -215,7 +214,7 @@ private[scaladsl2] final case class ForeachSink[In](f: In ⇒ Unit) extends Keye * function evaluation when the input stream ends, or completed with `Failure` * if there is an error is signaled in the stream. */ -private[scaladsl2] final case class FoldSink[U, In](zero: U)(f: (U, In) ⇒ U) extends KeyedActorFlowSink[In] { +private[scaladsl] final case class FoldSink[U, In](zero: U)(f: (U, In) ⇒ U) extends KeyedActorFlowSink[In] { type MaterializedType = Future[U] @@ -242,7 +241,7 @@ private[scaladsl2] final case class FoldSink[U, In](zero: U)(f: (U, In) ⇒ U) e /** * A sink that immediately cancels its upstream upon materialization. */ -private[scaladsl2] final case object CancelSink extends SimpleActorFlowSink[Any] { +private[scaladsl] final case object CancelSink extends SimpleActorFlowSink[Any] { override def attach(flowPublisher: Publisher[Any], materializer: ActorBasedFlowMaterializer, flowName: String): Unit = { flowPublisher.subscribe(new Subscriber[Any] { @@ -258,7 +257,7 @@ private[scaladsl2] final case object CancelSink extends SimpleActorFlowSink[Any] * Creates and wraps an actor into [[org.reactivestreams.Subscriber]] from the given `props`, * which should be [[akka.actor.Props]] for an [[akka.stream.actor.ActorSubscriber]]. */ -private[scaladsl2] final case class PropsSink[In](props: Props) extends KeyedActorFlowSink[In] { +private[scaladsl] final case class PropsSink[In](props: Props) extends KeyedActorFlowSink[In] { type MaterializedType = ActorRef diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/ActorFlowSource.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/ActorFlowSource.scala similarity index 88% rename from akka-stream/src/main/scala/akka/stream/scaladsl2/ActorFlowSource.scala rename to akka-stream/src/main/scala/akka/stream/scaladsl/ActorFlowSource.scala index e4422f56fc..e34d4d34d0 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/ActorFlowSource.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/ActorFlowSource.scala @@ -1,13 +1,13 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import akka.actor.ActorRef import akka.actor.Props import akka.stream.impl._ -import akka.stream.impl2.ActorBasedFlowMaterializer -import akka.stream.impl2.Ast.AstNode +import akka.stream.impl.ActorBasedFlowMaterializer +import akka.stream.impl.Ast.AstNode import org.reactivestreams.Publisher import org.reactivestreams.Subscriber @@ -61,7 +61,7 @@ sealed trait ActorFlowSource[+Out] extends Source[Out] { override def connect(sink: Sink[Out]): RunnableFlow = sourcePipe.connect(sink) /** INTERNAL API */ - override private[scaladsl2] def andThen[U](op: AstNode) = SourcePipe(this, List(op)) + override private[scaladsl] def andThen[U](op: AstNode) = SourcePipe(this, List(op)) } /** @@ -82,7 +82,7 @@ trait KeyedActorFlowSource[+Out] extends ActorFlowSource[Out] with KeyedSource[O * Holds a `Subscriber` representing the input side of the flow. * The `Subscriber` can later be connected to an upstream `Publisher`. */ -private[scaladsl2] final case class SubscriberSource[Out]() extends KeyedActorFlowSource[Out] { +private[scaladsl] final case class SubscriberSource[Out]() extends KeyedActorFlowSource[Out] { override type MaterializedType = Subscriber[Out] override def attach(flowSubscriber: Subscriber[Out], materializer: ActorBasedFlowMaterializer, flowName: String): Subscriber[Out] = @@ -95,7 +95,7 @@ private[scaladsl2] final case class SubscriberSource[Out]() extends KeyedActorFl * that mediate the flow of elements downstream and the propagation of * back-pressure upstream. */ -private[scaladsl2] final case class PublisherSource[Out](p: Publisher[Out]) extends SimpleActorFlowSource[Out] { +private[scaladsl] final case class PublisherSource[Out](p: Publisher[Out]) extends SimpleActorFlowSource[Out] { override def attach(flowSubscriber: Subscriber[Out], materializer: ActorBasedFlowMaterializer, flowName: String) = p.subscribe(flowSubscriber) override def isActive: Boolean = true @@ -109,7 +109,7 @@ private[scaladsl2] final case class PublisherSource[Out](p: Publisher[Out]) exte * in accordance with the demand coming from the downstream transformation * steps. */ -private[scaladsl2] final case class IteratorSource[Out](iterator: Iterator[Out]) extends SimpleActorFlowSource[Out] { +private[scaladsl] final case class IteratorSource[Out](iterator: Iterator[Out]) extends SimpleActorFlowSource[Out] { override def attach(flowSubscriber: Subscriber[Out], materializer: ActorBasedFlowMaterializer, flowName: String) = create(materializer, flowName)._1.subscribe(flowSubscriber) override def isActive: Boolean = true @@ -125,7 +125,7 @@ private[scaladsl2] final case class IteratorSource[Out](iterator: Iterator[Out]) * stream will see an individual flow of elements (always starting from the * beginning) regardless of when they subscribed. */ -private[scaladsl2] final case class IterableSource[Out](iterable: immutable.Iterable[Out]) extends SimpleActorFlowSource[Out] { +private[scaladsl] final case class IterableSource[Out](iterable: immutable.Iterable[Out]) extends SimpleActorFlowSource[Out] { override def attach(flowSubscriber: Subscriber[Out], materializer: ActorBasedFlowMaterializer, flowName: String) = create(materializer, flowName)._1.subscribe(flowSubscriber) override def isActive: Boolean = true @@ -140,7 +140,7 @@ private[scaladsl2] final case class IterableSource[Out](iterable: immutable.Iter * The stream ends normally when evaluation of the closure returns a `None`. * The stream ends exceptionally when an exception is thrown from the closure. */ -private[scaladsl2] final case class ThunkSource[Out](f: () ⇒ Option[Out]) extends SimpleActorFlowSource[Out] { +private[scaladsl] final case class ThunkSource[Out](f: () ⇒ Option[Out]) extends SimpleActorFlowSource[Out] { override def attach(flowSubscriber: Subscriber[Out], materializer: ActorBasedFlowMaterializer, flowName: String) = create(materializer, flowName)._1.subscribe(flowSubscriber) override def isActive: Boolean = true @@ -158,7 +158,7 @@ private[scaladsl2] final case class ThunkSource[Out](f: () ⇒ Option[Out]) exte * may happen before or after materializing the `Flow`. * The stream terminates with an error if the `Future` is completed with a failure. */ -private[scaladsl2] final case class FutureSource[Out](future: Future[Out]) extends SimpleActorFlowSource[Out] { +private[scaladsl] final case class FutureSource[Out](future: Future[Out]) extends SimpleActorFlowSource[Out] { override def attach(flowSubscriber: Subscriber[Out], materializer: ActorBasedFlowMaterializer, flowName: String) = create(materializer, flowName)._1.subscribe(flowSubscriber) override def isActive: Boolean = true @@ -182,7 +182,7 @@ private[scaladsl2] final case class FutureSource[Out](future: Future[Out]) exten * element is produced it will not receive that tick element later. It will * receive new tick elements as soon as it has requested more elements. */ -private[scaladsl2] final case class TickSource[Out](initialDelay: FiniteDuration, interval: FiniteDuration, tick: () ⇒ Out) extends SimpleActorFlowSource[Out] { +private[scaladsl] final case class TickSource[Out](initialDelay: FiniteDuration, interval: FiniteDuration, tick: () ⇒ Out) extends SimpleActorFlowSource[Out] { override def attach(flowSubscriber: Subscriber[Out], materializer: ActorBasedFlowMaterializer, flowName: String) = create(materializer, flowName)._1.subscribe(flowSubscriber) override def isActive: Boolean = true @@ -196,7 +196,7 @@ private[scaladsl2] final case class TickSource[Out](initialDelay: FiniteDuration * completely, then draining the elements arriving from the second Source. If the first Source is infinite then the * second Source will be never drained. */ -private[scaladsl2] final case class ConcatSource[Out](source1: Source[Out], source2: Source[Out]) extends SimpleActorFlowSource[Out] { +private[scaladsl] final case class ConcatSource[Out](source1: Source[Out], source2: Source[Out]) extends SimpleActorFlowSource[Out] { override def attach(flowSubscriber: Subscriber[Out], materializer: ActorBasedFlowMaterializer, flowName: String) = { val concatter = Concat[Out] @@ -215,7 +215,7 @@ private[scaladsl2] final case class ConcatSource[Out](source1: Source[Out], sour * Creates and wraps an actor into [[org.reactivestreams.Publisher]] from the given `props`, * which should be [[akka.actor.Props]] for an [[akka.stream.actor.ActorPublisher]]. */ -private[scaladsl2] final case class PropsSource[Out](props: Props) extends KeyedActorFlowSource[Out] { +private[scaladsl] final case class PropsSource[Out](props: Props) extends KeyedActorFlowSource[Out] { override type MaterializedType = ActorRef override def attach(flowSubscriber: Subscriber[Out], materializer: ActorBasedFlowMaterializer, flowName: String) = { diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl/Duct.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/Duct.scala deleted file mode 100644 index 8fbc410bb9..0000000000 --- a/akka-stream/src/main/scala/akka/stream/scaladsl/Duct.scala +++ /dev/null @@ -1,370 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream.scaladsl - -import scala.collection.immutable -import scala.util.Try -import org.reactivestreams.{ Publisher, Subscriber } -import akka.stream._ -import akka.stream.impl.DuctImpl -import akka.stream.impl.Ast -import scala.concurrent.duration.FiniteDuration -import scala.concurrent.Future - -object Duct { - - private val empty = DuctImpl[Any, Any](Nil) - - /** - * Create an empty [[Duct]]. The transformation steps are executed by a series - * of [[org.reactivestreams.Processor]] instances that mediate the flow of - * elements downstream and the propagation of back-pressure upstream. - */ - def apply[In]: Duct[In, In] = empty.asInstanceOf[Duct[In, In]] - -} - -/** - * A `Duct` provides the same kind of formulation of stream transformations as a [[Flow]]. - * The difference is that it is not attached to an input source. - * - * The pipeline must be materialized by calling the [[#produceTo]], [[#consume]] or [[#build]] - * methods on it and then attach the `Subscriber` representing the input side of the `Duct` to an - * upstream `Publisher`. - * - * Use [[ImplicitFlowMaterializer]] to define an implicit [[akka.stream.FlowMaterializer]] - * inside an [[akka.actor.Actor]]. - */ -trait Duct[In, +Out] { - /** - * Transform this stream by applying the given function to each of the elements - * as they pass through this processing step. - */ - def map[U](f: Out ⇒ U): Duct[In, U] - - /** - * Transform this stream by applying the given function to each of the elements - * as they pass through this processing step. The function returns a `Future` of the - * element that will be emitted downstream. As many futures as requested elements by - * downstream may run in parallel and may complete in any order, but the elements that - * are emitted downstream are in the same order as from upstream. - */ - def mapFuture[U](f: Out ⇒ Future[U]): Duct[In, U] - - /** - * Only pass on those elements that satisfy the given predicate. - */ - def filter(p: Out ⇒ Boolean): Duct[In, Out] - - /** - * Transform this stream by applying the given partial function to each of the elements - * on which the function is defined as they pass through this processing step. - * Non-matching elements are filtered out. - */ - def collect[U](pf: PartialFunction[Out, U]): Duct[In, U] - - /** - * Invoke the given function for every received element, giving it its previous - * output (or the given `zero` value) and the element as input. The returned stream - * will receive the return value of the final function evaluation when the input - * stream ends. - */ - def fold[U](zero: U)(f: (U, Out) ⇒ U): Duct[In, U] - - /** - * Discard the given number of elements at the beginning of the stream. - * No elements will be dropped if `n` is zero or negative. - */ - def drop(n: Int): Duct[In, Out] - - /** - * Discard the elements received within the given duration at beginning of the stream. - */ - def dropWithin(d: FiniteDuration): Duct[In, Out] - - /** - * Terminate processing (and cancel the upstream publisher) after the given - * number of elements. Due to input buffering some elements may have been - * requested from upstream publishers that will then not be processed downstream - * of this step. - * - * The stream will be completed without producing any elements if `n` is zero - * or negative. - */ - def take(n: Int): Duct[In, Out] - - /** - * Terminate processing (and cancel the upstream publisher) after the given - * duration. Due to input buffering some elements may have been - * requested from upstream publishers that will then not be processed downstream - * of this step. - * - * Note that this can be combined with [[#take]] to limit the number of elements - * within the duration. - */ - def takeWithin(d: FiniteDuration): Duct[In, Out] - - /** - * Chunk up this stream into groups of the given size, with the last group - * possibly smaller than requested due to end-of-stream. - * - * `n` must be positive, otherwise IllegalArgumentException is thrown. - */ - def grouped(n: Int): Duct[In, immutable.Seq[Out]] - - /** - * Chunk up this stream into groups of elements received within a time window, - * or limited by the given number of elements, whatever happens first. - * Empty groups will not be emitted if no elements are received from upstream. - * The last group before end-of-stream will contain the buffered elements - * since the previously emitted group. - * - * `n` must be positive, and `d` must be greater than 0 seconds, otherwise - * IllegalArgumentException is thrown. - */ - def groupedWithin(n: Int, d: FiniteDuration): Duct[In, immutable.Seq[Out]] - - /** - * Transform each input element into a sequence of output elements that is - * then flattened into the output stream. - */ - def mapConcat[U](f: Out ⇒ immutable.Seq[U]): Duct[In, U] - - /** - * Generic transformation of a stream: for each element the [[Transformer#onNext]] - * function is invoked and expecting a (possibly empty) sequence of output elements - * to be produced. - * After handing off the elements produced from one input element to the downstream - * subscribers, the [[Transformer#isComplete]] predicate determines whether to end - * stream processing at this point; in that case the upstream subscription is - * canceled. Before signaling normal completion to the downstream subscribers, - * the [[Transformer#onComplete]] function is invoked to produce a (possibly empty) - * sequence of elements in response to the end-of-stream event. - * - * After normal completion or error the [[Transformer#cleanup]] function is called. - * - * It is possible to keep state in the concrete [[Transformer]] instance with - * ordinary instance variables. The [[Transformer]] is executed by an actor and - * therefore you don not have to add any additional thread safety or memory - * visibility constructs to access the state from the callback methods. - * - * Note that you can use [[#timerTransform]] if you need support for scheduled events in the transformer. - */ - def transform[U](name: String, transformer: () ⇒ Transformer[Out, U]): Duct[In, U] - - /** - * Transformation of a stream, with additional support for scheduled events. - * - * For each element the [[akka.stream.Transformer#onNext]] - * function is invoked, expecting a (possibly empty) sequence of output elements - * to be produced. - * After handing off the elements produced from one input element to the downstream - * subscribers, the [[akka.stream.Transformer#isComplete]] predicate determines whether to end - * stream processing at this point; in that case the upstream subscription is - * canceled. Before signaling normal completion to the downstream subscribers, - * the [[akka.stream.Transformer#onComplete]] function is invoked to produce a (possibly empty) - * sequence of elements in response to the end-of-stream event. - * - * [[akka.stream.Transformer#onError]] is called when failure is signaled from upstream. - * - * After normal completion or error the [[akka.stream.Transformer#cleanup]] function is called. - * - * It is possible to keep state in the concrete [[akka.stream.Transformer]] instance with - * ordinary instance variables. The [[akka.stream.Transformer]] is executed by an actor and - * therefore you do not have to add any additional thread safety or memory - * visibility constructs to access the state from the callback methods. - * - * Note that you can use [[#transform]] if you just need to transform elements time plays no role in the transformation. - */ - def timerTransform[U](name: String, mkTransformer: () ⇒ TimerTransformer[Out, U]): Duct[In, U] - - /** - * Takes up to `n` elements from the stream and returns a pair containing a strict sequence of the taken element - * and a stream representing the remaining elements. If ''n'' is zero or negative, then this will return a pair - * of an empty collection and a stream containing the whole upstream unchanged. - */ - def prefixAndTail[U >: Out](n: Int): Duct[In, (immutable.Seq[Out], Publisher[U])] - - /** - * This operation demultiplexes the incoming stream into separate output - * streams, one for each element key. The key is computed for each element - * using the given function. When a new key is encountered for the first time - * it is emitted to the downstream subscriber together with a fresh - * publisher that will eventually produce all the elements of the substream - * for that key. Not consuming the elements from the created streams will - * stop this processor from processing more elements, therefore you must take - * care to unblock (or cancel) all of the produced streams even if you want - * to consume only one of them. - */ - def groupBy[K, U >: Out](f: Out ⇒ K): Duct[In, (K, Publisher[U])] - - /** - * This operation applies the given predicate to all incoming elements and - * emits them to a stream of output streams, always beginning a new one with - * the current element if the given predicate returns true for it. This means - * that for the following series of predicate values, three substreams will - * be produced with lengths 1, 2, and 3: - * - * {{{ - * false, // element goes into first substream - * true, false, // elements go into second substream - * true, false, false // elements go into third substream - * }}} - */ - def splitWhen[U >: Out](p: Out ⇒ Boolean): Duct[In, Publisher[U]] - - /** - * Merge this stream with the one emitted by the given publisher, taking - * elements as they arrive from either side (picking randomly when both - * have elements ready). - */ - def merge[U >: Out](other: Publisher[_ <: U]): Duct[In, U] - - /** - * Zip this stream together with the one emitted by the given publisher. - * This transformation finishes when either input stream reaches its end, - * cancelling the subscription to the other one. - */ - def zip[U](other: Publisher[U]): Duct[In, (Out, U)] - - /** - * Concatenate the given other stream to this stream so that the first element - * emitted by the given publisher is emitted after the last element of this - * stream. - */ - def concat[U >: Out](next: Publisher[U]): Duct[In, U] - - /** - * Fan-out the stream to another subscriber. Each element is produced to - * the `other` subscriber as well as to downstream subscribers. It will - * not shutdown until the subscriptions for `other` and at least - * one downstream subscriber have been established. - */ - def broadcast(other: Subscriber[_ >: Out]): Duct[In, Out] - - /** - * Transforms a stream of streams into a contiguous stream of elements using the provided flattening strategy. - * This operation can be used on a stream of element type [[Publisher]]. - */ - def flatten[U](strategy: FlattenStrategy[Out, U]): Duct[In, U] - - /** - * Allows a faster upstream to progress independently of a slower subscriber by conflating elements into a summary - * until the subscriber is ready to accept them. For example a conflate step might average incoming numbers if the - * upstream publisher is faster. - * - * This element only rolls up elements if the upstream is faster, but if the downstream is faster it will not - * duplicate elements. - * - * @param seed Provides the first state for a conflated value using the first unconsumed element as a start - * @param aggregate Takes the currently aggregated value and the current pending element to produce a new aggregate - */ - def conflate[S](seed: Out ⇒ S, aggregate: (S, Out) ⇒ S): Duct[In, S] - - /** - * Allows a faster downstream to progress independently of a slower publisher by extrapolating elements from an older - * element until new element comes from the upstream. For example an expand step might repeat the last element for - * the subscriber until it receives an update from upstream. - * - * This element will never "drop" upstream elements as all elements go through at least one extrapolation step. - * This means that if the upstream is actually faster than the upstream it will be backpressured by the downstream - * subscriber. - * - * @param seed Provides the first state for extrapolation using the first unconsumed element - * @param extrapolate Takes the current extrapolation state to produce an output element and the next extrapolation - * state. - */ - def expand[S, U](seed: Out ⇒ S, extrapolate: S ⇒ (U, S)): Duct[In, U] - - /** - * Adds a fixed size buffer in the flow that allows to store elements from a faster upstream until it becomes full. - * Depending on the defined [[OverflowStrategy]] it might drop elements or backpressure the upstream if there is no - * space available - * - * @param size The size of the buffer in element count - * @param overflowStrategy Strategy that is used when incoming elements cannot fit inside the buffer - */ - def buffer(size: Int, overflowStrategy: OverflowStrategy): Duct[In, Out] - - def fanout(initialBufferSize: Int, maximumBufferSize: Int): Duct[In, Out] - - /** - * Append the operations of a [[Duct]] to this `Duct`. - */ - def append[U](duct: Duct[_ >: Out, U]): Duct[In, U] - - /** - * Materialize this `Duct` by attaching it to the specified downstream `subscriber` - * and return a `Subscriber` representing the input side of the `Duct`. - * The returned `Subscriber` can later be connected to an upstream `Publisher`. - * - * *This will materialize the flow and initiate its execution.* - * - * The given `FlowMaterializer` decides how the flow’s logical structure is - * broken down into individual processing steps. - */ - def produceTo[U >: Out](subscriber: Subscriber[U])(implicit materializer: FlowMaterializer): Subscriber[In] - - /** - * Attaches a subscriber to this stream which will just discard all received - * elements. The returned `Subscriber` represents the input side of the `Duct` and can - * later be connected to an upstream `Publisher`. - * - * *This will materialize the flow and initiate its execution.* - * - * The given `FlowMaterializer` decides how the flow’s logical structure is - * broken down into individual processing steps. - */ - def consume()(implicit materializer: FlowMaterializer): Subscriber[In] - - /** - * When this flow is completed, either through an error or normal - * completion, apply the provided function with [[scala.util.Success]] - * or [[scala.util.Failure]]. The returned `Subscriber` represents the input side of - * the `Duct` and can later be connected to an upstream `Publisher`. - * - * *This operation materializes the flow and initiates its execution.* - */ - def onComplete(callback: Try[Unit] ⇒ Unit)(implicit materializer: FlowMaterializer): Subscriber[In] - - /** - * Materialize this `Duct` into a `Subscriber` representing the input side of the `Duct` - * and a `Publisher`representing the output side of the the `Duct`. - * - * The returned `Publisher` can later be connected to an downstream `Subscriber`. - * The returned `Subscriber` can later be connected to an upstream `Publisher`. - * - * *This will materialize the flow and initiate its execution.* - * - * The given `FlowMaterializer` decides how the flow’s logical structure is - * broken down into individual processing steps. - */ - def build[U >: Out]()(implicit materializer: FlowMaterializer): (Subscriber[In], Publisher[U]) - - /** - * Invoke the given procedure for each received element. - * Returns a tuple of a `Subscriber` and a `Future`. - * - * The returned `Subscriber` represents the input side of the `Duct` and can - * later be connected to an upstream `Publisher`. - * - * The returned [[scala.concurrent.Future]] will be completed with `Success` when - * reaching the normal end of the stream, or completed - * with `Failure` if there is an error is signaled in the stream. - * - * *This will materialize the flow and initiate its execution.* - * - * The given `FlowMaterializer` decides how the flow’s logical structure is - * broken down into individual processing steps. - */ - def foreach(c: Out ⇒ Unit)(implicit materializer: FlowMaterializer): (Subscriber[In], Future[Unit]) - - /** - * INTERNAL API - * Used by `Flow.append(duct)`. - */ - private[akka] def ops: immutable.Seq[Ast.AstNode] - -} - diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/FlexiMerge.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/FlexiMerge.scala similarity index 97% rename from akka-stream/src/main/scala/akka/stream/scaladsl2/FlexiMerge.scala rename to akka-stream/src/main/scala/akka/stream/scaladsl/FlexiMerge.scala index c4dce58cf8..adf366d316 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/FlexiMerge.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/FlexiMerge.scala @@ -1,10 +1,10 @@ /** * Copyright (C) 2009-2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import scala.collection.immutable -import akka.stream.impl2.Ast +import akka.stream.impl.Ast object FlexiMerge { @@ -205,10 +205,10 @@ abstract class FlexiMerge[Out](val name: Option[String]) { override private[akka] val astNode = Ast.FlexiMergeNode(FlexiMerge.this.asInstanceOf[FlexiMerge[Any]]) override def name = vertexName - final override private[scaladsl2] def newInstance() = new FlexiMergeVertex(None) + final override private[scaladsl] def newInstance() = new FlexiMergeVertex(None) } - private[scaladsl2] val vertex: FlowGraphInternal.InternalVertex = new FlexiMergeVertex(name) + private[scaladsl] val vertex: FlowGraphInternal.InternalVertex = new FlexiMergeVertex(name) /** * Output port of the `FlexiMerge` junction. A [[Sink]] can be connected to this output 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 12770b6ce1..13a2e86248 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/Flow.scala @@ -3,116 +3,127 @@ */ package akka.stream.scaladsl +import akka.stream.impl.Ast._ +import akka.stream.{ TimerTransformer, Transformer, OverflowStrategy } +import akka.util.Collections.EmptyImmutableSeq import scala.collection.immutable +import scala.concurrent.duration.{ Duration, FiniteDuration } import scala.concurrent.Future -import scala.util.Try -import org.reactivestreams.{ Publisher, Subscriber } -import akka.stream._ -import akka.stream.impl.Ast.{ ExistingPublisher, IterablePublisherNode, IteratorPublisherNode, ThunkPublisherNode } -import akka.stream.impl.Ast.FuturePublisherNode -import akka.stream.impl.FlowImpl -import akka.stream.impl.Ast.TickPublisherNode -import scala.concurrent.duration.FiniteDuration -import scala.concurrent.duration.FiniteDuration -import akka.stream.impl.Stop +import scala.language.higherKinds +import akka.stream.FlowMaterializer +import akka.stream.FlattenStrategy /** - * Scala API + * A `Flow` is a set of stream processing steps that has one open input and one open output. */ +trait Flow[-In, +Out] extends FlowOps[Out] { + override type Repr[+O] <: Flow[In, O] + + /** + * Transform this flow by appending the given processing steps. + */ + def connect[T](flow: Flow[Out, T]): Flow[In, T] + + /** + * Connect this flow to a sink, concatenating the processing steps of both. + */ + def connect(sink: Sink[Out]): Sink[In] + + /** + * + * 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 [[SubscriberSource]] and + * and `Publisher` of a [[PublisherSink]]. + */ + def runWith(source: KeyedSource[In], sink: KeyedSink[Out])(implicit materializer: FlowMaterializer): (source.MaterializedType, sink.MaterializedType) = { + val m = source.connect(this).connect(sink).run() + (m.get(source), m.get(sink)) + } + + /** + * Connect the `Source` to this `Flow` and then connect it to the `Sink` and run it. + * + * The returned value will contain the materialized value of the `KeyedSink`, e.g. `Publisher` of a [[PublisherSink]]. + */ + def runWith(source: Source[In], sink: KeyedSink[Out])(implicit materializer: FlowMaterializer): sink.MaterializedType = + source.connect(this).runWith(sink) + + /** + * Connect the `Source` to this `Flow` and then connect it to the `Sink` and run it. + * + * The returned value will contain the materialized value of the `SourceWithKey`, e.g. `Subscriber` of a [[SubscriberSource]]. + */ + def runWith(source: KeyedSource[In], sink: Sink[Out])(implicit materializer: FlowMaterializer): source.MaterializedType = + source.connect(this).connect(sink).run().get(source) + + /** + * Connect the `Source` to this `Flow` and then connect it to the `Sink` and run it. + * + * As both `Source` and `Sink` are "simple", no value is returned from this `runWith` overload. + */ + def runWith(source: Source[In], sink: Sink[Out])(implicit materializer: FlowMaterializer): Unit = + source.connect(this).connect(sink).run() +} + object Flow { /** - * Construct a transformation of the given publisher. The transformation steps - * are executed by a series of [[org.reactivestreams.Processor]] instances - * that mediate the flow of elements downstream and the propagation of - * back-pressure upstream. + * Helper to create `Flow` without a [[Source]] or a [[Sink]]. + * Example usage: `Flow[Int]` */ - def apply[T](publisher: Publisher[T]): Flow[T] = FlowImpl(ExistingPublisher(publisher), Nil) + def apply[T]: Flow[T, T] = Pipe.empty[T] /** - * Start a new `Flow` from the given Iterator. The produced stream of elements - * will continue until the iterator runs empty or fails during evaluation of - * the `next()` method. Elements are pulled out of the iterator - * in accordance with the demand coming from the downstream transformation - * steps. + * Creates a `Flow` by using an empty [[FlowGraphBuilder]] on a block that expects a [[FlowGraphBuilder]] and + * returns the `UndefinedSource` and `UndefinedSink`. */ - def apply[T](iterator: Iterator[T]): Flow[T] = FlowImpl(IteratorPublisherNode(iterator), Nil) + def apply[I, O]()(block: FlowGraphBuilder ⇒ (UndefinedSource[I], UndefinedSink[O])): Flow[I, O] = + createFlowFromBuilder(new FlowGraphBuilder(), block) /** - * Start a new `Flow` from the given Iterable. This is like starting from an - * Iterator, but every Subscriber directly attached to the Publisher of this - * stream will see an individual flow of elements (always starting from the - * beginning) regardless of when they subscribed. + * Creates a `Flow` by using a [[FlowGraphBuilder]] from this [[PartialFlowGraph]] on a block that expects + * a [[FlowGraphBuilder]] and returns the `UndefinedSource` and `UndefinedSink`. */ - def apply[T](iterable: immutable.Iterable[T]): Flow[T] = FlowImpl(IterablePublisherNode(iterable), Nil) + def apply[I, O](graph: PartialFlowGraph)(block: FlowGraphBuilder ⇒ (UndefinedSource[I], UndefinedSink[O])): Flow[I, O] = + createFlowFromBuilder(new FlowGraphBuilder(graph.graph), block) - /** - * Define the sequence of elements to be produced by the given closure. - * The stream ends normally when evaluation of the `Callable` returns a `None`. - * The stream ends exceptionally when an exception is thrown from the `Callable`. - */ - def apply[T](f: () ⇒ Option[T]): Flow[T] = - FlowImpl(ThunkPublisherNode(() ⇒ f() match { - case Some(t) ⇒ t - case _ ⇒ throw Stop - }), Nil) - - /** - * Start a new `Flow` from the given `Future`. The stream will consist of - * one element when the `Future` is completed with a successful value, which - * may happen before or after materializing the `Flow`. - * The stream terminates with an error if the `Future` is completed with a failure. - */ - def apply[T](future: Future[T]): Flow[T] = FlowImpl(FuturePublisherNode(future), Nil) - - /** - * Elements are produced from the tick closure periodically with the specified interval. - * The tick element will be delivered to downstream consumers that has requested any elements. - * If a consumer has not requested any elements at the point in time when the tick - * element is produced it will not receive that tick element later. It will - * receive new tick elements as soon as it has requested more elements. - */ - def apply[T](initialDelay: FiniteDuration, interval: FiniteDuration, tick: () ⇒ T): Flow[T] = FlowImpl(TickPublisherNode(initialDelay, interval, tick), Nil) + private def createFlowFromBuilder[I, O](builder: FlowGraphBuilder, + block: FlowGraphBuilder ⇒ (UndefinedSource[I], UndefinedSink[O])): Flow[I, O] = { + val (in, out) = block(builder) + builder.partialBuild().toFlow(in, out) + } } /** - * Scala API: The Flow DSL allows the formulation of stream transformations based on some - * input. The starting point can be a collection, an iterator, a block of code - * which is evaluated repeatedly or a [[org.reactivestreams.Publisher]]. - * - * See Reactive Streams for details. - * - * Each DSL element produces a new Flow that can be further transformed, building - * up a description of the complete transformation pipeline. In order to execute - * this pipeline the Flow must be materialized by calling the [[#toFuture]], [[#consume]], - * [[#onComplete]], or [[#toPublisher]] methods on it. - * - * It should be noted that the streams modeled by this library are “hot”, - * meaning that they asynchronously flow through a series of processors without - * detailed control by the user. In particular it is not predictable how many - * elements a given transformation step might buffer before handing elements - * downstream, which means that transformation functions may be invoked more - * often than for corresponding transformations on strict collections like - * [[List]]. *An important consequence* is that elements that were produced - * into a stream may be discarded by later processors, e.g. when using the - * [[#take]] combinator. - * - * By default every operation is executed within its own [[akka.actor.Actor]] - * to enable full pipelining of the chained set of computations. This behavior - * is determined by the [[akka.stream.FlowMaterializer]] which is required - * by those methods that materialize the Flow into a series of - * [[org.reactivestreams.Processor]] instances. The returned reactive stream - * is fully started and active. - * - * Use [[ImplicitFlowMaterializer]] to define an implicit [[akka.stream.FlowMaterializer]] - * inside an [[akka.actor.Actor]]. + * Flow with attached input and output, can be executed. */ -trait Flow[+T] { +trait RunnableFlow { + def run()(implicit materializer: FlowMaterializer): MaterializedMap +} + +/** + * Scala API: Operations offered by Flows and Sources with a free output side: the DSL flows left-to-right only. + */ +trait FlowOps[+Out] { + import FlowOps._ + type Repr[+O] /** * Transform this stream by applying the given function to each of the elements * as they pass through this processing step. */ - def map[U](f: T ⇒ U): Flow[U] + def map[T](f: Out ⇒ T): Repr[T] = + transform("map", () ⇒ new Transformer[Out, T] { + def onNext(in: Out) = List(f(in)) + }) + + /** + * Transform each input element into a sequence of output elements that is + * then flattened into the output stream. + */ + def mapConcat[T](f: Out ⇒ immutable.Seq[T]): Repr[T] = + transform("mapConcat", () ⇒ new Transformer[Out, T] { + def onNext(in: Out) = f(in) + }) /** * Transform this stream by applying the given function to each of the elements @@ -120,61 +131,42 @@ trait Flow[+T] { * element that will be emitted downstream. As many futures as requested elements by * downstream may run in parallel and may complete in any order, but the elements that * are emitted downstream are in the same order as from upstream. + * + * @see [[#mapAsyncUnordered]] */ - def mapFuture[U](f: T ⇒ Future[U]): Flow[U] + def mapAsync[T](f: Out ⇒ Future[T]): Repr[T] = + andThen(MapAsync(f.asInstanceOf[Any ⇒ Future[Any]])) + + /** + * Transform this stream by applying the given function to each of the elements + * as they pass through this processing step. The function returns a `Future` of the + * element that will be emitted downstream. As many futures as requested elements by + * downstream may run in parallel and each processed element will be emitted dowstream + * as soon as it is ready, i.e. it is possible that the elements are not emitted downstream + * in the same order as from upstream. + * + * @see [[#mapAsync]] + */ + def mapAsyncUnordered[T](f: Out ⇒ Future[T]): Repr[T] = + andThen(MapAsyncUnordered(f.asInstanceOf[Any ⇒ Future[Any]])) /** * Only pass on those elements that satisfy the given predicate. */ - def filter(p: T ⇒ Boolean): Flow[T] + def filter(p: Out ⇒ Boolean): Repr[Out] = + transform("filter", () ⇒ new Transformer[Out, Out] { + def onNext(in: Out) = if (p(in)) List(in) else Nil + }) /** * Transform this stream by applying the given partial function to each of the elements * on which the function is defined as they pass through this processing step. * Non-matching elements are filtered out. */ - def collect[U](pf: PartialFunction[T, U]): Flow[U] - - /** - * Invoke the given function for every received element, giving it its previous - * output (or the given `zero` value) and the element as input. The returned stream - * will receive the return value of the final function evaluation when the input - * stream ends. - */ - def fold[U](zero: U)(f: (U, T) ⇒ U): Flow[U] - - /** - * Discard the given number of elements at the beginning of the stream. - * No elements will be dropped if `n` is zero or negative. - */ - def drop(n: Int): Flow[T] - - /** - * Discard the elements received within the given duration at beginning of the stream. - */ - def dropWithin(d: FiniteDuration): Flow[T] - - /** - * Terminate processing (and cancel the upstream publisher) after the given - * number of elements. Due to input buffering some elements may have been - * requested from upstream publishers that will then not be processed downstream - * of this step. - * - * The stream will be completed without producing any elements if `n` is zero - * or negative. - */ - def take(n: Int): Flow[T] - - /** - * Terminate processing (and cancel the upstream publisher) after the given - * duration. Due to input buffering some elements may have been - * requested from upstream publishers that will then not be processed downstream - * of this step. - * - * Note that this can be combined with [[#take]] to limit the number of elements - * within the duration. - */ - def takeWithin(d: FiniteDuration): Flow[T] + def collect[T](pf: PartialFunction[Out, T]): Repr[T] = + transform("collect", () ⇒ new Transformer[Out, T] { + def onNext(in: Out) = if (pf.isDefinedAt(in)) List(pf(in)) else Nil + }) /** * Chunk up this stream into groups of the given size, with the last group @@ -182,7 +174,22 @@ trait Flow[+T] { * * `n` must be positive, otherwise IllegalArgumentException is thrown. */ - def grouped(n: Int): Flow[immutable.Seq[T]] + def grouped(n: Int): Repr[immutable.Seq[Out]] = { + require(n > 0, "n must be greater than 0") + transform("grouped", () ⇒ new Transformer[Out, immutable.Seq[Out]] { + var buf: Vector[Out] = Vector.empty + def onNext(in: Out) = { + buf :+= in + if (buf.size == n) { + val group = buf + buf = Vector.empty + List(group) + } else + Nil + } + override def onTermination(e: Option[Throwable]) = if (buf.isEmpty) Nil else List(buf) + }) + } /** * Chunk up this stream into groups of elements received within a time window, @@ -194,13 +201,165 @@ trait Flow[+T] { * `n` must be positive, and `d` must be greater than 0 seconds, otherwise * IllegalArgumentException is thrown. */ - def groupedWithin(n: Int, d: FiniteDuration): Flow[immutable.Seq[T]] + def groupedWithin(n: Int, d: FiniteDuration): Repr[immutable.Seq[Out]] = { + require(n > 0, "n must be greater than 0") + require(d > Duration.Zero) + timerTransform("groupedWithin", () ⇒ new TimerTransformer[Out, immutable.Seq[Out]] { + schedulePeriodically(GroupedWithinTimerKey, d) + var buf: Vector[Out] = Vector.empty + + def onNext(in: Out) = { + buf :+= in + if (buf.size == n) { + // start new time window + schedulePeriodically(GroupedWithinTimerKey, d) + emitGroup() + } else Nil + } + override def onTermination(e: Option[Throwable]) = if (buf.isEmpty) Nil else List(buf) + def onTimer(timerKey: Any) = emitGroup() + private def emitGroup(): immutable.Seq[immutable.Seq[Out]] = + if (buf.isEmpty) EmptyImmutableSeq + else { + val group = buf + buf = Vector.empty + List(group) + } + }) + } /** - * Transform each input element into a sequence of output elements that is - * then flattened into the output stream. + * Discard the given number of elements at the beginning of the stream. + * No elements will be dropped if `n` is zero or negative. */ - def mapConcat[U](f: T ⇒ immutable.Seq[U]): Flow[U] + def drop(n: Int): Repr[Out] = + transform("drop", () ⇒ new Transformer[Out, Out] { + var delegate: Transformer[Out, Out] = + if (n <= 0) identityTransformer.asInstanceOf[Transformer[Out, Out]] + else new Transformer[Out, Out] { + var c = n + def onNext(in: Out) = { + c -= 1 + if (c == 0) + delegate = identityTransformer.asInstanceOf[Transformer[Out, Out]] + Nil + } + } + + def onNext(in: Out) = delegate.onNext(in) + }) + + /** + * Discard the elements received within the given duration at beginning of the stream. + */ + def dropWithin(d: FiniteDuration): Repr[Out] = + timerTransform("dropWithin", () ⇒ new TimerTransformer[Out, Out] { + scheduleOnce(DropWithinTimerKey, d) + + var delegate: Transformer[Out, Out] = + new Transformer[Out, Out] { + def onNext(in: Out) = Nil + } + + def onNext(in: Out) = delegate.onNext(in) + def onTimer(timerKey: Any) = { + delegate = identityTransformer.asInstanceOf[Transformer[Out, Out]] + Nil + } + }) + + /** + * Terminate processing (and cancel the upstream publisher) after the given + * number of elements. Due to input buffering some elements may have been + * requested from upstream publishers that will then not be processed downstream + * of this step. + * + * The stream will be completed without producing any elements if `n` is zero + * or negative. + */ + def take(n: Int): Repr[Out] = + transform("take", () ⇒ new Transformer[Out, Out] { + var delegate: Transformer[Out, Out] = + if (n <= 0) takeCompletedTransformer.asInstanceOf[Transformer[Out, Out]] + else new Transformer[Out, Out] { + var c = n + def onNext(in: Out) = { + c -= 1 + if (c == 0) + delegate = takeCompletedTransformer.asInstanceOf[Transformer[Out, Out]] + List(in) + } + } + + def onNext(in: Out) = delegate.onNext(in) + override def isComplete = delegate.isComplete + }) + + /** + * Terminate processing (and cancel the upstream publisher) after the given + * duration. Due to input buffering some elements may have been + * requested from upstream publishers that will then not be processed downstream + * of this step. + * + * Note that this can be combined with [[#take]] to limit the number of elements + * within the duration. + */ + def takeWithin(d: FiniteDuration): Repr[Out] = + timerTransform("takeWithin", () ⇒ new TimerTransformer[Out, Out] { + scheduleOnce(TakeWithinTimerKey, d) + + var delegate: Transformer[Out, Out] = identityTransformer.asInstanceOf[Transformer[Out, Out]] + + def onNext(in: Out) = delegate.onNext(in) + override def isComplete = delegate.isComplete + def onTimer(timerKey: Any) = { + delegate = takeCompletedTransformer.asInstanceOf[Transformer[Out, Out]] + Nil + } + }) + + /** + * Allows a faster upstream to progress independently of a slower subscriber by conflating elements into a summary + * until the subscriber is ready to accept them. For example a conflate step might average incoming numbers if the + * upstream publisher is faster. + * + * This element only rolls up elements if the upstream is faster, but if the downstream is faster it will not + * duplicate elements. + * + * @param seed Provides the first state for a conflated value using the first unconsumed element as a start + * @param aggregate Takes the currently aggregated value and the current pending element to produce a new aggregate + */ + def conflate[S](seed: Out ⇒ S, aggregate: (S, Out) ⇒ S): Repr[S] = + andThen(Conflate(seed.asInstanceOf[Any ⇒ Any], aggregate.asInstanceOf[(Any, Any) ⇒ Any])) + + /** + * Allows a faster downstream to progress independently of a slower publisher by extrapolating elements from an older + * element until new element comes from the upstream. For example an expand step might repeat the last element for + * the subscriber until it receives an update from upstream. + * + * This element will never "drop" upstream elements as all elements go through at least one extrapolation step. + * This means that if the upstream is actually faster than the upstream it will be backpressured by the downstream + * subscriber. + * + * @param seed Provides the first state for extrapolation using the first unconsumed element + * @param extrapolate Takes the current extrapolation state to produce an output element and the next extrapolation + * state. + */ + def expand[S, U](seed: Out ⇒ S, extrapolate: S ⇒ (U, S)): Repr[U] = + andThen(Expand(seed.asInstanceOf[Any ⇒ Any], extrapolate.asInstanceOf[Any ⇒ (Any, Any)])) + + /** + * Adds a fixed size buffer in the flow that allows to store elements from a faster upstream until it becomes full. + * Depending on the defined [[OverflowStrategy]] it might drop elements or backpressure the upstream if there is no + * space available + * + * @param size The size of the buffer in element count + * @param overflowStrategy Strategy that is used when incoming elements cannot fit inside the buffer + */ + def buffer(size: Int, overflowStrategy: OverflowStrategy): Repr[Out] = { + require(size > 0, s"Buffer size must be larger than zero but was [$size]") + andThen(Buffer(size, overflowStrategy)) + } /** * Generic transformation of a stream: for each element the [[akka.stream.Transformer#onNext]] @@ -224,7 +383,58 @@ trait Flow[+T] { * * Note that you can use [[#timerTransform]] if you need support for scheduled events in the transformer. */ - def transform[U](name: String, mkTransformer: () ⇒ Transformer[T, U]): Flow[U] + def transform[T](name: String, mkTransformer: () ⇒ Transformer[Out, T]): Repr[T] = { + andThen(Transform(name, mkTransformer.asInstanceOf[() ⇒ Transformer[Any, Any]])) + } + + /** + * Takes up to `n` elements from the stream and returns a pair containing a strict sequence of the taken element + * and a stream representing the remaining elements. If ''n'' is zero or negative, then this will return a pair + * of an empty collection and a stream containing the whole upstream unchanged. + */ + def prefixAndTail[U >: Out](n: Int): Repr[(immutable.Seq[Out], Source[U])] = + andThen(PrefixAndTail(n)) + + /** + * This operation demultiplexes the incoming stream into separate output + * streams, one for each element key. The key is computed for each element + * using the given function. When a new key is encountered for the first time + * it is emitted to the downstream subscriber together with a fresh + * flow that will eventually produce all the elements of the substream + * for that key. Not consuming the elements from the created streams will + * stop this processor from processing more elements, therefore you must take + * care to unblock (or cancel) all of the produced streams even if you want + * to consume only one of them. + */ + def groupBy[K, U >: Out](f: Out ⇒ K): Repr[(K, Source[U])] = + andThen(GroupBy(f.asInstanceOf[Any ⇒ Any])) + + /** + * This operation applies the given predicate to all incoming elements and + * emits them to a stream of output streams, always beginning a new one with + * the current element if the given predicate returns true for it. This means + * that for the following series of predicate values, three substreams will + * be produced with lengths 1, 2, and 3: + * + * {{{ + * false, // element goes into first substream + * true, false, // elements go into second substream + * true, false, false // elements go into third substream + * }}} + */ + def splitWhen[U >: Out](p: Out ⇒ Boolean): Repr[Source[U]] = + andThen(SplitWhen(p.asInstanceOf[Any ⇒ Boolean])) + + /** + * Transforms a stream of streams into a contiguous stream of elements using the provided flattening strategy. + * This operation can be used on a stream of element type [[Source]]. + */ + def flatten[U](strategy: akka.stream.FlattenStrategy[Out, U]): Repr[U] = strategy match { + case _: FlattenStrategy.Concat[Out] ⇒ andThen(ConcatAll) + case _: FlattenStrategy.Concat[Out] ⇒ andThen(ConcatAll) // TODO remove duality here? + case _ ⇒ + throw new IllegalArgumentException(s"Unsupported flattening strategy [${strategy.getClass.getName}]") + } /** * Transformation of a stream, with additional support for scheduled events. @@ -250,187 +460,29 @@ trait Flow[+T] { * * Note that you can use [[#transform]] if you just need to transform elements time plays no role in the transformation. */ - def timerTransform[U](name: String, mkTransformer: () ⇒ TimerTransformer[T, U]): Flow[U] - - /** - * Takes up to `n` elements from the stream and returns a pair containing a strict sequence of the taken element - * and a stream representing the remaining elements. If ''n'' is zero or negative, then this will return a pair - * of an empty collection and a stream containing the whole upstream unchanged. - */ - def prefixAndTail[U >: T](n: Int): Flow[(immutable.Seq[T], Publisher[U])] - - /** - * This operation demultiplexes the incoming stream into separate output - * streams, one for each element key. The key is computed for each element - * using the given function. When a new key is encountered for the first time - * it is emitted to the downstream subscriber together with a fresh - * publisher that will eventually produce all the elements of the substream - * for that key. Not consuming the elements from the created streams will - * stop this processor from processing more elements, therefore you must take - * care to unblock (or cancel) all of the produced streams even if you want - * to consume only one of them. - */ - def groupBy[K, U >: T](f: T ⇒ K): Flow[(K, Publisher[U])] - - /** - * This operation applies the given predicate to all incoming elements and - * emits them to a stream of output streams, always beginning a new one with - * the current element if the given predicate returns true for it. This means - * that for the following series of predicate values, three substreams will - * be produced with lengths 1, 2, and 3: - * - * {{{ - * false, // element goes into first substream - * true, false, // elements go into second substream - * true, false, false // elements go into third substream - * }}} - */ - def splitWhen[U >: T](p: T ⇒ Boolean): Flow[Publisher[U]] - - /** - * Merge this stream with the one emitted by the given publisher, taking - * elements as they arrive from either side (picking randomly when both - * have elements ready). - */ - def merge[U >: T](other: Publisher[_ <: U]): Flow[U] - - /** - * Zip this stream together with the one emitted by the given publisher. - * This transformation finishes when either input stream reaches its end, - * cancelling the subscription to the other one. - */ - def zip[U](other: Publisher[U]): Flow[(T, U)] - - /** - * Concatenate the given other stream to this stream so that the first element - * emitted by the given publisher is emitted after the last element of this - * stream. - */ - def concat[U >: T](next: Publisher[U]): Flow[U] - - /** - * Fan-out the stream to another subscriber. Each element is produced to - * the `other` subscriber as well as to downstream subscribers. It will - * not shutdown until the subscriptions for `other` and at least - * one downstream subscriber have been established. - */ - def broadcast(other: Subscriber[_ >: T]): Flow[T] - - /** - * Transforms a stream of streams into a contiguous stream of elements using the provided flattening strategy. - * This operation can be used on a stream of element type [[Publisher]]. - */ - def flatten[U](strategy: FlattenStrategy[T, U]): Flow[U] - - /** - * Allows a faster upstream to progress independently of a slower subscriber by conflating elements into a summary - * until the subscriber is ready to accept them. For example a conflate step might average incoming numbers if the - * upstream publisher is faster. - * - * This element only rolls up elements if the upstream is faster, but if the downstream is faster it will not - * duplicate elements. - * - * @param seed Provides the first state for a conflated value using the first unconsumed element as a start - * @param aggregate Takes the currently aggregated value and the current pending element to produce a new aggregate - */ - def conflate[S](seed: T ⇒ S, aggregate: (S, T) ⇒ S): Flow[S] - - /** - * Allows a faster downstream to progress independently of a slower publisher by extrapolating elements from an older - * element until new element comes from the upstream. For example an expand step might repeat the last element for - * the subscriber until it receives an update from upstream. - * - * This element will never "drop" upstream elements as all elements go through at least one extrapolation step. - * This means that if the upstream is actually faster than the upstream it will be backpressured by the downstream - * subscriber. - * - * @param seed Provides the first state for extrapolation using the first unconsumed element - * @param extrapolate Takes the current extrapolation state to produce an output element and the next extrapolation - * state. - */ - def expand[S, U](seed: T ⇒ S, extrapolate: S ⇒ (U, S)): Flow[U] - - /** - * Adds a fixed size buffer in the flow that allows to store elements from a faster upstream until it becomes full. - * Depending on the defined [[OverflowStrategy]] it might drop elements or backpressure the upstream if there is no - * space available - * - * @param size The size of the buffer in element count - * @param overflowStrategy Strategy that is used when incoming elements cannot fit inside the buffer - */ - def buffer(size: Int, overflowStrategy: OverflowStrategy): Flow[T] - - def fanout(initialBufferSize: Int, maximumBufferSize: Int): Flow[T] - - /** - * Append the operations of a [[Duct]] to this flow. - */ - def append[U](duct: Duct[_ >: T, U]): Flow[U] - - /** - * Returns a [[scala.concurrent.Future]] that will be fulfilled with the first - * thing that is signaled to this stream, which can be either an element (after - * which the upstream subscription is canceled), an error condition (putting - * the Future into the corresponding failed state) or the end-of-stream - * (failing the Future with a NoSuchElementException). *This operation - * materializes the flow and initiates its execution.* - * - * The given `FlowMaterializer` decides how the flow’s logical structure is - * broken down into individual processing steps. - */ - def toFuture()(implicit materializer: FlowMaterializer): Future[T] - - /** - * Attaches a subscriber to this stream which will just discard all received - * elements. *This will materialize the flow and initiate its execution.* - * - * The given `FlowMaterializer` decides how the flow’s logical structure is - * broken down into individual processing steps. - */ - def consume()(implicit materializer: FlowMaterializer): Unit - - /** - * When this flow is completed, either through an error or normal - * completion, apply the provided function with [[scala.util.Success]] - * or [[scala.util.Failure]]. - * - * *This operation materializes the flow and initiates its execution.* - */ - def onComplete(callback: Try[Unit] ⇒ Unit)(implicit materializer: FlowMaterializer): Unit - - /** - * Materialize this flow and return the downstream-most - * [[org.reactivestreams.Publisher]] interface. The stream will not have - * any subscribers attached at this point, which means that after prefetching - * elements to fill the internal buffers it will assert back-pressure until - * a subscriber connects and creates demand for elements to be emitted. - * - * The given `FlowMaterializer` decides how the flow’s logical structure is - * broken down into individual processing steps. - */ - def toPublisher[U >: T]()(implicit materializer: FlowMaterializer): Publisher[U] - - /** - * Attaches a subscriber to this stream. - * - * *This will materialize the flow and initiate its execution.* - * - * The given `FlowMaterializer` decides how the flow’s logical structure is - * broken down into individual processing steps. - */ - def produceTo(subscriber: Subscriber[_ >: T])(implicit materializer: FlowMaterializer): Unit - - /** - * Invoke the given procedure for each received element. Returns a [[scala.concurrent.Future]] - * that will be completed with `Success` when reaching the normal end of the stream, or completed - * with `Failure` if there is an error is signaled in the stream. - * - * *This will materialize the flow and initiate its execution.* - * - * The given `FlowMaterializer` decides how the flow’s logical structure is - * broken down into individual processing steps. - */ - def foreach(c: T ⇒ Unit)(implicit materializer: FlowMaterializer): Future[Unit] + def timerTransform[U](name: String, mkTransformer: () ⇒ TimerTransformer[Out, U]): Repr[U] = + andThen(TimerTransform(name, mkTransformer.asInstanceOf[() ⇒ TimerTransformer[Any, Any]])) + /** INTERNAL API */ + // Storing ops in reverse order + private[scaladsl] def andThen[U](op: AstNode): Repr[U] +} + +/** + * INTERNAL API + */ +private[scaladsl] object FlowOps { + private case object TakeWithinTimerKey + private case object DropWithinTimerKey + private case object GroupedWithinTimerKey + + private val takeCompletedTransformer: Transformer[Any, Any] = new Transformer[Any, Any] { + override def onNext(elem: Any) = Nil + override def isComplete = true + } + + private val identityTransformer: Transformer[Any, Any] = new Transformer[Any, Any] { + override def onNext(elem: Any) = List(elem) + } } diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/FlowGraph.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/FlowGraph.scala similarity index 97% rename from akka-stream/src/main/scala/akka/stream/scaladsl2/FlowGraph.scala rename to akka-stream/src/main/scala/akka/stream/scaladsl/FlowGraph.scala index c21dd80d44..d09f62ada7 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/FlowGraph.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/FlowGraph.scala @@ -1,19 +1,17 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 - -import akka.stream.impl2 -import akka.stream.impl2.Ast.FanInAstNode -import impl2.Ast +package akka.stream.scaladsl +import akka.stream.impl.Ast.FanInAstNode +import akka.stream.impl.Ast import scala.language.existentials import scalax.collection.edge.{ LkBase, LkDiEdge } import scalax.collection.mutable.Graph import scalax.collection.immutable.{ Graph ⇒ ImmutableGraph } import org.reactivestreams.Subscriber import org.reactivestreams.Publisher -import akka.stream.impl2.Ast +import akka.stream.FlowMaterializer /** * Fan-in and fan-out vertices in the [[FlowGraph]] implements @@ -89,7 +87,7 @@ final class Merge[T](override val name: Option[String]) extends FlowGraphInterna override private[akka] def astNode = Ast.Merge - final override private[scaladsl2] def newInstance() = new Merge[T](None) + final override private[scaladsl] def newInstance() = new Merge[T](None) } object MergePreferred { @@ -138,7 +136,7 @@ final class MergePreferred[T](override val name: Option[String]) extends FlowGra override private[akka] def astNode = Ast.MergePreferred - final override private[scaladsl2] def newInstance() = new MergePreferred[T](None) + final override private[scaladsl] def newInstance() = new MergePreferred[T](None) } object Broadcast { @@ -172,7 +170,7 @@ final class Broadcast[T](override val name: Option[String]) extends FlowGraphInt override private[akka] def astNode = Ast.Broadcast - final override private[scaladsl2] def newInstance() = new Broadcast[T](None) + final override private[scaladsl] def newInstance() = new Broadcast[T](None) } object Balance { @@ -206,7 +204,7 @@ final class Balance[T](override val name: Option[String]) extends FlowGraphInter override private[akka] def astNode = Ast.Balance - final override private[scaladsl2] def newInstance() = new Balance[T](None) + final override private[scaladsl] def newInstance() = new Balance[T](None) } object Zip { @@ -245,6 +243,8 @@ object Zip { * longer than the other, its remaining elements are ignored. */ private[akka] class Zip[A, B](override val name: Option[String]) extends FlowGraphInternal.InternalVertex { + import akka.stream.impl.Zip.AsScalaTuple2 + val left = new Zip.Left(this) val right = new Zip.Right(this) val out = new Zip.Out(this) @@ -254,9 +254,9 @@ private[akka] class Zip[A, B](override val name: Option[String]) extends FlowGra override def minimumOutputCount: Int = 1 override def maximumOutputCount: Int = 1 - override private[akka] def astNode: FanInAstNode = Ast.Zip(impl2.Zip.AsScalaTuple2) + override private[akka] def astNode: FanInAstNode = Ast.Zip(AsScalaTuple2) - final override private[scaladsl2] def newInstance() = new Zip[A, B](name = None) + final override private[scaladsl] def newInstance() = new Zip[A, B](name = None) } object Unzip { @@ -304,7 +304,7 @@ final class Unzip[A, B](override val name: Option[String]) extends FlowGraphInte override private[akka] def astNode = Ast.Unzip - final override private[scaladsl2] def newInstance() = new Unzip[A, B](name = None) + final override private[scaladsl] def newInstance() = new Unzip[A, B](name = None) } object Concat { @@ -354,7 +354,7 @@ final class Concat[T](override val name: Option[String]) extends FlowGraphIntern override private[akka] def astNode = Ast.Concat - final override private[scaladsl2] def newInstance() = new Concat[T](name = None) + final override private[scaladsl] def newInstance() = new Concat[T](name = None) } object UndefinedSink { @@ -387,7 +387,7 @@ final class UndefinedSink[-T](override val name: Option[String]) extends FlowGra override private[akka] def astNode = throw new UnsupportedOperationException("Undefined sinks cannot be materialized") - final override private[scaladsl2] def newInstance() = new UndefinedSink[T](name = None) + final override private[scaladsl] def newInstance() = new UndefinedSink[T](name = None) } object UndefinedSource { @@ -419,7 +419,7 @@ final class UndefinedSource[+T](override val name: Option[String]) extends FlowG override private[akka] def astNode = throw new UnsupportedOperationException("Undefined sources cannot be materialized") - final override private[scaladsl2] def newInstance() = new UndefinedSource[T](name = None) + final override private[scaladsl] def newInstance() = new UndefinedSource[T](name = None) } /** @@ -450,7 +450,7 @@ private[akka] object FlowGraphInternal { sealed trait Vertex { // must return a new instance that is uniquely identifiable (i.e. no name for hashCode or equality) - private[scaladsl2] def newInstance(): Vertex + private[scaladsl] def newInstance(): Vertex } case class SourceVertex(source: Source[_]) extends Vertex { @@ -459,7 +459,7 @@ private[akka] object FlowGraphInternal { final override def equals(other: Any): Boolean = super.equals(other) final override def hashCode: Int = super.hashCode - final override private[scaladsl2] def newInstance() = this.copy() + final override private[scaladsl] def newInstance() = this.copy() } case class SinkVertex(sink: Sink[_]) extends Vertex { @@ -468,7 +468,7 @@ private[akka] object FlowGraphInternal { final override def equals(other: Any): Boolean = super.equals(other) final override def hashCode: Int = super.hashCode - final override private[scaladsl2] def newInstance() = this.copy() + final override private[scaladsl] def newInstance() = this.copy() } trait InternalVertex extends Vertex { @@ -517,7 +517,7 @@ private[akka] object FlowGraphInternal { } object FlowGraphBuilder { - private[scaladsl2] def apply[T](partialFlowGraph: PartialFlowGraph)(block: FlowGraphBuilder ⇒ T): T = { + private[scaladsl] def apply[T](partialFlowGraph: PartialFlowGraph)(block: FlowGraphBuilder ⇒ T): T = { val builder = new FlowGraphBuilder(partialFlowGraph.graph) block(builder) } @@ -851,7 +851,7 @@ class FlowGraphBuilder private (graph: Graph[FlowGraphInternal.Vertex, FlowGraph addGraphEdge(edge.from.value, edge.to.value, edge.label.pipe, edge.label.inputPort, edge.label.outputPort) } - private[scaladsl2] def remapPartialFlowGraph(partialFlowGraph: PartialFlowGraph, vertexMapping: Map[Vertex, Vertex]): this.type = { + private[scaladsl] def remapPartialFlowGraph(partialFlowGraph: PartialFlowGraph, vertexMapping: Map[Vertex, Vertex]): this.type = { val mapping = collection.mutable.Map.empty[Vertex, Vertex] ++ vertexMapping def get(vertex: Vertex): Vertex = mapping.getOrElseUpdate(vertex, vertex.newInstance()) @@ -1271,7 +1271,7 @@ class PartialFlowGraph private[akka] (private[akka] val graph: ImmutableGraph[Fl * Returned by [[FlowGraph#run]] and can be used to retrieve the materialized * `Source` inputs or `Sink` outputs. */ -private[scaladsl2] class MaterializedFlowGraph(materializedSources: Map[KeyedSource[_], Any], materializedSinks: Map[KeyedSink[_], Any]) +private[scaladsl] class MaterializedFlowGraph(materializedSources: Map[KeyedSource[_], Any], materializedSinks: Map[KeyedSink[_], Any]) extends MaterializedMap { override def get(key: KeyedSource[_]): key.MaterializedType = diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/GraphFlow.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/GraphFlow.scala similarity index 63% rename from akka-stream/src/main/scala/akka/stream/scaladsl2/GraphFlow.scala rename to akka-stream/src/main/scala/akka/stream/scaladsl/GraphFlow.scala index f090b3be83..7bfcf01290 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/GraphFlow.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/GraphFlow.scala @@ -1,32 +1,32 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl -import akka.stream.impl2.Ast.AstNode +import akka.stream.impl.Ast.AstNode import scala.annotation.unchecked.uncheckedVariance -private[scaladsl2] case class GraphFlow[-In, CIn, COut, +Out](inPipe: Pipe[In, CIn], in: UndefinedSource[CIn], graph: PartialFlowGraph, out: UndefinedSink[COut], outPipe: Pipe[COut, Out]) extends Flow[In, Out] { +private[scaladsl] case class GraphFlow[-In, CIn, COut, +Out](inPipe: Pipe[In, CIn], in: UndefinedSource[CIn], graph: PartialFlowGraph, out: UndefinedSink[COut], outPipe: Pipe[COut, Out]) extends Flow[In, Out] { override type Repr[+O] = GraphFlow[In @uncheckedVariance, CIn, COut, O] - private[scaladsl2] def prepend[T](pipe: Pipe[T, In]): GraphFlow[T, CIn, COut, Out] = copy(inPipe = pipe.appendPipe(inPipe)) + private[scaladsl] def prepend[T](pipe: Pipe[T, In]): GraphFlow[T, CIn, COut, Out] = copy(inPipe = pipe.appendPipe(inPipe)) - private[scaladsl2] def prepend(pipe: SourcePipe[In]): GraphSource[COut, Out] = { + private[scaladsl] def prepend(pipe: SourcePipe[In]): GraphSource[COut, Out] = { val newGraph = PartialFlowGraph(graph) { b ⇒ b.attachSource(in, pipe.appendPipe(inPipe)) } GraphSource(newGraph, out, outPipe) } - private[scaladsl2] def remap(builder: FlowGraphBuilder): (UndefinedSource[CIn], UndefinedSink[COut]) = { + private[scaladsl] def remap(builder: FlowGraphBuilder): (UndefinedSource[CIn], UndefinedSink[COut]) = { val nIn = UndefinedSource[CIn] val nOut = UndefinedSink[COut] builder.remapPartialFlowGraph(graph, Map(in -> nIn, out -> nOut)) (nIn, nOut) } - private[scaladsl2] def importAndConnect(builder: FlowGraphBuilder, oOut: UndefinedSink[In @uncheckedVariance], oIn: UndefinedSource[Out @uncheckedVariance]): Unit = { + private[scaladsl] def importAndConnect(builder: FlowGraphBuilder, oOut: UndefinedSink[In @uncheckedVariance], oIn: UndefinedSource[Out @uncheckedVariance]): Unit = { val (nIn, nOut) = remap(builder) builder.connect(oOut, inPipe, nIn) builder.connect(nOut, outPipe, oIn) @@ -58,19 +58,19 @@ private[scaladsl2] case class GraphFlow[-In, CIn, COut, +Out](inPipe: Pipe[In, C case sink: Sink[Out] ⇒ connect(Pipe.empty.withSink(sink)) // recursive, but now it is a SinkPipe } - override private[scaladsl2] def andThen[T](op: AstNode): Repr[T] = copy(outPipe = outPipe.andThen(op)) + override private[scaladsl] def andThen[T](op: AstNode): Repr[T] = copy(outPipe = outPipe.andThen(op)) } -private[scaladsl2] case class GraphSource[COut, +Out](graph: PartialFlowGraph, out: UndefinedSink[COut], outPipe: Pipe[COut, Out]) extends Source[Out] { +private[scaladsl] case class GraphSource[COut, +Out](graph: PartialFlowGraph, out: UndefinedSink[COut], outPipe: Pipe[COut, Out]) extends Source[Out] { override type Repr[+O] = GraphSource[COut, O] - private[scaladsl2] def remap(builder: FlowGraphBuilder): UndefinedSink[COut] = { + private[scaladsl] def remap(builder: FlowGraphBuilder): UndefinedSink[COut] = { val nOut = UndefinedSink[COut] builder.remapPartialFlowGraph(graph, Map(out -> nOut)) nOut } - private[scaladsl2] def importAndConnect(builder: FlowGraphBuilder, oIn: UndefinedSource[Out @uncheckedVariance]): Unit = { + private[scaladsl] def importAndConnect(builder: FlowGraphBuilder, oIn: UndefinedSource[Out @uncheckedVariance]): Unit = { val nOut = remap(builder) builder.connect(nOut, outPipe, oIn) } @@ -100,28 +100,28 @@ private[scaladsl2] case class GraphSource[COut, +Out](graph: PartialFlowGraph, o connect(Pipe.empty.withSink(sink)) // recursive, but now it is a SinkPipe } - override private[scaladsl2] def andThen[T](op: AstNode): Repr[T] = copy(outPipe = outPipe.andThen(op)) + override private[scaladsl] def andThen[T](op: AstNode): Repr[T] = copy(outPipe = outPipe.andThen(op)) } -private[scaladsl2] case class GraphSink[-In, CIn](inPipe: Pipe[In, CIn], in: UndefinedSource[CIn], graph: PartialFlowGraph) extends Sink[In] { +private[scaladsl] case class GraphSink[-In, CIn](inPipe: Pipe[In, CIn], in: UndefinedSource[CIn], graph: PartialFlowGraph) extends Sink[In] { - private[scaladsl2] def remap(builder: FlowGraphBuilder): UndefinedSource[CIn] = { + private[scaladsl] def remap(builder: FlowGraphBuilder): UndefinedSource[CIn] = { val nIn = UndefinedSource[CIn] builder.remapPartialFlowGraph(graph, Map(in -> nIn)) nIn } - private[scaladsl2] def prepend(pipe: SourcePipe[In]): FlowGraph = { + private[scaladsl] def prepend(pipe: SourcePipe[In]): FlowGraph = { FlowGraph(this.graph) { b ⇒ b.attachSource(in, pipe.connect(inPipe)) } } - private[scaladsl2] def prepend[T](pipe: Pipe[T, In]): GraphSink[T, CIn] = { + private[scaladsl] def prepend[T](pipe: Pipe[T, In]): GraphSink[T, CIn] = { GraphSink(pipe.appendPipe(inPipe), in, graph) } - private[scaladsl2] def importAndConnect(builder: FlowGraphBuilder, oOut: UndefinedSink[In @uncheckedVariance]): Unit = { + private[scaladsl] def importAndConnect(builder: FlowGraphBuilder, oOut: UndefinedSink[In @uncheckedVariance]): Unit = { val nIn = remap(builder) builder.connect(oOut, inPipe, nIn) } diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl/ImplicitFlowMaterializer.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/ImplicitFlowMaterializer.scala index 97c0efc6da..5bfda089fd 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl/ImplicitFlowMaterializer.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/ImplicitFlowMaterializer.scala @@ -4,8 +4,8 @@ package akka.stream.scaladsl import akka.actor.Actor -import akka.stream.FlowMaterializer import akka.stream.MaterializerSettings +import akka.stream.FlowMaterializer /** * Mix this trait into your [[akka.actor.Actor]] if you need an implicit diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/JavaConverters.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/JavaConverters.scala similarity index 69% rename from akka-stream/src/main/scala/akka/stream/scaladsl2/JavaConverters.scala rename to akka-stream/src/main/scala/akka/stream/scaladsl/JavaConverters.scala index c189fac4cc..3c39312cb3 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/JavaConverters.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/JavaConverters.scala @@ -1,49 +1,49 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import akka.stream.javadsl -import akka.stream.scaladsl2 +import akka.stream.scaladsl /** * Implicit converters allowing to convert between Java and Scala DSL elements. */ private[akka] object JavaConverters { - implicit final class AddAsJavaSource[Out](val source: scaladsl2.Source[Out]) extends AnyVal { + implicit final class AddAsJavaSource[Out](val source: scaladsl.Source[Out]) extends AnyVal { def asJava: javadsl.Source[Out] = new javadsl.Source(source) } - implicit final class AddAsJavaUndefinedSource[Out](val source: scaladsl2.UndefinedSource[Out]) extends AnyVal { + implicit final class AddAsJavaUndefinedSource[Out](val source: scaladsl.UndefinedSource[Out]) extends AnyVal { def asJava: javadsl.UndefinedSource[Out] = new javadsl.UndefinedSource(source) } - implicit final class AddAsJavaFlow[In, Out](val flow: scaladsl2.Flow[In, Out]) extends AnyVal { + implicit final class AddAsJavaFlow[In, Out](val flow: scaladsl.Flow[In, Out]) extends AnyVal { def asJava: javadsl.Flow[In, Out] = new javadsl.Flow[In, Out](flow) } - implicit final class AddAsJavaSink[In](val sink: scaladsl2.Sink[In]) extends AnyVal { + implicit final class AddAsJavaSink[In](val sink: scaladsl.Sink[In]) extends AnyVal { def asJava: javadsl.Sink[In] = new javadsl.Sink[In](sink) } - implicit final class AddAsJavaUndefinedSink[Out](val sink: scaladsl2.UndefinedSink[Out]) extends AnyVal { + implicit final class AddAsJavaUndefinedSink[Out](val sink: scaladsl.UndefinedSink[Out]) extends AnyVal { def asJava: javadsl.UndefinedSink[Out] = new javadsl.UndefinedSink(sink) } - implicit final class AsAsJavaFlowGraphBuilder[Out](val builder: scaladsl2.FlowGraphBuilder) extends AnyVal { + implicit final class AsAsJavaFlowGraphBuilder[Out](val builder: scaladsl.FlowGraphBuilder) extends AnyVal { def asJava: javadsl.FlowGraphBuilder = new javadsl.FlowGraphBuilder(builder) } implicit final class AddAsScalaSource[Out](val source: javadsl.Source[Out]) extends AnyVal { - def asScala: scaladsl2.Source[Out] = source.asInstanceOf[javadsl.Source[Out]].asScala + def asScala: scaladsl.Source[Out] = source.asInstanceOf[javadsl.Source[Out]].asScala } implicit final class AsAsScalaUndefinedSource[Out](val source: javadsl.UndefinedSource[Out]) extends AnyVal { - def asScala: scaladsl2.UndefinedSource[Out] = source.asScala + def asScala: scaladsl.UndefinedSource[Out] = source.asScala } implicit final class AddAsScalaFlow[In, Out](val flow: javadsl.Flow[In, Out]) extends AnyVal { - def asScala: scaladsl2.Flow[In, Out] = flow.asInstanceOf[javadsl.Flow[In, Out]].asScala + def asScala: scaladsl.Flow[In, Out] = flow.asInstanceOf[javadsl.Flow[In, Out]].asScala } implicit final class AddAsScalaSink[In](val sink: javadsl.Sink[In]) extends AnyVal { - def asScala: scaladsl2.Sink[In] = sink.asInstanceOf[javadsl.Sink[In]].asScala + def asScala: scaladsl.Sink[In] = sink.asInstanceOf[javadsl.Sink[In]].asScala } implicit final class AsAsScalaUndefinedSink[Out](val sink: javadsl.UndefinedSink[Out]) extends AnyVal { - def asScala: scaladsl2.UndefinedSink[Out] = sink.asScala + def asScala: scaladsl.UndefinedSink[Out] = sink.asScala } implicit final class AsAsScalaFlowGraphBuilder[Out](val builder: javadsl.FlowGraphBuilder) extends AnyVal { def asScala: FlowGraphBuilder = builder.asScala diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/MaterializedMap.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/MaterializedMap.scala similarity index 95% rename from akka-stream/src/main/scala/akka/stream/scaladsl2/MaterializedMap.scala rename to akka-stream/src/main/scala/akka/stream/scaladsl/MaterializedMap.scala index 352c6ea0fa..59e731795d 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/MaterializedMap.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/MaterializedMap.scala @@ -1,7 +1,7 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl /** * Returned by [[RunnableFlow#run]] and [[FlowGraph#run]] and can be used to retrieve the materialized diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/Pipe.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/Pipe.scala similarity index 92% rename from akka-stream/src/main/scala/akka/stream/scaladsl2/Pipe.scala rename to akka-stream/src/main/scala/akka/stream/scaladsl/Pipe.scala index ac4da8368a..6932c3eeb1 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/Pipe.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/Pipe.scala @@ -1,12 +1,12 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 - -import akka.stream.impl2.Ast.AstNode +package akka.stream.scaladsl +import akka.stream.impl.Ast.AstNode import scala.annotation.unchecked.uncheckedVariance import scala.language.{ existentials, higherKinds } +import akka.stream.FlowMaterializer private[stream] object Pipe { private val emptyInstance = Pipe[Any, Any](ops = Nil) @@ -19,7 +19,7 @@ private[stream] object Pipe { private[stream] final case class Pipe[-In, +Out](ops: List[AstNode]) extends Flow[In, Out] { override type Repr[+O] = Pipe[In @uncheckedVariance, O] - override private[scaladsl2] def andThen[U](op: AstNode): Repr[U] = this.copy(ops = op :: ops) + override private[scaladsl] def andThen[U](op: AstNode): Repr[U] = this.copy(ops = op :: ops) private[stream] def withSink(out: Sink[Out]): SinkPipe[In] = SinkPipe(out, ops) @@ -59,7 +59,7 @@ private[stream] final case class SinkPipe[-In](output: Sink[_], ops: List[AstNod private[stream] final case class SourcePipe[+Out](input: Source[_], ops: List[AstNode]) extends Source[Out] { override type Repr[+O] = SourcePipe[O] - override private[scaladsl2] def andThen[U](op: AstNode): Repr[U] = SourcePipe(input, op :: ops) + override private[scaladsl] def andThen[U](op: AstNode): Repr[U] = SourcePipe(input, op :: ops) private[stream] def withSink(out: Sink[Out]): RunnablePipe = RunnablePipe(input, out, ops) diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/Sink.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/Sink.scala similarity index 98% rename from akka-stream/src/main/scala/akka/stream/scaladsl2/Sink.scala rename to akka-stream/src/main/scala/akka/stream/scaladsl/Sink.scala index b30ab41653..7441a0f4f0 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/Sink.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/Sink.scala @@ -1,11 +1,12 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import akka.actor.Props import org.reactivestreams.Subscriber import scala.util.Try +import akka.stream.FlowMaterializer /** * A `Sink` is a set of stream processing steps that has one open input and an attached output. diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/Source.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala similarity index 99% rename from akka-stream/src/main/scala/akka/stream/scaladsl2/Source.scala rename to akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala index cdfef4b65f..e9e6e80ae4 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/Source.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/Source.scala @@ -1,7 +1,7 @@ /** * Copyright (C) 2014 Typesafe Inc. */ -package akka.stream.scaladsl2 +package akka.stream.scaladsl import akka.actor.Props import akka.stream.impl.{ EmptyPublisher, ErrorPublisher, SynchronousPublisherFromIterable } @@ -9,8 +9,8 @@ import org.reactivestreams.Publisher import scala.collection.immutable import scala.concurrent.duration.FiniteDuration import scala.concurrent.Future - import scala.language.higherKinds +import akka.stream.FlowMaterializer /** * A `Source` is a set of stream processing steps that has one open output and an attached input. diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/package.scala b/akka-stream/src/main/scala/akka/stream/scaladsl/package.scala similarity index 99% rename from akka-stream/src/main/scala/akka/stream/scaladsl2/package.scala rename to akka-stream/src/main/scala/akka/stream/scaladsl/package.scala index b8654a43d3..2baa7fa1aa 100644 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/package.scala +++ b/akka-stream/src/main/scala/akka/stream/scaladsl/package.scala @@ -51,5 +51,5 @@ package akka.stream * Use [[ImplicitFlowMaterializer]] to define an implicit [[akka.stream.FlowMaterializer]] * inside an [[akka.actor.Actor]]. */ -package object scaladsl2 { +package object scaladsl { } diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/FlattenStrategy.scala b/akka-stream/src/main/scala/akka/stream/scaladsl2/FlattenStrategy.scala deleted file mode 100644 index f35e533b7d..0000000000 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/FlattenStrategy.scala +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Copyright (C) 2009-2014 Typesafe Inc. - */ -package akka.stream.scaladsl2 - -import akka.stream.scaladsl2 -import akka.stream.FlattenStrategy - -object FlattenStrategy { - - /** - * Strategy that flattens a stream of streams by concatenating them. This means taking an incoming stream - * emitting its elements directly to the output until it completes and then taking the next stream. This has the - * consequence that if one of the input stream is infinite, no other streams after that will be consumed from. - */ - def concat[T]: FlattenStrategy[scaladsl2.Source[T], T] = Concat[T]() - - private[akka] case class Concat[T]() extends FlattenStrategy[scaladsl2.Source[T], T] -} diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/Flow.scala b/akka-stream/src/main/scala/akka/stream/scaladsl2/Flow.scala deleted file mode 100644 index 7a4402b764..0000000000 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/Flow.scala +++ /dev/null @@ -1,486 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream.scaladsl2 - -import akka.stream.impl2.Ast._ -import akka.stream.{ TimerTransformer, Transformer, OverflowStrategy } -import akka.util.Collections.EmptyImmutableSeq -import scala.collection.immutable -import scala.concurrent.duration.{ Duration, FiniteDuration } -import scala.concurrent.Future - -import scala.language.higherKinds - -/** - * A `Flow` is a set of stream processing steps that has one open input and one open output. - */ -trait Flow[-In, +Out] extends FlowOps[Out] { - override type Repr[+O] <: Flow[In, O] - - /** - * Transform this flow by appending the given processing steps. - */ - def connect[T](flow: Flow[Out, T]): Flow[In, T] - - /** - * Connect this flow to a sink, concatenating the processing steps of both. - */ - def connect(sink: Sink[Out]): Sink[In] - - /** - * - * 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 [[SubscriberSource]] and - * and `Publisher` of a [[PublisherSink]]. - */ - def runWith(source: KeyedSource[In], sink: KeyedSink[Out])(implicit materializer: FlowMaterializer): (source.MaterializedType, sink.MaterializedType) = { - val m = source.connect(this).connect(sink).run() - (m.get(source), m.get(sink)) - } - - /** - * Connect the `Source` to this `Flow` and then connect it to the `Sink` and run it. - * - * The returned value will contain the materialized value of the `KeyedSink`, e.g. `Publisher` of a [[PublisherSink]]. - */ - def runWith(source: Source[In], sink: KeyedSink[Out])(implicit materializer: FlowMaterializer): sink.MaterializedType = - source.connect(this).runWith(sink) - - /** - * Connect the `Source` to this `Flow` and then connect it to the `Sink` and run it. - * - * The returned value will contain the materialized value of the `SourceWithKey`, e.g. `Subscriber` of a [[SubscriberSource]]. - */ - def runWith(source: KeyedSource[In], sink: Sink[Out])(implicit materializer: FlowMaterializer): source.MaterializedType = - source.connect(this).connect(sink).run().get(source) - - /** - * Connect the `Source` to this `Flow` and then connect it to the `Sink` and run it. - * - * As both `Source` and `Sink` are "simple", no value is returned from this `runWith` overload. - */ - def runWith(source: Source[In], sink: Sink[Out])(implicit materializer: FlowMaterializer): Unit = - source.connect(this).connect(sink).run() -} - -object Flow { - /** - * Helper to create `Flow` without a [[Source]] or a [[Sink]]. - * Example usage: `Flow[Int]` - */ - def apply[T]: Flow[T, T] = Pipe.empty[T] - - /** - * Creates a `Flow` by using an empty [[FlowGraphBuilder]] on a block that expects a [[FlowGraphBuilder]] and - * returns the `UndefinedSource` and `UndefinedSink`. - */ - def apply[I, O]()(block: FlowGraphBuilder ⇒ (UndefinedSource[I], UndefinedSink[O])): Flow[I, O] = - createFlowFromBuilder(new FlowGraphBuilder(), block) - - /** - * Creates a `Flow` by using a [[FlowGraphBuilder]] from this [[PartialFlowGraph]] on a block that expects - * a [[FlowGraphBuilder]] and returns the `UndefinedSource` and `UndefinedSink`. - */ - def apply[I, O](graph: PartialFlowGraph)(block: FlowGraphBuilder ⇒ (UndefinedSource[I], UndefinedSink[O])): Flow[I, O] = - createFlowFromBuilder(new FlowGraphBuilder(graph.graph), block) - - private def createFlowFromBuilder[I, O](builder: FlowGraphBuilder, - block: FlowGraphBuilder ⇒ (UndefinedSource[I], UndefinedSink[O])): Flow[I, O] = { - val (in, out) = block(builder) - builder.partialBuild().toFlow(in, out) - } -} - -/** - * Flow with attached input and output, can be executed. - */ -trait RunnableFlow { - def run()(implicit materializer: FlowMaterializer): MaterializedMap -} - -/** - * Scala API: Operations offered by Flows and Sources with a free output side: the DSL flows left-to-right only. - */ -trait FlowOps[+Out] { - import FlowOps._ - type Repr[+O] - - /** - * Transform this stream by applying the given function to each of the elements - * as they pass through this processing step. - */ - def map[T](f: Out ⇒ T): Repr[T] = - transform("map", () ⇒ new Transformer[Out, T] { - def onNext(in: Out) = List(f(in)) - }) - - /** - * Transform each input element into a sequence of output elements that is - * then flattened into the output stream. - */ - def mapConcat[T](f: Out ⇒ immutable.Seq[T]): Repr[T] = - transform("mapConcat", () ⇒ new Transformer[Out, T] { - def onNext(in: Out) = f(in) - }) - - /** - * Transform this stream by applying the given function to each of the elements - * as they pass through this processing step. The function returns a `Future` of the - * element that will be emitted downstream. As many futures as requested elements by - * downstream may run in parallel and may complete in any order, but the elements that - * are emitted downstream are in the same order as from upstream. - * - * @see [[#mapAsyncUnordered]] - */ - def mapAsync[T](f: Out ⇒ Future[T]): Repr[T] = - andThen(MapAsync(f.asInstanceOf[Any ⇒ Future[Any]])) - - /** - * Transform this stream by applying the given function to each of the elements - * as they pass through this processing step. The function returns a `Future` of the - * element that will be emitted downstream. As many futures as requested elements by - * downstream may run in parallel and each processed element will be emitted dowstream - * as soon as it is ready, i.e. it is possible that the elements are not emitted downstream - * in the same order as from upstream. - * - * @see [[#mapAsync]] - */ - def mapAsyncUnordered[T](f: Out ⇒ Future[T]): Repr[T] = - andThen(MapAsyncUnordered(f.asInstanceOf[Any ⇒ Future[Any]])) - - /** - * Only pass on those elements that satisfy the given predicate. - */ - def filter(p: Out ⇒ Boolean): Repr[Out] = - transform("filter", () ⇒ new Transformer[Out, Out] { - def onNext(in: Out) = if (p(in)) List(in) else Nil - }) - - /** - * Transform this stream by applying the given partial function to each of the elements - * on which the function is defined as they pass through this processing step. - * Non-matching elements are filtered out. - */ - def collect[T](pf: PartialFunction[Out, T]): Repr[T] = - transform("collect", () ⇒ new Transformer[Out, T] { - def onNext(in: Out) = if (pf.isDefinedAt(in)) List(pf(in)) else Nil - }) - - /** - * Chunk up this stream into groups of the given size, with the last group - * possibly smaller than requested due to end-of-stream. - * - * `n` must be positive, otherwise IllegalArgumentException is thrown. - */ - def grouped(n: Int): Repr[immutable.Seq[Out]] = { - require(n > 0, "n must be greater than 0") - transform("grouped", () ⇒ new Transformer[Out, immutable.Seq[Out]] { - var buf: Vector[Out] = Vector.empty - def onNext(in: Out) = { - buf :+= in - if (buf.size == n) { - val group = buf - buf = Vector.empty - List(group) - } else - Nil - } - override def onTermination(e: Option[Throwable]) = if (buf.isEmpty) Nil else List(buf) - }) - } - - /** - * Chunk up this stream into groups of elements received within a time window, - * or limited by the given number of elements, whatever happens first. - * Empty groups will not be emitted if no elements are received from upstream. - * The last group before end-of-stream will contain the buffered elements - * since the previously emitted group. - * - * `n` must be positive, and `d` must be greater than 0 seconds, otherwise - * IllegalArgumentException is thrown. - */ - def groupedWithin(n: Int, d: FiniteDuration): Repr[immutable.Seq[Out]] = { - require(n > 0, "n must be greater than 0") - require(d > Duration.Zero) - timerTransform("groupedWithin", () ⇒ new TimerTransformer[Out, immutable.Seq[Out]] { - schedulePeriodically(GroupedWithinTimerKey, d) - var buf: Vector[Out] = Vector.empty - - def onNext(in: Out) = { - buf :+= in - if (buf.size == n) { - // start new time window - schedulePeriodically(GroupedWithinTimerKey, d) - emitGroup() - } else Nil - } - override def onTermination(e: Option[Throwable]) = if (buf.isEmpty) Nil else List(buf) - def onTimer(timerKey: Any) = emitGroup() - private def emitGroup(): immutable.Seq[immutable.Seq[Out]] = - if (buf.isEmpty) EmptyImmutableSeq - else { - val group = buf - buf = Vector.empty - List(group) - } - }) - } - - /** - * Discard the given number of elements at the beginning of the stream. - * No elements will be dropped if `n` is zero or negative. - */ - def drop(n: Int): Repr[Out] = - transform("drop", () ⇒ new Transformer[Out, Out] { - var delegate: Transformer[Out, Out] = - if (n <= 0) identityTransformer.asInstanceOf[Transformer[Out, Out]] - else new Transformer[Out, Out] { - var c = n - def onNext(in: Out) = { - c -= 1 - if (c == 0) - delegate = identityTransformer.asInstanceOf[Transformer[Out, Out]] - Nil - } - } - - def onNext(in: Out) = delegate.onNext(in) - }) - - /** - * Discard the elements received within the given duration at beginning of the stream. - */ - def dropWithin(d: FiniteDuration): Repr[Out] = - timerTransform("dropWithin", () ⇒ new TimerTransformer[Out, Out] { - scheduleOnce(DropWithinTimerKey, d) - - var delegate: Transformer[Out, Out] = - new Transformer[Out, Out] { - def onNext(in: Out) = Nil - } - - def onNext(in: Out) = delegate.onNext(in) - def onTimer(timerKey: Any) = { - delegate = identityTransformer.asInstanceOf[Transformer[Out, Out]] - Nil - } - }) - - /** - * Terminate processing (and cancel the upstream publisher) after the given - * number of elements. Due to input buffering some elements may have been - * requested from upstream publishers that will then not be processed downstream - * of this step. - * - * The stream will be completed without producing any elements if `n` is zero - * or negative. - */ - def take(n: Int): Repr[Out] = - transform("take", () ⇒ new Transformer[Out, Out] { - var delegate: Transformer[Out, Out] = - if (n <= 0) takeCompletedTransformer.asInstanceOf[Transformer[Out, Out]] - else new Transformer[Out, Out] { - var c = n - def onNext(in: Out) = { - c -= 1 - if (c == 0) - delegate = takeCompletedTransformer.asInstanceOf[Transformer[Out, Out]] - List(in) - } - } - - def onNext(in: Out) = delegate.onNext(in) - override def isComplete = delegate.isComplete - }) - - /** - * Terminate processing (and cancel the upstream publisher) after the given - * duration. Due to input buffering some elements may have been - * requested from upstream publishers that will then not be processed downstream - * of this step. - * - * Note that this can be combined with [[#take]] to limit the number of elements - * within the duration. - */ - def takeWithin(d: FiniteDuration): Repr[Out] = - timerTransform("takeWithin", () ⇒ new TimerTransformer[Out, Out] { - scheduleOnce(TakeWithinTimerKey, d) - - var delegate: Transformer[Out, Out] = identityTransformer.asInstanceOf[Transformer[Out, Out]] - - def onNext(in: Out) = delegate.onNext(in) - override def isComplete = delegate.isComplete - def onTimer(timerKey: Any) = { - delegate = takeCompletedTransformer.asInstanceOf[Transformer[Out, Out]] - Nil - } - }) - - /** - * Allows a faster upstream to progress independently of a slower subscriber by conflating elements into a summary - * until the subscriber is ready to accept them. For example a conflate step might average incoming numbers if the - * upstream publisher is faster. - * - * This element only rolls up elements if the upstream is faster, but if the downstream is faster it will not - * duplicate elements. - * - * @param seed Provides the first state for a conflated value using the first unconsumed element as a start - * @param aggregate Takes the currently aggregated value and the current pending element to produce a new aggregate - */ - def conflate[S](seed: Out ⇒ S, aggregate: (S, Out) ⇒ S): Repr[S] = - andThen(Conflate(seed.asInstanceOf[Any ⇒ Any], aggregate.asInstanceOf[(Any, Any) ⇒ Any])) - - /** - * Allows a faster downstream to progress independently of a slower publisher by extrapolating elements from an older - * element until new element comes from the upstream. For example an expand step might repeat the last element for - * the subscriber until it receives an update from upstream. - * - * This element will never "drop" upstream elements as all elements go through at least one extrapolation step. - * This means that if the upstream is actually faster than the upstream it will be backpressured by the downstream - * subscriber. - * - * @param seed Provides the first state for extrapolation using the first unconsumed element - * @param extrapolate Takes the current extrapolation state to produce an output element and the next extrapolation - * state. - */ - def expand[S, U](seed: Out ⇒ S, extrapolate: S ⇒ (U, S)): Repr[U] = - andThen(Expand(seed.asInstanceOf[Any ⇒ Any], extrapolate.asInstanceOf[Any ⇒ (Any, Any)])) - - /** - * Adds a fixed size buffer in the flow that allows to store elements from a faster upstream until it becomes full. - * Depending on the defined [[OverflowStrategy]] it might drop elements or backpressure the upstream if there is no - * space available - * - * @param size The size of the buffer in element count - * @param overflowStrategy Strategy that is used when incoming elements cannot fit inside the buffer - */ - def buffer(size: Int, overflowStrategy: OverflowStrategy): Repr[Out] = { - require(size > 0, s"Buffer size must be larger than zero but was [$size]") - andThen(Buffer(size, overflowStrategy)) - } - - /** - * Generic transformation of a stream: for each element the [[akka.stream.Transformer#onNext]] - * function is invoked, expecting a (possibly empty) sequence of output elements - * to be produced. - * After handing off the elements produced from one input element to the downstream - * subscribers, the [[akka.stream.Transformer#isComplete]] predicate determines whether to end - * stream processing at this point; in that case the upstream subscription is - * canceled. Before signaling normal completion to the downstream subscribers, - * the [[akka.stream.Transformer#onComplete]] function is invoked to produce a (possibly empty) - * sequence of elements in response to the end-of-stream event. - * - * [[akka.stream.Transformer#onError]] is called when failure is signaled from upstream. - * - * After normal completion or error the [[akka.stream.Transformer#cleanup]] function is called. - * - * It is possible to keep state in the concrete [[akka.stream.Transformer]] instance with - * ordinary instance variables. The [[akka.stream.Transformer]] is executed by an actor and - * therefore you do not have to add any additional thread safety or memory - * visibility constructs to access the state from the callback methods. - * - * Note that you can use [[#timerTransform]] if you need support for scheduled events in the transformer. - */ - def transform[T](name: String, mkTransformer: () ⇒ Transformer[Out, T]): Repr[T] = { - andThen(Transform(name, mkTransformer.asInstanceOf[() ⇒ Transformer[Any, Any]])) - } - - /** - * Takes up to `n` elements from the stream and returns a pair containing a strict sequence of the taken element - * and a stream representing the remaining elements. If ''n'' is zero or negative, then this will return a pair - * of an empty collection and a stream containing the whole upstream unchanged. - */ - def prefixAndTail[U >: Out](n: Int): Repr[(immutable.Seq[Out], Source[U])] = - andThen(PrefixAndTail(n)) - - /** - * This operation demultiplexes the incoming stream into separate output - * streams, one for each element key. The key is computed for each element - * using the given function. When a new key is encountered for the first time - * it is emitted to the downstream subscriber together with a fresh - * flow that will eventually produce all the elements of the substream - * for that key. Not consuming the elements from the created streams will - * stop this processor from processing more elements, therefore you must take - * care to unblock (or cancel) all of the produced streams even if you want - * to consume only one of them. - */ - def groupBy[K, U >: Out](f: Out ⇒ K): Repr[(K, Source[U])] = - andThen(GroupBy(f.asInstanceOf[Any ⇒ Any])) - - /** - * This operation applies the given predicate to all incoming elements and - * emits them to a stream of output streams, always beginning a new one with - * the current element if the given predicate returns true for it. This means - * that for the following series of predicate values, three substreams will - * be produced with lengths 1, 2, and 3: - * - * {{{ - * false, // element goes into first substream - * true, false, // elements go into second substream - * true, false, false // elements go into third substream - * }}} - */ - def splitWhen[U >: Out](p: Out ⇒ Boolean): Repr[Source[U]] = - andThen(SplitWhen(p.asInstanceOf[Any ⇒ Boolean])) - - /** - * Transforms a stream of streams into a contiguous stream of elements using the provided flattening strategy. - * This operation can be used on a stream of element type [[Source]]. - */ - def flatten[U](strategy: akka.stream.FlattenStrategy[Out, U]): Repr[U] = strategy match { - case _: akka.stream.FlattenStrategy.Concat[Out] ⇒ andThen(ConcatAll) - case _: akka.stream.scaladsl2.FlattenStrategy.Concat[Out] ⇒ andThen(ConcatAll) // TODO remove duality here? - case _ ⇒ throw new IllegalArgumentException(s"Unsupported flattening strategy [${strategy.getClass.getName}]") - } - - /** - * Transformation of a stream, with additional support for scheduled events. - * - * For each element the [[akka.stream.Transformer#onNext]] - * function is invoked, expecting a (possibly empty) sequence of output elements - * to be produced. - * After handing off the elements produced from one input element to the downstream - * subscribers, the [[akka.stream.Transformer#isComplete]] predicate determines whether to end - * stream processing at this point; in that case the upstream subscription is - * canceled. Before signaling normal completion to the downstream subscribers, - * the [[akka.stream.Transformer#onComplete]] function is invoked to produce a (possibly empty) - * sequence of elements in response to the end-of-stream event. - * - * [[akka.stream.Transformer#onError]] is called when failure is signaled from upstream. - * - * After normal completion or error the [[akka.stream.Transformer#cleanup]] function is called. - * - * It is possible to keep state in the concrete [[akka.stream.Transformer]] instance with - * ordinary instance variables. The [[akka.stream.Transformer]] is executed by an actor and - * therefore you do not have to add any additional thread safety or memory - * visibility constructs to access the state from the callback methods. - * - * Note that you can use [[#transform]] if you just need to transform elements time plays no role in the transformation. - */ - def timerTransform[U](name: String, mkTransformer: () ⇒ TimerTransformer[Out, U]): Repr[U] = - andThen(TimerTransform(name, mkTransformer.asInstanceOf[() ⇒ TimerTransformer[Any, Any]])) - - /** INTERNAL API */ - // Storing ops in reverse order - private[scaladsl2] def andThen[U](op: AstNode): Repr[U] -} - -/** - * INTERNAL API - */ -private[scaladsl2] object FlowOps { - private case object TakeWithinTimerKey - private case object DropWithinTimerKey - private case object GroupedWithinTimerKey - - private val takeCompletedTransformer: Transformer[Any, Any] = new Transformer[Any, Any] { - override def onNext(elem: Any) = Nil - override def isComplete = true - } - - private val identityTransformer: Transformer[Any, Any] = new Transformer[Any, Any] { - override def onNext(elem: Any) = List(elem) - } -} - diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/FlowMaterializer.scala b/akka-stream/src/main/scala/akka/stream/scaladsl2/FlowMaterializer.scala deleted file mode 100644 index da98883bf2..0000000000 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/FlowMaterializer.scala +++ /dev/null @@ -1,156 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream.scaladsl2 - -import scala.collection.immutable -import akka.actor.{ ActorContext, ActorRefFactory, ActorSystem, ExtendedActorSystem } -import akka.stream.MaterializerSettings -import akka.stream.impl2.{ ActorBasedFlowMaterializer, Ast, FlowNameCounter, StreamSupervisor } -import org.reactivestreams.Subscriber -import org.reactivestreams.Publisher - -// TODO: Find this guy a better place to live than scaladsl, as it's exposed in javadsl too -object FlowMaterializer { - - /** - * Scala API: Creates a FlowMaterializer which will execute every step of a transformation - * pipeline within its own [[akka.actor.Actor]]. The required [[akka.actor.ActorRefFactory]] - * (which can be either an [[akka.actor.ActorSystem]] or an [[akka.actor.ActorContext]]) - * will be used to create one actor that in turn creates actors for the transformation steps. - * - * The materializer's [[akka.stream.MaterializerSettings]] will be obtained from the - * configuration of the `context`'s underlying [[akka.actor.ActorSystem]]. - * - * The `namePrefix` is used as the first part of the names of the actors running - * the processing steps. The default `namePrefix` is `"flow"`. The actor names are built up of - * `namePrefix-flowNumber-flowStepNumber-stepName`. - */ - def apply(materializerSettings: Option[MaterializerSettings] = None, namePrefix: Option[String] = None)(implicit context: ActorRefFactory): FlowMaterializer = { - val system = actorSystemOf(context) - - val settings = materializerSettings getOrElse MaterializerSettings(system) - apply(settings, namePrefix.getOrElse("flow"))(context) - } - - /** - * Scala API: Creates a FlowMaterializer which will execute every step of a transformation - * pipeline within its own [[akka.actor.Actor]]. The required [[akka.actor.ActorRefFactory]] - * (which can be either an [[akka.actor.ActorSystem]] or an [[akka.actor.ActorContext]]) - * will be used to create these actors, therefore it is *forbidden* to pass this object - * to another actor if the factory is an ActorContext. - * - * The `namePrefix` is used as the first part of the names of the actors running - * the processing steps. The default `namePrefix` is `"flow"`. The actor names are built up of - * `namePrefix-flowNumber-flowStepNumber-stepName`. - */ - def apply(materializerSettings: MaterializerSettings, namePrefix: String)(implicit context: ActorRefFactory): FlowMaterializer = { - val system = actorSystemOf(context) - - new ActorBasedFlowMaterializer( - materializerSettings, - context.actorOf(StreamSupervisor.props(materializerSettings).withDispatcher(materializerSettings.dispatcher)), - FlowNameCounter(system).counter, - namePrefix) - } - - /** - * Scala API: Creates a FlowMaterializer which will execute every step of a transformation - * pipeline within its own [[akka.actor.Actor]]. The required [[akka.actor.ActorRefFactory]] - * (which can be either an [[akka.actor.ActorSystem]] or an [[akka.actor.ActorContext]]) - * will be used to create these actors, therefore it is *forbidden* to pass this object - * to another actor if the factory is an ActorContext. - * - * The `namePrefix` is used as the first part of the names of the actors running - * the processing steps. The default `namePrefix` is `"flow"`. The actor names are built up of - * `namePrefix-flowNumber-flowStepNumber-stepName`. - */ - def apply(materializerSettings: MaterializerSettings)(implicit context: ActorRefFactory): FlowMaterializer = - apply(Some(materializerSettings), None) - - /** - * Java API: Creates a FlowMaterializer which will execute every step of a transformation - * pipeline within its own [[akka.actor.Actor]]. The required [[akka.actor.ActorRefFactory]] - * (which can be either an [[akka.actor.ActorSystem]] or an [[akka.actor.ActorContext]]) - * will be used to create these actors, therefore it is *forbidden* to pass this object - * to another actor if the factory is an ActorContext. - * - * Defaults the actor name prefix used to name actors running the processing steps to `"flow"`. - * The actor names are built up of `namePrefix-flowNumber-flowStepNumber-stepName`. - */ - def create(context: ActorRefFactory): FlowMaterializer = - apply()(context) - - /** - * Java API: Creates a FlowMaterializer which will execute every step of a transformation - * pipeline within its own [[akka.actor.Actor]]. The required [[akka.actor.ActorRefFactory]] - * (which can be either an [[akka.actor.ActorSystem]] or an [[akka.actor.ActorContext]]) - * will be used to create one actor that in turn creates actors for the transformation steps. - */ - def create(settings: MaterializerSettings, context: ActorRefFactory): FlowMaterializer = - apply(Option(settings), None)(context) - - /** - * Java API: Creates a FlowMaterializer which will execute every step of a transformation - * pipeline within its own [[akka.actor.Actor]]. The required [[akka.actor.ActorRefFactory]] - * (which can be either an [[akka.actor.ActorSystem]] or an [[akka.actor.ActorContext]]) - * will be used to create these actors, therefore it is *forbidden* to pass this object - * to another actor if the factory is an ActorContext. - * - * The `namePrefix` is used as the first part of the names of the actors running - * the processing steps. The default `namePrefix` is `"flow"`. The actor names are built up of - * `namePrefix-flowNumber-flowStepNumber-stepName`. - */ - def create(settings: MaterializerSettings, context: ActorRefFactory, namePrefix: String): FlowMaterializer = - apply(Option(settings), Option(namePrefix))(context) - - private def actorSystemOf(context: ActorRefFactory): ActorSystem = { - val system = context match { - case s: ExtendedActorSystem ⇒ s - case c: ActorContext ⇒ c.system - case null ⇒ throw new IllegalArgumentException("ActorRefFactory context must be defined") - case _ ⇒ - throw new IllegalArgumentException(s"ActorRefFactory context must be a ActorSystem or ActorContext, got [${context.getClass.getName}]") - } - system - } - -} - -/** - * A FlowMaterializer takes the list of transformations comprising a - * [[akka.stream.scaladsl.Flow]] and materializes them in the form of - * [[org.reactivestreams.Processor]] instances. How transformation - * steps are split up into asynchronous regions is implementation - * dependent. - */ -abstract class FlowMaterializer(val settings: MaterializerSettings) { - - /** - * The `namePrefix` shall be used for deriving the names of processing - * entities that are created during materialization. This is meant to aid - * logging and error reporting both during materialization and while the - * stream is running. - */ - def withNamePrefix(name: String): FlowMaterializer - - /** - * This method interprets the given Flow description and creates the running - * stream. The result can be highly implementation specific, ranging from - * local actor chains to remote-deployed processing networks. - */ - def materialize[In, Out](source: Source[In], sink: Sink[Out], ops: List[Ast.AstNode]): MaterializedMap - - /** - * Create publishers and subscribers for fan-in and fan-out operations. - */ - def materializeJunction[In, Out](op: Ast.JunctionAstNode, inputCount: Int, outputCount: Int): (immutable.Seq[Subscriber[In]], immutable.Seq[Publisher[Out]]) - -} - -/** - * This exception or subtypes thereof should be used to signal materialization - * failures. - */ -class MaterializationException(msg: String, cause: Throwable = null) extends RuntimeException(msg, cause) - diff --git a/akka-stream/src/main/scala/akka/stream/scaladsl2/ImplicitFlowMaterializer.scala b/akka-stream/src/main/scala/akka/stream/scaladsl2/ImplicitFlowMaterializer.scala deleted file mode 100644 index ae2389fc28..0000000000 --- a/akka-stream/src/main/scala/akka/stream/scaladsl2/ImplicitFlowMaterializer.scala +++ /dev/null @@ -1,25 +0,0 @@ -/** - * Copyright (C) 2014 Typesafe Inc. - */ -package akka.stream.scaladsl2 - -import akka.actor.Actor -import akka.stream.MaterializerSettings - -/** - * Mix this trait into your [[akka.actor.Actor]] if you need an implicit - * [[akka.stream.FlowMaterializer]] in scope. - * - * Subclass may override [[#flowMaterializerSettings]] to define custom - * [[akka.stream.MaterializerSettings]] for the `FlowMaterializer`. - */ -trait ImplicitFlowMaterializer { this: Actor ⇒ - - /** - * Subclass may override this to define custom - * [[akka.stream.MaterializerSettings]] for the `FlowMaterializer`. - */ - def flowMaterializerSettings: MaterializerSettings = MaterializerSettings(context.system) - - final implicit val flowMaterializer: FlowMaterializer = FlowMaterializer(Some(flowMaterializerSettings)) -}