Search in sources :

Example 66 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class CompletableMergeDelayErrorIterable method subscribeActual.

@Override
public void subscribeActual(final CompletableObserver observer) {
    final CompositeDisposable set = new CompositeDisposable();
    observer.onSubscribe(set);
    Iterator<? extends CompletableSource> iterator;
    try {
        iterator = Objects.requireNonNull(sources.iterator(), "The source iterator returned is null");
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        observer.onError(e);
        return;
    }
    final AtomicInteger wip = new AtomicInteger(1);
    final AtomicThrowable errors = new AtomicThrowable();
    set.add(new TryTerminateAndReportDisposable(errors));
    for (; ; ) {
        if (set.isDisposed()) {
            return;
        }
        boolean b;
        try {
            b = iterator.hasNext();
        } catch (Throwable e) {
            Exceptions.throwIfFatal(e);
            errors.tryAddThrowableOrReport(e);
            break;
        }
        if (!b) {
            break;
        }
        if (set.isDisposed()) {
            return;
        }
        CompletableSource c;
        try {
            c = Objects.requireNonNull(iterator.next(), "The iterator returned a null CompletableSource");
        } catch (Throwable e) {
            Exceptions.throwIfFatal(e);
            errors.tryAddThrowableOrReport(e);
            break;
        }
        if (set.isDisposed()) {
            return;
        }
        wip.getAndIncrement();
        c.subscribe(new MergeInnerCompletableObserver(observer, set, errors, wip));
    }
    if (wip.decrementAndGet() == 0) {
        errors.tryTerminateConsumer(observer);
    }
}
Also used : AtomicThrowable(io.reactivex.rxjava3.internal.util.AtomicThrowable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicThrowable(io.reactivex.rxjava3.internal.util.AtomicThrowable) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable)

Example 67 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class ObservableRetryPredicate method subscribeActual.

@Override
public void subscribeActual(Observer<? super T> observer) {
    SequentialDisposable sa = new SequentialDisposable();
    observer.onSubscribe(sa);
    RepeatObserver<T> rs = new RepeatObserver<>(observer, count, predicate, sa, source);
    rs.subscribeNext();
}
Also used : SequentialDisposable(io.reactivex.rxjava3.internal.disposables.SequentialDisposable)

Example 68 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class ConnectableObservable method connect.

/**
 * Instructs the {@code ConnectableObservable} to begin emitting the items from its underlying
 * {@link Observable} to its {@link Observer}s.
 * <p>
 * To disconnect from a synchronous source, use the {@link #connect(Consumer)} method.
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>The behavior is determined by the implementor of this abstract class.</dd>
 * </dl>
 *
 * @return the {@link Disposable} representing the connection
 * @see <a href="http://reactivex.io/documentation/operators/connect.html">ReactiveX documentation: Connect</a>
 */
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable connect() {
    ConnectConsumer cc = new ConnectConsumer();
    connect(cc);
    return cc.disposable;
}
Also used : ConnectConsumer(io.reactivex.rxjava3.internal.util.ConnectConsumer)

Example 69 with Observer

use of io.reactivex.rxjava3.core.Observer 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);
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) InOrder(org.mockito.InOrder) IOException(java.io.IOException) Test(org.junit.Test)

Example 70 with Observer

use of io.reactivex.rxjava3.core.Observer in project RxJava by ReactiveX.

the class CompletableSafeSubscribeTest method onSubscribeCrash.

@Test
public void onSubscribeCrash() throws Throwable {
    TestHelper.withErrorTracking(errors -> {
        CompletableObserver consumer = mock(CompletableObserver.class);
        doThrow(new TestException()).when(consumer).onSubscribe(any());
        Disposable d = Disposable.empty();
        new Completable() {

            @Override
            protected void subscribeActual(@NonNull CompletableObserver observer) {
                observer.onSubscribe(d);
                // none of the following should arrive at the consumer
                observer.onError(new IOException());
                observer.onComplete();
            }
        }.safeSubscribe(consumer);
        InOrder order = inOrder(consumer);
        order.verify(consumer).onSubscribe(any(Disposable.class));
        order.verifyNoMoreInteractions();
        assertTrue(d.isDisposed());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
        TestHelper.assertUndeliverable(errors, 1, IOException.class);
    });
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) InOrder(org.mockito.InOrder) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)139 TestException (io.reactivex.rxjava3.exceptions.TestException)88 InOrder (org.mockito.InOrder)75 Observable (io.reactivex.rxjava3.core.Observable)49 Disposable (io.reactivex.rxjava3.disposables.Disposable)49 TestObserver (io.reactivex.rxjava3.observers.TestObserver)37 IOException (java.io.IOException)29 Observer (io.reactivex.rxjava3.core.Observer)23 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)11 Function (io.reactivex.rxjava3.functions.Function)10 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)6 ConnectableObservable (io.reactivex.rxjava3.observables.ConnectableObservable)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)5 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)5 io.reactivex.rxjava3.subjects (io.reactivex.rxjava3.subjects)5 RxMethod (io.reactivex.rxjava3.validators.BaseTypeParser.RxMethod)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5