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));
}
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);
}
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();
}
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();
}
}
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());
}
Aggregations