fix the build on main (#31251)
* Fix compilation on scala 2.12 * Add mergePrioritizedN to docs * Format Java code
This commit is contained in:
parent
fccb0ca220
commit
332f18c42b
4 changed files with 55 additions and 55 deletions
|
|
@ -19,62 +19,62 @@ import java.util.concurrent.CompletionStage;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class RecipeSplitter {
|
||||
private static ActorSystem system;
|
||||
private static ActorSystem system;
|
||||
|
||||
@Test
|
||||
public void simpleSplit() throws ExecutionException, InterruptedException {
|
||||
// #Simple-Split
|
||||
// Sample Source
|
||||
Source<String, NotUsed> source = Source.from(Arrays.asList("1-2-3", "2-3", "3-4"));
|
||||
@Test
|
||||
public void simpleSplit() throws ExecutionException, InterruptedException {
|
||||
// #Simple-Split
|
||||
// Sample Source
|
||||
Source<String, NotUsed> source = Source.from(Arrays.asList("1-2-3", "2-3", "3-4"));
|
||||
|
||||
CompletionStage<List<Integer>> ret =
|
||||
source
|
||||
.map(s -> Arrays.asList(s.split("-")))
|
||||
.mapConcat(f -> f)
|
||||
// Sub-streams logic
|
||||
.map(s -> Integer.valueOf(s))
|
||||
.runWith(Sink.seq(), system);
|
||||
CompletionStage<List<Integer>> ret =
|
||||
source
|
||||
.map(s -> Arrays.asList(s.split("-")))
|
||||
.mapConcat(f -> f)
|
||||
// Sub-streams logic
|
||||
.map(s -> Integer.valueOf(s))
|
||||
.runWith(Sink.seq(), system);
|
||||
|
||||
// Verify results
|
||||
List<Integer> list = ret.toCompletableFuture().get();
|
||||
assert list.equals(Arrays.asList(1, 2, 3, 2, 3, 3, 4));
|
||||
// #Simple-Split
|
||||
}
|
||||
// Verify results
|
||||
List<Integer> list = ret.toCompletableFuture().get();
|
||||
assert list.equals(Arrays.asList(1, 2, 3, 2, 3, 3, 4));
|
||||
// #Simple-Split
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitAggregate() throws ExecutionException, InterruptedException {
|
||||
// #Aggregate-Split
|
||||
// Sample Source
|
||||
Source<String, NotUsed> source = Source.from(Arrays.asList("1-2-3", "2-3", "3-4"));
|
||||
@Test
|
||||
public void splitAggregate() throws ExecutionException, InterruptedException {
|
||||
// #Aggregate-Split
|
||||
// Sample Source
|
||||
Source<String, NotUsed> source = Source.from(Arrays.asList("1-2-3", "2-3", "3-4"));
|
||||
|
||||
CompletionStage<List<Integer>> ret =
|
||||
source
|
||||
.map(s -> Arrays.asList(s.split("-")))
|
||||
// split all messages into sub-streams
|
||||
.splitWhen(a -> true)
|
||||
// now split each collection
|
||||
.mapConcat(f -> f)
|
||||
// Sub-streams logic
|
||||
.map(s -> Integer.valueOf(s))
|
||||
// aggregate each sub-stream
|
||||
.reduce((a, b) -> a + b)
|
||||
// and merge back the result into the original stream
|
||||
.mergeSubstreams()
|
||||
.runWith(Sink.seq(), system);
|
||||
CompletionStage<List<Integer>> ret =
|
||||
source
|
||||
.map(s -> Arrays.asList(s.split("-")))
|
||||
// split all messages into sub-streams
|
||||
.splitWhen(a -> true)
|
||||
// now split each collection
|
||||
.mapConcat(f -> f)
|
||||
// Sub-streams logic
|
||||
.map(s -> Integer.valueOf(s))
|
||||
// aggregate each sub-stream
|
||||
.reduce((a, b) -> a + b)
|
||||
// and merge back the result into the original stream
|
||||
.mergeSubstreams()
|
||||
.runWith(Sink.seq(), system);
|
||||
|
||||
// Verify results
|
||||
List<Integer> list = ret.toCompletableFuture().get();
|
||||
assert list.equals(Arrays.asList(6, 5, 7));
|
||||
// #Aggregate-Split
|
||||
}
|
||||
// Verify results
|
||||
List<Integer> list = ret.toCompletableFuture().get();
|
||||
assert list.equals(Arrays.asList(6, 5, 7));
|
||||
// #Aggregate-Split
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws Exception {
|
||||
system = ActorSystem.create();
|
||||
}
|
||||
@BeforeClass
|
||||
public static void setup() throws Exception {
|
||||
system = ActorSystem.create();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void teardown() throws Exception {
|
||||
TestKit.shutdownActorSystem(system);
|
||||
}
|
||||
@AfterClass
|
||||
public static void teardown() throws Exception {
|
||||
TestKit.shutdownActorSystem(system);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -208,10 +208,8 @@ class SourceOrFlow {
|
|||
Source<Integer, NotUsed> sourceA = Source.from(Arrays.asList(1, 2, 3, 4));
|
||||
Source<Integer, NotUsed> sourceB = Source.from(Arrays.asList(10, 20, 30, 40));
|
||||
Source<Integer, NotUsed> sourceC = Source.from(Arrays.asList(100, 200, 300, 400));
|
||||
List<Pair<Source<Integer, ?>,Integer>> sourcesAndPriorities = Arrays.asList(
|
||||
new Pair<>(sourceA, 9900),
|
||||
new Pair<>(sourceB, 99),
|
||||
new Pair<>(sourceC, 1));
|
||||
List<Pair<Source<Integer, ?>, Integer>> sourcesAndPriorities =
|
||||
Arrays.asList(new Pair<>(sourceA, 9900), new Pair<>(sourceB, 99), new Pair<>(sourceC, 1));
|
||||
Source.mergePrioritizedN(sourcesAndPriorities, false).runForeach(System.out::println, system);
|
||||
// prints e.g. 1, 100, 2, 3, 4, 10, 20, 30, 40, 200, 300, 400 since both sources have their
|
||||
// first element ready and
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue