use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoUsingTest method checkCleanupExecutionTime.
void checkCleanupExecutionTime(boolean eager, boolean fail) {
AtomicInteger cleanup = new AtomicInteger();
AtomicBoolean before = new AtomicBoolean();
AssertSubscriber<Integer> ts = new AssertSubscriber<Integer>() {
@Override
public void onError(Throwable t) {
super.onError(t);
before.set(cleanup.get() != 0);
}
@Override
public void onComplete() {
super.onComplete();
before.set(cleanup.get() != 0);
}
};
Mono.using(() -> 1, r -> {
if (fail) {
return Mono.error(new RuntimeException("forced failure"));
}
return Mono.just(1);
}, cleanup::set, eager).subscribe(ts);
if (fail) {
ts.assertNoValues().assertError(RuntimeException.class).assertNotComplete().assertErrorMessage("forced failure");
} else {
ts.assertValues(1).assertComplete().assertNoError();
}
Assert.assertEquals(1, cleanup.get());
Assert.assertEquals(eager, before.get());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoUsingTest method resourceThrowsEager.
@Test
public void resourceThrowsEager() {
AssertSubscriber<Object> ts = AssertSubscriber.create();
AtomicInteger cleanup = new AtomicInteger();
Mono.using(() -> {
throw new RuntimeException("forced failure");
}, r -> Mono.just(1), cleanup::set, false).subscribe(ts);
ts.assertNoValues().assertNotComplete().assertError(RuntimeException.class).assertErrorMessage("forced failure");
Assert.assertEquals(0, cleanup.get());
}
use of reactor.test.subscriber.AssertSubscriber in project reactor-core by reactor.
the class MonoUsingTest method factoryReturnsNull.
@Test
public void factoryReturnsNull() {
AssertSubscriber<Object> ts = AssertSubscriber.create();
AtomicInteger cleanup = new AtomicInteger();
Mono.<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 MonoUsingTest method factoryThrowsEager.
@Test
public void factoryThrowsEager() {
AssertSubscriber<Object> ts = AssertSubscriber.create();
AtomicInteger cleanup = new AtomicInteger();
Mono.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 ParallelReduceSeedTest method collectAsync3Take.
@Test
public void collectAsync3Take() {
Scheduler s = Schedulers.newParallel("test", 4);
Supplier<List<Integer>> as = () -> new ArrayList<>();
AssertSubscriber<Integer> ts = AssertSubscriber.create();
Flux.range(1, 100000).publishOn(s).parallel(3).runOn(s).collect(as, (a, b) -> a.add(b)).doOnNext(v -> System.out.println(v.size())).groups().flatMap(v -> v).reduce(0, (a, b) -> b.size() + a).subscribe(ts);
ts.await(Duration.ofSeconds(5));
ts.assertValues(100_000).assertNoError().assertComplete();
}
Aggregations