use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class MaybeDoFinallyTest method actionThrowsConditional.
@Test
public void actionThrowsConditional() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
Maybe.just(1).doFinally(new Action() {
@Override
public void run() throws Exception {
throw new TestException();
}
}).filter(Functions.alwaysTrue()).test().assertResult(1).dispose();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class MaybeBlockingSubscribeTest method threeArgEmptyFails.
@Test
public void threeArgEmptyFails() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") Consumer<Integer> success = mock(Consumer.class);
@SuppressWarnings("unchecked") Consumer<? super Throwable> consumer = mock(Consumer.class);
Action action = mock(Action.class);
doThrow(new TestException()).when(action).run();
Maybe.<Integer>empty().delay(50, TimeUnit.MILLISECONDS, Schedulers.computation()).blockingSubscribe(success, consumer, action);
TestHelper.assertUndeliverable(errors, 0, TestException.class);
verify(success, never()).accept(any());
verify(consumer, never()).accept(any());
verify(action).run();
});
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class SingleDoOnLifecycleTest method onDisposeCrash.
@Test
public void onDisposeCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") Consumer<? super Disposable> onSubscribe = mock(Consumer.class);
Action onDispose = mock(Action.class);
doThrow(new TestException("First")).when(onDispose).run();
SingleSubject<Integer> ss = SingleSubject.create();
TestObserver<Integer> to = ss.doOnLifecycle(onSubscribe, onDispose).test();
assertTrue(ss.hasObservers());
to.dispose();
assertFalse(ss.hasObservers());
TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
verify(onSubscribe).accept(any());
verify(onDispose).run();
});
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class SingleDoOnTerminateTest method doOnTerminateErrorCrash.
@Test
public void doOnTerminateErrorCrash() {
TestObserverEx<Object> to = Single.error(new TestException("Outer")).doOnTerminate(new Action() {
@Override
public void run() {
throw new TestException("Inner");
}
}).to(TestHelper.testConsumer()).assertFailure(CompositeException.class);
List<Throwable> errors = TestHelper.compositeList(to.errors().get(0));
TestHelper.assertError(errors, 0, TestException.class, "Outer");
TestHelper.assertError(errors, 1, TestException.class, "Inner");
}
use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.
the class TrampolineSchedulerTest method trampolineWorkerHandlesConcurrentScheduling.
/**
* This is a regression test for #1702. Concurrent work scheduling that is improperly synchronized can cause an
* action to be added or removed onto the priority queue during a poll, which can result in NPEs during queue
* sifting. While it is difficult to isolate the issue directly, we can easily trigger the behavior by spamming the
* trampoline with enqueue requests from multiple threads concurrently.
*/
@Test
public void trampolineWorkerHandlesConcurrentScheduling() {
final Worker trampolineWorker = Schedulers.trampoline().createWorker();
final Subscriber<Object> subscriber = TestHelper.mockSubscriber();
final TestSubscriber<Disposable> ts = new TestSubscriber<>(subscriber);
// Spam the trampoline with actions.
Flowable.range(0, 50).flatMap(new Function<Integer, Publisher<Disposable>>() {
@Override
public Publisher<Disposable> apply(Integer count) {
return Flowable.interval(1, TimeUnit.MICROSECONDS).map(new Function<Long, Disposable>() {
@Override
public Disposable apply(Long ount1) {
return trampolineWorker.schedule(Functions.EMPTY_RUNNABLE);
}
}).take(100);
}
}).subscribeOn(Schedulers.computation()).subscribe(ts);
ts.awaitDone(5, TimeUnit.SECONDS);
ts.assertNoErrors();
}
Aggregations