mirror of
https://github.com/jlengrand/error-prone-support.git
synced 2026-03-10 08:11:25 +00:00
Add templates for RxJava types #timeout(long, TimeUnit)
This commit is contained in:
committed by
Pieter Dirk Soels
parent
cbea5d9868
commit
1a26a23c2a
@@ -19,7 +19,9 @@ import io.reactivex.SingleSource;
|
||||
import io.reactivex.functions.Action;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.functions.Predicate;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.adapter.rxjava.RxJava2Adapter;
|
||||
@@ -355,7 +357,21 @@ final class RxJavaCompletableToReactorTemplates {
|
||||
// XXX: public final Completable subscribeOn(Scheduler)
|
||||
// XXX: public final CompletableObserver subscribeWith(CompletableObserver)
|
||||
// XXX: public final Completable takeUntil(CompletableSource)
|
||||
// XXX: public final Completable timeout(long,TimeUnit)
|
||||
|
||||
static final class CompletableTimeoutLongTimeUnit {
|
||||
@BeforeTemplate
|
||||
Completable before(Completable completable, long timeout, TimeUnit unit) {
|
||||
return completable.timeout(timeout, unit);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Completable after(Completable completable, long timeout, TimeUnit unit) {
|
||||
return RxJava2Adapter.monoToCompletable(
|
||||
RxJava2Adapter.completableToMono(completable)
|
||||
.timeout(Duration.of(timeout, unit.toChronoUnit())));
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: public final Completable timeout(long,TimeUnit,CompletableSource)
|
||||
// XXX: public final Completable timeout(long,TimeUnit,Scheduler)
|
||||
// XXX: public final Completable timeout(long,TimeUnit,Scheduler,CompletableSource)
|
||||
|
||||
@@ -28,6 +28,7 @@ import io.reactivex.functions.BiFunction;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.functions.Predicate;
|
||||
import java.time.Duration;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
@@ -1266,7 +1267,20 @@ final class RxJavaFlowableToReactorTemplates {
|
||||
// XXX: final Flowable timeInterval(TimeUnit,Scheduler)
|
||||
// XXX: final Flowable timeout(Function)
|
||||
// XXX: final Flowable timeout(Function,Flowable)
|
||||
// XXX: final Flowable timeout(long,TimeUnit)
|
||||
|
||||
static final class FlowableTimeoutLongTimeUnit<T> {
|
||||
@BeforeTemplate
|
||||
Flowable<T> before(Flowable<T> flowable, long timeout, TimeUnit unit) {
|
||||
return flowable.timeout(timeout, unit);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Flowable<T> after(Flowable<T> flowable, long timeout, TimeUnit unit) {
|
||||
return RxJava2Adapter.fluxToFlowable(
|
||||
RxJava2Adapter.flowableToFlux(flowable)
|
||||
.timeout(Duration.of(timeout, unit.toChronoUnit())));
|
||||
}
|
||||
}
|
||||
// XXX: final Flowable timeout(long,TimeUnit,Publisher)
|
||||
// XXX: final Flowable timeout(long,TimeUnit,Scheduler)
|
||||
// XXX: final Flowable timeout(long,TimeUnit,Scheduler,Publisher)
|
||||
|
||||
@@ -758,7 +758,19 @@ final class RxJavaMaybeToReactorTemplates {
|
||||
|
||||
// XXX: public final Maybe takeUntil(MaybeSource)
|
||||
// XXX: public final Maybe takeUntil(Publisher)
|
||||
// XXX: public final Maybe timeout(long,TimeUnit)
|
||||
|
||||
static final class MaybeTimeoutLongTimeUnit<T> {
|
||||
@BeforeTemplate
|
||||
Maybe<T> before(Maybe<T> maybe, long timeout, TimeUnit unit) {
|
||||
return maybe.timeout(timeout, unit);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Maybe<T> after(Maybe<T> maybe, long timeout, TimeUnit unit) {
|
||||
return RxJava2Adapter.monoToMaybe(
|
||||
RxJava2Adapter.maybeToMono(maybe).timeout(Duration.of(timeout, unit.toChronoUnit())));
|
||||
}
|
||||
}
|
||||
|
||||
static final class MaybeTimeOut<T> {
|
||||
@BeforeTemplate
|
||||
|
||||
@@ -19,7 +19,9 @@ import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.functions.Predicate;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.adapter.rxjava.RxJava2Adapter;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -643,7 +645,22 @@ final class RxJavaObservableToReactorTemplates {
|
||||
// XXX: public final Observable timeInterval(TimeUnit,Scheduler)
|
||||
// XXX: public final Observable timeout(Function)
|
||||
// XXX: public final Observable timeout(Function,ObservableSource)
|
||||
// XXX: public final Observable timeout(long,TimeUnit)
|
||||
|
||||
// Default BackpressureStrategy.BUFFER is set
|
||||
static final class ObservableTimeoutLongTimeUnit<T> {
|
||||
@BeforeTemplate
|
||||
Observable<T> before(Observable<T> observable, long timeout, TimeUnit unit) {
|
||||
return observable.timeout(timeout, unit);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Observable<T> after(Observable<T> observable, long timeout, TimeUnit unit) {
|
||||
return RxJava2Adapter.fluxToObservable(
|
||||
RxJava2Adapter.observableToFlux(observable, BackpressureStrategy.BUFFER)
|
||||
.timeout(Duration.of(timeout, unit.toChronoUnit())));
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: public final Observable timeout(long,TimeUnit,ObservableSource)
|
||||
// XXX: public final Observable timeout(long,TimeUnit,Scheduler)
|
||||
// XXX: public final Observable timeout(long,TimeUnit,Scheduler,ObservableSource)
|
||||
@@ -655,7 +672,7 @@ final class RxJavaObservableToReactorTemplates {
|
||||
// XXX: public final Observable timestamp(TimeUnit,Scheduler)
|
||||
// XXX: public final Object to(Function)
|
||||
|
||||
static final class CompletableToFlowable<T> {
|
||||
static final class ObservableToFlowable<T> {
|
||||
@BeforeTemplate
|
||||
Flowable<T> before(Observable<T> observable, BackpressureStrategy strategy) {
|
||||
return observable.toFlowable(strategy);
|
||||
|
||||
@@ -550,11 +550,24 @@ final class RxJavaSingleToReactorTemplates {
|
||||
// XXX: public final Single takeUntil(CompletableSource)
|
||||
// XXX: public final Single takeUntil(Publisher)
|
||||
// XXX: public final Single takeUntil(SingleSource)
|
||||
// XXX: public final Single timeout(long,TimeUnit)
|
||||
|
||||
static final class SingleTimeoutLongTimeUnit<T> {
|
||||
@BeforeTemplate
|
||||
Single<T> before(Single<T> single, long timeout, TimeUnit unit) {
|
||||
return single.timeout(timeout, unit);
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
Single<T> after(Single<T> single, long timeout, TimeUnit unit) {
|
||||
return RxJava2Adapter.monoToSingle(
|
||||
RxJava2Adapter.singleToMono(single).timeout(Duration.of(timeout, unit.toChronoUnit())));
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: public final Single timeout(long,TimeUnit,Scheduler)
|
||||
// XXX: public final Single timeout(long,TimeUnit,Scheduler,SingleSource)
|
||||
|
||||
static final class SingleTimeOut<T> {
|
||||
static final class SingleTimeoutLongTimeUnitSingleSource<T> {
|
||||
@BeforeTemplate
|
||||
Single<T> before(
|
||||
Single<T> single, long timeout, TimeUnit unit, SingleSource<? extends T> other) {
|
||||
|
||||
@@ -170,6 +170,27 @@ final class RxJavaToReactorUnwrapTemplates {
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add test
|
||||
@SuppressWarnings("unchecked")
|
||||
abstract static class SingleOnResumeUnwrapLambdaSpecialCase<T, R> {
|
||||
@Placeholder
|
||||
abstract Mono<R> placeholder(@MayOptionallyUse Throwable input);
|
||||
|
||||
@BeforeTemplate
|
||||
java.util.function.Function<? extends Throwable, ? extends Mono<? extends R>> before() {
|
||||
return e ->
|
||||
RxJava2Adapter.singleToMono(
|
||||
RxJavaReactorMigrationUtil.<Throwable, Single<R>>toJdkFunction(
|
||||
t -> RxJava2Adapter.monoToSingle(placeholder(t)))
|
||||
.apply(e));
|
||||
}
|
||||
|
||||
@AfterTemplate
|
||||
java.util.function.Function<Throwable, ? extends Mono<? extends R>> after() {
|
||||
return v -> placeholder(v);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX: Add test
|
||||
abstract static class FlowableConcatMapMaybeDelayErrorUnwrapLambda<T, R> {
|
||||
@Placeholder
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.reactivex.Maybe;
|
||||
import io.reactivex.Single;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
final class RxJavaCompletableReactorTemplatesTest implements RefasterTemplateTestCase {
|
||||
|
||||
@@ -94,6 +95,10 @@ final class RxJavaCompletableReactorTemplatesTest implements RefasterTemplateTes
|
||||
return Completable.complete().onErrorComplete(throwable -> true);
|
||||
}
|
||||
|
||||
Completable testCompletableTimeoutLongTimeUnit() {
|
||||
return Completable.complete().timeout(1000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
Flowable<Void> testCompletableToFlowable() {
|
||||
return Completable.complete().toFlowable();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ import io.reactivex.Flowable;
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.Single;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import reactor.adapter.rxjava.RxJava2Adapter;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -130,6 +132,12 @@ final class RxJavaCompletableReactorTemplatesTest implements RefasterTemplateTes
|
||||
RxJavaReactorMigrationUtil.toJdkPredicate(throwable -> true), t -> Mono.empty()));
|
||||
}
|
||||
|
||||
Completable testCompletableTimeoutLongTimeUnit() {
|
||||
return RxJava2Adapter.monoToCompletable(
|
||||
RxJava2Adapter.completableToMono(Completable.complete())
|
||||
.timeout(Duration.of(1000, TimeUnit.MILLISECONDS.toChronoUnit())));
|
||||
}
|
||||
|
||||
Flowable<Void> testCompletableToFlowable() {
|
||||
return RxJava2Adapter.fluxToFlowable(
|
||||
RxJava2Adapter.completableToMono(Completable.complete()).flux());
|
||||
|
||||
@@ -13,6 +13,7 @@ import io.reactivex.functions.Function;
|
||||
import io.reactivex.internal.functions.Functions;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import reactor.adapter.rxjava.RxJava2Adapter;
|
||||
import reactor.core.publisher.Flux;
|
||||
import tech.picnic.errorprone.migration.util.RxJavaReactorMigrationUtil;
|
||||
@@ -227,6 +228,10 @@ final class RxJavaFlowableToReactorTemplatesTest implements RefasterTemplateTest
|
||||
Flowable.just(1).subscribe(i -> {}, i -> {}, () -> {});
|
||||
}
|
||||
|
||||
Flowable<Integer> testFlowableTimeoutLongTimeUnit() {
|
||||
return Flowable.just(1).timeout(1000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
Single<List<Integer>> testFlowableToList() {
|
||||
return Flowable.just(1, 2).toList();
|
||||
}
|
||||
|
||||
@@ -11,8 +11,10 @@ import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.internal.functions.Functions;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import reactor.adapter.rxjava.RxJava2Adapter;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -313,6 +315,12 @@ final class RxJavaFlowableToReactorTemplatesTest implements RefasterTemplateTest
|
||||
RxJavaReactorMigrationUtil.toRunnable(() -> {}));
|
||||
}
|
||||
|
||||
Flowable<Integer> testFlowableTimeoutLongTimeUnit() {
|
||||
return RxJava2Adapter.fluxToFlowable(
|
||||
RxJava2Adapter.flowableToFlux(Flowable.just(1))
|
||||
.timeout(Duration.of(1000, TimeUnit.MILLISECONDS.toChronoUnit())));
|
||||
}
|
||||
|
||||
Single<List<Integer>> testFlowableToList() {
|
||||
return RxJava2Adapter.monoToSingle(
|
||||
RxJava2Adapter.flowableToFlux(Flowable.just(1, 2)).collectList());
|
||||
|
||||
@@ -204,6 +204,10 @@ final class RxJavaMaybeToReactorTemplatesTest implements RefasterTemplateTestCas
|
||||
}));
|
||||
}
|
||||
|
||||
Maybe<Integer> testMaybeTimeoutLongTimeUnit() {
|
||||
return Maybe.just(1).timeout(1000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
Maybe<Object> testMaybeTimeOut() {
|
||||
return Maybe.empty().timeout(100, TimeUnit.MILLISECONDS, Maybe.just(2));
|
||||
}
|
||||
|
||||
@@ -292,6 +292,12 @@ final class RxJavaMaybeToReactorTemplatesTest implements RefasterTemplateTestCas
|
||||
})))));
|
||||
}
|
||||
|
||||
Maybe<Integer> testMaybeTimeoutLongTimeUnit() {
|
||||
return RxJava2Adapter.monoToMaybe(
|
||||
RxJava2Adapter.maybeToMono(Maybe.just(1))
|
||||
.timeout(Duration.of(1000, TimeUnit.MILLISECONDS.toChronoUnit())));
|
||||
}
|
||||
|
||||
Maybe<Object> testMaybeTimeOut() {
|
||||
return RxJava2Adapter.monoToMaybe(
|
||||
RxJava2Adapter.maybeToMono(Maybe.empty())
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.reactivex.Completable;
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.Observable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
final class RxJavaObservableToReactorTemplatesTest implements RefasterTemplateTestCase {
|
||||
|
||||
@@ -41,7 +42,11 @@ final class RxJavaObservableToReactorTemplatesTest implements RefasterTemplateTe
|
||||
return Observable.just(1, 2).ignoreElements();
|
||||
}
|
||||
|
||||
Flowable<Integer> testCompletableToFlowable() {
|
||||
Observable<Integer> testObservableTimeoutLongTimeUnit() {
|
||||
return Observable.just(1).timeout(1000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
Flowable<Integer> testObservableToFlowable() {
|
||||
return Observable.just(1).toFlowable(BackpressureStrategy.BUFFER);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ import io.reactivex.Completable;
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.Observable;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import reactor.adapter.rxjava.RxJava2Adapter;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
@@ -57,7 +59,13 @@ final class RxJavaObservableToReactorTemplatesTest implements RefasterTemplateTe
|
||||
.then());
|
||||
}
|
||||
|
||||
Flowable<Integer> testCompletableToFlowable() {
|
||||
Observable<Integer> testObservableTimeoutLongTimeUnit() {
|
||||
return RxJava2Adapter.fluxToObservable(
|
||||
RxJava2Adapter.observableToFlux(Observable.just(1), BackpressureStrategy.BUFFER)
|
||||
.timeout(Duration.of(1000, TimeUnit.MILLISECONDS.toChronoUnit())));
|
||||
}
|
||||
|
||||
Flowable<Integer> testObservableToFlowable() {
|
||||
return RxJava2Adapter.fluxToFlowable(
|
||||
RxJava2Adapter.observableToFlux(Observable.just(1), BackpressureStrategy.BUFFER));
|
||||
}
|
||||
|
||||
@@ -104,7 +104,11 @@ final class RxJavaSingleToReactorTemplatesTest implements RefasterTemplateTestCa
|
||||
return Single.just(1).toFlowable();
|
||||
}
|
||||
|
||||
Single<Integer> testSingleTimeOut() {
|
||||
Single<Integer> testSingleTimeoutLongTimeUnit() {
|
||||
return Single.just(1).timeout(1000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
Single<Integer> testSingleTimeoutLongTimeUnitSingleSource() {
|
||||
return Single.just(1).timeout(1000, TimeUnit.MILLISECONDS, Single.just(2));
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,13 @@ final class RxJavaSingleToReactorTemplatesTest implements RefasterTemplateTestCa
|
||||
return RxJava2Adapter.fluxToFlowable(RxJava2Adapter.singleToMono(Single.just(1)).flux());
|
||||
}
|
||||
|
||||
Single<Integer> testSingleTimeOut() {
|
||||
Single<Integer> testSingleTimeoutLongTimeUnit() {
|
||||
return RxJava2Adapter.monoToSingle(
|
||||
RxJava2Adapter.singleToMono(Single.just(1))
|
||||
.timeout(Duration.of(1000, TimeUnit.MILLISECONDS.toChronoUnit())));
|
||||
}
|
||||
|
||||
Single<Integer> testSingleTimeoutLongTimeUnitSingleSource() {
|
||||
return RxJava2Adapter.monoToSingle(
|
||||
RxJava2Adapter.singleToMono(Single.just(1))
|
||||
.timeout(
|
||||
|
||||
Reference in New Issue
Block a user