return flatMapSequential(mapper, Queues.SMALL_BUFFER_SIZE);
@Override public Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) { //TODO: is this kosher? return writeWith(Flux.from(body) .flatMapSequential(p -> p)); }
@Override public Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body) { return writeWith(Flux.from(body) .flatMapSequential(p -> p)); } };
@Test(expected = IllegalArgumentException.class) public void testInvalidCapacityHint() { Flux.just(1).flatMapSequential(toJust, 0, Queues.SMALL_BUFFER_SIZE); }
@Test(expected = IllegalArgumentException.class) public void testInvalidMaxConcurrent() { Flux.just(1).flatMapSequential(toJust, Queues.SMALL_BUFFER_SIZE, 0); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void mappingBadPrefetch() throws Exception { Flux<Integer> source = Flux.just(1); try { Flux.just(source, source, source).flatMapSequential(Flux.identityFunction(), 10, -99); } catch (IllegalArgumentException ex) { assertEquals("prefetch > 0 required but it was -99", ex.getMessage()); } }
@Test public void testMapperThrows() { Flux.just(1).flatMapSequential(t -> { throw new RuntimeException(); }).subscribe(ts); ts.assertNoValues(); ts.assertNotComplete(); ts.assertError(RuntimeException.class); }
@Test public void testMaxConcurrent5() { final List<Long> requests = new ArrayList<>(); Flux.range(1, 100).doOnRequest(requests::add) .flatMapSequential(toJust, 5, Queues.SMALL_BUFFER_SIZE) .subscribe(ts); ts.assertNoError(); ts.assertValueCount(100); ts.assertComplete(); Assert.assertEquals(5, (long) requests.get(0)); Assert.assertEquals(1, (long) requests.get(1)); Assert.assertEquals(1, (long) requests.get(2)); Assert.assertEquals(1, (long) requests.get(3)); Assert.assertEquals(1, (long) requests.get(4)); Assert.assertEquals(1, (long) requests.get(5)); }
@Test public void testMainError() { Flux.<Integer>error(new RuntimeException()).flatMapSequential(toJust).subscribe(ts); ts.assertNoValues(); ts.assertError(RuntimeException.class); ts.assertNotComplete(); }
@Test public void mergeSequentialLargeUnorderedEach100() { Scheduler scheduler = Schedulers.elastic(); AtomicBoolean comparisonFailure = new AtomicBoolean(); long count = Flux.range(0, 500) .flatMapSequential(i -> { //ensure each pack of 100 is delayed in inverse order Duration sleep = Duration.ofMillis(600 - i % 100); return Mono.delay(sleep) .then(Mono.just(i)) .subscribeOn(scheduler); }) .zipWith(Flux.range(0, Integer.MAX_VALUE)) .doOnNext(i -> { if (!Objects.equals(i.getT1(), i.getT2())) { // System.out.println(i); comparisonFailure.set(true); } }) .count().block(); assertEquals(500L, count); assertFalse(comparisonFailure.get()); }
@Test public void testPrefetchIsBounded() { final AtomicInteger count = new AtomicInteger(); AssertSubscriber<Object> ts = AssertSubscriber.create(0); Flux.just(1).hide() .flatMapSequential(t -> Flux.range(1, Queues.SMALL_BUFFER_SIZE * 2) .doOnNext(t1 -> count.getAndIncrement()) .hide()) .subscribe(ts); ts.assertNoError(); ts.assertNoValues(); ts.assertNotComplete(); Assert.assertEquals(Queues.XS_BUFFER_SIZE, count.get()); }
@Test public void normalFusedSync() { StepVerifier.create(Flux.range(1, 5) .flatMapSequential(t -> Flux.range(t, 2))) .expectNext(1, 2, 2, 3, 3, 4, 4, 5, 5, 6) .verifyComplete(); }
@Test public void contextPassing2() throws InterruptedException { AtomicReference<String> innerC = new AtomicReference<>(); Flux.range(1, 1000) .log() .flatMapSequential(d -> Mono.just(d) .subscriberContext(ctx -> { if (innerC.get() == null) { innerC.set(""+ ctx.get("test") + ctx.get("test2")); } return ctx; }) .log()) .map(d -> d) .take(10) .subscriberContext(ctx -> ctx.put("test", "foo")) .subscriberContext(ctx -> ctx.put("test2", "bar")) .log() .subscribe(); assertThat(innerC.get(), is("foobar")); }
@Test public void testSimple() { Flux.range(1, 100).flatMapSequential(toJust).subscribe(ts); ts.assertNoError(); ts.assertValueCount(100); ts.assertComplete(); }
@Test public void testSimple2() { Flux.range(1, 100).flatMapSequential(toRange).subscribe(ts); ts.assertNoError(); ts.assertValueCount(200); ts.assertComplete(); }
@Test public void normal() { StepVerifier.create(Flux.range(1, 5) .hide() .flatMapSequential(t -> Flux.range(t, 2))) .expectNext(1, 2, 2, 3, 3, 4, 4, 5, 5, 6) .verifyComplete(); }
@Test public void testAsynchronousRun() { Flux.range(1, 2).flatMapSequential(t -> Flux.range(1, 1000) .subscribeOn(Schedulers.single()) ).publishOn(Schedulers.elastic()).subscribe(ts); ts.await(Duration.ofSeconds(5)); ts.assertNoError(); ts.assertValueCount(2000); }
@Test public void longEager() { Flux.range(1, 2 * Queues.SMALL_BUFFER_SIZE) .flatMapSequential(v -> Flux.just(1)) .subscribeWith(AssertSubscriber.create()) .assertValueCount(2 * Queues.SMALL_BUFFER_SIZE) .assertNoError() .assertComplete(); }
.flatMapSequential(d -> Mono.just(d)
@Test public void normalBackpressured() { AssertSubscriber<Integer> ts = Flux.range(1, 5) .hide() .flatMapSequential(t -> Flux.range(t, 2)) .subscribeWith(AssertSubscriber.create(3)); ts.assertValues(1, 2, 2); ts.request(1); ts.assertValues(1, 2, 2, 3); ts.request(1); ts.assertValues(1, 2, 2, 3, 3); ts.request(5); ts.assertComplete().assertValues(1, 2, 2, 3, 3, 4, 4, 5, 5, 6); }