use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoRepeatWhenEmptyTest method repeatInfinite.
@Test
public void repeatInfinite() {
AtomicInteger c = new AtomicInteger();
Mono<String> source = Mono.defer(() -> c.getAndIncrement() < 3 ? Mono.empty() : Mono.just("test-data"));
List<Long> iterations = new ArrayList<>();
AssertSubscriber<String> ts = AssertSubscriber.create();
source.repeatWhenEmpty(o -> o.doOnNext(iterations::add)).subscribe(ts);
ts.assertValues("test-data").assertComplete().assertNoError();
Assert.assertEquals(4, c.get());
Assert.assertEquals(Arrays.asList(0L, 1L, 2L), iterations);
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoRepeatWhenEmptyTest method repeatFiniteExceeded.
@Test
public void repeatFiniteExceeded() {
AtomicInteger c = new AtomicInteger();
Mono<String> source = Mono.defer(() -> c.getAndIncrement() < 3 ? Mono.empty() : Mono.just("test-data"));
List<Long> iterations = new ArrayList<>();
AssertSubscriber<String> ts = AssertSubscriber.create();
source.repeatWhenEmpty(2, o -> o.doOnNext(iterations::add)).subscribe(ts);
ts.assertError(IllegalStateException.class);
Assert.assertEquals(3, c.get());
Assert.assertEquals(Arrays.asList(0L, 1L), iterations);
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoDoOnEachTest method error.
@Test
public void error() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicInteger onNext = new AtomicInteger();
AtomicReference<Throwable> onError = new AtomicReference<>();
AtomicBoolean onComplete = new AtomicBoolean();
Mono.<Integer>error(new RuntimeException("forced failure")).doOnEach(s -> {
if (s.isOnNext()) {
onNext.incrementAndGet();
} else if (s.isOnError()) {
onError.set(s.getThrowable());
} else if (s.isOnComplete()) {
onComplete.set(true);
}
}).subscribe(ts);
assertThat(onNext.get()).isZero();
assertThat(onError.get()).isInstanceOf(RuntimeException.class).hasMessage("forced failure");
assertThat(onComplete.get()).isFalse();
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class ParallelFluxTest method parallelModeFused.
@Test
public void parallelModeFused() {
Flux<Integer> source = Flux.range(1, 1_000_000);
int ncpu = Math.max(8, Runtime.getRuntime().availableProcessors());
for (int i = 1; i < ncpu + 1; i++) {
Scheduler scheduler = Schedulers.newParallel("test", i);
try {
Flux<Integer> result = ParallelFlux.from(source, i).runOn(scheduler).map(v -> v + 1).sequential();
AssertSubscriber<Integer> ts = AssertSubscriber.create();
result.subscribe(ts);
ts.await(Duration.ofSeconds(10));
ts.assertSubscribed().assertValueCount(1_000_000).assertComplete().assertNoError();
} finally {
scheduler.dispose();
}
}
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class ParallelMergeReduceTest method parallelReduceFull.
@Test
public void parallelReduceFull() {
int m = 100_000;
for (int n = 1; n <= m; n *= 10) {
// System.out.println(n);
for (int i = 1; i <= Runtime.getRuntime().availableProcessors(); i++) {
// System.out.println(" " + i);
Scheduler scheduler = Schedulers.newParallel("test", i);
try {
AssertSubscriber<Long> ts = AssertSubscriber.create();
Flux.range(1, n).map(v -> (long) v).parallel(i).runOn(scheduler).reduce((a, b) -> a + b).subscribe(ts);
ts.await(Duration.ofSeconds(500));
long e = ((long) n) * (1 + n) / 2;
ts.assertValues(e);
} finally {
scheduler.dispose();
}
}
}
}
Aggregations