@Test public void contextTest() { StepVerifier.create(Flux.generate(s -> s.next(s.currentContext() .get(AtomicInteger.class) .incrementAndGet())) .take(10) .subscriberContext(ctx -> ctx.put(AtomicInteger.class, new AtomicInteger()))) .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .verifyComplete(); }
@Test public void contextTest() { StepVerifier.create(Flux.just("foo") .handle((d, s) -> s.next(s.currentContext() .get(AtomicInteger.class) .incrementAndGet())) .repeat(9) .subscriberContext(ctx -> ctx.put(AtomicInteger.class, new AtomicInteger()))) .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .verifyComplete(); }
@Test public void contextGetMono() throws InterruptedException { StepVerifier.create(Mono.just(1) .log() .handle((d, c) -> c.next(c.currentContext().get("test") + "" + d)) .handle((d, c) -> c.next(c.currentContext().get("test2") + "" + d)) .subscriberContext(ctx -> ctx.put("test2", "bar")) .subscriberContext(ctx -> ctx.put("test", "foo")) .log()) .expectNext("barfoo1") .verifyComplete(); }
@Test public void contextGetHideMono() throws InterruptedException { StepVerifier.create(Mono.just(1) .hide() .log() .handle((d, c) -> c.next(c.currentContext().get("test") + "" + d)) .handle((d, c) -> c.next(c.currentContext().get("test2") + "" + d)) .subscriberContext(ctx -> ctx.put("test", "foo")) .subscriberContext(ctx -> ctx.put("test2", "bar")) .log()) .expectNext("barfoo1") .verifyComplete(); }
@Test public void contextTestHide() { StepVerifier.create(Flux.just("foo") .hide() .handle((d, s) -> s.next(s.currentContext() .get(AtomicInteger.class) .incrementAndGet())) .repeat(9) .subscriberContext(ctx -> ctx.put(AtomicInteger.class, new AtomicInteger()))) .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .verifyComplete(); }
@Test public void contextTestFilterHide() { StepVerifier.create(Flux.just("foo") .handle((d, s) -> s.next(s.currentContext() .get(AtomicInteger.class) .incrementAndGet())) .filter(d -> true) .repeat(9) .subscriberContext(ctx -> ctx.put(AtomicInteger.class, new AtomicInteger()))) .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .verifyComplete(); }
@Test public void contextTestFilter() { StepVerifier.create(Flux.just("foo") .handle((d, s) -> s.next(s.currentContext() .get(AtomicInteger.class) .incrementAndGet())) .filter(d -> true) .repeat(9) .subscriberContext(ctx -> ctx.put(AtomicInteger.class, new AtomicInteger()))) .expectNext(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .verifyComplete(); } @Test
@Test public void contextGetHide() throws InterruptedException { StepVerifier.create(Flux.range(1, 1000) .hide() .log() .map(d -> d) .handle((d, c) -> c.next(c.currentContext().get("test") + "" + d)) .skip(3) .take(3) .handle((d, c) -> c.next(c.currentContext().get("test2") + "" + d)) .subscriberContext(ctx -> ctx.put("test", "foo")) .subscriberContext(ctx -> ctx.put("test2", "bar")) .log()) .expectNext("barfoo4") .expectNext("barfoo5") .expectNext("barfoo6") .verifyComplete(); }
@Test public void contextGet() throws InterruptedException { StepVerifier.create(Flux.range(1, 1000) .log() .handle((d, c) -> c.next(c.currentContext().get("test") + "" + d)) .skip(3) .take(3) .handle((d, c) -> c.next(c.currentContext().get("test2") + "" + d)) .subscriberContext(ctx -> ctx.put("test", "foo")) .subscriberContext(ctx -> ctx.put("test2", "bar")) .log()) .expectNext("barfoo4") .expectNext("barfoo5") .expectNext("barfoo6") .verifyComplete(); }