use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxDoOnEachTest method nextCallbackError.
@Test
public void nextCallbackError() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
LongAdder state = new LongAdder();
Throwable err = new Exception("test");
Flux.just(1).doOnEach(s -> {
if (s.isOnNext()) {
state.increment();
throw Exceptions.propagate(err);
}
}).subscribe(ts);
// nominal error path (DownstreamException)
ts.assertErrorMessage("test");
Assert.assertEquals(1, state.intValue());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxDoOnEachTest method never.
@Test
public void never() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicReference<Integer> onNext = new AtomicReference<>();
AtomicReference<Throwable> onError = new AtomicReference<>();
AtomicBoolean onComplete = new AtomicBoolean();
LongAdder state = new LongAdder();
Flux.never().cast(Integer.class).doOnEach(s -> {
if (s.isOnNext()) {
onNext.set(s.get());
state.increment();
} else if (s.isOnError()) {
onError.set(s.getThrowable());
} else if (s.isOnComplete()) {
onComplete.set(true);
}
}).subscribe(ts);
Assert.assertNull(onNext.get());
Assert.assertNull(onError.get());
Assert.assertFalse(onComplete.get());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxDoOnEachTest method errorCallbackError.
@Test
public void errorCallbackError() {
AssertSubscriber<String> ts = AssertSubscriber.create();
LongAdder state = new LongAdder();
IllegalStateException err = new IllegalStateException("test");
Flux.error(new IllegalStateException("bar")).cast(String.class).doOnEach(s -> {
if (s.isOnError()) {
state.increment();
throw Exceptions.propagate(err);
}
}).subscribe(ts);
ts.assertNoValues();
ts.assertError(IllegalStateException.class);
ts.assertErrorWith(e -> e.getSuppressed()[0].getMessage().equals("bar"));
Assert.assertEquals(1, state.intValue());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxDoOnEachTest method normal.
@Test
public void normal() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicReference<Integer> onNext = new AtomicReference<>();
AtomicReference<Throwable> onError = new AtomicReference<>();
AtomicBoolean onComplete = new AtomicBoolean();
LongAdder state = new LongAdder();
Flux.just(1, 2).hide().doOnEach(s -> {
if (s.isOnNext()) {
onNext.set(s.get());
state.increment();
} else if (s.isOnError()) {
onError.set(s.getThrowable());
} else if (s.isOnComplete()) {
onComplete.set(true);
}
}).subscribe(ts);
Assert.assertEquals((Integer) 2, onNext.get());
Assert.assertNull(onError.get());
Assert.assertTrue(onComplete.get());
Assert.assertEquals(2, state.intValue());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoUsingTest method subscriberCancels.
@Test
public void subscriberCancels() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicInteger cleanup = new AtomicInteger();
MonoProcessor<Integer> tp = MonoProcessor.create();
Mono.using(() -> 1, r -> tp, cleanup::set, true).subscribe(ts);
Assert.assertTrue("No subscriber?", tp.hasDownstreams());
tp.onNext(1);
ts.assertValues(1).assertComplete().assertNoError();
Assert.assertEquals(1, cleanup.get());
}
Aggregations