Search in sources :

Example 1 with AtomicThrowable

use of io.reactivex.rxjava3.internal.util.AtomicThrowable 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);
    }
}
Also used : AtomicThrowable(io.reactivex.rxjava3.internal.util.AtomicThrowable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicThrowable(io.reactivex.rxjava3.internal.util.AtomicThrowable)

Example 2 with AtomicThrowable

use of io.reactivex.rxjava3.internal.util.AtomicThrowable 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 3 with AtomicThrowable

use of io.reactivex.rxjava3.internal.util.AtomicThrowable in project RxJava by ReactiveX.

the class HalfSerializerObserverTest method onNextOnCompleteRace.

@Test
public void onNextOnCompleteRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final AtomicInteger wip = new AtomicInteger();
        final AtomicThrowable error = new AtomicThrowable();
        final TestObserver<Integer> to = new TestObserver<>();
        to.onSubscribe(Disposable.empty());
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                HalfSerializer.onNext(to, 1, wip, error);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                HalfSerializer.onComplete(to, wip, error);
            }
        };
        TestHelper.race(r1, r2);
        to.assertComplete().assertNoErrors();
        assertTrue(to.values().size() <= 1);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 4 with AtomicThrowable

use of io.reactivex.rxjava3.internal.util.AtomicThrowable in project RxJava by ReactiveX.

the class HalfSerializerObserverTest method reentrantOnNextOnError.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantOnNextOnError() {
    final AtomicInteger wip = new AtomicInteger();
    final AtomicThrowable error = new AtomicThrowable();
    final Observer[] a = { null };
    final TestObserver to = new TestObserver();
    Observer observer = new Observer() {

        @Override
        public void onSubscribe(Disposable d) {
            to.onSubscribe(d);
        }

        @Override
        public void onNext(Object t) {
            if (t.equals(1)) {
                HalfSerializer.onError(a[0], new TestException(), wip, error);
            }
            to.onNext(t);
        }

        @Override
        public void onError(Throwable t) {
            to.onError(t);
        }

        @Override
        public void onComplete() {
            to.onComplete();
        }
    };
    a[0] = observer;
    observer.onSubscribe(Disposable.empty());
    HalfSerializer.onNext(observer, 1, wip, error);
    to.assertFailure(TestException.class, 1);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.rxjava3.observers.TestObserver) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 5 with AtomicThrowable

use of io.reactivex.rxjava3.internal.util.AtomicThrowable in project RxJava by ReactiveX.

the class HalfSerializerObserverTest method reentrantOnNextOnComplete.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantOnNextOnComplete() {
    final AtomicInteger wip = new AtomicInteger();
    final AtomicThrowable error = new AtomicThrowable();
    final Observer[] a = { null };
    final TestObserver to = new TestObserver();
    Observer observer = new Observer() {

        @Override
        public void onSubscribe(Disposable d) {
            to.onSubscribe(d);
        }

        @Override
        public void onNext(Object t) {
            if (t.equals(1)) {
                HalfSerializer.onComplete(a[0], wip, error);
            }
            to.onNext(t);
        }

        @Override
        public void onError(Throwable t) {
            to.onError(t);
        }

        @Override
        public void onComplete() {
            to.onComplete();
        }
    };
    a[0] = observer;
    observer.onSubscribe(Disposable.empty());
    HalfSerializer.onNext(observer, 1, wip, error);
    to.assertResult(1);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.rxjava3.observers.TestObserver) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)22 TestException (io.reactivex.rxjava3.exceptions.TestException)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 TestObserver (io.reactivex.rxjava3.observers.TestObserver)10 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)9 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)8 AtomicThrowable (io.reactivex.rxjava3.internal.util.AtomicThrowable)2 IOException (java.io.IOException)2 CompositeDisposable (io.reactivex.rxjava3.disposables.CompositeDisposable)1