use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class ParallelFluxTest method parallelMode.
@Test
public void parallelMode() {
Flux<Integer> source = Flux.range(1, 1_000_000).hide();
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 MonoPublishOnTest method rejectedExecutionExceptionOnDataSignalExecutorService.
@Test
public void rejectedExecutionExceptionOnDataSignalExecutorService() throws InterruptedException {
int data = 1;
final AtomicReference<Throwable> throwableInOnOperatorError = new AtomicReference<>();
final AtomicReference<Object> dataInOnOperatorError = new AtomicReference<>();
try {
CountDownLatch hookLatch = new CountDownLatch(1);
Hooks.onOperatorError((t, d) -> {
throwableInOnOperatorError.set(t);
dataInOnOperatorError.set(d);
hookLatch.countDown();
return t;
});
ExecutorService executor = newCachedThreadPool();
CountDownLatch latch = new CountDownLatch(1);
AssertSubscriber<Integer> assertSubscriber = new AssertSubscriber<>();
Mono.just(data).publishOn(fromExecutorService(executor)).doOnNext(s -> {
try {
latch.await();
} catch (InterruptedException e) {
}
}).publishOn(fromExecutorService(executor)).subscribe(assertSubscriber);
executor.shutdownNow();
assertSubscriber.assertNoValues().assertNoError().assertNotComplete();
hookLatch.await();
assertThat(throwableInOnOperatorError.get(), instanceOf(RejectedExecutionException.class));
Assert.assertSame(dataInOnOperatorError.get(), data);
} finally {
Hooks.resetOnOperatorError();
}
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoPublishOnTest method rejectedExecutionExceptionOnDataSignalExecutor.
@Test
public void rejectedExecutionExceptionOnDataSignalExecutor() throws InterruptedException {
int data = 1;
final AtomicReference<Throwable> throwableInOnOperatorError = new AtomicReference<>();
final AtomicReference<Object> dataInOnOperatorError = new AtomicReference<>();
try {
CountDownLatch hookLatch = new CountDownLatch(1);
Hooks.onOperatorError((t, d) -> {
throwableInOnOperatorError.set(t);
dataInOnOperatorError.set(d);
hookLatch.countDown();
return t;
});
ExecutorService executor = newCachedThreadPool();
CountDownLatch latch = new CountDownLatch(1);
AssertSubscriber<Integer> assertSubscriber = new AssertSubscriber<>();
Mono.just(data).publishOn(fromExecutorService(executor)).doOnNext(s -> {
try {
latch.await();
} catch (InterruptedException e) {
}
}).publishOn(fromExecutor(executor)).subscribe(assertSubscriber);
executor.shutdownNow();
assertSubscriber.assertNoValues().assertNoError().assertNotComplete();
hookLatch.await();
assertThat(throwableInOnOperatorError.get(), instanceOf(RejectedExecutionException.class));
Assert.assertSame(dataInOnOperatorError.get(), data);
} finally {
Hooks.resetOnOperatorError();
}
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoRepeatWhenEmptyTest method repeatFinite.
@Test
public void repeatFinite() {
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(1000, 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 MonoDoOnEachTest method normal.
@Test
public void normal() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicInteger onNext = new AtomicInteger();
AtomicReference<Throwable> onError = new AtomicReference<>();
AtomicBoolean onComplete = new AtomicBoolean();
Mono.just(1).hide().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()).isEqualTo(1);
assertThat(onError.get()).isNull();
assertThat(onComplete.get()).isTrue();
}
Aggregations