use of io.reactivex.rxjava3.exceptions.CompositeException in project RxJava by ReactiveX.
the class FlowableSwitchMapCompletableTest method onNextInnerErrorRace.
@Test
public void onNextInnerErrorRace() {
final TestException ex = new TestException();
for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp = PublishProcessor.create();
final CompletableSubject cs = CompletableSubject.create();
TestObserver<Void> to = pp.switchMapCompletable(Functions.justFunction(cs)).test();
pp.onNext(1);
Runnable r1 = new Runnable() {
@Override
public void run() {
pp.onNext(2);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
cs.onError(ex);
}
};
TestHelper.race(r1, r2);
to.assertError(new Predicate<Throwable>() {
@Override
public boolean test(Throwable e) throws Exception {
return e instanceof TestException || e instanceof CompositeException;
}
});
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
} finally {
RxJavaPlugins.reset();
}
}
}
use of io.reactivex.rxjava3.exceptions.CompositeException in project RxJava by ReactiveX.
the class MaybeSafeSubscribeTest method onErrorCrash.
@Test
public void onErrorCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") MaybeObserver<Integer> consumer = mock(MaybeObserver.class);
doThrow(new TestException()).when(consumer).onError(any());
new Maybe<Integer>() {
@Override
protected void subscribeActual(@NonNull MaybeObserver<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
// none of the following should arrive at the consumer
observer.onError(new IOException());
}
}.safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verify(consumer).onError(any(IOException.class));
order.verifyNoMoreInteractions();
TestHelper.assertError(errors, 0, CompositeException.class);
CompositeException compositeException = (CompositeException) errors.get(0);
TestHelper.assertError(compositeException.getExceptions(), 0, IOException.class);
TestHelper.assertError(compositeException.getExceptions(), 1, TestException.class);
});
}
use of io.reactivex.rxjava3.exceptions.CompositeException in project RxJava by ReactiveX.
the class SingleSafeSubscribeTest method onErrorCrash.
@Test
public void onErrorCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
@SuppressWarnings("unchecked") SingleObserver<Integer> consumer = mock(SingleObserver.class);
doThrow(new TestException()).when(consumer).onError(any());
new Single<Integer>() {
@Override
protected void subscribeActual(@NonNull SingleObserver<? super Integer> observer) {
observer.onSubscribe(Disposable.empty());
// none of the following should arrive at the consumer
observer.onError(new IOException());
}
}.safeSubscribe(consumer);
InOrder order = inOrder(consumer);
order.verify(consumer).onSubscribe(any(Disposable.class));
order.verify(consumer).onError(any(IOException.class));
order.verifyNoMoreInteractions();
TestHelper.assertError(errors, 0, CompositeException.class);
CompositeException compositeException = (CompositeException) errors.get(0);
TestHelper.assertError(compositeException.getExceptions(), 0, IOException.class);
TestHelper.assertError(compositeException.getExceptions(), 1, TestException.class);
});
}
use of io.reactivex.rxjava3.exceptions.CompositeException in project RxJava by ReactiveX.
the class BaseTestConsumer method fail.
/**
* Fail with the given message and add the sequence of errors as suppressed ones.
* <p>Note this is deliberately the only fail method. Most of the times an assertion
* would fail but it is possible it was due to an exception somewhere. This construct
* will capture those potential errors and report it along with the original failure.
*
* @param message the message to use
* @return AssertionError the prepared AssertionError instance
*/
@NonNull
protected final AssertionError fail(@NonNull String message) {
StringBuilder b = new StringBuilder(64 + message.length());
b.append(message);
b.append(" (").append("latch = ").append(done.getCount()).append(", ").append("values = ").append(values.size()).append(", ").append("errors = ").append(errors.size()).append(", ").append("completions = ").append(completions);
if (timeout) {
b.append(", timeout!");
}
if (isDisposed()) {
b.append(", disposed!");
}
CharSequence tag = this.tag;
if (tag != null) {
b.append(", tag = ").append(tag);
}
b.append(')');
AssertionError ae = new AssertionError(b.toString());
if (!errors.isEmpty()) {
if (errors.size() == 1) {
ae.initCause(errors.get(0));
} else {
CompositeException ce = new CompositeException(errors);
ae.initCause(ce);
}
}
return ae;
}
use of io.reactivex.rxjava3.exceptions.CompositeException in project RxJava by ReactiveX.
the class ExceptionHelper method flatten.
/**
* Returns a flattened list of Throwables from tree-like CompositeException chain.
* @param t the starting throwable
* @return the list of Throwables flattened in a depth-first manner
*/
public static List<Throwable> flatten(Throwable t) {
List<Throwable> list = new ArrayList<>();
ArrayDeque<Throwable> deque = new ArrayDeque<>();
deque.offer(t);
while (!deque.isEmpty()) {
Throwable e = deque.removeFirst();
if (e instanceof CompositeException) {
CompositeException ce = (CompositeException) e;
List<Throwable> exceptions = ce.getExceptions();
for (int i = exceptions.size() - 1; i >= 0; i--) {
deque.offerFirst(exceptions.get(i));
}
} else {
list.add(e);
}
}
return list;
}
Aggregations