use of io.reactivex.rxjava3.functions.Consumer in project RxAndroid by ReactiveX.
the class HandlerSchedulerTest method throwingActionRoutedToRxJavaPlugins.
@Test
public void throwingActionRoutedToRxJavaPlugins() {
Consumer<? super Throwable> originalErrorHandler = RxJavaPlugins.getErrorHandler();
try {
final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
throwableRef.set(throwable);
}
});
Worker worker = scheduler.createWorker();
final NullPointerException npe = new NullPointerException();
Runnable action = new Runnable() {
@Override
public void run() {
throw npe;
}
};
worker.schedule(action);
runUiThreadTasks();
assertSame(npe, throwableRef.get());
} finally {
RxJavaPlugins.setErrorHandler(originalErrorHandler);
}
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class SingleConsumersTest method onErrorCrash.
@Test
public void onErrorCrash() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
subscribeAutoDispose(processor, composite, this, new Consumer<Throwable>() {
@Override
public void accept(Throwable t) throws Exception {
throw new IOException(t);
}
});
processor.onError(new IllegalArgumentException());
assertTrue(events.toString(), events.isEmpty());
TestHelper.assertError(errors, 0, CompositeException.class);
List<Throwable> inners = TestHelper.compositeList(errors.get(0));
TestHelper.assertError(inners, 0, IllegalArgumentException.class);
TestHelper.assertError(inners, 1, IOException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class MaybeAmbTest method noWinnerSuccessDispose.
@Test
public void noWinnerSuccessDispose() throws Exception {
for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
final AtomicBoolean interrupted = new AtomicBoolean();
final CountDownLatch cdl = new CountDownLatch(1);
Maybe.ambArray(Maybe.just(1).subscribeOn(Schedulers.single()).observeOn(Schedulers.computation()), Maybe.never()).subscribe(new Consumer<Object>() {
@Override
public void accept(Object v) throws Exception {
interrupted.set(Thread.currentThread().isInterrupted());
cdl.countDown();
}
});
assertTrue(cdl.await(500, TimeUnit.SECONDS));
assertFalse("Interrupted!", interrupted.get());
}
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class MaybeAmbTest method noWinnerErrorDispose.
@Test
public void noWinnerErrorDispose() throws Exception {
final TestException ex = new TestException();
for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
final AtomicBoolean interrupted = new AtomicBoolean();
final CountDownLatch cdl = new CountDownLatch(1);
Maybe.ambArray(Maybe.error(ex).subscribeOn(Schedulers.single()).observeOn(Schedulers.computation()), Maybe.never()).subscribe(Functions.emptyConsumer(), new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
interrupted.set(Thread.currentThread().isInterrupted());
cdl.countDown();
}
});
assertTrue(cdl.await(500, TimeUnit.SECONDS));
assertFalse("Interrupted!", interrupted.get());
}
}
use of io.reactivex.rxjava3.functions.Consumer in project RxJava by ReactiveX.
the class MaybeCacheTest method crossCancelOnError.
@Test
public void crossCancelOnError() {
final TestSubscriber<Integer> ts = new TestSubscriber<>();
PublishProcessor<Integer> pp = PublishProcessor.create();
Maybe<Integer> source = pp.singleElement().cache();
source.subscribe(Functions.emptyConsumer(), new Consumer<Object>() {
@Override
public void accept(Object v) throws Exception {
ts.cancel();
}
});
source.toFlowable().subscribe(ts);
pp.onError(new TestException());
ts.assertEmpty();
}
Aggregations