!str #15089 add flatMapMerge

This commit is contained in:
Roland Kuhn 2015-12-01 18:03:30 +01:00
parent 3f3f5c8575
commit 073e7058dc
13 changed files with 485 additions and 74 deletions

View file

@ -349,12 +349,12 @@ 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, ?>> mainInputs = new ArrayList<Source<Integer,?>>();
final List<Source<Integer, BoxedUnit>> mainInputs = new ArrayList<Source<Integer,BoxedUnit>>();
mainInputs.add(Source.from(input1));
mainInputs.add(Source.from(input2));
Future<List<Integer>> future = Source.from(mainInputs)
.<Integer>flatMapConcat(ConstantFun.<Source<Integer,?>>javaIdentityFunction())
.<Integer, BoxedUnit>flatMapConcat(ConstantFun.<Source<Integer,BoxedUnit>>javaIdentityFunction())
.grouped(6)
.runWith(Sink.<List<Integer>>head(), materializer);
@ -363,6 +363,37 @@ public class SourceTest extends StreamTest {
assertEquals(Arrays.asList(1, 2, 3, 4, 5), result);
}
@Test
public void mustBeAbleToUseFlatMapMerge() throws Exception {
final JavaTestKit probe = new JavaTestKit(system);
final Iterable<Integer> input1 = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
final Iterable<Integer> input2 = Arrays.asList(10, 11, 12, 13, 14, 15, 16, 17, 18, 19);
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>>();
mainInputs.add(Source.from(input1));
mainInputs.add(Source.from(input2));
mainInputs.add(Source.from(input3));
mainInputs.add(Source.from(input4));
Future<List<Integer>> future = Source.from(mainInputs)
.flatMapMerge(3, ConstantFun.<Source<Integer, BoxedUnit>>javaIdentityFunction()).grouped(60)
.runWith(Sink.<List<Integer>>head(), materializer);
List<Integer> result = Await.result(future, probe.dilated(FiniteDuration.create(3, TimeUnit.SECONDS)));
final Set<Integer> set = new HashSet<Integer>();
for (Integer i: result) {
set.add(i);
}
final Set<Integer> expected = new HashSet<Integer>();
for (int i = 0; i < 40; ++i) {
expected.add(i);
}
assertEquals(expected, set);
}
@Test
public void mustBeAbleToUseBuffer() throws Exception {
final JavaTestKit probe = new JavaTestKit(system);