use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxUsingTest method normal.
@Test
public void normal() {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicInteger cleanup = new AtomicInteger();
Flux.using(() -> 1, r -> Flux.range(r, 10), cleanup::set, false).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 factoryThrowsEager.
@Test
public void factoryThrowsEager() {
AssertSubscriber<Object> ts = AssertSubscriber.create();
AtomicInteger cleanup = new AtomicInteger();
Flux.using(() -> 1, r -> {
throw new RuntimeException("forced failure");
}, cleanup::set, false).subscribe(ts);
ts.assertNoValues().assertNotComplete().assertError(RuntimeException.class).assertErrorMessage("forced failure");
Assert.assertEquals(1, cleanup.get());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class FluxUsingTest method factoryReturnsNull.
@Test
public void factoryReturnsNull() {
AssertSubscriber<Object> ts = AssertSubscriber.create();
AtomicInteger cleanup = new AtomicInteger();
Flux.<Integer, Integer>using(() -> 1, r -> null, cleanup::set, false).subscribe(ts);
ts.assertNoValues().assertNotComplete().assertError(NullPointerException.class);
Assert.assertEquals(1, cleanup.get());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoPublishOnTest method rejectedExecutionExceptionOnErrorSignalExecutor.
@Test
public void rejectedExecutionExceptionOnErrorSignalExecutor() throws InterruptedException {
int data = 1;
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<>();
Mono.just(data).publishOn(fromExecutorService(executor)).doOnNext(s -> {
try {
latch.await();
} catch (InterruptedException e) {
throw Exceptions.propagate(exception);
}
}).publishOn(fromExecutor(executor)).subscribe(assertSubscriber);
executor.shutdownNow();
assertSubscriber.assertNoValues().assertNoError().assertNotComplete();
hookLatch.await();
assertThat(throwableInOnOperatorError.get(), instanceOf(RejectedExecutionException.class));
Assert.assertSame(throwableInOnOperatorError.get().getSuppressed()[0], exception);
} finally {
Hooks.resetOnOperatorError();
}
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoPublishOnTest method rejectedExecutionExceptionOnErrorSignalExecutorService.
@Test
public void rejectedExecutionExceptionOnErrorSignalExecutorService() throws InterruptedException {
int data = 1;
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<>();
Mono.just(data).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();
assertThat(throwableInOnOperatorError.get(), instanceOf(RejectedExecutionException.class));
Assert.assertSame(throwableInOnOperatorError.get().getSuppressed()[0], exception);
} finally {
Hooks.resetOnOperatorError();
}
}
Aggregations