fix the build on main (#31251)

* Fix compilation on scala 2.12

* Add mergePrioritizedN to docs

* Format Java code
This commit is contained in:
Arnout Engelen 2022-03-17 14:44:38 +01:00 committed by GitHub
parent fccb0ca220
commit 332f18c42b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 55 deletions

View file

@ -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);
}
}

View file

@ -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