use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.
the class CompletableMergeArrayDelayError method subscribeActual.
@Override
public void subscribeActual(final CompletableObserver observer) {
final CompositeDisposable set = new CompositeDisposable();
final AtomicInteger wip = new AtomicInteger(sources.length + 1);
final AtomicThrowable errors = new AtomicThrowable();
set.add(new TryTerminateAndReportDisposable(errors));
observer.onSubscribe(set);
for (CompletableSource c : sources) {
if (set.isDisposed()) {
return;
}
if (c == null) {
Throwable ex = new NullPointerException("A completable source is null");
errors.tryAddThrowableOrReport(ex);
wip.decrementAndGet();
continue;
}
c.subscribe(new MergeInnerCompletableObserver(observer, set, errors, wip));
}
if (wip.decrementAndGet() == 0) {
errors.tryTerminateConsumer(observer);
}
}
use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.
the class CompletableSwitchOnNextTest method delaySwitch.
@Test
public void delaySwitch() {
PublishProcessor<Completable> pp = PublishProcessor.create();
TestObserver<Void> to = Completable.switchOnNextDelayError(pp).test();
assertTrue(pp.hasSubscribers());
to.assertEmpty();
CompletableSubject cs1 = CompletableSubject.create();
CompletableSubject cs2 = CompletableSubject.create();
pp.onNext(cs1);
assertTrue(cs1.hasObservers());
pp.onNext(cs2);
assertFalse(cs1.hasObservers());
assertTrue(cs2.hasObservers());
assertTrue(cs2.hasObservers());
cs2.onError(new TestException());
assertTrue(pp.hasSubscribers());
to.assertEmpty();
pp.onComplete();
to.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.
the class CompletableTimeoutTest method timeoutContinueOther.
@Test
public void timeoutContinueOther() throws Exception {
final int[] call = { 0 };
Completable other = Completable.fromAction(new Action() {
@Override
public void run() throws Exception {
call[0]++;
}
});
Completable.never().timeout(100, TimeUnit.MILLISECONDS, Schedulers.io(), other).test().awaitDone(5, TimeUnit.SECONDS).assertResult();
assertEquals(1, call[0]);
}
use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.
the class CompletableMergeTest method mainErrorInnerErrorRace.
@Test
public void mainErrorInnerErrorRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final PublishProcessor<Integer> pp1 = PublishProcessor.create();
final PublishProcessor<Integer> pp2 = PublishProcessor.create();
TestObserverEx<Void> to = Completable.merge(pp1.map(new Function<Integer, Completable>() {
@Override
public Completable apply(Integer v) throws Exception {
return pp2.ignoreElements();
}
})).to(TestHelper.<Void>testConsumer());
pp1.onNext(1);
final Throwable ex1 = new TestException();
final Throwable ex2 = new TestException();
Runnable r1 = new Runnable() {
@Override
public void run() {
pp1.onError(ex1);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
pp2.onError(ex2);
}
};
TestHelper.race(r1, r2);
Throwable ex = to.errors().get(0);
if (ex instanceof CompositeException) {
to.assertSubscribed().assertNoValues().assertNotComplete();
errors = TestHelper.compositeList(ex);
TestHelper.assertError(errors, 0, TestException.class);
TestHelper.assertError(errors, 1, TestException.class);
} else {
to.assertFailure(TestException.class);
if (!errors.isEmpty()) {
TestHelper.assertUndeliverable(errors, 0, TestException.class);
}
}
} finally {
RxJavaPlugins.reset();
}
}
}
use of io.reactivex.rxjava3.core.Completable in project RxJava by ReactiveX.
the class CompletableSafeSubscribeTest method onErrorCrash.
@Test
public void onErrorCrash() throws Throwable {
TestHelper.withErrorTracking(errors -> {
CompletableObserver consumer = mock(CompletableObserver.class);
doThrow(new TestException()).when(consumer).onError(any());
new Completable() {
@Override
protected void subscribeActual(@NonNull CompletableObserver 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);
});
}
Aggregations