Search in sources :

Example 56 with Action

use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.

the class DisposableLambdaObserverTest method disposeCrash.

@Test
public void disposeCrash() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        DisposableLambdaObserver<Integer> o = new DisposableLambdaObserver<>(new TestObserver<>(), Functions.emptyConsumer(), new Action() {

            @Override
            public void run() throws Exception {
                throw new TestException();
            }
        });
        o.onSubscribe(Disposable.empty());
        assertFalse(o.isDisposed());
        o.dispose();
        assertTrue(o.isDisposed());
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 57 with Action

use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.

the class CompletableConcatDelayErrorTest method normalIterable.

@Test
public void normalIterable() throws Throwable {
    Action action1 = mock(Action.class);
    Action action2 = mock(Action.class);
    Completable.concatDelayError(Arrays.asList(Completable.fromAction(action1), Completable.error(new TestException()), Completable.fromAction(action2))).test().assertFailure(TestException.class);
    verify(action1).run();
    verify(action2).run();
}
Also used : Action(io.reactivex.rxjava3.functions.Action) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 58 with Action

use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.

the class FlowableToSingleTest method shouldUseUnsafeSubscribeInternallyNotSubscribe.

@Test
public void shouldUseUnsafeSubscribeInternallyNotSubscribe() {
    TestSubscriber<String> subscriber = TestSubscriber.create();
    final AtomicBoolean unsubscribed = new AtomicBoolean(false);
    Single<String> single = Flowable.just("Hello World!").doOnCancel(new Action() {

        @Override
        public void run() {
            unsubscribed.set(true);
        }
    }).single("");
    single.toFlowable().subscribe(subscriber);
    subscriber.assertComplete();
    Assert.assertFalse(unsubscribed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action(io.reactivex.rxjava3.functions.Action)

Example 59 with Action

use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.

the class FlowableThrottleLatestTest method missingBackpressureExceptionLatest.

@Test
public void missingBackpressureExceptionLatest() throws Throwable {
    TestScheduler sch = new TestScheduler();
    Action onCancel = mock(Action.class);
    TestSubscriber<Integer> ts = Flowable.just(1, 2).concatWith(Flowable.<Integer>never()).doOnCancel(onCancel).throttleLatest(1, TimeUnit.SECONDS, sch, true).test(1);
    sch.advanceTimeBy(1, TimeUnit.SECONDS);
    ts.assertFailure(MissingBackpressureException.class, 1);
    verify(onCancel).run();
}
Also used : TestScheduler(io.reactivex.rxjava3.schedulers.TestScheduler) Test(org.junit.Test)

Example 60 with Action

use of io.reactivex.rxjava3.functions.Action in project RxJava by ReactiveX.

the class FlowableToCompletableTest method shouldUseUnsafeSubscribeInternallyNotSubscribe.

@Test
public void shouldUseUnsafeSubscribeInternallyNotSubscribe() {
    TestSubscriber<String> subscriber = TestSubscriber.create();
    final AtomicBoolean unsubscribed = new AtomicBoolean(false);
    Completable cmp = Flowable.just("Hello World!").doOnCancel(new Action() {

        @Override
        public void run() {
            unsubscribed.set(true);
        }
    }).ignoreElements();
    cmp.<String>toFlowable().subscribe(subscriber);
    subscriber.assertComplete();
    assertFalse(unsubscribed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action(io.reactivex.rxjava3.functions.Action) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)109 TestException (io.reactivex.rxjava3.exceptions.TestException)64 Action (io.reactivex.rxjava3.functions.Action)49 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)13 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)13 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)13 TestObserver (io.reactivex.rxjava3.observers.TestObserver)10 Disposable (io.reactivex.rxjava3.disposables.Disposable)9 IOException (java.io.IOException)9 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)7 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)7 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)6 Observable (io.reactivex.rxjava3.core.Observable)4 ForEachWhileSubscriber (io.reactivex.rxjava3.internal.subscribers.ForEachWhileSubscriber)4 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)3 Flowable (io.reactivex.rxjava3.core.Flowable)3 GroupedFlowable (io.reactivex.rxjava3.flowables.GroupedFlowable)3 ConditionalSubscriber (io.reactivex.rxjava3.operators.ConditionalSubscriber)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3