use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxUsingTest method normalEager.
@Test
public void normalEager() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicInteger cleanup = new AtomicInteger();
Flux.using(() -> 1, r -> Flux.range(r, 10), cleanup::set).subscribe(ts);
ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).assertComplete().assertNoError();
Assert.assertEquals(1, cleanup.get());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxUsingTest method subscriberCancels.
@Test
public void subscriberCancels() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicInteger cleanup = new AtomicInteger();
DirectProcessor<Integer> tp = DirectProcessor.create();
Flux.using(() -> 1, r -> tp, cleanup::set, true).subscribe(ts);
Assert.assertTrue("No subscriber?", tp.hasDownstreams());
tp.onNext(1);
ts.assertValues(1).assertNotComplete().assertNoError();
ts.cancel();
tp.onNext(2);
ts.assertValues(1).assertNotComplete().assertNoError();
Assert.assertFalse("Has subscriber?", tp.hasDownstreams());
Assert.assertEquals(1, cleanup.get());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxDoOnEachTest method completeCallbackError.
@Test
public void completeCallbackError() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
LongAdder state = new LongAdder();
Throwable err = new Exception("test");
Flux.just(1).doOnEach(s -> {
if (s.isOnComplete()) {
state.increment();
throw Exceptions.propagate(err);
}
}).subscribe(ts);
ts.assertErrorMessage("test");
Assert.assertEquals(1, state.intValue());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxDoOnEachTest method empty.
@Test
public void empty() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicReference<Integer> onNext = new AtomicReference<>();
AtomicReference<Throwable> onError = new AtomicReference<>();
AtomicBoolean onComplete = new AtomicBoolean();
LongAdder state = new LongAdder();
Flux.empty().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.assertTrue(onComplete.get());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxDoOnEachTest method error.
@Test
public void error() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicReference<Integer> onNext = new AtomicReference<>();
AtomicReference<Throwable> onError = new AtomicReference<>();
AtomicBoolean onComplete = new AtomicBoolean();
LongAdder state = new LongAdder();
Flux.error(new RuntimeException("forced " + "failure")).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.assertTrue(onError.get() instanceof RuntimeException);
Assert.assertFalse(onComplete.get());
}
Aggregations