Search in sources :

Example 41 with Supplier

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

the class RxJavaPluginsTest method overrideInitNewThreadScheduler.

@Test
public void overrideInitNewThreadScheduler() {
    // make sure the Schedulers is initialized;
    final Scheduler s = Schedulers.newThread();
    Supplier<Scheduler> c = new Supplier<Scheduler>() {

        @Override
        public Scheduler get() throws Exception {
            return s;
        }
    };
    try {
        RxJavaPlugins.setInitNewThreadSchedulerHandler(initReplaceWithImmediate);
        assertSame(ImmediateThinScheduler.INSTANCE, RxJavaPlugins.initNewThreadScheduler(c));
    } finally {
        RxJavaPlugins.reset();
    }
    // make sure the reset worked
    assertSame(s, RxJavaPlugins.initNewThreadScheduler(c));
}
Also used : ImmediateThinScheduler(io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler) Test(org.junit.Test)

Example 42 with Supplier

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

the class FlowableDelayTest method delaySupplierErrors.

@Test
public void delaySupplierErrors() {
    final PublishProcessor<Integer> pp = PublishProcessor.create();
    Flowable<Integer> source = Flowable.range(1, 5);
    TestSubscriber<Integer> ts = new TestSubscriber<>();
    source.delaySubscription(Flowable.defer(new Supplier<Publisher<Integer>>() {

        @Override
        public Publisher<Integer> get() {
            return pp;
        }
    })).subscribe(ts);
    ts.assertNoValues();
    ts.assertNoErrors();
    ts.assertNotComplete();
    pp.onError(new TestException());
    ts.assertNoValues();
    ts.assertNotComplete();
    ts.assertError(TestException.class);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 43 with Supplier

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

the class FlowableDeferTest method deferFunctionThrows.

@Test
public void deferFunctionThrows() throws Throwable {
    Supplier<Flowable<String>> factory = mock(Supplier.class);
    when(factory.get()).thenThrow(new TestException());
    Flowable<String> result = Flowable.defer(factory);
    Subscriber<String> subscriber = TestHelper.mockSubscriber();
    result.subscribe(subscriber);
    verify(subscriber).onError(any(TestException.class));
    verify(subscriber, never()).onNext(any(String.class));
    verify(subscriber, never()).onComplete();
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 44 with Supplier

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

the class FlowableGenerateTest method disposerThrows.

@Test
public void disposerThrows() {
    List<Throwable> errors = TestHelper.trackPluginErrors();
    try {
        Flowable.generate(new Supplier<Object>() {

            @Override
            public Object get() throws Exception {
                return 1;
            }
        }, new BiConsumer<Object, Emitter<Object>>() {

            @Override
            public void accept(Object s, Emitter<Object> e) throws Exception {
                e.onComplete();
            }
        }, new Consumer<Object>() {

            @Override
            public void accept(Object d) throws Exception {
                throw new TestException();
            }
        }).test().assertResult();
        TestHelper.assertUndeliverable(errors, 0, TestException.class);
    } finally {
        RxJavaPlugins.reset();
    }
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Example 45 with Supplier

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

the class ObservableRetryTest method noCancelPreviousRetryUntil.

@Test
public void noCancelPreviousRetryUntil() {
    final AtomicInteger counter = new AtomicInteger();
    final AtomicInteger times = new AtomicInteger();
    Observable<Integer> source = Observable.defer(new Supplier<ObservableSource<Integer>>() {

        @Override
        public ObservableSource<Integer> get() throws Exception {
            if (times.getAndIncrement() < 4) {
                return Observable.error(new TestException());
            }
            return Observable.just(1);
        }
    }).doOnDispose(new Action() {

        @Override
        public void run() throws Exception {
            counter.getAndIncrement();
        }
    });
    source.retryUntil(new BooleanSupplier() {

        @Override
        public boolean getAsBoolean() throws Exception {
            return false;
        }
    }).test().assertResult(1);
    assertEquals(0, counter.get());
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException) TestException(io.reactivex.rxjava3.exceptions.TestException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)37 TestException (io.reactivex.rxjava3.exceptions.TestException)33 Observable (io.reactivex.rxjava3.core.Observable)13 IOException (java.io.IOException)9 InOrder (org.mockito.InOrder)8 java.util (java.util)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Disposable (io.reactivex.rxjava3.disposables.Disposable)5 Supplier (io.reactivex.rxjava3.functions.Supplier)5 ImmediateThinScheduler (io.reactivex.rxjava3.internal.schedulers.ImmediateThinScheduler)5 TestObserver (io.reactivex.rxjava3.observers.TestObserver)5 Observer (io.reactivex.rxjava3.core.Observer)4 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)4 ImmutableList (com.google.common.collect.ImmutableList)3 io.reactivex.rxjava3.processors (io.reactivex.rxjava3.processors)3 TestHelper (io.reactivex.rxjava3.testsupport.TestHelper)3 java.util.function (java.util.function)3 java.util.stream (java.util.stream)3 Assert.assertFalse (org.junit.Assert.assertFalse)3 SQLUtils (com.alibaba.druid.sql.SQLUtils)2