Search in sources :

Example 11 with SingleSubject

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

the class SingleTakeUntilTest method untilCompletableMainError.

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

Example 12 with SingleSubject

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

the class SingleTakeUntilTest method untilCompletableOtherError.

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

Example 13 with SingleSubject

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

the class SingleTimeoutTest method errorTimeoutRace.

@Test
public void errorTimeoutRace() {
    final TestException ex = new TestException();
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        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.onError(ex);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    sch.advanceTimeBy(1, TimeUnit.MILLISECONDS);
                }
            };
            TestHelper.race(r1, r2);
            if (!fallback.hasObservers()) {
                to.assertFailure(TestException.class);
            } else {
                to.assertEmpty();
            }
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        }
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 14 with SingleSubject

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

the class SingleTimeoutTest method fallbackDispose.

@Test
public void fallbackDispose() {
    TestScheduler sch = new TestScheduler();
    SingleSubject<Integer> subj = SingleSubject.create();
    SingleSubject<Integer> fallback = SingleSubject.create();
    TestObserver<Integer> to = subj.timeout(1, TimeUnit.SECONDS, sch, fallback).test();
    assertFalse(fallback.hasObservers());
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    assertFalse(subj.hasObservers());
    assertTrue(fallback.hasObservers());
    to.dispose();
    assertFalse(fallback.hasObservers());
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 15 with SingleSubject

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

the class SingleTimeoutTest method disposeWhenFallback.

@Test
public void disposeWhenFallback() {
    TestScheduler sch = new TestScheduler();
    SingleSubject<Integer> subj = SingleSubject.create();
    subj.timeout(1, TimeUnit.SECONDS, sch, Single.just(1)).test(true).assertEmpty();
    assertFalse(subj.hasObservers());
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Aggregations

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