!str - replaces flattenConcat with flatMapConcat
This commit is contained in:
parent
1378fedad0
commit
50c6f2267c
22 changed files with 112 additions and 96 deletions
|
|
@ -10,6 +10,7 @@ import akka.japi.JavaPartialFunction;
|
|||
import akka.japi.Pair;
|
||||
import akka.japi.function.*;
|
||||
import akka.stream.*;
|
||||
import akka.stream.impl.ConstantFun;
|
||||
import akka.stream.javadsl.FlowGraph.Builder;
|
||||
import akka.stream.stage.*;
|
||||
import akka.stream.testkit.AkkaSpec;
|
||||
|
|
@ -481,12 +482,12 @@ public class FlowTest extends StreamTest {
|
|||
final Iterable<Integer> input1 = Arrays.asList(1, 2, 3);
|
||||
final Iterable<Integer> input2 = Arrays.asList(4, 5);
|
||||
|
||||
final List<Source<Integer, BoxedUnit>> mainInputs = new ArrayList<Source<Integer,BoxedUnit>>();
|
||||
final List<Source<Integer, ?>> mainInputs = new ArrayList<Source<Integer,?>>();
|
||||
mainInputs.add(Source.from(input1));
|
||||
mainInputs.add(Source.from(input2));
|
||||
|
||||
final Flow<Source<Integer, BoxedUnit>, List<Integer>, BoxedUnit> flow = Flow.<Source<Integer, BoxedUnit>>create().
|
||||
<Integer>flattenConcat().grouped(6);
|
||||
final Flow<Source<Integer, ?>, List<Integer>, ?> flow = Flow.<Source<Integer, ?>>create().
|
||||
flatMapConcat(ConstantFun.<Source<Integer, ?>>javaIdentityFunction()).grouped(6);
|
||||
Future<List<Integer>> future = Source.from(mainInputs).via(flow)
|
||||
.runWith(Sink.<List<Integer>>head(), materializer);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import akka.stream.Graph;
|
|||
import akka.stream.OverflowStrategy;
|
||||
import akka.stream.StreamTest;
|
||||
import akka.stream.UniformFanInShape;
|
||||
import akka.stream.impl.ConstantFun;
|
||||
import akka.stream.stage.*;
|
||||
import akka.stream.testkit.AkkaSpec;
|
||||
import akka.stream.testkit.TestPublisher;
|
||||
|
|
@ -348,12 +349,13 @@ public class SourceTest extends StreamTest {
|
|||
final Iterable<Integer> input1 = Arrays.asList(1, 2, 3);
|
||||
final Iterable<Integer> input2 = Arrays.asList(4, 5);
|
||||
|
||||
final List<Source<Integer, BoxedUnit>> mainInputs = new ArrayList<Source<Integer,BoxedUnit>>();
|
||||
final List<Source<Integer, ?>> mainInputs = new ArrayList<Source<Integer,?>>();
|
||||
mainInputs.add(Source.from(input1));
|
||||
mainInputs.add(Source.from(input2));
|
||||
|
||||
Future<List<Integer>> future = Source.from(mainInputs)
|
||||
.<Integer>flattenConcat().grouped(6)
|
||||
.<Integer>flatMapConcat(ConstantFun.<Source<Integer,?>>javaIdentityFunction())
|
||||
.grouped(6)
|
||||
.runWith(Sink.<List<Integer>>head(), materializer);
|
||||
|
||||
List<Integer> result = Await.result(future, probe.dilated(FiniteDuration.create(3, TimeUnit.SECONDS)));
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
*/
|
||||
package akka.stream.scaladsl
|
||||
|
||||
import akka.stream.impl.ConstantFun
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import scala.util.control.NoStackTrace
|
||||
import akka.stream.ActorMaterializer
|
||||
|
|
@ -31,7 +33,7 @@ class FlowConcatAllSpec extends AkkaSpec {
|
|||
val main = Source(List(s1, s2, s3, s4, s5))
|
||||
|
||||
val subscriber = TestSubscriber.manualProbe[Int]()
|
||||
main.flattenConcat().to(Sink(subscriber)).run()
|
||||
main.flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink(subscriber)).run()
|
||||
val subscription = subscriber.expectSubscription()
|
||||
subscription.request(10)
|
||||
for (i ← 1 to 10)
|
||||
|
|
@ -42,7 +44,7 @@ class FlowConcatAllSpec extends AkkaSpec {
|
|||
|
||||
"work together with SplitWhen" in {
|
||||
val subscriber = TestSubscriber.manualProbe[Int]()
|
||||
Source(1 to 10).splitWhen(_ % 2 == 0).flattenConcat().runWith(Sink(subscriber))
|
||||
Source(1 to 10).splitWhen(_ % 2 == 0).flatMapConcat(ConstantFun.scalaIdentityFunction).runWith(Sink(subscriber))
|
||||
val subscription = subscriber.expectSubscription()
|
||||
subscription.request(10)
|
||||
for (i ← (1 to 10))
|
||||
|
|
@ -54,7 +56,7 @@ class FlowConcatAllSpec extends AkkaSpec {
|
|||
"on onError on master stream cancel the current open substream and signal error" in assertAllStagesStopped {
|
||||
val publisher = TestPublisher.manualProbe[Source[Int, _]]()
|
||||
val subscriber = TestSubscriber.manualProbe[Int]()
|
||||
Source(publisher).flattenConcat().to(Sink(subscriber)).run()
|
||||
Source(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink(subscriber)).run()
|
||||
|
||||
val upstream = publisher.expectSubscription()
|
||||
val downstream = subscriber.expectSubscription()
|
||||
|
|
@ -74,7 +76,7 @@ class FlowConcatAllSpec extends AkkaSpec {
|
|||
"on onError on master stream cancel the currently opening substream and signal error" in assertAllStagesStopped {
|
||||
val publisher = TestPublisher.manualProbe[Source[Int, _]]()
|
||||
val subscriber = TestSubscriber.manualProbe[Int]()
|
||||
Source(publisher).flattenConcat().to(Sink(subscriber)).run()
|
||||
Source(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink(subscriber)).run()
|
||||
|
||||
val upstream = publisher.expectSubscription()
|
||||
val downstream = subscriber.expectSubscription()
|
||||
|
|
@ -94,10 +96,27 @@ class FlowConcatAllSpec extends AkkaSpec {
|
|||
subUpstream.expectCancellation()
|
||||
}
|
||||
|
||||
"on onError on opening substream, cancel the master stream and signal error " in assertAllStagesStopped {
|
||||
val publisher = TestPublisher.manualProbe[Source[Int, _]]()
|
||||
val subscriber = TestSubscriber.manualProbe[Int]()
|
||||
Source(publisher).flatMapConcat(_ ⇒ throw testException).to(Sink(subscriber)).run()
|
||||
|
||||
val upstream = publisher.expectSubscription()
|
||||
val downstream = subscriber.expectSubscription()
|
||||
downstream.request(1000)
|
||||
|
||||
val substreamPublisher = TestPublisher.manualProbe[Int]()
|
||||
val substreamFlow = Source(substreamPublisher)
|
||||
upstream.expectRequest()
|
||||
upstream.sendNext(substreamFlow)
|
||||
subscriber.expectError(testException)
|
||||
upstream.expectCancellation()
|
||||
}
|
||||
|
||||
"on onError on open substream, cancel the master stream and signal error " in assertAllStagesStopped {
|
||||
val publisher = TestPublisher.manualProbe[Source[Int, _]]()
|
||||
val subscriber = TestSubscriber.manualProbe[Int]()
|
||||
Source(publisher).flattenConcat().to(Sink(subscriber)).run()
|
||||
Source(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink(subscriber)).run()
|
||||
|
||||
val upstream = publisher.expectSubscription()
|
||||
val downstream = subscriber.expectSubscription()
|
||||
|
|
@ -117,7 +136,7 @@ class FlowConcatAllSpec extends AkkaSpec {
|
|||
"on cancellation cancel the current open substream and the master stream" in assertAllStagesStopped {
|
||||
val publisher = TestPublisher.manualProbe[Source[Int, _]]()
|
||||
val subscriber = TestSubscriber.manualProbe[Int]()
|
||||
Source(publisher).flattenConcat().to(Sink(subscriber)).run()
|
||||
Source(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink(subscriber)).run()
|
||||
|
||||
val upstream = publisher.expectSubscription()
|
||||
val downstream = subscriber.expectSubscription()
|
||||
|
|
@ -138,7 +157,7 @@ class FlowConcatAllSpec extends AkkaSpec {
|
|||
"on cancellation cancel the currently opening substream and the master stream" in assertAllStagesStopped {
|
||||
val publisher = TestPublisher.manualProbe[Source[Int, _]]()
|
||||
val subscriber = TestSubscriber.manualProbe[Int]()
|
||||
Source(publisher).flattenConcat().to(Sink(subscriber)).run()
|
||||
Source(publisher).flatMapConcat(ConstantFun.scalaIdentityFunction).to(Sink(subscriber)).run()
|
||||
|
||||
val upstream = publisher.expectSubscription()
|
||||
val downstream = subscriber.expectSubscription()
|
||||
|
|
@ -162,7 +181,11 @@ class FlowConcatAllSpec extends AkkaSpec {
|
|||
val up = TestPublisher.manualProbe[Source[Int, _]]()
|
||||
val down = TestSubscriber.manualProbe[Int]()
|
||||
|
||||
val flowSubscriber = Source.subscriber[Source[Int, _]].flattenConcat().to(Sink(down)).run()
|
||||
val flowSubscriber = Source
|
||||
.subscriber[Source[Int, _]]
|
||||
.flatMapConcat(ConstantFun.scalaIdentityFunction)
|
||||
.to(Sink(down))
|
||||
.run()
|
||||
|
||||
val downstream = down.expectSubscription()
|
||||
downstream.cancel()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue