Search in sources :

Example 11 with SuppressUndeliverable

use of io.reactivex.rxjava3.testsupport.SuppressUndeliverable in project RxJava by ReactiveX.

the class TrampolineSchedulerInternalTest method reentrantScheduleInterrupt.

@Test
@SuppressUndeliverable
public void reentrantScheduleInterrupt() {
    final Worker w = Schedulers.trampoline().createWorker();
    try {
        final int[] calls = { 0 };
        Thread.currentThread().interrupt();
        w.schedule(new Runnable() {

            @Override
            public void run() {
                calls[0]++;
            }
        }, 1, TimeUnit.DAYS);
        assertTrue(Thread.interrupted());
        assertEquals(0, calls[0]);
    } finally {
        w.dispose();
    }
}
Also used : Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Example 12 with SuppressUndeliverable

use of io.reactivex.rxjava3.testsupport.SuppressUndeliverable in project RxJava by ReactiveX.

the class HalfSerializerObserverTest method reentrantErrorOnError.

@Test
@SuppressUndeliverable
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantErrorOnError() {
    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) {
            to.onNext(t);
        }

        @Override
        public void onError(Throwable t) {
            to.onError(t);
            HalfSerializer.onError(a[0], new IOException(), wip, error);
        }

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

Example 13 with SuppressUndeliverable

use of io.reactivex.rxjava3.testsupport.SuppressUndeliverable in project RxJava by ReactiveX.

the class HalfSerializerSubscriberTest method reentrantErrorOnError.

@Test
@SuppressUndeliverable
@SuppressWarnings({ "rawtypes", "unchecked" })
public void reentrantErrorOnError() {
    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) {
            ts.onNext(t);
        }

        @Override
        public void onError(Throwable t) {
            ts.onError(t);
            HalfSerializer.onError(a[0], new IOException(), wip, error);
        }

        @Override
        public void onComplete() {
            ts.onComplete();
        }
    };
    a[0] = s;
    s.onSubscribe(new BooleanSubscription());
    HalfSerializer.onError(s, new TestException(), wip, error);
    ts.assertFailure(TestException.class);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) TestSubscriber(io.reactivex.rxjava3.subscribers.TestSubscriber) IOException(java.io.IOException) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Example 14 with SuppressUndeliverable

use of io.reactivex.rxjava3.testsupport.SuppressUndeliverable in project RxJava by ReactiveX.

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

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

            @Override
            public void run() {
                HalfSerializer.onComplete(ts, wip, error);
            }
        };
        TestHelper.race(r1, r2);
        if (ts.completions() != 0) {
            ts.assertResult();
        } else {
            ts.assertFailure(TestException.class);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 15 with SuppressUndeliverable

use of io.reactivex.rxjava3.testsupport.SuppressUndeliverable in project RxJava by ReactiveX.

the class BoundedSubscriberTest method badSourceEmitAfterDone.

@Test
@SuppressUndeliverable
public void badSourceEmitAfterDone() {
    Flowable<Integer> source = Flowable.fromPublisher(new Publisher<Integer>() {

        @Override
        public void subscribe(Subscriber<? super Integer> s) {
            BooleanSubscription s1 = new BooleanSubscription();
            s.onSubscribe(s1);
            s.onNext(1);
            s.onComplete();
            s.onNext(2);
            s.onError(new TestException());
            s.onComplete();
        }
    });
    final List<Object> received = new ArrayList<>();
    BoundedSubscriber<Object> subscriber = new BoundedSubscriber<>(new Consumer<Object>() {

        @Override
        public void accept(Object v) throws Exception {
            received.add(v);
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable e) throws Exception {
            received.add(e);
        }
    }, new Action() {

        @Override
        public void run() throws Exception {
            received.add(100);
        }
    }, new Consumer<Subscription>() {

        @Override
        public void accept(Subscription s) throws Exception {
            s.request(128);
        }
    }, 128);
    source.subscribe(subscriber);
    assertEquals(Arrays.asList(1, 100), received);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) Test(org.junit.Test)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)31 Test (org.junit.Test)30 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Observable (io.reactivex.rxjava3.core.Observable)8 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)8 IOException (java.io.IOException)8 SuppressUndeliverable (io.reactivex.rxjava3.testsupport.SuppressUndeliverable)7 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)6 Disposable (io.reactivex.rxjava3.disposables.Disposable)6 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)5 Scheduler (io.reactivex.rxjava3.core.Scheduler)3 TestObserver (io.reactivex.rxjava3.observers.TestObserver)3 NewThreadWorker (io.reactivex.rxjava3.internal.schedulers.NewThreadWorker)2 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)2 Observer (io.reactivex.rxjava3.core.Observer)1 Cancellable (io.reactivex.rxjava3.functions.Cancellable)1 ComputationScheduler (io.reactivex.rxjava3.internal.schedulers.ComputationScheduler)1 DelayedRunnable (io.reactivex.rxjava3.internal.schedulers.ExecutorScheduler.DelayedRunnable)1 IoScheduler (io.reactivex.rxjava3.internal.schedulers.IoScheduler)1 ScheduledWorker (io.reactivex.rxjava3.internal.schedulers.SingleScheduler.ScheduledWorker)1