use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoDoOnEachTest method empty.
@Test
public void empty() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicInteger onNext = new AtomicInteger();
AtomicReference<Throwable> onError = new AtomicReference<>();
AtomicBoolean onComplete = new AtomicBoolean();
Mono.<Integer>empty().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()).isNull();
assertThat(onComplete.get()).isTrue();
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoDoOnEachTest method never.
@Test
public void never() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicInteger onNext = new AtomicInteger();
AtomicReference<Throwable> onError = new AtomicReference<>();
AtomicBoolean onComplete = new AtomicBoolean();
Mono.<Integer>never().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()).isNull();
assertThat(onComplete.get()).isFalse();
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoExpandTest method depthCancelRace2.
@Test
public void depthCancelRace2() throws Exception {
for (int i = 0; i < 1000; i++) {
final TestPublisher<Integer> pp = TestPublisher.create();
Flux<Integer> source = Mono.just(0).expandDeep(it -> pp);
final CountDownLatch cdl = new CountDownLatch(1);
AssertSubscriber<Integer> ts = new AssertSubscriber<Integer>() {
final AtomicInteger sync = new AtomicInteger(2);
@Override
public void onNext(Integer t) {
super.onNext(t);
Schedulers.single().schedule(() -> {
if (sync.decrementAndGet() != 0) {
while (sync.get() != 0) {
}
}
cancel();
cdl.countDown();
});
if (sync.decrementAndGet() != 0) {
while (sync.get() != 0) {
}
}
}
};
source.subscribe(ts);
assertThat(cdl.await(5, TimeUnit.SECONDS)).as("runs under 5s").isTrue();
}
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxPeekFuseableTest method syncFusionAvailable.
@Test
public void syncFusionAvailable() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 2).doOnNext(v -> {
}).subscribe(ts);
Subscription s = ts.upstream();
Assert.assertTrue("Non-fuseable upstream: " + s, s instanceof Fuseable.QueueSubscription);
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxPublishOnTest method rejectedExecutionExceptionOnErrorSignalExecutorService.
@Test(timeout = 5000)
public void rejectedExecutionExceptionOnErrorSignalExecutorService() throws InterruptedException {
Exception exception = new IllegalStateException();
final AtomicReference<Throwable> throwableInOnOperatorError = new AtomicReference<>();
final AtomicReference<Object> dataInOnOperatorError = new AtomicReference<>();
try {
CountDownLatch hookLatch = new CountDownLatch(2);
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<>();
Flux.range(0, 5).publishOn(fromExecutorService(executor)).doOnNext(s -> {
try {
latch.await();
} catch (InterruptedException e) {
throw Exceptions.propagate(exception);
}
}).publishOn(fromExecutorService(executor)).subscribe(assertSubscriber);
executor.shutdownNow();
assertSubscriber.assertNoValues().assertNoError().assertNotComplete();
hookLatch.await();
Assert.assertThat(throwableInOnOperatorError.get(), CoreMatchers.instanceOf(RejectedExecutionException.class));
Assert.assertSame(throwableInOnOperatorError.get().getSuppressed()[0], exception);
} finally {
Hooks.resetOnOperatorError();
}
}
Aggregations