Search in sources :

Example 6 with SingleSubject

use of io.reactivex.rxjava3.subjects.SingleSubject in project RxJava by ReactiveX.

the class SingleTimeoutTest method successTimeoutRace.

@Test
public void successTimeoutRace() {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final SingleSubject<Integer> subj = SingleSubject.create();
        SingleSubject<Integer> fallback = SingleSubject.create();
        final TestScheduler sch = new TestScheduler();
        TestObserver<Integer> to = subj.timeout(1, TimeUnit.MILLISECONDS, sch, fallback).test();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                subj.onSuccess(1);
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                sch.advanceTimeBy(1, TimeUnit.MILLISECONDS);
            }
        };
        TestHelper.race(r1, r2);
        if (!fallback.hasObservers()) {
            to.assertResult(1);
        } else {
            to.assertEmpty();
        }
    }
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 7 with SingleSubject

use of io.reactivex.rxjava3.subjects.SingleSubject in project RxJava by ReactiveX.

the class ObservableMergeWithSingleTest method cancelOtherOnMainError.

@Test
public void cancelOtherOnMainError() {
    PublishSubject<Integer> ps = PublishSubject.create();
    SingleSubject<Integer> ss = SingleSubject.create();
    TestObserver<Integer> to = ps.mergeWith(ss).test();
    assertTrue(ps.hasObservers());
    assertTrue(ss.hasObservers());
    ps.onError(new TestException());
    to.assertFailure(TestException.class);
    assertFalse("main has observers!", ps.hasObservers());
    assertFalse("other has observers", ss.hasObservers());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 8 with SingleSubject

use of io.reactivex.rxjava3.subjects.SingleSubject in project RxJava by ReactiveX.

the class ObservableMergeWithSingleTest method cancelMainOnOtherError.

@Test
public void cancelMainOnOtherError() {
    PublishSubject<Integer> ps = PublishSubject.create();
    SingleSubject<Integer> ss = SingleSubject.create();
    TestObserver<Integer> to = ps.mergeWith(ss).test();
    assertTrue(ps.hasObservers());
    assertTrue(ss.hasObservers());
    ss.onError(new TestException());
    to.assertFailure(TestException.class);
    assertFalse("main has observers!", ps.hasObservers());
    assertFalse("other has observers", ss.hasObservers());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 9 with SingleSubject

use of io.reactivex.rxjava3.subjects.SingleSubject in project RxJava by ReactiveX.

the class SingleFlatMapObservableTest method errorOther.

@Test
public void errorOther() {
    SingleSubject<Integer> ss = SingleSubject.create();
    PublishSubject<Integer> ps = PublishSubject.create();
    TestObserver<Integer> to = ss.flatMapObservable(Functions.justFunction(ps)).test();
    assertTrue(ss.hasObservers());
    assertFalse(ps.hasObservers());
    ss.onSuccess(1);
    assertFalse(ss.hasObservers());
    assertTrue(ps.hasObservers());
    ps.onError(new TestException());
    assertFalse(ss.hasObservers());
    assertFalse(ps.hasObservers());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 10 with SingleSubject

use of io.reactivex.rxjava3.subjects.SingleSubject in project RxJava by ReactiveX.

the class SingleTakeUntilTest method untilPublisherMainError.

@Test
public void untilPublisherMainError() {
    SingleSubject<Integer> main = SingleSubject.create();
    PublishProcessor<Integer> other = PublishProcessor.create();
    TestObserver<Integer> to = main.takeUntil(other).test();
    assertTrue("Main no observers?", main.hasObservers());
    assertTrue("Other no observers?", other.hasSubscribers());
    main.onError(new TestException());
    assertFalse("Main has observers?", main.hasObservers());
    assertFalse("Other has observers?", other.hasSubscribers());
    to.assertFailure(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 TestException (io.reactivex.rxjava3.exceptions.TestException)15 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)4