also fix FlowInterleaveSpec
Also-by: Johan Andrén <johan@markatta.com> Also-by: Roland Kuhn <rk@rkuhn.info> Also-by: Martynas Mickevičius <mmartynas@gmail.com>
This commit is contained in:
parent
ef77b56e66
commit
60497f6561
195 changed files with 1110 additions and 857 deletions
|
|
@ -3,6 +3,8 @@
|
|||
*/
|
||||
package akka.stream.javadsl;
|
||||
|
||||
import akka.Done;
|
||||
import akka.NotUsed;
|
||||
import akka.actor.ActorRef;
|
||||
import akka.dispatch.Foreach;
|
||||
import akka.dispatch.Futures;
|
||||
|
|
@ -24,7 +26,6 @@ import scala.concurrent.Await;
|
|||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -97,7 +98,7 @@ public class FlowTest extends StreamTest {
|
|||
}
|
||||
});
|
||||
|
||||
final Future<BoxedUnit> future = source.via(flow).runWith(Sink.foreach(new Procedure<Integer>() { // Scala Future
|
||||
final Future<Done> future = source.via(flow).runWith(Sink.foreach(new Procedure<Integer>() { // Scala Future
|
||||
public void apply(Integer elem) {
|
||||
probe.getRef().tell(elem, ActorRef.noSender());
|
||||
}
|
||||
|
|
@ -114,7 +115,7 @@ public class FlowTest extends StreamTest {
|
|||
final Source<String, ?> source = Source.from(Arrays.asList("0", "1", "2", "3"));
|
||||
final Flow<String, String, ?> flow = Flow.of(String.class).intersperse("[", ",", "]");
|
||||
|
||||
final Future<BoxedUnit> future = source.via(flow).runWith(Sink.foreach(new Procedure<String>() { // Scala Future
|
||||
final Future<Done> future = source.via(flow).runWith(Sink.foreach(new Procedure<String>() { // Scala Future
|
||||
public void apply(String elem) {
|
||||
probe.getRef().tell(elem, ActorRef.noSender());
|
||||
}
|
||||
|
|
@ -138,7 +139,7 @@ public class FlowTest extends StreamTest {
|
|||
final Source<String, ?> source = Source.from(Arrays.asList("0", "1", "2", "3"));
|
||||
final Flow<String, String, ?> flow = Flow.of(String.class).intersperse(",");
|
||||
|
||||
final Future<BoxedUnit> future = Source.single(">> ").concat(source.via(flow)).runWith(Sink.foreach(new Procedure<String>() { // Scala Future
|
||||
final Future<Done> future = Source.single(">> ").concat(source.via(flow)).runWith(Sink.foreach(new Procedure<String>() { // Scala Future
|
||||
public void apply(String elem) {
|
||||
probe.getRef().tell(elem, ActorRef.noSender());
|
||||
}
|
||||
|
|
@ -166,7 +167,7 @@ public class FlowTest extends StreamTest {
|
|||
}
|
||||
});
|
||||
|
||||
final Future<BoxedUnit> future = source.via(flow).runWith(Sink.foreach(new Procedure<Integer>() { // Scala Future
|
||||
final Future<Done> future = source.via(flow).runWith(Sink.foreach(new Procedure<Integer>() { // Scala Future
|
||||
public void apply(Integer elem) {
|
||||
probe.getRef().tell(elem, ActorRef.noSender());
|
||||
}
|
||||
|
|
@ -240,7 +241,7 @@ public class FlowTest extends StreamTest {
|
|||
@Test
|
||||
public void mustBeAbleToUseGroupBy() throws Exception {
|
||||
final Iterable<String> input = Arrays.asList("Aaa", "Abb", "Bcc", "Cdd", "Cee");
|
||||
final Flow<String, List<String>, BoxedUnit> flow = Flow
|
||||
final Flow<String, List<String>, NotUsed> flow = Flow
|
||||
.of(String.class)
|
||||
.groupBy(3, new Function<String, String>() {
|
||||
public String apply(String elem) {
|
||||
|
|
@ -266,7 +267,7 @@ public class FlowTest extends StreamTest {
|
|||
@Test
|
||||
public void mustBeAbleToUseSplitWhen() throws Exception {
|
||||
final Iterable<String> input = Arrays.asList("A", "B", "C", ".", "D", ".", "E", "F");
|
||||
final Flow<String, List<String>, BoxedUnit> flow = Flow
|
||||
final Flow<String, List<String>, NotUsed> flow = Flow
|
||||
.of(String.class)
|
||||
.splitWhen(new Predicate<String>() {
|
||||
public boolean test(String elem) {
|
||||
|
|
@ -286,7 +287,7 @@ public class FlowTest extends StreamTest {
|
|||
@Test
|
||||
public void mustBeAbleToUseSplitAfter() throws Exception {
|
||||
final Iterable<String> input = Arrays.asList("A", "B", "C", ".", "D", ".", "E", "F");
|
||||
final Flow<String, List<String>, BoxedUnit> flow = Flow
|
||||
final Flow<String, List<String>, NotUsed> flow = Flow
|
||||
.of(String.class)
|
||||
.splitAfter(new Predicate<String>() {
|
||||
public boolean test(String elem) {
|
||||
|
|
@ -324,23 +325,23 @@ public class FlowTest extends StreamTest {
|
|||
|
||||
@Test
|
||||
public void mustBeAbleToUseMerge() throws Exception {
|
||||
final Flow<String, String, BoxedUnit> f1 =
|
||||
final Flow<String, String, NotUsed> f1 =
|
||||
Flow.of(String.class).transform(FlowTest.this.<String> op()).named("f1");
|
||||
final Flow<String, String, BoxedUnit> f2 =
|
||||
final Flow<String, String, NotUsed> f2 =
|
||||
Flow.of(String.class).transform(FlowTest.this.<String> op()).named("f2");
|
||||
@SuppressWarnings("unused")
|
||||
final Flow<String, String, BoxedUnit> f3 =
|
||||
final Flow<String, String, NotUsed> f3 =
|
||||
Flow.of(String.class).transform(FlowTest.this.<String> op()).named("f3");
|
||||
|
||||
final Source<String, BoxedUnit> in1 = Source.from(Arrays.asList("a", "b", "c"));
|
||||
final Source<String, BoxedUnit> in2 = Source.from(Arrays.asList("d", "e", "f"));
|
||||
final Source<String, NotUsed> in1 = Source.from(Arrays.asList("a", "b", "c"));
|
||||
final Source<String, NotUsed> in2 = Source.from(Arrays.asList("d", "e", "f"));
|
||||
|
||||
final Sink<String, Publisher<String>> publisher = Sink.asPublisher(false);
|
||||
|
||||
final Source<String, BoxedUnit> source = Source.fromGraph(
|
||||
GraphDSL.create(new Function<GraphDSL.Builder<BoxedUnit>, SourceShape<String>>() {
|
||||
final Source<String, NotUsed> source = Source.fromGraph(
|
||||
GraphDSL.create(new Function<GraphDSL.Builder<NotUsed>, SourceShape<String>>() {
|
||||
@Override
|
||||
public SourceShape<String> apply(Builder<BoxedUnit> b) throws Exception {
|
||||
public SourceShape<String> apply(Builder<NotUsed> b) throws Exception {
|
||||
final UniformFanInShape<String, String> merge = b.add(Merge.<String>create(2));
|
||||
b.from(b.add(in1)).via(b.add(f1)).toInlet(merge.in(0));
|
||||
b.from(b.add(in2)).via(b.add(f2)).toInlet(merge.in(1));
|
||||
|
|
@ -362,8 +363,8 @@ public class FlowTest extends StreamTest {
|
|||
final Iterable<String> input1 = Arrays.asList("A", "B", "C");
|
||||
final Iterable<Integer> input2 = Arrays.asList(1, 2, 3);
|
||||
|
||||
RunnableGraph.fromGraph(GraphDSL.create(new Function<Builder<BoxedUnit>, ClosedShape>(){
|
||||
public ClosedShape apply(Builder<BoxedUnit> b) {
|
||||
RunnableGraph.fromGraph(GraphDSL.create(new Function<Builder<NotUsed>, ClosedShape>(){
|
||||
public ClosedShape apply(Builder<NotUsed> b) {
|
||||
final Outlet<String> in1 = b.add(Source.from(input1)).out();
|
||||
final Outlet<Integer> in2 = b.add(Source.from(input2)).out();
|
||||
final FanInShape2<String, Integer, Pair<String, Integer>> zip = b.add(Zip.<String, Integer>create());
|
||||
|
|
@ -431,10 +432,10 @@ public class FlowTest extends StreamTest {
|
|||
public void mustBeAbleToUsePrefixAndTail() throws Exception {
|
||||
final JavaTestKit probe = new JavaTestKit(system);
|
||||
final Iterable<Integer> input = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
final Flow<Integer, Pair<List<Integer>, Source<Integer, BoxedUnit>>, ?> flow = Flow.of(Integer.class).prefixAndTail(3);
|
||||
Future<Pair<List<Integer>, Source<Integer, BoxedUnit>>> future =
|
||||
Source.from(input).via(flow).runWith(Sink.<Pair<List<Integer>, Source<Integer, BoxedUnit>>>head(), materializer);
|
||||
Pair<List<Integer>, Source<Integer, BoxedUnit>> result = Await.result(future,
|
||||
final Flow<Integer, Pair<List<Integer>, Source<Integer, NotUsed>>, ?> flow = Flow.of(Integer.class).prefixAndTail(3);
|
||||
Future<Pair<List<Integer>, Source<Integer, NotUsed>>> future =
|
||||
Source.from(input).via(flow).runWith(Sink.<Pair<List<Integer>, Source<Integer, NotUsed>>>head(), materializer);
|
||||
Pair<List<Integer>, Source<Integer, NotUsed>> result = Await.result(future,
|
||||
probe.dilated(FiniteDuration.create(3, TimeUnit.SECONDS)));
|
||||
assertEquals(Arrays.asList(1, 2, 3), result.first());
|
||||
|
||||
|
|
@ -449,12 +450,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, NotUsed>> mainInputs = new ArrayList<Source<Integer,NotUsed>>();
|
||||
mainInputs.add(Source.from(input1));
|
||||
mainInputs.add(Source.from(input2));
|
||||
|
||||
final Flow<Source<Integer, BoxedUnit>, List<Integer>, ?> flow = Flow.<Source<Integer, BoxedUnit>>create().
|
||||
flatMapConcat(ConstantFun.<Source<Integer, BoxedUnit>>javaIdentityFunction()).grouped(6);
|
||||
final Flow<Source<Integer, NotUsed>, List<Integer>, ?> flow = Flow.<Source<Integer, NotUsed>>create().
|
||||
flatMapConcat(ConstantFun.<Source<Integer, NotUsed>>javaIdentityFunction()).grouped(6);
|
||||
Future<List<Integer>> future = Source.from(mainInputs).via(flow)
|
||||
.runWith(Sink.<List<Integer>>head(), materializer);
|
||||
|
||||
|
|
@ -471,14 +472,14 @@ public class FlowTest extends StreamTest {
|
|||
final Iterable<Integer> input3 = Arrays.asList(20, 21, 22, 23, 24, 25, 26, 27, 28, 29);
|
||||
final Iterable<Integer> input4 = Arrays.asList(30, 31, 32, 33, 34, 35, 36, 37, 38, 39);
|
||||
|
||||
final List<Source<Integer, BoxedUnit>> mainInputs = new ArrayList<Source<Integer,BoxedUnit>>();
|
||||
final List<Source<Integer, NotUsed>> mainInputs = new ArrayList<Source<Integer,NotUsed>>();
|
||||
mainInputs.add(Source.from(input1));
|
||||
mainInputs.add(Source.from(input2));
|
||||
mainInputs.add(Source.from(input3));
|
||||
mainInputs.add(Source.from(input4));
|
||||
|
||||
final Flow<Source<Integer, BoxedUnit>, List<Integer>, ?> flow = Flow.<Source<Integer, BoxedUnit>>create().
|
||||
flatMapMerge(3, ConstantFun.<Source<Integer, BoxedUnit>>javaIdentityFunction()).grouped(60);
|
||||
final Flow<Source<Integer, NotUsed>, List<Integer>, ?> flow = Flow.<Source<Integer, NotUsed>>create().
|
||||
flatMapMerge(3, ConstantFun.<Source<Integer, NotUsed>>javaIdentityFunction()).grouped(60);
|
||||
Future<List<Integer>> future = Source.from(mainInputs).via(flow)
|
||||
.runWith(Sink.<List<Integer>>head(), materializer);
|
||||
|
||||
|
|
@ -499,7 +500,7 @@ public class FlowTest extends StreamTest {
|
|||
public void mustBeAbleToUseBuffer() throws Exception {
|
||||
final JavaTestKit probe = new JavaTestKit(system);
|
||||
final List<String> input = Arrays.asList("A", "B", "C");
|
||||
final Flow<String, List<String>, BoxedUnit> flow = Flow.of(String.class).buffer(2, OverflowStrategy.backpressure()).grouped(4);
|
||||
final Flow<String, List<String>, NotUsed> flow = Flow.of(String.class).buffer(2, OverflowStrategy.backpressure()).grouped(4);
|
||||
Future<List<String>> future = Source.from(input).via(flow)
|
||||
.runWith(Sink.<List<String>>head(), materializer);
|
||||
|
||||
|
|
@ -511,7 +512,7 @@ public class FlowTest extends StreamTest {
|
|||
public void mustBeAbleToUseConflate() throws Exception {
|
||||
final JavaTestKit probe = new JavaTestKit(system);
|
||||
final List<String> input = Arrays.asList("A", "B", "C");
|
||||
final Flow<String, String, BoxedUnit> flow = Flow.of(String.class).conflate(new Function<String, String>() {
|
||||
final Flow<String, String, NotUsed> flow = Flow.of(String.class).conflate(new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String s) throws Exception {
|
||||
return s;
|
||||
|
|
@ -536,7 +537,7 @@ public class FlowTest extends StreamTest {
|
|||
public void mustBeAbleToUseExpand() throws Exception {
|
||||
final JavaTestKit probe = new JavaTestKit(system);
|
||||
final List<String> input = Arrays.asList("A", "B", "C");
|
||||
final Flow<String, String, BoxedUnit> flow = Flow.of(String.class).expand(new Function<String, String>() {
|
||||
final Flow<String, String, NotUsed> flow = Flow.of(String.class).expand(new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String in) throws Exception {
|
||||
return in;
|
||||
|
|
@ -557,7 +558,7 @@ public class FlowTest extends StreamTest {
|
|||
public void mustBeAbleToUseMapAsync() throws Exception {
|
||||
final JavaTestKit probe = new JavaTestKit(system);
|
||||
final Iterable<String> input = Arrays.asList("a", "b", "c");
|
||||
final Flow<String, String, BoxedUnit> flow = Flow.of(String.class).mapAsync(4, new Function<String, Future<String>>() {
|
||||
final Flow<String, String, NotUsed> flow = Flow.of(String.class).mapAsync(4, new Function<String, Future<String>>() {
|
||||
public Future<String> apply(String elem) {
|
||||
return Futures.successful(elem.toUpperCase());
|
||||
}
|
||||
|
|
@ -592,7 +593,7 @@ public class FlowTest extends StreamTest {
|
|||
}
|
||||
});
|
||||
|
||||
final Future<BoxedUnit> future = source.via(flow).runWith(Sink.foreach(new Procedure<Integer>() {
|
||||
final Future<Done> future = source.via(flow).runWith(Sink.foreach(new Procedure<Integer>() {
|
||||
public void apply(Integer elem) {
|
||||
probe.getRef().tell(elem, ActorRef.noSender());
|
||||
}
|
||||
|
|
@ -632,7 +633,7 @@ public class FlowTest extends StreamTest {
|
|||
final List<String> input = Arrays.asList("A", "B", "C");
|
||||
Flow<String,String,?> otherFlow = Flow.of(String.class);
|
||||
|
||||
Sink<String,BoxedUnit> sink = Flow.of(String.class).to(otherFlow.to(Sink.foreach(new Procedure<String>() { // Scala Future
|
||||
Sink<String,NotUsed> sink = Flow.of(String.class).to(otherFlow.to(Sink.foreach(new Procedure<String>() { // Scala Future
|
||||
public void apply(String elem) {
|
||||
probe.getRef().tell(elem, ActorRef.noSender());
|
||||
}
|
||||
|
|
@ -644,10 +645,10 @@ public class FlowTest extends StreamTest {
|
|||
|
||||
@Test
|
||||
public void mustBeAbleToBroadcastEagerCancel() throws Exception {
|
||||
final Sink<String, BoxedUnit> sink = Sink.fromGraph(
|
||||
GraphDSL.create(new Function<GraphDSL.Builder<BoxedUnit>, SinkShape<String>>() {
|
||||
final Sink<String, NotUsed> sink = Sink.fromGraph(
|
||||
GraphDSL.create(new Function<GraphDSL.Builder<NotUsed>, SinkShape<String>>() {
|
||||
@Override
|
||||
public SinkShape<String> apply(Builder<BoxedUnit> b) throws Exception {
|
||||
public SinkShape<String> apply(Builder<NotUsed> b) throws Exception {
|
||||
final UniformFanOutShape<String, String> broadcast = b.add(Broadcast.<String>create(2, true));
|
||||
final SinkShape<String> out1 = b.add(Sink.<String>cancelled());
|
||||
final SinkShape<String> out2 = b.add(Sink.<String>ignore());
|
||||
|
|
@ -659,7 +660,7 @@ public class FlowTest extends StreamTest {
|
|||
|
||||
final JavaTestKit probe = new JavaTestKit(system);
|
||||
Source<String, ActorRef> source = Source.actorRef(1, OverflowStrategy.dropNew());
|
||||
final ActorRef actor = source.toMat(sink, Keep.<ActorRef, BoxedUnit>left()).run(materializer);
|
||||
final ActorRef actor = source.toMat(sink, Keep.<ActorRef, NotUsed>left()).run(materializer);
|
||||
probe.watch(actor);
|
||||
probe.expectTerminated(actor);
|
||||
}
|
||||
|
|
@ -787,7 +788,7 @@ public class FlowTest extends StreamTest {
|
|||
|
||||
public void mustSuitablyOverrideAttributeHandlingMethods() {
|
||||
@SuppressWarnings("unused")
|
||||
final Flow<Integer, Integer, BoxedUnit> f =
|
||||
final Flow<Integer, Integer, NotUsed> f =
|
||||
Flow.of(Integer.class).withAttributes(Attributes.name("")).addAttributes(Attributes.asyncBoundary()).named("");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue