Search in sources :

Example 31 with TestSubscriberEx

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

the class SerializedSubscriberTest method onErrorQueuedUp.

@Test
@SuppressUndeliverable
public void onErrorQueuedUp() {
    AtomicReference<SerializedSubscriber<Integer>> ssRef = new AtomicReference<>();
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<Integer>() {

        @Override
        public void onNext(Integer t) {
            super.onNext(t);
            ssRef.get().onNext(2);
            ssRef.get().onError(new TestException());
        }
    };
    final SerializedSubscriber<Integer> so = new SerializedSubscriber<>(ts, true);
    ssRef.set(so);
    BooleanSubscription bs = new BooleanSubscription();
    so.onSubscribe(bs);
    so.onNext(1);
    ts.assertFailure(TestException.class, 1, 2);
}
Also used : BooleanSubscription(io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 32 with TestSubscriberEx

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

the class TestSubscriberExTest method interruptTerminalEventAwait.

@Test
public void interruptTerminalEventAwait() {
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
    final Thread t0 = Thread.currentThread();
    Worker w = Schedulers.computation().createWorker();
    try {
        w.schedule(new Runnable() {

            @Override
            public void run() {
                t0.interrupt();
            }
        }, 200, TimeUnit.MILLISECONDS);
        try {
            if (ts.await(5, TimeUnit.SECONDS)) {
                fail("Did not interrupt wait!");
            }
        } catch (InterruptedException expected) {
        // expected
        }
    } finally {
        w.dispose();
    }
}
Also used : Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Example 33 with TestSubscriberEx

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

the class FlowableWithLatestFromTest method otherThrows.

@Test
public void otherThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    PublishProcessor<Integer> other = PublishProcessor.create();
    Flowable<Integer> result = source.withLatestFrom(other, COMBINER);
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
    result.subscribe(ts);
    assertTrue(source.hasSubscribers());
    assertTrue(other.hasSubscribers());
    other.onNext(1);
    source.onNext(1);
    other.onError(new TestException());
    ts.assertTerminated();
    ts.assertValue((1 << 8) + 1);
    ts.assertNotComplete();
    ts.assertError(TestException.class);
    assertFalse(source.hasSubscribers());
    assertFalse(other.hasSubscribers());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 34 with TestSubscriberEx

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

the class FlowableWithLatestFromTest method sourceThrows.

@Test
public void sourceThrows() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    PublishProcessor<Integer> other = PublishProcessor.create();
    Flowable<Integer> result = source.withLatestFrom(other, COMBINER);
    TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
    result.subscribe(ts);
    assertTrue(source.hasSubscribers());
    assertTrue(other.hasSubscribers());
    other.onNext(1);
    source.onNext(1);
    source.onError(new TestException());
    ts.assertTerminated();
    ts.assertValue((1 << 8) + 1);
    ts.assertError(TestException.class);
    ts.assertNotComplete();
    assertFalse(source.hasSubscribers());
    assertFalse(other.hasSubscribers());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)26 TestException (io.reactivex.rxjava3.exceptions.TestException)15 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)12 Disposable (io.reactivex.rxjava3.disposables.Disposable)5 TestSubscriberEx (io.reactivex.rxjava3.testsupport.TestSubscriberEx)5 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)3 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)3 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)2 PublishProcessor (io.reactivex.rxjava3.processors.PublishProcessor)2 Random (java.util.Random)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Assert (org.junit.Assert)2 io.reactivex.rxjava3.core (io.reactivex.rxjava3.core)1 Flowable (io.reactivex.rxjava3.core.Flowable)1 io.reactivex.rxjava3.exceptions (io.reactivex.rxjava3.exceptions)1 io.reactivex.rxjava3.functions (io.reactivex.rxjava3.functions)1 BiFunction (io.reactivex.rxjava3.functions.BiFunction)1 Functions (io.reactivex.rxjava3.internal.functions.Functions)1 FlattenIterableSubscriber (io.reactivex.rxjava3.internal.operators.flowable.FlowableFlattenIterable.FlattenIterableSubscriber)1