+str #16885 add splitAfter
Implementation is shared with splitWhen - see Split / SplitWhere Allows for easy addition of splitWhen(x => Decision) if we'd like to Resolves #16885
This commit is contained in:
parent
454a393af1
commit
5e8ff792a0
12 changed files with 709 additions and 216 deletions
|
|
@ -216,6 +216,44 @@ public class FlowTest extends StreamTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mustBeAbleToUseSplitAfter() {
|
||||
final JavaTestKit probe = new JavaTestKit(system);
|
||||
final Iterable<String> input = Arrays.asList("A", "B", "C", ".", "D", ".", "E", "F");
|
||||
final Flow<String, Source<String, BoxedUnit>, ?> flow = Flow.of(String.class).splitAfter(new Predicate<String>() {
|
||||
public boolean test(String elem) {
|
||||
return elem.equals(".");
|
||||
}
|
||||
});
|
||||
|
||||
Source.from(input).via(flow).runForeach(new Procedure<Source<String, BoxedUnit>>() {
|
||||
@Override
|
||||
public void apply(Source<String, BoxedUnit> subStream) throws Exception {
|
||||
subStream.grouped(10).runForeach(new Procedure<List<String>>() {
|
||||
@Override
|
||||
public void apply(List<String> chunk) throws Exception {
|
||||
probe.getRef().tell(chunk, ActorRef.noSender());
|
||||
}
|
||||
}, materializer);
|
||||
}
|
||||
}, materializer);
|
||||
|
||||
for (Object o : probe.receiveN(3)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> chunk = (List<String>) o;
|
||||
if (chunk.get(0).equals("A")) {
|
||||
assertEquals(Arrays.asList("A", "B", "C", "."), chunk);
|
||||
} else if (chunk.get(0).equals("D")) {
|
||||
assertEquals(Arrays.asList("D", "."), chunk);
|
||||
} else if (chunk.get(0).equals("E")) {
|
||||
assertEquals(Arrays.asList("E", "F"), chunk);
|
||||
} else {
|
||||
assertEquals("[A, B, C, .] or [D, .] or [E, F]", chunk);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public <T> Creator<Stage<T, T>> op() {
|
||||
return new akka.japi.function.Creator<Stage<T, T>>() {
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue