Search in sources :

Example 21 with AtomicThrowable

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

the class HalfSerializerSubscriberTest method reentrantOnNextOnNext.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantOnNextOnNext() {
    final AtomicInteger wip = new AtomicInteger();
    final AtomicThrowable error = new AtomicThrowable();
    final Subscriber[] a = { null };
    final TestSubscriber ts = new TestSubscriber();
    FlowableSubscriber s = new FlowableSubscriber() {

        @Override
        public void onSubscribe(Subscription s) {
            ts.onSubscribe(s);
        }

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

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

        @Override
        public void onComplete() {
            ts.onComplete();
        }
    };
    a[0] = s;
    s.onSubscribe(new BooleanSubscription());
    HalfSerializer.onNext(s, 1, wip, error);
    ts.assertValue(1).assertNoErrors().assertNotComplete();
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 22 with AtomicThrowable

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

the class HalfSerializerSubscriberTest 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 TestSubscriber<Integer> ts = new TestSubscriber<>();
        ts.onSubscribe(new BooleanSubscription());
        Runnable r1 = new Runnable() {

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

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

Example 23 with AtomicThrowable

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

the class HalfSerializerObserverTest method reentrantOnNextOnNext.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantOnNextOnNext() {
    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.onNext(a[0], 2, 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.assertValue(1).assertNoErrors().assertNotComplete();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestObserver(io.reactivex.rxjava3.observers.TestObserver) TestObserver(io.reactivex.rxjava3.observers.TestObserver) Test(org.junit.Test)

Example 24 with AtomicThrowable

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

the class HalfSerializerObserverTest method onErrorOnCompleteRace.

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

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

            @Override
            public void run() {
                HalfSerializer.onComplete(to, wip, error);
            }
        };
        TestHelper.race(r1, r2);
        if (to.completions() != 0) {
            to.assertResult();
        } else {
            to.assertFailure(TestException.class);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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