use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class FlowableRepeatTest method noCancelPreviousRepeatWhen.
@Test
public void noCancelPreviousRepeatWhen() {
final AtomicInteger counter = new AtomicInteger();
Flowable<Integer> source = Flowable.just(1).doOnCancel(new Action() {
@Override
public void run() throws Exception {
counter.getAndIncrement();
}
});
final AtomicInteger times = new AtomicInteger();
source.repeatWhen(new Function<Flowable<Object>, Flowable<?>>() {
@Override
public Flowable<?> apply(Flowable<Object> e) throws Exception {
return e.takeWhile(new Predicate<Object>() {
@Override
public boolean test(Object v) throws Exception {
return times.getAndIncrement() < 4;
}
});
}
}).test().assertResult(1, 1, 1, 1, 1);
assertEquals(0, counter.get());
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class RxJavaPluginsTest method overrideConnectableFlowable.
@SuppressWarnings("rawtypes")
@Test
public void overrideConnectableFlowable() {
try {
RxJavaPlugins.setOnConnectableFlowableAssembly(new Function<ConnectableFlowable, ConnectableFlowable>() {
@Override
public ConnectableFlowable apply(ConnectableFlowable co) throws Exception {
return new ConnectableFlowable() {
@Override
public void connect(Consumer connection) {
}
@Override
public void reset() {
// nothing to do in this test
}
@SuppressWarnings("unchecked")
@Override
protected void subscribeActual(Subscriber subscriber) {
subscriber.onSubscribe(new ScalarSubscription(subscriber, 10));
}
};
}
});
Flowable.just(1).publish().autoConnect().test().assertResult(10);
} finally {
RxJavaPlugins.reset();
}
Flowable.just(1).publish().autoConnect().test().assertResult(1);
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class RxJavaPluginsTest method overrideConnectableObservable.
@SuppressWarnings("rawtypes")
@Test
public void overrideConnectableObservable() {
try {
RxJavaPlugins.setOnConnectableObservableAssembly(new Function<ConnectableObservable, ConnectableObservable>() {
@Override
public ConnectableObservable apply(ConnectableObservable co) throws Exception {
return new ConnectableObservable() {
@Override
public void connect(Consumer connection) {
}
@Override
public void reset() {
// nothing to do in this test
}
@SuppressWarnings("unchecked")
@Override
protected void subscribeActual(Observer observer) {
observer.onSubscribe(Disposable.empty());
observer.onNext(10);
observer.onComplete();
}
};
}
});
Observable.just(1).publish().autoConnect().test().assertResult(10);
} finally {
RxJavaPlugins.reset();
}
Observable.just(1).publish().autoConnect().test().assertResult(1);
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class RxJavaPluginsTest method createNewThreadScheduler.
@Test
public void createNewThreadScheduler() {
final String name = "NewThreadSchedulerTest";
ThreadFactory factory = new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, name);
}
};
final Scheduler customScheduler = RxJavaPlugins.createNewThreadScheduler(factory);
RxJavaPlugins.setNewThreadSchedulerHandler(new Function<Scheduler, Scheduler>() {
@Override
public Scheduler apply(Scheduler scheduler) throws Exception {
return customScheduler;
}
});
try {
verifyThread(Schedulers.newThread(), name);
} finally {
customScheduler.shutdown();
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Function in project RxJava by ReactiveX.
the class RxJavaPluginsTest method observableCreate.
@SuppressWarnings("rawtypes")
@Test
public void observableCreate() {
try {
RxJavaPlugins.setOnObservableAssembly(new Function<Observable, Observable>() {
@Override
public Observable apply(Observable t) {
return new ObservableRange(1, 2);
}
});
Observable.range(10, 3).test().assertValues(1, 2).assertNoErrors().assertComplete();
} finally {
RxJavaPlugins.reset();
}
// make sure the reset worked
Observable.range(10, 3).test().assertValues(10, 11, 12).assertNoErrors().assertComplete();
}
Aggregations