public void start() { this.subscription = Flux.interval(this.checkReminderInverval, Schedulers.newSingle("reminders")) .log(log.getName(), Level.FINEST) .doOnSubscribe(s -> log.debug("Started reminders")) .flatMap(i -> this.sendReminders()) .onErrorContinue((ex, value) -> log.warn( "Unexpected error while sending reminders", ex )) .subscribe(); }
public void start() { subscription = Flux.from(publisher) .log(log.getName(), Level.FINEST) .doOnSubscribe(s -> log.debug("Subscribed to {} events", eventType)) .ofType(eventType) .cast(eventType) .compose(this::handle) .onErrorContinue((ex, value) -> log.warn("Unexpected error while handling {}", value, ex)) .subscribe(); }
@Override public void start() { super.start(); intervalSubscription = Flux.interval(updateInterval) .doOnSubscribe(s -> log.debug("Scheduled status update every {}", updateInterval)) .log(log.getName(), Level.FINEST) .subscribeOn(Schedulers.newSingle("status-monitor")) .concatMap(i -> this.updateStatusForAllInstances()) .onErrorContinue((ex, value) -> log.warn("Unexpected error while updating statuses", ex )) .subscribe(); }
public Flux<Integer> commit() { System.out.println("commit"); this.commitProbe = PublisherProbe.of( Flux.just(3, 2, 1) .log("commit method used", level, SignalType.ON_NEXT, SignalType.ON_COMPLETE)); return commitProbe.flux(); }
@Test public void sampleMergeMonoTest() throws Exception { CountDownLatch latch = new CountDownLatch(2); Flux<Integer> p = Flux.merge(Flux.<Integer>empty().next(), Mono.just(1)) .log("mono"); awaitLatch(p, latch); }
public Flux<Integer> commitError() { this.commitProbe = PublisherProbe.of( Flux.just(3, 2, 1) .delayElements(DELAY) .map(i -> 100 / (i - 1)) //results in divide by 0 .log("commit method used", level, SignalType.ON_NEXT, SignalType.ON_COMPLETE)); return commitProbe.flux(); }
public Flux<Integer> rollback() { this.rollbackProbe = PublisherProbe.of( Flux.just(5, 4, 3, 2, 1) .log("rollback method used", level, SignalType.ON_NEXT, SignalType.ON_COMPLETE)); return rollbackProbe.flux(); }
@Test public void sampleAmbTest() throws Exception { int elements = 40; CountDownLatch latch = new CountDownLatch(elements / 2 + 1); Flux<SensorData> p = Flux.first(sensorOdd(), sensorEven()) .log("first"); p.subscribe(d -> latch.countDown(), null, latch::countDown); Thread.sleep(1000); generateData(elements); }
@Test public void cancelEvictAll() { StepVerifier.create(Flux.range(1, 5) .log() .onBackpressureBuffer(Duration.ofMinutes(1), Integer.MAX_VALUE, this, Schedulers.single()), 0) .thenAwait(Duration.ofMillis(100)) //small hiccup to cancel after the prefetch .thenCancel() .verify(); assertThat(evicted).containsExactly(1, 2, 3, 4, 5); }
public Flux<Integer> commitDelay() { this.commitProbe = PublisherProbe.of( Flux.just(3, 2, 1) .delayElements(DELAY) .log("commit method used", level, SignalType.ON_NEXT, SignalType.ON_COMPLETE)); return commitProbe.flux(); }
public Flux<Integer> rollbackDelay() { this.rollbackProbe = PublisherProbe.of( Flux.just(5, 4, 3, 2, 1) .delayElements(DELAY) .log("rollback method used", level, SignalType.ON_NEXT, SignalType.ON_COMPLETE)); return rollbackProbe.flux(); }
@Test public void sampleZipTest() throws Exception { int elements = 69; CountDownLatch latch = new CountDownLatch((elements / 2) + 1); Publisher<SensorData> p = Flux.zip(sensorEven(), sensorOdd(), this::computeMin) .log("zip"); generateData(elements); awaitLatch(p, latch); }
@Test public void sampleMergeTest() throws Exception { int elements = 40; CountDownLatch latch = new CountDownLatch(elements + 1); Publisher<SensorData> p = Flux.merge(sensorOdd(), sensorEven()) .log("merge"); generateData(elements); awaitLatch(p, latch); }
@Test public void sampleZipTest2() throws Exception { int elements = 1; CountDownLatch latch = new CountDownLatch(elements + 1); Publisher<SensorData> p = Flux.zip(sensorEven(), Flux.just(new SensorData(1L, 14.0f)), this::computeMin) .log("zip2"); generateData(elements); awaitLatch(p, latch); }
@Test public void expectNextCountAfterThenConsumeWhile() { StepVerifier.create(Flux.range(1, 5).log()) .thenConsumeWhile(i -> i <= 2) .expectNextCount(3) .verifyComplete(); }
@Test public void innerCancellationCancelsMainSequence() { StepVerifier.create(Flux.just("red", "green", "#", "black", "white") .log() .windowWhile(s -> !s.equals("#")) .flatMap(w -> w.take(1))) .expectNext("red") .thenCancel() .verify(); }
@Test public void testGreen() { FluxProcessor<String, String> processor = EmitterProcessor.create(); AssertSubscriber<String> subscriber = AssertSubscriber.create(1); processor.subscribe(subscriber); Flux.fromIterable(DATA) .log() .subscribe(processor); subscriber.awaitAndAssertNextValues("1"); }
@Test public void mergeWithNoInterleave() throws Exception{ Flux.concat(emitter1.log("test1"), emitter2.log("test2")).log().subscribe(ts); emitValues(); ts.assertValues(1L, 3L, 2L, 4L).assertComplete(); }
@Test public void secondWinner() { AssertSubscriber<Integer> ts = AssertSubscriber.create(); Flux.first(Flux.never(), Flux.range(11, 10) .log()) .subscribe(ts); ts.assertValues(11, 12, 13, 14, 15, 16, 17, 18, 19, 20) .assertComplete() .assertNoError(); }
@Test public void verifyVirtualTimeOnComplete() { StepVerifier.withVirtualTime(() -> Flux.empty() .delaySubscription(Duration.ofHours(1)) .log()) .thenAwait(Duration.ofHours(1)) .expectComplete() .verify(); }