Search in sources :

Example 36 with CompletableSubject

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

the class FlowableConcatMapCompletableTest method endError.

@Test
public void endError() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    final CompletableSubject cs = CompletableSubject.create();
    final CompletableSubject cs2 = CompletableSubject.create();
    TestObserver<Void> to = pp.concatMapCompletableDelayError(new Function<Integer, CompletableSource>() {

        @Override
        public CompletableSource apply(Integer v) throws Exception {
            if (v == 1) {
                return cs;
            }
            return cs2;
        }
    }, true, 32).test();
    to.assertEmpty();
    assertTrue(pp.hasSubscribers());
    assertFalse(cs.hasObservers());
    pp.onNext(1);
    assertTrue(cs.hasObservers());
    cs.onError(new TestException());
    assertTrue(pp.hasSubscribers());
    pp.onNext(2);
    to.assertEmpty();
    cs2.onComplete();
    assertTrue(pp.hasSubscribers());
    to.assertEmpty();
    pp.onComplete();
    to.assertFailure(TestException.class);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletableSubject(io.reactivex.rxjava3.subjects.CompletableSubject) Test(org.junit.Test)

Example 37 with CompletableSubject

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

the class FlowableConcatMapCompletableTest method immediateError.

@Test
public void immediateError() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    CompletableSubject cs = CompletableSubject.create();
    TestObserver<Void> to = pp.concatMapCompletable(Functions.justFunction(cs)).test();
    to.assertEmpty();
    assertTrue(pp.hasSubscribers());
    assertFalse(cs.hasObservers());
    pp.onNext(1);
    assertTrue(cs.hasObservers());
    pp.onError(new TestException());
    assertFalse(cs.hasObservers());
    to.assertFailure(TestException.class);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletableSubject(io.reactivex.rxjava3.subjects.CompletableSubject) Test(org.junit.Test)

Example 38 with CompletableSubject

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

the class FlowableConcatMapCompletableTest method immediateOuterInnerErrorRace.

@Test
public void immediateOuterInnerErrorRace() {
    final TestException ex = new TestException();
    for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
        List<Throwable> errors = TestHelper.trackPluginErrors();
        try {
            final PublishProcessor<Integer> pp = PublishProcessor.create();
            final CompletableSubject cs = CompletableSubject.create();
            TestObserver<Void> to = pp.concatMapCompletable(Functions.justFunction(cs)).test();
            pp.onNext(1);
            Runnable r1 = new Runnable() {

                @Override
                public void run() {
                    pp.onError(ex);
                }
            };
            Runnable r2 = new Runnable() {

                @Override
                public void run() {
                    cs.onError(ex);
                }
            };
            TestHelper.race(r1, r2);
            to.assertError(new Predicate<Throwable>() {

                @Override
                public boolean test(Throwable e) throws Exception {
                    return e instanceof TestException || e instanceof CompositeException;
                }
            }).assertNotComplete();
            if (!errors.isEmpty()) {
                TestHelper.assertUndeliverable(errors, 0, TestException.class);
            }
        } finally {
            RxJavaPlugins.reset();
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletableSubject(io.reactivex.rxjava3.subjects.CompletableSubject) Test(org.junit.Test)

Example 39 with CompletableSubject

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

the class FlowableConcatMapCompletableTest method boundaryError.

@Test
public void boundaryError() {
    PublishProcessor<Integer> pp = PublishProcessor.create();
    CompletableSubject cs = CompletableSubject.create();
    TestObserver<Void> to = pp.concatMapCompletableDelayError(Functions.justFunction(cs), false).test();
    to.assertEmpty();
    assertTrue(pp.hasSubscribers());
    assertFalse(cs.hasObservers());
    pp.onNext(1);
    assertTrue(cs.hasObservers());
    pp.onError(new TestException());
    assertTrue(cs.hasObservers());
    to.assertEmpty();
    cs.onComplete();
    to.assertFailure(TestException.class);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletableSubject(io.reactivex.rxjava3.subjects.CompletableSubject) Test(org.junit.Test)

Example 40 with CompletableSubject

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

the class CompletableAmbTest method untilCompletableMainError.

@Test
public void untilCompletableMainError() {
    CompletableSubject main = CompletableSubject.create();
    CompletableSubject other = CompletableSubject.create();
    TestObserver<Void> to = main.ambWith(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)

Aggregations

Test (org.junit.Test)49 CompletableSubject (io.reactivex.rxjava3.subjects.CompletableSubject)41 TestException (io.reactivex.rxjava3.exceptions.TestException)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)1