Java Code Examples for akka.stream.javadsl.Source#from()

The following examples show how to use akka.stream.javadsl.Source#from() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MergeSortedAsPairTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testMergeSortedResult() {
    final Source<Integer, NotUsed> source1 = Source.from(List.of(1, 3, 5, 7, 9));
    final Source<Integer, NotUsed> source2 = Source.from(List.of(2, 3, 4, 5, 6));
    final List<Pair<Integer, Integer>> mergeResult = runWithMergeSortedAsPair(source1, source2);
    assertThat(mergeResult)
            .containsExactlyElementsOf(List.of(
                    Pair.create(1, 2),
                    Pair.create(3, 2),
                    Pair.create(3, 3),
                    Pair.create(5, 4),
                    Pair.create(5, 5),
                    Pair.create(7, 6),
                    Pair.create(7, Integer.MAX_VALUE),
                    Pair.create(9, Integer.MAX_VALUE)
            ));
}
 
Example 2
Source File: MergeSortedAsPairTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void forIdenticalSources() {
    final Source<Integer, NotUsed> source1 = Source.from(List.of(1, 3, 5, 7, 9));
    final List<Pair<Integer, Integer>> mergeResult = runWithMergeSortedAsPair(source1, source1);
    assertThat(mergeResult)
            .containsExactlyElementsOf(List.of(
                    Pair.create(1, 1),
                    Pair.create(3, 3),
                    Pair.create(5, 5),
                    Pair.create(7, 7),
                    Pair.create(9, 9)
            ));
}
 
Example 3
Source File: MergeSortedAsPairTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBehaviorSpecificationByMergeSortOnExample() {
    final Source<Integer, NotUsed> source1 = Source.from(List.of(1, 3, 5, 7, 9));
    final Source<Integer, NotUsed> source2 = Source.from(List.of(2, 3, 4, 5, 6));
    final List<Integer> specifiedMergeSortedResult = runSource(source1.mergeSorted(source2, Integer::compare));
    final List<Integer> actualMergeSortedResult = runSource(equivalentOfMergeSortedUnderTest(source1, source2));
    assertThat(actualMergeSortedResult).isEqualTo(specifiedMergeSortedResult);
}
 
Example 4
Source File: MergeSortedAsPairTest.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testBehaviorSpecificationByMergeSortOnEarlyExhaustion() {
    final Source<Integer, NotUsed> source1 = Source.from(List.of(1, 3));
    final Source<Integer, NotUsed> source2 = Source.from(List.of(2, 4, 6, 8));
    final List<Integer> specifiedMergeSortedResult = runSource(source1.mergeSorted(source2, Integer::compare));
    final List<Integer> actualMergeSortedResult = runSource(equivalentOfMergeSortedUnderTest(source1, source2));
    assertThat(actualMergeSortedResult).isEqualTo(specifiedMergeSortedResult);
}
 
Example 5
Source File: BackgroundSyncStreamTest.java    From ditto with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void mergeMetadataStreams() {
    final Duration toleranceWindow = Duration.ofHours(1L);

    final Source<Metadata, NotUsed> persisted = Source.from(List.of(
            Metadata.of(ThingId.of("x:0-only-persisted"), 1L, null, 0L),
            Metadata.of(ThingId.of("x:2-within-tolerance"), 3L, null, 0L),
            Metadata.of(ThingId.of("x:3-revision-mismatch"), 3L, PolicyId.of("x:3"), 0L),
            Metadata.of(ThingId.of("x:4-policy-id-mismatch"), 3L, PolicyId.of("x:4"), 0L),
            Metadata.of(ThingId.of("x:5-policy-revision-mismatch"), 3L, PolicyId.of("x:5"), 0L),
            Metadata.of(ThingId.of("x:6-all-up-to-date"), 3L, PolicyId.of("x:6"), 0L)
    ));

    final Source<Metadata, NotUsed> indexed = Source.from(List.of(
            Metadata.of(ThingId.of("x:1-only-indexed"), 1L, null, 0L),
            Metadata.of(ThingId.of("x:2-within-tolerance"), 1L, null, 0L, Instant.now()),
            Metadata.of(ThingId.of("x:3-revision-mismatch"), 2L, PolicyId.of("x:3"), 1L),
            Metadata.of(ThingId.of("x:4-policy-id-mismatch"), 3L, PolicyId.of("x:mismatched"), 0L),
            Metadata.of(ThingId.of("x:5-policy-revision-mismatch"), 3L, PolicyId.of("x:5"), 3L),
            Metadata.of(ThingId.of("x:6-all-up-to-date"), 5L, PolicyId.of("x:6"), 6L)
    ));

    new TestKit(actorSystem) {{
        final BackgroundSyncStream underTest =
                BackgroundSyncStream.of(getRef(), Duration.ofSeconds(3L), toleranceWindow, 100,
                        Duration.ofSeconds(10L));
        final CompletionStage<List<String>> inconsistentThingIds =
                underTest.filterForInconsistencies(persisted, indexed)
                        .map(metadata -> metadata.getThingId().toString())
                        .runWith(Sink.seq(), materializer);

        expectMsg(SudoRetrievePolicyRevision.of(PolicyId.of("x:5"), DittoHeaders.empty()));
        reply(SudoRetrievePolicyRevisionResponse.of(PolicyId.of("x:5"), 6L, DittoHeaders.empty()));

        expectMsg(SudoRetrievePolicyRevision.of(PolicyId.of("x:6"), DittoHeaders.empty()));
        reply(SudoRetrievePolicyRevisionResponse.of(PolicyId.of("x:6"), 6L, DittoHeaders.empty()));

        assertThat(inconsistentThingIds.toCompletableFuture().join()).containsExactly(
                "x:0-only-persisted",
                "x:1-only-indexed",
                "x:3-revision-mismatch",
                "x:4-policy-id-mismatch",
                "x:5-policy-revision-mismatch"
        );
    }};
}