Search in sources :

Example 81 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class ObservableReplayEagerTruncateTest method connectConsumerThrows.

@Test
public void connectConsumerThrows() {
    ConnectableObservable<Integer> co = Observable.range(1, 2).replay();
    try {
        co.connect(new Consumer<Disposable>() {

            @Override
            public void accept(Disposable t) throws Exception {
                throw new TestException();
            }
        });
        fail("Should have thrown");
    } catch (TestException ex) {
    // expected
    }
    co.test().assertEmpty().dispose();
    co.connect();
    co.test().assertResult(1, 2);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 82 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class ObservableReplayEagerTruncateTest method disposeNoNeedForResetTimeAndSIzeBound.

@Test
public void disposeNoNeedForResetTimeAndSIzeBound() {
    PublishSubject<Integer> ps = PublishSubject.create();
    ConnectableObservable<Integer> co = ps.replay(10, 10, TimeUnit.MINUTES, Schedulers.single(), true);
    TestObserver<Integer> to = co.test();
    Disposable d = co.connect();
    ps.onNext(1);
    d.dispose();
    to = co.test();
    to.assertEmpty();
    co.connect();
    to.assertEmpty();
    ps.onNext(2);
    to.assertValuesOnly(2);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Example 83 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class ObservableResourceWrapperTest method onErrorDisposes.

@Test
public void onErrorDisposes() {
    TestObserver<Object> to = new TestObserver<>();
    ObserverResourceWrapper<Object> orw = new ObserverResourceWrapper<>(to);
    Disposable d = Disposable.empty();
    Disposable d1 = Disposable.empty();
    orw.setResource(d1);
    orw.onSubscribe(d);
    orw.onError(new TestException());
    assertTrue(d1.isDisposed());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestObserver(io.reactivex.rxjava3.observers.TestObserver) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 84 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class ObservableObserveOnTest method outputFusedCancelReentrant.

@Test
public void outputFusedCancelReentrant() throws Exception {
    final UnicastSubject<Integer> us = UnicastSubject.create();
    final CountDownLatch cdl = new CountDownLatch(1);
    us.observeOn(Schedulers.single()).subscribe(new Observer<Integer>() {

        Disposable upstream;

        int count;

        @Override
        public void onSubscribe(Disposable d) {
            this.upstream = d;
            ((QueueDisposable<?>) d).requestFusion(QueueFuseable.ANY);
        }

        @Override
        public void onNext(Integer value) {
            if (++count == 1) {
                us.onNext(2);
                upstream.dispose();
                cdl.countDown();
            }
        }

        @Override
        public void onError(Throwable e) {
        }

        @Override
        public void onComplete() {
        }
    });
    us.onNext(1);
    cdl.await();
}
Also used : QueueDisposable(io.reactivex.rxjava3.operators.QueueDisposable) Test(org.junit.Test)

Example 85 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project RxJava by ReactiveX.

the class TestObserverExTest method completeDelegateThrows.

@Test
public void completeDelegateThrows() {
    TestObserverEx<Integer> to = new TestObserverEx<>(new Observer<Integer>() {

        @Override
        public void onSubscribe(Disposable d) {
        }

        @Override
        public void onNext(Integer value) {
        }

        @Override
        public void onError(Throwable e) {
            throw new TestException();
        }

        @Override
        public void onComplete() {
            throw new TestException();
        }
    });
    to.onSubscribe(Disposable.empty());
    try {
        to.onComplete();
        throw new RuntimeException("Should have thrown!");
    } catch (TestException ex) {
        to.assertTerminated();
    }
}
Also used : ScalarDisposable(io.reactivex.rxjava3.internal.operators.observable.ObservableScalarXMap.ScalarDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)250 Disposable (io.reactivex.rxjava3.disposables.Disposable)219 TestException (io.reactivex.rxjava3.exceptions.TestException)74 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)56 IOException (java.io.IOException)37 Scheduler (io.reactivex.rxjava3.core.Scheduler)36 EmptyDisposable (io.reactivex.rxjava3.internal.disposables.EmptyDisposable)35 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)34 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)32 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 TestObserver (io.reactivex.rxjava3.observers.TestObserver)18 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)15 QueueDisposable (io.reactivex.rxjava3.operators.QueueDisposable)13 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)10 TrampolineScheduler (io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)9 Observable (io.reactivex.rxjava3.core.Observable)6 Observer (io.reactivex.rxjava3.core.Observer)6 ScalarDisposable (io.reactivex.rxjava3.internal.operators.observable.ObservableScalarXMap.ScalarDisposable)6 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)6