diff --git a/build.gradle b/build.gradle index 0413b92cfc..2dd83e7cfe 100644 --- a/build.gradle +++ b/build.gradle @@ -16,8 +16,8 @@ dependencies { testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.19' - perfCompile 'org.openjdk.jmh:jmh-core:1.10.5' - perfCompile 'org.openjdk.jmh:jmh-generator-annprocess:1.10.5' + perfCompile 'org.openjdk.jmh:jmh-core:1.11.3' + perfCompile 'org.openjdk.jmh:jmh-generator-annprocess:1.11.3' // perfCompile 'org.reactivex:rxjava:1.0.14' } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 784da58f34..d52ce81ab6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index f769188ae9..32d6b2dfd1 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -18,7 +18,7 @@ import org.reactivestreams.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.*; import io.reactivex.Single.*; import io.reactivex.annotations.*; import io.reactivex.disposables.*; @@ -353,7 +353,7 @@ public static Completable concat(Iterable sources) { * @throws NullPointerException if sources is null */ @SchedulerSupport(SchedulerKind.NONE) - public static Completable concat(Observable sources) { + public static Completable concat(Flowable sources) { return concat(sources, 2); } @@ -365,7 +365,7 @@ public static Completable concat(Observable sources) { * @throws NullPointerException if sources is null */ @SchedulerSupport(SchedulerKind.NONE) - public static Completable concat(Observable sources, int prefetch) { + public static Completable concat(Flowable sources, int prefetch) { Objects.requireNonNull(sources, "sources is null"); if (prefetch < 1) { throw new IllegalArgumentException("prefetch > 0 required but it was " + prefetch); @@ -517,7 +517,7 @@ public void accept(CompletableSubscriber s) { * @throws NullPointerException if flowable is null */ @SchedulerSupport(SchedulerKind.NONE) - public static Completable fromFlowable(final Observable flowable) { + public static Completable fromFlowable(final Flowable flowable) { Objects.requireNonNull(flowable, "flowable is null"); return create(new CompletableOnSubscribe() { @Override @@ -559,12 +559,12 @@ public void onSubscribe(Subscription s) { * @throws NullPointerException if flowable is null */ @SchedulerSupport(SchedulerKind.NONE) - public static Completable fromNbpObservable(final NbpObservable observable) { + public static Completable fromNbpObservable(final Observable observable) { Objects.requireNonNull(observable, "observable is null"); return create(new CompletableOnSubscribe() { @Override public void accept(final CompletableSubscriber s) { - observable.subscribe(new NbpSubscriber() { + observable.subscribe(new Observer() { @Override public void onComplete() { @@ -695,7 +695,7 @@ public static Completable merge(Iterable sources) { * @return the new Completable instance * @throws NullPointerException if sources is null */ - public static Completable merge(Observable sources) { + public static Completable merge(Flowable sources) { return merge0(sources, Integer.MAX_VALUE, false); } @@ -708,7 +708,7 @@ public static Completable merge(Observable sources) { * @throws NullPointerException if sources is null * @throws IllegalArgumentException if maxConcurrency is less than 1 */ - public static Completable merge(Observable sources, int maxConcurrency) { + public static Completable merge(Flowable sources, int maxConcurrency) { return merge0(sources, maxConcurrency, false); } @@ -724,7 +724,7 @@ public static Completable merge(Observable sources, int m * @throws NullPointerException if sources is null * @throws IllegalArgumentException if maxConcurrency is less than 1 */ - protected static Completable merge0(Observable sources, int maxConcurrency, boolean delayErrors) { + protected static Completable merge0(Flowable sources, int maxConcurrency, boolean delayErrors) { Objects.requireNonNull(sources, "sources is null"); if (maxConcurrency < 1) { throw new IllegalArgumentException("maxConcurrency > 0 required but it was " + maxConcurrency); @@ -767,7 +767,7 @@ public static Completable mergeDelayError(Iterable source * @return the new Completable instance * @throws NullPointerException if sources is null */ - public static Completable mergeDelayError(Observable sources) { + public static Completable mergeDelayError(Flowable sources) { return merge0(sources, Integer.MAX_VALUE, true); } @@ -781,7 +781,7 @@ public static Completable mergeDelayError(Observable sour * @return the new Completable instance * @throws NullPointerException if sources is null */ - public static Completable mergeDelayError(Observable sources, int maxConcurrency) { + public static Completable mergeDelayError(Flowable sources, int maxConcurrency) { return merge0(sources, maxConcurrency, true); } @@ -1390,7 +1390,7 @@ public final Completable endWith(Completable other) { * @throws NullPointerException if next is null */ @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable endWith(NbpObservable next) { + public final Observable endWith(Observable next) { return next.startWith(this.toNbpObservable()); } @@ -1403,7 +1403,7 @@ public final NbpObservable endWith(NbpObservable next) { * @throws NullPointerException if next is null */ @SchedulerSupport(SchedulerKind.CUSTOM) - public final Observable endWith(Observable next) { + public final Flowable endWith(Flowable next) { return next.startWith(this.toFlowable()); } @@ -1787,7 +1787,7 @@ public final Completable repeatUntil(BooleanSupplier stop) { * FIXME the Observable type doesn't make sense here because nulls are not allowed * FIXME add unit test once the type has been fixed */ - public final Completable repeatWhen(Function, ? extends Publisher> handler) { + public final Completable repeatWhen(Function, ? extends Publisher> handler) { return fromFlowable(toFlowable().repeatWhen(handler)); } @@ -1847,7 +1847,7 @@ public final Completable retry(Predicate predicate) { * @throws NullPointerException if handler is null */ @SchedulerSupport(SchedulerKind.NONE) - public final Completable retryWhen(Function, ? extends Publisher> handler) { + public final Completable retryWhen(Function, ? extends Publisher> handler) { return fromFlowable(toFlowable().retryWhen(handler)); } @@ -1873,7 +1873,7 @@ public final Completable startWith(Completable other) { * @throws NullPointerException if other is null */ @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable startWith(NbpObservable other) { + public final Observable startWith(Observable other) { Objects.requireNonNull(other, "other is null"); return other.endWith(this.toNbpObservable()); } @@ -1886,7 +1886,7 @@ public final NbpObservable startWith(NbpObservable other) { * @throws NullPointerException if other is null */ @SchedulerSupport(SchedulerKind.NONE) - public final Observable startWith(Observable other) { + public final Flowable startWith(Flowable other) { Objects.requireNonNull(other, "other is null"); return other.endWith(this.toFlowable()); } @@ -1988,7 +1988,7 @@ public void onSubscribe(Disposable d) { * @throws NullPointerException if s is null */ @SchedulerSupport(SchedulerKind.NONE) - public final void subscribe(final NbpSubscriber s) { + public final void subscribe(final Observer s) { Objects.requireNonNull(s, "s is null"); try { // TODO plugin wrapping the subscriber @@ -2221,8 +2221,8 @@ public final U to(Function converter) { * @return the new Observable created */ @SchedulerSupport(SchedulerKind.NONE) - public final Observable toFlowable() { - return Observable.create(new Publisher() { + public final Flowable toFlowable() { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { Completable.this.subscribe(s); @@ -2237,10 +2237,10 @@ public void subscribe(Subscriber s) { * @return the new NbpObservable created */ @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable toNbpObservable() { - return NbpObservable.create(new NbpOnSubscribe() { + public final Observable toNbpObservable() { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { subscribe(s); } }); diff --git a/src/main/java/io/reactivex/Flowable.java b/src/main/java/io/reactivex/Flowable.java new file mode 100644 index 0000000000..6407ac73af --- /dev/null +++ b/src/main/java/io/reactivex/Flowable.java @@ -0,0 +1,3750 @@ +/** + * Copyright 2016 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ +package io.reactivex; + + +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.AtomicReference; + +import org.reactivestreams.*; + +import io.reactivex.annotations.*; +import io.reactivex.disposables.Disposable; +import io.reactivex.flowables.*; +import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; +import io.reactivex.internal.functions.Objects; +import io.reactivex.internal.operators.flowable.*; +import io.reactivex.internal.subscribers.flowable.*; +import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.schedulers.*; +import io.reactivex.subscribers.*; + +public class Flowable implements Publisher { + /** + * Interface to map/wrap a downstream subscriber to an upstream subscriber. + * + * @param the value type of the downstream + * @param the value type of the upstream + */ + public interface Operator extends Function, Subscriber> { + + } + + /** + * Interface to compose observables. + * + * @param the upstream value type + * @param the downstream value type + */ + public interface Transformer extends Function, Publisher> { + + } + + /** The default buffer size. */ + static final int BUFFER_SIZE; + static { + BUFFER_SIZE = Math.max(16, Integer.getInteger("rx2.buffer-size", 128)); + } + + /** An empty observable instance as there is no need to instantiate this more than once. */ + static final Flowable EMPTY = create(PublisherEmptySource.INSTANCE); + + /** A never observable instance as there is no need to instantiate this more than once. */ + static final Flowable NEVER = create(new Publisher() { + @Override + public void subscribe(Subscriber s) { + s.onSubscribe(EmptySubscription.INSTANCE); + } + }); + + public static Flowable amb(Iterable> sources) { + Objects.requireNonNull(sources, "sources is null"); + return create(new PublisherAmb(null, sources)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable amb(Publisher... sources) { + Objects.requireNonNull(sources, "sources is null"); + int len = sources.length; + if (len == 0) { + return empty(); + } else + if (len == 1) { + return fromPublisher(sources[0]); + } + return create(new PublisherAmb(sources, null)); + } + + public static int bufferSize() { + return BUFFER_SIZE; + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest(Function combiner, boolean delayError, int bufferSize, Publisher... sources) { + return combineLatest(sources, combiner, delayError, bufferSize); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest(Iterable> sources, Function combiner) { + return combineLatest(sources, combiner, false, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest(Iterable> sources, Function combiner, boolean delayError) { + return combineLatest(sources, combiner, delayError, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest(Iterable> sources, Function combiner, boolean delayError, int bufferSize) { + Objects.requireNonNull(sources, "sources is null"); + Objects.requireNonNull(combiner, "combiner is null"); + validateBufferSize(bufferSize); + + // the queue holds a pair of values so we need to double the capacity + int s = bufferSize << 1; + return create(new PublisherCombineLatest(null, sources, combiner, s, delayError)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest(Publisher[] sources, Function combiner) { + return combineLatest(sources, combiner, false, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest(Publisher[] sources, Function combiner, boolean delayError) { + return combineLatest(sources, combiner, delayError, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest(Publisher[] sources, Function combiner, boolean delayError, int bufferSize) { + validateBufferSize(bufferSize); + Objects.requireNonNull(combiner, "combiner is null"); + if (sources.length == 0) { + return empty(); + } + // the queue holds a pair of values so we need to double the capacity + int s = bufferSize << 1; + return create(new PublisherCombineLatest(sources, null, combiner, s, delayError)); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest( + Publisher p1, Publisher p2, + BiFunction combiner) { + Function f = Functions.toFunction(combiner); + return combineLatest(f, false, bufferSize(), p1, p2); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest( + Publisher p1, Publisher p2, + Publisher p3, + Function3 combiner) { + return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4, + Function4 combiner) { + return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4, + Publisher p5, + Function5 combiner) { + return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4, + Publisher p5, Publisher p6, + Function6 combiner) { + return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5, p6); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4, + Publisher p5, Publisher p6, + Publisher p7, + Function7 combiner) { + return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4, + Publisher p5, Publisher p6, + Publisher p7, Publisher p8, + Function8 combiner) { + return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7, p8); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable combineLatest( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4, + Publisher p5, Publisher p6, + Publisher p7, Publisher p8, + Publisher p9, + Function9 combiner) { + return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7, p8, p9); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable concat(int prefetch, Iterable> sources) { + Objects.requireNonNull(sources, "sources is null"); + return fromIterable(sources).concatMap((Function)Functions.identity(), prefetch); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable concat(Iterable> sources) { + Objects.requireNonNull(sources, "sources is null"); + return fromIterable(sources).concatMap((Function)Functions.identity()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static final Flowable concat(Publisher> sources) { + return concat(sources, bufferSize()); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static final Flowable concat(Publisher> sources, int bufferSize) { + return fromPublisher(sources).concatMap((Function)Functions.identity()); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable concat(Publisher p1, Publisher p2) { + return concatArray(p1, p2); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable concat( + Publisher p1, Publisher p2, + Publisher p3) { + return concatArray(p1, p2, p3); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable concat( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4) { + return concatArray(p1, p2, p3, p4); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable concat( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4, + Publisher p5 + ) { + return concatArray(p1, p2, p3, p4, p5); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable concat( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4, + Publisher p5, Publisher p6 + ) { + return concatArray(p1, p2, p3, p4, p5, p6); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable concat( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4, + Publisher p5, Publisher p6, + Publisher p7 + ) { + return concatArray(p1, p2, p3, p4, p5, p6, p7); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable concat( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4, + Publisher p5, Publisher p6, + Publisher p7, Publisher p8 + ) { + return concatArray(p1, p2, p3, p4, p5, p6, p7, p8); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable concat( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4, + Publisher p5, Publisher p6, + Publisher p7, Publisher p8, + Publisher p9 + ) { + return concatArray(p1, p2, p3, p4, p5, p6, p7, p8, p9); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable concatArray(int prefetch, Publisher... sources) { + Objects.requireNonNull(sources, "sources is null"); + return fromArray(sources).concatMap((Function)Functions.identity(), prefetch); + } + + /** + * Concatenates a variable number of Observable sources. + *

+ * Note: named this way because of overload conflict with concat(NbpObservable<NbpObservable>) + * @param sources the array of sources + * @param the common base value type + * @return the new NbpObservable instance + * @throws NullPointerException if sources is null + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable concatArray(Publisher... sources) { + if (sources.length == 0) { + return empty(); + } else + if (sources.length == 1) { + return fromPublisher(sources[0]); + } + return fromArray(sources).concatMap((Function)Functions.identity()); + } + + @BackpressureSupport(BackpressureKind.NONE) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable create(Publisher onSubscribe) { + Objects.requireNonNull(onSubscribe, "onSubscribe is null"); + onSubscribe = RxJavaPlugins.onCreate(onSubscribe); + return new Flowable(onSubscribe); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable defer(Supplier> supplier) { + Objects.requireNonNull(supplier, "supplier is null"); + return create(new PublisherDefer(supplier)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + @SuppressWarnings("unchecked") + public static Flowable empty() { + return (Flowable)EMPTY; + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable error(Supplier errorSupplier) { + Objects.requireNonNull(errorSupplier, "errorSupplier is null"); + return create(new PublisherErrorSource(errorSupplier)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable error(final Throwable e) { + Objects.requireNonNull(e, "e is null"); + return error(new Supplier() { + @Override + public Throwable get() { + return e; + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable fromArray(T... values) { + Objects.requireNonNull(values, "values is null"); + if (values.length == 0) { + return empty(); + } else + if (values.length == 1) { + return just(values[0]); + } + return create(new PublisherArraySource(values)); + } + + // TODO match naming with RxJava 1.x + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable fromCallable(Callable supplier) { + Objects.requireNonNull(supplier, "supplier is null"); + return create(new PublisherScalarAsyncSource(supplier)); + } + + /* + * It doesn't add cancellation support by default like 1.x + * if necessary, one can use composition to achieve it: + * futureObservable.doOnCancel(() -> future.cancel(true)); + */ + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable fromFuture(Future future) { + Objects.requireNonNull(future, "future is null"); + Flowable o = create(new PublisherFutureSource(future, 0L, null)); + + return o; + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable fromFuture(Future future, long timeout, TimeUnit unit) { + Objects.requireNonNull(future, "future is null"); + Objects.requireNonNull(unit, "unit is null"); + Flowable o = create(new PublisherFutureSource(future, timeout, unit)); + return o; + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public static Flowable fromFuture(Future future, long timeout, TimeUnit unit, Scheduler scheduler) { + Objects.requireNonNull(scheduler, "scheduler is null"); + Flowable o = fromFuture(future, timeout, unit); + return o.subscribeOn(scheduler); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.IO) + public static Flowable fromFuture(Future future, Scheduler scheduler) { + Objects.requireNonNull(scheduler, "scheduler is null"); + Flowable o = fromFuture(future); + return o.subscribeOn(Schedulers.io()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable fromIterable(Iterable source) { + Objects.requireNonNull(source, "source is null"); + return create(new PublisherIterableSource(source)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + @SuppressWarnings("unchecked") + public static Flowable fromPublisher(final Publisher publisher) { + if (publisher instanceof Flowable) { + return (Flowable)publisher; + } + Objects.requireNonNull(publisher, "publisher is null"); + + return create(new Publisher() { + @Override + public void subscribe(Subscriber s) { + publisher.subscribe(s); + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable generate(final Consumer> generator) { + Objects.requireNonNull(generator, "generator is null"); + return generate(Functions.nullSupplier(), + new BiFunction, Object>() { + @Override + public Object apply(Object s, Subscriber o) { + generator.accept(o); + return s; + } + }, Functions.emptyConsumer()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable generate(Supplier initialState, final BiConsumer> generator) { + Objects.requireNonNull(generator, "generator is null"); + return generate(initialState, new BiFunction, S>() { + @Override + public S apply(S s, Subscriber o) { + generator.accept(s, o); + return s; + } + }, Functions.emptyConsumer()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable generate(Supplier initialState, final BiConsumer> generator, Consumer disposeState) { + Objects.requireNonNull(generator, "generator is null"); + return generate(initialState, new BiFunction, S>() { + @Override + public S apply(S s, Subscriber o) { + generator.accept(s, o); + return s; + } + }, disposeState); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable generate(Supplier initialState, BiFunction, S> generator) { + return generate(initialState, generator, Functions.emptyConsumer()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable generate(Supplier initialState, BiFunction, S> generator, Consumer disposeState) { + Objects.requireNonNull(initialState, "initialState is null"); + Objects.requireNonNull(generator, "generator is null"); + Objects.requireNonNull(disposeState, "disposeState is null"); + return create(new PublisherGenerate(initialState, generator, disposeState)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public static Flowable interval(long initialDelay, long period, TimeUnit unit) { + return interval(initialDelay, period, unit, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public static Flowable interval(long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { + if (initialDelay < 0) { + initialDelay = 0L; + } + if (period < 0) { + period = 0L; + } + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + + return create(new PublisherIntervalSource(initialDelay, period, unit, scheduler)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public static Flowable interval(long period, TimeUnit unit) { + return interval(period, period, unit, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public static Flowable interval(long period, TimeUnit unit, Scheduler scheduler) { + return interval(period, period, unit, scheduler); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public static Flowable intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit) { + return intervalRange(start, count, initialDelay, period, unit, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public static Flowable intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { + + long end = start + (count - 1); + if (end < 0) { + throw new IllegalArgumentException("Overflow! start + count is bigger than Long.MAX_VALUE"); + } + + if (initialDelay < 0) { + initialDelay = 0L; + } + if (period < 0) { + period = 0L; + } + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + + return create(new PublisherIntervalRangeSource(start, end, initialDelay, period, unit, scheduler)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable just(T value) { + Objects.requireNonNull(value, "value is null"); + return new ObservableScalarSource(value); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static final Flowable just(T v1, T v2) { + Objects.requireNonNull(v1, "The first value is null"); + Objects.requireNonNull(v2, "The second value is null"); + + return fromArray(v1, v2); + } + + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static final Flowable just(T v1, T v2, T v3) { + Objects.requireNonNull(v1, "The first value is null"); + Objects.requireNonNull(v2, "The second value is null"); + Objects.requireNonNull(v3, "The third value is null"); + + return fromArray(v1, v2, v3); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static final Flowable just(T v1, T v2, T v3, T v4) { + Objects.requireNonNull(v1, "The first value is null"); + Objects.requireNonNull(v2, "The second value is null"); + Objects.requireNonNull(v3, "The third value is null"); + Objects.requireNonNull(v4, "The fourth value is null"); + + return fromArray(v1, v2, v3, v4); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static final Flowable just(T v1, T v2, T v3, T v4, T v5) { + Objects.requireNonNull(v1, "The first value is null"); + Objects.requireNonNull(v2, "The second value is null"); + Objects.requireNonNull(v3, "The third value is null"); + Objects.requireNonNull(v4, "The fourth value is null"); + Objects.requireNonNull(v5, "The fifth value is null"); + + return fromArray(v1, v2, v3, v4, v5); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static final Flowable just(T v1, T v2, T v3, T v4, T v5, T v6) { + Objects.requireNonNull(v1, "The first value is null"); + Objects.requireNonNull(v2, "The second value is null"); + Objects.requireNonNull(v3, "The third value is null"); + Objects.requireNonNull(v4, "The fourth value is null"); + Objects.requireNonNull(v5, "The fifth value is null"); + Objects.requireNonNull(v6, "The sixth value is null"); + + return fromArray(v1, v2, v3, v4, v5, v6); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static final Flowable just(T v1, T v2, T v3, T v4, T v5, T v6, T v7) { + Objects.requireNonNull(v1, "The first value is null"); + Objects.requireNonNull(v2, "The second value is null"); + Objects.requireNonNull(v3, "The third value is null"); + Objects.requireNonNull(v4, "The fourth value is null"); + Objects.requireNonNull(v5, "The fifth value is null"); + Objects.requireNonNull(v6, "The sixth value is null"); + Objects.requireNonNull(v7, "The seventh value is null"); + + return fromArray(v1, v2, v3, v4, v5, v6, v7); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static final Flowable just(T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8) { + Objects.requireNonNull(v1, "The first value is null"); + Objects.requireNonNull(v2, "The second value is null"); + Objects.requireNonNull(v3, "The third value is null"); + Objects.requireNonNull(v4, "The fourth value is null"); + Objects.requireNonNull(v5, "The fifth value is null"); + Objects.requireNonNull(v6, "The sixth value is null"); + Objects.requireNonNull(v7, "The seventh value is null"); + Objects.requireNonNull(v8, "The eigth value is null"); + + return fromArray(v1, v2, v3, v4, v5, v6, v7, v8); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static final Flowable just(T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8, T v9) { + Objects.requireNonNull(v1, "The first value is null"); + Objects.requireNonNull(v2, "The second value is null"); + Objects.requireNonNull(v3, "The third value is null"); + Objects.requireNonNull(v4, "The fourth value is null"); + Objects.requireNonNull(v5, "The fifth value is null"); + Objects.requireNonNull(v6, "The sixth value is null"); + Objects.requireNonNull(v7, "The seventh value is null"); + Objects.requireNonNull(v8, "The eigth value is null"); + Objects.requireNonNull(v9, "The ninth is null"); + + return fromArray(v1, v2, v3, v4, v5, v6, v7, v8, v9); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable merge(int maxConcurrency, int bufferSize, Iterable> sources) { + return fromIterable(sources).flatMap((Function)Functions.identity(), false, maxConcurrency, bufferSize); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable merge(int maxConcurrency, int bufferSize, Publisher... sources) { + return fromArray(sources).flatMap((Function)Functions.identity(), false, maxConcurrency, bufferSize); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable merge(int maxConcurrency, Publisher... sources) { + return fromArray(sources).flatMap((Function)Functions.identity(), maxConcurrency); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable merge(Iterable> sources) { + return fromIterable(sources).flatMap((Function)Functions.identity()); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable merge(Iterable> sources, int maxConcurrency) { + return fromIterable(sources).flatMap((Function)Functions.identity(), maxConcurrency); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable merge(Publisher> sources) { + return merge(sources, bufferSize()); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable merge(Publisher> sources, int maxConcurrency) { + return fromPublisher(sources).flatMap((Function)Functions.identity(), maxConcurrency); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable merge(Publisher... sources) { + return fromArray(sources).flatMap((Function)Functions.identity(), sources.length); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable merge(Publisher p1, Publisher p2) { + Objects.requireNonNull(p1, "p1 is null"); + Objects.requireNonNull(p2, "p2 is null"); + return fromArray(p1, p2).flatMap((Function)Functions.identity(), false, 2); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable merge(Publisher p1, Publisher p2, Publisher p3) { + Objects.requireNonNull(p1, "p1 is null"); + Objects.requireNonNull(p2, "p2 is null"); + Objects.requireNonNull(p3, "p3 is null"); + return fromArray(p1, p2, p3).flatMap((Function)Functions.identity(), false, 3); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable merge( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4) { + Objects.requireNonNull(p1, "p1 is null"); + Objects.requireNonNull(p2, "p2 is null"); + Objects.requireNonNull(p3, "p3 is null"); + Objects.requireNonNull(p4, "p4 is null"); + return fromArray(p1, p2, p3, p4).flatMap((Function)Functions.identity(), false, 4); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable mergeDelayError(boolean delayErrors, Iterable> sources) { + return fromIterable(sources).flatMap((Function)Functions.identity(), true); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable mergeDelayError(int maxConcurrency, int bufferSize, Iterable> sources) { + return fromIterable(sources).flatMap((Function)Functions.identity(), true, maxConcurrency, bufferSize); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable mergeDelayError(int maxConcurrency, int bufferSize, Publisher... sources) { + return fromArray(sources).flatMap((Function)Functions.identity(), true, maxConcurrency, bufferSize); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable mergeDelayError(int maxConcurrency, Iterable> sources) { + return fromIterable(sources).flatMap((Function)Functions.identity(), true, maxConcurrency); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable mergeDelayError(int maxConcurrency, Publisher... sources) { + return fromArray(sources).flatMap((Function)Functions.identity(), true, maxConcurrency); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable mergeDelayError(Publisher> sources) { + return mergeDelayError(sources, bufferSize()); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable mergeDelayError(Publisher> sources, int maxConcurrency) { + return fromPublisher(sources).flatMap((Function)Functions.identity(), true, maxConcurrency); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable mergeDelayError(Publisher... sources) { + return fromArray(sources).flatMap((Function)Functions.identity(), true, sources.length); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable mergeDelayError(Publisher p1, Publisher p2) { + Objects.requireNonNull(p1, "p1 is null"); + Objects.requireNonNull(p2, "p2 is null"); + return fromArray(p1, p2).flatMap((Function)Functions.identity(), true, 2); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable mergeDelayError(Publisher p1, Publisher p2, Publisher p3) { + Objects.requireNonNull(p1, "p1 is null"); + Objects.requireNonNull(p2, "p2 is null"); + Objects.requireNonNull(p3, "p3 is null"); + return fromArray(p1, p2, p3).flatMap((Function)Functions.identity(), true, 3); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable mergeDelayError( + Publisher p1, Publisher p2, + Publisher p3, Publisher p4) { + Objects.requireNonNull(p1, "p1 is null"); + Objects.requireNonNull(p2, "p2 is null"); + Objects.requireNonNull(p3, "p3 is null"); + Objects.requireNonNull(p4, "p4 is null"); + return fromArray(p1, p2, p3, p4).flatMap((Function)Functions.identity(), true, 4); + } + + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + @SuppressWarnings("unchecked") + public static Flowable never() { + return (Flowable)NEVER; + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable range(int start, int count) { + if (count < 0) { + throw new IllegalArgumentException("count >= required but it was " + count); + } else + if (count == 0) { + return empty(); + } else + if (count == 1) { + return just(start); + } else + if ((long)start + (count - 1) > Integer.MAX_VALUE) { + throw new IllegalArgumentException("Integer overflow"); + } + return create(new PublisherRangeSource(start, count)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable sequenceEqual(Publisher p1, Publisher p2) { + return sequenceEqual(p1, p2, Objects.equalsPredicate(), bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable sequenceEqual(Publisher p1, Publisher p2, BiPredicate isEqual) { + return sequenceEqual(p1, p2, isEqual, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable sequenceEqual(Publisher p1, Publisher p2, BiPredicate isEqual, int bufferSize) { + Objects.requireNonNull(p1, "p1 is null"); + Objects.requireNonNull(p2, "p2 is null"); + Objects.requireNonNull(isEqual, "isEqual is null"); + validateBufferSize(bufferSize); + return create(new PublisherSequenceEqual(p1, p2, isEqual, bufferSize)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable sequenceEqual(Publisher p1, Publisher p2, int bufferSize) { + return sequenceEqual(p1, p2, Objects.equalsPredicate(), bufferSize); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable switchOnNext(int bufferSize, Publisher> sources) { + return fromPublisher(sources).switchMap((Function)Functions.identity(), bufferSize); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable switchOnNext(Publisher> sources) { + return fromPublisher(sources).switchMap((Function)Functions.identity()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public static Flowable timer(long delay, TimeUnit unit) { + return timer(delay, unit, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public static Flowable timer(long delay, TimeUnit unit, Scheduler scheduler) { + if (delay < 0) { + delay = 0L; + } + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + + return create(new PublisherIntervalOnceSource(delay, unit, scheduler)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable using(Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer) { + return using(resourceSupplier, sourceSupplier, disposer, true); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable using(Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer, boolean eager) { + Objects.requireNonNull(resourceSupplier, "resourceSupplier is null"); + Objects.requireNonNull(sourceSupplier, "sourceSupplier is null"); + Objects.requireNonNull(disposer, "disposer is null"); + return create(new PublisherUsing(resourceSupplier, sourceSupplier, disposer, eager)); + } + + private static void validateBufferSize(int bufferSize) { + if (bufferSize <= 0) { + throw new IllegalArgumentException("bufferSize > 0 required but it was " + bufferSize); + } + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zip(Iterable> sources, Function zipper) { + Objects.requireNonNull(zipper, "zipper is null"); + Objects.requireNonNull(sources, "sources is null"); + return create(new PublisherZip(null, sources, zipper, bufferSize(), false)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zip(Publisher> sources, final Function zipper) { + Objects.requireNonNull(zipper, "zipper is null"); + return fromPublisher(sources).toList().flatMap(new Function>, Publisher>() { + @Override + public Publisher apply(List> list) { + return zipIterable(zipper, false, bufferSize(), list); + } + }); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zip( + Publisher p1, Publisher p2, + BiFunction zipper) { + return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zip( + Publisher p1, Publisher p2, + BiFunction zipper, boolean delayError) { + return zipArray(Functions.toFunction(zipper), delayError, bufferSize(), p1, p2); + } + + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zip( + Publisher p1, Publisher p2, + BiFunction zipper, boolean delayError, int bufferSize) { + return zipArray(Functions.toFunction(zipper), delayError, bufferSize, p1, p2); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zip( + Publisher p1, Publisher p2, Publisher p3, + Function3 zipper) { + return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zip( + Publisher p1, Publisher p2, Publisher p3, + Publisher p4, + Function4 zipper) { + return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zip( + Publisher p1, Publisher p2, Publisher p3, + Publisher p4, Publisher p5, + Function5 zipper) { + return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zip( + Publisher p1, Publisher p2, Publisher p3, + Publisher p4, Publisher p5, Publisher p6, + Function6 zipper) { + return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5, p6); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zip( + Publisher p1, Publisher p2, Publisher p3, + Publisher p4, Publisher p5, Publisher p6, + Publisher p7, + Function7 zipper) { + return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zip( + Publisher p1, Publisher p2, Publisher p3, + Publisher p4, Publisher p5, Publisher p6, + Publisher p7, Publisher p8, + Function8 zipper) { + return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7, p8); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zip( + Publisher p1, Publisher p2, Publisher p3, + Publisher p4, Publisher p5, Publisher p6, + Publisher p7, Publisher p8, Publisher p9, + Function9 zipper) { + return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7, p8, p9); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zipArray(Function zipper, + boolean delayError, int bufferSize, Publisher... sources) { + if (sources.length == 0) { + return empty(); + } + Objects.requireNonNull(zipper, "zipper is null"); + validateBufferSize(bufferSize); + return create(new PublisherZip(sources, null, zipper, bufferSize, delayError)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public static Flowable zipIterable(Function zipper, + boolean delayError, int bufferSize, + Iterable> sources) { + Objects.requireNonNull(zipper, "zipper is null"); + Objects.requireNonNull(sources, "sources is null"); + validateBufferSize(bufferSize); + return create(new PublisherZip(null, sources, zipper, bufferSize, delayError)); + } + + final Publisher onSubscribe; + + protected Flowable(Publisher onSubscribe) { + this.onSubscribe = onSubscribe; + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable all(Predicate predicate) { + Objects.requireNonNull(predicate, "predicate is null"); + return lift(new OperatorAll(predicate)); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable ambWith(Publisher other) { + Objects.requireNonNull(other, "other is null"); + return amb(this, other); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable any(Predicate predicate) { + Objects.requireNonNull(predicate, "predicate is null"); + return lift(new OperatorAny(predicate)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable asObservable() { + return create(new Publisher() { + @Override + public void subscribe(Subscriber s) { + Flowable.this.subscribe(s); + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> buffer(int count) { + return buffer(count, count); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> buffer(int count, int skip) { + return buffer(count, skip, new Supplier>() { + @Override + public List get() { + return new ArrayList(); + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final > Flowable buffer(int count, int skip, Supplier bufferSupplier) { + Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); + return lift(new OperatorBuffer(count, skip, bufferSupplier)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final > Flowable buffer(int count, Supplier bufferSupplier) { + return buffer(count, count, bufferSupplier); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable> buffer(long timespan, long timeskip, TimeUnit unit) { + return buffer(timespan, timeskip, unit, Schedulers.computation(), new Supplier>() { + @Override + public List get() { + return new ArrayList(); + } + }); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> buffer(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler) { + return buffer(timespan, timeskip, unit, scheduler, new Supplier>() { + @Override + public List get() { + return new ArrayList(); + } + }); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final > Flowable buffer(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler, Supplier bufferSupplier) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); + return lift(new OperatorBufferTimed(timespan, timeskip, unit, scheduler, bufferSupplier, Integer.MAX_VALUE, false)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable> buffer(long timespan, TimeUnit unit) { + return buffer(timespan, unit, Integer.MAX_VALUE, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable> buffer(long timespan, TimeUnit unit, int count) { + return buffer(timespan, unit, count, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> buffer(long timespan, TimeUnit unit, int count, Scheduler scheduler) { + return buffer(timespan, unit, count, scheduler, new Supplier>() { + @Override + public List get() { + return new ArrayList(); + } + }, false); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final > Flowable buffer( + long timespan, TimeUnit unit, + int count, Scheduler scheduler, + Supplier bufferSupplier, + boolean restartTimerOnMaxSize) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); + if (count <= 0) { + throw new IllegalArgumentException("count > 0 required but it was " + count); + } + return lift(new OperatorBufferTimed(timespan, timespan, unit, scheduler, bufferSupplier, count, restartTimerOnMaxSize)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> buffer(long timespan, TimeUnit unit, Scheduler scheduler) { + return buffer(timespan, unit, Integer.MAX_VALUE, scheduler, new Supplier>() { + @Override + public List get() { + return new ArrayList(); + } + }, false); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> buffer( + Flowable bufferOpenings, + Function> bufferClosingSelector) { + return buffer(bufferOpenings, bufferClosingSelector, new Supplier>() { + @Override + public List get() { + return new ArrayList(); + } + }); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final > Flowable buffer( + Flowable bufferOpenings, + Function> bufferClosingSelector, + Supplier bufferSupplier) { + Objects.requireNonNull(bufferOpenings, "bufferOpenings is null"); + Objects.requireNonNull(bufferClosingSelector, "bufferClosingSelector is null"); + Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); + return lift(new OperatorBufferBoundary(bufferOpenings, bufferClosingSelector, bufferSupplier)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> buffer(Publisher boundary) { + /* + * XXX: javac complains if this is not manually cast, Eclipse is fine + */ + return buffer(boundary, new Supplier>() { + @Override + public List get() { + return new ArrayList(); + } + }); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> buffer(Publisher boundary, final int initialCapacity) { + return buffer(boundary, new Supplier>() { + @Override + public List get() { + return new ArrayList(initialCapacity); + } + }); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final > Flowable buffer(Publisher boundary, Supplier bufferSupplier) { + Objects.requireNonNull(boundary, "boundary is null"); + Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); + return lift(new OperatorBufferExactBoundary(boundary, bufferSupplier)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> buffer(Supplier> boundarySupplier) { + return buffer(boundarySupplier, new Supplier>() { + @Override + public List get() { + return new ArrayList(); + } + }); + + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final > Flowable buffer(Supplier> boundarySupplier, Supplier bufferSupplier) { + Objects.requireNonNull(boundarySupplier, "boundarySupplier is null"); + Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); + return lift(new OperatorBufferBoundarySupplier(boundarySupplier, bufferSupplier)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable cache() { + return CachedObservable.from(this); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable cache(int capacityHint) { + if (capacityHint <= 0) { + throw new IllegalArgumentException("capacityHint > 0 required but it was " + capacityHint); + } + return CachedObservable.from(this, capacityHint); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable cast(final Class clazz) { + Objects.requireNonNull(clazz, "clazz is null"); + return map(new Function() { + @Override + public U apply(T v) { + return clazz.cast(v); + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable collect(Supplier initialValueSupplier, BiConsumer collector) { + Objects.requireNonNull(initialValueSupplier, "initialValueSupplier is null"); + Objects.requireNonNull(collector, "collectior is null"); + return lift(new OperatorCollect(initialValueSupplier, collector)); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable collectInto(final U initialValue, BiConsumer collector) { + Objects.requireNonNull(initialValue, "initialValue is null"); + return collect(new Supplier() { + @Override + public U get() { + return initialValue; + } + }, collector); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + // TODO generics + public final Flowable compose(Transformer composer) { + return fromPublisher(to(composer)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable concatMap(Function> mapper) { + return concatMap(mapper, 2); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable concatMap(Function> mapper, int prefetch) { + Objects.requireNonNull(mapper, "mapper is null"); + if (prefetch <= 0) { + throw new IllegalArgumentException("prefetch > 0 required but it was " + prefetch); + } + return lift(new OperatorConcatMap(mapper, prefetch)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable concatMapIterable(Function> mapper) { + return concatMapIterable(mapper, 2); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable concatMapIterable(final Function> mapper, int prefetch) { + Objects.requireNonNull(mapper, "mapper is null"); + return concatMap(new Function>() { + @Override + public Publisher apply(T v) { + return new PublisherIterableSource(mapper.apply(v)); + } + }, prefetch); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable concatWith(Publisher other) { + Objects.requireNonNull(other, "other is null"); + return concat(this, other); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable contains(final Object o) { + Objects.requireNonNull(o, "o is null"); + return any(new Predicate() { + @Override + public boolean test(T v) { + return Objects.equals(v, o); + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable count() { + return lift(OperatorCount.instance()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable debounce(Function> debounceSelector) { + Objects.requireNonNull(debounceSelector, "debounceSelector is null"); + return lift(new OperatorDebounce(debounceSelector)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable debounce(long timeout, TimeUnit unit) { + return debounce(timeout, unit, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable debounce(long timeout, TimeUnit unit, Scheduler scheduler) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return lift(new OperatorDebounceTimed(timeout, unit, scheduler)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable defaultIfEmpty(T value) { + Objects.requireNonNull(value, "value is null"); + return switchIfEmpty(just(value)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + // TODO a more efficient implementation if necessary + public final Flowable delay(final Function> itemDelay) { + Objects.requireNonNull(itemDelay, "itemDelay is null"); + return flatMap(new Function>() { + @Override + public Publisher apply(final T v) { + return fromPublisher(itemDelay.apply(v)).take(1).map(new Function() { + @Override + public T apply(U u) { + return v; + } + }).defaultIfEmpty(v); + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable delay(long delay, TimeUnit unit) { + return delay(delay, unit, Schedulers.computation(), false); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable delay(long delay, TimeUnit unit, boolean delayError) { + return delay(delay, unit, Schedulers.computation(), delayError); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable delay(long delay, TimeUnit unit, Scheduler scheduler) { + return delay(delay, unit, scheduler, false); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable delay(long delay, TimeUnit unit, Scheduler scheduler, boolean delayError) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + + return lift(new OperatorDelay(delay, unit, scheduler, delayError)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable delay(Supplier> delaySupplier, + Function> itemDelay) { + return delaySubscription(delaySupplier).delay(itemDelay); + } + + /** + * Returns an Observable that delays the subscription to this Observable + * until the other Observable emits an element or completes normally. + *

+ *

+ *
Backpressure:
+ *
The operator forwards the backpressure requests to this Observable once + * the subscription happens and requests Long.MAX_VALUE from the other Observable
+ *
Scheduler:
+ *
This method does not operate by default on a particular {@link Scheduler}.
+ *
+ * + * @param the value type of the other Observable, irrelevant + * @param other the other Observable that should trigger the subscription + * to this Observable. + * @return an Observable that delays the subscription to this Observable + * until the other Observable emits an element or completes normally. + */ + @Experimental + public final Flowable delaySubscription(Publisher other) { + Objects.requireNonNull(other, "other is null"); + return create(new PublisherDelaySubscriptionOther(this, other)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable delaySubscription(long delay, TimeUnit unit) { + return delaySubscription(delay, unit, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + // TODO a more efficient implementation if necessary + public final Flowable delaySubscription(long delay, TimeUnit unit, Scheduler scheduler) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + + return timer(delay, unit, scheduler).flatMap(new Function>() { + @Override + public Publisher apply(Long v) { + return Flowable.this; + } + }); + } + + private static final Object OBJECT = new Object(); + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable delaySubscription(final Supplier> delaySupplier) { + Objects.requireNonNull(delaySupplier, "delaySupplier is null"); + return fromCallable(new Callable() { + @Override + public Object call() throws Exception { + return delaySupplier.get(); + } + }) + .flatMap((Function)Functions.identity()) + .take(1) + .cast(Object.class) // need a common supertype, the value is not relevant + .defaultIfEmpty(OBJECT) // in case the publisher is empty + .flatMap(new Function() { + @Override + public Object apply(Object v) { + return Flowable.this; + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable dematerialize() { + @SuppressWarnings("unchecked") + Flowable>> m = (Flowable>>)this; + return m.lift(OperatorDematerialize.instance()); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable distinct() { + return distinct((Function)Functions.identity(), new Supplier>() { + @Override + public Collection get() { + return new HashSet(); + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable distinct(Function keySelector) { + return distinct(keySelector, new Supplier>() { + @Override + public Collection get() { + return new HashSet(); + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable distinct(Function keySelector, Supplier> collectionSupplier) { + Objects.requireNonNull(keySelector, "keySelector is null"); + Objects.requireNonNull(collectionSupplier, "collectionSupplier is null"); + return lift(OperatorDistinct.withCollection(keySelector, collectionSupplier)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable distinctUntilChanged() { + return lift(OperatorDistinct.untilChanged()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable distinctUntilChanged(Function keySelector) { + Objects.requireNonNull(keySelector, "keySelector is null"); + return lift(OperatorDistinct.untilChanged(keySelector)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable doOnCancel(Runnable onCancel) { + return doOnLifecycle(Functions.emptyConsumer(), Functions.emptyLongConsumer(), onCancel); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable doOnComplete(Runnable onComplete) { + return doOnEach(Functions.emptyConsumer(), Functions.emptyConsumer(), onComplete, Functions.emptyRunnable()); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + private Flowable doOnEach(Consumer onNext, Consumer onError, Runnable onComplete, Runnable onAfterTerminate) { + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(onAfterTerminate, "onAfterTerminate is null"); + return lift(new OperatorDoOnEach(onNext, onError, onComplete, onAfterTerminate)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable doOnEach(final Consumer>> consumer) { + Objects.requireNonNull(consumer, "consumer is null"); + return doOnEach( + new Consumer() { + @Override + public void accept(T v) { + consumer.accept(Try.ofValue(Optional.of(v))); + } + }, + new Consumer() { + @Override + public void accept(Throwable e) { + consumer.accept(Try.>ofError(e)); + } + }, + new Runnable() { + @Override + public void run() { + consumer.accept(Try.ofValue(Optional.empty())); + } + }, + Functions.emptyRunnable() + ); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable doOnEach(final Subscriber observer) { + Objects.requireNonNull(observer, "observer is null"); + return doOnEach(new Consumer() { + @Override + public void accept(T v) { + observer.onNext(v); + } + }, new Consumer() { + @Override + public void accept(Throwable e) { + observer.onError(e); + } + }, new Runnable() { + @Override + public void run() { + observer.onComplete(); + } + }, Functions.emptyRunnable()); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable doOnError(Consumer onError) { + return doOnEach(Functions.emptyConsumer(), onError, Functions.emptyRunnable(), Functions.emptyRunnable()); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable doOnLifecycle(final Consumer onSubscribe, final LongConsumer onRequest, final Runnable onCancel) { + Objects.requireNonNull(onSubscribe, "onSubscribe is null"); + Objects.requireNonNull(onRequest, "onRequest is null"); + Objects.requireNonNull(onCancel, "onCancel is null"); + return lift(new Operator() { + @Override + public Subscriber apply(Subscriber s) { + return new SubscriptionLambdaSubscriber(s, onSubscribe, onRequest, onCancel); + } + }); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable doOnNext(Consumer onNext) { + return doOnEach(onNext, Functions.emptyConsumer(), Functions.emptyRunnable(), Functions.emptyRunnable()); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable doOnRequest(LongConsumer onRequest) { + return doOnLifecycle(Functions.emptyConsumer(), onRequest, Functions.emptyRunnable()); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable doOnSubscribe(Consumer onSubscribe) { + return doOnLifecycle(onSubscribe, Functions.emptyLongConsumer(), Functions.emptyRunnable()); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable doOnTerminate(final Runnable onTerminate) { + return doOnEach(Functions.emptyConsumer(), new Consumer() { + @Override + public void accept(Throwable e) { + onTerminate.run(); + } + }, onTerminate, Functions.emptyRunnable()); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable elementAt(long index) { + if (index < 0) { + throw new IndexOutOfBoundsException("index >= 0 required but it was " + index); + } + return lift(new OperatorElementAt(index, null)); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable elementAt(long index, T defaultValue) { + if (index < 0) { + throw new IndexOutOfBoundsException("index >= 0 required but it was " + index); + } + Objects.requireNonNull(defaultValue, "defaultValue is null"); + return lift(new OperatorElementAt(index, defaultValue)); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable endWith(Iterable values) { + return concatArray(this, fromIterable(values)); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable endWith(Publisher other) { + Objects.requireNonNull(other, "other is null"); + return concatArray(this, other); + } + + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable endWith(T value) { + Objects.requireNonNull(value, "value is null"); + return concatArray(this, just(value)); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable endWithArray(T... values) { + Flowable fromArray = fromArray(values); + if (fromArray == empty()) { + return this; + } + return concatArray(this, fromArray); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable filter(Predicate predicate) { + Objects.requireNonNull(predicate, "predicate is null"); + return lift(new OperatorFilter(predicate)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable finallyDo(Runnable onFinally) { + return doOnEach(Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyRunnable(), onFinally); + } + + @BackpressureSupport(BackpressureKind.SPECIAL) // take may trigger UNBOUNDED_IN + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable first() { + return take(1).single(); + } + + @BackpressureSupport(BackpressureKind.SPECIAL) // take may trigger UNBOUNDED_IN + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable first(T defaultValue) { + return take(1).single(defaultValue); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMap(Function> mapper) { + return flatMap(mapper, false, bufferSize(), bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMap(Function> mapper, boolean delayErrors) { + return flatMap(mapper, delayErrors, bufferSize(), bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMap(Function> mapper, boolean delayErrors, int maxConcurrency) { + return flatMap(mapper, delayErrors, maxConcurrency, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMap(Function> mapper, + boolean delayErrors, int maxConcurrency, int bufferSize) { + Objects.requireNonNull(mapper, "mapper is null"); + if (maxConcurrency <= 0) { + throw new IllegalArgumentException("maxConcurrency > 0 required but it was " + maxConcurrency); + } + validateBufferSize(bufferSize); + if (this instanceof ObservableScalarSource) { + ObservableScalarSource scalar = (ObservableScalarSource) this; + return create(scalar.scalarFlatMap(mapper)); + } + return lift(new OperatorFlatMap(mapper, delayErrors, maxConcurrency, bufferSize)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMap( + Function> onNextMapper, + Function> onErrorMapper, + Supplier> onCompleteSupplier) { + Objects.requireNonNull(onNextMapper, "onNextMapper is null"); + Objects.requireNonNull(onErrorMapper, "onErrorMapper is null"); + Objects.requireNonNull(onCompleteSupplier, "onCompleteSupplier is null"); + return merge(lift(new OperatorMapNotification(onNextMapper, onErrorMapper, onCompleteSupplier))); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMap( + Function> onNextMapper, + Function> onErrorMapper, + Supplier> onCompleteSupplier, + int maxConcurrency) { + Objects.requireNonNull(onNextMapper, "onNextMapper is null"); + Objects.requireNonNull(onErrorMapper, "onErrorMapper is null"); + Objects.requireNonNull(onCompleteSupplier, "onCompleteSupplier is null"); + return merge(lift(new OperatorMapNotification(onNextMapper, onErrorMapper, onCompleteSupplier)), maxConcurrency); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMap(Function> mapper, int maxConcurrency) { + return flatMap(mapper, false, maxConcurrency, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMap(Function> mapper, BiFunction resultSelector) { + return flatMap(mapper, resultSelector, false, bufferSize(), bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMap(Function> mapper, BiFunction combiner, boolean delayError) { + return flatMap(mapper, combiner, delayError, bufferSize(), bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMap(Function> mapper, BiFunction combiner, boolean delayError, int maxConcurrency) { + return flatMap(mapper, combiner, delayError, maxConcurrency, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMap(final Function> mapper, final BiFunction combiner, boolean delayError, int maxConcurrency, int bufferSize) { + Objects.requireNonNull(mapper, "mapper is null"); + Objects.requireNonNull(combiner, "combiner is null"); + return flatMap(new Function>() { + @Override + public Publisher apply(final T t) { + Flowable u = fromPublisher(mapper.apply(t)); + return u.map(new Function() { + @Override + public R apply(U w) { + return combiner.apply(t, w); + } + }); + } + }, delayError, maxConcurrency, bufferSize); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMap(Function> mapper, BiFunction combiner, int maxConcurrency) { + return flatMap(mapper, combiner, false, maxConcurrency, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMapIterable(final Function> mapper) { + Objects.requireNonNull(mapper, "mapper is null"); + return flatMap(new Function>() { + @Override + public Publisher apply(T v) { + return new PublisherIterableSource(mapper.apply(v)); + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMapIterable(final Function> mapper, final BiFunction resultSelector) { + Objects.requireNonNull(mapper, "mapper is null"); + Objects.requireNonNull(resultSelector, "resultSelector is null"); + return flatMap(new Function>() { + @Override + public Publisher apply(T t) { + return new PublisherIterableSource(mapper.apply(t)); + } + }, resultSelector, false, bufferSize(), bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable flatMapIterable(final Function> mapper, int bufferSize) { + return flatMap(new Function>() { + @Override + public Publisher apply(T v) { + return new PublisherIterableSource(mapper.apply(v)); + } + }, false, bufferSize); + } + + @BackpressureSupport(BackpressureKind.NONE) + @SchedulerSupport(SchedulerKind.NONE) + public final Disposable forEach(Consumer onNext) { + return subscribe(onNext); + } + + @BackpressureSupport(BackpressureKind.NONE) + @SchedulerSupport(SchedulerKind.NONE) + public final Disposable forEachWhile(Predicate onNext) { + return forEachWhile(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable()); + } + + @BackpressureSupport(BackpressureKind.NONE) + @SchedulerSupport(SchedulerKind.NONE) + public final Disposable forEachWhile(Predicate onNext, Consumer onError) { + return forEachWhile(onNext, onError, Functions.emptyRunnable()); + } + + @BackpressureSupport(BackpressureKind.NONE) + @SchedulerSupport(SchedulerKind.NONE) + public final Disposable forEachWhile(final Predicate onNext, final Consumer onError, + final Runnable onComplete) { + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); + + final AtomicReference subscription = new AtomicReference(); + return subscribe(new Consumer() { + @Override + public void accept(T v) { + if (!onNext.test(v)) { + subscription.get().cancel(); + onComplete.run(); + } + } + }, onError, onComplete, new Consumer() { + @Override + public void accept(Subscription s) { + subscription.lazySet(s); + s.request(Long.MAX_VALUE); + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> groupBy(Function keySelector) { + return groupBy(keySelector, Functions.identity(), false, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> groupBy(Function keySelector, boolean delayError) { + return groupBy(keySelector, Functions.identity(), delayError, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> groupBy(Function keySelector, + Function valueSelector) { + return groupBy(keySelector, valueSelector, false, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> groupBy(Function keySelector, + Function valueSelector, boolean delayError) { + return groupBy(keySelector, valueSelector, false, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> groupBy(Function keySelector, + Function valueSelector, + boolean delayError, int bufferSize) { + Objects.requireNonNull(keySelector, "keySelector is null"); + Objects.requireNonNull(valueSelector, "valueSelector is null"); + validateBufferSize(bufferSize); + + return lift(new OperatorGroupBy(keySelector, valueSelector, bufferSize, delayError)); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable ignoreElements() { + return lift(OperatorIgnoreElements.instance()); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable isEmpty() { + return all(new Predicate() { + @Override + public boolean test(T v) { + return false; + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable last() { + return takeLast(1).single(); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable last(T defaultValue) { + return takeLast(1).single(defaultValue); + } + + @BackpressureSupport(BackpressureKind.SPECIAL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable lift(Operator lifter) { + Objects.requireNonNull(lifter, "lifter is null"); + // using onSubscribe so the fusing has access to the underlying raw Publisher + return create(new PublisherLift(onSubscribe, lifter)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable map(Function mapper) { + Objects.requireNonNull(mapper, "mapper is null"); + return lift(new OperatorMap(mapper)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable>> materialize() { + return lift(OperatorMaterialize.instance()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable mergeWith(Publisher other) { + Objects.requireNonNull(other, "other is null"); + return merge(this, other); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + @Deprecated + public final Flowable> nest() { + return just(this); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable observeOn(Scheduler scheduler) { + return observeOn(scheduler, false, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable observeOn(Scheduler scheduler, boolean delayError) { + return observeOn(scheduler, delayError, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable observeOn(Scheduler scheduler, boolean delayError, int bufferSize) { + Objects.requireNonNull(scheduler, "scheduler is null"); + validateBufferSize(bufferSize); + return lift(new OperatorObserveOn(scheduler, delayError, bufferSize)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable ofType(final Class clazz) { + Objects.requireNonNull(clazz, "clazz is null"); + return filter(new Predicate() { + @Override + public boolean test(T c) { + return clazz.isInstance(c); + } + }).cast(clazz); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onBackpressureBuffer() { + return onBackpressureBuffer(bufferSize(), false, true); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onBackpressureBuffer(boolean delayError) { + return onBackpressureBuffer(bufferSize(), true, true); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onBackpressureBuffer(int bufferSize) { + return onBackpressureBuffer(bufferSize, false, false); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onBackpressureBuffer(int bufferSize, boolean delayError) { + return onBackpressureBuffer(bufferSize, true, false); + } + + @BackpressureSupport(BackpressureKind.SPECIAL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onBackpressureBuffer(int bufferSize, boolean delayError, boolean unbounded) { + validateBufferSize(bufferSize); + return lift(new OperatorOnBackpressureBuffer(bufferSize, unbounded, delayError, Functions.emptyRunnable())); + } + + @BackpressureSupport(BackpressureKind.SPECIAL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onBackpressureBuffer(int bufferSize, boolean delayError, boolean unbounded, Runnable onOverflow) { + Objects.requireNonNull(onOverflow, "onOverflow is null"); + return lift(new OperatorOnBackpressureBuffer(bufferSize, unbounded, delayError, onOverflow)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onBackpressureBuffer(int bufferSize, Runnable onOverflow) { + return onBackpressureBuffer(bufferSize, false, false, onOverflow); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onBackpressureDrop() { + return lift(OperatorOnBackpressureDrop.instance()); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onBackpressureDrop(Consumer onDrop) { + Objects.requireNonNull(onDrop, "onDrop is null"); + return lift(new OperatorOnBackpressureDrop(onDrop)); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onBackpressureLatest() { + return lift(OperatorOnBackpressureLatest.instance()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onErrorResumeNext(Function> resumeFunction) { + Objects.requireNonNull(resumeFunction, "resumeFunction is null"); + return lift(new OperatorOnErrorNext(resumeFunction, false)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onErrorResumeNext(final Publisher next) { + Objects.requireNonNull(next, "next is null"); + return onErrorResumeNext(new Function>() { + @Override + public Publisher apply(Throwable e) { + return next; + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onErrorReturn(Function valueSupplier) { + Objects.requireNonNull(valueSupplier, "valueSupplier is null"); + return lift(new OperatorOnErrorReturn(valueSupplier)); + } + + // TODO would result in ambiguity with onErrorReturn(Function) + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onErrorReturnValue(final T value) { + Objects.requireNonNull(value, "value is null"); + return onErrorReturn(new Function() { + @Override + public T apply(Throwable e) { + return value; + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable onExceptionResumeNext(final Publisher next) { + Objects.requireNonNull(next, "next is null"); + return lift(new OperatorOnErrorNext(new Function>() { + @Override + public Publisher apply(Throwable e) { + return next; + } + }, true)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final ConnectableFlowable publish() { + return publish(bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable publish(Function, ? extends Publisher> selector) { + return publish(selector, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable publish(Function, ? extends Publisher> selector, int bufferSize) { + validateBufferSize(bufferSize); + Objects.requireNonNull(selector, "selector is null"); + return OperatorPublish.create(this, selector, bufferSize); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final ConnectableFlowable publish(int bufferSize) { + validateBufferSize(bufferSize); + return OperatorPublish.create(this, bufferSize); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable reduce(BiFunction reducer) { + return scan(reducer).last(); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable reduce(R seed, BiFunction reducer) { + return scan(seed, reducer).last(); + } + + // Naming note, a plain scan would cause ambiguity with the value-seeded version + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable reduceWith(Supplier seedSupplier, BiFunction reducer) { + return scanWith(seedSupplier, reducer).last(); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable repeat() { + return repeat(Long.MAX_VALUE); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable repeat(long times) { + if (times < 0) { + throw new IllegalArgumentException("times >= 0 required but it was " + times); + } + if (times == 0) { + return empty(); + } + return create(new PublisherRepeat(this, times)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable repeatUntil(BooleanSupplier stop) { + Objects.requireNonNull(stop, "stop is null"); + return create(new PublisherRepeatUntil(this, stop)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable repeatWhen(final Function, ? extends Publisher> handler) { + Objects.requireNonNull(handler, "handler is null"); + + Function>>, Publisher> f = new Function>>, Publisher>() { + @Override + public Publisher apply(Flowable>> no) { + return handler.apply(no.map(new Function>, Object>() { + @Override + public Object apply(Try> v) { + return 0; + } + })); + } + } + ; + + return create(new PublisherRedo(this, f)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final ConnectableFlowable replay() { + return OperatorReplay.createFrom(this); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable replay(Function, ? extends Publisher> selector) { + Objects.requireNonNull(selector, "selector is null"); + return OperatorReplay.multicastSelector(new Supplier>() { + @Override + public ConnectableFlowable get() { + return replay(); + } + }, selector); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable replay(Function, ? extends Publisher> selector, final int bufferSize) { + Objects.requireNonNull(selector, "selector is null"); + return OperatorReplay.multicastSelector(new Supplier>() { + @Override + public ConnectableFlowable get() { + return replay(bufferSize); + } + }, selector); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable replay(Function, ? extends Publisher> selector, int bufferSize, long time, TimeUnit unit) { + return replay(selector, bufferSize, time, unit, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable replay(Function, ? extends Publisher> selector, final int bufferSize, final long time, final TimeUnit unit, final Scheduler scheduler) { + if (bufferSize < 0) { + throw new IllegalArgumentException("bufferSize < 0"); + } + Objects.requireNonNull(selector, "selector is null"); + return OperatorReplay.multicastSelector(new Supplier>() { + @Override + public ConnectableFlowable get() { + return replay(bufferSize, time, unit, scheduler); + } + }, selector); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable replay(final Function, ? extends Publisher> selector, final int bufferSize, final Scheduler scheduler) { + return OperatorReplay.multicastSelector(new Supplier>() { + @Override + public ConnectableFlowable get() { + return replay(bufferSize); + } + }, + new Function, Publisher>() { + @Override + public Publisher apply(Flowable t) { + return fromPublisher(selector.apply(t)).observeOn(scheduler); + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable replay(Function, ? extends Publisher> selector, long time, TimeUnit unit) { + return replay(selector, time, unit, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable replay(Function, ? extends Publisher> selector, final long time, final TimeUnit unit, final Scheduler scheduler) { + Objects.requireNonNull(selector, "selector is null"); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return OperatorReplay.multicastSelector(new Supplier>() { + @Override + public ConnectableFlowable get() { + return replay(time, unit, scheduler); + } + }, selector); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable replay(final Function, ? extends Publisher> selector, final Scheduler scheduler) { + Objects.requireNonNull(selector, "selector is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return OperatorReplay.multicastSelector(new Supplier>() { + @Override + public ConnectableFlowable get() { + return replay(); + } + }, + new Function, Publisher>() { + @Override + public Publisher apply(Flowable t) { + return fromPublisher(selector.apply(t)).observeOn(scheduler); + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final ConnectableFlowable replay(final int bufferSize) { + return OperatorReplay.create(this, bufferSize); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final ConnectableFlowable replay(int bufferSize, long time, TimeUnit unit) { + return replay(bufferSize, time, unit, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final ConnectableFlowable replay(final int bufferSize, final long time, final TimeUnit unit, final Scheduler scheduler) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + if (bufferSize < 0) { + throw new IllegalArgumentException("bufferSize < 0"); + } + return OperatorReplay.create(this, time, unit, scheduler, bufferSize); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final ConnectableFlowable replay(final int bufferSize, final Scheduler scheduler) { + Objects.requireNonNull(scheduler, "scheduler is null"); + return OperatorReplay.observeOn(replay(bufferSize), scheduler); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final ConnectableFlowable replay(long time, TimeUnit unit) { + return replay(time, unit, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final ConnectableFlowable replay(final long time, final TimeUnit unit, final Scheduler scheduler) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return OperatorReplay.create(this, time, unit, scheduler); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final ConnectableFlowable replay(final Scheduler scheduler) { + Objects.requireNonNull(scheduler, "scheduler is null"); + return OperatorReplay.observeOn(replay(), scheduler); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable retry() { + return retry(Long.MAX_VALUE, Functions.alwaysTrue()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable retry(BiPredicate predicate) { + Objects.requireNonNull(predicate, "predicate is null"); + + return create(new PublisherRetryBiPredicate(this, predicate)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable retry(long times) { + return retry(times, Functions.alwaysTrue()); + } + + // Retries at most times or until the predicate returns false, whichever happens first + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable retry(long times, Predicate predicate) { + if (times < 0) { + throw new IllegalArgumentException("times >= 0 required but it was " + times); + } + Objects.requireNonNull(predicate, "predicate is null"); + + return create(new PublisherRetryPredicate(this, times, predicate)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable retry(Predicate predicate) { + return retry(Long.MAX_VALUE, predicate); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable retryUntil(final BooleanSupplier stop) { + Objects.requireNonNull(stop, "stop is null"); + return retry(Long.MAX_VALUE, new Predicate() { + @Override + public boolean test(Throwable e) { + return !stop.getAsBoolean(); + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable retryWhen( + final Function, ? extends Publisher> handler) { + Objects.requireNonNull(handler, "handler is null"); + + Function>>, Publisher> f = new Function>>, Publisher>() { + @Override + public Publisher apply(Flowable>> no) { + Flowable map = no.takeWhile(new Predicate>>() { + @Override + public boolean test(Try> e) { + return e.hasError(); + } + }).map(new Function>, Throwable>() { + @Override + public Throwable apply(Try> t) { + return t.error(); + } + }); + return handler.apply(map); + } + } + ; + + return create(new PublisherRedo(this, f)); + } + + // TODO decide if safe subscription or unsafe should be the default + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final void safeSubscribe(Subscriber s) { + Objects.requireNonNull(s, "s is null"); + if (s instanceof SafeSubscriber) { + subscribeActual(s); + } else { + subscribeActual(new SafeSubscriber(s)); + } + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable sample(long period, TimeUnit unit) { + return sample(period, unit, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable sample(long period, TimeUnit unit, Scheduler scheduler) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return lift(new OperatorSampleTimed(period, unit, scheduler)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable sample(Publisher sampler) { + Objects.requireNonNull(sampler, "sampler is null"); + return lift(new OperatorSamplePublisher(sampler)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable scan(BiFunction accumulator) { + Objects.requireNonNull(accumulator, "accumulator is null"); + return lift(new OperatorScan(accumulator)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable scan(final R seed, BiFunction accumulator) { + Objects.requireNonNull(seed, "seed is null"); + return scanWith(new Supplier() { + @Override + public R get() { + return seed; + } + }, accumulator); + } + + // Naming note, a plain scan would cause ambiguity with the value-seeded version + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable scanWith(Supplier seedSupplier, BiFunction accumulator) { + Objects.requireNonNull(seedSupplier, "seedSupplier is null"); + Objects.requireNonNull(accumulator, "accumulator is null"); + return lift(new OperatorScanSeed(seedSupplier, accumulator)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable serialize() { + return lift(new Operator() { + @Override + public Subscriber apply(Subscriber s) { + return new SerializedSubscriber(s); + } + }); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable share() { + return publish().refCount(); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable single() { + return lift(OperatorSingle.instanceNoDefault()); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable single(T defaultValue) { + Objects.requireNonNull(defaultValue, "defaultValue is null"); + return lift(new OperatorSingle(defaultValue)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable skip(long n) { +// if (n < 0) { +// throw new IllegalArgumentException("n >= 0 required but it was " + n); +// } else + // FIXME negative skip allowed?! + if (n <= 0) { + return this; + } + return lift(new OperatorSkip(n)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable skip(long time, TimeUnit unit, Scheduler scheduler) { + // TODO consider inlining this behavior + return skipUntil(timer(time, unit, scheduler)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable skipLast(int n) { + if (n < 0) { + throw new IndexOutOfBoundsException("n >= 0 required but it was " + n); + } else + if (n == 0) { + return this; + } + return lift(new OperatorSkipLast(n)); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) + public final Flowable skipLast(long time, TimeUnit unit) { + return skipLast(time, unit, Schedulers.trampoline(), false, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) + public final Flowable skipLast(long time, TimeUnit unit, boolean delayError) { + return skipLast(time, unit, Schedulers.trampoline(), delayError, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable skipLast(long time, TimeUnit unit, Scheduler scheduler) { + return skipLast(time, unit, scheduler, false, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable skipLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError) { + return skipLast(time, unit, scheduler, delayError, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable skipLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + validateBufferSize(bufferSize); + // the internal buffer holds pairs of (timestamp, value) so double the default buffer size + int s = bufferSize << 1; + return lift(new OperatorSkipLastTimed(time, unit, scheduler, s, delayError)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable skipUntil(Publisher other) { + Objects.requireNonNull(other, "other is null"); + return lift(new OperatorSkipUntil(other)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable skipWhile(Predicate predicate) { + Objects.requireNonNull(predicate, "predicate is null"); + return lift(new OperatorSkipWhile(predicate)); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable startWith(Iterable values) { + return concatArray(fromIterable(values), this); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable startWith(Publisher other) { + Objects.requireNonNull(other, "other is null"); + return concatArray(other, this); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable startWith(T value) { + Objects.requireNonNull(value, "value is null"); + return concatArray(just(value), this); + } + + @SuppressWarnings("unchecked") + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable startWithArray(T... values) { + Flowable fromArray = fromArray(values); + if (fromArray == empty()) { + return this; + } + return concatArray(fromArray, this); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Disposable subscribe() { + return subscribe(Functions.emptyConsumer(), RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), new Consumer() { + @Override + public void accept(Subscription s) { + s.request(Long.MAX_VALUE); + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Disposable subscribe(Consumer onNext) { + return subscribe(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), new Consumer() { + @Override + public void accept(Subscription s) { + s.request(Long.MAX_VALUE); + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Disposable subscribe(Consumer onNext, Consumer onError) { + return subscribe(onNext, onError, Functions.emptyRunnable(), new Consumer() { + @Override + public void accept(Subscription s) { + s.request(Long.MAX_VALUE); + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Disposable subscribe(Consumer onNext, Consumer onError, + Runnable onComplete) { + return subscribe(onNext, onError, onComplete, new Consumer() { + @Override + public void accept(Subscription s) { + s.request(Long.MAX_VALUE); + } + }); + } + + @BackpressureSupport(BackpressureKind.SPECIAL) + @SchedulerSupport(SchedulerKind.NONE) + public final Disposable subscribe(Consumer onNext, Consumer onError, + Runnable onComplete, Consumer onSubscribe) { + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(onSubscribe, "onSubscribe is null"); + + LambdaSubscriber ls = new LambdaSubscriber(onNext, onError, onComplete, onSubscribe); + + unsafeSubscribe(ls); + + return ls; + } + + // TODO decide if safe subscription or unsafe should be the default + @BackpressureSupport(BackpressureKind.SPECIAL) + @SchedulerSupport(SchedulerKind.NONE) + @Override + public final void subscribe(Subscriber s) { + Objects.requireNonNull(s, "s is null"); + subscribeActual(s); + } + + private void subscribeActual(Subscriber s) { + try { + s = RxJavaPlugins.onSubscribe(s); + + if (s == null) { + throw new NullPointerException("Plugin returned null Subscriber"); + } + + onSubscribe.subscribe(s); + } catch (NullPointerException e) { + throw e; + } catch (Throwable e) { + // TODO throw if fatal? + // can't call onError because no way to know if a Subscription has been set or not + // can't call onSubscribe because the call might have set a Subscription already + RxJavaPlugins.onError(e); + + NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS"); + npe.initCause(e); + throw npe; + } + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable subscribeOn(Scheduler scheduler) { + return subscribeOn(scheduler, true); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable subscribeOn(Scheduler scheduler, boolean requestOn) { + Objects.requireNonNull(scheduler, "scheduler is null"); + return create(new PublisherSubscribeOn(this, scheduler, requestOn)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable switchIfEmpty(Publisher other) { + Objects.requireNonNull(other, "other is null"); + return lift(new OperatorSwitchIfEmpty(other)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable switchMap(Function> mapper) { + return switchMap(mapper, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable switchMap(Function> mapper, int bufferSize) { + Objects.requireNonNull(mapper, "mapper is null"); + validateBufferSize(bufferSize); + return lift(new OperatorSwitchMap(mapper, bufferSize)); + } + + @BackpressureSupport(BackpressureKind.SPECIAL) // may trigger UNBOUNDED_IN + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable take(long n) { + if (n < 0) { + throw new IllegalArgumentException("n >= required but it was " + n); + } else + if (n == 0) { + // FIXME may want to subscribe an cancel immediately +// return lift(s -> CancelledSubscriber.INSTANCE); + return empty(); + } + return lift(new OperatorTake(n)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable take(long time, TimeUnit unit, Scheduler scheduler) { + // TODO consider inlining this behavior + return takeUntil(timer(time, unit, scheduler)); + } + + @BackpressureSupport(BackpressureKind.SPECIAL) // may trigger UNBOUNDED_IN + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable takeFirst(Predicate predicate) { + return filter(predicate).take(1); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable takeLast(int n) { + if (n < 0) { + throw new IndexOutOfBoundsException("n >= required but it was " + n); + } else + if (n == 0) { + return ignoreElements(); + } else + if (n == 1) { + return lift(OperatorTakeLastOne.instance()); + } + return lift(new OperatorTakeLast(n)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) + public final Flowable takeLast(long count, long time, TimeUnit unit) { + return takeLast(count, time, unit, Schedulers.trampoline(), false, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable takeLast(long count, long time, TimeUnit unit, Scheduler scheduler) { + return takeLast(count, time, unit, scheduler, false, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable takeLast(long count, long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + validateBufferSize(bufferSize); + if (count < 0) { + throw new IndexOutOfBoundsException("count >= 0 required but it was " + count); + } + return lift(new OperatorTakeLastTimed(count, time, unit, scheduler, bufferSize, delayError)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) + public final Flowable takeLast(long time, TimeUnit unit) { + return takeLast(time, unit, Schedulers.trampoline(), false, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) + public final Flowable takeLast(long time, TimeUnit unit, boolean delayError) { + return takeLast(time, unit, Schedulers.trampoline(), delayError, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable takeLast(long time, TimeUnit unit, Scheduler scheduler) { + return takeLast(time, unit, scheduler, false, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable takeLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError) { + return takeLast(time, unit, scheduler, delayError, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable takeLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { + return takeLast(Long.MAX_VALUE, time, unit, scheduler, delayError, bufferSize); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> takeLastBuffer(int count) { + return takeLast(count).toList(); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) + public final Flowable> takeLastBuffer(int count, long time, TimeUnit unit) { + return takeLast(count, time, unit).toList(); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> takeLastBuffer(int count, long time, TimeUnit unit, Scheduler scheduler) { + return takeLast(count, time, unit, scheduler).toList(); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) + public final Flowable> takeLastBuffer(long time, TimeUnit unit) { + return takeLast(time, unit).toList(); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> takeLastBuffer(long time, TimeUnit unit, Scheduler scheduler) { + return takeLast(time, unit, scheduler).toList(); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable takeUntil(Predicate predicate) { + Objects.requireNonNull(predicate, "predicate is null"); + return lift(new OperatorTakeUntilPredicate(predicate)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable takeUntil(Publisher other) { + Objects.requireNonNull(other, "other is null"); + return lift(new OperatorTakeUntil(other)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable takeWhile(Predicate predicate) { + Objects.requireNonNull(predicate, "predicate is null"); + return lift(new OperatorTakeWhile(predicate)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable throttleFirst(long windowDuration, TimeUnit unit) { + return throttleFirst(windowDuration, unit, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable throttleFirst(long skipDuration, TimeUnit unit, Scheduler scheduler) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return lift(new OperatorThrottleFirstTimed(skipDuration, unit, scheduler)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable throttleLast(long intervalDuration, TimeUnit unit) { + return sample(intervalDuration, unit); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable throttleLast(long intervalDuration, TimeUnit unit, Scheduler scheduler) { + return sample(intervalDuration, unit, scheduler); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable throttleWithTimeout(long timeout, TimeUnit unit) { + return debounce(timeout, unit); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable throttleWithTimeout(long timeout, TimeUnit unit, Scheduler scheduler) { + return debounce(timeout, unit, scheduler); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) + public final Flowable> timeInterval() { + return timeInterval(TimeUnit.MILLISECONDS, Schedulers.trampoline()); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> timeInterval(Scheduler scheduler) { + return timeInterval(TimeUnit.MILLISECONDS, scheduler); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) + public final Flowable> timeInterval(TimeUnit unit) { + return timeInterval(unit, Schedulers.trampoline()); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> timeInterval(TimeUnit unit, Scheduler scheduler) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return lift(new OperatorTimeInterval(unit, scheduler)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable timeout(Function> timeoutSelector) { + return timeout0(null, timeoutSelector, null); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable timeout(Function> timeoutSelector, Flowable other) { + Objects.requireNonNull(other, "other is null"); + return timeout0(null, timeoutSelector, other); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable timeout(long timeout, TimeUnit timeUnit) { + return timeout0(timeout, timeUnit, null, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable timeout(long timeout, TimeUnit timeUnit, Flowable other) { + Objects.requireNonNull(other, "other is null"); + return timeout0(timeout, timeUnit, other, Schedulers.computation()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable timeout(long timeout, TimeUnit timeUnit, Flowable other, Scheduler scheduler) { + Objects.requireNonNull(other, "other is null"); + return timeout0(timeout, timeUnit, other, scheduler); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable timeout(long timeout, TimeUnit timeUnit, Scheduler scheduler) { + return timeout0(timeout, timeUnit, null, scheduler); + } + + public final Flowable timeout(Supplier> firstTimeoutSelector, + Function> timeoutSelector) { + Objects.requireNonNull(firstTimeoutSelector, "firstTimeoutSelector is null"); + return timeout0(firstTimeoutSelector, timeoutSelector, null); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable timeout( + Supplier> firstTimeoutSelector, + Function> timeoutSelector, + Publisher other) { + Objects.requireNonNull(firstTimeoutSelector, "firstTimeoutSelector is null"); + Objects.requireNonNull(other, "other is null"); + return timeout0(firstTimeoutSelector, timeoutSelector, other); + } + + private Flowable timeout0(long timeout, TimeUnit timeUnit, Flowable other, + Scheduler scheduler) { + Objects.requireNonNull(timeUnit, "timeUnit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return lift(new OperatorTimeoutTimed(timeout, timeUnit, scheduler, other)); + } + + private Flowable timeout0( + Supplier> firstTimeoutSelector, + Function> timeoutSelector, + Publisher other) { + Objects.requireNonNull(timeoutSelector, "timeoutSelector is null"); + return lift(new OperatorTimeout(firstTimeoutSelector, timeoutSelector, other)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) + public final Flowable> timestamp() { + return timestamp(TimeUnit.MILLISECONDS, Schedulers.trampoline()); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> timestamp(Scheduler scheduler) { + return timestamp(TimeUnit.MILLISECONDS, scheduler); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) + public final Flowable> timestamp(TimeUnit unit) { + return timestamp(unit, Schedulers.trampoline()); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> timestamp(final TimeUnit unit, final Scheduler scheduler) { + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return map(new Function>() { + @Override + public Timed apply(T v) { + return new Timed(v, scheduler.now(unit), unit); + } + }); + } + + // TODO generics + @BackpressureSupport(BackpressureKind.SPECIAL) + @SchedulerSupport(SchedulerKind.NONE) + public final R to(Function, R> converter) { + return converter.apply(this); + } + + @BackpressureSupport(BackpressureKind.SPECIAL) + @SchedulerSupport(SchedulerKind.NONE) + public final BlockingFlowable toBlocking() { + return BlockingFlowable.from(this); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> toList() { + return lift(OperatorToList.defaultInstance()); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> toList(final int capacityHint) { + if (capacityHint <= 0) { + throw new IllegalArgumentException("capacityHint > 0 required but it was " + capacityHint); + } + return lift(new OperatorToList>(new Supplier>() { + @Override + public List get() { + return new ArrayList(capacityHint); + } + })); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final > Flowable toList(Supplier collectionSupplier) { + Objects.requireNonNull(collectionSupplier, "collectionSupplier is null"); + return lift(new OperatorToList(collectionSupplier)); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> toMap(final Function keySelector) { + Objects.requireNonNull(keySelector, "keySelector is null"); + return collect(new Supplier>() { + @Override + public Map get() { + return new HashMap(); + } + }, new BiConsumer, T>() { + @Override + public void accept(Map m, T t) { + K key = keySelector.apply(t); + m.put(key, t); + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> toMap(final Function keySelector, final Function valueSelector) { + Objects.requireNonNull(keySelector, "keySelector is null"); + Objects.requireNonNull(valueSelector, "valueSelector is null"); + return collect(new Supplier>() { + @Override + public Map get() { + return new HashMap(); + } + }, new BiConsumer, T>() { + @Override + public void accept(Map m, T t) { + K key = keySelector.apply(t); + V value = valueSelector.apply(t); + m.put(key, value); + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> toMap(final Function keySelector, + final Function valueSelector, + final Supplier> mapSupplier) { + Objects.requireNonNull(keySelector, "keySelector is null"); + Objects.requireNonNull(valueSelector, "valueSelector is null"); + return collect(mapSupplier, new BiConsumer, T>() { + @Override + public void accept(Map m, T t) { + K key = keySelector.apply(t); + V value = valueSelector.apply(t); + m.put(key, value); + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable>> toMultimap(Function keySelector) { + Function valueSelector = Functions.identity(); + Supplier>> mapSupplier = new Supplier>>() { + @Override + public Map> get() { + return new HashMap>(); + } + }; + Function> collectionFactory = new Function>() { + @Override + public Collection apply(K k) { + return new ArrayList(); + } + }; + return toMultimap(keySelector, valueSelector, mapSupplier, collectionFactory); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable>> toMultimap(Function keySelector, Function valueSelector) { + Supplier>> mapSupplier = new Supplier>>() { + @Override + public Map> get() { + return new HashMap>(); + } + }; + Function> collectionFactory = new Function>() { + @Override + public Collection apply(K k) { + return new ArrayList(); + } + }; + return toMultimap(keySelector, valueSelector, mapSupplier, collectionFactory); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + @SuppressWarnings("unchecked") + public final Flowable>> toMultimap( + final Function keySelector, + final Function valueSelector, + final Supplier>> mapSupplier, + final Function> collectionFactory) { + Objects.requireNonNull(keySelector, "keySelector is null"); + Objects.requireNonNull(valueSelector, "valueSelector is null"); + Objects.requireNonNull(mapSupplier, "mapSupplier is null"); + Objects.requireNonNull(collectionFactory, "collectionFactory is null"); + return collect(mapSupplier, new BiConsumer>, T>() { + @Override + public void accept(Map> m, T t) { + K key = keySelector.apply(t); + + Collection coll = m.get(key); + if (coll == null) { + coll = (Collection)collectionFactory.apply(key); + m.put(key, coll); + } + + V value = valueSelector.apply(t); + + coll.add(value); + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable>> toMultimap( + Function keySelector, + Function valueSelector, + Supplier>> mapSupplier + ) { + return toMultimap(keySelector, valueSelector, mapSupplier, new Function>() { + @Override + public Collection apply(K k) { + return new ArrayList(); + } + }); + } + + @BackpressureSupport(BackpressureKind.NONE) + @SchedulerSupport(SchedulerKind.NONE) + public final Observable toNbpObservable() { + return Observable.fromPublisher(this); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Single toSingle() { + return Single.fromPublisher(this); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + @SuppressWarnings({ "unchecked", "rawtypes"}) + public final Flowable> toSortedList() { + return toSortedList(new Comparator() { + @Override + public int compare(T o1, T o2) { + return ((Comparable)o1).compareTo(o2); + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> toSortedList(final Comparator comparator) { + Objects.requireNonNull(comparator, "comparator is null"); + return toList().map(new Function, List>() { + @Override + public List apply(List v) { + Collections.sort(v, comparator); + return v; + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> toSortedList(final Comparator comparator, int capacityHint) { + Objects.requireNonNull(comparator, "comparator is null"); + return toList(capacityHint).map(new Function, List>() { + @Override + public List apply(List v) { + Collections.sort(v, comparator); + return v; + } + }); + } + + @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) + @SuppressWarnings({ "unchecked", "rawtypes"}) + public final Flowable> toSortedList(int capacityHint) { + return toSortedList(new Comparator() { + @Override + public int compare(T o1, T o2) { + return ((Comparable)o1).compareTo(o2); + } + }, capacityHint); + } + + @BackpressureSupport(BackpressureKind.SPECIAL) + @SchedulerSupport(SchedulerKind.NONE) + // TODO decide if safe subscription or unsafe should be the default + public final void unsafeSubscribe(Subscriber s) { + Objects.requireNonNull(s, "s is null"); + subscribeActual(s); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable unsubscribeOn(Scheduler scheduler) { + Objects.requireNonNull(scheduler, "scheduler is null"); + return lift(new OperatorUnsubscribeOn(scheduler)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> window(long count) { + return window(count, count, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> window(long count, long skip) { + return window(count, skip, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> window(long count, long skip, int bufferSize) { + if (skip <= 0) { + throw new IllegalArgumentException("skip > 0 required but it was " + skip); + } + if (count <= 0) { + throw new IllegalArgumentException("count > 0 required but it was " + count); + } + validateBufferSize(bufferSize); + return lift(new OperatorWindow(count, skip, bufferSize)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable> window(long timespan, long timeskip, TimeUnit unit) { + return window(timespan, timeskip, unit, Schedulers.computation(), bufferSize()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> window(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler) { + return window(timespan, timeskip, unit, scheduler, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> window(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler, int bufferSize) { + validateBufferSize(bufferSize); + Objects.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(unit, "unit is null"); + return lift(new OperatorWindowTimed(timespan, timeskip, unit, scheduler, Long.MAX_VALUE, bufferSize, false)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable> window(long timespan, TimeUnit unit) { + return window(timespan, unit, Schedulers.computation(), Long.MAX_VALUE, false); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable> window(long timespan, TimeUnit unit, + long count) { + return window(timespan, unit, Schedulers.computation(), count, false); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) + public final Flowable> window(long timespan, TimeUnit unit, + long count, boolean restart) { + return window(timespan, unit, Schedulers.computation(), count, restart); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> window(long timespan, TimeUnit unit, + Scheduler scheduler) { + return window(timespan, unit, scheduler, Long.MAX_VALUE, false); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> window(long timespan, TimeUnit unit, + Scheduler scheduler, long count) { + return window(timespan, unit, scheduler, count, false); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> window(long timespan, TimeUnit unit, + Scheduler scheduler, long count, boolean restart) { + return window(timespan, unit, scheduler, count, restart, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) + public final Flowable> window( + long timespan, TimeUnit unit, Scheduler scheduler, + long count, boolean restart, int bufferSize) { + validateBufferSize(bufferSize); + Objects.requireNonNull(scheduler, "scheduler is null"); + Objects.requireNonNull(unit, "unit is null"); + if (count <= 0) { + throw new IllegalArgumentException("count > 0 required but it was " + count); + } + return lift(new OperatorWindowTimed(timespan, timespan, unit, scheduler, count, bufferSize, restart)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> window(Publisher boundary) { + return window(boundary, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> window(Publisher boundary, int bufferSize) { + Objects.requireNonNull(boundary, "boundary is null"); + return lift(new OperatorWindowBoundary(boundary, bufferSize)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> window( + Publisher windowOpen, + Function> windowClose) { + return window(windowOpen, windowClose, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> window( + Publisher windowOpen, + Function> windowClose, int bufferSize) { + Objects.requireNonNull(windowOpen, "windowOpen is null"); + Objects.requireNonNull(windowClose, "windowClose is null"); + return lift(new OperatorWindowBoundarySelector(windowOpen, windowClose, bufferSize)); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> window(Supplier> boundary) { + return window(boundary, bufferSize()); + } + + @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable> window(Supplier> boundary, int bufferSize) { + Objects.requireNonNull(boundary, "boundary is null"); + return lift(new OperatorWindowBoundarySupplier(boundary, bufferSize)); + } + + @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable withLatestFrom(Publisher other, BiFunction combiner) { + Objects.requireNonNull(other, "other is null"); + Objects.requireNonNull(combiner, "combiner is null"); + + return lift(new OperatorWithLatestFrom(combiner, other)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable zipWith(Iterable other, BiFunction zipper) { + Objects.requireNonNull(other, "other is null"); + Objects.requireNonNull(zipper, "zipper is null"); + return create(new PublisherZipIterable(this, other, zipper)); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable zipWith(Publisher other, BiFunction zipper) { + Objects.requireNonNull(other, "other is null"); + return zip(this, other, zipper); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable zipWith(Publisher other, BiFunction zipper, boolean delayError) { + return zip(this, other, zipper, delayError); + } + + @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final Flowable zipWith(Publisher other, BiFunction zipper, boolean delayError, int bufferSize) { + return zip(this, other, zipper, delayError, bufferSize); + } + +} \ No newline at end of file diff --git a/src/main/java/io/reactivex/NbpObservable.java b/src/main/java/io/reactivex/NbpObservable.java deleted file mode 100644 index 7e865606cc..0000000000 --- a/src/main/java/io/reactivex/NbpObservable.java +++ /dev/null @@ -1,3409 +0,0 @@ -/** - * Copyright 2016 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. - */ - -package io.reactivex; - -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicReference; - -import org.reactivestreams.*; - -import io.reactivex.Single.*; -import io.reactivex.annotations.*; -import io.reactivex.disposables.*; -import io.reactivex.functions.*; -import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.internal.functions.*; -import io.reactivex.internal.functions.Objects; -import io.reactivex.internal.operators.nbp.*; -import io.reactivex.internal.subscribers.nbp.*; -import io.reactivex.internal.util.Exceptions; -import io.reactivex.observables.nbp.*; -import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.schedulers.*; -import io.reactivex.subscribers.nbp.*; - -/** - * Observable for delivering a sequence of values without backpressure. - * @param - */ -public class NbpObservable { - - public interface NbpOnSubscribe extends Consumer> { - - } - - public interface NbpOperator extends Function, NbpSubscriber> { - - } - - public interface NbpSubscriber { - - void onSubscribe(Disposable d); - - void onNext(T value); - - void onError(Throwable e); - - void onComplete(); - - } - - public interface NbpTransformer extends Function, NbpObservable> { - - } - - /** An empty observable instance as there is no need to instantiate this more than once. */ - static final NbpObservable EMPTY = create(new NbpOnSubscribe() { - @Override - public void accept(NbpSubscriber s) { - s.onSubscribe(EmptyDisposable.INSTANCE); - s.onComplete(); - } - }); - - /** A never NbpObservable instance as there is no need to instantiate this more than once. */ - static final NbpObservable NEVER = create(new NbpOnSubscribe() { - @Override - public void accept(NbpSubscriber s) { - s.onSubscribe(EmptyDisposable.INSTANCE); - } - }); - - static final Object OBJECT = new Object(); - - public static NbpObservable amb(Iterable> sources) { - Objects.requireNonNull(sources, "sources is null"); - return create(new NbpOnSubscribeAmb(null, sources)); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable amb(NbpObservable... sources) { - Objects.requireNonNull(sources, "sources is null"); - int len = sources.length; - if (len == 0) { - return empty(); - } else - if (len == 1) { - return (NbpObservable)sources[0]; - } - return create(new NbpOnSubscribeAmb(sources, null)); - } - - /** - * Returns the default 'island' size or capacity-increment hint for unbounded buffers. - * @return - */ - static int bufferSize() { - return Observable.bufferSize(); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest(Function combiner, boolean delayError, int bufferSize, NbpObservable... sources) { - return combineLatest(sources, combiner, delayError, bufferSize); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest(Iterable> sources, Function combiner) { - return combineLatest(sources, combiner, false, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest(Iterable> sources, Function combiner, boolean delayError) { - return combineLatest(sources, combiner, delayError, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest(Iterable> sources, Function combiner, boolean delayError, int bufferSize) { - Objects.requireNonNull(sources, "sources is null"); - Objects.requireNonNull(combiner, "combiner is null"); - validateBufferSize(bufferSize); - - // the queue holds a pair of values so we need to double the capacity - int s = bufferSize << 1; - return create(new NbpOnSubscribeCombineLatest(null, sources, combiner, s, delayError)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest(NbpObservable[] sources, Function combiner) { - return combineLatest(sources, combiner, false, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest(NbpObservable[] sources, Function combiner, boolean delayError) { - return combineLatest(sources, combiner, delayError, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest(NbpObservable[] sources, Function combiner, boolean delayError, int bufferSize) { - validateBufferSize(bufferSize); - Objects.requireNonNull(combiner, "combiner is null"); - if (sources.length == 0) { - return empty(); - } - // the queue holds a pair of values so we need to double the capacity - int s = bufferSize << 1; - return create(new NbpOnSubscribeCombineLatest(sources, null, combiner, s, delayError)); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest( - NbpObservable p1, NbpObservable p2, - BiFunction combiner) { - return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, - Function3 combiner) { - return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4, - Function4 combiner) { - return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4, - NbpObservable p5, - Function5 combiner) { - return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4, - NbpObservable p5, NbpObservable p6, - Function6 combiner) { - return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5, p6); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4, - NbpObservable p5, NbpObservable p6, - NbpObservable p7, - Function7 combiner) { - return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4, - NbpObservable p5, NbpObservable p6, - NbpObservable p7, NbpObservable p8, - Function8 combiner) { - return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7, p8); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable combineLatest( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4, - NbpObservable p5, NbpObservable p6, - NbpObservable p7, NbpObservable p8, - NbpObservable p9, - Function9 combiner) { - return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7, p8, p9); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable concat(int prefetch, Iterable> sources) { - Objects.requireNonNull(sources, "sources is null"); - return fromIterable(sources).concatMap((Function)Functions.identity(), prefetch); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable concat(Iterable> sources) { - Objects.requireNonNull(sources, "sources is null"); - return fromIterable(sources).concatMap((Function)Functions.identity()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static final NbpObservable concat(NbpObservable> sources) { - return concat(sources, bufferSize()); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static final NbpObservable concat(NbpObservable> sources, int bufferSize) { - return sources.concatMap((Function)Functions.identity()); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable concat(NbpObservable p1, NbpObservable p2) { - return concatArray(p1, p2); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable concat( - NbpObservable p1, NbpObservable p2, - NbpObservable p3) { - return concatArray(p1, p2, p3); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable concat( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4) { - return concatArray(p1, p2, p3, p4); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable concat( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4, - NbpObservable p5 - ) { - return concatArray(p1, p2, p3, p4, p5); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable concat( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4, - NbpObservable p5, NbpObservable p6 - ) { - return concatArray(p1, p2, p3, p4, p5, p6); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable concat( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4, - NbpObservable p5, NbpObservable p6, - NbpObservable p7 - ) { - return concatArray(p1, p2, p3, p4, p5, p6, p7); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable concat( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4, - NbpObservable p5, NbpObservable p6, - NbpObservable p7, NbpObservable p8 - ) { - return concatArray(p1, p2, p3, p4, p5, p6, p7, p8); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable concat( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4, - NbpObservable p5, NbpObservable p6, - NbpObservable p7, NbpObservable p8, - NbpObservable p9 - ) { - return concatArray(p1, p2, p3, p4, p5, p6, p7, p8, p9); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable concatArray(int prefetch, NbpObservable... sources) { - Objects.requireNonNull(sources, "sources is null"); - return fromArray(sources).concatMap((Function)Functions.identity(), prefetch); - } - - /** - * Concatenates a variable number of NbpObservable sources. - *

- * Note: named this way because of overload conflict with concat(NbpObservable<NbpObservable>) - * @param sources the array of sources - * @param the common base value type - * @return the new NbpObservable instance - * @throws NullPointerException if sources is null - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable concatArray(NbpObservable... sources) { - if (sources.length == 0) { - return empty(); - } else - if (sources.length == 1) { - return (NbpObservable)sources[0]; - } - return fromArray(sources).concatMap((Function)Functions.identity()); - } - - public static NbpObservable create(NbpOnSubscribe onSubscribe) { - Objects.requireNonNull(onSubscribe, "onSubscribe is null"); - // TODO plugin wrapper - return new NbpObservable(onSubscribe); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable defer(Supplier> supplier) { - Objects.requireNonNull(supplier, "supplier is null"); - return create(new NbpOnSubscribeDefer(supplier)); - } - - @SchedulerSupport(SchedulerKind.NONE) - @SuppressWarnings("unchecked") - public static NbpObservable empty() { - return (NbpObservable)EMPTY; - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable error(Supplier errorSupplier) { - Objects.requireNonNull(errorSupplier, "errorSupplier is null"); - return create(new NbpOnSubscribeErrorSource(errorSupplier)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable error(final Throwable e) { - Objects.requireNonNull(e, "e is null"); - return error(new Supplier() { - @Override - public Throwable get() { - return e; - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable fromArray(T... values) { - Objects.requireNonNull(values, "values is null"); - if (values.length == 0) { - return empty(); - } else - if (values.length == 1) { - return just(values[0]); - } - return create(new NbpOnSubscribeArraySource(values)); - } - - // TODO match naming with RxJava 1.x - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable fromCallable(Callable supplier) { - Objects.requireNonNull(supplier, "supplier is null"); - return create(new NbpOnSubscribeScalarAsyncSource(supplier)); - } - - /* - * It doesn't add cancellation support by default like 1.x - * if necessary, one can use composition to achieve it: - * futureObservable.doOnCancel(() -> future.cancel(true)); - */ - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable fromFuture(Future future) { - Objects.requireNonNull(future, "future is null"); - return create(new NbpOnSubscribeFutureSource(future, 0L, null)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable fromFuture(Future future, long timeout, TimeUnit unit) { - Objects.requireNonNull(future, "future is null"); - Objects.requireNonNull(unit, "unit is null"); - NbpObservable o = create(new NbpOnSubscribeFutureSource(future, timeout, unit)); - return o; - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public static NbpObservable fromFuture(Future future, long timeout, TimeUnit unit, Scheduler scheduler) { - Objects.requireNonNull(scheduler, "scheduler is null"); - NbpObservable o = fromFuture(future, timeout, unit); - return o.subscribeOn(scheduler); - } - - @SchedulerSupport(SchedulerKind.IO) - public static NbpObservable fromFuture(Future future, Scheduler scheduler) { - Objects.requireNonNull(scheduler, "scheduler is null"); - NbpObservable o = fromFuture(future); - return o.subscribeOn(Schedulers.io()); - } - - public static NbpObservable fromIterable(Iterable source) { - Objects.requireNonNull(source, "source is null"); - return create(new NbpOnSubscribeIterableSource(source)); - } - - public static NbpObservable fromPublisher(final Publisher publisher) { - Objects.requireNonNull(publisher, "publisher is null"); - return create(new NbpOnSubscribe() { - @Override - public void accept(final NbpSubscriber s) { - publisher.subscribe(new Subscriber() { - - @Override - public void onComplete() { - s.onComplete(); - } - - @Override - public void onError(Throwable t) { - s.onError(t); - } - - @Override - public void onNext(T t) { - s.onNext(t); - } - - @Override - public void onSubscribe(Subscription inner) { - s.onSubscribe(Disposables.from(inner)); - inner.request(Long.MAX_VALUE); - } - - }); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable generate(final Consumer> generator) { - Objects.requireNonNull(generator, "generator is null"); - return generate(Functions.nullSupplier(), - new BiFunction, Object>() { - @Override - public Object apply(Object s, NbpSubscriber o) { - generator.accept(o); - return s; - } - }, Functions.emptyConsumer()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable generate(Supplier initialState, final BiConsumer> generator) { - Objects.requireNonNull(generator, "generator is null"); - return generate(initialState, new BiFunction, S>() { - @Override - public S apply(S s, NbpSubscriber o) { - generator.accept(s, o); - return s; - } - }, Functions.emptyConsumer()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable generate( - final Supplier initialState, - final BiConsumer> generator, - Consumer disposeState) { - Objects.requireNonNull(generator, "generator is null"); - return generate(initialState, new BiFunction, S>() { - @Override - public S apply(S s, NbpSubscriber o) { - generator.accept(s, o); - return s; - } - }, disposeState); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable generate(Supplier initialState, BiFunction, S> generator) { - return generate(initialState, generator, Functions.emptyConsumer()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable generate(Supplier initialState, BiFunction, S> generator, Consumer disposeState) { - Objects.requireNonNull(initialState, "initialState is null"); - Objects.requireNonNull(generator, "generator is null"); - Objects.requireNonNull(disposeState, "diposeState is null"); - return create(new NbpOnSubscribeGenerate(initialState, generator, disposeState)); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public static NbpObservable interval(long initialDelay, long period, TimeUnit unit) { - return interval(initialDelay, period, unit, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public static NbpObservable interval(long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { - if (initialDelay < 0) { - initialDelay = 0L; - } - if (period < 0) { - period = 0L; - } - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - - return create(new NbpOnSubscribeIntervalSource(initialDelay, period, unit, scheduler)); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public static NbpObservable interval(long period, TimeUnit unit) { - return interval(period, period, unit, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public static NbpObservable interval(long period, TimeUnit unit, Scheduler scheduler) { - return interval(period, period, unit, scheduler); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public static NbpObservable intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit) { - return intervalRange(start, count, initialDelay, period, unit, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public static NbpObservable intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { - - long end = start + (count - 1); - if (end < 0) { - throw new IllegalArgumentException("Overflow! start + count is bigger than Long.MAX_VALUE"); - } - - if (initialDelay < 0) { - initialDelay = 0L; - } - if (period < 0) { - period = 0L; - } - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - - return create(new NbpOnSubscribeIntervalRangeSource(start, end, initialDelay, period, unit, scheduler)); - } - - public static NbpObservable just(T value) { - Objects.requireNonNull(value, "The value is null"); - return new NbpObservableScalarSource(value); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static final NbpObservable just(T v1, T v2) { - Objects.requireNonNull(v1, "The first value is null"); - Objects.requireNonNull(v2, "The second value is null"); - - return fromArray(v1, v2); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static final NbpObservable just(T v1, T v2, T v3) { - Objects.requireNonNull(v1, "The first value is null"); - Objects.requireNonNull(v2, "The second value is null"); - Objects.requireNonNull(v3, "The third value is null"); - - return fromArray(v1, v2, v3); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static final NbpObservable just(T v1, T v2, T v3, T v4) { - Objects.requireNonNull(v1, "The first value is null"); - Objects.requireNonNull(v2, "The second value is null"); - Objects.requireNonNull(v3, "The third value is null"); - Objects.requireNonNull(v4, "The fourth value is null"); - - return fromArray(v1, v2, v3, v4); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static final NbpObservable just(T v1, T v2, T v3, T v4, T v5) { - Objects.requireNonNull(v1, "The first value is null"); - Objects.requireNonNull(v2, "The second value is null"); - Objects.requireNonNull(v3, "The third value is null"); - Objects.requireNonNull(v4, "The fourth value is null"); - Objects.requireNonNull(v5, "The fifth value is null"); - - return fromArray(v1, v2, v3, v4, v5); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static final NbpObservable just(T v1, T v2, T v3, T v4, T v5, T v6) { - Objects.requireNonNull(v1, "The first value is null"); - Objects.requireNonNull(v2, "The second value is null"); - Objects.requireNonNull(v3, "The third value is null"); - Objects.requireNonNull(v4, "The fourth value is null"); - Objects.requireNonNull(v5, "The fifth value is null"); - Objects.requireNonNull(v6, "The sixth value is null"); - - return fromArray(v1, v2, v3, v4, v5, v6); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static final NbpObservable just(T v1, T v2, T v3, T v4, T v5, T v6, T v7) { - Objects.requireNonNull(v1, "The first value is null"); - Objects.requireNonNull(v2, "The second value is null"); - Objects.requireNonNull(v3, "The third value is null"); - Objects.requireNonNull(v4, "The fourth value is null"); - Objects.requireNonNull(v5, "The fifth value is null"); - Objects.requireNonNull(v6, "The sixth value is null"); - Objects.requireNonNull(v7, "The seventh value is null"); - - return fromArray(v1, v2, v3, v4, v5, v6, v7); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static final NbpObservable just(T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8) { - Objects.requireNonNull(v1, "The first value is null"); - Objects.requireNonNull(v2, "The second value is null"); - Objects.requireNonNull(v3, "The third value is null"); - Objects.requireNonNull(v4, "The fourth value is null"); - Objects.requireNonNull(v5, "The fifth value is null"); - Objects.requireNonNull(v6, "The sixth value is null"); - Objects.requireNonNull(v7, "The seventh value is null"); - Objects.requireNonNull(v8, "The eigth value is null"); - - return fromArray(v1, v2, v3, v4, v5, v6, v7, v8); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static final NbpObservable just(T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8, T v9) { - Objects.requireNonNull(v1, "The first value is null"); - Objects.requireNonNull(v2, "The second value is null"); - Objects.requireNonNull(v3, "The third value is null"); - Objects.requireNonNull(v4, "The fourth value is null"); - Objects.requireNonNull(v5, "The fifth value is null"); - Objects.requireNonNull(v6, "The sixth value is null"); - Objects.requireNonNull(v7, "The seventh value is null"); - Objects.requireNonNull(v8, "The eigth value is null"); - Objects.requireNonNull(v9, "The ninth is null"); - - return fromArray(v1, v2, v3, v4, v5, v6, v7, v8, v9); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable merge(int maxConcurrency, int bufferSize, Iterable> sources) { - return fromIterable(sources).flatMap((Function)Functions.identity(), false, maxConcurrency, bufferSize); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable merge(int maxConcurrency, int bufferSize, NbpObservable... sources) { - return fromArray(sources).flatMap((Function)Functions.identity(), false, maxConcurrency, bufferSize); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable merge(int maxConcurrency, NbpObservable... sources) { - return fromArray(sources).flatMap((Function)Functions.identity(), maxConcurrency); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable merge(Iterable> sources) { - return fromIterable(sources).flatMap((Function)Functions.identity()); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable merge(Iterable> sources, int maxConcurrency) { - return fromIterable(sources).flatMap((Function)Functions.identity(), maxConcurrency); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static NbpObservable merge(NbpObservable> sources) { - return sources.flatMap((Function)Functions.identity()); - } - - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable merge(NbpObservable> sources, int maxConcurrency) { - return sources.flatMap((Function)Functions.identity(), maxConcurrency); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable merge(NbpObservable p1, NbpObservable p2) { - Objects.requireNonNull(p1, "p1 is null"); - Objects.requireNonNull(p2, "p2 is null"); - return fromArray(p1, p2).flatMap((Function)Functions.identity(), false, 2); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable merge(NbpObservable p1, NbpObservable p2, NbpObservable p3) { - Objects.requireNonNull(p1, "p1 is null"); - Objects.requireNonNull(p2, "p2 is null"); - Objects.requireNonNull(p3, "p3 is null"); - return fromArray(p1, p2, p3).flatMap((Function)Functions.identity(), false, 3); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable merge( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4) { - Objects.requireNonNull(p1, "p1 is null"); - Objects.requireNonNull(p2, "p2 is null"); - Objects.requireNonNull(p3, "p3 is null"); - Objects.requireNonNull(p4, "p4 is null"); - return fromArray(p1, p2, p3, p4).flatMap((Function)Functions.identity(), false, 4); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable merge(NbpObservable... sources) { - return fromArray(sources).flatMap((Function)Functions.identity(), sources.length); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable mergeDelayError(boolean delayErrors, Iterable> sources) { - return fromIterable(sources).flatMap((Function)Functions.identity(), true); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable mergeDelayError(int maxConcurrency, int bufferSize, Iterable> sources) { - return fromIterable(sources).flatMap((Function)Functions.identity(), true, maxConcurrency, bufferSize); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable mergeDelayError(int maxConcurrency, int bufferSize, NbpObservable... sources) { - return fromArray(sources).flatMap((Function)Functions.identity(), true, maxConcurrency, bufferSize); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable mergeDelayError(int maxConcurrency, Iterable> sources) { - return fromIterable(sources).flatMap((Function)Functions.identity(), true, maxConcurrency); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable mergeDelayError(int maxConcurrency, NbpObservable... sources) { - return fromArray(sources).flatMap((Function)Functions.identity(), true, maxConcurrency); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static NbpObservable mergeDelayError(NbpObservable> sources) { - return sources.flatMap((Function)Functions.identity(), true); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable mergeDelayError(NbpObservable> sources, int maxConcurrency) { - return sources.flatMap((Function)Functions.identity(), true, maxConcurrency); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable mergeDelayError(NbpObservable p1, NbpObservable p2) { - Objects.requireNonNull(p1, "p1 is null"); - Objects.requireNonNull(p2, "p2 is null"); - return fromArray(p1, p2).flatMap((Function)Functions.identity(), true, 2); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable mergeDelayError(NbpObservable p1, NbpObservable p2, NbpObservable p3) { - Objects.requireNonNull(p1, "p1 is null"); - Objects.requireNonNull(p2, "p2 is null"); - Objects.requireNonNull(p3, "p3 is null"); - return fromArray(p1, p2, p3).flatMap((Function)Functions.identity(), true, 3); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable mergeDelayError( - NbpObservable p1, NbpObservable p2, - NbpObservable p3, NbpObservable p4) { - Objects.requireNonNull(p1, "p1 is null"); - Objects.requireNonNull(p2, "p2 is null"); - Objects.requireNonNull(p3, "p3 is null"); - Objects.requireNonNull(p4, "p4 is null"); - return fromArray(p1, p2, p3, p4).flatMap((Function)Functions.identity(), true, 4); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable mergeDelayError(NbpObservable... sources) { - return fromArray(sources).flatMap((Function)Functions.identity(), true, sources.length); - } - - @SchedulerSupport(SchedulerKind.NONE) - @SuppressWarnings("unchecked") - public static NbpObservable never() { - return (NbpObservable)NEVER; - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable range(final int start, final int count) { - if (count < 0) { - throw new IllegalArgumentException("count >= required but it was " + count); - } else - if (count == 0) { - return empty(); - } else - if (count == 1) { - return just(start); - } else - if ((long)start + (count - 1) > Integer.MAX_VALUE) { - throw new IllegalArgumentException("Integer overflow"); - } - return create(new NbpOnSubscribe() { - @Override - public void accept(NbpSubscriber s) { - BooleanDisposable d = new BooleanDisposable(); - s.onSubscribe(d); - - long end = start - 1L + count; - for (long i = start; i <= end && !d.isDisposed(); i++) { - s.onNext((int)i); - } - if (!d.isDisposed()) { - s.onComplete(); - } - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable sequenceEqual(NbpObservable p1, NbpObservable p2) { - return sequenceEqual(p1, p2, Objects.equalsPredicate(), bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable sequenceEqual(NbpObservable p1, NbpObservable p2, BiPredicate isEqual) { - return sequenceEqual(p1, p2, isEqual, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable sequenceEqual(NbpObservable p1, NbpObservable p2, BiPredicate isEqual, int bufferSize) { - Objects.requireNonNull(p1, "p1 is null"); - Objects.requireNonNull(p2, "p2 is null"); - Objects.requireNonNull(isEqual, "isEqual is null"); - validateBufferSize(bufferSize); - return create(new NbpOnSubscribeSequenceEqual(p1, p2, isEqual, bufferSize)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable sequenceEqual(NbpObservable p1, NbpObservable p2, int bufferSize) { - return sequenceEqual(p1, p2, Objects.equalsPredicate(), bufferSize); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable switchOnNext(int bufferSize, NbpObservable> sources) { - return sources.switchMap((Function)Functions.identity(), bufferSize); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable switchOnNext(NbpObservable> sources) { - return sources.switchMap((Function)Functions.identity()); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public static NbpObservable timer(long delay, TimeUnit unit) { - return timer(delay, unit, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public static NbpObservable timer(long delay, TimeUnit unit, Scheduler scheduler) { - if (delay < 0) { - delay = 0L; - } - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - - return create(new NbpOnSubscribeTimerOnceSource(delay, unit, scheduler)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable using(Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer) { - return using(resourceSupplier, sourceSupplier, disposer, true); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable using(Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer, boolean eager) { - Objects.requireNonNull(resourceSupplier, "resourceSupplier is null"); - Objects.requireNonNull(sourceSupplier, "sourceSupplier is null"); - Objects.requireNonNull(disposer, "disposer is null"); - return create(new NbpOnSubscribeUsing(resourceSupplier, sourceSupplier, disposer, eager)); - } - - private static void validateBufferSize(int bufferSize) { - if (bufferSize <= 0) { - throw new IllegalArgumentException("bufferSize > 0 required but it was " + bufferSize); - } - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zip(Iterable> sources, Function zipper) { - Objects.requireNonNull(zipper, "zipper is null"); - Objects.requireNonNull(sources, "sources is null"); - return create(new NbpOnSubscribeZip(null, sources, zipper, bufferSize(), false)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zip(NbpObservable> sources, final Function zipper) { - Objects.requireNonNull(zipper, "zipper is null"); - return sources.toList().flatMap(new Function>, NbpObservable>() { - @Override - public NbpObservable apply(List> list) { - return zipIterable(zipper, false, bufferSize(), list); - } - }); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zip( - NbpObservable p1, NbpObservable p2, - BiFunction zipper) { - return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zip( - NbpObservable p1, NbpObservable p2, - BiFunction zipper, boolean delayError) { - return zipArray(Functions.toFunction(zipper), delayError, bufferSize(), p1, p2); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zip( - NbpObservable p1, NbpObservable p2, - BiFunction zipper, boolean delayError, int bufferSize) { - return zipArray(Functions.toFunction(zipper), delayError, bufferSize, p1, p2); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zip( - NbpObservable p1, NbpObservable p2, NbpObservable p3, - Function3 zipper) { - return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zip( - NbpObservable p1, NbpObservable p2, NbpObservable p3, - NbpObservable p4, - Function4 zipper) { - return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zip( - NbpObservable p1, NbpObservable p2, NbpObservable p3, - NbpObservable p4, NbpObservable p5, - Function5 zipper) { - return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zip( - NbpObservable p1, NbpObservable p2, NbpObservable p3, - NbpObservable p4, NbpObservable p5, NbpObservable p6, - Function6 zipper) { - return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5, p6); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zip( - NbpObservable p1, NbpObservable p2, NbpObservable p3, - NbpObservable p4, NbpObservable p5, NbpObservable p6, - NbpObservable p7, - Function7 zipper) { - return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zip( - NbpObservable p1, NbpObservable p2, NbpObservable p3, - NbpObservable p4, NbpObservable p5, NbpObservable p6, - NbpObservable p7, NbpObservable p8, - Function8 zipper) { - return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7, p8); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zip( - NbpObservable p1, NbpObservable p2, NbpObservable p3, - NbpObservable p4, NbpObservable p5, NbpObservable p6, - NbpObservable p7, NbpObservable p8, NbpObservable p9, - Function9 zipper) { - return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7, p8, p9); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zipArray(Function zipper, - boolean delayError, int bufferSize, NbpObservable... sources) { - if (sources.length == 0) { - return empty(); - } - Objects.requireNonNull(zipper, "zipper is null"); - validateBufferSize(bufferSize); - return create(new NbpOnSubscribeZip(sources, null, zipper, bufferSize, delayError)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public static NbpObservable zipIterable(Function zipper, - boolean delayError, int bufferSize, - Iterable> sources) { - Objects.requireNonNull(zipper, "zipper is null"); - Objects.requireNonNull(sources, "sources is null"); - validateBufferSize(bufferSize); - return create(new NbpOnSubscribeZip(null, sources, zipper, bufferSize, delayError)); - } - - - protected final NbpOnSubscribe onSubscribe; - - protected NbpObservable(NbpOnSubscribe onSubscribe) { - this.onSubscribe = onSubscribe; - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable all(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); - return lift(new NbpOperatorAll(predicate)); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable ambWith(NbpObservable other) { - Objects.requireNonNull(other, "other is null"); - return amb(this, other); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable any(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); - return lift(new NbpOperatorAny(predicate)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable asObservable() { - return create(new NbpOnSubscribe() { - @Override - public void accept(NbpSubscriber s) { - NbpObservable.this.subscribe(s); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> buffer(int count) { - return buffer(count, count); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> buffer(int count, int skip) { - return buffer(count, skip, new Supplier>() { - @Override - public List get() { - return new ArrayList(); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final > NbpObservable buffer(int count, int skip, Supplier bufferSupplier) { - if (count <= 0) { - throw new IllegalArgumentException("count > 0 required but it was " + count); - } - if (skip <= 0) { - throw new IllegalArgumentException("skip > 0 required but it was " + count); - } - Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); - return lift(new NbpOperatorBuffer(count, skip, bufferSupplier)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final > NbpObservable buffer(int count, Supplier bufferSupplier) { - return buffer(count, count, bufferSupplier); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable> buffer(long timespan, long timeskip, TimeUnit unit) { - return buffer(timespan, timeskip, unit, Schedulers.computation(), new Supplier>() { - @Override - public List get() { - return new ArrayList(); - } - }); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> buffer(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler) { - return buffer(timespan, timeskip, unit, scheduler, new Supplier>() { - @Override - public List get() { - return new ArrayList(); - } - }); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final > NbpObservable buffer(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler, Supplier bufferSupplier) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); - return lift(new NbpOperatorBufferTimed(timespan, timeskip, unit, scheduler, bufferSupplier, Integer.MAX_VALUE, false)); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable> buffer(long timespan, TimeUnit unit) { - return buffer(timespan, unit, Integer.MAX_VALUE, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable> buffer(long timespan, TimeUnit unit, int count) { - return buffer(timespan, unit, count, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> buffer(long timespan, TimeUnit unit, int count, Scheduler scheduler) { - return buffer(timespan, unit, count, scheduler, new Supplier>() { - @Override - public List get() { - return new ArrayList(); - } - }, false); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final > NbpObservable buffer( - long timespan, TimeUnit unit, - int count, Scheduler scheduler, - Supplier bufferSupplier, - boolean restartTimerOnMaxSize) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); - if (count <= 0) { - throw new IllegalArgumentException("count > 0 required but it was " + count); - } - return lift(new NbpOperatorBufferTimed(timespan, timespan, unit, scheduler, bufferSupplier, count, restartTimerOnMaxSize)); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> buffer(long timespan, TimeUnit unit, Scheduler scheduler) { - return buffer(timespan, unit, Integer.MAX_VALUE, scheduler, new Supplier>() { - @Override - public List get() { - return new ArrayList(); - } - }, false); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> buffer( - NbpObservable bufferOpenings, - Function> bufferClosingSelector) { - return buffer(bufferOpenings, bufferClosingSelector, new Supplier>() { - @Override - public List get() { - return new ArrayList(); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final > NbpObservable buffer( - NbpObservable bufferOpenings, - Function> bufferClosingSelector, - Supplier bufferSupplier) { - Objects.requireNonNull(bufferOpenings, "bufferOpenings is null"); - Objects.requireNonNull(bufferClosingSelector, "bufferClosingSelector is null"); - Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); - return lift(new NbpOperatorBufferBoundary(bufferOpenings, bufferClosingSelector, bufferSupplier)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> buffer(NbpObservable boundary) { - /* - * XXX: javac complains if this is not manually cast, Eclipse is fine - */ - return buffer(boundary, new Supplier>() { - @Override - public List get() { - return new ArrayList(); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> buffer(NbpObservable boundary, final int initialCapacity) { - return buffer(boundary, new Supplier>() { - @Override - public List get() { - return new ArrayList(initialCapacity); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final > NbpObservable buffer(NbpObservable boundary, Supplier bufferSupplier) { - Objects.requireNonNull(boundary, "boundary is null"); - Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); - return lift(new NbpOperatorBufferExactBoundary(boundary, bufferSupplier)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> buffer(Supplier> boundarySupplier) { - return buffer(boundarySupplier, new Supplier>() { - @Override - public List get() { - return new ArrayList(); - } - }); - - } - - @SchedulerSupport(SchedulerKind.NONE) - public final > NbpObservable buffer(Supplier> boundarySupplier, Supplier bufferSupplier) { - Objects.requireNonNull(boundarySupplier, "boundarySupplier is null"); - Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); - return lift(new NbpOperatorBufferBoundarySupplier(boundarySupplier, bufferSupplier)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable cache() { - return NbpCachedObservable.from(this); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable cache(int capacityHint) { - return NbpCachedObservable.from(this, capacityHint); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable cast(final Class clazz) { - Objects.requireNonNull(clazz, "clazz is null"); - return map(new Function() { - @Override - public U apply(T v) { - return clazz.cast(v); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable collect(Supplier initialValueSupplier, BiConsumer collector) { - Objects.requireNonNull(initialValueSupplier, "initalValueSupplier is null"); - Objects.requireNonNull(collector, "collector is null"); - return lift(new NbpOperatorCollect(initialValueSupplier, collector)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable collectInto(final U initialValue, BiConsumer collector) { - Objects.requireNonNull(initialValue, "initialValue is null"); - return collect(new Supplier() { - @Override - public U get() { - return initialValue; - } - }, collector); - } - - public final NbpObservable compose(Function, ? extends NbpObservable> convert) { - return to(convert); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable concatMap(Function> mapper) { - return concatMap(mapper, 2); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable concatMap(Function> mapper, int prefetch) { - Objects.requireNonNull(mapper, "mapper is null"); - if (prefetch <= 0) { - throw new IllegalArgumentException("prefetch > 0 required but it was " + prefetch); - } - return lift(new NbpOperatorConcatMap(mapper, prefetch)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable concatMapIterable(final Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); - return concatMap(new Function>() { - @Override - public NbpObservable apply(T v) { - return fromIterable(mapper.apply(v)); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable concatMapIterable(final Function> mapper, int prefetch) { - return concatMap(new Function>() { - @Override - public NbpObservable apply(T v) { - return fromIterable(mapper.apply(v)); - } - }, prefetch); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable concatWith(NbpObservable other) { - Objects.requireNonNull(other, "other is null"); - return concat(this, other); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable contains(final Object o) { - Objects.requireNonNull(o, "o is null"); - return any(new Predicate() { - @Override - public boolean test(T v) { - return Objects.equals(v, o); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable count() { - return lift(NbpOperatorCount.instance()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable debounce(Function> debounceSelector) { - Objects.requireNonNull(debounceSelector, "debounceSelector is null"); - return lift(new NbpOperatorDebounce(debounceSelector)); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable debounce(long timeout, TimeUnit unit) { - return debounce(timeout, unit, Schedulers.computation()); - } - - @BackpressureSupport(BackpressureKind.ERROR) - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable debounce(long timeout, TimeUnit unit, Scheduler scheduler) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new NbpOperatorDebounceTimed(timeout, unit, scheduler)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable defaultIfEmpty(T value) { - Objects.requireNonNull(value, "value is null"); - return switchIfEmpty(just(value)); - } - - @SchedulerSupport(SchedulerKind.NONE) - // TODO a more efficient implementation if necessary - public final NbpObservable delay(final Function> itemDelay) { - Objects.requireNonNull(itemDelay, "itemDelay is null"); - return flatMap(new Function>() { - @Override - public NbpObservable apply(final T v) { - return itemDelay.apply(v).take(1).map(new Function() { - @Override - public T apply(U u) { - return v; - } - }).defaultIfEmpty(v); - } - }); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable delay(long delay, TimeUnit unit) { - return delay(delay, unit, Schedulers.computation(), false); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable delay(long delay, TimeUnit unit, boolean delayError) { - return delay(delay, unit, Schedulers.computation(), delayError); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable delay(long delay, TimeUnit unit, Scheduler scheduler) { - return delay(delay, unit, scheduler, false); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable delay(long delay, TimeUnit unit, Scheduler scheduler, boolean delayError) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - - return lift(new NbpOperatorDelay(delay, unit, scheduler, delayError)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable delay(Supplier> delaySupplier, - Function> itemDelay) { - return delaySubscription(delaySupplier).delay(itemDelay); - } - - /** - * Returns an Observable that delays the subscription to this Observable - * until the other Observable emits an element or completes normally. - *

- *

- *
Backpressure:
- *
The operator forwards the backpressure requests to this Observable once - * the subscription happens and requests Long.MAX_VALUE from the other Observable
- *
Scheduler:
- *
This method does not operate by default on a particular {@link Scheduler}.
- *
- * - * @param the value type of the other Observable, irrelevant - * @param other the other Observable that should trigger the subscription - * to this Observable. - * @return an Observable that delays the subscription to this Observable - * until the other Observable emits an element or completes normally. - */ - @Experimental - public final NbpObservable delaySubscription(NbpObservable other) { - Objects.requireNonNull(other, "other is null"); - return create(new NbpOnSubscribeDelaySubscriptionOther(this, other)); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable delaySubscription(long delay, TimeUnit unit) { - return delaySubscription(delay, unit, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - // TODO a more efficient implementation if necessary - public final NbpObservable delaySubscription(long delay, TimeUnit unit, Scheduler scheduler) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - - return timer(delay, unit, scheduler).flatMap(new Function>() { - @Override - public NbpObservable apply(Long v) { - return NbpObservable.this; - } - }); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable delaySubscription(final Supplier> delaySupplier) { - Objects.requireNonNull(delaySupplier, "delaySupplier is null"); - return fromCallable(new Callable>() { - @Override - public NbpObservable call() throws Exception { - return delaySupplier.get(); - } - }) - .flatMap((Function)Functions.identity()) - .take(1) - .cast(Object.class) - .defaultIfEmpty(OBJECT) - .flatMap(new Function>() { - @Override - public NbpObservable apply(Object v) { - return NbpObservable.this; - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable dematerialize() { - @SuppressWarnings("unchecked") - NbpObservable>> m = (NbpObservable>>)this; - return m.lift(NbpOperatorDematerialize.instance()); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable distinct() { - return distinct((Function)Functions.identity(), new Supplier>() { - @Override - public Collection get() { - return new HashSet(); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable distinct(Function keySelector) { - return distinct(keySelector, new Supplier>() { - @Override - public Collection get() { - return new HashSet(); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable distinct(Function keySelector, Supplier> collectionSupplier) { - Objects.requireNonNull(keySelector, "keySelector is null"); - Objects.requireNonNull(collectionSupplier, "collectionSupplier is null"); - return lift(NbpOperatorDistinct.withCollection(keySelector, collectionSupplier)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable distinctUntilChanged() { - return lift(NbpOperatorDistinct.untilChanged()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable distinctUntilChanged(Function keySelector) { - Objects.requireNonNull(keySelector, "keySelector is null"); - return lift(NbpOperatorDistinct.untilChanged(keySelector)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable doOnCancel(Runnable onCancel) { - return doOnLifecycle(Functions.emptyConsumer(), onCancel); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable doOnComplete(Runnable onComplete) { - return doOnEach(Functions.emptyConsumer(), Functions.emptyConsumer(), onComplete, Functions.emptyRunnable()); - } - - @SchedulerSupport(SchedulerKind.NONE) - private NbpObservable doOnEach(Consumer onNext, Consumer onError, Runnable onComplete, Runnable onAfterTerminate) { - Objects.requireNonNull(onNext, "onNext is null"); - Objects.requireNonNull(onError, "onError is null"); - Objects.requireNonNull(onComplete, "onComplete is null"); - Objects.requireNonNull(onAfterTerminate, "onAfterTerminate is null"); - return lift(new NbpOperatorDoOnEach(onNext, onError, onComplete, onAfterTerminate)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable doOnEach(final Consumer>> consumer) { - Objects.requireNonNull(consumer, "consumer is null"); - return doOnEach( - new Consumer() { - @Override - public void accept(T v) { - consumer.accept(Try.ofValue(Optional.of(v))); - } - }, - new Consumer() { - @Override - public void accept(Throwable e) { - consumer.accept(Try.>ofError(e)); - } - }, - new Runnable() { - @Override - public void run() { - consumer.accept(Try.ofValue(Optional.empty())); - } - }, - Functions.emptyRunnable() - ); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable doOnEach(final NbpSubscriber observer) { - Objects.requireNonNull(observer, "observer is null"); - return doOnEach(new Consumer() { - @Override - public void accept(T v) { - observer.onNext(v); - } - }, new Consumer() { - @Override - public void accept(Throwable e) { - observer.onError(e); - } - }, new Runnable() { - @Override - public void run() { - observer.onComplete(); - } - }, Functions.emptyRunnable()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable doOnError(Consumer onError) { - return doOnEach(Functions.emptyConsumer(), onError, Functions.emptyRunnable(), Functions.emptyRunnable()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable doOnLifecycle(final Consumer onSubscribe, final Runnable onCancel) { - Objects.requireNonNull(onSubscribe, "onSubscribe is null"); - Objects.requireNonNull(onCancel, "onCancel is null"); - return lift(new NbpOperator() { - @Override - public NbpSubscriber apply(NbpSubscriber s) { - return new NbpSubscriptionLambdaSubscriber(s, onSubscribe, onCancel); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable doOnNext(Consumer onNext) { - return doOnEach(onNext, Functions.emptyConsumer(), Functions.emptyRunnable(), Functions.emptyRunnable()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable doOnSubscribe(Consumer onSubscribe) { - return doOnLifecycle(onSubscribe, Functions.emptyRunnable()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable doOnTerminate(final Runnable onTerminate) { - return doOnEach(Functions.emptyConsumer(), new Consumer() { - @Override - public void accept(Throwable e) { - onTerminate.run(); - } - }, onTerminate, Functions.emptyRunnable()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable elementAt(long index) { - if (index < 0) { - throw new IndexOutOfBoundsException("index >= 0 required but it was " + index); - } - return lift(new NbpOperatorElementAt(index, null)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable elementAt(long index, T defaultValue) { - if (index < 0) { - throw new IndexOutOfBoundsException("index >= 0 required but it was " + index); - } - Objects.requireNonNull(defaultValue, "defaultValue is null"); - return lift(new NbpOperatorElementAt(index, defaultValue)); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable endWith(Iterable values) { - return concatArray(this, fromIterable(values)); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable endWith(NbpObservable other) { - Objects.requireNonNull(other, "other is null"); - return concatArray(this, other); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable endWith(T value) { - Objects.requireNonNull(value, "value is null"); - return concatArray(this, just(value)); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable endWithArray(T... values) { - NbpObservable fromArray = fromArray(values); - if (fromArray == empty()) { - return this; - } - return concatArray(this, fromArray); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable filter(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); - return lift(new NbpOperatorFilter(predicate)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable finallyDo(Runnable onFinally) { - return doOnEach(Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyRunnable(), onFinally); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable first() { - return take(1).single(); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable first(T defaultValue) { - return take(1).single(defaultValue); - } - - public final NbpObservable flatMap(Function> mapper) { - return flatMap(mapper, false); - } - - - public final NbpObservable flatMap(Function> mapper, boolean delayError) { - return flatMap(mapper, delayError, Integer.MAX_VALUE); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMap(Function> mapper, boolean delayErrors, int maxConcurrency) { - return flatMap(mapper, delayErrors, maxConcurrency, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMap(Function> mapper, - boolean delayErrors, int maxConcurrency, int bufferSize) { - Objects.requireNonNull(mapper, "mapper is null"); - if (maxConcurrency <= 0) { - throw new IllegalArgumentException("maxConcurrency > 0 required but it was " + maxConcurrency); - } - validateBufferSize(bufferSize); - if (this instanceof NbpObservableScalarSource) { - NbpObservableScalarSource scalar = (NbpObservableScalarSource) this; - return create(scalar.scalarFlatMap(mapper)); - } - return lift(new NbpOperatorFlatMap(mapper, delayErrors, maxConcurrency, bufferSize)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMap( - Function> onNextMapper, - Function> onErrorMapper, - Supplier> onCompleteSupplier) { - Objects.requireNonNull(onNextMapper, "onNextMapper is null"); - Objects.requireNonNull(onErrorMapper, "onErrorMapper is null"); - Objects.requireNonNull(onCompleteSupplier, "onCompleteSupplier is null"); - return merge(lift(new NbpOperatorMapNotification(onNextMapper, onErrorMapper, onCompleteSupplier))); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMap( - Function> onNextMapper, - Function> onErrorMapper, - Supplier> onCompleteSupplier, - int maxConcurrency) { - Objects.requireNonNull(onNextMapper, "onNextMapper is null"); - Objects.requireNonNull(onErrorMapper, "onErrorMapper is null"); - Objects.requireNonNull(onCompleteSupplier, "onCompleteSupplier is null"); - return merge(lift(new NbpOperatorMapNotification(onNextMapper, onErrorMapper, onCompleteSupplier)), maxConcurrency); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMap(Function> mapper, int maxConcurrency) { - return flatMap(mapper, false, maxConcurrency, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMap(Function> mapper, BiFunction resultSelector) { - return flatMap(mapper, resultSelector, false, bufferSize(), bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMap(Function> mapper, BiFunction combiner, boolean delayError) { - return flatMap(mapper, combiner, delayError, bufferSize(), bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMap(Function> mapper, BiFunction combiner, boolean delayError, int maxConcurrency) { - return flatMap(mapper, combiner, delayError, maxConcurrency, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMap(final Function> mapper, final BiFunction combiner, boolean delayError, int maxConcurrency, int bufferSize) { - Objects.requireNonNull(mapper, "mapper is null"); - Objects.requireNonNull(combiner, "combiner is null"); - return flatMap(new Function>() { - @Override - public NbpObservable apply(final T t) { - @SuppressWarnings("unchecked") - NbpObservable u = (NbpObservable)mapper.apply(t); - return u.map(new Function() { - @Override - public R apply(U w) { - return combiner.apply(t, w); - } - }); - } - }, delayError, maxConcurrency, bufferSize); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMap(Function> mapper, BiFunction combiner, int maxConcurrency) { - return flatMap(mapper, combiner, false, maxConcurrency, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMapIterable(final Function> mapper) { - Objects.requireNonNull(mapper, "mapper is null"); - return flatMap(new Function>() { - @Override - public NbpObservable apply(T v) { - return fromIterable(mapper.apply(v)); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMapIterable(final Function> mapper, BiFunction resultSelector) { - return flatMap(new Function>() { - @Override - public NbpObservable apply(T t) { - return fromIterable(mapper.apply(t)); - } - }, resultSelector, false, bufferSize(), bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable flatMapIterable(final Function> mapper, int bufferSize) { - return flatMap(new Function>() { - @Override - public NbpObservable apply(T v) { - return fromIterable(mapper.apply(v)); - } - }, false, bufferSize); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final Disposable forEach(Consumer onNext) { - return subscribe(onNext); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final Disposable forEachWhile(Predicate onNext) { - return forEachWhile(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final Disposable forEachWhile(Predicate onNext, Consumer onError) { - return forEachWhile(onNext, onError, Functions.emptyRunnable()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final Disposable forEachWhile(final Predicate onNext, Consumer onError, - final Runnable onComplete) { - Objects.requireNonNull(onNext, "onNext is null"); - Objects.requireNonNull(onError, "onError is null"); - Objects.requireNonNull(onComplete, "onComplete is null"); - - final AtomicReference subscription = new AtomicReference(); - return subscribe(new Consumer() { - @Override - public void accept(T v) { - if (!onNext.test(v)) { - subscription.get().dispose(); - onComplete.run(); - } - } - }, onError, onComplete, new Consumer() { - @Override - public void accept(Disposable s) { - subscription.lazySet(s); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final List getList() { - final List result = new ArrayList(); - final Throwable[] error = { null }; - final CountDownLatch cdl = new CountDownLatch(1); - - subscribe(new NbpSubscriber() { - @Override - public void onComplete() { - cdl.countDown(); - } - @Override - public void onError(Throwable e) { - error[0] = e; - cdl.countDown(); - } - @Override - public void onNext(T value) { - result.add(value); - } - @Override - public void onSubscribe(Disposable d) { - - } - }); - - if (cdl.getCount() != 0) { - try { - cdl.await(); - } catch (InterruptedException ex) { - throw Exceptions.propagate(ex); - } - } - - Throwable e = error[0]; - if (e != null) { - throw Exceptions.propagate(e); - } - - return result; - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> groupBy(Function keySelector) { - return groupBy(keySelector, (Function)Functions.identity(), false, bufferSize()); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> groupBy(Function keySelector, boolean delayError) { - return groupBy(keySelector, (Function)Functions.identity(), delayError, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> groupBy(Function keySelector, - Function valueSelector) { - return groupBy(keySelector, valueSelector, false, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> groupBy(Function keySelector, - Function valueSelector, boolean delayError) { - return groupBy(keySelector, valueSelector, false, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> groupBy(Function keySelector, - Function valueSelector, - boolean delayError, int bufferSize) { - Objects.requireNonNull(keySelector, "keySelector is null"); - Objects.requireNonNull(valueSelector, "valueSelector is null"); - validateBufferSize(bufferSize); - - return lift(new NbpOperatorGroupBy(keySelector, valueSelector, bufferSize, delayError)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable ignoreElements() { - return lift(NbpOperatorIgnoreElements.instance()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable isEmpty() { - return all(new Predicate() { - @Override - public boolean test(T v) { - return false; - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable last() { - return takeLast(1).single(); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable last(T defaultValue) { - return takeLast(1).single(defaultValue); - } - - public final NbpObservable lift(NbpOperator onLift) { - Objects.requireNonNull(onLift, "onLift is null"); - return create(new NbpOnSubscribeLift(this, onLift)); - } - - public final NbpObservable map(Function mapper) { - Objects.requireNonNull(mapper, "mapper is null"); - return lift(new NbpOperatorMap(mapper)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable>> materialize() { - return lift(NbpOperatorMaterialize.instance()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable mergeWith(NbpObservable other) { - Objects.requireNonNull(other, "other is null"); - return merge(this, other); - } - - @SchedulerSupport(SchedulerKind.NONE) - @Deprecated - public final NbpObservable> nest() { - return just(this); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable observeOn(Scheduler scheduler) { - return observeOn(scheduler, false, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable observeOn(Scheduler scheduler, boolean delayError) { - return observeOn(scheduler, delayError, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable observeOn(Scheduler scheduler, boolean delayError, int bufferSize) { - Objects.requireNonNull(scheduler, "scheduler is null"); - validateBufferSize(bufferSize); - return lift(new NbpOperatorObserveOn(scheduler, delayError, bufferSize)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable ofType(final Class clazz) { - Objects.requireNonNull(clazz, "clazz is null"); - return filter(new Predicate() { - @Override - public boolean test(T v) { - return clazz.isInstance(v); - } - }).cast(clazz); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable onErrorResumeNext(Function> resumeFunction) { - Objects.requireNonNull(resumeFunction, "resumeFunction is null"); - return lift(new NbpOperatorOnErrorNext(resumeFunction, false)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable onErrorResumeNext(final NbpObservable next) { - Objects.requireNonNull(next, "next is null"); - return onErrorResumeNext(new Function>() { - @Override - public NbpObservable apply(Throwable e) { - return next; - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable onErrorReturn(Function valueSupplier) { - Objects.requireNonNull(valueSupplier, "valueSupplier is null"); - return lift(new NbpOperatorOnErrorReturn(valueSupplier)); - } - - // TODO would result in ambiguity with onErrorReturn(Function) - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable onErrorReturnValue(final T value) { - Objects.requireNonNull(value, "value is null"); - return onErrorReturn(new Function() { - @Override - public T apply(Throwable e) { - return value; - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable onExceptionResumeNext(final NbpObservable next) { - Objects.requireNonNull(next, "next is null"); - return lift(new NbpOperatorOnErrorNext(new Function>() { - @Override - public NbpObservable apply(Throwable e) { - return next; - } - }, true)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpConnectableObservable publish() { - return publish(bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable publish(Function, ? extends NbpObservable> selector) { - return publish(selector, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable publish(Function, ? extends NbpObservable> selector, int bufferSize) { - validateBufferSize(bufferSize); - Objects.requireNonNull(selector, "selector is null"); - return NbpOperatorPublish.create(this, selector, bufferSize); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpConnectableObservable publish(int bufferSize) { - validateBufferSize(bufferSize); - return NbpOperatorPublish.create(this, bufferSize); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable reduce(BiFunction reducer) { - return scan(reducer).last(); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable reduce(R seed, BiFunction reducer) { - return scan(seed, reducer).last(); - } - - // Naming note, a plain scan would cause ambiguity with the value-seeded version - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable reduceWith(Supplier seedSupplier, BiFunction reducer) { - return scanWith(seedSupplier, reducer).last(); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable repeat() { - return repeat(Long.MAX_VALUE); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable repeat(long times) { - if (times < 0) { - throw new IllegalArgumentException("times >= 0 required but it was " + times); - } - if (times == 0) { - return empty(); - } - return create(new NbpOnSubscribeRepeat(this, times)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable repeatUntil(BooleanSupplier stop) { - Objects.requireNonNull(stop, "stop is null"); - return create(new NbpOnSubscribeRepeatUntil(this, stop)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable repeatWhen(final Function, ? extends NbpObservable> handler) { - Objects.requireNonNull(handler, "handler is null"); - - Function>>, NbpObservable> f = new Function>>, NbpObservable>() { - @Override - public NbpObservable apply(NbpObservable>> no) { - return handler.apply(no.map(new Function>, Object>() { - @Override - public Object apply(Try> v) { - return 0; - } - })); - } - } - ; - - return create(new NbpOnSubscribeRedo(this, f)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpConnectableObservable replay() { - return NbpOperatorReplay.createFrom(this); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable replay(Function, ? extends NbpObservable> selector) { - Objects.requireNonNull(selector, "selector is null"); - return NbpOperatorReplay.multicastSelector(new Supplier>() { - @Override - public NbpConnectableObservable get() { - return replay(); - } - }, selector); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable replay(Function, ? extends NbpObservable> selector, final int bufferSize) { - Objects.requireNonNull(selector, "selector is null"); - return NbpOperatorReplay.multicastSelector(new Supplier>() { - @Override - public NbpConnectableObservable get() { - return replay(bufferSize); - } - }, selector); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable replay(Function, ? extends NbpObservable> selector, int bufferSize, long time, TimeUnit unit) { - return replay(selector, bufferSize, time, unit, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable replay(Function, ? extends NbpObservable> selector, final int bufferSize, final long time, final TimeUnit unit, final Scheduler scheduler) { - if (bufferSize < 0) { - throw new IllegalArgumentException("bufferSize < 0"); - } - Objects.requireNonNull(selector, "selector is null"); - return NbpOperatorReplay.multicastSelector(new Supplier>() { - @Override - public NbpConnectableObservable get() { - return replay(bufferSize, time, unit, scheduler); - } - }, selector); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable replay(final Function, ? extends NbpObservable> selector, final int bufferSize, final Scheduler scheduler) { - return NbpOperatorReplay.multicastSelector(new Supplier>() { - @Override - public NbpConnectableObservable get() { - return replay(bufferSize); - } - }, - new Function, NbpObservable>() { - @Override - public NbpObservable apply(NbpObservable t) { - return selector.apply(t).observeOn(scheduler); - } - }); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable replay(Function, ? extends NbpObservable> selector, long time, TimeUnit unit) { - return replay(selector, time, unit, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable replay(Function, ? extends NbpObservable> selector, final long time, final TimeUnit unit, final Scheduler scheduler) { - Objects.requireNonNull(selector, "selector is null"); - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - return NbpOperatorReplay.multicastSelector(new Supplier>() { - @Override - public NbpConnectableObservable get() { - return replay(time, unit, scheduler); - } - }, selector); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable replay(final Function, ? extends NbpObservable> selector, final Scheduler scheduler) { - Objects.requireNonNull(selector, "selector is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - return NbpOperatorReplay.multicastSelector(new Supplier>() { - @Override - public NbpConnectableObservable get() { - return replay(); - } - }, - new Function, NbpObservable>() { - @Override - public NbpObservable apply(NbpObservable t) { - return selector.apply(t).observeOn(scheduler); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpConnectableObservable replay(final int bufferSize) { - return NbpOperatorReplay.create(this, bufferSize); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpConnectableObservable replay(int bufferSize, long time, TimeUnit unit) { - return replay(bufferSize, time, unit, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpConnectableObservable replay(final int bufferSize, final long time, final TimeUnit unit, final Scheduler scheduler) { - if (bufferSize < 0) { - throw new IllegalArgumentException("bufferSize < 0"); - } - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - return NbpOperatorReplay.create(this, time, unit, scheduler, bufferSize); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpConnectableObservable replay(final int bufferSize, final Scheduler scheduler) { - return NbpOperatorReplay.observeOn(replay(bufferSize), scheduler); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpConnectableObservable replay(long time, TimeUnit unit) { - return replay(time, unit, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpConnectableObservable replay(final long time, final TimeUnit unit, final Scheduler scheduler) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - return NbpOperatorReplay.create(this, time, unit, scheduler); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpConnectableObservable replay(final Scheduler scheduler) { - Objects.requireNonNull(scheduler, "scheduler is null"); - return NbpOperatorReplay.observeOn(replay(), scheduler); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable retry() { - return retry(Long.MAX_VALUE, Functions.alwaysTrue()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable retry(BiPredicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); - - return create(new NbpOnSubscribeRetryBiPredicate(this, predicate)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable retry(long times) { - return retry(times, Functions.alwaysTrue()); - } - - // Retries at most times or until the predicate returns false, whichever happens first - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable retry(long times, Predicate predicate) { - if (times < 0) { - throw new IllegalArgumentException("times >= 0 required but it was " + times); - } - Objects.requireNonNull(predicate, "predicate is null"); - - return create(new NbpOnSubscribeRetryPredicate(this, times, predicate)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable retry(Predicate predicate) { - return retry(Long.MAX_VALUE, predicate); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable retryUntil(final BooleanSupplier stop) { - Objects.requireNonNull(stop, "stop is null"); - return retry(Long.MAX_VALUE, new Predicate() { - @Override - public boolean test(Throwable e) { - return !stop.getAsBoolean(); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable retryWhen( - final Function, ? extends NbpObservable> handler) { - Objects.requireNonNull(handler, "handler is null"); - - Function>>, NbpObservable> f = new Function>>, NbpObservable>() { - @Override - public NbpObservable apply(NbpObservable>> no) { - return handler.apply(no - .takeWhile(new Predicate>>() { - @Override - public boolean test(Try> e) { - return e.hasError(); - } - }) - .map(new Function>, Throwable>() { - @Override - public Throwable apply(Try> t) { - return t.error(); - } - }) - ); - } - } - ; - - return create(new NbpOnSubscribeRedo(this, f)); - } - - // TODO decide if safe subscription or unsafe should be the default - @SchedulerSupport(SchedulerKind.NONE) - public final void safeSubscribe(NbpSubscriber s) { - Objects.requireNonNull(s, "s is null"); - if (s instanceof NbpSafeSubscriber) { - subscribe(s); - } else { - subscribe(new NbpSafeSubscriber(s)); - } - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable sample(long period, TimeUnit unit) { - return sample(period, unit, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable sample(long period, TimeUnit unit, Scheduler scheduler) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new NbpOperatorSampleTimed(period, unit, scheduler)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable sample(NbpObservable sampler) { - Objects.requireNonNull(sampler, "sampler is null"); - return lift(new NbpOperatorSampleWithObservable(sampler)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable scan(BiFunction accumulator) { - Objects.requireNonNull(accumulator, "accumulator is null"); - return lift(new NbpOperatorScan(accumulator)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable scan(final R seed, BiFunction accumulator) { - Objects.requireNonNull(seed, "seed is null"); - return scanWith(new Supplier() { - @Override - public R get() { - return seed; - } - }, accumulator); - } - - // Naming note, a plain scan would cause ambiguity with the value-seeded version - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable scanWith(Supplier seedSupplier, BiFunction accumulator) { - Objects.requireNonNull(seedSupplier, "seedSupplier is null"); - Objects.requireNonNull(accumulator, "accumulator is null"); - return lift(new NbpOperatorScanSeed(seedSupplier, accumulator)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable serialize() { - return lift(new NbpOperator() { - @Override - public NbpSubscriber apply(NbpSubscriber s) { - return new NbpSerializedSubscriber(s); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable share() { - return publish().refCount(); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable single() { - return lift(NbpOperatorSingle.instanceNoDefault()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable single(T defaultValue) { - Objects.requireNonNull(defaultValue, "defaultValue is null"); - return lift(new NbpOperatorSingle(defaultValue)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable skip(long n) { -// if (n < 0) { -// throw new IllegalArgumentException("n >= 0 required but it was " + n); -// } else - // FIXME negative skip allowed?! - if (n <= 0) { - return this; - } - return lift(new NbpOperatorSkip(n)); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable skip(long time, TimeUnit unit, Scheduler scheduler) { - // TODO consider inlining this behavior - return skipUntil(timer(time, unit, scheduler)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable skipLast(int n) { - if (n < 0) { - throw new IndexOutOfBoundsException("n >= 0 required but it was " + n); - } else - if (n == 0) { - return this; - } - return lift(new NbpOperatorSkipLast(n)); - } - - @SchedulerSupport(SchedulerKind.TRAMPOLINE) - public final NbpObservable skipLast(long time, TimeUnit unit) { - return skipLast(time, unit, Schedulers.trampoline(), false, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.TRAMPOLINE) - public final NbpObservable skipLast(long time, TimeUnit unit, boolean delayError) { - return skipLast(time, unit, Schedulers.trampoline(), delayError, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable skipLast(long time, TimeUnit unit, Scheduler scheduler) { - return skipLast(time, unit, scheduler, false, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable skipLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError) { - return skipLast(time, unit, scheduler, delayError, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable skipLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - validateBufferSize(bufferSize); - // the internal buffer holds pairs of (timestamp, value) so double the default buffer size - int s = bufferSize << 1; - return lift(new NbpOperatorSkipLastTimed(time, unit, scheduler, s, delayError)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable skipUntil(NbpObservable other) { - Objects.requireNonNull(other, "other is null"); - return lift(new NbpOperatorSkipUntil(other)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable skipWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); - return lift(new NbpOperatorSkipWhile(predicate)); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable startWith(Iterable values) { - return concatArray(fromIterable(values), this); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable startWith(NbpObservable other) { - Objects.requireNonNull(other, "other is null"); - return concatArray(other, this); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable startWith(T value) { - Objects.requireNonNull(value, "value is null"); - return concatArray(just(value), this); - } - - @SuppressWarnings("unchecked") - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable startWithArray(T... values) { - NbpObservable fromArray = fromArray(values); - if (fromArray == empty()) { - return this; - } - return concatArray(fromArray, this); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final Disposable subscribe() { - return subscribe(Functions.emptyConsumer(), RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), Functions.emptyConsumer()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final Disposable subscribe(Consumer onNext) { - return subscribe(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), Functions.emptyConsumer()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final Disposable subscribe(Consumer onNext, Consumer onError) { - return subscribe(onNext, onError, Functions.emptyRunnable(), Functions.emptyConsumer()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final Disposable subscribe(Consumer onNext, Consumer onError, - Runnable onComplete) { - return subscribe(onNext, onError, onComplete, Functions.emptyConsumer()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final Disposable subscribe(Consumer onNext, Consumer onError, - Runnable onComplete, Consumer onSubscribe) { - Objects.requireNonNull(onNext, "onNext is null"); - Objects.requireNonNull(onError, "onError is null"); - Objects.requireNonNull(onComplete, "onComplete is null"); - Objects.requireNonNull(onSubscribe, "onSubscribe is null"); - - NbpLambdaSubscriber ls = new NbpLambdaSubscriber(onNext, onError, onComplete, onSubscribe); - - unsafeSubscribe(ls); - - return ls; - } - - public final void subscribe(NbpSubscriber subscriber) { - Objects.requireNonNull(subscriber, "subscriber is null"); - onSubscribe.accept(subscriber); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable subscribeOn(Scheduler scheduler) { - Objects.requireNonNull(scheduler, "scheduler is null"); - return create(new NbpOnSubscribeSubscribeOn(this, scheduler)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable switchIfEmpty(NbpObservable other) { - Objects.requireNonNull(other, "other is null"); - return lift(new NbpOperatorSwitchIfEmpty(other)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable switchMap(Function> mapper) { - return switchMap(mapper, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable switchMap(Function> mapper, int bufferSize) { - Objects.requireNonNull(mapper, "mapper is null"); - validateBufferSize(bufferSize); - return lift(new NbpOperatorSwitchMap(mapper, bufferSize)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable take(long n) { - if (n < 0) { - throw new IllegalArgumentException("n >= required but it was " + n); - } else - if (n == 0) { - // FIXME may want to subscribe an cancel immediately -// return lift(s -> CancelledSubscriber.INSTANCE); - return empty(); - } - return lift(new NbpOperatorTake(n)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable take(long time, TimeUnit unit, Scheduler scheduler) { - // TODO consider inlining this behavior - return takeUntil(timer(time, unit, scheduler)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable takeFirst(Predicate predicate) { - return filter(predicate).take(1); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable takeLast(int n) { - if (n < 0) { - throw new IndexOutOfBoundsException("n >= required but it was " + n); - } else - if (n == 0) { - return ignoreElements(); - } else - if (n == 1) { - return lift(NbpOperatorTakeLastOne.instance()); - } - return lift(new NbpOperatorTakeLast(n)); - } - - @SchedulerSupport(SchedulerKind.TRAMPOLINE) - public final NbpObservable takeLast(long count, long time, TimeUnit unit) { - return takeLast(count, time, unit, Schedulers.trampoline(), false, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable takeLast(long count, long time, TimeUnit unit, Scheduler scheduler) { - return takeLast(count, time, unit, scheduler, false, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable takeLast(long count, long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - validateBufferSize(bufferSize); - if (count < 0) { - throw new IndexOutOfBoundsException("count >= 0 required but it was " + count); - } - return lift(new NbpOperatorTakeLastTimed(count, time, unit, scheduler, bufferSize, delayError)); - } - - @SchedulerSupport(SchedulerKind.TRAMPOLINE) - public final NbpObservable takeLast(long time, TimeUnit unit) { - return takeLast(time, unit, Schedulers.trampoline(), false, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.TRAMPOLINE) - public final NbpObservable takeLast(long time, TimeUnit unit, boolean delayError) { - return takeLast(time, unit, Schedulers.trampoline(), delayError, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable takeLast(long time, TimeUnit unit, Scheduler scheduler) { - return takeLast(time, unit, scheduler, false, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable takeLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError) { - return takeLast(time, unit, scheduler, delayError, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable takeLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { - return takeLast(Long.MAX_VALUE, time, unit, scheduler, delayError, bufferSize); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> takeLastBuffer(int count) { - return takeLast(count).toList(); - } - - @SchedulerSupport(SchedulerKind.TRAMPOLINE) - public final NbpObservable> takeLastBuffer(int count, long time, TimeUnit unit) { - return takeLast(count, time, unit).toList(); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> takeLastBuffer(int count, long time, TimeUnit unit, Scheduler scheduler) { - return takeLast(count, time, unit, scheduler).toList(); - } - - @SchedulerSupport(SchedulerKind.TRAMPOLINE) - public final NbpObservable> takeLastBuffer(long time, TimeUnit unit) { - return takeLast(time, unit).toList(); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> takeLastBuffer(long time, TimeUnit unit, Scheduler scheduler) { - return takeLast(time, unit, scheduler).toList(); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable takeUntil(NbpObservable other) { - Objects.requireNonNull(other, "other is null"); - return lift(new NbpOperatorTakeUntil(other)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable takeUntil(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); - return lift(new NbpOperatorTakeUntilPredicate(predicate)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable takeWhile(Predicate predicate) { - Objects.requireNonNull(predicate, "predicate is null"); - return lift(new NbpOperatorTakeWhile(predicate)); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable throttleFirst(long windowDuration, TimeUnit unit) { - return throttleFirst(windowDuration, unit, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable throttleFirst(long skipDuration, TimeUnit unit, Scheduler scheduler) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new NbpOperatorThrottleFirstTimed(skipDuration, unit, scheduler)); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable throttleLast(long intervalDuration, TimeUnit unit) { - return sample(intervalDuration, unit); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable throttleLast(long intervalDuration, TimeUnit unit, Scheduler scheduler) { - return sample(intervalDuration, unit, scheduler); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable throttleWithTimeout(long timeout, TimeUnit unit) { - return debounce(timeout, unit); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable throttleWithTimeout(long timeout, TimeUnit unit, Scheduler scheduler) { - return debounce(timeout, unit, scheduler); - } - - @SchedulerSupport(SchedulerKind.TRAMPOLINE) - public final NbpObservable> timeInterval() { - return timeInterval(TimeUnit.MILLISECONDS, Schedulers.trampoline()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> timeInterval(Scheduler scheduler) { - return timeInterval(TimeUnit.MILLISECONDS, scheduler); - } - - @SchedulerSupport(SchedulerKind.TRAMPOLINE) - public final NbpObservable> timeInterval(TimeUnit unit) { - return timeInterval(unit, Schedulers.trampoline()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> timeInterval(TimeUnit unit, Scheduler scheduler) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new NbpOperatorTimeInterval(unit, scheduler)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable timeout(Function> timeoutSelector) { - return timeout0(null, timeoutSelector, null); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable timeout(Function> timeoutSelector, NbpObservable other) { - Objects.requireNonNull(other, "other is null"); - return timeout0(null, timeoutSelector, other); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable timeout(long timeout, TimeUnit timeUnit) { - return timeout0(timeout, timeUnit, null, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable timeout(long timeout, TimeUnit timeUnit, NbpObservable other) { - Objects.requireNonNull(other, "other is null"); - return timeout0(timeout, timeUnit, other, Schedulers.computation()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable timeout(long timeout, TimeUnit timeUnit, NbpObservable other, Scheduler scheduler) { - Objects.requireNonNull(other, "other is null"); - return timeout0(timeout, timeUnit, other, scheduler); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable timeout(long timeout, TimeUnit timeUnit, Scheduler scheduler) { - return timeout0(timeout, timeUnit, null, scheduler); - } - - public final NbpObservable timeout(Supplier> firstTimeoutSelector, - Function> timeoutSelector) { - Objects.requireNonNull(firstTimeoutSelector, "firstTimeoutSelector is null"); - return timeout0(firstTimeoutSelector, timeoutSelector, null); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable timeout( - Supplier> firstTimeoutSelector, - Function> timeoutSelector, - NbpObservable other) { - Objects.requireNonNull(firstTimeoutSelector, "firstTimeoutSelector is null"); - Objects.requireNonNull(other, "other is null"); - return timeout0(firstTimeoutSelector, timeoutSelector, other); - } - - private NbpObservable timeout0(long timeout, TimeUnit timeUnit, NbpObservable other, - Scheduler scheduler) { - Objects.requireNonNull(timeUnit, "timeUnit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new NbpOperatorTimeoutTimed(timeout, timeUnit, scheduler, other)); - } - - private NbpObservable timeout0( - Supplier> firstTimeoutSelector, - Function> timeoutSelector, - NbpObservable other) { - Objects.requireNonNull(timeoutSelector, "timeoutSelector is null"); - return lift(new NbpOperatorTimeout(firstTimeoutSelector, timeoutSelector, other)); - } - - @SchedulerSupport(SchedulerKind.TRAMPOLINE) - public final NbpObservable> timestamp() { - return timestamp(TimeUnit.MILLISECONDS, Schedulers.trampoline()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> timestamp(Scheduler scheduler) { - return timestamp(TimeUnit.MILLISECONDS, scheduler); - } - - @SchedulerSupport(SchedulerKind.TRAMPOLINE) - public final NbpObservable> timestamp(TimeUnit unit) { - return timestamp(unit, Schedulers.trampoline()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> timestamp(final TimeUnit unit, final Scheduler scheduler) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); - return map(new Function>() { - @Override - public Timed apply(T v) { - return new Timed(v, scheduler.now(unit), unit); - } - }); - } - - public final R to(Function, R> convert) { - return convert.apply(this); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpBlockingObservable toBlocking() { - return NbpBlockingObservable.from(this); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> toList() { - return lift(NbpOperatorToList.defaultInstance()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> toList(final int capacityHint) { - if (capacityHint <= 0) { - throw new IllegalArgumentException("capacityHint > 0 required but it was " + capacityHint); - } - return lift(new NbpOperatorToList>(new Supplier>() { - @Override - public List get() { - return new ArrayList(capacityHint); - } - })); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final > NbpObservable toList(Supplier collectionSupplier) { - Objects.requireNonNull(collectionSupplier, "collectionSupplier is null"); - return lift(new NbpOperatorToList(collectionSupplier)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> toMap(final Function keySelector) { - return collect(new Supplier>() { - @Override - public Map get() { - return new HashMap(); - } - }, new BiConsumer, T>() { - @Override - public void accept(Map m, T t) { - K key = keySelector.apply(t); - m.put(key, t); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> toMap( - final Function keySelector, - final Function valueSelector) { - Objects.requireNonNull(keySelector, "keySelector is null"); - Objects.requireNonNull(valueSelector, "valueSelector is null"); - return collect(new Supplier>() { - @Override - public Map get() { - return new HashMap(); - } - }, new BiConsumer, T>() { - @Override - public void accept(Map m, T t) { - K key = keySelector.apply(t); - V value = valueSelector.apply(t); - m.put(key, value); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> toMap( - final Function keySelector, - final Function valueSelector, - Supplier> mapSupplier) { - return collect(mapSupplier, new BiConsumer, T>() { - @Override - public void accept(Map m, T t) { - K key = keySelector.apply(t); - V value = valueSelector.apply(t); - m.put(key, value); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable>> toMultimap(Function keySelector) { - @SuppressWarnings({ "rawtypes", "unchecked" }) - Function valueSelector = (Function)Functions.identity(); - Supplier>> mapSupplier = new Supplier>>() { - @Override - public Map> get() { - return new HashMap>(); - } - }; - Function> collectionFactory = new Function>() { - @Override - public Collection apply(K k) { - return new ArrayList(); - } - }; - return toMultimap(keySelector, valueSelector, mapSupplier, collectionFactory); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable>> toMultimap(Function keySelector, Function valueSelector) { - Supplier>> mapSupplier = new Supplier>>() { - @Override - public Map> get() { - return new HashMap>(); - } - }; - Function> collectionFactory = new Function>() { - @Override - public Collection apply(K k) { - return new ArrayList(); - } - }; - return toMultimap(keySelector, valueSelector, mapSupplier, collectionFactory); - } - - @SchedulerSupport(SchedulerKind.NONE) - @SuppressWarnings("unchecked") - public final NbpObservable>> toMultimap( - final Function keySelector, - final Function valueSelector, - final Supplier>> mapSupplier, - final Function> collectionFactory) { - Objects.requireNonNull(keySelector, "keySelector is null"); - Objects.requireNonNull(valueSelector, "valueSelector is null"); - Objects.requireNonNull(mapSupplier, "mapSupplier is null"); - Objects.requireNonNull(collectionFactory, "collectionFactory is null"); - return collect(mapSupplier, new BiConsumer>, T>() { - @Override - public void accept(Map> m, T t) { - K key = keySelector.apply(t); - - Collection coll = m.get(key); - if (coll == null) { - coll = (Collection)collectionFactory.apply(key); - m.put(key, coll); - } - - V value = valueSelector.apply(t); - - coll.add(value); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable>> toMultimap( - Function keySelector, - Function valueSelector, - Supplier>> mapSupplier - ) { - return toMultimap(keySelector, valueSelector, mapSupplier, new Function>() { - @Override - public Collection apply(K k) { - return new ArrayList(); - } - }); - } - - public final Observable toObservable(BackpressureStrategy strategy) { - Observable o = Observable.create(new Publisher() { - @Override - public void subscribe(final Subscriber s) { - NbpObservable.this.subscribe(new NbpSubscriber() { - - @Override - public void onComplete() { - s.onComplete(); - } - - @Override - public void onError(Throwable e) { - s.onError(e); - } - - @Override - public void onNext(T value) { - s.onNext(value); - } - - @Override - public void onSubscribe(final Disposable d) { - s.onSubscribe(new Subscription() { - - @Override - public void cancel() { - d.dispose(); - } - - @Override - public void request(long n) { - // no backpressure so nothing we can do about this - } - - }); - } - - }); - } - }); - - switch (strategy) { - case BUFFER: - return o.onBackpressureBuffer(); - case DROP: - return o.onBackpressureDrop(); - case LATEST: - return o.onBackpressureLatest(); - default: - return o; - } - } - - @SchedulerSupport(SchedulerKind.NONE) - public final Single toSingle() { - return Single.create(new SingleOnSubscribe() { - @Override - public void accept(final SingleSubscriber s) { - NbpObservable.this.subscribe(new NbpSubscriber() { - T last; - @Override - public void onSubscribe(Disposable d) { - s.onSubscribe(d); - } - @Override - public void onNext(T value) { - last = value; - } - @Override - public void onError(Throwable e) { - s.onError(e); - } - @Override - public void onComplete() { - T v = last; - last = null; - if (v != null) { - s.onSuccess(v); - } else { - s.onError(new NoSuchElementException()); - } - } - - - }); - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> toSortedList() { - return toSortedList(Functions.naturalOrder()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> toSortedList(final Comparator comparator) { - Objects.requireNonNull(comparator, "comparator is null"); - return toList().map(new Function, List>() { - @Override - public List apply(List v) { - Collections.sort(v, comparator); - return v; - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> toSortedList(final Comparator comparator, int capacityHint) { - Objects.requireNonNull(comparator, "comparator is null"); - return toList(capacityHint).map(new Function, List>() { - @Override - public List apply(List v) { - Collections.sort(v, comparator); - return v; - } - }); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> toSortedList(int capacityHint) { - return toSortedList(Functions.naturalOrder(), capacityHint); - } - - @SchedulerSupport(SchedulerKind.NONE) - // TODO decide if safe subscription or unsafe should be the default - public final void unsafeSubscribe(NbpSubscriber s) { - Objects.requireNonNull(s, "s is null"); - subscribe(s); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable unsubscribeOn(Scheduler scheduler) { - Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new NbpOperatorUnsubscribeOn(scheduler)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> window(long count) { - return window(count, count, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> window(long count, long skip) { - return window(count, skip, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> window(long count, long skip, int bufferSize) { - if (skip <= 0) { - throw new IllegalArgumentException("skip > 0 required but it was " + skip); - } - if (count <= 0) { - throw new IllegalArgumentException("count > 0 required but it was " + count); - } - validateBufferSize(bufferSize); - return lift(new NbpOperatorWindow(count, skip, bufferSize)); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable> window(long timespan, long timeskip, TimeUnit unit) { - return window(timespan, timeskip, unit, Schedulers.computation(), bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> window(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler) { - return window(timespan, timeskip, unit, scheduler, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> window(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler, int bufferSize) { - validateBufferSize(bufferSize); - Objects.requireNonNull(scheduler, "scheduler is null"); - Objects.requireNonNull(unit, "unit is null"); - return lift(new NbpOperatorWindowTimed(timespan, timeskip, unit, scheduler, Long.MAX_VALUE, bufferSize, false)); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable> window(long timespan, TimeUnit unit) { - return window(timespan, unit, Schedulers.computation(), Long.MAX_VALUE, false); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable> window(long timespan, TimeUnit unit, - long count) { - return window(timespan, unit, Schedulers.computation(), count, false); - } - - @SchedulerSupport(SchedulerKind.COMPUTATION) - public final NbpObservable> window(long timespan, TimeUnit unit, - long count, boolean restart) { - return window(timespan, unit, Schedulers.computation(), count, restart); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> window(long timespan, TimeUnit unit, - Scheduler scheduler) { - return window(timespan, unit, scheduler, Long.MAX_VALUE, false); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> window(long timespan, TimeUnit unit, - Scheduler scheduler, long count) { - return window(timespan, unit, scheduler, count, false); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> window(long timespan, TimeUnit unit, - Scheduler scheduler, long count, boolean restart) { - return window(timespan, unit, scheduler, count, restart, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.CUSTOM) - public final NbpObservable> window( - long timespan, TimeUnit unit, Scheduler scheduler, - long count, boolean restart, int bufferSize) { - validateBufferSize(bufferSize); - Objects.requireNonNull(scheduler, "scheduler is null"); - Objects.requireNonNull(unit, "unit is null"); - if (count <= 0) { - throw new IllegalArgumentException("count > 0 required but it was " + count); - } - return lift(new NbpOperatorWindowTimed(timespan, timespan, unit, scheduler, count, bufferSize, restart)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> window(NbpObservable boundary) { - return window(boundary, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> window(NbpObservable boundary, int bufferSize) { - Objects.requireNonNull(boundary, "boundary is null"); - return lift(new NbpOperatorWindowBoundary(boundary, bufferSize)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> window( - NbpObservable windowOpen, - Function> windowClose) { - return window(windowOpen, windowClose, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> window( - NbpObservable windowOpen, - Function> windowClose, int bufferSize) { - Objects.requireNonNull(windowOpen, "windowOpen is null"); - Objects.requireNonNull(windowClose, "windowClose is null"); - return lift(new NbpOperatorWindowBoundarySelector(windowOpen, windowClose, bufferSize)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> window(Supplier> boundary) { - return window(boundary, bufferSize()); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable> window(Supplier> boundary, int bufferSize) { - Objects.requireNonNull(boundary, "boundary is null"); - return lift(new NbpOperatorWindowBoundarySupplier(boundary, bufferSize)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable withLatestFrom(NbpObservable other, BiFunction combiner) { - Objects.requireNonNull(other, "other is null"); - Objects.requireNonNull(combiner, "combiner is null"); - - return lift(new NbpOperatorWithLatestFrom(combiner, other)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable zipWith(Iterable other, BiFunction zipper) { - Objects.requireNonNull(other, "other is null"); - Objects.requireNonNull(zipper, "zipper is null"); - return create(new NbpOnSubscribeZipIterable(this, other, zipper)); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable zipWith(NbpObservable other, BiFunction zipper) { - Objects.requireNonNull(other, "other is null"); - return zip(this, other, zipper); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable zipWith(NbpObservable other, BiFunction zipper, boolean delayError) { - return zip(this, other, zipper, delayError); - } - - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable zipWith(NbpObservable other, BiFunction zipper, boolean delayError, int bufferSize) { - return zip(this, other, zipper, delayError, bufferSize); - } - - - } \ No newline at end of file diff --git a/src/main/java/io/reactivex/Observable.java b/src/main/java/io/reactivex/Observable.java index dee64a7c76..55f90bf44c 100644 --- a/src/main/java/io/reactivex/Observable.java +++ b/src/main/java/io/reactivex/Observable.java @@ -10,8 +10,8 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex; import java.util.*; import java.util.concurrent.*; @@ -19,125 +19,123 @@ import org.reactivestreams.*; +import io.reactivex.Single.*; import io.reactivex.annotations.*; -import io.reactivex.disposables.Disposable; +import io.reactivex.disposables.*; import io.reactivex.functions.*; -import io.reactivex.internal.functions.*; +import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.internal.functions.Functions; import io.reactivex.internal.functions.Objects; -import io.reactivex.internal.operators.*; -import io.reactivex.internal.subscribers.*; -import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.internal.operators.observable.*; +import io.reactivex.internal.subscribers.observable.*; +import io.reactivex.internal.util.Exceptions; import io.reactivex.observables.*; +import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; -import io.reactivex.subscribers.*; -public class Observable implements Publisher { - /** - * Interface to map/wrap a downstream subscriber to an upstream subscriber. - * - * @param the value type of the downstream - * @param the value type of the upstream - */ - public interface Operator extends Function, Subscriber> { +/** + * Observable for delivering a sequence of values without backpressure. + * @param + */ +public class Observable { + public interface NbpOnSubscribe extends Consumer> { + } - /** - * Interface to compose observables. - * - * @param the upstream value type - * @param the downstream value type - */ - public interface Transformer extends Function, Publisher> { + public interface NbpOperator extends Function, Observer> { } - - /** The default buffer size. */ - static final int BUFFER_SIZE; - static { - BUFFER_SIZE = Math.max(16, Integer.getInteger("rx2.buffer-size", 128)); + + public interface NbpTransformer extends Function, Observable> { + } - + /** An empty observable instance as there is no need to instantiate this more than once. */ - static final Observable EMPTY = create(PublisherEmptySource.INSTANCE); - - /** A never observable instance as there is no need to instantiate this more than once. */ - static final Observable NEVER = create(new Publisher() { + static final Observable EMPTY = create(new NbpOnSubscribe() { @Override - public void subscribe(Subscriber s) { - s.onSubscribe(EmptySubscription.INSTANCE); + public void accept(Observer s) { + s.onSubscribe(EmptyDisposable.INSTANCE); + s.onComplete(); } }); - - public static Observable amb(Iterable> sources) { + + /** A never NbpObservable instance as there is no need to instantiate this more than once. */ + static final Observable NEVER = create(new NbpOnSubscribe() { + @Override + public void accept(Observer s) { + s.onSubscribe(EmptyDisposable.INSTANCE); + } + }); + + static final Object OBJECT = new Object(); + + public static Observable amb(Iterable> sources) { Objects.requireNonNull(sources, "sources is null"); - return create(new PublisherAmb(null, sources)); + return create(new NbpOnSubscribeAmb(null, sources)); } - - @BackpressureSupport(BackpressureKind.FULL) + + @SuppressWarnings("unchecked") @SchedulerSupport(SchedulerKind.NONE) - public static Observable amb(Publisher... sources) { + public static Observable amb(Observable... sources) { Objects.requireNonNull(sources, "sources is null"); int len = sources.length; if (len == 0) { return empty(); } else if (len == 1) { - return fromPublisher(sources[0]); + return (Observable)sources[0]; } - return create(new PublisherAmb(sources, null)); + return create(new NbpOnSubscribeAmb(sources, null)); } - - public static int bufferSize() { - return BUFFER_SIZE; + + /** + * Returns the default 'island' size or capacity-increment hint for unbounded buffers. + * @return + */ + static int bufferSize() { + return Flowable.bufferSize(); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) - public static Observable combineLatest(Function combiner, boolean delayError, int bufferSize, Publisher... sources) { + public static Observable combineLatest(Function combiner, boolean delayError, int bufferSize, Observable... sources) { return combineLatest(sources, combiner, delayError, bufferSize); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable combineLatest(Iterable> sources, Function combiner) { + public static Observable combineLatest(Iterable> sources, Function combiner) { return combineLatest(sources, combiner, false, bufferSize()); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) - public static Observable combineLatest(Iterable> sources, Function combiner, boolean delayError) { + public static Observable combineLatest(Iterable> sources, Function combiner, boolean delayError) { return combineLatest(sources, combiner, delayError, bufferSize()); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) - public static Observable combineLatest(Iterable> sources, Function combiner, boolean delayError, int bufferSize) { + public static Observable combineLatest(Iterable> sources, Function combiner, boolean delayError, int bufferSize) { Objects.requireNonNull(sources, "sources is null"); Objects.requireNonNull(combiner, "combiner is null"); validateBufferSize(bufferSize); // the queue holds a pair of values so we need to double the capacity int s = bufferSize << 1; - return create(new PublisherCombineLatest(null, sources, combiner, s, delayError)); + return create(new NbpOnSubscribeCombineLatest(null, sources, combiner, s, delayError)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable combineLatest(Publisher[] sources, Function combiner) { + public static Observable combineLatest(Observable[] sources, Function combiner) { return combineLatest(sources, combiner, false, bufferSize()); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) - public static Observable combineLatest(Publisher[] sources, Function combiner, boolean delayError) { + public static Observable combineLatest(Observable[] sources, Function combiner, boolean delayError) { return combineLatest(sources, combiner, delayError, bufferSize()); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) - public static Observable combineLatest(Publisher[] sources, Function combiner, boolean delayError, int bufferSize) { + public static Observable combineLatest(Observable[] sources, Function combiner, boolean delayError, int bufferSize) { validateBufferSize(bufferSize); Objects.requireNonNull(combiner, "combiner is null"); if (sources.length == 0) { @@ -145,221 +143,199 @@ public static Observable combineLatest(Publisher[] source } // the queue holds a pair of values so we need to double the capacity int s = bufferSize << 1; - return create(new PublisherCombineLatest(sources, null, combiner, s, delayError)); + return create(new NbpOnSubscribeCombineLatest(sources, null, combiner, s, delayError)); } - + @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable combineLatest( - Publisher p1, Publisher p2, + Observable p1, Observable p2, BiFunction combiner) { - Function f = Functions.toFunction(combiner); - return combineLatest(f, false, bufferSize(), p1, p2); + return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2); } - + @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable combineLatest( - Publisher p1, Publisher p2, - Publisher p3, + Observable p1, Observable p2, + Observable p3, Function3 combiner) { return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3); } - + @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable combineLatest( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4, + Observable p1, Observable p2, + Observable p3, Observable p4, Function4 combiner) { return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4); } - + @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable combineLatest( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4, - Publisher p5, + Observable p1, Observable p2, + Observable p3, Observable p4, + Observable p5, Function5 combiner) { return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5); } - + @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable combineLatest( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4, - Publisher p5, Publisher p6, + Observable p1, Observable p2, + Observable p3, Observable p4, + Observable p5, Observable p6, Function6 combiner) { return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5, p6); } - + @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable combineLatest( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4, - Publisher p5, Publisher p6, - Publisher p7, + Observable p1, Observable p2, + Observable p3, Observable p4, + Observable p5, Observable p6, + Observable p7, Function7 combiner) { return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable combineLatest( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4, - Publisher p5, Publisher p6, - Publisher p7, Publisher p8, + Observable p1, Observable p2, + Observable p3, Observable p4, + Observable p5, Observable p6, + Observable p7, Observable p8, Function8 combiner) { return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7, p8); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable combineLatest( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4, - Publisher p5, Publisher p6, - Publisher p7, Publisher p8, - Publisher p9, + Observable p1, Observable p2, + Observable p3, Observable p4, + Observable p5, Observable p6, + Observable p7, Observable p8, + Observable p9, Function9 combiner) { return combineLatest(Functions.toFunction(combiner), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7, p8, p9); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable concat(int prefetch, Iterable> sources) { + public static Observable concat(int prefetch, Iterable> sources) { Objects.requireNonNull(sources, "sources is null"); return fromIterable(sources).concatMap((Function)Functions.identity(), prefetch); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable concat(Iterable> sources) { + public static Observable concat(Iterable> sources) { Objects.requireNonNull(sources, "sources is null"); return fromIterable(sources).concatMap((Function)Functions.identity()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static final Observable concat(Publisher> sources) { + public static final Observable concat(Observable> sources) { return concat(sources, bufferSize()); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static final Observable concat(Publisher> sources, int bufferSize) { - return fromPublisher(sources).concatMap((Function)Functions.identity()); + public static final Observable concat(Observable> sources, int bufferSize) { + return sources.concatMap((Function)Functions.identity()); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable concat(Publisher p1, Publisher p2) { + public static Observable concat(Observable p1, Observable p2) { return concatArray(p1, p2); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable concat( - Publisher p1, Publisher p2, - Publisher p3) { + Observable p1, Observable p2, + Observable p3) { return concatArray(p1, p2, p3); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable concat( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4) { + Observable p1, Observable p2, + Observable p3, Observable p4) { return concatArray(p1, p2, p3, p4); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable concat( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4, - Publisher p5 + Observable p1, Observable p2, + Observable p3, Observable p4, + Observable p5 ) { return concatArray(p1, p2, p3, p4, p5); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable concat( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4, - Publisher p5, Publisher p6 + Observable p1, Observable p2, + Observable p3, Observable p4, + Observable p5, Observable p6 ) { return concatArray(p1, p2, p3, p4, p5, p6); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable concat( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4, - Publisher p5, Publisher p6, - Publisher p7 + Observable p1, Observable p2, + Observable p3, Observable p4, + Observable p5, Observable p6, + Observable p7 ) { return concatArray(p1, p2, p3, p4, p5, p6, p7); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable concat( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4, - Publisher p5, Publisher p6, - Publisher p7, Publisher p8 + Observable p1, Observable p2, + Observable p3, Observable p4, + Observable p5, Observable p6, + Observable p7, Observable p8 ) { return concatArray(p1, p2, p3, p4, p5, p6, p7, p8); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable concat( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4, - Publisher p5, Publisher p6, - Publisher p7, Publisher p8, - Publisher p9 + Observable p1, Observable p2, + Observable p3, Observable p4, + Observable p5, Observable p6, + Observable p7, Observable p8, + Observable p9 ) { return concatArray(p1, p2, p3, p4, p5, p6, p7, p8, p9); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable concatArray(int prefetch, Publisher... sources) { + public static Observable concatArray(int prefetch, Observable... sources) { Objects.requireNonNull(sources, "sources is null"); return fromArray(sources).concatMap((Function)Functions.identity(), prefetch); } /** - * Concatenates a variable number of Observable sources. + * Concatenates a variable number of NbpObservable sources. *

* Note: named this way because of overload conflict with concat(NbpObservable<NbpObservable>) * @param sources the array of sources @@ -368,48 +344,41 @@ public static Observable concatArray(int prefetch, Publisher * @throws NullPointerException if sources is null */ @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable concatArray(Publisher... sources) { + public static Observable concatArray(Observable... sources) { if (sources.length == 0) { return empty(); } else if (sources.length == 1) { - return fromPublisher(sources[0]); + return (Observable)sources[0]; } return fromArray(sources).concatMap((Function)Functions.identity()); } - @BackpressureSupport(BackpressureKind.NONE) - @SchedulerSupport(SchedulerKind.NONE) - public static Observable create(Publisher onSubscribe) { + public static Observable create(NbpOnSubscribe onSubscribe) { Objects.requireNonNull(onSubscribe, "onSubscribe is null"); - onSubscribe = RxJavaPlugins.onCreate(onSubscribe); + // TODO plugin wrapper return new Observable(onSubscribe); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) - public static Observable defer(Supplier> supplier) { + public static Observable defer(Supplier> supplier) { Objects.requireNonNull(supplier, "supplier is null"); - return create(new PublisherDefer(supplier)); + return create(new NbpOnSubscribeDefer(supplier)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) @SuppressWarnings("unchecked") public static Observable empty() { return (Observable)EMPTY; } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) public static Observable error(Supplier errorSupplier) { Objects.requireNonNull(errorSupplier, "errorSupplier is null"); - return create(new PublisherErrorSource(errorSupplier)); + return create(new NbpOnSubscribeErrorSource(errorSupplier)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) public static Observable error(final Throwable e) { Objects.requireNonNull(e, "e is null"); @@ -421,25 +390,23 @@ public Throwable get() { }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable fromArray(T... values) { Objects.requireNonNull(values, "values is null"); if (values.length == 0) { return empty(); } else - if (values.length == 1) { - return just(values[0]); - } - return create(new PublisherArraySource(values)); + if (values.length == 1) { + return just(values[0]); + } + return create(new NbpOnSubscribeArraySource(values)); } // TODO match naming with RxJava 1.x - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable fromCallable(Callable supplier) { Objects.requireNonNull(supplier, "supplier is null"); - return create(new PublisherScalarAsyncSource(supplier)); + return create(new NbpOnSubscribeScalarAsyncSource(supplier)); } /* @@ -447,25 +414,20 @@ public static Observable fromCallable(Callable supplier) { * if necessary, one can use composition to achieve it: * futureObservable.doOnCancel(() -> future.cancel(true)); */ - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable fromFuture(Future future) { Objects.requireNonNull(future, "future is null"); - Observable o = create(new PublisherFutureSource(future, 0L, null)); - - return o; + return create(new NbpOnSubscribeFutureSource(future, 0L, null)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable fromFuture(Future future, long timeout, TimeUnit unit) { Objects.requireNonNull(future, "future is null"); Objects.requireNonNull(unit, "unit is null"); - Observable o = create(new PublisherFutureSource(future, timeout, unit)); + Observable o = create(new NbpOnSubscribeFutureSource(future, timeout, unit)); return o; } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public static Observable fromFuture(Future future, long timeout, TimeUnit unit, Scheduler scheduler) { Objects.requireNonNull(scheduler, "scheduler is null"); @@ -473,7 +435,6 @@ public static Observable fromFuture(Future future, long time return o.subscribeOn(scheduler); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.IO) public static Observable fromFuture(Future future, Scheduler scheduler) { Objects.requireNonNull(scheduler, "scheduler is null"); @@ -481,92 +442,102 @@ public static Observable fromFuture(Future future, Scheduler return o.subscribeOn(Schedulers.io()); } - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) public static Observable fromIterable(Iterable source) { Objects.requireNonNull(source, "source is null"); - return create(new PublisherIterableSource(source)); + return create(new NbpOnSubscribeIterableSource(source)); } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) - @SchedulerSupport(SchedulerKind.NONE) - @SuppressWarnings("unchecked") + public static Observable fromPublisher(final Publisher publisher) { - if (publisher instanceof Observable) { - return (Observable)publisher; - } Objects.requireNonNull(publisher, "publisher is null"); - - return create(new Publisher() { + return create(new NbpOnSubscribe() { @Override - public void subscribe(Subscriber s) { - publisher.subscribe(s); + public void accept(final Observer s) { + publisher.subscribe(new Subscriber() { + + @Override + public void onComplete() { + s.onComplete(); + } + + @Override + public void onError(Throwable t) { + s.onError(t); + } + + @Override + public void onNext(T t) { + s.onNext(t); + } + + @Override + public void onSubscribe(Subscription inner) { + s.onSubscribe(Disposables.from(inner)); + inner.request(Long.MAX_VALUE); + } + + }); } }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable generate(final Consumer> generator) { - Objects.requireNonNull(generator, "generator is null"); - return generate(Functions.nullSupplier(), - new BiFunction, Object>() { + public static Observable generate(final Consumer> generator) { + Objects.requireNonNull(generator, "generator is null"); + return generate(Functions.nullSupplier(), + new BiFunction, Object>() { @Override - public Object apply(Object s, Subscriber o) { + public Object apply(Object s, Observer o) { generator.accept(o); return s; } - }, Functions.emptyConsumer()); + }, Functions.emptyConsumer()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable generate(Supplier initialState, final BiConsumer> generator) { - Objects.requireNonNull(generator, "generator is null"); - return generate(initialState, new BiFunction, S>() { + public static Observable generate(Supplier initialState, final BiConsumer> generator) { + Objects.requireNonNull(generator, "generator is null"); + return generate(initialState, new BiFunction, S>() { @Override - public S apply(S s, Subscriber o) { + public S apply(S s, Observer o) { generator.accept(s, o); return s; } }, Functions.emptyConsumer()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable generate(Supplier initialState, final BiConsumer> generator, Consumer disposeState) { - Objects.requireNonNull(generator, "generator is null"); - return generate(initialState, new BiFunction, S>() { + public static Observable generate( + final Supplier initialState, + final BiConsumer> generator, + Consumer disposeState) { + Objects.requireNonNull(generator, "generator is null"); + return generate(initialState, new BiFunction, S>() { @Override - public S apply(S s, Subscriber o) { + public S apply(S s, Observer o) { generator.accept(s, o); return s; } }, disposeState); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable generate(Supplier initialState, BiFunction, S> generator) { + public static Observable generate(Supplier initialState, BiFunction, S> generator) { return generate(initialState, generator, Functions.emptyConsumer()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable generate(Supplier initialState, BiFunction, S> generator, Consumer disposeState) { + public static Observable generate(Supplier initialState, BiFunction, S> generator, Consumer disposeState) { Objects.requireNonNull(initialState, "initialState is null"); - Objects.requireNonNull(generator, "generator is null"); - Objects.requireNonNull(disposeState, "disposeState is null"); - return create(new PublisherGenerate(initialState, generator, disposeState)); + Objects.requireNonNull(generator, "generator is null"); + Objects.requireNonNull(disposeState, "diposeState is null"); + return create(new NbpOnSubscribeGenerate(initialState, generator, disposeState)); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public static Observable interval(long initialDelay, long period, TimeUnit unit) { return interval(initialDelay, period, unit, Schedulers.computation()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public static Observable interval(long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { if (initialDelay < 0) { @@ -578,28 +549,24 @@ public static Observable interval(long initialDelay, long period, TimeUnit Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return create(new PublisherIntervalSource(initialDelay, period, unit, scheduler)); + return create(new NbpOnSubscribeIntervalSource(initialDelay, period, unit, scheduler)); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public static Observable interval(long period, TimeUnit unit) { return interval(period, period, unit, Schedulers.computation()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public static Observable interval(long period, TimeUnit unit, Scheduler scheduler) { return interval(period, period, unit, scheduler); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public static Observable intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit) { return intervalRange(start, count, initialDelay, period, unit, Schedulers.computation()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public static Observable intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit, Scheduler scheduler) { @@ -617,18 +584,15 @@ public static Observable intervalRange(long start, long count, long initia Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return create(new PublisherIntervalRangeSource(start, end, initialDelay, period, unit, scheduler)); + return create(new NbpOnSubscribeIntervalRangeSource(start, end, initialDelay, period, unit, scheduler)); } - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) public static Observable just(T value) { - Objects.requireNonNull(value, "value is null"); - return new ObservableScalarSource(value); + Objects.requireNonNull(value, "The value is null"); + return new NbpObservableScalarSource(value); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static final Observable just(T v1, T v2) { Objects.requireNonNull(v1, "The first value is null"); @@ -637,9 +601,7 @@ public static final Observable just(T v1, T v2) { return fromArray(v1, v2); } - @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static final Observable just(T v1, T v2, T v3) { Objects.requireNonNull(v1, "The first value is null"); @@ -650,7 +612,6 @@ public static final Observable just(T v1, T v2, T v3) { } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static final Observable just(T v1, T v2, T v3, T v4) { Objects.requireNonNull(v1, "The first value is null"); @@ -662,7 +623,6 @@ public static final Observable just(T v1, T v2, T v3, T v4) { } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static final Observable just(T v1, T v2, T v3, T v4, T v5) { Objects.requireNonNull(v1, "The first value is null"); @@ -675,7 +635,6 @@ public static final Observable just(T v1, T v2, T v3, T v4, T v5) { } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static final Observable just(T v1, T v2, T v3, T v4, T v5, T v6) { Objects.requireNonNull(v1, "The first value is null"); @@ -689,7 +648,6 @@ public static final Observable just(T v1, T v2, T v3, T v4, T v5, T v6) { } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static final Observable just(T v1, T v2, T v3, T v4, T v5, T v6, T v7) { Objects.requireNonNull(v1, "The first value is null"); @@ -704,7 +662,6 @@ public static final Observable just(T v1, T v2, T v3, T v4, T v5, T v6, T } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static final Observable just(T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8) { Objects.requireNonNull(v1, "The first value is null"); @@ -720,7 +677,6 @@ public static final Observable just(T v1, T v2, T v3, T v4, T v5, T v6, T } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static final Observable just(T v1, T v2, T v3, T v4, T v5, T v6, T v7, T v8, T v9) { Objects.requireNonNull(v1, "The first value is null"); @@ -737,64 +693,51 @@ public static final Observable just(T v1, T v2, T v3, T v4, T v5, T v6, T } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable merge(int maxConcurrency, int bufferSize, Iterable> sources) { + public static Observable merge(int maxConcurrency, int bufferSize, Iterable> sources) { return fromIterable(sources).flatMap((Function)Functions.identity(), false, maxConcurrency, bufferSize); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable merge(int maxConcurrency, int bufferSize, Publisher... sources) { + public static Observable merge(int maxConcurrency, int bufferSize, Observable... sources) { return fromArray(sources).flatMap((Function)Functions.identity(), false, maxConcurrency, bufferSize); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable merge(int maxConcurrency, Publisher... sources) { + public static Observable merge(int maxConcurrency, Observable... sources) { return fromArray(sources).flatMap((Function)Functions.identity(), maxConcurrency); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable merge(Iterable> sources) { + public static Observable merge(Iterable> sources) { return fromIterable(sources).flatMap((Function)Functions.identity()); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable merge(Iterable> sources, int maxConcurrency) { + public static Observable merge(Iterable> sources, int maxConcurrency) { return fromIterable(sources).flatMap((Function)Functions.identity(), maxConcurrency); } - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public static Observable merge(Publisher> sources) { - return merge(sources, bufferSize()); - } - @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public static Observable merge(Publisher> sources, int maxConcurrency) { - return fromPublisher(sources).flatMap((Function)Functions.identity(), maxConcurrency); + public static Observable merge(Observable> sources) { + return sources.flatMap((Function)Functions.identity()); } + @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable merge(Publisher... sources) { - return fromArray(sources).flatMap((Function)Functions.identity(), sources.length); + public static Observable merge(Observable> sources, int maxConcurrency) { + return sources.flatMap((Function)Functions.identity(), maxConcurrency); } - + @SuppressWarnings({ "unchecked", "rawtypes" }) @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable merge(Publisher p1, Publisher p2) { + public static Observable merge(Observable p1, Observable p2) { Objects.requireNonNull(p1, "p1 is null"); Objects.requireNonNull(p2, "p2 is null"); return fromArray(p1, p2).flatMap((Function)Functions.identity(), false, 2); @@ -803,7 +746,7 @@ public static Observable merge(Publisher p1, Publisher Observable merge(Publisher p1, Publisher p2, Publisher p3) { + public static Observable merge(Observable p1, Observable p2, Observable p3) { Objects.requireNonNull(p1, "p1 is null"); Objects.requireNonNull(p2, "p2 is null"); Objects.requireNonNull(p3, "p3 is null"); @@ -814,8 +757,8 @@ public static Observable merge(Publisher p1, Publisher Observable merge( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4) { + Observable p1, Observable p2, + Observable p3, Observable p4) { Objects.requireNonNull(p1, "p1 is null"); Objects.requireNonNull(p2, "p2 is null"); Objects.requireNonNull(p3, "p3 is null"); @@ -824,64 +767,56 @@ public static Observable merge( } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable mergeDelayError(boolean delayErrors, Iterable> sources) { + public static Observable merge(Observable... sources) { + return fromArray(sources).flatMap((Function)Functions.identity(), sources.length); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @SchedulerSupport(SchedulerKind.NONE) + public static Observable mergeDelayError(boolean delayErrors, Iterable> sources) { return fromIterable(sources).flatMap((Function)Functions.identity(), true); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable mergeDelayError(int maxConcurrency, int bufferSize, Iterable> sources) { + public static Observable mergeDelayError(int maxConcurrency, int bufferSize, Iterable> sources) { return fromIterable(sources).flatMap((Function)Functions.identity(), true, maxConcurrency, bufferSize); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable mergeDelayError(int maxConcurrency, int bufferSize, Publisher... sources) { + public static Observable mergeDelayError(int maxConcurrency, int bufferSize, Observable... sources) { return fromArray(sources).flatMap((Function)Functions.identity(), true, maxConcurrency, bufferSize); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable mergeDelayError(int maxConcurrency, Iterable> sources) { + public static Observable mergeDelayError(int maxConcurrency, Iterable> sources) { return fromIterable(sources).flatMap((Function)Functions.identity(), true, maxConcurrency); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable mergeDelayError(int maxConcurrency, Publisher... sources) { + public static Observable mergeDelayError(int maxConcurrency, Observable... sources) { return fromArray(sources).flatMap((Function)Functions.identity(), true, maxConcurrency); } - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public static Observable mergeDelayError(Publisher> sources) { - return mergeDelayError(sources, bufferSize()); - } - @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public static Observable mergeDelayError(Publisher> sources, int maxConcurrency) { - return fromPublisher(sources).flatMap((Function)Functions.identity(), true, maxConcurrency); + public static Observable mergeDelayError(Observable> sources) { + return sources.flatMap((Function)Functions.identity(), true); } @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable mergeDelayError(Publisher... sources) { - return fromArray(sources).flatMap((Function)Functions.identity(), true, sources.length); + public static Observable mergeDelayError(Observable> sources, int maxConcurrency) { + return sources.flatMap((Function)Functions.identity(), true, maxConcurrency); } @SuppressWarnings({ "unchecked", "rawtypes" }) @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable mergeDelayError(Publisher p1, Publisher p2) { + public static Observable mergeDelayError(Observable p1, Observable p2) { Objects.requireNonNull(p1, "p1 is null"); Objects.requireNonNull(p2, "p2 is null"); return fromArray(p1, p2).flatMap((Function)Functions.identity(), true, 2); @@ -890,7 +825,7 @@ public static Observable mergeDelayError(Publisher p1, Publi @SuppressWarnings({ "unchecked", "rawtypes" }) @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable mergeDelayError(Publisher p1, Publisher p2, Publisher p3) { + public static Observable mergeDelayError(Observable p1, Observable p2, Observable p3) { Objects.requireNonNull(p1, "p1 is null"); Objects.requireNonNull(p2, "p2 is null"); Objects.requireNonNull(p3, "p3 is null"); @@ -901,8 +836,8 @@ public static Observable mergeDelayError(Publisher p1, Publi @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable mergeDelayError( - Publisher p1, Publisher p2, - Publisher p3, Publisher p4) { + Observable p1, Observable p2, + Observable p3, Observable p4) { Objects.requireNonNull(p1, "p1 is null"); Objects.requireNonNull(p2, "p2 is null"); Objects.requireNonNull(p3, "p3 is null"); @@ -910,17 +845,20 @@ public static Observable mergeDelayError( return fromArray(p1, p2, p3, p4).flatMap((Function)Functions.identity(), true, 4); } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SuppressWarnings({ "unchecked", "rawtypes" }) + @SchedulerSupport(SchedulerKind.NONE) + public static Observable mergeDelayError(Observable... sources) { + return fromArray(sources).flatMap((Function)Functions.identity(), true, sources.length); + } + @SchedulerSupport(SchedulerKind.NONE) @SuppressWarnings("unchecked") public static Observable never() { return (Observable)NEVER; } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable range(int start, int count) { + public static Observable range(final int start, final int count) { if (count < 0) { throw new IllegalArgumentException("count >= required but it was " + count); } else @@ -933,58 +871,65 @@ public static Observable range(int start, int count) { if ((long)start + (count - 1) > Integer.MAX_VALUE) { throw new IllegalArgumentException("Integer overflow"); } - return create(new PublisherRangeSource(start, count)); + return create(new NbpOnSubscribe() { + @Override + public void accept(Observer s) { + BooleanDisposable d = new BooleanDisposable(); + s.onSubscribe(d); + + long end = start - 1L + count; + for (long i = start; i <= end && !d.isDisposed(); i++) { + s.onNext((int)i); + } + if (!d.isDisposed()) { + s.onComplete(); + } + } + }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable sequenceEqual(Publisher p1, Publisher p2) { + public static Observable sequenceEqual(Observable p1, Observable p2) { return sequenceEqual(p1, p2, Objects.equalsPredicate(), bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable sequenceEqual(Publisher p1, Publisher p2, BiPredicate isEqual) { + public static Observable sequenceEqual(Observable p1, Observable p2, BiPredicate isEqual) { return sequenceEqual(p1, p2, isEqual, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable sequenceEqual(Publisher p1, Publisher p2, BiPredicate isEqual, int bufferSize) { + public static Observable sequenceEqual(Observable p1, Observable p2, BiPredicate isEqual, int bufferSize) { Objects.requireNonNull(p1, "p1 is null"); Objects.requireNonNull(p2, "p2 is null"); Objects.requireNonNull(isEqual, "isEqual is null"); validateBufferSize(bufferSize); - return create(new PublisherSequenceEqual(p1, p2, isEqual, bufferSize)); + return create(new NbpOnSubscribeSequenceEqual(p1, p2, isEqual, bufferSize)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable sequenceEqual(Publisher p1, Publisher p2, int bufferSize) { + public static Observable sequenceEqual(Observable p1, Observable p2, int bufferSize) { return sequenceEqual(p1, p2, Objects.equalsPredicate(), bufferSize); } - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({ "rawtypes", "unchecked" }) @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable switchOnNext(int bufferSize, Publisher> sources) { - return fromPublisher(sources).switchMap((Function)Functions.identity(), bufferSize); + public static Observable switchOnNext(int bufferSize, Observable> sources) { + return sources.switchMap((Function)Functions.identity(), bufferSize); } - @SuppressWarnings({ "unchecked", "rawtypes" }) - @BackpressureSupport(BackpressureKind.FULL) + @SuppressWarnings({ "rawtypes", "unchecked" }) @SchedulerSupport(SchedulerKind.NONE) - public static Observable switchOnNext(Publisher> sources) { - return fromPublisher(sources).switchMap((Function)Functions.identity()); + public static Observable switchOnNext(Observable> sources) { + return sources.switchMap((Function)Functions.identity()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public static Observable timer(long delay, TimeUnit unit) { return timer(delay, unit, Schedulers.computation()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public static Observable timer(long delay, TimeUnit unit, Scheduler scheduler) { if (delay < 0) { @@ -993,22 +938,20 @@ public static Observable timer(long delay, TimeUnit unit, Scheduler schedu Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return create(new PublisherIntervalOnceSource(delay, unit, scheduler)); + return create(new NbpOnSubscribeTimerOnceSource(delay, unit, scheduler)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) - public static Observable using(Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer) { + public static Observable using(Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer) { return using(resourceSupplier, sourceSupplier, disposer, true); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) - public static Observable using(Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer, boolean eager) { + public static Observable using(Supplier resourceSupplier, Function> sourceSupplier, Consumer disposer, boolean eager) { Objects.requireNonNull(resourceSupplier, "resourceSupplier is null"); Objects.requireNonNull(sourceSupplier, "sourceSupplier is null"); Objects.requireNonNull(disposer, "disposer is null"); - return create(new PublisherUsing(resourceSupplier, sourceSupplier, disposer, eager)); + return create(new NbpOnSubscribeUsing(resourceSupplier, sourceSupplier, disposer, eager)); } private static void validateBufferSize(int bufferSize) { @@ -1017,195 +960,175 @@ private static void validateBufferSize(int bufferSize) { } } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable zip(Iterable> sources, Function zipper) { + public static Observable zip(Iterable> sources, Function zipper) { Objects.requireNonNull(zipper, "zipper is null"); Objects.requireNonNull(sources, "sources is null"); - return create(new PublisherZip(null, sources, zipper, bufferSize(), false)); + return create(new NbpOnSubscribeZip(null, sources, zipper, bufferSize(), false)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public static Observable zip(Publisher> sources, final Function zipper) { + public static Observable zip(Observable> sources, final Function zipper) { Objects.requireNonNull(zipper, "zipper is null"); - return fromPublisher(sources).toList().flatMap(new Function>, Publisher>() { + return sources.toList().flatMap(new Function>, Observable>() { @Override - public Publisher apply(List> list) { + public Observable apply(List> list) { return zipIterable(zipper, false, bufferSize(), list); } }); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable zip( - Publisher p1, Publisher p2, + Observable p1, Observable p2, BiFunction zipper) { return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable zip( - Publisher p1, Publisher p2, + Observable p1, Observable p2, BiFunction zipper, boolean delayError) { return zipArray(Functions.toFunction(zipper), delayError, bufferSize(), p1, p2); } - @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable zip( - Publisher p1, Publisher p2, + Observable p1, Observable p2, BiFunction zipper, boolean delayError, int bufferSize) { return zipArray(Functions.toFunction(zipper), delayError, bufferSize, p1, p2); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable zip( - Publisher p1, Publisher p2, Publisher p3, + Observable p1, Observable p2, Observable p3, Function3 zipper) { return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable zip( - Publisher p1, Publisher p2, Publisher p3, - Publisher p4, + Observable p1, Observable p2, Observable p3, + Observable p4, Function4 zipper) { return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable zip( - Publisher p1, Publisher p2, Publisher p3, - Publisher p4, Publisher p5, + Observable p1, Observable p2, Observable p3, + Observable p4, Observable p5, Function5 zipper) { return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable zip( - Publisher p1, Publisher p2, Publisher p3, - Publisher p4, Publisher p5, Publisher p6, + Observable p1, Observable p2, Observable p3, + Observable p4, Observable p5, Observable p6, Function6 zipper) { return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5, p6); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable zip( - Publisher p1, Publisher p2, Publisher p3, - Publisher p4, Publisher p5, Publisher p6, - Publisher p7, + Observable p1, Observable p2, Observable p3, + Observable p4, Observable p5, Observable p6, + Observable p7, Function7 zipper) { return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable zip( - Publisher p1, Publisher p2, Publisher p3, - Publisher p4, Publisher p5, Publisher p6, - Publisher p7, Publisher p8, + Observable p1, Observable p2, Observable p3, + Observable p4, Observable p5, Observable p6, + Observable p7, Observable p8, Function8 zipper) { return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7, p8); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable zip( - Publisher p1, Publisher p2, Publisher p3, - Publisher p4, Publisher p5, Publisher p6, - Publisher p7, Publisher p8, Publisher p9, + Observable p1, Observable p2, Observable p3, + Observable p4, Observable p5, Observable p6, + Observable p7, Observable p8, Observable p9, Function9 zipper) { return zipArray(Functions.toFunction(zipper), false, bufferSize(), p1, p2, p3, p4, p5, p6, p7, p8, p9); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable zipArray(Function zipper, - boolean delayError, int bufferSize, Publisher... sources) { + boolean delayError, int bufferSize, Observable... sources) { if (sources.length == 0) { return empty(); } Objects.requireNonNull(zipper, "zipper is null"); validateBufferSize(bufferSize); - return create(new PublisherZip(sources, null, zipper, bufferSize, delayError)); + return create(new NbpOnSubscribeZip(sources, null, zipper, bufferSize, delayError)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public static Observable zipIterable(Function zipper, boolean delayError, int bufferSize, - Iterable> sources) { + Iterable> sources) { Objects.requireNonNull(zipper, "zipper is null"); Objects.requireNonNull(sources, "sources is null"); validateBufferSize(bufferSize); - return create(new PublisherZip(null, sources, zipper, bufferSize, delayError)); + return create(new NbpOnSubscribeZip(null, sources, zipper, bufferSize, delayError)); } - final Publisher onSubscribe; - protected Observable(Publisher onSubscribe) { + protected final NbpOnSubscribe onSubscribe; + + protected Observable(NbpOnSubscribe onSubscribe) { this.onSubscribe = onSubscribe; } - - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) public final Observable all(Predicate predicate) { Objects.requireNonNull(predicate, "predicate is null"); - return lift(new OperatorAll(predicate)); + return lift(new NbpOperatorAll(predicate)); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable ambWith(Publisher other) { + public final Observable ambWith(Observable other) { Objects.requireNonNull(other, "other is null"); return amb(this, other); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable any(Predicate predicate) { Objects.requireNonNull(predicate, "predicate is null"); - return lift(new OperatorAny(predicate)); + return lift(new NbpOperatorAny(predicate)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) public final Observable asObservable() { - return create(new Publisher() { + return create(new NbpOnSubscribe() { @Override - public void subscribe(Subscriber s) { + public void accept(Observer s) { Observable.this.subscribe(s); } }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable> buffer(int count) { return buffer(count, count); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable> buffer(int count, int skip) { return buffer(count, skip, new Supplier>() { @@ -1216,20 +1139,23 @@ public List get() { }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final > Observable buffer(int count, int skip, Supplier bufferSupplier) { + if (count <= 0) { + throw new IllegalArgumentException("count > 0 required but it was " + count); + } + if (skip <= 0) { + throw new IllegalArgumentException("skip > 0 required but it was " + count); + } Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); - return lift(new OperatorBuffer(count, skip, bufferSupplier)); + return lift(new NbpOperatorBuffer(count, skip, bufferSupplier)); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) public final > Observable buffer(int count, Supplier bufferSupplier) { return buffer(count, count, bufferSupplier); } - - @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable> buffer(long timespan, long timeskip, TimeUnit unit) { return buffer(timespan, timeskip, unit, Schedulers.computation(), new Supplier>() { @@ -1240,7 +1166,6 @@ public List get() { }); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> buffer(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler) { return buffer(timespan, timeskip, unit, scheduler, new Supplier>() { @@ -1251,28 +1176,24 @@ public List get() { }); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public final > Observable buffer(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler, Supplier bufferSupplier) { Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); - return lift(new OperatorBufferTimed(timespan, timeskip, unit, scheduler, bufferSupplier, Integer.MAX_VALUE, false)); + return lift(new NbpOperatorBufferTimed(timespan, timeskip, unit, scheduler, bufferSupplier, Integer.MAX_VALUE, false)); } - - @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable> buffer(long timespan, TimeUnit unit) { return buffer(timespan, unit, Integer.MAX_VALUE, Schedulers.computation()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable> buffer(long timespan, TimeUnit unit, int count) { return buffer(timespan, unit, count, Schedulers.computation()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> buffer(long timespan, TimeUnit unit, int count, Scheduler scheduler) { return buffer(timespan, unit, count, scheduler, new Supplier>() { @@ -1283,7 +1204,6 @@ public List get() { }, false); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public final > Observable buffer( long timespan, TimeUnit unit, @@ -1296,10 +1216,9 @@ public final > Observable buffer( if (count <= 0) { throw new IllegalArgumentException("count > 0 required but it was " + count); } - return lift(new OperatorBufferTimed(timespan, timespan, unit, scheduler, bufferSupplier, count, restartTimerOnMaxSize)); + return lift(new NbpOperatorBufferTimed(timespan, timespan, unit, scheduler, bufferSupplier, count, restartTimerOnMaxSize)); } - - @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> buffer(long timespan, TimeUnit unit, Scheduler scheduler) { return buffer(timespan, unit, Integer.MAX_VALUE, scheduler, new Supplier>() { @@ -1309,12 +1228,11 @@ public List get() { } }, false); } - - @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) public final Observable> buffer( Observable bufferOpenings, - Function> bufferClosingSelector) { + Function> bufferClosingSelector) { return buffer(bufferOpenings, bufferClosingSelector, new Supplier>() { @Override public List get() { @@ -1323,21 +1241,19 @@ public List get() { }); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) public final > Observable buffer( Observable bufferOpenings, - Function> bufferClosingSelector, + Function> bufferClosingSelector, Supplier bufferSupplier) { Objects.requireNonNull(bufferOpenings, "bufferOpenings is null"); Objects.requireNonNull(bufferClosingSelector, "bufferClosingSelector is null"); Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); - return lift(new OperatorBufferBoundary(bufferOpenings, bufferClosingSelector, bufferSupplier)); + return lift(new NbpOperatorBufferBoundary(bufferOpenings, bufferClosingSelector, bufferSupplier)); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) - public final Observable> buffer(Publisher boundary) { + public final Observable> buffer(Observable boundary) { /* * XXX: javac complains if this is not manually cast, Eclipse is fine */ @@ -1348,10 +1264,9 @@ public List get() { } }); } - - @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.NONE) - public final Observable> buffer(Publisher boundary, final int initialCapacity) { + public final Observable> buffer(Observable boundary, final int initialCapacity) { return buffer(boundary, new Supplier>() { @Override public List get() { @@ -1360,17 +1275,15 @@ public List get() { }); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) - public final > Observable buffer(Publisher boundary, Supplier bufferSupplier) { + public final > Observable buffer(Observable boundary, Supplier bufferSupplier) { Objects.requireNonNull(boundary, "boundary is null"); Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); - return lift(new OperatorBufferExactBoundary(boundary, bufferSupplier)); + return lift(new NbpOperatorBufferExactBoundary(boundary, bufferSupplier)); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) - public final Observable> buffer(Supplier> boundarySupplier) { + public final Observable> buffer(Supplier> boundarySupplier) { return buffer(boundarySupplier, new Supplier>() { @Override public List get() { @@ -1380,30 +1293,23 @@ public List get() { } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) - public final > Observable buffer(Supplier> boundarySupplier, Supplier bufferSupplier) { + public final > Observable buffer(Supplier> boundarySupplier, Supplier bufferSupplier) { Objects.requireNonNull(boundarySupplier, "boundarySupplier is null"); Objects.requireNonNull(bufferSupplier, "bufferSupplier is null"); - return lift(new OperatorBufferBoundarySupplier(boundarySupplier, bufferSupplier)); + return lift(new NbpOperatorBufferBoundarySupplier(boundarySupplier, bufferSupplier)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable cache() { - return CachedObservable.from(this); + return NbpCachedObservable.from(this); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable cache(int capacityHint) { - if (capacityHint <= 0) { - throw new IllegalArgumentException("capacityHint > 0 required but it was " + capacityHint); - } - return CachedObservable.from(this, capacityHint); + return NbpCachedObservable.from(this, capacityHint); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) public final Observable cast(final Class clazz) { Objects.requireNonNull(clazz, "clazz is null"); @@ -1415,15 +1321,13 @@ public U apply(T v) { }); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable collect(Supplier initialValueSupplier, BiConsumer collector) { - Objects.requireNonNull(initialValueSupplier, "initialValueSupplier is null"); - Objects.requireNonNull(collector, "collectior is null"); - return lift(new OperatorCollect(initialValueSupplier, collector)); + Objects.requireNonNull(initialValueSupplier, "initalValueSupplier is null"); + Objects.requireNonNull(collector, "collector is null"); + return lift(new NbpOperatorCollect(initialValueSupplier, collector)); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable collectInto(final U initialValue, BiConsumer collector) { Objects.requireNonNull(initialValue, "initialValue is null"); @@ -1435,55 +1339,51 @@ public U get() { }, collector); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) - @SchedulerSupport(SchedulerKind.NONE) - // TODO generics - public final Observable compose(Transformer composer) { - return fromPublisher(to(composer)); + public final Observable compose(Function, ? extends Observable> convert) { + return to(convert); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable concatMap(Function> mapper) { + public final Observable concatMap(Function> mapper) { return concatMap(mapper, 2); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable concatMap(Function> mapper, int prefetch) { + public final Observable concatMap(Function> mapper, int prefetch) { Objects.requireNonNull(mapper, "mapper is null"); if (prefetch <= 0) { throw new IllegalArgumentException("prefetch > 0 required but it was " + prefetch); } - return lift(new OperatorConcatMap(mapper, prefetch)); + return lift(new NbpOperatorConcatMap(mapper, prefetch)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable concatMapIterable(Function> mapper) { - return concatMapIterable(mapper, 2); + public final Observable concatMapIterable(final Function> mapper) { + Objects.requireNonNull(mapper, "mapper is null"); + return concatMap(new Function>() { + @Override + public Observable apply(T v) { + return fromIterable(mapper.apply(v)); + } + }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable concatMapIterable(final Function> mapper, int prefetch) { - Objects.requireNonNull(mapper, "mapper is null"); - return concatMap(new Function>() { + return concatMap(new Function>() { @Override - public Publisher apply(T v) { - return new PublisherIterableSource(mapper.apply(v)); + public Observable apply(T v) { + return fromIterable(mapper.apply(v)); } }, prefetch); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable concatWith(Publisher other) { + public final Observable concatWith(Observable other) { Objects.requireNonNull(other, "other is null"); return concat(this, other); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable contains(final Object o) { Objects.requireNonNull(o, "o is null"); @@ -1495,20 +1395,17 @@ public boolean test(T v) { }); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable count() { - return lift(OperatorCount.instance()); + return lift(NbpOperatorCount.instance()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) - public final Observable debounce(Function> debounceSelector) { + public final Observable debounce(Function> debounceSelector) { Objects.requireNonNull(debounceSelector, "debounceSelector is null"); - return lift(new OperatorDebounce(debounceSelector)); + return lift(new NbpOperatorDebounce(debounceSelector)); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable debounce(long timeout, TimeUnit unit) { return debounce(timeout, unit, Schedulers.computation()); @@ -1519,25 +1416,23 @@ public final Observable debounce(long timeout, TimeUnit unit) { public final Observable debounce(long timeout, TimeUnit unit, Scheduler scheduler) { Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new OperatorDebounceTimed(timeout, unit, scheduler)); + return lift(new NbpOperatorDebounceTimed(timeout, unit, scheduler)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable defaultIfEmpty(T value) { Objects.requireNonNull(value, "value is null"); return switchIfEmpty(just(value)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) // TODO a more efficient implementation if necessary - public final Observable delay(final Function> itemDelay) { + public final Observable delay(final Function> itemDelay) { Objects.requireNonNull(itemDelay, "itemDelay is null"); - return flatMap(new Function>() { + return flatMap(new Function>() { @Override - public Publisher apply(final T v) { - return fromPublisher(itemDelay.apply(v)).take(1).map(new Function() { + public Observable apply(final T v) { + return itemDelay.apply(v).take(1).map(new Function() { @Override public T apply(U u) { return v; @@ -1547,40 +1442,35 @@ public T apply(U u) { }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable delay(long delay, TimeUnit unit) { return delay(delay, unit, Schedulers.computation(), false); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable delay(long delay, TimeUnit unit, boolean delayError) { return delay(delay, unit, Schedulers.computation(), delayError); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable delay(long delay, TimeUnit unit, Scheduler scheduler) { return delay(delay, unit, scheduler, false); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable delay(long delay, TimeUnit unit, Scheduler scheduler, boolean delayError) { Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new OperatorDelay(delay, unit, scheduler, delayError)); + return lift(new NbpOperatorDelay(delay, unit, scheduler, delayError)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable delay(Supplier> delaySupplier, - Function> itemDelay) { + public final Observable delay(Supplier> delaySupplier, + Function> itemDelay) { return delaySubscription(delaySupplier).delay(itemDelay); } - + /** * Returns an Observable that delays the subscription to this Observable * until the other Observable emits an element or completes normally. @@ -1600,67 +1490,60 @@ public final Observable delay(Supplier> delaySu * until the other Observable emits an element or completes normally. */ @Experimental - public final Observable delaySubscription(Publisher other) { + public final Observable delaySubscription(Observable other) { Objects.requireNonNull(other, "other is null"); - return create(new PublisherDelaySubscriptionOther(this, other)); + return create(new NbpOnSubscribeDelaySubscriptionOther(this, other)); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable delaySubscription(long delay, TimeUnit unit) { return delaySubscription(delay, unit, Schedulers.computation()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) // TODO a more efficient implementation if necessary public final Observable delaySubscription(long delay, TimeUnit unit, Scheduler scheduler) { Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return timer(delay, unit, scheduler).flatMap(new Function>() { + return timer(delay, unit, scheduler).flatMap(new Function>() { @Override - public Publisher apply(Long v) { + public Observable apply(Long v) { return Observable.this; } }); } - private static final Object OBJECT = new Object(); - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @BackpressureSupport(BackpressureKind.FULL) + @SuppressWarnings({ "unchecked", "rawtypes" }) @SchedulerSupport(SchedulerKind.NONE) - public final Observable delaySubscription(final Supplier> delaySupplier) { + public final Observable delaySubscription(final Supplier> delaySupplier) { Objects.requireNonNull(delaySupplier, "delaySupplier is null"); - return fromCallable(new Callable() { + return fromCallable(new Callable>() { @Override - public Object call() throws Exception { + public Observable call() throws Exception { return delaySupplier.get(); } - }) - .flatMap((Function)Functions.identity()) - .take(1) - .cast(Object.class) // need a common supertype, the value is not relevant - .defaultIfEmpty(OBJECT) // in case the publisher is empty - .flatMap(new Function() { + }) + .flatMap((Function)Functions.identity()) + .take(1) + .cast(Object.class) + .defaultIfEmpty(OBJECT) + .flatMap(new Function>() { @Override - public Object apply(Object v) { + public Observable apply(Object v) { return Observable.this; } - }); + }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable dematerialize() { @SuppressWarnings("unchecked") Observable>> m = (Observable>>)this; - return m.lift(OperatorDematerialize.instance()); + return m.lift(NbpOperatorDematerialize.instance()); } - + @SuppressWarnings({ "rawtypes", "unchecked" }) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable distinct() { return distinct((Function)Functions.identity(), new Supplier>() { @@ -1671,7 +1554,6 @@ public Collection get() { }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable distinct(Function keySelector) { return distinct(keySelector, new Supplier>() { @@ -1682,50 +1564,43 @@ public Collection get() { }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable distinct(Function keySelector, Supplier> collectionSupplier) { Objects.requireNonNull(keySelector, "keySelector is null"); Objects.requireNonNull(collectionSupplier, "collectionSupplier is null"); - return lift(OperatorDistinct.withCollection(keySelector, collectionSupplier)); + return lift(NbpOperatorDistinct.withCollection(keySelector, collectionSupplier)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable distinctUntilChanged() { - return lift(OperatorDistinct.untilChanged()); + return lift(NbpOperatorDistinct.untilChanged()); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) public final Observable distinctUntilChanged(Function keySelector) { Objects.requireNonNull(keySelector, "keySelector is null"); - return lift(OperatorDistinct.untilChanged(keySelector)); + return lift(NbpOperatorDistinct.untilChanged(keySelector)); } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) public final Observable doOnCancel(Runnable onCancel) { - return doOnLifecycle(Functions.emptyConsumer(), Functions.emptyLongConsumer(), onCancel); + return doOnLifecycle(Functions.emptyConsumer(), onCancel); } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) public final Observable doOnComplete(Runnable onComplete) { return doOnEach(Functions.emptyConsumer(), Functions.emptyConsumer(), onComplete, Functions.emptyRunnable()); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) private Observable doOnEach(Consumer onNext, Consumer onError, Runnable onComplete, Runnable onAfterTerminate) { Objects.requireNonNull(onNext, "onNext is null"); Objects.requireNonNull(onError, "onError is null"); Objects.requireNonNull(onComplete, "onComplete is null"); Objects.requireNonNull(onAfterTerminate, "onAfterTerminate is null"); - return lift(new OperatorDoOnEach(onNext, onError, onComplete, onAfterTerminate)); + return lift(new NbpOperatorDoOnEach(onNext, onError, onComplete, onAfterTerminate)); } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) public final Observable doOnEach(final Consumer>> consumer) { Objects.requireNonNull(consumer, "consumer is null"); @@ -1752,9 +1627,8 @@ public void run() { ); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) - public final Observable doOnEach(final Subscriber observer) { + public final Observable doOnEach(final Observer observer) { Objects.requireNonNull(observer, "observer is null"); return doOnEach(new Consumer() { @Override @@ -1774,45 +1648,33 @@ public void run() { }, Functions.emptyRunnable()); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) public final Observable doOnError(Consumer onError) { return doOnEach(Functions.emptyConsumer(), onError, Functions.emptyRunnable(), Functions.emptyRunnable()); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) - public final Observable doOnLifecycle(final Consumer onSubscribe, final LongConsumer onRequest, final Runnable onCancel) { + public final Observable doOnLifecycle(final Consumer onSubscribe, final Runnable onCancel) { Objects.requireNonNull(onSubscribe, "onSubscribe is null"); - Objects.requireNonNull(onRequest, "onRequest is null"); Objects.requireNonNull(onCancel, "onCancel is null"); - return lift(new Operator() { + return lift(new NbpOperator() { @Override - public Subscriber apply(Subscriber s) { - return new SubscriptionLambdaSubscriber(s, onSubscribe, onRequest, onCancel); + public Observer apply(Observer s) { + return new NbpSubscriptionLambdaSubscriber(s, onSubscribe, onCancel); } }); } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) public final Observable doOnNext(Consumer onNext) { return doOnEach(onNext, Functions.emptyConsumer(), Functions.emptyRunnable(), Functions.emptyRunnable()); } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable doOnRequest(LongConsumer onRequest) { - return doOnLifecycle(Functions.emptyConsumer(), onRequest, Functions.emptyRunnable()); - } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.NONE) - public final Observable doOnSubscribe(Consumer onSubscribe) { - return doOnLifecycle(onSubscribe, Functions.emptyLongConsumer(), Functions.emptyRunnable()); + public final Observable doOnSubscribe(Consumer onSubscribe) { + return doOnLifecycle(onSubscribe, Functions.emptyRunnable()); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) public final Observable doOnTerminate(final Runnable onTerminate) { return doOnEach(Functions.emptyConsumer(), new Consumer() { @@ -1823,43 +1685,37 @@ public void accept(Throwable e) { }, onTerminate, Functions.emptyRunnable()); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable elementAt(long index) { if (index < 0) { throw new IndexOutOfBoundsException("index >= 0 required but it was " + index); } - return lift(new OperatorElementAt(index, null)); + return lift(new NbpOperatorElementAt(index, null)); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable elementAt(long index, T defaultValue) { if (index < 0) { throw new IndexOutOfBoundsException("index >= 0 required but it was " + index); } Objects.requireNonNull(defaultValue, "defaultValue is null"); - return lift(new OperatorElementAt(index, defaultValue)); + return lift(new NbpOperatorElementAt(index, defaultValue)); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable endWith(Iterable values) { return concatArray(this, fromIterable(values)); } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable endWith(Publisher other) { + public final Observable endWith(Observable other) { Objects.requireNonNull(other, "other is null"); return concatArray(this, other); } - @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable endWith(T value) { Objects.requireNonNull(value, "value is null"); @@ -1867,7 +1723,6 @@ public final Observable endWith(T value) { } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable endWithArray(T... values) { Observable fromArray = fromArray(values); @@ -1877,123 +1732,108 @@ public final Observable endWithArray(T... values) { return concatArray(this, fromArray); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) public final Observable filter(Predicate predicate) { Objects.requireNonNull(predicate, "predicate is null"); - return lift(new OperatorFilter(predicate)); + return lift(new NbpOperatorFilter(predicate)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) public final Observable finallyDo(Runnable onFinally) { return doOnEach(Functions.emptyConsumer(), Functions.emptyConsumer(), Functions.emptyRunnable(), onFinally); } - @BackpressureSupport(BackpressureKind.SPECIAL) // take may trigger UNBOUNDED_IN @SchedulerSupport(SchedulerKind.NONE) public final Observable first() { return take(1).single(); } - @BackpressureSupport(BackpressureKind.SPECIAL) // take may trigger UNBOUNDED_IN @SchedulerSupport(SchedulerKind.NONE) public final Observable first(T defaultValue) { return take(1).single(defaultValue); } - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable flatMap(Function> mapper) { - return flatMap(mapper, false, bufferSize(), bufferSize()); + public final Observable flatMap(Function> mapper) { + return flatMap(mapper, false); } - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable flatMap(Function> mapper, boolean delayErrors) { - return flatMap(mapper, delayErrors, bufferSize(), bufferSize()); + + public final Observable flatMap(Function> mapper, boolean delayError) { + return flatMap(mapper, delayError, Integer.MAX_VALUE); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable flatMap(Function> mapper, boolean delayErrors, int maxConcurrency) { + public final Observable flatMap(Function> mapper, boolean delayErrors, int maxConcurrency) { return flatMap(mapper, delayErrors, maxConcurrency, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable flatMap(Function> mapper, + public final Observable flatMap(Function> mapper, boolean delayErrors, int maxConcurrency, int bufferSize) { Objects.requireNonNull(mapper, "mapper is null"); if (maxConcurrency <= 0) { throw new IllegalArgumentException("maxConcurrency > 0 required but it was " + maxConcurrency); } validateBufferSize(bufferSize); - if (this instanceof ObservableScalarSource) { - ObservableScalarSource scalar = (ObservableScalarSource) this; + if (this instanceof NbpObservableScalarSource) { + NbpObservableScalarSource scalar = (NbpObservableScalarSource) this; return create(scalar.scalarFlatMap(mapper)); } - return lift(new OperatorFlatMap(mapper, delayErrors, maxConcurrency, bufferSize)); + return lift(new NbpOperatorFlatMap(mapper, delayErrors, maxConcurrency, bufferSize)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable flatMap( - Function> onNextMapper, - Function> onErrorMapper, - Supplier> onCompleteSupplier) { + Function> onNextMapper, + Function> onErrorMapper, + Supplier> onCompleteSupplier) { Objects.requireNonNull(onNextMapper, "onNextMapper is null"); Objects.requireNonNull(onErrorMapper, "onErrorMapper is null"); Objects.requireNonNull(onCompleteSupplier, "onCompleteSupplier is null"); - return merge(lift(new OperatorMapNotification(onNextMapper, onErrorMapper, onCompleteSupplier))); + return merge(lift(new NbpOperatorMapNotification(onNextMapper, onErrorMapper, onCompleteSupplier))); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable flatMap( - Function> onNextMapper, - Function> onErrorMapper, - Supplier> onCompleteSupplier, + Function> onNextMapper, + Function> onErrorMapper, + Supplier> onCompleteSupplier, int maxConcurrency) { Objects.requireNonNull(onNextMapper, "onNextMapper is null"); Objects.requireNonNull(onErrorMapper, "onErrorMapper is null"); Objects.requireNonNull(onCompleteSupplier, "onCompleteSupplier is null"); - return merge(lift(new OperatorMapNotification(onNextMapper, onErrorMapper, onCompleteSupplier)), maxConcurrency); + return merge(lift(new NbpOperatorMapNotification(onNextMapper, onErrorMapper, onCompleteSupplier)), maxConcurrency); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable flatMap(Function> mapper, int maxConcurrency) { + public final Observable flatMap(Function> mapper, int maxConcurrency) { return flatMap(mapper, false, maxConcurrency, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable flatMap(Function> mapper, BiFunction resultSelector) { + public final Observable flatMap(Function> mapper, BiFunction resultSelector) { return flatMap(mapper, resultSelector, false, bufferSize(), bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable flatMap(Function> mapper, BiFunction combiner, boolean delayError) { + public final Observable flatMap(Function> mapper, BiFunction combiner, boolean delayError) { return flatMap(mapper, combiner, delayError, bufferSize(), bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable flatMap(Function> mapper, BiFunction combiner, boolean delayError, int maxConcurrency) { + public final Observable flatMap(Function> mapper, BiFunction combiner, boolean delayError, int maxConcurrency) { return flatMap(mapper, combiner, delayError, maxConcurrency, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable flatMap(final Function> mapper, final BiFunction combiner, boolean delayError, int maxConcurrency, int bufferSize) { + public final Observable flatMap(final Function> mapper, final BiFunction combiner, boolean delayError, int maxConcurrency, int bufferSize) { Objects.requireNonNull(mapper, "mapper is null"); Objects.requireNonNull(combiner, "combiner is null"); - return flatMap(new Function>() { + return flatMap(new Function>() { @Override - public Publisher apply(final T t) { - Observable u = fromPublisher(mapper.apply(t)); + public Observable apply(final T t) { + @SuppressWarnings("unchecked") + Observable u = (Observable)mapper.apply(t); return u.map(new Function() { @Override public R apply(U w) { @@ -2004,119 +1844,147 @@ public R apply(U w) { }, delayError, maxConcurrency, bufferSize); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable flatMap(Function> mapper, BiFunction combiner, int maxConcurrency) { + public final Observable flatMap(Function> mapper, BiFunction combiner, int maxConcurrency) { return flatMap(mapper, combiner, false, maxConcurrency, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable flatMapIterable(final Function> mapper) { Objects.requireNonNull(mapper, "mapper is null"); - return flatMap(new Function>() { + return flatMap(new Function>() { @Override - public Publisher apply(T v) { - return new PublisherIterableSource(mapper.apply(v)); + public Observable apply(T v) { + return fromIterable(mapper.apply(v)); } }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable flatMapIterable(final Function> mapper, final BiFunction resultSelector) { - Objects.requireNonNull(mapper, "mapper is null"); - Objects.requireNonNull(resultSelector, "resultSelector is null"); - return flatMap(new Function>() { + public final Observable flatMapIterable(final Function> mapper, BiFunction resultSelector) { + return flatMap(new Function>() { @Override - public Publisher apply(T t) { - return new PublisherIterableSource(mapper.apply(t)); + public Observable apply(T t) { + return fromIterable(mapper.apply(t)); } }, resultSelector, false, bufferSize(), bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable flatMapIterable(final Function> mapper, int bufferSize) { - return flatMap(new Function>() { + return flatMap(new Function>() { @Override - public Publisher apply(T v) { - return new PublisherIterableSource(mapper.apply(v)); + public Observable apply(T v) { + return fromIterable(mapper.apply(v)); } }, false, bufferSize); } - @BackpressureSupport(BackpressureKind.NONE) @SchedulerSupport(SchedulerKind.NONE) public final Disposable forEach(Consumer onNext) { return subscribe(onNext); } - @BackpressureSupport(BackpressureKind.NONE) @SchedulerSupport(SchedulerKind.NONE) public final Disposable forEachWhile(Predicate onNext) { return forEachWhile(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable()); } - @BackpressureSupport(BackpressureKind.NONE) @SchedulerSupport(SchedulerKind.NONE) public final Disposable forEachWhile(Predicate onNext, Consumer onError) { return forEachWhile(onNext, onError, Functions.emptyRunnable()); } - @BackpressureSupport(BackpressureKind.NONE) @SchedulerSupport(SchedulerKind.NONE) - public final Disposable forEachWhile(final Predicate onNext, final Consumer onError, + public final Disposable forEachWhile(final Predicate onNext, Consumer onError, final Runnable onComplete) { Objects.requireNonNull(onNext, "onNext is null"); Objects.requireNonNull(onError, "onError is null"); Objects.requireNonNull(onComplete, "onComplete is null"); - final AtomicReference subscription = new AtomicReference(); + final AtomicReference subscription = new AtomicReference(); return subscribe(new Consumer() { @Override public void accept(T v) { if (!onNext.test(v)) { - subscription.get().cancel(); + subscription.get().dispose(); onComplete.run(); } } - }, onError, onComplete, new Consumer() { + }, onError, onComplete, new Consumer() { @Override - public void accept(Subscription s) { + public void accept(Disposable s) { subscription.lazySet(s); - s.request(Long.MAX_VALUE); } }); } - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) + public final List getList() { + final List result = new ArrayList(); + final Throwable[] error = { null }; + final CountDownLatch cdl = new CountDownLatch(1); + + subscribe(new Observer() { + @Override + public void onComplete() { + cdl.countDown(); + } + @Override + public void onError(Throwable e) { + error[0] = e; + cdl.countDown(); + } + @Override + public void onNext(T value) { + result.add(value); + } + @Override + public void onSubscribe(Disposable d) { + + } + }); + + if (cdl.getCount() != 0) { + try { + cdl.await(); + } catch (InterruptedException ex) { + throw Exceptions.propagate(ex); + } + } + + Throwable e = error[0]; + if (e != null) { + throw Exceptions.propagate(e); + } + + return result; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) @SchedulerSupport(SchedulerKind.NONE) public final Observable> groupBy(Function keySelector) { - return groupBy(keySelector, Functions.identity(), false, bufferSize()); + return groupBy(keySelector, (Function)Functions.identity(), false, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) + @SuppressWarnings({ "unchecked", "rawtypes" }) @SchedulerSupport(SchedulerKind.NONE) public final Observable> groupBy(Function keySelector, boolean delayError) { - return groupBy(keySelector, Functions.identity(), delayError, bufferSize()); + return groupBy(keySelector, (Function)Functions.identity(), delayError, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable> groupBy(Function keySelector, Function valueSelector) { return groupBy(keySelector, valueSelector, false, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable> groupBy(Function keySelector, Function valueSelector, boolean delayError) { return groupBy(keySelector, valueSelector, false, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable> groupBy(Function keySelector, Function valueSelector, @@ -2125,16 +1993,14 @@ public final Observable> groupBy(Function(keySelector, valueSelector, bufferSize, delayError)); + return lift(new NbpOperatorGroupBy(keySelector, valueSelector, bufferSize, delayError)); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable ignoreElements() { - return lift(OperatorIgnoreElements.instance()); + return lift(NbpOperatorIgnoreElements.instance()); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable isEmpty() { return all(new Predicate() { @@ -2145,176 +2011,95 @@ public boolean test(T v) { }); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable last() { return takeLast(1).single(); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable last(T defaultValue) { return takeLast(1).single(defaultValue); } - @BackpressureSupport(BackpressureKind.SPECIAL) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable lift(Operator lifter) { - Objects.requireNonNull(lifter, "lifter is null"); - // using onSubscribe so the fusing has access to the underlying raw Publisher - return create(new PublisherLift(onSubscribe, lifter)); + public final Observable lift(NbpOperator onLift) { + Objects.requireNonNull(onLift, "onLift is null"); + return create(new NbpOnSubscribeLift(this, onLift)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) - @SchedulerSupport(SchedulerKind.NONE) public final Observable map(Function mapper) { Objects.requireNonNull(mapper, "mapper is null"); - return lift(new OperatorMap(mapper)); + return lift(new NbpOperatorMap(mapper)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable>> materialize() { - return lift(OperatorMaterialize.instance()); + return lift(NbpOperatorMaterialize.instance()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable mergeWith(Publisher other) { + public final Observable mergeWith(Observable other) { Objects.requireNonNull(other, "other is null"); return merge(this, other); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) @Deprecated public final Observable> nest() { return just(this); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable observeOn(Scheduler scheduler) { return observeOn(scheduler, false, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable observeOn(Scheduler scheduler, boolean delayError) { return observeOn(scheduler, delayError, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable observeOn(Scheduler scheduler, boolean delayError, int bufferSize) { Objects.requireNonNull(scheduler, "scheduler is null"); validateBufferSize(bufferSize); - return lift(new OperatorObserveOn(scheduler, delayError, bufferSize)); + return lift(new NbpOperatorObserveOn(scheduler, delayError, bufferSize)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) public final Observable ofType(final Class clazz) { Objects.requireNonNull(clazz, "clazz is null"); return filter(new Predicate() { @Override - public boolean test(T c) { - return clazz.isInstance(c); + public boolean test(T v) { + return clazz.isInstance(v); } }).cast(clazz); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable onBackpressureBuffer() { - return onBackpressureBuffer(bufferSize(), false, true); - } - - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) - public final Observable onBackpressureBuffer(boolean delayError) { - return onBackpressureBuffer(bufferSize(), true, true); - } - - @BackpressureSupport(BackpressureKind.ERROR) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable onBackpressureBuffer(int bufferSize) { - return onBackpressureBuffer(bufferSize, false, false); - } - - @BackpressureSupport(BackpressureKind.ERROR) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable onBackpressureBuffer(int bufferSize, boolean delayError) { - return onBackpressureBuffer(bufferSize, true, false); - } - - @BackpressureSupport(BackpressureKind.SPECIAL) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable onBackpressureBuffer(int bufferSize, boolean delayError, boolean unbounded) { - validateBufferSize(bufferSize); - return lift(new OperatorOnBackpressureBuffer(bufferSize, unbounded, delayError, Functions.emptyRunnable())); - } - - @BackpressureSupport(BackpressureKind.SPECIAL) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable onBackpressureBuffer(int bufferSize, boolean delayError, boolean unbounded, Runnable onOverflow) { - Objects.requireNonNull(onOverflow, "onOverflow is null"); - return lift(new OperatorOnBackpressureBuffer(bufferSize, unbounded, delayError, onOverflow)); - } - - @BackpressureSupport(BackpressureKind.ERROR) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable onBackpressureBuffer(int bufferSize, Runnable onOverflow) { - return onBackpressureBuffer(bufferSize, false, false, onOverflow); - } - - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable onBackpressureDrop() { - return lift(OperatorOnBackpressureDrop.instance()); - } - - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable onBackpressureDrop(Consumer onDrop) { - Objects.requireNonNull(onDrop, "onDrop is null"); - return lift(new OperatorOnBackpressureDrop(onDrop)); - } - - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable onBackpressureLatest() { - return lift(OperatorOnBackpressureLatest.instance()); - } - - @BackpressureSupport(BackpressureKind.FULL) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable onErrorResumeNext(Function> resumeFunction) { + public final Observable onErrorResumeNext(Function> resumeFunction) { Objects.requireNonNull(resumeFunction, "resumeFunction is null"); - return lift(new OperatorOnErrorNext(resumeFunction, false)); + return lift(new NbpOperatorOnErrorNext(resumeFunction, false)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable onErrorResumeNext(final Publisher next) { + public final Observable onErrorResumeNext(final Observable next) { Objects.requireNonNull(next, "next is null"); - return onErrorResumeNext(new Function>() { + return onErrorResumeNext(new Function>() { @Override - public Publisher apply(Throwable e) { + public Observable apply(Throwable e) { return next; } }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable onErrorReturn(Function valueSupplier) { Objects.requireNonNull(valueSupplier, "valueSupplier is null"); - return lift(new OperatorOnErrorReturn(valueSupplier)); + return lift(new NbpOperatorOnErrorReturn(valueSupplier)); } // TODO would result in ambiguity with onErrorReturn(Function) - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable onErrorReturnValue(final T value) { Objects.requireNonNull(value, "value is null"); @@ -2326,71 +2111,61 @@ public T apply(Throwable e) { }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable onExceptionResumeNext(final Publisher next) { + public final Observable onExceptionResumeNext(final Observable next) { Objects.requireNonNull(next, "next is null"); - return lift(new OperatorOnErrorNext(new Function>() { + return lift(new NbpOperatorOnErrorNext(new Function>() { @Override - public Publisher apply(Throwable e) { + public Observable apply(Throwable e) { return next; } }, true)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final ConnectableObservable publish() { return publish(bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable publish(Function, ? extends Publisher> selector) { + public final Observable publish(Function, ? extends Observable> selector) { return publish(selector, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable publish(Function, ? extends Publisher> selector, int bufferSize) { + public final Observable publish(Function, ? extends Observable> selector, int bufferSize) { validateBufferSize(bufferSize); Objects.requireNonNull(selector, "selector is null"); - return OperatorPublish.create(this, selector, bufferSize); + return NbpOperatorPublish.create(this, selector, bufferSize); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final ConnectableObservable publish(int bufferSize) { validateBufferSize(bufferSize); - return OperatorPublish.create(this, bufferSize); + return NbpOperatorPublish.create(this, bufferSize); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable reduce(BiFunction reducer) { return scan(reducer).last(); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable reduce(R seed, BiFunction reducer) { return scan(seed, reducer).last(); } // Naming note, a plain scan would cause ambiguity with the value-seeded version - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable reduceWith(Supplier seedSupplier, BiFunction reducer) { return scanWith(seedSupplier, reducer).last(); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable repeat() { return repeat(Long.MAX_VALUE); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable repeat(long times) { if (times < 0) { @@ -2399,24 +2174,22 @@ public final Observable repeat(long times) { if (times == 0) { return empty(); } - return create(new PublisherRepeat(this, times)); + return create(new NbpOnSubscribeRepeat(this, times)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable repeatUntil(BooleanSupplier stop) { Objects.requireNonNull(stop, "stop is null"); - return create(new PublisherRepeatUntil(this, stop)); + return create(new NbpOnSubscribeRepeatUntil(this, stop)); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) - public final Observable repeatWhen(final Function, ? extends Publisher> handler) { + public final Observable repeatWhen(final Function, ? extends Observable> handler) { Objects.requireNonNull(handler, "handler is null"); - Function>>, Publisher> f = new Function>>, Publisher>() { + Function>>, Observable> f = new Function>>, Observable>() { @Override - public Publisher apply(Observable>> no) { + public Observable apply(Observable>> no) { return handler.apply(no.map(new Function>, Object>() { @Override public Object apply(Try> v) { @@ -2427,53 +2200,48 @@ public Object apply(Try> v) { } ; - return create(new PublisherRedo(this, f)); + return create(new NbpOnSubscribeRedo(this, f)); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) public final ConnectableObservable replay() { - return OperatorReplay.createFrom(this); + return NbpOperatorReplay.createFrom(this); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable replay(Function, ? extends Publisher> selector) { + public final Observable replay(Function, ? extends Observable> selector) { Objects.requireNonNull(selector, "selector is null"); - return OperatorReplay.multicastSelector(new Supplier>() { + return NbpOperatorReplay.multicastSelector(new Supplier>() { @Override public ConnectableObservable get() { return replay(); } }, selector); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) - public final Observable replay(Function, ? extends Publisher> selector, final int bufferSize) { + public final Observable replay(Function, ? extends Observable> selector, final int bufferSize) { Objects.requireNonNull(selector, "selector is null"); - return OperatorReplay.multicastSelector(new Supplier>() { + return NbpOperatorReplay.multicastSelector(new Supplier>() { @Override public ConnectableObservable get() { return replay(bufferSize); } }, selector); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.COMPUTATION) - public final Observable replay(Function, ? extends Publisher> selector, int bufferSize, long time, TimeUnit unit) { + public final Observable replay(Function, ? extends Observable> selector, int bufferSize, long time, TimeUnit unit) { return replay(selector, bufferSize, time, unit, Schedulers.computation()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) - public final Observable replay(Function, ? extends Publisher> selector, final int bufferSize, final long time, final TimeUnit unit, final Scheduler scheduler) { + public final Observable replay(Function, ? extends Observable> selector, final int bufferSize, final long time, final TimeUnit unit, final Scheduler scheduler) { if (bufferSize < 0) { throw new IllegalArgumentException("bufferSize < 0"); } Objects.requireNonNull(selector, "selector is null"); - return OperatorReplay.multicastSelector(new Supplier>() { + return NbpOperatorReplay.multicastSelector(new Supplier>() { @Override public ConnectableObservable get() { return replay(bufferSize, time, unit, scheduler); @@ -2481,135 +2249,119 @@ public ConnectableObservable get() { }, selector); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) - public final Observable replay(final Function, ? extends Publisher> selector, final int bufferSize, final Scheduler scheduler) { - return OperatorReplay.multicastSelector(new Supplier>() { + public final Observable replay(final Function, ? extends Observable> selector, final int bufferSize, final Scheduler scheduler) { + return NbpOperatorReplay.multicastSelector(new Supplier>() { @Override public ConnectableObservable get() { return replay(bufferSize); } }, - new Function, Publisher>() { + new Function, Observable>() { @Override - public Publisher apply(Observable t) { - return fromPublisher(selector.apply(t)).observeOn(scheduler); + public Observable apply(Observable t) { + return selector.apply(t).observeOn(scheduler); } }); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.COMPUTATION) - public final Observable replay(Function, ? extends Publisher> selector, long time, TimeUnit unit) { + public final Observable replay(Function, ? extends Observable> selector, long time, TimeUnit unit) { return replay(selector, time, unit, Schedulers.computation()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) - public final Observable replay(Function, ? extends Publisher> selector, final long time, final TimeUnit unit, final Scheduler scheduler) { + public final Observable replay(Function, ? extends Observable> selector, final long time, final TimeUnit unit, final Scheduler scheduler) { Objects.requireNonNull(selector, "selector is null"); Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return OperatorReplay.multicastSelector(new Supplier>() { + return NbpOperatorReplay.multicastSelector(new Supplier>() { @Override public ConnectableObservable get() { return replay(time, unit, scheduler); } }, selector); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) - public final Observable replay(final Function, ? extends Publisher> selector, final Scheduler scheduler) { + public final Observable replay(final Function, ? extends Observable> selector, final Scheduler scheduler) { Objects.requireNonNull(selector, "selector is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return OperatorReplay.multicastSelector(new Supplier>() { + return NbpOperatorReplay.multicastSelector(new Supplier>() { @Override public ConnectableObservable get() { return replay(); } }, - new Function, Publisher>() { + new Function, Observable>() { @Override - public Publisher apply(Observable t) { - return fromPublisher(selector.apply(t)).observeOn(scheduler); + public Observable apply(Observable t) { + return selector.apply(t).observeOn(scheduler); } }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final ConnectableObservable replay(final int bufferSize) { - return OperatorReplay.create(this, bufferSize); + return NbpOperatorReplay.create(this, bufferSize); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.COMPUTATION) public final ConnectableObservable replay(int bufferSize, long time, TimeUnit unit) { return replay(bufferSize, time, unit, Schedulers.computation()); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) public final ConnectableObservable replay(final int bufferSize, final long time, final TimeUnit unit, final Scheduler scheduler) { - Objects.requireNonNull(unit, "unit is null"); - Objects.requireNonNull(scheduler, "scheduler is null"); if (bufferSize < 0) { throw new IllegalArgumentException("bufferSize < 0"); } - return OperatorReplay.create(this, time, unit, scheduler, bufferSize); + Objects.requireNonNull(unit, "unit is null"); + Objects.requireNonNull(scheduler, "scheduler is null"); + return NbpOperatorReplay.create(this, time, unit, scheduler, bufferSize); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) public final ConnectableObservable replay(final int bufferSize, final Scheduler scheduler) { - Objects.requireNonNull(scheduler, "scheduler is null"); - return OperatorReplay.observeOn(replay(bufferSize), scheduler); + return NbpOperatorReplay.observeOn(replay(bufferSize), scheduler); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.COMPUTATION) public final ConnectableObservable replay(long time, TimeUnit unit) { return replay(time, unit, Schedulers.computation()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public final ConnectableObservable replay(final long time, final TimeUnit unit, final Scheduler scheduler) { Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return OperatorReplay.create(this, time, unit, scheduler); + return NbpOperatorReplay.create(this, time, unit, scheduler); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public final ConnectableObservable replay(final Scheduler scheduler) { Objects.requireNonNull(scheduler, "scheduler is null"); - return OperatorReplay.observeOn(replay(), scheduler); + return NbpOperatorReplay.observeOn(replay(), scheduler); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable retry() { return retry(Long.MAX_VALUE, Functions.alwaysTrue()); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) public final Observable retry(BiPredicate predicate) { Objects.requireNonNull(predicate, "predicate is null"); - return create(new PublisherRetryBiPredicate(this, predicate)); + return create(new NbpOnSubscribeRetryBiPredicate(this, predicate)); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) public final Observable retry(long times) { return retry(times, Functions.alwaysTrue()); } // Retries at most times or until the predicate returns false, whichever happens first - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable retry(long times, Predicate predicate) { if (times < 0) { @@ -2617,16 +2369,14 @@ public final Observable retry(long times, Predicate predic } Objects.requireNonNull(predicate, "predicate is null"); - return create(new PublisherRetryPredicate(this, times, predicate)); + return create(new NbpOnSubscribeRetryPredicate(this, times, predicate)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable retry(Predicate predicate) { return retry(Long.MAX_VALUE, predicate); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable retryUntil(final BooleanSupplier stop) { Objects.requireNonNull(stop, "stop is null"); @@ -2638,75 +2388,70 @@ public boolean test(Throwable e) { }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable retryWhen( - final Function, ? extends Publisher> handler) { + final Function, ? extends Observable> handler) { Objects.requireNonNull(handler, "handler is null"); - Function>>, Publisher> f = new Function>>, Publisher>() { - @Override - public Publisher apply(Observable>> no) { - Observable map = no.takeWhile(new Predicate>>() { - @Override - public boolean test(Try> e) { - return e.hasError(); - } - }).map(new Function>, Throwable>() { - @Override - public Throwable apply(Try> t) { - return t.error(); - } - }); - return handler.apply(map); + Function>>, Observable> f = new Function>>, Observable>() { + @Override + public Observable apply(Observable>> no) { + return handler.apply(no + .takeWhile(new Predicate>>() { + @Override + public boolean test(Try> e) { + return e.hasError(); + } + }) + .map(new Function>, Throwable>() { + @Override + public Throwable apply(Try> t) { + return t.error(); + } + }) + ); } } ; - return create(new PublisherRedo(this, f)); + return create(new NbpOnSubscribeRedo(this, f)); } // TODO decide if safe subscription or unsafe should be the default - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) - public final void safeSubscribe(Subscriber s) { + public final void safeSubscribe(Observer s) { Objects.requireNonNull(s, "s is null"); - if (s instanceof SafeSubscriber) { - subscribeActual(s); + if (s instanceof SafeObserver) { + subscribe(s); } else { - subscribeActual(new SafeSubscriber(s)); + subscribe(new SafeObserver(s)); } } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable sample(long period, TimeUnit unit) { return sample(period, unit, Schedulers.computation()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable sample(long period, TimeUnit unit, Scheduler scheduler) { Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new OperatorSampleTimed(period, unit, scheduler)); + return lift(new NbpOperatorSampleTimed(period, unit, scheduler)); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) - public final Observable sample(Publisher sampler) { + public final Observable sample(Observable sampler) { Objects.requireNonNull(sampler, "sampler is null"); - return lift(new OperatorSamplePublisher(sampler)); + return lift(new NbpOperatorSampleWithObservable(sampler)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable scan(BiFunction accumulator) { Objects.requireNonNull(accumulator, "accumulator is null"); - return lift(new OperatorScan(accumulator)); + return lift(new NbpOperatorScan(accumulator)); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) public final Observable scan(final R seed, BiFunction accumulator) { Objects.requireNonNull(seed, "seed is null"); @@ -2719,45 +2464,39 @@ public R get() { } // Naming note, a plain scan would cause ambiguity with the value-seeded version - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable scanWith(Supplier seedSupplier, BiFunction accumulator) { Objects.requireNonNull(seedSupplier, "seedSupplier is null"); Objects.requireNonNull(accumulator, "accumulator is null"); - return lift(new OperatorScanSeed(seedSupplier, accumulator)); + return lift(new NbpOperatorScanSeed(seedSupplier, accumulator)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) public final Observable serialize() { - return lift(new Operator() { + return lift(new NbpOperator() { @Override - public Subscriber apply(Subscriber s) { - return new SerializedSubscriber(s); + public Observer apply(Observer s) { + return new SerializedObserver(s); } }); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable share() { return publish().refCount(); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable single() { - return lift(OperatorSingle.instanceNoDefault()); + return lift(NbpOperatorSingle.instanceNoDefault()); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable single(T defaultValue) { Objects.requireNonNull(defaultValue, "defaultValue is null"); - return lift(new OperatorSingle(defaultValue)); + return lift(new NbpOperatorSingle(defaultValue)); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.NONE) public final Observable skip(long n) { // if (n < 0) { @@ -2767,17 +2506,15 @@ public final Observable skip(long n) { if (n <= 0) { return this; } - return lift(new OperatorSkip(n)); + return lift(new NbpOperatorSkip(n)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable skip(long time, TimeUnit unit, Scheduler scheduler) { // TODO consider inlining this behavior return skipUntil(timer(time, unit, scheduler)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable skipLast(int n) { if (n < 0) { @@ -2786,34 +2523,29 @@ public final Observable skipLast(int n) { if (n == 0) { return this; } - return lift(new OperatorSkipLast(n)); + return lift(new NbpOperatorSkipLast(n)); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.TRAMPOLINE) public final Observable skipLast(long time, TimeUnit unit) { return skipLast(time, unit, Schedulers.trampoline(), false, bufferSize()); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.TRAMPOLINE) public final Observable skipLast(long time, TimeUnit unit, boolean delayError) { return skipLast(time, unit, Schedulers.trampoline(), delayError, bufferSize()); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable skipLast(long time, TimeUnit unit, Scheduler scheduler) { return skipLast(time, unit, scheduler, false, bufferSize()); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable skipLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError) { return skipLast(time, unit, scheduler, delayError, bufferSize()); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable skipLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { Objects.requireNonNull(unit, "unit is null"); @@ -2821,40 +2553,35 @@ public final Observable skipLast(long time, TimeUnit unit, Scheduler schedule validateBufferSize(bufferSize); // the internal buffer holds pairs of (timestamp, value) so double the default buffer size int s = bufferSize << 1; - return lift(new OperatorSkipLastTimed(time, unit, scheduler, s, delayError)); + return lift(new NbpOperatorSkipLastTimed(time, unit, scheduler, s, delayError)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable skipUntil(Publisher other) { + public final Observable skipUntil(Observable other) { Objects.requireNonNull(other, "other is null"); - return lift(new OperatorSkipUntil(other)); + return lift(new NbpOperatorSkipUntil(other)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable skipWhile(Predicate predicate) { Objects.requireNonNull(predicate, "predicate is null"); - return lift(new OperatorSkipWhile(predicate)); + return lift(new NbpOperatorSkipWhile(predicate)); } - + @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable startWith(Iterable values) { return concatArray(fromIterable(values), this); } - + @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable startWith(Publisher other) { + public final Observable startWith(Observable other) { Objects.requireNonNull(other, "other is null"); return concatArray(other, this); } - + @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable startWith(T value) { Objects.requireNonNull(value, "value is null"); @@ -2862,7 +2589,6 @@ public final Observable startWith(T value) { } @SuppressWarnings("unchecked") - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable startWithArray(T... values) { Observable fromArray = fromArray(values); @@ -2872,134 +2598,71 @@ public final Observable startWithArray(T... values) { return concatArray(fromArray, this); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Disposable subscribe() { - return subscribe(Functions.emptyConsumer(), RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), new Consumer() { - @Override - public void accept(Subscription s) { - s.request(Long.MAX_VALUE); - } - }); + return subscribe(Functions.emptyConsumer(), RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), Functions.emptyConsumer()); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Disposable subscribe(Consumer onNext) { - return subscribe(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), new Consumer() { - @Override - public void accept(Subscription s) { - s.request(Long.MAX_VALUE); - } - }); + return subscribe(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), Functions.emptyConsumer()); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Disposable subscribe(Consumer onNext, Consumer onError) { - return subscribe(onNext, onError, Functions.emptyRunnable(), new Consumer() { - @Override - public void accept(Subscription s) { - s.request(Long.MAX_VALUE); - } - }); + return subscribe(onNext, onError, Functions.emptyRunnable(), Functions.emptyConsumer()); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Disposable subscribe(Consumer onNext, Consumer onError, Runnable onComplete) { - return subscribe(onNext, onError, onComplete, new Consumer() { - @Override - public void accept(Subscription s) { - s.request(Long.MAX_VALUE); - } - }); + return subscribe(onNext, onError, onComplete, Functions.emptyConsumer()); } - - @BackpressureSupport(BackpressureKind.SPECIAL) + @SchedulerSupport(SchedulerKind.NONE) public final Disposable subscribe(Consumer onNext, Consumer onError, - Runnable onComplete, Consumer onSubscribe) { + Runnable onComplete, Consumer onSubscribe) { Objects.requireNonNull(onNext, "onNext is null"); Objects.requireNonNull(onError, "onError is null"); Objects.requireNonNull(onComplete, "onComplete is null"); Objects.requireNonNull(onSubscribe, "onSubscribe is null"); - LambdaSubscriber ls = new LambdaSubscriber(onNext, onError, onComplete, onSubscribe); + NbpLambdaSubscriber ls = new NbpLambdaSubscriber(onNext, onError, onComplete, onSubscribe); unsafeSubscribe(ls); return ls; } - // TODO decide if safe subscription or unsafe should be the default - @BackpressureSupport(BackpressureKind.SPECIAL) - @SchedulerSupport(SchedulerKind.NONE) - @Override - public final void subscribe(Subscriber s) { - Objects.requireNonNull(s, "s is null"); - subscribeActual(s); - } - - private void subscribeActual(Subscriber s) { - try { - s = RxJavaPlugins.onSubscribe(s); - - if (s == null) { - throw new NullPointerException("Plugin returned null Subscriber"); - } - - onSubscribe.subscribe(s); - } catch (NullPointerException e) { - throw e; - } catch (Throwable e) { - // TODO throw if fatal? - // can't call onError because no way to know if a Subscription has been set or not - // can't call onSubscribe because the call might have set a Subscription already - RxJavaPlugins.onError(e); - - NullPointerException npe = new NullPointerException("Actually not, but can't throw other exceptions due to RS"); - npe.initCause(e); - throw npe; - } - } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) - @SchedulerSupport(SchedulerKind.CUSTOM) - public final Observable subscribeOn(Scheduler scheduler) { - return subscribeOn(scheduler, true); + public final void subscribe(Observer subscriber) { + Objects.requireNonNull(subscriber, "subscriber is null"); + onSubscribe.accept(subscriber); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.CUSTOM) - public final Observable subscribeOn(Scheduler scheduler, boolean requestOn) { + public final Observable subscribeOn(Scheduler scheduler) { Objects.requireNonNull(scheduler, "scheduler is null"); - return create(new PublisherSubscribeOn(this, scheduler, requestOn)); + return create(new NbpOnSubscribeSubscribeOn(this, scheduler)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable switchIfEmpty(Publisher other) { + public final Observable switchIfEmpty(Observable other) { Objects.requireNonNull(other, "other is null"); - return lift(new OperatorSwitchIfEmpty(other)); + return lift(new NbpOperatorSwitchIfEmpty(other)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable switchMap(Function> mapper) { + public final Observable switchMap(Function> mapper) { return switchMap(mapper, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable switchMap(Function> mapper, int bufferSize) { + public final Observable switchMap(Function> mapper, int bufferSize) { Objects.requireNonNull(mapper, "mapper is null"); validateBufferSize(bufferSize); - return lift(new OperatorSwitchMap(mapper, bufferSize)); + return lift(new NbpOperatorSwitchMap(mapper, bufferSize)); } - @BackpressureSupport(BackpressureKind.SPECIAL) // may trigger UNBOUNDED_IN @SchedulerSupport(SchedulerKind.NONE) public final Observable take(long n) { if (n < 0) { @@ -3010,23 +2673,20 @@ public final Observable take(long n) { // return lift(s -> CancelledSubscriber.INSTANCE); return empty(); } - return lift(new OperatorTake(n)); + return lift(new NbpOperatorTake(n)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) public final Observable take(long time, TimeUnit unit, Scheduler scheduler) { // TODO consider inlining this behavior return takeUntil(timer(time, unit, scheduler)); } - - @BackpressureSupport(BackpressureKind.SPECIAL) // may trigger UNBOUNDED_IN + @SchedulerSupport(SchedulerKind.NONE) public final Observable takeFirst(Predicate predicate) { return filter(predicate).take(1); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable takeLast(int n) { if (n < 0) { @@ -3036,24 +2696,21 @@ public final Observable takeLast(int n) { return ignoreElements(); } else if (n == 1) { - return lift(OperatorTakeLastOne.instance()); + return lift(NbpOperatorTakeLastOne.instance()); } - return lift(new OperatorTakeLast(n)); + return lift(new NbpOperatorTakeLast(n)); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) public final Observable takeLast(long count, long time, TimeUnit unit) { return takeLast(count, time, unit, Schedulers.trampoline(), false, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable takeLast(long count, long time, TimeUnit unit, Scheduler scheduler) { return takeLast(count, time, unit, scheduler, false, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable takeLast(long count, long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { Objects.requireNonNull(unit, "unit is null"); @@ -3062,244 +2719,210 @@ public final Observable takeLast(long count, long time, TimeUnit unit, Schedu if (count < 0) { throw new IndexOutOfBoundsException("count >= 0 required but it was " + count); } - return lift(new OperatorTakeLastTimed(count, time, unit, scheduler, bufferSize, delayError)); + return lift(new NbpOperatorTakeLastTimed(count, time, unit, scheduler, bufferSize, delayError)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.TRAMPOLINE) public final Observable takeLast(long time, TimeUnit unit) { return takeLast(time, unit, Schedulers.trampoline(), false, bufferSize()); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) public final Observable takeLast(long time, TimeUnit unit, boolean delayError) { return takeLast(time, unit, Schedulers.trampoline(), delayError, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable takeLast(long time, TimeUnit unit, Scheduler scheduler) { return takeLast(time, unit, scheduler, false, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable takeLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError) { return takeLast(time, unit, scheduler, delayError, bufferSize()); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable takeLast(long time, TimeUnit unit, Scheduler scheduler, boolean delayError, int bufferSize) { return takeLast(Long.MAX_VALUE, time, unit, scheduler, delayError, bufferSize); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable> takeLastBuffer(int count) { return takeLast(count).toList(); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.TRAMPOLINE) public final Observable> takeLastBuffer(int count, long time, TimeUnit unit) { return takeLast(count, time, unit).toList(); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> takeLastBuffer(int count, long time, TimeUnit unit, Scheduler scheduler) { return takeLast(count, time, unit, scheduler).toList(); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) public final Observable> takeLastBuffer(long time, TimeUnit unit) { return takeLast(time, unit).toList(); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> takeLastBuffer(long time, TimeUnit unit, Scheduler scheduler) { return takeLast(time, unit, scheduler).toList(); } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) + + @SchedulerSupport(SchedulerKind.NONE) + public final Observable takeUntil(Observable other) { + Objects.requireNonNull(other, "other is null"); + return lift(new NbpOperatorTakeUntil(other)); + } + @SchedulerSupport(SchedulerKind.NONE) public final Observable takeUntil(Predicate predicate) { Objects.requireNonNull(predicate, "predicate is null"); - return lift(new OperatorTakeUntilPredicate(predicate)); + return lift(new NbpOperatorTakeUntilPredicate(predicate)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) - @SchedulerSupport(SchedulerKind.NONE) - public final Observable takeUntil(Publisher other) { - Objects.requireNonNull(other, "other is null"); - return lift(new OperatorTakeUntil(other)); - } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) public final Observable takeWhile(Predicate predicate) { Objects.requireNonNull(predicate, "predicate is null"); - return lift(new OperatorTakeWhile(predicate)); + return lift(new NbpOperatorTakeWhile(predicate)); } - - @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable throttleFirst(long windowDuration, TimeUnit unit) { return throttleFirst(windowDuration, unit, Schedulers.computation()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable throttleFirst(long skipDuration, TimeUnit unit, Scheduler scheduler) { Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new OperatorThrottleFirstTimed(skipDuration, unit, scheduler)); + return lift(new NbpOperatorThrottleFirstTimed(skipDuration, unit, scheduler)); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable throttleLast(long intervalDuration, TimeUnit unit) { return sample(intervalDuration, unit); } - - @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable throttleLast(long intervalDuration, TimeUnit unit, Scheduler scheduler) { return sample(intervalDuration, unit, scheduler); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable throttleWithTimeout(long timeout, TimeUnit unit) { return debounce(timeout, unit); } - - @BackpressureSupport(BackpressureKind.ERROR) + @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable throttleWithTimeout(long timeout, TimeUnit unit, Scheduler scheduler) { return debounce(timeout, unit, scheduler); } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) public final Observable> timeInterval() { return timeInterval(TimeUnit.MILLISECONDS, Schedulers.trampoline()); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> timeInterval(Scheduler scheduler) { return timeInterval(TimeUnit.MILLISECONDS, scheduler); } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.TRAMPOLINE) public final Observable> timeInterval(TimeUnit unit) { return timeInterval(unit, Schedulers.trampoline()); } - - @BackpressureSupport(BackpressureKind.PASS_THROUGH) + @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> timeInterval(TimeUnit unit, Scheduler scheduler) { Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new OperatorTimeInterval(unit, scheduler)); + return lift(new NbpOperatorTimeInterval(unit, scheduler)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) - public final Observable timeout(Function> timeoutSelector) { + public final Observable timeout(Function> timeoutSelector) { return timeout0(null, timeoutSelector, null); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable timeout(Function> timeoutSelector, Observable other) { + public final Observable timeout(Function> timeoutSelector, Observable other) { Objects.requireNonNull(other, "other is null"); return timeout0(null, timeoutSelector, other); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable timeout(long timeout, TimeUnit timeUnit) { return timeout0(timeout, timeUnit, null, Schedulers.computation()); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable timeout(long timeout, TimeUnit timeUnit, Observable other) { Objects.requireNonNull(other, "other is null"); return timeout0(timeout, timeUnit, other, Schedulers.computation()); } - - @BackpressureSupport(BackpressureKind.FULL) + @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable timeout(long timeout, TimeUnit timeUnit, Observable other, Scheduler scheduler) { Objects.requireNonNull(other, "other is null"); return timeout0(timeout, timeUnit, other, scheduler); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable timeout(long timeout, TimeUnit timeUnit, Scheduler scheduler) { return timeout0(timeout, timeUnit, null, scheduler); } - public final Observable timeout(Supplier> firstTimeoutSelector, - Function> timeoutSelector) { + public final Observable timeout(Supplier> firstTimeoutSelector, + Function> timeoutSelector) { Objects.requireNonNull(firstTimeoutSelector, "firstTimeoutSelector is null"); return timeout0(firstTimeoutSelector, timeoutSelector, null); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable timeout( - Supplier> firstTimeoutSelector, - Function> timeoutSelector, - Publisher other) { + Supplier> firstTimeoutSelector, + Function> timeoutSelector, + Observable other) { Objects.requireNonNull(firstTimeoutSelector, "firstTimeoutSelector is null"); Objects.requireNonNull(other, "other is null"); return timeout0(firstTimeoutSelector, timeoutSelector, other); } - + private Observable timeout0(long timeout, TimeUnit timeUnit, Observable other, Scheduler scheduler) { Objects.requireNonNull(timeUnit, "timeUnit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new OperatorTimeoutTimed(timeout, timeUnit, scheduler, other)); + return lift(new NbpOperatorTimeoutTimed(timeout, timeUnit, scheduler, other)); } private Observable timeout0( - Supplier> firstTimeoutSelector, - Function> timeoutSelector, - Publisher other) { + Supplier> firstTimeoutSelector, + Function> timeoutSelector, + Observable other) { Objects.requireNonNull(timeoutSelector, "timeoutSelector is null"); - return lift(new OperatorTimeout(firstTimeoutSelector, timeoutSelector, other)); + return lift(new NbpOperatorTimeout(firstTimeoutSelector, timeoutSelector, other)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.TRAMPOLINE) public final Observable> timestamp() { return timestamp(TimeUnit.MILLISECONDS, Schedulers.trampoline()); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> timestamp(Scheduler scheduler) { return timestamp(TimeUnit.MILLISECONDS, scheduler); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.TRAMPOLINE) public final Observable> timestamp(TimeUnit unit) { return timestamp(unit, Schedulers.trampoline()); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> timestamp(final TimeUnit unit, final Scheduler scheduler) { Objects.requireNonNull(unit, "unit is null"); @@ -3312,32 +2935,26 @@ public Timed apply(T v) { }); } - // TODO generics - @BackpressureSupport(BackpressureKind.SPECIAL) - @SchedulerSupport(SchedulerKind.NONE) - public final R to(Function, R> converter) { - return converter.apply(this); + public final R to(Function, R> convert) { + return convert.apply(this); } - @BackpressureSupport(BackpressureKind.SPECIAL) @SchedulerSupport(SchedulerKind.NONE) public final BlockingObservable toBlocking() { return BlockingObservable.from(this); } - - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) public final Observable> toList() { - return lift(OperatorToList.defaultInstance()); + return lift(NbpOperatorToList.defaultInstance()); } - - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) public final Observable> toList(final int capacityHint) { if (capacityHint <= 0) { throw new IllegalArgumentException("capacityHint > 0 required but it was " + capacityHint); } - return lift(new OperatorToList>(new Supplier>() { + return lift(new NbpOperatorToList>(new Supplier>() { @Override public List get() { return new ArrayList(capacityHint); @@ -3345,17 +2962,14 @@ public List get() { })); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final > Observable toList(Supplier collectionSupplier) { Objects.requireNonNull(collectionSupplier, "collectionSupplier is null"); - return lift(new OperatorToList(collectionSupplier)); + return lift(new NbpOperatorToList(collectionSupplier)); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable> toMap(final Function keySelector) { - Objects.requireNonNull(keySelector, "keySelector is null"); return collect(new Supplier>() { @Override public Map get() { @@ -3369,10 +2983,11 @@ public void accept(Map m, T t) { } }); } - - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) - public final Observable> toMap(final Function keySelector, final Function valueSelector) { + public final Observable> toMap( + final Function keySelector, + final Function valueSelector) { Objects.requireNonNull(keySelector, "keySelector is null"); Objects.requireNonNull(valueSelector, "valueSelector is null"); return collect(new Supplier>() { @@ -3390,13 +3005,11 @@ public void accept(Map m, T t) { }); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) - public final Observable> toMap(final Function keySelector, + public final Observable> toMap( + final Function keySelector, final Function valueSelector, - final Supplier> mapSupplier) { - Objects.requireNonNull(keySelector, "keySelector is null"); - Objects.requireNonNull(valueSelector, "valueSelector is null"); + Supplier> mapSupplier) { return collect(mapSupplier, new BiConsumer, T>() { @Override public void accept(Map m, T t) { @@ -3406,11 +3019,11 @@ public void accept(Map m, T t) { } }); } - - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) public final Observable>> toMultimap(Function keySelector) { - Function valueSelector = Functions.identity(); + @SuppressWarnings({ "rawtypes", "unchecked" }) + Function valueSelector = (Function)Functions.identity(); Supplier>> mapSupplier = new Supplier>>() { @Override public Map> get() { @@ -3425,8 +3038,7 @@ public Collection apply(K k) { }; return toMultimap(keySelector, valueSelector, mapSupplier, collectionFactory); } - - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) + @SchedulerSupport(SchedulerKind.NONE) public final Observable>> toMultimap(Function keySelector, Function valueSelector) { Supplier>> mapSupplier = new Supplier>>() { @@ -3444,7 +3056,6 @@ public Collection apply(K k) { return toMultimap(keySelector, valueSelector, mapSupplier, collectionFactory); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) @SuppressWarnings("unchecked") public final Observable>> toMultimap( @@ -3474,7 +3085,6 @@ public void accept(Map> m, T t) { }); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable>> toMultimap( Function keySelector, @@ -3489,31 +3099,101 @@ public Collection apply(K k) { }); } - @BackpressureSupport(BackpressureKind.NONE) - @SchedulerSupport(SchedulerKind.NONE) - public final NbpObservable toNbpObservable() { - return NbpObservable.fromPublisher(this); + public final Flowable toObservable(BackpressureStrategy strategy) { + Flowable o = Flowable.create(new Publisher() { + @Override + public void subscribe(final Subscriber s) { + Observable.this.subscribe(new Observer() { + + @Override + public void onComplete() { + s.onComplete(); + } + + @Override + public void onError(Throwable e) { + s.onError(e); + } + + @Override + public void onNext(T value) { + s.onNext(value); + } + + @Override + public void onSubscribe(final Disposable d) { + s.onSubscribe(new Subscription() { + + @Override + public void cancel() { + d.dispose(); + } + + @Override + public void request(long n) { + // no backpressure so nothing we can do about this + } + + }); + } + + }); + } + }); + + switch (strategy) { + case BUFFER: + return o.onBackpressureBuffer(); + case DROP: + return o.onBackpressureDrop(); + case LATEST: + return o.onBackpressureLatest(); + default: + return o; + } } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Single toSingle() { - return Single.fromPublisher(this); + return Single.create(new SingleOnSubscribe() { + @Override + public void accept(final SingleSubscriber s) { + Observable.this.subscribe(new Observer() { + T last; + @Override + public void onSubscribe(Disposable d) { + s.onSubscribe(d); + } + @Override + public void onNext(T value) { + last = value; + } + @Override + public void onError(Throwable e) { + s.onError(e); + } + @Override + public void onComplete() { + T v = last; + last = null; + if (v != null) { + s.onSuccess(v); + } else { + s.onError(new NoSuchElementException()); + } + } + + + }); + } + }); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) - @SuppressWarnings({ "unchecked", "rawtypes"}) public final Observable> toSortedList() { - return toSortedList(new Comparator() { - @Override - public int compare(T o1, T o2) { - return ((Comparable)o1).compareTo(o2); - } - }); + return toSortedList(Functions.naturalOrder()); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable> toSortedList(final Comparator comparator) { Objects.requireNonNull(comparator, "comparator is null"); @@ -3526,7 +3206,6 @@ public List apply(List v) { }); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) public final Observable> toSortedList(final Comparator comparator, int capacityHint) { Objects.requireNonNull(comparator, "comparator is null"); @@ -3539,46 +3218,34 @@ public List apply(List v) { }); } - @BackpressureSupport(BackpressureKind.UNBOUNDED_IN) @SchedulerSupport(SchedulerKind.NONE) - @SuppressWarnings({ "unchecked", "rawtypes"}) public final Observable> toSortedList(int capacityHint) { - return toSortedList(new Comparator() { - @Override - public int compare(T o1, T o2) { - return ((Comparable)o1).compareTo(o2); - } - }, capacityHint); + return toSortedList(Functions.naturalOrder(), capacityHint); } - @BackpressureSupport(BackpressureKind.SPECIAL) @SchedulerSupport(SchedulerKind.NONE) // TODO decide if safe subscription or unsafe should be the default - public final void unsafeSubscribe(Subscriber s) { + public final void unsafeSubscribe(Observer s) { Objects.requireNonNull(s, "s is null"); - subscribeActual(s); + subscribe(s); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable unsubscribeOn(Scheduler scheduler) { Objects.requireNonNull(scheduler, "scheduler is null"); - return lift(new OperatorUnsubscribeOn(scheduler)); + return lift(new NbpOperatorUnsubscribeOn(scheduler)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable> window(long count) { return window(count, count, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable> window(long count, long skip) { return window(count, skip, bufferSize()); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable> window(long count, long skip, int bufferSize) { if (skip <= 0) { @@ -3588,72 +3255,62 @@ public final Observable> window(long count, long skip, int bufferS throw new IllegalArgumentException("count > 0 required but it was " + count); } validateBufferSize(bufferSize); - return lift(new OperatorWindow(count, skip, bufferSize)); + return lift(new NbpOperatorWindow(count, skip, bufferSize)); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable> window(long timespan, long timeskip, TimeUnit unit) { return window(timespan, timeskip, unit, Schedulers.computation(), bufferSize()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> window(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler) { return window(timespan, timeskip, unit, scheduler, bufferSize()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> window(long timespan, long timeskip, TimeUnit unit, Scheduler scheduler, int bufferSize) { validateBufferSize(bufferSize); Objects.requireNonNull(scheduler, "scheduler is null"); Objects.requireNonNull(unit, "unit is null"); - return lift(new OperatorWindowTimed(timespan, timeskip, unit, scheduler, Long.MAX_VALUE, bufferSize, false)); + return lift(new NbpOperatorWindowTimed(timespan, timeskip, unit, scheduler, Long.MAX_VALUE, bufferSize, false)); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable> window(long timespan, TimeUnit unit) { return window(timespan, unit, Schedulers.computation(), Long.MAX_VALUE, false); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable> window(long timespan, TimeUnit unit, long count) { return window(timespan, unit, Schedulers.computation(), count, false); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.COMPUTATION) public final Observable> window(long timespan, TimeUnit unit, long count, boolean restart) { return window(timespan, unit, Schedulers.computation(), count, restart); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> window(long timespan, TimeUnit unit, Scheduler scheduler) { return window(timespan, unit, scheduler, Long.MAX_VALUE, false); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> window(long timespan, TimeUnit unit, Scheduler scheduler, long count) { return window(timespan, unit, scheduler, count, false); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> window(long timespan, TimeUnit unit, Scheduler scheduler, long count, boolean restart) { return window(timespan, unit, scheduler, count, restart, bufferSize()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.CUSTOM) public final Observable> window( long timespan, TimeUnit unit, Scheduler scheduler, @@ -3664,87 +3321,77 @@ public final Observable> window( if (count <= 0) { throw new IllegalArgumentException("count > 0 required but it was " + count); } - return lift(new OperatorWindowTimed(timespan, timespan, unit, scheduler, count, bufferSize, restart)); + return lift(new NbpOperatorWindowTimed(timespan, timespan, unit, scheduler, count, bufferSize, restart)); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) - public final Observable> window(Publisher boundary) { + public final Observable> window(Observable boundary) { return window(boundary, bufferSize()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) - public final Observable> window(Publisher boundary, int bufferSize) { + public final Observable> window(Observable boundary, int bufferSize) { Objects.requireNonNull(boundary, "boundary is null"); - return lift(new OperatorWindowBoundary(boundary, bufferSize)); + return lift(new NbpOperatorWindowBoundary(boundary, bufferSize)); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) public final Observable> window( - Publisher windowOpen, - Function> windowClose) { + Observable windowOpen, + Function> windowClose) { return window(windowOpen, windowClose, bufferSize()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) public final Observable> window( - Publisher windowOpen, - Function> windowClose, int bufferSize) { + Observable windowOpen, + Function> windowClose, int bufferSize) { Objects.requireNonNull(windowOpen, "windowOpen is null"); Objects.requireNonNull(windowClose, "windowClose is null"); - return lift(new OperatorWindowBoundarySelector(windowOpen, windowClose, bufferSize)); + return lift(new NbpOperatorWindowBoundarySelector(windowOpen, windowClose, bufferSize)); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) - public final Observable> window(Supplier> boundary) { + public final Observable> window(Supplier> boundary) { return window(boundary, bufferSize()); } - @BackpressureSupport(BackpressureKind.ERROR) @SchedulerSupport(SchedulerKind.NONE) - public final Observable> window(Supplier> boundary, int bufferSize) { + public final Observable> window(Supplier> boundary, int bufferSize) { Objects.requireNonNull(boundary, "boundary is null"); - return lift(new OperatorWindowBoundarySupplier(boundary, bufferSize)); + return lift(new NbpOperatorWindowBoundarySupplier(boundary, bufferSize)); } - @BackpressureSupport(BackpressureKind.PASS_THROUGH) @SchedulerSupport(SchedulerKind.NONE) - public final Observable withLatestFrom(Publisher other, BiFunction combiner) { + public final Observable withLatestFrom(Observable other, BiFunction combiner) { Objects.requireNonNull(other, "other is null"); Objects.requireNonNull(combiner, "combiner is null"); - return lift(new OperatorWithLatestFrom(combiner, other)); + return lift(new NbpOperatorWithLatestFrom(combiner, other)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) public final Observable zipWith(Iterable other, BiFunction zipper) { Objects.requireNonNull(other, "other is null"); Objects.requireNonNull(zipper, "zipper is null"); - return create(new PublisherZipIterable(this, other, zipper)); + return create(new NbpOnSubscribeZipIterable(this, other, zipper)); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable zipWith(Publisher other, BiFunction zipper) { + public final Observable zipWith(Observable other, BiFunction zipper) { Objects.requireNonNull(other, "other is null"); return zip(this, other, zipper); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable zipWith(Publisher other, BiFunction zipper, boolean delayError) { + public final Observable zipWith(Observable other, BiFunction zipper, boolean delayError) { return zip(this, other, zipper, delayError); } - @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerKind.NONE) - public final Observable zipWith(Publisher other, BiFunction zipper, boolean delayError, int bufferSize) { + public final Observable zipWith(Observable other, BiFunction zipper, boolean delayError, int bufferSize) { return zip(this, other, zipper, delayError, bufferSize); } -} \ No newline at end of file + + } \ No newline at end of file diff --git a/src/main/java/io/reactivex/Observer.java b/src/main/java/io/reactivex/Observer.java index 36bf722a4f..3d9e134f5e 100644 --- a/src/main/java/io/reactivex/Observer.java +++ b/src/main/java/io/reactivex/Observer.java @@ -13,40 +13,16 @@ package io.reactivex; -import org.reactivestreams.*; +import io.reactivex.disposables.Disposable; -import io.reactivex.internal.subscriptions.SubscriptionHelper; - -public abstract class Observer implements Subscriber { - private Subscription s; - @Override - public final void onSubscribe(Subscription s) { - if (SubscriptionHelper.validateSubscription(this.s, s)) { - return; - } - this.s = s; - onStart(); - } +public interface Observer { - protected final Subscription subscription() { - return s; - } + void onSubscribe(Disposable d); + + void onNext(T value); - protected final void request(long n) { - subscription().request(n); - } + void onError(Throwable e); - protected final void cancel() { - subscription().cancel(); - } - /** - * Called once the subscription has been set on this observer; override this - * to perform initialization or issue an initial request. - *

- * The default implementation requests {@link Long#MAX_VALUE}. - */ - protected void onStart() { - request(Long.MAX_VALUE); - } + void onComplete(); -} +} \ No newline at end of file diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 617d0505ec..c9eaa4ec96 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -23,7 +23,7 @@ import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.internal.functions.*; +import io.reactivex.internal.functions.Functions; import io.reactivex.internal.functions.Objects; import io.reactivex.internal.operators.single.*; import io.reactivex.internal.subscriptions.*; @@ -224,11 +224,11 @@ public void onError(Throwable e) { }); } - public static Observable concat(Iterable> sources) { - return concat(Observable.fromIterable(sources)); + public static Flowable concat(Iterable> sources) { + return concat(Flowable.fromIterable(sources)); } - public static Observable concat(Observable> sources) { + public static Flowable concat(Flowable> sources) { return sources.concatMap(new Function, Publisher>() { @Override public Publisher apply(Single v){ @@ -238,27 +238,27 @@ public Publisher apply(Single v){ } @SuppressWarnings("unchecked") - public static Observable concat( + public static Flowable concat( Single s1, Single s2 ) { Objects.requireNonNull(s1, "s1 is null"); Objects.requireNonNull(s2, "s2 is null"); - return concat(Observable.fromArray(s1, s2)); + return concat(Flowable.fromArray(s1, s2)); } @SuppressWarnings("unchecked") - public static Observable concat( + public static Flowable concat( Single s1, Single s2, Single s3 ) { Objects.requireNonNull(s1, "s1 is null"); Objects.requireNonNull(s2, "s2 is null"); Objects.requireNonNull(s3, "s3 is null"); - return concat(Observable.fromArray(s1, s2, s3)); + return concat(Flowable.fromArray(s1, s2, s3)); } @SuppressWarnings("unchecked") - public static Observable concat( + public static Flowable concat( Single s1, Single s2, Single s3, Single s4 ) { @@ -266,11 +266,11 @@ public static Observable concat( Objects.requireNonNull(s2, "s2 is null"); Objects.requireNonNull(s3, "s3 is null"); Objects.requireNonNull(s4, "s4 is null"); - return concat(Observable.fromArray(s1, s2, s3, s4)); + return concat(Flowable.fromArray(s1, s2, s3, s4)); } @SuppressWarnings("unchecked") - public static Observable concat( + public static Flowable concat( Single s1, Single s2, Single s3, Single s4, Single s5 @@ -280,11 +280,11 @@ public static Observable concat( Objects.requireNonNull(s3, "s3 is null"); Objects.requireNonNull(s4, "s4 is null"); Objects.requireNonNull(s5, "s5 is null"); - return concat(Observable.fromArray(s1, s2, s3, s4, s5)); + return concat(Flowable.fromArray(s1, s2, s3, s4, s5)); } @SuppressWarnings("unchecked") - public static Observable concat( + public static Flowable concat( Single s1, Single s2, Single s3, Single s4, Single s5, Single s6 @@ -295,11 +295,11 @@ public static Observable concat( Objects.requireNonNull(s4, "s4 is null"); Objects.requireNonNull(s5, "s5 is null"); Objects.requireNonNull(s6, "s6 is null"); - return concat(Observable.fromArray(s1, s2, s3, s4, s5, s6)); + return concat(Flowable.fromArray(s1, s2, s3, s4, s5, s6)); } @SuppressWarnings("unchecked") - public static Observable concat( + public static Flowable concat( Single s1, Single s2, Single s3, Single s4, Single s5, Single s6, @@ -312,11 +312,11 @@ public static Observable concat( Objects.requireNonNull(s5, "s5 is null"); Objects.requireNonNull(s6, "s6 is null"); Objects.requireNonNull(s7, "s7 is null"); - return concat(Observable.fromArray(s1, s2, s3, s4, s5, s6, s7)); + return concat(Flowable.fromArray(s1, s2, s3, s4, s5, s6, s7)); } @SuppressWarnings("unchecked") - public static Observable concat( + public static Flowable concat( Single s1, Single s2, Single s3, Single s4, Single s5, Single s6, @@ -330,11 +330,11 @@ public static Observable concat( Objects.requireNonNull(s6, "s6 is null"); Objects.requireNonNull(s7, "s7 is null"); Objects.requireNonNull(s8, "s8 is null"); - return concat(Observable.fromArray(s1, s2, s3, s4, s5, s6, s7, s8)); + return concat(Flowable.fromArray(s1, s2, s3, s4, s5, s6, s7, s8)); } @SuppressWarnings("unchecked") - public static Observable concat( + public static Flowable concat( Single s1, Single s2, Single s3, Single s4, Single s5, Single s6, @@ -350,7 +350,7 @@ public static Observable concat( Objects.requireNonNull(s7, "s7 is null"); Objects.requireNonNull(s8, "s8 is null"); Objects.requireNonNull(s9, "s9 is null"); - return concat(Observable.fromArray(s1, s2, s3, s4, s5, s6, s7, s8, s9)); + return concat(Flowable.fromArray(s1, s2, s3, s4, s5, s6, s7, s8, s9)); } public static Single create(SingleOnSubscribe onSubscribe) { @@ -439,19 +439,19 @@ public void accept(SingleSubscriber s) { } public static Single fromFuture(Future future) { - return Observable.fromFuture(future).toSingle(); + return Flowable.fromFuture(future).toSingle(); } public static Single fromFuture(Future future, long timeout, TimeUnit unit) { - return Observable.fromFuture(future, timeout, unit).toSingle(); + return Flowable.fromFuture(future, timeout, unit).toSingle(); } public static Single fromFuture(Future future, long timeout, TimeUnit unit, Scheduler scheduler) { - return Observable.fromFuture(future, timeout, unit, scheduler).toSingle(); + return Flowable.fromFuture(future, timeout, unit, scheduler).toSingle(); } public static Single fromFuture(Future future, Scheduler scheduler) { - return Observable.fromFuture(future, scheduler).toSingle(); + return Flowable.fromFuture(future, scheduler).toSingle(); } public static Single fromPublisher(final Publisher publisher) { @@ -505,11 +505,11 @@ public void accept(SingleSubscriber s) { }); } - public static Observable merge(Iterable> sources) { - return merge(Observable.fromIterable(sources)); + public static Flowable merge(Iterable> sources) { + return merge(Flowable.fromIterable(sources)); } - public static Observable merge(Observable> sources) { + public static Flowable merge(Flowable> sources) { return sources.flatMap(new Function, Publisher>() { @Override public Publisher apply(Single v){ @@ -524,27 +524,27 @@ public static Single merge(Single> source) } @SuppressWarnings("unchecked") - public static Observable merge( + public static Flowable merge( Single s1, Single s2 ) { Objects.requireNonNull(s1, "s1 is null"); Objects.requireNonNull(s2, "s2 is null"); - return merge(Observable.fromArray(s1, s2)); + return merge(Flowable.fromArray(s1, s2)); } @SuppressWarnings("unchecked") - public static Observable merge( + public static Flowable merge( Single s1, Single s2, Single s3 ) { Objects.requireNonNull(s1, "s1 is null"); Objects.requireNonNull(s2, "s2 is null"); Objects.requireNonNull(s3, "s3 is null"); - return merge(Observable.fromArray(s1, s2, s3)); + return merge(Flowable.fromArray(s1, s2, s3)); } @SuppressWarnings("unchecked") - public static Observable merge( + public static Flowable merge( Single s1, Single s2, Single s3, Single s4 ) { @@ -552,11 +552,11 @@ public static Observable merge( Objects.requireNonNull(s2, "s2 is null"); Objects.requireNonNull(s3, "s3 is null"); Objects.requireNonNull(s4, "s4 is null"); - return merge(Observable.fromArray(s1, s2, s3, s4)); + return merge(Flowable.fromArray(s1, s2, s3, s4)); } @SuppressWarnings("unchecked") - public static Observable merge( + public static Flowable merge( Single s1, Single s2, Single s3, Single s4, Single s5 @@ -566,11 +566,11 @@ public static Observable merge( Objects.requireNonNull(s3, "s3 is null"); Objects.requireNonNull(s4, "s4 is null"); Objects.requireNonNull(s5, "s5 is null"); - return merge(Observable.fromArray(s1, s2, s3, s4, s5)); + return merge(Flowable.fromArray(s1, s2, s3, s4, s5)); } @SuppressWarnings("unchecked") - public static Observable merge( + public static Flowable merge( Single s1, Single s2, Single s3, Single s4, Single s5, Single s6 @@ -581,11 +581,11 @@ public static Observable merge( Objects.requireNonNull(s4, "s4 is null"); Objects.requireNonNull(s5, "s5 is null"); Objects.requireNonNull(s6, "s6 is null"); - return merge(Observable.fromArray(s1, s2, s3, s4, s5, s6)); + return merge(Flowable.fromArray(s1, s2, s3, s4, s5, s6)); } @SuppressWarnings("unchecked") - public static Observable merge( + public static Flowable merge( Single s1, Single s2, Single s3, Single s4, Single s5, Single s6, @@ -598,11 +598,11 @@ public static Observable merge( Objects.requireNonNull(s5, "s5 is null"); Objects.requireNonNull(s6, "s6 is null"); Objects.requireNonNull(s7, "s7 is null"); - return merge(Observable.fromArray(s1, s2, s3, s4, s5, s6, s7)); + return merge(Flowable.fromArray(s1, s2, s3, s4, s5, s6, s7)); } @SuppressWarnings("unchecked") - public static Observable merge( + public static Flowable merge( Single s1, Single s2, Single s3, Single s4, Single s5, Single s6, @@ -616,11 +616,11 @@ public static Observable merge( Objects.requireNonNull(s6, "s6 is null"); Objects.requireNonNull(s7, "s7 is null"); Objects.requireNonNull(s8, "s8 is null"); - return merge(Observable.fromArray(s1, s2, s3, s4, s5, s6, s7, s8)); + return merge(Flowable.fromArray(s1, s2, s3, s4, s5, s6, s7, s8)); } @SuppressWarnings("unchecked") - public static Observable merge( + public static Flowable merge( Single s1, Single s2, Single s3, Single s4, Single s5, Single s6, @@ -636,7 +636,7 @@ public static Observable merge( Objects.requireNonNull(s7, "s7 is null"); Objects.requireNonNull(s8, "s8 is null"); Objects.requireNonNull(s9, "s9 is null"); - return merge(Observable.fromArray(s1, s2, s3, s4, s5, s6, s7, s8, s9)); + return merge(Flowable.fromArray(s1, s2, s3, s4, s5, s6, s7, s8, s9)); } static final Single NEVER = create(new SingleOnSubscribe() { @@ -842,11 +842,11 @@ public void onError(Throwable e) { public static Single zip(final Iterable> sources, Function zipper) { Objects.requireNonNull(sources, "sources is null"); - Iterable> it = new Iterable>() { + Iterable> it = new Iterable>() { @Override - public Iterator> iterator() { + public Iterator> iterator() { final Iterator> sit = sources.iterator(); - return new Iterator>() { + return new Iterator>() { @Override public boolean hasNext() { @@ -854,8 +854,8 @@ public boolean hasNext() { } @Override - public Observable next() { - return ((Observable)sit.next().toFlowable()); + public Flowable next() { + return ((Flowable)sit.next().toFlowable()); } @Override @@ -865,7 +865,7 @@ public void remove() { }; } }; - return Observable.zipIterable(zipper, false, 1, it).toSingle(); + return Flowable.zipIterable(zipper, false, 1, it).toSingle(); } @SuppressWarnings("unchecked") @@ -1000,7 +1000,7 @@ public static Single zipArray(Function sourcePublishers[i] = s.toFlowable(); i++; } - return Observable.zipArray(zipper, false, 1, sourcePublishers).toSingle(); + return Flowable.zipArray(zipper, false, 1, sourcePublishers).toSingle(); } protected final SingleOnSubscribe onSubscribe; @@ -1139,7 +1139,7 @@ public void onError(Throwable e) { }); } - public final Observable concatWith(Single other) { + public final Flowable concatWith(Single other) { return concat(this, other); } @@ -1322,7 +1322,7 @@ public final Single flatMap(Function(mapper)); } - public final Observable flatMapPublisher(Function> mapper) { + public final Flowable flatMapPublisher(Function> mapper) { return toFlowable().flatMap(mapper); } @@ -1423,7 +1423,7 @@ public void onError(Throwable e) { }); } - public final Observable mergeWith(Single other) { + public final Flowable mergeWith(Single other) { return merge(this, other); } @@ -1588,19 +1588,19 @@ public void onError(Throwable e) { }); } - public final Observable repeat() { + public final Flowable repeat() { return toFlowable().repeat(); } - public final Observable repeat(long times) { + public final Flowable repeat(long times) { return toFlowable().repeat(times); } - public final Observable repeatWhen(Function, ? extends Publisher> handler) { + public final Flowable repeatWhen(Function, ? extends Publisher> handler) { return toFlowable().repeatWhen(handler); } - public final Observable repeatUntil(BooleanSupplier stop) { + public final Flowable repeatUntil(BooleanSupplier stop) { return toFlowable().repeatUntil(stop); } @@ -1620,7 +1620,7 @@ public final Single retry(Predicate predicate) { return toFlowable().retry(predicate).toSingle(); } - public final Single retryWhen(Function, ? extends Publisher> handler) { + public final Single retryWhen(Function, ? extends Publisher> handler) { return toFlowable().retryWhen(handler).toSingle(); } @@ -1809,8 +1809,8 @@ public final R to(Function, R> convert) { return convert.apply(this); } - public final Observable toFlowable() { - return Observable.create(new Publisher() { + public final Flowable toFlowable() { + return Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber s) { final ScalarAsyncSubscription sas = new ScalarAsyncSubscription(s); diff --git a/src/main/java/io/reactivex/disposables/Disposables.java b/src/main/java/io/reactivex/disposables/Disposables.java index 894d2f745f..79f0d3d7fa 100644 --- a/src/main/java/io/reactivex/disposables/Disposables.java +++ b/src/main/java/io/reactivex/disposables/Disposables.java @@ -14,7 +14,7 @@ package io.reactivex.disposables; import java.util.concurrent.*; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; import org.reactivestreams.Subscription; diff --git a/src/main/java/io/reactivex/exceptions/CompositeException.java b/src/main/java/io/reactivex/exceptions/CompositeException.java index d689797ae7..a10c428133 100644 --- a/src/main/java/io/reactivex/exceptions/CompositeException.java +++ b/src/main/java/io/reactivex/exceptions/CompositeException.java @@ -15,15 +15,8 @@ */ package io.reactivex.exceptions; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; +import java.io.*; +import java.util.*; /** * Represents an exception that is a composite of one or more other exceptions. A {@code CompositeException} diff --git a/src/main/java/io/reactivex/observables/nbp/NbpBlockingObservable.java b/src/main/java/io/reactivex/flowables/BlockingFlowable.java similarity index 82% rename from src/main/java/io/reactivex/observables/nbp/NbpBlockingObservable.java rename to src/main/java/io/reactivex/flowables/BlockingFlowable.java index 50f8c2c76c..8e90fb15dc 100644 --- a/src/main/java/io/reactivex/observables/nbp/NbpBlockingObservable.java +++ b/src/main/java/io/reactivex/flowables/BlockingFlowable.java @@ -11,33 +11,38 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.observables.nbp; +package io.reactivex.flowables; import java.io.Closeable; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; +import org.reactivestreams.*; + +import io.reactivex.Flowable; import io.reactivex.Optional; -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.disposables.*; import io.reactivex.functions.Consumer; import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.operators.nbp.*; -import io.reactivex.internal.subscribers.BlockingSubscriber; -import io.reactivex.internal.subscribers.nbp.*; +import io.reactivex.internal.operators.flowable.*; +import io.reactivex.internal.subscribers.flowable.*; import io.reactivex.internal.util.*; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.subscribers.DefaultObserver; -public final class NbpBlockingObservable implements Iterable { - final NbpObservable o; - protected NbpBlockingObservable(NbpObservable source) { +public final class BlockingFlowable implements Publisher, Iterable { + final Publisher o; + protected BlockingFlowable(Publisher source) { this.o = source; } - public static NbpBlockingObservable from(NbpObservable source) { - return new NbpBlockingObservable(source); + @SuppressWarnings("unchecked") + public static BlockingFlowable from(Publisher source) { + if (source instanceof BlockingFlowable) { + return (BlockingFlowable)source; + } + return new BlockingFlowable(source); } @Override @@ -52,19 +57,19 @@ public void forEach(Consumer action) { action.accept(it.next()); } catch (Throwable e) { it.dispose(); - Exceptions.propagate(e); + throw Exceptions.propagate(e); } } } - static final BlockingIterator iterate(NbpObservable p) { + static final BlockingIterator iterate(Publisher p) { final BlockingQueue queue = new LinkedBlockingQueue(); - NbpLambdaSubscriber ls = new NbpLambdaSubscriber( + LambdaSubscriber ls = new LambdaSubscriber( new Consumer() { @Override public void accept(T v) { - queue.offer(NotificationLite.next(v)); + queue.offer(NotificationLite.next(v)); } }, new Consumer() { @@ -79,7 +84,12 @@ public void run() { queue.offer(NotificationLite.complete()); } }, - Functions.emptyConsumer() + new Consumer() { + @Override + public void accept(Subscription s) { + s.request(Long.MAX_VALUE); + } + } ); p.subscribe(ls); @@ -160,23 +170,24 @@ public Optional firstOption() { return firstOption(o); } - static Optional firstOption(NbpObservable o) { + static Optional firstOption(Publisher o) { final AtomicReference value = new AtomicReference(); final AtomicReference error = new AtomicReference(); final CountDownLatch cdl = new CountDownLatch(1); final MultipleAssignmentDisposable mad = new MultipleAssignmentDisposable(); - o.subscribe(new NbpSubscriber() { - Disposable s; + o.subscribe(new Subscriber() { + Subscription s; @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Subscription s) { this.s = s; - mad.set(s); + mad.set(Disposables.from(s)); + s.request(Long.MAX_VALUE); } @Override public void onNext(T t) { - s.dispose(); + s.cancel(); value.lazySet(t); cdl.countDown(); } @@ -228,16 +239,17 @@ public Optional lastOption() { return lastOption(o); } - static Optional lastOption(NbpObservable o) { + static Optional lastOption(Publisher o) { final AtomicReference value = new AtomicReference(); final AtomicReference error = new AtomicReference(); final CountDownLatch cdl = new CountDownLatch(1); final MultipleAssignmentDisposable mad = new MultipleAssignmentDisposable(); - o.subscribe(new NbpSubscriber() { + o.subscribe(new Subscriber() { @Override - public void onSubscribe(Disposable s) { - mad.set(s); + public void onSubscribe(Subscription s) { + mad.set(Disposables.from(s)); + s.request(Long.MAX_VALUE); } @Override @@ -289,7 +301,7 @@ public T last(T defaultValue) { } public T single() { - Optional o = firstOption(this.o.single()); + Optional o = firstOption(Flowable.fromPublisher(this.o).single()); if (o.isPresent()) { return o.get(); } @@ -297,8 +309,7 @@ public T single() { } public T single(T defaultValue) { - @SuppressWarnings("unchecked") - Optional o = firstOption(((NbpObservable)this.o).single(defaultValue)); + Optional o = firstOption(Flowable.fromPublisher(this.o).single(defaultValue)); if (o.isPresent()) { return o.get(); } @@ -306,15 +317,15 @@ public T single(T defaultValue) { } public Iterable mostRecent(T initialValue) { - return NbpBlockingOperatorMostRecent.mostRecent(o, initialValue); + return BlockingOperatorMostRecent.mostRecent(o, initialValue); } public Iterable next() { - return NbpBlockingOperatorNext.next(o); + return BlockingOperatorNext.next(o); } public Iterable latest() { - return NbpBlockingOperatorLatest.latest(o); + return BlockingOperatorLatest.latest(o); } public Future toFuture() { @@ -323,11 +334,12 @@ public Future toFuture() { final AtomicReference error = new AtomicReference(); final MultipleAssignmentDisposable mad = new MultipleAssignmentDisposable(); - o.subscribe(new NbpSubscriber() { + o.subscribe(new Subscriber() { @Override - public void onSubscribe(Disposable d) { - mad.set(d); + public void onSubscribe(Subscription d) { + mad.set(Disposables.from(d)); + d.request(Long.MAX_VALUE); } @Override @@ -424,20 +436,24 @@ private void awaitForComplete(CountDownLatch latch, Disposable subscription) { public void run() { final CountDownLatch cdl = new CountDownLatch(1); final Throwable[] error = { null }; - NbpLambdaSubscriber ls = new NbpLambdaSubscriber( - Functions.emptyConsumer(), - new Consumer() { - @Override - public void accept(Throwable e) { - error[0] = e; - cdl.countDown(); - } - }, new Runnable() { - @Override - public void run() { - cdl.countDown(); - } - }, Functions.emptyConsumer()); + LambdaSubscriber ls = new LambdaSubscriber(Functions.emptyConsumer(), + new Consumer() { + @Override + public void accept(Throwable e) { + error[0] = e; + cdl.countDown(); + } + }, new Runnable() { + @Override + public void run() { + cdl.countDown(); + } + }, new Consumer() { + @Override + public void accept(Subscription s) { + s.request(Long.MAX_VALUE); + } + }); o.subscribe(ls); @@ -458,10 +474,11 @@ public void run() { * The unsubscription and backpressure is composed through. * @param subscriber the subscriber to forward events and calls to in the current thread */ - public void subscribe(NbpSubscriber subscriber) { + @Override + public void subscribe(Subscriber subscriber) { final BlockingQueue queue = new LinkedBlockingQueue(); - NbpBlockingSubscriber bs = new NbpBlockingSubscriber(queue); + BlockingSubscriber bs = new BlockingSubscriber(queue); o.subscribe(bs); @@ -483,7 +500,7 @@ public void subscribe(NbpSubscriber subscriber) { if (o == BlockingSubscriber.TERMINATED) { break; } - if (NotificationLite.accept(o, subscriber)) { + if (NotificationLite.acceptFull(o, subscriber)) { break; } } @@ -491,7 +508,7 @@ public void subscribe(NbpSubscriber subscriber) { Thread.currentThread().interrupt(); subscriber.onError(e); } finally { - bs.dispose(); + bs.cancel(); } } @@ -527,7 +544,7 @@ public void subscribe(final Consumer onNext, final Consumer onNext, final Consumer onError, final Runnable onComplete) { - subscribe(new NbpObserver() { + subscribe(new DefaultObserver() { @Override public void onNext(T t) { onNext.accept(t); diff --git a/src/main/java/io/reactivex/observables/nbp/NbpConnectableObservable.java b/src/main/java/io/reactivex/flowables/ConnectableFlowable.java similarity index 82% rename from src/main/java/io/reactivex/observables/nbp/NbpConnectableObservable.java rename to src/main/java/io/reactivex/flowables/ConnectableFlowable.java index 16ca997b5d..bea1f3b58a 100644 --- a/src/main/java/io/reactivex/observables/nbp/NbpConnectableObservable.java +++ b/src/main/java/io/reactivex/flowables/ConnectableFlowable.java @@ -11,20 +11,20 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.observables.nbp; +package io.reactivex.flowables; -import org.reactivestreams.Subscriber; +import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.operators.nbp.*; +import io.reactivex.internal.operators.flowable.*; /** - * A {@code ConnectableObservable} resembles an ordinary {@link Observable}, except that it does not begin + * A {@code ConnectableObservable} resembles an ordinary {@link Flowable}, except that it does not begin * emitting items when it is subscribed to, but only when its {@link #connect} method is called. In this way you - * can wait for all intended {@link Subscriber}s to {@link Observable#subscribe} to the {@code Observable} + * can wait for all intended {@link Subscriber}s to {@link Flowable#subscribe} to the {@code Observable} * before the {@code Observable} begins emitting items. *

* @@ -34,15 +34,15 @@ * @param * the type of items emitted by the {@code ConnectableObservable} */ -public abstract class NbpConnectableObservable extends NbpObservable { +public abstract class ConnectableFlowable extends Flowable { - protected NbpConnectableObservable(NbpOnSubscribe onSubscribe) { + protected ConnectableFlowable(Publisher onSubscribe) { super(onSubscribe); } /** * Instructs the {@code ConnectableObservable} to begin emitting the items from its underlying - * {@link Observable} to its {@link Subscriber}s. + * {@link Flowable} to its {@link Subscriber}s. * * @param connection * the action that receives the connection subscription before the subscription to source happens @@ -53,9 +53,9 @@ protected NbpConnectableObservable(NbpOnSubscribe onSubscribe) { /** * Instructs the {@code ConnectableObservable} to begin emitting the items from its underlying - * {@link Observable} to its {@link Subscriber}s. + * {@link Flowable} to its {@link Subscriber}s. *

- * To disconnect from a synchronous source, use the {@link #connect(Consumer)} method. + * To disconnect from a synchronous source, use the {@link #connect(io.reactivex.functions.Consumer)} method. * * @return the subscription representing the connection * @see ReactiveX documentation: Connect @@ -75,11 +75,11 @@ public void accept(Disposable d) { * Returns an {@code Observable} that stays connected to this {@code ConnectableObservable} as long as there * is at least one subscription to this {@code ConnectableObservable}. * - * @return a {@link Observable} + * @return a {@link Flowable} * @see ReactiveX documentation: RefCount */ - public NbpObservable refCount() { - return create(new NbpOnSubscribeRefCount(this)); + public Flowable refCount() { + return create(new PublisherRefCount(this)); } /** @@ -89,7 +89,7 @@ public NbpObservable refCount() { * @return an Observable that automatically connects to this ConnectableObservable * when the first Subscriber subscribes */ - public NbpObservable autoConnect() { + public Flowable autoConnect() { return autoConnect(1); } /** @@ -102,7 +102,7 @@ public NbpObservable autoConnect() { * @return an Observable that automatically connects to this ConnectableObservable * when the specified number of Subscribers subscribe to it */ - public NbpObservable autoConnect(int numberOfSubscribers) { + public Flowable autoConnect(int numberOfSubscribers) { return autoConnect(numberOfSubscribers, Functions.emptyConsumer()); } @@ -120,11 +120,11 @@ public NbpObservable autoConnect(int numberOfSubscribers) { * when the specified number of Subscribers subscribe to it and calls the * specified callback with the Subscription associated with the established connection */ - public NbpObservable autoConnect(int numberOfSubscribers, Consumer connection) { + public Flowable autoConnect(int numberOfSubscribers, Consumer connection) { if (numberOfSubscribers <= 0) { this.connect(connection); return this; } - return create(new NbpOnSubscribeAutoConnect(this, numberOfSubscribers, connection)); + return create(new PublisherAutoConnect(this, numberOfSubscribers, connection)); } } diff --git a/src/main/java/io/reactivex/observables/nbp/NbpGroupedObservable.java b/src/main/java/io/reactivex/flowables/GroupedFlowable.java similarity index 78% rename from src/main/java/io/reactivex/observables/nbp/NbpGroupedObservable.java rename to src/main/java/io/reactivex/flowables/GroupedFlowable.java index 44a4a1a925..d1117b848a 100644 --- a/src/main/java/io/reactivex/observables/nbp/NbpGroupedObservable.java +++ b/src/main/java/io/reactivex/flowables/GroupedFlowable.java @@ -10,13 +10,15 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.observables.nbp; +package io.reactivex.flowables; -import io.reactivex.NbpObservable; +import org.reactivestreams.Publisher; -public class NbpGroupedObservable extends NbpObservable { +import io.reactivex.Flowable; + +public class GroupedFlowable extends Flowable { final K key; - protected NbpGroupedObservable(NbpOnSubscribe onSubscribe, K key) { + protected GroupedFlowable(Publisher onSubscribe, K key) { super(onSubscribe); this.key = key; } diff --git a/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java b/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java index a9dfd8d4c7..3339bdc908 100644 --- a/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java +++ b/src/main/java/io/reactivex/internal/disposables/EmptyDisposable.java @@ -13,7 +13,7 @@ package io.reactivex.internal.disposables; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; public enum EmptyDisposable implements Disposable { @@ -25,12 +25,12 @@ public void dispose() { // no-op } - public static void complete(NbpSubscriber s) { + public static void complete(Observer s) { s.onSubscribe(INSTANCE); s.onComplete(); } - public static void error(Throwable e, NbpSubscriber s) { + public static void error(Throwable e, Observer s) { s.onSubscribe(INSTANCE); s.onError(e); } diff --git a/src/main/java/io/reactivex/internal/disposables/NbpFullArbiter.java b/src/main/java/io/reactivex/internal/disposables/NbpFullArbiter.java index f33eb5a59b..901986939f 100644 --- a/src/main/java/io/reactivex/internal/disposables/NbpFullArbiter.java +++ b/src/main/java/io/reactivex/internal/disposables/NbpFullArbiter.java @@ -15,7 +15,7 @@ import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.internal.queue.SpscLinkedArrayQueue; import io.reactivex.internal.util.NotificationLite; @@ -28,7 +28,7 @@ * @param the value type */ public final class NbpFullArbiter extends FullArbiterPad1 implements Disposable { - final NbpSubscriber actual; + final Observer actual; final SpscLinkedArrayQueue queue; volatile Disposable s; @@ -42,7 +42,7 @@ public void dispose() { } volatile boolean cancelled; - public NbpFullArbiter(NbpSubscriber actual, Disposable resource, int capacity) { + public NbpFullArbiter(Observer actual, Disposable resource, int capacity) { this.actual = actual; this.resource = resource; this.queue = new SpscLinkedArrayQueue(capacity); @@ -107,7 +107,7 @@ void drain() { int missed = 1; final SpscLinkedArrayQueue q = queue; - final NbpSubscriber a = actual; + final Observer a = actual; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableOnSubscribeConcat.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableOnSubscribeConcat.java index 89df1407c3..83a7d10a40 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableOnSubscribeConcat.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableOnSubscribeConcat.java @@ -27,10 +27,10 @@ import io.reactivex.plugins.RxJavaPlugins; public final class CompletableOnSubscribeConcat implements CompletableOnSubscribe { - final Observable sources; + final Flowable sources; final int prefetch; - public CompletableOnSubscribeConcat(Observable sources, int prefetch) { + public CompletableOnSubscribeConcat(Flowable sources, int prefetch) { this.sources = sources; this.prefetch = prefetch; } diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableOnSubscribeMerge.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableOnSubscribeMerge.java index 09319ccce2..4bfe6aea7c 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableOnSubscribeMerge.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableOnSubscribeMerge.java @@ -28,11 +28,11 @@ import io.reactivex.plugins.RxJavaPlugins; public final class CompletableOnSubscribeMerge implements CompletableOnSubscribe { - final Observable source; + final Flowable source; final int maxConcurrency; final boolean delayErrors; - public CompletableOnSubscribeMerge(Observable source, int maxConcurrency, boolean delayErrors) { + public CompletableOnSubscribeMerge(Flowable source, int maxConcurrency, boolean delayErrors) { this.source = source; this.maxConcurrency = maxConcurrency; this.delayErrors = delayErrors; diff --git a/src/main/java/io/reactivex/internal/operators/BlockingOperatorLatest.java b/src/main/java/io/reactivex/internal/operators/flowable/BlockingOperatorLatest.java similarity index 95% rename from src/main/java/io/reactivex/internal/operators/BlockingOperatorLatest.java rename to src/main/java/io/reactivex/internal/operators/flowable/BlockingOperatorLatest.java index 28e4265ee9..92abc514e3 100644 --- a/src/main/java/io/reactivex/internal/operators/BlockingOperatorLatest.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/BlockingOperatorLatest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import java.util.concurrent.Semaphore; @@ -20,9 +20,8 @@ import org.reactivestreams.Publisher; import io.reactivex.*; -import io.reactivex.Observable; import io.reactivex.Optional; -import io.reactivex.internal.subscribers.DisposableSubscriber; +import io.reactivex.internal.subscribers.flowable.DisposableSubscriber; import io.reactivex.internal.util.Exceptions; /** @@ -47,7 +46,7 @@ public static Iterable latest(final Publisher source) { @Override public Iterator iterator() { LatestObserverIterator lio = new LatestObserverIterator(); - Observable.fromPublisher(source).materialize().subscribe(lio); + Flowable.fromPublisher(source).materialize().subscribe(lio); return lio; } }; diff --git a/src/main/java/io/reactivex/internal/operators/BlockingOperatorMostRecent.java b/src/main/java/io/reactivex/internal/operators/flowable/BlockingOperatorMostRecent.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/BlockingOperatorMostRecent.java rename to src/main/java/io/reactivex/internal/operators/flowable/BlockingOperatorMostRecent.java index f2164f80ad..288b101d31 100644 --- a/src/main/java/io/reactivex/internal/operators/BlockingOperatorMostRecent.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/BlockingOperatorMostRecent.java @@ -11,14 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import org.reactivestreams.Publisher; -import io.reactivex.Observer; import io.reactivex.internal.util.*; +import io.reactivex.subscribers.DefaultObserver; /** * Returns an Iterable that always returns the item most recently emitted by an Observable, or a @@ -57,7 +57,7 @@ public Iterator iterator() { }; } - private static final class MostRecentObserver extends Observer { + private static final class MostRecentObserver extends DefaultObserver { volatile Object value; private MostRecentObserver(T value) { diff --git a/src/main/java/io/reactivex/internal/operators/BlockingOperatorNext.java b/src/main/java/io/reactivex/internal/operators/flowable/BlockingOperatorNext.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/BlockingOperatorNext.java rename to src/main/java/io/reactivex/internal/operators/flowable/BlockingOperatorNext.java index b3bf45c5af..87ed18ca03 100644 --- a/src/main/java/io/reactivex/internal/operators/BlockingOperatorNext.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/BlockingOperatorNext.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import java.util.concurrent.*; @@ -19,10 +19,9 @@ import org.reactivestreams.Publisher; -import io.reactivex.Observable; +import io.reactivex.*; import io.reactivex.Optional; -import io.reactivex.Try; -import io.reactivex.internal.subscribers.DisposableSubscriber; +import io.reactivex.internal.subscribers.flowable.DisposableSubscriber; import io.reactivex.internal.util.Exceptions; /** @@ -93,7 +92,7 @@ private boolean moveToNext() { started = true; // if not started, start now observer.setWaiting(1); - Observable.fromPublisher(items) + Flowable.fromPublisher(items) .materialize().subscribe(observer); } diff --git a/src/main/java/io/reactivex/internal/operators/CachedObservable.java b/src/main/java/io/reactivex/internal/operators/flowable/CachedObservable.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/CachedObservable.java rename to src/main/java/io/reactivex/internal/operators/flowable/CachedObservable.java index 88b3824361..e02c28a94e 100644 --- a/src/main/java/io/reactivex/internal/operators/CachedObservable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/CachedObservable.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; import io.reactivex.internal.disposables.SerialResource; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -29,7 +29,7 @@ * * @param the source element type */ -public final class CachedObservable extends Observable { +public final class CachedObservable extends Flowable { /** The cache and replay state. */ private CacheState state; @@ -39,7 +39,7 @@ public final class CachedObservable extends Observable { * @param source the source Observable to cache * @return the CachedObservable instance */ - public static CachedObservable from(Observable source) { + public static CachedObservable from(Flowable source) { return from(source, 16); } @@ -50,7 +50,7 @@ public static CachedObservable from(Observable source) { * @param capacityHint the hint for the internal buffer size * @return the CachedObservable instance */ - public static CachedObservable from(Observable source, int capacityHint) { + public static CachedObservable from(Flowable source, int capacityHint) { if (capacityHint < 1) { throw new IllegalArgumentException("capacityHint > 0 required"); } @@ -101,7 +101,7 @@ private CachedObservable(Publisher onSubscribe, CacheState state) { */ static final class CacheState extends LinkedArrayList implements Subscriber { /** The source observable to connect to. */ - final Observable source; + final Flowable source; /** Holds onto the subscriber connected to source. */ final SerialResource connection; /** Guarded by connection (not this). */ @@ -117,7 +117,7 @@ static final class CacheState extends LinkedArrayList implements Subscriber source, int capacityHint) { + public CacheState(Flowable source, int capacityHint) { super(capacityHint); this.source = source; this.producers = EMPTY; diff --git a/src/main/java/io/reactivex/internal/operators/ObservableScalarSource.java b/src/main/java/io/reactivex/internal/operators/flowable/ObservableScalarSource.java similarity index 92% rename from src/main/java/io/reactivex/internal/operators/ObservableScalarSource.java rename to src/main/java/io/reactivex/internal/operators/flowable/ObservableScalarSource.java index fbbefc8383..c54c166406 100644 --- a/src/main/java/io/reactivex/internal/operators/ObservableScalarSource.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/ObservableScalarSource.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.*; @@ -23,7 +23,7 @@ * Represents a constant scalar value. * @param the value type */ -public final class ObservableScalarSource extends Observable { +public final class ObservableScalarSource extends Flowable { private final T value; public ObservableScalarSource(final T value) { super(new Publisher() { diff --git a/src/main/java/io/reactivex/internal/operators/OperatorAll.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorAll.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorAll.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorAll.java index c2ee4e2246..3fbd52e294 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorAll.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorAll.java @@ -10,13 +10,13 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicInteger; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.Predicate; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorAny.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorAny.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorAny.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorAny.java index 6f9e309fa1..db6648f0b0 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorAny.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorAny.java @@ -10,13 +10,13 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicInteger; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.Predicate; import io.reactivex.internal.subscriptions.SubscriptionHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorBuffer.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorBuffer.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorBuffer.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorBuffer.java index ebc699f2cc..73ace8e662 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorBuffer.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorBuffer.java @@ -11,16 +11,16 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.Supplier; -import io.reactivex.internal.subscribers.EmptySubscriber; +import io.reactivex.internal.subscribers.flowable.EmptySubscriber; import io.reactivex.internal.subscriptions.*; import io.reactivex.internal.util.BackpressureHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorBufferBoundary.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorBufferBoundary.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorBufferBoundary.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorBufferBoundary.java index 5fa2658d92..eb40236b7f 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorBufferBoundary.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorBufferBoundary.java @@ -11,19 +11,19 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.disposables.*; import io.reactivex.functions.*; import io.reactivex.internal.disposables.SetCompositeResource; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.*; +import io.reactivex.internal.subscribers.flowable.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.QueueDrainHelper; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorBufferBoundarySupplier.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorBufferBoundarySupplier.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorBufferBoundarySupplier.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorBufferBoundarySupplier.java index ecbced3da7..727481c117 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorBufferBoundarySupplier.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorBufferBoundarySupplier.java @@ -11,18 +11,18 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Collection; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Supplier; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.*; +import io.reactivex.internal.subscribers.flowable.*; import io.reactivex.internal.subscriptions.*; import io.reactivex.internal.util.QueueDrainHelper; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorBufferExactBoundary.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorBufferExactBoundary.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorBufferExactBoundary.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorBufferExactBoundary.java index aa5761769e..7bc6b86791 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorBufferExactBoundary.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorBufferExactBoundary.java @@ -11,17 +11,17 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Collection; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Supplier; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.*; +import io.reactivex.internal.subscribers.flowable.*; import io.reactivex.internal.subscriptions.*; import io.reactivex.internal.util.QueueDrainHelper; import io.reactivex.subscribers.SerializedSubscriber; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorBufferTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorBufferTimed.java similarity index 99% rename from src/main/java/io/reactivex/internal/operators/OperatorBufferTimed.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorBufferTimed.java index dc1920d31e..aa8c68cc0b 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorBufferTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorBufferTimed.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import java.util.concurrent.*; @@ -19,13 +19,13 @@ import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.Scheduler; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Supplier; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.QueueDrainSubscriber; +import io.reactivex.internal.subscribers.flowable.QueueDrainSubscriber; import io.reactivex.internal.subscriptions.*; import io.reactivex.internal.util.QueueDrainHelper; import io.reactivex.subscribers.SerializedSubscriber; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorCollect.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorCollect.java similarity index 95% rename from src/main/java/io/reactivex/internal/operators/OperatorCollect.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorCollect.java index 6f28d1a609..96dd2c5baf 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorCollect.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorCollect.java @@ -10,13 +10,13 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.*; -import io.reactivex.internal.subscribers.CancelledSubscriber; +import io.reactivex.internal.subscribers.flowable.CancelledSubscriber; import io.reactivex.internal.subscriptions.*; public final class OperatorCollect implements Operator { diff --git a/src/main/java/io/reactivex/internal/operators/OperatorConcatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorConcatMap.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorConcatMap.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorConcatMap.java index 03fe9d2969..f9d66b65e0 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorConcatMap.java @@ -10,14 +10,14 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Queue; import java.util.concurrent.atomic.AtomicInteger; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.Function; import io.reactivex.internal.queue.*; import io.reactivex.internal.subscriptions.SubscriptionArbiter; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorCount.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorCount.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/OperatorCount.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorCount.java index 466547b256..2bd63413e8 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorCount.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorCount.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.plugins.RxJavaPlugins; public enum OperatorCount implements Operator { diff --git a/src/main/java/io/reactivex/internal/operators/OperatorDebounce.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorDebounce.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorDebounce.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorDebounce.java index 2ce4cae388..fb4019d7ac 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorDebounce.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorDebounce.java @@ -11,16 +11,16 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; -import io.reactivex.internal.subscribers.DisposableSubscriber; +import io.reactivex.internal.subscribers.flowable.DisposableSubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorDebounceTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorDebounceTimed.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorDebounceTimed.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorDebounceTimed.java index 184c711e65..fb804aff05 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorDebounceTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorDebounceTimed.java @@ -11,15 +11,15 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; import org.reactivestreams.*; +import io.reactivex.Flowable.Operator; import io.reactivex.Scheduler; -import io.reactivex.Observable.Operator; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorDelay.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorDelay.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorDelay.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorDelay.java index 0246352f4a..f3f5599f4b 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorDelay.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorDelay.java @@ -11,14 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.TimeUnit; import org.reactivestreams.*; +import io.reactivex.Flowable.Operator; import io.reactivex.Scheduler; -import io.reactivex.Observable.Operator; import io.reactivex.Scheduler.Worker; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.subscribers.SerializedSubscriber; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorDematerialize.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorDematerialize.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/OperatorDematerialize.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorDematerialize.java index 9bea9a8df1..d5f31c6a4d 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorDematerialize.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorDematerialize.java @@ -11,12 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorDistinct.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorDistinct.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorDistinct.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorDistinct.java index f2a218c24a..cc86fa2c86 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorDistinct.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorDistinct.java @@ -11,17 +11,17 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Collection; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.*; import io.reactivex.internal.functions.*; -import io.reactivex.internal.subscribers.CancelledSubscriber; +import io.reactivex.internal.subscribers.flowable.CancelledSubscriber; import io.reactivex.internal.subscriptions.*; public final class OperatorDistinct implements Operator { diff --git a/src/main/java/io/reactivex/internal/operators/OperatorDoOnEach.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorDoOnEach.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorDoOnEach.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorDoOnEach.java index 1d59cbbc21..d804d73e30 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorDoOnEach.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorDoOnEach.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.Consumer; import io.reactivex.internal.subscriptions.SubscriptionHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorElementAt.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorElementAt.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorElementAt.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorElementAt.java index 84d44e5a59..e7930d14a7 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorElementAt.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorElementAt.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.plugins.RxJavaPlugins; public final class OperatorElementAt implements Operator { diff --git a/src/main/java/io/reactivex/internal/operators/OperatorFilter.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorFilter.java similarity index 93% rename from src/main/java/io/reactivex/internal/operators/OperatorFilter.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorFilter.java index 23a73d5e54..ce710150a1 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorFilter.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorFilter.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.Predicate; -import io.reactivex.internal.subscribers.ConditionalSubscriber; +import io.reactivex.internal.subscribers.flowable.ConditionalSubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; public final class OperatorFilter implements Operator { diff --git a/src/main/java/io/reactivex/internal/operators/OperatorFlatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorFlatMap.java similarity index 99% rename from src/main/java/io/reactivex/internal/operators/OperatorFlatMap.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorFlatMap.java index bc9fcb7f15..f262654af6 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorFlatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorFlatMap.java @@ -11,14 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.*; import io.reactivex.functions.Function; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorGroupBy.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorGroupBy.java similarity index 92% rename from src/main/java/io/reactivex/internal/operators/OperatorGroupBy.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorGroupBy.java index bc7de4582a..6f757a5006 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorGroupBy.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorGroupBy.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -19,15 +19,15 @@ import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; +import io.reactivex.flowables.GroupedFlowable; import io.reactivex.functions.Function; import io.reactivex.internal.queue.SpscLinkedArrayQueue; import io.reactivex.internal.subscriptions.*; import io.reactivex.internal.util.BackpressureHelper; -import io.reactivex.observables.GroupedObservable; import io.reactivex.plugins.RxJavaPlugins; -public final class OperatorGroupBy implements Operator, T>{ +public final class OperatorGroupBy implements Operator, T>{ final Function keySelector; final Function valueSelector; final int bufferSize; @@ -41,7 +41,7 @@ public OperatorGroupBy(Function keySelector, Function apply(Subscriber> t) { + public Subscriber apply(Subscriber> t) { return new GroupBySubscriber(t, keySelector, valueSelector, bufferSize, delayError); } @@ -51,13 +51,13 @@ public static final class GroupBySubscriber /** */ private static final long serialVersionUID = -3688291656102519502L; - final Subscriber> actual; + final Subscriber> actual; final Function keySelector; final Function valueSelector; final int bufferSize; final boolean delayError; final Map> groups; - final Queue> queue; + final Queue> queue; static final Object NULL_KEY = new Object(); @@ -72,14 +72,14 @@ public static final class GroupBySubscriber Throwable error; volatile boolean done; - public GroupBySubscriber(Subscriber> actual, Function keySelector, Function valueSelector, int bufferSize, boolean delayError) { + public GroupBySubscriber(Subscriber> actual, Function keySelector, Function valueSelector, int bufferSize, boolean delayError) { this.actual = actual; this.keySelector = keySelector; this.valueSelector = valueSelector; this.bufferSize = bufferSize; this.delayError = delayError; this.groups = new ConcurrentHashMap>(); - this.queue = new SpscLinkedArrayQueue>(bufferSize); + this.queue = new SpscLinkedArrayQueue>(bufferSize); } @Override @@ -99,8 +99,8 @@ public void onNext(T t) { return; } - final Queue> q = this.queue; - final Subscriber> a = this.actual; + final Queue> q = this.queue; + final Subscriber> a = this.actual; K key; try { @@ -211,8 +211,8 @@ void drain() { int missed = 1; - final Queue> q = this.queue; - final Subscriber> a = this.actual; + final Queue> q = this.queue; + final Subscriber> a = this.actual; for (;;) { @@ -227,7 +227,7 @@ void drain() { while (r != 0) { boolean d = done; - GroupedObservable t = q.poll(); + GroupedFlowable t = q.poll(); boolean empty = t == null; @@ -259,7 +259,7 @@ void drain() { } } - void errorAll(Subscriber> a, Queue q, Throwable ex) { + void errorAll(Subscriber> a, Queue q, Throwable ex) { q.clear(); List> list = new ArrayList>(groups.values()); groups.clear(); @@ -272,7 +272,7 @@ void errorAll(Subscriber> a, Queue q, Throwab } boolean checkTerminated(boolean d, boolean empty, - Subscriber> a, Queue q) { + Subscriber> a, Queue q) { if (d) { Throwable err = error; if (err != null) { @@ -295,7 +295,7 @@ boolean checkTerminated(boolean d, boolean empty, } } - static final class GroupedUnicast extends GroupedObservable { + static final class GroupedUnicast extends GroupedFlowable { public static GroupedUnicast createWith(K key, int bufferSize, GroupBySubscriber parent, boolean delayError) { State state = new State(bufferSize, parent, key, delayError); diff --git a/src/main/java/io/reactivex/internal/operators/OperatorIgnoreElements.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorIgnoreElements.java similarity index 94% rename from src/main/java/io/reactivex/internal/operators/OperatorIgnoreElements.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorIgnoreElements.java index 04acb4d4de..46be0d1b57 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorIgnoreElements.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorIgnoreElements.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; public enum OperatorIgnoreElements implements Operator { INSTANCE; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorMap.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorMap.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorMap.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorMap.java index a0bbe1dd9a..bf952119c5 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorMap.java @@ -12,11 +12,11 @@ */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorMapNotification.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorMapNotification.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorMapNotification.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorMapNotification.java index a498636f6a..6ad4027797 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorMapNotification.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorMapNotification.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorMaterialize.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorMaterialize.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorMaterialize.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorMaterialize.java index f9a4ea9e73..fd213bae9e 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorMaterialize.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorMaterialize.java @@ -11,14 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.*; import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorObserveOn.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorObserveOn.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorObserveOn.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorObserveOn.java index e423293546..b8a0252bc7 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorObserveOn.java @@ -11,15 +11,15 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Queue; import java.util.concurrent.atomic.*; import org.reactivestreams.*; +import io.reactivex.Flowable.Operator; import io.reactivex.Scheduler; -import io.reactivex.Observable.Operator; import io.reactivex.exceptions.MissingBackpressureException; import io.reactivex.internal.queue.*; import io.reactivex.internal.schedulers.TrampolineScheduler; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorOnBackpressureBuffer.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureBuffer.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorOnBackpressureBuffer.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureBuffer.java index b09c65fc76..f44cc3e1fd 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorOnBackpressureBuffer.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureBuffer.java @@ -11,14 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Queue; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.exceptions.MissingBackpressureException; import io.reactivex.internal.queue.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorOnBackpressureDrop.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureDrop.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorOnBackpressureDrop.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureDrop.java index 114ea7e2f8..32c3123f88 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorOnBackpressureDrop.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureDrop.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicLong; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.Consumer; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.SubscriptionHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorOnBackpressureLatest.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureLatest.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorOnBackpressureLatest.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureLatest.java index 60633e6509..ead54fb5b1 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorOnBackpressureLatest.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureLatest.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.util.BackpressureHelper; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorOnErrorNext.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorOnErrorNext.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorOnErrorNext.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorOnErrorNext.java index f57ea7ca33..7ef8645f9d 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorOnErrorNext.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorOnErrorNext.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.SubscriptionArbiter; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorOnErrorReturn.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorOnErrorReturn.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorOnErrorReturn.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorOnErrorReturn.java index cf65874227..fb7b96dd64 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorOnErrorReturn.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorOnErrorReturn.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.SubscriptionHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorPublish.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorPublish.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorPublish.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorPublish.java index faf5645ec8..3b0c37b272 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorPublish.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorPublish.java @@ -11,20 +11,20 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Queue; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.disposables.*; +import io.reactivex.flowables.ConnectableFlowable; import io.reactivex.functions.*; import io.reactivex.internal.queue.SpscArrayQueue; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.NotificationLite; -import io.reactivex.observables.ConnectableObservable; import io.reactivex.plugins.RxJavaPlugins; /** @@ -32,7 +32,7 @@ * manner. * @param the value type */ -public final class OperatorPublish extends ConnectableObservable { +public final class OperatorPublish extends ConnectableFlowable { /** The source observable. */ final Publisher source; /** Holds the current subscriber that is, will be or just was subscribed to the source observable. */ @@ -48,7 +48,7 @@ public final class OperatorPublish extends ConnectableObservable { * @param bufferSize the size of the prefetch buffer * @return the connectable observable */ - public static ConnectableObservable create(Observable source, final int bufferSize) { + public static ConnectableFlowable create(Flowable source, final int bufferSize) { // the current connection to source needs to be shared between the operator and its onSubscribe call final AtomicReference> curr = new AtomicReference>(); Publisher onSubscribe = new Publisher() { @@ -118,12 +118,12 @@ public void subscribe(Subscriber child) { return new OperatorPublish(onSubscribe, source, curr, bufferSize); } - public static Observable create(final Observable source, - final Function, ? extends Publisher> selector, final int bufferSize) { + public static Flowable create(final Flowable source, + final Function, ? extends Publisher> selector, final int bufferSize) { return create(new Publisher() { @Override public void subscribe(Subscriber sr) { - ConnectableObservable op = create(source, bufferSize); + ConnectableFlowable op = create(source, bufferSize); final SubscriberResourceWrapper srw = new SubscriberResourceWrapper(sr, Disposables.consumeAndDispose()); diff --git a/src/main/java/io/reactivex/internal/operators/OperatorReplay.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorReplay.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorReplay.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorReplay.java index 372bd90017..c947677108 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorReplay.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorReplay.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import java.util.concurrent.TimeUnit; @@ -19,17 +19,16 @@ import org.reactivestreams.*; -import io.reactivex.Observable; import io.reactivex.*; import io.reactivex.disposables.*; +import io.reactivex.flowables.ConnectableFlowable; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.*; import io.reactivex.internal.util.*; -import io.reactivex.observables.ConnectableObservable; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Timed; -public final class OperatorReplay extends ConnectableObservable { +public final class OperatorReplay extends ConnectableFlowable { /** The source observable. */ final Publisher source; /** Holds the current subscriber that is, will be or just was subscribed to the source observable. */ @@ -54,13 +53,13 @@ public Object get() { * @param selector * @return the new Observable instance */ - public static Observable multicastSelector( - final Supplier> connectableFactory, - final Function, ? extends Publisher> selector) { - return Observable.create(new Publisher() { + public static Flowable multicastSelector( + final Supplier> connectableFactory, + final Function, ? extends Publisher> selector) { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber child) { - ConnectableObservable co; + ConnectableFlowable co; Publisher observable; try { co = connectableFactory.get(); @@ -106,9 +105,9 @@ public void accept(Disposable r) { * @param scheduler * @return the new ConnectableObservable instance */ - public static ConnectableObservable observeOn(final ConnectableObservable co, final Scheduler scheduler) { - final Observable observable = co.observeOn(scheduler); - return new ConnectableObservable(observable) { + public static ConnectableFlowable observeOn(final ConnectableFlowable co, final Scheduler scheduler) { + final Flowable observable = co.observeOn(scheduler); + return new ConnectableFlowable(observable) { @Override public void connect(Consumer connection) { co.connect(connection); @@ -123,7 +122,7 @@ public void connect(Consumer connection) { * @return the new ConnectableObservable instance */ @SuppressWarnings("unchecked") - public static ConnectableObservable createFrom(Observable source) { + public static ConnectableFlowable createFrom(Flowable source) { return create(source, DEFAULT_UNBOUNDED_FACTORY); } @@ -134,7 +133,7 @@ public static ConnectableObservable createFrom(Observable so * @param bufferSize * @return the new ConnectableObservable instance */ - public static ConnectableObservable create(Observable source, + public static ConnectableFlowable create(Flowable source, final int bufferSize) { if (bufferSize == Integer.MAX_VALUE) { return createFrom(source); @@ -156,7 +155,7 @@ public ReplayBuffer get() { * @param scheduler * @return the new ConnectableObservable instance */ - public static ConnectableObservable create(Observable source, + public static ConnectableFlowable create(Flowable source, long maxAge, TimeUnit unit, Scheduler scheduler) { return create(source, maxAge, unit, scheduler, Integer.MAX_VALUE); } @@ -171,7 +170,7 @@ public static ConnectableObservable create(Observable source * @param bufferSize * @return the new NbpConnectableObservable instance */ - public static ConnectableObservable create(Observable source, + public static ConnectableFlowable create(Flowable source, final long maxAge, final TimeUnit unit, final Scheduler scheduler, final int bufferSize) { return create(source, new Supplier>() { @Override @@ -187,7 +186,7 @@ public ReplayBuffer get() { * @param bufferFactory the factory to instantiate the appropriate buffer when the observable becomes active * @return the connectable observable */ - static ConnectableObservable create(Observable source, + static ConnectableFlowable create(Flowable source, final Supplier> bufferFactory) { // the current connection to source needs to be shared between the operator and its onSubscribe call final AtomicReference> curr = new AtomicReference>(); @@ -232,7 +231,7 @@ public void subscribe(Subscriber child) { }; return new OperatorReplay(onSubscribe, source, curr, bufferFactory); } - private OperatorReplay(Publisher onSubscribe, Observable source, + private OperatorReplay(Publisher onSubscribe, Flowable source, final AtomicReference> current, final Supplier> bufferFactory) { super(onSubscribe); diff --git a/src/main/java/io/reactivex/internal/operators/OperatorSamplePublisher.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSamplePublisher.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorSamplePublisher.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorSamplePublisher.java index 00d4426865..8c7e657a5a 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorSamplePublisher.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSamplePublisher.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; import io.reactivex.subscribers.SerializedSubscriber; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorSampleTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSampleTimed.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorSampleTimed.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorSampleTimed.java index fb6a21e73f..cc3b8fdad3 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorSampleTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSampleTimed.java @@ -11,15 +11,15 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; import org.reactivestreams.*; +import io.reactivex.Flowable.Operator; import io.reactivex.Scheduler; -import io.reactivex.Observable.Operator; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorScan.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorScan.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/OperatorScan.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorScan.java index 17b5877455..4c3bb9aa34 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorScan.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorScan.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.BiFunction; import io.reactivex.internal.subscriptions.SubscriptionHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorScanSeed.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorScanSeed.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/OperatorScanSeed.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorScanSeed.java index b505b0ea4d..96bf50dcfb 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorScanSeed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorScanSeed.java @@ -10,14 +10,14 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.*; import io.reactivex.internal.queue.SpscArrayQueue; -import io.reactivex.internal.subscribers.*; +import io.reactivex.internal.subscribers.flowable.*; import io.reactivex.internal.subscriptions.*; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorSingle.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSingle.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorSingle.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorSingle.java index 840dd4fdad..0eb9253cff 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorSingle.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSingle.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.NoSuchElementException; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorSkip.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSkip.java similarity index 95% rename from src/main/java/io/reactivex/internal/operators/OperatorSkip.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorSkip.java index 84435b8296..35a58b179e 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorSkip.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSkip.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; public final class OperatorSkip implements Operator { final long n; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorSkipLast.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSkipLast.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/OperatorSkipLast.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorSkipLast.java index 40a6e03c2b..5a34e14728 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorSkipLast.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSkipLast.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.ArrayDeque; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.plugins.RxJavaPlugins; public final class OperatorSkipLast implements Operator { diff --git a/src/main/java/io/reactivex/internal/operators/OperatorSkipLastTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSkipLastTimed.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorSkipLastTimed.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorSkipLastTimed.java index 28491301e2..4d6ebaf921 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorSkipLastTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSkipLastTimed.java @@ -11,15 +11,15 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; import org.reactivestreams.*; +import io.reactivex.Flowable.Operator; import io.reactivex.Scheduler; -import io.reactivex.Observable.Operator; import io.reactivex.internal.queue.SpscLinkedArrayQueue; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorSkipUntil.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSkipUntil.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorSkipUntil.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorSkipUntil.java index 10bb231a24..18a3bb793f 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorSkipUntil.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSkipUntil.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicBoolean; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.disposables.ArrayCompositeResource; import io.reactivex.internal.subscriptions.*; import io.reactivex.subscribers.SerializedSubscriber; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorSkipWhile.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSkipWhile.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/OperatorSkipWhile.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorSkipWhile.java index ced080f964..3858535b24 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorSkipWhile.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSkipWhile.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.Predicate; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorSwitchIfEmpty.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSwitchIfEmpty.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/OperatorSwitchIfEmpty.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorSwitchIfEmpty.java index 68ff82853f..4a46dbd407 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorSwitchIfEmpty.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSwitchIfEmpty.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.subscriptions.SubscriptionArbiter; public final class OperatorSwitchIfEmpty implements Operator { diff --git a/src/main/java/io/reactivex/internal/operators/OperatorSwitchMap.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSwitchMap.java similarity index 99% rename from src/main/java/io/reactivex/internal/operators/OperatorSwitchMap.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorSwitchMap.java index aa360465d7..755703c4de 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorSwitchMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorSwitchMap.java @@ -11,14 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Queue; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.Function; import io.reactivex.internal.queue.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorTake.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTake.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorTake.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorTake.java index d1c02a1aa4..4a640ed466 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorTake.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTake.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicLong; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorTakeLast.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeLast.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorTakeLast.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeLast.java index dfea2844e2..780a842e66 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorTakeLast.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeLast.java @@ -11,14 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.ArrayDeque; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorTakeLastOne.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeLastOne.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorTakeLastOne.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeLastOne.java index d064cd5d35..8dc5df9da5 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorTakeLastOne.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeLastOne.java @@ -10,13 +10,13 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicInteger; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.subscriptions.SubscriptionHelper; public enum OperatorTakeLastOne implements Operator { diff --git a/src/main/java/io/reactivex/internal/operators/OperatorTakeLastTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeLastTimed.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorTakeLastTimed.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeLastTimed.java index 7109236aed..d62c073c53 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorTakeLastTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeLastTimed.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Queue; import java.util.concurrent.TimeUnit; @@ -19,8 +19,8 @@ import org.reactivestreams.*; +import io.reactivex.Flowable.Operator; import io.reactivex.Scheduler; -import io.reactivex.Observable.Operator; import io.reactivex.internal.queue.SpscLinkedArrayQueue; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorTakeUntil.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeUntil.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorTakeUntil.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeUntil.java index 7d3d444c8c..3e9a28eb72 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorTakeUntil.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeUntil.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicBoolean; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.disposables.ArrayCompositeResource; import io.reactivex.internal.subscriptions.*; import io.reactivex.subscribers.SerializedSubscriber; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorTakeUntilPredicate.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeUntilPredicate.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/OperatorTakeUntilPredicate.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeUntilPredicate.java index 4ad84b0dd2..3510c2a489 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorTakeUntilPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeUntilPredicate.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.Predicate; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorTakeWhile.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeWhile.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/OperatorTakeWhile.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeWhile.java index ea180f438d..465858f283 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorTakeWhile.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTakeWhile.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.Predicate; import io.reactivex.internal.subscriptions.SubscriptionHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorThrottleFirstTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorThrottleFirstTimed.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorThrottleFirstTimed.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorThrottleFirstTimed.java index 602f7b3e93..d6384b33bc 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorThrottleFirstTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorThrottleFirstTimed.java @@ -11,15 +11,15 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; import org.reactivestreams.*; +import io.reactivex.Flowable.Operator; import io.reactivex.Scheduler; -import io.reactivex.Observable.Operator; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorTimeInterval.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTimeInterval.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/OperatorTimeInterval.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorTimeInterval.java index b8d4e98767..7b3bc335ea 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorTimeInterval.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTimeInterval.java @@ -11,14 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.TimeUnit; import org.reactivestreams.*; +import io.reactivex.Flowable.Operator; import io.reactivex.Scheduler; -import io.reactivex.Observable.Operator; import io.reactivex.schedulers.Timed; public final class OperatorTimeInterval implements Operator, T> { diff --git a/src/main/java/io/reactivex/internal/operators/OperatorTimeout.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTimeout.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/OperatorTimeout.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorTimeout.java index 8ff92adcec..3a73abdbe2 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorTimeout.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTimeout.java @@ -11,17 +11,17 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.disposables.Disposable; import io.reactivex.functions.*; -import io.reactivex.internal.subscribers.*; +import io.reactivex.internal.subscribers.flowable.*; import io.reactivex.internal.subscriptions.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.SerializedSubscriber; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorTimeoutTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTimeoutTimed.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorTimeoutTimed.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorTimeoutTimed.java index 54cc3eebd7..f9fafe541f 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorTimeoutTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorTimeoutTimed.java @@ -11,18 +11,18 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.*; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; import org.reactivestreams.*; +import io.reactivex.Flowable.Operator; import io.reactivex.Scheduler; -import io.reactivex.Observable.Operator; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; -import io.reactivex.internal.subscribers.FullArbiterSubscriber; +import io.reactivex.internal.subscribers.flowable.FullArbiterSubscriber; import io.reactivex.internal.subscriptions.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.SerializedSubscriber; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorToList.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorToList.java similarity index 95% rename from src/main/java/io/reactivex/internal/operators/OperatorToList.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorToList.java index c40f04fb22..309dfa7385 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorToList.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorToList.java @@ -11,15 +11,15 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.Supplier; -import io.reactivex.internal.subscribers.CancelledSubscriber; +import io.reactivex.internal.subscribers.flowable.CancelledSubscriber; import io.reactivex.internal.subscriptions.EmptySubscription; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/OperatorUnsubscribeOn.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorUnsubscribeOn.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/OperatorUnsubscribeOn.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorUnsubscribeOn.java index 82334ebe12..4be5558b13 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorUnsubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorUnsubscribeOn.java @@ -11,14 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicBoolean; import org.reactivestreams.*; +import io.reactivex.Flowable.Operator; import io.reactivex.Scheduler; -import io.reactivex.Observable.Operator; import io.reactivex.internal.subscriptions.SubscriptionHelper; public final class OperatorUnsubscribeOn implements Operator { diff --git a/src/main/java/io/reactivex/internal/operators/OperatorWindow.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorWindow.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/OperatorWindow.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorWindow.java index 777f99de3e..687fdbec5c 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorWindow.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorWindow.java @@ -11,20 +11,20 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.ArrayDeque; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; -import io.reactivex.subjects.UnicastSubject; +import io.reactivex.processors.UnicastProcessor; -public final class OperatorWindow implements Operator, T> { +public final class OperatorWindow implements Operator, T> { final long count; final long skip; final int capacityHint; @@ -36,7 +36,7 @@ public OperatorWindow(long count, long skip, int capacityHint) { } @Override - public Subscriber apply(Subscriber> t) { + public Subscriber apply(Subscriber> t) { if (count == skip) { return new WindowExactSubscriber(t, count, capacityHint); } @@ -48,7 +48,7 @@ static final class WindowExactSubscriber implements Subscriber, Subscription, Runnable { /** */ private static final long serialVersionUID = -7481782523886138128L; - final Subscriber> actual; + final Subscriber> actual; final long count; final int capacityHint; @@ -56,11 +56,11 @@ static final class WindowExactSubscriber Subscription s; - UnicastSubject window; + UnicastProcessor window; volatile boolean cancelled; - public WindowExactSubscriber(Subscriber> actual, long count, int capacityHint) { + public WindowExactSubscriber(Subscriber> actual, long count, int capacityHint) { this.actual = actual; this.count = count; this.capacityHint = capacityHint; @@ -79,9 +79,9 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { - UnicastSubject w = window; + UnicastProcessor w = window; if (w == null && !cancelled) { - w = UnicastSubject.create(capacityHint, this); + w = UnicastProcessor.create(capacityHint, this); window = w; actual.onNext(w); } @@ -99,7 +99,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - UnicastSubject w = window; + UnicastProcessor w = window; if (w != null) { window = null; w.onError(t); @@ -109,7 +109,7 @@ public void onError(Throwable t) { @Override public void onComplete() { - UnicastSubject w = window; + UnicastProcessor w = window; if (w != null) { window = null; w.onComplete(); @@ -144,11 +144,11 @@ static final class WindowSkipSubscriber extends AtomicBoolean implements Subscriber, Subscription, Runnable { /** */ private static final long serialVersionUID = 3366976432059579510L; - final Subscriber> actual; + final Subscriber> actual; final long count; final long skip; final int capacityHint; - final ArrayDeque> windows; + final ArrayDeque> windows; long index; @@ -161,12 +161,12 @@ static final class WindowSkipSubscriber extends AtomicBoolean final AtomicInteger wip = new AtomicInteger(); - public WindowSkipSubscriber(Subscriber> actual, long count, long skip, int capacityHint) { + public WindowSkipSubscriber(Subscriber> actual, long count, long skip, int capacityHint) { this.actual = actual; this.count = count; this.skip = skip; this.capacityHint = capacityHint; - this.windows = new ArrayDeque>(); + this.windows = new ArrayDeque>(); } @Override @@ -182,7 +182,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { - final ArrayDeque> ws = windows; + final ArrayDeque> ws = windows; long i = index; @@ -190,14 +190,14 @@ public void onNext(T t) { if (i % s == 0 && !cancelled) { wip.getAndIncrement(); - UnicastSubject w = UnicastSubject.create(capacityHint, this); + UnicastProcessor w = UnicastProcessor.create(capacityHint, this); ws.offer(w); actual.onNext(w); } long c = firstEmission + 1; - for (UnicastSubject w : ws) { + for (UnicastProcessor w : ws) { w.onNext(t); } @@ -217,7 +217,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - final ArrayDeque> ws = windows; + final ArrayDeque> ws = windows; while (!ws.isEmpty()) { ws.poll().onError(t); } @@ -226,7 +226,7 @@ public void onError(Throwable t) { @Override public void onComplete() { - final ArrayDeque> ws = windows; + final ArrayDeque> ws = windows; while (!ws.isEmpty()) { ws.poll().onComplete(); } diff --git a/src/main/java/io/reactivex/internal/operators/OperatorWindowBoundary.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorWindowBoundary.java similarity index 89% rename from src/main/java/io/reactivex/internal/operators/OperatorWindowBoundary.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorWindowBoundary.java index e556db61a9..3db1900fbb 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorWindowBoundary.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorWindowBoundary.java @@ -11,25 +11,25 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Queue; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable; +import io.reactivex.Flowable.Operator; import io.reactivex.disposables.Disposable; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.*; +import io.reactivex.internal.subscribers.flowable.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.NotificationLite; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.UnicastSubject; +import io.reactivex.processors.UnicastProcessor; import io.reactivex.subscribers.SerializedSubscriber; -public final class OperatorWindowBoundary implements Operator, T> { +public final class OperatorWindowBoundary implements Operator, T> { final Publisher other; final int bufferSize; @@ -39,12 +39,12 @@ public OperatorWindowBoundary(Publisher other, int bufferSize) { } @Override - public Subscriber apply(Subscriber> t) { - return new WindowBoundaryMainSubscriber(new SerializedSubscriber>(t), other, bufferSize); + public Subscriber apply(Subscriber> t) { + return new WindowBoundaryMainSubscriber(new SerializedSubscriber>(t), other, bufferSize); } static final class WindowBoundaryMainSubscriber - extends QueueDrainSubscriber> + extends QueueDrainSubscriber> implements Subscription { final Publisher other; @@ -59,13 +59,13 @@ static final class WindowBoundaryMainSubscriber public void dispose() { } }; - UnicastSubject window; + UnicastProcessor window; static final Object NEXT = new Object(); final AtomicLong windows = new AtomicLong(); - public WindowBoundaryMainSubscriber(Subscriber> actual, Publisher other, + public WindowBoundaryMainSubscriber(Subscriber> actual, Publisher other, int bufferSize) { super(actual, new MpscLinkedQueue()); this.other = other; @@ -80,14 +80,14 @@ public void onSubscribe(Subscription s) { } this.s = s; - Subscriber> a = actual; + Subscriber> a = actual; a.onSubscribe(this); if (cancelled) { return; } - UnicastSubject w = UnicastSubject.create(bufferSize); + UnicastProcessor w = UnicastProcessor.create(bufferSize); long r = requested(); if (r != 0L) { @@ -114,7 +114,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (fastEnter()) { - UnicastSubject w = window; + UnicastProcessor w = window; w.onNext(t); @@ -191,9 +191,9 @@ void dispose() { void drainLoop() { final Queue q = queue; - final Subscriber> a = actual; + final Subscriber> a = actual; int missed = 1; - UnicastSubject w = window; + UnicastProcessor w = window; for (;;) { for (;;) { @@ -230,7 +230,7 @@ void drainLoop() { continue; } - w = UnicastSubject.create(bufferSize); + w = UnicastProcessor.create(bufferSize); long r = requested(); if (r != 0L) { @@ -269,7 +269,7 @@ void next() { } @Override - public boolean accept(Subscriber> a, Object v) { + public boolean accept(Subscriber> a, Object v) { // not used by this operator return false; } diff --git a/src/main/java/io/reactivex/internal/operators/OperatorWindowBoundarySelector.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorWindowBoundarySelector.java similarity index 89% rename from src/main/java/io/reactivex/internal/operators/OperatorWindowBoundarySelector.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorWindowBoundarySelector.java index 9669ba3e26..17c374195a 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorWindowBoundarySelector.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorWindowBoundarySelector.java @@ -11,27 +11,27 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable; +import io.reactivex.Flowable.Operator; import io.reactivex.disposables.*; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.SetCompositeResource; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.*; +import io.reactivex.internal.subscribers.flowable.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.NotificationLite; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.UnicastSubject; +import io.reactivex.processors.UnicastProcessor; import io.reactivex.subscribers.SerializedSubscriber; -public final class OperatorWindowBoundarySelector implements Operator, T> { +public final class OperatorWindowBoundarySelector implements Operator, T> { final Publisher open; final Function> close; final int bufferSize; @@ -44,14 +44,14 @@ public OperatorWindowBoundarySelector(Publisher open, Function apply(Subscriber> t) { + public Subscriber apply(Subscriber> t) { return new WindowBoundaryMainSubscriber( - new SerializedSubscriber>(t), + new SerializedSubscriber>(t), open, close, bufferSize); } static final class WindowBoundaryMainSubscriber - extends QueueDrainSubscriber> + extends QueueDrainSubscriber> implements Subscription { final Publisher open; final Function> close; @@ -67,18 +67,18 @@ static final class WindowBoundaryMainSubscriber public void dispose() { } }; - final List> ws; + final List> ws; final AtomicLong windows = new AtomicLong(); - public WindowBoundaryMainSubscriber(Subscriber> actual, + public WindowBoundaryMainSubscriber(Subscriber> actual, Publisher open, Function> close, int bufferSize) { super(actual, new MpscLinkedQueue()); this.open = open; this.close = close; this.bufferSize = bufferSize; this.resources = new SetCompositeResource(Disposables.consumeAndDispose()); - this.ws = new ArrayList>(); + this.ws = new ArrayList>(); windows.lazySet(1); } @@ -109,7 +109,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (fastEnter()) { - for (UnicastSubject w : ws) { + for (UnicastProcessor w : ws) { w.onNext(t); } if (leave(-1) == 0) { @@ -207,8 +207,8 @@ void dispose() { void drainLoop() { final Queue q = queue; - final Subscriber> a = actual; - final List> ws = this.ws; + final Subscriber> a = actual; + final List> ws = this.ws; int missed = 1; for (;;) { @@ -223,11 +223,11 @@ void drainLoop() { dispose(); Throwable e = error; if (e != null) { - for (UnicastSubject w : ws) { + for (UnicastProcessor w : ws) { w.onError(e); } } else { - for (UnicastSubject w : ws) { + for (UnicastProcessor w : ws) { w.onComplete(); } } @@ -243,7 +243,7 @@ void drainLoop() { @SuppressWarnings("unchecked") WindowOperation wo = (WindowOperation) o; - UnicastSubject w = wo.w; + UnicastProcessor w = wo.w; if (w != null) { if (ws.remove(wo.w)) { wo.w.onComplete(); @@ -261,7 +261,7 @@ void drainLoop() { } - w = UnicastSubject.create(bufferSize); + w = UnicastProcessor.create(bufferSize); long r = requested(); if (r != 0L) { @@ -303,7 +303,7 @@ void drainLoop() { continue; } - for (UnicastSubject w : ws) { + for (UnicastProcessor w : ws) { w.onNext(NotificationLite.getValue(o)); } } @@ -316,7 +316,7 @@ void drainLoop() { } @Override - public boolean accept(Subscriber> a, Object v) { + public boolean accept(Subscriber> a, Object v) { // not used by this operator return false; } @@ -338,9 +338,9 @@ void close(OperatorWindowBoundaryCloseSubscriber w) { } static final class WindowOperation { - final UnicastSubject w; + final UnicastProcessor w; final B open; - public WindowOperation(UnicastSubject w, B open) { + public WindowOperation(UnicastProcessor w, B open) { this.w = w; this.open = open; } @@ -385,11 +385,11 @@ public void onComplete() { static final class OperatorWindowBoundaryCloseSubscriber extends DisposableSubscriber { final WindowBoundaryMainSubscriber parent; - final UnicastSubject w; + final UnicastProcessor w; boolean done; - public OperatorWindowBoundaryCloseSubscriber(WindowBoundaryMainSubscriber parent, UnicastSubject w) { + public OperatorWindowBoundaryCloseSubscriber(WindowBoundaryMainSubscriber parent, UnicastProcessor w) { this.parent = parent; this.w = w; } diff --git a/src/main/java/io/reactivex/internal/operators/OperatorWindowBoundarySupplier.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorWindowBoundarySupplier.java similarity index 90% rename from src/main/java/io/reactivex/internal/operators/OperatorWindowBoundarySupplier.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorWindowBoundarySupplier.java index 39ab3c51ab..efc155ca3f 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorWindowBoundarySupplier.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorWindowBoundarySupplier.java @@ -11,26 +11,26 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Queue; import java.util.concurrent.atomic.*; import org.reactivestreams.*; -import io.reactivex.Observable; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable; +import io.reactivex.Flowable.Operator; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Supplier; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.*; +import io.reactivex.internal.subscribers.flowable.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.NotificationLite; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.UnicastSubject; +import io.reactivex.processors.UnicastProcessor; import io.reactivex.subscribers.SerializedSubscriber; -public final class OperatorWindowBoundarySupplier implements Operator, T> { +public final class OperatorWindowBoundarySupplier implements Operator, T> { final Supplier> other; final int bufferSize; @@ -40,12 +40,12 @@ public OperatorWindowBoundarySupplier(Supplier> other, in } @Override - public Subscriber apply(Subscriber> t) { - return new WindowBoundaryMainSubscriber(new SerializedSubscriber>(t), other, bufferSize); + public Subscriber apply(Subscriber> t) { + return new WindowBoundaryMainSubscriber(new SerializedSubscriber>(t), other, bufferSize); } static final class WindowBoundaryMainSubscriber - extends QueueDrainSubscriber> + extends QueueDrainSubscriber> implements Subscription { final Supplier> other; @@ -60,13 +60,13 @@ static final class WindowBoundaryMainSubscriber public void dispose() { } }; - UnicastSubject window; + UnicastProcessor window; static final Object NEXT = new Object(); final AtomicLong windows = new AtomicLong(); - public WindowBoundaryMainSubscriber(Subscriber> actual, Supplier> other, + public WindowBoundaryMainSubscriber(Subscriber> actual, Supplier> other, int bufferSize) { super(actual, new MpscLinkedQueue()); this.other = other; @@ -81,7 +81,7 @@ public void onSubscribe(Subscription s) { } this.s = s; - Subscriber> a = actual; + Subscriber> a = actual; a.onSubscribe(this); if (cancelled) { @@ -104,7 +104,7 @@ public void onSubscribe(Subscription s) { return; } - UnicastSubject w = UnicastSubject.create(bufferSize); + UnicastProcessor w = UnicastProcessor.create(bufferSize); long r = requested(); if (r != 0L) { @@ -133,7 +133,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (fastEnter()) { - UnicastSubject w = window; + UnicastProcessor w = window; w.onNext(t); @@ -210,9 +210,9 @@ void dispose() { void drainLoop() { final Queue q = queue; - final Subscriber> a = actual; + final Subscriber> a = actual; int missed = 1; - UnicastSubject w = window; + UnicastProcessor w = window; for (;;) { for (;;) { @@ -264,7 +264,7 @@ void drainLoop() { return; } - w = UnicastSubject.create(bufferSize); + w = UnicastProcessor.create(bufferSize); long r = requested(); if (r != 0L) { @@ -310,7 +310,7 @@ void next() { } @Override - public boolean accept(Subscriber> a, Object v) { + public boolean accept(Subscriber> a, Object v) { // not used by this operator return false; } diff --git a/src/main/java/io/reactivex/internal/operators/OperatorWindowTimed.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorWindowTimed.java similarity index 90% rename from src/main/java/io/reactivex/internal/operators/OperatorWindowTimed.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorWindowTimed.java index d82811e63e..2844af1bd4 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorWindowTimed.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorWindowTimed.java @@ -11,28 +11,27 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.nio.channels.CancelledKeyException; import java.util.*; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; import org.reactivestreams.*; -import io.reactivex.Observable; -import io.reactivex.Observable.Operator; -import io.reactivex.Scheduler; +import io.reactivex.*; +import io.reactivex.Flowable.Operator; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.QueueDrainSubscriber; +import io.reactivex.internal.subscribers.flowable.QueueDrainSubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.NotificationLite; -import io.reactivex.subjects.UnicastSubject; +import io.reactivex.processors.UnicastProcessor; import io.reactivex.subscribers.SerializedSubscriber; -public final class OperatorWindowTimed implements Operator, T> { +public final class OperatorWindowTimed implements Operator, T> { final long timespan; final long timeskip; final TimeUnit unit; @@ -53,8 +52,8 @@ public OperatorWindowTimed(long timespan, long timeskip, TimeUnit unit, Schedule } @Override - public Subscriber apply(Subscriber> t) { - SerializedSubscriber> actual = new SerializedSubscriber>(t); + public Subscriber apply(Subscriber> t) { + SerializedSubscriber> actual = new SerializedSubscriber>(t); if (timespan == timeskip) { if (maxSize == Long.MAX_VALUE) { @@ -72,7 +71,7 @@ public Subscriber apply(Subscriber> t) { } static final class WindowExactUnboundedSubscriber - extends QueueDrainSubscriber> + extends QueueDrainSubscriber> implements Subscriber, Subscription, Disposable, Runnable { final long timespan; final TimeUnit unit; @@ -83,7 +82,7 @@ static final class WindowExactUnboundedSubscriber boolean selfCancel; - UnicastSubject window; + UnicastProcessor window; final AtomicReference timer = new AtomicReference(); @@ -96,7 +95,7 @@ public void dispose() { } volatile boolean terminated; - public WindowExactUnboundedSubscriber(Subscriber> actual, long timespan, TimeUnit unit, + public WindowExactUnboundedSubscriber(Subscriber> actual, long timespan, TimeUnit unit, Scheduler scheduler, int bufferSize) { super(actual, new MpscLinkedQueue()); this.timespan = timespan; @@ -112,9 +111,9 @@ public void onSubscribe(Subscription s) { } this.s = s; - window = UnicastSubject.create(bufferSize); + window = UnicastProcessor.create(bufferSize); - Subscriber> a = actual; + Subscriber> a = actual; a.onSubscribe(this); long r = requested(); @@ -226,8 +225,8 @@ public void run() { void drainLoop() { final Queue q = queue; - final Subscriber> a = actual; - UnicastSubject w = window; + final Subscriber> a = actual; + UnicastProcessor w = window; int missed = 1; for (;;) { @@ -259,7 +258,7 @@ void drainLoop() { if (o == NEXT) { w.onComplete(); if (!term) { - w = UnicastSubject.create(bufferSize); + w = UnicastProcessor.create(bufferSize); window = w; long r = requested(); @@ -293,14 +292,14 @@ void drainLoop() { } @Override - public boolean accept(Subscriber> a, Object v) { + public boolean accept(Subscriber> a, Object v) { // not used in this operator return true; } } static final class WindowExactBoundedSubscriber - extends QueueDrainSubscriber> + extends QueueDrainSubscriber> implements Subscription, Disposable { final long timespan; final TimeUnit unit; @@ -317,7 +316,7 @@ static final class WindowExactBoundedSubscriber Subscription s; - UnicastSubject window; + UnicastProcessor window; Scheduler.Worker worker; @@ -331,7 +330,7 @@ public void dispose() { } }; public WindowExactBoundedSubscriber( - Subscriber> actual, + Subscriber> actual, long timespan, TimeUnit unit, Scheduler scheduler, int bufferSize, long maxSize, boolean restartTimerOnMaxSize) { super(actual, new MpscLinkedQueue()); @@ -351,7 +350,7 @@ public void onSubscribe(Subscription s) { this.s = s; - Subscriber> a = actual; + Subscriber> a = actual; a.onSubscribe(this); @@ -359,7 +358,7 @@ public void onSubscribe(Subscription s) { return; } - UnicastSubject w = UnicastSubject.create(bufferSize); + UnicastProcessor w = UnicastProcessor.create(bufferSize); window = w; long r = requested(); @@ -399,7 +398,7 @@ public void onNext(T t) { } if (fastEnter()) { - UnicastSubject w = window; + UnicastProcessor w = window; w.onNext(t); long c = count + 1; @@ -413,7 +412,7 @@ public void onNext(T t) { long r = requested(); if (r != 0L) { - w = UnicastSubject.create(bufferSize); + w = UnicastProcessor.create(bufferSize); window = w; actual.onNext(w); if (r != Long.MAX_VALUE) { @@ -500,15 +499,15 @@ public void dispose() { } @Override - public boolean accept(Subscriber> a, Object v) { + public boolean accept(Subscriber> a, Object v) { // not needed in this operator return false; } void drainLoop() { final Queue q = queue; - final Subscriber> a = actual; - UnicastSubject w = window; + final Subscriber> a = actual; + UnicastProcessor w = window; int missed = 1; for (;;) { @@ -548,7 +547,7 @@ void drainLoop() { if (isHolder) { ConsumerIndexHolder consumerIndexHolder = (ConsumerIndexHolder) o; if (producerIndex == consumerIndexHolder.index) { - w = UnicastSubject.create(bufferSize); + w = UnicastProcessor.create(bufferSize); window = w; long r = requested(); @@ -581,7 +580,7 @@ void drainLoop() { long r = requested(); if (r != 0L) { - w = UnicastSubject.create(bufferSize); + w = UnicastProcessor.create(bufferSize); window = w; actual.onNext(w); if (r != Long.MAX_VALUE) { @@ -647,7 +646,7 @@ public void run() { } static final class WindowSkipSubscriber - extends QueueDrainSubscriber> + extends QueueDrainSubscriber> implements Subscription, Disposable, Runnable { final long timespan; final long timeskip; @@ -655,13 +654,13 @@ static final class WindowSkipSubscriber final Scheduler.Worker worker; final int bufferSize; - final List> windows; + final List> windows; Subscription s; volatile boolean terminated; - public WindowSkipSubscriber(Subscriber> actual, + public WindowSkipSubscriber(Subscriber> actual, long timespan, long timeskip, TimeUnit unit, Worker worker, int bufferSize) { super(actual, new MpscLinkedQueue()); @@ -670,7 +669,7 @@ public WindowSkipSubscriber(Subscriber> actual, this.unit = unit; this.worker = worker; this.bufferSize = bufferSize; - this.windows = new LinkedList>(); + this.windows = new LinkedList>(); } @Override @@ -689,7 +688,7 @@ public void onSubscribe(Subscription s) { long r = requested(); if (r != 0L) { - final UnicastSubject w = UnicastSubject.create(bufferSize); + final UnicastProcessor w = UnicastProcessor.create(bufferSize); windows.add(w); actual.onNext(w); @@ -717,7 +716,7 @@ public void run() { @Override public void onNext(T t) { if (fastEnter()) { - for (UnicastSubject w : windows) { + for (UnicastProcessor w : windows) { w.onNext(t); } if (leave(-1) == 0) { @@ -773,12 +772,12 @@ public void dispose() { } @Override - public boolean accept(Subscriber> a, Object v) { + public boolean accept(Subscriber> a, Object v) { // not used by this operator return false; } - void complete(UnicastSubject w) { + void complete(UnicastProcessor w) { queue.offer(new SubjectWork(w, false)); if (enter()) { drainLoop(); @@ -787,8 +786,8 @@ void complete(UnicastSubject w) { void drainLoop() { final Queue q = queue; - final Subscriber> a = actual; - final List> ws = windows; + final Subscriber> a = actual; + final List> ws = windows; int missed = 1; @@ -815,11 +814,11 @@ void drainLoop() { dispose(); Throwable e = error; if (e != null) { - for (UnicastSubject w : ws) { + for (UnicastProcessor w : ws) { w.onError(e); } } else { - for (UnicastSubject w : ws) { + for (UnicastProcessor w : ws) { w.onError(e); } } @@ -842,7 +841,7 @@ void drainLoop() { long r = requested(); if (r != 0L) { - final UnicastSubject w = UnicastSubject.create(bufferSize); + final UnicastProcessor w = UnicastProcessor.create(bufferSize); ws.add(w); a.onNext(w); if (r != Long.MAX_VALUE) { @@ -869,7 +868,7 @@ public void run() { } } - for (UnicastSubject w : ws) { + for (UnicastProcessor w : ws) { w.onNext(NotificationLite.getValue(v)); } } @@ -884,7 +883,7 @@ public void run() { @Override public void run() { - UnicastSubject w = UnicastSubject.create(bufferSize); + UnicastProcessor w = UnicastProcessor.create(bufferSize); SubjectWork sw = new SubjectWork(w, true); if (!cancelled) { @@ -896,9 +895,9 @@ public void run() { } static final class SubjectWork { - final UnicastSubject w; + final UnicastProcessor w; final boolean open; - public SubjectWork(UnicastSubject w, boolean open) { + public SubjectWork(UnicastProcessor w, boolean open) { this.w = w; this.open = open; } diff --git a/src/main/java/io/reactivex/internal/operators/OperatorWithLatestFrom.java b/src/main/java/io/reactivex/internal/operators/flowable/OperatorWithLatestFrom.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/OperatorWithLatestFrom.java rename to src/main/java/io/reactivex/internal/operators/flowable/OperatorWithLatestFrom.java index 01f9cfbdcd..83d1406c8a 100644 --- a/src/main/java/io/reactivex/internal/operators/OperatorWithLatestFrom.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/OperatorWithLatestFrom.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.BiFunction; import io.reactivex.internal.subscriptions.*; import io.reactivex.plugins.RxJavaPlugins; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherAmb.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherAmb.java similarity index 99% rename from src/main/java/io/reactivex/internal/operators/PublisherAmb.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherAmb.java index 0f67c6dc4b..119680bc56 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherAmb.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherAmb.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.*; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherArraySource.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherArraySource.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/PublisherArraySource.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherArraySource.java index 535b5c09be..ad6d5bdf81 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherArraySource.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherArraySource.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicLong; import org.reactivestreams.*; -import io.reactivex.internal.subscribers.ConditionalSubscriber; +import io.reactivex.internal.subscribers.flowable.ConditionalSubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherAutoConnect.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherAutoConnect.java similarity index 88% rename from src/main/java/io/reactivex/internal/operators/PublisherAutoConnect.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherAutoConnect.java index 8ae4f9bb16..a42013c079 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherAutoConnect.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherAutoConnect.java @@ -11,15 +11,15 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicInteger; import org.reactivestreams.*; import io.reactivex.disposables.Disposable; +import io.reactivex.flowables.ConnectableFlowable; import io.reactivex.functions.Consumer; -import io.reactivex.observables.ConnectableObservable; /** * Wraps a ConnectableObservable and calls its connect() method once @@ -28,12 +28,12 @@ * @param the value type of the chain */ public final class PublisherAutoConnect implements Publisher { - final ConnectableObservable source; + final ConnectableFlowable source; final int numberOfSubscribers; final Consumer connection; final AtomicInteger clients; - public PublisherAutoConnect(ConnectableObservable source, + public PublisherAutoConnect(ConnectableFlowable source, int numberOfSubscribers, Consumer connection) { if (numberOfSubscribers <= 0) { diff --git a/src/main/java/io/reactivex/internal/operators/PublisherCombineLatest.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherCombineLatest.java similarity index 99% rename from src/main/java/io/reactivex/internal/operators/PublisherCombineLatest.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherCombineLatest.java index 73915ad5c1..a7f7421eb9 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherCombineLatest.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherCombineLatest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import java.util.concurrent.atomic.*; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherDefer.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherDefer.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/PublisherDefer.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherDefer.java index 527bbca205..4f7eb28f19 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherDefer.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherDefer.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherDelaySubscriptionOther.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherDelaySubscriptionOther.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/PublisherDelaySubscriptionOther.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherDelaySubscriptionOther.java index 9f3c8203e9..6f082b2db9 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherDelaySubscriptionOther.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherDelaySubscriptionOther.java @@ -10,7 +10,7 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherEmptySource.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherEmptySource.java similarity index 95% rename from src/main/java/io/reactivex/internal/operators/PublisherEmptySource.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherEmptySource.java index 23d910135d..0e845e1b13 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherEmptySource.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherEmptySource.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherErrorSource.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherErrorSource.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/PublisherErrorSource.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherErrorSource.java index 9806afd4c2..bbdbcf8405 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherErrorSource.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherErrorSource.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherFutureSource.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherFutureSource.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/PublisherFutureSource.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherFutureSource.java index 2ba1e90765..fe442e789f 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherFutureSource.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherFutureSource.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.*; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherGenerate.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherGenerate.java similarity index 99% rename from src/main/java/io/reactivex/internal/operators/PublisherGenerate.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherGenerate.java index 5c2beba60c..3ed432f166 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherGenerate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherGenerate.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicLong; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherIntervalOnceSource.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherIntervalOnceSource.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/PublisherIntervalOnceSource.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherIntervalOnceSource.java index 381b7a4cf8..381dc8db2b 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherIntervalOnceSource.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherIntervalOnceSource.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherIntervalRangeSource.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherIntervalRangeSource.java similarity index 99% rename from src/main/java/io/reactivex/internal/operators/PublisherIntervalRangeSource.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherIntervalRangeSource.java index 55feb17261..b3c61ef0fd 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherIntervalRangeSource.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherIntervalRangeSource.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherIntervalSource.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherIntervalSource.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/PublisherIntervalSource.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherIntervalSource.java index 37dee8c2e8..df07c86771 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherIntervalSource.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherIntervalSource.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherIterableSource.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherIterableSource.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/PublisherIterableSource.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherIterableSource.java index fa7af841f9..d9d115b4d8 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherIterableSource.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherIterableSource.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Iterator; import java.util.concurrent.atomic.*; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherLift.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherLift.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/PublisherLift.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherLift.java index 04f868dfa3..4d3c3965e5 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherLift.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherLift.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.plugins.RxJavaPlugins; /** diff --git a/src/main/java/io/reactivex/internal/operators/PublisherRangeSource.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRangeSource.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/PublisherRangeSource.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherRangeSource.java index 5430378ea6..c040d208f4 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherRangeSource.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRangeSource.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicLong; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherRedo.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRedo.java similarity index 87% rename from src/main/java/io/reactivex/internal/operators/PublisherRedo.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherRedo.java index 93a2a78309..ca1aef0913 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherRedo.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRedo.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.*; @@ -19,16 +19,16 @@ import io.reactivex.*; import io.reactivex.functions.*; -import io.reactivex.internal.subscribers.ToNotificationSubscriber; +import io.reactivex.internal.subscribers.flowable.ToNotificationSubscriber; import io.reactivex.internal.subscriptions.SubscriptionArbiter; -import io.reactivex.subjects.BehaviorSubject; +import io.reactivex.processors.BehaviorProcessor; public final class PublisherRedo implements Publisher { final Publisher source; - final Function>>, ? extends Publisher> manager; + final Function>>, ? extends Publisher> manager; public PublisherRedo(Publisher source, - Function>>, ? extends Publisher> manager) { + Function>>, ? extends Publisher> manager) { this.source = source; this.manager = manager; } @@ -37,7 +37,7 @@ public PublisherRedo(Publisher source, public void subscribe(Subscriber s) { // FIXE use BehaviorSubject? (once available) - BehaviorSubject>> subject = BehaviorSubject.create(); + BehaviorProcessor>> subject = BehaviorProcessor.create(); final RedoSubscriber parent = new RedoSubscriber(s, subject, source); @@ -60,13 +60,13 @@ static final class RedoSubscriber extends AtomicBoolean implements Subscriber /** */ private static final long serialVersionUID = -1151903143112844287L; final Subscriber actual; - final BehaviorSubject>> subject; + final BehaviorProcessor>> subject; final Publisher source; final SubscriptionArbiter arbiter; final AtomicInteger wip = new AtomicInteger(); - public RedoSubscriber(Subscriber actual, BehaviorSubject>> subject, Publisher source) { + public RedoSubscriber(Subscriber actual, BehaviorProcessor>> subject, Publisher source) { this.actual = actual; this.subject = subject; this.source = source; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherRefCount.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRefCount.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/PublisherRefCount.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherRefCount.java index e0c10a4191..1bc3a0bf50 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRefCount.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.*; import java.util.concurrent.locks.ReentrantLock; @@ -19,10 +19,10 @@ import org.reactivestreams.*; import io.reactivex.disposables.*; +import io.reactivex.flowables.ConnectableFlowable; import io.reactivex.functions.Consumer; import io.reactivex.internal.disposables.SetCompositeResource; import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.observables.ConnectableObservable; /** * Returns an observable sequence that stays connected to the source as long as @@ -100,7 +100,7 @@ void cleanup() { } } - final ConnectableObservable source; + final ConnectableFlowable source; volatile SetCompositeResource baseSubscription = new SetCompositeResource(Disposables.consumeAndDispose()); final AtomicInteger subscriptionCount = new AtomicInteger(0); @@ -115,7 +115,7 @@ void cleanup() { * @param source * observable to apply ref count to */ - public PublisherRefCount(ConnectableObservable source) { + public PublisherRefCount(ConnectableFlowable source) { this.source = source; } diff --git a/src/main/java/io/reactivex/internal/operators/PublisherRepeat.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRepeat.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/PublisherRepeat.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherRepeat.java index 78b3904167..9ae20546bd 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherRepeat.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRepeat.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherRepeatUntil.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRepeatUntil.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/PublisherRepeatUntil.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherRepeatUntil.java index 17eff72e61..fca54ace2d 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherRepeatUntil.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRepeatUntil.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherRetryBiPredicate.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRetryBiPredicate.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/PublisherRetryBiPredicate.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherRetryBiPredicate.java index 25ffd9f26c..bf91654c6c 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherRetryBiPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRetryBiPredicate.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherRetryPredicate.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRetryPredicate.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/PublisherRetryPredicate.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherRetryPredicate.java index a3a1a08c32..08cfc92166 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherRetryPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherRetryPredicate.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherScalarAsyncSource.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherScalarAsyncSource.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/PublisherScalarAsyncSource.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherScalarAsyncSource.java index 2f7a2b8895..1411928057 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherScalarAsyncSource.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherScalarAsyncSource.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.Callable; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherSequenceEqual.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherSequenceEqual.java similarity index 99% rename from src/main/java/io/reactivex/internal/operators/PublisherSequenceEqual.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherSequenceEqual.java index d0cc62befb..79172cb3e1 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherSequenceEqual.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherSequenceEqual.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Queue; import java.util.concurrent.atomic.*; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherSubscribeOn.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherSubscribeOn.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/PublisherSubscribeOn.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherSubscribeOn.java index c9b515657a..4f63a375fc 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherSubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherSubscribeOn.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicReference; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherUsing.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherUsing.java similarity index 99% rename from src/main/java/io/reactivex/internal/operators/PublisherUsing.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherUsing.java index 2753bf3ad9..ec9bb1ba4d 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherUsing.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherUsing.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherZip.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherZip.java similarity index 99% rename from src/main/java/io/reactivex/internal/operators/PublisherZip.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherZip.java index 9fa0e9c986..3d0f7b33a2 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherZip.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherZip.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Queue; import java.util.concurrent.atomic.*; diff --git a/src/main/java/io/reactivex/internal/operators/PublisherZipIterable.java b/src/main/java/io/reactivex/internal/operators/flowable/PublisherZipIterable.java similarity index 98% rename from src/main/java/io/reactivex/internal/operators/PublisherZipIterable.java rename to src/main/java/io/reactivex/internal/operators/flowable/PublisherZipIterable.java index 937d7df8dc..77a66a3114 100644 --- a/src/main/java/io/reactivex/internal/operators/PublisherZipIterable.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/PublisherZipIterable.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Iterator; diff --git a/src/main/java/io/reactivex/internal/operators/SubscriberResourceWrapper.java b/src/main/java/io/reactivex/internal/operators/flowable/SubscriberResourceWrapper.java similarity index 97% rename from src/main/java/io/reactivex/internal/operators/SubscriberResourceWrapper.java rename to src/main/java/io/reactivex/internal/operators/flowable/SubscriberResourceWrapper.java index d68770a206..3d98616fcf 100644 --- a/src/main/java/io/reactivex/internal/operators/SubscriberResourceWrapper.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/SubscriberResourceWrapper.java @@ -11,9 +11,9 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; import org.reactivestreams.*; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorLatest.java b/src/main/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorLatest.java similarity index 91% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorLatest.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorLatest.java index 22613c4cf3..328f7e10d5 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorLatest.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorLatest.java @@ -11,15 +11,16 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.*; import java.util.concurrent.Semaphore; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; import io.reactivex.*; +import io.reactivex.Observable; import io.reactivex.Optional; -import io.reactivex.internal.subscribers.nbp.NbpDisposableSubscriber; +import io.reactivex.internal.subscribers.observable.NbpDisposableSubscriber; import io.reactivex.internal.util.Exceptions; /** @@ -39,14 +40,14 @@ public enum NbpBlockingOperatorLatest { * @return an {@code Iterable} that blocks until or unless the {@code Observable} emits an item that has not * been returned by the {@code Iterable}, then returns that item */ - public static Iterable latest(final NbpObservable source) { + public static Iterable latest(final Observable source) { return new Iterable() { @Override public Iterator iterator() { NbpLatestObserverIterator lio = new NbpLatestObserverIterator(); @SuppressWarnings("unchecked") - NbpObservable>> materialized = ((NbpObservable)source).materialize(); + Observable>> materialized = ((Observable)source).materialize(); materialized.subscribe(lio); return lio; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorMostRecent.java b/src/main/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorMostRecent.java similarity index 93% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorMostRecent.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorMostRecent.java index eff82c060f..24a5de2e68 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorMostRecent.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorMostRecent.java @@ -11,12 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; + import java.util.*; -import io.reactivex.*; +import io.reactivex.Observable; import io.reactivex.internal.util.*; +import io.reactivex.observers.DefaultObserver; /** * Returns an Iterable that always returns the item most recently emitted by an Observable, or a @@ -38,7 +40,7 @@ public enum NbpBlockingOperatorMostRecent { * @return an {@code Iterable} that always returns the item most recently emitted by {@code source}, or * {@code initialValue} if {@code source} has not yet emitted any items */ - public static Iterable mostRecent(final NbpObservable source, final T initialValue) { + public static Iterable mostRecent(final Observable source, final T initialValue) { return new Iterable() { @Override public Iterator iterator() { @@ -55,7 +57,7 @@ public Iterator iterator() { }; } - static final class NbpMostRecentObserver extends NbpObserver { + static final class NbpMostRecentObserver extends DefaultObserver { volatile Object value; private NbpMostRecentObserver(T value) { diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorNext.java b/src/main/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorNext.java similarity index 92% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorNext.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorNext.java index 293567d2f6..2115aa3b2e 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorNext.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorNext.java @@ -11,15 +11,16 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.*; +import io.reactivex.Observable; import io.reactivex.Optional; -import io.reactivex.internal.subscribers.nbp.NbpDisposableSubscriber; +import io.reactivex.Try; +import io.reactivex.internal.subscribers.observable.NbpDisposableSubscriber; import io.reactivex.internal.util.Exceptions; /** @@ -38,7 +39,7 @@ public enum NbpBlockingOperatorNext { * the {@code Observable} to observe * @return an {@code Iterable} that behaves like a blocking version of {@code items} */ - public static Iterable next(final NbpObservable items) { + public static Iterable next(final Observable items) { return new Iterable() { @Override public Iterator iterator() { @@ -53,14 +54,14 @@ public Iterator iterator() { /* private */static final class NextIterator implements Iterator { private final NbpNextObserver observer; - private final NbpObservable items; + private final Observable items; private T next; private boolean hasNext = true; private boolean isNextConsumed = true; private Throwable error = null; private boolean started = false; - private NextIterator(NbpObservable items, NbpNextObserver observer) { + private NextIterator(Observable items, NbpNextObserver observer) { this.items = items; this.observer = observer; } @@ -91,7 +92,7 @@ private boolean moveToNext() { // if not started, start now observer.setWaiting(1); @SuppressWarnings("unchecked") - NbpObservable nbpObservable = (NbpObservable)items; + Observable nbpObservable = (Observable)items; nbpObservable.materialize().subscribe(observer); } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpCachedObservable.java b/src/main/java/io/reactivex/internal/operators/observable/NbpCachedObservable.java similarity index 94% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpCachedObservable.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpCachedObservable.java index 3d3113a720..b995073a6c 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpCachedObservable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpCachedObservable.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.AtomicBoolean; -import io.reactivex.NbpObservable; +import io.reactivex.*; import io.reactivex.disposables.*; import io.reactivex.internal.disposables.SerialResource; import io.reactivex.internal.util.*; @@ -26,7 +26,7 @@ * * @param the source element type */ -public final class NbpCachedObservable extends NbpObservable { +public final class NbpCachedObservable extends Observable { /** The cache and replay state. */ private CacheState state; @@ -36,7 +36,7 @@ public final class NbpCachedObservable extends NbpObservable { * @param source the source Observable to cache * @return the CachedObservable instance */ - public static NbpCachedObservable from(NbpObservable source) { + public static NbpCachedObservable from(Observable source) { return from(source, 16); } @@ -47,7 +47,7 @@ public static NbpCachedObservable from(NbpObservable source) * @param capacityHint the hint for the internal buffer size * @return the CachedObservable instance */ - public static NbpCachedObservable from(NbpObservable source, int capacityHint) { + public static NbpCachedObservable from(Observable source, int capacityHint) { if (capacityHint < 1) { throw new IllegalArgumentException("capacityHint > 0 required"); } @@ -96,9 +96,9 @@ private NbpCachedObservable(NbpOnSubscribe onSubscribe, CacheState state) * * @param */ - static final class CacheState extends LinkedArrayList implements NbpSubscriber { + static final class CacheState extends LinkedArrayList implements Observer { /** The source observable to connect to. */ - final NbpObservable source; + final Observable source; /** Holds onto the subscriber connected to source. */ final SerialResource connection; /** Guarded by connection (not this). */ @@ -114,7 +114,7 @@ static final class CacheState extends LinkedArrayList implements NbpSubscribe */ boolean sourceDone; - public CacheState(NbpObservable source, int capacityHint) { + public CacheState(Observable source, int capacityHint) { super(capacityHint); this.source = source; this.producers = EMPTY; @@ -230,7 +230,7 @@ public CachedSubscribe(CacheState state) { this.state = state; } @Override - public void accept(NbpSubscriber t) { + public void accept(Observer t) { // we can connect first because we replay everything anyway ReplaySubscription rp = new ReplaySubscription(t, state); state.addProducer(rp); @@ -253,7 +253,7 @@ public void accept(NbpSubscriber t) { */ static final class ReplaySubscription implements Disposable { /** The actual child subscriber. */ - final NbpSubscriber child; + final Observer child; /** The cache state object. */ final CacheState state; @@ -280,7 +280,7 @@ static final class ReplaySubscription implements Disposable { /** Set if the Subscription has been cancelled/disposed. */ volatile boolean cancelled; - public ReplaySubscription(NbpSubscriber child, CacheState state) { + public ReplaySubscription(Observer child, CacheState state) { this.child = child; this.state = state; } @@ -310,7 +310,7 @@ public void replay() { } boolean skipFinal = false; try { - final NbpSubscriber child = this.child; + final Observer child = this.child; for (;;) { diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpObservableScalarSource.java b/src/main/java/io/reactivex/internal/operators/observable/NbpObservableScalarSource.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpObservableScalarSource.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpObservableScalarSource.java index eb009abbde..43ad80d9ed 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpObservableScalarSource.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpObservableScalarSource.java @@ -11,9 +11,9 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable; +import io.reactivex.*; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.EmptyDisposable; @@ -21,12 +21,12 @@ * Represents a constant scalar value. * @param the value type */ -public final class NbpObservableScalarSource extends NbpObservable { +public final class NbpObservableScalarSource extends Observable { private final T value; public NbpObservableScalarSource(final T value) { super(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { s.onSubscribe(EmptyDisposable.INSTANCE); s.onNext(value); s.onComplete(); @@ -39,11 +39,11 @@ public T value() { return value; } - public NbpOnSubscribe scalarFlatMap(final Function> mapper) { + public NbpOnSubscribe scalarFlatMap(final Function> mapper) { return new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { - NbpObservable other; + public void accept(Observer s) { + Observable other; try { other = mapper.apply(value); } catch (Throwable e) { diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeAmb.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeAmb.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeAmb.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeAmb.java index 498ff6432d..c42937177e 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeAmb.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeAmb.java @@ -11,36 +11,36 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; public final class NbpOnSubscribeAmb implements NbpOnSubscribe { - final NbpObservable[] sources; - final Iterable> sourcesIterable; + final Observable[] sources; + final Iterable> sourcesIterable; - public NbpOnSubscribeAmb(NbpObservable[] sources, Iterable> sourcesIterable) { + public NbpOnSubscribeAmb(Observable[] sources, Iterable> sourcesIterable) { this.sources = sources; this.sourcesIterable = sourcesIterable; } @Override @SuppressWarnings("unchecked") - public void accept(NbpSubscriber s) { - NbpObservable[] sources = this.sources; + public void accept(Observer s) { + Observable[] sources = this.sources; int count = 0; if (sources == null) { - sources = new NbpObservable[8]; - for (NbpObservable p : sourcesIterable) { + sources = new Observable[8]; + for (Observable p : sourcesIterable) { if (count == sources.length) { - NbpObservable[] b = new NbpObservable[count + (count >> 2)]; + Observable[] b = new Observable[count + (count >> 2)]; System.arraycopy(sources, 0, b, 0, count); sources = b; } @@ -64,18 +64,18 @@ public void accept(NbpSubscriber s) { } static final class AmbCoordinator implements Disposable { - final NbpSubscriber actual; + final Observer actual; final AmbInnerSubscriber[] subscribers; final AtomicInteger winner = new AtomicInteger(); @SuppressWarnings("unchecked") - public AmbCoordinator(NbpSubscriber actual, int count) { + public AmbCoordinator(Observer actual, int count) { this.actual = actual; this.subscribers = new AmbInnerSubscriber[count]; } - public void subscribe(NbpObservable[] sources) { + public void subscribe(Observable[] sources) { AmbInnerSubscriber[] as = subscribers; int len = as.length; for (int i = 0; i < len; i++) { @@ -123,12 +123,12 @@ public void dispose() { } } - static final class AmbInnerSubscriber extends AtomicReference implements NbpSubscriber, Disposable { + static final class AmbInnerSubscriber extends AtomicReference implements Observer, Disposable { /** */ private static final long serialVersionUID = -1185974347409665484L; final AmbCoordinator parent; final int index; - final NbpSubscriber actual; + final Observer actual; boolean won; @@ -137,7 +137,7 @@ static final class AmbInnerSubscriber extends AtomicReference imp public void dispose() { } }; - public AmbInnerSubscriber(AmbCoordinator parent, int index, NbpSubscriber actual) { + public AmbInnerSubscriber(AmbCoordinator parent, int index, Observer actual) { this.parent = parent; this.index = index; this.actual = actual; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeArraySource.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeArraySource.java similarity index 89% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeArraySource.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeArraySource.java index 52682f32ca..cf8eb2a9e2 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeArraySource.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeArraySource.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.BooleanDisposable; public final class NbpOnSubscribeArraySource implements NbpOnSubscribe { @@ -25,7 +26,7 @@ public T[] array() { return array; } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { BooleanDisposable bd = new BooleanDisposable(); s.onSubscribe(bd); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeAutoConnect.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeAutoConnect.java similarity index 82% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeAutoConnect.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeAutoConnect.java index a150e00264..7159a95334 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeAutoConnect.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeAutoConnect.java @@ -11,14 +11,15 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; -import io.reactivex.observables.nbp.NbpConnectableObservable; +import io.reactivex.observables.ConnectableObservable; /** * Wraps a ConnectableObservable and calls its connect() method once @@ -27,12 +28,12 @@ * @param the value type of the chain */ public final class NbpOnSubscribeAutoConnect implements NbpOnSubscribe { - final NbpConnectableObservable source; + final ConnectableObservable source; final int numberOfSubscribers; final Consumer connection; final AtomicInteger clients; - public NbpOnSubscribeAutoConnect(NbpConnectableObservable source, + public NbpOnSubscribeAutoConnect(ConnectableObservable source, int numberOfSubscribers, Consumer connection) { if (numberOfSubscribers <= 0) { @@ -45,7 +46,7 @@ public NbpOnSubscribeAutoConnect(NbpConnectableObservable source, } @Override - public void accept(NbpSubscriber child) { + public void accept(Observer child) { source.unsafeSubscribe(child); if (clients.incrementAndGet() == numberOfSubscribers) { source.connect(connection); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeCombineLatest.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeCombineLatest.java similarity index 90% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeCombineLatest.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeCombineLatest.java index 976fe206c8..f94e1c0a63 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeCombineLatest.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeCombineLatest.java @@ -11,13 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.*; import java.util.concurrent.atomic.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.Function; @@ -27,14 +28,14 @@ import io.reactivex.plugins.RxJavaPlugins; public final class NbpOnSubscribeCombineLatest implements NbpOnSubscribe { - final NbpObservable[] sources; - final Iterable> sourcesIterable; + final Observable[] sources; + final Iterable> sourcesIterable; final Function combiner; final int bufferSize; final boolean delayError; - public NbpOnSubscribeCombineLatest(NbpObservable[] sources, - Iterable> sourcesIterable, + public NbpOnSubscribeCombineLatest(Observable[] sources, + Iterable> sourcesIterable, Function combiner, int bufferSize, boolean delayError) { this.sources = sources; @@ -47,14 +48,14 @@ public NbpOnSubscribeCombineLatest(NbpObservable[] sources, @Override @SuppressWarnings("unchecked") - public void accept(NbpSubscriber s) { - NbpObservable[] sources = this.sources; + public void accept(Observer s) { + Observable[] sources = this.sources; int count = 0; if (sources == null) { - sources = new NbpObservable[8]; - for (NbpObservable p : sourcesIterable) { + sources = new Observable[8]; + for (Observable p : sourcesIterable) { if (count == sources.length) { - NbpObservable[] b = new NbpObservable[count + (count >> 2)]; + Observable[] b = new Observable[count + (count >> 2)]; System.arraycopy(sources, 0, b, 0, count); sources = b; } @@ -76,7 +77,7 @@ public void accept(NbpSubscriber s) { static final class LatestCoordinator extends AtomicInteger implements Disposable { /** */ private static final long serialVersionUID = 8567835998786448817L; - final NbpSubscriber actual; + final Observer actual; final Function combiner; final int count; final CombinerSubscriber[] subscribers; @@ -95,7 +96,7 @@ static final class LatestCoordinator extends AtomicInteger implements Disp int complete; @SuppressWarnings("unchecked") - public LatestCoordinator(NbpSubscriber actual, + public LatestCoordinator(Observer actual, Function combiner, int count, int bufferSize, boolean delayError) { this.actual = actual; @@ -108,8 +109,8 @@ public LatestCoordinator(NbpSubscriber actual, this.queue = new SpscLinkedArrayQueue(bufferSize); } - public void subscribe(NbpObservable[] sources) { - NbpSubscriber[] as = subscribers; + public void subscribe(Observable[] sources) { + Observer[] as = subscribers; int len = as.length; for (int i = 0; i < len; i++) { as[i] = new CombinerSubscriber(this, i); @@ -199,7 +200,7 @@ void drain() { } final Queue q = queue; - final NbpSubscriber a = actual; + final Observer a = actual; final boolean delayError = this.delayError; int missed = 1; @@ -262,7 +263,7 @@ void drain() { } - boolean checkTerminated(boolean d, boolean empty, NbpSubscriber a, Queue q, boolean delayError) { + boolean checkTerminated(boolean d, boolean empty, Observer a, Queue q, boolean delayError) { if (cancelled) { cancel(q); return true; @@ -312,7 +313,7 @@ void onError(Throwable e) { } } - static final class CombinerSubscriber implements NbpSubscriber, Disposable { + static final class CombinerSubscriber implements Observer, Disposable { final LatestCoordinator parent; final int index; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeDefer.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeDefer.java similarity index 75% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeDefer.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeDefer.java index 9cc3408f9c..6b77cc6361 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeDefer.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeDefer.java @@ -11,21 +11,21 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.functions.Supplier; import io.reactivex.internal.disposables.EmptyDisposable; public final class NbpOnSubscribeDefer implements NbpOnSubscribe { - final Supplier> supplier; - public NbpOnSubscribeDefer(Supplier> supplier) { + final Supplier> supplier; + public NbpOnSubscribeDefer(Supplier> supplier) { this.supplier = supplier; } @Override - public void accept(NbpSubscriber s) { - NbpObservable pub; + public void accept(Observer s) { + Observable pub; try { pub = supplier.get(); } catch (Throwable t) { diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeDelaySubscriptionOther.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeDelaySubscriptionOther.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeDelaySubscriptionOther.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeDelaySubscriptionOther.java index c31e15a1dd..5e0d54075b 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeDelaySubscriptionOther.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeDelaySubscriptionOther.java @@ -11,10 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.plugins.RxJavaPlugins; @@ -25,20 +25,20 @@ * @param the other value type, ignored */ public final class NbpOnSubscribeDelaySubscriptionOther implements NbpOnSubscribe { - final NbpObservable main; - final NbpObservable other; + final Observable main; + final Observable other; - public NbpOnSubscribeDelaySubscriptionOther(NbpObservable main, NbpObservable other) { + public NbpOnSubscribeDelaySubscriptionOther(Observable main, Observable other) { this.main = main; this.other = other; } @Override - public void accept(final NbpSubscriber child) { + public void accept(final Observer child) { final SerialDisposable serial = new SerialDisposable(); child.onSubscribe(serial); - NbpSubscriber otherSubscriber = new NbpSubscriber() { + Observer otherSubscriber = new Observer() { boolean done; @Override public void onSubscribe(Disposable d) { @@ -67,7 +67,7 @@ public void onComplete() { } done = true; - main.unsafeSubscribe(new NbpSubscriber() { + main.unsafeSubscribe(new Observer() { @Override public void onSubscribe(Disposable d) { serial.set(d); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeErrorSource.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeErrorSource.java similarity index 88% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeErrorSource.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeErrorSource.java index bad1f2de89..3e9b1ecf46 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeErrorSource.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeErrorSource.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.functions.Supplier; import io.reactivex.internal.disposables.EmptyDisposable; @@ -23,7 +24,7 @@ public NbpOnSubscribeErrorSource(Supplier errorSupplier) { this.errorSupplier = errorSupplier; } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { Throwable error; try { error = errorSupplier.get(); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeFutureSource.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeFutureSource.java similarity index 91% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeFutureSource.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeFutureSource.java index 8ff4dce10c..ba9bd29094 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeFutureSource.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeFutureSource.java @@ -11,11 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.BooleanDisposable; public final class NbpOnSubscribeFutureSource implements NbpOnSubscribe { @@ -30,7 +31,7 @@ public NbpOnSubscribeFutureSource(Future future, long timeout, Time } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { BooleanDisposable bd = new BooleanDisposable(); s.onSubscribe(bd); if (!bd.isDisposed()) { diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeGenerate.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeGenerate.java similarity index 86% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeGenerate.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeGenerate.java index 4c825c2d7d..6f67acd396 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeGenerate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeGenerate.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; @@ -21,10 +22,10 @@ public final class NbpOnSubscribeGenerate implements NbpOnSubscribe { final Supplier stateSupplier; - final BiFunction, S> generator; + final BiFunction, S> generator; final Consumer disposeState; - public NbpOnSubscribeGenerate(Supplier stateSupplier, BiFunction, S> generator, + public NbpOnSubscribeGenerate(Supplier stateSupplier, BiFunction, S> generator, Consumer disposeState) { this.stateSupplier = stateSupplier; this.generator = generator; @@ -32,7 +33,7 @@ public NbpOnSubscribeGenerate(Supplier stateSupplier, BiFunction s) { + public void accept(Observer s) { S state; try { @@ -48,10 +49,10 @@ public void accept(NbpSubscriber s) { } static final class GeneratorDisposable - implements NbpSubscriber, Disposable { + implements Observer, Disposable { - final NbpSubscriber actual; - final BiFunction, S> generator; + final Observer actual; + final BiFunction, S> generator; final Consumer disposeState; S state; @@ -60,8 +61,8 @@ static final class GeneratorDisposable boolean terminate; - public GeneratorDisposable(NbpSubscriber actual, - BiFunction, S> generator, + public GeneratorDisposable(Observer actual, + BiFunction, S> generator, Consumer disposeState, S initialState) { this.actual = actual; this.generator = generator; @@ -72,7 +73,7 @@ public GeneratorDisposable(NbpSubscriber actual, public void run() { S s = state; - final BiFunction, S> f = generator; + final BiFunction, S> f = generator; if (cancelled) { dispose(s); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeIntervalRangeSource.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeIntervalRangeSource.java similarity index 92% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeIntervalRangeSource.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeIntervalRangeSource.java index 4e5336741d..cc031ea842 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeIntervalRangeSource.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeIntervalRangeSource.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable.*; -import io.reactivex.Scheduler; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.plugins.RxJavaPlugins; @@ -39,7 +39,7 @@ public NbpOnSubscribeIntervalRangeSource(long start, long end, long initialDelay } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { IntervalRangeSubscriber is = new IntervalRangeSubscriber(s, start, end); s.onSubscribe(is); @@ -51,7 +51,7 @@ public void accept(NbpSubscriber s) { static final class IntervalRangeSubscriber implements Disposable, Runnable { - final NbpSubscriber actual; + final Observer actual; final long end; long count; @@ -65,7 +65,7 @@ public void dispose() { } final AtomicReference resource = new AtomicReference(); - public IntervalRangeSubscriber(NbpSubscriber actual, long start, long end) { + public IntervalRangeSubscriber(Observer actual, long start, long end) { this.actual = actual; this.count = start; this.end = end; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeIntervalSource.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeIntervalSource.java similarity index 90% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeIntervalSource.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeIntervalSource.java index a81a0183ed..aec684c237 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeIntervalSource.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeIntervalSource.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable.*; -import io.reactivex.Scheduler; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.plugins.RxJavaPlugins; @@ -35,7 +35,7 @@ public NbpOnSubscribeIntervalSource(long initialDelay, long period, TimeUnit uni } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { IntervalSubscriber is = new IntervalSubscriber(s); s.onSubscribe(is); @@ -47,7 +47,7 @@ public void accept(NbpSubscriber s) { static final class IntervalSubscriber implements Disposable, Runnable { - final NbpSubscriber actual; + final Observer actual; long count; @@ -60,7 +60,7 @@ public void dispose() { } final AtomicReference resource = new AtomicReference(); - public IntervalSubscriber(NbpSubscriber actual) { + public IntervalSubscriber(Observer actual) { this.actual = actual; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeIterableSource.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeIterableSource.java similarity index 93% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeIterableSource.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeIterableSource.java index 1555555713..433079fe86 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeIterableSource.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeIterableSource.java @@ -11,11 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Iterator; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.BooleanDisposable; import io.reactivex.internal.disposables.EmptyDisposable; @@ -26,7 +27,7 @@ public NbpOnSubscribeIterableSource(Iterable source) { } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { Iterator it; try { it = source.iterator(); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeLift.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeLift.java similarity index 86% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeLift.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeLift.java index 0259a30e9d..39641c0830 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeLift.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeLift.java @@ -11,10 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.plugins.RxJavaPlugins; /** @@ -30,9 +30,9 @@ public final class NbpOnSubscribeLift implements NbpOnSubscribe { /** The actual operator. */ final NbpOperator operator; /** The source publisher. */ - final NbpObservable source; + final Observable source; - public NbpOnSubscribeLift(NbpObservable source, NbpOperator operator) { + public NbpOnSubscribeLift(Observable source, NbpOperator operator) { this.source = source; this.operator = operator; } @@ -49,17 +49,17 @@ public NbpOnSubscribeLift(NbpObservable source, NbpOperator source() { + public Observable source() { return source; } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { try { if (s == null) { throw new NullPointerException("Operator " + operator + " received a null Subscriber"); } - NbpSubscriber st = operator.apply(s); + Observer st = operator.apply(s); if (st == null) { throw new NullPointerException("Operator " + operator + " returned a null Subscriber"); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRedo.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRedo.java similarity index 78% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRedo.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRedo.java index aff97aece6..1cd9507d52 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRedo.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRedo.java @@ -11,38 +11,38 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.*; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.functions.*; -import io.reactivex.internal.subscribers.nbp.NbpToNotificationSubscriber; -import io.reactivex.subjects.nbp.NbpBehaviorSubject; +import io.reactivex.internal.subscribers.observable.NbpToNotificationSubscriber; +import io.reactivex.subjects.BehaviorSubject; public final class NbpOnSubscribeRedo implements NbpOnSubscribe { - final NbpObservable source; - final Function>>, ? extends NbpObservable> manager; + final Observable source; + final Function>>, ? extends Observable> manager; - public NbpOnSubscribeRedo(NbpObservable source, - Function>>, ? extends NbpObservable> manager) { + public NbpOnSubscribeRedo(Observable source, + Function>>, ? extends Observable> manager) { this.source = source; this.manager = manager; } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { // FIXE use BehaviorSubject? (once available) - NbpBehaviorSubject>> subject = NbpBehaviorSubject.create(); + BehaviorSubject>> subject = BehaviorSubject.create(); final RedoSubscriber parent = new RedoSubscriber(s, subject, source); s.onSubscribe(parent.arbiter); - NbpObservable action = manager.apply(subject); + Observable action = manager.apply(subject); action.subscribe(new NbpToNotificationSubscriber(new Consumer>>() { @Override @@ -55,17 +55,17 @@ public void accept(Try> o) { parent.handle(Notification.next(0)); } - static final class RedoSubscriber extends AtomicBoolean implements NbpSubscriber { + static final class RedoSubscriber extends AtomicBoolean implements Observer { /** */ private static final long serialVersionUID = -1151903143112844287L; - final NbpSubscriber actual; - final NbpBehaviorSubject>> subject; - final NbpObservable source; + final Observer actual; + final BehaviorSubject>> subject; + final Observable source; final MultipleAssignmentDisposable arbiter; final AtomicInteger wip = new AtomicInteger(); - public RedoSubscriber(NbpSubscriber actual, NbpBehaviorSubject>> subject, NbpObservable source) { + public RedoSubscriber(Observer actual, BehaviorSubject>> subject, Observable source) { this.actual = actual; this.subject = subject; this.source = source; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRefCount.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRefCount.java similarity index 88% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRefCount.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRefCount.java index 596309bb52..6a0b1c458c 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRefCount.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRefCount.java @@ -11,17 +11,18 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.*; import java.util.concurrent.locks.ReentrantLock; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.functions.Consumer; import io.reactivex.internal.disposables.SetCompositeResource; import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.observables.nbp.NbpConnectableObservable; +import io.reactivex.observables.ConnectableObservable; /** * Returns an observable sequence that stays connected to the source as long as @@ -32,14 +33,14 @@ */ public final class NbpOnSubscribeRefCount implements NbpOnSubscribe { - final class ConnectionSubscriber implements NbpSubscriber, Disposable { - final NbpSubscriber subscriber; + final class ConnectionSubscriber implements Observer, Disposable { + final Observer subscriber; final SetCompositeResource currentBase; final Disposable resource; Disposable s; - private ConnectionSubscriber(NbpSubscriber subscriber, + private ConnectionSubscriber(Observer subscriber, SetCompositeResource currentBase, Disposable resource) { this.subscriber = subscriber; this.currentBase = currentBase; @@ -94,7 +95,7 @@ void cleanup() { } } - final NbpConnectableObservable source; + final ConnectableObservable source; volatile SetCompositeResource baseSubscription = new SetCompositeResource(Disposables.consumeAndDispose()); @@ -111,12 +112,12 @@ void cleanup() { * @param source * observable to apply ref count to */ - public NbpOnSubscribeRefCount(NbpConnectableObservable source) { + public NbpOnSubscribeRefCount(ConnectableObservable source) { this.source = source; } @Override - public void accept(final NbpSubscriber subscriber) { + public void accept(final Observer subscriber) { lock.lock(); if (subscriptionCount.incrementAndGet() == 1) { @@ -149,7 +150,7 @@ public void accept(final NbpSubscriber subscriber) { } - private Consumer onSubscribe(final NbpSubscriber subscriber, + private Consumer onSubscribe(final Observer subscriber, final AtomicBoolean writeLocked) { return new Consumer() { @Override @@ -167,7 +168,7 @@ public void accept(Disposable subscription) { }; } - void doSubscribe(final NbpSubscriber subscriber, final SetCompositeResource currentBase) { + void doSubscribe(final Observer subscriber, final SetCompositeResource currentBase) { // handle unsubscribing from the base subscription Disposable d = disconnect(currentBase); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRepeat.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRepeat.java similarity index 82% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRepeat.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRepeat.java index d1c87ee84e..9e4e769f90 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRepeat.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRepeat.java @@ -11,24 +11,24 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; public final class NbpOnSubscribeRepeat implements NbpOnSubscribe { - final NbpObservable source; + final Observable source; final long count; - public NbpOnSubscribeRepeat(NbpObservable source, long count) { + public NbpOnSubscribeRepeat(Observable source, long count) { this.source = source; this.count = count; } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { MultipleAssignmentDisposable mad = new MultipleAssignmentDisposable(); s.onSubscribe(mad); @@ -36,15 +36,15 @@ public void accept(NbpSubscriber s) { rs.subscribeNext(); } - static final class RepeatSubscriber extends AtomicInteger implements NbpSubscriber { + static final class RepeatSubscriber extends AtomicInteger implements Observer { /** */ private static final long serialVersionUID = -7098360935104053232L; - final NbpSubscriber actual; + final Observer actual; final MultipleAssignmentDisposable mad; - final NbpObservable source; + final Observable source; long remaining; - public RepeatSubscriber(NbpSubscriber actual, long count, MultipleAssignmentDisposable sa, NbpObservable source) { + public RepeatSubscriber(Observer actual, long count, MultipleAssignmentDisposable sa, Observable source) { this.actual = actual; this.mad = sa; this.source = source; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRepeatUntil.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRepeatUntil.java similarity index 81% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRepeatUntil.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRepeatUntil.java index deec32b34c..a75a71c056 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRepeatUntil.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRepeatUntil.java @@ -11,25 +11,25 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.functions.BooleanSupplier; public final class NbpOnSubscribeRepeatUntil implements NbpOnSubscribe { - final NbpObservable source; + final Observable source; final BooleanSupplier until; - public NbpOnSubscribeRepeatUntil(NbpObservable source, BooleanSupplier until) { + public NbpOnSubscribeRepeatUntil(Observable source, BooleanSupplier until) { this.source = source; this.until = until; } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { MultipleAssignmentDisposable sa = new MultipleAssignmentDisposable(); s.onSubscribe(sa); @@ -37,15 +37,15 @@ public void accept(NbpSubscriber s) { rs.subscribeNext(); } - static final class RepeatSubscriber extends AtomicInteger implements NbpSubscriber { + static final class RepeatSubscriber extends AtomicInteger implements Observer { /** */ private static final long serialVersionUID = -7098360935104053232L; - final NbpSubscriber actual; + final Observer actual; final MultipleAssignmentDisposable sa; - final NbpObservable source; + final Observable source; final BooleanSupplier stop; - public RepeatSubscriber(NbpSubscriber actual, BooleanSupplier until, MultipleAssignmentDisposable sa, NbpObservable source) { + public RepeatSubscriber(Observer actual, BooleanSupplier until, MultipleAssignmentDisposable sa, Observable source) { this.actual = actual; this.sa = sa; this.source = source; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRetryBiPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRetryBiPredicate.java similarity index 85% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRetryBiPredicate.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRetryBiPredicate.java index 0ba5868da4..c39bdc5ce3 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRetryBiPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRetryBiPredicate.java @@ -11,28 +11,28 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.BiPredicate; public final class NbpOnSubscribeRetryBiPredicate implements NbpOnSubscribe { - final NbpObservable source; + final Observable source; final BiPredicate predicate; public NbpOnSubscribeRetryBiPredicate( - NbpObservable source, + Observable source, BiPredicate predicate) { this.source = source; this.predicate = predicate; } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { SerialDisposable sa = new SerialDisposable(); s.onSubscribe(sa); @@ -40,17 +40,17 @@ public void accept(NbpSubscriber s) { rs.subscribeNext(); } - static final class RetryBiSubscriber extends AtomicInteger implements NbpSubscriber { + static final class RetryBiSubscriber extends AtomicInteger implements Observer { /** */ private static final long serialVersionUID = -7098360935104053232L; - final NbpSubscriber actual; + final Observer actual; final SerialDisposable sa; - final NbpObservable source; + final Observable source; final BiPredicate predicate; int retries; - public RetryBiSubscriber(NbpSubscriber actual, - BiPredicate predicate, SerialDisposable sa, NbpObservable source) { + public RetryBiSubscriber(Observer actual, + BiPredicate predicate, SerialDisposable sa, Observable source) { this.actual = actual; this.sa = sa; this.source = source; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRetryPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRetryPredicate.java similarity index 86% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRetryPredicate.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRetryPredicate.java index 3b4516317f..332f472e59 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRetryPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRetryPredicate.java @@ -11,21 +11,21 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.Predicate; public final class NbpOnSubscribeRetryPredicate implements NbpOnSubscribe { - final NbpObservable source; + final Observable source; final Predicate predicate; final long count; - public NbpOnSubscribeRetryPredicate(NbpObservable source, + public NbpOnSubscribeRetryPredicate(Observable source, long count, Predicate predicate) { this.source = source; @@ -34,7 +34,7 @@ public NbpOnSubscribeRetryPredicate(NbpObservable source, } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { SerialDisposable sa = new SerialDisposable(); s.onSubscribe(sa); @@ -42,17 +42,17 @@ public void accept(NbpSubscriber s) { rs.subscribeNext(); } - static final class RepeatSubscriber extends AtomicInteger implements NbpSubscriber { + static final class RepeatSubscriber extends AtomicInteger implements Observer { /** */ private static final long serialVersionUID = -7098360935104053232L; - final NbpSubscriber actual; + final Observer actual; final SerialDisposable sa; - final NbpObservable source; + final Observable source; final Predicate predicate; long remaining; - public RepeatSubscriber(NbpSubscriber actual, long count, - Predicate predicate, SerialDisposable sa, NbpObservable source) { + public RepeatSubscriber(Observer actual, long count, + Predicate predicate, SerialDisposable sa, Observable source) { this.actual = actual; this.sa = sa; this.source = source; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeScalarAsyncSource.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeScalarAsyncSource.java similarity index 90% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeScalarAsyncSource.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeScalarAsyncSource.java index 76356117d1..d10d5abb9e 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeScalarAsyncSource.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeScalarAsyncSource.java @@ -11,11 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.Callable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.BooleanDisposable; public final class NbpOnSubscribeScalarAsyncSource implements NbpOnSubscribe { @@ -24,7 +25,7 @@ public NbpOnSubscribeScalarAsyncSource(Callable callable) { this.callable = callable; } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { BooleanDisposable bd = new BooleanDisposable(); s.onSubscribe(bd); if (bd.isDisposed()) { diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeSequenceEqual.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeSequenceEqual.java similarity index 90% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeSequenceEqual.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeSequenceEqual.java index ec2866be4f..0852591ef3 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeSequenceEqual.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeSequenceEqual.java @@ -11,25 +11,25 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Queue; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.functions.BiPredicate; import io.reactivex.internal.disposables.ArrayCompositeResource; import io.reactivex.internal.queue.SpscLinkedArrayQueue; public final class NbpOnSubscribeSequenceEqual implements NbpOnSubscribe { - final NbpObservable first; - final NbpObservable second; + final Observable first; + final Observable second; final BiPredicate comparer; final int bufferSize; - public NbpOnSubscribeSequenceEqual(NbpObservable first, NbpObservable second, + public NbpOnSubscribeSequenceEqual(Observable first, Observable second, BiPredicate comparer, int bufferSize) { this.first = first; this.second = second; @@ -38,7 +38,7 @@ public NbpOnSubscribeSequenceEqual(NbpObservable first, NbpObservab } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { EqualCoordinator ec = new EqualCoordinator(s, bufferSize, first, second, comparer); ec.subscribe(); } @@ -46,17 +46,17 @@ public void accept(NbpSubscriber s) { static final class EqualCoordinator extends AtomicInteger implements Disposable { /** */ private static final long serialVersionUID = -6178010334400373240L; - final NbpSubscriber actual; + final Observer actual; final BiPredicate comparer; final ArrayCompositeResource resources; - final NbpObservable first; - final NbpObservable second; + final Observable first; + final Observable second; final EqualSubscriber[] subscribers; volatile boolean cancelled; - public EqualCoordinator(NbpSubscriber actual, int bufferSize, - NbpObservable first, NbpObservable second, + public EqualCoordinator(Observer actual, int bufferSize, + Observable first, Observable second, BiPredicate comparer) { this.actual = actual; this.first = first; @@ -199,7 +199,7 @@ void drain() { } } - static final class EqualSubscriber implements NbpSubscriber { + static final class EqualSubscriber implements Observer { final EqualCoordinator parent; final Queue queue; final int index; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeSubscribeOn.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeSubscribeOn.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeSubscribeOn.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeSubscribeOn.java index 5c263ac0cd..2c8a0dbf9a 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeSubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeSubscribeOn.java @@ -11,26 +11,26 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.AtomicReference; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; public final class NbpOnSubscribeSubscribeOn implements NbpOnSubscribe { - final NbpObservable source; + final Observable source; final Scheduler scheduler; - public NbpOnSubscribeSubscribeOn(NbpObservable source, Scheduler scheduler) { + public NbpOnSubscribeSubscribeOn(Observable source, Scheduler scheduler) { this.source = source; this.scheduler = scheduler; } @Override - public void accept(final NbpSubscriber s) { + public void accept(final Observer s) { /* * TODO can't use the returned disposable because to dispose it, * one must set a Subscription on s on the current thread, but @@ -44,15 +44,15 @@ public void run() { }); } - static final class SubscribeOnSubscriber extends AtomicReference implements NbpSubscriber, Disposable { + static final class SubscribeOnSubscriber extends AtomicReference implements Observer, Disposable { /** */ private static final long serialVersionUID = 8094547886072529208L; - final NbpSubscriber actual; + final Observer actual; final Scheduler.Worker worker; Disposable s; - public SubscribeOnSubscriber(NbpSubscriber actual, Scheduler.Worker worker) { + public SubscribeOnSubscriber(Observer actual, Scheduler.Worker worker) { this.actual = actual; this.worker = worker; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeTimerOnceSource.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeTimerOnceSource.java similarity index 91% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeTimerOnceSource.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeTimerOnceSource.java index 41420a9d10..1165fffce9 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeTimerOnceSource.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeTimerOnceSource.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.Scheduler; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.plugins.RxJavaPlugins; @@ -32,7 +32,7 @@ public NbpOnSubscribeTimerOnceSource(long delay, TimeUnit unit, Scheduler schedu } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { IntervalOnceSubscriber ios = new IntervalOnceSubscriber(s); s.onSubscribe(ios); @@ -46,7 +46,7 @@ static final class IntervalOnceSubscriber extends AtomicReference /** */ private static final long serialVersionUID = -2809475196591179431L; - final NbpSubscriber actual; + final Observer actual; static final Disposable DISPOSED = new Disposable() { @Override @@ -61,7 +61,7 @@ public void dispose() { } volatile boolean cancelled; - public IntervalOnceSubscriber(NbpSubscriber actual) { + public IntervalOnceSubscriber(Observer actual) { this.actual = actual; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeUsing.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeUsing.java similarity index 88% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeUsing.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeUsing.java index 218dc20e6e..bcdefef590 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeUsing.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeUsing.java @@ -11,12 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.AtomicBoolean; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.*; @@ -26,12 +26,12 @@ public final class NbpOnSubscribeUsing implements NbpOnSubscribe { final Supplier resourceSupplier; - final Function> sourceSupplier; + final Function> sourceSupplier; final Consumer disposer; final boolean eager; public NbpOnSubscribeUsing(Supplier resourceSupplier, - Function> sourceSupplier, + Function> sourceSupplier, Consumer disposer, boolean eager) { this.resourceSupplier = resourceSupplier; @@ -41,7 +41,7 @@ public NbpOnSubscribeUsing(Supplier resourceSupplier, } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { D resource; try { @@ -51,7 +51,7 @@ public void accept(NbpSubscriber s) { return; } - NbpObservable source; + Observable source; try { source = sourceSupplier.apply(resource); } catch (Throwable e) { @@ -70,18 +70,18 @@ public void accept(NbpSubscriber s) { source.subscribe(us); } - static final class UsingSubscriber extends AtomicBoolean implements NbpSubscriber, Disposable { + static final class UsingSubscriber extends AtomicBoolean implements Observer, Disposable { /** */ private static final long serialVersionUID = 5904473792286235046L; - final NbpSubscriber actual; + final Observer actual; final D resource; final Consumer disposer; final boolean eager; Disposable s; - public UsingSubscriber(NbpSubscriber actual, D resource, Consumer disposer, boolean eager) { + public UsingSubscriber(Observer actual, D resource, Consumer disposer, boolean eager) { this.actual = actual; this.resource = resource; this.disposer = disposer; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeZip.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeZip.java similarity index 88% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeZip.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeZip.java index cdf8ec9486..ca69776a13 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeZip.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeZip.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Queue; import java.util.concurrent.atomic.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.EmptyDisposable; @@ -26,14 +26,14 @@ public final class NbpOnSubscribeZip implements NbpOnSubscribe { - final NbpObservable[] sources; - final Iterable> sourcesIterable; + final Observable[] sources; + final Iterable> sourcesIterable; final Function zipper; final int bufferSize; final boolean delayError; - public NbpOnSubscribeZip(NbpObservable[] sources, - Iterable> sourcesIterable, + public NbpOnSubscribeZip(Observable[] sources, + Iterable> sourcesIterable, Function zipper, int bufferSize, boolean delayError) { @@ -46,14 +46,14 @@ public NbpOnSubscribeZip(NbpObservable[] sources, @Override @SuppressWarnings("unchecked") - public void accept(NbpSubscriber s) { - NbpObservable[] sources = this.sources; + public void accept(Observer s) { + Observable[] sources = this.sources; int count = 0; if (sources == null) { - sources = new NbpObservable[8]; - for (NbpObservable p : sourcesIterable) { + sources = new Observable[8]; + for (Observable p : sourcesIterable) { if (count == sources.length) { - NbpObservable[] b = new NbpObservable[count + (count >> 2)]; + Observable[] b = new Observable[count + (count >> 2)]; System.arraycopy(sources, 0, b, 0, count); sources = b; } @@ -75,7 +75,7 @@ public void accept(NbpSubscriber s) { static final class ZipCoordinator extends AtomicInteger implements Disposable { /** */ private static final long serialVersionUID = 2983708048395377667L; - final NbpSubscriber actual; + final Observer actual; final Function zipper; final ZipSubscriber[] subscribers; final Object[] row; @@ -84,7 +84,7 @@ static final class ZipCoordinator extends AtomicInteger implements Disposa volatile boolean cancelled; @SuppressWarnings("unchecked") - public ZipCoordinator(NbpSubscriber actual, + public ZipCoordinator(Observer actual, Function zipper, int count, boolean delayError) { this.actual = actual; @@ -94,7 +94,7 @@ public ZipCoordinator(NbpSubscriber actual, this.delayError = delayError; } - public void subscribe(NbpObservable[] sources, int bufferSize) { + public void subscribe(Observable[] sources, int bufferSize) { ZipSubscriber[] s = subscribers; int len = s.length; for (int i = 0; i < len; i++) { @@ -136,7 +136,7 @@ public void drain() { int missing = 1; final ZipSubscriber[] zs = subscribers; - final NbpSubscriber a = actual; + final Observer a = actual; final Object[] os = row; final boolean delayError = this.delayError; @@ -196,7 +196,7 @@ public void drain() { } } - boolean checkTerminated(boolean d, boolean empty, NbpSubscriber a, boolean delayError, ZipSubscriber source) { + boolean checkTerminated(boolean d, boolean empty, Observer a, boolean delayError, ZipSubscriber source) { if (cancelled) { clear(); return true; @@ -233,7 +233,7 @@ boolean checkTerminated(boolean d, boolean empty, NbpSubscriber a, bo } } - static final class ZipSubscriber implements NbpSubscriber, Disposable { + static final class ZipSubscriber implements Observer, Disposable { final ZipCoordinator parent; final Queue queue; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeZipIterable.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeZipIterable.java similarity index 91% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeZipIterable.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeZipIterable.java index 5c562484ff..2b20a9c390 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeZipIterable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOnSubscribeZipIterable.java @@ -11,12 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Iterator; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.BiFunction; import io.reactivex.internal.disposables.EmptyDisposable; @@ -24,12 +24,12 @@ import io.reactivex.plugins.RxJavaPlugins; public final class NbpOnSubscribeZipIterable implements NbpOnSubscribe { - final NbpObservable source; + final Observable source; final Iterable other; final BiFunction zipper; public NbpOnSubscribeZipIterable( - NbpObservable source, + Observable source, Iterable other, BiFunction zipper) { this.source = source; this.other = other; @@ -37,7 +37,7 @@ public NbpOnSubscribeZipIterable( } @Override - public void accept(NbpSubscriber t) { + public void accept(Observer t) { Iterator it; try { @@ -69,8 +69,8 @@ public void accept(NbpSubscriber t) { source.subscribe(new ZipIterableSubscriber(t, it, zipper)); } - static final class ZipIterableSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class ZipIterableSubscriber implements Observer { + final Observer actual; final Iterator iterator; final BiFunction zipper; @@ -78,7 +78,7 @@ static final class ZipIterableSubscriber implements NbpSubscriber { boolean done; - public ZipIterableSubscriber(NbpSubscriber actual, Iterator iterator, + public ZipIterableSubscriber(Observer actual, Iterator iterator, BiFunction zipper) { this.actual = actual; this.iterator = iterator; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorAll.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorAll.java similarity index 86% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorAll.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorAll.java index 59ce08e8b1..e30e3f7533 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorAll.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorAll.java @@ -10,9 +10,10 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Predicate; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -25,19 +26,19 @@ public NbpOperatorAll(Predicate predicate) { } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new AllSubscriber(t, predicate); } - static final class AllSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class AllSubscriber implements Observer { + final Observer actual; final Predicate predicate; Disposable s; boolean done; - public AllSubscriber(NbpSubscriber actual, Predicate predicate) { + public AllSubscriber(Observer actual, Predicate predicate) { this.actual = actual; this.predicate = predicate; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorAny.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorAny.java similarity index 86% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorAny.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorAny.java index 6d1c75f985..f4f66919d7 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorAny.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorAny.java @@ -10,9 +10,10 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Predicate; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -24,20 +25,20 @@ public NbpOperatorAny(Predicate predicate) { } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new AnySubscriber(t, predicate); } - static final class AnySubscriber implements NbpSubscriber { + static final class AnySubscriber implements Observer { - final NbpSubscriber actual; + final Observer actual; final Predicate predicate; Disposable s; boolean done; - public AnySubscriber(NbpSubscriber actual, Predicate predicate) { + public AnySubscriber(Observer actual, Predicate predicate) { this.actual = actual; this.predicate = predicate; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBuffer.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBuffer.java similarity index 90% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBuffer.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBuffer.java index e4764febd0..6d7522a103 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBuffer.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBuffer.java @@ -11,16 +11,17 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Supplier; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.internal.subscribers.nbp.NbpEmptySubscriber; +import io.reactivex.internal.subscribers.observable.NbpEmptySubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; public final class NbpOperatorBuffer> implements NbpOperator { @@ -35,7 +36,7 @@ public NbpOperatorBuffer(int count, int skip, Supplier bufferSupplier) { } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { if (skip == count) { BufferExactSubscriber bes = new BufferExactSubscriber(t, count, bufferSupplier); if (bes.createBuffer()) { @@ -46,8 +47,8 @@ public NbpSubscriber apply(NbpSubscriber t) { return new BufferSkipSubscriber(t, count, skip, bufferSupplier); } - static final class BufferExactSubscriber> implements NbpSubscriber { - final NbpSubscriber actual; + static final class BufferExactSubscriber> implements Observer { + final Observer actual; final int count; final Supplier bufferSupplier; U buffer; @@ -56,7 +57,7 @@ static final class BufferExactSubscriber> imp Disposable s; - public BufferExactSubscriber(NbpSubscriber actual, int count, Supplier bufferSupplier) { + public BufferExactSubscriber(Observer actual, int count, Supplier bufferSupplier) { this.actual = actual; this.count = count; this.bufferSupplier = bufferSupplier; @@ -136,10 +137,10 @@ public void onComplete() { } static final class BufferSkipSubscriber> - extends AtomicBoolean implements NbpSubscriber { + extends AtomicBoolean implements Observer { /** */ private static final long serialVersionUID = -8223395059921494546L; - final NbpSubscriber actual; + final Observer actual; final int count; final int skip; final Supplier bufferSupplier; @@ -150,7 +151,7 @@ static final class BufferSkipSubscriber> long index; - public BufferSkipSubscriber(NbpSubscriber actual, int count, int skip, Supplier bufferSupplier) { + public BufferSkipSubscriber(Observer actual, int count, int skip, Supplier bufferSupplier) { this.actual = actual; this.count = count; this.skip = skip; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferBoundary.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBufferBoundary.java similarity index 87% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferBoundary.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBufferBoundary.java index 6e287f7e8c..7ed75ed4c3 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferBoundary.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBufferBoundary.java @@ -11,47 +11,48 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.functions.*; import io.reactivex.internal.disposables.SetCompositeResource; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.nbp.*; +import io.reactivex.internal.subscribers.observable.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.QueueDrainHelper; +import io.reactivex.observers.SerializedObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; public final class NbpOperatorBufferBoundary, Open, Close> implements NbpOperator { final Supplier bufferSupplier; - final NbpObservable bufferOpen; - final Function> bufferClose; + final Observable bufferOpen; + final Function> bufferClose; - public NbpOperatorBufferBoundary(NbpObservable bufferOpen, - Function> bufferClose, Supplier bufferSupplier) { + public NbpOperatorBufferBoundary(Observable bufferOpen, + Function> bufferClose, Supplier bufferSupplier) { this.bufferOpen = bufferOpen; this.bufferClose = bufferClose; this.bufferSupplier = bufferSupplier; } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new BufferBoundarySubscriber( - new NbpSerializedSubscriber(t), + new SerializedObserver(t), bufferOpen, bufferClose, bufferSupplier ); } static final class BufferBoundarySubscriber, Open, Close> extends NbpQueueDrainSubscriber implements Disposable { - final NbpObservable bufferOpen; - final Function> bufferClose; + final Observable bufferOpen; + final Function> bufferClose; final Supplier bufferSupplier; final SetCompositeResource resources; @@ -61,9 +62,9 @@ static final class BufferBoundarySubscriber, final AtomicInteger windows = new AtomicInteger(); - public BufferBoundarySubscriber(NbpSubscriber actual, - NbpObservable bufferOpen, - Function> bufferClose, + public BufferBoundarySubscriber(Observer actual, + Observable bufferOpen, + Function> bufferClose, Supplier bufferSupplier) { super(actual, new MpscLinkedQueue()); this.bufferOpen = bufferOpen; @@ -140,7 +141,7 @@ public void dispose() { } @Override - public void accept(NbpSubscriber a, U v) { + public void accept(Observer a, U v) { a.onNext(v); } @@ -163,7 +164,7 @@ void open(Open window) { return; } - NbpObservable p; + Observable p; try { p = bufferClose.apply(window); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferBoundarySupplier.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBufferBoundarySupplier.java similarity index 88% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferBoundarySupplier.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBufferBoundarySupplier.java index f4fc1d9392..272923f294 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferBoundarySupplier.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBufferBoundarySupplier.java @@ -11,42 +11,42 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Collection; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Supplier; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.nbp.*; +import io.reactivex.internal.subscribers.observable.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.QueueDrainHelper; +import io.reactivex.observers.SerializedObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; public final class NbpOperatorBufferBoundarySupplier, B> implements NbpOperator { - final Supplier> boundarySupplier; + final Supplier> boundarySupplier; final Supplier bufferSupplier; - public NbpOperatorBufferBoundarySupplier(Supplier> boundarySupplier, Supplier bufferSupplier) { + public NbpOperatorBufferBoundarySupplier(Supplier> boundarySupplier, Supplier bufferSupplier) { this.boundarySupplier = boundarySupplier; this.bufferSupplier = bufferSupplier; } @Override - public NbpSubscriber apply(NbpSubscriber t) { - return new BufferBondarySupplierSubscriber(new NbpSerializedSubscriber(t), bufferSupplier, boundarySupplier); + public Observer apply(Observer t) { + return new BufferBondarySupplierSubscriber(new SerializedObserver(t), bufferSupplier, boundarySupplier); } static final class BufferBondarySupplierSubscriber, B> - extends NbpQueueDrainSubscriber implements NbpSubscriber, Disposable { + extends NbpQueueDrainSubscriber implements Observer, Disposable { /** */ final Supplier bufferSupplier; - final Supplier> boundarySupplier; + final Supplier> boundarySupplier; Disposable s; @@ -59,8 +59,8 @@ public void dispose() { } U buffer; - public BufferBondarySupplierSubscriber(NbpSubscriber actual, Supplier bufferSupplier, - Supplier> boundarySupplier) { + public BufferBondarySupplierSubscriber(Observer actual, Supplier bufferSupplier, + Supplier> boundarySupplier) { super(actual, new MpscLinkedQueue()); this.bufferSupplier = bufferSupplier; this.boundarySupplier = boundarySupplier; @@ -73,7 +73,7 @@ public void onSubscribe(Disposable s) { } this.s = s; - NbpSubscriber actual = this.actual; + Observer actual = this.actual; U b; @@ -94,7 +94,7 @@ public void onSubscribe(Disposable s) { } buffer = b; - NbpObservable boundary; + Observable boundary; try { boundary = boundarySupplier.get(); @@ -199,7 +199,7 @@ void next() { return; } - NbpObservable boundary; + Observable boundary; try { boundary = boundarySupplier.get(); @@ -238,7 +238,7 @@ void next() { } @Override - public void accept(NbpSubscriber a, U v) { + public void accept(Observer a, U v) { actual.onNext(v); } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferExactBoundary.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBufferExactBoundary.java similarity index 85% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferExactBoundary.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBufferExactBoundary.java index be5b4fa3eb..f980d2eda9 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferExactBoundary.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBufferExactBoundary.java @@ -11,40 +11,40 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Collection; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Supplier; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.nbp.*; +import io.reactivex.internal.subscribers.observable.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.QueueDrainHelper; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; +import io.reactivex.observers.SerializedObserver; public final class NbpOperatorBufferExactBoundary, B> implements NbpOperator { - final NbpObservable boundary; + final Observable boundary; final Supplier bufferSupplier; - public NbpOperatorBufferExactBoundary(NbpObservable boundary, Supplier bufferSupplier) { + public NbpOperatorBufferExactBoundary(Observable boundary, Supplier bufferSupplier) { this.boundary = boundary; this.bufferSupplier = bufferSupplier; } @Override - public NbpSubscriber apply(NbpSubscriber t) { - return new BufferExactBondarySubscriber(new NbpSerializedSubscriber(t), bufferSupplier, boundary); + public Observer apply(Observer t) { + return new BufferExactBondarySubscriber(new SerializedObserver(t), bufferSupplier, boundary); } static final class BufferExactBondarySubscriber, B> - extends NbpQueueDrainSubscriber implements NbpSubscriber, Disposable { + extends NbpQueueDrainSubscriber implements Observer, Disposable { /** */ final Supplier bufferSupplier; - final NbpObservable boundary; + final Observable boundary; Disposable s; @@ -52,8 +52,8 @@ static final class BufferExactBondarySubscriber actual, Supplier bufferSupplier, - NbpObservable boundary) { + public BufferExactBondarySubscriber(Observer actual, Supplier bufferSupplier, + Observable boundary) { super(actual, new MpscLinkedQueue()); this.bufferSupplier = bufferSupplier; this.boundary = boundary; @@ -173,7 +173,7 @@ void next() { } @Override - public void accept(NbpSubscriber a, U v) { + public void accept(Observer a, U v) { actual.onNext(v); } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferTimed.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBufferTimed.java similarity index 95% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferTimed.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBufferTimed.java index 1529afe21a..1de25e3c84 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorBufferTimed.java @@ -11,23 +11,24 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.*; import java.util.concurrent.*; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOperator; +import io.reactivex.Observer; import io.reactivex.Scheduler; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Supplier; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.nbp.NbpQueueDrainSubscriber; +import io.reactivex.internal.subscribers.observable.NbpQueueDrainSubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.QueueDrainHelper; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; +import io.reactivex.observers.SerializedObserver; public final class NbpOperatorBufferTimed> implements NbpOperator { @@ -51,17 +52,17 @@ public NbpOperatorBufferTimed(long timespan, long timeskip, TimeUnit unit, Sched } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { if (timespan == timeskip && maxSize == Integer.MAX_VALUE) { return new BufferExactUnboundedSubscriber( - new NbpSerializedSubscriber(t), + new SerializedObserver(t), bufferSupplier, timespan, unit, scheduler); } Scheduler.Worker w = scheduler.createWorker(); if (timespan == timeskip) { return new BufferExactBoundedSubscriber( - new NbpSerializedSubscriber(t), + new SerializedObserver(t), bufferSupplier, timespan, unit, maxSize, restartTimerOnMaxSize, w ); @@ -69,7 +70,7 @@ public NbpSubscriber apply(NbpSubscriber t) { // Can't use maxSize because what to do if a buffer is full but its // timespan hasn't been elapsed? return new BufferSkipBoundedSubscriber( - new NbpSerializedSubscriber(t), + new SerializedObserver(t), bufferSupplier, timespan, timeskip, unit, w); } @@ -94,7 +95,7 @@ public void dispose() { } }; public BufferExactUnboundedSubscriber( - NbpSubscriber actual, Supplier bufferSupplier, + Observer actual, Supplier bufferSupplier, long timespan, TimeUnit unit, Scheduler scheduler) { super(actual, new MpscLinkedQueue()); this.bufferSupplier = bufferSupplier; @@ -241,7 +242,7 @@ public void run() { } @Override - public void accept(NbpSubscriber a, U v) { + public void accept(Observer a, U v) { actual.onNext(v); } } @@ -258,7 +259,7 @@ static final class BufferSkipBoundedSubscriber buffers; - public BufferSkipBoundedSubscriber(NbpSubscriber actual, + public BufferSkipBoundedSubscriber(Observer actual, Supplier bufferSupplier, long timespan, long timeskip, TimeUnit unit, Worker w) { super(actual, new MpscLinkedQueue()); @@ -403,7 +404,7 @@ public void run() { } @Override - public void accept(NbpSubscriber a, U v) { + public void accept(Observer a, U v) { a.onNext(v); } } @@ -428,7 +429,7 @@ static final class BufferExactBoundedSubscriber actual, + Observer actual, Supplier bufferSupplier, long timespan, TimeUnit unit, int maxSize, boolean restartOnMaxSize, Worker w) { @@ -555,7 +556,7 @@ public void onComplete() { } @Override - public void accept(NbpSubscriber a, U v) { + public void accept(Observer a, U v) { a.onNext(v); } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorCollect.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorCollect.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorCollect.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorCollect.java index aa90efef3e..9f03695b3a 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorCollect.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorCollect.java @@ -10,13 +10,14 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.internal.subscribers.nbp.NbpCancelledSubscriber; +import io.reactivex.internal.subscribers.observable.NbpCancelledSubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; public final class NbpOperatorCollect implements NbpOperator { @@ -29,7 +30,7 @@ public NbpOperatorCollect(Supplier initialSupplier, BiConsumer apply(NbpSubscriber t) { + public Observer apply(Observer t) { U u; try { @@ -47,14 +48,14 @@ public NbpSubscriber apply(NbpSubscriber t) { return new CollectSubscriber(t, u, collector); } - static final class CollectSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class CollectSubscriber implements Observer { + final Observer actual; final BiConsumer collector; final U u; Disposable s; - public CollectSubscriber(NbpSubscriber actual, U u, BiConsumer collector) { + public CollectSubscriber(Observer actual, U u, BiConsumer collector) { this.actual = actual; this.collector = collector; this.u = u; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorConcatMap.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorConcatMap.java similarity index 83% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorConcatMap.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorConcatMap.java index 84c11cc5c6..2c09f8cb1c 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorConcatMap.java @@ -10,42 +10,42 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Queue; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.functions.Function; import io.reactivex.internal.queue.SpscLinkedArrayQueue; import io.reactivex.internal.subscriptions.SubscriptionHelper; +import io.reactivex.observers.SerializedObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; public final class NbpOperatorConcatMap implements NbpOperator { - final Function> mapper; + final Function> mapper; final int bufferSize; - public NbpOperatorConcatMap(Function> mapper, int bufferSize) { + public NbpOperatorConcatMap(Function> mapper, int bufferSize) { this.mapper = mapper; this.bufferSize = Math.max(8, bufferSize); } @Override - public NbpSubscriber apply(NbpSubscriber s) { - NbpSerializedSubscriber ssub = new NbpSerializedSubscriber(s); + public Observer apply(Observer s) { + SerializedObserver ssub = new SerializedObserver(s); SerialDisposable sa = new SerialDisposable(); ssub.onSubscribe(sa); return new SourceSubscriber(ssub, sa, mapper, bufferSize); } - static final class SourceSubscriber extends AtomicInteger implements NbpSubscriber { + static final class SourceSubscriber extends AtomicInteger implements Observer { /** */ private static final long serialVersionUID = 8828587559905699186L; - final NbpSubscriber actual; + final Observer actual; final SerialDisposable sa; - final Function> mapper; - final NbpSubscriber inner; + final Function> mapper; + final Observer inner; final Queue queue; final int bufferSize; @@ -55,8 +55,8 @@ static final class SourceSubscriber extends AtomicInteger implements NbpSu volatile long index; - public SourceSubscriber(NbpSubscriber actual, SerialDisposable sa, - Function> mapper, int bufferSize) { + public SourceSubscriber(Observer actual, SerialDisposable sa, + Function> mapper, int bufferSize) { this.actual = actual; this.sa = sa; this.mapper = mapper; @@ -129,7 +129,7 @@ void drain() { RxJavaPlugins.onError(new IllegalStateException("Queue is empty?!")); return; } - NbpObservable p; + Observable p; try { p = mapper.apply(o); } catch (Throwable e) { @@ -151,8 +151,8 @@ void drain() { } } - static final class InnerSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class InnerSubscriber implements Observer { + final Observer actual; final SerialDisposable sa; final SourceSubscriber parent; @@ -165,7 +165,7 @@ static final class InnerSubscriber implements NbpSubscriber { long index; - public InnerSubscriber(NbpSubscriber actual, + public InnerSubscriber(Observer actual, SerialDisposable sa, SourceSubscriber parent) { this.actual = actual; this.sa = sa; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorCount.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorCount.java similarity index 82% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorCount.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorCount.java index 2c610944db..360c15b0ec 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorCount.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorCount.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -26,18 +27,18 @@ public static NbpOperator instance() { } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new CountSubscriber(t); } - static final class CountSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class CountSubscriber implements Observer { + final Observer actual; Disposable s; long count; - public CountSubscriber(NbpSubscriber actual) { + public CountSubscriber(Observer actual) { this.actual = actual; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDebounce.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDebounce.java similarity index 85% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDebounce.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDebounce.java index 771b652d55..6658de87c0 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDebounce.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDebounce.java @@ -11,35 +11,35 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; -import io.reactivex.internal.subscribers.nbp.NbpDisposableSubscriber; +import io.reactivex.internal.subscribers.observable.NbpDisposableSubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; +import io.reactivex.observers.SerializedObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; public final class NbpOperatorDebounce implements NbpOperator { - final Function> debounceSelector; + final Function> debounceSelector; - public NbpOperatorDebounce(Function> debounceSelector) { + public NbpOperatorDebounce(Function> debounceSelector) { this.debounceSelector = debounceSelector; } @Override - public NbpSubscriber apply(NbpSubscriber t) { - return new DebounceSubscriber(new NbpSerializedSubscriber(t), debounceSelector); + public Observer apply(Observer t) { + return new DebounceSubscriber(new SerializedObserver(t), debounceSelector); } static final class DebounceSubscriber - implements NbpSubscriber, Disposable { - final NbpSubscriber actual; - final Function> debounceSelector; + implements Observer, Disposable { + final Observer actual; + final Function> debounceSelector; volatile boolean gate; @@ -56,8 +56,8 @@ public void dispose() { } boolean done; - public DebounceSubscriber(NbpSubscriber actual, - Function> debounceSelector) { + public DebounceSubscriber(Observer actual, + Function> debounceSelector) { this.actual = actual; this.debounceSelector = debounceSelector; } @@ -86,7 +86,7 @@ public void onNext(T t) { d.dispose(); } - NbpObservable p; + Observable p; try { p = debounceSelector.apply(t); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDebounceTimed.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDebounceTimed.java similarity index 92% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDebounceTimed.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDebounceTimed.java index 86193be821..1d9b5967e7 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDebounceTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDebounceTimed.java @@ -11,18 +11,18 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; -import io.reactivex.Scheduler; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; +import io.reactivex.observers.SerializedObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; public final class NbpOperatorDebounceTimed implements NbpOperator { final long timeout; @@ -36,15 +36,15 @@ public NbpOperatorDebounceTimed(long timeout, TimeUnit unit, Scheduler scheduler } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new DebounceTimedSubscriber( - new NbpSerializedSubscriber(t), + new SerializedObserver(t), timeout, unit, scheduler.createWorker()); } static final class DebounceTimedSubscriber - implements NbpSubscriber, Disposable { - final NbpSubscriber actual; + implements Observer, Disposable { + final Observer actual; final long timeout; final TimeUnit unit; final Scheduler.Worker worker; @@ -67,7 +67,7 @@ public void dispose() { } boolean done; - public DebounceTimedSubscriber(NbpSubscriber actual, long timeout, TimeUnit unit, Worker worker) { + public DebounceTimedSubscriber(Observer actual, long timeout, TimeUnit unit, Worker worker) { this.actual = actual; this.timeout = timeout; this.unit = unit; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDelay.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDelay.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDelay.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDelay.java index 15f909848f..ce8db96988 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDelay.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDelay.java @@ -11,16 +11,16 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.TimeUnit; -import io.reactivex.Scheduler; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; +import io.reactivex.observers.SerializedObserver; public final class NbpOperatorDelay implements NbpOperator { final long delay; @@ -39,12 +39,12 @@ public NbpOperatorDelay(long delay, TimeUnit unit, Scheduler scheduler, boolean @Override @SuppressWarnings("unchecked") - public NbpSubscriber apply(NbpSubscriber t) { - NbpSubscriber s; + public Observer apply(Observer t) { + Observer s; if (delayError) { - s = (NbpSubscriber)t; + s = (Observer)t; } else { - s = new NbpSerializedSubscriber(t); + s = new SerializedObserver(t); } Scheduler.Worker w = scheduler.createWorker(); @@ -52,8 +52,8 @@ public NbpSubscriber apply(NbpSubscriber t) { return new DelaySubscriber(s, delay, unit, w, delayError); } - static final class DelaySubscriber implements NbpSubscriber, Disposable { - final NbpSubscriber actual; + static final class DelaySubscriber implements Observer, Disposable { + final Observer actual; final long delay; final TimeUnit unit; final Scheduler.Worker w; @@ -61,7 +61,7 @@ static final class DelaySubscriber implements NbpSubscriber, Disposable { Disposable s; - public DelaySubscriber(NbpSubscriber actual, long delay, TimeUnit unit, Worker w, boolean delayError) { + public DelaySubscriber(Observer actual, long delay, TimeUnit unit, Worker w, boolean delayError) { super(); this.actual = actual; this.delay = delay; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDematerialize.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDematerialize.java similarity index 86% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDematerialize.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDematerialize.java index 51d11dd8ad..d94530b8d2 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDematerialize.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDematerialize.java @@ -11,10 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; @@ -28,18 +28,18 @@ public static NbpOperator>> instance() { } @Override - public NbpSubscriber>> apply(NbpSubscriber t) { + public Observer>> apply(Observer t) { return new DematerializeSubscriber(t); } - static final class DematerializeSubscriber implements NbpSubscriber>> { - final NbpSubscriber actual; + static final class DematerializeSubscriber implements Observer>> { + final Observer actual; boolean done; Disposable s; - public DematerializeSubscriber(NbpSubscriber actual) { + public DematerializeSubscriber(Observer actual) { this.actual = actual; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDistinct.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDistinct.java similarity index 92% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDistinct.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDistinct.java index c75cac9c0b..a27e97127a 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDistinct.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDistinct.java @@ -11,17 +11,18 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Collection; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.functions.*; -import io.reactivex.internal.subscribers.nbp.NbpCancelledSubscriber; +import io.reactivex.internal.subscribers.observable.NbpCancelledSubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; public final class NbpOperatorDistinct implements NbpOperator { @@ -109,7 +110,7 @@ public boolean test(K t) { @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { Predicate coll; try { coll = predicateSupplier.get(); @@ -126,14 +127,14 @@ public NbpSubscriber apply(NbpSubscriber t) { return new DistinctSubscriber(t, keySelector, coll); } - static final class DistinctSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class DistinctSubscriber implements Observer { + final Observer actual; final Predicate predicate; final Function keySelector; Disposable s; - public DistinctSubscriber(NbpSubscriber actual, Function keySelector, Predicate predicate) { + public DistinctSubscriber(Observer actual, Function keySelector, Predicate predicate) { this.actual = actual; this.keySelector = keySelector; this.predicate = predicate; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDoOnEach.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDoOnEach.java similarity index 92% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDoOnEach.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDoOnEach.java index 4893c95262..618e9b5d52 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorDoOnEach.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorDoOnEach.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.Consumer; @@ -37,12 +38,12 @@ public NbpOperatorDoOnEach(Consumer onNext, } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new DoOnEachSubscriber(t, onNext, onError, onComplete, onAfterTerminate); } - static final class DoOnEachSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class DoOnEachSubscriber implements Observer { + final Observer actual; final Consumer onNext; final Consumer onError; final Runnable onComplete; @@ -53,7 +54,7 @@ static final class DoOnEachSubscriber implements NbpSubscriber { boolean done; public DoOnEachSubscriber( - NbpSubscriber actual, + Observer actual, Consumer onNext, Consumer onError, Runnable onComplete, diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorElementAt.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorElementAt.java similarity index 87% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorElementAt.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorElementAt.java index 59f38865f9..3c226de90d 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorElementAt.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorElementAt.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -25,12 +26,12 @@ public NbpOperatorElementAt(long index, T defaultValue) { this.defaultValue = defaultValue; } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new ElementAtSubscriber(t, index, defaultValue); } - static final class ElementAtSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class ElementAtSubscriber implements Observer { + final Observer actual; final long index; final T defaultValue; @@ -40,7 +41,7 @@ static final class ElementAtSubscriber implements NbpSubscriber { boolean done; - public ElementAtSubscriber(NbpSubscriber actual, long index, T defaultValue) { + public ElementAtSubscriber(Observer actual, long index, T defaultValue) { this.actual = actual; this.index = index; this.defaultValue = defaultValue; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorFilter.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorFilter.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorFilter.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorFilter.java index 452e45e700..05524be507 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorFilter.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorFilter.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Predicate; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -25,17 +26,17 @@ public NbpOperatorFilter(Predicate predicate) { } @Override - public NbpSubscriber apply(NbpSubscriber s) { + public Observer apply(Observer s) { return new FilterSubscriber(s, predicate); } - static final class FilterSubscriber implements NbpSubscriber { + static final class FilterSubscriber implements Observer { final Predicate filter; - final NbpSubscriber actual; + final Observer actual; Disposable subscription; - public FilterSubscriber(NbpSubscriber actual, Predicate filter) { + public FilterSubscriber(Observer actual, Predicate filter) { this.actual = actual; this.filter = filter; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorFlatMap.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorFlatMap.java similarity index 94% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorFlatMap.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorFlatMap.java index 2070d922c3..e4651395f4 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorFlatMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorFlatMap.java @@ -11,13 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.*; import java.util.concurrent.atomic.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.*; import io.reactivex.functions.Function; @@ -26,13 +27,13 @@ import io.reactivex.internal.util.Pow2; public final class NbpOperatorFlatMap implements NbpOperator { - final Function> mapper; + final Function> mapper; final boolean delayErrors; final int maxConcurrency; final int bufferSize; public NbpOperatorFlatMap( - Function> mapper, + Function> mapper, boolean delayErrors, int maxConcurrency, int bufferSize) { this.mapper = mapper; this.delayErrors = delayErrors; @@ -41,16 +42,16 @@ public NbpOperatorFlatMap( } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new MergeSubscriber(t, mapper, delayErrors, maxConcurrency, bufferSize); } - static final class MergeSubscriber extends AtomicInteger implements Disposable, NbpSubscriber { + static final class MergeSubscriber extends AtomicInteger implements Disposable, Observer { /** */ private static final long serialVersionUID = -2117620485640801370L; - final NbpSubscriber actual; - final Function> mapper; + final Observer actual; + final Function> mapper; final boolean delayErrors; final int maxConcurrency; final int bufferSize; @@ -77,11 +78,11 @@ static final class MergeSubscriber extends AtomicInteger implements Dispos long lastId; int lastIndex; - Queue> sources; + Queue> sources; int wip; - public MergeSubscriber(NbpSubscriber actual, Function> mapper, + public MergeSubscriber(Observer actual, Function> mapper, boolean delayErrors, int maxConcurrency, int bufferSize) { this.actual = actual; this.mapper = mapper; @@ -89,7 +90,7 @@ public MergeSubscriber(NbpSubscriber actual, Function>(maxConcurrency); + sources = new ArrayDeque>(maxConcurrency); } this.subscribers = new AtomicReference[]>(EMPTY); } @@ -109,7 +110,7 @@ public void onNext(T t) { if (done) { return; } - NbpObservable p; + Observable p; try { p = mapper.apply(t); } catch (Throwable e) { @@ -134,7 +135,7 @@ public void onNext(T t) { } } - void subscribeInner(NbpObservable p) { + void subscribeInner(Observable p) { InnerSubscriber inner = new InnerSubscriber(this, uniqueId++); addInner(inner); p.subscribe(inner); @@ -295,7 +296,7 @@ void drain() { } void drainLoop() { - final NbpSubscriber child = this.actual; + final Observer child = this.actual; int missed = 1; for (;;) { if (checkTerminate()) { @@ -412,7 +413,7 @@ void drainLoop() { if (innerCompleted) { if (maxConcurrency != Integer.MAX_VALUE) { - NbpObservable p; + Observable p; synchronized (this) { p = sources.poll(); if (p == null) { @@ -502,7 +503,7 @@ Queue getErrorQueue() { } static final class InnerSubscriber extends AtomicReference - implements NbpSubscriber, Disposable { + implements Observer, Disposable { /** */ private static final long serialVersionUID = -4606175640614850599L; final long id; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorGroupBy.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorGroupBy.java similarity index 90% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorGroupBy.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorGroupBy.java index ef83b95ec5..6301962cef 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorGroupBy.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorGroupBy.java @@ -11,21 +11,22 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.queue.SpscLinkedArrayQueue; import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.observables.nbp.NbpGroupedObservable; +import io.reactivex.observables.GroupedObservable; -public final class NbpOperatorGroupBy implements NbpOperator, T>{ +public final class NbpOperatorGroupBy implements NbpOperator, T>{ final Function keySelector; final Function valueSelector; final int bufferSize; @@ -39,15 +40,15 @@ public NbpOperatorGroupBy(Function keySelector, Function } @Override - public NbpSubscriber apply(NbpSubscriber> t) { + public Observer apply(Observer> t) { return new GroupBySubscriber(t, keySelector, valueSelector, bufferSize, delayError); } - public static final class GroupBySubscriber extends AtomicInteger implements NbpSubscriber, Disposable { + public static final class GroupBySubscriber extends AtomicInteger implements Observer, Disposable { /** */ private static final long serialVersionUID = -3688291656102519502L; - final NbpSubscriber> actual; + final Observer> actual; final Function keySelector; final Function valueSelector; final int bufferSize; @@ -60,7 +61,7 @@ public static final class GroupBySubscriber extends AtomicInteger imple final AtomicBoolean cancelled = new AtomicBoolean(); - public GroupBySubscriber(NbpSubscriber> actual, Function keySelector, Function valueSelector, int bufferSize, boolean delayError) { + public GroupBySubscriber(Observer> actual, Function keySelector, Function valueSelector, int bufferSize, boolean delayError) { this.actual = actual; this.keySelector = keySelector; this.valueSelector = valueSelector; @@ -170,7 +171,7 @@ public void cancel(K key) { } } - static final class GroupedUnicast extends NbpGroupedObservable { + static final class GroupedUnicast extends GroupedObservable { public static GroupedUnicast createWith(K key, int bufferSize, GroupBySubscriber parent, boolean delayError) { State state = new State(bufferSize, parent, key, delayError); @@ -211,7 +212,7 @@ static final class State extends AtomicInteger implements Disposable, NbpO final AtomicBoolean cancelled = new AtomicBoolean(); - final AtomicReference> actual = new AtomicReference>(); + final AtomicReference> actual = new AtomicReference>(); public State(int bufferSize, GroupBySubscriber parent, K key, boolean delayError) { this.queue = new SpscLinkedArrayQueue(bufferSize); @@ -230,7 +231,7 @@ public void dispose() { } @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { if (actual.compareAndSet(null, s)) { s.onSubscribe(this); drain(); @@ -268,7 +269,7 @@ void drain() { final Queue q = queue; final boolean delayError = this.delayError; - NbpSubscriber a = actual.get(); + Observer a = actual.get(); for (;;) { if (a != null) { if (checkTerminated(done, q.isEmpty(), a, delayError)) { @@ -302,7 +303,7 @@ void drain() { } } - boolean checkTerminated(boolean d, boolean empty, NbpSubscriber a, boolean delayError) { + boolean checkTerminated(boolean d, boolean empty, Observer a, boolean delayError) { if (cancelled.get()) { queue.clear(); parent.cancel(key); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorIgnoreElements.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorIgnoreElements.java similarity index 85% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorIgnoreElements.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorIgnoreElements.java index 449973c32b..691bb9a560 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorIgnoreElements.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorIgnoreElements.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; public enum NbpOperatorIgnoreElements implements NbpOperator { @@ -25,8 +26,8 @@ public static NbpOperator instance() { } @Override - public NbpSubscriber apply(final NbpSubscriber t) { - return new NbpSubscriber() { + public Observer apply(final Observer t) { + return new Observer() { @Override public void onSubscribe(Disposable s) { t.onSubscribe(s); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorMap.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorMap.java similarity index 87% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorMap.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorMap.java index 184920affe..e2b06ed947 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorMap.java @@ -12,9 +12,10 @@ */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -28,19 +29,19 @@ public NbpOperatorMap(Function function) { } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new MapperSubscriber(t, function); } - static final class MapperSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class MapperSubscriber implements Observer { + final Observer actual; final Function function; Disposable subscription; boolean done; - public MapperSubscriber(NbpSubscriber actual, Function function) { + public MapperSubscriber(Observer actual, Function function) { this.actual = actual; this.function = function; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorMapNotification.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorMapNotification.java similarity index 66% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorMapNotification.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorMapNotification.java index b9597c033e..9627470860 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorMapNotification.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorMapNotification.java @@ -11,50 +11,50 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; -public final class NbpOperatorMapNotification implements NbpOperator, T>{ +public final class NbpOperatorMapNotification implements NbpOperator, T>{ - final Function> onNextMapper; - final Function> onErrorMapper; - final Supplier> onCompleteSupplier; + final Function> onNextMapper; + final Function> onErrorMapper; + final Supplier> onCompleteSupplier; - public NbpOperatorMapNotification(Function> onNextMapper, - Function> onErrorMapper, - Supplier> onCompleteSupplier) { + public NbpOperatorMapNotification(Function> onNextMapper, + Function> onErrorMapper, + Supplier> onCompleteSupplier) { this.onNextMapper = onNextMapper; this.onErrorMapper = onErrorMapper; this.onCompleteSupplier = onCompleteSupplier; } @Override - public NbpSubscriber apply(NbpSubscriber> t) { + public Observer apply(Observer> t) { return new MapNotificationSubscriber(t, onNextMapper, onErrorMapper, onCompleteSupplier); } static final class MapNotificationSubscriber - implements NbpSubscriber { - final NbpSubscriber> actual; - final Function> onNextMapper; - final Function> onErrorMapper; - final Supplier> onCompleteSupplier; + implements Observer { + final Observer> actual; + final Function> onNextMapper; + final Function> onErrorMapper; + final Supplier> onCompleteSupplier; Disposable s; - NbpObservable value; + Observable value; volatile boolean done; - public MapNotificationSubscriber(NbpSubscriber> actual, - Function> onNextMapper, - Function> onErrorMapper, - Supplier> onCompleteSupplier) { + public MapNotificationSubscriber(Observer> actual, + Function> onNextMapper, + Function> onErrorMapper, + Supplier> onCompleteSupplier) { this.actual = actual; this.onNextMapper = onNextMapper; this.onErrorMapper = onErrorMapper; @@ -72,7 +72,7 @@ public void onSubscribe(Disposable s) { @Override public void onNext(T t) { - NbpObservable p; + Observable p; try { p = onNextMapper.apply(t); @@ -91,7 +91,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - NbpObservable p; + Observable p; try { p = onErrorMapper.apply(t); @@ -111,7 +111,7 @@ public void onError(Throwable t) { @Override public void onComplete() { - NbpObservable p; + Observable p; try { p = onCompleteSupplier.get(); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorMaterialize.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorMaterialize.java similarity index 83% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorMaterialize.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorMaterialize.java index 94087b7ae8..0b5307e870 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorMaterialize.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorMaterialize.java @@ -11,10 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -27,18 +27,18 @@ public static NbpOperator>, T> instance() { } @Override - public NbpSubscriber apply(NbpSubscriber>> t) { + public Observer apply(Observer>> t) { return new MaterializeSubscriber(t); } - static final class MaterializeSubscriber implements NbpSubscriber { - final NbpSubscriber>> actual; + static final class MaterializeSubscriber implements Observer { + final Observer>> actual; Disposable s; volatile boolean done; - public MaterializeSubscriber(NbpSubscriber>> actual) { + public MaterializeSubscriber(Observer>> actual) { this.actual = actual; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorObserveOn.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorObserveOn.java similarity index 91% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorObserveOn.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorObserveOn.java index aa3892f991..6b9d0fad80 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorObserveOn.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorObserveOn.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Queue; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.Scheduler; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.MissingBackpressureException; import io.reactivex.internal.queue.SpscLinkedArrayQueue; @@ -36,7 +36,7 @@ public NbpOperatorObserveOn(Scheduler scheduler, boolean delayError, int bufferS } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { if (scheduler instanceof TrampolineScheduler) { return t; } @@ -57,10 +57,10 @@ static class Padding0 extends AtomicInteger { volatile long p08, p09, p0A, p0B, p0C, p0D, p0E, p0F; } - static final class ObserveOnSubscriber extends Padding0 implements NbpSubscriber, Disposable, Runnable { + static final class ObserveOnSubscriber extends Padding0 implements Observer, Disposable, Runnable { /** */ private static final long serialVersionUID = 6576896619930983584L; - final NbpSubscriber actual; + final Observer actual; final Scheduler.Worker worker; final boolean delayError; final int bufferSize; @@ -73,7 +73,7 @@ static final class ObserveOnSubscriber extends Padding0 implements NbpSubscri volatile boolean cancelled; - public ObserveOnSubscriber(NbpSubscriber actual, Scheduler.Worker worker, boolean delayError, int bufferSize) { + public ObserveOnSubscriber(Observer actual, Scheduler.Worker worker, boolean delayError, int bufferSize) { this.actual = actual; this.worker = worker; this.delayError = delayError; @@ -144,7 +144,7 @@ public void run() { int missed = 1; final Queue q = queue; - final NbpSubscriber a = actual; + final Observer a = actual; for (;;) { if (checkTerminated(done, q.isEmpty(), a)) { @@ -174,7 +174,7 @@ public void run() { } } - boolean checkTerminated(boolean d, boolean empty, NbpSubscriber a) { + boolean checkTerminated(boolean d, boolean empty, Observer a) { if (cancelled) { s.dispose(); worker.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorNext.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorNext.java similarity index 79% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorNext.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorNext.java index 3a28e0de91..fdd8dab09c 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorNext.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorNext.java @@ -11,34 +11,34 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.Function; import io.reactivex.plugins.RxJavaPlugins; public final class NbpOperatorOnErrorNext implements NbpOperator { - final Function> nextSupplier; + final Function> nextSupplier; final boolean allowFatal; - public NbpOperatorOnErrorNext(Function> nextSupplier, boolean allowFatal) { + public NbpOperatorOnErrorNext(Function> nextSupplier, boolean allowFatal) { this.nextSupplier = nextSupplier; this.allowFatal = allowFatal; } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { OnErrorNextSubscriber parent = new OnErrorNextSubscriber(t, nextSupplier, allowFatal); t.onSubscribe(parent.arbiter); return parent; } - static final class OnErrorNextSubscriber implements NbpSubscriber { - final NbpSubscriber actual; - final Function> nextSupplier; + static final class OnErrorNextSubscriber implements Observer { + final Observer actual; + final Function> nextSupplier; final boolean allowFatal; final MultipleAssignmentDisposable arbiter; @@ -46,7 +46,7 @@ static final class OnErrorNextSubscriber implements NbpSubscriber { boolean done; - public OnErrorNextSubscriber(NbpSubscriber actual, Function> nextSupplier, boolean allowFatal) { + public OnErrorNextSubscriber(Observer actual, Function> nextSupplier, boolean allowFatal) { this.actual = actual; this.nextSupplier = nextSupplier; this.allowFatal = allowFatal; @@ -83,7 +83,7 @@ public void onError(Throwable t) { return; } - NbpObservable p; + Observable p; try { p = nextSupplier.apply(t); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorReturn.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorReturn.java similarity index 85% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorReturn.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorReturn.java index 5b98d1c494..20e2508dbb 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorReturn.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorReturn.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.Function; @@ -26,19 +27,19 @@ public NbpOperatorOnErrorReturn(Function valueSu } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new OnErrorReturnSubscriber(t, valueSupplier); } - static final class OnErrorReturnSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class OnErrorReturnSubscriber implements Observer { + final Observer actual; final Function valueSupplier; Disposable s; volatile boolean done; - public OnErrorReturnSubscriber(NbpSubscriber actual, Function valueSupplier) { + public OnErrorReturnSubscriber(Observer actual, Function valueSupplier) { this.actual = actual; this.valueSupplier = valueSupplier; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorPublish.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorPublish.java similarity index 96% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorPublish.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorPublish.java index 3dd15f15b0..504125722f 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorPublish.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorPublish.java @@ -11,27 +11,27 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Queue; import java.util.concurrent.atomic.*; -import io.reactivex.NbpObservable; +import io.reactivex.*; import io.reactivex.disposables.*; import io.reactivex.functions.*; import io.reactivex.internal.queue.SpscArrayQueue; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.NotificationLite; -import io.reactivex.observables.nbp.NbpConnectableObservable; +import io.reactivex.observables.ConnectableObservable; /** * A connectable observable which shares an underlying source and dispatches source values to subscribers in a backpressure-aware * manner. * @param the value type */ -public final class NbpOperatorPublish extends NbpConnectableObservable { +public final class NbpOperatorPublish extends ConnectableObservable { /** The source observable. */ - final NbpObservable source; + final Observable source; /** Holds the current subscriber that is, will be or just was subscribed to the source observable. */ final AtomicReference> current; @@ -45,12 +45,12 @@ public final class NbpOperatorPublish extends NbpConnectableObservable { * @param bufferSize the size of the prefetch buffer * @return the connectable observable */ - public static NbpConnectableObservable create(NbpObservable source, final int bufferSize) { + public static ConnectableObservable create(Observable source, final int bufferSize) { // the current connection to source needs to be shared between the operator and its onSubscribe call final AtomicReference> curr = new AtomicReference>(); NbpOnSubscribe onSubscribe = new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber child) { + public void accept(Observer child) { // concurrent connection/disconnection may change the state, // we loop to be atomic while the child subscribes for (;;) { @@ -115,12 +115,12 @@ public void accept(NbpSubscriber child) { return new NbpOperatorPublish(onSubscribe, source, curr, bufferSize); } - public static NbpObservable create(final NbpObservable source, - final Function, ? extends NbpObservable> selector, final int bufferSize) { + public static Observable create(final Observable source, + final Function, ? extends Observable> selector, final int bufferSize) { return create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber sr) { - NbpConnectableObservable op = create(source, bufferSize); + public void accept(Observer sr) { + ConnectableObservable op = create(source, bufferSize); final NbpSubscriberResourceWrapper srw = new NbpSubscriberResourceWrapper(sr, Disposables.consumeAndDispose()); @@ -136,7 +136,7 @@ public void accept(Disposable r) { }); } - private NbpOperatorPublish(NbpOnSubscribe onSubscribe, NbpObservable source, + private NbpOperatorPublish(NbpOnSubscribe onSubscribe, Observable source, final AtomicReference> current, int bufferSize) { super(onSubscribe); this.source = source; @@ -189,7 +189,7 @@ public void connect(Consumer connection) { } @SuppressWarnings("rawtypes") - static final class PublishSubscriber implements NbpSubscriber, Disposable { + static final class PublishSubscriber implements Observer, Disposable { /** Holds notifications from upstream. */ final Queue queue; /** Holds onto the current connected PublishSubscriber. */ @@ -624,14 +624,14 @@ static final class InnerProducer implements Disposable { */ final PublishSubscriber parent; /** The actual child subscriber. */ - final NbpSubscriber child; + final Observer child; /** * Indicates this child has been unsubscribed: the state is swapped in atomically and * will prevent the dispatch() to emit (too many) values to a terminated child subscriber. */ volatile boolean cancelled; - public InnerProducer(PublishSubscriber parent, NbpSubscriber child) { + public InnerProducer(PublishSubscriber parent, Observer child) { this.parent = parent; this.child = child; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorReplay.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorReplay.java similarity index 94% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorReplay.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorReplay.java index 9957bda3e2..829d7ecbf3 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorReplay.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorReplay.java @@ -11,24 +11,26 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; -import io.reactivex.*; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.Scheduler; import io.reactivex.disposables.*; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.NotificationLite; -import io.reactivex.observables.nbp.NbpConnectableObservable; +import io.reactivex.observables.ConnectableObservable; import io.reactivex.schedulers.Timed; -public final class NbpOperatorReplay extends NbpConnectableObservable { +public final class NbpOperatorReplay extends ConnectableObservable { /** The source observable. */ - final NbpObservable source; + final Observable source; /** Holds the current subscriber that is, will be or just was subscribed to the source observable. */ final AtomicReference> current; /** A factory that creates the appropriate buffer for the ReplaySubscriber. */ @@ -51,14 +53,14 @@ public Object get() { * @param selector * @return the new NbpObservable instance */ - public static NbpObservable multicastSelector( - final Supplier> connectableFactory, - final Function, ? extends NbpObservable> selector) { - return NbpObservable.create(new NbpOnSubscribe() { + public static Observable multicastSelector( + final Supplier> connectableFactory, + final Function, ? extends Observable> selector) { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber child) { - NbpConnectableObservable co; - NbpObservable observable; + public void accept(Observer child) { + ConnectableObservable co; + Observable observable; try { co = connectableFactory.get(); observable = selector.apply(co); @@ -89,11 +91,11 @@ public void accept(Disposable r) { * @param scheduler the target scheduler * @return the new NbpConnectableObservable instance */ - public static NbpConnectableObservable observeOn(final NbpConnectableObservable co, final Scheduler scheduler) { - final NbpObservable observable = co.observeOn(scheduler); - return new NbpConnectableObservable(new NbpOnSubscribe() { + public static ConnectableObservable observeOn(final ConnectableObservable co, final Scheduler scheduler) { + final Observable observable = co.observeOn(scheduler); + return new ConnectableObservable(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { observable.subscribe(s); } }) { @@ -111,7 +113,7 @@ public void connect(Consumer connection) { * @return the new NbpConnectableObservable instance */ @SuppressWarnings("unchecked") - public static NbpConnectableObservable createFrom(NbpObservable source) { + public static ConnectableObservable createFrom(Observable source) { return create(source, DEFAULT_UNBOUNDED_FACTORY); } @@ -122,7 +124,7 @@ public static NbpConnectableObservable createFrom(NbpObservable NbpConnectableObservable create(NbpObservable source, + public static ConnectableObservable create(Observable source, final int bufferSize) { if (bufferSize == Integer.MAX_VALUE) { return createFrom(source); @@ -144,7 +146,7 @@ public ReplayBuffer get() { * @param scheduler * @return the new NbpConnectableObservable instance */ - public static NbpConnectableObservable create(NbpObservable source, + public static ConnectableObservable create(Observable source, long maxAge, TimeUnit unit, Scheduler scheduler) { return create(source, maxAge, unit, scheduler, Integer.MAX_VALUE); } @@ -159,7 +161,7 @@ public static NbpConnectableObservable create(NbpObservable * @param bufferSize * @return the new NbpConnectableObservable instance */ - public static NbpConnectableObservable create(NbpObservable source, + public static ConnectableObservable create(Observable source, final long maxAge, final TimeUnit unit, final Scheduler scheduler, final int bufferSize) { return create(source, new Supplier>() { @Override @@ -175,13 +177,13 @@ public ReplayBuffer get() { * @param bufferFactory the factory to instantiate the appropriate buffer when the observable becomes active * @return the connectable observable */ - static NbpConnectableObservable create(NbpObservable source, + static ConnectableObservable create(Observable source, final Supplier> bufferFactory) { // the current connection to source needs to be shared between the operator and its onSubscribe call final AtomicReference> curr = new AtomicReference>(); NbpOnSubscribe onSubscribe = new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber child) { + public void accept(Observer child) { // concurrent connection/disconnection may change the state, // we loop to be atomic while the child subscribes for (;;) { @@ -222,7 +224,7 @@ public void accept(NbpSubscriber child) { }; return new NbpOperatorReplay(onSubscribe, source, curr, bufferFactory); } - private NbpOperatorReplay(NbpOnSubscribe onSubscribe, NbpObservable source, + private NbpOperatorReplay(NbpOnSubscribe onSubscribe, Observable source, final AtomicReference> current, final Supplier> bufferFactory) { super(onSubscribe); @@ -276,7 +278,7 @@ public void connect(Consumer connection) { } @SuppressWarnings("rawtypes") - static final class ReplaySubscriber implements NbpSubscriber, Disposable { + static final class ReplaySubscriber implements Observer, Disposable { /** Holds notifications from upstream. */ final ReplayBuffer buffer; /** The notification-lite factory. */ @@ -481,7 +483,7 @@ static final class InnerSubscription implements Disposable { */ final ReplaySubscriber parent; /** The actual child subscriber. */ - final NbpSubscriber child; + final Observer child; /** * Holds an object that represents the current location in the buffer. * Guarded by the emitter loop. @@ -494,7 +496,7 @@ static final class InnerSubscription implements Disposable { volatile boolean cancelled; - public InnerSubscription(ReplaySubscriber parent, NbpSubscriber child) { + public InnerSubscription(ReplaySubscriber parent, Observer child) { this.parent = parent; this.child = child; } @@ -591,7 +593,7 @@ public void replay(InnerSubscription output) { } output.emitting = true; } - final NbpSubscriber child = output.child; + final Observer child = output.child; for (;;) { if (output.isDisposed()) { diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSampleTimed.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSampleTimed.java similarity index 85% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSampleTimed.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSampleTimed.java index 57c2d0f026..4137925c89 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSampleTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSampleTimed.java @@ -11,16 +11,16 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.Scheduler; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; +import io.reactivex.observers.SerializedObserver; public final class NbpOperatorSampleTimed implements NbpOperator { final long period; @@ -35,16 +35,16 @@ public NbpOperatorSampleTimed(long period, TimeUnit unit, Scheduler scheduler) { @Override - public NbpSubscriber apply(NbpSubscriber t) { - NbpSerializedSubscriber serial = new NbpSerializedSubscriber(t); + public Observer apply(Observer t) { + SerializedObserver serial = new SerializedObserver(t); return new SampleTimedSubscriber(serial, period, unit, scheduler); } - static final class SampleTimedSubscriber extends AtomicReference implements NbpSubscriber, Disposable, Runnable { + static final class SampleTimedSubscriber extends AtomicReference implements Observer, Disposable, Runnable { /** */ private static final long serialVersionUID = -3517602651313910099L; - final NbpSubscriber actual; + final Observer actual; final long period; final TimeUnit unit; final Scheduler scheduler; @@ -58,7 +58,7 @@ public void dispose() { } Disposable s; - public SampleTimedSubscriber(NbpSubscriber actual, long period, TimeUnit unit, Scheduler scheduler) { + public SampleTimedSubscriber(Observer actual, long period, TimeUnit unit, Scheduler scheduler) { this.actual = actual; this.period = period; this.unit = unit; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSampleWithObservable.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSampleWithObservable.java similarity index 83% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSampleWithObservable.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSampleWithObservable.java index 5f7f6d2b7a..dc61415a09 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSampleWithObservable.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSampleWithObservable.java @@ -11,36 +11,36 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; +import io.reactivex.observers.SerializedObserver; public final class NbpOperatorSampleWithObservable implements NbpOperator { - final NbpObservable other; + final Observable other; - public NbpOperatorSampleWithObservable(NbpObservable other) { + public NbpOperatorSampleWithObservable(Observable other) { this.other = other; } @Override - public NbpSubscriber apply(NbpSubscriber t) { - NbpSerializedSubscriber serial = new NbpSerializedSubscriber(t); + public Observer apply(Observer t) { + SerializedObserver serial = new SerializedObserver(t); return new SamplePublisherSubscriber(serial, other); } static final class SamplePublisherSubscriber extends AtomicReference - implements NbpSubscriber, Disposable { + implements Observer, Disposable { /** */ private static final long serialVersionUID = -3517602651313910099L; - final NbpSubscriber actual; - final NbpObservable sampler; + final Observer actual; + final Observable sampler; final AtomicReference other = new AtomicReference(); @@ -51,7 +51,7 @@ public void dispose() { } Disposable s; - public SamplePublisherSubscriber(NbpSubscriber actual, NbpObservable other) { + public SamplePublisherSubscriber(Observer actual, Observable other) { this.actual = actual; this.sampler = other; } @@ -131,7 +131,7 @@ public void emit() { } } - static final class SamplerSubscriber implements NbpSubscriber { + static final class SamplerSubscriber implements Observer { final SamplePublisherSubscriber parent; public SamplerSubscriber(SamplePublisherSubscriber parent) { this.parent = parent; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorScan.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorScan.java similarity index 85% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorScan.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorScan.java index 5924b01b8c..919d0d34ea 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorScan.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorScan.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.BiFunction; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -25,19 +26,19 @@ public NbpOperatorScan(BiFunction accumulator) { } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new ScanSubscriber(t, accumulator); } - static final class ScanSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class ScanSubscriber implements Observer { + final Observer actual; final BiFunction accumulator; Disposable s; T value; - public ScanSubscriber(NbpSubscriber actual, BiFunction accumulator) { + public ScanSubscriber(Observer actual, BiFunction accumulator) { this.actual = actual; this.accumulator = accumulator; } @@ -53,7 +54,7 @@ public void onSubscribe(Disposable s) { @Override public void onNext(T t) { - final NbpSubscriber a = actual; + final Observer a = actual; T v = value; if (v == null) { value = t; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorScanSeed.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorScanSeed.java similarity index 87% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorScanSeed.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorScanSeed.java index 2fadf90762..b75108da80 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorScanSeed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorScanSeed.java @@ -10,13 +10,14 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.internal.subscribers.nbp.NbpEmptySubscriber; +import io.reactivex.internal.subscribers.observable.NbpEmptySubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; @@ -30,7 +31,7 @@ public NbpOperatorScanSeed(Supplier seedSupplier, BiFunction } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { R r; try { @@ -48,8 +49,8 @@ public NbpSubscriber apply(NbpSubscriber t) { return new ScanSeedSubscriber(t, accumulator, r); } - static final class ScanSeedSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class ScanSeedSubscriber implements Observer { + final Observer actual; final BiFunction accumulator; R value; @@ -58,7 +59,7 @@ static final class ScanSeedSubscriber implements NbpSubscriber { boolean done; - public ScanSeedSubscriber(NbpSubscriber actual, BiFunction accumulator, R value) { + public ScanSeedSubscriber(Observer actual, BiFunction accumulator, R value) { this.actual = actual; this.accumulator = accumulator; this.value = value; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSingle.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSingle.java similarity index 88% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSingle.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSingle.java index eae65a92db..16bea5ef56 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSingle.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSingle.java @@ -11,11 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.NoSuchElementException; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -33,12 +34,12 @@ public NbpOperatorSingle(T defaultValue) { this.defaultValue = defaultValue; } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new SingleElementSubscriber(t, defaultValue); } - static final class SingleElementSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class SingleElementSubscriber implements Observer { + final Observer actual; final T defaultValue; Disposable s; @@ -47,7 +48,7 @@ static final class SingleElementSubscriber implements NbpSubscriber { boolean done; - public SingleElementSubscriber(NbpSubscriber actual, T defaultValue) { + public SingleElementSubscriber(Observer actual, T defaultValue) { this.actual = actual; this.defaultValue = defaultValue; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkip.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkip.java similarity index 81% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkip.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkip.java index d6efda8e92..71c70daf58 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkip.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkip.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; public final class NbpOperatorSkip implements NbpOperator { @@ -23,14 +24,14 @@ public NbpOperatorSkip(long n) { } @Override - public NbpSubscriber apply(NbpSubscriber s) { + public Observer apply(Observer s) { return new SkipSubscriber(s, n); } - static final class SkipSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class SkipSubscriber implements Observer { + final Observer actual; long remaining; - public SkipSubscriber(NbpSubscriber actual, long n) { + public SkipSubscriber(Observer actual, long n) { this.actual = actual; this.remaining = n; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipLast.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkipLast.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipLast.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkipLast.java index 6676d83bec..588430415c 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipLast.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkipLast.java @@ -11,11 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.ArrayDeque; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; public final class NbpOperatorSkipLast implements NbpOperator { @@ -26,17 +27,17 @@ public NbpOperatorSkipLast(int skip) { } @Override - public NbpSubscriber apply(NbpSubscriber s) { + public Observer apply(Observer s) { return new SkipLastSubscriber(s, skip); } - static final class SkipLastSubscriber extends ArrayDeque implements NbpSubscriber { + static final class SkipLastSubscriber extends ArrayDeque implements Observer { /** */ private static final long serialVersionUID = -3807491841935125653L; - final NbpSubscriber actual; + final Observer actual; final int skip; - public SkipLastSubscriber(NbpSubscriber actual, int skip) { + public SkipLastSubscriber(Observer actual, int skip) { super(skip); this.actual = actual; this.skip = skip; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipLastTimed.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkipLastTimed.java similarity index 91% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipLastTimed.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkipLastTimed.java index 77c9975f91..a49d311db6 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipLastTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkipLastTimed.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.Scheduler; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.queue.SpscLinkedArrayQueue; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -38,14 +38,14 @@ public NbpOperatorSkipLastTimed(long time, TimeUnit unit, Scheduler scheduler, i } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new SkipLastTimedSubscriber(t, time, unit, scheduler, bufferSize, delayError); } - static final class SkipLastTimedSubscriber extends AtomicInteger implements NbpSubscriber, Disposable { + static final class SkipLastTimedSubscriber extends AtomicInteger implements Observer, Disposable { /** */ private static final long serialVersionUID = -5677354903406201275L; - final NbpSubscriber actual; + final Observer actual; final long time; final TimeUnit unit; final Scheduler scheduler; @@ -59,7 +59,7 @@ static final class SkipLastTimedSubscriber extends AtomicInteger implements N volatile boolean done; Throwable error; - public SkipLastTimedSubscriber(NbpSubscriber actual, long time, TimeUnit unit, Scheduler scheduler, int bufferSize, boolean delayError) { + public SkipLastTimedSubscriber(Observer actual, long time, TimeUnit unit, Scheduler scheduler, int bufferSize, boolean delayError) { this.actual = actual; this.time = time; this.unit = unit; @@ -120,7 +120,7 @@ void drain() { int missed = 1; - final NbpSubscriber a = actual; + final Observer a = actual; final SpscLinkedArrayQueue q = queue; final boolean delayError = this.delayError; final TimeUnit unit = this.unit; @@ -180,7 +180,7 @@ void drain() { } } - boolean checkTerminated(boolean d, boolean empty, NbpSubscriber a, boolean delayError) { + boolean checkTerminated(boolean d, boolean empty, Observer a, boolean delayError) { if (cancelled) { queue.clear(); s.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipUntil.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkipUntil.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipUntil.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkipUntil.java index 95315678e6..7a867ef893 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipUntil.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkipUntil.java @@ -11,33 +11,33 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.AtomicBoolean; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.internal.disposables.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; +import io.reactivex.observers.SerializedObserver; public final class NbpOperatorSkipUntil implements NbpOperator { - final NbpObservable other; - public NbpOperatorSkipUntil(NbpObservable other) { + final Observable other; + public NbpOperatorSkipUntil(Observable other) { this.other = other; } @Override - public NbpSubscriber apply(NbpSubscriber child) { + public Observer apply(Observer child) { - final NbpSerializedSubscriber serial = new NbpSerializedSubscriber(child); + final SerializedObserver serial = new SerializedObserver(child); final ArrayCompositeResource frc = new ArrayCompositeResource(2, Disposables.consumeAndDispose()); final SkipUntilSubscriber sus = new SkipUntilSubscriber(serial, frc); - other.subscribe(new NbpSubscriber() { + other.subscribe(new Observer() { Disposable s; @Override public void onSubscribe(Disposable s) { @@ -74,10 +74,10 @@ public void onComplete() { return sus; } - static final class SkipUntilSubscriber extends AtomicBoolean implements NbpSubscriber, Disposable { + static final class SkipUntilSubscriber extends AtomicBoolean implements Observer, Disposable { /** */ private static final long serialVersionUID = -1113667257122396604L; - final NbpSubscriber actual; + final Observer actual; final ArrayCompositeResource frc; Disposable s; @@ -85,7 +85,7 @@ static final class SkipUntilSubscriber extends AtomicBoolean implements NbpSu volatile boolean notSkipping; boolean notSkippingLocal; - public SkipUntilSubscriber(NbpSubscriber actual, ArrayCompositeResource frc) { + public SkipUntilSubscriber(Observer actual, ArrayCompositeResource frc) { this.actual = actual; this.frc = frc; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipWhile.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkipWhile.java similarity index 85% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipWhile.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkipWhile.java index 8798fc58eb..a655f77cbf 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipWhile.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSkipWhile.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Predicate; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -25,16 +26,16 @@ public NbpOperatorSkipWhile(Predicate predicate) { } @Override - public NbpSubscriber apply(NbpSubscriber s) { + public Observer apply(Observer s) { return new SkipWhileSubscriber(s, predicate); } - static final class SkipWhileSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class SkipWhileSubscriber implements Observer { + final Observer actual; final Predicate predicate; Disposable s; boolean notSkipping; - public SkipWhileSubscriber(NbpSubscriber actual, Predicate predicate) { + public SkipWhileSubscriber(Observer actual, Predicate predicate) { this.actual = actual; this.predicate = predicate; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSwitchIfEmpty.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSwitchIfEmpty.java similarity index 75% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSwitchIfEmpty.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSwitchIfEmpty.java index 82dddbdd4e..10631414a1 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSwitchIfEmpty.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSwitchIfEmpty.java @@ -11,33 +11,33 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; public final class NbpOperatorSwitchIfEmpty implements NbpOperator { - final NbpObservable other; - public NbpOperatorSwitchIfEmpty(NbpObservable other) { + final Observable other; + public NbpOperatorSwitchIfEmpty(Observable other) { this.other = other; } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { SwitchIfEmptySubscriber parent = new SwitchIfEmptySubscriber(t, other); t.onSubscribe(parent.arbiter); return parent; } - static final class SwitchIfEmptySubscriber implements NbpSubscriber { - final NbpSubscriber actual; - final NbpObservable other; + static final class SwitchIfEmptySubscriber implements Observer { + final Observer actual; + final Observable other; final SerialDisposable arbiter; boolean empty; - public SwitchIfEmptySubscriber(NbpSubscriber actual, NbpObservable other) { + public SwitchIfEmptySubscriber(Observer actual, Observable other) { this.actual = actual; this.other = other; this.empty = true; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSwitchMap.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSwitchMap.java similarity index 92% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSwitchMap.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSwitchMap.java index a339640271..9ad926d72c 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorSwitchMap.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorSwitchMap.java @@ -11,15 +11,15 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Queue; import java.util.concurrent.atomic.*; import org.reactivestreams.Subscriber; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; import io.reactivex.internal.queue.*; @@ -28,24 +28,24 @@ import io.reactivex.plugins.RxJavaPlugins; public final class NbpOperatorSwitchMap implements NbpOperator { - final Function> mapper; + final Function> mapper; final int bufferSize; - public NbpOperatorSwitchMap(Function> mapper, int bufferSize) { + public NbpOperatorSwitchMap(Function> mapper, int bufferSize) { this.mapper = mapper; this.bufferSize = bufferSize; } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new SwitchMapSubscriber(t, mapper, bufferSize); } - static final class SwitchMapSubscriber extends AtomicInteger implements NbpSubscriber, Disposable { + static final class SwitchMapSubscriber extends AtomicInteger implements Observer, Disposable { /** */ private static final long serialVersionUID = -3491074160481096299L; - final NbpSubscriber actual; - final Function> mapper; + final Observer actual; + final Function> mapper; final int bufferSize; @@ -66,7 +66,7 @@ static final class SwitchMapSubscriber extends AtomicInteger implements Nb volatile long unique; - public SwitchMapSubscriber(NbpSubscriber actual, Function> mapper, int bufferSize) { + public SwitchMapSubscriber(Observer actual, Function> mapper, int bufferSize) { this.actual = actual; this.mapper = mapper; this.bufferSize = bufferSize; @@ -91,7 +91,7 @@ public void onNext(T t) { inner.cancel(); } - NbpObservable p; + Observable p; try { p = mapper.apply(t); } catch (Throwable e) { @@ -165,7 +165,7 @@ void drain() { return; } - final NbpSubscriber a = actual; + final Observer a = actual; int missing = 1; @@ -279,7 +279,7 @@ boolean checkTerminated(boolean d, boolean empty, Subscriber a) { } } - static final class SwitchMapInnerSubscriber extends AtomicReference implements NbpSubscriber { + static final class SwitchMapInnerSubscriber extends AtomicReference implements Observer { /** */ private static final long serialVersionUID = 3837284832786408377L; final SwitchMapSubscriber parent; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTake.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTake.java similarity index 85% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTake.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTake.java index f12cce772c..1e6feb3928 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTake.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTake.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -24,19 +25,19 @@ public NbpOperatorTake(long limit) { } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new TakeSubscriber(t, limit); } - static final class TakeSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class TakeSubscriber implements Observer { + final Observer actual; boolean done; Disposable subscription; long remaining; - public TakeSubscriber(NbpSubscriber actual, long limit) { + public TakeSubscriber(Observer actual, long limit) { this.actual = actual; this.remaining = limit; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLast.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLast.java similarity index 87% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLast.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLast.java index 91802515c6..6bc0f1302d 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLast.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLast.java @@ -11,11 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.ArrayDeque; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -27,14 +28,14 @@ public NbpOperatorTakeLast(int count) { } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new TakeLastSubscriber(t, count); } - static final class TakeLastSubscriber extends ArrayDeque implements NbpSubscriber, Disposable { + static final class TakeLastSubscriber extends ArrayDeque implements Observer, Disposable { /** */ private static final long serialVersionUID = 7240042530241604978L; - final NbpSubscriber actual; + final Observer actual; final int count; Disposable s; @@ -42,7 +43,7 @@ static final class TakeLastSubscriber extends ArrayDeque implements NbpSub volatile boolean done; volatile boolean cancelled; - public TakeLastSubscriber(NbpSubscriber actual, int count) { + public TakeLastSubscriber(Observer actual, int count) { this.actual = actual; this.count = count; } @@ -75,7 +76,7 @@ public void onComplete() { if (cancelled) { return; } - NbpSubscriber a = actual; + Observer a = actual; for (;;) { if (cancelled) { return; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastOne.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastOne.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastOne.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastOne.java index 587ec0f84e..5d47eee387 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastOne.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastOne.java @@ -10,9 +10,10 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -26,18 +27,18 @@ public static NbpOperator instance() { } @Override - public NbpSubscriber apply(NbpSubscriber s) { + public Observer apply(Observer s) { return new TakeLastOneSubscriber(s); } - static final class TakeLastOneSubscriber implements NbpSubscriber, Disposable { - final NbpSubscriber actual; + static final class TakeLastOneSubscriber implements Observer, Disposable { + final Observer actual; Disposable s; T value; - public TakeLastOneSubscriber(NbpSubscriber actual) { + public TakeLastOneSubscriber(Observer actual) { this.actual = actual; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastTimed.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastTimed.java similarity index 91% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastTimed.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastTimed.java index 404de39b66..f7b346fc17 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastTimed.java @@ -11,14 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Queue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.Scheduler; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.queue.SpscLinkedArrayQueue; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -41,14 +41,14 @@ public NbpOperatorTakeLastTimed(long count, long time, TimeUnit unit, Scheduler } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new TakeLastTimedSubscriber(t, count, time, unit, scheduler, bufferSize, delayError); } - static final class TakeLastTimedSubscriber extends AtomicInteger implements NbpSubscriber, Disposable { + static final class TakeLastTimedSubscriber extends AtomicInteger implements Observer, Disposable { /** */ private static final long serialVersionUID = -5677354903406201275L; - final NbpSubscriber actual; + final Observer actual; final long count; final long time; final TimeUnit unit; @@ -63,7 +63,7 @@ static final class TakeLastTimedSubscriber extends AtomicInteger implements N volatile boolean done; Throwable error; - public TakeLastTimedSubscriber(NbpSubscriber actual, long count, long time, TimeUnit unit, Scheduler scheduler, int bufferSize, boolean delayError) { + public TakeLastTimedSubscriber(Observer actual, long count, long time, TimeUnit unit, Scheduler scheduler, int bufferSize, boolean delayError) { this.actual = actual; this.count = count; this.time = time; @@ -137,7 +137,7 @@ void drain() { int missed = 1; - final NbpSubscriber a = actual; + final Observer a = actual; final Queue q = queue; final boolean delayError = this.delayError; @@ -185,7 +185,7 @@ void drain() { } } - boolean checkTerminated(boolean empty, NbpSubscriber a, boolean delayError) { + boolean checkTerminated(boolean empty, Observer a, boolean delayError) { if (cancelled) { queue.clear(); s.dispose(); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeUntil.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeUntil.java similarity index 82% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeUntil.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeUntil.java index fc9e998a22..8d878e0454 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeUntil.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeUntil.java @@ -11,31 +11,31 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.AtomicBoolean; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.internal.disposables.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; +import io.reactivex.observers.SerializedObserver; public final class NbpOperatorTakeUntil implements NbpOperator { - final NbpObservable other; - public NbpOperatorTakeUntil(NbpObservable other) { + final Observable other; + public NbpOperatorTakeUntil(Observable other) { this.other = other; } @Override - public NbpSubscriber apply(NbpSubscriber child) { - final NbpSerializedSubscriber serial = new NbpSerializedSubscriber(child); + public Observer apply(Observer child) { + final SerializedObserver serial = new SerializedObserver(child); final ArrayCompositeResource frc = new ArrayCompositeResource(2, Disposables.consumeAndDispose()); final TakeUntilSubscriber tus = new TakeUntilSubscriber(serial, frc); - other.subscribe(new NbpSubscriber() { + other.subscribe(new Observer() { @Override public void onSubscribe(Disposable s) { frc.setResource(1, s); @@ -72,15 +72,15 @@ public void onComplete() { return tus; } - static final class TakeUntilSubscriber extends AtomicBoolean implements NbpSubscriber, Disposable { + static final class TakeUntilSubscriber extends AtomicBoolean implements Observer, Disposable { /** */ private static final long serialVersionUID = 3451719290311127173L; - final NbpSubscriber actual; + final Observer actual; final ArrayCompositeResource frc; Disposable s; - public TakeUntilSubscriber(NbpSubscriber actual, ArrayCompositeResource frc) { + public TakeUntilSubscriber(Observer actual, ArrayCompositeResource frc) { this.actual = actual; this.frc = frc; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeUntilPredicate.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeUntilPredicate.java similarity index 86% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeUntilPredicate.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeUntilPredicate.java index 090554a076..a5438db317 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeUntilPredicate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeUntilPredicate.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Predicate; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -25,16 +26,16 @@ public NbpOperatorTakeUntilPredicate(Predicate predicate) { } @Override - public NbpSubscriber apply(NbpSubscriber s) { + public Observer apply(Observer s) { return new InnerSubscriber(s, predicate); } - static final class InnerSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class InnerSubscriber implements Observer { + final Observer actual; final Predicate predicate; Disposable s; boolean done; - public InnerSubscriber(NbpSubscriber actual, Predicate predicate) { + public InnerSubscriber(Observer actual, Predicate predicate) { this.actual = actual; this.predicate = predicate; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeWhile.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeWhile.java similarity index 86% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeWhile.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeWhile.java index 474edae06f..ef4c0c42ad 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeWhile.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTakeWhile.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Predicate; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -25,19 +26,19 @@ public NbpOperatorTakeWhile(Predicate predicate) { } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new TakeWhileSubscriber(t, predicate); } - static final class TakeWhileSubscriber implements NbpSubscriber { - final NbpSubscriber actual; + static final class TakeWhileSubscriber implements Observer { + final Observer actual; final Predicate predicate; Disposable s; boolean done; - public TakeWhileSubscriber(NbpSubscriber actual, Predicate predicate) { + public TakeWhileSubscriber(Observer actual, Predicate predicate) { this.actual = actual; this.predicate = predicate; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorThrottleFirstTimed.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorThrottleFirstTimed.java similarity index 89% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorThrottleFirstTimed.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorThrottleFirstTimed.java index 609b5b5786..8ee482f77d 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorThrottleFirstTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorThrottleFirstTimed.java @@ -11,18 +11,18 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable.*; -import io.reactivex.Scheduler; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; +import io.reactivex.observers.SerializedObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; public final class NbpOperatorThrottleFirstTimed implements NbpOperator { final long timeout; @@ -36,15 +36,15 @@ public NbpOperatorThrottleFirstTimed(long timeout, TimeUnit unit, Scheduler sche } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new DebounceTimedSubscriber( - new NbpSerializedSubscriber(t), + new SerializedObserver(t), timeout, unit, scheduler.createWorker()); } static final class DebounceTimedSubscriber - implements NbpSubscriber, Disposable, Runnable { - final NbpSubscriber actual; + implements Observer, Disposable, Runnable { + final Observer actual; final long timeout; final TimeUnit unit; final Scheduler.Worker worker; @@ -67,7 +67,7 @@ public void dispose() { } boolean done; - public DebounceTimedSubscriber(NbpSubscriber actual, long timeout, TimeUnit unit, Worker worker) { + public DebounceTimedSubscriber(Observer actual, long timeout, TimeUnit unit, Worker worker) { this.actual = actual; this.timeout = timeout; this.unit = unit; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeInterval.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTimeInterval.java similarity index 81% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeInterval.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTimeInterval.java index 82b30836b2..a9ca79c01d 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeInterval.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTimeInterval.java @@ -11,12 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.TimeUnit; -import io.reactivex.Scheduler; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Timed; @@ -30,18 +30,18 @@ public NbpOperatorTimeInterval(TimeUnit unit, Scheduler scheduler) { } @Override - public NbpSubscriber apply(NbpSubscriber> t) { + public Observer apply(Observer> t) { return new TimeIntervalSubscriber(t, unit, scheduler); } - static final class TimeIntervalSubscriber implements NbpSubscriber { - final NbpSubscriber> actual; + static final class TimeIntervalSubscriber implements Observer { + final Observer> actual; final TimeUnit unit; final Scheduler scheduler; long lastTime; - public TimeIntervalSubscriber(NbpSubscriber> actual, TimeUnit unit, Scheduler scheduler) { + public TimeIntervalSubscriber(Observer> actual, TimeUnit unit, Scheduler scheduler) { this.actual = actual; this.scheduler = scheduler; this.unit = unit; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeout.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTimeout.java similarity index 82% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeout.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTimeout.java index a6b0d136f2..d62eb66533 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeout.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTimeout.java @@ -11,48 +11,48 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.*; import io.reactivex.internal.disposables.*; -import io.reactivex.internal.subscribers.NbpFullArbiterSubscriber; -import io.reactivex.internal.subscribers.nbp.NbpDisposableSubscriber; +import io.reactivex.internal.subscribers.flowable.NbpFullArbiterSubscriber; +import io.reactivex.internal.subscribers.observable.NbpDisposableSubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; +import io.reactivex.observers.SerializedObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; public final class NbpOperatorTimeout implements NbpOperator { - final Supplier> firstTimeoutSelector; - final Function> timeoutSelector; - final NbpObservable other; + final Supplier> firstTimeoutSelector; + final Function> timeoutSelector; + final Observable other; - public NbpOperatorTimeout(Supplier> firstTimeoutSelector, - Function> timeoutSelector, NbpObservable other) { + public NbpOperatorTimeout(Supplier> firstTimeoutSelector, + Function> timeoutSelector, Observable other) { this.firstTimeoutSelector = firstTimeoutSelector; this.timeoutSelector = timeoutSelector; this.other = other; } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { if (other == null) { return new TimeoutSubscriber( - new NbpSerializedSubscriber(t), + new SerializedObserver(t), firstTimeoutSelector, timeoutSelector); } return new TimeoutOtherSubscriber(t, firstTimeoutSelector, timeoutSelector, other); } - static final class TimeoutSubscriber implements NbpSubscriber, Disposable, OnTimeout { - final NbpSubscriber actual; - final Supplier> firstTimeoutSelector; - final Function> timeoutSelector; + static final class TimeoutSubscriber implements Observer, Disposable, OnTimeout { + final Observer actual; + final Supplier> firstTimeoutSelector; + final Function> timeoutSelector; Disposable s; @@ -67,9 +67,9 @@ static final class TimeoutSubscriber implements NbpSubscriber, Dispo public void dispose() { } }; - public TimeoutSubscriber(NbpSubscriber actual, - Supplier> firstTimeoutSelector, - Function> timeoutSelector) { + public TimeoutSubscriber(Observer actual, + Supplier> firstTimeoutSelector, + Function> timeoutSelector) { this.actual = actual; this.firstTimeoutSelector = firstTimeoutSelector; this.timeoutSelector = timeoutSelector; @@ -82,9 +82,9 @@ public void onSubscribe(Disposable s) { } this.s = s; - NbpSubscriber a = actual; + Observer a = actual; - NbpObservable p; + Observable p; if (firstTimeoutSelector != null) { try { @@ -124,7 +124,7 @@ public void onNext(T t) { d.dispose(); } - NbpObservable p; + Observable p; try { p = timeoutSelector.apply(t); @@ -226,11 +226,11 @@ public void onComplete() { } } - static final class TimeoutOtherSubscriber implements NbpSubscriber, Disposable, OnTimeout { - final NbpSubscriber actual; - final Supplier> firstTimeoutSelector; - final Function> timeoutSelector; - final NbpObservable other; + static final class TimeoutOtherSubscriber implements Observer, Disposable, OnTimeout { + final Observer actual; + final Supplier> firstTimeoutSelector; + final Function> timeoutSelector; + final Observable other; final NbpFullArbiter arbiter; Disposable s; @@ -248,9 +248,9 @@ static final class TimeoutOtherSubscriber implements NbpSubscriber, public void dispose() { } }; - public TimeoutOtherSubscriber(NbpSubscriber actual, - Supplier> firstTimeoutSelector, - Function> timeoutSelector, NbpObservable other) { + public TimeoutOtherSubscriber(Observer actual, + Supplier> firstTimeoutSelector, + Function> timeoutSelector, Observable other) { this.actual = actual; this.firstTimeoutSelector = firstTimeoutSelector; this.timeoutSelector = timeoutSelector; @@ -268,10 +268,10 @@ public void onSubscribe(Disposable s) { if (!arbiter.setSubscription(s)) { return; } - NbpSubscriber a = actual; + Observer a = actual; if (firstTimeoutSelector != null) { - NbpObservable p; + Observable p; try { p = firstTimeoutSelector.get(); @@ -315,7 +315,7 @@ public void onNext(T t) { d.dispose(); } - NbpObservable p; + Observable p; try { p = timeoutSelector.apply(t); diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeoutTimed.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTimeoutTimed.java similarity index 88% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeoutTimed.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTimeoutTimed.java index c068678318..094b434b19 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeoutTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorTimeoutTimed.java @@ -11,28 +11,28 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.*; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.*; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; import io.reactivex.internal.disposables.NbpFullArbiter; -import io.reactivex.internal.subscribers.NbpFullArbiterSubscriber; +import io.reactivex.internal.subscribers.flowable.NbpFullArbiterSubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; +import io.reactivex.observers.SerializedObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; public final class NbpOperatorTimeoutTimed implements NbpOperator { final long timeout; final TimeUnit unit; final Scheduler scheduler; - final NbpObservable other; + final Observable other; - public NbpOperatorTimeoutTimed(long timeout, TimeUnit unit, Scheduler scheduler, NbpObservable other) { + public NbpOperatorTimeoutTimed(long timeout, TimeUnit unit, Scheduler scheduler, Observable other) { this.timeout = timeout; this.unit = unit; this.scheduler = scheduler; @@ -40,10 +40,10 @@ public NbpOperatorTimeoutTimed(long timeout, TimeUnit unit, Scheduler scheduler, } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { if (other == null) { return new TimeoutTimedSubscriber( - new NbpSerializedSubscriber(t), // because errors can race + new SerializedObserver(t), // because errors can race timeout, unit, scheduler.createWorker()); } return new TimeoutTimedOtherSubscriber( @@ -51,12 +51,12 @@ public NbpSubscriber apply(NbpSubscriber t) { timeout, unit, scheduler.createWorker(), other); } - static final class TimeoutTimedOtherSubscriber implements NbpSubscriber, Disposable { - final NbpSubscriber actual; + static final class TimeoutTimedOtherSubscriber implements Observer, Disposable { + final Observer actual; final long timeout; final TimeUnit unit; final Scheduler.Worker worker; - final NbpObservable other; + final Observable other; Disposable s; @@ -78,8 +78,8 @@ public void dispose() { } volatile boolean done; - public TimeoutTimedOtherSubscriber(NbpSubscriber actual, long timeout, TimeUnit unit, Worker worker, - NbpObservable other) { + public TimeoutTimedOtherSubscriber(Observer actual, long timeout, TimeUnit unit, Worker worker, + Observable other) { this.actual = actual; this.timeout = timeout; this.unit = unit; @@ -190,8 +190,8 @@ public void disposeTimer() { } } - static final class TimeoutTimedSubscriber implements NbpSubscriber, Disposable { - final NbpSubscriber actual; + static final class TimeoutTimedSubscriber implements Observer, Disposable { + final Observer actual; final long timeout; final TimeUnit unit; final Scheduler.Worker worker; @@ -214,7 +214,7 @@ public void dispose() { } volatile boolean done; - public TimeoutTimedSubscriber(NbpSubscriber actual, long timeout, TimeUnit unit, Worker worker) { + public TimeoutTimedSubscriber(Observer actual, long timeout, TimeUnit unit, Worker worker) { this.actual = actual; this.timeout = timeout; this.unit = unit; diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorToList.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorToList.java similarity index 87% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorToList.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorToList.java index 79d86caa46..3fa8969af3 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorToList.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorToList.java @@ -11,15 +11,16 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Supplier; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.internal.subscribers.nbp.NbpCancelledSubscriber; +import io.reactivex.internal.subscribers.observable.NbpCancelledSubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; @@ -45,7 +46,7 @@ public NbpOperatorToList(Supplier collectionSupplier) { } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { U coll; try { coll = collectionSupplier.get(); @@ -56,13 +57,13 @@ public NbpSubscriber apply(NbpSubscriber t) { return new ToListSubscriber(t, coll); } - static final class ToListSubscriber> implements NbpSubscriber { + static final class ToListSubscriber> implements Observer { U collection; - final NbpSubscriber actual; + final Observer actual; Disposable s; - public ToListSubscriber(NbpSubscriber actual, U collection) { + public ToListSubscriber(Observer actual, U collection) { this.actual = actual; this.collection = collection; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorUnsubscribeOn.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorUnsubscribeOn.java similarity index 85% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorUnsubscribeOn.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorUnsubscribeOn.java index 6a41b27e33..aaca98cac6 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorUnsubscribeOn.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorUnsubscribeOn.java @@ -11,12 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.AtomicBoolean; -import io.reactivex.Scheduler; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -27,20 +27,20 @@ public NbpOperatorUnsubscribeOn(Scheduler scheduler) { } @Override - public NbpSubscriber apply(NbpSubscriber t) { + public Observer apply(Observer t) { return new UnsubscribeSubscriber(t, scheduler); } - static final class UnsubscribeSubscriber extends AtomicBoolean implements NbpSubscriber, Disposable { + static final class UnsubscribeSubscriber extends AtomicBoolean implements Observer, Disposable { /** */ private static final long serialVersionUID = 1015244841293359600L; - final NbpSubscriber actual; + final Observer actual; final Scheduler scheduler; Disposable s; - public UnsubscribeSubscriber(NbpSubscriber actual, Scheduler scheduler) { + public UnsubscribeSubscriber(Observer actual, Scheduler scheduler) { this.actual = actual; this.scheduler = scheduler; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindow.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindow.java similarity index 78% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindow.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindow.java index 60bdb543a4..255e2cbc14 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindow.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindow.java @@ -11,18 +11,18 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.ArrayDeque; import java.util.concurrent.atomic.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.subjects.nbp.NbpUnicastSubject; +import io.reactivex.subjects.UnicastSubject; -public final class NbpOperatorWindow implements NbpOperator, T> { +public final class NbpOperatorWindow implements NbpOperator, T> { final long count; final long skip; final int capacityHint; @@ -34,7 +34,7 @@ public NbpOperatorWindow(long count, long skip, int capacityHint) { } @Override - public NbpSubscriber apply(NbpSubscriber> t) { + public Observer apply(Observer> t) { if (count == skip) { return new WindowExactSubscriber(t, count, capacityHint); } @@ -43,10 +43,10 @@ public NbpSubscriber apply(NbpSubscriber> t) static final class WindowExactSubscriber extends AtomicInteger - implements NbpSubscriber, Disposable, Runnable { + implements Observer, Disposable, Runnable { /** */ private static final long serialVersionUID = -7481782523886138128L; - final NbpSubscriber> actual; + final Observer> actual; final long count; final int capacityHint; @@ -54,11 +54,11 @@ static final class WindowExactSubscriber Disposable s; - NbpUnicastSubject window; + UnicastSubject window; volatile boolean cancelled; - public WindowExactSubscriber(NbpSubscriber> actual, long count, int capacityHint) { + public WindowExactSubscriber(Observer> actual, long count, int capacityHint) { this.actual = actual; this.count = count; this.capacityHint = capacityHint; @@ -77,9 +77,9 @@ public void onSubscribe(Disposable s) { @Override public void onNext(T t) { - NbpUnicastSubject w = window; + UnicastSubject w = window; if (w == null && !cancelled) { - w = NbpUnicastSubject.create(capacityHint, this); + w = UnicastSubject.create(capacityHint, this); window = w; actual.onNext(w); } @@ -97,7 +97,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - NbpUnicastSubject w = window; + UnicastSubject w = window; if (w != null) { window = null; w.onError(t); @@ -107,7 +107,7 @@ public void onError(Throwable t) { @Override public void onComplete() { - NbpUnicastSubject w = window; + UnicastSubject w = window; if (w != null) { window = null; w.onComplete(); @@ -129,14 +129,14 @@ public void run() { } static final class WindowSkipSubscriber extends AtomicBoolean - implements NbpSubscriber, Disposable, Runnable { + implements Observer, Disposable, Runnable { /** */ private static final long serialVersionUID = 3366976432059579510L; - final NbpSubscriber> actual; + final Observer> actual; final long count; final long skip; final int capacityHint; - final ArrayDeque> windows; + final ArrayDeque> windows; long index; @@ -149,12 +149,12 @@ static final class WindowSkipSubscriber extends AtomicBoolean final AtomicInteger wip = new AtomicInteger(); - public WindowSkipSubscriber(NbpSubscriber> actual, long count, long skip, int capacityHint) { + public WindowSkipSubscriber(Observer> actual, long count, long skip, int capacityHint) { this.actual = actual; this.count = count; this.skip = skip; this.capacityHint = capacityHint; - this.windows = new ArrayDeque>(); + this.windows = new ArrayDeque>(); } @Override @@ -170,7 +170,7 @@ public void onSubscribe(Disposable s) { @Override public void onNext(T t) { - final ArrayDeque> ws = windows; + final ArrayDeque> ws = windows; long i = index; @@ -178,14 +178,14 @@ public void onNext(T t) { if (i % s == 0 && !cancelled) { wip.getAndIncrement(); - NbpUnicastSubject w = NbpUnicastSubject.create(capacityHint, this); + UnicastSubject w = UnicastSubject.create(capacityHint, this); ws.offer(w); actual.onNext(w); } long c = firstEmission + 1; - for (NbpUnicastSubject w : ws) { + for (UnicastSubject w : ws) { w.onNext(t); } @@ -205,7 +205,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { - final ArrayDeque> ws = windows; + final ArrayDeque> ws = windows; while (!ws.isEmpty()) { ws.poll().onError(t); } @@ -214,7 +214,7 @@ public void onError(Throwable t) { @Override public void onComplete() { - final ArrayDeque> ws = windows; + final ArrayDeque> ws = windows; while (!ws.isEmpty()) { ws.poll().onComplete(); } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowBoundary.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindowBoundary.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowBoundary.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindowBoundary.java index 43b29a8588..1288de89a4 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowBoundary.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindowBoundary.java @@ -11,41 +11,41 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Queue; import java.util.concurrent.atomic.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.nbp.*; +import io.reactivex.internal.subscribers.observable.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.NotificationLite; +import io.reactivex.observers.SerializedObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.nbp.NbpUnicastSubject; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; +import io.reactivex.subjects.UnicastSubject; -public final class NbpOperatorWindowBoundary implements NbpOperator, T> { - final NbpObservable other; +public final class NbpOperatorWindowBoundary implements NbpOperator, T> { + final Observable other; final int bufferSize; - public NbpOperatorWindowBoundary(NbpObservable other, int bufferSize) { + public NbpOperatorWindowBoundary(Observable other, int bufferSize) { this.other = other; this.bufferSize = bufferSize; } @Override - public NbpSubscriber apply(NbpSubscriber> t) { - return new WindowBoundaryMainSubscriber(new NbpSerializedSubscriber>(t), other, bufferSize); + public Observer apply(Observer> t) { + return new WindowBoundaryMainSubscriber(new SerializedObserver>(t), other, bufferSize); } static final class WindowBoundaryMainSubscriber - extends NbpQueueDrainSubscriber> + extends NbpQueueDrainSubscriber> implements Disposable { - final NbpObservable other; + final Observable other; final int bufferSize; Disposable s; @@ -57,13 +57,13 @@ static final class WindowBoundaryMainSubscriber public void dispose() { } }; - NbpUnicastSubject window; + UnicastSubject window; static final Object NEXT = new Object(); final AtomicLong windows = new AtomicLong(); - public WindowBoundaryMainSubscriber(NbpSubscriber> actual, NbpObservable other, + public WindowBoundaryMainSubscriber(Observer> actual, Observable other, int bufferSize) { super(actual, new MpscLinkedQueue()); this.other = other; @@ -78,14 +78,14 @@ public void onSubscribe(Disposable s) { } this.s = s; - NbpSubscriber> a = actual; + Observer> a = actual; a.onSubscribe(this); if (cancelled) { return; } - NbpUnicastSubject w = NbpUnicastSubject.create(bufferSize); + UnicastSubject w = UnicastSubject.create(bufferSize); window = w; @@ -102,7 +102,7 @@ public void onSubscribe(Disposable s) { @Override public void onNext(T t) { if (fastEnter()) { - NbpUnicastSubject w = window; + UnicastSubject w = window; w.onNext(t); @@ -174,9 +174,9 @@ void disposeBoundary() { void drainLoop() { final Queue q = queue; - final NbpSubscriber> a = actual; + final Observer> a = actual; int missed = 1; - NbpUnicastSubject w = window; + UnicastSubject w = window; for (;;) { for (;;) { @@ -213,7 +213,7 @@ void drainLoop() { continue; } - w = NbpUnicastSubject.create(bufferSize); + w = UnicastSubject.create(bufferSize); windows.getAndIncrement(); @@ -242,7 +242,7 @@ void next() { } @Override - public void accept(NbpSubscriber> a, Object v) { + public void accept(Observer> a, Object v) { // not used by this operator } } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowBoundarySelector.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindowBoundarySelector.java similarity index 84% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowBoundarySelector.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindowBoundarySelector.java index b37e59ab08..e39f54c23b 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowBoundarySelector.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindowBoundarySelector.java @@ -11,30 +11,31 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.*; import java.util.concurrent.atomic.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observer; +import io.reactivex.Observable; +import io.reactivex.Observable.*; import io.reactivex.disposables.*; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.SetCompositeResource; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.nbp.*; +import io.reactivex.internal.subscribers.observable.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.NotificationLite; +import io.reactivex.observers.SerializedObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.nbp.NbpUnicastSubject; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; +import io.reactivex.subjects.UnicastSubject; -public final class NbpOperatorWindowBoundarySelector implements NbpOperator, T> { - final NbpObservable open; - final Function> close; +public final class NbpOperatorWindowBoundarySelector implements NbpOperator, T> { + final Observable open; + final Function> close; final int bufferSize; - public NbpOperatorWindowBoundarySelector(NbpObservable open, Function> close, + public NbpOperatorWindowBoundarySelector(Observable open, Function> close, int bufferSize) { this.open = open; this.close = close; @@ -42,17 +43,17 @@ public NbpOperatorWindowBoundarySelector(NbpObservable open, Function apply(NbpSubscriber> t) { + public Observer apply(Observer> t) { return new WindowBoundaryMainSubscriber( - new NbpSerializedSubscriber>(t), + new SerializedObserver>(t), open, close, bufferSize); } static final class WindowBoundaryMainSubscriber - extends NbpQueueDrainSubscriber> + extends NbpQueueDrainSubscriber> implements Disposable { - final NbpObservable open; - final Function> close; + final Observable open; + final Function> close; final int bufferSize; final SetCompositeResource resources; @@ -65,18 +66,18 @@ static final class WindowBoundaryMainSubscriber public void dispose() { } }; - final List> ws; + final List> ws; final AtomicLong windows = new AtomicLong(); - public WindowBoundaryMainSubscriber(NbpSubscriber> actual, - NbpObservable open, Function> close, int bufferSize) { + public WindowBoundaryMainSubscriber(Observer> actual, + Observable open, Function> close, int bufferSize) { super(actual, new MpscLinkedQueue()); this.open = open; this.close = close; this.bufferSize = bufferSize; this.resources = new SetCompositeResource(Disposables.consumeAndDispose()); - this.ws = new ArrayList>(); + this.ws = new ArrayList>(); windows.lazySet(1); } @@ -106,7 +107,7 @@ public void onSubscribe(Disposable s) { @Override public void onNext(T t) { if (fastEnter()) { - for (NbpUnicastSubject w : ws) { + for (UnicastSubject w : ws) { w.onNext(t); } if (leave(-1) == 0) { @@ -199,8 +200,8 @@ void disposeBoundary() { void drainLoop() { final Queue q = queue; - final NbpSubscriber> a = actual; - final List> ws = this.ws; + final Observer> a = actual; + final List> ws = this.ws; int missed = 1; for (;;) { @@ -215,11 +216,11 @@ void drainLoop() { disposeBoundary(); Throwable e = error; if (e != null) { - for (NbpUnicastSubject w : ws) { + for (UnicastSubject w : ws) { w.onError(e); } } else { - for (NbpUnicastSubject w : ws) { + for (UnicastSubject w : ws) { w.onComplete(); } } @@ -235,7 +236,7 @@ void drainLoop() { @SuppressWarnings("unchecked") WindowOperation wo = (WindowOperation) o; - NbpUnicastSubject w = wo.w; + UnicastSubject w = wo.w; if (w != null) { if (ws.remove(wo.w)) { wo.w.onComplete(); @@ -253,12 +254,12 @@ void drainLoop() { } - w = NbpUnicastSubject.create(bufferSize); + w = UnicastSubject.create(bufferSize); ws.add(w); a.onNext(w); - NbpObservable p; + Observable p; try { p = close.apply(wo.open); @@ -285,7 +286,7 @@ void drainLoop() { continue; } - for (NbpUnicastSubject w : ws) { + for (UnicastSubject w : ws) { w.onNext(NotificationLite.getValue(o)); } } @@ -298,7 +299,7 @@ void drainLoop() { } @Override - public void accept(NbpSubscriber> a, Object v) { + public void accept(Observer> a, Object v) { } void open(B b) { @@ -318,9 +319,9 @@ void close(OperatorWindowBoundaryCloseSubscriber w) { } static final class WindowOperation { - final NbpUnicastSubject w; + final UnicastSubject w; final B open; - public WindowOperation(NbpUnicastSubject w, B open) { + public WindowOperation(UnicastSubject w, B open) { this.w = w; this.open = open; } @@ -365,11 +366,11 @@ public void onComplete() { static final class OperatorWindowBoundaryCloseSubscriber extends NbpDisposableSubscriber { final WindowBoundaryMainSubscriber parent; - final NbpUnicastSubject w; + final UnicastSubject w; boolean done; - public OperatorWindowBoundaryCloseSubscriber(WindowBoundaryMainSubscriber parent, NbpUnicastSubject w) { + public OperatorWindowBoundaryCloseSubscriber(WindowBoundaryMainSubscriber parent, UnicastSubject w) { this.parent = parent; this.w = w; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowBoundarySupplier.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindowBoundarySupplier.java similarity index 85% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowBoundarySupplier.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindowBoundarySupplier.java index 4a6c6420f3..7d7bb709a5 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowBoundarySupplier.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindowBoundarySupplier.java @@ -11,42 +11,42 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.Queue; import java.util.concurrent.atomic.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Supplier; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.nbp.*; +import io.reactivex.internal.subscribers.observable.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.NotificationLite; +import io.reactivex.observers.SerializedObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subjects.nbp.NbpUnicastSubject; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; +import io.reactivex.subjects.UnicastSubject; -public final class NbpOperatorWindowBoundarySupplier implements NbpOperator, T> { - final Supplier> other; +public final class NbpOperatorWindowBoundarySupplier implements NbpOperator, T> { + final Supplier> other; final int bufferSize; - public NbpOperatorWindowBoundarySupplier(Supplier> other, int bufferSize) { + public NbpOperatorWindowBoundarySupplier(Supplier> other, int bufferSize) { this.other = other; this.bufferSize = bufferSize; } @Override - public NbpSubscriber apply(NbpSubscriber> t) { - return new WindowBoundaryMainSubscriber(new NbpSerializedSubscriber>(t), other, bufferSize); + public Observer apply(Observer> t) { + return new WindowBoundaryMainSubscriber(new SerializedObserver>(t), other, bufferSize); } static final class WindowBoundaryMainSubscriber - extends NbpQueueDrainSubscriber> + extends NbpQueueDrainSubscriber> implements Disposable { - final Supplier> other; + final Supplier> other; final int bufferSize; Disposable s; @@ -58,13 +58,13 @@ static final class WindowBoundaryMainSubscriber public void dispose() { } }; - NbpUnicastSubject window; + UnicastSubject window; static final Object NEXT = new Object(); final AtomicLong windows = new AtomicLong(); - public WindowBoundaryMainSubscriber(NbpSubscriber> actual, Supplier> other, + public WindowBoundaryMainSubscriber(Observer> actual, Supplier> other, int bufferSize) { super(actual, new MpscLinkedQueue()); this.other = other; @@ -79,14 +79,14 @@ public void onSubscribe(Disposable s) { } this.s = s; - NbpSubscriber> a = actual; + Observer> a = actual; a.onSubscribe(this); if (cancelled) { return; } - NbpObservable p; + Observable p; try { p = other.get(); @@ -102,7 +102,7 @@ public void onSubscribe(Disposable s) { return; } - NbpUnicastSubject w = NbpUnicastSubject.create(bufferSize); + UnicastSubject w = UnicastSubject.create(bufferSize); window = w; @@ -120,7 +120,7 @@ public void onSubscribe(Disposable s) { @Override public void onNext(T t) { if (fastEnter()) { - NbpUnicastSubject w = window; + UnicastSubject w = window; w.onNext(t); @@ -192,9 +192,9 @@ void disposeBoundary() { void drainLoop() { final Queue q = queue; - final NbpSubscriber> a = actual; + final Observer> a = actual; int missed = 1; - NbpUnicastSubject w = window; + UnicastSubject w = window; for (;;) { for (;;) { @@ -230,7 +230,7 @@ void drainLoop() { continue; } - NbpObservable p; + Observable p; try { p = other.get(); @@ -246,7 +246,7 @@ void drainLoop() { return; } - w = NbpUnicastSubject.create(bufferSize); + w = UnicastSubject.create(bufferSize); windows.getAndIncrement(); @@ -281,7 +281,7 @@ void next() { } @Override - public void accept(NbpSubscriber> a, Object v) { + public void accept(Observer> a, Object v) { // not used by this operator } } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowTimed.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindowTimed.java similarity index 87% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowTimed.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindowTimed.java index 101006106b..999b6682ef 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowTimed.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWindowTimed.java @@ -11,25 +11,27 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.nio.channels.CancelledKeyException; import java.util.*; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOperator; +import io.reactivex.Observer; +import io.reactivex.Scheduler; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; import io.reactivex.internal.queue.MpscLinkedQueue; -import io.reactivex.internal.subscribers.nbp.NbpQueueDrainSubscriber; +import io.reactivex.internal.subscribers.observable.NbpQueueDrainSubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.NotificationLite; -import io.reactivex.subjects.nbp.NbpUnicastSubject; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; +import io.reactivex.observers.SerializedObserver; +import io.reactivex.subjects.UnicastSubject; -public final class NbpOperatorWindowTimed implements NbpOperator, T> { +public final class NbpOperatorWindowTimed implements NbpOperator, T> { final long timespan; final long timeskip; final TimeUnit unit; @@ -50,8 +52,8 @@ public NbpOperatorWindowTimed(long timespan, long timeskip, TimeUnit unit, Sched } @Override - public NbpSubscriber apply(NbpSubscriber> t) { - NbpSerializedSubscriber> actual = new NbpSerializedSubscriber>(t); + public Observer apply(Observer> t) { + SerializedObserver> actual = new SerializedObserver>(t); if (timespan == timeskip) { if (maxSize == Long.MAX_VALUE) { @@ -69,8 +71,8 @@ public NbpSubscriber apply(NbpSubscriber> t) } static final class WindowExactUnboundedSubscriber - extends NbpQueueDrainSubscriber> - implements NbpSubscriber, Disposable, Runnable { + extends NbpQueueDrainSubscriber> + implements Observer, Disposable, Runnable { final long timespan; final TimeUnit unit; final Scheduler scheduler; @@ -80,7 +82,7 @@ static final class WindowExactUnboundedSubscriber boolean selfCancel; - NbpUnicastSubject window; + UnicastSubject window; final AtomicReference timer = new AtomicReference(); @@ -93,7 +95,7 @@ public void dispose() { } volatile boolean terminated; - public WindowExactUnboundedSubscriber(NbpSubscriber> actual, long timespan, TimeUnit unit, + public WindowExactUnboundedSubscriber(Observer> actual, long timespan, TimeUnit unit, Scheduler scheduler, int bufferSize) { super(actual, new MpscLinkedQueue()); this.timespan = timespan; @@ -109,9 +111,9 @@ public void onSubscribe(Disposable s) { } this.s = s; - window = NbpUnicastSubject.create(bufferSize); + window = UnicastSubject.create(bufferSize); - NbpSubscriber> a = actual; + Observer> a = actual; a.onSubscribe(this); a.onNext(window); @@ -205,8 +207,8 @@ public void run() { void drainLoop() { final Queue q = queue; - final NbpSubscriber> a = actual; - NbpUnicastSubject w = window; + final Observer> a = actual; + UnicastSubject w = window; int missed = 1; for (;;) { @@ -238,7 +240,7 @@ void drainLoop() { if (o == NEXT) { w.onComplete(); if (!term) { - w = NbpUnicastSubject.create(bufferSize); + w = UnicastSubject.create(bufferSize); window = w; a.onNext(w); @@ -259,13 +261,13 @@ void drainLoop() { } @Override - public void accept(NbpSubscriber> a, Object v) { + public void accept(Observer> a, Object v) { // not used in this operator } } static final class WindowExactBoundedSubscriber - extends NbpQueueDrainSubscriber> + extends NbpQueueDrainSubscriber> implements Disposable { final long timespan; final TimeUnit unit; @@ -282,7 +284,7 @@ static final class WindowExactBoundedSubscriber Disposable s; - NbpUnicastSubject window; + UnicastSubject window; Scheduler.Worker worker; @@ -296,7 +298,7 @@ public void dispose() { } }; public WindowExactBoundedSubscriber( - NbpSubscriber> actual, + Observer> actual, long timespan, TimeUnit unit, Scheduler scheduler, int bufferSize, long maxSize, boolean restartTimerOnMaxSize) { super(actual, new MpscLinkedQueue()); @@ -316,7 +318,7 @@ public void onSubscribe(Disposable s) { this.s = s; - NbpSubscriber> a = actual; + Observer> a = actual; a.onSubscribe(this); @@ -324,7 +326,7 @@ public void onSubscribe(Disposable s) { return; } - NbpUnicastSubject w = NbpUnicastSubject.create(bufferSize); + UnicastSubject w = UnicastSubject.create(bufferSize); window = w; a.onNext(w); @@ -352,7 +354,7 @@ public void onNext(T t) { } if (fastEnter()) { - NbpUnicastSubject w = window; + UnicastSubject w = window; w.onNext(t); long c = count + 1; @@ -363,7 +365,7 @@ public void onNext(T t) { w.onComplete(); - w = NbpUnicastSubject.create(bufferSize); + w = UnicastSubject.create(bufferSize); window = w; actual.onNext(w); if (restartTimerOnMaxSize) { @@ -433,14 +435,14 @@ void disposeTimer() { } @Override - public void accept(NbpSubscriber> a, Object v) { + public void accept(Observer> a, Object v) { // not needed in this operator } void drainLoop() { final Queue q = queue; - final NbpSubscriber> a = actual; - NbpUnicastSubject w = window; + final Observer> a = actual; + UnicastSubject w = window; int missed = 1; for (;;) { @@ -480,7 +482,7 @@ void drainLoop() { if (isHolder) { ConsumerIndexHolder consumerIndexHolder = (ConsumerIndexHolder) o; if (producerIndex == consumerIndexHolder.index) { - w = NbpUnicastSubject.create(bufferSize); + w = UnicastSubject.create(bufferSize); window = w; a.onNext(w); @@ -497,7 +499,7 @@ void drainLoop() { w.onComplete(); - w = NbpUnicastSubject.create(bufferSize); + w = UnicastSubject.create(bufferSize); window = w; actual.onNext(w); @@ -553,7 +555,7 @@ public void run() { } static final class WindowSkipSubscriber - extends NbpQueueDrainSubscriber> + extends NbpQueueDrainSubscriber> implements Disposable, Runnable { final long timespan; final long timeskip; @@ -561,13 +563,13 @@ static final class WindowSkipSubscriber final Scheduler.Worker worker; final int bufferSize; - final List> windows; + final List> windows; Disposable s; volatile boolean terminated; - public WindowSkipSubscriber(NbpSubscriber> actual, + public WindowSkipSubscriber(Observer> actual, long timespan, long timeskip, TimeUnit unit, Worker worker, int bufferSize) { super(actual, new MpscLinkedQueue()); @@ -576,7 +578,7 @@ public WindowSkipSubscriber(NbpSubscriber> actual, this.unit = unit; this.worker = worker; this.bufferSize = bufferSize; - this.windows = new LinkedList>(); + this.windows = new LinkedList>(); } @Override @@ -593,7 +595,7 @@ public void onSubscribe(Disposable s) { return; } - final NbpUnicastSubject w = NbpUnicastSubject.create(bufferSize); + final UnicastSubject w = UnicastSubject.create(bufferSize); windows.add(w); actual.onNext(w); @@ -610,7 +612,7 @@ public void run() { @Override public void onNext(T t) { if (fastEnter()) { - for (NbpUnicastSubject w : windows) { + for (UnicastSubject w : windows) { w.onNext(t); } if (leave(-1) == 0) { @@ -660,11 +662,11 @@ void disposeWorker() { } @Override - public void accept(NbpSubscriber> a, Object v) { + public void accept(Observer> a, Object v) { // not used by this operator } - void complete(NbpUnicastSubject w) { + void complete(UnicastSubject w) { queue.offer(new SubjectWork(w, false)); if (enter()) { drainLoop(); @@ -673,8 +675,8 @@ void complete(NbpUnicastSubject w) { void drainLoop() { final Queue q = queue; - final NbpSubscriber> a = actual; - final List> ws = windows; + final Observer> a = actual; + final List> ws = windows; int missed = 1; @@ -701,11 +703,11 @@ void drainLoop() { disposeWorker(); Throwable e = error; if (e != null) { - for (NbpUnicastSubject w : ws) { + for (UnicastSubject w : ws) { w.onError(e); } } else { - for (NbpUnicastSubject w : ws) { + for (UnicastSubject w : ws) { w.onError(e); } } @@ -726,7 +728,7 @@ void drainLoop() { continue; } - final NbpUnicastSubject w = NbpUnicastSubject.create(bufferSize); + final UnicastSubject w = UnicastSubject.create(bufferSize); ws.add(w); a.onNext(w); @@ -746,7 +748,7 @@ public void run() { } } - for (NbpUnicastSubject w : ws) { + for (UnicastSubject w : ws) { w.onNext(NotificationLite.getValue(v)); } } @@ -761,7 +763,7 @@ public void run() { @Override public void run() { - NbpUnicastSubject w = NbpUnicastSubject.create(bufferSize); + UnicastSubject w = UnicastSubject.create(bufferSize); SubjectWork sw = new SubjectWork(w, true); if (!cancelled) { @@ -773,9 +775,9 @@ public void run() { } static final class SubjectWork { - final NbpUnicastSubject w; + final UnicastSubject w; final boolean open; - public SubjectWork(NbpUnicastSubject w, boolean open) { + public SubjectWork(UnicastSubject w, boolean open) { this.w = w; this.open = open; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWithLatestFrom.java b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWithLatestFrom.java similarity index 86% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWithLatestFrom.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWithLatestFrom.java index 7a9b8bc25d..760f4a4f4d 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpOperatorWithLatestFrom.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpOperatorWithLatestFrom.java @@ -11,33 +11,33 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.BiFunction; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; +import io.reactivex.observers.SerializedObserver; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.nbp.NbpSerializedSubscriber; public final class NbpOperatorWithLatestFrom implements NbpOperator { final BiFunction combiner; - final NbpObservable other; - public NbpOperatorWithLatestFrom(BiFunction combiner, NbpObservable other) { + final Observable other; + public NbpOperatorWithLatestFrom(BiFunction combiner, Observable other) { this.combiner = combiner; this.other = other; } @Override - public NbpSubscriber apply(NbpSubscriber t) { - final NbpSerializedSubscriber serial = new NbpSerializedSubscriber(t); + public Observer apply(Observer t) { + final SerializedObserver serial = new SerializedObserver(t); final WithLatestFromSubscriber wlf = new WithLatestFromSubscriber(serial, combiner); - other.subscribe(new NbpSubscriber() { + other.subscribe(new Observer() { @Override public void onSubscribe(Disposable s) { wlf.setOther(s); @@ -62,11 +62,11 @@ public void onComplete() { return wlf; } - static final class WithLatestFromSubscriber extends AtomicReference implements NbpSubscriber, Disposable { + static final class WithLatestFromSubscriber extends AtomicReference implements Observer, Disposable { /** */ private static final long serialVersionUID = -312246233408980075L; - final NbpSubscriber actual; + final Observer actual; final BiFunction combiner; final AtomicReference s = new AtomicReference(); @@ -78,7 +78,7 @@ static final class WithLatestFromSubscriber extends AtomicReference public void dispose() { } }; - public WithLatestFromSubscriber(NbpSubscriber actual, BiFunction combiner) { + public WithLatestFromSubscriber(Observer actual, BiFunction combiner) { this.actual = actual; this.combiner = combiner; } diff --git a/src/main/java/io/reactivex/internal/operators/nbp/NbpSubscriberResourceWrapper.java b/src/main/java/io/reactivex/internal/operators/observable/NbpSubscriberResourceWrapper.java similarity index 89% rename from src/main/java/io/reactivex/internal/operators/nbp/NbpSubscriberResourceWrapper.java rename to src/main/java/io/reactivex/internal/operators/observable/NbpSubscriberResourceWrapper.java index 4599a552d3..d37b848c40 100644 --- a/src/main/java/io/reactivex/internal/operators/nbp/NbpSubscriberResourceWrapper.java +++ b/src/main/java/io/reactivex/internal/operators/observable/NbpSubscriberResourceWrapper.java @@ -11,20 +11,20 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.internal.subscriptions.SubscriptionHelper; -public final class NbpSubscriberResourceWrapper extends AtomicReference implements NbpSubscriber, Disposable { +public final class NbpSubscriberResourceWrapper extends AtomicReference implements Observer, Disposable { /** */ private static final long serialVersionUID = -8612022020200669122L; - final NbpSubscriber actual; + final Observer actual; final Consumer disposer; final AtomicReference subscription = new AtomicReference(); @@ -34,7 +34,7 @@ public final class NbpSubscriberResourceWrapper extends AtomicReference actual, Consumer disposer) { + public NbpSubscriberResourceWrapper(Observer actual, Consumer disposer) { this.actual = actual; this.disposer = disposer; } diff --git a/src/main/java/io/reactivex/internal/schedulers/TrampolineScheduler.java b/src/main/java/io/reactivex/internal/schedulers/TrampolineScheduler.java index 944c2618e7..98a08da1ce 100644 --- a/src/main/java/io/reactivex/internal/schedulers/TrampolineScheduler.java +++ b/src/main/java/io/reactivex/internal/schedulers/TrampolineScheduler.java @@ -17,7 +17,7 @@ package io.reactivex.internal.schedulers; import java.util.concurrent.*; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicInteger; import io.reactivex.Scheduler; import io.reactivex.disposables.Disposable; diff --git a/src/main/java/io/reactivex/internal/subscribers/BlockingSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/flowable/BlockingSubscriber.java similarity index 97% rename from src/main/java/io/reactivex/internal/subscribers/BlockingSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/flowable/BlockingSubscriber.java index 4c62f5ef3c..d9181d38e4 100644 --- a/src/main/java/io/reactivex/internal/subscribers/BlockingSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/flowable/BlockingSubscriber.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers; +package io.reactivex.internal.subscribers.flowable; import java.util.Queue; import java.util.concurrent.atomic.AtomicReference; diff --git a/src/main/java/io/reactivex/internal/subscribers/CancelledSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/flowable/CancelledSubscriber.java similarity index 96% rename from src/main/java/io/reactivex/internal/subscribers/CancelledSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/flowable/CancelledSubscriber.java index 63cd11ff60..b0dbc4a14d 100644 --- a/src/main/java/io/reactivex/internal/subscribers/CancelledSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/flowable/CancelledSubscriber.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers; +package io.reactivex.internal.subscribers.flowable; import org.reactivestreams.*; diff --git a/src/main/java/io/reactivex/internal/subscribers/ConditionalSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/flowable/ConditionalSubscriber.java similarity index 95% rename from src/main/java/io/reactivex/internal/subscribers/ConditionalSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/flowable/ConditionalSubscriber.java index dcfc37fd19..58b0bc3922 100644 --- a/src/main/java/io/reactivex/internal/subscribers/ConditionalSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/flowable/ConditionalSubscriber.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers; +package io.reactivex.internal.subscribers.flowable; import org.reactivestreams.Subscriber; diff --git a/src/main/java/io/reactivex/internal/subscribers/DisposableSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/flowable/DisposableSubscriber.java similarity index 95% rename from src/main/java/io/reactivex/internal/subscribers/DisposableSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/flowable/DisposableSubscriber.java index cb6adfcdc3..4a1a5d210f 100644 --- a/src/main/java/io/reactivex/internal/subscribers/DisposableSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/flowable/DisposableSubscriber.java @@ -11,9 +11,9 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers; +package io.reactivex.internal.subscribers.flowable; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; import org.reactivestreams.*; diff --git a/src/main/java/io/reactivex/internal/subscribers/EmptySubscriber.java b/src/main/java/io/reactivex/internal/subscribers/flowable/EmptySubscriber.java similarity index 96% rename from src/main/java/io/reactivex/internal/subscribers/EmptySubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/flowable/EmptySubscriber.java index b6a8b3b2c5..54a2d6f6d8 100644 --- a/src/main/java/io/reactivex/internal/subscribers/EmptySubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/flowable/EmptySubscriber.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers; +package io.reactivex.internal.subscribers.flowable; import org.reactivestreams.*; diff --git a/src/main/java/io/reactivex/internal/subscribers/FullArbiterSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/flowable/FullArbiterSubscriber.java similarity index 96% rename from src/main/java/io/reactivex/internal/subscribers/FullArbiterSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/flowable/FullArbiterSubscriber.java index 19d5613344..8af7c8cba7 100644 --- a/src/main/java/io/reactivex/internal/subscribers/FullArbiterSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/flowable/FullArbiterSubscriber.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers; +package io.reactivex.internal.subscribers.flowable; import org.reactivestreams.*; diff --git a/src/main/java/io/reactivex/internal/subscribers/LambdaSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/flowable/LambdaSubscriber.java similarity index 98% rename from src/main/java/io/reactivex/internal/subscribers/LambdaSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/flowable/LambdaSubscriber.java index c9372d4a5e..4773763db9 100644 --- a/src/main/java/io/reactivex/internal/subscribers/LambdaSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/flowable/LambdaSubscriber.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers; +package io.reactivex.internal.subscribers.flowable; import java.util.concurrent.atomic.AtomicReference; diff --git a/src/main/java/io/reactivex/internal/subscribers/NbpFullArbiterSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/flowable/NbpFullArbiterSubscriber.java similarity index 89% rename from src/main/java/io/reactivex/internal/subscribers/NbpFullArbiterSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/flowable/NbpFullArbiterSubscriber.java index 675f293ca2..931f6ed624 100644 --- a/src/main/java/io/reactivex/internal/subscribers/NbpFullArbiterSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/flowable/NbpFullArbiterSubscriber.java @@ -11,9 +11,9 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers; +package io.reactivex.internal.subscribers.flowable; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.internal.disposables.NbpFullArbiter; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -23,7 +23,7 @@ * * @param the value type */ -public final class NbpFullArbiterSubscriber implements NbpSubscriber { +public final class NbpFullArbiterSubscriber implements Observer { final NbpFullArbiter arbiter; Disposable s; diff --git a/src/main/java/io/reactivex/internal/subscribers/QueueDrainSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/flowable/QueueDrainSubscriber.java similarity index 99% rename from src/main/java/io/reactivex/internal/subscribers/QueueDrainSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/flowable/QueueDrainSubscriber.java index 75e61285bf..412b5bd3aa 100644 --- a/src/main/java/io/reactivex/internal/subscribers/QueueDrainSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/flowable/QueueDrainSubscriber.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers; +package io.reactivex.internal.subscribers.flowable; import java.util.Queue; import java.util.concurrent.atomic.*; diff --git a/src/main/java/io/reactivex/internal/subscribers/SubscriptionLambdaSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/flowable/SubscriptionLambdaSubscriber.java similarity index 98% rename from src/main/java/io/reactivex/internal/subscribers/SubscriptionLambdaSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/flowable/SubscriptionLambdaSubscriber.java index 33a0d744eb..a361e867b5 100644 --- a/src/main/java/io/reactivex/internal/subscribers/SubscriptionLambdaSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/flowable/SubscriptionLambdaSubscriber.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers; +package io.reactivex.internal.subscribers.flowable; import org.reactivestreams.*; diff --git a/src/main/java/io/reactivex/internal/subscribers/ToNotificationSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/flowable/ToNotificationSubscriber.java similarity index 97% rename from src/main/java/io/reactivex/internal/subscribers/ToNotificationSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/flowable/ToNotificationSubscriber.java index 706dddec59..15ecf979c7 100644 --- a/src/main/java/io/reactivex/internal/subscribers/ToNotificationSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/flowable/ToNotificationSubscriber.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers; +package io.reactivex.internal.subscribers.flowable; import org.reactivestreams.*; diff --git a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpBlockingSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/observable/NbpBlockingSubscriber.java similarity index 92% rename from src/main/java/io/reactivex/internal/subscribers/nbp/NbpBlockingSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/observable/NbpBlockingSubscriber.java index 8ebf82ed3f..bf2b5d22ba 100644 --- a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpBlockingSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/observable/NbpBlockingSubscriber.java @@ -11,17 +11,16 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers.nbp; +package io.reactivex.internal.subscribers.observable; import java.util.Queue; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.Notification; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.*; import io.reactivex.disposables.Disposable; import io.reactivex.internal.util.NotificationLite; -public final class NbpBlockingSubscriber extends AtomicReference implements NbpSubscriber, Disposable { +public final class NbpBlockingSubscriber extends AtomicReference implements Observer, Disposable { /** */ private static final long serialVersionUID = -4875965440900746268L; diff --git a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpCancelledSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/observable/NbpCancelledSubscriber.java similarity index 82% rename from src/main/java/io/reactivex/internal/subscribers/nbp/NbpCancelledSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/observable/NbpCancelledSubscriber.java index f1a4658468..85f68a3f54 100644 --- a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpCancelledSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/observable/NbpCancelledSubscriber.java @@ -11,9 +11,9 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers.nbp; +package io.reactivex.internal.subscribers.observable; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.plugins.RxJavaPlugins; @@ -21,12 +21,12 @@ * A subscriber that cancels the subscription sent to it * and ignores all events (onError is forwarded to RxJavaPlugins though). */ -public enum NbpCancelledSubscriber implements NbpSubscriber { +public enum NbpCancelledSubscriber implements Observer { INSTANCE; @SuppressWarnings("unchecked") - public static NbpSubscriber instance() { - return (NbpSubscriber)INSTANCE; + public static Observer instance() { + return (Observer)INSTANCE; } @Override diff --git a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpConditionalSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/observable/NbpConditionalSubscriber.java similarity index 86% rename from src/main/java/io/reactivex/internal/subscribers/nbp/NbpConditionalSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/observable/NbpConditionalSubscriber.java index 0bebcac1df..175acdc20e 100644 --- a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpConditionalSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/observable/NbpConditionalSubscriber.java @@ -11,9 +11,9 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers.nbp; +package io.reactivex.internal.subscribers.observable; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; /** * An Subscriber with an additional onNextIf(T) method that @@ -25,7 +25,7 @@ * * @param the value type */ -public interface NbpConditionalSubscriber extends NbpSubscriber { +public interface NbpConditionalSubscriber extends Observer { /** * Conditionally takes the value. * @param t the value to deliver diff --git a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpDisposableSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/observable/NbpDisposableSubscriber.java similarity index 90% rename from src/main/java/io/reactivex/internal/subscribers/nbp/NbpDisposableSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/observable/NbpDisposableSubscriber.java index 19978e24ee..bae3c6328f 100644 --- a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpDisposableSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/observable/NbpDisposableSubscriber.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers.nbp; +package io.reactivex.internal.subscribers.observable; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -24,7 +24,7 @@ * * @param */ -public abstract class NbpDisposableSubscriber implements NbpSubscriber, Disposable { +public abstract class NbpDisposableSubscriber implements Observer, Disposable { final AtomicReference s = new AtomicReference(); static final Disposable CANCELLED = new Disposable() { diff --git a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpEmptySubscriber.java b/src/main/java/io/reactivex/internal/subscribers/observable/NbpEmptySubscriber.java similarity index 90% rename from src/main/java/io/reactivex/internal/subscribers/nbp/NbpEmptySubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/observable/NbpEmptySubscriber.java index 20461ed4a3..b24f32d755 100644 --- a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpEmptySubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/observable/NbpEmptySubscriber.java @@ -11,16 +11,16 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers.nbp; +package io.reactivex.internal.subscribers.observable; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.plugins.RxJavaPlugins; /** * A subscriber that ignores all events (onError is forwarded to RxJavaPlugins though). */ -public enum NbpEmptySubscriber implements NbpSubscriber { +public enum NbpEmptySubscriber implements Observer { /** Empty instance that reports error to the plugins. */ INSTANCE(true), /** Empty instance that doesn't report to the plugins to avoid flooding the test output. */ diff --git a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpLambdaSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/observable/NbpLambdaSubscriber.java similarity index 94% rename from src/main/java/io/reactivex/internal/subscribers/nbp/NbpLambdaSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/observable/NbpLambdaSubscriber.java index dc20060b84..41b1c982a6 100644 --- a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpLambdaSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/observable/NbpLambdaSubscriber.java @@ -11,17 +11,17 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers.nbp; +package io.reactivex.internal.subscribers.observable; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; -public final class NbpLambdaSubscriber extends AtomicReference implements NbpSubscriber, Disposable { +public final class NbpLambdaSubscriber extends AtomicReference implements Observer, Disposable { /** */ private static final long serialVersionUID = -7251123623727029452L; final Consumer onNext; diff --git a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpQueueDrainSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/observable/NbpQueueDrainSubscriber.java similarity index 90% rename from src/main/java/io/reactivex/internal/subscribers/nbp/NbpQueueDrainSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/observable/NbpQueueDrainSubscriber.java index 6942b9c72c..b027d1af78 100644 --- a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpQueueDrainSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/observable/NbpQueueDrainSubscriber.java @@ -11,12 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers.nbp; +package io.reactivex.internal.subscribers.observable; import java.util.Queue; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.internal.util.*; @@ -28,8 +28,8 @@ * @param the value type in the queue * @param the value type the child subscriber accepts */ -public abstract class NbpQueueDrainSubscriber extends QueueDrainSubscriberPad2 implements NbpSubscriber, NbpQueueDrain { - protected final NbpSubscriber actual; +public abstract class NbpQueueDrainSubscriber extends QueueDrainSubscriberPad2 implements Observer, NbpQueueDrain { + protected final Observer actual; protected final Queue queue; protected volatile boolean cancelled; @@ -37,7 +37,7 @@ public abstract class NbpQueueDrainSubscriber extends QueueDrainSubscri protected volatile boolean done; protected Throwable error; - public NbpQueueDrainSubscriber(NbpSubscriber actual, Queue queue) { + public NbpQueueDrainSubscriber(Observer actual, Queue queue) { this.actual = actual; this.queue = queue; } @@ -62,7 +62,7 @@ public final boolean fastEnter() { } protected final void fastpathEmit(U value, boolean delayError, Disposable dispose) { - final NbpSubscriber s = actual; + final Observer s = actual; final Queue q = queue; if (wip.get() == 0 && wip.compareAndSet(0, 1)) { @@ -85,7 +85,7 @@ protected final void fastpathEmit(U value, boolean delayError, Disposable dispos * @param delayError */ protected final void fastpathOrderedEmit(U value, boolean delayError, Disposable disposable) { - final NbpSubscriber s = actual; + final Observer s = actual; final Queue q = queue; if (wip.get() == 0 && wip.compareAndSet(0, 1)) { diff --git a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpSubscriptionLambdaSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/observable/NbpSubscriptionLambdaSubscriber.java similarity index 89% rename from src/main/java/io/reactivex/internal/subscribers/nbp/NbpSubscriptionLambdaSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/observable/NbpSubscriptionLambdaSubscriber.java index 1add5bb72a..d86291531e 100644 --- a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpSubscriptionLambdaSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/observable/NbpSubscriptionLambdaSubscriber.java @@ -11,23 +11,23 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers.nbp; +package io.reactivex.internal.subscribers.observable; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; -public final class NbpSubscriptionLambdaSubscriber implements NbpSubscriber, Disposable { - final NbpSubscriber actual; +public final class NbpSubscriptionLambdaSubscriber implements Observer, Disposable { + final Observer actual; final Consumer onSubscribe; final Runnable onCancel; Disposable s; - public NbpSubscriptionLambdaSubscriber(NbpSubscriber actual, + public NbpSubscriptionLambdaSubscriber(Observer actual, Consumer onSubscribe, Runnable onCancel) { this.actual = actual; diff --git a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpToNotificationSubscriber.java b/src/main/java/io/reactivex/internal/subscribers/observable/NbpToNotificationSubscriber.java similarity index 90% rename from src/main/java/io/reactivex/internal/subscribers/nbp/NbpToNotificationSubscriber.java rename to src/main/java/io/reactivex/internal/subscribers/observable/NbpToNotificationSubscriber.java index 0adef75192..9b919c18f2 100644 --- a/src/main/java/io/reactivex/internal/subscribers/nbp/NbpToNotificationSubscriber.java +++ b/src/main/java/io/reactivex/internal/subscribers/observable/NbpToNotificationSubscriber.java @@ -11,15 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.subscribers.nbp; +package io.reactivex.internal.subscribers.observable; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.internal.subscriptions.SubscriptionHelper; -public final class NbpToNotificationSubscriber implements NbpSubscriber { +public final class NbpToNotificationSubscriber implements Observer { final Consumer>> consumer; Disposable s; diff --git a/src/main/java/io/reactivex/internal/subscriptions/SubscriptionHelper.java b/src/main/java/io/reactivex/internal/subscriptions/SubscriptionHelper.java index b905e08a86..4748452636 100644 --- a/src/main/java/io/reactivex/internal/subscriptions/SubscriptionHelper.java +++ b/src/main/java/io/reactivex/internal/subscriptions/SubscriptionHelper.java @@ -13,7 +13,7 @@ package io.reactivex.internal.subscriptions; -import org.reactivestreams.*; +import org.reactivestreams.Subscription; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; diff --git a/src/main/java/io/reactivex/internal/util/BackpressureHelper.java b/src/main/java/io/reactivex/internal/util/BackpressureHelper.java index 7e72f0c511..f0870283ad 100644 --- a/src/main/java/io/reactivex/internal/util/BackpressureHelper.java +++ b/src/main/java/io/reactivex/internal/util/BackpressureHelper.java @@ -12,7 +12,7 @@ */ package io.reactivex.internal.util; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicLong; /** * Utility class to help with backpressure-related operations such as request aggregation. diff --git a/src/main/java/io/reactivex/internal/util/NbpQueueDrain.java b/src/main/java/io/reactivex/internal/util/NbpQueueDrain.java index c7ed796e7e..27e8762914 100644 --- a/src/main/java/io/reactivex/internal/util/NbpQueueDrain.java +++ b/src/main/java/io/reactivex/internal/util/NbpQueueDrain.java @@ -13,7 +13,7 @@ package io.reactivex.internal.util; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; public interface NbpQueueDrain { @@ -37,5 +37,5 @@ public interface NbpQueueDrain { * @param a the subscriber to deliver values to * @param v the value to deliver */ - void accept(NbpSubscriber a, T v); + void accept(Observer a, T v); } diff --git a/src/main/java/io/reactivex/internal/util/NotificationLite.java b/src/main/java/io/reactivex/internal/util/NotificationLite.java index d5752859cb..fd9f6c2715 100644 --- a/src/main/java/io/reactivex/internal/util/NotificationLite.java +++ b/src/main/java/io/reactivex/internal/util/NotificationLite.java @@ -16,7 +16,7 @@ import org.reactivestreams.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; /** @@ -230,7 +230,7 @@ public static boolean accept(Object o, Subscriber s) { * @return true if the notification was a terminal event (i.e., complete or error) */ @SuppressWarnings("unchecked") - public static boolean accept(Object o, NbpSubscriber s) { + public static boolean accept(Object o, Observer s) { if (o == Complete.INSTANCE) { s.onComplete(); return true; @@ -275,10 +275,10 @@ public static boolean acceptFull(Object o, Subscriber s) { * @param o the notification object * @param s the subscriber to call methods on * @return true if the notification was a terminal event (i.e., complete or error) - * @see #accept(Object, NbpSubscriber) + * @see #accept(Object, Observer) */ @SuppressWarnings("unchecked") - public static boolean acceptFull(Object o, NbpSubscriber s) { + public static boolean acceptFull(Object o, Observer s) { if (o == Complete.INSTANCE) { s.onComplete(); return true; diff --git a/src/main/java/io/reactivex/internal/util/QueueDrainHelper.java b/src/main/java/io/reactivex/internal/util/QueueDrainHelper.java index ae9c53f2e4..09029fd734 100644 --- a/src/main/java/io/reactivex/internal/util/QueueDrainHelper.java +++ b/src/main/java/io/reactivex/internal/util/QueueDrainHelper.java @@ -13,11 +13,11 @@ package io.reactivex.internal.util; import java.util.Queue; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicInteger; import org.reactivestreams.Subscriber; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.BooleanSupplier; @@ -289,7 +289,7 @@ public static boolean checkTerminated(boolean d, boolean empty, return false; } - public static void drainLoop(Queue q, NbpSubscriber a, boolean delayError, Disposable dispose, NbpQueueDrain qd) { + public static void drainLoop(Queue q, Observer a, boolean delayError, Disposable dispose, NbpQueueDrain qd) { int missed = 1; @@ -323,7 +323,7 @@ public static void drainLoop(Queue q, NbpSubscriber a, bool } public static boolean checkTerminated(boolean d, boolean empty, - NbpSubscriber s, boolean delayError, Queue q, Disposable disposable, NbpQueueDrain qd) { + Observer s, boolean delayError, Queue q, Disposable disposable, NbpQueueDrain qd) { if (qd.cancelled()) { q.clear(); disposable.dispose(); diff --git a/src/main/java/io/reactivex/internal/util/TerminalAtomicsHelper.java b/src/main/java/io/reactivex/internal/util/TerminalAtomicsHelper.java index 47db4368c0..b4a89b835e 100644 --- a/src/main/java/io/reactivex/internal/util/TerminalAtomicsHelper.java +++ b/src/main/java/io/reactivex/internal/util/TerminalAtomicsHelper.java @@ -12,7 +12,7 @@ */ package io.reactivex.internal.util; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; import io.reactivex.functions.*; diff --git a/src/main/java/io/reactivex/observables/BlockingObservable.java b/src/main/java/io/reactivex/observables/BlockingObservable.java index addae0669f..873a8a1533 100644 --- a/src/main/java/io/reactivex/observables/BlockingObservable.java +++ b/src/main/java/io/reactivex/observables/BlockingObservable.java @@ -18,30 +18,26 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; -import org.reactivestreams.*; - -import io.reactivex.Optional; import io.reactivex.Observable; import io.reactivex.Observer; +import io.reactivex.Optional; import io.reactivex.disposables.*; import io.reactivex.functions.Consumer; import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.operators.*; -import io.reactivex.internal.subscribers.*; +import io.reactivex.internal.operators.observable.*; +import io.reactivex.internal.subscribers.flowable.BlockingSubscriber; +import io.reactivex.internal.subscribers.observable.*; import io.reactivex.internal.util.*; +import io.reactivex.observers.DefaultObserver; import io.reactivex.plugins.RxJavaPlugins; -public final class BlockingObservable implements Publisher, Iterable { - final Publisher o; - protected BlockingObservable(Publisher source) { +public final class BlockingObservable implements Iterable { + final Observable o; + protected BlockingObservable(Observable source) { this.o = source; } - @SuppressWarnings("unchecked") - public static BlockingObservable from(Publisher source) { - if (source instanceof BlockingObservable) { - return (BlockingObservable)source; - } + public static BlockingObservable from(Observable source) { return new BlockingObservable(source); } @@ -57,19 +53,19 @@ public void forEach(Consumer action) { action.accept(it.next()); } catch (Throwable e) { it.dispose(); - throw Exceptions.propagate(e); + Exceptions.propagate(e); } } } - static final BlockingIterator iterate(Publisher p) { + static final BlockingIterator iterate(Observable p) { final BlockingQueue queue = new LinkedBlockingQueue(); - LambdaSubscriber ls = new LambdaSubscriber( + NbpLambdaSubscriber ls = new NbpLambdaSubscriber( new Consumer() { @Override public void accept(T v) { - queue.offer(NotificationLite.next(v)); + queue.offer(NotificationLite.next(v)); } }, new Consumer() { @@ -84,12 +80,7 @@ public void run() { queue.offer(NotificationLite.complete()); } }, - new Consumer() { - @Override - public void accept(Subscription s) { - s.request(Long.MAX_VALUE); - } - } + Functions.emptyConsumer() ); p.subscribe(ls); @@ -170,24 +161,23 @@ public Optional firstOption() { return firstOption(o); } - static Optional firstOption(Publisher o) { + static Optional firstOption(Observable o) { final AtomicReference value = new AtomicReference(); final AtomicReference error = new AtomicReference(); final CountDownLatch cdl = new CountDownLatch(1); final MultipleAssignmentDisposable mad = new MultipleAssignmentDisposable(); - o.subscribe(new Subscriber() { - Subscription s; + o.subscribe(new Observer() { + Disposable s; @Override - public void onSubscribe(Subscription s) { + public void onSubscribe(Disposable s) { this.s = s; - mad.set(Disposables.from(s)); - s.request(Long.MAX_VALUE); + mad.set(s); } @Override public void onNext(T t) { - s.cancel(); + s.dispose(); value.lazySet(t); cdl.countDown(); } @@ -239,17 +229,16 @@ public Optional lastOption() { return lastOption(o); } - static Optional lastOption(Publisher o) { + static Optional lastOption(Observable o) { final AtomicReference value = new AtomicReference(); final AtomicReference error = new AtomicReference(); final CountDownLatch cdl = new CountDownLatch(1); final MultipleAssignmentDisposable mad = new MultipleAssignmentDisposable(); - o.subscribe(new Subscriber() { + o.subscribe(new Observer() { @Override - public void onSubscribe(Subscription s) { - mad.set(Disposables.from(s)); - s.request(Long.MAX_VALUE); + public void onSubscribe(Disposable s) { + mad.set(s); } @Override @@ -301,7 +290,7 @@ public T last(T defaultValue) { } public T single() { - Optional o = firstOption(Observable.fromPublisher(this.o).single()); + Optional o = firstOption(this.o.single()); if (o.isPresent()) { return o.get(); } @@ -309,7 +298,8 @@ public T single() { } public T single(T defaultValue) { - Optional o = firstOption(Observable.fromPublisher(this.o).single(defaultValue)); + @SuppressWarnings("unchecked") + Optional o = firstOption(((Observable)this.o).single(defaultValue)); if (o.isPresent()) { return o.get(); } @@ -317,15 +307,15 @@ public T single(T defaultValue) { } public Iterable mostRecent(T initialValue) { - return BlockingOperatorMostRecent.mostRecent(o, initialValue); + return NbpBlockingOperatorMostRecent.mostRecent(o, initialValue); } public Iterable next() { - return BlockingOperatorNext.next(o); + return NbpBlockingOperatorNext.next(o); } public Iterable latest() { - return BlockingOperatorLatest.latest(o); + return NbpBlockingOperatorLatest.latest(o); } public Future toFuture() { @@ -334,12 +324,11 @@ public Future toFuture() { final AtomicReference error = new AtomicReference(); final MultipleAssignmentDisposable mad = new MultipleAssignmentDisposable(); - o.subscribe(new Subscriber() { + o.subscribe(new Observer() { @Override - public void onSubscribe(Subscription d) { - mad.set(Disposables.from(d)); - d.request(Long.MAX_VALUE); + public void onSubscribe(Disposable d) { + mad.set(d); } @Override @@ -436,24 +425,20 @@ private void awaitForComplete(CountDownLatch latch, Disposable subscription) { public void run() { final CountDownLatch cdl = new CountDownLatch(1); final Throwable[] error = { null }; - LambdaSubscriber ls = new LambdaSubscriber(Functions.emptyConsumer(), - new Consumer() { - @Override - public void accept(Throwable e) { - error[0] = e; - cdl.countDown(); - } - }, new Runnable() { - @Override - public void run() { - cdl.countDown(); - } - }, new Consumer() { - @Override - public void accept(Subscription s) { - s.request(Long.MAX_VALUE); - } - }); + NbpLambdaSubscriber ls = new NbpLambdaSubscriber( + Functions.emptyConsumer(), + new Consumer() { + @Override + public void accept(Throwable e) { + error[0] = e; + cdl.countDown(); + } + }, new Runnable() { + @Override + public void run() { + cdl.countDown(); + } + }, Functions.emptyConsumer()); o.subscribe(ls); @@ -474,11 +459,10 @@ public void accept(Subscription s) { * The unsubscription and backpressure is composed through. * @param subscriber the subscriber to forward events and calls to in the current thread */ - @Override - public void subscribe(Subscriber subscriber) { + public void subscribe(Observer subscriber) { final BlockingQueue queue = new LinkedBlockingQueue(); - BlockingSubscriber bs = new BlockingSubscriber(queue); + NbpBlockingSubscriber bs = new NbpBlockingSubscriber(queue); o.subscribe(bs); @@ -500,7 +484,7 @@ public void subscribe(Subscriber subscriber) { if (o == BlockingSubscriber.TERMINATED) { break; } - if (NotificationLite.acceptFull(o, subscriber)) { + if (NotificationLite.accept(o, subscriber)) { break; } } @@ -508,7 +492,7 @@ public void subscribe(Subscriber subscriber) { Thread.currentThread().interrupt(); subscriber.onError(e); } finally { - bs.cancel(); + bs.dispose(); } } @@ -544,7 +528,7 @@ public void subscribe(final Consumer onNext, final Consumer onNext, final Consumer onError, final Runnable onComplete) { - subscribe(new Observer() { + subscribe(new DefaultObserver() { @Override public void onNext(T t) { onNext.accept(t); diff --git a/src/main/java/io/reactivex/observables/ConnectableObservable.java b/src/main/java/io/reactivex/observables/ConnectableObservable.java index d7e14a222c..aa0527d253 100644 --- a/src/main/java/io/reactivex/observables/ConnectableObservable.java +++ b/src/main/java/io/reactivex/observables/ConnectableObservable.java @@ -13,18 +13,18 @@ package io.reactivex.observables; -import org.reactivestreams.*; +import org.reactivestreams.Subscriber; -import io.reactivex.Observable; +import io.reactivex.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.operators.*; +import io.reactivex.internal.operators.observable.*; /** - * A {@code ConnectableObservable} resembles an ordinary {@link Observable}, except that it does not begin + * A {@code ConnectableObservable} resembles an ordinary {@link Flowable}, except that it does not begin * emitting items when it is subscribed to, but only when its {@link #connect} method is called. In this way you - * can wait for all intended {@link Subscriber}s to {@link Observable#subscribe} to the {@code Observable} + * can wait for all intended {@link Subscriber}s to {@link Flowable#subscribe} to the {@code Observable} * before the {@code Observable} begins emitting items. *

* @@ -36,13 +36,13 @@ */ public abstract class ConnectableObservable extends Observable { - protected ConnectableObservable(Publisher onSubscribe) { + protected ConnectableObservable(NbpOnSubscribe onSubscribe) { super(onSubscribe); } /** * Instructs the {@code ConnectableObservable} to begin emitting the items from its underlying - * {@link Observable} to its {@link Subscriber}s. + * {@link Flowable} to its {@link Subscriber}s. * * @param connection * the action that receives the connection subscription before the subscription to source happens @@ -53,9 +53,9 @@ protected ConnectableObservable(Publisher onSubscribe) { /** * Instructs the {@code ConnectableObservable} to begin emitting the items from its underlying - * {@link Observable} to its {@link Subscriber}s. + * {@link Flowable} to its {@link Subscriber}s. *

- * To disconnect from a synchronous source, use the {@link #connect(io.reactivex.functions.Consumer)} method. + * To disconnect from a synchronous source, use the {@link #connect(Consumer)} method. * * @return the subscription representing the connection * @see ReactiveX documentation: Connect @@ -75,11 +75,11 @@ public void accept(Disposable d) { * Returns an {@code Observable} that stays connected to this {@code ConnectableObservable} as long as there * is at least one subscription to this {@code ConnectableObservable}. * - * @return a {@link Observable} + * @return a {@link Flowable} * @see ReactiveX documentation: RefCount */ public Observable refCount() { - return create(new PublisherRefCount(this)); + return create(new NbpOnSubscribeRefCount(this)); } /** @@ -125,6 +125,6 @@ public Observable autoConnect(int numberOfSubscribers, Consumer(this, numberOfSubscribers, connection)); + return create(new NbpOnSubscribeAutoConnect(this, numberOfSubscribers, connection)); } } diff --git a/src/main/java/io/reactivex/observables/GroupedObservable.java b/src/main/java/io/reactivex/observables/GroupedObservable.java index 1404bfcba8..77b15d40e2 100644 --- a/src/main/java/io/reactivex/observables/GroupedObservable.java +++ b/src/main/java/io/reactivex/observables/GroupedObservable.java @@ -12,13 +12,11 @@ */ package io.reactivex.observables; -import org.reactivestreams.Publisher; - import io.reactivex.Observable; public class GroupedObservable extends Observable { final K key; - protected GroupedObservable(Publisher onSubscribe, K key) { + protected GroupedObservable(NbpOnSubscribe onSubscribe, K key) { super(onSubscribe); this.key = key; } diff --git a/src/main/java/io/reactivex/subscribers/nbp/NbpAsyncObserver.java b/src/main/java/io/reactivex/observers/AsyncObserver.java similarity index 94% rename from src/main/java/io/reactivex/subscribers/nbp/NbpAsyncObserver.java rename to src/main/java/io/reactivex/observers/AsyncObserver.java index 3e72165d77..3c18aa0261 100644 --- a/src/main/java/io/reactivex/subscribers/nbp/NbpAsyncObserver.java +++ b/src/main/java/io/reactivex/observers/AsyncObserver.java @@ -11,11 +11,11 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subscribers.nbp; +package io.reactivex.observers; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.internal.disposables.ListCompositeResource; import io.reactivex.internal.functions.Objects; @@ -32,7 +32,7 @@ * * @param the value type */ -public abstract class NbpAsyncObserver implements NbpSubscriber, Disposable { +public abstract class AsyncObserver implements Observer, Disposable { /** The active subscription. */ private final AtomicReference s = new AtomicReference(); @@ -48,7 +48,7 @@ public void dispose() { } /** * Constructs an AsyncObserver with resource support. */ - public NbpAsyncObserver() { + public AsyncObserver() { this(true); } @@ -56,7 +56,7 @@ public NbpAsyncObserver() { * Constructs an AsyncObserver and allows specifying if it should support resources or not. * @param withResources true if resource support should be on. */ - public NbpAsyncObserver(boolean withResources) { + public AsyncObserver(boolean withResources) { this.resources = withResources ? new ListCompositeResource(Disposables.consumeAndDispose()) : null; } diff --git a/src/main/java/io/reactivex/NbpObserver.java b/src/main/java/io/reactivex/observers/DefaultObserver.java similarity index 89% rename from src/main/java/io/reactivex/NbpObserver.java rename to src/main/java/io/reactivex/observers/DefaultObserver.java index 1c51f90007..70328b0cf9 100644 --- a/src/main/java/io/reactivex/NbpObserver.java +++ b/src/main/java/io/reactivex/observers/DefaultObserver.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.observers; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.SubscriptionHelper; -public abstract class NbpObserver implements NbpSubscriber { +public abstract class DefaultObserver implements Observer { private Disposable s; @Override public final void onSubscribe(Disposable s) { diff --git a/src/main/java/io/reactivex/subscribers/Observers.java b/src/main/java/io/reactivex/observers/Observers.java similarity index 53% rename from src/main/java/io/reactivex/subscribers/Observers.java rename to src/main/java/io/reactivex/observers/Observers.java index 00d0629b06..defef4b83c 100644 --- a/src/main/java/io/reactivex/subscribers/Observers.java +++ b/src/main/java/io/reactivex/observers/Observers.java @@ -11,11 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subscribers; +package io.reactivex.observers; -import io.reactivex.Observer; +import io.reactivex.*; +import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.internal.functions.*; +import io.reactivex.internal.subscribers.observable.*; +import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; /** @@ -27,25 +30,6 @@ private Observers() { throw new IllegalStateException("No instances!"); } - public static Observer empty() { - return new Observer() { - @Override - public void onNext(T t) { - - } - - @Override - public void onError(Throwable t) { - RxJavaPlugins.onError(t); - } - - @Override - public void onComplete() { - - } - }; - } - public static AsyncObserver emptyAsync() { return new AsyncObserver() { @Override @@ -65,21 +49,21 @@ public void onComplete() { }; } - public static Observer create(Consumer onNext) { + public static DefaultObserver create(Consumer onNext) { return create(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), Functions.emptyRunnable()); } - public static Observer create(Consumer onNext, + public static DefaultObserver create(Consumer onNext, Consumer onError) { return create(onNext, onError, Functions.emptyRunnable(), Functions.emptyRunnable()); } - public static Observer create(Consumer onNext, + public static DefaultObserver create(Consumer onNext, Consumer onError, Runnable onComplete) { return create(onNext, onError, onComplete, Functions.emptyRunnable()); } - public static Observer create( + public static DefaultObserver create( final Consumer onNext, final Consumer onError, final Runnable onComplete, @@ -87,8 +71,8 @@ public static Observer create( Objects.requireNonNull(onNext, "onNext is null"); Objects.requireNonNull(onError, "onError is null"); Objects.requireNonNull(onComplete, "onComplete is null"); - Objects.requireNonNull(onStart, "onStart is null"); - return new Observer() { + Objects.requireNonNull(onStart, "onStart ins null"); + return new DefaultObserver() { boolean done; @Override protected void onStart() { @@ -101,8 +85,8 @@ protected void onStart() { try { onError.accept(e); } catch (Throwable ex) { - RxJavaPlugins.onError(e); RxJavaPlugins.onError(ex); + RxJavaPlugins.onError(e); } } } @@ -119,8 +103,8 @@ public void onNext(T t) { try { onError.accept(e); } catch (Throwable ex) { - RxJavaPlugins.onError(e); RxJavaPlugins.onError(ex); + RxJavaPlugins.onError(e); } } } @@ -182,7 +166,6 @@ public static AsyncObserver createAsync( boolean done; @Override protected void onStart() { - super.onStart(); try { onStart.run(); } catch (Throwable e) { @@ -244,4 +227,213 @@ public void onComplete() { } }; } + + @SuppressWarnings("unchecked") + public static Observer empty() { + return (Observer)NbpEmptySubscriber.INSTANCE; + } + + @SuppressWarnings("unchecked") + public static Observer cancelled() { + return (Observer)NbpCancelledSubscriber.INSTANCE; + } + + public static NbpDisposableSubscriber emptyDisposable() { + return new NbpDisposableSubscriber() { + @Override + public void onNext(T t) { + + } + + @Override + public void onError(Throwable t) { + + } + + @Override + public void onComplete() { + + } + }; + } + + public static NbpDisposableSubscriber createDisposable( + Consumer onNext + ) { + return createDisposable(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), Functions.emptyRunnable()); + } + + public static NbpDisposableSubscriber createDisposable( + Consumer onNext, + Consumer onError + ) { + return createDisposable(onNext, onError, Functions.emptyRunnable(), Functions.emptyRunnable()); + } + + public static NbpDisposableSubscriber createDisposable( + Consumer onNext, + Consumer onError, + Runnable onComplete + ) { + return createDisposable(onNext, onError, onComplete, Functions.emptyRunnable()); + } + + public static NbpDisposableSubscriber createDisposable( + final Consumer onNext, + final Consumer onError, + final Runnable onComplete, + final Runnable onStart + ) { + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(onStart, "onStart is null"); + return new NbpDisposableSubscriber() { + boolean done; + @Override + protected void onStart() { + super.onStart(); + try { + onStart.run(); + } catch (Throwable e) { + done = true; + dispose(); + try { + onError.accept(e); + } catch (Throwable ex) { + RxJavaPlugins.onError(ex); + RxJavaPlugins.onError(e); + } + } + } + @Override + public void onNext(T t) { + if (done) { + return; + } + try { + onNext.accept(t); + } catch (Throwable e) { + done = true; + dispose(); + try { + onError.accept(e); + } catch (Throwable ex) { + RxJavaPlugins.onError(ex); + RxJavaPlugins.onError(e); + } + } + } + + @Override + public void onError(Throwable t) { + if (done) { + RxJavaPlugins.onError(t); + return; + } + done = true; + try { + onError.accept(t); + } catch (Throwable ex) { + RxJavaPlugins.onError(ex); + RxJavaPlugins.onError(t); + } + } + + @Override + public void onComplete() { + if (done) { + return; + } + done = true; + try { + onComplete.run(); + } catch (Throwable e) { + RxJavaPlugins.onError(e); + } + } + }; + } + + public static Observer create( + final Consumer onNext, + final Consumer onError, + final Runnable onComplete, + final Consumer onStart + ) { + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(onStart, "onStart is null"); + return new Observer() { + boolean done; + + Disposable s; + @Override + public void onSubscribe(Disposable s) { + if (SubscriptionHelper.validateDisposable(this.s, s)) { + return; + } + this.s = s; + try { + onStart.accept(s); + } catch (Throwable e) { + done = true; + s.dispose(); + try { + onError.accept(e); + } catch (Throwable ex) { + RxJavaPlugins.onError(ex); + RxJavaPlugins.onError(e); + } + } + } + @Override + public void onNext(T t) { + if (done) { + return; + } + try { + onNext.accept(t); + } catch (Throwable e) { + done = true; + s.dispose(); + try { + onError.accept(e); + } catch (Throwable ex) { + RxJavaPlugins.onError(ex); + RxJavaPlugins.onError(e); + } + } + } + + @Override + public void onError(Throwable t) { + if (done) { + RxJavaPlugins.onError(t); + return; + } + done = true; + try { + onError.accept(t); + } catch (Throwable ex) { + RxJavaPlugins.onError(ex); + RxJavaPlugins.onError(t); + } + } + + @Override + public void onComplete() { + if (done) { + return; + } + done = true; + try { + onComplete.run(); + } catch (Throwable e) { + RxJavaPlugins.onError(e); + } + } + }; + } } diff --git a/src/main/java/io/reactivex/subscribers/nbp/NbpSafeSubscriber.java b/src/main/java/io/reactivex/observers/SafeObserver.java similarity index 93% rename from src/main/java/io/reactivex/subscribers/nbp/NbpSafeSubscriber.java rename to src/main/java/io/reactivex/observers/SafeObserver.java index 04cee6f371..b53304e9f6 100644 --- a/src/main/java/io/reactivex/subscribers/nbp/NbpSafeSubscriber.java +++ b/src/main/java/io/reactivex/observers/SafeObserver.java @@ -10,9 +10,9 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subscribers.nbp; +package io.reactivex.observers; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.CompositeException; import io.reactivex.internal.disposables.EmptyDisposable; @@ -24,15 +24,15 @@ * * @param the value type */ -public final class NbpSafeSubscriber implements NbpSubscriber { +public final class SafeObserver implements Observer { /** The actual Subscriber. */ - final NbpSubscriber actual; + final Observer actual; /** The subscription. */ Disposable subscription; /** Indicates a terminal state. */ boolean done; - public NbpSafeSubscriber(NbpSubscriber actual) { + public SafeObserver(Observer actual) { this.actual = actual; } @@ -175,7 +175,7 @@ public void onComplete() { } } - /* test */ NbpSubscriber actual() { + /* test */ Observer actual() { return actual; } } diff --git a/src/main/java/io/reactivex/subscribers/nbp/NbpSerializedSubscriber.java b/src/main/java/io/reactivex/observers/SerializedObserver.java similarity index 93% rename from src/main/java/io/reactivex/subscribers/nbp/NbpSerializedSubscriber.java rename to src/main/java/io/reactivex/observers/SerializedObserver.java index 31766924e2..642a788812 100644 --- a/src/main/java/io/reactivex/subscribers/nbp/NbpSerializedSubscriber.java +++ b/src/main/java/io/reactivex/observers/SerializedObserver.java @@ -10,9 +10,9 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subscribers.nbp; +package io.reactivex.observers; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Predicate; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -29,8 +29,8 @@ * * @param the value type */ -public final class NbpSerializedSubscriber implements NbpSubscriber { - final NbpSubscriber actual; +public final class SerializedObserver implements Observer { + final Observer actual; final boolean delayError; static final int QUEUE_LINK_SIZE = 4; @@ -42,11 +42,11 @@ public final class NbpSerializedSubscriber implements NbpSubscriber { volatile boolean done; - public NbpSerializedSubscriber(NbpSubscriber actual) { + public SerializedObserver(Observer actual) { this(actual, false); } - public NbpSerializedSubscriber(NbpSubscriber actual, boolean delayError) { + public SerializedObserver(Observer actual, boolean delayError) { this.actual = actual; this.delayError = delayError; } diff --git a/src/main/java/io/reactivex/subscribers/nbp/NbpTestSubscriber.java b/src/main/java/io/reactivex/observers/TestObserver.java similarity index 98% rename from src/main/java/io/reactivex/subscribers/nbp/NbpTestSubscriber.java rename to src/main/java/io/reactivex/observers/TestObserver.java index 704200f41b..9fc8139d06 100644 --- a/src/main/java/io/reactivex/subscribers/nbp/NbpTestSubscriber.java +++ b/src/main/java/io/reactivex/observers/TestObserver.java @@ -10,18 +10,18 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subscribers.nbp; +package io.reactivex.observers; import java.util.*; import java.util.concurrent.*; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.Notification; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.CompositeException; import io.reactivex.internal.functions.Objects; -import io.reactivex.internal.subscribers.nbp.NbpEmptySubscriber; +import io.reactivex.internal.subscribers.observable.NbpEmptySubscriber; /** * A subscriber that records events and allows making assertions about them. @@ -36,9 +36,9 @@ * * @param the value type */ -public class NbpTestSubscriber implements NbpSubscriber, Disposable { +public class TestObserver implements Observer, Disposable { /** The actual subscriber to forward events to. */ - private final NbpSubscriber actual; + private final Observer actual; /** The latch that indicates an onError or onCompleted has been called. */ private final CountDownLatch done; /** The list of values received. */ @@ -67,7 +67,7 @@ public void dispose() { } /** * Constructs a non-forwarding TestSubscriber with an initial request value of Long.MAX_VALUE. */ - public NbpTestSubscriber() { + public TestObserver() { this(NbpEmptySubscriber.INSTANCE_NOERROR); } @@ -75,7 +75,7 @@ public NbpTestSubscriber() { * Constructs a forwarding TestSubscriber but leaves the requesting to the wrapped subscriber. * @param actual the actual Subscriber to forward events to */ - public NbpTestSubscriber(NbpSubscriber actual) { + public TestObserver(Observer actual) { this.actual = actual; this.values = new ArrayList(); this.errors = new ArrayList(); diff --git a/src/main/java/io/reactivex/plugins/RxJavaPlugins.java b/src/main/java/io/reactivex/plugins/RxJavaPlugins.java index 31ae26074b..859a638cf9 100644 --- a/src/main/java/io/reactivex/plugins/RxJavaPlugins.java +++ b/src/main/java/io/reactivex/plugins/RxJavaPlugins.java @@ -14,8 +14,7 @@ import org.reactivestreams.*; -import io.reactivex.Scheduler; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.*; import io.reactivex.functions.*; /** @@ -27,7 +26,7 @@ public final class RxJavaPlugins { static volatile Function, Subscriber> onSubscribeHandler; - static volatile Function, NbpSubscriber> onNbpSubscribeHandler; + static volatile Function, Observer> onNbpSubscribeHandler; static volatile Function, Publisher> onCreateHandler; @@ -118,7 +117,7 @@ public static Function, Subscriber> getSubscribeHandler() { } @SuppressWarnings({ "rawtypes", "unchecked" }) - public static Function, NbpSubscriber> getNbpSubscribeHandler() { + public static Function, Observer> getNbpSubscribeHandler() { return (Function)onNbpSubscribeHandler; } @@ -258,12 +257,12 @@ public static Subscriber onSubscribe(Subscriber subscriber) { * @return the replacement NbpSubscriber */ @SuppressWarnings({ "unchecked", "rawtypes"}) - public static NbpSubscriber onNbpSubscribe(NbpSubscriber subscriber) { - Function, NbpSubscriber> f = onNbpSubscribeHandler; + public static Observer onNbpSubscribe(Observer subscriber) { + Function, Observer> f = onNbpSubscribeHandler; if (f == null) { return subscriber; } - return (NbpSubscriber)((Function)f).apply(subscriber); + return (Observer)((Function)f).apply(subscriber); } /** @@ -273,12 +272,12 @@ public static NbpSubscriber onNbpSubscribe(NbpSubscriber subscriber) { * @return the replacement subscriber */ @SuppressWarnings({ "unchecked", "rawtypes"}) - public static NbpSubscriber onSubscribe(NbpSubscriber subscriber) { - Function, NbpSubscriber> f = onNbpSubscribeHandler; + public static Observer onSubscribe(Observer subscriber) { + Function, Observer> f = onNbpSubscribeHandler; if (f == null) { return subscriber; } - return (NbpSubscriber)((Function)f).apply(subscriber); + return (Observer)((Function)f).apply(subscriber); } /** @@ -391,7 +390,7 @@ public static void setSubscribeHandler(Function, Subscriber } @SuppressWarnings({ "rawtypes", "unchecked" }) - public static void setNbpSubscribeHandler(Function, NbpSubscriber> handler) { + public static void setNbpSubscribeHandler(Function, Observer> handler) { if (lockdown) { throw new IllegalStateException("Plugins can't be changed anymore"); } diff --git a/src/main/java/io/reactivex/processors/AsyncProcessor.java b/src/main/java/io/reactivex/processors/AsyncProcessor.java new file mode 100644 index 0000000000..1ba15c2066 --- /dev/null +++ b/src/main/java/io/reactivex/processors/AsyncProcessor.java @@ -0,0 +1,373 @@ +/** + * Copyright 2016 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ +package io.reactivex.processors; + +import java.util.Arrays; +import java.util.concurrent.atomic.*; + +import org.reactivestreams.*; + +import io.reactivex.functions.IntFunction; +import io.reactivex.internal.util.*; +import io.reactivex.plugins.RxJavaPlugins; + +/** + * A Subject that emits the very last value followed by a completion event or the received error to Subscribers. + * + *

The implementation of onXXX methods are technically thread-safe but non-serialized calls + * to them may lead to undefined state in the currently subscribed Subscribers. + * + *

Due to the nature Observables are constructed, the AsyncSubject can't be instantiated through + * {@code new} but must be created via the {@link #create()} method. + * + * @param the value type + */ +public final class AsyncProcessor extends FlowProcessor { + + /** + * Constructs an empty AsyncSubject. + * @param the observed and observable value type + * @return the new AsyncSubject instance. + */ + public static AsyncProcessor create() { + State state = new State(); + return new AsyncProcessor(state); + } + + /** The state holding onto the latest value or error and the array of subscribers. */ + final State state; + /** + * Indicates the subject has been terminated. It is checked in the onXXX methods in + * a relaxed matter: concurrent calls may not properly see it (which shouldn't happen if + * the reactive-streams contract is held). + */ + boolean done; + + protected AsyncProcessor(State state) { + super(state); + this.state = state; + } + + @Override + public void onSubscribe(Subscription s) { + if (done) { + s.cancel(); + return; + } + s.request(Long.MAX_VALUE); + } + + @Override + public void onNext(T t) { + if (done) { + return; + } + if (t == null) { + onError(new NullPointerException()); + return; + } + state.lazySet(t); + } + + @Override + public void onError(Throwable t) { + if (done) { + RxJavaPlugins.onError(t); + return; + } + if (t == null) { + t = new NullPointerException(); + } + done = true; + state.lazySet(NotificationLite.error(t)); + for (AsyncSubscription as : state.terminate()) { + as.setError(t); + } + } + + @Override + public void onComplete() { + if (done) { + return; + } + done = true; + @SuppressWarnings("unchecked") + T value = (T)state.get(); + for (AsyncSubscription as : state.terminate()) { + as.setValue(value); + } + } + + @Override + public boolean hasSubscribers() { + return state.subscribers().length != 0; + } + + @Override + public boolean hasValue() { + Object o = state.get(); + return o != null && !NotificationLite.isError(o); + } + + @Override + public boolean hasComplete() { + Object o = state.get(); + return state.subscribers() == State.TERMINATED && !NotificationLite.isError(o); + } + + @Override + public boolean hasThrowable() { + return NotificationLite.isError(state.get()); + } + + @Override + public Throwable getThrowable() { + Object o = state.get(); + if (NotificationLite.isError(o)) { + return NotificationLite.getError(o); + } + return null; + } + + @Override + @SuppressWarnings("unchecked") + public T getValue() { + Object o = state.get(); + if (o != null && !NotificationLite.isError(o)) { + return (T)o; + } + return null; + } + + @Override + @SuppressWarnings("unchecked") + public T[] getValues(T[] array) { + Object o = state.get(); + if (o != null && !NotificationLite.isError(o) && !NotificationLite.isComplete(o)) { + int n = array.length; + if (n == 0) { + array = Arrays.copyOf(array, 1); + } + array[0] = (T)o; + if (array.length > 1) { + array[1] = null; + } + } else { + if (array.length != 0) { + array[0] = null; + } + } + return array; + } + /** + * The state of the AsyncSubject. + * + * @param the value type + */ + @SuppressWarnings("rawtypes") + static final class State extends AtomicReference + implements Publisher, IntFunction[]> { + + /** */ + private static final long serialVersionUID = 2983503212425065796L; + + /** An empty AsyncSubscription array to avoid allocating it in remove. */ + static final AsyncSubscription[] EMPTY = new AsyncSubscription[0]; + /** An empty array indicating a terminal state .*/ + static final AsyncSubscription[] TERMINATED = new AsyncSubscription[0]; + + /** The array of current subscribers. */ + @SuppressWarnings("unchecked") + final AtomicReference[]> subscribers = new AtomicReference[]>(EMPTY); + + /** + * Returns the array of current subscribers. + * @return the array of current subscribers + */ + public AsyncSubscription[] subscribers() { + return subscribers.get(); + } + + /** + * Terminates the state and returns the last array of subscribers. + * @return the last array of subscribers + */ + @SuppressWarnings("unchecked") + public AsyncSubscription[] terminate() { + return TerminalAtomicsHelper.terminate(subscribers, TERMINATED); + } + + /** + * Atomically tries to add the AsyncSubscription to the subscribers array + * or returns false if the state has been terminated. + * @param as the AsyncSubscription to add + * @return true if successful, false if the state has been terminated + */ + @SuppressWarnings("unchecked") + boolean add(AsyncSubscription as) { + return TerminalAtomicsHelper.add(subscribers, as, TERMINATED, this); + } + + /** + * Atomically removes the given AsyncSubscription. + * @param as the AsyncSubscription to remove + */ + @SuppressWarnings("unchecked") + void remove(AsyncSubscription as) { + TerminalAtomicsHelper.remove(subscribers, as, TERMINATED, EMPTY, this); + } + + @SuppressWarnings("unchecked") + @Override + public AsyncSubscription[] apply(int value) { + return new AsyncSubscription[value]; + } + + @Override + @SuppressWarnings("unchecked") + public void subscribe(Subscriber t) { + AsyncSubscription as = new AsyncSubscription(t, this); + t.onSubscribe(as); + + if (add(as)) { + if (as.isDone()) { + remove(as); + } + } else { + Object o = get(); + if (NotificationLite.isError(o)) { + as.setError(NotificationLite.getError(o)); + } else { + as.setValue((T)o); + } + } + } + } + + /** + * A subscription implementation that wraps the actual Subscriber and manages the request and cancel calls. + * + * @param the value type + */ + static final class AsyncSubscription extends AtomicInteger implements Subscription { + /** */ + private static final long serialVersionUID = 2900823026377918858L; + /** The actual subscriber. */ + final Subscriber actual; + /** The AsyncSubject state containing the value. */ + final State state; + + /** State management: no request and no value has been set. */ + static final int NO_REQUEST_NO_VALUE = 0; + /** State management: no request but value is available. */ + static final int NO_REQUEST_HAS_VALUE = 1; + /** State management: a positive request has been made but no value is available. */ + static final int HAS_REQUEST_NO_VALUE = 2; + /** State management: both positive request and value is available, terminal state. */ + static final int HAS_REQUEST_HAS_VALUE = 3; + + public AsyncSubscription(Subscriber actual, State state) { + this.actual = actual; + this.state = state; + } + + /** + * Indicates the given value is available and emits it to the actual Subscriber if + * it has requested. + * @param value the value to emit + */ + public void setValue(T value) { + for (;;) { + int s = get(); + if (s == NO_REQUEST_HAS_VALUE || s == HAS_REQUEST_HAS_VALUE) { + return; + } else + if (s == NO_REQUEST_NO_VALUE) { + if (compareAndSet(NO_REQUEST_NO_VALUE, NO_REQUEST_HAS_VALUE)) { + return; + } + } else + if (s == HAS_REQUEST_NO_VALUE) { + lazySet(HAS_REQUEST_HAS_VALUE); // setValue is called once, no need for CAS + if (value != null) { + actual.onNext(value); + } + actual.onComplete(); + } + } + } + + /** + * Terminates the AsyncSubscription and emits the given error + * if not already terminated. + * @param e the Throwable to emit to the Subscriber + */ + public void setError(Throwable e) { + int s = get(); + if (s != HAS_REQUEST_HAS_VALUE) { + s = getAndSet(HAS_REQUEST_HAS_VALUE); + if (s != HAS_REQUEST_HAS_VALUE) { + actual.onError(e); + } + } + } + + @Override + public void request(long n) { + if (n <= 0) { + RxJavaPlugins.onError(new IllegalArgumentException("n > 0 required but it was " + n)); + return; + } + for (;;) { + int s = get(); + if (s == HAS_REQUEST_NO_VALUE || s == HAS_REQUEST_HAS_VALUE) { + return; + } else + if (s == NO_REQUEST_NO_VALUE) { + if (compareAndSet(NO_REQUEST_NO_VALUE, HAS_REQUEST_NO_VALUE)) { + return; + } + } else { + if (compareAndSet(NO_REQUEST_HAS_VALUE, HAS_REQUEST_HAS_VALUE)) { + @SuppressWarnings("unchecked") + T v = (T)state.get(); + if (v != null) { + actual.onNext(v); + } + actual.onComplete(); + return; + } + } + } + } + + @Override + public void cancel() { + int s = get(); + if (s != HAS_REQUEST_HAS_VALUE) { + s = getAndSet(HAS_REQUEST_HAS_VALUE); + if (s != HAS_REQUEST_HAS_VALUE) { + state.remove(this); + } + } + } + + /** + * Returns true if the AsyncSubscription has reached its terminal state. + * @return true if the AsyncSubscription has reached its terminal state + */ + boolean isDone() { + return get() == HAS_REQUEST_HAS_VALUE; + } + } +} diff --git a/src/main/java/io/reactivex/subjects/nbp/NbpBehaviorSubject.java b/src/main/java/io/reactivex/processors/BehaviorProcessor.java similarity index 75% rename from src/main/java/io/reactivex/subjects/nbp/NbpBehaviorSubject.java rename to src/main/java/io/reactivex/processors/BehaviorProcessor.java index 10707bc80d..042eb6e93d 100644 --- a/src/main/java/io/reactivex/subjects/nbp/NbpBehaviorSubject.java +++ b/src/main/java/io/reactivex/processors/BehaviorProcessor.java @@ -11,41 +11,43 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects.nbp; +package io.reactivex.processors; import java.lang.reflect.Array; import java.util.concurrent.atomic.*; import java.util.concurrent.locks.*; -import io.reactivex.disposables.Disposable; +import org.reactivestreams.*; + import io.reactivex.functions.Predicate; import io.reactivex.internal.functions.Objects; +import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.*; import io.reactivex.plugins.RxJavaPlugins; -public final class NbpBehaviorSubject extends NbpSubject { +public final class BehaviorProcessor extends FlowProcessor { - public static NbpBehaviorSubject create() { + public static BehaviorProcessor create() { State state = new State(); - return new NbpBehaviorSubject(state); + return new BehaviorProcessor(state); } - // A plain create(T) would create a method ambiguity with Observable.create with javac - public static NbpBehaviorSubject createDefault(T defaultValue) { + // TODO a plain create() would create a method ambiguity with Observable.create with javac + public static BehaviorProcessor createDefault(T defaultValue) { Objects.requireNonNull(defaultValue, "defaultValue is null"); State state = new State(); state.lazySet(defaultValue); - return new NbpBehaviorSubject(state); + return new BehaviorProcessor(state); } final State state; - protected NbpBehaviorSubject(State state) { + protected BehaviorProcessor(State state) { super(state); this.state = state; } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Subscription s) { state.onSubscribe(s); } @@ -140,19 +142,19 @@ public boolean hasValue() { return o != null && !NotificationLite.isComplete(o) && !NotificationLite.isError(o); } - static final class State extends AtomicReference implements NbpOnSubscribe, NbpSubscriber { + static final class State extends AtomicReference implements Publisher, Subscriber { /** */ private static final long serialVersionUID = -4311717003288339429L; boolean done; - final AtomicReference[]> subscribers; + final AtomicReference[]> subscribers; @SuppressWarnings("rawtypes") - static final BehaviorDisposable[] EMPTY = new BehaviorDisposable[0]; + static final BehaviorSubscription[] EMPTY = new BehaviorSubscription[0]; @SuppressWarnings("rawtypes") - static final BehaviorDisposable[] TERMINATED = new BehaviorDisposable[0]; + static final BehaviorSubscription[] TERMINATED = new BehaviorSubscription[0]; long index; @@ -165,18 +167,18 @@ public State() { this.lock = new ReentrantReadWriteLock(); this.readLock = lock.readLock(); this.writeLock = lock.writeLock(); - this.subscribers = new AtomicReference[]>(EMPTY); + this.subscribers = new AtomicReference[]>(EMPTY); } - public boolean add(BehaviorDisposable rs) { + public boolean add(BehaviorSubscription rs) { for (;;) { - BehaviorDisposable[] a = subscribers.get(); + BehaviorSubscription[] a = subscribers.get(); if (a == TERMINATED) { return false; } int len = a.length; @SuppressWarnings("unchecked") - BehaviorDisposable[] b = new BehaviorDisposable[len + 1]; + BehaviorSubscription[] b = new BehaviorSubscription[len + 1]; System.arraycopy(a, 0, b, 0, len); b[len] = rs; if (subscribers.compareAndSet(a, b)) { @@ -186,9 +188,9 @@ public boolean add(BehaviorDisposable rs) { } @SuppressWarnings("unchecked") - public void remove(BehaviorDisposable rs) { + public void remove(BehaviorSubscription rs) { for (;;) { - BehaviorDisposable[] a = subscribers.get(); + BehaviorSubscription[] a = subscribers.get(); if (a == TERMINATED || a == EMPTY) { return; } @@ -204,11 +206,11 @@ public void remove(BehaviorDisposable rs) { if (j < 0) { return; } - BehaviorDisposable[] b; + BehaviorSubscription[] b; if (len == 1) { b = EMPTY; } else { - b = new BehaviorDisposable[len - 1]; + b = new BehaviorSubscription[len - 1]; System.arraycopy(a, 0, b, 0, j); System.arraycopy(a, j + 1, b, j, len - j - 1); } @@ -219,9 +221,9 @@ public void remove(BehaviorDisposable rs) { } @SuppressWarnings("unchecked") - public BehaviorDisposable[] terminate(Object terminalValue) { + public BehaviorSubscription[] terminate(Object terminalValue) { - BehaviorDisposable[] a = subscribers.get(); + BehaviorSubscription[] a = subscribers.get(); if (a != TERMINATED) { a = subscribers.getAndSet(TERMINATED); if (a != TERMINATED) { @@ -234,8 +236,8 @@ public BehaviorDisposable[] terminate(Object terminalValue) { } @Override - public void accept(NbpSubscriber s) { - BehaviorDisposable bs = new BehaviorDisposable(s, this); + public void subscribe(Subscriber s) { + BehaviorSubscription bs = new BehaviorSubscription(s, this); s.onSubscribe(bs); if (!bs.cancelled) { if (add(bs)) { @@ -256,11 +258,12 @@ public void accept(NbpSubscriber s) { } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Subscription s) { if (done) { - s.dispose(); + s.cancel(); return; } + s.request(Long.MAX_VALUE); } void setCurrent(Object o) { @@ -280,7 +283,7 @@ public void onNext(T t) { } Object o = NotificationLite.next(t); setCurrent(o); - for (BehaviorDisposable bs : subscribers.get()) { + for (BehaviorSubscription bs : subscribers.get()) { bs.emitNext(o, index); } } @@ -293,7 +296,7 @@ public void onError(Throwable t) { } done = true; Object o = NotificationLite.error(t); - for (BehaviorDisposable bs : terminate(o)) { + for (BehaviorSubscription bs : terminate(o)) { bs.emitNext(o, index); } } @@ -305,15 +308,17 @@ public void onComplete() { } done = true; Object o = NotificationLite.complete(); - for (BehaviorDisposable bs : terminate(o)) { + for (BehaviorSubscription bs : terminate(o)) { bs.emitNext(o, index); // relaxed read okay since this is the only mutator thread } } } - static final class BehaviorDisposable implements Disposable, Predicate { + static final class BehaviorSubscription extends AtomicLong implements Subscription, Predicate { + /** */ + private static final long serialVersionUID = 3293175281126227086L; - final NbpSubscriber actual; + final Subscriber actual; final State state; boolean next; @@ -326,13 +331,22 @@ static final class BehaviorDisposable implements Disposable, Predicate actual, State state) { + public BehaviorSubscription(Subscriber actual, State state) { this.actual = actual; this.state = state; } @Override - public void dispose() { + public void request(long n) { + if (SubscriptionHelper.validateRequest(n)) { + return; + } + + BackpressureHelper.add(this, n); + } + + @Override + public void cancel() { if (!cancelled) { cancelled = true; @@ -354,14 +368,14 @@ void emitFirst() { } State s = state; - Lock lock = s.readLock; - lock.lock(); + Lock readLock = s.readLock; + readLock.lock(); try { index = s.index; o = s.get(); } finally { - lock.unlock(); + readLock.unlock(); } emitting = o != null; @@ -411,7 +425,29 @@ public boolean test(Object o) { if (cancelled) { return true; } - return NotificationLite.accept(o, actual); + + if (NotificationLite.isComplete(o)) { + cancel(); + actual.onComplete(); + return true; + } else + if (NotificationLite.isError(o)) { + cancel(); + actual.onError(NotificationLite.getError(o)); + return true; + } + + long r = get(); + if (r != 0L) { + actual.onNext(NotificationLite.getValue(o)); + if (r != Long.MAX_VALUE) { + decrementAndGet(); + } + return false; + } + cancel(); + actual.onError(new IllegalStateException("Could not deliver value due to lack of requests")); + return true; } void emitLoop() { diff --git a/src/main/java/io/reactivex/subjects/nbp/NbpSubject.java b/src/main/java/io/reactivex/processors/FlowProcessor.java similarity index 88% rename from src/main/java/io/reactivex/subjects/nbp/NbpSubject.java rename to src/main/java/io/reactivex/processors/FlowProcessor.java index b30aa892d7..0bcd930a7e 100644 --- a/src/main/java/io/reactivex/subjects/nbp/NbpSubject.java +++ b/src/main/java/io/reactivex/processors/FlowProcessor.java @@ -11,13 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects.nbp; +package io.reactivex.processors; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.NbpSubscriber; +import org.reactivestreams.*; + +import io.reactivex.Flowable; /** - * Represents a NbpSubscriber and a NbpObservable at the same time, allowing + * Represents a Subscriber and an Observable (Publisher) at the same time, allowing * multicasting events from a single source to multiple child Subscribers. *

All methods except the onSubscribe, onNext, onError and onComplete are thread-safe. * Use {@link #toSerialized()} to make these methods thread-safe as well. @@ -25,9 +26,9 @@ * @param the source value type * @param the emission value type */ -public abstract class NbpSubject extends NbpObservable implements NbpSubscriber { +public abstract class FlowProcessor extends Flowable implements Processor { - protected NbpSubject(NbpOnSubscribe onSubscribe) { + protected FlowProcessor(Publisher onSubscribe) { super(onSubscribe); } @@ -43,7 +44,7 @@ protected NbpSubject(NbpOnSubscribe onSubscribe) { *

The method is thread-safe. * @return true if the subject has reached a terminal state through an error event * @see #getThrowable() - * &see {@link #hasComplete()} + * @see #hasComplete() */ public boolean hasThrowable() { throw new UnsupportedOperationException(); @@ -94,11 +95,11 @@ public R getValue() { *

The method is thread-safe. * @return the wrapped and serialized subject */ - public final NbpSubject toSerialized() { - if (this instanceof NbpSerializedSubject) { + public final FlowProcessor toSerialized() { + if (this instanceof SerializedProcessor) { return this; } - return new NbpSerializedSubject(this); + return new SerializedProcessor(this); } /** An empty array to avoid allocation in getValues(). */ diff --git a/src/main/java/io/reactivex/processors/PublishProcessor.java b/src/main/java/io/reactivex/processors/PublishProcessor.java new file mode 100644 index 0000000000..a1d3dfae10 --- /dev/null +++ b/src/main/java/io/reactivex/processors/PublishProcessor.java @@ -0,0 +1,332 @@ +/** + * Copyright 2016 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ +package io.reactivex.processors; + +import java.util.concurrent.atomic.*; + +import org.reactivestreams.*; + +import io.reactivex.exceptions.MissingBackpressureException; +import io.reactivex.functions.IntFunction; +import io.reactivex.internal.subscriptions.SubscriptionHelper; +import io.reactivex.internal.util.*; +import io.reactivex.plugins.RxJavaPlugins; + +/** + * A Subject that multicasts events to Subscribers that are currently subscribed to it. + * + *

The subject does not coordinate backpressure for its subscribers and implements a weaker onSubscribe which + * calls requests Long.MAX_VALUE from the incoming Subscriptions. This makes it possible to subscribe the PublishSubject + * to multiple sources (note on serialization though) unlike the standard contract on Subscriber. Child subscribers, however, are not overflown but receive an + * IllegalStateException in case their requested amount is zero. + * + *

The implementation of onXXX methods are technically thread-safe but non-serialized calls + * to them may lead to undefined state in the currently subscribed Subscribers. + * + *

Due to the nature Observables are constructed, the PublishSubject can't be instantiated through + * {@code new} but must be created via the {@link #create()} method. + * + * @param the value type multicast to Subscribers. + */ +public final class PublishProcessor extends FlowProcessor { + + /** + * Constructs a PublishSubject. + * @param the value type + * @return the new PublishSubject + */ + public static PublishProcessor create() { + State state = new State(); + return new PublishProcessor(state); + } + + /** Holds the terminal event and manages the array of subscribers. */ + final State state; + /** + * Indicates the subject has been terminated. It is checked in the onXXX methods in + * a relaxed matter: concurrent calls may not properly see it (which shouldn't happen if + * the reactive-streams contract is held). + */ + boolean done; + + protected PublishProcessor(State state) { + super(state); + this.state = state; + } + + @Override + public void onSubscribe(Subscription s) { + if (done) { + s.cancel(); + return; + } + // PublishSubject doesn't bother with request coordination. + s.request(Long.MAX_VALUE); + } + + @Override + public void onNext(T t) { + if (done) { + return; + } + if (t == null) { + onError(new NullPointerException()); + return; + } + for (PublishSubscriber s : state.subscribers()) { + s.onNext(t); + } + } + + @Override + public void onError(Throwable t) { + if (done) { + RxJavaPlugins.onError(t); + return; + } + done = true; + if (t == null) { + t = new NullPointerException(); + } + for (PublishSubscriber s : state.terminate(t)) { + s.onError(t); + } + } + + @Override + public void onComplete() { + if (done) { + return; + } + done = true; + for (PublishSubscriber s : state.terminate()) { + s.onComplete(); + } + } + + @Override + public boolean hasSubscribers() { + return state.subscribers().length != 0; + } + + @Override + public boolean hasValue() { + return false; + } + + @Override + public T getValue() { + return null; + } + + @Override + public T[] getValues(T[] array) { + if (array.length != 0) { + array[0] = null; + } + return array; + } + + @Override + public Throwable getThrowable() { + Object o = state.get(); + if (o == State.COMPLETE) { + return null; + } + return (Throwable)o; + } + + @Override + public boolean hasThrowable() { + Object o = state.get(); + return o != null && o != State.COMPLETE; + } + + @Override + public boolean hasComplete() { + return state.get() == State.COMPLETE; + } + + /** + * Contains the state of the Subject, including the currently subscribed clients and the + * terminal value. + * + * @param the value type of the events + */ + @SuppressWarnings("rawtypes") + static final class State extends AtomicReference + implements Publisher, IntFunction[]> { + /** */ + private static final long serialVersionUID = -2699311989055418316L; + /** The completion token. */ + static final Object COMPLETE = new Object(); + + /** The terminated indicator for the subscribers array. */ + static final PublishSubscriber[] TERMINATED = new PublishSubscriber[0]; + /** An empty subscribers array to avoid allocating it all the time. */ + static final PublishSubscriber[] EMPTY = new PublishSubscriber[0]; + + /** The array of currently subscribed subscribers. */ + @SuppressWarnings("unchecked") + final AtomicReference[]> subscribers = new AtomicReference[]>(EMPTY); + + @Override + public void subscribe(Subscriber t) { + PublishSubscriber ps = new PublishSubscriber(t, this); + t.onSubscribe(ps); + if (!ps.cancelled.get()) { + if (add(ps)) { + // if cancellation happened while a successful add, the remove() didn't work + // so we need to do it again + if (ps.cancelled.get()) { + remove(ps); + } + } else { + Object o = get(); + if (o == COMPLETE) { + ps.onComplete(); + } else { + ps.onError((Throwable)o); + } + } + } + } + + /** + * @return the array of currently subscribed subscribers + */ + PublishSubscriber[] subscribers() { + return subscribers.get(); + } + + /** + * Atomically swaps in the terminal state with a completion indicator and returns + * the last array of subscribers. + * @return the last array of subscribers + */ + PublishSubscriber[] terminate() { + return terminate(COMPLETE); + } + + /** + * Atomically swaps in the terminal state with a completion indicator and returns + * the last array of subscribers. + * @param event the terminal state value to set + * @return the last array of subscribers + */ + @SuppressWarnings("unchecked") + PublishSubscriber[] terminate(Object event) { + if (compareAndSet(null, event)) { + return TerminalAtomicsHelper.terminate(subscribers, TERMINATED); + } + return TERMINATED; + } + + /** + * Tries to add the given subscriber to the subscribers array atomically + * or returns false if the subject has terminated. + * @param ps the subscriber to add + * @return true if successful, false if the subject has terminated + */ + @SuppressWarnings("unchecked") + boolean add(PublishSubscriber ps) { + return TerminalAtomicsHelper.add(subscribers, ps, TERMINATED, this); + } + + /** + * Atomically removes the given subscriber if it is subscribed to the subject. + * @param ps the subject to remove + */ + @SuppressWarnings("unchecked") + void remove(PublishSubscriber ps) { + TerminalAtomicsHelper.remove(subscribers, ps, TERMINATED, EMPTY, this); + } + + @SuppressWarnings("unchecked") + @Override + public PublishSubscriber[] apply(int value) { + return new PublishSubscriber[value]; + } + } + + /** + * Wraps the actual subscriber, tracks its requests and makes cancellation + * to remove itself from the current subscribers array. + * + * @param the value type + */ + static final class PublishSubscriber extends AtomicLong implements Subscriber, Subscription { + /** */ + private static final long serialVersionUID = 3562861878281475070L; + /** The actual subscriber. */ + final Subscriber actual; + /** The subject state. */ + final State state; + + final AtomicBoolean cancelled = new AtomicBoolean(); + + /** + * Constructs a PublishSubscriber, wraps the actual subscriber and the state. + * @param actual the actual subscriber + * @param state the state + */ + public PublishSubscriber(Subscriber actual, State state) { + this.actual = actual; + this.state = state; + } + + @Override + public void onSubscribe(Subscription s) { + // not called because requests are handled locally and cancel is forwared to state + } + + @Override + public void onNext(T t) { + long r = get(); + if (r != 0L) { + actual.onNext(t); + if (r != Long.MAX_VALUE) { + decrementAndGet(); + } + } else { + cancel(); + actual.onError(new MissingBackpressureException("Could not emit value due to lack of requests")); + } + } + + @Override + public void onError(Throwable t) { + actual.onError(t); + } + + @Override + public void onComplete() { + actual.onComplete(); + } + + @Override + public void request(long n) { + if (SubscriptionHelper.validateRequest(n)) { + return; + } + BackpressureHelper.add(this, n); + } + + @Override + public void cancel() { + if (!cancelled.get() && cancelled.compareAndSet(false, true)) { + state.remove(this); + } + } + } +} diff --git a/src/main/java/io/reactivex/subjects/nbp/NbpReplaySubject.java b/src/main/java/io/reactivex/processors/ReplayProcessor.java similarity index 83% rename from src/main/java/io/reactivex/subjects/nbp/NbpReplaySubject.java rename to src/main/java/io/reactivex/processors/ReplayProcessor.java index dc2c1a7f2d..95a154630b 100644 --- a/src/main/java/io/reactivex/subjects/nbp/NbpReplaySubject.java +++ b/src/main/java/io/reactivex/processors/ReplayProcessor.java @@ -11,17 +11,19 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects.nbp; +package io.reactivex.processors; import java.lang.reflect.Array; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; +import org.reactivestreams.*; + import io.reactivex.Scheduler; -import io.reactivex.disposables.Disposable; import io.reactivex.internal.functions.Objects; -import io.reactivex.internal.util.NotificationLite; +import io.reactivex.internal.subscriptions.SubscriptionHelper; +import io.reactivex.internal.util.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; @@ -32,13 +34,13 @@ * * @param the value type */ -public final class NbpReplaySubject extends NbpSubject { +public final class ReplayProcessor extends FlowProcessor { - public static NbpReplaySubject create() { + public static ReplayProcessor create() { return create(16); } - public static NbpReplaySubject create(int capacityHint) { + public static ReplayProcessor create(int capacityHint) { if (capacityHint <= 0) { throw new IllegalArgumentException("capacityHint > 0 required but it was " + capacityHint); } @@ -46,7 +48,7 @@ public static NbpReplaySubject create(int capacityHint) { return createWithBuffer(buffer); } - public static NbpReplaySubject createWithSize(int size) { + public static ReplayProcessor createWithSize(int size) { if (size <= 0) { throw new IllegalArgumentException("size > 0 required but it was " + size); } @@ -54,20 +56,20 @@ public static NbpReplaySubject createWithSize(int size) { return createWithBuffer(buffer); } - /* test */ static NbpReplaySubject createUnbounded() { + /* test */ static ReplayProcessor createUnbounded() { SizeBoundReplayBuffer buffer = new SizeBoundReplayBuffer(Integer.MAX_VALUE); return createWithBuffer(buffer); } - public static NbpReplaySubject createWithTime(long maxAge, TimeUnit unit) { + public static ReplayProcessor createWithTime(long maxAge, TimeUnit unit) { return createWithTime(maxAge, unit, Schedulers.trampoline()); } - public static NbpReplaySubject createWithTime(long maxAge, TimeUnit unit, Scheduler scheduler) { + public static ReplayProcessor createWithTime(long maxAge, TimeUnit unit, Scheduler scheduler) { return createWithTimeAndSize(maxAge, unit, scheduler, Integer.MAX_VALUE); } - public static NbpReplaySubject createWithTimeAndSize(long maxAge, TimeUnit unit, Scheduler scheduler, int size) { + public static ReplayProcessor createWithTimeAndSize(long maxAge, TimeUnit unit, Scheduler scheduler, int size) { Objects.requireNonNull(unit, "unit is null"); Objects.requireNonNull(scheduler, "scheduler is null"); if (size <= 0) { @@ -77,21 +79,21 @@ public static NbpReplaySubject createWithTimeAndSize(long maxAge, TimeUni return createWithBuffer(buffer); } - static NbpReplaySubject createWithBuffer(ReplayBuffer buffer) { + static ReplayProcessor createWithBuffer(ReplayBuffer buffer) { State state = new State(buffer); - return new NbpReplaySubject(state); + return new ReplayProcessor(state); } final State state; - protected NbpReplaySubject(State state) { + protected ReplayProcessor(State state) { super(state); this.state = state; } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Subscription s) { state.onSubscribe(s); } @@ -166,7 +168,7 @@ public boolean hasValue() { return state.buffer.size(); } - static final class State extends AtomicReference implements NbpOnSubscribe, NbpSubscriber { + static final class State extends AtomicReference implements Publisher, Subscriber { /** */ private static final long serialVersionUID = -4673197222000219014L; @@ -174,23 +176,23 @@ static final class State extends AtomicReference implements NbpOnSubs boolean done; - final AtomicReference[]> subscribers = new AtomicReference[]>(); + final AtomicReference[]> subscribers; @SuppressWarnings("rawtypes") - static final ReplayDisposable[] EMPTY = new ReplayDisposable[0]; + static final ReplaySubscription[] EMPTY = new ReplaySubscription[0]; @SuppressWarnings("rawtypes") - static final ReplayDisposable[] TERMINATED = new ReplayDisposable[0]; + static final ReplaySubscription[] TERMINATED = new ReplaySubscription[0]; @SuppressWarnings("unchecked") public State(ReplayBuffer buffer) { this.buffer = buffer; - subscribers.lazySet(EMPTY); + this.subscribers = new AtomicReference[]>(EMPTY); } @Override - public void accept(NbpSubscriber s) { - ReplayDisposable rs = new ReplayDisposable(s, this); + public void subscribe(Subscriber s) { + ReplaySubscription rs = new ReplaySubscription(s, this); s.onSubscribe(rs); if (!rs.cancelled) { @@ -204,15 +206,15 @@ public void accept(NbpSubscriber s) { } } - public boolean add(ReplayDisposable rs) { + public boolean add(ReplaySubscription rs) { for (;;) { - ReplayDisposable[] a = subscribers.get(); + ReplaySubscription[] a = subscribers.get(); if (a == TERMINATED) { return false; } int len = a.length; @SuppressWarnings("unchecked") - ReplayDisposable[] b = new ReplayDisposable[len + 1]; + ReplaySubscription[] b = new ReplaySubscription[len + 1]; System.arraycopy(a, 0, b, 0, len); b[len] = rs; if (subscribers.compareAndSet(a, b)) { @@ -222,9 +224,9 @@ public boolean add(ReplayDisposable rs) { } @SuppressWarnings("unchecked") - public void remove(ReplayDisposable rs) { + public void remove(ReplaySubscription rs) { for (;;) { - ReplayDisposable[] a = subscribers.get(); + ReplaySubscription[] a = subscribers.get(); if (a == TERMINATED || a == EMPTY) { return; } @@ -240,11 +242,11 @@ public void remove(ReplayDisposable rs) { if (j < 0) { return; } - ReplayDisposable[] b; + ReplaySubscription[] b; if (len == 1) { b = EMPTY; } else { - b = new ReplayDisposable[len - 1]; + b = new ReplaySubscription[len - 1]; System.arraycopy(a, 0, b, 0, j); System.arraycopy(a, j + 1, b, j, len - j - 1); } @@ -255,7 +257,7 @@ public void remove(ReplayDisposable rs) { } @SuppressWarnings("unchecked") - public ReplayDisposable[] terminate(Object terminalValue) { + public ReplaySubscription[] terminate(Object terminalValue) { if (compareAndSet(null, terminalValue)) { return subscribers.getAndSet(TERMINATED); } @@ -263,10 +265,12 @@ public ReplayDisposable[] terminate(Object terminalValue) { } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Subscription s) { if (done) { - s.dispose(); + s.cancel(); + return; } + s.request(Long.MAX_VALUE); } @Override @@ -278,8 +282,7 @@ public void onNext(T t) { ReplayBuffer b = buffer; b.add(t); - for (ReplayDisposable rs : subscribers.get()) { - // FIXME there is a caught-up optimization possible here as is with 1.x + for (ReplaySubscription rs : subscribers.get()) { b.replay(rs); } } @@ -298,7 +301,7 @@ public void onError(Throwable t) { b.addFinal(o); - for (ReplayDisposable rs : terminate(o)) { + for (ReplaySubscription rs : terminate(o)) { b.replay(rs); } } @@ -316,7 +319,7 @@ public void onComplete() { b.addFinal(o); - for (ReplayDisposable rs : terminate(o)) { + for (ReplaySubscription rs : terminate(o)) { b.replay(rs); } } @@ -328,7 +331,7 @@ interface ReplayBuffer { void addFinal(Object notificationLite); - void replay(ReplayDisposable rs); + void replay(ReplaySubscription rs); int size(); @@ -337,23 +340,34 @@ interface ReplayBuffer { T[] getValues(T[] array); } - static final class ReplayDisposable extends AtomicInteger implements Disposable { + static final class ReplaySubscription extends AtomicInteger implements Subscription { /** */ private static final long serialVersionUID = 466549804534799122L; - final NbpSubscriber actual; + final Subscriber actual; final State state; Object index; + final AtomicLong requested; + volatile boolean cancelled; - public ReplayDisposable(NbpSubscriber actual, State state) { + public ReplaySubscription(Subscriber actual, State state) { this.actual = actual; this.state = state; + this.requested = new AtomicLong(); + } + @Override + public void request(long n) { + if (SubscriptionHelper.validateRequest(n)) { + return; + } + BackpressureHelper.add(requested, n); + state.buffer.replay(this); } @Override - public void dispose() { + public void cancel() { if (!cancelled) { cancelled = true; state.remove(this); @@ -442,14 +456,14 @@ public T[] getValues(T[] array) { @Override @SuppressWarnings("unchecked") - public void replay(ReplayDisposable rs) { + public void replay(ReplaySubscription rs) { if (rs.getAndIncrement() != 0) { return; } int missed = 1; final List b = buffer; - final NbpSubscriber a = rs.actual; + final Subscriber a = rs.actual; Integer indexObject = (Integer)rs.index; int index = 0; @@ -468,6 +482,9 @@ public void replay(ReplayDisposable rs) { } int s = size; + long r = rs.requested.get(); + boolean unbounded = r == Long.MAX_VALUE; + long e = 0L; while (s != index) { @@ -494,11 +511,25 @@ public void replay(ReplayDisposable rs) { } } + if (r == 0) { + r = rs.requested.get() + e; + if (r == 0) { + break; + } + } + a.onNext((T)o); + r--; + e--; index++; } - if (index != size) { + if (e != 0L) { + if (!unbounded) { + r = rs.requested.addAndGet(e); + } + } + if (index != size && r != 0L) { continue; } @@ -663,13 +694,13 @@ public T[] getValues(T[] array) { @Override @SuppressWarnings("unchecked") - public void replay(ReplayDisposable rs) { + public void replay(ReplaySubscription rs) { if (rs.getAndIncrement() != 0) { return; } int missed = 1; - final NbpSubscriber a = rs.actual; + final Subscriber a = rs.actual; Node index = (Node)rs.index; if (index == null) { @@ -683,6 +714,10 @@ public void replay(ReplayDisposable rs) { return; } + long r = rs.requested.get(); + boolean unbounded = r == Long.MAX_VALUE; + long e = 0; + for (;;) { if (rs.cancelled) { rs.index = null; @@ -711,12 +746,27 @@ public void replay(ReplayDisposable rs) { } } + if (r == 0) { + r = rs.requested.get() + e; + if (r == 0) { + break; + } + } + a.onNext((T)o); + r--; + e--; index = n; } - if (index.get() != null) { + if (e != 0L) { + if (!unbounded) { + r = rs.requested.addAndGet(e); + } + } + + if (index.get() != null && r != 0L) { continue; } @@ -912,13 +962,13 @@ public T[] getValues(T[] array) { @Override @SuppressWarnings("unchecked") - public void replay(ReplayDisposable rs) { + public void replay(ReplaySubscription rs) { if (rs.getAndIncrement() != 0) { return; } int missed = 1; - final NbpSubscriber a = rs.actual; + final Subscriber a = rs.actual; TimedNode index = (TimedNode)rs.index; if (index == null) { @@ -945,6 +995,10 @@ public void replay(ReplayDisposable rs) { return; } + long r = rs.requested.get(); + boolean unbounded = r == Long.MAX_VALUE; + long e = 0; + for (;;) { if (rs.cancelled) { rs.index = null; @@ -973,12 +1027,27 @@ public void replay(ReplayDisposable rs) { } } + if (r == 0) { + r = rs.requested.get() + e; + if (r == 0) { + break; + } + } + a.onNext((T)o); + r--; + e--; index = n; } - if (index.get() != null) { + if (e != 0L) { + if (!unbounded) { + r = rs.requested.addAndGet(e); + } + } + + if (index.get() != null && r != 0L) { continue; } @@ -1011,4 +1080,4 @@ public int size() { return s; } } -} +} \ No newline at end of file diff --git a/src/main/java/io/reactivex/subjects/nbp/NbpSerializedSubject.java b/src/main/java/io/reactivex/processors/SerializedProcessor.java similarity index 82% rename from src/main/java/io/reactivex/subjects/nbp/NbpSerializedSubject.java rename to src/main/java/io/reactivex/processors/SerializedProcessor.java index ff32dadb15..12268c81b9 100644 --- a/src/main/java/io/reactivex/subjects/nbp/NbpSerializedSubject.java +++ b/src/main/java/io/reactivex/processors/SerializedProcessor.java @@ -11,9 +11,10 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects.nbp; +package io.reactivex.processors; + +import org.reactivestreams.*; -import io.reactivex.disposables.Disposable; import io.reactivex.functions.Predicate; import io.reactivex.internal.util.*; import io.reactivex.plugins.RxJavaPlugins; @@ -25,9 +26,9 @@ * @param the source value type * @param the subject's result value type */ -/* public */ final class NbpSerializedSubject extends NbpSubject { +/* public */ final class SerializedProcessor extends FlowProcessor { /** The actual subscriber to serialize Subscriber calls to. */ - final NbpSubject actual; + final FlowProcessor actual; /** Indicates an emission is going on, guarted by this. */ boolean emitting; /** If not null, it holds the missed NotificationLite events. */ @@ -39,10 +40,10 @@ * Constructor that wraps an actual subject. * @param actual the subject wrapped */ - public NbpSerializedSubject(final NbpSubject actual) { - super(new io.reactivex.NbpObservable.NbpOnSubscribe() { + public SerializedProcessor(final FlowProcessor actual) { + super(new Publisher() { @Override - public void accept(io.reactivex.NbpObservable.NbpSubscriber s) { + public void subscribe(Subscriber s) { actual.subscribe(s); } }); @@ -50,8 +51,27 @@ public void accept(io.reactivex.NbpObservable.NbpSubscriber s) { } @Override - public void onSubscribe(Disposable s) { - // NO-OP + public void onSubscribe(Subscription s) { + if (done) { + return; + } + synchronized (this) { + if (done) { + return; + } + if (emitting) { + AppendOnlyLinkedArrayList q = queue; + if (q == null) { + q = new AppendOnlyLinkedArrayList(4); + queue = q; + } + q.add(NotificationLite.subscription(s)); + return; + } + emitting = true; + } + actual.onSubscribe(s); + emitLoop(); } @Override @@ -150,17 +170,17 @@ void emitLoop() { q.forEachWhile(consumer); } } - + final Predicate consumer = new Predicate() { @Override public boolean test(Object v) { - return accept(v); + return SerializedProcessor.this.accept(v); } }; /** Delivers the notification to the actual subscriber. */ boolean accept(Object o) { - return NotificationLite.accept(o, actual); + return NotificationLite.acceptFull(o, actual); } @Override diff --git a/src/main/java/io/reactivex/subjects/nbp/NbpUnicastSubject.java b/src/main/java/io/reactivex/processors/UnicastProcessor.java similarity index 76% rename from src/main/java/io/reactivex/subjects/nbp/NbpUnicastSubject.java rename to src/main/java/io/reactivex/processors/UnicastProcessor.java index 2efca09044..3ae0a417d9 100644 --- a/src/main/java/io/reactivex/subjects/nbp/NbpUnicastSubject.java +++ b/src/main/java/io/reactivex/processors/UnicastProcessor.java @@ -11,14 +11,16 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects.nbp; +package io.reactivex.processors; import java.util.Queue; import java.util.concurrent.atomic.*; -import io.reactivex.disposables.Disposable; -import io.reactivex.internal.disposables.EmptyDisposable; +import org.reactivestreams.*; + import io.reactivex.internal.queue.SpscLinkedArrayQueue; +import io.reactivex.internal.subscriptions.*; +import io.reactivex.internal.util.BackpressureHelper; /** * Subject that allows only a single Subscriber to subscribe to it during its lifetime. @@ -34,14 +36,14 @@ * * @param the value type unicasted */ -public final class NbpUnicastSubject extends NbpSubject { +public final class UnicastProcessor extends FlowProcessor { /** * Creates an UnicastSubject with an internal buffer capacity hint 16. * @param the value type * @return an UnicastSubject instance */ - public static NbpUnicastSubject create() { + public static UnicastProcessor create() { return create(16); } @@ -51,7 +53,7 @@ public static NbpUnicastSubject create() { * @param capacityHint the hint to size the internal unbounded buffer * @return an UnicastSubject instance */ - public static NbpUnicastSubject create(int capacityHint) { + public static UnicastProcessor create(int capacityHint) { return create(capacityHint, null); } @@ -67,9 +69,9 @@ public static NbpUnicastSubject create(int capacityHint) { * @param onCancelled the optional callback * @return an UnicastSubject instance */ - public static NbpUnicastSubject create(int capacityHint, Runnable onCancelled) { + public static UnicastProcessor create(int capacityHint, Runnable onCancelled) { State state = new State(capacityHint, onCancelled); - return new NbpUnicastSubject(state); + return new UnicastProcessor(state); } /** The subject state. */ @@ -78,7 +80,7 @@ public static NbpUnicastSubject create(int capacityHint, Runnable onCance * Constructs the Observable base class. * @param state the subject state */ - protected NbpUnicastSubject(State state) { + protected UnicastProcessor(State state) { super(state); this.state = state; } @@ -94,8 +96,26 @@ static abstract class StatePad0 extends AtomicInteger { volatile long p8a, p9a, p10a, p11a, p12a, p13a, p14a, p15a; } + /** Contains the requested counter. */ + static abstract class StateRequested extends StatePad0 { + /** */ + private static final long serialVersionUID = -2744070795149472578L; + /** Holds the current requested amount. */ + final AtomicLong requested = new AtomicLong(); + } + + /** Pads away the requested counter. */ + static abstract class StatePad1 extends StateRequested { + /** */ + private static final long serialVersionUID = -446575186947206398L; + /** Cache line padding 3. */ + volatile long p1b, p2b, p3b, p4b, p5b, p6b, p7b; + /** Cache line padding 4. */ + volatile long p8b, p9b, p10b, p11b, p12b, p13b, p14b, p15b; + } + /** The state of the UnicastSubject. */ - static final class State extends StatePad0 implements NbpOnSubscribe, Disposable, NbpSubscriber { + static final class State extends StatePad1 implements Publisher, Subscription, Subscriber { /** */ private static final long serialVersionUID = 5058617037583835632L; @@ -103,7 +123,7 @@ static final class State extends StatePad0 implements NbpOnSubscribe, Disp final Queue queue; /** The single subscriber. */ - final AtomicReference> subscriber = new AtomicReference>(); + final AtomicReference> subscriber = new AtomicReference>(); /** Indicates the single subscriber has cancelled. */ volatile boolean cancelled; @@ -137,19 +157,40 @@ public State(int capacityHint, Runnable onCancelled) { } @Override - public void accept(NbpSubscriber s) { + public void subscribe(Subscriber s) { if (!once.get() && once.compareAndSet(false, true)) { s.onSubscribe(this); subscriber.lazySet(s); // full barrier in drain + if (cancelled) { + subscriber.lazySet(null); + return; + } drain(); } else { - s.onSubscribe(EmptyDisposable.INSTANCE); - s.onError(new IllegalStateException("Only a single subscriber allowed.")); + if (done) { + Throwable e = error; + if (e != null) { + EmptySubscription.error(e, s); + } else { + EmptySubscription.complete(s); + } + } else { + EmptySubscription.error(new IllegalStateException("Only a single subscriber allowed."), s); + } } } @Override - public void dispose() { + public void request(long n) { + if (SubscriptionHelper.validateRequest(n)) { + return; + } + BackpressureHelper.add(requested, n); + drain(); + } + + @Override + public void cancel() { if (!cancelled) { cancelled = true; @@ -178,10 +219,12 @@ void clear(Queue q) { } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Subscription s) { if (done || cancelled) { - s.dispose(); + s.cancel(); + return; } + s.request(Long.MAX_VALUE); } @Override @@ -225,7 +268,7 @@ void drain() { } final Queue q = queue; - NbpSubscriber a = subscriber.get(); + Subscriber a = subscriber.get(); int missed = 1; for (;;) { @@ -251,7 +294,11 @@ void drain() { return; } - for (;;) { + long r = requested.get(); + boolean unbounded = r == Long.MAX_VALUE; + long e = 0L; + + while (r != 0L) { if (cancelled) { clear(q); @@ -279,7 +326,15 @@ void drain() { } a.onNext(v); + + r--; + e--; } + + if (e != 0 && !unbounded) { + requested.getAndAdd(e); + } + } missed = addAndGet(-missed); @@ -295,7 +350,7 @@ void drain() { } @Override - public void onSubscribe(Disposable s) { + public void onSubscribe(Subscription s) { state.onSubscribe(s); } diff --git a/src/main/java/io/reactivex/subjects/AsyncSubject.java b/src/main/java/io/reactivex/subjects/AsyncSubject.java index 7a8c0febff..8d58590a85 100644 --- a/src/main/java/io/reactivex/subjects/AsyncSubject.java +++ b/src/main/java/io/reactivex/subjects/AsyncSubject.java @@ -10,124 +10,66 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects; -import java.util.Arrays; -import java.util.concurrent.atomic.*; +package io.reactivex.subjects; -import org.reactivestreams.*; +import java.lang.reflect.Array; +import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.functions.IntFunction; -import io.reactivex.internal.util.*; +import io.reactivex.Observer; +import io.reactivex.disposables.*; +import io.reactivex.internal.util.NotificationLite; import io.reactivex.plugins.RxJavaPlugins; /** - * A Subject that emits the very last value followed by a completion event or the received error to Subscribers. + * An NbpSubject that emits the very last value followed by a completion event or the received error to NbpSubscribers. * *

The implementation of onXXX methods are technically thread-safe but non-serialized calls - * to them may lead to undefined state in the currently subscribed Subscribers. + * to them may lead to undefined state in the currently subscribed NbpSubscribers. * - *

Due to the nature Observables are constructed, the AsyncSubject can't be instantiated through + *

Due to the nature Observables are constructed, the NbpAsyncSubject can't be instantiated through * {@code new} but must be created via the {@link #create()} method. * * @param the value type */ + public final class AsyncSubject extends Subject { - - /** - * Constructs an empty AsyncSubject. - * @param the observed and observable value type - * @return the new AsyncSubject instance. - */ public static AsyncSubject create() { State state = new State(); return new AsyncSubject(state); } - /** The state holding onto the latest value or error and the array of subscribers. */ final State state; - /** - * Indicates the subject has been terminated. It is checked in the onXXX methods in - * a relaxed matter: concurrent calls may not properly see it (which shouldn't happen if - * the reactive-streams contract is held). - */ - boolean done; - protected AsyncSubject(State state) { super(state); this.state = state; } @Override - public void onSubscribe(Subscription s) { - if (done) { - s.cancel(); - return; + public void onSubscribe(Disposable d) { + if (state.subscribers.get() == State.TERMINATED) { + d.dispose(); } - s.request(Long.MAX_VALUE); } @Override - public void onNext(T t) { - if (done) { - return; - } - if (t == null) { - onError(new NullPointerException()); - return; - } - state.lazySet(t); + public void onNext(T value) { + state.onNext(value); } @Override - public void onError(Throwable t) { - if (done) { - RxJavaPlugins.onError(t); - return; - } - if (t == null) { - t = new NullPointerException(); - } - done = true; - state.lazySet(NotificationLite.error(t)); - for (AsyncSubscription as : state.terminate()) { - as.setError(t); - } + public void onError(Throwable e) { + state.onError(e); } @Override public void onComplete() { - if (done) { - return; - } - done = true; - @SuppressWarnings("unchecked") - T value = (T)state.get(); - for (AsyncSubscription as : state.terminate()) { - as.setValue(value); - } + state.onComplete(); } @Override public boolean hasSubscribers() { - return state.subscribers().length != 0; - } - - @Override - public boolean hasValue() { - Object o = state.get(); - return o != null && !NotificationLite.isError(o); - } - - @Override - public boolean hasComplete() { - Object o = state.get(); - return state.subscribers() == State.TERMINATED && !NotificationLite.isError(o); - } - - @Override - public boolean hasThrowable() { - return NotificationLite.isError(state.get()); + return state.subscribers.get().length != 0; } @Override @@ -140,27 +82,37 @@ public Throwable getThrowable() { } @Override - @SuppressWarnings("unchecked") public T getValue() { Object o = state.get(); - if (o != null && !NotificationLite.isError(o)) { - return (T)o; + if (o != null) { + if (NotificationLite.isComplete(o) || NotificationLite.isError(o)) { + return null; + } + return NotificationLite.getValue(o); } return null; } - @Override @SuppressWarnings("unchecked") + @Override public T[] getValues(T[] array) { Object o = state.get(); - if (o != null && !NotificationLite.isError(o) && !NotificationLite.isComplete(o)) { - int n = array.length; - if (n == 0) { - array = Arrays.copyOf(array, 1); - } - array[0] = (T)o; - if (array.length > 1) { - array[1] = null; + if (o != null) { + if (NotificationLite.isComplete(o) || NotificationLite.isError(o)) { + if (array.length != 0) { + array[0] = null; + } + } else { + T v = NotificationLite.getValue(o); + if (array.length != 0) { + array[0] = v; + if (array.length != 1) { + array[1] = null; + } + } else { + array = (T[])Array.newInstance(array.getClass().getComponentType(), 1); + array[0] = v; + } } } else { if (array.length != 0) { @@ -169,205 +121,186 @@ public T[] getValues(T[] array) { } return array; } - /** - * The state of the AsyncSubject. - * - * @param the value type - */ - @SuppressWarnings("rawtypes") - static final class State extends AtomicReference - implements Publisher, IntFunction[]> { - + + @Override + public boolean hasComplete() { + return state.subscribers.get() == State.TERMINATED && !NotificationLite.isError(state.get()); + } + + @Override + public boolean hasThrowable() { + return NotificationLite.isError(state.get()); + } + + @Override + public boolean hasValue() { + Object o = state.get(); + return o != null && !NotificationLite.isComplete(o) && !NotificationLite.isError(o); + } + + static final class State extends AtomicReference implements NbpOnSubscribe, Observer { /** */ - private static final long serialVersionUID = 2983503212425065796L; + private static final long serialVersionUID = 4876574210612691772L; - /** An empty AsyncSubscription array to avoid allocating it in remove. */ - static final AsyncSubscription[] EMPTY = new AsyncSubscription[0]; - /** An empty array indicating a terminal state .*/ - static final AsyncSubscription[] TERMINATED = new AsyncSubscription[0]; + final AtomicReference[]> subscribers; - /** The array of current subscribers. */ - @SuppressWarnings("unchecked") - final AtomicReference[]> subscribers = new AtomicReference[]>(EMPTY); - - /** - * Returns the array of current subscribers. - * @return the array of current subscribers - */ - public AsyncSubscription[] subscribers() { - return subscribers.get(); - } + @SuppressWarnings("rawtypes") + static final Observer[] EMPTY = new Observer[0]; + @SuppressWarnings("rawtypes") + static final Observer[] TERMINATED = new Observer[0]; - /** - * Terminates the state and returns the last array of subscribers. - * @return the last array of subscribers - */ - @SuppressWarnings("unchecked") - public AsyncSubscription[] terminate() { - return TerminalAtomicsHelper.terminate(subscribers, TERMINATED); - } - - /** - * Atomically tries to add the AsyncSubscription to the subscribers array - * or returns false if the state has been terminated. - * @param as the AsyncSubscription to add - * @return true if successful, false if the state has been terminated - */ - @SuppressWarnings("unchecked") - boolean add(AsyncSubscription as) { - return TerminalAtomicsHelper.add(subscribers, as, TERMINATED, this); - } + boolean done; - /** - * Atomically removes the given AsyncSubscription. - * @param as the AsyncSubscription to remove - */ @SuppressWarnings("unchecked") - void remove(AsyncSubscription as) { - TerminalAtomicsHelper.remove(subscribers, as, TERMINATED, EMPTY, this); + public State() { + subscribers = new AtomicReference[]>(EMPTY); } - @SuppressWarnings("unchecked") - @Override - public AsyncSubscription[] apply(int value) { - return new AsyncSubscription[value]; + boolean add(Observer s) { + for (;;) { + Observer[] a = subscribers.get(); + if (a == TERMINATED) { + return false; + } + int n = a.length; + + @SuppressWarnings("unchecked") + Observer[] b = new Observer[n + 1]; + System.arraycopy(a, 0, b, 0, n); + b[n] = s; + + if (subscribers.compareAndSet(a, b)) { + return true; + } + } } - @Override @SuppressWarnings("unchecked") - public void subscribe(Subscriber t) { - AsyncSubscription as = new AsyncSubscription(t, this); - t.onSubscribe(as); - - if (add(as)) { - if (as.isDone()) { - remove(as); + void remove(Observer s) { + for (;;) { + Observer[] a = subscribers.get(); + if (a == TERMINATED || a == EMPTY) { + return; } - } else { - Object o = get(); - if (NotificationLite.isError(o)) { - as.setError(NotificationLite.getError(o)); + int n = a.length; + int j = -1; + for (int i = 0; i < n; i++) { + Observer e = a[i]; + if (e.equals(s)) { + j = i; + break; + } + } + if (j < 0) { + return; + } + Observer[] b; + if (n == 1) { + b = EMPTY; } else { - as.setValue((T)o); + b = new Observer[n - 1]; + System.arraycopy(a, 0, b, 0, j); + System.arraycopy(a, j + 1, b, j, n - j - 1); + } + if (subscribers.compareAndSet(a, b)) { + return; } } } - } - - /** - * A subscription implementation that wraps the actual Subscriber and manages the request and cancel calls. - * - * @param the value type - */ - static final class AsyncSubscription extends AtomicInteger implements Subscription { - /** */ - private static final long serialVersionUID = 2900823026377918858L; - /** The actual subscriber. */ - final Subscriber actual; - /** The AsyncSubject state containing the value. */ - final State state; - /** State management: no request and no value has been set. */ - static final int NO_REQUEST_NO_VALUE = 0; - /** State management: no request but value is available. */ - static final int NO_REQUEST_HAS_VALUE = 1; - /** State management: a positive request has been made but no value is available. */ - static final int HAS_REQUEST_NO_VALUE = 2; - /** State management: both positive request and value is available, terminal state. */ - static final int HAS_REQUEST_HAS_VALUE = 3; + @SuppressWarnings("unchecked") + Observer[] terminate(Object notification) { + if (compareAndSet(get(), notification)) { + Observer[] a = subscribers.get(); + if (a != TERMINATED) { + return subscribers.getAndSet(TERMINATED); + } + } + return TERMINATED; + } - public AsyncSubscription(Subscriber actual, State state) { - this.actual = actual; - this.state = state; + void emit(Observer t, Object v) { + if (NotificationLite.isComplete(v)) { + t.onComplete(); + } else + if (NotificationLite.isError(v)) { + t.onError(NotificationLite.getError(v)); + } else { + t.onNext(NotificationLite.getValue(v)); + t.onComplete(); + } } - /** - * Indicates the given value is available and emits it to the actual Subscriber if - * it has requested. - * @param value the value to emit - */ - public void setValue(T value) { - for (;;) { - int s = get(); - if (s == NO_REQUEST_HAS_VALUE || s == HAS_REQUEST_HAS_VALUE) { - return; - } else - if (s == NO_REQUEST_NO_VALUE) { - if (compareAndSet(NO_REQUEST_NO_VALUE, NO_REQUEST_HAS_VALUE)) { - return; - } - } else - if (s == HAS_REQUEST_NO_VALUE) { - lazySet(HAS_REQUEST_HAS_VALUE); // setValue is called once, no need for CAS - if (value != null) { - actual.onNext(value); - } - actual.onComplete(); + @Override + public void accept(final Observer t) { + BooleanDisposable bd = new BooleanDisposable(new Runnable() { + @Override + public void run() { + remove(t); + } + }); + t.onSubscribe(bd); + if (add(t)) { + if (bd.isDisposed()) { + remove(t); } + return; } + Object v = get(); + emit(t, v); } - /** - * Terminates the AsyncSubscription and emits the given error - * if not already terminated. - * @param e the Throwable to emit to the Subscriber - */ - public void setError(Throwable e) { - int s = get(); - if (s != HAS_REQUEST_HAS_VALUE) { - s = getAndSet(HAS_REQUEST_HAS_VALUE); - if (s != HAS_REQUEST_HAS_VALUE) { - actual.onError(e); - } + @Override + public void onSubscribe(Disposable d) { + if (done) { + d.dispose(); } } @Override - public void request(long n) { - if (n <= 0) { - RxJavaPlugins.onError(new IllegalArgumentException("n > 0 required but it was " + n)); + public void onNext(T value) { + if (done) { return; } - for (;;) { - int s = get(); - if (s == HAS_REQUEST_NO_VALUE || s == HAS_REQUEST_HAS_VALUE) { - return; - } else - if (s == NO_REQUEST_NO_VALUE) { - if (compareAndSet(NO_REQUEST_NO_VALUE, HAS_REQUEST_NO_VALUE)) { - return; - } - } else { - if (compareAndSet(NO_REQUEST_HAS_VALUE, HAS_REQUEST_HAS_VALUE)) { - @SuppressWarnings("unchecked") - T v = (T)state.get(); - if (v != null) { - actual.onNext(v); - } - actual.onComplete(); - return; - } - } + if (value == null) { + onError(new NullPointerException()); + return; } + lazySet(value); } @Override - public void cancel() { - int s = get(); - if (s != HAS_REQUEST_HAS_VALUE) { - s = getAndSet(HAS_REQUEST_HAS_VALUE); - if (s != HAS_REQUEST_HAS_VALUE) { - state.remove(this); - } + public void onError(Throwable e) { + if (done) { + RxJavaPlugins.onError(e); + return; + } + done = true; + if (e == null) { + e = new NullPointerException(); + } + for (Observer v : terminate(NotificationLite.error(e))) { + v.onError(e); } } - /** - * Returns true if the AsyncSubscription has reached its terminal state. - * @return true if the AsyncSubscription has reached its terminal state - */ - boolean isDone() { - return get() == HAS_REQUEST_HAS_VALUE; + @Override + public void onComplete() { + if (done) { + return; + } + done = true; + T value = NotificationLite.getValue(get()); + if (value == null) { + for (Observer v : terminate(NotificationLite.complete())) { + v.onComplete(); + } + } else { + for (Observer v : terminate(NotificationLite.next(value))) { + v.onNext(value); + v.onComplete(); + } + } } } -} +} \ No newline at end of file diff --git a/src/main/java/io/reactivex/subjects/BehaviorSubject.java b/src/main/java/io/reactivex/subjects/BehaviorSubject.java index 5d1c5836ec..979a008e3a 100644 --- a/src/main/java/io/reactivex/subjects/BehaviorSubject.java +++ b/src/main/java/io/reactivex/subjects/BehaviorSubject.java @@ -14,14 +14,13 @@ package io.reactivex.subjects; import java.lang.reflect.Array; -import java.util.concurrent.atomic.*; +import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.*; -import org.reactivestreams.*; - +import io.reactivex.Observer; +import io.reactivex.disposables.Disposable; import io.reactivex.functions.Predicate; import io.reactivex.internal.functions.Objects; -import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.*; import io.reactivex.plugins.RxJavaPlugins; @@ -32,7 +31,7 @@ public static BehaviorSubject create() { return new BehaviorSubject(state); } - // TODO a plain create() would create a method ambiguity with Observable.create with javac + // A plain create(T) would create a method ambiguity with Observable.create with javac public static BehaviorSubject createDefault(T defaultValue) { Objects.requireNonNull(defaultValue, "defaultValue is null"); State state = new State(); @@ -47,7 +46,7 @@ protected BehaviorSubject(State state) { } @Override - public void onSubscribe(Subscription s) { + public void onSubscribe(Disposable s) { state.onSubscribe(s); } @@ -142,19 +141,19 @@ public boolean hasValue() { return o != null && !NotificationLite.isComplete(o) && !NotificationLite.isError(o); } - static final class State extends AtomicReference implements Publisher, Subscriber { + static final class State extends AtomicReference implements NbpOnSubscribe, Observer { /** */ private static final long serialVersionUID = -4311717003288339429L; boolean done; - final AtomicReference[]> subscribers; + final AtomicReference[]> subscribers; @SuppressWarnings("rawtypes") - static final BehaviorSubscription[] EMPTY = new BehaviorSubscription[0]; + static final BehaviorDisposable[] EMPTY = new BehaviorDisposable[0]; @SuppressWarnings("rawtypes") - static final BehaviorSubscription[] TERMINATED = new BehaviorSubscription[0]; + static final BehaviorDisposable[] TERMINATED = new BehaviorDisposable[0]; long index; @@ -167,18 +166,18 @@ public State() { this.lock = new ReentrantReadWriteLock(); this.readLock = lock.readLock(); this.writeLock = lock.writeLock(); - this.subscribers = new AtomicReference[]>(EMPTY); + this.subscribers = new AtomicReference[]>(EMPTY); } - public boolean add(BehaviorSubscription rs) { + public boolean add(BehaviorDisposable rs) { for (;;) { - BehaviorSubscription[] a = subscribers.get(); + BehaviorDisposable[] a = subscribers.get(); if (a == TERMINATED) { return false; } int len = a.length; @SuppressWarnings("unchecked") - BehaviorSubscription[] b = new BehaviorSubscription[len + 1]; + BehaviorDisposable[] b = new BehaviorDisposable[len + 1]; System.arraycopy(a, 0, b, 0, len); b[len] = rs; if (subscribers.compareAndSet(a, b)) { @@ -188,9 +187,9 @@ public boolean add(BehaviorSubscription rs) { } @SuppressWarnings("unchecked") - public void remove(BehaviorSubscription rs) { + public void remove(BehaviorDisposable rs) { for (;;) { - BehaviorSubscription[] a = subscribers.get(); + BehaviorDisposable[] a = subscribers.get(); if (a == TERMINATED || a == EMPTY) { return; } @@ -206,11 +205,11 @@ public void remove(BehaviorSubscription rs) { if (j < 0) { return; } - BehaviorSubscription[] b; + BehaviorDisposable[] b; if (len == 1) { b = EMPTY; } else { - b = new BehaviorSubscription[len - 1]; + b = new BehaviorDisposable[len - 1]; System.arraycopy(a, 0, b, 0, j); System.arraycopy(a, j + 1, b, j, len - j - 1); } @@ -221,9 +220,9 @@ public void remove(BehaviorSubscription rs) { } @SuppressWarnings("unchecked") - public BehaviorSubscription[] terminate(Object terminalValue) { + public BehaviorDisposable[] terminate(Object terminalValue) { - BehaviorSubscription[] a = subscribers.get(); + BehaviorDisposable[] a = subscribers.get(); if (a != TERMINATED) { a = subscribers.getAndSet(TERMINATED); if (a != TERMINATED) { @@ -236,8 +235,8 @@ public BehaviorSubscription[] terminate(Object terminalValue) { } @Override - public void subscribe(Subscriber s) { - BehaviorSubscription bs = new BehaviorSubscription(s, this); + public void accept(Observer s) { + BehaviorDisposable bs = new BehaviorDisposable(s, this); s.onSubscribe(bs); if (!bs.cancelled) { if (add(bs)) { @@ -258,12 +257,11 @@ public void subscribe(Subscriber s) { } @Override - public void onSubscribe(Subscription s) { + public void onSubscribe(Disposable s) { if (done) { - s.cancel(); + s.dispose(); return; } - s.request(Long.MAX_VALUE); } void setCurrent(Object o) { @@ -283,7 +281,7 @@ public void onNext(T t) { } Object o = NotificationLite.next(t); setCurrent(o); - for (BehaviorSubscription bs : subscribers.get()) { + for (BehaviorDisposable bs : subscribers.get()) { bs.emitNext(o, index); } } @@ -296,7 +294,7 @@ public void onError(Throwable t) { } done = true; Object o = NotificationLite.error(t); - for (BehaviorSubscription bs : terminate(o)) { + for (BehaviorDisposable bs : terminate(o)) { bs.emitNext(o, index); } } @@ -308,17 +306,15 @@ public void onComplete() { } done = true; Object o = NotificationLite.complete(); - for (BehaviorSubscription bs : terminate(o)) { + for (BehaviorDisposable bs : terminate(o)) { bs.emitNext(o, index); // relaxed read okay since this is the only mutator thread } } } - static final class BehaviorSubscription extends AtomicLong implements Subscription, Predicate { - /** */ - private static final long serialVersionUID = 3293175281126227086L; + static final class BehaviorDisposable implements Disposable, Predicate { - final Subscriber actual; + final Observer actual; final State state; boolean next; @@ -331,22 +327,13 @@ static final class BehaviorSubscription extends AtomicLong implements Subscri long index; - public BehaviorSubscription(Subscriber actual, State state) { + public BehaviorDisposable(Observer actual, State state) { this.actual = actual; this.state = state; } @Override - public void request(long n) { - if (SubscriptionHelper.validateRequest(n)) { - return; - } - - BackpressureHelper.add(this, n); - } - - @Override - public void cancel() { + public void dispose() { if (!cancelled) { cancelled = true; @@ -368,14 +355,14 @@ void emitFirst() { } State s = state; + Lock lock = s.readLock; - Lock readLock = s.readLock; - readLock.lock(); + lock.lock(); try { index = s.index; o = s.get(); } finally { - readLock.unlock(); + lock.unlock(); } emitting = o != null; @@ -425,29 +412,7 @@ public boolean test(Object o) { if (cancelled) { return true; } - - if (NotificationLite.isComplete(o)) { - cancel(); - actual.onComplete(); - return true; - } else - if (NotificationLite.isError(o)) { - cancel(); - actual.onError(NotificationLite.getError(o)); - return true; - } - - long r = get(); - if (r != 0L) { - actual.onNext(NotificationLite.getValue(o)); - if (r != Long.MAX_VALUE) { - decrementAndGet(); - } - return false; - } - cancel(); - actual.onError(new IllegalStateException("Could not deliver value due to lack of requests")); - return true; + return NotificationLite.accept(o, actual); } void emitLoop() { diff --git a/src/main/java/io/reactivex/subjects/PublishSubject.java b/src/main/java/io/reactivex/subjects/PublishSubject.java index 78db4506f5..bf57cff0e7 100644 --- a/src/main/java/io/reactivex/subjects/PublishSubject.java +++ b/src/main/java/io/reactivex/subjects/PublishSubject.java @@ -10,118 +10,63 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects; -import java.util.concurrent.atomic.*; +package io.reactivex.subjects; -import org.reactivestreams.*; +import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.exceptions.MissingBackpressureException; -import io.reactivex.functions.IntFunction; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.*; +import io.reactivex.Observer; +import io.reactivex.disposables.*; +import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.internal.util.NotificationLite; import io.reactivex.plugins.RxJavaPlugins; -/** - * A Subject that multicasts events to Subscribers that are currently subscribed to it. - * - *

The subject does not coordinate backpressure for its subscribers and implements a weaker onSubscribe which - * calls requests Long.MAX_VALUE from the incoming Subscriptions. This makes it possible to subscribe the PublishSubject - * to multiple sources (note on serialization though) unlike the standard contract on Subscriber. Child subscribers, however, are not overflown but receive an - * IllegalStateException in case their requested amount is zero. - * - *

The implementation of onXXX methods are technically thread-safe but non-serialized calls - * to them may lead to undefined state in the currently subscribed Subscribers. - * - *

Due to the nature Observables are constructed, the PublishSubject can't be instantiated through - * {@code new} but must be created via the {@link #create()} method. - * - * @param the value type multicast to Subscribers. - */ public final class PublishSubject extends Subject { - - /** - * Constructs a PublishSubject. - * @param the value type - * @return the new PublishSubject - */ public static PublishSubject create() { State state = new State(); return new PublishSubject(state); } - /** Holds the terminal event and manages the array of subscribers. */ final State state; - /** - * Indicates the subject has been terminated. It is checked in the onXXX methods in - * a relaxed matter: concurrent calls may not properly see it (which shouldn't happen if - * the reactive-streams contract is held). - */ - boolean done; - protected PublishSubject(State state) { super(state); this.state = state; } @Override - public void onSubscribe(Subscription s) { - if (done) { - s.cancel(); - return; + public void onSubscribe(Disposable d) { + if (state.done) { + d.dispose(); } - // PublishSubject doesn't bother with request coordination. - s.request(Long.MAX_VALUE); } @Override - public void onNext(T t) { - if (done) { - return; - } - if (t == null) { - onError(new NullPointerException()); - return; - } - for (PublishSubscriber s : state.subscribers()) { - s.onNext(t); - } + public void onNext(T value) { + state.onNext(value); } @Override - public void onError(Throwable t) { - if (done) { - RxJavaPlugins.onError(t); - return; - } - done = true; - if (t == null) { - t = new NullPointerException(); - } - for (PublishSubscriber s : state.terminate(t)) { - s.onError(t); - } + public void onError(Throwable e) { + state.onError(e); } @Override public void onComplete() { - if (done) { - return; - } - done = true; - for (PublishSubscriber s : state.terminate()) { - s.onComplete(); - } + state.onComplete(); } @Override public boolean hasSubscribers() { - return state.subscribers().length != 0; + return state.subscribers.get().length != 0; } @Override - public boolean hasValue() { - return false; + public Throwable getThrowable() { + Object o = state.get(); + if (NotificationLite.isError(o)) { + return NotificationLite.getError(o); + } + return null; } @Override @@ -138,195 +83,181 @@ public T[] getValues(T[] array) { } @Override - public Throwable getThrowable() { + public boolean hasComplete() { Object o = state.get(); - if (o == State.COMPLETE) { - return null; - } - return (Throwable)o; + return o != null && !NotificationLite.isError(o); } @Override public boolean hasThrowable() { - Object o = state.get(); - return o != null && o != State.COMPLETE; + return NotificationLite.isError(state.get()); } @Override - public boolean hasComplete() { - return state.get() == State.COMPLETE; + public boolean hasValue() { + return false; } - /** - * Contains the state of the Subject, including the currently subscribed clients and the - * terminal value. - * - * @param the value type of the events - */ - @SuppressWarnings("rawtypes") - static final class State extends AtomicReference - implements Publisher, IntFunction[]> { + static final class State extends AtomicReference implements NbpOnSubscribe, Observer { /** */ - private static final long serialVersionUID = -2699311989055418316L; - /** The completion token. */ - static final Object COMPLETE = new Object(); + private static final long serialVersionUID = 4876574210612691772L; + + final AtomicReference[]> subscribers = new AtomicReference[]>(); - /** The terminated indicator for the subscribers array. */ - static final PublishSubscriber[] TERMINATED = new PublishSubscriber[0]; - /** An empty subscribers array to avoid allocating it all the time. */ - static final PublishSubscriber[] EMPTY = new PublishSubscriber[0]; + @SuppressWarnings("rawtypes") + static final Observer[] EMPTY = new Observer[0]; + @SuppressWarnings("rawtypes") + static final Observer[] TERMINATED = new Observer[0]; - /** The array of currently subscribed subscribers. */ + volatile boolean done; + @SuppressWarnings("unchecked") - final AtomicReference[]> subscribers = new AtomicReference[]>(EMPTY); + public State() { + subscribers.lazySet(EMPTY); + } - @Override - public void subscribe(Subscriber t) { - PublishSubscriber ps = new PublishSubscriber(t, this); - t.onSubscribe(ps); - if (!ps.cancelled.get()) { - if (add(ps)) { - // if cancellation happened while a successful add, the remove() didn't work - // so we need to do it again - if (ps.cancelled.get()) { - remove(ps); - } - } else { - Object o = get(); - if (o == COMPLETE) { - ps.onComplete(); - } else { - ps.onError((Throwable)o); - } + boolean add(Observer s) { + for (;;) { + Observer[] a = subscribers.get(); + if (a == TERMINATED) { + return false; + } + int n = a.length; + + @SuppressWarnings("unchecked") + Observer[] b = new Observer[n + 1]; + System.arraycopy(a, 0, b, 0, n); + b[n] = s; + + if (subscribers.compareAndSet(a, b)) { + return true; } } } - /** - * @return the array of currently subscribed subscribers - */ - PublishSubscriber[] subscribers() { - return subscribers.get(); - } - - /** - * Atomically swaps in the terminal state with a completion indicator and returns - * the last array of subscribers. - * @return the last array of subscribers - */ - PublishSubscriber[] terminate() { - return terminate(COMPLETE); - } - - /** - * Atomically swaps in the terminal state with a completion indicator and returns - * the last array of subscribers. - * @param event the terminal state value to set - * @return the last array of subscribers - */ @SuppressWarnings("unchecked") - PublishSubscriber[] terminate(Object event) { - if (compareAndSet(null, event)) { - return TerminalAtomicsHelper.terminate(subscribers, TERMINATED); + void remove(Observer s) { + for (;;) { + Observer[] a = subscribers.get(); + if (a == TERMINATED || a == EMPTY) { + return; + } + int n = a.length; + int j = -1; + for (int i = 0; i < n; i++) { + Observer e = a[i]; + if (e.equals(s)) { + j = i; + break; + } + } + if (j < 0) { + return; + } + Observer[] b; + if (n == 1) { + b = EMPTY; + } else { + b = new Observer[n - 1]; + System.arraycopy(a, 0, b, 0, j); + System.arraycopy(a, j + 1, b, j, n - j - 1); + } + if (subscribers.compareAndSet(a, b)) { + return; + } } - return TERMINATED; - } - - /** - * Tries to add the given subscriber to the subscribers array atomically - * or returns false if the subject has terminated. - * @param ps the subscriber to add - * @return true if successful, false if the subject has terminated - */ - @SuppressWarnings("unchecked") - boolean add(PublishSubscriber ps) { - return TerminalAtomicsHelper.add(subscribers, ps, TERMINATED, this); - } - - /** - * Atomically removes the given subscriber if it is subscribed to the subject. - * @param ps the subject to remove - */ - @SuppressWarnings("unchecked") - void remove(PublishSubscriber ps) { - TerminalAtomicsHelper.remove(subscribers, ps, TERMINATED, EMPTY, this); } @SuppressWarnings("unchecked") - @Override - public PublishSubscriber[] apply(int value) { - return new PublishSubscriber[value]; - } - } - - /** - * Wraps the actual subscriber, tracks its requests and makes cancellation - * to remove itself from the current subscribers array. - * - * @param the value type - */ - static final class PublishSubscriber extends AtomicLong implements Subscriber, Subscription { - /** */ - private static final long serialVersionUID = 3562861878281475070L; - /** The actual subscriber. */ - final Subscriber actual; - /** The subject state. */ - final State state; - - final AtomicBoolean cancelled = new AtomicBoolean(); - - /** - * Constructs a PublishSubscriber, wraps the actual subscriber and the state. - * @param actual the actual subscriber - * @param state the state - */ - public PublishSubscriber(Subscriber actual, State state) { - this.actual = actual; - this.state = state; + Observer[] terminate(Object notification) { + if (compareAndSet(null, notification)) { + Observer[] a = subscribers.get(); + if (a != TERMINATED) { + return subscribers.getAndSet(TERMINATED); + } + } + return TERMINATED; } - @Override - public void onSubscribe(Subscription s) { - // not called because requests are handled locally and cancel is forwared to state + void emit(Observer t, Object v) { + if (NotificationLite.isComplete(v)) { + t.onComplete(); + } else { + t.onError(NotificationLite.getError(v)); + } } @Override - public void onNext(T t) { - long r = get(); - if (r != 0L) { - actual.onNext(t); - if (r != Long.MAX_VALUE) { - decrementAndGet(); + public void accept(final Observer t) { + Object v = get(); + if (v != null) { + t.onSubscribe(EmptyDisposable.INSTANCE); + emit(t, v); + return; + } + BooleanDisposable bd = new BooleanDisposable(new Runnable() { + @Override + public void run() { + remove(t); } - } else { - cancel(); - actual.onError(new MissingBackpressureException("Could not emit value due to lack of requests")); + }); + t.onSubscribe(bd); + if (add(t)) { + if (bd.isDisposed()) { + remove(t); + } + return; } + v = get(); + emit(t, v); } @Override - public void onError(Throwable t) { - actual.onError(t); + public void onSubscribe(Disposable d) { + if (done) { + d.dispose(); + } } @Override - public void onComplete() { - actual.onComplete(); + public void onNext(T value) { + if (done) { + return; + } + if (value == null) { + onError(new NullPointerException("The value is null")); + return; + } + for (Observer v : subscribers.get()) { + v.onNext(value); + } } @Override - public void request(long n) { - if (SubscriptionHelper.validateRequest(n)) { + public void onError(Throwable e) { + if (done) { + RxJavaPlugins.onError(e); return; } - BackpressureHelper.add(this, n); + done = true; + if (e == null) { + e = new NullPointerException(); + } + + for (Observer v : terminate(NotificationLite.error(e))) { + v.onError(e); + } } @Override - public void cancel() { - if (!cancelled.get() && cancelled.compareAndSet(false, true)) { - state.remove(this); + public void onComplete() { + if (done) { + return; + } + done = true; + for (Observer v : terminate(NotificationLite.complete())) { + v.onComplete(); } } } -} +} \ No newline at end of file diff --git a/src/main/java/io/reactivex/subjects/ReplaySubject.java b/src/main/java/io/reactivex/subjects/ReplaySubject.java index 698604bcf1..412ba9abb5 100644 --- a/src/main/java/io/reactivex/subjects/ReplaySubject.java +++ b/src/main/java/io/reactivex/subjects/ReplaySubject.java @@ -18,12 +18,11 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - +import io.reactivex.Observer; import io.reactivex.Scheduler; +import io.reactivex.disposables.Disposable; import io.reactivex.internal.functions.Objects; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.*; +import io.reactivex.internal.util.NotificationLite; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; @@ -93,7 +92,7 @@ protected ReplaySubject(State state) { } @Override - public void onSubscribe(Subscription s) { + public void onSubscribe(Disposable s) { state.onSubscribe(s); } @@ -168,7 +167,7 @@ public boolean hasValue() { return state.buffer.size(); } - static final class State extends AtomicReference implements Publisher, Subscriber { + static final class State extends AtomicReference implements NbpOnSubscribe, Observer { /** */ private static final long serialVersionUID = -4673197222000219014L; @@ -176,23 +175,23 @@ static final class State extends AtomicReference implements Publisher boolean done; - final AtomicReference[]> subscribers; + final AtomicReference[]> subscribers = new AtomicReference[]>(); @SuppressWarnings("rawtypes") - static final ReplaySubscription[] EMPTY = new ReplaySubscription[0]; + static final ReplayDisposable[] EMPTY = new ReplayDisposable[0]; @SuppressWarnings("rawtypes") - static final ReplaySubscription[] TERMINATED = new ReplaySubscription[0]; + static final ReplayDisposable[] TERMINATED = new ReplayDisposable[0]; @SuppressWarnings("unchecked") public State(ReplayBuffer buffer) { this.buffer = buffer; - this.subscribers = new AtomicReference[]>(EMPTY); + subscribers.lazySet(EMPTY); } @Override - public void subscribe(Subscriber s) { - ReplaySubscription rs = new ReplaySubscription(s, this); + public void accept(Observer s) { + ReplayDisposable rs = new ReplayDisposable(s, this); s.onSubscribe(rs); if (!rs.cancelled) { @@ -206,15 +205,15 @@ public void subscribe(Subscriber s) { } } - public boolean add(ReplaySubscription rs) { + public boolean add(ReplayDisposable rs) { for (;;) { - ReplaySubscription[] a = subscribers.get(); + ReplayDisposable[] a = subscribers.get(); if (a == TERMINATED) { return false; } int len = a.length; @SuppressWarnings("unchecked") - ReplaySubscription[] b = new ReplaySubscription[len + 1]; + ReplayDisposable[] b = new ReplayDisposable[len + 1]; System.arraycopy(a, 0, b, 0, len); b[len] = rs; if (subscribers.compareAndSet(a, b)) { @@ -224,9 +223,9 @@ public boolean add(ReplaySubscription rs) { } @SuppressWarnings("unchecked") - public void remove(ReplaySubscription rs) { + public void remove(ReplayDisposable rs) { for (;;) { - ReplaySubscription[] a = subscribers.get(); + ReplayDisposable[] a = subscribers.get(); if (a == TERMINATED || a == EMPTY) { return; } @@ -242,11 +241,11 @@ public void remove(ReplaySubscription rs) { if (j < 0) { return; } - ReplaySubscription[] b; + ReplayDisposable[] b; if (len == 1) { b = EMPTY; } else { - b = new ReplaySubscription[len - 1]; + b = new ReplayDisposable[len - 1]; System.arraycopy(a, 0, b, 0, j); System.arraycopy(a, j + 1, b, j, len - j - 1); } @@ -257,7 +256,7 @@ public void remove(ReplaySubscription rs) { } @SuppressWarnings("unchecked") - public ReplaySubscription[] terminate(Object terminalValue) { + public ReplayDisposable[] terminate(Object terminalValue) { if (compareAndSet(null, terminalValue)) { return subscribers.getAndSet(TERMINATED); } @@ -265,12 +264,10 @@ public ReplaySubscription[] terminate(Object terminalValue) { } @Override - public void onSubscribe(Subscription s) { + public void onSubscribe(Disposable s) { if (done) { - s.cancel(); - return; + s.dispose(); } - s.request(Long.MAX_VALUE); } @Override @@ -282,7 +279,8 @@ public void onNext(T t) { ReplayBuffer b = buffer; b.add(t); - for (ReplaySubscription rs : subscribers.get()) { + for (ReplayDisposable rs : subscribers.get()) { + // FIXME there is a caught-up optimization possible here as is with 1.x b.replay(rs); } } @@ -301,7 +299,7 @@ public void onError(Throwable t) { b.addFinal(o); - for (ReplaySubscription rs : terminate(o)) { + for (ReplayDisposable rs : terminate(o)) { b.replay(rs); } } @@ -319,7 +317,7 @@ public void onComplete() { b.addFinal(o); - for (ReplaySubscription rs : terminate(o)) { + for (ReplayDisposable rs : terminate(o)) { b.replay(rs); } } @@ -331,7 +329,7 @@ interface ReplayBuffer { void addFinal(Object notificationLite); - void replay(ReplaySubscription rs); + void replay(ReplayDisposable rs); int size(); @@ -340,34 +338,23 @@ interface ReplayBuffer { T[] getValues(T[] array); } - static final class ReplaySubscription extends AtomicInteger implements Subscription { + static final class ReplayDisposable extends AtomicInteger implements Disposable { /** */ private static final long serialVersionUID = 466549804534799122L; - final Subscriber actual; + final Observer actual; final State state; Object index; - final AtomicLong requested; - volatile boolean cancelled; - public ReplaySubscription(Subscriber actual, State state) { + public ReplayDisposable(Observer actual, State state) { this.actual = actual; this.state = state; - this.requested = new AtomicLong(); - } - @Override - public void request(long n) { - if (SubscriptionHelper.validateRequest(n)) { - return; - } - BackpressureHelper.add(requested, n); - state.buffer.replay(this); } @Override - public void cancel() { + public void dispose() { if (!cancelled) { cancelled = true; state.remove(this); @@ -456,14 +443,14 @@ public T[] getValues(T[] array) { @Override @SuppressWarnings("unchecked") - public void replay(ReplaySubscription rs) { + public void replay(ReplayDisposable rs) { if (rs.getAndIncrement() != 0) { return; } int missed = 1; final List b = buffer; - final Subscriber a = rs.actual; + final Observer a = rs.actual; Integer indexObject = (Integer)rs.index; int index = 0; @@ -482,9 +469,6 @@ public void replay(ReplaySubscription rs) { } int s = size; - long r = rs.requested.get(); - boolean unbounded = r == Long.MAX_VALUE; - long e = 0L; while (s != index) { @@ -511,25 +495,11 @@ public void replay(ReplaySubscription rs) { } } - if (r == 0) { - r = rs.requested.get() + e; - if (r == 0) { - break; - } - } - a.onNext((T)o); - r--; - e--; index++; } - if (e != 0L) { - if (!unbounded) { - r = rs.requested.addAndGet(e); - } - } - if (index != size && r != 0L) { + if (index != size) { continue; } @@ -694,13 +664,13 @@ public T[] getValues(T[] array) { @Override @SuppressWarnings("unchecked") - public void replay(ReplaySubscription rs) { + public void replay(ReplayDisposable rs) { if (rs.getAndIncrement() != 0) { return; } int missed = 1; - final Subscriber a = rs.actual; + final Observer a = rs.actual; Node index = (Node)rs.index; if (index == null) { @@ -714,10 +684,6 @@ public void replay(ReplaySubscription rs) { return; } - long r = rs.requested.get(); - boolean unbounded = r == Long.MAX_VALUE; - long e = 0; - for (;;) { if (rs.cancelled) { rs.index = null; @@ -746,27 +712,12 @@ public void replay(ReplaySubscription rs) { } } - if (r == 0) { - r = rs.requested.get() + e; - if (r == 0) { - break; - } - } - a.onNext((T)o); - r--; - e--; index = n; } - if (e != 0L) { - if (!unbounded) { - r = rs.requested.addAndGet(e); - } - } - - if (index.get() != null && r != 0L) { + if (index.get() != null) { continue; } @@ -962,13 +913,13 @@ public T[] getValues(T[] array) { @Override @SuppressWarnings("unchecked") - public void replay(ReplaySubscription rs) { + public void replay(ReplayDisposable rs) { if (rs.getAndIncrement() != 0) { return; } int missed = 1; - final Subscriber a = rs.actual; + final Observer a = rs.actual; TimedNode index = (TimedNode)rs.index; if (index == null) { @@ -995,10 +946,6 @@ public void replay(ReplaySubscription rs) { return; } - long r = rs.requested.get(); - boolean unbounded = r == Long.MAX_VALUE; - long e = 0; - for (;;) { if (rs.cancelled) { rs.index = null; @@ -1027,27 +974,12 @@ public void replay(ReplaySubscription rs) { } } - if (r == 0) { - r = rs.requested.get() + e; - if (r == 0) { - break; - } - } - a.onNext((T)o); - r--; - e--; index = n; } - if (e != 0L) { - if (!unbounded) { - r = rs.requested.addAndGet(e); - } - } - - if (index.get() != null && r != 0L) { + if (index.get() != null) { continue; } @@ -1080,4 +1012,4 @@ public int size() { return s; } } -} \ No newline at end of file +} diff --git a/src/main/java/io/reactivex/subjects/SerializedSubject.java b/src/main/java/io/reactivex/subjects/SerializedSubject.java index cf3f41c3bf..e63c5a4091 100644 --- a/src/main/java/io/reactivex/subjects/SerializedSubject.java +++ b/src/main/java/io/reactivex/subjects/SerializedSubject.java @@ -13,8 +13,7 @@ package io.reactivex.subjects; -import org.reactivestreams.*; - +import io.reactivex.disposables.Disposable; import io.reactivex.functions.Predicate; import io.reactivex.internal.util.*; import io.reactivex.plugins.RxJavaPlugins; @@ -41,9 +40,9 @@ * @param actual the subject wrapped */ public SerializedSubject(final Subject actual) { - super(new Publisher() { + super(new io.reactivex.Observable.NbpOnSubscribe() { @Override - public void subscribe(Subscriber s) { + public void accept(io.reactivex.Observer s) { actual.subscribe(s); } }); @@ -51,27 +50,8 @@ public void subscribe(Subscriber s) { } @Override - public void onSubscribe(Subscription s) { - if (done) { - return; - } - synchronized (this) { - if (done) { - return; - } - if (emitting) { - AppendOnlyLinkedArrayList q = queue; - if (q == null) { - q = new AppendOnlyLinkedArrayList(4); - queue = q; - } - q.add(NotificationLite.subscription(s)); - return; - } - emitting = true; - } - actual.onSubscribe(s); - emitLoop(); + public void onSubscribe(Disposable s) { + // NO-OP } @Override @@ -170,17 +150,17 @@ void emitLoop() { q.forEachWhile(consumer); } } - + final Predicate consumer = new Predicate() { @Override public boolean test(Object v) { - return SerializedSubject.this.accept(v); + return accept(v); } }; /** Delivers the notification to the actual subscriber. */ boolean accept(Object o) { - return NotificationLite.acceptFull(o, actual); + return NotificationLite.accept(o, actual); } @Override diff --git a/src/main/java/io/reactivex/subjects/Subject.java b/src/main/java/io/reactivex/subjects/Subject.java index f912b51b02..df64fc1f0d 100644 --- a/src/main/java/io/reactivex/subjects/Subject.java +++ b/src/main/java/io/reactivex/subjects/Subject.java @@ -13,12 +13,10 @@ package io.reactivex.subjects; -import org.reactivestreams.*; - -import io.reactivex.Observable; +import io.reactivex.*; /** - * Represents a Subscriber and an Observable (Publisher) at the same time, allowing + * Represents a NbpSubscriber and a NbpObservable at the same time, allowing * multicasting events from a single source to multiple child Subscribers. *

All methods except the onSubscribe, onNext, onError and onComplete are thread-safe. * Use {@link #toSerialized()} to make these methods thread-safe as well. @@ -26,9 +24,9 @@ * @param the source value type * @param the emission value type */ -public abstract class Subject extends Observable implements Processor { +public abstract class Subject extends Observable implements Observer { - protected Subject(Publisher onSubscribe) { + protected Subject(NbpOnSubscribe onSubscribe) { super(onSubscribe); } @@ -44,7 +42,7 @@ protected Subject(Publisher onSubscribe) { *

The method is thread-safe. * @return true if the subject has reached a terminal state through an error event * @see #getThrowable() - * @see #hasComplete() + * &see {@link #hasComplete()} */ public boolean hasThrowable() { throw new UnsupportedOperationException(); diff --git a/src/main/java/io/reactivex/subjects/UnicastSubject.java b/src/main/java/io/reactivex/subjects/UnicastSubject.java index ea273ce8b8..e65f5b8283 100644 --- a/src/main/java/io/reactivex/subjects/UnicastSubject.java +++ b/src/main/java/io/reactivex/subjects/UnicastSubject.java @@ -16,11 +16,10 @@ import java.util.Queue; import java.util.concurrent.atomic.*; -import org.reactivestreams.*; - +import io.reactivex.Observer; +import io.reactivex.disposables.Disposable; +import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.queue.SpscLinkedArrayQueue; -import io.reactivex.internal.subscriptions.*; -import io.reactivex.internal.util.BackpressureHelper; /** * Subject that allows only a single Subscriber to subscribe to it during its lifetime. @@ -96,26 +95,8 @@ static abstract class StatePad0 extends AtomicInteger { volatile long p8a, p9a, p10a, p11a, p12a, p13a, p14a, p15a; } - /** Contains the requested counter. */ - static abstract class StateRequested extends StatePad0 { - /** */ - private static final long serialVersionUID = -2744070795149472578L; - /** Holds the current requested amount. */ - final AtomicLong requested = new AtomicLong(); - } - - /** Pads away the requested counter. */ - static abstract class StatePad1 extends StateRequested { - /** */ - private static final long serialVersionUID = -446575186947206398L; - /** Cache line padding 3. */ - volatile long p1b, p2b, p3b, p4b, p5b, p6b, p7b; - /** Cache line padding 4. */ - volatile long p8b, p9b, p10b, p11b, p12b, p13b, p14b, p15b; - } - /** The state of the UnicastSubject. */ - static final class State extends StatePad1 implements Publisher, Subscription, Subscriber { + static final class State extends StatePad0 implements NbpOnSubscribe, Disposable, Observer { /** */ private static final long serialVersionUID = 5058617037583835632L; @@ -123,7 +104,7 @@ static final class State extends StatePad1 implements Publisher, Subscript final Queue queue; /** The single subscriber. */ - final AtomicReference> subscriber = new AtomicReference>(); + final AtomicReference> subscriber = new AtomicReference>(); /** Indicates the single subscriber has cancelled. */ volatile boolean cancelled; @@ -157,40 +138,19 @@ public State(int capacityHint, Runnable onCancelled) { } @Override - public void subscribe(Subscriber s) { + public void accept(Observer s) { if (!once.get() && once.compareAndSet(false, true)) { s.onSubscribe(this); subscriber.lazySet(s); // full barrier in drain - if (cancelled) { - subscriber.lazySet(null); - return; - } drain(); } else { - if (done) { - Throwable e = error; - if (e != null) { - EmptySubscription.error(e, s); - } else { - EmptySubscription.complete(s); - } - } else { - EmptySubscription.error(new IllegalStateException("Only a single subscriber allowed."), s); - } + s.onSubscribe(EmptyDisposable.INSTANCE); + s.onError(new IllegalStateException("Only a single subscriber allowed.")); } } @Override - public void request(long n) { - if (SubscriptionHelper.validateRequest(n)) { - return; - } - BackpressureHelper.add(requested, n); - drain(); - } - - @Override - public void cancel() { + public void dispose() { if (!cancelled) { cancelled = true; @@ -219,12 +179,10 @@ void clear(Queue q) { } @Override - public void onSubscribe(Subscription s) { + public void onSubscribe(Disposable s) { if (done || cancelled) { - s.cancel(); - return; + s.dispose(); } - s.request(Long.MAX_VALUE); } @Override @@ -268,7 +226,7 @@ void drain() { } final Queue q = queue; - Subscriber a = subscriber.get(); + Observer a = subscriber.get(); int missed = 1; for (;;) { @@ -294,11 +252,7 @@ void drain() { return; } - long r = requested.get(); - boolean unbounded = r == Long.MAX_VALUE; - long e = 0L; - - while (r != 0L) { + for (;;) { if (cancelled) { clear(q); @@ -326,15 +280,7 @@ void drain() { } a.onNext(v); - - r--; - e--; } - - if (e != 0 && !unbounded) { - requested.getAndAdd(e); - } - } missed = addAndGet(-missed); @@ -350,7 +296,7 @@ void drain() { } @Override - public void onSubscribe(Subscription s) { + public void onSubscribe(Disposable s) { state.onSubscribe(s); } diff --git a/src/main/java/io/reactivex/subjects/nbp/NbpAsyncSubject.java b/src/main/java/io/reactivex/subjects/nbp/NbpAsyncSubject.java deleted file mode 100644 index 9f8ccd389a..0000000000 --- a/src/main/java/io/reactivex/subjects/nbp/NbpAsyncSubject.java +++ /dev/null @@ -1,305 +0,0 @@ -/** - * Copyright 2016 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. - */ - -package io.reactivex.subjects.nbp; - -import java.lang.reflect.Array; -import java.util.concurrent.atomic.*; - -import io.reactivex.disposables.*; -import io.reactivex.internal.util.NotificationLite; -import io.reactivex.plugins.RxJavaPlugins; - -/** - * An NbpSubject that emits the very last value followed by a completion event or the received error to NbpSubscribers. - * - *

The implementation of onXXX methods are technically thread-safe but non-serialized calls - * to them may lead to undefined state in the currently subscribed NbpSubscribers. - * - *

Due to the nature Observables are constructed, the NbpAsyncSubject can't be instantiated through - * {@code new} but must be created via the {@link #create()} method. - * - * @param the value type - */ - -public final class NbpAsyncSubject extends NbpSubject { - public static NbpAsyncSubject create() { - State state = new State(); - return new NbpAsyncSubject(state); - } - - final State state; - protected NbpAsyncSubject(State state) { - super(state); - this.state = state; - } - - @Override - public void onSubscribe(Disposable d) { - if (state.subscribers.get() == State.TERMINATED) { - d.dispose(); - } - } - - @Override - public void onNext(T value) { - state.onNext(value); - } - - @Override - public void onError(Throwable e) { - state.onError(e); - } - - @Override - public void onComplete() { - state.onComplete(); - } - - @Override - public boolean hasSubscribers() { - return state.subscribers.get().length != 0; - } - - @Override - public Throwable getThrowable() { - Object o = state.get(); - if (NotificationLite.isError(o)) { - return NotificationLite.getError(o); - } - return null; - } - - @Override - public T getValue() { - Object o = state.get(); - if (o != null) { - if (NotificationLite.isComplete(o) || NotificationLite.isError(o)) { - return null; - } - return NotificationLite.getValue(o); - } - return null; - } - - @SuppressWarnings("unchecked") - @Override - public T[] getValues(T[] array) { - Object o = state.get(); - if (o != null) { - if (NotificationLite.isComplete(o) || NotificationLite.isError(o)) { - if (array.length != 0) { - array[0] = null; - } - } else { - T v = NotificationLite.getValue(o); - if (array.length != 0) { - array[0] = v; - if (array.length != 1) { - array[1] = null; - } - } else { - array = (T[])Array.newInstance(array.getClass().getComponentType(), 1); - array[0] = v; - } - } - } else { - if (array.length != 0) { - array[0] = null; - } - } - return array; - } - - @Override - public boolean hasComplete() { - return state.subscribers.get() == State.TERMINATED && !NotificationLite.isError(state.get()); - } - - @Override - public boolean hasThrowable() { - return NotificationLite.isError(state.get()); - } - - @Override - public boolean hasValue() { - Object o = state.get(); - return o != null && !NotificationLite.isComplete(o) && !NotificationLite.isError(o); - } - - static final class State extends AtomicReference implements NbpOnSubscribe, NbpSubscriber { - /** */ - private static final long serialVersionUID = 4876574210612691772L; - - final AtomicReference[]> subscribers; - - @SuppressWarnings("rawtypes") - static final NbpSubscriber[] EMPTY = new NbpSubscriber[0]; - @SuppressWarnings("rawtypes") - static final NbpSubscriber[] TERMINATED = new NbpSubscriber[0]; - - boolean done; - - @SuppressWarnings("unchecked") - public State() { - subscribers = new AtomicReference[]>(EMPTY); - } - - boolean add(NbpSubscriber s) { - for (;;) { - NbpSubscriber[] a = subscribers.get(); - if (a == TERMINATED) { - return false; - } - int n = a.length; - - @SuppressWarnings("unchecked") - NbpSubscriber[] b = new NbpSubscriber[n + 1]; - System.arraycopy(a, 0, b, 0, n); - b[n] = s; - - if (subscribers.compareAndSet(a, b)) { - return true; - } - } - } - - @SuppressWarnings("unchecked") - void remove(NbpSubscriber s) { - for (;;) { - NbpSubscriber[] a = subscribers.get(); - if (a == TERMINATED || a == EMPTY) { - return; - } - int n = a.length; - int j = -1; - for (int i = 0; i < n; i++) { - NbpSubscriber e = a[i]; - if (e.equals(s)) { - j = i; - break; - } - } - if (j < 0) { - return; - } - NbpSubscriber[] b; - if (n == 1) { - b = EMPTY; - } else { - b = new NbpSubscriber[n - 1]; - System.arraycopy(a, 0, b, 0, j); - System.arraycopy(a, j + 1, b, j, n - j - 1); - } - if (subscribers.compareAndSet(a, b)) { - return; - } - } - } - - @SuppressWarnings("unchecked") - NbpSubscriber[] terminate(Object notification) { - if (compareAndSet(get(), notification)) { - NbpSubscriber[] a = subscribers.get(); - if (a != TERMINATED) { - return subscribers.getAndSet(TERMINATED); - } - } - return TERMINATED; - } - - void emit(NbpSubscriber t, Object v) { - if (NotificationLite.isComplete(v)) { - t.onComplete(); - } else - if (NotificationLite.isError(v)) { - t.onError(NotificationLite.getError(v)); - } else { - t.onNext(NotificationLite.getValue(v)); - t.onComplete(); - } - } - - @Override - public void accept(final NbpSubscriber t) { - BooleanDisposable bd = new BooleanDisposable(new Runnable() { - @Override - public void run() { - remove(t); - } - }); - t.onSubscribe(bd); - if (add(t)) { - if (bd.isDisposed()) { - remove(t); - } - return; - } - Object v = get(); - emit(t, v); - } - - @Override - public void onSubscribe(Disposable d) { - if (done) { - d.dispose(); - } - } - - @Override - public void onNext(T value) { - if (done) { - return; - } - if (value == null) { - onError(new NullPointerException()); - return; - } - lazySet(value); - } - - @Override - public void onError(Throwable e) { - if (done) { - RxJavaPlugins.onError(e); - return; - } - done = true; - if (e == null) { - e = new NullPointerException(); - } - for (NbpSubscriber v : terminate(NotificationLite.error(e))) { - v.onError(e); - } - } - - @Override - public void onComplete() { - if (done) { - return; - } - done = true; - T value = NotificationLite.getValue(get()); - if (value == null) { - for (NbpSubscriber v : terminate(NotificationLite.complete())) { - v.onComplete(); - } - } else { - for (NbpSubscriber v : terminate(NotificationLite.next(value))) { - v.onNext(value); - v.onComplete(); - } - } - } - } -} \ No newline at end of file diff --git a/src/main/java/io/reactivex/subjects/nbp/NbpPublishSubject.java b/src/main/java/io/reactivex/subjects/nbp/NbpPublishSubject.java deleted file mode 100644 index 4c07c6a086..0000000000 --- a/src/main/java/io/reactivex/subjects/nbp/NbpPublishSubject.java +++ /dev/null @@ -1,262 +0,0 @@ -/** - * Copyright 2016 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. - */ - -package io.reactivex.subjects.nbp; - -import java.util.concurrent.atomic.*; - -import io.reactivex.disposables.*; -import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.internal.util.NotificationLite; -import io.reactivex.plugins.RxJavaPlugins; - -public final class NbpPublishSubject extends NbpSubject { - public static NbpPublishSubject create() { - State state = new State(); - return new NbpPublishSubject(state); - } - - final State state; - protected NbpPublishSubject(State state) { - super(state); - this.state = state; - } - - @Override - public void onSubscribe(Disposable d) { - if (state.done) { - d.dispose(); - } - } - - @Override - public void onNext(T value) { - state.onNext(value); - } - - @Override - public void onError(Throwable e) { - state.onError(e); - } - - @Override - public void onComplete() { - state.onComplete(); - } - - @Override - public boolean hasSubscribers() { - return state.subscribers.get().length != 0; - } - - @Override - public Throwable getThrowable() { - Object o = state.get(); - if (NotificationLite.isError(o)) { - return NotificationLite.getError(o); - } - return null; - } - - @Override - public T getValue() { - return null; - } - - @Override - public T[] getValues(T[] array) { - if (array.length != 0) { - array[0] = null; - } - return array; - } - - @Override - public boolean hasComplete() { - Object o = state.get(); - return o != null && !NotificationLite.isError(o); - } - - @Override - public boolean hasThrowable() { - return NotificationLite.isError(state.get()); - } - - @Override - public boolean hasValue() { - return false; - } - - static final class State extends AtomicReference implements NbpOnSubscribe, NbpSubscriber { - /** */ - private static final long serialVersionUID = 4876574210612691772L; - - final AtomicReference[]> subscribers = new AtomicReference[]>(); - - @SuppressWarnings("rawtypes") - static final NbpSubscriber[] EMPTY = new NbpSubscriber[0]; - @SuppressWarnings("rawtypes") - static final NbpSubscriber[] TERMINATED = new NbpSubscriber[0]; - - volatile boolean done; - - @SuppressWarnings("unchecked") - public State() { - subscribers.lazySet(EMPTY); - } - - boolean add(NbpSubscriber s) { - for (;;) { - NbpSubscriber[] a = subscribers.get(); - if (a == TERMINATED) { - return false; - } - int n = a.length; - - @SuppressWarnings("unchecked") - NbpSubscriber[] b = new NbpSubscriber[n + 1]; - System.arraycopy(a, 0, b, 0, n); - b[n] = s; - - if (subscribers.compareAndSet(a, b)) { - return true; - } - } - } - - @SuppressWarnings("unchecked") - void remove(NbpSubscriber s) { - for (;;) { - NbpSubscriber[] a = subscribers.get(); - if (a == TERMINATED || a == EMPTY) { - return; - } - int n = a.length; - int j = -1; - for (int i = 0; i < n; i++) { - NbpSubscriber e = a[i]; - if (e.equals(s)) { - j = i; - break; - } - } - if (j < 0) { - return; - } - NbpSubscriber[] b; - if (n == 1) { - b = EMPTY; - } else { - b = new NbpSubscriber[n - 1]; - System.arraycopy(a, 0, b, 0, j); - System.arraycopy(a, j + 1, b, j, n - j - 1); - } - if (subscribers.compareAndSet(a, b)) { - return; - } - } - } - - @SuppressWarnings("unchecked") - NbpSubscriber[] terminate(Object notification) { - if (compareAndSet(null, notification)) { - NbpSubscriber[] a = subscribers.get(); - if (a != TERMINATED) { - return subscribers.getAndSet(TERMINATED); - } - } - return TERMINATED; - } - - void emit(NbpSubscriber t, Object v) { - if (NotificationLite.isComplete(v)) { - t.onComplete(); - } else { - t.onError(NotificationLite.getError(v)); - } - } - - @Override - public void accept(final NbpSubscriber t) { - Object v = get(); - if (v != null) { - t.onSubscribe(EmptyDisposable.INSTANCE); - emit(t, v); - return; - } - BooleanDisposable bd = new BooleanDisposable(new Runnable() { - @Override - public void run() { - remove(t); - } - }); - t.onSubscribe(bd); - if (add(t)) { - if (bd.isDisposed()) { - remove(t); - } - return; - } - v = get(); - emit(t, v); - } - - @Override - public void onSubscribe(Disposable d) { - if (done) { - d.dispose(); - } - } - - @Override - public void onNext(T value) { - if (done) { - return; - } - if (value == null) { - onError(new NullPointerException("The value is null")); - return; - } - for (NbpSubscriber v : subscribers.get()) { - v.onNext(value); - } - } - - @Override - public void onError(Throwable e) { - if (done) { - RxJavaPlugins.onError(e); - return; - } - done = true; - if (e == null) { - e = new NullPointerException(); - } - - for (NbpSubscriber v : terminate(NotificationLite.error(e))) { - v.onError(e); - } - } - - @Override - public void onComplete() { - if (done) { - return; - } - done = true; - for (NbpSubscriber v : terminate(NotificationLite.complete())) { - v.onComplete(); - } - } - } -} \ No newline at end of file diff --git a/src/main/java/io/reactivex/subscribers/AsyncObserver.java b/src/main/java/io/reactivex/subscribers/AsyncSubscriber.java similarity index 97% rename from src/main/java/io/reactivex/subscribers/AsyncObserver.java rename to src/main/java/io/reactivex/subscribers/AsyncSubscriber.java index ffbb66b386..4518e26eaf 100644 --- a/src/main/java/io/reactivex/subscribers/AsyncObserver.java +++ b/src/main/java/io/reactivex/subscribers/AsyncSubscriber.java @@ -34,7 +34,7 @@ * * @param the value type */ -public abstract class AsyncObserver implements Subscriber, Disposable { +public abstract class AsyncSubscriber implements Subscriber, Disposable { /** The active subscription. */ private final AtomicReference s; @@ -60,7 +60,7 @@ public void cancel() { /** * Constructs an AsyncObserver with resource support. */ - public AsyncObserver() { + public AsyncSubscriber() { this(true); } @@ -68,7 +68,7 @@ public AsyncObserver() { * Constructs an AsyncObserver and allows specifying if it should support resources or not. * @param withResources true if resource support should be on. */ - public AsyncObserver(boolean withResources) { + public AsyncSubscriber(boolean withResources) { this.resources = withResources ? new ListCompositeResource(Disposables.consumeAndDispose()) : null; this.missedRequested = new AtomicLong(); this.s = new AtomicReference(); diff --git a/src/main/java/io/reactivex/subscribers/DefaultObserver.java b/src/main/java/io/reactivex/subscribers/DefaultObserver.java new file mode 100644 index 0000000000..cc710ab1f1 --- /dev/null +++ b/src/main/java/io/reactivex/subscribers/DefaultObserver.java @@ -0,0 +1,52 @@ +/** + * Copyright 2016 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package io.reactivex.subscribers; + +import org.reactivestreams.*; + +import io.reactivex.internal.subscriptions.SubscriptionHelper; + +public abstract class DefaultObserver implements Subscriber { + private Subscription s; + @Override + public final void onSubscribe(Subscription s) { + if (SubscriptionHelper.validateSubscription(this.s, s)) { + return; + } + this.s = s; + onStart(); + } + + protected final Subscription subscription() { + return s; + } + + protected final void request(long n) { + subscription().request(n); + } + + protected final void cancel() { + subscription().cancel(); + } + /** + * Called once the subscription has been set on this observer; override this + * to perform initialization or issue an initial request. + *

+ * The default implementation requests {@link Long#MAX_VALUE}. + */ + protected void onStart() { + request(Long.MAX_VALUE); + } + +} diff --git a/src/main/java/io/reactivex/subscribers/Subscribers.java b/src/main/java/io/reactivex/subscribers/Subscribers.java index 5aef09cebc..087f7995b4 100644 --- a/src/main/java/io/reactivex/subscribers/Subscribers.java +++ b/src/main/java/io/reactivex/subscribers/Subscribers.java @@ -17,7 +17,7 @@ import io.reactivex.functions.Consumer; import io.reactivex.internal.functions.*; -import io.reactivex.internal.subscribers.*; +import io.reactivex.internal.subscribers.flowable.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.plugins.RxJavaPlugins; @@ -252,6 +252,190 @@ public void onError(Throwable t) { } } + @Override + public void onComplete() { + if (done) { + return; + } + done = true; + try { + onComplete.run(); + } catch (Throwable e) { + RxJavaPlugins.onError(e); + } + } + }; + } + public static AsyncSubscriber emptyAsync() { + return new AsyncSubscriber() { + @Override + public void onNext(T t) { + + } + + @Override + public void onError(Throwable t) { + RxJavaPlugins.onError(t); + } + + @Override + public void onComplete() { + + } + }; + } + + public static DefaultObserver create( + final Consumer onNext, + final Consumer onError, + final Runnable onComplete, + final Runnable onStart) { + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(onStart, "onStart is null"); + return new DefaultObserver() { + boolean done; + @Override + protected void onStart() { + super.onStart(); + try { + onStart.run(); + } catch (Throwable e) { + done = true; + cancel(); + try { + onError.accept(e); + } catch (Throwable ex) { + RxJavaPlugins.onError(e); + RxJavaPlugins.onError(ex); + } + } + } + @Override + public void onNext(T t) { + if (done) { + return; + } + try { + onNext.accept(t); + } catch (Throwable e) { + done = true; + cancel(); + try { + onError.accept(e); + } catch (Throwable ex) { + RxJavaPlugins.onError(e); + RxJavaPlugins.onError(ex); + } + } + } + + @Override + public void onError(Throwable t) { + if (done) { + RxJavaPlugins.onError(t); + return; + } + done = true; + try { + onError.accept(t); + } catch (Throwable ex) { + RxJavaPlugins.onError(ex); + RxJavaPlugins.onError(t); + } + } + + @Override + public void onComplete() { + if (done) { + return; + } + done = true; + try { + onComplete.run(); + } catch (Throwable e) { + RxJavaPlugins.onError(e); + } + } + }; + } + + public static AsyncSubscriber createAsync(Consumer onNext) { + return createAsync(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), Functions.emptyRunnable()); + } + + public static AsyncSubscriber createAsync(Consumer onNext, + Consumer onError) { + return createAsync(onNext, onError, Functions.emptyRunnable(), Functions.emptyRunnable()); + } + + public static AsyncSubscriber createAsync(Consumer onNext, + Consumer onError, Runnable onComplete) { + return createAsync(onNext, onError, onComplete, Functions.emptyRunnable()); + } + + public static AsyncSubscriber createAsync( + final Consumer onNext, + final Consumer onError, + final Runnable onComplete, + final Runnable onStart) { + Objects.requireNonNull(onNext, "onNext is null"); + Objects.requireNonNull(onError, "onError is null"); + Objects.requireNonNull(onComplete, "onComplete is null"); + Objects.requireNonNull(onStart, "onStart is null"); + return new AsyncSubscriber() { + boolean done; + @Override + protected void onStart() { + super.onStart(); + try { + onStart.run(); + } catch (Throwable e) { + done = true; + cancel(); + try { + onError.accept(e); + } catch (Throwable ex) { + RxJavaPlugins.onError(ex); + RxJavaPlugins.onError(e); + } + } + } + @Override + public void onNext(T t) { + if (done) { + return; + } + try { + onNext.accept(t); + } catch (Throwable e) { + done = true; + cancel(); + try { + onError.accept(e); + } catch (Throwable ex) { + RxJavaPlugins.onError(ex); + RxJavaPlugins.onError(e); + } + } + } + + @Override + public void onError(Throwable t) { + if (done) { + RxJavaPlugins.onError(t); + return; + } + done = true; + try { + onError.accept(t); + } catch (Throwable ex) { + RxJavaPlugins.onError(ex); + RxJavaPlugins.onError(t); + } + } + @Override public void onComplete() { if (done) { diff --git a/src/main/java/io/reactivex/subscribers/TestSubscriber.java b/src/main/java/io/reactivex/subscribers/TestSubscriber.java index cd2ed205d8..a7546b8c5c 100644 --- a/src/main/java/io/reactivex/subscribers/TestSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/TestSubscriber.java @@ -22,7 +22,7 @@ import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.CompositeException; import io.reactivex.internal.functions.Objects; -import io.reactivex.internal.subscribers.EmptySubscriber; +import io.reactivex.internal.subscribers.flowable.EmptySubscriber; import io.reactivex.internal.subscriptions.SubscriptionHelper; import io.reactivex.internal.util.BackpressureHelper; diff --git a/src/main/java/io/reactivex/subscribers/nbp/NbpObservers.java b/src/main/java/io/reactivex/subscribers/nbp/NbpObservers.java deleted file mode 100644 index 9623182bd3..0000000000 --- a/src/main/java/io/reactivex/subscribers/nbp/NbpObservers.java +++ /dev/null @@ -1,246 +0,0 @@ -/** - * Copyright 2016 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. - */ - -package io.reactivex.subscribers.nbp; - -import io.reactivex.NbpObserver; -import io.reactivex.functions.Consumer; -import io.reactivex.internal.functions.*; -import io.reactivex.plugins.RxJavaPlugins; - -/** - * Utility class to create Observers from lambdas. - */ -public final class NbpObservers { - /** Utility class with factory methods only. */ - private NbpObservers() { - throw new IllegalStateException("No instances!"); - } - - public static NbpObserver empty() { - return new NbpObserver() { - @Override - public void onNext(T t) { - - } - - @Override - public void onError(Throwable t) { - RxJavaPlugins.onError(t); - } - - @Override - public void onComplete() { - - } - }; - } - - public static NbpAsyncObserver emptyAsync() { - return new NbpAsyncObserver() { - @Override - public void onNext(T t) { - - } - - @Override - public void onError(Throwable t) { - RxJavaPlugins.onError(t); - } - - @Override - public void onComplete() { - - } - }; - } - - public static NbpObserver create(Consumer onNext) { - return create(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), Functions.emptyRunnable()); - } - - public static NbpObserver create(Consumer onNext, - Consumer onError) { - return create(onNext, onError, Functions.emptyRunnable(), Functions.emptyRunnable()); - } - - public static NbpObserver create(Consumer onNext, - Consumer onError, Runnable onComplete) { - return create(onNext, onError, onComplete, Functions.emptyRunnable()); - } - - public static NbpObserver create( - final Consumer onNext, - final Consumer onError, - final Runnable onComplete, - final Runnable onStart) { - Objects.requireNonNull(onNext, "onNext is null"); - Objects.requireNonNull(onError, "onError is null"); - Objects.requireNonNull(onComplete, "onComplete is null"); - Objects.requireNonNull(onStart, "onStart ins null"); - return new NbpObserver() { - boolean done; - @Override - protected void onStart() { - super.onStart(); - try { - onStart.run(); - } catch (Throwable e) { - done = true; - cancel(); - try { - onError.accept(e); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - RxJavaPlugins.onError(e); - } - } - } - @Override - public void onNext(T t) { - if (done) { - return; - } - try { - onNext.accept(t); - } catch (Throwable e) { - done = true; - cancel(); - try { - onError.accept(e); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - RxJavaPlugins.onError(e); - } - } - } - - @Override - public void onError(Throwable t) { - if (done) { - RxJavaPlugins.onError(t); - return; - } - done = true; - try { - onError.accept(t); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - RxJavaPlugins.onError(t); - } - } - - @Override - public void onComplete() { - if (done) { - return; - } - done = true; - try { - onComplete.run(); - } catch (Throwable e) { - RxJavaPlugins.onError(e); - } - } - }; - } - - public static NbpAsyncObserver createAsync(Consumer onNext) { - return createAsync(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), Functions.emptyRunnable()); - } - - public static NbpAsyncObserver createAsync(Consumer onNext, - Consumer onError) { - return createAsync(onNext, onError, Functions.emptyRunnable(), Functions.emptyRunnable()); - } - - public static NbpAsyncObserver createAsync(Consumer onNext, - Consumer onError, Runnable onComplete) { - return createAsync(onNext, onError, onComplete, Functions.emptyRunnable()); - } - - public static NbpAsyncObserver createAsync( - final Consumer onNext, - final Consumer onError, - final Runnable onComplete, - final Runnable onStart) { - Objects.requireNonNull(onNext, "onNext is null"); - Objects.requireNonNull(onError, "onError is null"); - Objects.requireNonNull(onComplete, "onComplete is null"); - Objects.requireNonNull(onStart, "onStart is null"); - return new NbpAsyncObserver() { - boolean done; - @Override - protected void onStart() { - try { - onStart.run(); - } catch (Throwable e) { - done = true; - cancel(); - try { - onError.accept(e); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - RxJavaPlugins.onError(e); - } - } - } - @Override - public void onNext(T t) { - if (done) { - return; - } - try { - onNext.accept(t); - } catch (Throwable e) { - done = true; - cancel(); - try { - onError.accept(e); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - RxJavaPlugins.onError(e); - } - } - } - - @Override - public void onError(Throwable t) { - if (done) { - RxJavaPlugins.onError(t); - return; - } - done = true; - try { - onError.accept(t); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - RxJavaPlugins.onError(t); - } - } - - @Override - public void onComplete() { - if (done) { - return; - } - done = true; - try { - onComplete.run(); - } catch (Throwable e) { - RxJavaPlugins.onError(e); - } - } - }; - } -} diff --git a/src/main/java/io/reactivex/subscribers/nbp/NbpSubscribers.java b/src/main/java/io/reactivex/subscribers/nbp/NbpSubscribers.java deleted file mode 100644 index 80fe46f9b0..0000000000 --- a/src/main/java/io/reactivex/subscribers/nbp/NbpSubscribers.java +++ /dev/null @@ -1,262 +0,0 @@ -/** - * Copyright 2016 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. - */ - -package io.reactivex.subscribers.nbp; - -import io.reactivex.NbpObservable.NbpSubscriber; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Consumer; -import io.reactivex.internal.functions.*; -import io.reactivex.internal.subscribers.nbp.*; -import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.plugins.RxJavaPlugins; - -/** - * Utility class to construct various resource-holding and disposable Subscribers from lambdas. - */ -public final class NbpSubscribers { - /** Utility class. */ - private NbpSubscribers() { - throw new IllegalStateException("No instances!"); - } - - @SuppressWarnings("unchecked") - public static NbpSubscriber empty() { - return (NbpSubscriber)NbpEmptySubscriber.INSTANCE; - } - - @SuppressWarnings("unchecked") - public static NbpSubscriber cancelled() { - return (NbpSubscriber)NbpCancelledSubscriber.INSTANCE; - } - - public static NbpDisposableSubscriber emptyDisposable() { - return new NbpDisposableSubscriber() { - @Override - public void onNext(T t) { - - } - - @Override - public void onError(Throwable t) { - - } - - @Override - public void onComplete() { - - } - }; - } - - public static NbpDisposableSubscriber createDisposable( - Consumer onNext - ) { - return createDisposable(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), Functions.emptyRunnable()); - } - - public static NbpDisposableSubscriber createDisposable( - Consumer onNext, - Consumer onError - ) { - return createDisposable(onNext, onError, Functions.emptyRunnable(), Functions.emptyRunnable()); - } - - public static NbpDisposableSubscriber createDisposable( - Consumer onNext, - Consumer onError, - Runnable onComplete - ) { - return createDisposable(onNext, onError, onComplete, Functions.emptyRunnable()); - } - - public static NbpDisposableSubscriber createDisposable( - final Consumer onNext, - final Consumer onError, - final Runnable onComplete, - final Runnable onStart - ) { - Objects.requireNonNull(onNext, "onNext is null"); - Objects.requireNonNull(onError, "onError is null"); - Objects.requireNonNull(onComplete, "onComplete is null"); - Objects.requireNonNull(onStart, "onStart is null"); - return new NbpDisposableSubscriber() { - boolean done; - @Override - protected void onStart() { - super.onStart(); - try { - onStart.run(); - } catch (Throwable e) { - done = true; - dispose(); - try { - onError.accept(e); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - RxJavaPlugins.onError(e); - } - } - } - @Override - public void onNext(T t) { - if (done) { - return; - } - try { - onNext.accept(t); - } catch (Throwable e) { - done = true; - dispose(); - try { - onError.accept(e); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - RxJavaPlugins.onError(e); - } - } - } - - @Override - public void onError(Throwable t) { - if (done) { - RxJavaPlugins.onError(t); - return; - } - done = true; - try { - onError.accept(t); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - RxJavaPlugins.onError(t); - } - } - - @Override - public void onComplete() { - if (done) { - return; - } - done = true; - try { - onComplete.run(); - } catch (Throwable e) { - RxJavaPlugins.onError(e); - } - } - }; - } - - public static NbpSubscriber create( - Consumer onNext - ) { - return create(onNext, RxJavaPlugins.errorConsumer(), Functions.emptyRunnable(), Functions.emptyConsumer()); - } - - public static NbpSubscriber create( - Consumer onNext, - Consumer onError - ) { - return create(onNext, onError, Functions.emptyRunnable(), Functions.emptyConsumer()); - } - - public static NbpSubscriber create( - Consumer onNext, - Consumer onError, - Runnable onComplete - ) { - return create(onNext, onError, onComplete, Functions.emptyConsumer()); - } - - public static NbpSubscriber create( - final Consumer onNext, - final Consumer onError, - final Runnable onComplete, - final Consumer onStart - ) { - Objects.requireNonNull(onNext, "onNext is null"); - Objects.requireNonNull(onError, "onError is null"); - Objects.requireNonNull(onComplete, "onComplete is null"); - Objects.requireNonNull(onStart, "onStart is null"); - return new NbpSubscriber() { - boolean done; - - Disposable s; - @Override - public void onSubscribe(Disposable s) { - if (SubscriptionHelper.validateDisposable(this.s, s)) { - return; - } - this.s = s; - try { - onStart.accept(s); - } catch (Throwable e) { - done = true; - s.dispose(); - try { - onError.accept(e); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - RxJavaPlugins.onError(e); - } - } - } - @Override - public void onNext(T t) { - if (done) { - return; - } - try { - onNext.accept(t); - } catch (Throwable e) { - done = true; - s.dispose(); - try { - onError.accept(e); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - RxJavaPlugins.onError(e); - } - } - } - - @Override - public void onError(Throwable t) { - if (done) { - RxJavaPlugins.onError(t); - return; - } - done = true; - try { - onError.accept(t); - } catch (Throwable ex) { - RxJavaPlugins.onError(ex); - RxJavaPlugins.onError(t); - } - } - - @Override - public void onComplete() { - if (done) { - return; - } - done = true; - try { - onComplete.run(); - } catch (Throwable e) { - RxJavaPlugins.onError(e); - } - } - }; - } -} diff --git a/src/perf/java/io/reactivex/EachTypeFlatMapPerf.java b/src/perf/java/io/reactivex/EachTypeFlatMapPerf.java index ce567d6880..5406c89c7e 100644 --- a/src/perf/java/io/reactivex/EachTypeFlatMapPerf.java +++ b/src/perf/java/io/reactivex/EachTypeFlatMapPerf.java @@ -31,45 +31,45 @@ public class EachTypeFlatMapPerf { @Param({ "1", "1000", "1000000" }) public int times; - Observable bpRange; - NbpObservable nbpRange; + Flowable bpRange; + Observable nbpRange; Single singleJust; - Observable bpRangeMapJust; - NbpObservable nbpRangeMapJust; + Flowable bpRangeMapJust; + Observable nbpRangeMapJust; Single singleJustMapJust; - Observable bpRangeMapRange; - NbpObservable nbpRangeMapRange; + Flowable bpRangeMapRange; + Observable nbpRangeMapRange; @Setup public void setup() { - bpRange = Observable.range(1, times); - nbpRange = NbpObservable.range(1, times); + bpRange = Flowable.range(1, times); + nbpRange = Observable.range(1, times); bpRangeMapJust = bpRange.flatMap(new Function>() { @Override public Publisher apply(Integer v) { - return Observable.just(v); + return Flowable.just(v); } }); - nbpRangeMapJust = nbpRange.flatMap(new Function>() { + nbpRangeMapJust = nbpRange.flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { - return NbpObservable.just(v); + public Observable apply(Integer v) { + return Observable.just(v); } }); bpRangeMapRange = bpRange.flatMap(new Function>() { @Override public Publisher apply(Integer v) { - return Observable.range(v, 2); + return Flowable.range(v, 2); } }); - nbpRangeMapRange = nbpRange.flatMap(new Function>() { + nbpRangeMapRange = nbpRange.flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { - return NbpObservable.range(v, 2); + public Observable apply(Integer v) { + return Observable.range(v, 2); } }); diff --git a/src/perf/java/io/reactivex/InputWithIncrementingInteger.java b/src/perf/java/io/reactivex/InputWithIncrementingInteger.java index 7ff7e5a63d..6115a754ec 100644 --- a/src/perf/java/io/reactivex/InputWithIncrementingInteger.java +++ b/src/perf/java/io/reactivex/InputWithIncrementingInteger.java @@ -20,14 +20,15 @@ import org.reactivestreams.*; import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.subscribers.DefaultObserver; /** * Exposes an Observable and Observer that increments n Integers and consumes them in a Blackhole. */ public abstract class InputWithIncrementingInteger { public Iterable iterable; - public Observable observable; - public Observable firehose; + public Flowable observable; + public Flowable firehose; public Blackhole bh; public abstract int getSize(); @@ -36,9 +37,9 @@ public abstract class InputWithIncrementingInteger { public void setup(final Blackhole bh) { this.bh = bh; final int size = getSize(); - observable = Observable.range(0, size); + observable = Flowable.range(0, size); - firehose = Observable.create(new Publisher() { + firehose = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -82,7 +83,7 @@ public LatchedObserver newLatchedObserver() { } public Subscriber newSubscriber() { - return new Observer() { + return new DefaultObserver() { @Override public void onComplete() { diff --git a/src/perf/java/io/reactivex/LatchedNbpObserver.java b/src/perf/java/io/reactivex/LatchedNbpObserver.java index 629b277233..e4385a6109 100644 --- a/src/perf/java/io/reactivex/LatchedNbpObserver.java +++ b/src/perf/java/io/reactivex/LatchedNbpObserver.java @@ -17,10 +17,9 @@ import org.openjdk.jmh.infra.Blackhole; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.disposables.Disposable; -public final class LatchedNbpObserver implements NbpSubscriber { +public final class LatchedNbpObserver implements Observer { final CountDownLatch cdl; final Blackhole bh; public LatchedNbpObserver(Blackhole bh) { diff --git a/src/perf/java/io/reactivex/LatchedObserver.java b/src/perf/java/io/reactivex/LatchedObserver.java index e02e562a5b..15c91179eb 100644 --- a/src/perf/java/io/reactivex/LatchedObserver.java +++ b/src/perf/java/io/reactivex/LatchedObserver.java @@ -17,9 +17,9 @@ import org.openjdk.jmh.infra.Blackhole; -import io.reactivex.Observer; +import io.reactivex.subscribers.DefaultObserver; -public class LatchedObserver extends Observer { +public class LatchedObserver extends DefaultObserver { public CountDownLatch latch = new CountDownLatch(1); private final Blackhole bh; diff --git a/src/perf/java/io/reactivex/OperatorFlatMapPerf.java b/src/perf/java/io/reactivex/OperatorFlatMapPerf.java index f8d27eeb00..56769859f8 100644 --- a/src/perf/java/io/reactivex/OperatorFlatMapPerf.java +++ b/src/perf/java/io/reactivex/OperatorFlatMapPerf.java @@ -18,7 +18,7 @@ import org.openjdk.jmh.annotations.*; import org.reactivestreams.Publisher; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.functions.Function; import io.reactivex.schedulers.Schedulers; @@ -45,7 +45,7 @@ public void flatMapIntPassthruSync(Input input) throws InterruptedException { input.observable.flatMap(new Function>() { @Override public Publisher apply(Integer v) { - return Observable.just(v); + return Flowable.just(v); } }).subscribe(input.newSubscriber()); } @@ -56,7 +56,7 @@ public void flatMapIntPassthruAsync(Input input) throws InterruptedException { input.observable.flatMap(new Function>() { @Override public Publisher apply(Integer i) { - return Observable.just(i).subscribeOn(Schedulers.computation()); + return Flowable.just(i).subscribeOn(Schedulers.computation()); } }).subscribe(latchedObserver); if (input.size == 1) { @@ -68,7 +68,7 @@ public Publisher apply(Integer i) { @Benchmark public void flatMapTwoNestedSync(final Input input) throws InterruptedException { - Observable.range(1, 2).flatMap(new Function>() { + Flowable.range(1, 2).flatMap(new Function>() { @Override public Publisher apply(Integer i) { return input.observable; diff --git a/src/perf/java/io/reactivex/OperatorMergePerf.java b/src/perf/java/io/reactivex/OperatorMergePerf.java index e8eef8b97d..27626fd848 100644 --- a/src/perf/java/io/reactivex/OperatorMergePerf.java +++ b/src/perf/java/io/reactivex/OperatorMergePerf.java @@ -19,7 +19,7 @@ import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.functions.Function; import io.reactivex.schedulers.Schedulers; @@ -30,15 +30,15 @@ public class OperatorMergePerf { // flatMap @Benchmark public void oneStreamOfNthatMergesIn1(final InputMillion input) throws InterruptedException { - Observable> os = Observable.range(1, input.size) - .map(new Function>() { + Flowable> os = Flowable.range(1, input.size) + .map(new Function>() { @Override - public Observable apply(Integer v) { - return Observable.just(v); + public Flowable apply(Integer v) { + return Flowable.just(v); } }); LatchedObserver o = input.newLatchedObserver(); - Observable.merge(os).subscribe(o); + Flowable.merge(os).subscribe(o); if (input.size == 1) { while (o.latch.getCount() != 0); @@ -50,14 +50,14 @@ public Observable apply(Integer v) { // flatMap @Benchmark public void merge1SyncStreamOfN(final InputMillion input) throws InterruptedException { - Observable> os = Observable.just(1).map(new Function>() { + Flowable> os = Flowable.just(1).map(new Function>() { @Override - public Observable apply(Integer i) { - return Observable.range(0, input.size); + public Flowable apply(Integer i) { + return Flowable.range(0, input.size); } }); LatchedObserver o = input.newLatchedObserver(); - Observable.merge(os).subscribe(o); + Flowable.merge(os).subscribe(o); if (input.size == 1) { while (o.latch.getCount() != 0); @@ -68,14 +68,14 @@ public Observable apply(Integer i) { @Benchmark public void mergeNSyncStreamsOfN(final InputThousand input) throws InterruptedException { - Observable> os = input.observable.map(new Function>() { + Flowable> os = input.observable.map(new Function>() { @Override - public Observable apply(Integer i) { - return Observable.range(0, input.size); + public Flowable apply(Integer i) { + return Flowable.range(0, input.size); } }); LatchedObserver o = input.newLatchedObserver(); - Observable.merge(os).subscribe(o); + Flowable.merge(os).subscribe(o); if (input.size == 1) { while (o.latch.getCount() != 0); } else { @@ -85,14 +85,14 @@ public Observable apply(Integer i) { @Benchmark public void mergeNAsyncStreamsOfN(final InputThousand input) throws InterruptedException { - Observable> os = input.observable.map(new Function>() { + Flowable> os = input.observable.map(new Function>() { @Override - public Observable apply(Integer i) { - return Observable.range(0, input.size).subscribeOn(Schedulers.computation()); + public Flowable apply(Integer i) { + return Flowable.range(0, input.size).subscribeOn(Schedulers.computation()); } }); LatchedObserver o = input.newLatchedObserver(); - Observable.merge(os).subscribe(o); + Flowable.merge(os).subscribe(o); if (input.size == 1) { while (o.latch.getCount() != 0); } else { @@ -103,8 +103,8 @@ public Observable apply(Integer i) { @Benchmark public void mergeTwoAsyncStreamsOfN(final InputThousand input) throws InterruptedException { LatchedObserver o = input.newLatchedObserver(); - Observable ob = Observable.range(0, input.size).subscribeOn(Schedulers.computation()); - Observable.merge(ob, ob).subscribe(o); + Flowable ob = Flowable.range(0, input.size).subscribeOn(Schedulers.computation()); + Flowable.merge(ob, ob).subscribe(o); if (input.size == 1) { while (o.latch.getCount() != 0); } else { @@ -115,7 +115,7 @@ public void mergeTwoAsyncStreamsOfN(final InputThousand input) throws Interrupte @Benchmark public void mergeNSyncStreamsOf1(final InputForMergeN input) throws InterruptedException { LatchedObserver o = input.newLatchedObserver(); - Observable.merge(input.observables).subscribe(o); + Flowable.merge(input.observables).subscribe(o); if (input.size == 1) { while (o.latch.getCount() != 0); } else { @@ -130,14 +130,14 @@ public static class InputForMergeN { public int size; private Blackhole bh; - List> observables; + List> observables; @Setup public void setup(final Blackhole bh) { this.bh = bh; - observables = new ArrayList>(); + observables = new ArrayList>(); for (int i = 0; i < size; i++) { - observables.add(Observable.just(i)); + observables.add(Flowable.just(i)); } } diff --git a/src/perf/java/io/reactivex/RangePerf.java b/src/perf/java/io/reactivex/RangePerf.java index 768ccdb3b3..7972a259a6 100644 --- a/src/perf/java/io/reactivex/RangePerf.java +++ b/src/perf/java/io/reactivex/RangePerf.java @@ -18,7 +18,7 @@ import org.openjdk.jmh.annotations.*; import org.openjdk.jmh.infra.Blackhole; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.internal.schedulers.SingleScheduler; import io.reactivex.schedulers.Schedulers; @@ -32,15 +32,15 @@ public class RangePerf { @Param({ "1", "1000", "1000000" }) public int times; - Observable range; + Flowable range; - Observable rangeAsync; + Flowable rangeAsync; - Observable rangeAsyncPipeline; + Flowable rangeAsyncPipeline; @Setup public void setup() { - range = Observable.range(1, times); + range = Flowable.range(1, times); rangeAsync = range.observeOn(Schedulers.single()); diff --git a/src/perf/java/io/reactivex/RxVsStreamPerf.java b/src/perf/java/io/reactivex/RxVsStreamPerf.java index 67a1e86bb9..5e99bfcfb6 100644 --- a/src/perf/java/io/reactivex/RxVsStreamPerf.java +++ b/src/perf/java/io/reactivex/RxVsStreamPerf.java @@ -32,51 +32,51 @@ public class RxVsStreamPerf { @Param({ "1", "1000", "1000000" }) public int times; - Observable range; + Flowable range; - NbpObservable rangeNbp; + Observable rangeNbp; - Observable rangeFlatMap; + Flowable rangeFlatMap; - NbpObservable rangeNbpFlatMap; + Observable rangeNbpFlatMap; - Observable rangeFlatMapJust; + Flowable rangeFlatMapJust; - NbpObservable rangeNbpFlatMapJust; + Observable rangeNbpFlatMapJust; List values; @Setup public void setup() { - range = Observable.range(1, times); + range = Flowable.range(1, times); rangeFlatMapJust = range.flatMap(new Function>() { @Override public Publisher apply(Integer v) { - return Observable.just(v); + return Flowable.just(v); } }); rangeFlatMap = range.flatMap(new Function>() { @Override public Publisher apply(Integer v) { - return Observable.range(v, 2); + return Flowable.range(v, 2); } }); - rangeNbp = NbpObservable.range(1, times); + rangeNbp = Observable.range(1, times); - rangeNbpFlatMapJust = rangeNbp.flatMap(new Function>() { + rangeNbpFlatMapJust = rangeNbp.flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { - return NbpObservable.just(v); + public Observable apply(Integer v) { + return Observable.just(v); } }); - rangeNbpFlatMap = rangeNbp.flatMap(new Function>() { + rangeNbpFlatMap = rangeNbp.flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { - return NbpObservable.range(v, 2); + public Observable apply(Integer v) { + return Observable.range(v, 2); } }); diff --git a/src/test/java/io/reactivex/CompletableTest.java b/src/test/java/io/reactivex/completable/CompletableTest.java similarity index 95% rename from src/test/java/io/reactivex/CompletableTest.java rename to src/test/java/io/reactivex/completable/CompletableTest.java index cc1577ed46..02f6053aed 100644 --- a/src/test/java/io/reactivex/CompletableTest.java +++ b/src/test/java/io/reactivex/completable/CompletableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.completable; import java.util.*; import java.util.concurrent.*; @@ -20,18 +20,20 @@ import org.junit.*; import org.reactivestreams.*; +import io.reactivex.*; import io.reactivex.Completable.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.functions.Functions; +import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; -import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; /** * Test Completable methods and operators. @@ -295,14 +297,14 @@ public void concatIterableIteratorNextThrows() { @Test(timeout = 1000) public void concatObservableEmpty() { - Completable c = Completable.concat(Observable.empty()); + Completable c = Completable.concat(Flowable.empty()); c.await(); } @Test(timeout = 1000, expected = TestException.class) public void concatObservableError() { - Completable c = Completable.concat(Observable.error(new Supplier() { + Completable c = Completable.concat(Flowable.error(new Supplier() { @Override public Throwable get() { return new TestException(); @@ -314,7 +316,7 @@ public Throwable get() { @Test(timeout = 1000) public void concatObservableSingle() { - Completable c = Completable.concat(Observable.just(normal.completable)); + Completable c = Completable.concat(Flowable.just(normal.completable)); c.await(); @@ -323,14 +325,14 @@ public void concatObservableSingle() { @Test(timeout = 1000, expected = TestException.class) public void concatObservableSingleThrows() { - Completable c = Completable.concat(Observable.just(error.completable)); + Completable c = Completable.concat(Flowable.just(error.completable)); c.await(); } @Test(timeout = 1000) public void concatObservableMany() { - Completable c = Completable.concat(Observable.just(normal.completable).repeat(3)); + Completable c = Completable.concat(Flowable.just(normal.completable).repeat(3)); c.await(); @@ -339,7 +341,7 @@ public void concatObservableMany() { @Test(timeout = 1000, expected = TestException.class) public void concatObservableManyOneThrows() { - Completable c = Completable.concat(Observable.just(normal.completable, error.completable)); + Completable c = Completable.concat(Flowable.just(normal.completable, error.completable)); c.await(); } @@ -347,7 +349,7 @@ public void concatObservableManyOneThrows() { @Test(timeout = 1000) public void concatObservablePrefetch() { final List requested = new ArrayList(); - Observable cs = Observable + Flowable cs = Flowable .just(normal.completable) .repeat(10) .doOnRequest(new LongConsumer() { @@ -545,7 +547,7 @@ public void fromFlowableNull() { @Test(timeout = 1000) public void fromFlowableEmpty() { - Completable c = Completable.fromFlowable(Observable.empty()); + Completable c = Completable.fromFlowable(Flowable.empty()); c.await(); } @@ -553,7 +555,7 @@ public void fromFlowableEmpty() { @Test(timeout = 5000) public void fromFlowableSome() { for (int n = 1; n < 10000; n *= 10) { - Completable c = Completable.fromFlowable(Observable.range(1, n)); + Completable c = Completable.fromFlowable(Flowable.range(1, n)); c.await(); } @@ -561,7 +563,7 @@ public void fromFlowableSome() { @Test(timeout = 1000, expected = TestException.class) public void fromFlowableError() { - Completable c = Completable.fromFlowable(Observable.error(new Supplier() { + Completable c = Completable.fromFlowable(Flowable.error(new Supplier() { @Override public Throwable get() { return new TestException(); @@ -578,7 +580,7 @@ public void fromNbpObservableNull() { @Test(timeout = 1000) public void fromNbpObservableEmpty() { - Completable c = Completable.fromNbpObservable(NbpObservable.empty()); + Completable c = Completable.fromNbpObservable(Observable.empty()); c.await(); } @@ -586,7 +588,7 @@ public void fromNbpObservableEmpty() { @Test(timeout = 5000) public void fromNbpObservableSome() { for (int n = 1; n < 10000; n *= 10) { - Completable c = Completable.fromNbpObservable(NbpObservable.range(1, n)); + Completable c = Completable.fromNbpObservable(Observable.range(1, n)); c.await(); } @@ -594,7 +596,7 @@ public void fromNbpObservableSome() { @Test(timeout = 1000, expected = TestException.class) public void fromNbpObservableError() { - Completable c = Completable.fromNbpObservable(NbpObservable.error(new Supplier() { + Completable c = Completable.fromNbpObservable(Observable.error(new Supplier() { @Override public Throwable get() { return new TestException(); @@ -801,14 +803,14 @@ public void mergeIterableIteratorNextThrows() { @Test(timeout = 1000) public void mergeObservableEmpty() { - Completable c = Completable.merge(Observable.empty()); + Completable c = Completable.merge(Flowable.empty()); c.await(); } @Test(timeout = 1000, expected = TestException.class) public void mergeObservableError() { - Completable c = Completable.merge(Observable.error(new Supplier() { + Completable c = Completable.merge(Flowable.error(new Supplier() { @Override public Throwable get() { return new TestException(); @@ -820,7 +822,7 @@ public Throwable get() { @Test(timeout = 1000) public void mergeObservableSingle() { - Completable c = Completable.merge(Observable.just(normal.completable)); + Completable c = Completable.merge(Flowable.just(normal.completable)); c.await(); @@ -829,14 +831,14 @@ public void mergeObservableSingle() { @Test(timeout = 1000, expected = TestException.class) public void mergeObservableSingleThrows() { - Completable c = Completable.merge(Observable.just(error.completable)); + Completable c = Completable.merge(Flowable.just(error.completable)); c.await(); } @Test(timeout = 1000) public void mergeObservableMany() { - Completable c = Completable.merge(Observable.just(normal.completable).repeat(3)); + Completable c = Completable.merge(Flowable.just(normal.completable).repeat(3)); c.await(); @@ -845,7 +847,7 @@ public void mergeObservableMany() { @Test(timeout = 1000, expected = TestException.class) public void mergeObservableManyOneThrows() { - Completable c = Completable.merge(Observable.just(normal.completable, error.completable)); + Completable c = Completable.merge(Flowable.just(normal.completable, error.completable)); c.await(); } @@ -853,7 +855,7 @@ public void mergeObservableManyOneThrows() { @Test(timeout = 1000) public void mergeObservableMaxConcurrent() { final List requested = new ArrayList(); - Observable cs = Observable + Flowable cs = Flowable .just(normal.completable) .repeat(10) .doOnRequest(new LongConsumer() { @@ -1021,14 +1023,14 @@ public void mergeDelayErrorIterableIteratorNextThrows() { @Test(timeout = 1000) public void mergeDelayErrorObservableEmpty() { - Completable c = Completable.mergeDelayError(Observable.empty()); + Completable c = Completable.mergeDelayError(Flowable.empty()); c.await(); } @Test(timeout = 1000, expected = TestException.class) public void mergeDelayErrorObservableError() { - Completable c = Completable.mergeDelayError(Observable.error(new Supplier() { + Completable c = Completable.mergeDelayError(Flowable.error(new Supplier() { @Override public Throwable get() { return new TestException(); @@ -1040,7 +1042,7 @@ public Throwable get() { @Test(timeout = 1000) public void mergeDelayErrorObservableSingle() { - Completable c = Completable.mergeDelayError(Observable.just(normal.completable)); + Completable c = Completable.mergeDelayError(Flowable.just(normal.completable)); c.await(); @@ -1049,14 +1051,14 @@ public void mergeDelayErrorObservableSingle() { @Test(timeout = 1000, expected = TestException.class) public void mergeDelayErrorObservableSingleThrows() { - Completable c = Completable.mergeDelayError(Observable.just(error.completable)); + Completable c = Completable.mergeDelayError(Flowable.just(error.completable)); c.await(); } @Test(timeout = 1000) public void mergeDelayErrorObservableMany() { - Completable c = Completable.mergeDelayError(Observable.just(normal.completable).repeat(3)); + Completable c = Completable.mergeDelayError(Flowable.just(normal.completable).repeat(3)); c.await(); @@ -1065,7 +1067,7 @@ public void mergeDelayErrorObservableMany() { @Test(timeout = 1000, expected = TestException.class) public void mergeDelayErrorObservableManyOneThrows() { - Completable c = Completable.mergeDelayError(Observable.just(normal.completable, error.completable)); + Completable c = Completable.mergeDelayError(Flowable.just(normal.completable, error.completable)); c.await(); } @@ -1073,7 +1075,7 @@ public void mergeDelayErrorObservableManyOneThrows() { @Test(timeout = 1000) public void mergeDelayErrorObservableMaxConcurrent() { final List requested = new ArrayList(); - Observable cs = Observable + Flowable cs = Flowable .just(normal.completable) .repeat(10) .doOnRequest(new LongConsumer() { @@ -2501,10 +2503,10 @@ public void run() { throw new TestException(); } } - }).retryWhen(new Function, Publisher>() { + }).retryWhen(new Function, Publisher>() { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override - public Publisher apply(Observable o) { + public Publisher apply(Flowable o) { return (Publisher)o; } }); @@ -2641,7 +2643,7 @@ public void run() { } @Test(timeout = 1000) public void subscribeNbpSubscriberNormal() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); normal.completable.subscribe(ts); @@ -2652,7 +2654,7 @@ public void subscribeNbpSubscriberNormal() { @Test(timeout = 1000) public void subscribeNbpSubscriberError() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); error.completable.subscribe(ts); @@ -2701,7 +2703,7 @@ public void subscribeSubscriberNull() { @Test(expected = NullPointerException.class) public void subscribeNbpSubscriberNull() { - normal.completable.subscribe((NbpSubscriber)null); + normal.completable.subscribe((Observer)null); } @Test(expected = NullPointerException.class) @@ -2827,9 +2829,9 @@ public void timeoutOtherNull() { @Test(timeout = 1000) public void toNormal() { - Observable flow = normal.completable.to(new Function>() { + Flowable flow = normal.completable.to(new Function>() { @Override - public Observable apply(Completable c) { + public Flowable apply(Completable c) { return c.toFlowable(); } }); @@ -2992,8 +2994,8 @@ public void ambArraySingleError() { @Test(timeout = 1000) public void ambArrayOneFires() { - PublishSubject ps1 = PublishSubject.create(); - PublishSubject ps2 = PublishSubject.create(); + PublishProcessor ps1 = PublishProcessor.create(); + PublishProcessor ps2 = PublishProcessor.create(); Completable c1 = Completable.fromFlowable(ps1); @@ -3023,8 +3025,8 @@ public void run() { @Test(timeout = 1000) public void ambArrayOneFiresError() { - PublishSubject ps1 = PublishSubject.create(); - PublishSubject ps2 = PublishSubject.create(); + PublishProcessor ps1 = PublishProcessor.create(); + PublishProcessor ps2 = PublishProcessor.create(); Completable c1 = Completable.fromFlowable(ps1); @@ -3054,8 +3056,8 @@ public void accept(Throwable v) { @Test(timeout = 1000) public void ambArraySecondFires() { - PublishSubject ps1 = PublishSubject.create(); - PublishSubject ps2 = PublishSubject.create(); + PublishProcessor ps1 = PublishProcessor.create(); + PublishProcessor ps2 = PublishProcessor.create(); Completable c1 = Completable.fromFlowable(ps1); @@ -3085,8 +3087,8 @@ public void run() { @Test(timeout = 1000) public void ambArraySecondFiresError() { - PublishSubject ps1 = PublishSubject.create(); - PublishSubject ps2 = PublishSubject.create(); + PublishProcessor ps1 = PublishProcessor.create(); + PublishProcessor ps2 = PublishProcessor.create(); Completable c1 = Completable.fromFlowable(ps1); @@ -3217,8 +3219,8 @@ public void ambWithNull() { @Test(timeout = 1000) public void ambWithArrayOneFires() { - PublishSubject ps1 = PublishSubject.create(); - PublishSubject ps2 = PublishSubject.create(); + PublishProcessor ps1 = PublishProcessor.create(); + PublishProcessor ps2 = PublishProcessor.create(); Completable c1 = Completable.fromFlowable(ps1); @@ -3248,8 +3250,8 @@ public void run() { @Test(timeout = 1000) public void ambWithArrayOneFiresError() { - PublishSubject ps1 = PublishSubject.create(); - PublishSubject ps2 = PublishSubject.create(); + PublishProcessor ps1 = PublishProcessor.create(); + PublishProcessor ps2 = PublishProcessor.create(); Completable c1 = Completable.fromFlowable(ps1); @@ -3279,8 +3281,8 @@ public void accept(Throwable v) { @Test(timeout = 1000) public void ambWithArraySecondFires() { - PublishSubject ps1 = PublishSubject.create(); - PublishSubject ps2 = PublishSubject.create(); + PublishProcessor ps1 = PublishProcessor.create(); + PublishProcessor ps2 = PublishProcessor.create(); Completable c1 = Completable.fromFlowable(ps1); @@ -3310,8 +3312,8 @@ public void run() { @Test(timeout = 1000) public void ambWithArraySecondFiresError() { - PublishSubject ps1 = PublishSubject.create(); - PublishSubject ps2 = PublishSubject.create(); + PublishProcessor ps1 = PublishProcessor.create(); + PublishProcessor ps2 = PublishProcessor.create(); Completable c1 = Completable.fromFlowable(ps1); @@ -3373,8 +3375,8 @@ public void startWithCompletableError() { @Test(timeout = 1000) public void startWithFlowableNormal() { final AtomicBoolean run = new AtomicBoolean(); - Observable c = normal.completable - .startWith(Observable.fromCallable(new Callable() { + Flowable c = normal.completable + .startWith(Flowable.fromCallable(new Callable() { @Override public Object call() throws Exception { run.set(normal.get() == 0); @@ -3396,8 +3398,8 @@ public Object call() throws Exception { @Test(timeout = 1000) public void startWithFlowableError() { - Observable c = normal.completable - .startWith(Observable.error(new TestException())); + Flowable c = normal.completable + .startWith(Flowable.error(new TestException())); TestSubscriber ts = new TestSubscriber(); @@ -3413,8 +3415,8 @@ public void startWithFlowableError() { @Test(timeout = 1000) public void startWithNbpObservableNormal() { final AtomicBoolean run = new AtomicBoolean(); - NbpObservable c = normal.completable - .startWith(NbpObservable.fromCallable(new Callable() { + Observable c = normal.completable + .startWith(Observable.fromCallable(new Callable() { @Override public Object call() throws Exception { run.set(normal.get() == 0); @@ -3422,7 +3424,7 @@ public Object call() throws Exception { } })); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); c.subscribe(ts); @@ -3436,10 +3438,10 @@ public Object call() throws Exception { @Test(timeout = 1000) public void startWithNbpObservableError() { - NbpObservable c = normal.completable - .startWith(NbpObservable.error(new TestException())); + Observable c = normal.completable + .startWith(Observable.error(new TestException())); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); c.subscribe(ts); @@ -3457,12 +3459,12 @@ public void startWithCompletableNull() { @Test(expected = NullPointerException.class) public void startWithFlowableNull() { - normal.completable.startWith((Observable)null); + normal.completable.startWith((Flowable)null); } @Test(expected = NullPointerException.class) public void startWithNbpObservableNull() { - normal.completable.startWith((NbpObservable)null); + normal.completable.startWith((Observable)null); } @Test(expected = NullPointerException.class) @@ -3472,12 +3474,12 @@ public void endWithCompletableNull() { @Test(expected = NullPointerException.class) public void endWithFlowableNull() { - normal.completable.endWith((Observable)null); + normal.completable.endWith((Flowable)null); } @Test(expected = NullPointerException.class) public void endWithNbpObservableNull() { - normal.completable.endWith((NbpObservable)null); + normal.completable.endWith((Observable)null); } @Test(timeout = 1000) @@ -3514,8 +3516,8 @@ public void endWithCompletableError() { @Test(timeout = 1000) public void endWithFlowableNormal() { final AtomicBoolean run = new AtomicBoolean(); - Observable c = normal.completable - .endWith(Observable.fromCallable(new Callable() { + Flowable c = normal.completable + .endWith(Flowable.fromCallable(new Callable() { @Override public Object call() throws Exception { run.set(normal.get() == 0); @@ -3537,8 +3539,8 @@ public Object call() throws Exception { @Test(timeout = 1000) public void endWithFlowableError() { - Observable c = normal.completable - .endWith(Observable.error(new TestException())); + Flowable c = normal.completable + .endWith(Flowable.error(new TestException())); TestSubscriber ts = new TestSubscriber(); @@ -3554,8 +3556,8 @@ public void endWithFlowableError() { @Test(timeout = 1000) public void endWithNbpObservableNormal() { final AtomicBoolean run = new AtomicBoolean(); - NbpObservable c = normal.completable - .endWith(NbpObservable.fromCallable(new Callable() { + Observable c = normal.completable + .endWith(Observable.fromCallable(new Callable() { @Override public Object call() throws Exception { run.set(normal.get() == 0); @@ -3563,7 +3565,7 @@ public Object call() throws Exception { } })); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); c.subscribe(ts); @@ -3577,10 +3579,10 @@ public Object call() throws Exception { @Test(timeout = 1000) public void endWithNbpObservableError() { - NbpObservable c = normal.completable - .endWith(NbpObservable.error(new TestException())); + Observable c = normal.completable + .endWith(Observable.error(new TestException())); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); c.subscribe(ts); diff --git a/src/test/java/io/reactivex/BackpressureTests.java b/src/test/java/io/reactivex/flowable/BackpressureTests.java similarity index 89% rename from src/test/java/io/reactivex/BackpressureTests.java rename to src/test/java/io/reactivex/flowable/BackpressureTests.java index de964ef8fa..21c9004f8f 100644 --- a/src/test/java/io/reactivex/BackpressureTests.java +++ b/src/test/java/io/reactivex/flowable/BackpressureTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import static org.junit.Assert.*; @@ -23,7 +23,7 @@ import org.junit.rules.TestName; import org.reactivestreams.*; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.exceptions.MissingBackpressureException; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.SubscriptionHelper; @@ -80,7 +80,7 @@ public void doAfterTest() { @Test public void testObserveOn() { - int NUM = (int) (Observable.bufferSize() * 2.1); + int NUM = (int) (Flowable.bufferSize() * 2.1); AtomicInteger c = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); incrementingIntegers(c).observeOn(Schedulers.computation()).take(NUM).subscribe(ts); @@ -88,12 +88,12 @@ public void testObserveOn() { ts.assertNoErrors(); System.out.println("testObserveOn => Received: " + ts.valueCount() + " Emitted: " + c.get()); assertEquals(NUM, ts.valueCount()); - assertTrue(c.get() < Observable.bufferSize() * 4); + assertTrue(c.get() < Flowable.bufferSize() * 4); } @Test public void testObserveOnWithSlowConsumer() { - int NUM = (int) (Observable.bufferSize() * 0.2); + int NUM = (int) (Flowable.bufferSize() * 0.2); AtomicInteger c = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); incrementingIntegers(c).observeOn(Schedulers.computation()).map( @@ -113,16 +113,16 @@ public Integer apply(Integer i) { ts.assertNoErrors(); System.out.println("testObserveOnWithSlowConsumer => Received: " + ts.valueCount() + " Emitted: " + c.get()); assertEquals(NUM, ts.valueCount()); - assertTrue(c.get() < Observable.bufferSize() * 2); + assertTrue(c.get() < Flowable.bufferSize() * 2); } @Test public void testMergeSync() { - int NUM = (int) (Observable.bufferSize() * 4.1); + int NUM = (int) (Flowable.bufferSize() * 4.1); AtomicInteger c1 = new AtomicInteger(); AtomicInteger c2 = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); - Observable merged = Observable.merge(incrementingIntegers(c1), incrementingIntegers(c2)); + Flowable merged = Flowable.merge(incrementingIntegers(c1), incrementingIntegers(c2)); merged.take(NUM).subscribe(ts); ts.awaitTerminalEvent(); @@ -133,17 +133,17 @@ public void testMergeSync() { // either one can starve the other, but neither should be capable of doing more than 5 batches (taking 4.1) // TODO is it possible to make this deterministic rather than one possibly starving the other? // benjchristensen => In general I'd say it's not worth trying to make it so, as "fair" algoritms generally take a performance hit - assertTrue(c1.get() < Observable.bufferSize() * 5); - assertTrue(c2.get() < Observable.bufferSize() * 5); + assertTrue(c1.get() < Flowable.bufferSize() * 5); + assertTrue(c2.get() < Flowable.bufferSize() * 5); } @Test public void testMergeAsync() { - int NUM = (int) (Observable.bufferSize() * 4.1); + int NUM = (int) (Flowable.bufferSize() * 4.1); AtomicInteger c1 = new AtomicInteger(); AtomicInteger c2 = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); - Observable merged = Observable.merge( + Flowable merged = Flowable.merge( incrementingIntegers(c1).subscribeOn(Schedulers.computation()), incrementingIntegers(c2).subscribeOn(Schedulers.computation())); @@ -155,7 +155,7 @@ public void testMergeAsync() { // either one can starve the other, but neither should be capable of doing more than 5 batches (taking 4.1) // TODO is it possible to make this deterministic rather than one possibly starving the other? // benjchristensen => In general I'd say it's not worth trying to make it so, as "fair" algoritms generally take a performance hit - int max = Observable.bufferSize() * 7; + int max = Flowable.bufferSize() * 7; assertTrue("" + c1.get() + " >= " + max, c1.get() < max); assertTrue("" + c2.get() + " >= " + max, c2.get() < max); } @@ -167,12 +167,12 @@ public void testMergeAsyncThenObserveOnLoop() { System.out.println("testMergeAsyncThenObserveOnLoop >> " + i); } // Verify there is no MissingBackpressureException - int NUM = (int) (Observable.bufferSize() * 4.1); + int NUM = (int) (Flowable.bufferSize() * 4.1); AtomicInteger c1 = new AtomicInteger(); AtomicInteger c2 = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); - Observable merged = Observable.merge( + Flowable merged = Flowable.merge( incrementingIntegers(c1).subscribeOn(Schedulers.computation()), incrementingIntegers(c2).subscribeOn(Schedulers.computation())); @@ -192,11 +192,11 @@ public void testMergeAsyncThenObserveOnLoop() { @Test public void testMergeAsyncThenObserveOn() { - int NUM = (int) (Observable.bufferSize() * 4.1); + int NUM = (int) (Flowable.bufferSize() * 4.1); AtomicInteger c1 = new AtomicInteger(); AtomicInteger c2 = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); - Observable merged = Observable.merge( + Flowable merged = Flowable.merge( incrementingIntegers(c1).subscribeOn(Schedulers.computation()), incrementingIntegers(c2).subscribeOn(Schedulers.computation())); @@ -209,13 +209,13 @@ public void testMergeAsyncThenObserveOn() { // TODO is it possible to make this deterministic rather than one possibly starving the other? // benjchristensen => In general I'd say it's not worth trying to make it so, as "fair" algoritms generally take a performance hit // akarnokd => run this in a loop over 10k times and never saw values get as high as 7*SIZE, but since observeOn delays the unsubscription non-deterministically, the test will remain unreliable - assertTrue(c1.get() < Observable.bufferSize() * 7); - assertTrue(c2.get() < Observable.bufferSize() * 7); + assertTrue(c1.get() < Flowable.bufferSize() * 7); + assertTrue(c2.get() < Flowable.bufferSize() * 7); } @Test public void testFlatMapSync() { - int NUM = (int) (Observable.bufferSize() * 2.1); + int NUM = (int) (Flowable.bufferSize() * 2.1); AtomicInteger c = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); @@ -233,13 +233,13 @@ public Publisher apply(Integer i) { System.out.println("testFlatMapSync => Received: " + ts.valueCount() + " Emitted: " + c.get()); assertEquals(NUM, ts.valueCount()); // expect less than 1 buffer since the flatMap is emitting 10 each time, so it is NUM/10 that will be taken. - assertTrue(c.get() < Observable.bufferSize()); + assertTrue(c.get() < Flowable.bufferSize()); } @Test @Ignore // the test is non-deterministic and can't be made deterministic public void testFlatMapAsync() { - int NUM = (int) (Observable.bufferSize() * 2.1); + int NUM = (int) (Flowable.bufferSize() * 2.1); AtomicInteger c = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); @@ -258,22 +258,22 @@ public Publisher apply(Integer i) { ts.awaitTerminalEvent(); ts.assertNoErrors(); - System.out.println("testFlatMapAsync => Received: " + ts.valueCount() + " Emitted: " + c.get() + " Size: " + Observable.bufferSize()); + System.out.println("testFlatMapAsync => Received: " + ts.valueCount() + " Emitted: " + c.get() + " Size: " + Flowable.bufferSize()); assertEquals(NUM, ts.valueCount()); // even though we only need 10, it will request at least Observable.bufferSize(), and then as it drains keep requesting more // and then it will be non-deterministic when the take() causes the unsubscribe as it is scheduled on 10 different schedulers (threads) // normally this number is ~250 but can get up to ~1200 when Observable.bufferSize() == 1024 - assertTrue(c.get() <= Observable.bufferSize() * 2); + assertTrue(c.get() <= Flowable.bufferSize() * 2); } @Test public void testZipSync() { - int NUM = (int) (Observable.bufferSize() * 4.1); + int NUM = (int) (Flowable.bufferSize() * 4.1); AtomicInteger c1 = new AtomicInteger(); AtomicInteger c2 = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); - Observable zipped = Observable.zip( + Flowable zipped = Flowable.zip( incrementingIntegers(c1), incrementingIntegers(c2), new BiFunction() { @@ -290,17 +290,17 @@ public Integer apply(Integer t1, Integer t2) { ts.assertNoErrors(); System.out.println("testZipSync => Received: " + ts.valueCount() + " Emitted: " + c1.get() + " / " + c2.get()); assertEquals(NUM, ts.valueCount()); - assertTrue(c1.get() < Observable.bufferSize() * 7); - assertTrue(c2.get() < Observable.bufferSize() * 7); + assertTrue(c1.get() < Flowable.bufferSize() * 7); + assertTrue(c2.get() < Flowable.bufferSize() * 7); } @Test public void testZipAsync() { - int NUM = (int) (Observable.bufferSize() * 2.1); + int NUM = (int) (Flowable.bufferSize() * 2.1); AtomicInteger c1 = new AtomicInteger(); AtomicInteger c2 = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); - Observable zipped = Observable.zip( + Flowable zipped = Flowable.zip( incrementingIntegers(c1).subscribeOn(Schedulers.computation()), incrementingIntegers(c2).subscribeOn(Schedulers.computation()), new BiFunction() { @@ -315,7 +315,7 @@ public Integer apply(Integer t1, Integer t2) { ts.assertNoErrors(); System.out.println("testZipAsync => Received: " + ts.valueCount() + " Emitted: " + c1.get() + " / " + c2.get()); assertEquals(NUM, ts.valueCount()); - int max = Observable.bufferSize() * 5; + int max = Flowable.bufferSize() * 5; assertTrue("" + c1.get() + " >= " + max, c1.get() < max); assertTrue("" + c2.get() + " >= " + max, c2.get() < max); } @@ -324,7 +324,7 @@ public Integer apply(Integer t1, Integer t2) { public void testSubscribeOnScheduling() { // in a loop for repeating the concurrency in this to increase chance of failure for (int i = 0; i < 100; i++) { - int NUM = (int) (Observable.bufferSize() * 2.1); + int NUM = (int) (Flowable.bufferSize() * 2.1); AtomicInteger c = new AtomicInteger(); ConcurrentLinkedQueue threads = new ConcurrentLinkedQueue(); TestSubscriber ts = new TestSubscriber(); @@ -334,7 +334,7 @@ public void testSubscribeOnScheduling() { ts.assertNoErrors(); System.out.println("testSubscribeOnScheduling => Received: " + ts.valueCount() + " Emitted: " + c.get()); assertEquals(NUM, ts.valueCount()); - assertTrue(c.get() < Observable.bufferSize() * 4); + assertTrue(c.get() < Flowable.bufferSize() * 4); Thread first = null; for (Thread t : threads) { System.out.println("testSubscribeOnScheduling => thread: " + t); @@ -354,7 +354,7 @@ public void testSubscribeOnScheduling() { @Test public void testTakeFilterSkipChainAsync() { - int NUM = (int) (Observable.bufferSize() * 2.1); + int NUM = (int) (Flowable.bufferSize() * 2.1); AtomicInteger c = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); incrementingIntegers(c).observeOn(Schedulers.computation()) @@ -373,7 +373,7 @@ public boolean test(Integer i) { // emit next 1000 that are filtered out // take NUM // so emitted is at least 10000+1000+NUM + extra for buffer size/threshold - int expected = 10000 + 1000 + Observable.bufferSize() * 3 + Observable.bufferSize() / 2; + int expected = 10000 + 1000 + Flowable.bufferSize() * 3 + Flowable.bufferSize() / 2; System.out.println("testTakeFilterSkipChain => Received: " + ts.valueCount() + " Emitted: " + c.get() + " Expected: " + expected); assertEquals(NUM, ts.valueCount()); @@ -386,7 +386,7 @@ public void testUserSubscriberUsingRequestSync() { final AtomicInteger totalReceived = new AtomicInteger(); final AtomicInteger batches = new AtomicInteger(); final AtomicInteger received = new AtomicInteger(); - incrementingIntegers(c).subscribe(new AsyncObserver() { + incrementingIntegers(c).subscribe(new AsyncSubscriber() { @Override public void onStart() { @@ -433,7 +433,7 @@ public void testUserSubscriberUsingRequestAsync() throws InterruptedException { final AtomicInteger batches = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(1); incrementingIntegers(c).subscribeOn(Schedulers.newThread()).subscribe( - new AsyncObserver() { + new AsyncSubscriber() { @Override public void onStart() { @@ -525,7 +525,7 @@ public void testOnBackpressureDrop() { if (System.currentTimeMillis() - t > TimeUnit.SECONDS.toMillis(9)) { break; } - int NUM = (int) (Observable.bufferSize() * 1.1); // > 1 so that take doesn't prevent buffer overflow + int NUM = (int) (Flowable.bufferSize() * 1.1); // > 1 so that take doesn't prevent buffer overflow AtomicInteger c = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); firehose(c).onBackpressureDrop() @@ -551,7 +551,7 @@ public void testOnBackpressureDropWithAction() { final AtomicInteger emitCount = new AtomicInteger(); final AtomicInteger dropCount = new AtomicInteger(); final AtomicInteger passCount = new AtomicInteger(); - final int NUM = Observable.bufferSize() * 3; // > 1 so that take doesn't prevent buffer overflow + final int NUM = Flowable.bufferSize() * 3; // > 1 so that take doesn't prevent buffer overflow TestSubscriber ts = new TestSubscriber(); firehose(emitCount) @@ -590,7 +590,7 @@ public void accept(Integer v) { @Test(timeout = 10000) public void testOnBackpressureDropSynchronous() { for (int i = 0; i < 100; i++) { - int NUM = (int) (Observable.bufferSize() * 1.1); // > 1 so that take doesn't prevent buffer overflow + int NUM = (int) (Flowable.bufferSize() * 1.1); // > 1 so that take doesn't prevent buffer overflow AtomicInteger c = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); firehose(c).onBackpressureDrop() @@ -613,7 +613,7 @@ public void testOnBackpressureDropSynchronous() { public void testOnBackpressureDropSynchronousWithAction() { for (int i = 0; i < 100; i++) { final AtomicInteger dropCount = new AtomicInteger(); - int NUM = (int) (Observable.bufferSize() * 1.1); // > 1 so that take doesn't prevent buffer overflow + int NUM = (int) (Flowable.bufferSize() * 1.1); // > 1 so that take doesn't prevent buffer overflow AtomicInteger c = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); firehose(c).onBackpressureDrop(new Consumer() { @@ -642,7 +642,7 @@ public void accept(Integer j) { @Test(timeout = 2000) public void testOnBackpressureBuffer() { - int NUM = (int) (Observable.bufferSize() * 1.1); // > 1 so that take doesn't prevent buffer overflow + int NUM = (int) (Flowable.bufferSize() * 1.1); // > 1 so that take doesn't prevent buffer overflow AtomicInteger c = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); @@ -670,12 +670,12 @@ public boolean test(Integer t1) { * @param counter * @return */ - private static Observable incrementingIntegers(final AtomicInteger counter) { + private static Flowable incrementingIntegers(final AtomicInteger counter) { return incrementingIntegers(counter, null); } - private static Observable incrementingIntegers(final AtomicInteger counter, final ConcurrentLinkedQueue threadsSeen) { - return Observable.create(new Publisher() { + private static Flowable incrementingIntegers(final AtomicInteger counter, final ConcurrentLinkedQueue threadsSeen) { + return Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber s) { @@ -723,8 +723,8 @@ public void cancel() { * @param counter * @return */ - private static Observable firehose(final AtomicInteger counter) { - return Observable.create(new Publisher() { + private static Flowable firehose(final AtomicInteger counter) { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { Subscription s2 = new FirehoseNoBackpressure(counter, s); diff --git a/src/test/java/io/reactivex/nbp/NbpCombineLatestTests.java b/src/test/java/io/reactivex/flowable/CombineLatestTests.java similarity index 55% rename from src/test/java/io/reactivex/nbp/NbpCombineLatestTests.java rename to src/test/java/io/reactivex/flowable/CombineLatestTests.java index 163140323e..81c8e4981d 100644 --- a/src/test/java/io/reactivex/nbp/NbpCombineLatestTests.java +++ b/src/test/java/io/reactivex/flowable/CombineLatestTests.java @@ -13,33 +13,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.flowable; -import static io.reactivex.NbpObservable.combineLatest; +import static io.reactivex.Flowable.combineLatest; +import static org.junit.Assert.assertNull; import org.junit.*; -import io.reactivex.NbpObservable; +import io.reactivex.Flowable; +import io.reactivex.flowable.CovarianceTest.*; import io.reactivex.functions.*; -import io.reactivex.nbp.NbpCovarianceTest.*; -import io.reactivex.subjects.nbp.NbpBehaviorSubject; +import io.reactivex.processors.BehaviorProcessor; -public class NbpCombineLatestTests { +public class CombineLatestTests { /** * This won't compile if super/extends isn't done correctly on generics */ @Test public void testCovarianceOfCombineLatest() { - NbpObservable horrors = NbpObservable.just(new HorrorMovie()); - NbpObservable ratings = NbpObservable.just(new CoolRating()); + Flowable horrors = Flowable.just(new HorrorMovie()); + Flowable ratings = Flowable.just(new CoolRating()); - NbpObservable. combineLatest(horrors, ratings, combine).toBlocking().forEach(action); - NbpObservable. combineLatest(horrors, ratings, combine).toBlocking().forEach(action); - NbpObservable. combineLatest(horrors, ratings, combine).toBlocking().forEach(extendedAction); - NbpObservable. combineLatest(horrors, ratings, combine).toBlocking().forEach(action); - NbpObservable. combineLatest(horrors, ratings, combine).toBlocking().forEach(action); + Flowable. combineLatest(horrors, ratings, combine).toBlocking().forEach(action); + Flowable. combineLatest(horrors, ratings, combine).toBlocking().forEach(action); + Flowable. combineLatest(horrors, ratings, combine).toBlocking().forEach(extendedAction); + Flowable. combineLatest(horrors, ratings, combine).toBlocking().forEach(action); + Flowable. combineLatest(horrors, ratings, combine).toBlocking().forEach(action); - NbpObservable. combineLatest(horrors, ratings, combine); + Flowable. combineLatest(horrors, ratings, combine); } BiFunction combine = new BiFunction() { @@ -67,10 +68,10 @@ public void accept(ExtendedResult t1) { @Test public void testNullEmitting() throws Exception { // FIXME this is no longer allowed - NbpObservable nullNbpObservable = NbpBehaviorSubject.createDefault((Boolean) null); - NbpObservable nonNullNbpObservable = NbpBehaviorSubject.createDefault(true); - NbpObservable combined = - combineLatest(nullNbpObservable, nonNullNbpObservable, new BiFunction() { + Flowable nullObservable = BehaviorProcessor.createDefault((Boolean) null); + Flowable nonNullObservable = BehaviorProcessor.createDefault(true); + Flowable combined = + combineLatest(nullObservable, nonNullObservable, new BiFunction() { @Override public Boolean apply(Boolean bool1, Boolean bool2) { return bool1 == null ? null : bool2; @@ -79,7 +80,7 @@ public Boolean apply(Boolean bool1, Boolean bool2) { combined.subscribe(new Consumer() { @Override public void accept(Boolean aBoolean) { - Assert.assertNull(aBoolean); + assertNull(aBoolean); } }); } diff --git a/src/test/java/io/reactivex/nbp/NbpConcatTests.java b/src/test/java/io/reactivex/flowable/ConcatTests.java similarity index 60% rename from src/test/java/io/reactivex/nbp/NbpConcatTests.java rename to src/test/java/io/reactivex/flowable/ConcatTests.java index 40f5cbfdf8..7d50bdc005 100644 --- a/src/test/java/io/reactivex/nbp/NbpConcatTests.java +++ b/src/test/java/io/reactivex/flowable/ConcatTests.java @@ -10,26 +10,26 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.flowable; import static org.junit.Assert.assertEquals; import java.util.*; import org.junit.Test; +import org.reactivestreams.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; -import io.reactivex.nbp.NbpCovarianceTest.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.CovarianceTest.*; -public class NbpConcatTests { +public class ConcatTests { @Test public void testConcatSimple() { - NbpObservable o1 = NbpObservable.just("one", "two"); - NbpObservable o2 = NbpObservable.just("three", "four"); + Flowable o1 = Flowable.just("one", "two"); + Flowable o2 = Flowable.just("three", "four"); - List values = NbpObservable.concat(o1, o2).toList().toBlocking().single(); + List values = Flowable.concat(o1, o2).toList().toBlocking().single(); assertEquals("one", values.get(0)); assertEquals("two", values.get(1)); @@ -38,14 +38,14 @@ public void testConcatSimple() { } @Test - public void testConcatWithNbpObservableOfNbpObservable() { - NbpObservable o1 = NbpObservable.just("one", "two"); - NbpObservable o2 = NbpObservable.just("three", "four"); - NbpObservable o3 = NbpObservable.just("five", "six"); + public void testConcatWithObservableOfObservable() { + Flowable o1 = Flowable.just("one", "two"); + Flowable o2 = Flowable.just("three", "four"); + Flowable o3 = Flowable.just("five", "six"); - NbpObservable> os = NbpObservable.just(o1, o2, o3); + Flowable> os = Flowable.just(o1, o2, o3); - List values = NbpObservable.concat(os).toList().toBlocking().single(); + List values = Flowable.concat(os).toList().toBlocking().single(); assertEquals("one", values.get(0)); assertEquals("two", values.get(1)); @@ -56,15 +56,15 @@ public void testConcatWithNbpObservableOfNbpObservable() { } @Test - public void testConcatWithIterableOfNbpObservable() { - NbpObservable o1 = NbpObservable.just("one", "two"); - NbpObservable o2 = NbpObservable.just("three", "four"); - NbpObservable o3 = NbpObservable.just("five", "six"); + public void testConcatWithIterableOfObservable() { + Flowable o1 = Flowable.just("one", "two"); + Flowable o2 = Flowable.just("three", "four"); + Flowable o3 = Flowable.just("five", "six"); @SuppressWarnings("unchecked") - Iterable> is = Arrays.asList(o1, o2, o3); + Iterable> is = Arrays.asList(o1, o2, o3); - List values = NbpObservable.concat(NbpObservable.fromIterable(is)).toList().toBlocking().single(); + List values = Flowable.concat(Flowable.fromIterable(is)).toList().toBlocking().single(); assertEquals("one", values.get(0)); assertEquals("two", values.get(1)); @@ -81,12 +81,12 @@ public void testConcatCovariance() { Media media = new Media(); HorrorMovie horrorMovie2 = new HorrorMovie(); - NbpObservable o1 = NbpObservable. just(horrorMovie1, movie); - NbpObservable o2 = NbpObservable.just(media, horrorMovie2); + Flowable o1 = Flowable. just(horrorMovie1, movie); + Flowable o2 = Flowable.just(media, horrorMovie2); - NbpObservable> os = NbpObservable.just(o1, o2); + Flowable> os = Flowable.just(o1, o2); - List values = NbpObservable.concat(os).toList().toBlocking().single(); + List values = Flowable.concat(os).toList().toBlocking().single(); assertEquals(horrorMovie1, values.get(0)); assertEquals(movie, values.get(1)); @@ -103,12 +103,12 @@ public void testConcatCovariance2() { Media media2 = new Media(); HorrorMovie horrorMovie2 = new HorrorMovie(); - NbpObservable o1 = NbpObservable.just(horrorMovie1, movie, media1); - NbpObservable o2 = NbpObservable.just(media2, horrorMovie2); + Flowable o1 = Flowable.just(horrorMovie1, movie, media1); + Flowable o2 = Flowable.just(media2, horrorMovie2); - NbpObservable> os = NbpObservable.just(o1, o2); + Flowable> os = Flowable.just(o1, o2); - List values = NbpObservable.concat(os).toList().toBlocking().single(); + List values = Flowable.concat(os).toList().toBlocking().single(); assertEquals(horrorMovie1, values.get(0)); assertEquals(movie, values.get(1)); @@ -125,10 +125,10 @@ public void testConcatCovariance3() { Media media = new Media(); HorrorMovie horrorMovie2 = new HorrorMovie(); - NbpObservable o1 = NbpObservable.just(horrorMovie1, movie); - NbpObservable o2 = NbpObservable.just(media, horrorMovie2); + Flowable o1 = Flowable.just(horrorMovie1, movie); + Flowable o2 = Flowable.just(media, horrorMovie2); - List values = NbpObservable.concat(o1, o2).toList().toBlocking().single(); + List values = Flowable.concat(o1, o2).toList().toBlocking().single(); assertEquals(horrorMovie1, values.get(0)); assertEquals(movie, values.get(1)); @@ -144,9 +144,9 @@ public void testConcatCovariance4() { Media media = new Media(); HorrorMovie horrorMovie2 = new HorrorMovie(); - NbpObservable o1 = NbpObservable.create(new NbpOnSubscribe() { + Flowable o1 = Flowable.create(new Publisher() { @Override - public void accept(NbpSubscriber o) { + public void subscribe(Subscriber o) { o.onNext(horrorMovie1); o.onNext(movie); // o.onNext(new Media()); // correctly doesn't compile @@ -154,9 +154,9 @@ public void accept(NbpSubscriber o) { } }); - NbpObservable o2 = NbpObservable.just(media, horrorMovie2); + Flowable o2 = Flowable.just(media, horrorMovie2); - List values = NbpObservable.concat(o1, o2).toList().toBlocking().single(); + List values = Flowable.concat(o1, o2).toList().toBlocking().single(); assertEquals(horrorMovie1, values.get(0)); assertEquals(movie, values.get(1)); diff --git a/src/test/java/io/reactivex/nbp/NbpCovarianceTest.java b/src/test/java/io/reactivex/flowable/CovarianceTest.java similarity index 55% rename from src/test/java/io/reactivex/nbp/NbpCovarianceTest.java rename to src/test/java/io/reactivex/flowable/CovarianceTest.java index a3c96343ce..5b454d638a 100644 --- a/src/test/java/io/reactivex/nbp/NbpCovarianceTest.java +++ b/src/test/java/io/reactivex/flowable/CovarianceTest.java @@ -14,35 +14,36 @@ * limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.flowable; import static org.junit.Assert.assertEquals; import java.util.*; import org.junit.Test; +import org.reactivestreams.Publisher; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.NbpTransformer; +import io.reactivex.Flowable; +import io.reactivex.Flowable.Transformer; +import io.reactivex.flowables.GroupedFlowable; import io.reactivex.functions.*; -import io.reactivex.observables.nbp.NbpGroupedObservable; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subscribers.TestSubscriber; /** * Test super/extends of generics. * * See https://github.com/Netflix/RxJava/pull/331 */ -public class NbpCovarianceTest { +public class CovarianceTest { /** * This won't compile if super/extends isn't done correctly on generics */ @Test public void testCovarianceOfFrom() { - NbpObservable. just(new HorrorMovie()); - NbpObservable. fromIterable(new ArrayList()); - // NbpObservable.from(new Movie()); // may not compile + Flowable. just(new HorrorMovie()); + Flowable. fromIterable(new ArrayList()); + // Observable.from(new Movie()); // may not compile } @Test @@ -55,18 +56,19 @@ public int compare(Media t1, Media t2) { }; // this one would work without the covariance generics - NbpObservable o = NbpObservable.just(new Movie(), new TVSeason(), new Album()); + Flowable o = Flowable.just(new Movie(), new TVSeason(), new Album()); o.toSortedList(SORT_FUNCTION); // this one would NOT work without the covariance generics - NbpObservable o2 = NbpObservable.just(new Movie(), new ActionMovie(), new HorrorMovie()); + Flowable o2 = Flowable.just(new Movie(), new ActionMovie(), new HorrorMovie()); o2.toSortedList(SORT_FUNCTION); } @Test public void testGroupByCompose() { - NbpObservable movies = NbpObservable.just(new HorrorMovie(), new ActionMovie(), new Movie()); - NbpTestSubscriber ts = new NbpTestSubscriber(); + Flowable movies = Flowable.just(new HorrorMovie(), new ActionMovie(), new Movie()); + TestSubscriber ts = new TestSubscriber(); + movies .groupBy(new Function() { @Override @@ -74,35 +76,35 @@ public Object apply(Movie v) { return v.getClass(); } }) - .doOnNext(new Consumer>() { + .doOnNext(new Consumer>() { @Override - public void accept(NbpGroupedObservable g) { + public void accept(GroupedFlowable g) { System.out.println(g.key()); } }) - .flatMap(new Function, NbpObservable>() { + .flatMap(new Function, Publisher>() { @Override - public NbpObservable apply(NbpGroupedObservable g) { + public Publisher apply(GroupedFlowable g) { return g - .doOnNext(new Consumer() { - @Override - public void accept(Movie pv) { - System.out.println(pv); - } - }) - .compose(new Function, NbpObservable>() { - @Override - public NbpObservable apply(NbpObservable m) { - return m.concatWith(NbpObservable.just(new ActionMovie())); - } - } - ) - .map(new Function() { - @Override - public String apply(Movie v) { - return v.toString(); - } - }); + .doOnNext(new Consumer() { + @Override + public void accept(Movie v) { + System.out.println(v); + } + }) + .compose(new Transformer() { + @Override + public Publisher apply(Flowable m) { + return m.concatWith(Flowable.just(new ActionMovie())); + } + } + ) + .map(new Function() { + @Override + public String apply(Object v) { + return v.toString(); + } + }); } }) .subscribe(ts); @@ -115,11 +117,11 @@ public String apply(Movie v) { @SuppressWarnings("unused") @Test public void testCovarianceOfCompose() { - NbpObservable movie = NbpObservable.just(new HorrorMovie()); - NbpObservable movie2 = movie.compose(new Function, NbpObservable>() { + Flowable movie = Flowable.just(new HorrorMovie()); + Flowable movie2 = movie.compose(new Transformer() { @Override - public NbpObservable apply(NbpObservable t) { - return NbpObservable.just(new Movie()); + public Publisher apply(Flowable t) { + return Flowable.just(new Movie()); } }); } @@ -127,11 +129,11 @@ public NbpObservable apply(NbpObservable t) { @SuppressWarnings("unused") @Test public void testCovarianceOfCompose2() { - NbpObservable movie = NbpObservable. just(new HorrorMovie()); - NbpObservable movie2 = movie.compose(new Function, NbpObservable>() { + Flowable movie = Flowable. just(new HorrorMovie()); + Flowable movie2 = movie.compose(new Transformer() { @Override - public NbpObservable apply(NbpObservable t) { - return NbpObservable.just(new HorrorMovie()); + public Publisher apply(Flowable t) { + return Flowable.just(new HorrorMovie()); } }); } @@ -139,11 +141,11 @@ public NbpObservable apply(NbpObservable t) { @SuppressWarnings("unused") @Test public void testCovarianceOfCompose3() { - NbpObservable movie = NbpObservable.just(new HorrorMovie()); - NbpObservable movie2 = movie.compose(new Function, NbpObservable>() { + Flowable movie = Flowable.just(new HorrorMovie()); + Flowable movie2 = movie.compose(new Transformer() { @Override - public NbpObservable apply(NbpObservable t) { - return NbpObservable.just(new HorrorMovie()).map(new Function() { + public Publisher apply(Flowable t) { + return Flowable.just(new HorrorMovie()).map(new Function() { @Override public HorrorMovie apply(HorrorMovie v) { return v; @@ -157,10 +159,10 @@ public HorrorMovie apply(HorrorMovie v) { @SuppressWarnings("unused") @Test public void testCovarianceOfCompose4() { - NbpObservable movie = NbpObservable.just(new HorrorMovie()); - NbpObservable movie2 = movie.compose(new Function, NbpObservable>() { + Flowable movie = Flowable.just(new HorrorMovie()); + Flowable movie2 = movie.compose(new Transformer() { @Override - public NbpObservable apply(NbpObservable t1) { + public Publisher apply(Flowable t1) { return t1.map(new Function() { @Override public HorrorMovie apply(HorrorMovie v) { @@ -175,15 +177,15 @@ public HorrorMovie apply(HorrorMovie v) { public void testComposeWithDeltaLogic() { List list1 = Arrays.asList(new Movie(), new HorrorMovie(), new ActionMovie()); List list2 = Arrays.asList(new ActionMovie(), new Movie(), new HorrorMovie(), new ActionMovie()); - NbpObservable> movies = NbpObservable.just(list1, list2); + Flowable> movies = Flowable.just(list1, list2); movies.compose(deltaTransformer); } - static Function>, NbpObservable> calculateDelta = new Function>, NbpObservable>() { + static Function>, Flowable> calculateDelta = new Function>, Flowable>() { @Override - public NbpObservable apply(List> listOfLists) { + public Flowable apply(List> listOfLists) { if (listOfLists.size() == 1) { - return NbpObservable.fromIterable(listOfLists.get(0)); + return Flowable.fromIterable(listOfLists.get(0)); } else { // diff the two List newList = listOfLists.get(1); @@ -202,14 +204,14 @@ public NbpObservable apply(List> listOfLists) { delta.add(new Movie()); } - return NbpObservable.fromIterable(delta); + return Flowable.fromIterable(delta); } } }; - static NbpTransformer, Movie> deltaTransformer = new NbpTransformer, Movie>() { + static Transformer, Movie> deltaTransformer = new Transformer, Movie>() { @Override - public NbpObservable apply(NbpObservable> movieList) { + public Publisher apply(Flowable> movieList) { return movieList .startWith(new ArrayList()) .buffer(2, 1) diff --git a/src/test/java/io/reactivex/ErrorHandlingTests.java b/src/test/java/io/reactivex/flowable/ErrorHandlingTests.java similarity index 88% rename from src/test/java/io/reactivex/ErrorHandlingTests.java rename to src/test/java/io/reactivex/flowable/ErrorHandlingTests.java index b538fe216e..21659d7dd3 100644 --- a/src/test/java/io/reactivex/ErrorHandlingTests.java +++ b/src/test/java/io/reactivex/flowable/ErrorHandlingTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import static org.junit.Assert.assertNotNull; @@ -21,7 +21,9 @@ import org.junit.Test; import org.reactivestreams.Subscriber; +import io.reactivex.Flowable; import io.reactivex.schedulers.Schedulers; +import io.reactivex.subscribers.DefaultObserver; public class ErrorHandlingTests { @@ -33,8 +35,8 @@ public class ErrorHandlingTests { public void testOnNextError() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference caughtError = new AtomicReference(); - Observable o = Observable.interval(50, TimeUnit.MILLISECONDS); - Subscriber observer = new Observer() { + Flowable o = Flowable.interval(50, TimeUnit.MILLISECONDS); + Subscriber observer = new DefaultObserver() { @Override public void onComplete() { @@ -69,8 +71,8 @@ public void onNext(Long args) { public void testOnNextErrorAcrossThread() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference caughtError = new AtomicReference(); - Observable o = Observable.interval(50, TimeUnit.MILLISECONDS); - Subscriber observer = new Observer() { + Flowable o = Flowable.interval(50, TimeUnit.MILLISECONDS); + Subscriber observer = new DefaultObserver() { @Override public void onComplete() { diff --git a/src/test/java/io/reactivex/EventStream.java b/src/test/java/io/reactivex/flowable/EventStream.java similarity index 92% rename from src/test/java/io/reactivex/EventStream.java rename to src/test/java/io/reactivex/flowable/EventStream.java index 45a3e3992c..5ce5fac2af 100644 --- a/src/test/java/io/reactivex/EventStream.java +++ b/src/test/java/io/reactivex/flowable/EventStream.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import java.util.*; import org.reactivestreams.Subscriber; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; @@ -28,9 +28,9 @@ public final class EventStream { private EventStream() { throw new IllegalStateException("No instances!"); } - public static Observable getEventStream(final String type, final int numInstances) { + public static Flowable getEventStream(final String type, final int numInstances) { - return Observable.generate(new Consumer>() { + return Flowable.generate(new Consumer>() { @Override public void accept(Subscriber s) { s.onNext(randomEvent(type, numInstances)); diff --git a/src/test/java/io/reactivex/GroupByTests.java b/src/test/java/io/reactivex/flowable/GroupByTests.java similarity index 82% rename from src/test/java/io/reactivex/GroupByTests.java rename to src/test/java/io/reactivex/flowable/GroupByTests.java index 73ba84e80b..991385e2ee 100644 --- a/src/test/java/io/reactivex/GroupByTests.java +++ b/src/test/java/io/reactivex/flowable/GroupByTests.java @@ -11,21 +11,21 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import org.junit.Test; import org.reactivestreams.Publisher; -import io.reactivex.Observable; -import io.reactivex.EventStream.Event; +import io.reactivex.Flowable; +import io.reactivex.flowable.EventStream.Event; +import io.reactivex.flowables.GroupedFlowable; import io.reactivex.functions.*; -import io.reactivex.observables.GroupedObservable; public class GroupByTests { @Test public void testTakeUnsubscribesOnGroupBy() { - Observable.merge( + Flowable.merge( EventStream.getEventStream("HTTP-ClusterA", 50), EventStream.getEventStream("HTTP-ClusterB", 20) ) @@ -38,9 +38,9 @@ public Object apply(Event event) { }) .take(1) .toBlocking() - .forEach(new Consumer>() { + .forEach(new Consumer>() { @Override - public void accept(GroupedObservable v) { + public void accept(GroupedFlowable v) { System.out.println(v); v.take(1).subscribe(); // FIXME groups need consumption to a certain degree to cancel upstream } @@ -51,7 +51,7 @@ public void accept(GroupedObservable v) { @Test public void testTakeUnsubscribesOnFlatMapOfGroupBy() { - Observable.merge( + Flowable.merge( EventStream.getEventStream("HTTP-ClusterA", 50), EventStream.getEventStream("HTTP-ClusterB", 20) ) @@ -62,9 +62,9 @@ public Object apply(Event event) { return event.type; } }) - .flatMap(new Function, Publisher>() { + .flatMap(new Function, Publisher>() { @Override - public Publisher apply(GroupedObservable g) { + public Publisher apply(GroupedFlowable g) { return g.map(new Function() { @Override public Object apply(Event event) { diff --git a/src/test/java/io/reactivex/nbp/NbpMergeTests.java b/src/test/java/io/reactivex/flowable/MergeTests.java similarity index 51% rename from src/test/java/io/reactivex/nbp/NbpMergeTests.java rename to src/test/java/io/reactivex/flowable/MergeTests.java index 2c01b3a7f6..09b475854d 100644 --- a/src/test/java/io/reactivex/nbp/NbpMergeTests.java +++ b/src/test/java/io/reactivex/flowable/MergeTests.java @@ -11,60 +11,61 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.flowable; import static org.junit.Assert.*; import java.util.List; import org.junit.Test; +import org.reactivestreams.Publisher; -import io.reactivex.NbpObservable; +import io.reactivex.Flowable; +import io.reactivex.flowable.CovarianceTest.*; import io.reactivex.functions.Supplier; -import io.reactivex.nbp.NbpCovarianceTest.*; -public class NbpMergeTests { +public class MergeTests { /** * This won't compile if super/extends isn't done correctly on generics */ @Test public void testCovarianceOfMerge() { - NbpObservable horrors = NbpObservable.just(new HorrorMovie()); - NbpObservable> metaHorrors = NbpObservable.just(horrors); - NbpObservable. merge(metaHorrors); + Flowable horrors = Flowable.just(new HorrorMovie()); + Flowable> metaHorrors = Flowable.just(horrors); + Flowable. merge(metaHorrors); } @Test public void testMergeCovariance() { - NbpObservable o1 = NbpObservable. just(new HorrorMovie(), new Movie()); - NbpObservable o2 = NbpObservable.just(new Media(), new HorrorMovie()); + Flowable o1 = Flowable. just(new HorrorMovie(), new Movie()); + Flowable o2 = Flowable.just(new Media(), new HorrorMovie()); - NbpObservable> os = NbpObservable.just(o1, o2); + Flowable> os = Flowable.just(o1, o2); - List values = NbpObservable.merge(os).toList().toBlocking().single(); + List values = Flowable.merge(os).toList().toBlocking().single(); assertEquals(4, values.size()); } @Test public void testMergeCovariance2() { - NbpObservable o1 = NbpObservable.just(new HorrorMovie(), new Movie(), new Media()); - NbpObservable o2 = NbpObservable.just(new Media(), new HorrorMovie()); + Flowable o1 = Flowable.just(new HorrorMovie(), new Movie(), new Media()); + Flowable o2 = Flowable.just(new Media(), new HorrorMovie()); - NbpObservable> os = NbpObservable.just(o1, o2); + Flowable> os = Flowable.just(o1, o2); - List values = NbpObservable.merge(os).toList().toBlocking().single(); + List values = Flowable.merge(os).toList().toBlocking().single(); assertEquals(5, values.size()); } @Test public void testMergeCovariance3() { - NbpObservable o1 = NbpObservable.just(new HorrorMovie(), new Movie()); - NbpObservable o2 = NbpObservable.just(new Media(), new HorrorMovie()); + Flowable o1 = Flowable.just(new HorrorMovie(), new Movie()); + Flowable o2 = Flowable.just(new Media(), new HorrorMovie()); - List values = NbpObservable.merge(o1, o2).toList().toBlocking().single(); + List values = Flowable.merge(o1, o2).toList().toBlocking().single(); assertTrue(values.get(0) instanceof HorrorMovie); assertTrue(values.get(1) instanceof Movie); @@ -75,19 +76,19 @@ public void testMergeCovariance3() { @Test public void testMergeCovariance4() { - NbpObservable o1 = NbpObservable.defer(new Supplier>() { + Flowable o1 = Flowable.defer(new Supplier>() { @Override - public NbpObservable get() { - return NbpObservable.just( + public Publisher get() { + return Flowable.just( new HorrorMovie(), new Movie() ); } }); - NbpObservable o2 = NbpObservable.just(new Media(), new HorrorMovie()); + Flowable o2 = Flowable.just(new Media(), new HorrorMovie()); - List values = NbpObservable.merge(o1, o2).toList().toBlocking().single(); + List values = Flowable.merge(o1, o2).toList().toBlocking().single(); assertTrue(values.get(0) instanceof HorrorMovie); assertTrue(values.get(1) instanceof Movie); diff --git a/src/test/java/io/reactivex/NotificationTest.java b/src/test/java/io/reactivex/flowable/NotificationTest.java similarity index 98% rename from src/test/java/io/reactivex/NotificationTest.java rename to src/test/java/io/reactivex/flowable/NotificationTest.java index 85e609c751..d381011dac 100644 --- a/src/test/java/io/reactivex/NotificationTest.java +++ b/src/test/java/io/reactivex/flowable/NotificationTest.java @@ -11,10 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import org.junit.*; +import io.reactivex.*; + public class NotificationTest { @Test(expected = NullPointerException.class) diff --git a/src/test/java/io/reactivex/ObservableConversionTest.java b/src/test/java/io/reactivex/flowable/ObservableConversionTest.java similarity index 91% rename from src/test/java/io/reactivex/ObservableConversionTest.java rename to src/test/java/io/reactivex/flowable/ObservableConversionTest.java index dac7b15419..aa887d964a 100644 --- a/src/test/java/io/reactivex/ObservableConversionTest.java +++ b/src/test/java/io/reactivex/flowable/ObservableConversionTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import java.util.*; import java.util.concurrent.ConcurrentLinkedQueue; @@ -20,10 +20,12 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable; +import io.reactivex.Flowable.Operator; import io.reactivex.functions.*; -import io.reactivex.internal.operators.*; +import io.reactivex.internal.operators.flowable.*; import io.reactivex.schedulers.Schedulers; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; public class ObservableConversionTest { @@ -128,16 +130,16 @@ public CylonDetectorObservable apply(final Publisher onSubscribe) { } } - public static class ConvertToObservable implements Function, Observable> { + public static class ConvertToObservable implements Function, Flowable> { @Override - public Observable apply(final Publisher onSubscribe) { - return Observable.create(onSubscribe); + public Flowable apply(final Publisher onSubscribe) { + return Flowable.create(onSubscribe); } } @Test public void testConversionBetweenObservableClasses() { - final TestSubscriber subscriber = new TestSubscriber(new Observer() { + final TestSubscriber subscriber = new TestSubscriber(new DefaultObserver() { @Override public void onComplete() { @@ -158,7 +160,7 @@ public void onNext(String t) { List crewOfBattlestarGalactica = Arrays.asList(new Object[] {"William Adama", "Laura Roslin", "Lee Adama", new Cylon()}); - Observable.fromIterable(crewOfBattlestarGalactica) + Flowable.fromIterable(crewOfBattlestarGalactica) .doOnNext(new Consumer() { @Override public void accept(Object pv) { @@ -196,11 +198,11 @@ public String apply(String a, String n) { public void testConvertToConcurrentQueue() { final AtomicReference thrown = new AtomicReference(null); final AtomicBoolean isFinished = new AtomicBoolean(false); - ConcurrentLinkedQueue queue = Observable.range(0,5) + ConcurrentLinkedQueue queue = Flowable.range(0,5) .flatMap(new Function>() { @Override public Publisher apply(final Integer i) { - return Observable.range(0, 5) + return Flowable.range(0, 5) .observeOn(Schedulers.io()) .map(new Function() { @Override @@ -215,11 +217,11 @@ public Integer apply(Integer k) { }); } }) - .to(new Function, ConcurrentLinkedQueue>() { + .to(new Function, ConcurrentLinkedQueue>() { @Override - public ConcurrentLinkedQueue apply(Observable onSubscribe) { + public ConcurrentLinkedQueue apply(Flowable onSubscribe) { final ConcurrentLinkedQueue q = new ConcurrentLinkedQueue(); - onSubscribe.subscribe(new Observer(){ + onSubscribe.subscribe(new DefaultObserver(){ @Override public void onComplete() { isFinished.set(true); diff --git a/src/test/java/io/reactivex/ObservableDoOnTest.java b/src/test/java/io/reactivex/flowable/ObservableDoOnTest.java similarity index 87% rename from src/test/java/io/reactivex/ObservableDoOnTest.java rename to src/test/java/io/reactivex/flowable/ObservableDoOnTest.java index 1ad2fafd90..b3afe4a1ba 100644 --- a/src/test/java/io/reactivex/ObservableDoOnTest.java +++ b/src/test/java/io/reactivex/flowable/ObservableDoOnTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import static org.junit.Assert.*; @@ -19,7 +19,7 @@ import org.junit.Test; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.functions.Consumer; public class ObservableDoOnTest { @@ -27,7 +27,7 @@ public class ObservableDoOnTest { @Test public void testDoOnEach() { final AtomicReference r = new AtomicReference(); - String output = Observable.just("one").doOnNext(new Consumer() { + String output = Flowable.just("one").doOnNext(new Consumer() { @Override public void accept(String v) { r.set(v); @@ -43,7 +43,7 @@ public void testDoOnError() { final AtomicReference r = new AtomicReference(); Throwable t = null; try { - Observable. error(new RuntimeException("an error")) + Flowable. error(new RuntimeException("an error")) .doOnError(new Consumer() { @Override public void accept(Throwable v) { @@ -62,7 +62,7 @@ public void accept(Throwable v) { @Test public void testDoOnCompleted() { final AtomicBoolean r = new AtomicBoolean(); - String output = Observable.just("one").doOnComplete(new Runnable() { + String output = Flowable.just("one").doOnComplete(new Runnable() { @Override public void run() { r.set(true); diff --git a/src/test/java/io/reactivex/ObservableNullTests.java b/src/test/java/io/reactivex/flowable/ObservableNullTests.java similarity index 90% rename from src/test/java/io/reactivex/ObservableNullTests.java rename to src/test/java/io/reactivex/flowable/ObservableNullTests.java index 35274c9452..775ed06d9b 100644 --- a/src/test/java/io/reactivex/ObservableNullTests.java +++ b/src/test/java/io/reactivex/flowable/ObservableNullTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import java.lang.reflect.*; import java.util.*; @@ -20,12 +20,14 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.*; +import io.reactivex.Flowable.Operator; +import io.reactivex.Optional; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; +import io.reactivex.processors.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.*; import io.reactivex.subscribers.TestSubscriber; /** @@ -33,7 +35,7 @@ */ public class ObservableNullTests { - Observable just1 = Observable.just(1); + Flowable just1 = Flowable.just(1); //*********************************************************** // Static methods @@ -41,23 +43,23 @@ public class ObservableNullTests { @Test(expected = NullPointerException.class) public void ambVarargsNull() { - Observable.amb((Publisher[])null); + Flowable.amb((Publisher[])null); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void ambVarargsOneIsNull() { - Observable.amb(Observable.never(), null).toBlocking().lastOption(); + Flowable.amb(Flowable.never(), null).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void ambIterableNull() { - Observable.amb((Iterable>)null); + Flowable.amb((Iterable>)null); } @Test(expected = NullPointerException.class) public void ambIterableIteratorNull() { - Observable.amb(new Iterable>() { + Flowable.amb(new Iterable>() { @Override public Iterator> iterator() { return null; @@ -68,12 +70,12 @@ public Iterator> iterator() { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void ambIterableOneIsNull() { - Observable.amb(Arrays.asList(Observable.never(), null)).toBlocking().lastOption(); + Flowable.amb(Arrays.asList(Flowable.never(), null)).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void combineLatestVarargsNull() { - Observable.combineLatest(new Function() { + Flowable.combineLatest(new Function() { @Override public Object apply(Object[] v) { return 1; @@ -84,17 +86,17 @@ public Object apply(Object[] v) { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void combineLatestVarargsOneIsNull() { - Observable.combineLatest(new Function() { + Flowable.combineLatest(new Function() { @Override public Object apply(Object[] v) { return 1; } - }, true, 128, Observable.never(), null).toBlocking().lastOption(); + }, true, 128, Flowable.never(), null).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void combineLatestIterableNull() { - Observable.combineLatest((Iterable>)null, new Function() { + Flowable.combineLatest((Iterable>)null, new Function() { @Override public Object apply(Object[] v) { return 1; @@ -104,7 +106,7 @@ public Object apply(Object[] v) { @Test(expected = NullPointerException.class) public void combineLatestIterableIteratorNull() { - Observable.combineLatest(new Iterable>() { + Flowable.combineLatest(new Iterable>() { @Override public Iterator> iterator() { return null; @@ -120,7 +122,7 @@ public Object apply(Object[] v) { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void combineLatestIterableOneIsNull() { - Observable.combineLatest(Arrays.asList(Observable.never(), null), new Function() { + Flowable.combineLatest(Arrays.asList(Flowable.never(), null), new Function() { @Override public Object apply(Object[] v) { return 1; @@ -131,13 +133,13 @@ public Object apply(Object[] v) { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void combineLatestVarargsFunctionNull() { - Observable.combineLatest(null, true, 128, Observable.never()); + Flowable.combineLatest(null, true, 128, Flowable.never()); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void combineLatestVarargsFunctionReturnsNull() { - Observable.combineLatest(new Function() { + Flowable.combineLatest(new Function() { @Override public Object apply(Object[] v) { return null; @@ -148,13 +150,13 @@ public Object apply(Object[] v) { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void combineLatestIterableFunctionNull() { - Observable.combineLatest(Arrays.asList(just1), null, true, 128); + Flowable.combineLatest(Arrays.asList(just1), null, true, 128); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void combineLatestIterableFunctionReturnsNull() { - Observable.combineLatest(Arrays.asList(just1), new Function() { + Flowable.combineLatest(Arrays.asList(just1), new Function() { @Override public Object apply(Object[] v) { return null; @@ -164,12 +166,12 @@ public Object apply(Object[] v) { @Test(expected = NullPointerException.class) public void concatIterableNull() { - Observable.concat((Iterable>)null); + Flowable.concat((Iterable>)null); } @Test(expected = NullPointerException.class) public void concatIterableIteratorNull() { - Observable.concat(new Iterable>() { + Flowable.concat(new Iterable>() { @Override public Iterator> iterator() { return null; @@ -180,39 +182,39 @@ public Iterator> iterator() { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void concatIterableOneIsNull() { - Observable.concat(Arrays.asList(just1, null)).toBlocking().lastOption(); + Flowable.concat(Arrays.asList(just1, null)).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void concatPublisherNull() { - Observable.concat((Publisher>)null); + Flowable.concat((Publisher>)null); } @Test(expected = NullPointerException.class) public void concatArrayNull() { - Observable.concatArray((Publisher[])null); + Flowable.concatArray((Publisher[])null); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void concatArrayOneIsNull() { - Observable.concatArray(just1, null).toBlocking().lastOption(); + Flowable.concatArray(just1, null).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void createNull() { - Observable.create(null); + Flowable.create(null); } @Test(expected = NullPointerException.class) public void deferFunctionNull() { - Observable.defer(null); + Flowable.defer(null); } @Test(expected = NullPointerException.class) public void deferFunctionReturnsNull() { - Observable.defer(new Supplier>() { + Flowable.defer(new Supplier>() { @Override public Publisher get() { return null; @@ -222,12 +224,12 @@ public Publisher get() { @Test(expected = NullPointerException.class) public void errorFunctionNull() { - Observable.error((Supplier)null); + Flowable.error((Supplier)null); } @Test(expected = NullPointerException.class) public void errorFunctionReturnsNull() { - Observable.error(new Supplier() { + Flowable.error(new Supplier() { @Override public Throwable get() { return null; @@ -237,27 +239,27 @@ public Throwable get() { @Test(expected = NullPointerException.class) public void errorThrowableNull() { - Observable.error((Throwable)null); + Flowable.error((Throwable)null); } @Test(expected = NullPointerException.class) public void fromArrayNull() { - Observable.fromArray((Object[])null); + Flowable.fromArray((Object[])null); } @Test(expected = NullPointerException.class) public void fromArrayOneIsNull() { - Observable.fromArray(1, null).toBlocking().lastOption(); + Flowable.fromArray(1, null).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void fromCallableNull() { - Observable.fromCallable(null); + Flowable.fromCallable(null); } @Test(expected = NullPointerException.class) public void fromCallableReturnsNull() { - Observable.fromCallable(new Callable() { + Flowable.fromCallable(new Callable() { @Override public Object call() throws Exception { return null; @@ -267,7 +269,7 @@ public Object call() throws Exception { @Test(expected = NullPointerException.class) public void fromFutureNull() { - Observable.fromFuture(null); + Flowable.fromFuture(null); } @Test @@ -276,7 +278,7 @@ public void fromFutureReturnsNull() { f.run(); TestSubscriber ts = new TestSubscriber(); - Observable.fromFuture(f).subscribe(ts); + Flowable.fromFuture(f).subscribe(ts); ts.assertNoValues(); ts.assertNotComplete(); ts.assertError(NullPointerException.class); @@ -284,39 +286,39 @@ public void fromFutureReturnsNull() { @Test(expected = NullPointerException.class) public void fromFutureTimedFutureNull() { - Observable.fromFuture(null, 1, TimeUnit.SECONDS); + Flowable.fromFuture(null, 1, TimeUnit.SECONDS); } @Test(expected = NullPointerException.class) public void fromFutureTimedUnitNull() { - Observable.fromFuture(new FutureTask(Functions.emptyRunnable(), null), 1, null); + Flowable.fromFuture(new FutureTask(Functions.emptyRunnable(), null), 1, null); } @Test(expected = NullPointerException.class) public void fromFutureTimedSchedulerNull() { - Observable.fromFuture(new FutureTask(Functions.emptyRunnable(), null), 1, TimeUnit.SECONDS, null); + Flowable.fromFuture(new FutureTask(Functions.emptyRunnable(), null), 1, TimeUnit.SECONDS, null); } @Test(expected = NullPointerException.class) public void fromFutureTimedReturnsNull() { FutureTask f = new FutureTask(Functions.emptyRunnable(), null); f.run(); - Observable.fromFuture(f, 1, TimeUnit.SECONDS).toBlocking().lastOption(); + Flowable.fromFuture(f, 1, TimeUnit.SECONDS).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void fromFutureSchedulerNull() { - Observable.fromFuture(new FutureTask(Functions.emptyRunnable(), null), null); + Flowable.fromFuture(new FutureTask(Functions.emptyRunnable(), null), null); } @Test(expected = NullPointerException.class) public void fromIterableNull() { - Observable.fromIterable(null); + Flowable.fromIterable(null); } @Test(expected = NullPointerException.class) public void fromIterableIteratorNull() { - Observable.fromIterable(new Iterable() { + Flowable.fromIterable(new Iterable() { @Override public Iterator iterator() { return null; @@ -326,22 +328,22 @@ public Iterator iterator() { @Test(expected = NullPointerException.class) public void fromIterableValueNull() { - Observable.fromIterable(Arrays.asList(1, null)).toBlocking().lastOption(); + Flowable.fromIterable(Arrays.asList(1, null)).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void fromPublisherNull() { - Observable.fromPublisher(null); + Flowable.fromPublisher(null); } @Test(expected = NullPointerException.class) public void generateConsumerNull() { - Observable.generate(null); + Flowable.generate(null); } @Test(expected = NullPointerException.class) public void generateConsumerEmitsNull() { - Observable.generate(new Consumer>() { + Flowable.generate(new Consumer>() { @Override public void accept(Subscriber s) { s.onNext(null); @@ -357,12 +359,12 @@ public void accept(Integer s, Subscriber o) { o.onNext(1); } }; - Observable.generate(null, generator); + Flowable.generate(null, generator); } @Test(expected = NullPointerException.class) public void generateStateFunctionInitialStateNull() { - Observable.generate(null, new BiFunction, Object>() { + Flowable.generate(null, new BiFunction, Object>() { @Override public Object apply(Object s, Subscriber o) { o.onNext(1); return s; } }); @@ -370,7 +372,7 @@ public void generateStateFunctionInitialStateNull() { @Test(expected = NullPointerException.class) public void generateStateConsumerNull() { - Observable.generate(new Supplier() { + Flowable.generate(new Supplier() { @Override public Integer get() { return 1; @@ -386,7 +388,7 @@ public void accept(Integer s, Subscriber o) { o.onComplete(); } }; - Observable.generate(new Supplier() { + Flowable.generate(new Supplier() { @Override public Integer get() { return null; @@ -396,7 +398,7 @@ public Integer get() { @Test public void generateFunctionStateNullAllowed() { - Observable.generate(new Supplier() { + Flowable.generate(new Supplier() { @Override public Object get() { return null; @@ -415,7 +417,7 @@ public void accept(Integer s, Subscriber o) { o.onNext(1); } }; - Observable.generate(new Supplier() { + Flowable.generate(new Supplier() { @Override public Integer get() { return 1; @@ -425,7 +427,7 @@ public Integer get() { @Test(expected = NullPointerException.class) public void generateFunctionDisposeNull() { - Observable.generate(new Supplier() { + Flowable.generate(new Supplier() { @Override public Object get() { return 1; @@ -438,37 +440,37 @@ public Object get() { @Test(expected = NullPointerException.class) public void intervalUnitNull() { - Observable.interval(1, null); + Flowable.interval(1, null); } public void intervalSchedulerNull() { - Observable.interval(1, TimeUnit.SECONDS, null); + Flowable.interval(1, TimeUnit.SECONDS, null); } @Test(expected = NullPointerException.class) public void intervalPeriodUnitNull() { - Observable.interval(1, 1, null); + Flowable.interval(1, 1, null); } @Test(expected = NullPointerException.class) public void intervalPeriodSchedulerNull() { - Observable.interval(1, 1, TimeUnit.SECONDS, null); + Flowable.interval(1, 1, TimeUnit.SECONDS, null); } @Test(expected = NullPointerException.class) public void intervalRangeUnitNull() { - Observable.intervalRange(1,1, 1, 1, null); + Flowable.intervalRange(1,1, 1, 1, null); } @Test(expected = NullPointerException.class) public void intervalRangeSchedulerNull() { - Observable.intervalRange(1, 1, 1, 1, TimeUnit.SECONDS, null); + Flowable.intervalRange(1, 1, 1, 1, TimeUnit.SECONDS, null); } @Test public void justNull() throws Exception { @SuppressWarnings("rawtypes") - Class clazz = Observable.class; + Class clazz = Flowable.class; for (int argCount = 1; argCount < 10; argCount++) { for (int argNull = 1; argNull <= argCount; argNull++) { Class[] params = new Class[argCount]; @@ -494,12 +496,12 @@ public void justNull() throws Exception { @Test(expected = NullPointerException.class) public void mergeIterableNull() { - Observable.merge(128, 128, (Iterable>)null); + Flowable.merge(128, 128, (Iterable>)null); } @Test(expected = NullPointerException.class) public void mergeIterableIteratorNull() { - Observable.merge(128, 128, new Iterable>() { + Flowable.merge(128, 128, new Iterable>() { @Override public Iterator> iterator() { return null; @@ -510,28 +512,28 @@ public Iterator> iterator() { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void mergeIterableOneIsNull() { - Observable.merge(128, 128, Arrays.asList(just1, null)).toBlocking().lastOption(); + Flowable.merge(128, 128, Arrays.asList(just1, null)).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void mergeArrayNull() { - Observable.merge(128, 128, (Publisher[])null); + Flowable.merge(128, 128, (Publisher[])null); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void mergeArrayOneIsNull() { - Observable.merge(128, 128, just1, null).toBlocking().lastOption(); + Flowable.merge(128, 128, just1, null).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void mergeDelayErrorIterableNull() { - Observable.mergeDelayError(128, 128, (Iterable>)null); + Flowable.mergeDelayError(128, 128, (Iterable>)null); } @Test(expected = NullPointerException.class) public void mergeDelayErrorIterableIteratorNull() { - Observable.mergeDelayError(128, 128, new Iterable>() { + Flowable.mergeDelayError(128, 128, new Iterable>() { @Override public Iterator> iterator() { return null; @@ -542,53 +544,53 @@ public Iterator> iterator() { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void mergeDelayErrorIterableOneIsNull() { - Observable.mergeDelayError(128, 128, Arrays.asList(just1, null)).toBlocking().lastOption(); + Flowable.mergeDelayError(128, 128, Arrays.asList(just1, null)).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void mergeDelayErrorArrayNull() { - Observable.mergeDelayError(128, 128, (Publisher[])null); + Flowable.mergeDelayError(128, 128, (Publisher[])null); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void mergeDelayErrorArrayOneIsNull() { - Observable.mergeDelayError(128, 128, just1, null).toBlocking().lastOption(); + Flowable.mergeDelayError(128, 128, just1, null).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void sequenceEqualFirstNull() { - Observable.sequenceEqual(null, just1); + Flowable.sequenceEqual(null, just1); } @Test(expected = NullPointerException.class) public void sequenceEqualSecondNull() { - Observable.sequenceEqual(just1, null); + Flowable.sequenceEqual(just1, null); } @Test(expected = NullPointerException.class) public void sequenceEqualComparatorNull() { - Observable.sequenceEqual(just1, just1, null); + Flowable.sequenceEqual(just1, just1, null); } @Test(expected = NullPointerException.class) public void switchOnNextNull() { - Observable.switchOnNext(null); + Flowable.switchOnNext(null); } @Test(expected = NullPointerException.class) public void timerUnitNull() { - Observable.timer(1, null); + Flowable.timer(1, null); } @Test(expected = NullPointerException.class) public void timerSchedulerNull() { - Observable.timer(1, TimeUnit.SECONDS, null); + Flowable.timer(1, TimeUnit.SECONDS, null); } @Test(expected = NullPointerException.class) public void usingResourceSupplierNull() { - Observable.using(null, new Function>() { + Flowable.using(null, new Function>() { @Override public Publisher apply(Object d) { return just1; @@ -598,7 +600,7 @@ public Publisher apply(Object d) { @Test(expected = NullPointerException.class) public void usingObservableSupplierNull() { - Observable.using(new Supplier() { + Flowable.using(new Supplier() { @Override public Object get() { return 1; @@ -608,7 +610,7 @@ public Object get() { @Test(expected = NullPointerException.class) public void usingObservableSupplierReturnsNull() { - Observable.using(new Supplier() { + Flowable.using(new Supplier() { @Override public Object get() { return 1; @@ -623,7 +625,7 @@ public Publisher apply(Object d) { @Test(expected = NullPointerException.class) public void usingDisposeNull() { - Observable.using(new Supplier() { + Flowable.using(new Supplier() { @Override public Object get() { return 1; @@ -638,7 +640,7 @@ public Publisher apply(Object d) { @Test(expected = NullPointerException.class) public void zipIterableNull() { - Observable.zip((Iterable>)null, new Function() { + Flowable.zip((Iterable>)null, new Function() { @Override public Object apply(Object[] v) { return 1; @@ -648,7 +650,7 @@ public Object apply(Object[] v) { @Test(expected = NullPointerException.class) public void zipIterableIteratorNull() { - Observable.zip(new Iterable>() { + Flowable.zip(new Iterable>() { @Override public Iterator> iterator() { return null; @@ -664,13 +666,13 @@ public Object apply(Object[] v) { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void zipIterableFunctionNull() { - Observable.zip(Arrays.asList(just1, just1), null); + Flowable.zip(Arrays.asList(just1, just1), null); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void zipIterableFunctionReturnsNull() { - Observable.zip(Arrays.asList(just1, just1), new Function() { + Flowable.zip(Arrays.asList(just1, just1), new Function() { @Override public Object apply(Object[] a) { return null; @@ -680,7 +682,7 @@ public Object apply(Object[] a) { @Test(expected = NullPointerException.class) public void zipPublisherNull() { - Observable.zip((Publisher>)null, new Function() { + Flowable.zip((Publisher>)null, new Function() { @Override public Object apply(Object[] a) { return 1; @@ -690,12 +692,12 @@ public Object apply(Object[] a) { @Test(expected = NullPointerException.class) public void zipPublisherFunctionNull() { - Observable.zip((Observable.just(just1)), null); + Flowable.zip((Flowable.just(just1)), null); } @Test(expected = NullPointerException.class) public void zipPublisherFunctionReturnsNull() { - Observable.zip((Observable.just(just1)), new Function() { + Flowable.zip((Flowable.just(just1)), new Function() { @Override public Object apply(Object[] a) { return null; @@ -705,7 +707,7 @@ public Object apply(Object[] a) { @Test(expected = NullPointerException.class) public void zipIterable2Null() { - Observable.zipIterable(new Function() { + Flowable.zipIterable(new Function() { @Override public Object apply(Object[] a) { return 1; @@ -715,7 +717,7 @@ public Object apply(Object[] a) { @Test(expected = NullPointerException.class) public void zipIterable2IteratorNull() { - Observable.zipIterable(new Function() { + Flowable.zipIterable(new Function() { @Override public Object apply(Object[] a) { return 1; @@ -731,13 +733,13 @@ public Iterator> iterator() { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void zipIterable2FunctionNull() { - Observable.zipIterable(null, true, 128, Arrays.asList(just1, just1)); + Flowable.zipIterable(null, true, 128, Arrays.asList(just1, just1)); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void zipIterable2FunctionReturnsNull() { - Observable.zipIterable(new Function() { + Flowable.zipIterable(new Function() { @Override public Object apply(Object[] a) { return null; @@ -866,9 +868,9 @@ public Publisher get() { @Test(expected = NullPointerException.class) public void bufferBoundarySupplier2SupplierNull() { - just1.buffer(new Supplier>() { + just1.buffer(new Supplier>() { @Override - public Observable get() { + public Flowable get() { return just1; } }, null); @@ -876,9 +878,9 @@ public Observable get() { @Test(expected = NullPointerException.class) public void bufferBoundarySupplier2SupplierReturnsNull() { - just1.buffer(new Supplier>() { + just1.buffer(new Supplier>() { @Override - public Observable get() { + public Flowable get() { return just1; } }, new Supplier>() { @@ -1383,7 +1385,7 @@ public Publisher get() { @Test(expected = NullPointerException.class) public void flatMapNotificationOnErrorReturnsNull() { - Observable.error(new TestException()).flatMap(new Function>() { + Flowable.error(new TestException()).flatMap(new Function>() { @Override public Publisher apply(Object v) { return just1; @@ -1690,7 +1692,7 @@ public void onErrorResumeNextFunctionNull() { @Test(expected = NullPointerException.class) public void onErrorResumeNextFunctionReturnsNull() { - Observable.error(new TestException()).onErrorResumeNext(new Function>() { + Flowable.error(new TestException()).onErrorResumeNext(new Function>() { @Override public Publisher apply(Throwable e) { return null; @@ -1715,7 +1717,7 @@ public void onErrorReturnValueNull() { @Test(expected = NullPointerException.class) public void onErrorReturnFunctionReturnsNull() { - Observable.error(new TestException()).onErrorReturn(new Function() { + Flowable.error(new TestException()).onErrorReturn(new Function() { @Override public Object apply(Throwable e) { return null; @@ -1735,9 +1737,9 @@ public void publishFunctionNull() { @Test(expected = NullPointerException.class) public void publishFunctionReturnsNull() { - just1.publish(new Function, Publisher>() { + just1.publish(new Function, Publisher>() { @Override - public Publisher apply(Observable v) { + public Publisher apply(Flowable v) { return null; } }).toBlocking().run(); @@ -1750,7 +1752,7 @@ public void reduceFunctionNull() { @Test(expected = NullPointerException.class) public void reduceFunctionReturnsNull() { - Observable.just(1, 1).reduce(new BiFunction() { + Flowable.just(1, 1).reduce(new BiFunction() { @Override public Integer apply(Integer a, Integer b) { return null; @@ -1820,9 +1822,9 @@ public void repeatWhenNull() { @Test(expected = NullPointerException.class) public void repeatWhenFunctionReturnsNull() { - just1.repeatWhen(new Function, Publisher>() { + just1.repeatWhen(new Function, Publisher>() { @Override - public Publisher apply(Observable v) { + public Publisher apply(Flowable v) { return null; } }).toBlocking().run(); @@ -1830,14 +1832,14 @@ public Publisher apply(Observable v) { @Test(expected = NullPointerException.class) public void replaySelectorNull() { - just1.replay((Function, Observable>)null); + just1.replay((Function, Flowable>)null); } @Test(expected = NullPointerException.class) public void replaySelectorReturnsNull() { - just1.replay(new Function, Publisher>() { + just1.replay(new Function, Publisher>() { @Override - public Publisher apply(Observable o) { + public Publisher apply(Flowable o) { return null; } }).toBlocking().run(); @@ -1845,14 +1847,14 @@ public Publisher apply(Observable o) { @Test(expected = NullPointerException.class) public void replayBoundedSelectorNull() { - just1.replay((Function, Observable>)null, 1, 1, TimeUnit.SECONDS); + just1.replay((Function, Flowable>)null, 1, 1, TimeUnit.SECONDS); } @Test(expected = NullPointerException.class) public void replayBoundedSelectorReturnsNull() { - just1.replay(new Function, Publisher>() { + just1.replay(new Function, Publisher>() { @Override - public Publisher apply(Observable v) { + public Publisher apply(Flowable v) { return null; } }, 1, 1, TimeUnit.SECONDS).toBlocking().run(); @@ -1865,9 +1867,9 @@ public void replaySchedulerNull() { @Test(expected = NullPointerException.class) public void replayBoundedUnitNull() { - just1.replay(new Function, Publisher>() { + just1.replay(new Function, Publisher>() { @Override - public Publisher apply(Observable v) { + public Publisher apply(Flowable v) { return v; } }, 1, 1, null).toBlocking().run(); @@ -1875,9 +1877,9 @@ public Publisher apply(Observable v) { @Test(expected = NullPointerException.class) public void replayBoundedSchedulerNull() { - just1.replay(new Function, Publisher>() { + just1.replay(new Function, Publisher>() { @Override - public Publisher apply(Observable v) { + public Publisher apply(Flowable v) { return v; } }, 1, 1, TimeUnit.SECONDS, null).toBlocking().run(); @@ -1890,9 +1892,9 @@ public void replayTimeBoundedSelectorNull() { @Test(expected = NullPointerException.class) public void replayTimeBoundedSelectorReturnsNull() { - just1.replay(new Function, Publisher>() { + just1.replay(new Function, Publisher>() { @Override - public Publisher apply(Observable v) { + public Publisher apply(Flowable v) { return null; } }, 1, TimeUnit.SECONDS, Schedulers.single()).toBlocking().run(); @@ -1900,9 +1902,9 @@ public Publisher apply(Observable v) { @Test(expected = NullPointerException.class) public void replaySelectorTimeBoundedUnitNull() { - just1.replay(new Function, Publisher>() { + just1.replay(new Function, Publisher>() { @Override - public Publisher apply(Observable v) { + public Publisher apply(Flowable v) { return v; } }, 1, null, Schedulers.single()); @@ -1910,9 +1912,9 @@ public Publisher apply(Observable v) { @Test(expected = NullPointerException.class) public void replaySelectorTimeBoundedSchedulerNull() { - just1.replay(new Function, Publisher>() { + just1.replay(new Function, Publisher>() { @Override - public Publisher apply(Observable v) { + public Publisher apply(Flowable v) { return v; } }, 1, TimeUnit.SECONDS, null); @@ -1965,9 +1967,9 @@ public void retryWhenFunctionNull() { @Test(expected = NullPointerException.class) public void retryWhenFunctionReturnsNull() { - Observable.error(new TestException()).retryWhen(new Function, Publisher>() { + Flowable.error(new TestException()).retryWhen(new Function, Publisher>() { @Override - public Publisher apply(Observable f) { + public Publisher apply(Flowable f) { return null; } }).toBlocking().run(); @@ -2005,7 +2007,7 @@ public void scanFunctionNull() { @Test(expected = NullPointerException.class) public void scanFunctionReturnsNull() { - Observable.just(1, 1).scan(new BiFunction() { + Flowable.just(1, 1).scan(new BiFunction() { @Override public Integer apply(Integer a, Integer b) { return null; @@ -2675,7 +2677,7 @@ public void windowOpenCloseCloseNull() { @Test(expected = NullPointerException.class) public void windowOpenCloseCloseReturnsNull() { - Observable.never().window(just1, new Function>() { + Flowable.never().window(just1, new Function>() { @Override public Publisher apply(Integer v) { return null; @@ -2765,7 +2767,7 @@ public Object apply(Integer a, Object b) { @Test(expected = NullPointerException.class) public void zipWithIterableOneIsNull() { - Observable.just(1, 2).zipWith(Arrays.asList(1, null), new BiFunction() { + Flowable.just(1, 2).zipWith(Arrays.asList(1, null), new BiFunction() { @Override public Object apply(Integer a, Integer b) { return 1; @@ -2805,70 +2807,70 @@ public Object apply(Integer a, Integer b) { @Test(expected = NullPointerException.class) public void asyncSubjectOnNextNull() { - Subject subject = AsyncSubject.create(); + FlowProcessor subject = AsyncProcessor.create(); subject.onNext(null); subject.toBlocking().run(); } @Test(expected = NullPointerException.class) public void asyncSubjectOnErrorNull() { - Subject subject = AsyncSubject.create(); + FlowProcessor subject = AsyncProcessor.create(); subject.onError(null); subject.toBlocking().run(); } @Test(expected = NullPointerException.class) public void behaviorSubjectOnNextNull() { - Subject subject = BehaviorSubject.create(); + FlowProcessor subject = BehaviorProcessor.create(); subject.onNext(null); subject.toBlocking().run(); } @Test(expected = NullPointerException.class) public void behaviorSubjectOnErrorNull() { - Subject subject = BehaviorSubject.create(); + FlowProcessor subject = BehaviorProcessor.create(); subject.onError(null); subject.toBlocking().run(); } @Test(expected = NullPointerException.class) public void publishSubjectOnNextNull() { - Subject subject = PublishSubject.create(); + FlowProcessor subject = PublishProcessor.create(); subject.onNext(null); subject.toBlocking().run(); } @Test(expected = NullPointerException.class) public void publishSubjectOnErrorNull() { - Subject subject = PublishSubject.create(); + FlowProcessor subject = PublishProcessor.create(); subject.onError(null); subject.toBlocking().run(); } @Test(expected = NullPointerException.class) public void replaycSubjectOnNextNull() { - Subject subject = ReplaySubject.create(); + FlowProcessor subject = ReplayProcessor.create(); subject.onNext(null); subject.toBlocking().run(); } @Test(expected = NullPointerException.class) public void replaySubjectOnErrorNull() { - Subject subject = ReplaySubject.create(); + FlowProcessor subject = ReplayProcessor.create(); subject.onError(null); subject.toBlocking().run(); } @Test(expected = NullPointerException.class) public void serializedcSubjectOnNextNull() { - Subject subject = PublishSubject.create().toSerialized(); + FlowProcessor subject = PublishProcessor.create().toSerialized(); subject.onNext(null); subject.toBlocking().run(); } @Test(expected = NullPointerException.class) public void serializedSubjectOnErrorNull() { - Subject subject = PublishSubject.create().toSerialized(); + FlowProcessor subject = PublishProcessor.create().toSerialized(); subject.onError(null); subject.toBlocking().run(); } diff --git a/src/test/java/io/reactivex/ObservableTests.java b/src/test/java/io/reactivex/flowable/ObservableTests.java similarity index 86% rename from src/test/java/io/reactivex/ObservableTests.java rename to src/test/java/io/reactivex/flowable/ObservableTests.java index abbab199a3..d3a698c5e9 100644 --- a/src/test/java/io/reactivex/ObservableTests.java +++ b/src/test/java/io/reactivex/flowable/ObservableTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,13 +25,15 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.Observable.Transformer; +import io.reactivex.Flowable; +import io.reactivex.Flowable.Transformer; import io.reactivex.disposables.Disposable; +import io.reactivex.flowables.ConnectableFlowable; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.EmptySubscription; -import io.reactivex.observables.ConnectableObservable; +import io.reactivex.processors.*; import io.reactivex.schedulers.*; -import io.reactivex.subjects.*; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; public class ObservableTests { @@ -53,9 +55,9 @@ public void before() { @Test public void fromArray() { String[] items = new String[] { "one", "two", "three" }; - assertEquals((Long)3L, Observable.fromArray(items).count().toBlocking().single()); - assertEquals("two", Observable.fromArray(items).skip(1).take(1).toBlocking().single()); - assertEquals("three", Observable.fromArray(items).takeLast(1).toBlocking().single()); + assertEquals((Long)3L, Flowable.fromArray(items).count().toBlocking().single()); + assertEquals("two", Flowable.fromArray(items).skip(1).take(1).toBlocking().single()); + assertEquals("three", Flowable.fromArray(items).takeLast(1).toBlocking().single()); } @Test @@ -65,14 +67,14 @@ public void fromIterable() { items.add("two"); items.add("three"); - assertEquals((Long)3L, Observable.fromIterable(items).count().toBlocking().single()); - assertEquals("two", Observable.fromIterable(items).skip(1).take(1).toBlocking().single()); - assertEquals("three", Observable.fromIterable(items).takeLast(1).toBlocking().single()); + assertEquals((Long)3L, Flowable.fromIterable(items).count().toBlocking().single()); + assertEquals("two", Flowable.fromIterable(items).skip(1).take(1).toBlocking().single()); + assertEquals("three", Flowable.fromIterable(items).takeLast(1).toBlocking().single()); } @Test public void fromArityArgs3() { - Observable items = Observable.just("one", "two", "three"); + Flowable items = Flowable.just("one", "two", "three"); assertEquals((Long)3L, items.count().toBlocking().single()); assertEquals("two", items.skip(1).take(1).toBlocking().single()); @@ -81,7 +83,7 @@ public void fromArityArgs3() { @Test public void fromArityArgs1() { - Observable items = Observable.just("one"); + Flowable items = Flowable.just("one"); assertEquals((Long)1L, items.count().toBlocking().single()); assertEquals("one", items.takeLast(1).toBlocking().single()); @@ -90,7 +92,7 @@ public void fromArityArgs1() { @Test public void testCreate() { - Observable observable = Observable.just("one", "two", "three"); + Flowable observable = Flowable.just("one", "two", "three"); Subscriber observer = TestHelper.mockSubscriber(); @@ -105,7 +107,7 @@ public void testCreate() { @Test public void testCountAFewItems() { - Observable observable = Observable.just("a", "b", "c", "d"); + Flowable observable = Flowable.just("a", "b", "c", "d"); observable.count().subscribe(w); @@ -118,7 +120,7 @@ public void testCountAFewItems() { @Test public void testCountZeroItems() { - Observable observable = Observable.empty(); + Flowable observable = Flowable.empty(); observable.count().subscribe(w); // we should be called only once verify(w, times(1)).onNext(anyLong()); @@ -129,7 +131,7 @@ public void testCountZeroItems() { @Test public void testCountError() { - Observable o = Observable.error(new Supplier() { + Flowable o = Flowable.error(new Supplier() { @Override public Throwable get() { return new RuntimeException(); @@ -143,7 +145,7 @@ public Throwable get() { } public void testTakeFirstWithPredicateOfSome() { - Observable observable = Observable.just(1, 3, 5, 4, 6, 3); + Flowable observable = Flowable.just(1, 3, 5, 4, 6, 3); observable.takeFirst(IS_EVEN).subscribe(w); verify(w, times(1)).onNext(anyInt()); verify(w).onNext(4); @@ -153,7 +155,7 @@ public void testTakeFirstWithPredicateOfSome() { @Test public void testTakeFirstWithPredicateOfNoneMatchingThePredicate() { - Observable observable = Observable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); + Flowable observable = Flowable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); observable.takeFirst(IS_EVEN).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, times(1)).onComplete(); @@ -162,7 +164,7 @@ public void testTakeFirstWithPredicateOfNoneMatchingThePredicate() { @Test public void testTakeFirstOfSome() { - Observable observable = Observable.just(1, 2, 3); + Flowable observable = Flowable.just(1, 2, 3); observable.take(1).subscribe(w); verify(w, times(1)).onNext(anyInt()); verify(w).onNext(1); @@ -172,7 +174,7 @@ public void testTakeFirstOfSome() { @Test public void testTakeFirstOfNone() { - Observable observable = Observable.empty(); + Flowable observable = Flowable.empty(); observable.take(1).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, times(1)).onComplete(); @@ -181,7 +183,7 @@ public void testTakeFirstOfNone() { @Test public void testFirstOfNone() { - Observable observable = Observable.empty(); + Flowable observable = Flowable.empty(); observable.first().subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onComplete(); @@ -190,7 +192,7 @@ public void testFirstOfNone() { @Test public void testFirstWithPredicateOfNoneMatchingThePredicate() { - Observable observable = Observable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); + Flowable observable = Flowable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); observable.filter(IS_EVEN).first().subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onComplete(); @@ -199,7 +201,7 @@ public void testFirstWithPredicateOfNoneMatchingThePredicate() { @Test public void testReduce() { - Observable observable = Observable.just(1, 2, 3, 4); + Flowable observable = Flowable.just(1, 2, 3, 4); observable.reduce(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -217,7 +219,7 @@ public Integer apply(Integer t1, Integer t2) { */ @Test(expected = NoSuchElementException.class) public void testReduceWithEmptyObservable() { - Observable observable = Observable.range(1, 0); + Flowable observable = Flowable.range(1, 0); observable.reduce(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -241,7 +243,7 @@ public void accept(Integer t1) { */ @Test public void testReduceWithEmptyObservableAndSeed() { - Observable observable = Observable.range(1, 0); + Flowable observable = Flowable.range(1, 0); int value = observable.reduce(1, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -255,7 +257,7 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testReduceWithInitialValue() { - Observable observable = Observable.just(1, 2, 3, 4); + Flowable observable = Flowable.just(1, 2, 3, 4); observable.reduce(50, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -274,7 +276,7 @@ public void testOnSubscribeFails() { Subscriber observer = TestHelper.mockSubscriber(); final RuntimeException re = new RuntimeException("bad impl"); - Observable o = Observable.create(new Publisher() { + Flowable o = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { throw re; } }); @@ -287,8 +289,8 @@ public void testOnSubscribeFails() { @Test public void testMaterializeDematerializeChaining() { - Observable obs = Observable.just(1); - Observable chained = obs.materialize().dematerialize(); + Flowable obs = Flowable.just(1); + Flowable chained = obs.materialize().dematerialize(); Subscriber observer = TestHelper.mockSubscriber(); @@ -314,9 +316,9 @@ public void testCustomObservableWithErrorInObserverAsynchronous() throws Interru final AtomicReference error = new AtomicReference(); // FIXME custom built??? - Observable.just("1", "2", "three", "4") + Flowable.just("1", "2", "three", "4") .subscribeOn(Schedulers.newThread()) - .safeSubscribe(new Observer() { + .safeSubscribe(new DefaultObserver() { @Override public void onComplete() { System.out.println("completed"); @@ -362,8 +364,8 @@ public void testCustomObservableWithErrorInObserverSynchronous() { final AtomicReference error = new AtomicReference(); // FIXME custom built??? - Observable.just("1", "2", "three", "4") - .safeSubscribe(new Observer() { + Flowable.just("1", "2", "three", "4") + .safeSubscribe(new DefaultObserver() { @Override public void onComplete() { @@ -404,13 +406,13 @@ public void testCustomObservableWithErrorInObservableSynchronous() { final AtomicInteger count = new AtomicInteger(); final AtomicReference error = new AtomicReference(); // FIXME custom built??? - Observable.just("1", "2").concatWith(Observable.error(new Supplier() { + Flowable.just("1", "2").concatWith(Flowable.error(new Supplier() { @Override public Throwable get() { return new NumberFormatException(); } })) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -441,7 +443,7 @@ public void onNext(String v) { @Test public void testPublishLast() throws InterruptedException { final AtomicInteger count = new AtomicInteger(); - ConnectableObservable connectable = Observable.create(new Publisher() { + ConnectableFlowable connectable = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -479,7 +481,7 @@ public void accept(String value) { @Test public void testReplay() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - ConnectableObservable o = Observable.create(new Publisher() { + ConnectableFlowable o = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -532,7 +534,7 @@ public void accept(String v) { @Test public void testCache() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - Observable o = Observable.create(new Publisher() { + Flowable o = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -577,7 +579,7 @@ public void accept(String v) { @Test public void testCacheWithCapacity() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - Observable o = Observable.create(new Publisher() { + Flowable o = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -632,7 +634,7 @@ public void accept(String v) { @Ignore("Subscribers can't throw") public void testErrorThrownWithoutErrorHandlerSynchronous() { try { - Observable.error(new RuntimeException("failure")) + Flowable.error(new RuntimeException("failure")) .subscribe(); fail("expected exception"); } catch (Throwable e) { @@ -656,7 +658,7 @@ public void testErrorThrownWithoutErrorHandlerSynchronous() { public void testErrorThrownWithoutErrorHandlerAsynchronous() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference exception = new AtomicReference(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -684,8 +686,8 @@ public void run() { public void testTakeWithErrorInObserver() { final AtomicInteger count = new AtomicInteger(); final AtomicReference error = new AtomicReference(); - Observable.just("1", "2", "three", "4").take(3) - .safeSubscribe(new Observer() { + Flowable.just("1", "2", "three", "4").take(3) + .safeSubscribe(new DefaultObserver() { @Override public void onComplete() { @@ -717,7 +719,7 @@ public void onNext(String v) { @Test public void testOfType() { - Observable observable = Observable.just(1, "abc", false, 2L).ofType(String.class); + Flowable observable = Flowable.just(1, "abc", false, 2L).ofType(String.class); Subscriber observer = TestHelper.mockSubscriber(); @@ -740,7 +742,7 @@ public void testOfTypeWithPolymorphism() { l2.add(2); @SuppressWarnings("rawtypes") - Observable observable = Observable. just(l1, l2, "123").ofType(List.class); + Flowable observable = Flowable. just(l1, l2, "123").ofType(List.class); Subscriber observer = TestHelper.mockSubscriber(); @@ -756,7 +758,7 @@ public void testOfTypeWithPolymorphism() { @Test public void testContains() { - Observable observable = Observable.just("a", "b", "c").contains("b"); // FIXME nulls not allowed, changed to "c" + Flowable observable = Flowable.just("a", "b", "c").contains("b"); // FIXME nulls not allowed, changed to "c" Subscriber observer = TestHelper.mockSubscriber(); @@ -771,7 +773,7 @@ public void testContains() { @Test public void testContainsWithInexistence() { - Observable observable = Observable.just("a", "b").contains("c"); // FIXME null values are not allowed, removed + Flowable observable = Flowable.just("a", "b").contains("c"); // FIXME null values are not allowed, removed Subscriber observer = TestHelper.mockSubscriber(); @@ -787,7 +789,7 @@ public void testContainsWithInexistence() { @Test @Ignore("null values are not allowed") public void testContainsWithNull() { - Observable observable = Observable.just("a", "b", null).contains(null); + Flowable observable = Flowable.just("a", "b", null).contains(null); Subscriber observer = TestHelper.mockSubscriber(); @@ -802,7 +804,7 @@ public void testContainsWithNull() { @Test public void testContainsWithEmptyObservable() { - Observable observable = Observable. empty().contains("a"); + Flowable observable = Flowable. empty().contains("a"); Subscriber observer = TestHelper.mockSubscriber(); @@ -817,7 +819,7 @@ public void testContainsWithEmptyObservable() { @Test public void testIgnoreElements() { - Observable observable = Observable.just(1, 2, 3).ignoreElements(); + Flowable observable = Flowable.just(1, 2, 3).ignoreElements(); Subscriber observer = TestHelper.mockSubscriber(); @@ -831,7 +833,7 @@ public void testIgnoreElements() { @Test public void testJustWithScheduler() { TestScheduler scheduler = new TestScheduler(); - Observable observable = Observable.fromArray(1, 2).subscribeOn(scheduler); + Flowable observable = Flowable.fromArray(1, 2).subscribeOn(scheduler); Subscriber observer = TestHelper.mockSubscriber(); @@ -849,7 +851,7 @@ public void testJustWithScheduler() { @Test public void testStartWithWithScheduler() { TestScheduler scheduler = new TestScheduler(); - Observable observable = Observable.just(3, 4).startWith(Arrays.asList(1, 2)).subscribeOn(scheduler); + Flowable observable = Flowable.just(3, 4).startWith(Arrays.asList(1, 2)).subscribeOn(scheduler); Subscriber observer = TestHelper.mockSubscriber(); @@ -869,7 +871,7 @@ public void testStartWithWithScheduler() { @Test public void testRangeWithScheduler() { TestScheduler scheduler = new TestScheduler(); - Observable observable = Observable.range(3, 4).subscribeOn(scheduler); + Flowable observable = Flowable.range(3, 4).subscribeOn(scheduler); Subscriber observer = TestHelper.mockSubscriber(); @@ -888,7 +890,7 @@ public void testRangeWithScheduler() { @Test public void testCollectToList() { - Observable> o = Observable.just(1, 2, 3) + Flowable> o = Flowable.just(1, 2, 3) .collect(new Supplier>() { @Override public List get() { @@ -919,7 +921,7 @@ public void accept(List list, Integer v) { @Test public void testCollectToString() { - String value = Observable.just(1, 2, 3).collect(new Supplier() { + String value = Flowable.just(1, 2, 3).collect(new Supplier() { @Override public StringBuilder get() { return new StringBuilder(); @@ -941,21 +943,21 @@ public void accept(StringBuilder sb, Integer v) { @Test public void testMergeWith() { TestSubscriber ts = new TestSubscriber(); - Observable.just(1).mergeWith(Observable.just(2)).subscribe(ts); + Flowable.just(1).mergeWith(Flowable.just(2)).subscribe(ts); ts.assertValues(1, 2); } @Test public void testConcatWith() { TestSubscriber ts = new TestSubscriber(); - Observable.just(1).concatWith(Observable.just(2)).subscribe(ts); + Flowable.just(1).concatWith(Flowable.just(2)).subscribe(ts); ts.assertValues(1, 2); } @Test public void testAmbWith() { TestSubscriber ts = new TestSubscriber(); - Observable.just(1).ambWith(Observable.just(2)).subscribe(ts); + Flowable.just(1).ambWith(Flowable.just(2)).subscribe(ts); ts.assertValue(1); } // FIXME Subscribers can't throw @@ -975,7 +977,7 @@ public void testTakeWhileToList() { final int expectedCount = 3; final AtomicInteger count = new AtomicInteger(); for (int i = 0;i < expectedCount; i++) { - Observable + Flowable .just(Boolean.TRUE, Boolean.FALSE) .takeWhile(new Predicate() { @Override @@ -998,9 +1000,9 @@ public void accept(List booleans) { @Test public void testCompose() { TestSubscriber ts = new TestSubscriber(); - Observable.just(1, 2, 3).compose(new Transformer() { + Flowable.just(1, 2, 3).compose(new Transformer() { @Override - public Publisher apply(Observable t1) { + public Publisher apply(Flowable t1) { return t1.map(new Function() { @Override public String apply(Integer v) { @@ -1017,9 +1019,9 @@ public String apply(Integer v) { @Test public void testErrorThrownIssue1685() { - Subject subject = ReplaySubject.create(); + FlowProcessor subject = ReplayProcessor.create(); - Observable.error(new RuntimeException("oops")) + Flowable.error(new RuntimeException("oops")) .materialize() .delay(1, TimeUnit.SECONDS) .dematerialize() @@ -1033,12 +1035,12 @@ public void testErrorThrownIssue1685() { @Test public void testEmptyIdentity() { - assertEquals(Observable.empty(), Observable.empty()); + assertEquals(Flowable.empty(), Flowable.empty()); } @Test public void testEmptyIsEmpty() { - Observable.empty().subscribe(w); + Flowable.empty().subscribe(w); verify(w).onComplete(); verify(w, never()).onNext(any(Integer.class)); @@ -1069,7 +1071,7 @@ public void testEmptyIsEmpty() { @Test(expected = NullPointerException.class) public void testForEachWithNull() { - Observable.error(new Exception("boo")) + Flowable.error(new Exception("boo")) // .forEach(null); } @@ -1078,9 +1080,9 @@ public void testForEachWithNull() { public void testExtend() { final TestSubscriber subscriber = new TestSubscriber(); final Object value = new Object(); - Observable.just(value).to(new Function, Object>() { + Flowable.just(value).to(new Function, Object>() { @Override - public Object apply(Observable onSubscribe) { + public Object apply(Flowable onSubscribe) { onSubscribe.subscribe(subscriber); subscriber.assertNoErrors(); subscriber.assertComplete(); diff --git a/src/test/java/io/reactivex/ObservableWindowTests.java b/src/test/java/io/reactivex/flowable/ObservableWindowTests.java similarity index 83% rename from src/test/java/io/reactivex/ObservableWindowTests.java rename to src/test/java/io/reactivex/flowable/ObservableWindowTests.java index e6f797a7c4..36914e3747 100644 --- a/src/test/java/io/reactivex/ObservableWindowTests.java +++ b/src/test/java/io/reactivex/flowable/ObservableWindowTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import static org.junit.Assert.*; @@ -19,7 +19,7 @@ import org.junit.Test; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.functions.*; public class ObservableWindowTests { @@ -28,12 +28,12 @@ public class ObservableWindowTests { public void testWindow() { final ArrayList> lists = new ArrayList>(); - Observable.concat( - Observable.just(1, 2, 3, 4, 5, 6) + Flowable.concat( + Flowable.just(1, 2, 3, 4, 5, 6) .window(3) - .map(new Function, Observable>>() { + .map(new Function, Flowable>>() { @Override - public Observable> apply(Observable xs) { + public Flowable> apply(Flowable xs) { return xs.toList(); } }) diff --git a/src/test/java/io/reactivex/ReduceTests.java b/src/test/java/io/reactivex/flowable/ReduceTests.java similarity index 75% rename from src/test/java/io/reactivex/ReduceTests.java rename to src/test/java/io/reactivex/flowable/ReduceTests.java index 1abc64cf89..684f6baed7 100644 --- a/src/test/java/io/reactivex/ReduceTests.java +++ b/src/test/java/io/reactivex/flowable/ReduceTests.java @@ -11,21 +11,21 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import static org.junit.Assert.assertEquals; import org.junit.Test; -import io.reactivex.Observable; -import io.reactivex.CovarianceTest.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.CovarianceTest.*; import io.reactivex.functions.BiFunction; public class ReduceTests { @Test public void reduceInts() { - Observable o = Observable.just(1, 2, 3); + Flowable o = Flowable.just(1, 2, 3); int value = o.reduce(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -39,16 +39,16 @@ public Integer apply(Integer t1, Integer t2) { @SuppressWarnings("unused") @Test public void reduceWithObjects() { - Observable horrorMovies = Observable. just(new HorrorMovie()); + Flowable horrorMovies = Flowable. just(new HorrorMovie()); - Observable reduceResult = horrorMovies.scan(new BiFunction() { + Flowable reduceResult = horrorMovies.scan(new BiFunction() { @Override public Movie apply(Movie t1, Movie t2) { return t2; } }).takeLast(1); - Observable reduceResult2 = horrorMovies.reduce(new BiFunction() { + Flowable reduceResult2 = horrorMovies.reduce(new BiFunction() { @Override public Movie apply(Movie t1, Movie t2) { return t2; @@ -64,9 +64,9 @@ public Movie apply(Movie t1, Movie t2) { @SuppressWarnings("unused") @Test public void reduceWithCovariantObjects() { - Observable horrorMovies = Observable. just(new HorrorMovie()); + Flowable horrorMovies = Flowable. just(new HorrorMovie()); - Observable reduceResult2 = horrorMovies.reduce(new BiFunction() { + Flowable reduceResult2 = horrorMovies.reduce(new BiFunction() { @Override public Movie apply(Movie t1, Movie t2) { return t2; @@ -82,14 +82,14 @@ public Movie apply(Movie t1, Movie t2) { @Test public void reduceCovariance() { // must type it to - Observable horrorMovies = Observable. just(new HorrorMovie()); + Flowable horrorMovies = Flowable. just(new HorrorMovie()); libraryFunctionActingOnMovieObservables(horrorMovies); } /* * This accepts instead of since `reduce` can't handle covariants */ - public void libraryFunctionActingOnMovieObservables(Observable obs) { + public void libraryFunctionActingOnMovieObservables(Flowable obs) { obs.reduce(new BiFunction() { @Override diff --git a/src/test/java/io/reactivex/ScanTests.java b/src/test/java/io/reactivex/flowable/ScanTests.java similarity index 94% rename from src/test/java/io/reactivex/ScanTests.java rename to src/test/java/io/reactivex/flowable/ScanTests.java index c5fa8a4197..c812d3ac0e 100644 --- a/src/test/java/io/reactivex/ScanTests.java +++ b/src/test/java/io/reactivex/flowable/ScanTests.java @@ -11,13 +11,13 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import java.util.HashMap; import org.junit.Test; -import io.reactivex.EventStream.Event; +import io.reactivex.flowable.EventStream.Event; import io.reactivex.functions.*; public class ScanTests { diff --git a/src/test/java/io/reactivex/StartWithTests.java b/src/test/java/io/reactivex/flowable/StartWithTests.java similarity index 83% rename from src/test/java/io/reactivex/StartWithTests.java rename to src/test/java/io/reactivex/flowable/StartWithTests.java index 4ae91ae6fe..b7b986fe0e 100644 --- a/src/test/java/io/reactivex/StartWithTests.java +++ b/src/test/java/io/reactivex/flowable/StartWithTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import static org.junit.Assert.assertEquals; @@ -19,13 +19,13 @@ import org.junit.Test; -import io.reactivex.Observable; +import io.reactivex.Flowable; public class StartWithTests { @Test public void startWith1() { - List values = Observable.just("one", "two") + List values = Flowable.just("one", "two") .startWithArray("zero").toList().toBlocking().single(); assertEquals("zero", values.get(0)); @@ -37,7 +37,7 @@ public void startWithIterable() { List li = new ArrayList(); li.add("alpha"); li.add("beta"); - List values = Observable.just("one", "two").startWith(li).toList().toBlocking().single(); + List values = Flowable.just("one", "two").startWith(li).toList().toBlocking().single(); assertEquals("alpha", values.get(0)); assertEquals("beta", values.get(1)); @@ -50,8 +50,8 @@ public void startWithObservable() { List li = new ArrayList(); li.add("alpha"); li.add("beta"); - List values = Observable.just("one", "two") - .startWith(Observable.fromIterable(li)) + List values = Flowable.just("one", "two") + .startWith(Flowable.fromIterable(li)) .toList() .toBlocking() .single(); diff --git a/src/test/java/io/reactivex/SubscriberTest.java b/src/test/java/io/reactivex/flowable/SubscriberTest.java similarity index 93% rename from src/test/java/io/reactivex/SubscriberTest.java rename to src/test/java/io/reactivex/flowable/SubscriberTest.java index 46b0ae00b6..5036b16bbc 100644 --- a/src/test/java/io/reactivex/SubscriberTest.java +++ b/src/test/java/io/reactivex/flowable/SubscriberTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import static org.junit.Assert.assertEquals; @@ -22,9 +22,11 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable; +import io.reactivex.Flowable.Operator; import io.reactivex.internal.functions.Functions; import io.reactivex.subscribers.*; +import io.reactivex.subscribers.DefaultObserver; public class SubscriberTest { @@ -203,7 +205,7 @@ public void cancel() { }); - AsyncObserver as = new AsyncObserver() { + AsyncSubscriber as = new AsyncSubscriber() { @Override protected void onStart() { @@ -259,7 +261,7 @@ public void testRequestToObservable() { TestSubscriber ts = new TestSubscriber(); ts.request(3); final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { s.onSubscribe(new Subscription() { @@ -284,7 +286,7 @@ public void testRequestThroughMap() { TestSubscriber ts = new TestSubscriber((Long)null); ts.request(3); final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { s.onSubscribe(new Subscription() { @@ -309,7 +311,7 @@ public void testRequestThroughTakeThatReducesRequest() { TestSubscriber ts = new TestSubscriber((Long)null); ts.request(3); final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { s.onSubscribe(new Subscription() { @@ -337,7 +339,7 @@ public void testRequestThroughTakeWhereRequestIsSmallerThanTake() { TestSubscriber ts = new TestSubscriber((Long)null); ts.request(3); final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { s.onSubscribe(new Subscription() { @@ -361,7 +363,7 @@ public void cancel() { @Test public void testOnStartCalledOnceViaSubscribe() { final AtomicInteger c = new AtomicInteger(); - Observable.just(1, 2, 3, 4).take(2).subscribe(new Observer() { + Flowable.just(1, 2, 3, 4).take(2).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -392,7 +394,7 @@ public void onNext(Integer t) { @Test public void testOnStartCalledOnceViaUnsafeSubscribe() { final AtomicInteger c = new AtomicInteger(); - Observable.just(1, 2, 3, 4).take(2).unsafeSubscribe(new Observer() { + Flowable.just(1, 2, 3, 4).take(2).unsafeSubscribe(new DefaultObserver() { @Override public void onStart() { @@ -423,11 +425,11 @@ public void onNext(Integer t) { @Test public void testOnStartCalledOnceViaLift() { final AtomicInteger c = new AtomicInteger(); - Observable.just(1, 2, 3, 4).lift(new Operator() { + Flowable.just(1, 2, 3, 4).lift(new Operator() { @Override public Subscriber apply(final Subscriber child) { - return new Observer() { + return new DefaultObserver() { @Override public void onStart() { @@ -464,7 +466,7 @@ public void onNext(Integer t) { public void testNegativeRequestThrowsIllegalArgumentException() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference exception = new AtomicReference(); - Observable.just(1,2,3,4).subscribe(new Observer() { + Flowable.just(1,2,3,4).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -495,7 +497,7 @@ public void onNext(Integer t) { @Test public void testOnStartRequestsAreAdditive() { final List list = new ArrayList(); - Observable.just(1,2,3,4,5).subscribe(new Observer() { + Flowable.just(1,2,3,4,5).subscribe(new DefaultObserver() { @Override public void onStart() { request(3); @@ -522,7 +524,7 @@ public void onNext(Integer t) { @Test public void testOnStartRequestsAreAdditiveAndOverflowBecomesMaxValue() { final List list = new ArrayList(); - Observable.just(1,2,3,4,5).subscribe(new Observer() { + Flowable.just(1,2,3,4,5).subscribe(new DefaultObserver() { @Override public void onStart() { request(2); diff --git a/src/test/java/io/reactivex/TestHelper.java b/src/test/java/io/reactivex/flowable/TestHelper.java similarity index 90% rename from src/test/java/io/reactivex/TestHelper.java rename to src/test/java/io/reactivex/flowable/TestHelper.java index 3c1bd2efa0..4a264af6c9 100644 --- a/src/test/java/io/reactivex/TestHelper.java +++ b/src/test/java/io/reactivex/flowable/TestHelper.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; @@ -21,7 +21,7 @@ import org.mockito.stubbing.Answer; import org.reactivestreams.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; /** * Common methods for helping with tests from 1.x mostly. @@ -50,7 +50,7 @@ public Object answer(InvocationOnMock a) throws Throwable { } @SuppressWarnings("unchecked") - public static NbpSubscriber mockNbpSubscriber() { - return mock(NbpSubscriber.class); + public static Observer mockNbpSubscriber() { + return mock(Observer.class); } } diff --git a/src/test/java/io/reactivex/ThrottleLastTests.java b/src/test/java/io/reactivex/flowable/ThrottleLastTests.java similarity index 93% rename from src/test/java/io/reactivex/ThrottleLastTests.java rename to src/test/java/io/reactivex/flowable/ThrottleLastTests.java index e0d753d8f3..88922de96a 100644 --- a/src/test/java/io/reactivex/ThrottleLastTests.java +++ b/src/test/java/io/reactivex/flowable/ThrottleLastTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import static org.mockito.Mockito.inOrder; @@ -21,8 +21,8 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; public class ThrottleLastTests { @@ -31,7 +31,7 @@ public void testThrottle() { Subscriber observer = TestHelper.mockSubscriber(); TestScheduler s = new TestScheduler(); - PublishSubject o = PublishSubject.create(); + PublishProcessor o = PublishProcessor.create(); o.throttleLast(500, TimeUnit.MILLISECONDS, s).subscribe(observer); // send events with simulated time increments diff --git a/src/test/java/io/reactivex/ThrottleWithTimeoutTests.java b/src/test/java/io/reactivex/flowable/ThrottleWithTimeoutTests.java similarity index 93% rename from src/test/java/io/reactivex/ThrottleWithTimeoutTests.java rename to src/test/java/io/reactivex/flowable/ThrottleWithTimeoutTests.java index a9d8ff3ec4..dcdff01f2c 100644 --- a/src/test/java/io/reactivex/ThrottleWithTimeoutTests.java +++ b/src/test/java/io/reactivex/flowable/ThrottleWithTimeoutTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.flowable; import static org.mockito.Mockito.inOrder; @@ -21,8 +21,8 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; public class ThrottleWithTimeoutTests { @@ -31,7 +31,7 @@ public void testThrottle() { Subscriber observer = TestHelper.mockSubscriber(); TestScheduler s = new TestScheduler(); - PublishSubject o = PublishSubject.create(); + PublishProcessor o = PublishProcessor.create(); o.throttleWithTimeout(500, TimeUnit.MILLISECONDS, s) .subscribe(observer); diff --git a/src/test/java/io/reactivex/nbp/NbpZipTests.java b/src/test/java/io/reactivex/flowable/ZipTests.java similarity index 59% rename from src/test/java/io/reactivex/nbp/NbpZipTests.java rename to src/test/java/io/reactivex/flowable/ZipTests.java index cd63343db1..e452308afe 100644 --- a/src/test/java/io/reactivex/nbp/NbpZipTests.java +++ b/src/test/java/io/reactivex/flowable/ZipTests.java @@ -11,25 +11,26 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.flowable; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; import java.util.*; -import org.junit.*; +import org.junit.Test; +import org.reactivestreams.Publisher; -import io.reactivex.NbpObservable; +import io.reactivex.Flowable; +import io.reactivex.flowable.CovarianceTest.*; +import io.reactivex.flowable.EventStream.Event; +import io.reactivex.flowables.GroupedFlowable; import io.reactivex.functions.*; -import io.reactivex.nbp.NbpCovarianceTest.*; -import io.reactivex.nbp.NbpEventStream.Event; -import io.reactivex.observables.nbp.NbpGroupedObservable; -public class NbpZipTests { +public class ZipTests { @Test - public void testZipNbpObservableOfNbpObservables() { - NbpEventStream.getEventStream("HTTP-ClusterB", 20) + public void testZipObservableOfObservables() { + EventStream.getEventStream("HTTP-ClusterB", 20) .groupBy(new Function() { @Override public String apply(Event e) { @@ -37,9 +38,9 @@ public String apply(Event e) { } }) // now we have streams of cluster+instanceId - .flatMap(new Function, NbpObservable>>() { + .flatMap(new Function, Publisher>>() { @Override - public NbpObservable> apply(final NbpGroupedObservable ge) { + public Publisher> apply(final GroupedFlowable ge) { return ge.scan(new HashMap(), new BiFunction, Event, HashMap>() { @Override public HashMap apply(HashMap accum, @@ -51,10 +52,10 @@ public HashMap apply(HashMap accum, } }) .take(10) - .toBlocking().forEach(new Consumer() { + .toBlocking().forEach(new Consumer>() { @Override - public void accept(Object pv) { - System.out.println(pv); + public void accept(HashMap v) { + System.out.println(v); } }); @@ -66,36 +67,36 @@ public void accept(Object pv) { */ @Test public void testCovarianceOfZip() { - NbpObservable horrors = NbpObservable.just(new HorrorMovie()); - NbpObservable ratings = NbpObservable.just(new CoolRating()); + Flowable horrors = Flowable.just(new HorrorMovie()); + Flowable ratings = Flowable.just(new CoolRating()); - NbpObservable. zip(horrors, ratings, combine).toBlocking().forEach(action); - NbpObservable. zip(horrors, ratings, combine).toBlocking().forEach(action); - NbpObservable. zip(horrors, ratings, combine).toBlocking().forEach(extendedAction); - NbpObservable. zip(horrors, ratings, combine).toBlocking().forEach(action); - NbpObservable. zip(horrors, ratings, combine).toBlocking().forEach(action); + Flowable. zip(horrors, ratings, combine).toBlocking().forEach(action); + Flowable. zip(horrors, ratings, combine).toBlocking().forEach(action); + Flowable. zip(horrors, ratings, combine).toBlocking().forEach(extendedAction); + Flowable. zip(horrors, ratings, combine).toBlocking().forEach(action); + Flowable. zip(horrors, ratings, combine).toBlocking().forEach(action); - NbpObservable. zip(horrors, ratings, combine); + Flowable. zip(horrors, ratings, combine); } /** - * Occasionally zip may be invoked with 0 NbpObservables. Test that we don't block indefinitely instead + * Occasionally zip may be invoked with 0 observables. Test that we don't block indefinitely instead * of immediately invoking zip with 0 argument. * * We now expect an NoSuchElementException since last() requires at least one value and nothing will be emitted. */ @Test(expected = NoSuchElementException.class) - public void nonBlockingNbpObservable() { + public void nonBlockingObservable() { final Object invoked = new Object(); - Collection> NbpObservables = Collections.emptyList(); + Collection> observables = Collections.emptyList(); - NbpObservable result = NbpObservable.zip(NbpObservables, new Function() { + Flowable result = Flowable.zip(observables, new Function() { @Override public Object apply(Object[] args) { System.out.println("received: " + args); - Assert.assertEquals("No argument should have been passed", 0, args.length); + assertEquals("No argument should have been passed", 0, args.length); return invoked; } }); diff --git a/src/test/java/io/reactivex/internal/operators/BackpressureHelperTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BackpressureHelperTest.java similarity index 97% rename from src/test/java/io/reactivex/internal/operators/BackpressureHelperTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/BackpressureHelperTest.java index d3674fe83a..953bd9a20a 100644 --- a/src/test/java/io/reactivex/internal/operators/BackpressureHelperTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BackpressureHelperTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/io/reactivex/internal/operators/BlockingOperatorLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingOperatorLatestTest.java similarity index 81% rename from src/test/java/io/reactivex/internal/operators/BlockingOperatorLatestTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/BlockingOperatorLatestTest.java index ab123c2c00..d5e8430559 100644 --- a/src/test/java/io/reactivex/internal/operators/BlockingOperatorLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingOperatorLatestTest.java @@ -11,24 +11,24 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.*; import java.util.concurrent.TimeUnit; import org.junit.*; -import io.reactivex.Observable; -import io.reactivex.observables.BlockingObservable; +import io.reactivex.Flowable; +import io.reactivex.flowables.BlockingFlowable; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; public class BlockingOperatorLatestTest { @Test(timeout = 1000) public void testSimple() { TestScheduler scheduler = new TestScheduler(); - BlockingObservable source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); + BlockingFlowable source = Flowable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); Iterable iter = source.latest(); @@ -52,7 +52,7 @@ public void testSimple() { public void testSameSourceMultipleIterators() { TestScheduler scheduler = new TestScheduler(); - BlockingObservable source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); + BlockingFlowable source = Flowable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); Iterable iter = source.latest(); @@ -76,7 +76,7 @@ public void testSameSourceMultipleIterators() { @Test(timeout = 1000, expected = NoSuchElementException.class) public void testEmpty() { - BlockingObservable source = Observable. empty().toBlocking(); + BlockingFlowable source = Flowable. empty().toBlocking(); Iterable iter = source.latest(); @@ -91,7 +91,7 @@ public void testEmpty() { public void testSimpleJustNext() { TestScheduler scheduler = new TestScheduler(); - BlockingObservable source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); + BlockingFlowable source = Flowable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); Iterable iter = source.latest(); @@ -110,7 +110,7 @@ public void testSimpleJustNext() { public void testHasNextThrows() { TestScheduler scheduler = new TestScheduler(); - BlockingObservable source = Observable. error(new RuntimeException("Forced failure!")).subscribeOn(scheduler).toBlocking(); + BlockingFlowable source = Flowable. error(new RuntimeException("Forced failure!")).subscribeOn(scheduler).toBlocking(); Iterable iter = source.latest(); @@ -125,7 +125,7 @@ public void testHasNextThrows() { public void testNextThrows() { TestScheduler scheduler = new TestScheduler(); - BlockingObservable source = Observable. error(new RuntimeException("Forced failure!")).subscribeOn(scheduler).toBlocking(); + BlockingFlowable source = Flowable. error(new RuntimeException("Forced failure!")).subscribeOn(scheduler).toBlocking(); Iterable iter = source.latest(); Iterator it = iter.iterator(); @@ -137,8 +137,8 @@ public void testNextThrows() { @Test(timeout = 1000) public void testFasterSource() { - PublishSubject source = PublishSubject.create(); - BlockingObservable blocker = source.toBlocking(); + PublishProcessor source = PublishProcessor.create(); + BlockingFlowable blocker = source.toBlocking(); Iterable iter = blocker.latest(); Iterator it = iter.iterator(); diff --git a/src/test/java/io/reactivex/internal/operators/BlockingOperatorMostRecentTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingOperatorMostRecentTest.java similarity index 80% rename from src/test/java/io/reactivex/internal/operators/BlockingOperatorMostRecentTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/BlockingOperatorMostRecentTest.java index e4221555f6..a5886af49d 100644 --- a/src/test/java/io/reactivex/internal/operators/BlockingOperatorMostRecentTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingOperatorMostRecentTest.java @@ -11,9 +11,9 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; -import static io.reactivex.internal.operators.BlockingOperatorMostRecent.mostRecent; +import static io.reactivex.internal.operators.flowable.BlockingOperatorMostRecent.mostRecent; import static org.junit.Assert.*; import java.util.Iterator; @@ -21,21 +21,21 @@ import org.junit.*; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; -import io.reactivex.observables.BlockingObservable; +import io.reactivex.flowables.BlockingFlowable; +import io.reactivex.processors.*; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.*; public class BlockingOperatorMostRecentTest { @Test public void testMostRecentNull() { - assertEquals(null, Observable.never().toBlocking().mostRecent(null).iterator().next()); + assertEquals(null, Flowable.never().toBlocking().mostRecent(null).iterator().next()); } @Test public void testMostRecent() { - Subject s = PublishSubject.create(); + FlowProcessor s = PublishProcessor.create(); Iterator it = mostRecent(s, "default").iterator(); @@ -60,7 +60,7 @@ public void testMostRecent() { @Test(expected = TestException.class) public void testMostRecentWithException() { - Subject s = PublishSubject.create(); + FlowProcessor s = PublishProcessor.create(); Iterator it = mostRecent(s, "default").iterator(); @@ -77,7 +77,7 @@ public void testMostRecentWithException() { @Test(timeout = 1000) public void testSingleSourceManyIterators() { TestScheduler scheduler = new TestScheduler(); - BlockingObservable source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); + BlockingFlowable source = Flowable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); Iterable iter = source.mostRecent(-1L); diff --git a/src/test/java/io/reactivex/internal/operators/BlockingOperatorNextTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingOperatorNextTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/BlockingOperatorNextTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/BlockingOperatorNextTest.java index 62e249abd9..601654c854 100644 --- a/src/test/java/io/reactivex/internal/operators/BlockingOperatorNextTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingOperatorNextTest.java @@ -11,9 +11,9 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; -import static io.reactivex.internal.operators.BlockingOperatorNext.next; +import static io.reactivex.internal.operators.flowable.BlockingOperatorNext.next; import static org.junit.Assert.*; import java.util.*; @@ -23,17 +23,16 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; -import io.reactivex.internal.operators.BlockingOperatorNext; +import io.reactivex.flowables.BlockingFlowable; import io.reactivex.internal.subscriptions.EmptySubscription; -import io.reactivex.observables.BlockingObservable; +import io.reactivex.processors.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.*; public class BlockingOperatorNextTest { - private void fireOnNextInNewThread(final Subject o, final String value) { + private void fireOnNextInNewThread(final FlowProcessor o, final String value) { new Thread() { @Override public void run() { @@ -47,7 +46,7 @@ public void run() { }.start(); } - private void fireOnErrorInNewThread(final Subject o) { + private void fireOnErrorInNewThread(final FlowProcessor o) { new Thread() { @Override public void run() { @@ -63,7 +62,7 @@ public void run() { @Test public void testNext() { - Subject obs = PublishSubject.create(); + FlowProcessor obs = PublishProcessor.create(); Iterator it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertTrue(it.hasNext()); @@ -99,7 +98,7 @@ public void testNext() { @Test public void testNextWithError() { - Subject obs = PublishSubject.create(); + FlowProcessor obs = PublishProcessor.create(); Iterator it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertTrue(it.hasNext()); @@ -117,7 +116,7 @@ public void testNextWithError() { @Test public void testNextWithEmpty() { - Observable obs = Observable. empty().observeOn(Schedulers.newThread()); + Flowable obs = Flowable. empty().observeOn(Schedulers.newThread()); Iterator it = next(obs).iterator(); assertFalse(it.hasNext()); @@ -138,7 +137,7 @@ public void testNextWithEmpty() { @Test public void testOnError() throws Throwable { - Subject obs = PublishSubject.create(); + FlowProcessor obs = PublishProcessor.create(); Iterator it = next(obs).iterator(); obs.onError(new TestException()); @@ -154,7 +153,7 @@ public void testOnError() throws Throwable { @Test public void testOnErrorInNewThread() { - Subject obs = PublishSubject.create(); + FlowProcessor obs = PublishProcessor.create(); Iterator it = next(obs).iterator(); fireOnErrorInNewThread(obs); @@ -185,7 +184,7 @@ private void assertErrorAfterObservableFail(Iterator it) { @Test public void testNextWithOnlyUsingNextMethod() { - Subject obs = PublishSubject.create(); + FlowProcessor obs = PublishProcessor.create(); Iterator it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertEquals("one", it.next()); @@ -203,7 +202,7 @@ public void testNextWithOnlyUsingNextMethod() { @Test public void testNextWithCallingHasNextMultipleTimes() { - Subject obs = PublishSubject.create(); + FlowProcessor obs = PublishProcessor.create(); Iterator it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertTrue(it.hasNext()); @@ -234,7 +233,7 @@ public void testNoBufferingOrBlockingOfSequence() throws Throwable { final CountDownLatch timeHasPassed = new CountDownLatch(COUNT); final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger count = new AtomicInteger(0); - final Observable obs = Observable.create(new Publisher() { + final Flowable obs = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber o) { @@ -294,9 +293,9 @@ public void run() { @Test /* (timeout = 8000) */ public void testSingleSourceManyIterators() throws InterruptedException { - Observable o = Observable.interval(100, TimeUnit.MILLISECONDS); - PublishSubject terminal = PublishSubject.create(); - BlockingObservable source = o.takeUntil(terminal).toBlocking(); + Flowable o = Flowable.interval(100, TimeUnit.MILLISECONDS); + PublishProcessor terminal = PublishProcessor.create(); + BlockingFlowable source = o.takeUntil(terminal).toBlocking(); Iterable iter = source.next(); @@ -313,8 +312,8 @@ public void testSingleSourceManyIterators() throws InterruptedException { @Test public void testSynchronousNext() { - assertEquals(1, BehaviorSubject.createDefault(1).take(1).toBlocking().single().intValue()); - assertEquals(2, BehaviorSubject.createDefault(2).toBlocking().iterator().next().intValue()); - assertEquals(3, BehaviorSubject.createDefault(3).toBlocking().next().iterator().next().intValue()); + assertEquals(1, BehaviorProcessor.createDefault(1).take(1).toBlocking().single().intValue()); + assertEquals(2, BehaviorProcessor.createDefault(2).toBlocking().iterator().next().intValue()); + assertEquals(3, BehaviorProcessor.createDefault(3).toBlocking().next().iterator().next().intValue()); } } \ No newline at end of file diff --git a/src/test/java/io/reactivex/internal/operators/BlockingOperatorToIteratorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingOperatorToIteratorTest.java similarity index 89% rename from src/test/java/io/reactivex/internal/operators/BlockingOperatorToIteratorTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/BlockingOperatorToIteratorTest.java index d02df09f88..022192925c 100644 --- a/src/test/java/io/reactivex/internal/operators/BlockingOperatorToIteratorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingOperatorToIteratorTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; @@ -20,7 +20,7 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.internal.subscriptions.EmptySubscription; @@ -28,7 +28,7 @@ public class BlockingOperatorToIteratorTest { @Test public void testToIterator() { - Observable obs = Observable.just("one", "two", "three"); + Flowable obs = Flowable.just("one", "two", "three"); Iterator it = obs.toBlocking().iterator(); @@ -47,7 +47,7 @@ public void testToIterator() { @Test(expected = TestException.class) public void testToIteratorWithException() { - Observable obs = Observable.create(new Publisher() { + Flowable obs = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { @@ -69,7 +69,7 @@ public void subscribe(Subscriber observer) { @Ignore("subscribe() should not throw") @Test(expected = TestException.class) public void testExceptionThrownFromOnSubscribe() { - Iterable strings = Observable.create(new Publisher() { + Iterable strings = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber subscriber) { throw new TestException("intentional"); diff --git a/src/test/java/io/reactivex/internal/operators/BufferUntilSubscriberTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BufferUntilSubscriberTest.java similarity index 88% rename from src/test/java/io/reactivex/internal/operators/BufferUntilSubscriberTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/BufferUntilSubscriberTest.java index 7912fd5d95..ad1071499a 100644 --- a/src/test/java/io/reactivex/internal/operators/BufferUntilSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BufferUntilSubscriberTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.List; import java.util.concurrent.*; @@ -20,10 +20,10 @@ import org.junit.*; import org.reactivestreams.Publisher; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.functions.*; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; public class BufferUntilSubscriberTest { @@ -37,14 +37,14 @@ public void testIssue1677() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(NITERS); for (int iters = 0; iters < NITERS; iters++) { final CountDownLatch innerLatch = new CountDownLatch(1); - final PublishSubject s = PublishSubject.create(); + final PublishProcessor s = PublishProcessor.create(); final AtomicBoolean completed = new AtomicBoolean(); - Observable.fromArray(numbers) + Flowable.fromArray(numbers) .takeUntil(s) .window(50) - .flatMap(new Function, Publisher>() { + .flatMap(new Function, Publisher>() { @Override - public Publisher apply(Observable integerObservable) { + public Publisher apply(Flowable integerObservable) { return integerObservable .subscribeOn(Schedulers.computation()) .map(new Function() { diff --git a/src/test/java/io/reactivex/internal/operators/CachedObservableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/CachedObservableTest.java similarity index 91% rename from src/test/java/io/reactivex/internal/operators/CachedObservableTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/CachedObservableTest.java index 46dad13f44..11774cc53b 100644 --- a/src/test/java/io/reactivex/internal/operators/CachedObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/CachedObservableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -23,10 +23,9 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Consumer; -import io.reactivex.internal.operators.CachedObservable; import io.reactivex.internal.subscriptions.EmptySubscription; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; @@ -34,7 +33,7 @@ public class CachedObservableTest { @Test public void testColdReplayNoBackpressure() { - CachedObservable source = CachedObservable.from(Observable.range(0, 1000)); + CachedObservable source = CachedObservable.from(Flowable.range(0, 1000)); assertFalse("Source is connected!", source.isConnected()); @@ -56,7 +55,7 @@ public void testColdReplayNoBackpressure() { } @Test public void testColdReplayBackpressure() { - CachedObservable source = CachedObservable.from(Observable.range(0, 1000)); + CachedObservable source = CachedObservable.from(Flowable.range(0, 1000)); assertFalse("Source is connected!", source.isConnected()); @@ -84,7 +83,7 @@ public void testColdReplayBackpressure() { @Test public void testCache() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - Observable o = Observable.create(new Publisher() { + Flowable o = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { @@ -134,7 +133,7 @@ public void accept(String v) { @Test public void testUnsubscribeSource() { Runnable unsubscribe = mock(Runnable.class); - Observable o = Observable.just(1).doOnCancel(unsubscribe).cache(); + Flowable o = Flowable.just(1).doOnCancel(unsubscribe).cache(); o.subscribe(); o.subscribe(); o.subscribe(); @@ -145,7 +144,7 @@ public void testUnsubscribeSource() { public void testTake() { TestSubscriber ts = new TestSubscriber(); - CachedObservable cached = CachedObservable.from(Observable.range(1, 100)); + CachedObservable cached = CachedObservable.from(Flowable.range(1, 100)); cached.take(10).subscribe(ts); ts.assertNoErrors(); @@ -157,7 +156,7 @@ public void testTake() { @Test public void testAsync() { - Observable source = Observable.range(1, 10000); + Flowable source = Flowable.range(1, 10000); for (int i = 0; i < 100; i++) { TestSubscriber ts1 = new TestSubscriber(); @@ -181,12 +180,12 @@ public void testAsync() { } @Test public void testAsyncComeAndGo() { - Observable source = Observable.interval(1, 1, TimeUnit.MILLISECONDS) + Flowable source = Flowable.interval(1, 1, TimeUnit.MILLISECONDS) .take(1000) .subscribeOn(Schedulers.io()); CachedObservable cached = CachedObservable.from(source); - Observable output = cached.observeOn(Schedulers.computation()); + Flowable output = cached.observeOn(Schedulers.computation()); List> list = new ArrayList>(100); for (int i = 0; i < 100; i++) { @@ -218,7 +217,7 @@ public void testAsyncComeAndGo() { @Test public void testNoMissingBackpressureException() { final int m = 4 * 1000 * 1000; - Observable firehose = Observable.create(new Publisher() { + Flowable firehose = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber t) { t.onSubscribe(EmptySubscription.INSTANCE); @@ -241,8 +240,8 @@ public void subscribe(Subscriber t) { @Test public void testValuesAndThenError() { - Observable source = Observable.range(1, 10) - .concatWith(Observable.error(new TestException())) + Flowable source = Flowable.range(1, 10) + .concatWith(Flowable.error(new TestException())) .cache(); @@ -265,7 +264,7 @@ public void testValuesAndThenError() { public void unsafeChildThrows() { final AtomicInteger count = new AtomicInteger(); - Observable source = Observable.range(1, 100) + Flowable source = Flowable.range(1, 100) .doOnNext(new Consumer() { @Override public void accept(Integer t) { diff --git a/src/test/java/io/reactivex/internal/operators/NotificationLiteTest.java b/src/test/java/io/reactivex/internal/operators/flowable/NotificationLiteTest.java similarity index 97% rename from src/test/java/io/reactivex/internal/operators/NotificationLiteTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/NotificationLiteTest.java index d5f6db73cf..574852d387 100644 --- a/src/test/java/io/reactivex/internal/operators/NotificationLiteTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/NotificationLiteTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; diff --git a/src/test/java/io/reactivex/internal/operators/OnSubscribeAmbTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeAmbTest.java similarity index 80% rename from src/test/java/io/reactivex/internal/operators/OnSubscribeAmbTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeAmbTest.java index 71195544e7..15f8ac72b4 100644 --- a/src/test/java/io/reactivex/internal/operators/OnSubscribeAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeAmbTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -27,9 +27,9 @@ import io.reactivex.*; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.functions.Consumer; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; -import io.reactivex.subjects.PublishSubject; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class OnSubscribeAmbTest { @@ -42,9 +42,9 @@ public void setUp() { innerScheduler = scheduler.createWorker(); } - private Observable createObservable(final String[] values, + private Flowable createObservable(final String[] values, final long interval, final Throwable e) { - return Observable.create(new Publisher() { + return Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber subscriber) { @@ -89,19 +89,19 @@ public void run() { @Test public void testAmb() { - Observable observable1 = createObservable(new String[] { + Flowable observable1 = createObservable(new String[] { "1", "11", "111", "1111" }, 2000, null); - Observable observable2 = createObservable(new String[] { + Flowable observable2 = createObservable(new String[] { "2", "22", "222", "2222" }, 1000, null); - Observable observable3 = createObservable(new String[] { + Flowable observable3 = createObservable(new String[] { "3", "33", "333", "3333" }, 3000, null); @SuppressWarnings("unchecked") - Observable o = Observable.amb(observable1, + Flowable o = Flowable.amb(observable1, observable2, observable3); @SuppressWarnings("unchecked") - Observer observer = mock(Observer.class); + DefaultObserver observer = mock(DefaultObserver.class); o.subscribe(observer); scheduler.advanceTimeBy(100000, TimeUnit.MILLISECONDS); @@ -119,19 +119,19 @@ public void testAmb() { public void testAmb2() { IOException expectedException = new IOException( "fake exception"); - Observable observable1 = createObservable(new String[] {}, + Flowable observable1 = createObservable(new String[] {}, 2000, new IOException("fake exception")); - Observable observable2 = createObservable(new String[] { + Flowable observable2 = createObservable(new String[] { "2", "22", "222", "2222" }, 1000, expectedException); - Observable observable3 = createObservable(new String[] {}, + Flowable observable3 = createObservable(new String[] {}, 3000, new IOException("fake exception")); @SuppressWarnings("unchecked") - Observable o = Observable.amb(observable1, + Flowable o = Flowable.amb(observable1, observable2, observable3); @SuppressWarnings("unchecked") - Observer observer = mock(Observer.class); + DefaultObserver observer = mock(DefaultObserver.class); o.subscribe(observer); scheduler.advanceTimeBy(100000, TimeUnit.MILLISECONDS); @@ -147,19 +147,19 @@ public void testAmb2() { @Test public void testAmb3() { - Observable observable1 = createObservable(new String[] { + Flowable observable1 = createObservable(new String[] { "1" }, 2000, null); - Observable observable2 = createObservable(new String[] {}, + Flowable observable2 = createObservable(new String[] {}, 1000, null); - Observable observable3 = createObservable(new String[] { + Flowable observable3 = createObservable(new String[] { "3" }, 3000, null); @SuppressWarnings("unchecked") - Observable o = Observable.amb(observable1, + Flowable o = Flowable.amb(observable1, observable2, observable3); @SuppressWarnings("unchecked") - Observer observer = mock(Observer.class); + DefaultObserver observer = mock(DefaultObserver.class); o.subscribe(observer); scheduler.advanceTimeBy(100000, TimeUnit.MILLISECONDS); @@ -175,7 +175,7 @@ public void testProducerRequestThroughAmb() { ts.request(3); final AtomicLong requested1 = new AtomicLong(); final AtomicLong requested2 = new AtomicLong(); - Observable o1 = Observable.create(new Publisher() { + Flowable o1 = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -195,7 +195,7 @@ public void cancel() { } }); - Observable o2 = Observable.create(new Publisher() { + Flowable o2 = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -215,7 +215,7 @@ public void cancel() { } }); - Observable.amb(o1, o2).subscribe(ts); + Flowable.amb(o1, o2).subscribe(ts); assertEquals(3, requested1.get()); assertEquals(3, requested2.get()); } @@ -223,15 +223,15 @@ public void cancel() { @Test public void testBackpressure() { TestSubscriber ts = new TestSubscriber(); - Observable.range(0, Observable.bufferSize() * 2) - .ambWith(Observable.range(0, Observable.bufferSize() * 2)) + Flowable.range(0, Flowable.bufferSize() * 2) + .ambWith(Flowable.range(0, Flowable.bufferSize() * 2)) .observeOn(Schedulers.computation()) // observeOn has a backpressured RxRingBuffer .delay(1, TimeUnit.MICROSECONDS) // make it a slightly slow consumer .subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.values().size()); + assertEquals(Flowable.bufferSize() * 2, ts.values().size()); } @@ -247,13 +247,13 @@ public void accept(Subscription s) { }; //this aync stream should emit first - Observable o1 = Observable.just(1).doOnSubscribe(incrementer) + Flowable o1 = Flowable.just(1).doOnSubscribe(incrementer) .delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation()); //this stream emits second - Observable o2 = Observable.just(1).doOnSubscribe(incrementer) + Flowable o2 = Flowable.just(1).doOnSubscribe(incrementer) .delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation()); TestSubscriber ts = new TestSubscriber(); - Observable.amb(o1, o2).subscribe(ts); + Flowable.amb(o1, o2).subscribe(ts); ts.request(1); ts.awaitTerminalEvent(5, TimeUnit.SECONDS); ts.assertNoErrors(); @@ -264,14 +264,14 @@ public void accept(Subscription s) { @Test public void testSecondaryRequestsPropagatedToChildren() throws InterruptedException { //this aync stream should emit first - Observable o1 = Observable.fromArray(1, 2, 3) + Flowable o1 = Flowable.fromArray(1, 2, 3) .delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation()); //this stream emits second - Observable o2 = Observable.fromArray(4, 5, 6) + Flowable o2 = Flowable.fromArray(4, 5, 6) .delay(200, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation()); TestSubscriber ts = new TestSubscriber(1L); - Observable.amb(o1, o2).subscribe(ts); + Flowable.amb(o1, o2).subscribe(ts); // before first emission request 20 more // this request should suffice to emit all ts.request(20); @@ -287,7 +287,7 @@ public void testSynchronousSources() { // then second observable does not get subscribed to before first // subscription completes hence first observable emits result through // amb - int result = Observable.just(1).doOnNext(new Consumer() { + int result = Flowable.just(1).doOnNext(new Consumer() { @Override public void accept(Integer t) { try { @@ -296,20 +296,20 @@ public void accept(Integer t) { // } } - }).ambWith(Observable.just(2)).toBlocking().single(); + }).ambWith(Flowable.just(2)).toBlocking().single(); assertEquals(1, result); } @SuppressWarnings("unchecked") @Test public void testAmbCancelsOthers() { - PublishSubject source1 = PublishSubject.create(); - PublishSubject source2 = PublishSubject.create(); - PublishSubject source3 = PublishSubject.create(); + PublishProcessor source1 = PublishProcessor.create(); + PublishProcessor source2 = PublishProcessor.create(); + PublishProcessor source3 = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber(); - Observable.amb(source1, source2, source3).subscribe(ts); + Flowable.amb(source1, source2, source3).subscribe(ts); assertTrue("Source 1 doesn't have subscribers!", source1.hasSubscribers()); assertTrue("Source 2 doesn't have subscribers!", source2.hasSubscribers()); diff --git a/src/test/java/io/reactivex/internal/operators/OnSubscribeCombineLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeCombineLatestTest.java similarity index 76% rename from src/test/java/io/reactivex/internal/operators/OnSubscribeCombineLatestTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeCombineLatestTest.java index c9ab0bd385..6e5a547c73 100644 --- a/src/test/java/io/reactivex/internal/operators/OnSubscribeCombineLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeCombineLatestTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,13 +25,13 @@ import org.mockito.*; import org.reactivestreams.Subscriber; -import io.reactivex.Optional; -import io.reactivex.Observable; -import io.reactivex.Observer; import io.reactivex.*; +import io.reactivex.Optional; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; public class OnSubscribeCombineLatestTest { @@ -40,10 +40,10 @@ public class OnSubscribeCombineLatestTest { public void testCombineLatestWithFunctionThatThrowsAnException() { Subscriber w = TestHelper.mockSubscriber(); - PublishSubject w1 = PublishSubject.create(); - PublishSubject w2 = PublishSubject.create(); + PublishProcessor w1 = PublishProcessor.create(); + PublishProcessor w2 = PublishProcessor.create(); - Observable combined = Observable.combineLatest(w1, w2, new BiFunction() { + Flowable combined = Flowable.combineLatest(w1, w2, new BiFunction() { @Override public String apply(String v1, String v2) { throw new RuntimeException("I don't work."); @@ -63,11 +63,11 @@ public String apply(String v1, String v2) { public void testCombineLatestDifferentLengthObservableSequences1() { Subscriber w = TestHelper.mockSubscriber(); - PublishSubject w1 = PublishSubject.create(); - PublishSubject w2 = PublishSubject.create(); - PublishSubject w3 = PublishSubject.create(); + PublishProcessor w1 = PublishProcessor.create(); + PublishProcessor w2 = PublishProcessor.create(); + PublishProcessor w3 = PublishProcessor.create(); - Observable combineLatestW = Observable.combineLatest(w1, w2, w3, + Flowable combineLatestW = Flowable.combineLatest(w1, w2, w3, getConcat3StringsCombineLatestFunction()); combineLatestW.subscribe(w); @@ -101,11 +101,11 @@ public void testCombineLatestDifferentLengthObservableSequences1() { public void testCombineLatestDifferentLengthObservableSequences2() { Subscriber w = TestHelper.mockSubscriber(); - PublishSubject w1 = PublishSubject.create(); - PublishSubject w2 = PublishSubject.create(); - PublishSubject w3 = PublishSubject.create(); + PublishProcessor w1 = PublishProcessor.create(); + PublishProcessor w2 = PublishProcessor.create(); + PublishProcessor w3 = PublishProcessor.create(); - Observable combineLatestW = Observable.combineLatest(w1, w2, w3, getConcat3StringsCombineLatestFunction()); + Flowable combineLatestW = Flowable.combineLatest(w1, w2, w3, getConcat3StringsCombineLatestFunction()); combineLatestW.subscribe(w); /* simulate sending data */ @@ -136,11 +136,11 @@ public void testCombineLatestDifferentLengthObservableSequences2() { public void testCombineLatestWithInterleavingSequences() { Subscriber w = TestHelper.mockSubscriber(); - PublishSubject w1 = PublishSubject.create(); - PublishSubject w2 = PublishSubject.create(); - PublishSubject w3 = PublishSubject.create(); + PublishProcessor w1 = PublishProcessor.create(); + PublishProcessor w2 = PublishProcessor.create(); + PublishProcessor w3 = PublishProcessor.create(); - Observable combineLatestW = Observable.combineLatest(w1, w2, w3, getConcat3StringsCombineLatestFunction()); + Flowable combineLatestW = Flowable.combineLatest(w1, w2, w3, getConcat3StringsCombineLatestFunction()); combineLatestW.subscribe(w); /* simulate sending data */ @@ -177,7 +177,7 @@ public void testCombineLatest2Types() { /* define a Observer to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); - Observable w = Observable.combineLatest(Observable.just("one", "two"), Observable.just(2, 3, 4), combineLatestFunction); + Flowable w = Flowable.combineLatest(Flowable.just("one", "two"), Flowable.just(2, 3, 4), combineLatestFunction); w.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); @@ -194,7 +194,7 @@ public void testCombineLatest3TypesA() { /* define a Observer to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); - Observable w = Observable.combineLatest(Observable.just("one", "two"), Observable.just(2), Observable.just(new int[] { 4, 5, 6 }), combineLatestFunction); + Flowable w = Flowable.combineLatest(Flowable.just("one", "two"), Flowable.just(2), Flowable.just(new int[] { 4, 5, 6 }), combineLatestFunction); w.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); @@ -209,7 +209,7 @@ public void testCombineLatest3TypesB() { /* define a Observer to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); - Observable w = Observable.combineLatest(Observable.just("one"), Observable.just(2), Observable.just(new int[] { 4, 5, 6 }, new int[] { 7, 8 }), combineLatestFunction); + Flowable w = Flowable.combineLatest(Flowable.just("one"), Flowable.just(2), Flowable.just(new int[] { 4, 5, 6 }, new int[] { 7, 8 }), combineLatestFunction); w.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); @@ -277,10 +277,10 @@ public Integer apply(Integer t1, Integer t2) { @Test public void combineSimple() { - PublishSubject a = PublishSubject.create(); - PublishSubject b = PublishSubject.create(); + PublishProcessor a = PublishProcessor.create(); + PublishProcessor b = PublishProcessor.create(); - Observable source = Observable.combineLatest(a, b, or); + Flowable source = Flowable.combineLatest(a, b, or); Subscriber observer = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(observer); @@ -321,10 +321,10 @@ public void combineSimple() { @Test public void combineMultipleObservers() { - PublishSubject a = PublishSubject.create(); - PublishSubject b = PublishSubject.create(); + PublishProcessor a = PublishProcessor.create(); + PublishProcessor b = PublishProcessor.create(); - Observable source = Observable.combineLatest(a, b, or); + Flowable source = Flowable.combineLatest(a, b, or); Subscriber observer1 = TestHelper.mockSubscriber(); @@ -378,10 +378,10 @@ public void combineMultipleObservers() { @Test public void testFirstNeverProduces() { - PublishSubject a = PublishSubject.create(); - PublishSubject b = PublishSubject.create(); + PublishProcessor a = PublishProcessor.create(); + PublishProcessor b = PublishProcessor.create(); - Observable source = Observable.combineLatest(a, b, or); + Flowable source = Flowable.combineLatest(a, b, or); Subscriber observer = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(observer); @@ -400,10 +400,10 @@ public void testFirstNeverProduces() { @Test public void testSecondNeverProduces() { - PublishSubject a = PublishSubject.create(); - PublishSubject b = PublishSubject.create(); + PublishProcessor a = PublishProcessor.create(); + PublishProcessor b = PublishProcessor.create(); - Observable source = Observable.combineLatest(a, b, or); + Flowable source = Flowable.combineLatest(a, b, or); Subscriber observer = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(observer); @@ -437,14 +437,14 @@ public List apply(Object[] args) { }; for (int i = 1; i <= n; i++) { System.out.println("test1ToNSources: " + i + " sources"); - List> sources = new ArrayList>(); + List> sources = new ArrayList>(); List values = new ArrayList(); for (int j = 0; j < i; j++) { - sources.add(Observable.just(j)); + sources.add(Flowable.just(j)); values.add(j); } - Observable> result = Observable.combineLatest(sources, func); + Flowable> result = Flowable.combineLatest(sources, func); Subscriber> o = TestHelper.mockSubscriber(); @@ -468,20 +468,20 @@ public List apply(Object[] args) { }; for (int i = 1; i <= n; i++) { System.out.println("test1ToNSourcesScheduled: " + i + " sources"); - List> sources = new ArrayList>(); + List> sources = new ArrayList>(); List values = new ArrayList(); for (int j = 0; j < i; j++) { - sources.add(Observable.just(j).subscribeOn(Schedulers.io())); + sources.add(Flowable.just(j).subscribeOn(Schedulers.io())); values.add(j); } - Observable> result = Observable.combineLatest(sources, func); + Flowable> result = Flowable.combineLatest(sources, func); final Subscriber> o = TestHelper.mockSubscriber(); final CountDownLatch cdl = new CountDownLatch(1); - Subscriber> s = new Observer>() { + Subscriber> s = new DefaultObserver>() { @Override public void onNext(List t) { @@ -513,10 +513,10 @@ public void onComplete() { @Test public void test2SourcesOverload() { - Observable s1 = Observable.just(1); - Observable s2 = Observable.just(2); + Flowable s1 = Flowable.just(1); + Flowable s2 = Flowable.just(2); - Observable> result = Observable.combineLatest(s1, s2, + Flowable> result = Flowable.combineLatest(s1, s2, new BiFunction>() { @Override public List apply(Integer t1, Integer t2) { @@ -535,11 +535,11 @@ public List apply(Integer t1, Integer t2) { @Test public void test3SourcesOverload() { - Observable s1 = Observable.just(1); - Observable s2 = Observable.just(2); - Observable s3 = Observable.just(3); + Flowable s1 = Flowable.just(1); + Flowable s2 = Flowable.just(2); + Flowable s3 = Flowable.just(3); - Observable> result = Observable.combineLatest(s1, s2, s3, + Flowable> result = Flowable.combineLatest(s1, s2, s3, new Function3>() { @Override public List apply(Integer t1, Integer t2, Integer t3) { @@ -558,12 +558,12 @@ public List apply(Integer t1, Integer t2, Integer t3) { @Test public void test4SourcesOverload() { - Observable s1 = Observable.just(1); - Observable s2 = Observable.just(2); - Observable s3 = Observable.just(3); - Observable s4 = Observable.just(4); + Flowable s1 = Flowable.just(1); + Flowable s2 = Flowable.just(2); + Flowable s3 = Flowable.just(3); + Flowable s4 = Flowable.just(4); - Observable> result = Observable.combineLatest(s1, s2, s3, s4, + Flowable> result = Flowable.combineLatest(s1, s2, s3, s4, new Function4>() { @Override public List apply(Integer t1, Integer t2, Integer t3, Integer t4) { @@ -582,13 +582,13 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4) { @Test public void test5SourcesOverload() { - Observable s1 = Observable.just(1); - Observable s2 = Observable.just(2); - Observable s3 = Observable.just(3); - Observable s4 = Observable.just(4); - Observable s5 = Observable.just(5); + Flowable s1 = Flowable.just(1); + Flowable s2 = Flowable.just(2); + Flowable s3 = Flowable.just(3); + Flowable s4 = Flowable.just(4); + Flowable s5 = Flowable.just(5); - Observable> result = Observable.combineLatest(s1, s2, s3, s4, s5, + Flowable> result = Flowable.combineLatest(s1, s2, s3, s4, s5, new Function5>() { @Override public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5) { @@ -607,14 +607,14 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ @Test public void test6SourcesOverload() { - Observable s1 = Observable.just(1); - Observable s2 = Observable.just(2); - Observable s3 = Observable.just(3); - Observable s4 = Observable.just(4); - Observable s5 = Observable.just(5); - Observable s6 = Observable.just(6); - - Observable> result = Observable.combineLatest(s1, s2, s3, s4, s5, s6, + Flowable s1 = Flowable.just(1); + Flowable s2 = Flowable.just(2); + Flowable s3 = Flowable.just(3); + Flowable s4 = Flowable.just(4); + Flowable s5 = Flowable.just(5); + Flowable s6 = Flowable.just(6); + + Flowable> result = Flowable.combineLatest(s1, s2, s3, s4, s5, s6, new Function6>() { @Override public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6) { @@ -633,15 +633,15 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ @Test public void test7SourcesOverload() { - Observable s1 = Observable.just(1); - Observable s2 = Observable.just(2); - Observable s3 = Observable.just(3); - Observable s4 = Observable.just(4); - Observable s5 = Observable.just(5); - Observable s6 = Observable.just(6); - Observable s7 = Observable.just(7); - - Observable> result = Observable.combineLatest(s1, s2, s3, s4, s5, s6, s7, + Flowable s1 = Flowable.just(1); + Flowable s2 = Flowable.just(2); + Flowable s3 = Flowable.just(3); + Flowable s4 = Flowable.just(4); + Flowable s5 = Flowable.just(5); + Flowable s6 = Flowable.just(6); + Flowable s7 = Flowable.just(7); + + Flowable> result = Flowable.combineLatest(s1, s2, s3, s4, s5, s6, s7, new Function7>() { @Override public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6, Integer t7) { @@ -660,16 +660,16 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ @Test public void test8SourcesOverload() { - Observable s1 = Observable.just(1); - Observable s2 = Observable.just(2); - Observable s3 = Observable.just(3); - Observable s4 = Observable.just(4); - Observable s5 = Observable.just(5); - Observable s6 = Observable.just(6); - Observable s7 = Observable.just(7); - Observable s8 = Observable.just(8); - - Observable> result = Observable.combineLatest(s1, s2, s3, s4, s5, s6, s7, s8, + Flowable s1 = Flowable.just(1); + Flowable s2 = Flowable.just(2); + Flowable s3 = Flowable.just(3); + Flowable s4 = Flowable.just(4); + Flowable s5 = Flowable.just(5); + Flowable s6 = Flowable.just(6); + Flowable s7 = Flowable.just(7); + Flowable s8 = Flowable.just(8); + + Flowable> result = Flowable.combineLatest(s1, s2, s3, s4, s5, s6, s7, s8, new Function8>() { @Override public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6, Integer t7, Integer t8) { @@ -688,17 +688,17 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ @Test public void test9SourcesOverload() { - Observable s1 = Observable.just(1); - Observable s2 = Observable.just(2); - Observable s3 = Observable.just(3); - Observable s4 = Observable.just(4); - Observable s5 = Observable.just(5); - Observable s6 = Observable.just(6); - Observable s7 = Observable.just(7); - Observable s8 = Observable.just(8); - Observable s9 = Observable.just(9); - - Observable> result = Observable.combineLatest(s1, s2, s3, s4, s5, s6, s7, s8, s9, + Flowable s1 = Flowable.just(1); + Flowable s2 = Flowable.just(2); + Flowable s3 = Flowable.just(3); + Flowable s4 = Flowable.just(4); + Flowable s5 = Flowable.just(5); + Flowable s6 = Flowable.just(6); + Flowable s7 = Flowable.just(7); + Flowable s8 = Flowable.just(8); + Flowable s9 = Flowable.just(9); + + Flowable> result = Flowable.combineLatest(s1, s2, s3, s4, s5, s6, s7, s8, s9, new Function9>() { @Override public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6, Integer t7, Integer t8, Integer t9) { @@ -717,8 +717,8 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ @Test public void testZeroSources() { - Observable result = Observable.combineLatest( - Collections.> emptyList(), new Function() { + Flowable result = Flowable.combineLatest( + Collections.> emptyList(), new Function() { @Override public Object apply(Object[] args) { @@ -748,11 +748,11 @@ public void testBackpressureLoop() { public void testBackpressure() { BiFunction combineLatestFunction = getConcatStringIntegerCombineLatestFunction(); - int NUM = Observable.bufferSize() * 4; + int NUM = Flowable.bufferSize() * 4; TestSubscriber ts = new TestSubscriber(); - Observable.combineLatest( - Observable.just("one", "two"), - Observable.range(2, NUM), + Flowable.combineLatest( + Flowable.just("one", "two"), + Flowable.range(2, NUM), combineLatestFunction ) .observeOn(Schedulers.computation()) @@ -772,7 +772,7 @@ public void testWithCombineLatestIssue1717() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicInteger count = new AtomicInteger(); final int SIZE = 2000; - Observable timer = Observable.interval(0, 1, TimeUnit.MILLISECONDS) + Flowable timer = Flowable.interval(0, 1, TimeUnit.MILLISECONDS) .observeOn(Schedulers.newThread()) .doOnEach(new Consumer>>() { @Override @@ -786,7 +786,7 @@ public void accept(Try> n) { TestSubscriber ts = new TestSubscriber(); - Observable.combineLatest(timer, Observable. never(), new BiFunction() { + Flowable.combineLatest(timer, Flowable. never(), new BiFunction() { @Override public Long apply(Long t1, Integer t2) { return t1; @@ -803,16 +803,16 @@ public Long apply(Long t1, Integer t2) { @Test(timeout=10000) public void testCombineLatestRequestOverflow() throws InterruptedException { @SuppressWarnings("unchecked") - List> sources = Arrays.asList(Observable.fromArray(1, 2, 3, 4), - Observable.fromArray(5,6,7,8)); - Observable o = Observable.combineLatest(sources,new Function() { + List> sources = Arrays.asList(Flowable.fromArray(1, 2, 3, 4), + Flowable.fromArray(5,6,7,8)); + Flowable o = Flowable.combineLatest(sources,new Function() { @Override public Integer apply(Object[] args) { return (Integer) args[0]; }}); //should get at least 4 final CountDownLatch latch = new CountDownLatch(4); - o.subscribeOn(Schedulers.computation()).subscribe(new Observer() { + o.subscribeOn(Schedulers.computation()).subscribe(new DefaultObserver() { @Override public void onStart() { diff --git a/src/test/java/io/reactivex/internal/operators/OnSubscribeDeferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeDeferTest.java similarity index 78% rename from src/test/java/io/reactivex/internal/operators/OnSubscribeDeferTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeDeferTest.java index 25a5ef9d6e..cb1c4bdbcf 100644 --- a/src/test/java/io/reactivex/internal/operators/OnSubscribeDeferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeDeferTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -19,9 +19,11 @@ import org.junit.Test; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Supplier; +import io.reactivex.subscribers.DefaultObserver; @SuppressWarnings("unchecked") public class OnSubscribeDeferTest { @@ -29,13 +31,13 @@ public class OnSubscribeDeferTest { @Test public void testDefer() throws Throwable { - Supplier> factory = mock(Supplier.class); + Supplier> factory = mock(Supplier.class); - Observable firstObservable = Observable.just("one", "two"); - Observable secondObservable = Observable.just("three", "four"); + Flowable firstObservable = Flowable.just("one", "two"); + Flowable secondObservable = Flowable.just("three", "four"); when(factory.get()).thenReturn(firstObservable, secondObservable); - Observable deferred = Observable.defer(factory); + Flowable deferred = Flowable.defer(factory); verifyZeroInteractions(factory); @@ -63,13 +65,13 @@ public void testDefer() throws Throwable { @Test public void testDeferFunctionThrows() { - Supplier> factory = mock(Supplier.class); + Supplier> factory = mock(Supplier.class); when(factory.get()).thenThrow(new TestException()); - Observable result = Observable.defer(factory); + Flowable result = Flowable.defer(factory); - Observer o = mock(Observer.class); + DefaultObserver o = mock(DefaultObserver.class); result.subscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/OnSubscribeFromIterableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeFromIterableTest.java similarity index 87% rename from src/test/java/io/reactivex/internal/operators/OnSubscribeFromIterableTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeFromIterableTest.java index 443bab026e..0e003bbb42 100644 --- a/src/test/java/io/reactivex/internal/operators/OnSubscribeFromIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeFromIterableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -25,22 +25,22 @@ import org.mockito.Mockito; import org.reactivestreams.Subscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.schedulers.Schedulers; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; public class OnSubscribeFromIterableTest { @Test(expected = NullPointerException.class) public void testNull() { - Observable.fromIterable(null); + Flowable.fromIterable(null); } @Test public void testListIterable() { - Observable observable = Observable.fromIterable(Arrays. asList("one", "two", "three")); + Flowable observable = Flowable.fromIterable(Arrays. asList("one", "two", "three")); Subscriber observer = TestHelper.mockSubscriber(); @@ -84,7 +84,7 @@ public void remove() { } }; - Observable observable = Observable.fromIterable(it); + Flowable observable = Flowable.fromIterable(it); Subscriber observer = TestHelper.mockSubscriber(); @@ -99,7 +99,7 @@ public void remove() { @Test public void testObservableFromIterable() { - Observable observable = Observable.fromIterable(Arrays. asList("one", "two", "three")); + Flowable observable = Flowable.fromIterable(Arrays. asList("one", "two", "three")); Subscriber observer = TestHelper.mockSubscriber(); @@ -114,11 +114,11 @@ public void testObservableFromIterable() { @Test public void testBackpressureViaRequest() { - ArrayList list = new ArrayList(Observable.bufferSize()); - for (int i = 1; i <= Observable.bufferSize() + 1; i++) { + ArrayList list = new ArrayList(Flowable.bufferSize()); + for (int i = 1; i <= Flowable.bufferSize() + 1; i++) { list.add(i); } - Observable o = Observable.fromIterable(list); + Flowable o = Flowable.fromIterable(list); TestSubscriber ts = new TestSubscriber((Long)null); @@ -138,7 +138,7 @@ public void testBackpressureViaRequest() { @Test public void testNoBackpressure() { - Observable o = Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)); + Flowable o = Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)); TestSubscriber ts = new TestSubscriber((Long)null); @@ -153,7 +153,7 @@ public void testNoBackpressure() { @Test public void testSubscribeMultipleTimes() { - Observable o = Observable.fromIterable(Arrays.asList(1, 2, 3)); + Flowable o = Flowable.fromIterable(Arrays.asList(1, 2, 3)); for (int i = 0; i < 10; i++) { TestSubscriber ts = new TestSubscriber(); @@ -168,13 +168,13 @@ public void testSubscribeMultipleTimes() { @Test public void testFromIterableRequestOverflow() throws InterruptedException { - Observable o = Observable.fromIterable(Arrays.asList(1,2,3,4)); + Flowable o = Flowable.fromIterable(Arrays.asList(1,2,3,4)); final int expectedCount = 4; final CountDownLatch latch = new CountDownLatch(expectedCount); o.subscribeOn(Schedulers.computation()) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onStart() { @@ -204,7 +204,7 @@ public void testFromEmptyIterableWhenZeroRequestedShouldStillEmitOnCompletedEage final AtomicBoolean completed = new AtomicBoolean(false); - Observable.fromIterable(Collections.emptyList()).subscribe(new Observer() { + Flowable.fromIterable(Collections.emptyList()).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -261,7 +261,7 @@ public Integer next() { }; } }; - Observable.fromIterable(iterable).take(1).subscribe(); + Flowable.fromIterable(iterable).take(1).subscribe(); assertFalse(called.get()); } @@ -298,7 +298,7 @@ public Integer next() { }; } }; - Observable.fromIterable(iterable).subscribe(new Observer() { + Flowable.fromIterable(iterable).subscribe(new DefaultObserver() { @Override public void onComplete() { diff --git a/src/test/java/io/reactivex/internal/operators/OnSubscribeRangeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeRangeTest.java similarity index 83% rename from src/test/java/io/reactivex/internal/operators/OnSubscribeRangeTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeRangeTest.java index 817f1521b3..50d5aca03e 100644 --- a/src/test/java/io/reactivex/internal/operators/OnSubscribeRangeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeRangeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -22,10 +22,10 @@ import org.junit.Test; import org.reactivestreams.Subscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Consumer; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; public class OnSubscribeRangeTest { @@ -34,7 +34,7 @@ public class OnSubscribeRangeTest { public void testRangeStartAt2Count3() { Subscriber observer = TestHelper.mockSubscriber(); - Observable.range(2, 3).subscribe(observer); + Flowable.range(2, 3).subscribe(observer); verify(observer, times(1)).onNext(2); verify(observer, times(1)).onNext(3); @@ -50,7 +50,7 @@ public void testRangeUnsubscribe() { final AtomicInteger count = new AtomicInteger(); - Observable.range(1, 1000).doOnNext(new Consumer() { + Flowable.range(1, 1000).doOnNext(new Consumer() { @Override public void accept(Integer t1) { count.incrementAndGet(); @@ -69,32 +69,32 @@ public void accept(Integer t1) { @Test public void testRangeWithZero() { - Observable.range(1, 0); + Flowable.range(1, 0); } @Test public void testRangeWithOverflow2() { - Observable.range(Integer.MAX_VALUE, 0); + Flowable.range(Integer.MAX_VALUE, 0); } @Test public void testRangeWithOverflow3() { - Observable.range(1, Integer.MAX_VALUE); + Flowable.range(1, Integer.MAX_VALUE); } @Test(expected = IllegalArgumentException.class) public void testRangeWithOverflow4() { - Observable.range(2, Integer.MAX_VALUE); + Flowable.range(2, Integer.MAX_VALUE); } @Test public void testRangeWithOverflow5() { - assertFalse(Observable.range(Integer.MIN_VALUE, 0).toBlocking().iterator().hasNext()); + assertFalse(Flowable.range(Integer.MIN_VALUE, 0).toBlocking().iterator().hasNext()); } @Test public void testBackpressureViaRequest() { - Observable o = Observable.range(1, Observable.bufferSize()); + Flowable o = Flowable.range(1, Flowable.bufferSize()); TestSubscriber ts = new TestSubscriber((Long)null); @@ -111,18 +111,18 @@ public void testBackpressureViaRequest() { ts.request(3); ts.assertValues(1, 2, 3, 4, 5, 6); - ts.request(Observable.bufferSize()); + ts.request(Flowable.bufferSize()); ts.assertTerminated(); } @Test public void testNoBackpressure() { - ArrayList list = new ArrayList(Observable.bufferSize() * 2); - for (int i = 1; i <= Observable.bufferSize() * 2 + 1; i++) { + ArrayList list = new ArrayList(Flowable.bufferSize() * 2); + for (int i = 1; i <= Flowable.bufferSize() * 2 + 1; i++) { list.add(i); } - Observable o = Observable.range(1, list.size()); + Flowable o = Flowable.range(1, list.size()); TestSubscriber ts = new TestSubscriber((Long)null); @@ -135,7 +135,7 @@ public void testNoBackpressure() { ts.assertTerminated(); } void testWithBackpressureOneByOne(int start) { - Observable source = Observable.range(start, 100); + Flowable source = Flowable.range(start, 100); TestSubscriber ts = new TestSubscriber((Long)null); ts.request(1); @@ -150,7 +150,7 @@ void testWithBackpressureOneByOne(int start) { ts.assertTerminated(); } void testWithBackpressureAllAtOnce(int start) { - Observable source = Observable.range(start, 100); + Flowable source = Flowable.range(start, 100); TestSubscriber ts = new TestSubscriber((Long)null); ts.request(100); @@ -177,7 +177,7 @@ public void testWithBackpressureAllAtOnce() { } @Test public void testWithBackpressureRequestWayMore() { - Observable source = Observable.range(50, 100); + Flowable source = Flowable.range(50, 100); TestSubscriber ts = new TestSubscriber((Long)null); ts.request(150); @@ -198,7 +198,7 @@ public void testWithBackpressureRequestWayMore() { public void testRequestOverflow() { final AtomicInteger count = new AtomicInteger(); int n = 10; - Observable.range(1, n).subscribe(new Observer() { + Flowable.range(1, n).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -226,7 +226,7 @@ public void onNext(Integer t) { @Test public void testEmptyRangeSendsOnCompleteEagerlyWithRequestZero() { final AtomicBoolean completed = new AtomicBoolean(false); - Observable.range(1, 0).subscribe(new Observer() { + Flowable.range(1, 0).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -253,7 +253,7 @@ public void onNext(Integer t) { @Test(timeout = 1000) public void testNearMaxValueWithoutBackpressure() { TestSubscriber ts = new TestSubscriber(); - Observable.range(Integer.MAX_VALUE - 1, 2).subscribe(ts); + Flowable.range(Integer.MAX_VALUE - 1, 2).subscribe(ts); ts.assertComplete(); ts.assertNoErrors(); @@ -262,7 +262,7 @@ public void testNearMaxValueWithoutBackpressure() { @Test(timeout = 1000) public void testNearMaxValueWithBackpressure() { TestSubscriber ts = new TestSubscriber(3L); - Observable.range(Integer.MAX_VALUE - 1, 2).subscribe(ts); + Flowable.range(Integer.MAX_VALUE - 1, 2).subscribe(ts); ts.assertComplete(); ts.assertNoErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/OnSubscribeRefCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeRefCountTest.java similarity index 91% rename from src/test/java/io/reactivex/internal/operators/OnSubscribeRefCountTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeRefCountTest.java index 1c1c46abd5..b0c8ffd0c2 100644 --- a/src/test/java/io/reactivex/internal/operators/OnSubscribeRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeRefCountTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -25,13 +25,13 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.Observable; -import io.reactivex.TestHelper; +import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.internal.subscribers.CancelledSubscriber; +import io.reactivex.internal.subscribers.flowable.CancelledSubscriber; +import io.reactivex.processors.ReplayProcessor; import io.reactivex.schedulers.*; -import io.reactivex.subjects.ReplaySubject; import io.reactivex.subscribers.TestSubscriber; public class OnSubscribeRefCountTest { @@ -40,7 +40,7 @@ public class OnSubscribeRefCountTest { public void testRefCountAsync() { final AtomicInteger subscribeCount = new AtomicInteger(); final AtomicInteger nextCount = new AtomicInteger(); - Observable r = Observable.interval(0, 5, TimeUnit.MILLISECONDS) + Flowable r = Flowable.interval(0, 5, TimeUnit.MILLISECONDS) .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -87,7 +87,7 @@ public void accept(Long l) { public void testRefCountSynchronous() { final AtomicInteger subscribeCount = new AtomicInteger(); final AtomicInteger nextCount = new AtomicInteger(); - Observable r = Observable.just(1, 2, 3, 4, 5, 6, 7, 8, 9) + Flowable r = Flowable.just(1, 2, 3, 4, 5, 6, 7, 8, 9) .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -133,7 +133,7 @@ public void accept(Integer l) { @Test public void testRefCountSynchronousTake() { final AtomicInteger nextCount = new AtomicInteger(); - Observable r = Observable.just(1, 2, 3, 4, 5, 6, 7, 8, 9) + Flowable r = Flowable.just(1, 2, 3, 4, 5, 6, 7, 8, 9) .doOnNext(new Consumer() { @Override public void accept(Integer l) { @@ -162,7 +162,7 @@ public void accept(Integer l) { public void testRepeat() { final AtomicInteger subscribeCount = new AtomicInteger(); final AtomicInteger unsubscribeCount = new AtomicInteger(); - Observable r = Observable.interval(0, 1, TimeUnit.MILLISECONDS) + Flowable r = Flowable.interval(0, 1, TimeUnit.MILLISECONDS) .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -207,7 +207,7 @@ public void testConnectUnsubscribe() throws InterruptedException { final CountDownLatch unsubscribeLatch = new CountDownLatch(1); final CountDownLatch subscribeLatch = new CountDownLatch(1); - Observable o = synchronousInterval() + Flowable o = synchronousInterval() .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -253,7 +253,7 @@ public void testConnectUnsubscribeRaceConditionLoop() throws InterruptedExceptio @Test public void testConnectUnsubscribeRaceCondition() throws InterruptedException { final AtomicInteger subUnsubCount = new AtomicInteger(); - Observable o = synchronousInterval() + Flowable o = synchronousInterval() .doOnCancel(new Runnable() { @Override public void run() { @@ -290,8 +290,8 @@ public void accept(Subscription s) { s.assertNoErrors(); } - private Observable synchronousInterval() { - return Observable.create(new Publisher() { + private Flowable synchronousInterval() { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber subscriber) { final AtomicBoolean cancel = new AtomicBoolean(); @@ -325,7 +325,7 @@ public void cancel() { public void onlyFirstShouldSubscribeAndLastUnsubscribe() { final AtomicInteger subscriptionCount = new AtomicInteger(); final AtomicInteger unsubscriptionCount = new AtomicInteger(); - Observable observable = Observable.create(new Publisher() { + Flowable observable = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { subscriptionCount.incrementAndGet(); @@ -342,7 +342,7 @@ public void cancel() { }); } }); - Observable refCounted = observable.publish().refCount(); + Flowable refCounted = observable.publish().refCount(); Disposable first = refCounted.subscribe(); assertEquals(1, subscriptionCount.get()); @@ -360,7 +360,7 @@ public void cancel() { @Test public void testRefCount() { TestScheduler s = new TestScheduler(); - Observable interval = Observable.interval(100, TimeUnit.MILLISECONDS, s).publish().refCount(); + Flowable interval = Flowable.interval(100, TimeUnit.MILLISECONDS, s).publish().refCount(); // subscribe list1 final List list1 = new ArrayList(); @@ -445,7 +445,7 @@ public void testAlreadyUnsubscribedClient() { Subscriber o = TestHelper.mockSubscriber(); - Observable result = Observable.just(1).publish().refCount(); + Flowable result = Flowable.just(1).publish().refCount(); result.subscribe(done); @@ -458,14 +458,14 @@ public void testAlreadyUnsubscribedClient() { @Test public void testAlreadyUnsubscribedInterleavesWithClient() { - ReplaySubject source = ReplaySubject.create(); + ReplayProcessor source = ReplayProcessor.create(); Subscriber done = CancelledSubscriber.instance(); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); - Observable result = source.publish().refCount(); + Flowable result = source.publish().refCount(); result.subscribe(o); @@ -484,9 +484,9 @@ public void testAlreadyUnsubscribedInterleavesWithClient() { @Test public void testConnectDisconnectConnectAndSubjectState() { - Observable o1 = Observable.just(10); - Observable o2 = Observable.just(20); - Observable combined = Observable.combineLatest(o1, o2, new BiFunction() { + Flowable o1 = Flowable.just(10); + Flowable o2 = Flowable.just(20); + Flowable combined = Flowable.combineLatest(o1, o2, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2; @@ -512,8 +512,8 @@ public Integer apply(Integer t1, Integer t2) { @Test(timeout = 10000) public void testUpstreamErrorAllowsRetry() throws InterruptedException { final AtomicInteger intervalSubscribed = new AtomicInteger(); - Observable interval = - Observable.interval(200,TimeUnit.MILLISECONDS) + Flowable interval = + Flowable.interval(200,TimeUnit.MILLISECONDS) .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -524,10 +524,10 @@ public void accept(Subscription s) { .flatMap(new Function>() { @Override public Publisher apply(Long t1) { - return Observable.defer(new Supplier>() { + return Flowable.defer(new Supplier>() { @Override public Publisher get() { - return Observable.error(new Exception("Some exception")); + return Flowable.error(new Exception("Some exception")); } }); } @@ -535,7 +535,7 @@ public Publisher get() { .onErrorResumeNext(new Function>() { @Override public Publisher apply(Throwable t1) { - return Observable.error(t1); + return Flowable.error(t1); } }) .publish() diff --git a/src/test/java/io/reactivex/internal/operators/OnSubscribeTimerTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeTimerTest.java similarity index 87% rename from src/test/java/io/reactivex/internal/operators/OnSubscribeTimerTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeTimerTest.java index d069f7fa79..43793845dd 100644 --- a/src/test/java/io/reactivex/internal/operators/OnSubscribeTimerTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeTimerTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -22,11 +22,12 @@ import org.mockito.*; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; -import io.reactivex.observables.ConnectableObservable; +import io.reactivex.flowable.TestHelper; +import io.reactivex.flowables.ConnectableFlowable; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class OnSubscribeTimerTest { @Mock @@ -47,7 +48,7 @@ public void before() { @Test public void testTimerOnce() { - Observable.timer(100, TimeUnit.MILLISECONDS, scheduler).subscribe(observer); + Flowable.timer(100, TimeUnit.MILLISECONDS, scheduler).subscribe(observer); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); verify(observer, times(1)).onNext(0L); @@ -59,7 +60,7 @@ public void testTimerOnce() { public void testTimerPeriodically() { TestSubscriber ts = new TestSubscriber(); - Observable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler).subscribe(ts); + Flowable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler).subscribe(ts); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); @@ -83,7 +84,7 @@ public void testTimerPeriodically() { } @Test public void testInterval() { - Observable w = Observable.interval(1, TimeUnit.SECONDS, scheduler); + Flowable w = Flowable.interval(1, TimeUnit.SECONDS, scheduler); TestSubscriber ts = new TestSubscriber(); w.subscribe(ts); @@ -107,7 +108,7 @@ public void testInterval() { @Test public void testWithMultipleSubscribersStartingAtSameTime() { - Observable w = Observable.interval(1, TimeUnit.SECONDS, scheduler); + Flowable w = Flowable.interval(1, TimeUnit.SECONDS, scheduler); TestSubscriber ts1 = new TestSubscriber(); TestSubscriber ts2 = new TestSubscriber(); @@ -144,7 +145,7 @@ public void testWithMultipleSubscribersStartingAtSameTime() { @Test public void testWithMultipleStaggeredSubscribers() { - Observable w = Observable.interval(1, TimeUnit.SECONDS, scheduler); + Flowable w = Flowable.interval(1, TimeUnit.SECONDS, scheduler); TestSubscriber ts1 = new TestSubscriber(); @@ -184,7 +185,7 @@ public void testWithMultipleStaggeredSubscribers() { @Test public void testWithMultipleStaggeredSubscribersAndPublish() { - ConnectableObservable w = Observable.interval(1, TimeUnit.SECONDS, scheduler).publish(); + ConnectableFlowable w = Flowable.interval(1, TimeUnit.SECONDS, scheduler).publish(); TestSubscriber ts1 = new TestSubscriber(); @@ -223,9 +224,9 @@ public void testWithMultipleStaggeredSubscribersAndPublish() { } @Test public void testOnceObserverThrows() { - Observable source = Observable.timer(100, TimeUnit.MILLISECONDS, scheduler); + Flowable source = Flowable.timer(100, TimeUnit.MILLISECONDS, scheduler); - source.safeSubscribe(new Observer() { + source.safeSubscribe(new DefaultObserver() { @Override public void onNext(Long t) { @@ -251,11 +252,11 @@ public void onComplete() { } @Test public void testPeriodicObserverThrows() { - Observable source = Observable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler); + Flowable source = Flowable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler); InOrder inOrder = inOrder(observer); - source.safeSubscribe(new Observer() { + source.safeSubscribe(new DefaultObserver() { @Override public void onNext(Long t) { diff --git a/src/test/java/io/reactivex/internal/operators/OnSubscribeToObservableFutureTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeToObservableFutureTest.java similarity index 92% rename from src/test/java/io/reactivex/internal/operators/OnSubscribeToObservableFutureTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeToObservableFutureTest.java index 35cc0062e4..9e338f6b7d 100644 --- a/src/test/java/io/reactivex/internal/operators/OnSubscribeToObservableFutureTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeToObservableFutureTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,7 +22,8 @@ import org.junit.Test; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; @@ -39,7 +40,7 @@ public void testSuccess() throws Exception { TestSubscriber ts = new TestSubscriber(o); - Observable.fromFuture(future).subscribe(ts); + Flowable.fromFuture(future).subscribe(ts); ts.dispose(); @@ -60,7 +61,7 @@ public void testFailure() throws Exception { TestSubscriber ts = new TestSubscriber(o); - Observable.fromFuture(future).subscribe(ts); + Flowable.fromFuture(future).subscribe(ts); ts.dispose(); @@ -82,7 +83,7 @@ public void testCancelledBeforeSubscribe() throws Exception { TestSubscriber ts = new TestSubscriber(o); ts.dispose(); - Observable.fromFuture(future).subscribe(ts); + Flowable.fromFuture(future).subscribe(ts); ts.assertNoErrors(); ts.assertNotComplete(); @@ -126,7 +127,7 @@ public Object get(long timeout, TimeUnit unit) throws InterruptedException, Exec Subscriber o = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(o); - Observable futureObservable = Observable.fromFuture(future); + Flowable futureObservable = Flowable.fromFuture(future); futureObservable.subscribeOn(Schedulers.computation()).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/OnSubscribeUsingTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeUsingTest.java similarity index 78% rename from src/test/java/io/reactivex/internal/operators/OnSubscribeUsingTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeUsingTest.java index abb3c21fab..4ad52079bb 100644 --- a/src/test/java/io/reactivex/internal/operators/OnSubscribeUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OnSubscribeUsingTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -22,10 +22,10 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.Observable; -import io.reactivex.TestHelper; +import io.reactivex.Flowable; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; public class OnSubscribeUsingTest { @@ -75,16 +75,16 @@ public Resource get() { } }; - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public Observable apply(Resource res) { - return Observable.fromArray(res.getTextFromWeb().split(" ")); + public Flowable apply(Resource res) { + return Flowable.fromArray(res.getTextFromWeb().split(" ")); } }; Subscriber observer = TestHelper.mockSubscriber(); - Observable observable = Observable.using(resourceFactory, observableFactory, + Flowable observable = Flowable.using(resourceFactory, observableFactory, new DisposeAction(), disposeEagerly); observable.subscribe(observer); @@ -135,16 +135,16 @@ public void dispose() { } }; - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public Observable apply(Resource res) { - return Observable.fromArray(res.getTextFromWeb().split(" ")); + public Flowable apply(Resource res) { + return Flowable.fromArray(res.getTextFromWeb().split(" ")); } }; Subscriber observer = TestHelper.mockSubscriber(); - Observable observable = Observable.using(resourceFactory, observableFactory, + Flowable observable = Flowable.using(resourceFactory, observableFactory, new DisposeAction(), disposeEagerly); observable.subscribe(observer); observable.subscribe(observer); @@ -179,14 +179,14 @@ public Disposable get() { } }; - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public Observable apply(Disposable s) { - return Observable.empty(); + public Flowable apply(Disposable s) { + return Flowable.empty(); } }; - Observable.using(resourceFactory, observableFactory, disposeSubscription) + Flowable.using(resourceFactory, observableFactory, disposeSubscription) .toBlocking() .last(); } @@ -210,15 +210,15 @@ public Disposable get() { } }; - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public Observable apply(Disposable subscription) { + public Flowable apply(Disposable subscription) { throw new TestException(); } }; try { - Observable.using(resourceFactory, observableFactory, disposeSubscription).toBlocking() + Flowable.using(resourceFactory, observableFactory, disposeSubscription).toBlocking() .last(); fail("Should throw a TestException when the observableFactory throws it"); } catch (TestException e) { @@ -249,10 +249,10 @@ public Disposable get() { } }; - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public Observable apply(Disposable subscription) { - return Observable.create(new Publisher() { + public Flowable apply(Disposable subscription) { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber t1) { throw new TestException(); @@ -262,7 +262,7 @@ public void subscribe(Subscriber t1) { }; try { - Observable + Flowable .using(resourceFactory, observableFactory, disposeSubscription, disposeEagerly) .toBlocking().last(); @@ -281,16 +281,16 @@ public void testUsingDisposesEagerlyBeforeCompletion() { final Runnable completion = createOnCompletedAction(events); final Runnable unsub =createUnsubAction(events); - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public Observable apply(Resource resource) { - return Observable.fromArray(resource.getTextFromWeb().split(" ")); + public Flowable apply(Resource resource) { + return Flowable.fromArray(resource.getTextFromWeb().split(" ")); } }; Subscriber observer = TestHelper.mockSubscriber(); - Observable observable = Observable.using(resourceFactory, observableFactory, + Flowable observable = Flowable.using(resourceFactory, observableFactory, new DisposeAction(), true) .doOnCancel(unsub) .doOnComplete(completion); @@ -308,16 +308,16 @@ public void testUsingDoesNotDisposesEagerlyBeforeCompletion() { final Runnable completion = createOnCompletedAction(events); final Runnable unsub = createUnsubAction(events); - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public Observable apply(Resource resource) { - return Observable.fromArray(resource.getTextFromWeb().split(" ")); + public Flowable apply(Resource resource) { + return Flowable.fromArray(resource.getTextFromWeb().split(" ")); } }; Subscriber observer = TestHelper.mockSubscriber(); - Observable observable = Observable.using(resourceFactory, observableFactory, + Flowable observable = Flowable.using(resourceFactory, observableFactory, new DisposeAction(), false) .doOnCancel(unsub) .doOnComplete(completion); @@ -337,17 +337,17 @@ public void testUsingDisposesEagerlyBeforeError() { final Consumer onError = createOnErrorAction(events); final Runnable unsub = createUnsubAction(events); - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public Observable apply(Resource resource) { - return Observable.fromArray(resource.getTextFromWeb().split(" ")) - .concatWith(Observable.error(new RuntimeException())); + public Flowable apply(Resource resource) { + return Flowable.fromArray(resource.getTextFromWeb().split(" ")) + .concatWith(Flowable.error(new RuntimeException())); } }; Subscriber observer = TestHelper.mockSubscriber(); - Observable observable = Observable.using(resourceFactory, observableFactory, + Flowable observable = Flowable.using(resourceFactory, observableFactory, new DisposeAction(), true) .doOnCancel(unsub) .doOnError(onError); @@ -365,17 +365,17 @@ public void testUsingDoesNotDisposesEagerlyBeforeError() { final Consumer onError = createOnErrorAction(events); final Runnable unsub = createUnsubAction(events); - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public Observable apply(Resource resource) { - return Observable.fromArray(resource.getTextFromWeb().split(" ")) - .concatWith(Observable.error(new RuntimeException())); + public Flowable apply(Resource resource) { + return Flowable.fromArray(resource.getTextFromWeb().split(" ")) + .concatWith(Flowable.error(new RuntimeException())); } }; Subscriber observer = TestHelper.mockSubscriber(); - Observable observable = Observable.using(resourceFactory, observableFactory, + Flowable observable = Flowable.using(resourceFactory, observableFactory, new DisposeAction(), false) .doOnCancel(unsub) .doOnError(onError); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorAllTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorAllTest.java similarity index 86% rename from src/test/java/io/reactivex/internal/operators/OperatorAllTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorAllTest.java index 50daa68cbd..33442ca32e 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorAllTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorAllTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -22,7 +22,8 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.subscribers.TestSubscriber; @@ -30,7 +31,7 @@ public class OperatorAllTest { @Test public void testAll() { - Observable obs = Observable.just("one", "two", "six"); + Flowable obs = Flowable.just("one", "two", "six"); Subscriber observer = TestHelper.mockSubscriber(); @@ -50,7 +51,7 @@ public boolean test(String s) { @Test public void testNotAll() { - Observable obs = Observable.just("one", "two", "three", "six"); + Flowable obs = Flowable.just("one", "two", "three", "six"); Subscriber observer = TestHelper.mockSubscriber(); @@ -70,7 +71,7 @@ public boolean test(String s) { @Test public void testEmpty() { - Observable obs = Observable.empty(); + Flowable obs = Flowable.empty(); Subscriber observer = TestHelper.mockSubscriber(); @@ -91,7 +92,7 @@ public boolean test(String s) { @Test public void testError() { Throwable error = new Throwable(); - Observable obs = Observable.error(error); + Flowable obs = Flowable.error(error); Subscriber observer = TestHelper.mockSubscriber(); @@ -110,8 +111,8 @@ public boolean test(String s) { @Test public void testFollowingFirst() { - Observable o = Observable.fromArray(1, 3, 5, 6); - Observable allOdd = o.all(new Predicate() { + Flowable o = Flowable.fromArray(1, 3, 5, 6); + Flowable allOdd = o.all(new Predicate() { @Override public boolean test(Integer i) { return i % 2 == 1; @@ -122,7 +123,7 @@ public boolean test(Integer i) { } @Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstream() { - Observable source = Observable.just(1) + Flowable source = Flowable.just(1) .all(new Predicate() { @Override public boolean test(Integer t1) { @@ -132,7 +133,7 @@ public boolean test(Integer t1) { .flatMap(new Function>() { @Override public Publisher apply(Boolean t1) { - return Observable.just(2).delay(500, TimeUnit.MILLISECONDS); + return Flowable.just(2).delay(500, TimeUnit.MILLISECONDS); } }); @@ -142,7 +143,7 @@ public Publisher apply(Boolean t1) { @Test public void testBackpressureIfNoneRequestedNoneShouldBeDelivered() { TestSubscriber ts = new TestSubscriber((Long)null); - Observable.empty().all(new Predicate() { + Flowable.empty().all(new Predicate() { @Override public boolean test(Object t1) { return false; @@ -158,7 +159,7 @@ public boolean test(Object t1) { public void testBackpressureIfOneRequestedOneShouldBeDelivered() { TestSubscriber ts = new TestSubscriber(1L); - Observable.empty().all(new Predicate() { + Flowable.empty().all(new Predicate() { @Override public boolean test(Object t) { return false; @@ -178,7 +179,7 @@ public void testPredicateThrowsExceptionAndValueInCauseMessage() { final IllegalArgumentException ex = new IllegalArgumentException(); - Observable.just("Boo!").all(new Predicate() { + Flowable.just("Boo!").all(new Predicate() { @Override public boolean test(String v) { throw ex; diff --git a/src/test/java/io/reactivex/internal/operators/OperatorAnyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorAnyTest.java similarity index 81% rename from src/test/java/io/reactivex/internal/operators/OperatorAnyTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorAnyTest.java index 8172f579f2..c671d8ab5c 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorAnyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorAnyTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -21,7 +21,8 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.subscribers.TestSubscriber; @@ -29,8 +30,8 @@ public class OperatorAnyTest { @Test public void testAnyWithTwoItems() { - Observable w = Observable.just(1, 2); - Observable observable = w.any(new Predicate() { + Flowable w = Flowable.just(1, 2); + Flowable observable = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -49,8 +50,8 @@ public boolean test(Integer v) { @Test public void testIsEmptyWithTwoItems() { - Observable w = Observable.just(1, 2); - Observable observable = w.isEmpty(); + Flowable w = Flowable.just(1, 2); + Flowable observable = w.isEmpty(); Subscriber observer = TestHelper.mockSubscriber(); @@ -64,8 +65,8 @@ public void testIsEmptyWithTwoItems() { @Test public void testAnyWithOneItem() { - Observable w = Observable.just(1); - Observable observable = w.any(new Predicate() { + Flowable w = Flowable.just(1); + Flowable observable = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -84,8 +85,8 @@ public boolean test(Integer v) { @Test public void testIsEmptyWithOneItem() { - Observable w = Observable.just(1); - Observable observable = w.isEmpty(); + Flowable w = Flowable.just(1); + Flowable observable = w.isEmpty(); Subscriber observer = TestHelper.mockSubscriber(); @@ -99,8 +100,8 @@ public void testIsEmptyWithOneItem() { @Test public void testAnyWithEmpty() { - Observable w = Observable.empty(); - Observable observable = w.any(new Predicate() { + Flowable w = Flowable.empty(); + Flowable observable = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -119,8 +120,8 @@ public boolean test(Integer v) { @Test public void testIsEmptyWithEmpty() { - Observable w = Observable.empty(); - Observable observable = w.isEmpty(); + Flowable w = Flowable.empty(); + Flowable observable = w.isEmpty(); Subscriber observer = TestHelper.mockSubscriber(); @@ -134,8 +135,8 @@ public void testIsEmptyWithEmpty() { @Test public void testAnyWithPredicate1() { - Observable w = Observable.just(1, 2, 3); - Observable observable = w.any(new Predicate() { + Flowable w = Flowable.just(1, 2, 3); + Flowable observable = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 2; @@ -154,8 +155,8 @@ public boolean test(Integer t1) { @Test public void testExists1() { - Observable w = Observable.just(1, 2, 3); - Observable observable = w.any(new Predicate() { + Flowable w = Flowable.just(1, 2, 3); + Flowable observable = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 2; @@ -174,8 +175,8 @@ public boolean test(Integer t1) { @Test public void testAnyWithPredicate2() { - Observable w = Observable.just(1, 2, 3); - Observable observable = w.any(new Predicate() { + Flowable w = Flowable.just(1, 2, 3); + Flowable observable = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 1; @@ -195,8 +196,8 @@ public boolean test(Integer t1) { @Test public void testAnyWithEmptyAndPredicate() { // If the source is empty, always output false. - Observable w = Observable.empty(); - Observable observable = w.any(new Predicate() { + Flowable w = Flowable.empty(); + Flowable observable = w.any(new Predicate() { @Override public boolean test(Integer t) { return true; @@ -215,8 +216,8 @@ public boolean test(Integer t) { @Test public void testWithFollowingFirst() { - Observable o = Observable.fromArray(1, 3, 5, 6); - Observable anyEven = o.any(new Predicate() { + Flowable o = Flowable.fromArray(1, 3, 5, 6); + Flowable anyEven = o.any(new Predicate() { @Override public boolean test(Integer i) { return i % 2 == 0; @@ -227,11 +228,11 @@ public boolean test(Integer i) { } @Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstream() { - Observable source = Observable.just(1).isEmpty() + Flowable source = Flowable.just(1).isEmpty() .flatMap(new Function>() { @Override public Publisher apply(Boolean t1) { - return Observable.just(2).delay(500, TimeUnit.MILLISECONDS); + return Flowable.just(2).delay(500, TimeUnit.MILLISECONDS); } }); @@ -242,7 +243,7 @@ public Publisher apply(Boolean t1) { public void testBackpressureIfNoneRequestedNoneShouldBeDelivered() { TestSubscriber ts = new TestSubscriber((Long)null); - Observable.just(1).any(new Predicate() { + Flowable.just(1).any(new Predicate() { @Override public boolean test(Integer t) { return true; @@ -258,7 +259,7 @@ public boolean test(Integer t) { @Test public void testBackpressureIfOneRequestedOneShouldBeDelivered() { TestSubscriber ts = new TestSubscriber(1L); - Observable.just(1).any(new Predicate() { + Flowable.just(1).any(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -276,7 +277,7 @@ public void testPredicateThrowsExceptionAndValueInCauseMessage() { TestSubscriber ts = new TestSubscriber(); final IllegalArgumentException ex = new IllegalArgumentException(); - Observable.just("Boo!").any(new Predicate() { + Flowable.just("Boo!").any(new Predicate() { @Override public boolean test(String v) { throw ex; diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorAsObservableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorAsObservableTest.java similarity index 63% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorAsObservableTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorAsObservableTest.java index 98c06894d4..f597135372 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorAsObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorAsObservableTest.java @@ -11,29 +11,31 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertFalse; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; import org.junit.Test; +import org.reactivestreams.Subscriber; -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.flowable.TestHelper; +import io.reactivex.processors.PublishProcessor; +import io.reactivex.subscribers.DefaultObserver; -public class NbpOperatorAsObservableTest { +public class OperatorAsObservableTest { @Test public void testHiding() { - NbpPublishSubject src = NbpPublishSubject.create(); + PublishProcessor src = PublishProcessor.create(); - NbpObservable dst = src.asObservable(); + Flowable dst = src.asObservable(); - assertFalse(dst instanceof NbpPublishSubject); + assertFalse(dst instanceof PublishProcessor); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Subscriber o = TestHelper.mockSubscriber(); dst.subscribe(o); @@ -46,13 +48,14 @@ public void testHiding() { } @Test public void testHidingError() { - NbpPublishSubject src = NbpPublishSubject.create(); + PublishProcessor src = PublishProcessor.create(); - NbpObservable dst = src.asObservable(); + Flowable dst = src.asObservable(); - assertFalse(dst instanceof NbpPublishSubject); + assertFalse(dst instanceof PublishProcessor); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + @SuppressWarnings("unchecked") + DefaultObserver o = mock(DefaultObserver.class); dst.subscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorBufferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorBufferTest.java similarity index 81% rename from src/test/java/io/reactivex/internal/operators/OperatorBufferTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorBufferTest.java index 79cbd9ea14..d7afb682f0 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorBufferTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -26,14 +26,14 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.Observable; -import io.reactivex.Observer; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.*; +import io.reactivex.subscribers.DefaultObserver; public class OperatorBufferTest { @@ -50,9 +50,9 @@ public void before() { @Test public void testComplete() { - Observable source = Observable.empty(); + Flowable source = Flowable.empty(); - Observable> buffered = source.buffer(3, 3); + Flowable> buffered = source.buffer(3, 3); buffered.subscribe(observer); Mockito.verify(observer, Mockito.never()).onNext(Mockito.anyListOf(String.class)); @@ -62,7 +62,7 @@ public void testComplete() { @Test public void testSkipAndCountOverlappingBuffers() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -74,7 +74,7 @@ public void subscribe(Subscriber observer) { } }); - Observable> buffered = source.buffer(3, 1); + Flowable> buffered = source.buffer(3, 1); buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); @@ -88,9 +88,9 @@ public void subscribe(Subscriber observer) { @Test public void testSkipAndCountGaplessBuffers() { - Observable source = Observable.just("one", "two", "three", "four", "five"); + Flowable source = Flowable.just("one", "two", "three", "four", "five"); - Observable> buffered = source.buffer(3, 3); + Flowable> buffered = source.buffer(3, 3); buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); @@ -103,9 +103,9 @@ public void testSkipAndCountGaplessBuffers() { @Test public void testSkipAndCountBuffersWithGaps() { - Observable source = Observable.just("one", "two", "three", "four", "five"); + Flowable source = Flowable.just("one", "two", "three", "four", "five"); - Observable> buffered = source.buffer(2, 3); + Flowable> buffered = source.buffer(2, 3); buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); @@ -118,7 +118,7 @@ public void testSkipAndCountBuffersWithGaps() { @Test public void testTimedAndCount() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -131,7 +131,7 @@ public void subscribe(Subscriber observer) { } }); - Observable> buffered = source.buffer(100, TimeUnit.MILLISECONDS, 2, scheduler); + Flowable> buffered = source.buffer(100, TimeUnit.MILLISECONDS, 2, scheduler); buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); @@ -150,7 +150,7 @@ public void subscribe(Subscriber observer) { @Test public void testTimed() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -168,7 +168,7 @@ public void subscribe(Subscriber observer) { } }); - Observable> buffered = source.buffer(100, TimeUnit.MILLISECONDS, scheduler); + Flowable> buffered = source.buffer(100, TimeUnit.MILLISECONDS, scheduler); buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); @@ -184,7 +184,7 @@ public void subscribe(Subscriber observer) { @Test public void testObservableBasedOpenerAndCloser() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -197,7 +197,7 @@ public void subscribe(Subscriber observer) { } }); - Observable openings = Observable.create(new Publisher() { + Flowable openings = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -207,10 +207,10 @@ public void subscribe(Subscriber observer) { } }); - Function> closer = new Function>() { + Function> closer = new Function>() { @Override - public Observable apply(Object opening) { - return Observable.create(new Publisher() { + public Flowable apply(Object opening) { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -221,7 +221,7 @@ public void subscribe(Subscriber observer) { } }; - Observable> buffered = source.buffer(openings, closer); + Flowable> buffered = source.buffer(openings, closer); buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); @@ -235,7 +235,7 @@ public void subscribe(Subscriber observer) { @Test public void testObservableBasedCloser() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -248,10 +248,10 @@ public void subscribe(Subscriber observer) { } }); - Supplier> closer = new Supplier>() { + Supplier> closer = new Supplier>() { @Override - public Observable get() { - return Observable.create(new Publisher() { + public Flowable get() { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -264,7 +264,7 @@ public void subscribe(Subscriber observer) { } }; - Observable> buffered = source.buffer(closer); + Flowable> buffered = source.buffer(closer); buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); @@ -281,7 +281,7 @@ public void subscribe(Subscriber observer) { public void testLongTimeAction() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); LongTimeAction action = new LongTimeAction(latch); - Observable.just(1).buffer(10, TimeUnit.MILLISECONDS, 10) + Flowable.just(1).buffer(10, TimeUnit.MILLISECONDS, 10) .subscribe(action); latch.await(); assertFalse(action.fail); @@ -339,7 +339,7 @@ public void run() { @Test public void testBufferStopsWhenUnsubscribed1() { - Observable source = Observable.never(); + Flowable source = Flowable.never(); Subscriber> o = TestHelper.mockSubscriber(); TestSubscriber> ts = new TestSubscriber>(o, (Long)null); @@ -368,8 +368,8 @@ public void accept(List pv) { @Test public void bufferWithBONormal1() { - PublishSubject source = PublishSubject.create(); - PublishSubject boundary = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor boundary = PublishProcessor.create(); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = Mockito.inOrder(o); @@ -403,8 +403,8 @@ public void bufferWithBONormal1() { @Test public void bufferWithBOEmptyLastViaBoundary() { - PublishSubject source = PublishSubject.create(); - PublishSubject boundary = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor boundary = PublishProcessor.create(); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = Mockito.inOrder(o); @@ -422,8 +422,8 @@ public void bufferWithBOEmptyLastViaBoundary() { @Test public void bufferWithBOEmptyLastViaSource() { - PublishSubject source = PublishSubject.create(); - PublishSubject boundary = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor boundary = PublishProcessor.create(); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = Mockito.inOrder(o); @@ -441,8 +441,8 @@ public void bufferWithBOEmptyLastViaSource() { @Test public void bufferWithBOEmptyLastViaBoth() { - PublishSubject source = PublishSubject.create(); - PublishSubject boundary = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor boundary = PublishProcessor.create(); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = Mockito.inOrder(o); @@ -461,8 +461,8 @@ public void bufferWithBOEmptyLastViaBoth() { @Test public void bufferWithBOSourceThrows() { - PublishSubject source = PublishSubject.create(); - PublishSubject boundary = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor boundary = PublishProcessor.create(); Subscriber o = TestHelper.mockSubscriber(); @@ -477,8 +477,8 @@ public void bufferWithBOSourceThrows() { @Test public void bufferWithBOBoundaryThrows() { - PublishSubject source = PublishSubject.create(); - PublishSubject boundary = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor boundary = PublishProcessor.create(); Subscriber o = TestHelper.mockSubscriber(); @@ -493,9 +493,9 @@ public void bufferWithBOBoundaryThrows() { } @Test(timeout = 2000) public void bufferWithSizeTake1() { - Observable source = Observable.just(1).repeat(); + Flowable source = Flowable.just(1).repeat(); - Observable> result = source.buffer(2).take(1); + Flowable> result = source.buffer(2).take(1); Subscriber o = TestHelper.mockSubscriber(); @@ -508,9 +508,9 @@ public void bufferWithSizeTake1() { @Test(timeout = 2000) public void bufferWithSizeSkipTake1() { - Observable source = Observable.just(1).repeat(); + Flowable source = Flowable.just(1).repeat(); - Observable> result = source.buffer(2, 3).take(1); + Flowable> result = source.buffer(2, 3).take(1); Subscriber o = TestHelper.mockSubscriber(); @@ -522,9 +522,9 @@ public void bufferWithSizeSkipTake1() { } @Test(timeout = 2000) public void bufferWithTimeTake1() { - Observable source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); + Flowable source = Flowable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); - Observable> result = source.buffer(100, TimeUnit.MILLISECONDS, scheduler).take(1); + Flowable> result = source.buffer(100, TimeUnit.MILLISECONDS, scheduler).take(1); Subscriber o = TestHelper.mockSubscriber(); @@ -538,9 +538,9 @@ public void bufferWithTimeTake1() { } @Test(timeout = 2000) public void bufferWithTimeSkipTake2() { - Observable source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); + Flowable source = Flowable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); - Observable> result = source.buffer(100, 60, TimeUnit.MILLISECONDS, scheduler).take(2); + Flowable> result = source.buffer(100, 60, TimeUnit.MILLISECONDS, scheduler).take(2); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); @@ -556,10 +556,10 @@ public void bufferWithTimeSkipTake2() { } @Test(timeout = 2000) public void bufferWithBoundaryTake2() { - Observable boundary = Observable.interval(60, 60, TimeUnit.MILLISECONDS, scheduler); - Observable source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); + Flowable boundary = Flowable.interval(60, 60, TimeUnit.MILLISECONDS, scheduler); + Flowable source = Flowable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); - Observable> result = source.buffer(boundary).take(2); + Flowable> result = source.buffer(boundary).take(2); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); @@ -577,17 +577,17 @@ public void bufferWithBoundaryTake2() { @Test(timeout = 2000) public void bufferWithStartEndBoundaryTake2() { - Observable start = Observable.interval(61, 61, TimeUnit.MILLISECONDS, scheduler); - Function> end = new Function>() { + Flowable start = Flowable.interval(61, 61, TimeUnit.MILLISECONDS, scheduler); + Function> end = new Function>() { @Override - public Observable apply(Long t1) { - return Observable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler); + public Flowable apply(Long t1) { + return Flowable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler); } }; - Observable source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); + Flowable source = Flowable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); - Observable> result = source.buffer(start, end).take(2); + Flowable> result = source.buffer(start, end).take(2); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); @@ -610,9 +610,9 @@ public void accept(List pv) { } @Test public void bufferWithSizeThrows() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable> result = source.buffer(2); + Flowable> result = source.buffer(2); Subscriber o = TestHelper.mockSubscriber(); @@ -635,9 +635,9 @@ public void bufferWithSizeThrows() { @Test public void bufferWithTimeThrows() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable> result = source.buffer(100, TimeUnit.MILLISECONDS, scheduler); + Flowable> result = source.buffer(100, TimeUnit.MILLISECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); @@ -661,9 +661,9 @@ public void bufferWithTimeThrows() { @Test public void bufferWithTimeAndSize() { - Observable source = Observable.interval(30, 30, TimeUnit.MILLISECONDS, scheduler); + Flowable source = Flowable.interval(30, 30, TimeUnit.MILLISECONDS, scheduler); - Observable> result = source.buffer(100, TimeUnit.MILLISECONDS, 2, scheduler).take(3); + Flowable> result = source.buffer(100, TimeUnit.MILLISECONDS, 2, scheduler).take(3); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); @@ -679,18 +679,18 @@ public void bufferWithTimeAndSize() { } @Test public void bufferWithStartEndStartThrows() { - PublishSubject start = PublishSubject.create(); + PublishProcessor start = PublishProcessor.create(); - Function> end = new Function>() { + Function> end = new Function>() { @Override - public Observable apply(Integer t1) { - return Observable.never(); + public Flowable apply(Integer t1) { + return Flowable.never(); } }; - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable> result = source.buffer(start, end); + Flowable> result = source.buffer(start, end); Subscriber o = TestHelper.mockSubscriber(); @@ -707,18 +707,18 @@ public Observable apply(Integer t1) { } @Test public void bufferWithStartEndEndFunctionThrows() { - PublishSubject start = PublishSubject.create(); + PublishProcessor start = PublishProcessor.create(); - Function> end = new Function>() { + Function> end = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { throw new TestException(); } }; - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable> result = source.buffer(start, end); + Flowable> result = source.buffer(start, end); Subscriber o = TestHelper.mockSubscriber(); @@ -734,18 +734,18 @@ public Observable apply(Integer t1) { } @Test public void bufferWithStartEndEndThrows() { - PublishSubject start = PublishSubject.create(); + PublishProcessor start = PublishProcessor.create(); - Function> end = new Function>() { + Function> end = new Function>() { @Override - public Observable apply(Integer t1) { - return Observable.error(new TestException()); + public Flowable apply(Integer t1) { + return Flowable.error(new TestException()); } }; - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable> result = source.buffer(start, end); + Flowable> result = source.buffer(start, end); Subscriber o = TestHelper.mockSubscriber(); @@ -765,7 +765,7 @@ public void testProducerRequestThroughBufferWithSize1() { TestSubscriber> ts = new TestSubscriber>(3L); final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -796,7 +796,7 @@ public void testProducerRequestThroughBufferWithSize2() { TestSubscriber> ts = new TestSubscriber>(); final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -823,7 +823,7 @@ public void cancel() { public void testProducerRequestThroughBufferWithSize3() { TestSubscriber> ts = new TestSubscriber>(3L); final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -852,7 +852,7 @@ public void cancel() { public void testProducerRequestThroughBufferWithSize4() { TestSubscriber> ts = new TestSubscriber>(); final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -882,7 +882,7 @@ public void testProducerRequestOverflowThroughBufferWithSize1() { final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -911,7 +911,7 @@ public void testProducerRequestOverflowThroughBufferWithSize2() { final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -937,7 +937,7 @@ public void cancel() { @Test public void testProducerRequestOverflowThroughBufferWithSize3() { final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber s) { @@ -961,7 +961,7 @@ public void cancel() { }); } - }).buffer(3, 2).subscribe(new Observer>() { + }).buffer(3, 2).subscribe(new DefaultObserver>() { @Override public void onStart() { @@ -990,7 +990,7 @@ public void testBufferWithTimeDoesntUnsubscribeDownstream() throws InterruptedEx final Subscriber o = TestHelper.mockSubscriber(); final CountDownLatch cdl = new CountDownLatch(1); - AsyncObserver s = new AsyncObserver() { + AsyncSubscriber s = new AsyncSubscriber() { @Override public void onNext(Object t) { o.onNext(t); @@ -1007,7 +1007,7 @@ public void onComplete() { } }; - Observable.range(1, 1).delay(1, TimeUnit.SECONDS).buffer(2, TimeUnit.SECONDS).unsafeSubscribe(s); + Flowable.range(1, 1).delay(1, TimeUnit.SECONDS).buffer(2, TimeUnit.SECONDS).unsafeSubscribe(s); cdl.await(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorCastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorCastTest.java similarity index 80% rename from src/test/java/io/reactivex/internal/operators/OperatorCastTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorCastTest.java index 68f078a71a..4556d3f804 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorCastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorCastTest.java @@ -11,21 +11,22 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Mockito.*; import org.junit.Test; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; public class OperatorCastTest { @Test public void testCast() { - Observable source = Observable.just(1, 2); - Observable observable = source.cast(Integer.class); + Flowable source = Flowable.just(1, 2); + Flowable observable = source.cast(Integer.class); Subscriber observer = TestHelper.mockSubscriber(); @@ -40,8 +41,8 @@ public void testCast() { @Test public void testCastWithWrongType() { - Observable source = Observable.just(1, 2); - Observable observable = source.cast(Boolean.class); + Flowable source = Flowable.just(1, 2); + Flowable observable = source.cast(Boolean.class); Subscriber observer = TestHelper.mockSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorConcatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorConcatTest.java similarity index 83% rename from src/test/java/io/reactivex/internal/operators/OperatorConcatTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorConcatTest.java index 605b872241..e3521f5577 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorConcatTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -26,13 +26,13 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.Observable; -import io.reactivex.Observer; import io.reactivex.disposables.BooleanDisposable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.processors.*; import io.reactivex.schedulers.*; -import io.reactivex.subjects.*; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; public class OperatorConcatTest { @@ -44,10 +44,10 @@ public void testConcat() { final String[] o = { "1", "3", "5", "7" }; final String[] e = { "2", "4", "6" }; - final Observable odds = Observable.fromArray(o); - final Observable even = Observable.fromArray(e); + final Flowable odds = Flowable.fromArray(o); + final Flowable even = Flowable.fromArray(e); - Observable concat = Observable.concat(odds, even); + Flowable concat = Flowable.concat(odds, even); concat.subscribe(observer); verify(observer, times(7)).onNext(anyString()); @@ -60,12 +60,12 @@ public void testConcatWithList() { final String[] o = { "1", "3", "5", "7" }; final String[] e = { "2", "4", "6" }; - final Observable odds = Observable.fromArray(o); - final Observable even = Observable.fromArray(e); - final List> list = new ArrayList>(); + final Flowable odds = Flowable.fromArray(o); + final Flowable even = Flowable.fromArray(e); + final List> list = new ArrayList>(); list.add(odds); list.add(even); - Observable concat = Observable.concat(Observable.fromIterable(list)); + Flowable concat = Flowable.concat(Flowable.fromIterable(list)); concat.subscribe(observer); verify(observer, times(7)).onNext(anyString()); @@ -78,13 +78,13 @@ public void testConcatObservableOfObservables() { final String[] o = { "1", "3", "5", "7" }; final String[] e = { "2", "4", "6" }; - final Observable odds = Observable.fromArray(o); - final Observable even = Observable.fromArray(e); + final Flowable odds = Flowable.fromArray(o); + final Flowable even = Flowable.fromArray(e); - Observable> observableOfObservables = Observable.create(new Publisher>() { + Flowable> observableOfObservables = Flowable.create(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { + public void subscribe(Subscriber> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); // simulate what would happen in an observable observer.onNext(odds); @@ -93,7 +93,7 @@ public void subscribe(Subscriber> observer) { } }); - Observable concat = Observable.concat(observableOfObservables); + Flowable concat = Flowable.concat(observableOfObservables); concat.subscribe(observer); @@ -110,7 +110,7 @@ public void testSimpleAsyncConcat() { TestObservable o1 = new TestObservable("one", "two", "three"); TestObservable o2 = new TestObservable("four", "five", "six"); - Observable.concat(Observable.create(o1), Observable.create(o2)).subscribe(observer); + Flowable.concat(Flowable.create(o1), Flowable.create(o2)).subscribe(observer); try { // wait for async observables to complete @@ -157,10 +157,10 @@ public void testNestedAsyncConcat() throws InterruptedException { final CountDownLatch parentHasFinished = new CountDownLatch(1); - Observable> observableOfObservables = Observable.create(new Publisher>() { + Flowable> observableOfObservables = Flowable.create(new Publisher>() { @Override - public void subscribe(final Subscriber> observer) { + public void subscribe(final Subscriber> observer) { final BooleanDisposable s = new BooleanDisposable(); observer.onSubscribe(new Subscription() { @Override @@ -180,12 +180,12 @@ public void run() { // emit first if (!s.isDisposed()) { System.out.println("Emit o1"); - observer.onNext(Observable.create(o1)); + observer.onNext(Flowable.create(o1)); } // emit second if (!s.isDisposed()) { System.out.println("Emit o2"); - observer.onNext(Observable.create(o2)); + observer.onNext(Flowable.create(o2)); } // wait until sometime later and emit third @@ -196,7 +196,7 @@ public void run() { } if (!s.isDisposed()) { System.out.println("Emit o3"); - observer.onNext(Observable.create(o3)); + observer.onNext(Flowable.create(o3)); } } catch (Throwable e) { @@ -213,7 +213,7 @@ public void run() { } }); - Observable.concat(observableOfObservables).subscribe(observer); + Flowable.concat(observableOfObservables).subscribe(observer); // wait for parent to start parentHasStarted.await(); @@ -276,13 +276,13 @@ public void testBlockedObservableOfObservables() { final String[] o = { "1", "3", "5", "7" }; final String[] e = { "2", "4", "6" }; - final Observable odds = Observable.fromArray(o); - final Observable even = Observable.fromArray(e); + final Flowable odds = Flowable.fromArray(o); + final Flowable even = Flowable.fromArray(e); final CountDownLatch callOnce = new CountDownLatch(1); final CountDownLatch okToContinue = new CountDownLatch(1); @SuppressWarnings("unchecked") - TestObservable> observableOfObservables = new TestObservable>(callOnce, okToContinue, odds, even); - Observable concatF = Observable.concat(Observable.create(observableOfObservables)); + TestObservable> observableOfObservables = new TestObservable>(callOnce, okToContinue, odds, even); + Flowable concatF = Flowable.concat(Flowable.create(observableOfObservables)); concatF.subscribe(observer); try { //Block main thread to allow observables to serve up o1. @@ -320,8 +320,8 @@ public void testConcatConcurrentWithInfinity() { Subscriber observer = TestHelper.mockSubscriber(); @SuppressWarnings("unchecked") - TestObservable> observableOfObservables = new TestObservable>(Observable.create(w1), Observable.create(w2)); - Observable concatF = Observable.concat(Observable.create(observableOfObservables)); + TestObservable> observableOfObservables = new TestObservable>(Flowable.create(w1), Flowable.create(w2)); + Flowable concatF = Flowable.concat(Flowable.create(observableOfObservables)); concatF.take(50).subscribe(observer); @@ -353,19 +353,19 @@ public void testConcatNonBlockingObservables() { Subscriber observer = TestHelper.mockSubscriber(); - Observable> observableOfObservables = Observable.create(new Publisher>() { + Flowable> observableOfObservables = Flowable.create(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { + public void subscribe(Subscriber> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); // simulate what would happen in an observable - observer.onNext(Observable.create(w1)); - observer.onNext(Observable.create(w2)); + observer.onNext(Flowable.create(w1)); + observer.onNext(Flowable.create(w2)); observer.onComplete(); } }); - Observable concat = Observable.concat(observableOfObservables); + Flowable concat = Flowable.concat(observableOfObservables); concat.subscribe(observer); verify(observer, times(0)).onComplete(); @@ -405,7 +405,7 @@ public void testConcatUnsubscribe() { Subscriber observer = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(observer, null); - final Observable concat = Observable.concat(Observable.create(w1), Observable.create(w2)); + final Flowable concat = Flowable.concat(Flowable.create(w1), Flowable.create(w2)); try { // Subscribe @@ -448,8 +448,8 @@ public void testConcatUnsubscribeConcurrent() { TestSubscriber ts = new TestSubscriber(observer, null); @SuppressWarnings("unchecked") - TestObservable> observableOfObservables = new TestObservable>(Observable.create(w1), Observable.create(w2)); - Observable concatF = Observable.concat(Observable.create(observableOfObservables)); + TestObservable> observableOfObservables = new TestObservable>(Flowable.create(w1), Flowable.create(w2)); + Flowable concatF = Flowable.concat(Flowable.create(observableOfObservables)); concatF.subscribe(ts); @@ -570,8 +570,8 @@ public void testMultipleObservers() { TestScheduler s = new TestScheduler(); - Observable timer = Observable.interval(500, TimeUnit.MILLISECONDS, s).take(2); - Observable o = Observable.concat(timer, timer); + Flowable timer = Flowable.interval(500, TimeUnit.MILLISECONDS, s).take(2); + Flowable o = Flowable.concat(timer, timer); o.subscribe(o1); o.subscribe(o2); @@ -609,14 +609,14 @@ public void testMultipleObservers() { @Test public void concatVeryLongObservableOfObservables() { final int n = 10000; - Observable> source = Observable.range(0, n).map(new Function>() { + Flowable> source = Flowable.range(0, n).map(new Function>() { @Override - public Observable apply(Integer v) { - return Observable.just(v); + public Flowable apply(Integer v) { + return Flowable.just(v); } }); - Observable> result = Observable.concat(source).toList(); + Flowable> result = Flowable.concat(source).toList(); Subscriber> o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); @@ -634,14 +634,14 @@ public Observable apply(Integer v) { @Test public void concatVeryLongObservableOfObservablesTakeHalf() { final int n = 10000; - Observable> source = Observable.range(0, n).map(new Function>() { + Flowable> source = Flowable.range(0, n).map(new Function>() { @Override - public Observable apply(Integer v) { - return Observable.just(v); + public Flowable apply(Integer v) { + return Flowable.just(v); } }); - Observable> result = Observable.concat(source).take(n / 2).toList(); + Flowable> result = Flowable.concat(source).take(n / 2).toList(); Subscriber> o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); @@ -660,8 +660,8 @@ public Observable apply(Integer v) { @Test public void testConcatOuterBackpressure() { assertEquals(1, - (int) Observable. empty() - .concatWith(Observable.just(1)) + (int) Flowable. empty() + .concatWith(Flowable.just(1)) .take(1) .toBlocking().single()); } @@ -669,14 +669,14 @@ public void testConcatOuterBackpressure() { @Test public void testInnerBackpressureWithAlignedBoundaries() { TestSubscriber ts = new TestSubscriber(); - Observable.range(0, Observable.bufferSize() * 2) - .concatWith(Observable.range(0, Observable.bufferSize() * 2)) + Flowable.range(0, Flowable.bufferSize() * 2) + .concatWith(Flowable.range(0, Flowable.bufferSize() * 2)) .observeOn(Schedulers.computation()) // observeOn has a backpressured RxRingBuffer .subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 4, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 4, ts.valueCount()); } /* @@ -688,20 +688,20 @@ public void testInnerBackpressureWithAlignedBoundaries() { @Test public void testInnerBackpressureWithoutAlignedBoundaries() { TestSubscriber ts = new TestSubscriber(); - Observable.range(0, (Observable.bufferSize() * 2) + 10) - .concatWith(Observable.range(0, (Observable.bufferSize() * 2) + 10)) + Flowable.range(0, (Flowable.bufferSize() * 2) + 10) + .concatWith(Flowable.range(0, (Flowable.bufferSize() * 2) + 10)) .observeOn(Schedulers.computation()) // observeOn has a backpressured RxRingBuffer .subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals((Observable.bufferSize() * 4) + 20, ts.valueCount()); + assertEquals((Flowable.bufferSize() * 4) + 20, ts.valueCount()); } // https://github.com/ReactiveX/RxJava/issues/1818 @Test public void testConcatWithNonCompliantSourceDoubleOnComplete() { - Observable o = Observable.create(new Publisher() { + Flowable o = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -714,7 +714,7 @@ public void subscribe(Subscriber s) { }); TestSubscriber ts = new TestSubscriber(); - Observable.concat(o, o).subscribe(ts); + Flowable.concat(o, o).subscribe(ts); ts.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); ts.assertTerminated(); ts.assertNoErrors(); @@ -726,13 +726,13 @@ public void testIssue2890NoStackoverflow() throws InterruptedException { final ExecutorService executor = Executors.newFixedThreadPool(2); final Scheduler sch = Schedulers.from(executor); - Function> func = new Function>() { + Function> func = new Function>() { @Override - public Observable apply(Integer t) { - Observable observable = Observable.just(t) + public Flowable apply(Integer t) { + Flowable observable = Flowable.just(t) .subscribeOn(sch) ; - Subject subject = UnicastSubject.create(); + FlowProcessor subject = UnicastProcessor.create(); observable.subscribe(subject); return subject; } @@ -741,7 +741,7 @@ public Observable apply(Integer t) { int n = 5000; final AtomicInteger counter = new AtomicInteger(); - Observable.range(1, n).concatMap(func).subscribe(new Observer() { + Flowable.range(1, n).concatMap(func).subscribe(new DefaultObserver() { @Override public void onNext(Integer t) { // Consume after sleep for 1 ms @@ -774,10 +774,10 @@ public void onError(Throwable e) { @Test public void testRequestOverflowDoesNotStallStream() { - Observable o1 = Observable.just(1,2,3); - Observable o2 = Observable.just(4,5,6); + Flowable o1 = Flowable.just(1,2,3); + Flowable o2 = Flowable.just(4,5,6); final AtomicBoolean completed = new AtomicBoolean(false); - o1.concatWith(o2).subscribe(new Observer() { + o1.concatWith(o2).subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -809,11 +809,11 @@ public void concatMapRangeAsyncLoopIssue2876() { System.out.println("concatMapRangeAsyncLoop > " + i); } TestSubscriber ts = new TestSubscriber(); - Observable.range(0, 1000) - .concatMap(new Function>() { + Flowable.range(0, 1000) + .concatMap(new Function>() { @Override - public Observable apply(Integer t) { - return Observable.fromIterable(Arrays.asList(t)); + public Flowable apply(Integer t) { + return Flowable.fromIterable(Arrays.asList(t)); } }) .observeOn(Schedulers.computation()).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorDebounceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDebounceTest.java similarity index 82% rename from src/test/java/io/reactivex/internal/operators/OperatorDebounceTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorDebounceTest.java index 4491ab8aac..3c857b452e 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDebounceTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -24,10 +24,11 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.TestSubscriber; public class OperatorDebounceTest { @@ -45,7 +46,7 @@ public void before() { @Test public void testDebounceWithCompleted() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -56,7 +57,7 @@ public void subscribe(Subscriber observer) { } }); - Observable sampled = source.debounce(400, TimeUnit.MILLISECONDS, scheduler); + Flowable sampled = source.debounce(400, TimeUnit.MILLISECONDS, scheduler); sampled.subscribe(observer); scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS); @@ -71,7 +72,7 @@ public void subscribe(Subscriber observer) { @Test public void testDebounceNeverEmits() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -88,7 +89,7 @@ public void subscribe(Subscriber observer) { } }); - Observable sampled = source.debounce(200, TimeUnit.MILLISECONDS, scheduler); + Flowable sampled = source.debounce(200, TimeUnit.MILLISECONDS, scheduler); sampled.subscribe(observer); scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS); @@ -101,7 +102,7 @@ public void subscribe(Subscriber observer) { @Test public void testDebounceWithError() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -112,7 +113,7 @@ public void subscribe(Subscriber observer) { } }); - Observable sampled = source.debounce(400, TimeUnit.MILLISECONDS, scheduler); + Flowable sampled = source.debounce(400, TimeUnit.MILLISECONDS, scheduler); sampled.subscribe(observer); scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS); @@ -154,12 +155,12 @@ public void run() { @Test public void debounceSelectorNormal1() { - PublishSubject source = PublishSubject.create(); - final PublishSubject debouncer = PublishSubject.create(); - Function> debounceSel = new Function>() { + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor debouncer = PublishProcessor.create(); + Function> debounceSel = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { return debouncer; } }; @@ -191,11 +192,11 @@ public Observable apply(Integer t1) { @Test public void debounceSelectorFuncThrows() { - PublishSubject source = PublishSubject.create(); - Function> debounceSel = new Function>() { + PublishProcessor source = PublishProcessor.create(); + Function> debounceSel = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { throw new TestException(); } }; @@ -213,12 +214,12 @@ public Observable apply(Integer t1) { @Test public void debounceSelectorObservableThrows() { - PublishSubject source = PublishSubject.create(); - Function> debounceSel = new Function>() { + PublishProcessor source = PublishProcessor.create(); + Function> debounceSel = new Function>() { @Override - public Observable apply(Integer t1) { - return Observable.error(new TestException()); + public Flowable apply(Integer t1) { + return Flowable.error(new TestException()); } }; @@ -234,7 +235,7 @@ public Observable apply(Integer t1) { } @Test public void debounceTimedLastIsNotLost() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); Subscriber o = TestHelper.mockSubscriber(); @@ -251,13 +252,13 @@ public void debounceTimedLastIsNotLost() { } @Test public void debounceSelectorLastIsNotLost() { - PublishSubject source = PublishSubject.create(); - final PublishSubject debouncer = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor debouncer = PublishProcessor.create(); - Function> debounceSel = new Function>() { + Function> debounceSel = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { return debouncer; } }; @@ -280,9 +281,9 @@ public Observable apply(Integer t1) { public void debounceWithTimeBackpressure() throws InterruptedException { TestScheduler scheduler = new TestScheduler(); TestSubscriber subscriber = new TestSubscriber(); - Observable.merge( - Observable.just(1), - Observable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler) + Flowable.merge( + Flowable.just(1), + Flowable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler) ).debounce(20, TimeUnit.MILLISECONDS, scheduler).take(1).subscribe(subscriber); scheduler.advanceTimeBy(30, TimeUnit.MILLISECONDS); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorDefaultIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDefaultIfEmptyTest.java similarity index 82% rename from src/test/java/io/reactivex/internal/operators/OperatorDefaultIfEmptyTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorDefaultIfEmptyTest.java index ad2ccea977..f6209bafb0 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorDefaultIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDefaultIfEmptyTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -19,16 +19,17 @@ import org.junit.*; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.flowable.TestHelper; +import io.reactivex.subscribers.*; public class OperatorDefaultIfEmptyTest { @Test public void testDefaultIfEmpty() { - Observable source = Observable.just(1, 2, 3); - Observable observable = source.defaultIfEmpty(10); + Flowable source = Flowable.just(1, 2, 3); + Flowable observable = source.defaultIfEmpty(10); Subscriber observer = TestHelper.mockSubscriber(); @@ -44,8 +45,8 @@ public void testDefaultIfEmpty() { @Test public void testDefaultIfEmptyWithEmpty() { - Observable source = Observable.empty(); - Observable observable = source.defaultIfEmpty(10); + Flowable source = Flowable.empty(); + Flowable observable = source.defaultIfEmpty(10); Subscriber observer = TestHelper.mockSubscriber(); @@ -61,7 +62,7 @@ public void testDefaultIfEmptyWithEmpty() { public void testEmptyButClientThrows() { final Subscriber o = TestHelper.mockSubscriber(); - Observable.empty().defaultIfEmpty(1).subscribe(new Observer() { + Flowable.empty().defaultIfEmpty(1).subscribe(new DefaultObserver() { @Override public void onNext(Integer t) { throw new TestException(); @@ -86,7 +87,7 @@ public void onComplete() { @Test public void testBackpressureEmpty() { TestSubscriber ts = new TestSubscriber((Long)null); - Observable.empty().defaultIfEmpty(1).subscribe(ts); + Flowable.empty().defaultIfEmpty(1).subscribe(ts); ts.assertNoValues(); ts.assertNotTerminated(); ts.request(1); @@ -98,7 +99,7 @@ public void testBackpressureEmpty() { @Test public void testBackpressureNonEmpty() { TestSubscriber ts = new TestSubscriber((Long)null); - Observable.just(1,2,3).defaultIfEmpty(1).subscribe(ts); + Flowable.just(1,2,3).defaultIfEmpty(1).subscribe(ts); ts.assertNoValues(); ts.assertNotTerminated(); ts.request(2); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorDelayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDelayTest.java similarity index 76% rename from src/test/java/io/reactivex/internal/operators/OperatorDelayTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorDelayTest.java index 30d9668e51..49555db856 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDelayTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.*; @@ -26,11 +26,11 @@ import io.reactivex.*; import io.reactivex.Optional; -import io.reactivex.Observable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; -import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.TestSubscriber; public class OperatorDelayTest { @@ -49,8 +49,8 @@ public void before() { @Test public void testDelay() { - Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); - Observable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); + Flowable source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); + Flowable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); delayed.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -89,8 +89,8 @@ public void testDelay() { @Test public void testLongDelay() { - Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); - Observable delayed = source.delay(5L, TimeUnit.SECONDS, scheduler); + Flowable source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); + Flowable delayed = source.delay(5L, TimeUnit.SECONDS, scheduler); delayed.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -118,7 +118,7 @@ public void testLongDelay() { @Test public void testDelayWithError() { - Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler) + Flowable source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler) .map(new Function() { @Override public Long apply(Long value) { @@ -128,7 +128,7 @@ public Long apply(Long value) { return value; } }); - Observable delayed = source.delay(1L, TimeUnit.SECONDS, scheduler); + Flowable delayed = source.delay(1L, TimeUnit.SECONDS, scheduler); delayed.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -151,8 +151,8 @@ public Long apply(Long value) { @Test public void testDelayWithMultipleSubscriptions() { - Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); - Observable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); + Flowable source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); + Flowable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); delayed.subscribe(observer); delayed.subscribe(observer2); @@ -192,7 +192,7 @@ public void testDelayWithMultipleSubscriptions() { @Test public void testDelaySubscription() { - Observable result = Observable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + Flowable result = Flowable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); @@ -214,7 +214,7 @@ public void testDelaySubscription() { @Test public void testDelaySubscriptionCancelBeforeTime() { - Observable result = Observable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + Flowable result = Flowable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(o); @@ -230,17 +230,17 @@ public void testDelaySubscriptionCancelBeforeTime() { @Test public void testDelayWithObservableNormal1() { - PublishSubject source = PublishSubject.create(); - final List> delays = new ArrayList>(); + PublishProcessor source = PublishProcessor.create(); + final List> delays = new ArrayList>(); final int n = 10; for (int i = 0; i < n; i++) { - PublishSubject delay = PublishSubject.create(); + PublishProcessor delay = PublishProcessor.create(); delays.add(delay); } - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { return delays.get(t1); } }; @@ -265,13 +265,13 @@ public Observable apply(Integer t1) { @Test public void testDelayWithObservableSingleSend1() { - PublishSubject source = PublishSubject.create(); - final PublishSubject delay = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor delay = PublishProcessor.create(); - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { return delay; } }; @@ -291,13 +291,13 @@ public Observable apply(Integer t1) { @Test public void testDelayWithObservableSourceThrows() { - PublishSubject source = PublishSubject.create(); - final PublishSubject delay = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor delay = PublishProcessor.create(); - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { return delay; } }; @@ -317,12 +317,12 @@ public Observable apply(Integer t1) { @Test public void testDelayWithObservableDelayFunctionThrows() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { throw new TestException(); } }; @@ -340,13 +340,13 @@ public Observable apply(Integer t1) { @Test public void testDelayWithObservableDelayThrows() { - PublishSubject source = PublishSubject.create(); - final PublishSubject delay = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor delay = PublishProcessor.create(); - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { return delay; } }; @@ -365,18 +365,18 @@ public Observable apply(Integer t1) { @Test public void testDelayWithObservableSubscriptionNormal() { - PublishSubject source = PublishSubject.create(); - final PublishSubject delay = PublishSubject.create(); - Supplier> subFunc = new Supplier>() { + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor delay = PublishProcessor.create(); + Supplier> subFunc = new Supplier>() { @Override - public Observable get() { + public Flowable get() { return delay; } }; - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { return delay; } }; @@ -400,18 +400,18 @@ public Observable apply(Integer t1) { @Test public void testDelayWithObservableSubscriptionFunctionThrows() { - PublishSubject source = PublishSubject.create(); - final PublishSubject delay = PublishSubject.create(); - Supplier> subFunc = new Supplier>() { + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor delay = PublishProcessor.create(); + Supplier> subFunc = new Supplier>() { @Override - public Observable get() { + public Flowable get() { throw new TestException(); } }; - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { return delay; } }; @@ -434,18 +434,18 @@ public Observable apply(Integer t1) { @Test public void testDelayWithObservableSubscriptionThrows() { - PublishSubject source = PublishSubject.create(); - final PublishSubject delay = PublishSubject.create(); - Supplier> subFunc = new Supplier>() { + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor delay = PublishProcessor.create(); + Supplier> subFunc = new Supplier>() { @Override - public Observable get() { + public Flowable get() { return delay; } }; - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { return delay; } }; @@ -468,13 +468,13 @@ public Observable apply(Integer t1) { @Test public void testDelayWithObservableEmptyDelayer() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public Observable apply(Integer t1) { - return Observable.empty(); + public Flowable apply(Integer t1) { + return Flowable.empty(); } }; Subscriber o = TestHelper.mockSubscriber(); @@ -493,19 +493,19 @@ public Observable apply(Integer t1) { @Test public void testDelayWithObservableSubscriptionRunCompletion() { - PublishSubject source = PublishSubject.create(); - final PublishSubject sdelay = PublishSubject.create(); - final PublishSubject delay = PublishSubject.create(); - Supplier> subFunc = new Supplier>() { + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor sdelay = PublishProcessor.create(); + final PublishProcessor delay = PublishProcessor.create(); + Supplier> subFunc = new Supplier>() { @Override - public Observable get() { + public Flowable get() { return sdelay; } }; - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { return delay; } }; @@ -529,18 +529,18 @@ public Observable apply(Integer t1) { @Test public void testDelayWithObservableAsTimed() { - Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); + Flowable source = Flowable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); - final Observable delayer = Observable.timer(500L, TimeUnit.MILLISECONDS, scheduler); + final Flowable delayer = Flowable.timer(500L, TimeUnit.MILLISECONDS, scheduler); - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public Observable apply(Long t1) { + public Flowable apply(Long t1) { return delayer; } }; - Observable delayed = source.delay(delayFunc); + Flowable delayed = source.delay(delayFunc); delayed.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -581,16 +581,16 @@ public Observable apply(Long t1) { public void testDelayWithObservableReorder() { int n = 3; - PublishSubject source = PublishSubject.create(); - final List> subjects = new ArrayList>(); + PublishProcessor source = PublishProcessor.create(); + final List> subjects = new ArrayList>(); for (int i = 0; i < n; i++) { - subjects.add(PublishSubject. create()); + subjects.add(PublishProcessor. create()); } - Observable result = source.delay(new Function>() { + Flowable result = source.delay(new Function>() { @Override - public Observable apply(Integer t1) { + public Flowable apply(Integer t1) { return subjects.get(t1); } }); @@ -620,8 +620,8 @@ public Observable apply(Integer t1) { @Test public void testDelayEmitsEverything() { - Observable source = Observable.range(1, 5); - Observable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); + Flowable source = Flowable.range(1, 5); + Flowable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); delayed = delayed.doOnEach(new Consumer>>() { @Override @@ -640,7 +640,7 @@ public void accept(Try> t1) { @Test public void testBackpressureWithTimedDelay() { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, Observable.bufferSize() * 2) + Flowable.range(1, Flowable.bufferSize() * 2) .delay(100, TimeUnit.MILLISECONDS) .observeOn(Schedulers.computation()) .map(new Function() { @@ -662,13 +662,13 @@ public Integer apply(Integer t) { ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); } @Test public void testBackpressureWithSubscriptionTimedDelay() { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, Observable.bufferSize() * 2) + Flowable.range(1, Flowable.bufferSize() * 2) .delaySubscription(100, TimeUnit.MILLISECONDS) .delay(100, TimeUnit.MILLISECONDS) .observeOn(Schedulers.computation()) @@ -691,18 +691,18 @@ public Integer apply(Integer t) { ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); } @Test public void testBackpressureWithSelectorDelay() { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, Observable.bufferSize() * 2) - .delay(new Function>() { + Flowable.range(1, Flowable.bufferSize() * 2) + .delay(new Function>() { @Override - public Observable apply(Integer i) { - return Observable.timer(100, TimeUnit.MILLISECONDS); + public Flowable apply(Integer i) { + return Flowable.timer(100, TimeUnit.MILLISECONDS); } }) @@ -726,24 +726,24 @@ public Integer apply(Integer t) { ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); } @Test public void testBackpressureWithSelectorDelayAndSubscriptionDelay() { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, Observable.bufferSize() * 2) - .delay(new Supplier>() { + Flowable.range(1, Flowable.bufferSize() * 2) + .delay(new Supplier>() { @Override - public Observable get() { - return Observable.timer(500, TimeUnit.MILLISECONDS); + public Flowable get() { + return Flowable.timer(500, TimeUnit.MILLISECONDS); } - }, new Function>() { + }, new Function>() { @Override - public Observable apply(Integer i) { - return Observable.timer(100, TimeUnit.MILLISECONDS); + public Flowable apply(Integer i) { + return Flowable.timer(100, TimeUnit.MILLISECONDS); } }) @@ -767,14 +767,14 @@ public Integer apply(Integer t) { ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); } @Test public void testErrorRunsBeforeOnNext() { TestScheduler test = Schedulers.test(); - PublishSubject ps = PublishSubject.create(); + PublishProcessor ps = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber(); @@ -793,9 +793,9 @@ public void testErrorRunsBeforeOnNext() { ts.assertNotComplete(); } public void testDelaySupplierSimple() { - final PublishSubject ps = PublishSubject.create(); + final PublishProcessor ps = PublishProcessor.create(); - Observable source = Observable.range(1, 5); + Flowable source = Flowable.range(1, 5); TestSubscriber ts = new TestSubscriber(); @@ -819,9 +819,9 @@ public Publisher get() { @Test public void testDelaySupplierCompletes() { - final PublishSubject ps = PublishSubject.create(); + final PublishProcessor ps = PublishProcessor.create(); - Observable source = Observable.range(1, 5); + Flowable source = Flowable.range(1, 5); TestSubscriber ts = new TestSubscriber(); @@ -846,9 +846,9 @@ public Publisher get() { @Test public void testDelaySupplierErrors() { - final PublishSubject ps = PublishSubject.create(); + final PublishProcessor ps = PublishProcessor.create(); - Observable source = Observable.range(1, 5); + Flowable source = Flowable.range(1, 5); TestSubscriber ts = new TestSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorDematerializeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDematerializeTest.java similarity index 76% rename from src/test/java/io/reactivex/internal/operators/OperatorDematerializeTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorDematerializeTest.java index 20318e14c8..6b810ac404 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorDematerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDematerializeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -21,14 +21,15 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.subscribers.TestSubscriber; public class OperatorDematerializeTest { @Test public void testDematerialize1() { - Observable>> notifications = Observable.just(1, 2).materialize(); - Observable dematerialize = notifications.dematerialize(); + Flowable>> notifications = Flowable.just(1, 2).materialize(); + Flowable dematerialize = notifications.dematerialize(); Subscriber observer = TestHelper.mockSubscriber(); @@ -43,8 +44,8 @@ public void testDematerialize1() { @Test public void testDematerialize2() { Throwable exception = new Throwable("test"); - Observable observable = Observable.error(exception); - Observable dematerialize = observable.materialize().dematerialize(); + Flowable observable = Flowable.error(exception); + Flowable dematerialize = observable.materialize().dematerialize(); Subscriber observer = TestHelper.mockSubscriber(); @@ -58,8 +59,8 @@ public void testDematerialize2() { @Test public void testDematerialize3() { Exception exception = new Exception("test"); - Observable observable = Observable.error(exception); - Observable dematerialize = observable.materialize().dematerialize(); + Flowable observable = Flowable.error(exception); + Flowable dematerialize = observable.materialize().dematerialize(); Subscriber observer = TestHelper.mockSubscriber(); @@ -73,8 +74,8 @@ public void testDematerialize3() { @Test public void testErrorPassThru() { Exception exception = new Exception("test"); - Observable observable = Observable.error(exception); - Observable dematerialize = observable.dematerialize(); + Flowable observable = Flowable.error(exception); + Flowable dematerialize = observable.dematerialize(); Subscriber observer = TestHelper.mockSubscriber(); @@ -87,8 +88,8 @@ public void testErrorPassThru() { @Test public void testCompletePassThru() { - Observable observable = Observable.empty(); - Observable dematerialize = observable.dematerialize(); + Flowable observable = Flowable.empty(); + Flowable dematerialize = observable.dematerialize(); Subscriber observer = TestHelper.mockSubscriber(); @@ -104,9 +105,9 @@ public void testCompletePassThru() { @Test public void testHonorsContractWhenCompleted() { - Observable source = Observable.just(1); + Flowable source = Flowable.just(1); - Observable result = source.materialize().dematerialize(); + Flowable result = source.materialize().dematerialize(); Subscriber o = TestHelper.mockSubscriber(); @@ -119,9 +120,9 @@ public void testHonorsContractWhenCompleted() { @Test public void testHonorsContractWhenThrows() { - Observable source = Observable.error(new TestException()); + Flowable source = Flowable.error(new TestException()); - Observable result = source.materialize().dematerialize(); + Flowable result = source.materialize().dematerialize(); Subscriber o = TestHelper.mockSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorDistinctTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDistinctTest.java similarity index 87% rename from src/test/java/io/reactivex/internal/operators/OperatorDistinctTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorDistinctTest.java index ac0008a261..e8276af39e 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorDistinctTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDistinctTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -20,7 +20,8 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; public class OperatorDistinctTest { @@ -45,7 +46,7 @@ public void before() { @Test public void testDistinctOfNone() { - Observable src = Observable.empty(); + Flowable src = Flowable.empty(); src.distinct().subscribe(w); verify(w, never()).onNext(anyString()); @@ -55,7 +56,7 @@ public void testDistinctOfNone() { @Test public void testDistinctOfNoneWithKeySelector() { - Observable src = Observable.empty(); + Flowable src = Flowable.empty(); src.distinct(TO_UPPER_WITH_EXCEPTION).subscribe(w); verify(w, never()).onNext(anyString()); @@ -65,7 +66,7 @@ public void testDistinctOfNoneWithKeySelector() { @Test public void testDistinctOfNormalSource() { - Observable src = Observable.just("a", "b", "c", "c", "c", "b", "b", "a", "e"); + Flowable src = Flowable.just("a", "b", "c", "c", "c", "b", "b", "a", "e"); src.distinct().subscribe(w); InOrder inOrder = inOrder(w); @@ -80,7 +81,7 @@ public void testDistinctOfNormalSource() { @Test public void testDistinctOfNormalSourceWithKeySelector() { - Observable src = Observable.just("a", "B", "c", "C", "c", "B", "b", "a", "E"); + Flowable src = Flowable.just("a", "B", "c", "C", "c", "B", "b", "a", "E"); src.distinct(TO_UPPER_WITH_EXCEPTION).subscribe(w); InOrder inOrder = inOrder(w); @@ -96,7 +97,7 @@ public void testDistinctOfNormalSourceWithKeySelector() { @Test @Ignore("Null values no longer allowed") public void testDistinctOfSourceWithNulls() { - Observable src = Observable.just(null, "a", "a", null, null, "b", null); + Flowable src = Flowable.just(null, "a", "a", null, null, "b", null); src.distinct().subscribe(w); InOrder inOrder = inOrder(w); @@ -111,7 +112,7 @@ public void testDistinctOfSourceWithNulls() { @Test @Ignore("Null values no longer allowed") public void testDistinctOfSourceWithExceptionsFromKeySelector() { - Observable src = Observable.just("a", "b", null, "c"); + Flowable src = Flowable.just("a", "b", null, "c"); src.distinct(TO_UPPER_WITH_EXCEPTION).subscribe(w); InOrder inOrder = inOrder(w); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorDistinctUntilChangedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDistinctUntilChangedTest.java similarity index 88% rename from src/test/java/io/reactivex/internal/operators/OperatorDistinctUntilChangedTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorDistinctUntilChangedTest.java index 8e593f7021..bcc97a303e 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorDistinctUntilChangedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDistinctUntilChangedTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -20,7 +20,8 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; public class OperatorDistinctUntilChangedTest { @@ -47,7 +48,7 @@ public void before() { @Test public void testDistinctUntilChangedOfNone() { - Observable src = Observable.empty(); + Flowable src = Flowable.empty(); src.distinctUntilChanged().subscribe(w); verify(w, never()).onNext(anyString()); @@ -57,7 +58,7 @@ public void testDistinctUntilChangedOfNone() { @Test public void testDistinctUntilChangedOfNoneWithKeySelector() { - Observable src = Observable.empty(); + Flowable src = Flowable.empty(); src.distinctUntilChanged(TO_UPPER_WITH_EXCEPTION).subscribe(w); verify(w, never()).onNext(anyString()); @@ -67,7 +68,7 @@ public void testDistinctUntilChangedOfNoneWithKeySelector() { @Test public void testDistinctUntilChangedOfNormalSource() { - Observable src = Observable.just("a", "b", "c", "c", "c", "b", "b", "a", "e"); + Flowable src = Flowable.just("a", "b", "c", "c", "c", "b", "b", "a", "e"); src.distinctUntilChanged().subscribe(w); InOrder inOrder = inOrder(w); @@ -84,7 +85,7 @@ public void testDistinctUntilChangedOfNormalSource() { @Test public void testDistinctUntilChangedOfNormalSourceWithKeySelector() { - Observable src = Observable.just("a", "b", "c", "C", "c", "B", "b", "a", "e"); + Flowable src = Flowable.just("a", "b", "c", "C", "c", "B", "b", "a", "e"); src.distinctUntilChanged(TO_UPPER_WITH_EXCEPTION).subscribe(w); InOrder inOrder = inOrder(w); @@ -102,7 +103,7 @@ public void testDistinctUntilChangedOfNormalSourceWithKeySelector() { @Test @Ignore("Null values no longer allowed") public void testDistinctUntilChangedOfSourceWithNulls() { - Observable src = Observable.just(null, "a", "a", null, null, "b", null, null); + Flowable src = Flowable.just(null, "a", "a", null, null, "b", null, null); src.distinctUntilChanged().subscribe(w); InOrder inOrder = inOrder(w); @@ -119,7 +120,7 @@ public void testDistinctUntilChangedOfSourceWithNulls() { @Test @Ignore("Null values no longer allowed") public void testDistinctUntilChangedOfSourceWithExceptionsFromKeySelector() { - Observable src = Observable.just("a", "b", null, "c"); + Flowable src = Flowable.just("a", "b", null, "c"); src.distinctUntilChanged(TO_UPPER_WITH_EXCEPTION).subscribe(w); InOrder inOrder = inOrder(w); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorDoOnEachTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDoOnEachTest.java similarity index 91% rename from src/test/java/io/reactivex/internal/operators/OperatorDoOnEachTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorDoOnEachTest.java index ce216aad2e..e56b0a0304 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorDoOnEachTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDoOnEachTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -23,7 +23,8 @@ import org.junit.*; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; public class OperatorDoOnEachTest { @@ -39,8 +40,8 @@ public void before() { @Test public void testDoOnEach() { - Observable base = Observable.just("a", "b", "c"); - Observable doOnEach = base.doOnEach(sideEffectObserver); + Flowable base = Flowable.just("a", "b", "c"); + Flowable doOnEach = base.doOnEach(sideEffectObserver); doOnEach.subscribe(subscribedObserver); @@ -61,8 +62,8 @@ public void testDoOnEach() { @Test public void testDoOnEachWithError() { - Observable base = Observable.just("one", "fail", "two", "three", "fail"); - Observable errs = base.map(new Function() { + Flowable base = Flowable.just("one", "fail", "two", "three", "fail"); + Flowable errs = base.map(new Function() { @Override public String apply(String s) { if ("fail".equals(s)) { @@ -72,7 +73,7 @@ public String apply(String s) { } }); - Observable doOnEach = errs.doOnEach(sideEffectObserver); + Flowable doOnEach = errs.doOnEach(sideEffectObserver); doOnEach.subscribe(subscribedObserver); verify(subscribedObserver, times(1)).onNext("one"); @@ -90,8 +91,8 @@ public String apply(String s) { @Test public void testDoOnEachWithErrorInCallback() { - Observable base = Observable.just("one", "two", "fail", "three"); - Observable doOnEach = base.doOnNext(new Consumer() { + Flowable base = Flowable.just("one", "two", "fail", "three"); + Flowable doOnEach = base.doOnNext(new Consumer() { @Override public void accept(String s) { if ("fail".equals(s)) { @@ -115,7 +116,7 @@ public void testIssue1451Case1() { final int expectedCount = 3; final AtomicInteger count = new AtomicInteger(); for (int i=0; i < expectedCount; i++) { - Observable + Flowable .just(Boolean.TRUE, Boolean.FALSE) .takeWhile(new Predicate() { @Override @@ -141,7 +142,7 @@ public void testIssue1451Case2() { final int expectedCount = 3; final AtomicInteger count = new AtomicInteger(); for (int i=0; i < expectedCount; i++) { - Observable + Flowable .just(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE) .takeWhile(new Predicate() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/OperatorDoOnRequestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDoOnRequestTest.java similarity index 90% rename from src/test/java/io/reactivex/internal/operators/OperatorDoOnRequestTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorDoOnRequestTest.java index f1e15aaa8c..bae74d97e1 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorDoOnRequestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDoOnRequestTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; @@ -20,16 +20,16 @@ import org.junit.Test; -import io.reactivex.Observable; -import io.reactivex.Observer; +import io.reactivex.Flowable; import io.reactivex.functions.LongConsumer; +import io.reactivex.subscribers.DefaultObserver; public class OperatorDoOnRequestTest { @Test public void testUnsubscribeHappensAgainstParent() { final AtomicBoolean unsubscribed = new AtomicBoolean(false); - Observable.just(1) + Flowable.just(1) // .doOnCancel(new Runnable() { @Override @@ -52,7 +52,7 @@ public void accept(long n) { @Test public void testDoRequest() { final List requests = new ArrayList(); - Observable.range(1, 5) + Flowable.range(1, 5) // .doOnRequest(new LongConsumer() { @Override @@ -61,7 +61,7 @@ public void accept(long n) { } }) // - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onStart() { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorDoOnSubscribeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDoOnSubscribeTest.java similarity index 90% rename from src/test/java/io/reactivex/internal/operators/OperatorDoOnSubscribeTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorDoOnSubscribeTest.java index 1b839990ca..a09b6c6dd4 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorDoOnSubscribeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDoOnSubscribeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; @@ -20,7 +20,7 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.functions.Consumer; import io.reactivex.internal.subscriptions.EmptySubscription; @@ -29,7 +29,7 @@ public class OperatorDoOnSubscribeTest { @Test public void testDoOnSubscribe() throws Exception { final AtomicInteger count = new AtomicInteger(); - Observable o = Observable.just(1).doOnSubscribe(new Consumer() { + Flowable o = Flowable.just(1).doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { count.incrementAndGet(); @@ -45,7 +45,7 @@ public void accept(Subscription s) { @Test public void testDoOnSubscribe2() throws Exception { final AtomicInteger count = new AtomicInteger(); - Observable o = Observable.just(1).doOnSubscribe(new Consumer() { + Flowable o = Flowable.just(1).doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { count.incrementAndGet(); @@ -67,7 +67,7 @@ public void testDoOnUnSubscribeWorksWithRefCount() throws Exception { final AtomicInteger countBefore = new AtomicInteger(); final AtomicInteger countAfter = new AtomicInteger(); final AtomicReference> sref = new AtomicReference>(); - Observable o = Observable.create(new Publisher() { + Flowable o = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorDoOnUnsubscribeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDoOnUnsubscribeTest.java similarity index 97% rename from src/test/java/io/reactivex/internal/operators/OperatorDoOnUnsubscribeTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorDoOnUnsubscribeTest.java index 5437287a72..09f2984122 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorDoOnUnsubscribeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorDoOnUnsubscribeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; @@ -21,7 +21,7 @@ import org.junit.Test; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.subscribers.TestSubscriber; @@ -37,7 +37,7 @@ public void testDoOnUnsubscribe() throws Exception { final AtomicInteger upperCount = new AtomicInteger(); final AtomicInteger lowerCount = new AtomicInteger(); - Observable longs = Observable + Flowable longs = Flowable // The stream needs to be infinite to ensure the stream does not terminate // before it is unsubscribed .interval(50, TimeUnit.MILLISECONDS) @@ -99,7 +99,7 @@ public void testDoOnUnSubscribeWorksWithRefCount() throws Exception { final AtomicInteger upperCount = new AtomicInteger(); final AtomicInteger lowerCount = new AtomicInteger(); - Observable longs = Observable + Flowable longs = Flowable // The stream needs to be infinite to ensure the stream does not terminate // before it is unsubscribed .interval(50, TimeUnit.MILLISECONDS) diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorElementAtTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorElementAtTest.java similarity index 70% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorElementAtTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorElementAtTest.java index 5db709e74a..6940311220 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorElementAtTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorElementAtTest.java @@ -11,46 +11,46 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import org.junit.Test; -import io.reactivex.NbpObservable; +import io.reactivex.Flowable; -public class NbpOperatorElementAtTest { +public class OperatorElementAtTest { @Test public void testElementAt() { - assertEquals(2, NbpObservable.fromArray(1, 2).elementAt(1).toBlocking().single() + assertEquals(2, Flowable.fromArray(1, 2).elementAt(1).toBlocking().single() .intValue()); } @Test(expected = IndexOutOfBoundsException.class) public void testElementAtWithMinusIndex() { - NbpObservable.fromArray(1, 2).elementAt(-1); + Flowable.fromArray(1, 2).elementAt(-1); } @Test(expected = IndexOutOfBoundsException.class) public void testElementAtWithIndexOutOfBounds() { - NbpObservable.fromArray(1, 2).elementAt(2).toBlocking().single(); + Flowable.fromArray(1, 2).elementAt(2).toBlocking().single(); } @Test public void testElementAtOrDefault() { - assertEquals(2, NbpObservable.fromArray(1, 2).elementAt(1, 0).toBlocking() + assertEquals(2, Flowable.fromArray(1, 2).elementAt(1, 0).toBlocking() .single().intValue()); } @Test public void testElementAtOrDefaultWithIndexOutOfBounds() { - assertEquals(0, NbpObservable.fromArray(1, 2).elementAt(2, 0).toBlocking() + assertEquals(0, Flowable.fromArray(1, 2).elementAt(2, 0).toBlocking() .single().intValue()); } @Test(expected = IndexOutOfBoundsException.class) public void testElementAtOrDefaultWithMinusIndex() { - NbpObservable.fromArray(1, 2).elementAt(-1, 0); + Flowable.fromArray(1, 2).elementAt(-1, 0); } } \ No newline at end of file diff --git a/src/test/java/io/reactivex/internal/operators/OperatorFilterTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorFilterTest.java similarity index 90% rename from src/test/java/io/reactivex/internal/operators/OperatorFilterTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorFilterTest.java index 397b5f2909..1f8a8da3be 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorFilterTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorFilterTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,7 +22,8 @@ import org.mockito.Mockito; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Predicate; import io.reactivex.subscribers.TestSubscriber; @@ -30,8 +31,8 @@ public class OperatorFilterTest { @Test public void testFilter() { - Observable w = Observable.just("one", "two", "three"); - Observable observable = w.filter(new Predicate() { + Flowable w = Flowable.just("one", "two", "three"); + Flowable observable = w.filter(new Predicate() { @Override public boolean test(String t1) { @@ -57,8 +58,8 @@ public boolean test(String t1) { */ @Test(timeout = 500) public void testWithBackpressure() throws InterruptedException { - Observable w = Observable.just("one", "two", "three"); - Observable o = w.filter(new Predicate() { + Flowable w = Flowable.just("one", "two", "three"); + Flowable o = w.filter(new Predicate() { @Override public boolean test(String t1) { @@ -104,8 +105,8 @@ public void onNext(String t) { */ @Test(timeout = 500000) public void testWithBackpressure2() throws InterruptedException { - Observable w = Observable.range(1, Observable.bufferSize() * 2); - Observable o = w.filter(new Predicate() { + Flowable w = Flowable.range(1, Flowable.bufferSize() * 2); + Flowable o = w.filter(new Predicate() { @Override public boolean test(Integer t1) { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorFinallyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorFinallyTest.java similarity index 78% rename from src/test/java/io/reactivex/internal/operators/OperatorFinallyTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorFinallyTest.java index 08c6e449e0..ebb60838cc 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorFinallyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorFinallyTest.java @@ -11,14 +11,15 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Mockito.*; import org.junit.*; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; public class OperatorFinallyTest { @@ -32,18 +33,18 @@ public void before() { observer = TestHelper.mockSubscriber(); } - private void checkActionCalled(Observable input) { + private void checkActionCalled(Flowable input) { input.finallyDo(aAction0).subscribe(observer); verify(aAction0, times(1)).run(); } @Test public void testFinallyCalledOnComplete() { - checkActionCalled(Observable.fromArray("1", "2", "3")); + checkActionCalled(Flowable.fromArray("1", "2", "3")); } @Test public void testFinallyCalledOnError() { - checkActionCalled(Observable. error(new RuntimeException("expected"))); + checkActionCalled(Flowable. error(new RuntimeException("expected"))); } } \ No newline at end of file diff --git a/src/test/java/io/reactivex/internal/operators/OperatorFirstTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorFirstTest.java similarity index 88% rename from src/test/java/io/reactivex/internal/operators/OperatorFirstTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorFirstTest.java index 210923d73f..0d52e1b551 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorFirstTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorFirstTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -22,7 +22,8 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Predicate; public class OperatorFirstTest { @@ -43,7 +44,7 @@ public void before() { @Test public void testFirstOrElseOfNone() { - Observable src = Observable.empty(); + Flowable src = Flowable.empty(); src.first("default").subscribe(w); verify(w, times(1)).onNext(anyString()); @@ -54,7 +55,7 @@ public void testFirstOrElseOfNone() { @Test public void testFirstOrElseOfSome() { - Observable src = Observable.just("a", "b", "c"); + Flowable src = Flowable.just("a", "b", "c"); src.first("default").subscribe(w); verify(w, times(1)).onNext(anyString()); @@ -65,7 +66,7 @@ public void testFirstOrElseOfSome() { @Test public void testFirstOrElseWithPredicateOfNoneMatchingThePredicate() { - Observable src = Observable.just("a", "b", "c"); + Flowable src = Flowable.just("a", "b", "c"); src.filter(IS_D).first("default").subscribe(w); verify(w, times(1)).onNext(anyString()); @@ -76,7 +77,7 @@ public void testFirstOrElseWithPredicateOfNoneMatchingThePredicate() { @Test public void testFirstOrElseWithPredicateOfSome() { - Observable src = Observable.just("a", "b", "c", "d", "e", "f"); + Flowable src = Flowable.just("a", "b", "c", "d", "e", "f"); src.filter(IS_D).first("default").subscribe(w); verify(w, times(1)).onNext(anyString()); @@ -87,7 +88,7 @@ public void testFirstOrElseWithPredicateOfSome() { @Test public void testFirst() { - Observable observable = Observable.just(1, 2, 3).first(); + Flowable observable = Flowable.just(1, 2, 3).first(); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -100,7 +101,7 @@ public void testFirst() { @Test public void testFirstWithOneElement() { - Observable observable = Observable.just(1).first(); + Flowable observable = Flowable.just(1).first(); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -113,7 +114,7 @@ public void testFirstWithOneElement() { @Test public void testFirstWithEmpty() { - Observable observable = Observable. empty().first(); + Flowable observable = Flowable. empty().first(); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -126,7 +127,7 @@ public void testFirstWithEmpty() { @Test public void testFirstWithPredicate() { - Observable observable = Observable.just(1, 2, 3, 4, 5, 6) + Flowable observable = Flowable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -146,7 +147,7 @@ public boolean test(Integer t1) { @Test public void testFirstWithPredicateAndOneElement() { - Observable observable = Observable.just(1, 2) + Flowable observable = Flowable.just(1, 2) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -166,7 +167,7 @@ public boolean test(Integer t1) { @Test public void testFirstWithPredicateAndEmpty() { - Observable observable = Observable.just(1) + Flowable observable = Flowable.just(1) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -186,7 +187,7 @@ public boolean test(Integer t1) { @Test public void testFirstOrDefault() { - Observable observable = Observable.just(1, 2, 3) + Flowable observable = Flowable.just(1, 2, 3) .first(4); Subscriber observer = TestHelper.mockSubscriber(); @@ -200,7 +201,7 @@ public void testFirstOrDefault() { @Test public void testFirstOrDefaultWithOneElement() { - Observable observable = Observable.just(1).first(2); + Flowable observable = Flowable.just(1).first(2); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -213,7 +214,7 @@ public void testFirstOrDefaultWithOneElement() { @Test public void testFirstOrDefaultWithEmpty() { - Observable observable = Observable. empty() + Flowable observable = Flowable. empty() .first(1); Subscriber observer = TestHelper.mockSubscriber(); @@ -227,7 +228,7 @@ public void testFirstOrDefaultWithEmpty() { @Test public void testFirstOrDefaultWithPredicate() { - Observable observable = Observable.just(1, 2, 3, 4, 5, 6) + Flowable observable = Flowable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -247,7 +248,7 @@ public boolean test(Integer t1) { @Test public void testFirstOrDefaultWithPredicateAndOneElement() { - Observable observable = Observable.just(1, 2) + Flowable observable = Flowable.just(1, 2) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -267,7 +268,7 @@ public boolean test(Integer t1) { @Test public void testFirstOrDefaultWithPredicateAndEmpty() { - Observable observable = Observable.just(1) + Flowable observable = Flowable.just(1) .filter(new Predicate() { @Override public boolean test(Integer t1) { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorFlatMapTest.java similarity index 75% rename from src/test/java/io/reactivex/internal/operators/OperatorFlatMapTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorFlatMapTest.java index 08044c702c..9323ebc2bf 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorFlatMapTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -24,9 +24,9 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.Observable; -import io.reactivex.TestHelper; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; @@ -54,7 +54,7 @@ public Integer apply(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - Observable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); + Flowable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); for (Integer s : source) { for (Integer v : list) { @@ -85,7 +85,7 @@ public Integer apply(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - Observable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); + Flowable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); verify(o, never()).onComplete(); verify(o, never()).onNext(any()); @@ -114,7 +114,7 @@ public Integer apply(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - Observable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); + Flowable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); verify(o, never()).onComplete(); verify(o, never()).onNext(any()); @@ -125,10 +125,10 @@ public Integer apply(Integer t1, Integer t2) { public void testMergeError() { Subscriber o = TestHelper.mockSubscriber(); - Function> func = new Function>() { + Function> func = new Function>() { @Override - public Observable apply(Integer t1) { - return Observable.error(new TestException()); + public Flowable apply(Integer t1) { + return Flowable.error(new TestException()); } }; BiFunction resFunc = new BiFunction() { @@ -141,7 +141,7 @@ public Integer apply(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - Observable.fromIterable(source).flatMap(func, resFunc).subscribe(o); + Flowable.fromIterable(source).flatMap(func, resFunc).subscribe(o); verify(o, never()).onComplete(); verify(o, never()).onNext(any()); @@ -170,11 +170,11 @@ public R get() { @Test public void testFlatMapTransformsNormal() { - Observable onNext = Observable.fromIterable(Arrays.asList(1, 2, 3)); - Observable onCompleted = Observable.fromIterable(Arrays.asList(4)); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Flowable onNext = Flowable.fromIterable(Arrays.asList(1, 2, 3)); + Flowable onCompleted = Flowable.fromIterable(Arrays.asList(4)); + Flowable onError = Flowable.fromIterable(Arrays.asList(5)); - Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); + Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); Subscriber o = TestHelper.mockSubscriber(); @@ -192,13 +192,13 @@ public void testFlatMapTransformsNormal() { @Test public void testFlatMapTransformsException() { - Observable onNext = Observable.fromIterable(Arrays.asList(1, 2, 3)); - Observable onCompleted = Observable.fromIterable(Arrays.asList(4)); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Flowable onNext = Flowable.fromIterable(Arrays.asList(1, 2, 3)); + Flowable onCompleted = Flowable.fromIterable(Arrays.asList(4)); + Flowable onError = Flowable.fromIterable(Arrays.asList(5)); - Observable source = Observable.concat( - Observable.fromIterable(Arrays.asList(10, 20, 30)), - Observable. error(new RuntimeException("Forced failure!")) + Flowable source = Flowable.concat( + Flowable.fromIterable(Arrays.asList(10, 20, 30)), + Flowable. error(new RuntimeException("Forced failure!")) ); @@ -236,10 +236,10 @@ public R apply(T t) { @Test public void testFlatMapTransformsOnNextFuncThrows() { - Observable onCompleted = Observable.fromIterable(Arrays.asList(4)); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Flowable onCompleted = Flowable.fromIterable(Arrays.asList(4)); + Flowable onError = Flowable.fromIterable(Arrays.asList(5)); - Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); + Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); Subscriber o = TestHelper.mockSubscriber(); @@ -252,11 +252,11 @@ public void testFlatMapTransformsOnNextFuncThrows() { @Test public void testFlatMapTransformsOnErrorFuncThrows() { - Observable onNext = Observable.fromIterable(Arrays.asList(1, 2, 3)); - Observable onCompleted = Observable.fromIterable(Arrays.asList(4)); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Flowable onNext = Flowable.fromIterable(Arrays.asList(1, 2, 3)); + Flowable onCompleted = Flowable.fromIterable(Arrays.asList(4)); + Flowable onError = Flowable.fromIterable(Arrays.asList(5)); - Observable source = Observable.error(new TestException()); + Flowable source = Flowable.error(new TestException()); Subscriber o = TestHelper.mockSubscriber(); @@ -269,11 +269,11 @@ public void testFlatMapTransformsOnErrorFuncThrows() { @Test public void testFlatMapTransformsOnCompletedFuncThrows() { - Observable onNext = Observable.fromIterable(Arrays.asList(1, 2, 3)); - Observable onCompleted = Observable.fromIterable(Arrays.asList(4)); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Flowable onNext = Flowable.fromIterable(Arrays.asList(1, 2, 3)); + Flowable onCompleted = Flowable.fromIterable(Arrays.asList(4)); + Flowable onError = Flowable.fromIterable(Arrays.asList(5)); - Observable source = Observable.fromIterable(Arrays. asList()); + Flowable source = Flowable.fromIterable(Arrays. asList()); Subscriber o = TestHelper.mockSubscriber(); @@ -286,11 +286,11 @@ public void testFlatMapTransformsOnCompletedFuncThrows() { @Test public void testFlatMapTransformsMergeException() { - Observable onNext = Observable.error(new TestException()); - Observable onCompleted = Observable.fromIterable(Arrays.asList(4)); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Flowable onNext = Flowable.error(new TestException()); + Flowable onCompleted = Flowable.fromIterable(Arrays.asList(4)); + Flowable onError = Flowable.fromIterable(Arrays.asList(5)); - Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); + Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); Subscriber o = TestHelper.mockSubscriber(); @@ -301,7 +301,7 @@ public void testFlatMapTransformsMergeException() { verify(o, never()).onComplete(); } - private static Observable composer(Observable source, final AtomicInteger subscriptionCount, final int m) { + private static Flowable composer(Flowable source, final AtomicInteger subscriptionCount, final int m) { return source.doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -325,11 +325,11 @@ public void run() { public void testFlatMapMaxConcurrent() { final int m = 4; final AtomicInteger subscriptionCount = new AtomicInteger(); - Observable source = Observable.range(1, 10) - .flatMap(new Function>() { + Flowable source = Flowable.range(1, 10) + .flatMap(new Function>() { @Override - public Observable apply(Integer t1) { - return composer(Observable.range(t1 * 10, 2), subscriptionCount, m) + public Flowable apply(Integer t1) { + return composer(Flowable.range(t1 * 10, 2), subscriptionCount, m) .subscribeOn(Schedulers.computation()); } }, m); @@ -350,11 +350,11 @@ public Observable apply(Integer t1) { public void testFlatMapSelectorMaxConcurrent() { final int m = 4; final AtomicInteger subscriptionCount = new AtomicInteger(); - Observable source = Observable.range(1, 10) - .flatMap(new Function>() { + Flowable source = Flowable.range(1, 10) + .flatMap(new Function>() { @Override - public Observable apply(Integer t1) { - return composer(Observable.range(t1 * 10, 2), subscriptionCount, m) + public Flowable apply(Integer t1) { + return composer(Flowable.range(t1 * 10, 2), subscriptionCount, m) .subscribeOn(Schedulers.computation()); } }, new BiFunction() { @@ -393,28 +393,28 @@ public void testFlatMapTransformsMaxConcurrentNormalLoop() { public void testFlatMapTransformsMaxConcurrentNormal() { final int m = 2; final AtomicInteger subscriptionCount = new AtomicInteger(); - Observable onNext = + Flowable onNext = composer( - Observable.fromIterable(Arrays.asList(1, 2, 3)) + Flowable.fromIterable(Arrays.asList(1, 2, 3)) .observeOn(Schedulers.computation()) , subscriptionCount, m) .subscribeOn(Schedulers.computation()) ; - Observable onCompleted = composer(Observable.fromIterable(Arrays.asList(4)), subscriptionCount, m) + Flowable onCompleted = composer(Flowable.fromIterable(Arrays.asList(4)), subscriptionCount, m) .subscribeOn(Schedulers.computation()); - Observable onError = Observable.fromIterable(Arrays.asList(5)); + Flowable onError = Flowable.fromIterable(Arrays.asList(5)); - Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); + Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); Subscriber o = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(o); - Function> just = just(onNext); - Function> just2 = just(onError); - Supplier> just0 = just0(onCompleted); + Function> just = just(onNext); + Function> just2 = just(onError); + Supplier> just0 = just0(onCompleted); source.flatMap(just, just2, just0, m).subscribe(ts); ts.awaitTerminalEvent(1, TimeUnit.SECONDS); @@ -439,11 +439,11 @@ public void flatMapRangeAsyncLoop() { System.out.println("flatMapRangeAsyncLoop > " + i); } TestSubscriber ts = new TestSubscriber(); - Observable.range(0, 1000) - .flatMap(new Function>() { + Flowable.range(0, 1000) + .flatMap(new Function>() { @Override - public Observable apply(Integer t) { - return Observable.just(t); + public Flowable apply(Integer t) { + return Flowable.just(t); } }) .observeOn(Schedulers.computation()) @@ -476,12 +476,12 @@ public void flatMapRangeMixedAsyncLoop() { System.out.println("flatMapRangeAsyncLoop > " + i); } TestSubscriber ts = new TestSubscriber(); - Observable.range(0, 1000) - .flatMap(new Function>() { + Flowable.range(0, 1000) + .flatMap(new Function>() { final Random rnd = new Random(); @Override - public Observable apply(Integer t) { - Observable r = Observable.just(t); + public Flowable apply(Integer t) { + Flowable r = Flowable.just(t); if (rnd.nextBoolean()) { r = r.asObservable(); } @@ -515,10 +515,10 @@ public void flatMapIntPassthruAsync() { for (int i = 0;i < 1000; i++) { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, 1000).flatMap(new Function>() { + Flowable.range(1, 1000).flatMap(new Function>() { @Override - public Observable apply(Integer t) { - return Observable.just(1).subscribeOn(Schedulers.computation()); + public Flowable apply(Integer t) { + return Flowable.just(1).subscribeOn(Schedulers.computation()); } }).subscribe(ts); @@ -533,10 +533,10 @@ public void flatMapTwoNestedSync() { for (final int n : new int[] { 1, 1000, 1000000 }) { TestSubscriber ts = new TestSubscriber(); - Observable.just(1, 2).flatMap(new Function>() { + Flowable.just(1, 2).flatMap(new Function>() { @Override - public Observable apply(Integer t) { - return Observable.range(1, n); + public Flowable apply(Integer t) { + return Flowable.range(1, n); } }).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorGroupByTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorGroupByTest.java similarity index 83% rename from src/test/java/io/reactivex/internal/operators/OperatorGroupByTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorGroupByTest.java index 63d2b6dd15..a405ec369b 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorGroupByTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,15 +25,14 @@ import org.mockito.Matchers; import org.reactivestreams.*; -import io.reactivex.Optional; -import io.reactivex.Observable; -import io.reactivex.Observer; import io.reactivex.*; +import io.reactivex.Optional; import io.reactivex.exceptions.TestException; +import io.reactivex.flowables.GroupedFlowable; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.*; -import io.reactivex.observables.GroupedObservable; import io.reactivex.schedulers.Schedulers; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; public class OperatorGroupByTest { @@ -47,8 +46,8 @@ public Integer apply(String s) { @Test public void testGroupBy() { - Observable source = Observable.just("one", "two", "three", "four", "five", "six"); - Observable> grouped = source.groupBy(length); + Flowable source = Flowable.just("one", "two", "three", "four", "five", "six"); + Flowable> grouped = source.groupBy(length); Map> map = toMap(grouped); @@ -60,8 +59,8 @@ public void testGroupBy() { @Test public void testGroupByWithElementSelector() { - Observable source = Observable.just("one", "two", "three", "four", "five", "six"); - Observable> grouped = source.groupBy(length, length); + Flowable source = Flowable.just("one", "two", "three", "four", "five", "six"); + Flowable> grouped = source.groupBy(length, length); Map> map = toMap(grouped); @@ -73,8 +72,8 @@ public void testGroupByWithElementSelector() { @Test public void testGroupByWithElementSelector2() { - Observable source = Observable.just("one", "two", "three", "four", "five", "six"); - Observable> grouped = source.groupBy(length, length); + Flowable source = Flowable.just("one", "two", "three", "four", "five", "six"); + Flowable> grouped = source.groupBy(length, length); Map> map = toMap(grouped); @@ -86,8 +85,8 @@ public void testGroupByWithElementSelector2() { @Test public void testEmpty() { - Observable source = Observable.empty(); - Observable> grouped = source.groupBy(length); + Flowable source = Flowable.empty(); + Flowable> grouped = source.groupBy(length); Map> map = toMap(grouped); @@ -96,20 +95,20 @@ public void testEmpty() { @Test public void testError() { - Observable sourceStrings = Observable.just("one", "two", "three", "four", "five", "six"); - Observable errorSource = Observable.error(new RuntimeException("forced failure")); - Observable source = Observable.concat(sourceStrings, errorSource); + Flowable sourceStrings = Flowable.just("one", "two", "three", "four", "five", "six"); + Flowable errorSource = Flowable.error(new RuntimeException("forced failure")); + Flowable source = Flowable.concat(sourceStrings, errorSource); - Observable> grouped = source.groupBy(length); + Flowable> grouped = source.groupBy(length); final AtomicInteger groupCounter = new AtomicInteger(); final AtomicInteger eventCounter = new AtomicInteger(); final AtomicReference error = new AtomicReference(); - grouped.flatMap(new Function, Observable>() { + grouped.flatMap(new Function, Flowable>() { @Override - public Observable apply(final GroupedObservable o) { + public Flowable apply(final GroupedFlowable o) { groupCounter.incrementAndGet(); return o.map(new Function() { @@ -119,7 +118,7 @@ public String apply(String v) { } }); } - }).subscribe(new Observer() { + }).subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -145,14 +144,14 @@ public void onNext(String v) { assertNotNull(error.get()); } - private static Map> toMap(Observable> observable) { + private static Map> toMap(Flowable> observable) { final ConcurrentHashMap> result = new ConcurrentHashMap>(); - observable.toBlocking().forEach(new Consumer>() { + observable.toBlocking().forEach(new Consumer>() { @Override - public void accept(final GroupedObservable o) { + public void accept(final GroupedFlowable o) { result.put(o.getKey(), new ConcurrentLinkedQueue()); o.subscribe(new Consumer() { @@ -183,7 +182,7 @@ public void testGroupedEventStream() throws Throwable { final int count = 100; final int groupCount = 2; - Observable es = Observable.create(new Publisher() { + Flowable es = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { @@ -214,10 +213,10 @@ public void run() { public Integer apply(Event e) { return e.source; } - }).flatMap(new Function, Observable>() { + }).flatMap(new Function, Flowable>() { @Override - public Observable apply(GroupedObservable eventGroupedObservable) { + public Flowable apply(GroupedFlowable eventGroupedObservable) { System.out.println("GroupedObservable Key: " + eventGroupedObservable.getKey()); groupCounter.incrementAndGet(); @@ -230,7 +229,7 @@ public String apply(Event event) { }); } - }).subscribe(new Observer() { + }).subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -281,7 +280,7 @@ public void testUnsubscribeOnNestedTakeAndAsyncInfiniteStream() throws Interrupt assertEquals(39, sentEventCounter.get()); } - private void doTestUnsubscribeOnNestedTakeAndAsyncInfiniteStream(Observable es, AtomicInteger subscribeCounter) throws InterruptedException { + private void doTestUnsubscribeOnNestedTakeAndAsyncInfiniteStream(Flowable es, AtomicInteger subscribeCounter) throws InterruptedException { final AtomicInteger eventCounter = new AtomicInteger(); final AtomicInteger groupCounter = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(1); @@ -294,10 +293,10 @@ public Integer apply(Event e) { } }) .take(1) // we want only the first group - .flatMap(new Function, Observable>() { + .flatMap(new Function, Flowable>() { @Override - public Observable apply(GroupedObservable eventGroupedObservable) { + public Flowable apply(GroupedFlowable eventGroupedObservable) { System.out.println("testUnsubscribe => GroupedObservable Key: " + eventGroupedObservable.getKey()); groupCounter.incrementAndGet(); @@ -312,7 +311,7 @@ public String apply(Event event) { }); } - }).subscribe(new Observer() { + }).subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -359,10 +358,10 @@ public Integer apply(Event e) { }) // take 2 of the 4 groups .take(2) - .flatMap(new Function, Observable>() { + .flatMap(new Function, Flowable>() { @Override - public Observable apply(GroupedObservable eventGroupedObservable) { + public Flowable apply(GroupedFlowable eventGroupedObservable) { return eventGroupedObservable .map(new Function() { @@ -405,10 +404,10 @@ public Integer apply(Event e) { }) // take 2 of the 4 groups .take(2) - .flatMap(new Function, Observable>() { + .flatMap(new Function, Flowable>() { @Override - public Observable apply(GroupedObservable eventGroupedObservable) { + public Flowable apply(GroupedFlowable eventGroupedObservable) { int numToTake = 0; if (eventGroupedObservable.getKey() == 1) { numToTake = 10; @@ -446,7 +445,7 @@ public void accept(String s) { public void testStaggeredCompletion() throws InterruptedException { final AtomicInteger eventCounter = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(1); - Observable.range(0, 100) + Flowable.range(0, 100) .groupBy(new Function() { @Override @@ -454,10 +453,10 @@ public Integer apply(Integer i) { return i % 2; } }) - .flatMap(new Function, Observable>() { + .flatMap(new Function, Flowable>() { @Override - public Observable apply(GroupedObservable group) { + public Flowable apply(GroupedFlowable group) { if (group.getKey() == 0) { return group.delay(100, TimeUnit.MILLISECONDS).map(new Function() { @Override @@ -471,7 +470,7 @@ public Integer apply(Integer t) { } } }) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -503,7 +502,7 @@ public void onNext(Integer s) { public void testCompletionIfInnerNotSubscribed() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicInteger eventCounter = new AtomicInteger(); - Observable.range(0, 100) + Flowable.range(0, 100) .groupBy(new Function() { @Override @@ -511,7 +510,7 @@ public Integer apply(Integer i) { return i % 2; } }) - .subscribe(new Observer>() { + .subscribe(new DefaultObserver>() { @Override public void onComplete() { @@ -525,7 +524,7 @@ public void onError(Throwable e) { } @Override - public void onNext(GroupedObservable s) { + public void onNext(GroupedFlowable s) { eventCounter.incrementAndGet(); System.out.println("=> " + s); } @@ -550,11 +549,11 @@ public Integer apply(Event e) { return e.source; } }) - .flatMap(new Function, Observable>() { + .flatMap(new Function, Flowable>() { @Override - public Observable apply(GroupedObservable eventGroupedObservable) { - Observable eventStream = eventGroupedObservable; + public Flowable apply(GroupedFlowable eventGroupedObservable) { + Flowable eventStream = eventGroupedObservable; if (eventGroupedObservable.getKey() >= 2) { // filter these eventStream = eventGroupedObservable.filter(new Predicate() { @@ -595,7 +594,7 @@ public void accept(String s) { public void testFirstGroupsCompleteAndParentSlowToThenEmitFinalGroupsAndThenComplete() throws InterruptedException { final CountDownLatch first = new CountDownLatch(2); // there are two groups to first complete final ArrayList results = new ArrayList(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber sub) { @@ -622,10 +621,10 @@ public Integer apply(Integer t) { return t; } - }).flatMap(new Function, Observable>() { + }).flatMap(new Function, Flowable>() { @Override - public Observable apply(final GroupedObservable group) { + public Flowable apply(final GroupedFlowable group) { if (group.getKey() < 3) { return group.map(new Function() { @@ -674,7 +673,7 @@ public void testFirstGroupsCompleteAndParentSlowToThenEmitFinalGroupsWhichThenSu System.err.println("----------------------------------------------------------------------------------------------"); final CountDownLatch first = new CountDownLatch(2); // there are two groups to first complete final ArrayList results = new ArrayList(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber sub) { @@ -701,10 +700,10 @@ public Integer apply(Integer t) { return t; } - }).flatMap(new Function, Observable>() { + }).flatMap(new Function, Flowable>() { @Override - public Observable apply(final GroupedObservable group) { + public Flowable apply(final GroupedFlowable group) { if (group.getKey() < 3) { return group.map(new Function() { @@ -766,7 +765,7 @@ public void accept(String s) { public void testFirstGroupsCompleteAndParentSlowToThenEmitFinalGroupsWhichThenObservesOnAndDelaysAndThenCompletes() throws InterruptedException { final CountDownLatch first = new CountDownLatch(2); // there are two groups to first complete final ArrayList results = new ArrayList(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber sub) { @@ -793,10 +792,10 @@ public Integer apply(Integer t) { return t; } - }).flatMap(new Function, Observable>() { + }).flatMap(new Function, Flowable>() { @Override - public Observable apply(final GroupedObservable group) { + public Flowable apply(final GroupedFlowable group) { if (group.getKey() < 3) { return group.map(new Function() { @@ -843,7 +842,7 @@ public void accept(String s) { @Test public void testGroupsWithNestedSubscribeOn() throws InterruptedException { final ArrayList results = new ArrayList(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber sub) { @@ -862,10 +861,10 @@ public Integer apply(Integer t) { return t; } - }).flatMap(new Function, Observable>() { + }).flatMap(new Function, Flowable>() { @Override - public Observable apply(final GroupedObservable group) { + public Flowable apply(final GroupedFlowable group) { return group.subscribeOn(Schedulers.newThread()).map(new Function() { @Override @@ -900,7 +899,7 @@ public void accept(String s) { @Test public void testGroupsWithNestedObserveOn() throws InterruptedException { final ArrayList results = new ArrayList(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber sub) { @@ -919,10 +918,10 @@ public Integer apply(Integer t) { return t; } - }).flatMap(new Function, Observable>() { + }).flatMap(new Function, Flowable>() { @Override - public Observable apply(final GroupedObservable group) { + public Flowable apply(final GroupedFlowable group) { return group.observeOn(Schedulers.newThread()).delay(400, TimeUnit.MILLISECONDS).map(new Function() { @Override @@ -956,12 +955,12 @@ public String toString() { } } - Observable ASYNC_INFINITE_OBSERVABLE_OF_EVENT(final int numGroups, final AtomicInteger subscribeCounter, final AtomicInteger sentEventCounter) { + Flowable ASYNC_INFINITE_OBSERVABLE_OF_EVENT(final int numGroups, final AtomicInteger subscribeCounter, final AtomicInteger sentEventCounter) { return SYNC_INFINITE_OBSERVABLE_OF_EVENT(numGroups, subscribeCounter, sentEventCounter).subscribeOn(Schedulers.newThread()); }; - Observable SYNC_INFINITE_OBSERVABLE_OF_EVENT(final int numGroups, final AtomicInteger subscribeCounter, final AtomicInteger sentEventCounter) { - return Observable.create(new Publisher() { + Flowable SYNC_INFINITE_OBSERVABLE_OF_EVENT(final int numGroups, final AtomicInteger subscribeCounter, final AtomicInteger sentEventCounter) { + return Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber op) { @@ -987,16 +986,16 @@ public void subscribe(final Subscriber op) { public void testGroupByOnAsynchronousSourceAcceptsMultipleSubscriptions() throws InterruptedException { // choose an asynchronous source - Observable source = Observable.interval(10, TimeUnit.MILLISECONDS).take(1); + Flowable source = Flowable.interval(10, TimeUnit.MILLISECONDS).take(1); // apply groupBy to the source - Observable> stream = source.groupBy(IS_EVEN); + Flowable> stream = source.groupBy(IS_EVEN); // create two observers @SuppressWarnings("unchecked") - Observer> o1 = mock(Observer.class); + DefaultObserver> o1 = mock(DefaultObserver.class); @SuppressWarnings("unchecked") - Observer> o2 = mock(Observer.class); + DefaultObserver> o2 = mock(DefaultObserver.class); // subscribe with the observers stream.subscribe(o1); @@ -1028,12 +1027,12 @@ public void testGroupByBackpressure() throws InterruptedException { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, 4000) + Flowable.range(1, 4000) .groupBy(IS_EVEN2) - .flatMap(new Function, Observable>() { + .flatMap(new Function, Flowable>() { @Override - public Observable apply(final GroupedObservable g) { + public Flowable apply(final GroupedFlowable g) { return g.observeOn(Schedulers.computation()).map(new Function() { @Override @@ -1099,7 +1098,7 @@ public Integer apply(Integer v) { @Test public void normalBehavior() { - Observable source = Observable.fromIterable(Arrays.asList( + Flowable source = Flowable.fromIterable(Arrays.asList( " foo", " FoO ", "baR ", @@ -1134,10 +1133,10 @@ public String apply(String t1) { } }; - Observable m = source.groupBy(keysel, valuesel) - .flatMap(new Function, Publisher>() { + Flowable m = source.groupBy(keysel, valuesel) + .flatMap(new Function, Publisher>() { @Override - public Publisher apply(final GroupedObservable g) { + public Publisher apply(final GroupedFlowable g) { System.out.println("-----------> NEXT: " + g.getKey()); return g.take(2).map(new Function() { @@ -1165,9 +1164,9 @@ public String apply(String v) { @Test public void keySelectorThrows() { - Observable source = Observable.just(0, 1, 2, 3, 4, 5, 6); + Flowable source = Flowable.just(0, 1, 2, 3, 4, 5, 6); - Observable m = source.groupBy(fail(0), dbl).flatMap(FLATTEN_INTEGER); + Flowable m = source.groupBy(fail(0), dbl).flatMap(FLATTEN_INTEGER); TestSubscriber ts = new TestSubscriber(); m.subscribe(ts); @@ -1178,9 +1177,9 @@ public void keySelectorThrows() { @Test public void valueSelectorThrows() { - Observable source = Observable.just(0, 1, 2, 3, 4, 5, 6); + Flowable source = Flowable.just(0, 1, 2, 3, 4, 5, 6); - Observable m = source.groupBy(identity, fail(0)).flatMap(FLATTEN_INTEGER); + Flowable m = source.groupBy(identity, fail(0)).flatMap(FLATTEN_INTEGER); TestSubscriber ts = new TestSubscriber(); m.subscribe(ts); ts.awaitTerminalEvent(); @@ -1191,9 +1190,9 @@ public void valueSelectorThrows() { @Test public void innerEscapeCompleted() { - Observable source = Observable.just(0); + Flowable source = Flowable.just(0); - Observable m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); + Flowable m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); TestSubscriber ts = new TestSubscriber(); m.subscribe(ts); @@ -1207,15 +1206,15 @@ public void innerEscapeCompleted() { */ @Test public void testExceptionIfSubscribeToChildMoreThanOnce() { - Observable source = Observable.just(0); + Flowable source = Flowable.just(0); - final AtomicReference> inner = new AtomicReference>(); + final AtomicReference> inner = new AtomicReference>(); - Observable> m = source.groupBy(identity, dbl); + Flowable> m = source.groupBy(identity, dbl); - m.subscribe(new Consumer>() { + m.subscribe(new Consumer>() { @Override - public void accept(GroupedObservable t1) { + public void accept(GroupedFlowable t1) { inner.set(t1); } }); @@ -1223,7 +1222,7 @@ public void accept(GroupedObservable t1) { inner.get().subscribe(); @SuppressWarnings("unchecked") - Observer o2 = mock(Observer.class); + DefaultObserver o2 = mock(DefaultObserver.class); inner.get().subscribe(o2); @@ -1234,10 +1233,10 @@ public void accept(GroupedObservable t1) { @Test public void testError2() { - Observable source = Observable.concat(Observable.just(0), - Observable. error(new TestException("Forced failure"))); + Flowable source = Flowable.concat(Flowable.just(0), + Flowable. error(new TestException("Forced failure"))); - Observable m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); + Flowable m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); TestSubscriber ts = new TestSubscriber(); m.subscribe(ts); @@ -1250,10 +1249,10 @@ public void testError2() { public void testgroupByBackpressure() throws InterruptedException { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, 4000).groupBy(IS_EVEN2).flatMap(new Function, Observable>() { + Flowable.range(1, 4000).groupBy(IS_EVEN2).flatMap(new Function, Flowable>() { @Override - public Observable apply(final GroupedObservable g) { + public Flowable apply(final GroupedFlowable g) { return g.doOnComplete(new Runnable() { @Override @@ -1307,17 +1306,17 @@ public void testgroupByBackpressure2() throws InterruptedException { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, 4000) + Flowable.range(1, 4000) .doOnNext(new Consumer() { @Override public void accept(Integer v) { System.out.println("testgroupByBackpressure2 >> " + v); } }) - .groupBy(IS_EVEN2).flatMap(new Function, Observable>() { + .groupBy(IS_EVEN2).flatMap(new Function, Flowable>() { @Override - public Observable apply(final GroupedObservable g) { + public Flowable apply(final GroupedFlowable g) { return g.take(2).observeOn(Schedulers.computation()).map(new Function() { @Override @@ -1341,10 +1340,10 @@ public String apply(Integer l) { ts.assertNoErrors(); } - static Function, Observable> FLATTEN_INTEGER = new Function, Observable>() { + static Function, Flowable> FLATTEN_INTEGER = new Function, Flowable>() { @Override - public Observable apply(GroupedObservable t) { + public Flowable apply(GroupedFlowable t) { return t; } @@ -1354,16 +1353,16 @@ public Observable apply(GroupedObservable t) { public void testGroupByWithNullKey() { final String[] key = new String[]{"uninitialized"}; final List values = new ArrayList(); - Observable.just("a", "b", "c").groupBy(new Function() { + Flowable.just("a", "b", "c").groupBy(new Function() { @Override public String apply(String value) { return null; } - }).subscribe(new Consumer>() { + }).subscribe(new Consumer>() { @Override - public void accept(GroupedObservable groupedObservable) { + public void accept(GroupedFlowable groupedObservable) { key[0] = groupedObservable.getKey(); groupedObservable.subscribe(new Consumer() { @@ -1381,7 +1380,7 @@ public void accept(String s) { @Test public void testGroupByUnsubscribe() { final Subscription s = mock(Subscription.class); - Observable o = Observable.create( + Flowable o = Flowable.create( new Publisher() { @Override public void subscribe(Subscriber subscriber) { @@ -1410,8 +1409,8 @@ public void testGroupByShouldPropagateError() { final TestSubscriber inner1 = new TestSubscriber(); final TestSubscriber inner2 = new TestSubscriber(); - final TestSubscriber> outer - = new TestSubscriber>(new Observer>() { + final TestSubscriber> outer + = new TestSubscriber>(new DefaultObserver>() { @Override public void onComplete() { @@ -1422,7 +1421,7 @@ public void onError(Throwable e) { } @Override - public void onNext(GroupedObservable o) { + public void onNext(GroupedFlowable o) { if (o.getKey() == 0) { o.subscribe(inner1); } else { @@ -1430,7 +1429,7 @@ public void onNext(GroupedObservable o) { } } }); - Observable.create( + Flowable.create( new Publisher() { @Override public void subscribe(Subscriber subscriber) { @@ -1455,7 +1454,7 @@ public Integer apply(Integer i) { @Test public void testRequestOverflow() { final AtomicBoolean completed = new AtomicBoolean(false); - Observable + Flowable .just(1, 2, 3) // group into one group .groupBy(new Function() { @@ -1465,13 +1464,13 @@ public Integer apply(Integer t) { } }) // flatten - .concatMap(new Function, Observable>() { + .concatMap(new Function, Flowable>() { @Override - public Observable apply(GroupedObservable g) { + public Flowable apply(GroupedFlowable g) { return g; } }) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onStart() { @@ -1509,12 +1508,12 @@ public void onNext(Integer t) { @Test public void testBackpressureObserveOnOuter() { for (int j = 0; j < 1000; j++) { - Observable.merge( - Observable.range(0, 500) + Flowable.merge( + Flowable.range(0, 500) .groupBy(new Function() { @Override public Object apply(Integer i) { - return i % (Observable.bufferSize() + 2); + return i % (Flowable.bufferSize() + 2); } }) .observeOn(Schedulers.computation()) @@ -1527,18 +1526,18 @@ public Object apply(Integer i) { */ @Test public void testBackpressureInnerDoesntOverflowOuter() { - TestSubscriber> ts = new TestSubscriber>((Long)null); + TestSubscriber> ts = new TestSubscriber>((Long)null); - Observable.fromArray(1, 2) + Flowable.fromArray(1, 2) .groupBy(new Function() { @Override public Integer apply(Integer v) { return v; } }) - .doOnNext(new Consumer>() { + .doOnNext(new Consumer>() { @Override - public void accept(GroupedObservable g) { + public void accept(GroupedFlowable g) { g.subscribe(); } }) // this will request Long.MAX_VALUE @@ -1556,16 +1555,16 @@ public void testOneGroupInnerRequestsTwiceBuffer() { TestSubscriber ts1 = new TestSubscriber((Long)null); final TestSubscriber ts2 = new TestSubscriber((Long)null); - Observable.range(1, Observable.bufferSize() * 2) + Flowable.range(1, Flowable.bufferSize() * 2) .groupBy(new Function() { @Override public Object apply(Integer v) { return 1; } }) - .doOnNext(new Consumer>() { + .doOnNext(new Consumer>() { @Override - public void accept(GroupedObservable g) { + public void accept(GroupedFlowable g) { g.subscribe(ts2); } }) @@ -1589,9 +1588,9 @@ public void accept(GroupedObservable g) { ts2.assertNoErrors(); ts2.assertNotComplete(); - ts2.request(Observable.bufferSize() * 2); + ts2.request(Flowable.bufferSize() * 2); - ts2.assertValueCount(Observable.bufferSize() * 2); + ts2.assertValueCount(Flowable.bufferSize() * 2); ts2.assertNoErrors(); ts2.assertNotComplete(); } diff --git a/src/test/java/io/reactivex/internal/operators/OperatorIgnoreElementsTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorIgnoreElementsTest.java similarity index 86% rename from src/test/java/io/reactivex/internal/operators/OperatorIgnoreElementsTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorIgnoreElementsTest.java index ccf35ec5e5..9e3fcb8d1a 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorIgnoreElementsTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorIgnoreElementsTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; @@ -19,28 +19,28 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Consumer; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class OperatorIgnoreElementsTest { @Test public void testWithEmpty() { - assertTrue(Observable.empty().ignoreElements().isEmpty().toBlocking().single()); + assertTrue(Flowable.empty().ignoreElements().isEmpty().toBlocking().single()); } @Test public void testWithNonEmpty() { - assertTrue(Observable.just(1, 2, 3).ignoreElements().isEmpty().toBlocking().single()); + assertTrue(Flowable.just(1, 2, 3).ignoreElements().isEmpty().toBlocking().single()); } @Test public void testUpstreamIsProcessedButIgnored() { final int num = 10; final AtomicInteger upstreamCount = new AtomicInteger(); - long count = Observable.range(1, num) + long count = Flowable.range(1, num) .doOnNext(new Consumer() { @Override public void accept(Integer t) { @@ -56,7 +56,7 @@ public void accept(Integer t) { @Test public void testCompletedOk() { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, 10).ignoreElements().subscribe(ts); + Flowable.range(1, 10).ignoreElements().subscribe(ts); ts.assertNoErrors(); ts.assertNoValues(); ts.assertTerminated(); @@ -68,7 +68,7 @@ public void testCompletedOk() { public void testErrorReceived() { TestSubscriber ts = new TestSubscriber(); TestException ex = new TestException("boo"); - Observable.error(ex).ignoreElements().subscribe(ts); + Flowable.error(ex).ignoreElements().subscribe(ts); ts.assertNoValues(); ts.assertTerminated(); // FIXME no longer testable @@ -80,7 +80,7 @@ public void testErrorReceived() { @Test public void testUnsubscribesFromUpstream() { final AtomicBoolean unsub = new AtomicBoolean(); - Observable.range(1, 10).doOnCancel(new Runnable() { + Flowable.range(1, 10).doOnCancel(new Runnable() { @Override public void run() { unsub.set(true); @@ -94,7 +94,7 @@ public void testDoesNotHangAndProcessesAllUsingBackpressure() { final AtomicInteger upstreamCount = new AtomicInteger(); final AtomicInteger count = new AtomicInteger(0); int num = 10; - Observable.range(1, num) + Flowable.range(1, num) // .doOnNext(new Consumer() { @Override @@ -113,7 +113,7 @@ public void accept(Integer t) { } }) // - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onStart() { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorLastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorLastTest.java similarity index 87% rename from src/test/java/io/reactivex/internal/operators/OperatorLastTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorLastTest.java index 1ad7796bb1..23594fb937 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorLastTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.isA; @@ -23,38 +23,39 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Predicate; public class OperatorLastTest { @Test public void testLastWithElements() { - Observable last = Observable.just(1, 2, 3).last(); + Flowable last = Flowable.just(1, 2, 3).last(); assertEquals(3, last.toBlocking().single().intValue()); } @Test(expected = NoSuchElementException.class) public void testLastWithNoElements() { - Observable last = Observable.empty().last(); + Flowable last = Flowable.empty().last(); last.toBlocking().single(); } @Test public void testLastMultiSubscribe() { - Observable last = Observable.just(1, 2, 3).last(); + Flowable last = Flowable.just(1, 2, 3).last(); assertEquals(3, last.toBlocking().single().intValue()); assertEquals(3, last.toBlocking().single().intValue()); } @Test public void testLastViaObservable() { - Observable.just(1, 2, 3).last(); + Flowable.just(1, 2, 3).last(); } @Test public void testLast() { - Observable observable = Observable.just(1, 2, 3).last(); + Flowable observable = Flowable.just(1, 2, 3).last(); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -67,7 +68,7 @@ public void testLast() { @Test public void testLastWithOneElement() { - Observable observable = Observable.just(1).last(); + Flowable observable = Flowable.just(1).last(); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -80,7 +81,7 @@ public void testLastWithOneElement() { @Test public void testLastWithEmpty() { - Observable observable = Observable. empty().last(); + Flowable observable = Flowable. empty().last(); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -93,7 +94,7 @@ public void testLastWithEmpty() { @Test public void testLastWithPredicate() { - Observable observable = Observable.just(1, 2, 3, 4, 5, 6) + Flowable observable = Flowable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override @@ -114,7 +115,7 @@ public boolean test(Integer t1) { @Test public void testLastWithPredicateAndOneElement() { - Observable observable = Observable.just(1, 2) + Flowable observable = Flowable.just(1, 2) .filter( new Predicate() { @@ -136,7 +137,7 @@ public boolean test(Integer t1) { @Test public void testLastWithPredicateAndEmpty() { - Observable observable = Observable.just(1) + Flowable observable = Flowable.just(1) .filter( new Predicate() { @@ -157,7 +158,7 @@ public boolean test(Integer t1) { @Test public void testLastOrDefault() { - Observable observable = Observable.just(1, 2, 3) + Flowable observable = Flowable.just(1, 2, 3) .last(4); Subscriber observer = TestHelper.mockSubscriber(); @@ -171,7 +172,7 @@ public void testLastOrDefault() { @Test public void testLastOrDefaultWithOneElement() { - Observable observable = Observable.just(1).last(2); + Flowable observable = Flowable.just(1).last(2); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -184,7 +185,7 @@ public void testLastOrDefaultWithOneElement() { @Test public void testLastOrDefaultWithEmpty() { - Observable observable = Observable. empty() + Flowable observable = Flowable. empty() .last(1); Subscriber observer = TestHelper.mockSubscriber(); @@ -198,7 +199,7 @@ public void testLastOrDefaultWithEmpty() { @Test public void testLastOrDefaultWithPredicate() { - Observable observable = Observable.just(1, 2, 3, 4, 5, 6) + Flowable observable = Flowable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override @@ -219,7 +220,7 @@ public boolean test(Integer t1) { @Test public void testLastOrDefaultWithPredicateAndOneElement() { - Observable observable = Observable.just(1, 2) + Flowable observable = Flowable.just(1, 2) .filter(new Predicate() { @Override @@ -240,7 +241,7 @@ public boolean test(Integer t1) { @Test public void testLastOrDefaultWithPredicateAndEmpty() { - Observable observable = Observable.just(1) + Flowable observable = Flowable.just(1) .filter( new Predicate() { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMapNotificationTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMapNotificationTest.java similarity index 55% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMapNotificationTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorMapNotificationTest.java index 85a4a0e519..387a54b6b2 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMapNotificationTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMapNotificationTest.java @@ -11,36 +11,36 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.flowable; import org.junit.Test; -import io.reactivex.NbpObservable; +import io.reactivex.Flowable; import io.reactivex.functions.*; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subscribers.TestSubscriber; -public class NbpOperatorMapNotificationTest { +public class OperatorMapNotificationTest { @Test public void testJust() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.just(1) + TestSubscriber ts = new TestSubscriber(); + Flowable.just(1) .flatMap( - new Function>() { + new Function>() { @Override - public NbpObservable apply(Integer item) { - return NbpObservable.just((Object)(item + 1)); + public Flowable apply(Integer item) { + return Flowable.just((Object)(item + 1)); } }, - new Function>() { + new Function>() { @Override - public NbpObservable apply(Throwable e) { - return NbpObservable.error(e); + public Flowable apply(Throwable e) { + return Flowable.error(e); } }, - new Supplier>() { + new Supplier>() { @Override - public NbpObservable get() { - return NbpObservable.never(); + public Flowable get() { + return Flowable.never(); } } ).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMapTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/OperatorMapTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorMapTest.java index 14cd32fcc5..d22266312b 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMapTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -21,8 +21,8 @@ import org.junit.*; import org.reactivestreams.Subscriber; -import io.reactivex.Observable; -import io.reactivex.TestHelper; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.schedulers.Schedulers; @@ -48,9 +48,9 @@ public void before() { public void testMap() { Map m1 = getMap("One"); Map m2 = getMap("Two"); - Observable> observable = Observable.just(m1, m2); + Flowable> observable = Flowable.just(m1, m2); - Observable m = observable.map(new Function, String>() { + Flowable m = observable.map(new Function, String>() { @Override public String apply(Map map) { return map.get("firstName"); @@ -68,23 +68,23 @@ public String apply(Map map) { @Test public void testMapMany() { /* simulate a top-level async call which returns IDs */ - Observable ids = Observable.just(1, 2); + Flowable ids = Flowable.just(1, 2); /* now simulate the behavior to take those IDs and perform nested async calls based on them */ - Observable m = ids.flatMap(new Function>() { + Flowable m = ids.flatMap(new Function>() { @Override - public Observable apply(Integer id) { + public Flowable apply(Integer id) { /* simulate making a nested async call which creates another Observable */ - Observable> subObservable = null; + Flowable> subObservable = null; if (id == 1) { Map m1 = getMap("One"); Map m2 = getMap("Two"); - subObservable = Observable.just(m1, m2); + subObservable = Flowable.just(m1, m2); } else { Map m3 = getMap("Three"); Map m4 = getMap("Four"); - subObservable = Observable.just(m3, m4); + subObservable = Flowable.just(m3, m4); } /* simulate kicking off the async call and performing a select on it to transform the data */ @@ -111,18 +111,18 @@ public String apply(Map map) { public void testMapMany2() { Map m1 = getMap("One"); Map m2 = getMap("Two"); - Observable> observable1 = Observable.just(m1, m2); + Flowable> observable1 = Flowable.just(m1, m2); Map m3 = getMap("Three"); Map m4 = getMap("Four"); - Observable> observable2 = Observable.just(m3, m4); + Flowable> observable2 = Flowable.just(m3, m4); - Observable>> observable = Observable.just(observable1, observable2); + Flowable>> observable = Flowable.just(observable1, observable2); - Observable m = observable.flatMap(new Function>, Observable>() { + Flowable m = observable.flatMap(new Function>, Flowable>() { @Override - public Observable apply(Observable> o) { + public Flowable apply(Flowable> o) { return o.map(new Function, String>() { @Override @@ -146,8 +146,8 @@ public String apply(Map map) { @Test public void testMapWithError() { - Observable w = Observable.just("one", "fail", "two", "three", "fail"); - Observable m = w.map(new Function() { + Flowable w = Flowable.just("one", "fail", "two", "three", "fail"); + Flowable m = w.map(new Function() { @Override public String apply(String s) { if ("fail".equals(s)) { @@ -174,7 +174,7 @@ public void accept(Throwable t1) { @Test(expected = IllegalArgumentException.class) public void testMapWithIssue417() { - Observable.just(1).observeOn(Schedulers.computation()) + Flowable.just(1).observeOn(Schedulers.computation()) .map(new Function() { @Override public Integer apply(Integer arg0) { @@ -188,7 +188,7 @@ public void testMapWithErrorInFuncAndThreadPoolScheduler() throws InterruptedExc // The error will throw in one of threads in the thread pool. // If map does not handle it, the error will disappear. // so map needs to handle the error by itself. - Observable m = Observable.just("one") + Flowable m = Flowable.just("one") .observeOn(Schedulers.computation()) .map(new Function() { @Override @@ -206,7 +206,7 @@ public String apply(String arg0) { */ @Test(expected = NoSuchElementException.class) public void testErrorPassesThruMap() { - Observable.range(1, 0).last().map(new Function() { + Flowable.range(1, 0).last().map(new Function() { @Override public Integer apply(Integer i) { @@ -221,7 +221,7 @@ public Integer apply(Integer i) { */ @Test(expected = IllegalStateException.class) public void testErrorPassesThruMap2() { - Observable.error(new IllegalStateException()).map(new Function() { + Flowable.error(new IllegalStateException()).map(new Function() { @Override public Object apply(Object i) { @@ -237,7 +237,7 @@ public Object apply(Object i) { */ @Test(expected = ArithmeticException.class) public void testMapWithErrorInFunc() { - Observable.range(1, 1).last().map(new Function() { + Flowable.range(1, 1).last().map(new Function() { @Override public Integer apply(Integer i) { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorMaterializeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMaterializeTest.java similarity index 90% rename from src/test/java/io/reactivex/internal/operators/OperatorMaterializeTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorMaterializeTest.java index df5857872f..a3807463b7 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorMaterializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMaterializeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; @@ -21,13 +21,12 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.Optional; -import io.reactivex.Observable; -import io.reactivex.Observer; import io.reactivex.*; +import io.reactivex.Optional; import io.reactivex.functions.Consumer; import io.reactivex.internal.subscriptions.EmptySubscription; import io.reactivex.schedulers.Schedulers; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; public class OperatorMaterializeTest { @@ -40,7 +39,7 @@ public void testMaterialize1() { "three"); TestObserver observer = new TestObserver(); - Observable>> m = Observable.create(o1).materialize(); + Flowable>> m = Flowable.create(o1).materialize(); m.subscribe(observer); try { @@ -65,7 +64,7 @@ public void testMaterialize2() { final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", "three"); TestObserver Observer = new TestObserver(); - Observable>> m = Observable.create(o1).materialize(); + Flowable>> m = Flowable.create(o1).materialize(); m.subscribe(Observer); try { @@ -90,7 +89,7 @@ public void testMaterialize2() { public void testMultipleSubscribes() throws InterruptedException, ExecutionException { final TestAsyncErrorObservable o = new TestAsyncErrorObservable("one", "two", null, "three"); - Observable>> m = Observable.create(o).materialize(); + Flowable>> m = Flowable.create(o).materialize(); assertEquals(3, m.toList().toBlocking().toFuture().get().size()); assertEquals(3, m.toList().toBlocking().toFuture().get().size()); @@ -99,7 +98,7 @@ public void testMultipleSubscribes() throws InterruptedException, ExecutionExcep @Test public void testBackpressureOnEmptyStream() { TestSubscriber>> ts = new TestSubscriber>>((Long)null); - Observable. empty().materialize().subscribe(ts); + Flowable. empty().materialize().subscribe(ts); ts.assertNoValues(); ts.request(1); ts.assertValueCount(1); @@ -110,7 +109,7 @@ public void testBackpressureOnEmptyStream() { @Test public void testBackpressureNoError() { TestSubscriber>> ts = new TestSubscriber>>((Long)null); - Observable.just(1, 2, 3).materialize().subscribe(ts); + Flowable.just(1, 2, 3).materialize().subscribe(ts); ts.assertNoValues(); ts.request(1); ts.assertValueCount(1); @@ -124,7 +123,7 @@ public void testBackpressureNoError() { @Test public void testBackpressureNoErrorAsync() throws InterruptedException { TestSubscriber>> ts = new TestSubscriber>>((Long)null); - Observable.just(1, 2, 3) + Flowable.just(1, 2, 3) .materialize() .subscribeOn(Schedulers.computation()) .subscribe(ts); @@ -145,7 +144,7 @@ public void testBackpressureNoErrorAsync() throws InterruptedException { @Test public void testBackpressureWithError() { TestSubscriber>> ts = new TestSubscriber>>((Long)null); - Observable. error(new IllegalArgumentException()).materialize().subscribe(ts); + Flowable. error(new IllegalArgumentException()).materialize().subscribe(ts); ts.assertNoValues(); ts.request(1); ts.assertValueCount(1); @@ -156,7 +155,7 @@ public void testBackpressureWithError() { public void testBackpressureWithEmissionThenError() { TestSubscriber>> ts = new TestSubscriber>>((Long)null); IllegalArgumentException ex = new IllegalArgumentException(); - Observable.fromIterable(Arrays.asList(1)).concatWith(Observable. error(ex)).materialize() + Flowable.fromIterable(Arrays.asList(1)).concatWith(Flowable. error(ex)).materialize() .subscribe(ts); ts.assertNoValues(); ts.request(1); @@ -173,7 +172,7 @@ public void testBackpressureWithEmissionThenError() { public void testWithCompletionCausingError() { TestSubscriber>> ts = new TestSubscriber>>(); final RuntimeException ex = new RuntimeException("boo"); - Observable.empty().materialize().doOnNext(new Consumer() { + Flowable.empty().materialize().doOnNext(new Consumer() { @Override public void accept(Object t) { throw ex; @@ -188,7 +187,7 @@ public void accept(Object t) { public void testUnsubscribeJustBeforeCompletionNotificationShouldPreventThatNotificationArriving() { TestSubscriber>> ts = new TestSubscriber>>((Long)null); - Observable.empty().materialize() + Flowable.empty().materialize() .subscribe(ts); ts.assertNoValues(); ts.dispose(); @@ -198,7 +197,7 @@ public void testUnsubscribeJustBeforeCompletionNotificationShouldPreventThatNoti // ts.assertUnsubscribed(); } - private static class TestObserver extends Observer>> { + private static class TestObserver extends DefaultObserver>> { boolean onCompleted = false; boolean onError = false; diff --git a/src/test/java/io/reactivex/internal/operators/OperatorMergeDelayErrorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMergeDelayErrorTest.java similarity index 76% rename from src/test/java/io/reactivex/internal/operators/OperatorMergeDelayErrorTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorMergeDelayErrorTest.java index 86880e096b..78c46e2d9e 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorMergeDelayErrorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMergeDelayErrorTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -24,12 +24,12 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.*; -import io.reactivex.Observable; -import io.reactivex.Observer; +import io.reactivex.Flowable; import io.reactivex.exceptions.*; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.LongConsumer; import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; public class OperatorMergeDelayErrorTest { @@ -43,10 +43,10 @@ public void before() { @Test public void testErrorDelayed1() { - final Observable o1 = Observable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called - final Observable o2 = Observable.create(new TestErrorObservable("one", "two", "three")); + final Flowable o1 = Flowable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called + final Flowable o2 = Flowable.create(new TestErrorObservable("one", "two", "three")); - Observable m = Observable.mergeDelayError(o1, o2); + Flowable m = Flowable.mergeDelayError(o1, o2); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); @@ -64,12 +64,12 @@ public void testErrorDelayed1() { @Test public void testErrorDelayed2() { - final Observable o1 = Observable.create(new TestErrorObservable("one", "two", "three")); - final Observable o2 = Observable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called - final Observable o3 = Observable.create(new TestErrorObservable("seven", "eight", null)); - final Observable o4 = Observable.create(new TestErrorObservable("nine")); + final Flowable o1 = Flowable.create(new TestErrorObservable("one", "two", "three")); + final Flowable o2 = Flowable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called + final Flowable o3 = Flowable.create(new TestErrorObservable("seven", "eight", null)); + final Flowable o4 = Flowable.create(new TestErrorObservable("nine")); - Observable m = Observable.mergeDelayError(o1, o2, o3, o4); + Flowable m = Flowable.mergeDelayError(o1, o2, o3, o4); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); @@ -89,12 +89,12 @@ public void testErrorDelayed2() { @Test public void testErrorDelayed3() { - final Observable o1 = Observable.create(new TestErrorObservable("one", "two", "three")); - final Observable o2 = Observable.create(new TestErrorObservable("four", "five", "six")); - final Observable o3 = Observable.create(new TestErrorObservable("seven", "eight", null)); - final Observable o4 = Observable.create(new TestErrorObservable("nine")); + final Flowable o1 = Flowable.create(new TestErrorObservable("one", "two", "three")); + final Flowable o2 = Flowable.create(new TestErrorObservable("four", "five", "six")); + final Flowable o3 = Flowable.create(new TestErrorObservable("seven", "eight", null)); + final Flowable o4 = Flowable.create(new TestErrorObservable("nine")); - Observable m = Observable.mergeDelayError(o1, o2, o3, o4); + Flowable m = Flowable.mergeDelayError(o1, o2, o3, o4); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); @@ -112,12 +112,12 @@ public void testErrorDelayed3() { @Test public void testErrorDelayed4() { - final Observable o1 = Observable.create(new TestErrorObservable("one", "two", "three")); - final Observable o2 = Observable.create(new TestErrorObservable("four", "five", "six")); - final Observable o3 = Observable.create(new TestErrorObservable("seven", "eight")); - final Observable o4 = Observable.create(new TestErrorObservable("nine", null)); + final Flowable o1 = Flowable.create(new TestErrorObservable("one", "two", "three")); + final Flowable o2 = Flowable.create(new TestErrorObservable("four", "five", "six")); + final Flowable o3 = Flowable.create(new TestErrorObservable("seven", "eight")); + final Flowable o4 = Flowable.create(new TestErrorObservable("nine", null)); - Observable m = Observable.mergeDelayError(o1, o2, o3, o4); + Flowable m = Flowable.mergeDelayError(o1, o2, o3, o4); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); @@ -141,7 +141,7 @@ public void testErrorDelayed4WithThreading() { // throw the error at the very end so no onComplete will be called after it final TestAsyncErrorObservable o4 = new TestAsyncErrorObservable("nine", null); - Observable m = Observable.mergeDelayError(Observable.create(o1), Observable.create(o2), Observable.create(o3), Observable.create(o4)); + Flowable m = Flowable.mergeDelayError(Flowable.create(o1), Flowable.create(o2), Flowable.create(o3), Flowable.create(o4)); m.subscribe(stringObserver); try { @@ -168,10 +168,10 @@ public void testErrorDelayed4WithThreading() { @Test public void testCompositeErrorDelayed1() { - final Observable o1 = Observable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called - final Observable o2 = Observable.create(new TestErrorObservable("one", "two", null)); + final Flowable o1 = Flowable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called + final Flowable o2 = Flowable.create(new TestErrorObservable("one", "two", null)); - Observable m = Observable.mergeDelayError(o1, o2); + Flowable m = Flowable.mergeDelayError(o1, o2); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(Throwable.class)); @@ -188,10 +188,10 @@ public void testCompositeErrorDelayed1() { @Test public void testCompositeErrorDelayed2() { - final Observable o1 = Observable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called - final Observable o2 = Observable.create(new TestErrorObservable("one", "two", null)); + final Flowable o1 = Flowable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called + final Flowable o2 = Flowable.create(new TestErrorObservable("one", "two", null)); - Observable m = Observable.mergeDelayError(o1, o2); + Flowable m = Flowable.mergeDelayError(o1, o2); CaptureObserver w = new CaptureObserver(); m.subscribe(w); @@ -218,13 +218,13 @@ public void testCompositeErrorDelayed2() { @Test public void testMergeObservableOfObservables() { - final Observable o1 = Observable.create(new TestSynchronousObservable()); - final Observable o2 = Observable.create(new TestSynchronousObservable()); + final Flowable o1 = Flowable.create(new TestSynchronousObservable()); + final Flowable o2 = Flowable.create(new TestSynchronousObservable()); - Observable> observableOfObservables = Observable.create(new Publisher>() { + Flowable> observableOfObservables = Flowable.create(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { + public void subscribe(Subscriber> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); // simulate what would happen in an observable observer.onNext(o1); @@ -233,7 +233,7 @@ public void subscribe(Subscriber> observer) { } }); - Observable m = Observable.mergeDelayError(observableOfObservables); + Flowable m = Flowable.mergeDelayError(observableOfObservables); m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -243,10 +243,10 @@ public void subscribe(Subscriber> observer) { @Test public void testMergeArray() { - final Observable o1 = Observable.create(new TestSynchronousObservable()); - final Observable o2 = Observable.create(new TestSynchronousObservable()); + final Flowable o1 = Flowable.create(new TestSynchronousObservable()); + final Flowable o2 = Flowable.create(new TestSynchronousObservable()); - Observable m = Observable.mergeDelayError(o1, o2); + Flowable m = Flowable.mergeDelayError(o1, o2); m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -256,13 +256,13 @@ public void testMergeArray() { @Test public void testMergeList() { - final Observable o1 = Observable.create(new TestSynchronousObservable()); - final Observable o2 = Observable.create(new TestSynchronousObservable()); - List> listOfObservables = new ArrayList>(); + final Flowable o1 = Flowable.create(new TestSynchronousObservable()); + final Flowable o2 = Flowable.create(new TestSynchronousObservable()); + List> listOfObservables = new ArrayList>(); listOfObservables.add(o1); listOfObservables.add(o2); - Observable m = Observable.mergeDelayError(Observable.fromIterable(listOfObservables)); + Flowable m = Flowable.mergeDelayError(Flowable.fromIterable(listOfObservables)); m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -275,7 +275,7 @@ public void testMergeArrayWithThreading() { final TestASynchronousObservable o1 = new TestASynchronousObservable(); final TestASynchronousObservable o2 = new TestASynchronousObservable(); - Observable m = Observable.mergeDelayError(Observable.create(o1), Observable.create(o2)); + Flowable m = Flowable.mergeDelayError(Flowable.create(o1), Flowable.create(o2)); m.subscribe(stringObserver); try { @@ -292,10 +292,10 @@ public void testMergeArrayWithThreading() { @Test(timeout = 1000L) public void testSynchronousError() { - final Observable> o1 = Observable.error(new RuntimeException("unit test")); + final Flowable> o1 = Flowable.error(new RuntimeException("unit test")); final CountDownLatch latch = new CountDownLatch(1); - Observable.mergeDelayError(o1).subscribe(new Observer() { + Flowable.mergeDelayError(o1).subscribe(new DefaultObserver() { @Override public void onComplete() { fail("Expected onError path"); @@ -417,7 +417,7 @@ public void run() { } } - private static class CaptureObserver extends Observer { + private static class CaptureObserver extends DefaultObserver { volatile Throwable e; @Override @@ -439,7 +439,7 @@ public void onNext(String args) { @Test @Ignore("Subscribers should not throw") public void testMergeSourceWhichDoesntPropagateExceptionBack() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber t1) { t1.onSubscribe(EmptySubscription.INSTANCE); @@ -453,12 +453,12 @@ public void subscribe(Subscriber t1) { } }); - Observable result = Observable.mergeDelayError(source, Observable.just(2)); + Flowable result = Flowable.mergeDelayError(source, Flowable.just(2)); final Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); - result.unsafeSubscribe(new Observer() { + result.unsafeSubscribe(new DefaultObserver() { int calls; @Override public void onNext(Integer t) { @@ -495,9 +495,9 @@ public void onComplete() { @Test public void testErrorInParentObservable() { TestSubscriber ts = new TestSubscriber(); - Observable.mergeDelayError( - Observable.just(Observable.just(1), Observable.just(2)) - .startWith(Observable. error(new RuntimeException())) + Flowable.mergeDelayError( + Flowable.just(Flowable.just(1), Flowable.just(2)) + .startWith(Flowable. error(new RuntimeException())) ).subscribe(ts); ts.awaitTerminalEvent(); ts.assertTerminated(); @@ -511,12 +511,12 @@ public void testErrorInParentObservableDelayed() throws Exception { for (int i = 0; i < 50; i++) { final TestASynchronous1sDelayedObservable o1 = new TestASynchronous1sDelayedObservable(); final TestASynchronous1sDelayedObservable o2 = new TestASynchronous1sDelayedObservable(); - Observable> parentObservable = Observable.create(new Publisher>() { + Flowable> parentObservable = Flowable.create(new Publisher>() { @Override - public void subscribe(Subscriber> op) { + public void subscribe(Subscriber> op) { op.onSubscribe(EmptySubscription.INSTANCE); - op.onNext(Observable.create(o1)); - op.onNext(Observable.create(o2)); + op.onNext(Flowable.create(o1)); + op.onNext(Flowable.create(o2)); op.onError(new NullPointerException("throwing exception in parent")); } }); @@ -524,7 +524,7 @@ public void subscribe(Subscriber> op) { Subscriber stringObserver = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(stringObserver); - Observable m = Observable.mergeDelayError(parentObservable); + Flowable m = Flowable.mergeDelayError(parentObservable); m.subscribe(ts); System.out.println("testErrorInParentObservableDelayed | " + i); ts.awaitTerminalEvent(2000, TimeUnit.MILLISECONDS); @@ -562,9 +562,9 @@ public void run() { @Test public void testDelayErrorMaxConcurrent() { final List requests = new ArrayList(); - Observable source = Observable.mergeDelayError(Observable.just( - Observable.just(1).asObservable(), - Observable.error(new TestException())) + Flowable source = Flowable.mergeDelayError(Flowable.just( + Flowable.just(1).asObservable(), + Flowable.error(new TestException())) .doOnRequest(new LongConsumer() { @Override public void accept(long t1) { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMergeMaxConcurrentTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMergeMaxConcurrentTest.java similarity index 61% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMergeMaxConcurrentTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorMergeMaxConcurrentTest.java index e8da9ca6cf..0888b66a73 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMergeMaxConcurrentTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMergeMaxConcurrentTest.java @@ -11,42 +11,43 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import java.util.*; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; import org.junit.*; +import org.reactivestreams.*; -import io.reactivex.*; -import io.reactivex.NbpObservable.*; -import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.internal.schedulers.IOScheduler; +import io.reactivex.internal.subscriptions.EmptySubscription; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subscribers.TestSubscriber; -public class NbpOperatorMergeMaxConcurrentTest { +public class OperatorMergeMaxConcurrentTest { - NbpSubscriber stringObserver; + Subscriber stringObserver; @Before public void before() { - stringObserver = TestHelper.mockNbpSubscriber(); + stringObserver = TestHelper.mockSubscriber(); } @Test public void testWhenMaxConcurrentIsOne() { for (int i = 0; i < 100; i++) { - List> os = new ArrayList>(); - os.add(NbpObservable.just("one", "two", "three", "four", "five").subscribeOn(Schedulers.newThread())); - os.add(NbpObservable.just("one", "two", "three", "four", "five").subscribeOn(Schedulers.newThread())); - os.add(NbpObservable.just("one", "two", "three", "four", "five").subscribeOn(Schedulers.newThread())); + List> os = new ArrayList>(); + os.add(Flowable.just("one", "two", "three", "four", "five").subscribeOn(Schedulers.newThread())); + os.add(Flowable.just("one", "two", "three", "four", "five").subscribeOn(Schedulers.newThread())); + os.add(Flowable.just("one", "two", "three", "four", "five").subscribeOn(Schedulers.newThread())); List expected = Arrays.asList("one", "two", "three", "four", "five", "one", "two", "three", "four", "five", "one", "two", "three", "four", "five"); - Iterator iter = NbpObservable.merge(os, 1).toBlocking().iterator(); + Iterator iter = Flowable.merge(os, 1).toBlocking().iterator(); List actual = new ArrayList(); while (iter.hasNext()) { actual.add(iter.next()); @@ -63,15 +64,15 @@ public void testMaxConcurrent() { int maxConcurrent = 2 + (times % 10); AtomicInteger subscriptionCount = new AtomicInteger(0); - List> os = new ArrayList>(); + List> os = new ArrayList>(); List scos = new ArrayList(); for (int i = 0; i < observableCount; i++) { SubscriptionCheckObservable sco = new SubscriptionCheckObservable(subscriptionCount, maxConcurrent); scos.add(sco); - os.add(NbpObservable.create(sco)); + os.add(Flowable.create(sco)); } - Iterator iter = NbpObservable.merge(os, maxConcurrent).toBlocking().iterator(); + Iterator iter = Flowable.merge(os, maxConcurrent).toBlocking().iterator(); List actual = new ArrayList(); while (iter.hasNext()) { actual.add(iter.next()); @@ -84,7 +85,7 @@ public void testMaxConcurrent() { } } - private static class SubscriptionCheckObservable implements NbpOnSubscribe { + private static class SubscriptionCheckObservable implements Publisher { private final AtomicInteger subscriptionCount; private final int maxConcurrent; @@ -96,8 +97,8 @@ private static class SubscriptionCheckObservable implements NbpOnSubscribe t1) { - t1.onSubscribe(EmptyDisposable.INSTANCE); + public void subscribe(final Subscriber t1) { + t1.onSubscribe(EmptySubscription.INSTANCE); new Thread(new Runnable() { @Override @@ -124,11 +125,11 @@ public void run() { @Test public void testMergeALotOfSourcesOneByOneSynchronously() { int n = 10000; - List> sourceList = new ArrayList>(n); + List> sourceList = new ArrayList>(n); for (int i = 0; i < n; i++) { - sourceList.add(NbpObservable.just(i)); + sourceList.add(Flowable.just(i)); } - Iterator it = NbpObservable.merge(NbpObservable.fromIterable(sourceList), 1).toBlocking().iterator(); + Iterator it = Flowable.merge(Flowable.fromIterable(sourceList), 1).toBlocking().iterator(); int j = 0; while (it.hasNext()) { assertEquals((Integer)j, it.next()); @@ -139,11 +140,11 @@ public void testMergeALotOfSourcesOneByOneSynchronously() { @Test public void testMergeALotOfSourcesOneByOneSynchronouslyTakeHalf() { int n = 10000; - List> sourceList = new ArrayList>(n); + List> sourceList = new ArrayList>(n); for (int i = 0; i < n; i++) { - sourceList.add(NbpObservable.just(i)); + sourceList.add(Flowable.just(i)); } - Iterator it = NbpObservable.merge(NbpObservable.fromIterable(sourceList), 1).take(n / 2).toBlocking().iterator(); + Iterator it = Flowable.merge(Flowable.fromIterable(sourceList), 1).take(n / 2).toBlocking().iterator(); int j = 0; while (it.hasNext()) { assertEquals((Integer)j, it.next()); @@ -155,15 +156,15 @@ public void testMergeALotOfSourcesOneByOneSynchronouslyTakeHalf() { @Test public void testSimple() { for (int i = 1; i < 100; i++) { - NbpTestSubscriber ts = new NbpTestSubscriber(); - List> sourceList = new ArrayList>(i); + TestSubscriber ts = new TestSubscriber(); + List> sourceList = new ArrayList>(i); List result = new ArrayList(i); for (int j = 1; j <= i; j++) { - sourceList.add(NbpObservable.just(j)); + sourceList.add(Flowable.just(j)); result.add(j); } - NbpObservable.merge(sourceList, i).subscribe(ts); + Flowable.merge(sourceList, i).subscribe(ts); ts.assertNoErrors(); ts.assertTerminated(); @@ -173,15 +174,15 @@ public void testSimple() { @Test public void testSimpleOneLess() { for (int i = 2; i < 100; i++) { - NbpTestSubscriber ts = new NbpTestSubscriber(); - List> sourceList = new ArrayList>(i); + TestSubscriber ts = new TestSubscriber(); + List> sourceList = new ArrayList>(i); List result = new ArrayList(i); for (int j = 1; j <= i; j++) { - sourceList.add(NbpObservable.just(j)); + sourceList.add(Flowable.just(j)); result.add(j); } - NbpObservable.merge(sourceList, i - 1).subscribe(ts); + Flowable.merge(sourceList, i - 1).subscribe(ts); ts.assertNoErrors(); ts.assertTerminated(); @@ -203,15 +204,15 @@ public void testSimpleAsyncLoop() { @Test(timeout = 10000) public void testSimpleAsync() { for (int i = 1; i < 50; i++) { - NbpTestSubscriber ts = new NbpTestSubscriber(); - List> sourceList = new ArrayList>(i); + TestSubscriber ts = new TestSubscriber(); + List> sourceList = new ArrayList>(i); Set expected = new HashSet(i); for (int j = 1; j <= i; j++) { - sourceList.add(NbpObservable.just(j).subscribeOn(Schedulers.io())); + sourceList.add(Flowable.just(j).subscribeOn(Schedulers.io())); expected.add(j); } - NbpObservable.merge(sourceList, i).subscribe(ts); + Flowable.merge(sourceList, i).subscribe(ts); ts.awaitTerminalEvent(1, TimeUnit.SECONDS); ts.assertNoErrors(); @@ -233,15 +234,15 @@ public void testSimpleOneLessAsync() { if (System.currentTimeMillis() - t > TimeUnit.SECONDS.toMillis(9)) { break; } - NbpTestSubscriber ts = new NbpTestSubscriber(); - List> sourceList = new ArrayList>(i); + TestSubscriber ts = new TestSubscriber(); + List> sourceList = new ArrayList>(i); Set expected = new HashSet(i); for (int j = 1; j <= i; j++) { - sourceList.add(NbpObservable.just(j).subscribeOn(Schedulers.io())); + sourceList.add(Flowable.just(j).subscribeOn(Schedulers.io())); expected.add(j); } - NbpObservable.merge(sourceList, i - 1).subscribe(ts); + Flowable.merge(sourceList, i - 1).subscribe(ts); ts.awaitTerminalEvent(1, TimeUnit.SECONDS); ts.assertNoErrors(); @@ -250,18 +251,47 @@ public void testSimpleOneLessAsync() { assertEquals(expected, actual); } } - + @Test(timeout = 5000) + public void testBackpressureHonored() throws Exception { + List> sourceList = new ArrayList>(3); + + sourceList.add(Flowable.range(0, 100000).subscribeOn(Schedulers.io())); + sourceList.add(Flowable.range(0, 100000).subscribeOn(Schedulers.io())); + sourceList.add(Flowable.range(0, 100000).subscribeOn(Schedulers.io())); + + final CountDownLatch cdl = new CountDownLatch(5); + + TestSubscriber ts = new TestSubscriber((Long)null) { + @Override + public void onNext(Integer t) { + super.onNext(t); + cdl.countDown(); + } + }; + + Flowable.merge(sourceList, 2).subscribe(ts); + + ts.request(5); + + cdl.await(); + + ts.assertNoErrors(); + ts.assertValueCount(5); + ts.assertNotComplete(); + + ts.dispose(); + } @Test(timeout = 5000) public void testTake() throws Exception { - List> sourceList = new ArrayList>(3); + List> sourceList = new ArrayList>(3); - sourceList.add(NbpObservable.range(0, 100000).subscribeOn(Schedulers.io())); - sourceList.add(NbpObservable.range(0, 100000).subscribeOn(Schedulers.io())); - sourceList.add(NbpObservable.range(0, 100000).subscribeOn(Schedulers.io())); + sourceList.add(Flowable.range(0, 100000).subscribeOn(Schedulers.io())); + sourceList.add(Flowable.range(0, 100000).subscribeOn(Schedulers.io())); + sourceList.add(Flowable.range(0, 100000).subscribeOn(Schedulers.io())); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestSubscriber ts = new TestSubscriber(); - NbpObservable.merge(sourceList, 2).take(5).subscribe(ts); + Flowable.merge(sourceList, 2).take(5).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorMergeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMergeTest.java similarity index 80% rename from src/test/java/io/reactivex/internal/operators/OperatorMergeTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorMergeTest.java index 236b8e10e7..bc538108b4 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMergeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static java.util.Arrays.asList; import static org.junit.Assert.*; @@ -25,13 +25,13 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.Observable; -import io.reactivex.Observer; import io.reactivex.*; import io.reactivex.Scheduler.Worker; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.*; import io.reactivex.schedulers.*; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; public class OperatorMergeTest { @@ -71,13 +71,13 @@ public void after() { @Test public void testMergeObservableOfObservables() { - final Observable o1 = Observable.create(new TestSynchronousObservable()); - final Observable o2 = Observable.create(new TestSynchronousObservable()); + final Flowable o1 = Flowable.create(new TestSynchronousObservable()); + final Flowable o2 = Flowable.create(new TestSynchronousObservable()); - Observable> observableOfObservables = Observable.create(new Publisher>() { + Flowable> observableOfObservables = Flowable.create(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { + public void subscribe(Subscriber> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); // simulate what would happen in an observable observer.onNext(o1); @@ -86,7 +86,7 @@ public void subscribe(Subscriber> observer) { } }); - Observable m = Observable.merge(observableOfObservables); + Flowable m = Flowable.merge(observableOfObservables); m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -96,10 +96,10 @@ public void subscribe(Subscriber> observer) { @Test public void testMergeArray() { - final Observable o1 = Observable.create(new TestSynchronousObservable()); - final Observable o2 = Observable.create(new TestSynchronousObservable()); + final Flowable o1 = Flowable.create(new TestSynchronousObservable()); + final Flowable o2 = Flowable.create(new TestSynchronousObservable()); - Observable m = Observable.merge(o1, o2); + Flowable m = Flowable.merge(o1, o2); m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -109,13 +109,13 @@ public void testMergeArray() { @Test public void testMergeList() { - final Observable o1 = Observable.create(new TestSynchronousObservable()); - final Observable o2 = Observable.create(new TestSynchronousObservable()); - List> listOfObservables = new ArrayList>(); + final Flowable o1 = Flowable.create(new TestSynchronousObservable()); + final Flowable o2 = Flowable.create(new TestSynchronousObservable()); + List> listOfObservables = new ArrayList>(); listOfObservables.add(o1); listOfObservables.add(o2); - Observable m = Observable.merge(listOfObservables); + Flowable m = Flowable.merge(listOfObservables); m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -129,10 +129,10 @@ public void testUnSubscribeObservableOfObservables() throws InterruptedException final AtomicBoolean unsubscribed = new AtomicBoolean(); final CountDownLatch latch = new CountDownLatch(1); - Observable> source = Observable.create(new Publisher>() { + Flowable> source = Flowable.create(new Publisher>() { @Override - public void subscribe(final Subscriber> observer) { + public void subscribe(final Subscriber> observer) { // verbose on purpose so I can track the inside of it final Subscription s = new Subscription() { @@ -156,7 +156,7 @@ public void cancel() { public void run() { while (!unsubscribed.get()) { - observer.onNext(Observable.just(1L, 2L)); + observer.onNext(Flowable.just(1L, 2L)); } System.out.println("Done looping after unsubscribe: " + unsubscribed.get()); observer.onComplete(); @@ -170,7 +170,7 @@ public void run() { }); final AtomicInteger count = new AtomicInteger(); - Observable.merge(source).take(6).toBlocking().forEach(new Consumer() { + Flowable.merge(source).take(6).toBlocking().forEach(new Consumer() { @Override public void accept(Long v) { @@ -196,7 +196,7 @@ public void testMergeArrayWithThreading() { final TestASynchronousObservable o1 = new TestASynchronousObservable(); final TestASynchronousObservable o2 = new TestASynchronousObservable(); - Observable m = Observable.merge(Observable.create(o1), Observable.create(o2)); + Flowable m = Flowable.merge(Flowable.create(o1), Flowable.create(o2)); TestSubscriber ts = new TestSubscriber(stringObserver); m.subscribe(ts); @@ -227,8 +227,8 @@ public void testSynchronizationOfMultipleSequences() throws Throwable { final AtomicInteger concurrentCounter = new AtomicInteger(); final AtomicInteger totalCounter = new AtomicInteger(); - Observable m = Observable.merge(Observable.create(o1), Observable.create(o2)); - m.subscribe(new Observer() { + Flowable m = Flowable.merge(Flowable.create(o1), Flowable.create(o2)); + m.subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -297,10 +297,10 @@ public void onNext(String v) { @Test public void testError1() { // we are using synchronous execution to test this exactly rather than non-deterministic concurrent behavior - final Observable o1 = Observable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" - final Observable o2 = Observable.create(new TestErrorObservable("one", "two", "three")); // we expect to lose all of these since o1 is done first and fails + final Flowable o1 = Flowable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" + final Flowable o2 = Flowable.create(new TestErrorObservable("one", "two", "three")); // we expect to lose all of these since o1 is done first and fails - Observable m = Observable.merge(o1, o2); + Flowable m = Flowable.merge(o1, o2); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); @@ -319,12 +319,12 @@ public void testError1() { @Test public void testError2() { // we are using synchronous execution to test this exactly rather than non-deterministic concurrent behavior - final Observable o1 = Observable.create(new TestErrorObservable("one", "two", "three")); - final Observable o2 = Observable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" - final Observable o3 = Observable.create(new TestErrorObservable("seven", "eight", null));// we expect to lose all of these since o2 is done first and fails - final Observable o4 = Observable.create(new TestErrorObservable("nine"));// we expect to lose all of these since o2 is done first and fails + final Flowable o1 = Flowable.create(new TestErrorObservable("one", "two", "three")); + final Flowable o2 = Flowable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" + final Flowable o3 = Flowable.create(new TestErrorObservable("seven", "eight", null));// we expect to lose all of these since o2 is done first and fails + final Flowable o4 = Flowable.create(new TestErrorObservable("nine"));// we expect to lose all of these since o2 is done first and fails - Observable m = Observable.merge(o1, o2, o3, o4); + Flowable m = Flowable.merge(o1, o2, o3, o4); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); @@ -344,7 +344,7 @@ public void testError2() { @Ignore("Subscribe should not throw") public void testThrownErrorHandling() { TestSubscriber ts = new TestSubscriber(); - Observable o1 = Observable.create(new Publisher() { + Flowable o1 = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -353,7 +353,7 @@ public void subscribe(Subscriber s) { }); - Observable.merge(o1, o1).subscribe(ts); + Flowable.merge(o1, o1).subscribe(ts); ts.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); ts.assertTerminated(); System.out.println("Error: " + ts.errors()); @@ -423,14 +423,14 @@ public void subscribe(Subscriber observer) { public void testUnsubscribeAsObservablesComplete() { TestScheduler scheduler1 = Schedulers.test(); AtomicBoolean os1 = new AtomicBoolean(false); - Observable o1 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler1, os1); + Flowable o1 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler1, os1); TestScheduler scheduler2 = Schedulers.test(); AtomicBoolean os2 = new AtomicBoolean(false); - Observable o2 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); + Flowable o2 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); TestSubscriber ts = new TestSubscriber(); - Observable.merge(o1, o2).subscribe(ts); + Flowable.merge(o1, o2).subscribe(ts); // we haven't incremented time so nothing should be received yet ts.assertNoValues(); @@ -465,14 +465,14 @@ public void testEarlyUnsubscribe() { for (int i = 0; i < 10; i++) { TestScheduler scheduler1 = Schedulers.test(); AtomicBoolean os1 = new AtomicBoolean(false); - Observable o1 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler1, os1); + Flowable o1 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler1, os1); TestScheduler scheduler2 = Schedulers.test(); AtomicBoolean os2 = new AtomicBoolean(false); - Observable o2 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); + Flowable o2 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); TestSubscriber ts = new TestSubscriber(); - Observable.merge(o1, o2).subscribe(ts); + Flowable.merge(o1, o2).subscribe(ts); // we haven't incremented time so nothing should be received yet ts.assertNoValues(); @@ -497,12 +497,12 @@ public void testEarlyUnsubscribe() { } } - private Observable createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(final Scheduler scheduler, final AtomicBoolean unsubscribed) { - return Observable.create(new Publisher() { + private Flowable createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(final Scheduler scheduler, final AtomicBoolean unsubscribed) { + return Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber child) { - Observable.interval(1, TimeUnit.SECONDS, scheduler) + Flowable.interval(1, TimeUnit.SECONDS, scheduler) .take(5) .subscribe(new Subscriber() { @Override @@ -545,10 +545,10 @@ public void onComplete() { @Test//(timeout = 10000) public void testConcurrency() { - Observable o = Observable.range(1, 10000).subscribeOn(Schedulers.newThread()); + Flowable o = Flowable.range(1, 10000).subscribeOn(Schedulers.newThread()); for (int i = 0; i < 10; i++) { - Observable merge = Observable.merge(o.onBackpressureBuffer(), o.onBackpressureBuffer(), o.onBackpressureBuffer()); + Flowable merge = Flowable.merge(o.onBackpressureBuffer(), o.onBackpressureBuffer(), o.onBackpressureBuffer()); TestSubscriber ts = new TestSubscriber(); merge.subscribe(ts); @@ -565,7 +565,7 @@ public void testConcurrency() { @Test public void testConcurrencyWithSleeping() { - Observable o = Observable.create(new Publisher() { + Flowable o = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber s) { @@ -601,7 +601,7 @@ public void run() { }); for (int i = 0; i < 10; i++) { - Observable merge = Observable.merge(o, o, o); + Flowable merge = Flowable.merge(o, o, o); TestSubscriber ts = new TestSubscriber(); merge.subscribe(ts); @@ -615,7 +615,7 @@ public void run() { @Test public void testConcurrencyWithBrokenOnCompleteContract() { - Observable o = Observable.create(new Publisher() { + Flowable o = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber s) { @@ -648,7 +648,7 @@ public void run() { }); for (int i = 0; i < 10; i++) { - Observable merge = Observable.merge(o.onBackpressureBuffer(), o.onBackpressureBuffer(), o.onBackpressureBuffer()); + Flowable merge = Flowable.merge(o.onBackpressureBuffer(), o.onBackpressureBuffer(), o.onBackpressureBuffer()); TestSubscriber ts = new TestSubscriber(); merge.subscribe(ts); @@ -664,9 +664,9 @@ public void run() { @Test public void testBackpressureUpstream() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - Observable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); + Flowable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); final AtomicInteger generated2 = new AtomicInteger(); - Observable o2 = createInfiniteObservable(generated2).subscribeOn(Schedulers.computation()); + Flowable o2 = createInfiniteObservable(generated2).subscribeOn(Schedulers.computation()); TestSubscriber testSubscriber = new TestSubscriber() { @Override @@ -676,18 +676,18 @@ public void onNext(Integer t) { } }; - Observable.merge(o1.take(Observable.bufferSize() * 2), o2.take(Observable.bufferSize() * 2)).subscribe(testSubscriber); + Flowable.merge(o1.take(Flowable.bufferSize() * 2), o2.take(Flowable.bufferSize() * 2)).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); if (testSubscriber.errors().size() > 0) { testSubscriber.errors().get(0).printStackTrace(); } testSubscriber.assertNoErrors(); System.err.println(testSubscriber.values()); - assertEquals(Observable.bufferSize() * 4, testSubscriber.values().size()); + assertEquals(Flowable.bufferSize() * 4, testSubscriber.values().size()); // it should be between the take num and requested batch size across the async boundary System.out.println("Generated 1: " + generated1.get()); System.out.println("Generated 2: " + generated2.get()); - assertTrue(generated1.get() >= Observable.bufferSize() * 2 && generated1.get() <= Observable.bufferSize() * 4); + assertTrue(generated1.get() >= Flowable.bufferSize() * 2 && generated1.get() <= Flowable.bufferSize() * 4); } @Test @@ -703,7 +703,7 @@ public void testBackpressureUpstream2InLoop() throws InterruptedException { @Test public void testBackpressureUpstream2() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - Observable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); + Flowable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); TestSubscriber testSubscriber = new TestSubscriber() { @Override @@ -712,7 +712,7 @@ public void onNext(Integer t) { } }; - Observable.merge(o1.take(Observable.bufferSize() * 2), Observable.just(-99)).subscribe(testSubscriber); + Flowable.merge(o1.take(Flowable.bufferSize() * 2), Flowable.just(-99)).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); List onNextEvents = testSubscriber.values(); @@ -724,9 +724,9 @@ public void onNext(Integer t) { testSubscriber.errors().get(0).printStackTrace(); } testSubscriber.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2 + 1, onNextEvents.size()); + assertEquals(Flowable.bufferSize() * 2 + 1, onNextEvents.size()); // it should be between the take num and requested batch size across the async boundary - assertTrue(generated1.get() >= Observable.bufferSize() * 2 && generated1.get() <= Observable.bufferSize() * 3); + assertTrue(generated1.get() >= Flowable.bufferSize() * 2 && generated1.get() <= Flowable.bufferSize() * 3); } /** @@ -738,9 +738,9 @@ public void onNext(Integer t) { @Test(timeout = 10000) public void testBackpressureDownstreamWithConcurrentStreams() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - Observable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); + Flowable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); final AtomicInteger generated2 = new AtomicInteger(); - Observable o2 = createInfiniteObservable(generated2).subscribeOn(Schedulers.computation()); + Flowable o2 = createInfiniteObservable(generated2).subscribeOn(Schedulers.computation()); TestSubscriber testSubscriber = new TestSubscriber() { @Override @@ -757,29 +757,29 @@ public void onNext(Integer t) { } }; - Observable.merge(o1.take(Observable.bufferSize() * 2), o2.take(Observable.bufferSize() * 2)).observeOn(Schedulers.computation()).subscribe(testSubscriber); + Flowable.merge(o1.take(Flowable.bufferSize() * 2), o2.take(Flowable.bufferSize() * 2)).observeOn(Schedulers.computation()).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); if (testSubscriber.errors().size() > 0) { testSubscriber.errors().get(0).printStackTrace(); } testSubscriber.assertNoErrors(); System.err.println(testSubscriber.values()); - assertEquals(Observable.bufferSize() * 4, testSubscriber.values().size()); + assertEquals(Flowable.bufferSize() * 4, testSubscriber.values().size()); // it should be between the take num and requested batch size across the async boundary System.out.println("Generated 1: " + generated1.get()); System.out.println("Generated 2: " + generated2.get()); - assertTrue(generated1.get() >= Observable.bufferSize() * 2 && generated1.get() <= Observable.bufferSize() * 4); + assertTrue(generated1.get() >= Flowable.bufferSize() * 2 && generated1.get() <= Flowable.bufferSize() * 4); } @Test public void testBackpressureBothUpstreamAndDownstreamWithSynchronousScalarObservables() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - Observable> o1 = createInfiniteObservable(generated1) - .map(new Function>() { + Flowable> o1 = createInfiniteObservable(generated1) + .map(new Function>() { @Override - public Observable apply(Integer t1) { - return Observable.just(t1); + public Flowable apply(Integer t1) { + return Flowable.just(t1); } }); @@ -799,7 +799,7 @@ public void onNext(Integer t) { } }; - Observable.merge(o1).observeOn(Schedulers.computation()).take(Observable.bufferSize() * 2).subscribe(testSubscriber); + Flowable.merge(o1).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); if (testSubscriber.errors().size() > 0) { testSubscriber.errors().get(0).printStackTrace(); @@ -807,9 +807,9 @@ public void onNext(Integer t) { testSubscriber.assertNoErrors(); System.out.println("Generated 1: " + generated1.get()); System.err.println(testSubscriber.values()); - assertEquals(Observable.bufferSize() * 2, testSubscriber.values().size()); + assertEquals(Flowable.bufferSize() * 2, testSubscriber.values().size()); // it should be between the take num and requested batch size across the async boundary - assertTrue(generated1.get() >= Observable.bufferSize() * 2 && generated1.get() <= Observable.bufferSize() * 4); + assertTrue(generated1.get() >= Flowable.bufferSize() * 2 && generated1.get() <= Flowable.bufferSize() * 4); } /** @@ -827,11 +827,11 @@ public void onNext(Integer t) { @Test(timeout = 5000) public void testBackpressureBothUpstreamAndDownstreamWithRegularObservables() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - Observable> o1 = createInfiniteObservable(generated1).map(new Function>() { + Flowable> o1 = createInfiniteObservable(generated1).map(new Function>() { @Override - public Observable apply(Integer t1) { - return Observable.just(1, 2, 3); + public Flowable apply(Integer t1) { + return Flowable.just(1, 2, 3); } }); @@ -853,7 +853,7 @@ public void onNext(Integer t) { } }; - Observable.merge(o1).observeOn(Schedulers.computation()).take(Observable.bufferSize() * 2).subscribe(testSubscriber); + Flowable.merge(o1).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(testSubscriber); testSubscriber.awaitTerminalEvent(); if (testSubscriber.errors().size() > 0) { testSubscriber.errors().get(0).printStackTrace(); @@ -862,7 +862,7 @@ public void onNext(Integer t) { System.out.println("Generated 1: " + generated1.get()); System.err.println(testSubscriber.values()); System.out.println("done1 testBackpressureBothUpstreamAndDownstreamWithRegularObservables "); - assertEquals(Observable.bufferSize() * 2, testSubscriber.values().size()); + assertEquals(Flowable.bufferSize() * 2, testSubscriber.values().size()); System.out.println("done2 testBackpressureBothUpstreamAndDownstreamWithRegularObservables "); // we can't restrict this ... see comment above // assertTrue(generated1.get() >= Observable.bufferSize() && generated1.get() <= Observable.bufferSize() * 4); @@ -873,7 +873,7 @@ public void onNext(Integer t) { public void mergeWithNullValues() { System.out.println("mergeWithNullValues"); TestSubscriber ts = new TestSubscriber(); - Observable.merge(Observable.just(null, "one"), Observable.just("two", null)).subscribe(ts); + Flowable.merge(Flowable.just(null, "one"), Flowable.just("two", null)).subscribe(ts); ts.assertTerminated(); ts.assertNoErrors(); ts.assertValues(null, "one", "two", null); @@ -884,7 +884,7 @@ public void mergeWithNullValues() { public void mergeWithTerminalEventAfterUnsubscribe() { System.out.println("mergeWithTerminalEventAfterUnsubscribe"); TestSubscriber ts = new TestSubscriber(); - Observable bad = Observable.create(new Publisher() { + Flowable bad = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -895,7 +895,7 @@ public void subscribe(Subscriber s) { } }); - Observable.merge(Observable.just(null, "one"), bad).subscribe(ts); + Flowable.merge(Flowable.just(null, "one"), bad).subscribe(ts); ts.assertNoErrors(); ts.assertValues(null, "one", "two"); } @@ -904,7 +904,7 @@ public void subscribe(Subscriber s) { @Ignore("Null values are not permitted") public void mergingNullObservable() { TestSubscriber ts = new TestSubscriber(); - Observable.merge(Observable.just("one"), null).subscribe(ts); + Flowable.merge(Flowable.just("one"), null).subscribe(ts); ts.assertNoErrors(); ts.assertValue("one"); } @@ -963,17 +963,17 @@ public void merge100AsyncStreamOf1() { assertEquals(100, ts.values().size()); } - private Observable mergeNAsyncStreamsOfN(final int outerSize, final int innerSize) { - Observable> os = Observable.range(1, outerSize) - .map(new Function>() { + private Flowable mergeNAsyncStreamsOfN(final int outerSize, final int innerSize) { + Flowable> os = Flowable.range(1, outerSize) + .map(new Function>() { @Override - public Observable apply(Integer i) { - return Observable.range(1, innerSize).subscribeOn(Schedulers.computation()); + public Flowable apply(Integer i) { + return Flowable.range(1, innerSize).subscribeOn(Schedulers.computation()); } }); - return Observable.merge(os); + return Flowable.merge(os); } @Test @@ -1021,21 +1021,21 @@ public void merge1000000SyncStreamOf1() { assertEquals(1000000, ts.values().size()); } - private Observable mergeNSyncStreamsOfN(final int outerSize, final int innerSize) { - Observable> os = Observable.range(1, outerSize) - .map(new Function>() { + private Flowable mergeNSyncStreamsOfN(final int outerSize, final int innerSize) { + Flowable> os = Flowable.range(1, outerSize) + .map(new Function>() { @Override - public Observable apply(Integer i) { - return Observable.range(1, innerSize); + public Flowable apply(Integer i) { + return Flowable.range(1, innerSize); } }); - return Observable.merge(os); + return Flowable.merge(os); } - private Observable createInfiniteObservable(final AtomicInteger generated) { - Observable observable = Observable.fromIterable(new Iterable() { + private Flowable createInfiniteObservable(final AtomicInteger generated) { + Flowable observable = Flowable.fromIterable(new Iterable() { @Override public Iterator iterator() { return new Iterator() { @@ -1062,12 +1062,12 @@ public boolean hasNext() { @Test public void mergeManyAsyncSingle() { TestSubscriber ts = new TestSubscriber(); - Observable> os = Observable.range(1, 10000) - .map(new Function>() { + Flowable> os = Flowable.range(1, 10000) + .map(new Function>() { @Override - public Observable apply(final Integer i) { - return Observable.create(new Publisher() { + public Flowable apply(final Integer i) { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -1087,7 +1087,7 @@ public void subscribe(Subscriber s) { } }); - Observable.merge(os).subscribe(ts); + Flowable.merge(os).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); assertEquals(10000, ts.values().size()); @@ -1095,7 +1095,7 @@ public void subscribe(Subscriber s) { @Test public void shouldCompleteAfterApplyingBackpressure_NormalPath() { - Observable source = Observable.mergeDelayError(Observable.just(Observable.range(1, 2))); + Flowable source = Flowable.mergeDelayError(Flowable.just(Flowable.range(1, 2))); TestSubscriber subscriber = new TestSubscriber((Long)null); source.subscribe(subscriber); subscriber.request(3); // 1, 2, - with request(2) we get the 1 and 2 but not the @@ -1105,7 +1105,7 @@ public void shouldCompleteAfterApplyingBackpressure_NormalPath() { @Test public void shouldCompleteAfterApplyingBackpressure_FastPath() { - Observable source = Observable.mergeDelayError(Observable.just(Observable.just(1))); + Flowable source = Flowable.mergeDelayError(Flowable.just(Flowable.just(1))); TestSubscriber subscriber = new TestSubscriber((Long)null); source.subscribe(subscriber); subscriber.request(2); // 1, - should work as per .._NormalPath above @@ -1116,7 +1116,7 @@ public void shouldCompleteAfterApplyingBackpressure_FastPath() { @Test public void shouldNotCompleteIfThereArePendingScalarSynchronousEmissionsWhenTheLastInnerSubscriberCompletes() { TestScheduler scheduler = Schedulers.test(); - Observable source = Observable.mergeDelayError(Observable.just(1L), Observable.timer(1, TimeUnit.SECONDS, scheduler).skip(1)); + Flowable source = Flowable.mergeDelayError(Flowable.just(1L), Flowable.timer(1, TimeUnit.SECONDS, scheduler).skip(1)); TestSubscriber subscriber = new TestSubscriber((Long)null); source.subscribe(subscriber); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); @@ -1133,7 +1133,7 @@ public void shouldNotCompleteIfThereArePendingScalarSynchronousEmissionsWhenTheL @Test public void delayedErrorsShouldBeEmittedWhenCompleteAfterApplyingBackpressure_NormalPath() { Throwable exception = new Throwable(); - Observable source = Observable.mergeDelayError(Observable.range(1, 2), Observable.error(exception)); + Flowable source = Flowable.mergeDelayError(Flowable.range(1, 2), Flowable.error(exception)); TestSubscriber subscriber = new TestSubscriber((Long)null); source.subscribe(subscriber); subscriber.request(3); // 1, 2, @@ -1145,7 +1145,7 @@ public void delayedErrorsShouldBeEmittedWhenCompleteAfterApplyingBackpressure_No @Test public void delayedErrorsShouldBeEmittedWhenCompleteAfterApplyingBackpressure_FastPath() { Throwable exception = new Throwable(); - Observable source = Observable.mergeDelayError(Observable.just(1), Observable.error(exception)); + Flowable source = Flowable.mergeDelayError(Flowable.just(1), Flowable.error(exception)); TestSubscriber subscriber = new TestSubscriber((Long)null); source.subscribe(subscriber); subscriber.request(2); // 1, @@ -1156,7 +1156,7 @@ public void delayedErrorsShouldBeEmittedWhenCompleteAfterApplyingBackpressure_Fa @Test public void shouldNotCompleteWhileThereAreStillScalarSynchronousEmissionsInTheQueue() { - Observable source = Observable.merge(Observable.just(1), Observable.just(2)); + Flowable source = Flowable.merge(Flowable.just(1), Flowable.just(2)); TestSubscriber subscriber = new TestSubscriber(1L); source.subscribe(subscriber); subscriber.assertValue(1); @@ -1167,7 +1167,7 @@ public void shouldNotCompleteWhileThereAreStillScalarSynchronousEmissionsInTheQu @Test public void shouldNotReceivedDelayedErrorWhileThereAreStillScalarSynchronousEmissionsInTheQueue() { Throwable exception = new Throwable(); - Observable source = Observable.mergeDelayError(Observable.just(1), Observable.just(2), Observable.error(exception)); + Flowable source = Flowable.mergeDelayError(Flowable.just(1), Flowable.just(2), Flowable.error(exception)); TestSubscriber subscriber = new TestSubscriber((Long)null); subscriber.request(1); source.subscribe(subscriber); @@ -1181,7 +1181,7 @@ public void shouldNotReceivedDelayedErrorWhileThereAreStillScalarSynchronousEmis @Test public void shouldNotReceivedDelayedErrorWhileThereAreStillNormalEmissionsInTheQueue() { Throwable exception = new Throwable(); - Observable source = Observable.mergeDelayError(Observable.range(1, 2), Observable.range(3, 2), Observable.error(exception)); + Flowable source = Flowable.mergeDelayError(Flowable.range(1, 2), Flowable.range(3, 2), Flowable.error(exception)); TestSubscriber subscriber = new TestSubscriber((Long)null); subscriber.request(3); source.subscribe(subscriber); @@ -1199,12 +1199,12 @@ public void testMergeKeepsRequesting() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final ConcurrentLinkedQueue messages = new ConcurrentLinkedQueue(); - Observable.range(1, 2) + Flowable.range(1, 2) // produce many integers per second - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public Observable apply(final Integer number) { - return Observable.range(1, Integer.MAX_VALUE) + public Flowable apply(final Integer number) { + return Flowable.range(1, Integer.MAX_VALUE) .doOnRequest(new LongConsumer() { @Override @@ -1231,7 +1231,7 @@ public void accept(long n) { }) // take a number bigger than 2* Observable.bufferSize() (used by OperatorMerge) - .take(Observable.bufferSize() * 2 + 1) + .take(Flowable.bufferSize() * 2 + 1) // log count .doOnNext(printCount()) // release latch @@ -1254,11 +1254,11 @@ public void run() { @Test public void testMergeRequestOverflow() throws InterruptedException { //do a non-trivial merge so that future optimisations with EMPTY don't invalidate this test - Observable o = Observable.fromIterable(Arrays.asList(1,2)) - .mergeWith(Observable.fromIterable(Arrays.asList(3,4))); + Flowable o = Flowable.fromIterable(Arrays.asList(1,2)) + .mergeWith(Flowable.fromIterable(Arrays.asList(3,4))); final int expectedCount = 4; final CountDownLatch latch = new CountDownLatch(expectedCount); - o.subscribeOn(Schedulers.computation()).subscribe(new Observer() { + o.subscribeOn(Schedulers.computation()).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -1309,27 +1309,27 @@ public void accept(Integer s) { }; } - Function> toScalar = new Function>() { + Function> toScalar = new Function>() { @Override - public Observable apply(Integer v) { - return Observable.just(v); + public Flowable apply(Integer v) { + return Flowable.just(v); } }; - Function> toHiddenScalar = new Function>() { + Function> toHiddenScalar = new Function>() { @Override - public Observable apply(Integer t) { - return Observable.just(t).asObservable(); + public Flowable apply(Integer t) { + return Flowable.just(t).asObservable(); } }; ; - void runMerge(Function> func, TestSubscriber ts) { + void runMerge(Function> func, TestSubscriber ts) { List list = new ArrayList(); for (int i = 0; i < 1000; i++) { list.add(i); } - Observable source = Observable.fromIterable(list); + Flowable source = Flowable.fromIterable(list); source.flatMap(func).subscribe(ts); if (ts.values().size() != 1000) { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorMulticastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMulticastTest.java similarity index 98% rename from src/test/java/io/reactivex/internal/operators/OperatorMulticastTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorMulticastTest.java index 32676aca4d..de4dd97802 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorMulticastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorMulticastTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; public class OperatorMulticastTest { // FIXME operator multicast not supported diff --git a/src/test/java/io/reactivex/internal/operators/OperatorObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorObserveOnTest.java similarity index 89% rename from src/test/java/io/reactivex/internal/operators/OperatorObserveOnTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorObserveOnTest.java index 8e5d91271e..a6c9ca0439 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorObserveOnTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,15 +25,15 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.Optional; -import io.reactivex.Observable; -import io.reactivex.Observer; import io.reactivex.*; +import io.reactivex.Optional; import io.reactivex.exceptions.*; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; public class OperatorObserveOnTest { @@ -46,7 +46,7 @@ public class OperatorObserveOnTest { @Ignore("immediate scheduler not supported") public void testObserveOn() { Subscriber observer = TestHelper.mockSubscriber(); - Observable.just(1, 2, 3).observeOn(Schedulers.immediate()).subscribe(observer); + Flowable.just(1, 2, 3).observeOn(Schedulers.immediate()).subscribe(observer); verify(observer, times(1)).onNext(1); verify(observer, times(1)).onNext(2); @@ -58,7 +58,7 @@ public void testObserveOn() { public void testOrdering() throws InterruptedException { // Observable obs = Observable.just("one", null, "two", "three", "four"); // FIXME null values not allowed - Observable obs = Observable.just("one", "null", "two", "three", "four"); + Flowable obs = Flowable.just("one", "null", "two", "three", "four"); Subscriber observer = TestHelper.mockSubscriber(); @@ -89,7 +89,7 @@ public void testThreadName() throws InterruptedException { System.out.println("Main Thread: " + Thread.currentThread().getName()); // FIXME null values not allowed // Observable obs = Observable.just("one", null, "two", "three", "four"); - Observable obs = Observable.just("one", "null", "two", "three", "four"); + Flowable obs = Flowable.just("one", "null", "two", "three", "four"); Subscriber observer = TestHelper.mockSubscriber(); final String parentThreadName = Thread.currentThread().getName(); @@ -143,13 +143,13 @@ public void run() { public void observeOnTheSameSchedulerTwice() { Scheduler scheduler = Schedulers.immediate(); - Observable o = Observable.just(1, 2, 3); - Observable o2 = o.observeOn(scheduler); + Flowable o = Flowable.just(1, 2, 3); + Flowable o2 = o.observeOn(scheduler); @SuppressWarnings("unchecked") - Observer observer1 = mock(Observer.class); + DefaultObserver observer1 = mock(DefaultObserver.class); @SuppressWarnings("unchecked") - Observer observer2 = mock(Observer.class); + DefaultObserver observer2 = mock(DefaultObserver.class); InOrder inOrder1 = inOrder(observer1); InOrder inOrder2 = inOrder(observer2); @@ -177,9 +177,9 @@ public void observeSameOnMultipleSchedulers() { TestScheduler scheduler1 = new TestScheduler(); TestScheduler scheduler2 = new TestScheduler(); - Observable o = Observable.just(1, 2, 3); - Observable o1 = o.observeOn(scheduler1); - Observable o2 = o.observeOn(scheduler2); + Flowable o = Flowable.just(1, 2, 3); + Flowable o1 = o.observeOn(scheduler1); + Flowable o2 = o.observeOn(scheduler2); Subscriber observer1 = TestHelper.mockSubscriber(); Subscriber observer2 = TestHelper.mockSubscriber(); @@ -216,7 +216,7 @@ public void testObserveOnWithNewThreadScheduler() { final AtomicInteger count = new AtomicInteger(); final int _multiple = 99; - Observable.range(1, 100000).map(new Function() { + Flowable.range(1, 100000).map(new Function() { @Override public Integer apply(Integer t1) { @@ -246,7 +246,7 @@ public void testObserveOnWithThreadPoolScheduler() { final AtomicInteger count = new AtomicInteger(); final int _multiple = 99; - Observable.range(1, 100000).map(new Function() { + Flowable.range(1, 100000).map(new Function() { @Override public Integer apply(Integer t1) { @@ -281,7 +281,7 @@ public void testObserveOnOrderingConcurrency() { final AtomicInteger count = new AtomicInteger(); final int _multiple = 99; - Observable.range(1, 10000).map(new Function() { + Flowable.range(1, 10000).map(new Function() { @Override public Integer apply(Integer t1) { @@ -317,7 +317,7 @@ public void testNonBlockingOuterWhileBlockingOnNext() throws InterruptedExceptio final CountDownLatch nextLatch = new CountDownLatch(1); final AtomicLong completeTime = new AtomicLong(); // use subscribeOn to make async, observeOn to move - Observable.range(1, 2).subscribeOn(Schedulers.newThread()).observeOn(Schedulers.newThread()).subscribe(new Observer() { + Flowable.range(1, 2).subscribeOn(Schedulers.newThread()).observeOn(Schedulers.newThread()).subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -367,10 +367,10 @@ private static int randomIntFrom0to100() { public void testDelayedErrorDeliveryWhenSafeSubscriberUnsubscribes() { TestScheduler testScheduler = new TestScheduler(); - Observable source = Observable.concat(Observable. error(new TestException()), Observable.just(1)); + Flowable source = Flowable.concat(Flowable. error(new TestException()), Flowable.just(1)); @SuppressWarnings("unchecked") - Observer o = mock(Observer.class); + DefaultObserver o = mock(DefaultObserver.class); InOrder inOrder = inOrder(o); source.observeOn(testScheduler).subscribe(o); @@ -391,7 +391,7 @@ public void testAfterUnsubscribeCalledThenObserverOnNextNeverCalled() { final Subscriber observer = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(observer); - Observable.just(1, 2, 3) + Flowable.just(1, 2, 3) .observeOn(testScheduler) .subscribe(ts); @@ -408,7 +408,7 @@ public void testAfterUnsubscribeCalledThenObserverOnNextNeverCalled() { @Test public void testBackpressureWithTakeAfter() { final AtomicInteger generated = new AtomicInteger(); - Observable observable = Observable.fromIterable(new Iterable() { + Flowable observable = Flowable.fromIterable(new Iterable() { @Override public Iterator iterator() { return new Iterator() { @@ -451,14 +451,14 @@ public void onNext(Integer t) { testSubscriber.assertValues(0, 1, 2); // it should be between the take num and requested batch size across the async boundary System.out.println("Generated: " + generated.get()); - assertTrue(generated.get() >= 3 && generated.get() <= Observable.bufferSize()); + assertTrue(generated.get() >= 3 && generated.get() <= Flowable.bufferSize()); } @Test public void testBackpressureWithTakeAfterAndMultipleBatches() { - int numForBatches = Observable.bufferSize() * 3 + 1; // should be 4 batches == ((3*n)+1) items + int numForBatches = Flowable.bufferSize() * 3 + 1; // should be 4 batches == ((3*n)+1) items final AtomicInteger generated = new AtomicInteger(); - Observable observable = Observable.fromIterable(new Iterable() { + Flowable observable = Flowable.fromIterable(new Iterable() { @Override public Iterator iterator() { return new Iterator() { @@ -496,13 +496,13 @@ public void onNext(Integer t) { System.err.println(testSubscriber.values()); // it should be between the take num and requested batch size across the async boundary System.out.println("Generated: " + generated.get()); - assertTrue(generated.get() >= numForBatches && generated.get() <= numForBatches + Observable.bufferSize()); + assertTrue(generated.get() >= numForBatches && generated.get() <= numForBatches + Flowable.bufferSize()); } @Test public void testBackpressureWithTakeBefore() { final AtomicInteger generated = new AtomicInteger(); - Observable observable = Observable.fromIterable(new Iterable() { + Flowable observable = Flowable.fromIterable(new Iterable() { @Override public Iterator iterator() { return new Iterator() { @@ -538,12 +538,12 @@ public boolean hasNext() { @Test public void testQueueFullEmitsError() { final CountDownLatch latch = new CountDownLatch(1); - Observable observable = Observable.create(new Publisher() { + Flowable observable = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber o) { o.onSubscribe(EmptySubscription.INSTANCE); - for (int i = 0; i < Observable.bufferSize() + 10; i++) { + for (int i = 0; i < Flowable.bufferSize() + 10; i++) { o.onNext(i); } latch.countDown(); @@ -552,7 +552,7 @@ public void subscribe(Subscriber o) { }); - TestSubscriber testSubscriber = new TestSubscriber(new Observer() { + TestSubscriber testSubscriber = new TestSubscriber(new DefaultObserver() { @Override public void onComplete() { @@ -596,7 +596,7 @@ public void onNext(Integer t) { @Test public void testAsyncChild() { TestSubscriber ts = new TestSubscriber(); - Observable.range(0, 100000).observeOn(Schedulers.newThread()).observeOn(Schedulers.newThread()).subscribe(ts); + Flowable.range(0, 100000).observeOn(Schedulers.newThread()).observeOn(Schedulers.newThread()).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); } @@ -604,10 +604,10 @@ public void testAsyncChild() { @Test public void testOnErrorCutsAheadOfOnNext() { for (int i = 0; i < 50; i++) { - final PublishSubject subject = PublishSubject.create(); + final PublishProcessor subject = PublishProcessor.create(); final AtomicLong counter = new AtomicLong(); - TestSubscriber ts = new TestSubscriber(new Observer() { + TestSubscriber ts = new TestSubscriber(new DefaultObserver() { @Override public void onComplete() { @@ -645,7 +645,7 @@ public void onNext(Long t) { List onNextEvents = ts.values(); assertTrue(onNextEvents.isEmpty() || onNextEvents.size() == onNextEvents.get(onNextEvents.size() - 1) + 1); // we should emit the error without emitting the full buffer size - assertTrue(onNextEvents.size() < Observable.bufferSize()); + assertTrue(onNextEvents.size() < Flowable.bufferSize()); } } @@ -655,7 +655,7 @@ public void onNext(Long t) { @Test public void testHotOperatorBackpressure() { TestSubscriber ts = new TestSubscriber(); - Observable.interval(0, 1, TimeUnit.MICROSECONDS) + Flowable.interval(0, 1, TimeUnit.MICROSECONDS) .observeOn(Schedulers.computation()) .map(new Function() { @@ -679,7 +679,7 @@ public String apply(Long t1) { @Test public void testErrorPropagatesWhenNoOutstandingRequests() { - Observable timer = Observable.interval(0, 1, TimeUnit.MICROSECONDS) + Flowable timer = Flowable.interval(0, 1, TimeUnit.MICROSECONDS) .doOnEach(new Consumer>>() { @Override @@ -704,14 +704,14 @@ public void accept(Try> n) { TestSubscriber ts = new TestSubscriber(); - Observable.combineLatest(timer, Observable. never(), new BiFunction() { + Flowable.combineLatest(timer, Flowable. never(), new BiFunction() { @Override public Long apply(Long t1, Integer t2) { return t1; } - }).take(Observable.bufferSize() * 2).subscribe(ts); + }).take(Flowable.bufferSize() * 2).subscribe(ts); ts.awaitTerminalEvent(); assertEquals(1, ts.errors().size()); @@ -723,8 +723,8 @@ public void testRequestOverflow() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicInteger count = new AtomicInteger(); - Observable.range(1, 100).observeOn(Schedulers.computation()) - .subscribe(new Observer() { + Flowable.range(1, 100).observeOn(Schedulers.computation()) + .subscribe(new DefaultObserver() { boolean first = true; @@ -763,7 +763,7 @@ public void onNext(Integer t) { public void testNoMoreRequestsAfterUnsubscribe() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final List requests = Collections.synchronizedList(new ArrayList()); - Observable.range(1, 1000000) + Flowable.range(1, 1000000) .doOnRequest(new LongConsumer() { @Override @@ -772,7 +772,7 @@ public void accept(long n) { } }) .observeOn(Schedulers.io()) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onStart() { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorOnBackpressureBufferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureBufferTest.java similarity index 90% rename from src/test/java/io/reactivex/internal/operators/OperatorOnBackpressureBufferTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureBufferTest.java index 548c70da4e..4bf2e03547 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorOnBackpressureBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureBufferTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; @@ -20,11 +20,11 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.MissingBackpressureException; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class OperatorOnBackpressureBufferTest { @@ -44,7 +44,7 @@ public void testNoBackpressureSupport() { public void testFixBackpressureWithBuffer() throws InterruptedException { final CountDownLatch l1 = new CountDownLatch(100); final CountDownLatch l2 = new CountDownLatch(150); - TestSubscriber ts = new TestSubscriber(new Observer() { + TestSubscriber ts = new TestSubscriber(new DefaultObserver() { @Override protected void onStart() { @@ -89,19 +89,19 @@ public void onNext(Long t) { @Test(expected = IllegalArgumentException.class) public void testFixBackpressureBufferNegativeCapacity() throws InterruptedException { - Observable.empty().onBackpressureBuffer(-1); + Flowable.empty().onBackpressureBuffer(-1); } @Test(expected = IllegalArgumentException.class) public void testFixBackpressureBufferZeroCapacity() throws InterruptedException { - Observable.empty().onBackpressureBuffer(0); + Flowable.empty().onBackpressureBuffer(0); } @Test public void testFixBackpressureBoundedBuffer() throws InterruptedException { final CountDownLatch l1 = new CountDownLatch(100); final CountDownLatch backpressureCallback = new CountDownLatch(1); - TestSubscriber ts = new TestSubscriber(new Observer() { + TestSubscriber ts = new TestSubscriber(new DefaultObserver() { @Override protected void onStart() { @@ -145,7 +145,7 @@ public void run() { // assertTrue(s.isUnsubscribed()); } - static final Observable infinite = Observable.create(new Publisher() { + static final Flowable infinite = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorOnBackpressureDropTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureDropTest.java similarity index 87% rename from src/test/java/io/reactivex/internal/operators/OperatorOnBackpressureDropTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureDropTest.java index 8c0dab953f..3883f74734 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorOnBackpressureDropTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureDropTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; @@ -21,10 +21,10 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class OperatorOnBackpressureDropTest { @@ -43,7 +43,7 @@ public void testNoBackpressureSupport() { @Test(timeout = 500) public void testWithObserveOn() throws InterruptedException { TestSubscriber ts = new TestSubscriber(); - Observable.range(0, Observable.bufferSize() * 10).onBackpressureDrop().observeOn(Schedulers.io()).subscribe(ts); + Flowable.range(0, Flowable.bufferSize() * 10).onBackpressureDrop().observeOn(Schedulers.io()).subscribe(ts); ts.awaitTerminalEvent(); } @@ -51,7 +51,7 @@ public void testWithObserveOn() throws InterruptedException { public void testFixBackpressureWithBuffer() throws InterruptedException { final CountDownLatch l1 = new CountDownLatch(100); final CountDownLatch l2 = new CountDownLatch(150); - TestSubscriber ts = new TestSubscriber(new Observer() { + TestSubscriber ts = new TestSubscriber(new DefaultObserver() { @Override protected void onStart() { @@ -93,7 +93,7 @@ public void onNext(Long t) { public void testRequestOverflow() throws InterruptedException { final AtomicInteger count = new AtomicInteger(); int n = 10; - range(n).onBackpressureDrop().subscribe(new Observer() { + range(n).onBackpressureDrop().subscribe(new DefaultObserver() { @Override public void onStart() { @@ -118,7 +118,7 @@ public void onNext(Long t) { assertEquals(n, count.get()); } - static final Observable infinite = Observable.create(new Publisher() { + static final Flowable infinite = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -132,8 +132,8 @@ public void subscribe(Subscriber s) { }); - private static final Observable range(final long n) { - return Observable.create(new Publisher() { + private static final Flowable range(final long n) { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorOnBackpressureLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureLatestTest.java similarity index 88% rename from src/test/java/io/reactivex/internal/operators/OperatorOnBackpressureLatestTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureLatestTest.java index 49ff71098b..71ca8e4ed5 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorOnBackpressureLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnBackpressureLatestTest.java @@ -11,17 +11,17 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.Random; import java.util.concurrent.TimeUnit; import org.junit.*; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.TestSubscriber; public class OperatorOnBackpressureLatestTest { @@ -29,7 +29,7 @@ public class OperatorOnBackpressureLatestTest { public void testSimple() { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, 5).onBackpressureLatest().subscribe(ts); + Flowable.range(1, 5).onBackpressureLatest().subscribe(ts); ts.assertNoErrors(); ts.assertTerminated(); @@ -39,7 +39,7 @@ public void testSimple() { public void testSimpleError() { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, 5).concatWith(Observable.error(new TestException())) + Flowable.range(1, 5).concatWith(Flowable.error(new TestException())) .onBackpressureLatest().subscribe(ts); ts.assertTerminated(); @@ -50,7 +50,7 @@ public void testSimpleError() { public void testSimpleBackpressure() { TestSubscriber ts = new TestSubscriber(2L); - Observable.range(1, 5).onBackpressureLatest().subscribe(ts); + Flowable.range(1, 5).onBackpressureLatest().subscribe(ts); ts.assertNoErrors(); ts.assertValues(1, 2); @@ -59,7 +59,7 @@ public void testSimpleBackpressure() { @Test public void testSynchronousDrop() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber((Long)null); source.onBackpressureLatest().subscribe(ts); @@ -116,7 +116,7 @@ public void onNext(Integer t) { } }; int m = 100000; - Observable.range(1, m) + Flowable.range(1, m) .subscribeOn(Schedulers.computation()) .onBackpressureLatest() .observeOn(Schedulers.io()) diff --git a/src/test/java/io/reactivex/internal/operators/OperatorOnErrorResumeNextViaFunctionTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnErrorResumeNextViaFunctionTest.java similarity index 80% rename from src/test/java/io/reactivex/internal/operators/OperatorOnErrorResumeNextViaFunctionTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorOnErrorResumeNextViaFunctionTest.java index aae1550b65..192a13e658 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorOnErrorResumeNextViaFunctionTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnErrorResumeNextViaFunctionTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -23,19 +23,20 @@ import org.mockito.Mockito; import org.reactivestreams.*; -import io.reactivex.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable; +import io.reactivex.Flowable.Operator; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.EmptySubscription; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class OperatorOnErrorResumeNextViaFunctionTest { @Test public void testResumeNextWithSynchronousExecution() { final AtomicReference receivedException = new AtomicReference(); - Observable w = Observable.create(new Publisher() { + Flowable w = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { @@ -47,16 +48,16 @@ public void subscribe(Subscriber observer) { } }); - Function> resume = new Function>() { + Function> resume = new Function>() { @Override - public Observable apply(Throwable t1) { + public Flowable apply(Throwable t1) { receivedException.set(t1); - return Observable.just("twoResume", "threeResume"); + return Flowable.just("twoResume", "threeResume"); } }; - Observable observable = w.onErrorResumeNext(resume); + Flowable observable = w.onErrorResumeNext(resume); Subscriber observer = TestHelper.mockSubscriber(); @@ -77,16 +78,16 @@ public void testResumeNextWithAsyncExecution() { final AtomicReference receivedException = new AtomicReference(); Subscription s = mock(Subscription.class); TestObservable w = new TestObservable(s, "one"); - Function> resume = new Function>() { + Function> resume = new Function>() { @Override - public Observable apply(Throwable t1) { + public Flowable apply(Throwable t1) { receivedException.set(t1); - return Observable.just("twoResume", "threeResume"); + return Flowable.just("twoResume", "threeResume"); } }; - Observable observable = Observable.create(w).onErrorResumeNext(resume); + Flowable observable = Flowable.create(w).onErrorResumeNext(resume); Subscriber observer = TestHelper.mockSubscriber(); @@ -115,18 +116,18 @@ public Observable apply(Throwable t1) { public void testFunctionThrowsError() { Subscription s = mock(Subscription.class); TestObservable w = new TestObservable(s, "one"); - Function> resume = new Function>() { + Function> resume = new Function>() { @Override - public Observable apply(Throwable t1) { + public Flowable apply(Throwable t1) { throw new RuntimeException("exception from function"); } }; - Observable observable = Observable.create(w).onErrorResumeNext(resume); + Flowable observable = Flowable.create(w).onErrorResumeNext(resume); @SuppressWarnings("unchecked") - Observer observer = mock(Observer.class); + DefaultObserver observer = mock(DefaultObserver.class); observable.subscribe(observer); try { @@ -151,21 +152,21 @@ public Observable apply(Throwable t1) { @Ignore("Failed operator may leave the child subscriber in an inconsistent state which prevents further error delivery.") public void testOnErrorResumeReceivesErrorFromPreviousNonProtectedOperator() { TestSubscriber ts = new TestSubscriber(); - Observable.just(1).lift(new Operator() { + Flowable.just(1).lift(new Operator() { @Override public Subscriber apply(Subscriber t1) { throw new RuntimeException("failed"); } - }).onErrorResumeNext(new Function>() { + }).onErrorResumeNext(new Function>() { @Override - public Observable apply(Throwable t1) { + public Flowable apply(Throwable t1) { if (t1.getMessage().equals("failed")) { - return Observable.just("success"); + return Flowable.just("success"); } else { - return Observable.error(t1); + return Flowable.error(t1); } } @@ -184,7 +185,7 @@ public Observable apply(Throwable t1) { @Ignore("A crashing operator may leave the downstream in an inconsistent state and not suitable for event delivery") public void testOnErrorResumeReceivesErrorFromPreviousNonProtectedOperatorOnNext() { TestSubscriber ts = new TestSubscriber(); - Observable.just(1).lift(new Operator() { + Flowable.just(1).lift(new Operator() { @Override public Subscriber apply(final Subscriber t1) { @@ -213,14 +214,14 @@ public void onNext(Integer t) { }; } - }).onErrorResumeNext(new Function>() { + }).onErrorResumeNext(new Function>() { @Override - public Observable apply(Throwable t1) { + public Flowable apply(Throwable t1) { if (t1.getMessage().equals("failed")) { - return Observable.just("success"); + return Flowable.just("success"); } else { - return Observable.error(t1); + return Flowable.error(t1); } } @@ -234,7 +235,7 @@ public Observable apply(Throwable t1) { @Test public void testMapResumeAsyncNext() { // Trigger multiple failures - Observable w = Observable.just("one", "fail", "two", "three", "fail"); + Flowable w = Flowable.just("one", "fail", "two", "three", "fail"); // Introduce map function that fails intermittently (Map does not prevent this when the observer is a // rx.operator incl onErrorResumeNextViaObservable) @@ -248,17 +249,17 @@ public String apply(String s) { } }); - Observable observable = w.onErrorResumeNext(new Function>() { + Flowable observable = w.onErrorResumeNext(new Function>() { @Override - public Observable apply(Throwable t1) { - return Observable.just("twoResume", "threeResume").subscribeOn(Schedulers.computation()); + public Flowable apply(Throwable t1) { + return Flowable.just("twoResume", "threeResume").subscribeOn(Schedulers.computation()); } }); @SuppressWarnings("unchecked") - Observer observer = mock(Observer.class); + DefaultObserver observer = mock(DefaultObserver.class); TestSubscriber ts = new TestSubscriber(observer, Long.MAX_VALUE); observable.subscribe(ts); @@ -313,12 +314,12 @@ public void run() { @Test public void testBackpressure() { TestSubscriber ts = new TestSubscriber(); - Observable.range(0, 100000) - .onErrorResumeNext(new Function>() { + Flowable.range(0, 100000) + .onErrorResumeNext(new Function>() { @Override - public Observable apply(Throwable t1) { - return Observable.just(1); + public Flowable apply(Throwable t1) { + return Flowable.just(1); } }) diff --git a/src/test/java/io/reactivex/internal/operators/OperatorOnErrorResumeNextViaObservableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnErrorResumeNextViaObservableTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/OperatorOnErrorResumeNextViaObservableTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorOnErrorResumeNextViaObservableTest.java index e77335b9d3..3d7da7e3c3 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorOnErrorResumeNextViaObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnErrorResumeNextViaObservableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -21,10 +21,11 @@ import org.mockito.Mockito; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class OperatorOnErrorResumeNextViaObservableTest { @@ -33,9 +34,9 @@ public void testResumeNext() { Subscription s = mock(Subscription.class); // Trigger failure on second element TestObservable f = new TestObservable(s, "one", "fail", "two", "three"); - Observable w = Observable.create(f); - Observable resume = Observable.just("twoResume", "threeResume"); - Observable observable = w.onErrorResumeNext(resume); + Flowable w = Flowable.create(f); + Flowable resume = Flowable.just("twoResume", "threeResume"); + Flowable observable = w.onErrorResumeNext(resume); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -59,10 +60,10 @@ public void testResumeNext() { public void testMapResumeAsyncNext() { Subscription sr = mock(Subscription.class); // Trigger multiple failures - Observable w = Observable.just("one", "fail", "two", "three", "fail"); + Flowable w = Flowable.just("one", "fail", "two", "three", "fail"); // Resume Observable is async TestObservable f = new TestObservable(sr, "twoResume", "threeResume"); - Observable resume = Observable.create(f); + Flowable resume = Flowable.create(f); // Introduce map function that fails intermittently (Map does not prevent this when the observer is a // rx.operator incl onErrorResumeNextViaObservable) @@ -76,7 +77,7 @@ public String apply(String s) { } }); - Observable observable = w.onErrorResumeNext(resume); + Flowable observable = w.onErrorResumeNext(resume); Subscriber observer = TestHelper.mockSubscriber(); @@ -100,7 +101,7 @@ public String apply(String s) { @Test @Ignore("Publishers should not throw") public void testResumeNextWithFailureOnSubscribe() { - Observable testObservable = Observable.create(new Publisher() { + Flowable testObservable = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber t1) { @@ -108,8 +109,8 @@ public void subscribe(Subscriber t1) { } }); - Observable resume = Observable.just("resume"); - Observable observable = testObservable.onErrorResumeNext(resume); + Flowable resume = Flowable.just("resume"); + Flowable observable = testObservable.onErrorResumeNext(resume); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -122,7 +123,7 @@ public void subscribe(Subscriber t1) { @Test @Ignore("Publishers should not throw") public void testResumeNextWithFailureOnSubscribeAsync() { - Observable testObservable = Observable.create(new Publisher() { + Flowable testObservable = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber t1) { @@ -130,11 +131,11 @@ public void subscribe(Subscriber t1) { } }); - Observable resume = Observable.just("resume"); - Observable observable = testObservable.subscribeOn(Schedulers.io()).onErrorResumeNext(resume); + Flowable resume = Flowable.just("resume"); + Flowable observable = testObservable.subscribeOn(Schedulers.io()).onErrorResumeNext(resume); @SuppressWarnings("unchecked") - Observer observer = mock(Observer.class); + DefaultObserver observer = mock(DefaultObserver.class); TestSubscriber ts = new TestSubscriber(observer, Long.MAX_VALUE); observable.subscribe(ts); @@ -190,8 +191,8 @@ public void run() { @Test public void testBackpressure() { TestSubscriber ts = new TestSubscriber(); - Observable.range(0, 100000) - .onErrorResumeNext(Observable.just(1)) + Flowable.range(0, 100000) + .onErrorResumeNext(Flowable.just(1)) .observeOn(Schedulers.computation()) .map(new Function() { int c = 0; diff --git a/src/test/java/io/reactivex/internal/operators/OperatorOnErrorReturnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnErrorReturnTest.java similarity index 89% rename from src/test/java/io/reactivex/internal/operators/OperatorOnErrorReturnTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorOnErrorReturnTest.java index a830da3716..1c11e3213f 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorOnErrorReturnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnErrorReturnTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -23,21 +23,21 @@ import org.mockito.Mockito; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.EmptySubscription; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class OperatorOnErrorReturnTest { @Test public void testResumeNext() { TestObservable f = new TestObservable("one"); - Observable w = Observable.create(f); + Flowable w = Flowable.create(f); final AtomicReference capturedException = new AtomicReference(); - Observable observable = w.onErrorReturn(new Function() { + Flowable observable = w.onErrorReturn(new Function() { @Override public String apply(Throwable e) { @@ -48,7 +48,7 @@ public String apply(Throwable e) { }); @SuppressWarnings("unchecked") - Observer observer = mock(Observer.class); + DefaultObserver observer = mock(DefaultObserver.class); observable.subscribe(observer); try { @@ -70,10 +70,10 @@ public String apply(Throwable e) { @Test public void testFunctionThrowsError() { TestObservable f = new TestObservable("one"); - Observable w = Observable.create(f); + Flowable w = Flowable.create(f); final AtomicReference capturedException = new AtomicReference(); - Observable observable = w.onErrorReturn(new Function() { + Flowable observable = w.onErrorReturn(new Function() { @Override public String apply(Throwable e) { @@ -84,7 +84,7 @@ public String apply(Throwable e) { }); @SuppressWarnings("unchecked") - Observer observer = mock(Observer.class); + DefaultObserver observer = mock(DefaultObserver.class); observable.subscribe(observer); try { @@ -105,7 +105,7 @@ public String apply(Throwable e) { @Test public void testMapResumeAsyncNext() { // Trigger multiple failures - Observable w = Observable.just("one", "fail", "two", "three", "fail"); + Flowable w = Flowable.just("one", "fail", "two", "three", "fail"); // Introduce map function that fails intermittently (Map does not prevent this when the observer is a // rx.operator incl onErrorResumeNextViaObservable) @@ -119,7 +119,7 @@ public String apply(String s) { } }); - Observable observable = w.onErrorReturn(new Function() { + Flowable observable = w.onErrorReturn(new Function() { @Override public String apply(Throwable t1) { @@ -129,7 +129,7 @@ public String apply(Throwable t1) { }); @SuppressWarnings("unchecked") - Observer observer = mock(Observer.class); + DefaultObserver observer = mock(DefaultObserver.class); TestSubscriber ts = new TestSubscriber(observer, Long.MAX_VALUE); observable.subscribe(ts); ts.awaitTerminalEvent(); @@ -145,7 +145,7 @@ public String apply(Throwable t1) { @Test public void testBackpressure() { TestSubscriber ts = new TestSubscriber(); - Observable.range(0, 100000) + Flowable.range(0, 100000) .onErrorReturn(new Function() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/OperatorOnExceptionResumeNextViaObservableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnExceptionResumeNextViaObservableTest.java similarity index 88% rename from src/test/java/io/reactivex/internal/operators/OperatorOnExceptionResumeNextViaObservableTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorOnExceptionResumeNextViaObservableTest.java index 9faed28124..9d0312d284 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorOnExceptionResumeNextViaObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorOnExceptionResumeNextViaObservableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -21,7 +21,8 @@ import org.mockito.Mockito; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.EmptySubscription; import io.reactivex.schedulers.Schedulers; @@ -33,9 +34,9 @@ public class OperatorOnExceptionResumeNextViaObservableTest { public void testResumeNextWithException() { // Trigger failure on second element TestObservable f = new TestObservable("one", "EXCEPTION", "two", "three"); - Observable w = Observable.create(f); - Observable resume = Observable.just("twoResume", "threeResume"); - Observable observable = w.onExceptionResumeNext(resume); + Flowable w = Flowable.create(f); + Flowable resume = Flowable.just("twoResume", "threeResume"); + Flowable observable = w.onExceptionResumeNext(resume); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -61,9 +62,9 @@ public void testResumeNextWithException() { public void testResumeNextWithRuntimeException() { // Trigger failure on second element TestObservable f = new TestObservable("one", "RUNTIMEEXCEPTION", "two", "three"); - Observable w = Observable.create(f); - Observable resume = Observable.just("twoResume", "threeResume"); - Observable observable = w.onExceptionResumeNext(resume); + Flowable w = Flowable.create(f); + Flowable resume = Flowable.just("twoResume", "threeResume"); + Flowable observable = w.onExceptionResumeNext(resume); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -89,9 +90,9 @@ public void testResumeNextWithRuntimeException() { public void testThrowablePassesThru() { // Trigger failure on second element TestObservable f = new TestObservable("one", "THROWABLE", "two", "three"); - Observable w = Observable.create(f); - Observable resume = Observable.just("twoResume", "threeResume"); - Observable observable = w.onExceptionResumeNext(resume); + Flowable w = Flowable.create(f); + Flowable resume = Flowable.just("twoResume", "threeResume"); + Flowable observable = w.onExceptionResumeNext(resume); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -117,9 +118,9 @@ public void testThrowablePassesThru() { public void testErrorPassesThru() { // Trigger failure on second element TestObservable f = new TestObservable("one", "ERROR", "two", "three"); - Observable w = Observable.create(f); - Observable resume = Observable.just("twoResume", "threeResume"); - Observable observable = w.onExceptionResumeNext(resume); + Flowable w = Flowable.create(f); + Flowable resume = Flowable.just("twoResume", "threeResume"); + Flowable observable = w.onExceptionResumeNext(resume); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -144,10 +145,10 @@ public void testErrorPassesThru() { @Test public void testMapResumeAsyncNext() { // Trigger multiple failures - Observable w = Observable.just("one", "fail", "two", "three", "fail"); + Flowable w = Flowable.just("one", "fail", "two", "three", "fail"); // Resume Observable is async TestObservable f = new TestObservable("twoResume", "threeResume"); - Observable resume = Observable.create(f); + Flowable resume = Flowable.create(f); // Introduce map function that fails intermittently (Map does not prevent this when the observer is a // rx.operator incl onErrorResumeNextViaObservable) @@ -161,7 +162,7 @@ public String apply(String s) { } }); - Observable observable = w.onExceptionResumeNext(resume); + Flowable observable = w.onExceptionResumeNext(resume); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -188,8 +189,8 @@ public String apply(String s) { @Test public void testBackpressure() { TestSubscriber ts = new TestSubscriber(); - Observable.range(0, 100000) - .onExceptionResumeNext(Observable.just(1)) + Flowable.range(0, 100000) + .onExceptionResumeNext(Flowable.just(1)) .observeOn(Schedulers.computation()) .map(new Function() { int c = 0; diff --git a/src/test/java/io/reactivex/internal/operators/OperatorPublishTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorPublishTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/OperatorPublishTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorPublishTest.java index e75375d392..45c41188a7 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorPublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorPublishTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; @@ -22,12 +22,11 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; +import io.reactivex.flowables.ConnectableFlowable; import io.reactivex.functions.*; -import io.reactivex.internal.operators.OperatorPublish; import io.reactivex.internal.subscriptions.EmptySubscription; -import io.reactivex.observables.ConnectableObservable; import io.reactivex.schedulers.*; import io.reactivex.subscribers.TestSubscriber; @@ -36,7 +35,7 @@ public class OperatorPublishTest { @Test public void testPublish() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - ConnectableObservable o = Observable.create(new Publisher() { + ConnectableFlowable o = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { @@ -88,8 +87,8 @@ public void accept(String v) { @Test public void testBackpressureFastSlow() { - ConnectableObservable is = Observable.range(1, Observable.bufferSize() * 2).publish(); - Observable fast = is.observeOn(Schedulers.computation()) + ConnectableFlowable is = Flowable.range(1, Flowable.bufferSize() * 2).publish(); + Flowable fast = is.observeOn(Schedulers.computation()) .doOnComplete(new Runnable() { @Override public void run() { @@ -97,7 +96,7 @@ public void run() { } }); - Observable slow = is.observeOn(Schedulers.computation()).map(new Function() { + Flowable slow = is.observeOn(Schedulers.computation()).map(new Function() { int c = 0; @Override @@ -122,18 +121,18 @@ public void run() { }); TestSubscriber ts = new TestSubscriber(); - Observable.merge(fast, slow).subscribe(ts); + Flowable.merge(fast, slow).subscribe(ts); is.connect(); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 4, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 4, ts.valueCount()); } // use case from https://github.com/ReactiveX/RxJava/issues/1732 @Test public void testTakeUntilWithPublishedStreamUsingSelector() { final AtomicInteger emitted = new AtomicInteger(); - Observable xs = Observable.range(0, Observable.bufferSize() * 2).doOnNext(new Consumer() { + Flowable xs = Flowable.range(0, Flowable.bufferSize() * 2).doOnNext(new Consumer() { @Override public void accept(Integer t1) { @@ -142,10 +141,10 @@ public void accept(Integer t1) { }); TestSubscriber ts = new TestSubscriber(); - xs.publish(new Function, Observable>() { + xs.publish(new Function, Flowable>() { @Override - public Observable apply(Observable xs) { + public Flowable apply(Flowable xs) { return xs.takeUntil(xs.skipWhile(new Predicate() { @Override @@ -167,9 +166,9 @@ public boolean test(Integer i) { // use case from https://github.com/ReactiveX/RxJava/issues/1732 @Test public void testTakeUntilWithPublishedStream() { - Observable xs = Observable.range(0, Observable.bufferSize() * 2); + Flowable xs = Flowable.range(0, Flowable.bufferSize() * 2); TestSubscriber ts = new TestSubscriber(); - ConnectableObservable xsp = xs.publish(); + ConnectableFlowable xsp = xs.publish(); xsp.takeUntil(xsp.skipWhile(new Predicate() { @Override @@ -186,7 +185,7 @@ public boolean test(Integer i) { public void testBackpressureTwoConsumers() { final AtomicInteger sourceEmission = new AtomicInteger(); final AtomicBoolean sourceUnsubscribed = new AtomicBoolean(); - final Observable source = Observable.range(1, 100) + final Flowable source = Flowable.range(1, 100) .doOnNext(new Consumer() { @Override public void accept(Integer t1) { @@ -248,7 +247,7 @@ public void run() { @Test public void testConnectWithNoSubscriber() { TestScheduler scheduler = new TestScheduler(); - ConnectableObservable co = Observable.interval(10, 10, TimeUnit.MILLISECONDS, scheduler).take(3).publish(); + ConnectableFlowable co = Flowable.interval(10, 10, TimeUnit.MILLISECONDS, scheduler).take(3).publish(); co.connect(); // Emit 0 scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); @@ -263,7 +262,7 @@ public void testConnectWithNoSubscriber() { @Test public void testSubscribeAfterDisconnectThenConnect() { - ConnectableObservable source = Observable.just(1).publish(); + ConnectableFlowable source = Flowable.just(1).publish(); TestSubscriber ts1 = new TestSubscriber(); @@ -291,7 +290,7 @@ public void testSubscribeAfterDisconnectThenConnect() { @Test public void testNoSubscriberRetentionOnCompleted() { - OperatorPublish source = (OperatorPublish)Observable.just(1).publish(); + OperatorPublish source = (OperatorPublish)Flowable.just(1).publish(); TestSubscriber ts1 = new TestSubscriber(); @@ -312,7 +311,7 @@ public void testNoSubscriberRetentionOnCompleted() { @Test public void testNonNullConnection() { - ConnectableObservable source = Observable.never().publish(); + ConnectableFlowable source = Flowable.never().publish(); assertNotNull(source.connect()); assertNotNull(source.connect()); @@ -320,7 +319,7 @@ public void testNonNullConnection() { @Test public void testNoDisconnectSomeoneElse() { - ConnectableObservable source = Observable.never().publish(); + ConnectableFlowable source = Flowable.never().publish(); Disposable s1 = source.connect(); Disposable s2 = source.connect(); @@ -343,7 +342,7 @@ static boolean checkPublishDisposed(Disposable d) { @Test public void testZeroRequested() { - ConnectableObservable source = Observable.just(1).publish(); + ConnectableFlowable source = Flowable.just(1).publish(); TestSubscriber ts = new TestSubscriber((Long)null); @@ -368,7 +367,7 @@ public void testZeroRequested() { @Test public void testConnectIsIdempotent() { final AtomicInteger calls = new AtomicInteger(); - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber t) { t.onSubscribe(EmptySubscription.INSTANCE); @@ -376,7 +375,7 @@ public void subscribe(Subscriber t) { } }); - ConnectableObservable conn = source.publish(); + ConnectableFlowable conn = source.publish(); assertEquals(0, calls.get()); @@ -394,8 +393,8 @@ public void subscribe(Subscriber t) { } @Test public void testObserveOn() { - ConnectableObservable co = Observable.range(0, 1000).publish(); - Observable obs = co.observeOn(Schedulers.computation()); + ConnectableFlowable co = Flowable.range(0, 1000).publish(); + Flowable obs = co.observeOn(Schedulers.computation()); for (int i = 0; i < 1000; i++) { for (int j = 1; j < 6; j++) { List> tss = new ArrayList>(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorReduceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorReduceTest.java similarity index 84% rename from src/test/java/io/reactivex/internal/operators/OperatorReduceTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorReduceTest.java index 93e28b0d09..7dd0ede7e5 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorReduceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorReduceTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -20,8 +20,9 @@ import org.junit.*; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; public class OperatorReduceTest { @@ -42,7 +43,7 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testAggregateAsIntSum() { - Observable result = Observable.just(1, 2, 3, 4, 5).reduce(0, sum) + Flowable result = Flowable.just(1, 2, 3, 4, 5).reduce(0, sum) .map(new Function() { @Override public Integer apply(Integer v) { @@ -59,8 +60,8 @@ public Integer apply(Integer v) { @Test public void testAggregateAsIntSumSourceThrows() { - Observable result = Observable.concat(Observable.just(1, 2, 3, 4, 5), - Observable. error(new TestException())) + Flowable result = Flowable.concat(Flowable.just(1, 2, 3, 4, 5), + Flowable. error(new TestException())) .reduce(0, sum).map(new Function() { @Override public Integer apply(Integer v) { @@ -84,7 +85,7 @@ public Integer apply(Integer t1, Integer t2) { } }; - Observable result = Observable.just(1, 2, 3, 4, 5) + Flowable result = Flowable.just(1, 2, 3, 4, 5) .reduce(0, sumErr).map(new Function() { @Override public Integer apply(Integer v) { @@ -110,7 +111,7 @@ public Integer apply(Integer t1) { } }; - Observable result = Observable.just(1, 2, 3, 4, 5) + Flowable result = Flowable.just(1, 2, 3, 4, 5) .reduce(0, sum).map(error); result.subscribe(observer); @@ -122,8 +123,8 @@ public Integer apply(Integer t1) { @Test public void testBackpressureWithNoInitialValue() throws InterruptedException { - Observable source = Observable.just(1, 2, 3, 4, 5, 6); - Observable reduced = source.reduce(sum); + Flowable source = Flowable.just(1, 2, 3, 4, 5, 6); + Flowable reduced = source.reduce(sum); Integer r = reduced.toBlocking().first(); assertEquals(21, r.intValue()); @@ -131,8 +132,8 @@ public void testBackpressureWithNoInitialValue() throws InterruptedException { @Test public void testBackpressureWithInitialValue() throws InterruptedException { - Observable source = Observable.just(1, 2, 3, 4, 5, 6); - Observable reduced = source.reduce(0, sum); + Flowable source = Flowable.just(1, 2, 3, 4, 5, 6); + Flowable reduced = source.reduce(0, sum); Integer r = reduced.toBlocking().first(); assertEquals(21, r.intValue()); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorRepeatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorRepeatTest.java similarity index 84% rename from src/test/java/io/reactivex/internal/operators/OperatorRepeatTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorRepeatTest.java index 64f306e148..39c1d5f5ea 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorRepeatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorRepeatTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -24,9 +24,9 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.Observable; -import io.reactivex.TestHelper; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.EmptySubscription; import io.reactivex.schedulers.Schedulers; @@ -38,7 +38,7 @@ public class OperatorRepeatTest { public void testRepetition() { int NUM = 10; final AtomicInteger count = new AtomicInteger(); - int value = Observable.create(new Publisher() { + int value = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber o) { @@ -53,21 +53,21 @@ public void subscribe(final Subscriber o) { @Test(timeout = 2000) public void testRepeatTake() { - Observable xs = Observable.just(1, 2); + Flowable xs = Flowable.just(1, 2); Object[] ys = xs.repeat().subscribeOn(Schedulers.newThread()).take(4).toList().toBlocking().last().toArray(); assertArrayEquals(new Object[] { 1, 2, 1, 2 }, ys); } @Test(timeout = 20000) public void testNoStackOverFlow() { - Observable.just(1).repeat().subscribeOn(Schedulers.newThread()).take(100000).toBlocking().last(); + Flowable.just(1).repeat().subscribeOn(Schedulers.newThread()).take(100000).toBlocking().last(); } @Test public void testRepeatTakeWithSubscribeOn() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - Observable oi = Observable.create(new Publisher() { + Flowable oi = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber sub) { @@ -101,7 +101,7 @@ public Integer apply(Integer t1) { public void testRepeatAndTake() { Subscriber o = TestHelper.mockSubscriber(); - Observable.just(1).repeat().take(10).subscribe(o); + Flowable.just(1).repeat().take(10).subscribe(o); verify(o, times(10)).onNext(1); verify(o).onComplete(); @@ -112,7 +112,7 @@ public void testRepeatAndTake() { public void testRepeatLimited() { Subscriber o = TestHelper.mockSubscriber(); - Observable.just(1).repeat(10).subscribe(o); + Flowable.just(1).repeat(10).subscribe(o); verify(o, times(10)).onNext(1); verify(o).onComplete(); @@ -123,7 +123,7 @@ public void testRepeatLimited() { public void testRepeatError() { Subscriber o = TestHelper.mockSubscriber(); - Observable.error(new TestException()).repeat(10).subscribe(o); + Flowable.error(new TestException()).repeat(10).subscribe(o); verify(o).onError(any(TestException.class)); verify(o, never()).onNext(any()); @@ -135,7 +135,7 @@ public void testRepeatError() { public void testRepeatZero() { Subscriber o = TestHelper.mockSubscriber(); - Observable.just(1).repeat(0).subscribe(o); + Flowable.just(1).repeat(0).subscribe(o); verify(o).onComplete(); verify(o, never()).onNext(any()); @@ -146,7 +146,7 @@ public void testRepeatZero() { public void testRepeatOne() { Subscriber o = TestHelper.mockSubscriber(); - Observable.just(1).repeat(1).subscribe(o); + Flowable.just(1).repeat(1).subscribe(o); verify(o).onComplete(); verify(o, times(1)).onNext(any()); @@ -156,7 +156,7 @@ public void testRepeatOne() { /** Issue #2587. */ @Test public void testRepeatAndDistinctUnbounded() { - Observable src = Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)) + Flowable src = Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)) .take(3) .repeat(3) .distinct(); @@ -175,14 +175,14 @@ public void testRepeatAndDistinctUnbounded() { public void testRepeatRetarget() { final List concatBase = new ArrayList(); TestSubscriber ts = new TestSubscriber(); - Observable.just(1, 2) + Flowable.just(1, 2) .repeat(5) - .concatMap(new Function>() { + .concatMap(new Function>() { @Override - public Observable apply(Integer x) { + public Flowable apply(Integer x) { System.out.println("testRepeatRetarget -> " + x); concatBase.add(x); - return Observable.empty() + return Flowable.empty() .delay(200, TimeUnit.MILLISECONDS); } }) diff --git a/src/test/java/io/reactivex/internal/operators/OperatorReplayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorReplayTest.java similarity index 90% rename from src/test/java/io/reactivex/internal/operators/OperatorReplayTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorReplayTest.java index af3796b781..6d7a56d360 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorReplayTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,25 +25,25 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.Observable; import io.reactivex.*; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; +import io.reactivex.flowables.ConnectableFlowable; import io.reactivex.functions.*; -import io.reactivex.internal.operators.OperatorReplay.*; +import io.reactivex.internal.operators.flowable.OperatorReplay.*; import io.reactivex.internal.subscriptions.EmptySubscription; -import io.reactivex.observables.ConnectableObservable; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; -import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.TestSubscriber; public class OperatorReplayTest { @Test public void testBufferedReplay() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - ConnectableObservable co = source.replay(3); + ConnectableFlowable co = source.replay(3); co.connect(); { @@ -86,9 +86,9 @@ public void testBufferedReplay() { @Test public void testBufferedWindowReplay() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); TestScheduler scheduler = new TestScheduler(); - ConnectableObservable co = source.replay(3, 100, TimeUnit.MILLISECONDS, scheduler); + ConnectableFlowable co = source.replay(3, 100, TimeUnit.MILLISECONDS, scheduler); co.connect(); { @@ -138,9 +138,9 @@ public void testBufferedWindowReplay() { public void testWindowedReplay() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - ConnectableObservable co = source.replay(100, TimeUnit.MILLISECONDS, scheduler); + ConnectableFlowable co = source.replay(100, TimeUnit.MILLISECONDS, scheduler); co.connect(); { @@ -191,18 +191,18 @@ public Integer apply(Integer t1) { }; - Function, Observable> selector = new Function, Observable>() { + Function, Flowable> selector = new Function, Flowable>() { @Override - public Observable apply(Observable t1) { + public Flowable apply(Flowable t1) { return t1.map(dbl); } }; - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable co = source.replay(selector); + Flowable co = source.replay(selector); { Subscriber observer1 = TestHelper.mockSubscriber(); @@ -253,18 +253,18 @@ public Integer apply(Integer t1) { }; - Function, Observable> selector = new Function, Observable>() { + Function, Flowable> selector = new Function, Flowable>() { @Override - public Observable apply(Observable t1) { + public Flowable apply(Flowable t1) { return t1.map(dbl); } }; - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable co = source.replay(selector, 3); + Flowable co = source.replay(selector, 3); { Subscriber observer1 = TestHelper.mockSubscriber(); @@ -313,10 +313,10 @@ public Integer apply(Integer t1) { }; - Function, Observable> selector = new Function, Observable>() { + Function, Flowable> selector = new Function, Flowable>() { @Override - public Observable apply(Observable t1) { + public Flowable apply(Flowable t1) { return t1.map(dbl); } @@ -324,9 +324,9 @@ public Observable apply(Observable t1) { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable co = source.replay(selector, 100, TimeUnit.MILLISECONDS, scheduler); + Flowable co = source.replay(selector, 100, TimeUnit.MILLISECONDS, scheduler); { Subscriber observer1 = TestHelper.mockSubscriber(); @@ -366,9 +366,9 @@ public Observable apply(Observable t1) { @Test public void testBufferedReplayError() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - ConnectableObservable co = source.replay(3); + ConnectableFlowable co = source.replay(3); co.connect(); { @@ -414,9 +414,9 @@ public void testBufferedReplayError() { public void testWindowedReplayError() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - ConnectableObservable co = source.replay(100, TimeUnit.MILLISECONDS, scheduler); + ConnectableFlowable co = source.replay(100, TimeUnit.MILLISECONDS, scheduler); co.connect(); { @@ -459,7 +459,7 @@ public void testWindowedReplayError() { @Test public void testSynchronousDisconnect() { final AtomicInteger effectCounter = new AtomicInteger(); - Observable source = Observable.just(1, 2, 3, 4) + Flowable source = Flowable.just(1, 2, 3, 4) .doOnNext(new Consumer() { @Override public void accept(Integer v) { @@ -468,10 +468,10 @@ public void accept(Integer v) { } }); - Observable result = source.replay( - new Function, Observable>() { + Flowable result = source.replay( + new Function, Flowable>() { @Override - public Observable apply(Observable o) { + public Flowable apply(Flowable o) { return o.take(2); } }); @@ -518,9 +518,9 @@ public void testIssue2191_UnsubscribeSource() { Subscriber spiedSubscriberAfterConnect = TestHelper.mockSubscriber(); // Observable under test - Observable source = Observable.just(1,2); + Flowable source = Flowable.just(1,2); - ConnectableObservable replay = source + ConnectableFlowable replay = source .doOnNext(sourceNext) .doOnCancel(sourceUnsubscribed) .doOnComplete(sourceCompleted) @@ -573,7 +573,7 @@ public void testIssue2191_SchedulerUnsubscribe() throws Exception { when(mockScheduler.createWorker()).thenReturn(spiedWorker); // Observable under test - ConnectableObservable replay = Observable.just(1, 2, 3) + ConnectableFlowable replay = Flowable.just(1, 2, 3) .doOnNext(sourceNext) .doOnCancel(sourceUnsubscribed) .doOnComplete(sourceCompleted) @@ -640,7 +640,7 @@ public void testIssue2191_SchedulerUnsubscribeOnError() throws Exception { IllegalArgumentException illegalArgumentException = new IllegalArgumentException(); when(mockFunc.apply(1)).thenReturn(1); when(mockFunc.apply(2)).thenThrow(illegalArgumentException); - ConnectableObservable replay = Observable.just(1, 2, 3).map(mockFunc) + ConnectableFlowable replay = Flowable.just(1, 2, 3).map(mockFunc) .doOnNext(sourceNext) .doOnCancel(sourceUnsubscribed) .doOnComplete(sourceCompleted) @@ -800,14 +800,14 @@ public void testTimedAndSizedTruncation() { @Test public void testBackpressure() { final AtomicLong requested = new AtomicLong(); - Observable source = Observable.range(1, 1000) + Flowable source = Flowable.range(1, 1000) .doOnRequest(new LongConsumer() { @Override public void accept(long t) { requested.addAndGet(t); } }); - ConnectableObservable co = source.replay(); + ConnectableFlowable co = source.replay(); TestSubscriber ts1 = new TestSubscriber(10L); TestSubscriber ts2 = new TestSubscriber(90L); @@ -831,14 +831,14 @@ public void accept(long t) { @Test public void testBackpressureBounded() { final AtomicLong requested = new AtomicLong(); - Observable source = Observable.range(1, 1000) + Flowable source = Flowable.range(1, 1000) .doOnRequest(new LongConsumer() { @Override public void accept(long t) { requested.addAndGet(t); } }); - ConnectableObservable co = source.replay(50); + ConnectableFlowable co = source.replay(50); TestSubscriber ts1 = new TestSubscriber(10L); TestSubscriber ts2 = new TestSubscriber(90L); @@ -861,7 +861,7 @@ public void accept(long t) { @Test public void testColdReplayNoBackpressure() { - Observable source = Observable.range(0, 1000).replay().autoConnect(); + Flowable source = Flowable.range(0, 1000).replay().autoConnect(); TestSubscriber ts = new TestSubscriber(); @@ -878,7 +878,7 @@ public void testColdReplayNoBackpressure() { } @Test public void testColdReplayBackpressure() { - Observable source = Observable.range(0, 1000).replay().autoConnect(); + Flowable source = Flowable.range(0, 1000).replay().autoConnect(); TestSubscriber ts = new TestSubscriber((Long)null); ts.request(10); @@ -900,7 +900,7 @@ public void testColdReplayBackpressure() { @Test public void testCache() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - Observable o = Observable.create(new Publisher() { + Flowable o = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { @@ -952,7 +952,7 @@ public void accept(String v) { @Test public void testUnsubscribeSource() { Runnable unsubscribe = mock(Runnable.class); - Observable o = Observable.just(1).doOnCancel(unsubscribe).cache(); + Flowable o = Flowable.just(1).doOnCancel(unsubscribe).cache(); o.subscribe(); o.subscribe(); o.subscribe(); @@ -963,7 +963,7 @@ public void testUnsubscribeSource() { public void testTake() { TestSubscriber ts = new TestSubscriber(); - Observable cached = Observable.range(1, 100).replay().autoConnect(); + Flowable cached = Flowable.range(1, 100).replay().autoConnect(); cached.take(10).subscribe(ts); ts.assertNoErrors(); @@ -975,11 +975,11 @@ public void testTake() { @Test public void testAsync() { - Observable source = Observable.range(1, 10000); + Flowable source = Flowable.range(1, 10000); for (int i = 0; i < 100; i++) { TestSubscriber ts1 = new TestSubscriber(); - Observable cached = source.replay().autoConnect(); + Flowable cached = source.replay().autoConnect(); cached.observeOn(Schedulers.computation()).subscribe(ts1); @@ -999,12 +999,12 @@ public void testAsync() { } @Test public void testAsyncComeAndGo() { - Observable source = Observable.interval(1, 1, TimeUnit.MILLISECONDS) + Flowable source = Flowable.interval(1, 1, TimeUnit.MILLISECONDS) .take(1000) .subscribeOn(Schedulers.io()); - Observable cached = source.replay().autoConnect(); + Flowable cached = source.replay().autoConnect(); - Observable output = cached.observeOn(Schedulers.computation()); + Flowable output = cached.observeOn(Schedulers.computation()); List> list = new ArrayList>(100); for (int i = 0; i < 100; i++) { @@ -1036,7 +1036,7 @@ public void testAsyncComeAndGo() { @Test public void testNoMissingBackpressureException() { final int m = 4 * 1000 * 1000; - Observable firehose = Observable.create(new Publisher() { + Flowable firehose = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber t) { t.onSubscribe(EmptySubscription.INSTANCE); @@ -1059,8 +1059,8 @@ public void subscribe(Subscriber t) { @Test public void testValuesAndThenError() { - Observable source = Observable.range(1, 10) - .concatWith(Observable.error(new TestException())) + Flowable source = Flowable.range(1, 10) + .concatWith(Flowable.error(new TestException())) .replay().autoConnect(); @@ -1083,7 +1083,7 @@ public void testValuesAndThenError() { public void unsafeChildThrows() { final AtomicInteger count = new AtomicInteger(); - Observable source = Observable.range(1, 100) + Flowable source = Flowable.range(1, 100) .doOnNext(new Consumer() { @Override public void accept(Integer t) { @@ -1110,11 +1110,11 @@ public void onNext(Integer t) { @Test public void unboundedLeavesEarly() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); final List requests = new ArrayList(); - Observable out = source + Flowable out = source .doOnRequest(new LongConsumer() { @Override public void accept(long t) { @@ -1134,7 +1134,7 @@ public void accept(long t) { @Test public void testSubscribersComeAndGoAtRequestBoundaries() { - ConnectableObservable source = Observable.range(1, 10).replay(1); + ConnectableFlowable source = Flowable.range(1, 10).replay(1); source.connect(); TestSubscriber ts1 = new TestSubscriber(2L); @@ -1182,7 +1182,7 @@ public void testSubscribersComeAndGoAtRequestBoundaries() { @Test public void testSubscribersComeAndGoAtRequestBoundaries2() { - ConnectableObservable source = Observable.range(1, 10).replay(2); + ConnectableFlowable source = Flowable.range(1, 10).replay(2); source.connect(); TestSubscriber ts1 = new TestSubscriber(2L); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorRetryTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorRetryTest.java similarity index 88% rename from src/test/java/io/reactivex/internal/operators/OperatorRetryTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorRetryTest.java index d84833be7d..521b201769 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorRetryTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,15 +25,15 @@ import org.mockito.*; import org.reactivestreams.*; -import io.reactivex.Observable; -import io.reactivex.Observer; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; +import io.reactivex.flowable.TestHelper; +import io.reactivex.flowables.GroupedFlowable; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.*; -import io.reactivex.observables.GroupedObservable; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; public class OperatorRetryTest { @@ -42,7 +42,7 @@ public class OperatorRetryTest { public void iterativeBackoff() { Subscriber consumer = TestHelper.mockSubscriber(); - Observable producer = Observable.create(new Publisher() { + Flowable producer = Flowable.create(new Publisher() { private AtomicInteger count = new AtomicInteger(4); long last = System.currentTimeMillis(); @@ -62,10 +62,10 @@ public void subscribe(Subscriber t1) { }); TestSubscriber ts = new TestSubscriber(consumer); - producer.retryWhen(new Function, Observable>() { + producer.retryWhen(new Function, Flowable>() { @Override - public Observable apply(Observable attempts) { + public Flowable apply(Flowable attempts) { // Worker w = Schedulers.computation().createWorker(); return attempts .map(new Function() { @@ -78,13 +78,13 @@ public Tuple apply(Throwable n) { public Tuple apply(Tuple t, Tuple n) { return new Tuple(t.count + n.count, n.n); }}) - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public Observable apply(Tuple t) { + public Flowable apply(Tuple t) { System.out.println("Retry # "+t.count); return t.count > 20 ? - Observable.error(t.n) : - Observable.timer(t.count *1L, TimeUnit.MILLISECONDS) + Flowable.error(t.n) : + Flowable.timer(t.count *1L, TimeUnit.MILLISECONDS) .cast(Object.class); }}); } @@ -114,7 +114,7 @@ public static class Tuple { public void testRetryIndefinitely() { Subscriber observer = TestHelper.mockSubscriber(); int NUM_RETRIES = 20; - Observable origin = Observable.create(new FuncWithErrors(NUM_RETRIES)); + Flowable origin = Flowable.create(new FuncWithErrors(NUM_RETRIES)); origin.retry().unsafeSubscribe(new TestSubscriber(observer)); InOrder inOrder = inOrder(observer); @@ -133,11 +133,11 @@ public void testRetryIndefinitely() { public void testSchedulingNotificationHandler() { Subscriber observer = TestHelper.mockSubscriber(); int NUM_RETRIES = 2; - Observable origin = Observable.create(new FuncWithErrors(NUM_RETRIES)); + Flowable origin = Flowable.create(new FuncWithErrors(NUM_RETRIES)); TestSubscriber subscriber = new TestSubscriber(observer); - origin.retryWhen(new Function, Observable>() { + origin.retryWhen(new Function, Flowable>() { @Override - public Observable apply(Observable t1) { + public Flowable apply(Flowable t1) { return t1.observeOn(Schedulers.computation()).map(new Function() { @Override public Integer apply(Throwable t1) { @@ -171,10 +171,10 @@ public void accept(Throwable e) { public void testOnNextFromNotificationHandler() { Subscriber observer = TestHelper.mockSubscriber(); int NUM_RETRIES = 2; - Observable origin = Observable.create(new FuncWithErrors(NUM_RETRIES)); - origin.retryWhen(new Function, Observable>() { + Flowable origin = Flowable.create(new FuncWithErrors(NUM_RETRIES)); + origin.retryWhen(new Function, Flowable>() { @Override - public Observable apply(Observable t1) { + public Flowable apply(Flowable t1) { return t1.map(new Function() { @Override @@ -200,12 +200,12 @@ public Integer apply(Throwable t1) { @Test public void testOnCompletedFromNotificationHandler() { Subscriber observer = TestHelper.mockSubscriber(); - Observable origin = Observable.create(new FuncWithErrors(1)); + Flowable origin = Flowable.create(new FuncWithErrors(1)); TestSubscriber subscriber = new TestSubscriber(observer); - origin.retryWhen(new Function, Observable>() { + origin.retryWhen(new Function, Flowable>() { @Override - public Observable apply(Observable t1) { - return Observable.empty(); + public Flowable apply(Flowable t1) { + return Flowable.empty(); } }).subscribe(subscriber); @@ -221,11 +221,11 @@ public Observable apply(Observable t1) { @Test public void testOnErrorFromNotificationHandler() { Subscriber observer = TestHelper.mockSubscriber(); - Observable origin = Observable.create(new FuncWithErrors(2)); - origin.retryWhen(new Function, Observable>() { + Flowable origin = Flowable.create(new FuncWithErrors(2)); + origin.retryWhen(new Function, Flowable>() { @Override - public Observable apply(Observable t1) { - return Observable.error(new RuntimeException()); + public Flowable apply(Flowable t1) { + return Flowable.error(new RuntimeException()); } }).subscribe(observer); @@ -251,11 +251,11 @@ public void subscribe(Subscriber subscriber) { } }; - int first = Observable.create(onSubscribe) - .retryWhen(new Function, Observable>() { + int first = Flowable.create(onSubscribe) + .retryWhen(new Function, Flowable>() { @Override - public Observable apply(Observable attempt) { - return attempt.zipWith(Observable.just(1), new BiFunction() { + public Flowable apply(Flowable attempt) { + return attempt.zipWith(Flowable.just(1), new BiFunction() { @Override public Object apply(Throwable o, Integer integer) { return 0; @@ -273,7 +273,7 @@ public Object apply(Throwable o, Integer integer) { @Test public void testOriginFails() { Subscriber observer = TestHelper.mockSubscriber(); - Observable origin = Observable.create(new FuncWithErrors(1)); + Flowable origin = Flowable.create(new FuncWithErrors(1)); origin.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -288,7 +288,7 @@ public void testRetryFail() { int NUM_RETRIES = 1; int NUM_FAILURES = 2; Subscriber observer = TestHelper.mockSubscriber(); - Observable origin = Observable.create(new FuncWithErrors(NUM_FAILURES)); + Flowable origin = Flowable.create(new FuncWithErrors(NUM_FAILURES)); origin.retry(NUM_RETRIES).subscribe(observer); InOrder inOrder = inOrder(observer); @@ -306,7 +306,7 @@ public void testRetryFail() { public void testRetrySuccess() { int NUM_FAILURES = 1; Subscriber observer = TestHelper.mockSubscriber(); - Observable origin = Observable.create(new FuncWithErrors(NUM_FAILURES)); + Flowable origin = Flowable.create(new FuncWithErrors(NUM_FAILURES)); origin.retry(3).subscribe(observer); InOrder inOrder = inOrder(observer); @@ -325,7 +325,7 @@ public void testRetrySuccess() { public void testInfiniteRetry() { int NUM_FAILURES = 20; Subscriber observer = TestHelper.mockSubscriber(); - Observable origin = Observable.create(new FuncWithErrors(NUM_FAILURES)); + Flowable origin = Flowable.create(new FuncWithErrors(NUM_FAILURES)); origin.retry().subscribe(observer); InOrder inOrder = inOrder(observer); @@ -358,7 +358,7 @@ public void testRetrySubscribesAgainAfterError() { doThrow(new RuntimeException()).when(throwException).accept(Mockito.anyInt()); // create a retrying observable based on a PublishSubject - PublishSubject subject = PublishSubject.create(); + PublishProcessor subject = PublishProcessor.create(); subject // record item .doOnNext(record) @@ -446,7 +446,7 @@ public void cancel() { @Test public void testUnsubscribeFromRetry() { - PublishSubject subject = PublishSubject.create(); + PublishProcessor subject = PublishProcessor.create(); final AtomicInteger count = new AtomicInteger(0); Disposable sub = subject.retry().subscribe(new Consumer() { @Override @@ -482,8 +482,8 @@ public void cancel() { } }; - Observable stream = Observable.create(onSubscribe); - Observable streamWithRetry = stream.retry(); + Flowable stream = Flowable.create(onSubscribe); + Flowable streamWithRetry = stream.retry(); Disposable sub = streamWithRetry.subscribe(); assertEquals(1, subsCount.get()); sub.dispose(); @@ -519,7 +519,7 @@ public void subscribe(Subscriber s) { } }; - Observable.create(onSubscribe).retry(3).subscribe(ts); + Flowable.create(onSubscribe).retry(3).subscribe(ts); assertEquals(4, subsCount.get()); // 1 + 3 retries } @@ -538,7 +538,7 @@ public void subscribe(Subscriber s) { } }; - Observable.create(onSubscribe).retry(1).subscribe(ts); + Flowable.create(onSubscribe).retry(1).subscribe(ts); assertEquals(2, subsCount.get()); } @@ -557,7 +557,7 @@ public void subscribe(Subscriber s) { } }; - Observable.create(onSubscribe).retry(0).subscribe(ts); + Flowable.create(onSubscribe).retry(0).subscribe(ts); assertEquals(1, subsCount.get()); } @@ -615,7 +615,7 @@ public void run() { } /** Observer for listener on seperate thread */ - static final class AsyncObserver extends Observer { + static final class AsyncObserver extends DefaultObserver { protected CountDownLatch latch = new CountDownLatch(1); @@ -662,11 +662,11 @@ public void onNext(T v) { public void testUnsubscribeAfterError() { @SuppressWarnings("unchecked") - Observer observer = mock(Observer.class); + DefaultObserver observer = mock(DefaultObserver.class); // Observable that always fails after 100ms SlowObservable so = new SlowObservable(100, 0); - Observable o = Observable.create(so).retry(5); + Flowable o = Flowable.create(so).retry(5); AsyncObserver async = new AsyncObserver(observer); @@ -687,11 +687,11 @@ public void testUnsubscribeAfterError() { public void testTimeoutWithRetry() { @SuppressWarnings("unchecked") - Observer observer = mock(Observer.class); + DefaultObserver observer = mock(DefaultObserver.class); // Observable that sends every 100ms (timeout fails instead) SlowObservable so = new SlowObservable(100, 10); - Observable o = Observable.create(so).timeout(80, TimeUnit.MILLISECONDS).retry(5); + Flowable o = Flowable.create(so).timeout(80, TimeUnit.MILLISECONDS).retry(5); AsyncObserver async = new AsyncObserver(observer); @@ -711,10 +711,10 @@ public void testTimeoutWithRetry() { public void testRetryWithBackpressure() throws InterruptedException { final int NUM_LOOPS = 1; for (int j=0;j observer = TestHelper.mockSubscriber(); - Observable origin = Observable.create(new FuncWithErrors(NUM_RETRIES)); + Flowable origin = Flowable.create(new FuncWithErrors(NUM_RETRIES)); TestSubscriber ts = new TestSubscriber(observer); origin.retry().observeOn(Schedulers.computation()).unsafeSubscribe(ts); ts.awaitTerminalEvent(5, TimeUnit.SECONDS); @@ -736,7 +736,7 @@ public void testRetryWithBackpressure() throws InterruptedException { @Test//(timeout = 15000) public void testRetryWithBackpressureParallel() throws InterruptedException { final int NUM_LOOPS = 1; - final int NUM_RETRIES = Observable.bufferSize() * 2; + final int NUM_RETRIES = Flowable.bufferSize() * 2; int ncpu = Runtime.getRuntime().availableProcessors(); ExecutorService exec = Executors.newFixedThreadPool(Math.max(ncpu / 2, 2)); try { @@ -757,7 +757,7 @@ public void testRetryWithBackpressureParallel() throws InterruptedException { public void run() { final AtomicInteger nexts = new AtomicInteger(); try { - Observable origin = Observable.create(new FuncWithErrors(NUM_RETRIES)); + Flowable origin = Flowable.create(new FuncWithErrors(NUM_RETRIES)); TestSubscriber ts = new TestSubscriber(); origin.retry() .observeOn(Schedulers.computation()).unsafeSubscribe(ts); @@ -838,7 +838,7 @@ public void testIssue1900() throws InterruptedException { final int NUM_MSG = 1034; final AtomicInteger count = new AtomicInteger(); - Observable origin = Observable.range(0, NUM_MSG) + Flowable origin = Flowable.range(0, NUM_MSG) .map(new Function() { @Override public String apply(Integer t1) { @@ -853,9 +853,9 @@ public String apply(String t1) { return t1; } }) - .flatMap(new Function, Observable>() { + .flatMap(new Function, Flowable>() { @Override - public Observable apply(GroupedObservable t1) { + public Flowable apply(GroupedFlowable t1) { return t1.take(1); } }) @@ -878,7 +878,7 @@ public void testIssue1900SourceNotSupportingBackpressure() { final int NUM_MSG = 1034; final AtomicInteger count = new AtomicInteger(); - Observable origin = Observable.create(new Publisher() { + Flowable origin = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber o) { @@ -897,9 +897,9 @@ public String apply(String t1) { return t1; } }) - .flatMap(new Function, Observable>() { + .flatMap(new Function, Flowable>() { @Override - public Observable apply(GroupedObservable t1) { + public Flowable apply(GroupedFlowable t1) { return t1.take(1); } }) diff --git a/src/test/java/io/reactivex/internal/operators/OperatorRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorRetryWithPredicateTest.java similarity index 89% rename from src/test/java/io/reactivex/internal/operators/OperatorRetryWithPredicateTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorRetryWithPredicateTest.java index 9161d388fb..8f05159472 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorRetryWithPredicateTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -26,15 +26,15 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.EmptySubscription; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.processors.PublishProcessor; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; public class OperatorRetryWithPredicateTest { BiPredicate retryTwice = new BiPredicate() { @@ -57,7 +57,7 @@ public boolean test(Integer t1, Throwable t2) { }; @Test public void testWithNothingToRetry() { - Observable source = Observable.range(0, 3); + Flowable source = Flowable.range(0, 3); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); @@ -72,7 +72,7 @@ public void testWithNothingToRetry() { } @Test public void testRetryTwice() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { int count; @Override public void subscribe(Subscriber t1) { @@ -91,7 +91,7 @@ public void subscribe(Subscriber t1) { }); @SuppressWarnings("unchecked") - Observer o = mock(Observer.class); + DefaultObserver o = mock(DefaultObserver.class); InOrder inOrder = inOrder(o); source.retry(retryTwice).subscribe(o); @@ -108,7 +108,7 @@ public void subscribe(Subscriber t1) { } @Test public void testRetryTwiceAndGiveUp() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber t1) { t1.onSubscribe(EmptySubscription.INSTANCE); @@ -119,7 +119,7 @@ public void subscribe(Subscriber t1) { }); @SuppressWarnings("unchecked") - Observer o = mock(Observer.class); + DefaultObserver o = mock(DefaultObserver.class); InOrder inOrder = inOrder(o); source.retry(retryTwice).subscribe(o); @@ -136,7 +136,7 @@ public void subscribe(Subscriber t1) { } @Test public void testRetryOnSpecificException() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { int count; @Override public void subscribe(Subscriber t1) { @@ -155,7 +155,7 @@ public void subscribe(Subscriber t1) { }); @SuppressWarnings("unchecked") - Observer o = mock(Observer.class); + DefaultObserver o = mock(DefaultObserver.class); InOrder inOrder = inOrder(o); source.retry(retryOnTestException).subscribe(o); @@ -173,7 +173,7 @@ public void subscribe(Subscriber t1) { public void testRetryOnSpecificExceptionAndNotOther() { final IOException ioe = new IOException(); final TestException te = new TestException(); - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { int count; @Override public void subscribe(Subscriber t1) { @@ -192,7 +192,7 @@ public void subscribe(Subscriber t1) { }); @SuppressWarnings("unchecked") - Observer o = mock(Observer.class); + DefaultObserver o = mock(DefaultObserver.class); InOrder inOrder = inOrder(o); source.retry(retryOnTestException).subscribe(o); @@ -210,7 +210,7 @@ public void subscribe(Subscriber t1) { @Test public void testUnsubscribeFromRetry() { - PublishSubject subject = PublishSubject.create(); + PublishProcessor subject = PublishProcessor.create(); final AtomicInteger count = new AtomicInteger(0); Disposable sub = subject.retry(retryTwice).subscribe(new Consumer() { @Override @@ -231,7 +231,7 @@ public void testUnsubscribeAfterError() { // Observable that always fails after 100ms OperatorRetryTest.SlowObservable so = new OperatorRetryTest.SlowObservable(100, 0); - Observable o = Observable + Flowable o = Flowable .create(so) .retry(retry5); @@ -257,7 +257,7 @@ public void testTimeoutWithRetry() { // Observable that sends every 100ms (timeout fails instead) OperatorRetryTest.SlowObservable so = new OperatorRetryTest.SlowObservable(100, 10); - Observable o = Observable + Flowable o = Flowable .create(so) .timeout(80, TimeUnit.MILLISECONDS) .retry(retry5); @@ -281,7 +281,7 @@ public void testIssue2826() { TestSubscriber ts = new TestSubscriber(); final RuntimeException e = new RuntimeException("You shall not pass"); final AtomicInteger c = new AtomicInteger(); - Observable.just(1).map(new Function() { + Flowable.just(1).map(new Function() { @Override public Integer apply(Integer t1) { c.incrementAndGet(); @@ -296,7 +296,7 @@ public Integer apply(Integer t1) { @Test public void testJustAndRetry() throws Exception { final AtomicBoolean throwException = new AtomicBoolean(true); - int value = Observable.just(1).map(new Function() { + int value = Flowable.just(1).map(new Function() { @Override public Integer apply(Integer t1) { if (throwException.compareAndSet(true, false)) { @@ -313,7 +313,7 @@ public Integer apply(Integer t1) { public void testIssue3008RetryWithPredicate() { final List list = new CopyOnWriteArrayList(); final AtomicBoolean isFirst = new AtomicBoolean(true); - Observable. just(1L, 2L, 3L).map(new Function(){ + Flowable. just(1L, 2L, 3L).map(new Function(){ @Override public Long apply(Long x) { System.out.println("map " + x); @@ -341,7 +341,7 @@ public void accept(Long t) { public void testIssue3008RetryInfinite() { final List list = new CopyOnWriteArrayList(); final AtomicBoolean isFirst = new AtomicBoolean(true); - Observable. just(1L, 2L, 3L).map(new Function(){ + Flowable. just(1L, 2L, 3L).map(new Function(){ @Override public Long apply(Long x) { System.out.println("map " + x); @@ -365,9 +365,9 @@ public void accept(Long t) { public void testBackpressure() { final List requests = new ArrayList(); - Observable source = Observable + Flowable source = Flowable .just(1) - .concatWith(Observable.error(new TestException())) + .concatWith(Flowable.error(new TestException())) .doOnRequest(new LongConsumer() { @Override public void accept(long t) { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSampleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSampleTest.java similarity index 82% rename from src/test/java/io/reactivex/internal/operators/OperatorSampleTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorSampleTest.java index 2e886d07c3..2d76689d0a 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSampleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSampleTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -23,9 +23,10 @@ import org.reactivestreams.*; import io.reactivex.*; +import io.reactivex.flowable.TestHelper; import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; public class OperatorSampleTest { private TestScheduler scheduler; @@ -44,7 +45,7 @@ public void before() { @Test public void testSample() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer1) { observer1.onSubscribe(EmptySubscription.INSTANCE); @@ -69,7 +70,7 @@ public void run() { } }); - Observable sampled = source.sample(400L, TimeUnit.MILLISECONDS, scheduler); + Flowable sampled = source.sample(400L, TimeUnit.MILLISECONDS, scheduler); sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -106,10 +107,10 @@ public void run() { @Test public void sampleWithSamplerNormal() { - PublishSubject source = PublishSubject.create(); - PublishSubject sampler = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor sampler = PublishProcessor.create(); - Observable m = source.sample(sampler); + Flowable m = source.sample(sampler); m.subscribe(observer2); source.onNext(1); @@ -132,10 +133,10 @@ public void sampleWithSamplerNormal() { @Test public void sampleWithSamplerNoDuplicates() { - PublishSubject source = PublishSubject.create(); - PublishSubject sampler = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor sampler = PublishProcessor.create(); - Observable m = source.sample(sampler); + Flowable m = source.sample(sampler); m.subscribe(observer2); source.onNext(1); @@ -162,10 +163,10 @@ public void sampleWithSamplerNoDuplicates() { @Test public void sampleWithSamplerTerminatingEarly() { - PublishSubject source = PublishSubject.create(); - PublishSubject sampler = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor sampler = PublishProcessor.create(); - Observable m = source.sample(sampler); + Flowable m = source.sample(sampler); m.subscribe(observer2); source.onNext(1); @@ -186,10 +187,10 @@ public void sampleWithSamplerTerminatingEarly() { @Test public void sampleWithSamplerEmitAndTerminate() { - PublishSubject source = PublishSubject.create(); - PublishSubject sampler = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor sampler = PublishProcessor.create(); - Observable m = source.sample(sampler); + Flowable m = source.sample(sampler); m.subscribe(observer2); source.onNext(1); @@ -211,10 +212,10 @@ public void sampleWithSamplerEmitAndTerminate() { @Test public void sampleWithSamplerEmptySource() { - PublishSubject source = PublishSubject.create(); - PublishSubject sampler = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor sampler = PublishProcessor.create(); - Observable m = source.sample(sampler); + Flowable m = source.sample(sampler); m.subscribe(observer2); source.onComplete(); @@ -228,10 +229,10 @@ public void sampleWithSamplerEmptySource() { @Test public void sampleWithSamplerSourceThrows() { - PublishSubject source = PublishSubject.create(); - PublishSubject sampler = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor sampler = PublishProcessor.create(); - Observable m = source.sample(sampler); + Flowable m = source.sample(sampler); m.subscribe(observer2); source.onNext(1); @@ -246,10 +247,10 @@ public void sampleWithSamplerSourceThrows() { @Test public void sampleWithSamplerThrows() { - PublishSubject source = PublishSubject.create(); - PublishSubject sampler = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor sampler = PublishProcessor.create(); - Observable m = source.sample(sampler); + Flowable m = source.sample(sampler); m.subscribe(observer2); source.onNext(1); @@ -265,7 +266,7 @@ public void sampleWithSamplerThrows() { @Test public void testSampleUnsubscribe() { final Subscription s = mock(Subscription.class); - Observable o = Observable.create( + Flowable o = Flowable.create( new Publisher() { @Override public void subscribe(Subscriber subscriber) { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorScanTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorScanTest.java similarity index 88% rename from src/test/java/io/reactivex/internal/operators/OperatorScanTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorScanTest.java index e38f3162c7..529198c423 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorScanTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorScanTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.*; @@ -23,12 +23,12 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.processors.PublishProcessor; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; public class OperatorScanTest { @@ -36,9 +36,9 @@ public class OperatorScanTest { public void testScanIntegersWithInitialValue() { Subscriber observer = TestHelper.mockSubscriber(); - Observable observable = Observable.just(1, 2, 3); + Flowable observable = Flowable.just(1, 2, 3); - Observable m = observable.scan("", new BiFunction() { + Flowable m = observable.scan("", new BiFunction() { @Override public String apply(String s, Integer n) { @@ -62,9 +62,9 @@ public String apply(String s, Integer n) { public void testScanIntegersWithoutInitialValue() { Subscriber observer = TestHelper.mockSubscriber(); - Observable observable = Observable.just(1, 2, 3); + Flowable observable = Flowable.just(1, 2, 3); - Observable m = observable.scan(new BiFunction() { + Flowable m = observable.scan(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -88,9 +88,9 @@ public Integer apply(Integer t1, Integer t2) { public void testScanIntegersWithoutInitialValueAndOnlyOneValue() { Subscriber observer = TestHelper.mockSubscriber(); - Observable observable = Observable.just(1); + Flowable observable = Flowable.just(1); - Observable m = observable.scan(new BiFunction() { + Flowable m = observable.scan(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -111,7 +111,7 @@ public Integer apply(Integer t1, Integer t2) { @Test public void shouldNotEmitUntilAfterSubscription() { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, 100).scan(0, new BiFunction() { + Flowable.range(1, 100).scan(0, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -134,7 +134,7 @@ public boolean test(Integer t1) { @Test public void testBackpressureWithInitialValue() { final AtomicInteger count = new AtomicInteger(); - Observable.range(1, 100) + Flowable.range(1, 100) .scan(0, new BiFunction() { @Override @@ -143,7 +143,7 @@ public Integer apply(Integer t1, Integer t2) { } }) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onStart() { @@ -175,7 +175,7 @@ public void onNext(Integer t) { @Test public void testBackpressureWithoutInitialValue() { final AtomicInteger count = new AtomicInteger(); - Observable.range(1, 100) + Flowable.range(1, 100) .scan(new BiFunction() { @Override @@ -184,7 +184,7 @@ public Integer apply(Integer t1, Integer t2) { } }) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onStart() { @@ -216,7 +216,7 @@ public void onNext(Integer t) { @Test public void testNoBackpressureWithInitialValue() { final AtomicInteger count = new AtomicInteger(); - Observable.range(1, 100) + Flowable.range(1, 100) .scan(0, new BiFunction() { @Override @@ -225,7 +225,7 @@ public Integer apply(Integer t1, Integer t2) { } }) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -254,7 +254,7 @@ public void onNext(Integer t) { */ @Test public void testSeedFactory() { - Observable> o = Observable.range(1, 10) + Flowable> o = Flowable.range(1, 10) .collect(new Supplier>() { @Override @@ -277,7 +277,7 @@ public void accept(List list, Integer t2) { @Test public void testScanWithRequestOne() { - Observable o = Observable.just(1, 2).scan(0, new BiFunction() { + Flowable o = Flowable.just(1, 2).scan(0, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -295,7 +295,7 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testScanShouldNotRequestZero() { final AtomicReference producer = new AtomicReference(); - Observable o = Observable.create(new Publisher() { + Flowable o = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber subscriber) { Subscription p = spy(new Subscription() { @@ -341,7 +341,7 @@ public void onNext(Integer integer) { @Test public void testInitialValueEmittedNoProducer() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber(); @@ -359,7 +359,7 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testInitialValueEmittedWithProducer() { - Observable source = Observable.never(); + Flowable source = Flowable.never(); TestSubscriber ts = new TestSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/OperatorSequenceEqualTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSequenceEqualTest.java new file mode 100644 index 0000000000..83b4a2e128 --- /dev/null +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSequenceEqualTest.java @@ -0,0 +1,153 @@ +/** + * Copyright 2016 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package io.reactivex.internal.operators.flowable; + +import static org.mockito.Matchers.isA; +import static org.mockito.Mockito.*; + +import org.junit.*; +import org.mockito.InOrder; +import org.reactivestreams.Subscriber; + +import io.reactivex.Flowable; +import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; +import io.reactivex.functions.BiPredicate; + +public class OperatorSequenceEqualTest { + + @Test + public void test1() { + Flowable observable = Flowable.sequenceEqual( + Flowable.just("one", "two", "three"), + Flowable.just("one", "two", "three")); + verifyResult(observable, true); + } + + @Test + public void test2() { + Flowable observable = Flowable.sequenceEqual( + Flowable.just("one", "two", "three"), + Flowable.just("one", "two", "three", "four")); + verifyResult(observable, false); + } + + @Test + public void test3() { + Flowable observable = Flowable.sequenceEqual( + Flowable.just("one", "two", "three", "four"), + Flowable.just("one", "two", "three")); + verifyResult(observable, false); + } + + @Test + public void testWithError1() { + Flowable observable = Flowable.sequenceEqual( + Flowable.concat(Flowable.just("one"), + Flowable. error(new TestException())), + Flowable.just("one", "two", "three")); + verifyError(observable); + } + + @Test + public void testWithError2() { + Flowable observable = Flowable.sequenceEqual( + Flowable.just("one", "two", "three"), + Flowable.concat(Flowable.just("one"), + Flowable. error(new TestException()))); + verifyError(observable); + } + + @Test + public void testWithError3() { + Flowable observable = Flowable.sequenceEqual( + Flowable.concat(Flowable.just("one"), + Flowable. error(new TestException())), + Flowable.concat(Flowable.just("one"), + Flowable. error(new TestException()))); + verifyError(observable); + } + + @Test + public void testWithEmpty1() { + Flowable observable = Flowable.sequenceEqual( + Flowable. empty(), + Flowable.just("one", "two", "three")); + verifyResult(observable, false); + } + + @Test + public void testWithEmpty2() { + Flowable observable = Flowable.sequenceEqual( + Flowable.just("one", "two", "three"), + Flowable. empty()); + verifyResult(observable, false); + } + + @Test + public void testWithEmpty3() { + Flowable observable = Flowable.sequenceEqual( + Flowable. empty(), Flowable. empty()); + verifyResult(observable, true); + } + + @Test + @Ignore("Null values not allowed") + public void testWithNull1() { + Flowable observable = Flowable.sequenceEqual( + Flowable.just((String) null), Flowable.just("one")); + verifyResult(observable, false); + } + + @Test + @Ignore("Null values not allowed") + public void testWithNull2() { + Flowable observable = Flowable.sequenceEqual( + Flowable.just((String) null), Flowable.just((String) null)); + verifyResult(observable, true); + } + + @Test + public void testWithEqualityError() { + Flowable observable = Flowable.sequenceEqual( + Flowable.just("one"), Flowable.just("one"), + new BiPredicate() { + @Override + public boolean test(String t1, String t2) { + throw new TestException(); + } + }); + verifyError(observable); + } + + private void verifyResult(Flowable observable, boolean result) { + Subscriber observer = TestHelper.mockSubscriber(); + + observable.subscribe(observer); + + InOrder inOrder = inOrder(observer); + inOrder.verify(observer, times(1)).onNext(result); + inOrder.verify(observer).onComplete(); + inOrder.verifyNoMoreInteractions(); + } + + private void verifyError(Flowable observable) { + Subscriber observer = TestHelper.mockSubscriber(); + observable.subscribe(observer); + + InOrder inOrder = inOrder(observer); + inOrder.verify(observer, times(1)).onError(isA(TestException.class)); + inOrder.verifyNoMoreInteractions(); + } +} \ No newline at end of file diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSerializeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSerializeTest.java similarity index 95% rename from src/test/java/io/reactivex/internal/operators/OperatorSerializeTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorSerializeTest.java index 7a0eacd934..3a81cb9c90 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSerializeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -23,8 +23,10 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.subscribers.DefaultObserver; public class OperatorSerializeTest { @@ -38,7 +40,7 @@ public void before() { @Test public void testSingleThreadedBasic() { TestSingleThreadedObservable onSubscribe = new TestSingleThreadedObservable("one", "two", "three"); - Observable w = Observable.create(onSubscribe); + Flowable w = Flowable.create(onSubscribe); w.serialize().subscribe(observer); onSubscribe.waitToFinish(); @@ -56,7 +58,7 @@ public void testSingleThreadedBasic() { @Test public void testMultiThreadedBasic() { TestMultiThreadedObservable onSubscribe = new TestMultiThreadedObservable("one", "two", "three"); - Observable w = Observable.create(onSubscribe); + Flowable w = Flowable.create(onSubscribe); BusyObserver busyobserver = new BusyObserver(); @@ -79,7 +81,7 @@ public void testMultiThreadedBasic() { @Test public void testMultiThreadedWithNPE() { TestMultiThreadedObservable onSubscribe = new TestMultiThreadedObservable("one", "two", "three", null); - Observable w = Observable.create(onSubscribe); + Flowable w = Flowable.create(onSubscribe); BusyObserver busyobserver = new BusyObserver(); @@ -110,7 +112,7 @@ public void testMultiThreadedWithNPEinMiddle() { boolean lessThan9 = false; for (int i = 0; i < 3; i++) { TestMultiThreadedObservable onSubscribe = new TestMultiThreadedObservable("one", "two", "three", null, "four", "five", "six", "seven", "eight", "nine"); - Observable w = Observable.create(onSubscribe); + Flowable w = Flowable.create(onSubscribe); BusyObserver busyobserver = new BusyObserver(); @@ -144,10 +146,10 @@ public void testMultiThreadedWithNPEinMiddle() { */ public static class OnNextThread implements Runnable { - private final Observer observer; + private final DefaultObserver observer; private final int numStringsToSend; - OnNextThread(Observer observer, int numStringsToSend) { + OnNextThread(DefaultObserver observer, int numStringsToSend) { this.observer = observer; this.numStringsToSend = numStringsToSend; } @@ -165,11 +167,11 @@ public void run() { */ public static class CompletionThread implements Runnable { - private final Observer observer; + private final DefaultObserver observer; private final TestConcurrencyobserverEvent event; private final Future[] waitOnThese; - CompletionThread(Observer observer, TestConcurrencyobserverEvent event, Future... waitOnThese) { + CompletionThread(DefaultObserver observer, TestConcurrencyobserverEvent event, Future... waitOnThese) { this.observer = observer; this.event = event; this.waitOnThese = waitOnThese; @@ -338,7 +340,7 @@ public void waitToFinish() { } } - private static class BusyObserver extends Observer { + private static class BusyObserver extends DefaultObserver { volatile boolean onCompleted = false; volatile boolean onError = false; AtomicInteger onNextCount = new AtomicInteger(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSingleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSingleTest.java similarity index 88% rename from src/test/java/io/reactivex/internal/operators/OperatorSingleTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorSingleTest.java index b2f0178d81..cbca4f9b24 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSingleTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.isA; @@ -24,16 +24,16 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.Observable; -import io.reactivex.Observer; +import io.reactivex.subscribers.DefaultObserver; public class OperatorSingleTest { @Test public void testSingle() { - Observable observable = Observable.just(1).single(); + Flowable observable = Flowable.just(1).single(); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -46,7 +46,7 @@ public void testSingle() { @Test public void testSingleWithTooManyElements() { - Observable observable = Observable.just(1, 2).single(); + Flowable observable = Flowable.just(1, 2).single(); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -59,7 +59,7 @@ public void testSingleWithTooManyElements() { @Test public void testSingleWithEmpty() { - Observable observable = Observable. empty().single(); + Flowable observable = Flowable. empty().single(); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -73,7 +73,7 @@ public void testSingleWithEmpty() { @Test public void testSingleDoesNotRequestMoreThanItNeedsToEmitItem() { final AtomicLong request = new AtomicLong(); - Observable.just(1).doOnRequest(new LongConsumer() { + Flowable.just(1).doOnRequest(new LongConsumer() { @Override public void accept(long n) { request.addAndGet(n); @@ -87,7 +87,7 @@ public void accept(long n) { public void testSingleDoesNotRequestMoreThanItNeedsToEmitErrorFromEmpty() { final AtomicLong request = new AtomicLong(); try { - Observable.empty().doOnRequest(new LongConsumer() { + Flowable.empty().doOnRequest(new LongConsumer() { @Override public void accept(long n) { request.addAndGet(n); @@ -103,7 +103,7 @@ public void accept(long n) { public void testSingleDoesNotRequestMoreThanItNeedsToEmitErrorFromMoreThanOne() { final AtomicLong request = new AtomicLong(); try { - Observable.just(1, 2).doOnRequest(new LongConsumer() { + Flowable.just(1, 2).doOnRequest(new LongConsumer() { @Override public void accept(long n) { request.addAndGet(n); @@ -118,7 +118,7 @@ public void accept(long n) { @Test public void testSingleDoesNotRequestMoreThanItNeedsIf1Then2Requested() { final List requests = new ArrayList(); - Observable.just(1) + Flowable.just(1) // .doOnRequest(new LongConsumer() { @Override @@ -129,7 +129,7 @@ public void accept(long n) { // .single() // - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onStart() { @@ -158,7 +158,7 @@ public void onNext(Integer t) { @Test public void testSingleDoesNotRequestMoreThanItNeedsIf3Requested() { final List requests = new ArrayList(); - Observable.just(1) + Flowable.just(1) // .doOnRequest(new LongConsumer() { @Override @@ -169,7 +169,7 @@ public void accept(long n) { // .single() // - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onStart() { @@ -197,7 +197,7 @@ public void onNext(Integer t) { @Test public void testSingleRequestsExactlyWhatItNeedsIf1Requested() { final List requests = new ArrayList(); - Observable.just(1) + Flowable.just(1) // .doOnRequest(new LongConsumer() { @Override @@ -208,7 +208,7 @@ public void accept(long n) { // .single() // - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onStart() { @@ -236,7 +236,7 @@ public void onNext(Integer t) { @Test public void testSingleWithPredicate() { - Observable observable = Observable.just(1, 2) + Flowable observable = Flowable.just(1, 2) .filter( new Predicate() { @@ -258,7 +258,7 @@ public boolean test(Integer t1) { @Test public void testSingleWithPredicateAndTooManyElements() { - Observable observable = Observable.just(1, 2, 3, 4) + Flowable observable = Flowable.just(1, 2, 3, 4) .filter( new Predicate() { @@ -280,7 +280,7 @@ public boolean test(Integer t1) { @Test public void testSingleWithPredicateAndEmpty() { - Observable observable = Observable.just(1) + Flowable observable = Flowable.just(1) .filter( new Predicate() { @@ -301,7 +301,7 @@ public boolean test(Integer t1) { @Test public void testSingleOrDefault() { - Observable observable = Observable.just(1).single(2); + Flowable observable = Flowable.just(1).single(2); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -314,7 +314,7 @@ public void testSingleOrDefault() { @Test public void testSingleOrDefaultWithTooManyElements() { - Observable observable = Observable.just(1, 2).single(3); + Flowable observable = Flowable.just(1, 2).single(3); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -327,7 +327,7 @@ public void testSingleOrDefaultWithTooManyElements() { @Test public void testSingleOrDefaultWithEmpty() { - Observable observable = Observable. empty() + Flowable observable = Flowable. empty() .single(1); Subscriber observer = TestHelper.mockSubscriber(); @@ -341,7 +341,7 @@ public void testSingleOrDefaultWithEmpty() { @Test public void testSingleOrDefaultWithPredicate() { - Observable observable = Observable.just(1, 2) + Flowable observable = Flowable.just(1, 2) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -361,7 +361,7 @@ public boolean test(Integer t1) { @Test public void testSingleOrDefaultWithPredicateAndTooManyElements() { - Observable observable = Observable.just(1, 2, 3, 4) + Flowable observable = Flowable.just(1, 2, 3, 4) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -381,7 +381,7 @@ public boolean test(Integer t1) { @Test public void testSingleOrDefaultWithPredicateAndEmpty() { - Observable observable = Observable.just(1) + Flowable observable = Flowable.just(1) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -401,9 +401,9 @@ public boolean test(Integer t1) { @Test public void testSingleWithBackpressure() { - Observable observable = Observable.just(1, 2).single(); + Flowable observable = Flowable.just(1, 2).single(); - Subscriber subscriber = spy(new Observer() { + Subscriber subscriber = spy(new DefaultObserver() { @Override public void onStart() { @@ -435,8 +435,8 @@ public void onNext(Integer integer) { @Test(timeout = 30000) public void testIssue1527() throws InterruptedException { //https://github.com/ReactiveX/RxJava/pull/1527 - Observable source = Observable.just(1, 2, 3, 4, 5, 6); - Observable reduced = source.reduce(new BiFunction() { + Flowable source = Flowable.just(1, 2, 3, 4, 5, 6); + Flowable reduced = source.reduce(new BiFunction() { @Override public Integer apply(Integer i1, Integer i2) { return i1 + i2; diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSkipLastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipLastTest.java similarity index 79% rename from src/test/java/io/reactivex/internal/operators/OperatorSkipLastTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipLastTest.java index fe88d86257..fa8455b268 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSkipLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipLastTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -23,7 +23,8 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; @@ -31,7 +32,7 @@ public class OperatorSkipLastTest { @Test public void testSkipLastEmpty() { - Observable observable = Observable. empty().skipLast(2); + Flowable observable = Flowable. empty().skipLast(2); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -42,7 +43,7 @@ public void testSkipLastEmpty() { @Test public void testSkipLast1() { - Observable observable = Observable.fromIterable(Arrays.asList("one", "two", "three")).skipLast(2); + Flowable observable = Flowable.fromIterable(Arrays.asList("one", "two", "three")).skipLast(2); Subscriber observer = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(observer); @@ -56,7 +57,7 @@ public void testSkipLast1() { @Test public void testSkipLast2() { - Observable observable = Observable.fromIterable(Arrays.asList("one", "two")).skipLast(2); + Flowable observable = Flowable.fromIterable(Arrays.asList("one", "two")).skipLast(2); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -67,8 +68,8 @@ public void testSkipLast2() { @Test public void testSkipLastWithZeroCount() { - Observable w = Observable.just("one", "two"); - Observable observable = w.skipLast(0); + Flowable w = Flowable.just("one", "two"); + Flowable observable = w.skipLast(0); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -81,7 +82,7 @@ public void testSkipLastWithZeroCount() { @Test @Ignore("Null values not allowed") public void testSkipLastWithNull() { - Observable observable = Observable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1); + Flowable observable = Flowable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1); Subscriber observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -94,18 +95,18 @@ public void testSkipLastWithNull() { @Test public void testSkipLastWithBackpressure() { - Observable o = Observable.range(0, Observable.bufferSize() * 2).skipLast(Observable.bufferSize() + 10); + Flowable o = Flowable.range(0, Flowable.bufferSize() * 2).skipLast(Flowable.bufferSize() + 10); TestSubscriber ts = new TestSubscriber(); o.observeOn(Schedulers.computation()).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals((Observable.bufferSize()) - 10, ts.valueCount()); + assertEquals((Flowable.bufferSize()) - 10, ts.valueCount()); } @Test(expected = IndexOutOfBoundsException.class) public void testSkipLastWithNegativeCount() { - Observable.just("one").skipLast(-1); + Flowable.just("one").skipLast(-1); } } \ No newline at end of file diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSkipLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipLastTimedTest.java similarity index 82% rename from src/test/java/io/reactivex/internal/operators/OperatorSkipLastTimedTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipLastTimedTest.java index a65f4c15a1..08f52d2a06 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSkipLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipLastTimedTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,10 +22,11 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; public class OperatorSkipLastTimedTest { @@ -33,10 +34,10 @@ public class OperatorSkipLastTimedTest { public void testSkipLastTimed() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); // FIXME the timeunit now matters due to rounding - Observable result = source.skipLast(1000, TimeUnit.MILLISECONDS, scheduler); + Flowable result = source.skipLast(1000, TimeUnit.MILLISECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -72,9 +73,9 @@ public void testSkipLastTimed() { public void testSkipLastTimedErrorBeforeTime() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); + Flowable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -97,9 +98,9 @@ public void testSkipLastTimedErrorBeforeTime() { public void testSkipLastTimedCompleteBeforeTime() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); + Flowable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -125,9 +126,9 @@ public void testSkipLastTimedCompleteBeforeTime() { public void testSkipLastTimedWhenAllElementsAreValid() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable result = source.skipLast(1, TimeUnit.MILLISECONDS, scheduler); + Flowable result = source.skipLast(1, TimeUnit.MILLISECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSkipTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipTest.java similarity index 83% rename from src/test/java/io/reactivex/internal/operators/OperatorSkipTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipTest.java index 629be744d7..e034ff2591 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSkipTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -24,9 +24,9 @@ import org.junit.Test; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.LongConsumer; -import io.reactivex.internal.operators.OperatorSkip; import io.reactivex.subscribers.TestSubscriber; public class OperatorSkipTest { @@ -34,7 +34,7 @@ public class OperatorSkipTest { @Test public void testSkipNegativeElements() { - Observable skip = Observable.just("one", "two", "three").skip(-99); + Flowable skip = Flowable.just("one", "two", "three").skip(-99); Subscriber observer = TestHelper.mockSubscriber(); skip.subscribe(observer); @@ -48,7 +48,7 @@ public void testSkipNegativeElements() { @Test public void testSkipZeroElements() { - Observable skip = Observable.just("one", "two", "three").lift(new OperatorSkip(0)); + Flowable skip = Flowable.just("one", "two", "three").lift(new OperatorSkip(0)); Subscriber observer = TestHelper.mockSubscriber(); skip.subscribe(observer); @@ -62,7 +62,7 @@ public void testSkipZeroElements() { @Test public void testSkipOneElement() { - Observable skip = Observable.just("one", "two", "three").lift(new OperatorSkip(1)); + Flowable skip = Flowable.just("one", "two", "three").lift(new OperatorSkip(1)); Subscriber observer = TestHelper.mockSubscriber(); skip.subscribe(observer); @@ -76,7 +76,7 @@ public void testSkipOneElement() { @Test public void testSkipTwoElements() { - Observable skip = Observable.just("one", "two", "three").lift(new OperatorSkip(2)); + Flowable skip = Flowable.just("one", "two", "three").lift(new OperatorSkip(2)); Subscriber observer = TestHelper.mockSubscriber(); skip.subscribe(observer); @@ -90,8 +90,8 @@ public void testSkipTwoElements() { @Test public void testSkipEmptyStream() { - Observable w = Observable.empty(); - Observable skip = w.lift(new OperatorSkip(1)); + Flowable w = Flowable.empty(); + Flowable skip = w.lift(new OperatorSkip(1)); Subscriber observer = TestHelper.mockSubscriber(); skip.subscribe(observer); @@ -103,7 +103,7 @@ public void testSkipEmptyStream() { @Test public void testSkipMultipleObservers() { - Observable skip = Observable.just("one", "two", "three") + Flowable skip = Flowable.just("one", "two", "three") .skip(2); Subscriber observer1 = TestHelper.mockSubscriber(); @@ -126,10 +126,10 @@ public void testSkipError() { Exception e = new Exception(); - Observable ok = Observable.just("one"); - Observable error = Observable.error(e); + Flowable ok = Flowable.just("one"); + Flowable error = Flowable.error(e); - Observable skip = Observable.concat(ok, error).lift(new OperatorSkip(100)); + Flowable skip = Flowable.concat(ok, error).lift(new OperatorSkip(100)); Subscriber observer = TestHelper.mockSubscriber(); skip.subscribe(observer); @@ -144,7 +144,7 @@ public void testSkipError() { public void testBackpressureMultipleSmallAsyncRequests() throws InterruptedException { final AtomicLong requests = new AtomicLong(0); TestSubscriber ts = new TestSubscriber((Long)null); - Observable.interval(100, TimeUnit.MILLISECONDS) + Flowable.interval(100, TimeUnit.MILLISECONDS) .doOnRequest(new LongConsumer() { @Override public void accept(long n) { @@ -165,7 +165,7 @@ public void accept(long n) { @Test public void testRequestOverflowDoesNotOccur() { TestSubscriber ts = new TestSubscriber(Long.MAX_VALUE-1); - Observable.range(1, 10).skip(5).subscribe(ts); + Flowable.range(1, 10).skip(5).subscribe(ts); ts.assertTerminated(); ts.assertComplete(); ts.assertNoErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSkipTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipTimedTest.java similarity index 83% rename from src/test/java/io/reactivex/internal/operators/OperatorSkipTimedTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipTimedTest.java index 3904afb81f..3ac9d301c0 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSkipTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipTimedTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,10 +22,11 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; public class OperatorSkipTimedTest { @@ -33,9 +34,9 @@ public class OperatorSkipTimedTest { public void testSkipTimed() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable result = source.skip(1, TimeUnit.SECONDS, scheduler); + Flowable result = source.skip(1, TimeUnit.SECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -70,9 +71,9 @@ public void testSkipTimed() { public void testSkipTimedFinishBeforeTime() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable result = source.skip(1, TimeUnit.SECONDS, scheduler); + Flowable result = source.skip(1, TimeUnit.SECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -97,9 +98,9 @@ public void testSkipTimedFinishBeforeTime() { public void testSkipTimedErrorBeforeTime() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable result = source.skip(1, TimeUnit.SECONDS, scheduler); + Flowable result = source.skip(1, TimeUnit.SECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -124,9 +125,9 @@ public void testSkipTimedErrorBeforeTime() { public void testSkipTimedErrorAfterTime() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable result = source.skip(1, TimeUnit.SECONDS, scheduler); + Flowable result = source.skip(1, TimeUnit.SECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSkipUntilTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipUntilTest.java similarity index 73% rename from src/test/java/io/reactivex/internal/operators/OperatorSkipUntilTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipUntilTest.java index 56a09e97a4..8d4acb737d 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSkipUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipUntilTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -19,8 +19,9 @@ import org.junit.*; import org.reactivestreams.Subscriber; -import io.reactivex.*; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; +import io.reactivex.processors.PublishProcessor; public class OperatorSkipUntilTest { Subscriber observer; @@ -32,10 +33,10 @@ public void before() { @Test public void normal1() { - PublishSubject source = PublishSubject.create(); - PublishSubject other = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor other = PublishProcessor.create(); - Observable m = source.skipUntil(other); + Flowable m = source.skipUntil(other); m.subscribe(observer); source.onNext(0); @@ -57,9 +58,9 @@ public void normal1() { @Test public void otherNeverFires() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable m = source.skipUntil(Observable.never()); + Flowable m = source.skipUntil(Flowable.never()); m.subscribe(observer); @@ -77,9 +78,9 @@ public void otherNeverFires() { @Test public void otherEmpty() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable m = source.skipUntil(Observable.empty()); + Flowable m = source.skipUntil(Flowable.empty()); m.subscribe(observer); @@ -90,10 +91,10 @@ public void otherEmpty() { @Test public void otherFiresAndCompletes() { - PublishSubject source = PublishSubject.create(); - PublishSubject other = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor other = PublishProcessor.create(); - Observable m = source.skipUntil(other); + Flowable m = source.skipUntil(other); m.subscribe(observer); source.onNext(0); @@ -116,10 +117,10 @@ public void otherFiresAndCompletes() { @Test public void sourceThrows() { - PublishSubject source = PublishSubject.create(); - PublishSubject other = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor other = PublishProcessor.create(); - Observable m = source.skipUntil(other); + Flowable m = source.skipUntil(other); m.subscribe(observer); source.onNext(0); @@ -138,10 +139,10 @@ public void sourceThrows() { @Test public void otherThrowsImmediately() { - PublishSubject source = PublishSubject.create(); - PublishSubject other = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor other = PublishProcessor.create(); - Observable m = source.skipUntil(other); + Flowable m = source.skipUntil(other); m.subscribe(observer); source.onNext(0); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSkipWhileTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipWhileTest.java similarity index 87% rename from src/test/java/io/reactivex/internal/operators/OperatorSkipWhileTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipWhileTest.java index 355ff08231..108db75d62 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSkipWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSkipWhileTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -20,7 +20,8 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Predicate; public class OperatorSkipWhileTest { @@ -46,7 +47,7 @@ public boolean test(Integer value) { @Test public void testSkipWithIndex() { - Observable src = Observable.just(1, 2, 3, 4, 5); + Flowable src = Flowable.just(1, 2, 3, 4, 5); src.skipWhile(INDEX_LESS_THAN_THREE).subscribe(w); InOrder inOrder = inOrder(w); @@ -58,7 +59,7 @@ public void testSkipWithIndex() { @Test public void testSkipEmpty() { - Observable src = Observable.empty(); + Flowable src = Flowable.empty(); src.skipWhile(LESS_THAN_FIVE).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onError(any(Throwable.class)); @@ -67,7 +68,7 @@ public void testSkipEmpty() { @Test public void testSkipEverything() { - Observable src = Observable.just(1, 2, 3, 4, 3, 2, 1); + Flowable src = Flowable.just(1, 2, 3, 4, 3, 2, 1); src.skipWhile(LESS_THAN_FIVE).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onError(any(Throwable.class)); @@ -76,7 +77,7 @@ public void testSkipEverything() { @Test public void testSkipNothing() { - Observable src = Observable.just(5, 3, 1); + Flowable src = Flowable.just(5, 3, 1); src.skipWhile(LESS_THAN_FIVE).subscribe(w); InOrder inOrder = inOrder(w); @@ -89,7 +90,7 @@ public void testSkipNothing() { @Test public void testSkipSome() { - Observable src = Observable.just(1, 2, 3, 4, 5, 3, 1, 5); + Flowable src = Flowable.just(1, 2, 3, 4, 5, 3, 1, 5); src.skipWhile(LESS_THAN_FIVE).subscribe(w); InOrder inOrder = inOrder(w); @@ -103,7 +104,7 @@ public void testSkipSome() { @Test public void testSkipError() { - Observable src = Observable.just(1, 2, 42, 5, 3, 1); + Flowable src = Flowable.just(1, 2, 42, 5, 3, 1); src.skipWhile(LESS_THAN_FIVE).subscribe(w); InOrder inOrder = inOrder(w); @@ -114,7 +115,7 @@ public void testSkipError() { @Test public void testSkipManySubscribers() { - Observable src = Observable.range(1, 10).skipWhile(LESS_THAN_FIVE); + Flowable src = Flowable.range(1, 10).skipWhile(LESS_THAN_FIVE); int n = 5; for (int i = 0; i < n; i++) { Subscriber o = TestHelper.mockSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSubscribeOnTest.java similarity index 93% rename from src/test/java/io/reactivex/internal/operators/OperatorSubscribeOnTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorSubscribeOnTest.java index d796b4a52a..5b59d95ad3 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSubscribeOnTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; @@ -22,11 +22,11 @@ import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.Observable.Operator; +import io.reactivex.Flowable.Operator; import io.reactivex.disposables.Disposable; import io.reactivex.internal.subscriptions.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class OperatorSubscribeOnTest { @@ -39,7 +39,7 @@ public void testIssue813() throws InterruptedException { TestSubscriber observer = new TestSubscriber(); - Observable + Flowable .create(new Publisher() { @Override public void subscribe( @@ -77,7 +77,7 @@ public void subscribe( @Ignore("Publisher.subscribe can't throw") public void testThrownErrorHandling() { TestSubscriber ts = new TestSubscriber(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -92,7 +92,7 @@ public void subscribe(Subscriber s) { @Test public void testOnError() { TestSubscriber ts = new TestSubscriber(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -164,7 +164,7 @@ public Disposable schedule(final Runnable action, final long delayTime, final Ti public void testUnsubscribeInfiniteStream() throws InterruptedException { TestSubscriber ts = new TestSubscriber(); final AtomicInteger count = new AtomicInteger(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber sub) { @@ -188,7 +188,7 @@ public void subscribe(Subscriber sub) { @Test public void testBackpressureReschedulesCorrectly() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(10); - TestSubscriber ts = new TestSubscriber(new Observer() { + TestSubscriber ts = new TestSubscriber(new DefaultObserver() { @Override public void onComplete() { @@ -205,7 +205,7 @@ public void onNext(Integer t) { }); ts.request(10); - Observable.range(1, 10000000).subscribeOn(Schedulers.newThread()).take(20).subscribe(ts); + Flowable.range(1, 10000000).subscribeOn(Schedulers.newThread()).take(20).subscribe(ts); latch.await(); Thread t = ts.lastThread(); System.out.println("First schedule: " + t); @@ -219,7 +219,7 @@ public void onNext(Integer t) { @Test public void testSetProducerSynchronousRequest() { TestSubscriber ts = new TestSubscriber(); - Observable.just(1, 2, 3).lift(new Operator() { + Flowable.just(1, 2, 3).lift(new Operator() { @Override public Subscriber apply(final Subscriber child) { @@ -239,7 +239,7 @@ public void cancel() { } }); - Subscriber parent = new Observer() { + Subscriber parent = new DefaultObserver() { @Override public void onComplete() { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSwitchIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSwitchIfEmptyTest.java similarity index 82% rename from src/test/java/io/reactivex/internal/operators/OperatorSwitchIfEmptyTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorSwitchIfEmptyTest.java index 906f9c621a..d6d1df4e3f 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSwitchIfEmptyTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; @@ -22,11 +22,11 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.functions.Consumer; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class OperatorSwitchIfEmptyTest { @@ -34,8 +34,8 @@ public class OperatorSwitchIfEmptyTest { @Test public void testSwitchWhenNotEmpty() throws Exception { final AtomicBoolean subscribed = new AtomicBoolean(false); - final Observable observable = Observable.just(4) - .switchIfEmpty(Observable.just(2) + final Flowable observable = Flowable.just(4) + .switchIfEmpty(Flowable.just(2) .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -49,8 +49,8 @@ public void accept(Subscription s) { @Test public void testSwitchWhenEmpty() throws Exception { - final Observable observable = Observable.empty() - .switchIfEmpty(Observable.fromIterable(Arrays.asList(42))); + final Flowable observable = Flowable.empty() + .switchIfEmpty(Flowable.fromIterable(Arrays.asList(42))); assertEquals(42, observable.toBlocking().single().intValue()); } @@ -58,7 +58,7 @@ public void testSwitchWhenEmpty() throws Exception { @Test public void testSwitchWithProducer() throws Exception { final AtomicBoolean emitted = new AtomicBoolean(false); - Observable withProducer = Observable.create(new Publisher() { + Flowable withProducer = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber subscriber) { subscriber.onSubscribe(new Subscription() { @@ -79,7 +79,7 @@ public void cancel() { } }); - final Observable observable = Observable.empty().switchIfEmpty(withProducer); + final Flowable observable = Flowable.empty().switchIfEmpty(withProducer); assertEquals(42, observable.toBlocking().single().intValue()); } @@ -88,7 +88,7 @@ public void testSwitchTriggerUnsubscribe() throws Exception { final BooleanSubscription bs = new BooleanSubscription(); - Observable withProducer = Observable.create(new Publisher() { + Flowable withProducer = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber subscriber) { subscriber.onSubscribe(bs); @@ -96,12 +96,12 @@ public void subscribe(final Subscriber subscriber) { } }); - Observable.empty() + Flowable.empty() .switchIfEmpty(withProducer) - .lift(new Observable.Operator() { + .lift(new Flowable.Operator() { @Override public Subscriber apply(final Subscriber child) { - return new Observer() { + return new DefaultObserver() { @Override public void onComplete() { @@ -131,13 +131,13 @@ public void onNext(Long aLong) { public void testSwitchShouldTriggerUnsubscribe() { final BooleanSubscription bs = new BooleanSubscription(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber subscriber) { subscriber.onSubscribe(bs); subscriber.onComplete(); } - }).switchIfEmpty(Observable.never()).subscribe(); + }).switchIfEmpty(Flowable.never()).subscribe(); assertTrue(bs.isCancelled()); } @@ -146,7 +146,7 @@ public void testSwitchRequestAlternativeObservableWithBackpressure() { TestSubscriber ts = new TestSubscriber(1L); - Observable.empty().switchIfEmpty(Observable.just(1, 2, 3)).subscribe(ts); + Flowable.empty().switchIfEmpty(Flowable.just(1, 2, 3)).subscribe(ts); assertEquals(Arrays.asList(1), ts.values()); ts.assertNoErrors(); @@ -158,7 +158,7 @@ public void testSwitchRequestAlternativeObservableWithBackpressure() { @Test public void testBackpressureNoRequest() { TestSubscriber ts = new TestSubscriber((Long)null); - Observable.empty().switchIfEmpty(Observable.just(1, 2, 3)).subscribe(ts); + Flowable.empty().switchIfEmpty(Flowable.just(1, 2, 3)).subscribe(ts); ts.assertNoValues(); ts.assertNoErrors(); } @@ -166,7 +166,7 @@ public void testBackpressureNoRequest() { @Test public void testBackpressureOnFirstObservable() { TestSubscriber ts = new TestSubscriber((Long)null); - Observable.just(1,2,3).switchIfEmpty(Observable.just(4, 5, 6)).subscribe(ts); + Flowable.just(1,2,3).switchIfEmpty(Flowable.just(4, 5, 6)).subscribe(ts); ts.assertNotComplete(); ts.assertNoErrors(); ts.assertNoValues(); @@ -175,7 +175,7 @@ public void testBackpressureOnFirstObservable() { @Test(timeout = 10000) public void testRequestsNotLost() throws InterruptedException { final TestSubscriber ts = new TestSubscriber((Long)null); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber subscriber) { @@ -198,7 +198,7 @@ public void cancel() { } }); }}) - .switchIfEmpty(Observable.fromIterable(Arrays.asList(1L, 2L, 3L))) + .switchIfEmpty(Flowable.fromIterable(Arrays.asList(1L, 2L, 3L))) .subscribeOn(Schedulers.computation()) .subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSwitchTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSwitchTest.java similarity index 79% rename from src/test/java/io/reactivex/internal/operators/OperatorSwitchTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorSwitchTest.java index e61c191562..553280710e 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorSwitchTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -27,13 +27,13 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.*; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; public class OperatorSwitchTest { @@ -50,11 +50,11 @@ public void before() { @Test public void testSwitchWhenOuterCompleteBeforeInner() { - Observable> source = Observable.create(new Publisher>() { + Flowable> source = Flowable.create(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { + public void subscribe(Subscriber> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); - publishNext(observer, 50, Observable.create(new Publisher() { + publishNext(observer, 50, Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -67,7 +67,7 @@ public void subscribe(Subscriber observer) { } }); - Observable sampled = Observable.switchOnNext(source); + Flowable sampled = Flowable.switchOnNext(source); sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -79,11 +79,11 @@ public void subscribe(Subscriber observer) { @Test public void testSwitchWhenInnerCompleteBeforeOuter() { - Observable> source = Observable.create(new Publisher>() { + Flowable> source = Flowable.create(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { + public void subscribe(Subscriber> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); - publishNext(observer, 10, Observable.create(new Publisher() { + publishNext(observer, 10, Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -93,7 +93,7 @@ public void subscribe(Subscriber observer) { } })); - publishNext(observer, 100, Observable.create(new Publisher() { + publishNext(observer, 100, Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -106,7 +106,7 @@ public void subscribe(Subscriber observer) { } }); - Observable sampled = Observable.switchOnNext(source); + Flowable sampled = Flowable.switchOnNext(source); sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -125,11 +125,11 @@ public void subscribe(Subscriber observer) { @Test public void testSwitchWithComplete() { - Observable> source = Observable.create(new Publisher>() { + Flowable> source = Flowable.create(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { + public void subscribe(Subscriber> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); - publishNext(observer, 50, Observable.create(new Publisher() { + publishNext(observer, 50, Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -138,7 +138,7 @@ public void subscribe(final Subscriber observer) { } })); - publishNext(observer, 200, Observable.create(new Publisher() { + publishNext(observer, 200, Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -151,7 +151,7 @@ public void subscribe(final Subscriber observer) { } }); - Observable sampled = Observable.switchOnNext(source); + Flowable sampled = Flowable.switchOnNext(source); sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -184,11 +184,11 @@ public void subscribe(final Subscriber observer) { @Test public void testSwitchWithError() { - Observable> source = Observable.create(new Publisher>() { + Flowable> source = Flowable.create(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { + public void subscribe(Subscriber> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); - publishNext(observer, 50, Observable.create(new Publisher() { + publishNext(observer, 50, Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -197,7 +197,7 @@ public void subscribe(final Subscriber observer) { } })); - publishNext(observer, 200, Observable.create(new Publisher() { + publishNext(observer, 200, Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -210,7 +210,7 @@ public void subscribe(Subscriber observer) { } }); - Observable sampled = Observable.switchOnNext(source); + Flowable sampled = Flowable.switchOnNext(source); sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -243,11 +243,11 @@ public void subscribe(Subscriber observer) { @Test public void testSwitchWithSubsequenceComplete() { - Observable> source = Observable.create(new Publisher>() { + Flowable> source = Flowable.create(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { + public void subscribe(Subscriber> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); - publishNext(observer, 50, Observable.create(new Publisher() { + publishNext(observer, 50, Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -256,7 +256,7 @@ public void subscribe(Subscriber observer) { } })); - publishNext(observer, 130, Observable.create(new Publisher() { + publishNext(observer, 130, Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -264,7 +264,7 @@ public void subscribe(Subscriber observer) { } })); - publishNext(observer, 150, Observable.create(new Publisher() { + publishNext(observer, 150, Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -274,7 +274,7 @@ public void subscribe(Subscriber observer) { } }); - Observable sampled = Observable.switchOnNext(source); + Flowable sampled = Flowable.switchOnNext(source); sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -297,11 +297,11 @@ public void subscribe(Subscriber observer) { @Test public void testSwitchWithSubsequenceError() { - Observable> source = Observable.create(new Publisher>() { + Flowable> source = Flowable.create(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { + public void subscribe(Subscriber> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); - publishNext(observer, 50, Observable.create(new Publisher() { + publishNext(observer, 50, Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -310,7 +310,7 @@ public void subscribe(Subscriber observer) { } })); - publishNext(observer, 130, Observable.create(new Publisher() { + publishNext(observer, 130, Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -318,7 +318,7 @@ public void subscribe(Subscriber observer) { } })); - publishNext(observer, 150, Observable.create(new Publisher() { + publishNext(observer, 150, Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -329,7 +329,7 @@ public void subscribe(Subscriber observer) { } }); - Observable sampled = Observable.switchOnNext(source); + Flowable sampled = Flowable.switchOnNext(source); sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -380,11 +380,11 @@ public void run() { @Test public void testSwitchIssue737() { // https://github.com/ReactiveX/RxJava/issues/737 - Observable> source = Observable.create(new Publisher>() { + Flowable> source = Flowable.create(new Publisher>() { @Override - public void subscribe(Subscriber> observer) { + public void subscribe(Subscriber> observer) { observer.onSubscribe(EmptySubscription.INSTANCE); - publishNext(observer, 0, Observable.create(new Publisher() { + publishNext(observer, 0, Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -395,7 +395,7 @@ public void subscribe(Subscriber observer) { publishCompleted(observer, 40); } })); - publishNext(observer, 25, Observable.create(new Publisher() { + publishNext(observer, 25, Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -409,7 +409,7 @@ public void subscribe(Subscriber observer) { } }); - Observable sampled = Observable.switchOnNext(source); + Flowable sampled = Flowable.switchOnNext(source); sampled.subscribe(observer); scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS); @@ -427,11 +427,11 @@ public void subscribe(Subscriber observer) { @Test public void testBackpressure() { - PublishSubject o1 = PublishSubject.create(); - PublishSubject o2 = PublishSubject.create(); - PublishSubject o3 = PublishSubject.create(); + PublishProcessor o1 = PublishProcessor.create(); + PublishProcessor o2 = PublishProcessor.create(); + PublishProcessor o3 = PublishProcessor.create(); - PublishSubject> o = PublishSubject.create(); + PublishProcessor> o = PublishProcessor.create(); publishNext(o, 0, o1); publishNext(o, 5, o2); @@ -450,7 +450,7 @@ public void testBackpressure() { final TestSubscriber testSubscriber = new TestSubscriber(); - Observable.switchOnNext(o).subscribe(new Observer() { + Flowable.switchOnNext(o).subscribe(new DefaultObserver() { private int requested = 0; @@ -490,13 +490,13 @@ public void onNext(String s) { @Test public void testUnsubscribe() { final AtomicBoolean isUnsubscribed = new AtomicBoolean(); - Observable.switchOnNext( - Observable.create(new Publisher>() { + Flowable.switchOnNext( + Flowable.create(new Publisher>() { @Override - public void subscribe(final Subscriber> subscriber) { + public void subscribe(final Subscriber> subscriber) { BooleanSubscription bs = new BooleanSubscription(); subscriber.onSubscribe(bs); - subscriber.onNext(Observable.just(1)); + subscriber.onNext(Flowable.just(1)); isUnsubscribed.set(bs.isCancelled()); } }) @@ -506,13 +506,13 @@ public void subscribe(final Subscriber> subscriber) /** The upstream producer hijacked the switch producer stopping the requests aimed at the inner observables. */ @Test public void testIssue2654() { - Observable oneItem = Observable.just("Hello").mergeWith(Observable.never()); + Flowable oneItem = Flowable.just("Hello").mergeWith(Flowable.never()); - Observable src = oneItem.switchMap(new Function>() { + Flowable src = oneItem.switchMap(new Function>() { @Override - public Observable apply(final String s) { - return Observable.just(s) - .mergeWith(Observable.interval(10, TimeUnit.MILLISECONDS) + public Flowable apply(final String s) { + return Flowable.just(s) + .mergeWith(Flowable.interval(10, TimeUnit.MILLISECONDS) .map(new Function() { @Override public String apply(Long i) { @@ -549,13 +549,13 @@ public void onNext(String t) { @Test(timeout = 10000) public void testInitialRequestsAreAdditive() { TestSubscriber ts = new TestSubscriber((Long)null); - Observable.switchOnNext( - Observable.interval(100, TimeUnit.MILLISECONDS) + Flowable.switchOnNext( + Flowable.interval(100, TimeUnit.MILLISECONDS) .map( - new Function>() { + new Function>() { @Override - public Observable apply(Long t) { - return Observable.just(1L, 2L, 3L); + public Flowable apply(Long t) { + return Flowable.just(1L, 2L, 3L); } } ).take(3)) @@ -568,12 +568,12 @@ public Observable apply(Long t) { @Test(timeout = 10000) public void testInitialRequestsDontOverflow() { TestSubscriber ts = new TestSubscriber((Long)null); - Observable.switchOnNext( - Observable.interval(100, TimeUnit.MILLISECONDS) - .map(new Function>() { + Flowable.switchOnNext( + Flowable.interval(100, TimeUnit.MILLISECONDS) + .map(new Function>() { @Override - public Observable apply(Long t) { - return Observable.fromIterable(Arrays.asList(1L, 2L, 3L)); + public Flowable apply(Long t) { + return Flowable.fromIterable(Arrays.asList(1L, 2L, 3L)); } }).take(3)).subscribe(ts); ts.request(Long.MAX_VALUE - 1); @@ -586,12 +586,12 @@ public Observable apply(Long t) { @Test(timeout = 10000) public void testSecondaryRequestsDontOverflow() throws InterruptedException { TestSubscriber ts = new TestSubscriber((Long)null); - Observable.switchOnNext( - Observable.interval(100, TimeUnit.MILLISECONDS) - .map(new Function>() { + Flowable.switchOnNext( + Flowable.interval(100, TimeUnit.MILLISECONDS) + .map(new Function>() { @Override - public Observable apply(Long t) { - return Observable.fromIterable(Arrays.asList(1L, 2L, 3L)); + public Flowable apply(Long t) { + return Flowable.fromIterable(Arrays.asList(1L, 2L, 3L)); } }).take(3)).subscribe(ts); ts.request(1); @@ -610,12 +610,12 @@ public void testSecondaryRequestsAdditivelyAreMoreThanLongMaxValueInducesMaxValu final List requests = new CopyOnWriteArrayList(); TestSubscriber ts = new TestSubscriber(1L); - Observable.switchOnNext( - Observable.interval(100, TimeUnit.MILLISECONDS) - .map(new Function>() { + Flowable.switchOnNext( + Flowable.interval(100, TimeUnit.MILLISECONDS) + .map(new Function>() { @Override - public Observable apply(Long t) { - return Observable.fromIterable(Arrays.asList(1L, 2L, 3L)) + public Flowable apply(Long t) { + return Flowable.fromIterable(Arrays.asList(1L, 2L, 3L)) .doOnRequest(new LongConsumer() { @Override public void accept(long v) { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorTakeLastOneTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeLastOneTest.java similarity index 86% rename from src/test/java/io/reactivex/internal/operators/OperatorTakeLastOneTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeLastOneTest.java index 7814126317..137ab27e3e 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorTakeLastOneTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeLastOneTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; @@ -20,17 +20,17 @@ import org.junit.Test; +import io.reactivex.Flowable; import io.reactivex.functions.Consumer; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; public class OperatorTakeLastOneTest { @Test public void testLastOfManyReturnsLast() { TestSubscriber s = new TestSubscriber(); - Observable.range(1, 10).takeLast(1).subscribe(s); + Flowable.range(1, 10).takeLast(1).subscribe(s); s.assertValue(10); s.assertNoErrors(); s.assertTerminated(); @@ -41,7 +41,7 @@ public void testLastOfManyReturnsLast() { @Test public void testLastOfEmptyReturnsEmpty() { TestSubscriber s = new TestSubscriber(); - Observable.empty().takeLast(1).subscribe(s); + Flowable.empty().takeLast(1).subscribe(s); s.assertNoValues(); s.assertNoErrors(); s.assertTerminated(); @@ -52,7 +52,7 @@ public void testLastOfEmptyReturnsEmpty() { @Test public void testLastOfOneReturnsLast() { TestSubscriber s = new TestSubscriber(); - Observable.just(1).takeLast(1).subscribe(s); + Flowable.just(1).takeLast(1).subscribe(s); s.assertValue(1); s.assertNoErrors(); s.assertTerminated(); @@ -69,7 +69,7 @@ public void run() { unsubscribed.set(true); } }; - Observable.just(1).doOnCancel(unsubscribeAction) + Flowable.just(1).doOnCancel(unsubscribeAction) .takeLast(1).subscribe(); assertTrue(unsubscribed.get()); } @@ -77,7 +77,7 @@ public void run() { @Test public void testLastWithBackpressure() { MySubscriber s = new MySubscriber(0); - Observable.just(1).takeLast(1).subscribe(s); + Flowable.just(1).takeLast(1).subscribe(s); assertEquals(0, s.list.size()); s.requestMore(1); assertEquals(1, s.list.size()); @@ -87,7 +87,7 @@ public void testLastWithBackpressure() { public void testTakeLastZeroProcessesAllItemsButIgnoresThem() { final AtomicInteger upstreamCount = new AtomicInteger(); final int num = 10; - long count = Observable.range(1,num).doOnNext(new Consumer() { + long count = Flowable.range(1,num).doOnNext(new Consumer() { @Override public void accept(Integer t) { @@ -98,7 +98,7 @@ public void accept(Integer t) { assertEquals(0L, count); } - private static class MySubscriber extends Observer { + private static class MySubscriber extends DefaultObserver { private long initialRequest; diff --git a/src/test/java/io/reactivex/internal/operators/OperatorTakeLastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeLastTest.java similarity index 84% rename from src/test/java/io/reactivex/internal/operators/OperatorTakeLastTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeLastTest.java index 64ebbf1fee..a9d13bf199 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorTakeLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeLastTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -24,19 +24,19 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.schedulers.Schedulers; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; public class OperatorTakeLastTest { @Test public void testTakeLastEmpty() { - Observable w = Observable.empty(); - Observable take = w.takeLast(2); + Flowable w = Flowable.empty(); + Flowable take = w.takeLast(2); Subscriber observer = TestHelper.mockSubscriber(); take.subscribe(observer); @@ -47,8 +47,8 @@ public void testTakeLastEmpty() { @Test public void testTakeLast1() { - Observable w = Observable.just("one", "two", "three"); - Observable take = w.takeLast(2); + Flowable w = Flowable.just("one", "two", "three"); + Flowable take = w.takeLast(2); Subscriber observer = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(observer); @@ -62,8 +62,8 @@ public void testTakeLast1() { @Test public void testTakeLast2() { - Observable w = Observable.just("one"); - Observable take = w.takeLast(10); + Flowable w = Flowable.just("one"); + Flowable take = w.takeLast(10); Subscriber observer = TestHelper.mockSubscriber(); take.subscribe(observer); @@ -74,8 +74,8 @@ public void testTakeLast2() { @Test public void testTakeLastWithZeroCount() { - Observable w = Observable.just("one"); - Observable take = w.takeLast(0); + Flowable w = Flowable.just("one"); + Flowable take = w.takeLast(0); Subscriber observer = TestHelper.mockSubscriber(); take.subscribe(observer); @@ -87,8 +87,8 @@ public void testTakeLastWithZeroCount() { @Test @Ignore("Null values no longer allowed") public void testTakeLastWithNull() { - Observable w = Observable.just("one", null, "three"); - Observable take = w.takeLast(2); + Flowable w = Flowable.just("one", null, "three"); + Flowable take = w.takeLast(2); Subscriber observer = TestHelper.mockSubscriber(); take.subscribe(observer); @@ -101,13 +101,13 @@ public void testTakeLastWithNull() { @Test(expected = IndexOutOfBoundsException.class) public void testTakeLastWithNegativeCount() { - Observable.just("one").takeLast(-1); + Flowable.just("one").takeLast(-1); } @Test public void testBackpressure1() { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, 100000).takeLast(1) + Flowable.range(1, 100000).takeLast(1) .observeOn(Schedulers.newThread()) .map(newSlowProcessor()).subscribe(ts); ts.awaitTerminalEvent(); @@ -118,11 +118,11 @@ public void testBackpressure1() { @Test public void testBackpressure2() { TestSubscriber ts = new TestSubscriber(); - Observable.range(1, 100000).takeLast(Observable.bufferSize() * 4) + Flowable.range(1, 100000).takeLast(Flowable.bufferSize() * 4) .observeOn(Schedulers.newThread()).map(newSlowProcessor()).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 4, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 4, ts.valueCount()); } private Function newSlowProcessor() { @@ -146,7 +146,7 @@ public Integer apply(Integer i) { @Test public void testIssue1522() { // https://github.com/ReactiveX/RxJava/issues/1522 - assertEquals(0, Observable + assertEquals(0, Flowable .empty() .count() .filter(new Predicate() { @@ -162,7 +162,7 @@ public boolean test(Long v) { @Test public void testIgnoreRequest1() { // If `takeLast` does not ignore `request` properly, StackOverflowError will be thrown. - Observable.range(0, 100000).takeLast(100000).subscribe(new Observer() { + Flowable.range(0, 100000).takeLast(100000).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -188,7 +188,7 @@ public void onNext(Integer integer) { @Test public void testIgnoreRequest2() { // If `takeLast` does not ignore `request` properly, StackOverflowError will be thrown. - Observable.range(0, 100000).takeLast(100000).subscribe(new Observer() { + Flowable.range(0, 100000).takeLast(100000).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -213,7 +213,7 @@ public void onNext(Integer integer) { @Test(timeout = 30000) public void testIgnoreRequest3() { // If `takeLast` does not ignore `request` properly, it will enter an infinite loop. - Observable.range(0, 100000).takeLast(100000).subscribe(new Observer() { + Flowable.range(0, 100000).takeLast(100000).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -240,7 +240,7 @@ public void onNext(Integer integer) { @Test public void testIgnoreRequest4() { // If `takeLast` does not ignore `request` properly, StackOverflowError will be thrown. - Observable.range(0, 100000).takeLast(100000).subscribe(new Observer() { + Flowable.range(0, 100000).takeLast(100000).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -266,7 +266,7 @@ public void onNext(Integer integer) { @Test public void testUnsubscribeTakesEffectEarlyOnFastPath() { final AtomicInteger count = new AtomicInteger(); - Observable.range(0, 100000).takeLast(100000).subscribe(new Observer() { + Flowable.range(0, 100000).takeLast(100000).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -294,7 +294,7 @@ public void onNext(Integer integer) { @Test(timeout=10000) public void testRequestOverflow() { final List list = new ArrayList(); - Observable.range(1, 100).takeLast(50).subscribe(new Observer() { + Flowable.range(1, 100).takeLast(50).subscribe(new DefaultObserver() { @Override public void onStart() { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorTakeLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeLastTimedTest.java similarity index 86% rename from src/test/java/io/reactivex/internal/operators/OperatorTakeLastTimedTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeLastTimedTest.java index df65395427..a4ed7d359d 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorTakeLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeLastTimedTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,27 +22,28 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; -import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.TestSubscriber; public class OperatorTakeLastTimedTest { @Test(expected = IndexOutOfBoundsException.class) public void testTakeLastTimedWithNegativeCount() { - Observable.just("one").takeLast(-1, 1, TimeUnit.SECONDS); + Flowable.just("one").takeLast(-1, 1, TimeUnit.SECONDS); } @Test public void takeLastTimed() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); // FIXME time unit now matters! - Observable result = source.takeLast(1000, TimeUnit.MILLISECONDS, scheduler); + Flowable result = source.takeLast(1000, TimeUnit.MILLISECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -75,10 +76,10 @@ public void takeLastTimed() { public void takeLastTimedDelayCompletion() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); // FIXME time unit now matters - Observable result = source.takeLast(1000, TimeUnit.MILLISECONDS, scheduler); + Flowable result = source.takeLast(1000, TimeUnit.MILLISECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -108,10 +109,10 @@ public void takeLastTimedDelayCompletion() { public void takeLastTimedWithCapacity() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); // FIXME time unit now matters! - Observable result = source.takeLast(2, 1000, TimeUnit.MILLISECONDS, scheduler); + Flowable result = source.takeLast(2, 1000, TimeUnit.MILLISECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -142,9 +143,9 @@ public void takeLastTimedWithCapacity() { public void takeLastTimedThrowingSource() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable result = source.takeLast(1, TimeUnit.SECONDS, scheduler); + Flowable result = source.takeLast(1, TimeUnit.SECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -174,9 +175,9 @@ public void takeLastTimedThrowingSource() { public void takeLastTimedWithZeroCapacity() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable result = source.takeLast(0, 1, TimeUnit.SECONDS, scheduler); + Flowable result = source.takeLast(0, 1, TimeUnit.SECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -208,7 +209,7 @@ public void testContinuousDelivery() { TestSubscriber ts = new TestSubscriber((Long)null); - PublishSubject ps = PublishSubject.create(); + PublishProcessor ps = PublishProcessor.create(); ps.takeLast(1000, TimeUnit.MILLISECONDS, scheduler).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorTakeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeTest.java similarity index 90% rename from src/test/java/io/reactivex/internal/operators/OperatorTakeTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeTest.java index f0bd83f101..9e10eae9f4 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorTakeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,20 +25,21 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.*; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.TestSubscriber; public class OperatorTakeTest { @Test public void testTake1() { - Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); - Observable take = w.take(2); + Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); + Flowable take = w.take(2); Subscriber observer = TestHelper.mockSubscriber(); take.subscribe(observer); @@ -51,8 +52,8 @@ public void testTake1() { @Test public void testTake2() { - Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); - Observable take = w.take(1); + Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); + Flowable take = w.take(1); Subscriber observer = TestHelper.mockSubscriber(); take.subscribe(observer); @@ -65,7 +66,7 @@ public void testTake2() { @Test(expected = IllegalArgumentException.class) public void testTakeWithError() { - Observable.fromIterable(Arrays.asList(1, 2, 3)).take(1) + Flowable.fromIterable(Arrays.asList(1, 2, 3)).take(1) .map(new Function() { @Override public Integer apply(Integer t1) { @@ -76,7 +77,7 @@ public Integer apply(Integer t1) { @Test public void testTakeWithErrorHappeningInOnNext() { - Observable w = Observable.fromIterable(Arrays.asList(1, 2, 3)) + Flowable w = Flowable.fromIterable(Arrays.asList(1, 2, 3)) .take(2).map(new Function() { @Override public Integer apply(Integer t1) { @@ -93,7 +94,7 @@ public Integer apply(Integer t1) { @Test public void testTakeWithErrorHappeningInTheLastOnNext() { - Observable w = Observable.fromIterable(Arrays.asList(1, 2, 3)).take(1).map(new Function() { + Flowable w = Flowable.fromIterable(Arrays.asList(1, 2, 3)).take(1).map(new Function() { @Override public Integer apply(Integer t1) { throw new IllegalArgumentException("some error"); @@ -109,7 +110,7 @@ public Integer apply(Integer t1) { @Test public void testTakeDoesntLeakErrors() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -135,7 +136,7 @@ public void subscribe(Subscriber observer) { public void testTakeZeroDoesntLeakError() { final AtomicBoolean subscribed = new AtomicBoolean(false); final BooleanSubscription bs = new BooleanSubscription(); - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { subscribed.set(true); @@ -160,11 +161,11 @@ public void subscribe(Subscriber observer) { @Test public void testUnsubscribeAfterTake() { TestObservableFunc f = new TestObservableFunc("one", "two", "three"); - Observable w = Observable.create(f); + Flowable w = Flowable.create(f); Subscriber observer = TestHelper.mockSubscriber(); - Observable take = w.take(1); + Flowable take = w.take(1); take.subscribe(observer); // wait for the Observable to complete @@ -203,7 +204,7 @@ public void accept(Long l) { @Test(timeout = 2000) public void testMultiTake() { final AtomicInteger count = new AtomicInteger(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -265,7 +266,7 @@ public void run() { } } - private static Observable INFINITE_OBSERVABLE = Observable.create(new Publisher() { + private static Flowable INFINITE_OBSERVABLE = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber op) { @@ -301,7 +302,7 @@ public void testProducerRequestThroughTake() { TestSubscriber ts = new TestSubscriber(); ts.request(3); final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -329,7 +330,7 @@ public void testProducerRequestThroughTakeIsModified() { TestSubscriber ts = new TestSubscriber(); ts.request(3); final AtomicLong requested = new AtomicLong(); - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -356,7 +357,7 @@ public void cancel() { public void testInterrupt() throws InterruptedException { final AtomicReference exception = new AtomicReference(); final CountDownLatch latch = new CountDownLatch(1); - Observable.just(1).subscribeOn(Schedulers.computation()).take(1) + Flowable.just(1).subscribeOn(Schedulers.computation()).take(1) .subscribe(new Consumer() { @Override @@ -381,7 +382,7 @@ public void accept(Integer t1) { public void testDoesntRequestMoreThanNeededFromUpstream() throws InterruptedException { final AtomicLong requests = new AtomicLong(); TestSubscriber ts = new TestSubscriber((Long)null); - Observable.interval(100, TimeUnit.MILLISECONDS) + Flowable.interval(100, TimeUnit.MILLISECONDS) // .doOnRequest(new LongConsumer() { @Override @@ -406,7 +407,7 @@ public void accept(long n) { @Test public void takeFinalValueThrows() { - Observable source = Observable.just(1).take(1); + Flowable source = Flowable.just(1).take(1); TestSubscriber ts = new TestSubscriber() { @Override @@ -424,7 +425,7 @@ public void onNext(Integer t) { @Test public void testReentrantTake() { - final PublishSubject source = PublishSubject.create(); + final PublishProcessor source = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorTakeTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeTimedTest.java similarity index 83% rename from src/test/java/io/reactivex/internal/operators/OperatorTakeTimedTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeTimedTest.java index 738de4eb79..3ce513c05e 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorTakeTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeTimedTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,10 +22,11 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; public class OperatorTakeTimedTest { @@ -33,9 +34,9 @@ public class OperatorTakeTimedTest { public void testTakeTimed() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable result = source.take(1, TimeUnit.SECONDS, scheduler); + Flowable result = source.take(1, TimeUnit.SECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -64,9 +65,9 @@ public void testTakeTimed() { public void testTakeTimedErrorBeforeTime() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable result = source.take(1, TimeUnit.SECONDS, scheduler); + Flowable result = source.take(1, TimeUnit.SECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); @@ -96,9 +97,9 @@ public void testTakeTimedErrorBeforeTime() { public void testTakeTimedErrorAfterTime() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - Observable result = source.take(1, TimeUnit.SECONDS, scheduler); + Flowable result = source.take(1, TimeUnit.SECONDS, scheduler); Subscriber o = TestHelper.mockSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorTakeUntilPredicateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeUntilPredicateTest.java similarity index 86% rename from src/test/java/io/reactivex/internal/operators/OperatorTakeUntilPredicateTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeUntilPredicateTest.java index 857b5af916..5f3cb92206 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorTakeUntilPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeUntilPredicateTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -19,8 +19,9 @@ import org.junit.Test; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Predicate; import io.reactivex.subscribers.TestSubscriber; ; @@ -30,7 +31,7 @@ public class OperatorTakeUntilPredicateTest { public void takeEmpty() { Subscriber o = TestHelper.mockSubscriber(); - Observable.empty().takeUntil(new Predicate() { + Flowable.empty().takeUntil(new Predicate() { @Override public boolean test(Object v) { return true; @@ -45,7 +46,7 @@ public boolean test(Object v) { public void takeAll() { Subscriber o = TestHelper.mockSubscriber(); - Observable.just(1, 2).takeUntil(new Predicate() { + Flowable.just(1, 2).takeUntil(new Predicate() { @Override public boolean test(Integer v) { return false; @@ -61,7 +62,7 @@ public boolean test(Integer v) { public void takeFirst() { Subscriber o = TestHelper.mockSubscriber(); - Observable.just(1, 2).takeUntil(new Predicate() { + Flowable.just(1, 2).takeUntil(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -77,7 +78,7 @@ public boolean test(Integer v) { public void takeSome() { Subscriber o = TestHelper.mockSubscriber(); - Observable.just(1, 2, 3).takeUntil(new Predicate() { + Flowable.just(1, 2, 3).takeUntil(new Predicate() { @Override public boolean test(Integer t1) { return t1 == 2; @@ -101,7 +102,7 @@ public boolean test(Integer t1) { throw new TestException("Forced failure"); } }; - Observable.just(1, 2, 3).takeUntil(predicate).subscribe(o); + Flowable.just(1, 2, 3).takeUntil(predicate).subscribe(o); verify(o).onNext(1); verify(o, never()).onNext(2); @@ -113,9 +114,9 @@ public boolean test(Integer t1) { public void sourceThrows() { Subscriber o = TestHelper.mockSubscriber(); - Observable.just(1) - .concatWith(Observable.error(new TestException())) - .concatWith(Observable.just(2)) + Flowable.just(1) + .concatWith(Flowable.error(new TestException())) + .concatWith(Flowable.just(2)) .takeUntil(new Predicate() { @Override public boolean test(Integer v) { @@ -132,7 +133,7 @@ public boolean test(Integer v) { public void backpressure() { TestSubscriber ts = new TestSubscriber(5L); - Observable.range(1, 1000).takeUntil(new Predicate() { + Flowable.range(1, 1000).takeUntil(new Predicate() { @Override public boolean test(Integer v) { return false; @@ -154,7 +155,7 @@ public boolean test(String t) { throw e; } }; - Observable.just("abc").takeUntil(predicate).subscribe(ts); + Flowable.just("abc").takeUntil(predicate).subscribe(ts); ts.assertTerminated(); ts.assertNotComplete(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeUntilTest.java similarity index 87% rename from src/test/java/io/reactivex/internal/operators/OperatorTakeUntilTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeUntilTest.java index 6ac26e91cc..89a5f61c24 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeUntilTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -19,8 +19,9 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; +import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; public class OperatorTakeUntilTest { @@ -33,8 +34,8 @@ public void testTakeUntil() { TestObservable other = new TestObservable(sOther); Subscriber result = TestHelper.mockSubscriber(); - Observable stringObservable = Observable.create(source) - .takeUntil(Observable.create(other)); + Flowable stringObservable = Flowable.create(source) + .takeUntil(Flowable.create(other)); stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); @@ -60,7 +61,7 @@ public void testTakeUntilSourceCompleted() { TestObservable other = new TestObservable(sOther); Subscriber result = TestHelper.mockSubscriber(); - Observable stringObservable = Observable.create(source).takeUntil(Observable.create(other)); + Flowable stringObservable = Flowable.create(source).takeUntil(Flowable.create(other)); stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); @@ -82,7 +83,7 @@ public void testTakeUntilSourceError() { Throwable error = new Throwable(); Subscriber result = TestHelper.mockSubscriber(); - Observable stringObservable = Observable.create(source).takeUntil(Observable.create(other)); + Flowable stringObservable = Flowable.create(source).takeUntil(Flowable.create(other)); stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); @@ -107,7 +108,7 @@ public void testTakeUntilOtherError() { Throwable error = new Throwable(); Subscriber result = TestHelper.mockSubscriber(); - Observable stringObservable = Observable.create(source).takeUntil(Observable.create(other)); + Flowable stringObservable = Flowable.create(source).takeUntil(Flowable.create(other)); stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); @@ -135,7 +136,7 @@ public void testTakeUntilOtherCompleted() { TestObservable other = new TestObservable(sOther); Subscriber result = TestHelper.mockSubscriber(); - Observable stringObservable = Observable.create(source).takeUntil(Observable.create(other)); + Flowable stringObservable = Flowable.create(source).takeUntil(Flowable.create(other)); stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); @@ -184,8 +185,8 @@ public void subscribe(Subscriber observer) { @Test public void testUntilFires() { - PublishSubject source = PublishSubject.create(); - PublishSubject until = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor until = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber(); @@ -209,8 +210,8 @@ public void testUntilFires() { } @Test public void testMainCompletes() { - PublishSubject source = PublishSubject.create(); - PublishSubject until = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor until = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber(); @@ -232,8 +233,8 @@ public void testMainCompletes() { } @Test public void testDownstreamUnsubscribes() { - PublishSubject source = PublishSubject.create(); - PublishSubject until = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor until = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber(); @@ -253,11 +254,11 @@ public void testDownstreamUnsubscribes() { assertFalse("TestSubscriber is unsubscribed", ts.isCancelled()); } public void testBackpressure() { - PublishSubject until = PublishSubject.create(); + PublishProcessor until = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber((Long)null); - Observable.range(1, 10).takeUntil(until).unsafeSubscribe(ts); + Flowable.range(1, 10).takeUntil(until).unsafeSubscribe(ts); assertTrue(until.hasSubscribers()); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorTakeWhileTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeWhileTest.java similarity index 88% rename from src/test/java/io/reactivex/internal/operators/OperatorTakeWhileTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeWhileTest.java index a0a3936792..5acb0e41fe 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorTakeWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTakeWhileTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -20,19 +20,20 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Predicate; import io.reactivex.internal.subscriptions.EmptySubscription; -import io.reactivex.subjects.*; +import io.reactivex.processors.*; import io.reactivex.subscribers.TestSubscriber; public class OperatorTakeWhileTest { @Test public void testTakeWhile1() { - Observable w = Observable.just(1, 2, 3); - Observable take = w.takeWhile(new Predicate() { + Flowable w = Flowable.just(1, 2, 3); + Flowable take = w.takeWhile(new Predicate() { @Override public boolean test(Integer input) { return input < 3; @@ -50,8 +51,8 @@ public boolean test(Integer input) { @Test public void testTakeWhileOnSubject1() { - Subject s = PublishSubject.create(); - Observable take = s.takeWhile(new Predicate() { + FlowProcessor s = PublishProcessor.create(); + Flowable take = s.takeWhile(new Predicate() { @Override public boolean test(Integer input) { return input < 3; @@ -79,8 +80,8 @@ public boolean test(Integer input) { @Test public void testTakeWhile2() { - Observable w = Observable.just("one", "two", "three"); - Observable take = w.takeWhile(new Predicate() { + Flowable w = Flowable.just("one", "two", "three"); + Flowable take = w.takeWhile(new Predicate() { int index = 0; @Override @@ -100,7 +101,7 @@ public boolean test(String input) { @Test public void testTakeWhileDoesntLeakErrors() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -123,7 +124,7 @@ public void testTakeWhileProtectsPredicateCall() { final RuntimeException testException = new RuntimeException("test exception"); Subscriber observer = TestHelper.mockSubscriber(); - Observable take = Observable.create(source) + Flowable take = Flowable.create(source) .takeWhile(new Predicate() { @Override public boolean test(String s) { @@ -150,7 +151,7 @@ public void testUnsubscribeAfterTake() { TestObservable w = new TestObservable(s, "one", "two", "three"); Subscriber observer = TestHelper.mockSubscriber(); - Observable take = Observable.create(w) + Flowable take = Flowable.create(w) .takeWhile(new Predicate() { int index = 0; @@ -216,7 +217,7 @@ public void run() { @Test public void testBackpressure() { - Observable source = Observable.range(1, 1000).takeWhile(new Predicate() { + Flowable source = Flowable.range(1, 1000).takeWhile(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 100; @@ -237,7 +238,7 @@ public boolean test(Integer t1) { @Test public void testNoUnsubscribeDownstream() { - Observable source = Observable.range(1, 1000).takeWhile(new Predicate() { + Flowable source = Flowable.range(1, 1000).takeWhile(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 2; @@ -256,7 +257,7 @@ public boolean test(Integer t1) { @Test public void testErrorCauseIncludesLastValue() { TestSubscriber ts = new TestSubscriber(); - Observable.just("abc").takeWhile(new Predicate() { + Flowable.just("abc").takeWhile(new Predicate() { @Override public boolean test(String t1) { throw new TestException(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorThrottleFirstTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorThrottleFirstTest.java similarity index 90% rename from src/test/java/io/reactivex/internal/operators/OperatorThrottleFirstTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorThrottleFirstTest.java index 3c15bf0369..9dd27acddf 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorThrottleFirstTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorThrottleFirstTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -24,9 +24,10 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; public class OperatorThrottleFirstTest { @@ -43,7 +44,7 @@ public void before() { @Test public void testThrottlingWithCompleted() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -55,7 +56,7 @@ public void subscribe(Subscriber observer) { } }); - Observable sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler); + Flowable sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler); sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -71,7 +72,7 @@ public void subscribe(Subscriber observer) { @Test public void testThrottlingWithError() { - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -82,7 +83,7 @@ public void subscribe(Subscriber observer) { } }); - Observable sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler); + Flowable sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler); sampled.subscribe(observer); InOrder inOrder = inOrder(observer); @@ -124,7 +125,7 @@ public void run() { public void testThrottle() { Subscriber observer = TestHelper.mockSubscriber(); TestScheduler s = new TestScheduler(); - PublishSubject o = PublishSubject.create(); + PublishProcessor o = PublishProcessor.create(); o.throttleFirst(500, TimeUnit.MILLISECONDS, s).subscribe(observer); // send events with simulated time increments diff --git a/src/test/java/io/reactivex/internal/operators/OperatorTimeIntervalTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTimeIntervalTest.java similarity index 86% rename from src/test/java/io/reactivex/internal/operators/OperatorTimeIntervalTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorTimeIntervalTest.java index e39b43fa50..0667dbd57b 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorTimeIntervalTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTimeIntervalTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Mockito.*; @@ -21,9 +21,10 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; -import io.reactivex.subjects.PublishSubject; public class OperatorTimeIntervalTest { @@ -32,14 +33,14 @@ public class OperatorTimeIntervalTest { private Subscriber> observer; private TestScheduler testScheduler; - private PublishSubject subject; - private Observable> observable; + private PublishProcessor subject; + private Flowable> observable; @Before public void setUp() { observer = TestHelper.mockSubscriber(); testScheduler = new TestScheduler(); - subject = PublishSubject.create(); + subject = PublishProcessor.create(); observable = subject.timeInterval(testScheduler); } diff --git a/src/test/java/io/reactivex/internal/operators/OperatorTimeoutTests.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTimeoutTests.java similarity index 88% rename from src/test/java/io/reactivex/internal/operators/OperatorTimeoutTests.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorTimeoutTests.java index d9978c50cb..8e205a484a 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorTimeoutTests.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTimeoutTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -23,23 +23,24 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.TestSubscriber; public class OperatorTimeoutTests { - private PublishSubject underlyingSubject; + private PublishProcessor underlyingSubject; private TestScheduler testScheduler; - private Observable withTimeout; + private Flowable withTimeout; private static final long TIMEOUT = 3; private static final TimeUnit TIME_UNIT = TimeUnit.SECONDS; @Before public void setUp() { - underlyingSubject = PublishSubject.create(); + underlyingSubject = PublishProcessor.create(); testScheduler = new TestScheduler(); withTimeout = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler); } @@ -128,8 +129,8 @@ public void shouldErrorIfUnderlyingErrors() { @Test public void shouldSwitchToOtherIfOnNextNotWithinTimeout() { - Observable other = Observable.just("a", "b", "c"); - Observable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); + Flowable other = Flowable.just("a", "b", "c"); + Flowable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); Subscriber observer = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(observer); @@ -151,8 +152,8 @@ public void shouldSwitchToOtherIfOnNextNotWithinTimeout() { @Test public void shouldSwitchToOtherIfOnErrorNotWithinTimeout() { - Observable other = Observable.just("a", "b", "c"); - Observable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); + Flowable other = Flowable.just("a", "b", "c"); + Flowable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); Subscriber observer = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(observer); @@ -174,8 +175,8 @@ public void shouldSwitchToOtherIfOnErrorNotWithinTimeout() { @Test public void shouldSwitchToOtherIfOnCompletedNotWithinTimeout() { - Observable other = Observable.just("a", "b", "c"); - Observable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); + Flowable other = Flowable.just("a", "b", "c"); + Flowable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); Subscriber observer = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(observer); @@ -197,8 +198,8 @@ public void shouldSwitchToOtherIfOnCompletedNotWithinTimeout() { @Test public void shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout() { - PublishSubject other = PublishSubject.create(); - Observable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); + PublishProcessor other = PublishProcessor.create(); + Flowable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); Subscriber observer = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(observer); @@ -238,7 +239,7 @@ public void shouldTimeoutIfSynchronizedObservableEmitFirstOnNextNotWithinTimeout @Override public void run() { - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber subscriber) { @@ -273,7 +274,7 @@ public void shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout() throws Interr // From https://github.com/ReactiveX/RxJava/pull/951 final Subscription s = mock(Subscription.class); - Observable never = Observable.create(new Publisher() { + Flowable never = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber subscriber) { subscriber.onSubscribe(s); @@ -281,7 +282,7 @@ public void subscribe(Subscriber subscriber) { }); TestScheduler testScheduler = new TestScheduler(); - Observable observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); + Flowable observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); Subscriber observer = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(observer); @@ -302,7 +303,7 @@ public void shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyComplete() { // From https://github.com/ReactiveX/RxJava/pull/951 final Subscription s = mock(Subscription.class); - Observable immediatelyComplete = Observable.create(new Publisher() { + Flowable immediatelyComplete = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber subscriber) { subscriber.onSubscribe(s); @@ -311,7 +312,7 @@ public void subscribe(Subscriber subscriber) { }); TestScheduler testScheduler = new TestScheduler(); - Observable observableWithTimeout = immediatelyComplete.timeout(1000, TimeUnit.MILLISECONDS, + Flowable observableWithTimeout = immediatelyComplete.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); Subscriber observer = TestHelper.mockSubscriber(); @@ -333,7 +334,7 @@ public void shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyErrored() th // From https://github.com/ReactiveX/RxJava/pull/951 final Subscription s = mock(Subscription.class); - Observable immediatelyError = Observable.create(new Publisher() { + Flowable immediatelyError = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber subscriber) { subscriber.onSubscribe(s); @@ -342,7 +343,7 @@ public void subscribe(Subscriber subscriber) { }); TestScheduler testScheduler = new TestScheduler(); - Observable observableWithTimeout = immediatelyError.timeout(1000, TimeUnit.MILLISECONDS, + Flowable observableWithTimeout = immediatelyError.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); Subscriber observer = TestHelper.mockSubscriber(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeoutWithSelectorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTimeoutWithSelectorTest.java similarity index 58% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeoutWithSelectorTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorTimeoutWithSelectorTest.java index 2867268eee..8ca04f945f 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeoutWithSelectorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTimeoutWithSelectorTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertFalse; import static org.mockito.Matchers.*; @@ -25,40 +25,40 @@ import org.mockito.InOrder; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import org.reactivestreams.*; -import io.reactivex.*; -import io.reactivex.NbpObservable.*; -import io.reactivex.disposables.Disposable; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subscribers.TestSubscriber; -public class NbpOperatorTimeoutWithSelectorTest { +public class OperatorTimeoutWithSelectorTest { @Test(timeout = 2000) public void testTimeoutSelectorNormal1() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject timeout = NbpPublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { + Function> timeoutFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Flowable apply(Integer t1) { return timeout; } }; - Supplier> firstTimeoutFunc = new Supplier>() { + Supplier> firstTimeoutFunc = new Supplier>() { @Override - public NbpObservable get() { + public Flowable get() { return timeout; } }; - NbpObservable other = NbpObservable.fromIterable(Arrays.asList(100)); + Flowable other = Flowable.fromIterable(Arrays.asList(100)); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); @@ -79,26 +79,26 @@ public NbpObservable get() { @Test public void testTimeoutSelectorTimeoutFirst() throws InterruptedException { - NbpObservable source = NbpObservable.never(); - final NbpPublishSubject timeout = NbpPublishSubject.create(); + Flowable source = Flowable.never(); + final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { + Function> timeoutFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Flowable apply(Integer t1) { return timeout; } }; - Supplier> firstTimeoutFunc = new Supplier>() { + Supplier> firstTimeoutFunc = new Supplier>() { @Override - public NbpObservable get() { + public Flowable get() { return timeout; } }; - NbpObservable other = NbpObservable.fromIterable(Arrays.asList(100)); + Flowable other = Flowable.fromIterable(Arrays.asList(100)); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); @@ -113,26 +113,26 @@ public NbpObservable get() { @Test public void testTimeoutSelectorFirstThrows() { - NbpObservable source = NbpObservable.never(); - final NbpPublishSubject timeout = NbpPublishSubject.create(); + Flowable source = Flowable.never(); + final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { + Function> timeoutFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Flowable apply(Integer t1) { return timeout; } }; - Supplier> firstTimeoutFunc = new Supplier>() { + Supplier> firstTimeoutFunc = new Supplier>() { @Override - public NbpObservable get() { + public Flowable get() { throw new TestException(); } }; - NbpObservable other = NbpObservable.fromIterable(Arrays.asList(100)); + Flowable other = Flowable.fromIterable(Arrays.asList(100)); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Subscriber o = TestHelper.mockSubscriber(); source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); @@ -144,26 +144,26 @@ public NbpObservable get() { @Test public void testTimeoutSelectorSubsequentThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject timeout = NbpPublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { + Function> timeoutFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Flowable apply(Integer t1) { throw new TestException(); } }; - Supplier> firstTimeoutFunc = new Supplier>() { + Supplier> firstTimeoutFunc = new Supplier>() { @Override - public NbpObservable get() { + public Flowable get() { return timeout; } }; - NbpObservable other = NbpObservable.fromIterable(Arrays.asList(100)); + Flowable other = Flowable.fromIterable(Arrays.asList(100)); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); @@ -178,26 +178,26 @@ public NbpObservable get() { @Test public void testTimeoutSelectorFirstObservableThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject timeout = NbpPublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { + Function> timeoutFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Flowable apply(Integer t1) { return timeout; } }; - Supplier> firstTimeoutFunc = new Supplier>() { + Supplier> firstTimeoutFunc = new Supplier>() { @Override - public NbpObservable get() { - return NbpObservable. error(new TestException()); + public Flowable get() { + return Flowable. error(new TestException()); } }; - NbpObservable other = NbpObservable.fromIterable(Arrays.asList(100)); + Flowable other = Flowable.fromIterable(Arrays.asList(100)); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Subscriber o = TestHelper.mockSubscriber(); source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); @@ -209,26 +209,26 @@ public NbpObservable get() { @Test public void testTimeoutSelectorSubsequentObservableThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject timeout = NbpPublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor timeout = PublishProcessor.create(); - Function> timeoutFunc = new Function>() { + Function> timeoutFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { - return NbpObservable. error(new TestException()); + public Flowable apply(Integer t1) { + return Flowable. error(new TestException()); } }; - Supplier> firstTimeoutFunc = new Supplier>() { + Supplier> firstTimeoutFunc = new Supplier>() { @Override - public NbpObservable get() { + public Flowable get() { return timeout; } }; - NbpObservable other = NbpObservable.fromIterable(Arrays.asList(100)); + Flowable other = Flowable.fromIterable(Arrays.asList(100)); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); @@ -243,24 +243,24 @@ public NbpObservable get() { @Test public void testTimeoutSelectorWithFirstTimeoutFirstAndNoOtherObservable() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject timeout = NbpPublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor timeout = PublishProcessor.create(); - Supplier> firstTimeoutFunc = new Supplier>() { + Supplier> firstTimeoutFunc = new Supplier>() { @Override - public NbpObservable get() { + public Flowable get() { return timeout; } }; - Function> timeoutFunc = new Function>() { + Function> timeoutFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { - return NbpPublishSubject.create(); + public Flowable apply(Integer t1) { + return PublishProcessor.create(); } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Subscriber o = TestHelper.mockSubscriber(); source.timeout(firstTimeoutFunc, timeoutFunc).subscribe(o); timeout.onNext(1); @@ -272,24 +272,24 @@ public NbpObservable apply(Integer t1) { @Test public void testTimeoutSelectorWithTimeoutFirstAndNoOtherObservable() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject timeout = NbpPublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor timeout = PublishProcessor.create(); - Supplier> firstTimeoutFunc = new Supplier>() { + Supplier> firstTimeoutFunc = new Supplier>() { @Override - public NbpObservable get() { - return NbpPublishSubject.create(); + public Flowable get() { + return PublishProcessor.create(); } }; - Function> timeoutFunc = new Function>() { + Function> timeoutFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Flowable apply(Integer t1) { return timeout; } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Subscriber o = TestHelper.mockSubscriber(); source.timeout(firstTimeoutFunc, timeoutFunc).subscribe(o); source.onNext(1); @@ -305,33 +305,33 @@ public NbpObservable apply(Integer t1) { public void testTimeoutSelectorWithTimeoutAndOnNextRaceCondition() throws InterruptedException { // Thread 1 Thread 2 // - // NbpObserver.onNext(1) + // observer.onNext(1) // start timeout // unsubscribe timeout in thread 2 start to do some long-time work in "unsubscribe" - // NbpObserver.onNext(2) + // observer.onNext(2) // timeout.onNext(1) // "unsubscribe" done // // // In the above case, the timeout operator should ignore "timeout.onNext(1)" - // since "NbpObserver" has already seen 2. + // since "observer" has already seen 2. final CountDownLatch observerReceivedTwo = new CountDownLatch(1); final CountDownLatch timeoutEmittedOne = new CountDownLatch(1); final CountDownLatch observerCompleted = new CountDownLatch(1); final CountDownLatch enteredTimeoutOne = new CountDownLatch(1); final AtomicBoolean latchTimeout = new AtomicBoolean(false); - final Function> timeoutFunc = new Function>() { + final Function> timeoutFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Flowable apply(Integer t1) { if (t1 == 1) { // Force "unsubscribe" run on another thread - return NbpObservable.create(new NbpOnSubscribe() { + return Flowable.create(new Publisher() { @Override - public void accept(NbpSubscriber NbpSubscriber) { - NbpSubscriber.onSubscribe(EmptyDisposable.INSTANCE); + public void subscribe(Subscriber subscriber) { + subscriber.onSubscribe(EmptySubscription.INSTANCE); enteredTimeoutOne.countDown(); - // force the timeout message be sent after NbpObserver.onNext(2) + // force the timeout message be sent after observer.onNext(2) while (true) { try { if (!observerReceivedTwo.await(30, TimeUnit.SECONDS)) { @@ -345,17 +345,17 @@ public void accept(NbpSubscriber NbpSubscriber) { // we ignore the interrupt signal from Scheduler. } } - NbpSubscriber.onNext(1); + subscriber.onNext(1); timeoutEmittedOne.countDown(); } }).subscribeOn(Schedulers.newThread()); } else { - return NbpPublishSubject.create(); + return PublishProcessor.create(); } } }; - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + final Subscriber o = TestHelper.mockSubscriber(); doAnswer(new Answer() { @Override @@ -375,14 +375,14 @@ public Void answer(InvocationOnMock invocation) throws Throwable { }).when(o).onComplete(); - final NbpTestSubscriber ts = new NbpTestSubscriber(o); + final TestSubscriber ts = new TestSubscriber(o); new Thread(new Runnable() { @Override public void run() { - NbpPublishSubject source = NbpPublishSubject.create(); - source.timeout(timeoutFunc, NbpObservable.just(3)).subscribe(ts); + PublishProcessor source = PublishProcessor.create(); + source.timeout(timeoutFunc, Flowable.just(3)).subscribe(ts); source.onNext(1); // start timeout try { if(!enteredTimeoutOne.await(30, TimeUnit.SECONDS)) { @@ -411,7 +411,7 @@ public void run() { assertFalse("CoundDownLatch timeout", latchTimeout.get()); InOrder inOrder = inOrder(o); - inOrder.verify(o).onSubscribe((Disposable)notNull()); + inOrder.verify(o).onSubscribe((Subscription)notNull()); inOrder.verify(o).onNext(1); inOrder.verify(o).onNext(2); inOrder.verify(o, never()).onNext(3); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorTimestampTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTimestampTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/OperatorTimestampTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorTimestampTest.java index 302a53202a..4ec7f1e5db 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorTimestampTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorTimestampTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,9 +22,10 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; -import io.reactivex.subjects.PublishSubject; public class OperatorTimestampTest { Subscriber observer; @@ -38,8 +39,8 @@ public void before() { public void timestampWithScheduler() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); - Observable> m = source.timestamp(scheduler); + PublishProcessor source = PublishProcessor.create(); + Flowable> m = source.timestamp(scheduler); m.subscribe(observer); source.onNext(1); @@ -62,8 +63,8 @@ public void timestampWithScheduler() { public void timestampWithScheduler2() { TestScheduler scheduler = new TestScheduler(); - PublishSubject source = PublishSubject.create(); - Observable> m = source.timestamp(scheduler); + PublishProcessor source = PublishProcessor.create(); + Flowable> m = source.timestamp(scheduler); m.subscribe(observer); source.onNext(1); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorToMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorToMapTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/OperatorToMapTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorToMapTest.java index ba8ee122eb..78d914a249 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorToMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorToMapTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -21,8 +21,8 @@ import org.junit.*; import org.reactivestreams.Subscriber; -import io.reactivex.Observable; -import io.reactivex.TestHelper; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; public class OperatorToMapTest { @@ -48,9 +48,9 @@ public String apply(String t1) { @Test public void testToMap() { - Observable source = Observable.just("a", "bb", "ccc", "dddd"); + Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); - Observable> mapped = source.toMap(lengthFunc); + Flowable> mapped = source.toMap(lengthFunc); Map expected = new HashMap(); expected.put(1, "a"); @@ -67,9 +67,9 @@ public void testToMap() { @Test public void testToMapWithValueSelector() { - Observable source = Observable.just("a", "bb", "ccc", "dddd"); + Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); - Observable> mapped = source.toMap(lengthFunc, duplicate); + Flowable> mapped = source.toMap(lengthFunc, duplicate); Map expected = new HashMap(); expected.put(1, "aa"); @@ -86,7 +86,7 @@ public void testToMapWithValueSelector() { @Test public void testToMapWithError() { - Observable source = Observable.just("a", "bb", "ccc", "dddd"); + Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); Function lengthFuncErr = new Function() { @Override @@ -97,7 +97,7 @@ public Integer apply(String t1) { return t1.length(); } }; - Observable> mapped = source.toMap(lengthFuncErr); + Flowable> mapped = source.toMap(lengthFuncErr); Map expected = new HashMap(); expected.put(1, "a"); @@ -115,7 +115,7 @@ public Integer apply(String t1) { @Test public void testToMapWithErrorInValueSelector() { - Observable source = Observable.just("a", "bb", "ccc", "dddd"); + Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); Function duplicateErr = new Function() { @Override @@ -127,7 +127,7 @@ public String apply(String t1) { } }; - Observable> mapped = source.toMap(lengthFunc, duplicateErr); + Flowable> mapped = source.toMap(lengthFunc, duplicateErr); Map expected = new HashMap(); expected.put(1, "aa"); @@ -145,7 +145,7 @@ public String apply(String t1) { @Test public void testToMapWithFactory() { - Observable source = Observable.just("a", "bb", "ccc", "dddd"); + Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); Supplier> mapFactory = new Supplier>() { @Override @@ -168,7 +168,7 @@ public Integer apply(String t1) { return t1.length(); } }; - Observable> mapped = source.toMap(lengthFunc, new Function() { + Flowable> mapped = source.toMap(lengthFunc, new Function() { @Override public String apply(String v) { return v; @@ -189,7 +189,7 @@ public String apply(String v) { @Test public void testToMapWithErrorThrowingFactory() { - Observable source = Observable.just("a", "bb", "ccc", "dddd"); + Flowable source = Flowable.just("a", "bb", "ccc", "dddd"); Supplier> mapFactory = new Supplier>() { @Override @@ -204,7 +204,7 @@ public Integer apply(String t1) { return t1.length(); } }; - Observable> mapped = source.toMap(lengthFunc, new Function() { + Flowable> mapped = source.toMap(lengthFunc, new Function() { @Override public String apply(String v) { return v; diff --git a/src/test/java/io/reactivex/internal/operators/OperatorToMultimapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorToMultimapTest.java similarity index 86% rename from src/test/java/io/reactivex/internal/operators/OperatorToMultimapTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorToMultimapTest.java index 43b0a8f942..b43e2a83a8 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorToMultimapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorToMultimapTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -21,8 +21,8 @@ import org.junit.*; import org.reactivestreams.Subscriber; -import io.reactivex.Observable; -import io.reactivex.TestHelper; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; public class OperatorToMultimapTest { @@ -48,9 +48,9 @@ public String apply(String t1) { @Test public void testToMultimap() { - Observable source = Observable.just("a", "b", "cc", "dd"); + Flowable source = Flowable.just("a", "b", "cc", "dd"); - Observable>> mapped = source.toMultimap(lengthFunc); + Flowable>> mapped = source.toMultimap(lengthFunc); Map> expected = new HashMap>(); expected.put(1, Arrays.asList("a", "b")); @@ -65,9 +65,9 @@ public void testToMultimap() { @Test public void testToMultimapWithValueSelector() { - Observable source = Observable.just("a", "b", "cc", "dd"); + Flowable source = Flowable.just("a", "b", "cc", "dd"); - Observable>> mapped = source.toMultimap(lengthFunc, duplicate); + Flowable>> mapped = source.toMultimap(lengthFunc, duplicate); Map> expected = new HashMap>(); expected.put(1, Arrays.asList("aa", "bb")); @@ -82,7 +82,7 @@ public void testToMultimapWithValueSelector() { @Test public void testToMultimapWithMapFactory() { - Observable source = Observable.just("a", "b", "cc", "dd", "eee", "fff"); + Flowable source = Flowable.just("a", "b", "cc", "dd", "eee", "fff"); Supplier>> mapFactory = new Supplier>>() { @Override @@ -106,7 +106,7 @@ public String apply(String v) { } }; - Observable>> mapped = source.toMultimap( + Flowable>> mapped = source.toMultimap( lengthFunc, identity, mapFactory, new Function>() { @Override @@ -128,7 +128,7 @@ public Collection apply(Integer e) { @Test public void testToMultimapWithCollectionFactory() { - Observable source = Observable.just("cc", "dd", "eee", "eee"); + Flowable source = Flowable.just("cc", "dd", "eee", "eee"); Function> collectionFactory = new Function>() { @Override @@ -154,7 +154,7 @@ public Map> get() { } }; - Observable>> mapped = source + Flowable>> mapped = source .toMultimap(lengthFunc, identity, mapSupplier, collectionFactory); Map> expected = new HashMap>(); @@ -170,7 +170,7 @@ public Map> get() { @Test public void testToMultimapWithError() { - Observable source = Observable.just("a", "b", "cc", "dd"); + Flowable source = Flowable.just("a", "b", "cc", "dd"); Function lengthFuncErr = new Function() { @Override @@ -182,7 +182,7 @@ public Integer apply(String t1) { } }; - Observable>> mapped = source.toMultimap(lengthFuncErr); + Flowable>> mapped = source.toMultimap(lengthFuncErr); Map> expected = new HashMap>(); expected.put(1, Arrays.asList("a", "b")); @@ -197,7 +197,7 @@ public Integer apply(String t1) { @Test public void testToMultimapWithErrorInValueSelector() { - Observable source = Observable.just("a", "b", "cc", "dd"); + Flowable source = Flowable.just("a", "b", "cc", "dd"); Function duplicateErr = new Function() { @Override @@ -209,7 +209,7 @@ public String apply(String t1) { } }; - Observable>> mapped = source.toMultimap(lengthFunc, duplicateErr); + Flowable>> mapped = source.toMultimap(lengthFunc, duplicateErr); Map> expected = new HashMap>(); expected.put(1, Arrays.asList("aa", "bb")); @@ -224,7 +224,7 @@ public String apply(String t1) { @Test public void testToMultimapWithMapThrowingFactory() { - Observable source = Observable.just("a", "b", "cc", "dd", "eee", "fff"); + Flowable source = Flowable.just("a", "b", "cc", "dd", "eee", "fff"); Supplier>> mapFactory = new Supplier>>() { @Override @@ -233,7 +233,7 @@ public Map> get() { } }; - Observable>> mapped = source + Flowable>> mapped = source .toMultimap(lengthFunc, new Function() { @Override public String apply(String v) { @@ -254,7 +254,7 @@ public String apply(String v) { @Test public void testToMultimapWithThrowingCollectionFactory() { - Observable source = Observable.just("cc", "cc", "eee", "eee"); + Flowable source = Flowable.just("cc", "cc", "eee", "eee"); Function> collectionFactory = new Function>() { @Override @@ -280,7 +280,7 @@ public Map> get() { } }; - Observable>> mapped = source.toMultimap(lengthFunc, + Flowable>> mapped = source.toMultimap(lengthFunc, identity, mapSupplier, collectionFactory); Map> expected = new HashMap>(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorToObservableListTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorToObservableListTest.java similarity index 82% rename from src/test/java/io/reactivex/internal/operators/OperatorToObservableListTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorToObservableListTest.java index 660b4ae2f0..c28cc398f0 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorToObservableListTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorToObservableListTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -24,17 +24,17 @@ import org.reactivestreams.Subscriber; import io.reactivex.*; +import io.reactivex.flowable.TestHelper; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; public class OperatorToObservableListTest { @Test public void testList() { - Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); - Observable> observable = w.toList(); + Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); + Flowable> observable = w.toList(); Subscriber> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -45,8 +45,8 @@ public void testList() { @Test public void testListViaObservable() { - Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); - Observable> observable = w.toList(); + Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); + Flowable> observable = w.toList(); Subscriber> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -57,8 +57,8 @@ public void testListViaObservable() { @Test public void testListMultipleSubscribers() { - Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); - Observable> observable = w.toList(); + Flowable w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); + Flowable> observable = w.toList(); Subscriber> o1 = TestHelper.mockSubscriber(); observable.subscribe(o1); @@ -80,8 +80,8 @@ public void testListMultipleSubscribers() { @Test @Ignore("Null values are not allowed") public void testListWithNullValue() { - Observable w = Observable.fromIterable(Arrays.asList("one", null, "three")); - Observable> observable = w.toList(); + Flowable w = Flowable.fromIterable(Arrays.asList("one", null, "three")); + Flowable> observable = w.toList(); Subscriber> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -92,13 +92,13 @@ public void testListWithNullValue() { @Test public void testListWithBlockingFirst() { - Observable o = Observable.fromIterable(Arrays.asList("one", "two", "three")); + Flowable o = Flowable.fromIterable(Arrays.asList("one", "two", "three")); List actual = o.toList().toBlocking().first(); Assert.assertEquals(Arrays.asList("one", "two", "three"), actual); } @Test public void testBackpressureHonored() { - Observable> w = Observable.just(1, 2, 3, 4, 5).toList(); + Flowable> w = Flowable.just(1, 2, 3, 4, 5).toList(); TestSubscriber> ts = new TestSubscriber>((Long)null); w.subscribe(ts); @@ -128,8 +128,8 @@ public void testAsyncRequested() { if (i % 50 == 0) { System.out.println("testAsyncRequested -> " + i); } - PublishSubject source = PublishSubject.create(); - Observable> sorted = source.toList(); + PublishProcessor source = PublishProcessor.create(); + Flowable> sorted = source.toList(); final CyclicBarrier cb = new CyclicBarrier(2); final TestSubscriber> ts = new TestSubscriber>((Long)null); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorToObservableSortedListTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorToObservableSortedListTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/OperatorToObservableSortedListTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorToObservableSortedListTest.java index bf7d316178..36a5ad0123 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorToObservableSortedListTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorToObservableSortedListTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -25,17 +25,17 @@ import org.reactivestreams.Subscriber; import io.reactivex.*; +import io.reactivex.flowable.TestHelper; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; public class OperatorToObservableSortedListTest { @Test public void testSortedList() { - Observable w = Observable.just(1, 3, 2, 5, 4); - Observable> observable = w.toSortedList(); + Flowable w = Flowable.just(1, 3, 2, 5, 4); + Flowable> observable = w.toSortedList(); Subscriber> observer = TestHelper.mockSubscriber(); observable.subscribe(observer); @@ -46,8 +46,8 @@ public void testSortedList() { @Test public void testSortedListWithCustomFunction() { - Observable w = Observable.just(1, 3, 2, 5, 4); - Observable> observable = w.toSortedList(new Comparator() { + Flowable w = Flowable.just(1, 3, 2, 5, 4); + Flowable> observable = w.toSortedList(new Comparator() { @Override public int compare(Integer t1, Integer t2) { @@ -65,12 +65,12 @@ public int compare(Integer t1, Integer t2) { @Test public void testWithFollowingFirst() { - Observable o = Observable.just(1, 3, 2, 5, 4); + Flowable o = Flowable.just(1, 3, 2, 5, 4); assertEquals(Arrays.asList(1, 2, 3, 4, 5), o.toSortedList().toBlocking().first()); } @Test public void testBackpressureHonored() { - Observable> w = Observable.just(1, 3, 2, 5, 4).toSortedList(); + Flowable> w = Flowable.just(1, 3, 2, 5, 4).toSortedList(); TestSubscriber> ts = new TestSubscriber>((Long)null); w.subscribe(ts); @@ -100,8 +100,8 @@ public void testAsyncRequested() { if (i % 50 == 0) { System.out.println("testAsyncRequested -> " + i); } - PublishSubject source = PublishSubject.create(); - Observable> sorted = source.toSortedList(); + PublishProcessor source = PublishProcessor.create(); + Flowable> sorted = source.toSortedList(); final CyclicBarrier cb = new CyclicBarrier(2); final TestSubscriber> ts = new TestSubscriber>((Long)null); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorUnsubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorUnsubscribeOnTest.java similarity index 96% rename from src/test/java/io/reactivex/internal/operators/OperatorUnsubscribeOnTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorUnsubscribeOnTest.java index 48df08e311..133181ded3 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorUnsubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorUnsubscribeOnTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; @@ -33,7 +33,7 @@ public void testUnsubscribeWhenSubscribeOnAndUnsubscribeOnAreOnSameThread() thro try { final ThreadSubscription subscription = new ThreadSubscription(); final AtomicReference subscribeThread = new AtomicReference(); - Observable w = Observable.create(new Publisher() { + Flowable w = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber t1) { @@ -77,7 +77,7 @@ public void testUnsubscribeWhenSubscribeOnAndUnsubscribeOnAreOnDifferentThreads( try { final ThreadSubscription subscription = new ThreadSubscription(); final AtomicReference subscribeThread = new AtomicReference(); - Observable w = Observable.create(new Publisher() { + Flowable w = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber t1) { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowWithObservableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorWindowWithObservableTest.java similarity index 58% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowWithObservableTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorWindowWithObservableTest.java index feab752c65..b5baf5daa6 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowWithObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorWindowWithObservableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -21,29 +21,31 @@ import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; +import org.reactivestreams.Subscriber; -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Supplier; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.processors.PublishProcessor; +import io.reactivex.subscribers.DefaultObserver; +import io.reactivex.subscribers.TestSubscriber; -public class NbpOperatorWindowWithObservableTest { +public class OperatorWindowWithObservableTest { @Test public void testWindowViaObservableNormal1() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject boundary = NbpPublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor boundary = PublishProcessor.create(); - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + final Subscriber o = TestHelper.mockSubscriber(); - final List> values = new ArrayList>(); + final List> values = new ArrayList>(); - NbpSubscriber> wo = new NbpObserver>() { + Subscriber> wo = new DefaultObserver>() { @Override - public void onNext(NbpObservable args) { - final NbpSubscriber mo = TestHelper.mockNbpSubscriber(); + public void onNext(Flowable args) { + final Subscriber mo = TestHelper.mockSubscriber(); values.add(mo); args.subscribe(mo); @@ -77,7 +79,7 @@ public void onComplete() { assertEquals(n / 3, values.size()); int j = 0; - for (NbpSubscriber mo : values) { + for (Subscriber mo : values) { verify(mo, never()).onError(any(Throwable.class)); for (int i = 0; i < 3; i++) { verify(mo).onNext(j + i); @@ -91,17 +93,17 @@ public void onComplete() { @Test public void testWindowViaObservableBoundaryCompletes() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject boundary = NbpPublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor boundary = PublishProcessor.create(); - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + final Subscriber o = TestHelper.mockSubscriber(); - final List> values = new ArrayList>(); + final List> values = new ArrayList>(); - NbpSubscriber> wo = new NbpObserver>() { + Subscriber> wo = new DefaultObserver>() { @Override - public void onNext(NbpObservable args) { - final NbpSubscriber mo = TestHelper.mockNbpSubscriber(); + public void onNext(Flowable args) { + final Subscriber mo = TestHelper.mockSubscriber(); values.add(mo); args.subscribe(mo); @@ -132,7 +134,7 @@ public void onComplete() { assertEquals(n / 3, values.size()); int j = 0; - for (NbpSubscriber mo : values) { + for (Subscriber mo : values) { for (int i = 0; i < 3; i++) { verify(mo).onNext(j + i); } @@ -147,17 +149,17 @@ public void onComplete() { @Test public void testWindowViaObservableBoundaryThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject boundary = NbpPublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor boundary = PublishProcessor.create(); - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + final Subscriber o = TestHelper.mockSubscriber(); - final List> values = new ArrayList>(); + final List> values = new ArrayList>(); - NbpSubscriber> wo = new NbpObserver>() { + Subscriber> wo = new DefaultObserver>() { @Override - public void onNext(NbpObservable args) { - final NbpSubscriber mo = TestHelper.mockNbpSubscriber(); + public void onNext(Flowable args) { + final Subscriber mo = TestHelper.mockSubscriber(); values.add(mo); args.subscribe(mo); @@ -184,7 +186,7 @@ public void onComplete() { assertEquals(1, values.size()); - NbpSubscriber mo = values.get(0); + Subscriber mo = values.get(0); verify(mo).onNext(0); verify(mo).onNext(1); @@ -197,17 +199,17 @@ public void onComplete() { @Test public void testWindowViaObservableSourceThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject boundary = NbpPublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor boundary = PublishProcessor.create(); - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + final Subscriber o = TestHelper.mockSubscriber(); - final List> values = new ArrayList>(); + final List> values = new ArrayList>(); - NbpSubscriber> wo = new NbpObserver>() { + Subscriber> wo = new DefaultObserver>() { @Override - public void onNext(NbpObservable args) { - final NbpSubscriber mo = TestHelper.mockNbpSubscriber(); + public void onNext(Flowable args) { + final Subscriber mo = TestHelper.mockSubscriber(); values.add(mo); args.subscribe(mo); @@ -234,7 +236,7 @@ public void onComplete() { assertEquals(1, values.size()); - NbpSubscriber mo = values.get(0); + Subscriber mo = values.get(0); verify(mo).onNext(0); verify(mo).onNext(1); @@ -247,8 +249,8 @@ public void onComplete() { @Test public void testWindowNoDuplication() { - final NbpPublishSubject source = NbpPublishSubject.create(); - final NbpTestSubscriber tsw = new NbpTestSubscriber() { + final PublishProcessor source = PublishProcessor.create(); + final TestSubscriber tsw = new TestSubscriber() { boolean once; @Override public void onNext(Integer t) { @@ -259,17 +261,17 @@ public void onNext(Integer t) { super.onNext(t); } }; - NbpTestSubscriber> ts = new NbpTestSubscriber>() { + TestSubscriber> ts = new TestSubscriber>() { @Override - public void onNext(NbpObservable t) { + public void onNext(Flowable t) { t.subscribe(tsw); super.onNext(t); } }; - source.window(new Supplier>() { + source.window(new Supplier>() { @Override - public NbpObservable get() { - return NbpObservable.never(); + public Flowable get() { + return Flowable.never(); } }).subscribe(ts); @@ -282,15 +284,15 @@ public NbpObservable get() { @Test public void testWindowViaObservableNoUnsubscribe() { - NbpObservable source = NbpObservable.range(1, 10); - Supplier> boundary = new Supplier>() { + Flowable source = Flowable.range(1, 10); + Supplier> boundary = new Supplier>() { @Override - public NbpObservable get() { - return NbpObservable.empty(); + public Flowable get() { + return Flowable.empty(); } }; - NbpTestSubscriber> ts = new NbpTestSubscriber>(); + TestSubscriber> ts = new TestSubscriber>(); source.window(boundary).unsafeSubscribe(ts); assertFalse(ts.isCancelled()); @@ -298,16 +300,16 @@ public NbpObservable get() { @Test public void testBoundaryUnsubscribedOnMainCompletion() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject boundary = NbpPublishSubject.create(); - Supplier> boundaryFunc = new Supplier>() { + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor boundary = PublishProcessor.create(); + Supplier> boundaryFunc = new Supplier>() { @Override - public NbpObservable get() { + public Flowable get() { return boundary; } }; - NbpTestSubscriber> ts = new NbpTestSubscriber>(); + TestSubscriber> ts = new TestSubscriber>(); source.window(boundaryFunc).subscribe(ts); assertTrue(source.hasSubscribers()); @@ -324,16 +326,16 @@ public NbpObservable get() { } @Test public void testMainUnsubscribedOnBoundaryCompletion() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject boundary = NbpPublishSubject.create(); - Supplier> boundaryFunc = new Supplier>() { + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor boundary = PublishProcessor.create(); + Supplier> boundaryFunc = new Supplier>() { @Override - public NbpObservable get() { + public Flowable get() { return boundary; } }; - NbpTestSubscriber> ts = new NbpTestSubscriber>(); + TestSubscriber> ts = new TestSubscriber>(); source.window(boundaryFunc).subscribe(ts); assertTrue(source.hasSubscribers()); @@ -352,16 +354,16 @@ public NbpObservable get() { @Test public void testChildUnsubscribed() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject boundary = NbpPublishSubject.create(); - Supplier> boundaryFunc = new Supplier>() { + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor boundary = PublishProcessor.create(); + Supplier> boundaryFunc = new Supplier>() { @Override - public NbpObservable get() { + public Flowable get() { return boundary; } }; - NbpTestSubscriber> ts = new NbpTestSubscriber>(); + TestSubscriber> ts = new TestSubscriber>(); source.window(boundaryFunc).subscribe(ts); assertTrue(source.hasSubscribers()); @@ -378,21 +380,57 @@ public NbpObservable get() { ts.assertNoErrors(); ts.assertValueCount(1); } + @Test + public void testInnerBackpressure() { + Flowable source = Flowable.range(1, 10); + final PublishProcessor boundary = PublishProcessor.create(); + Supplier> boundaryFunc = new Supplier>() { + @Override + public Flowable get() { + return boundary; + } + }; + + final TestSubscriber ts = new TestSubscriber(1L); + final TestSubscriber> ts1 = new TestSubscriber>(1L) { + @Override + public void onNext(Flowable t) { + super.onNext(t); + t.subscribe(ts); + } + }; + source.window(boundaryFunc) + .subscribe(ts1); + + ts1.assertNoErrors(); + ts1.assertComplete(); + ts1.assertValueCount(1); + + ts.assertNoErrors(); + ts.assertNotComplete(); + ts.assertValues(1); + + ts.request(11); + + ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + ts.assertNoErrors(); + ts.assertComplete(); + } @Test public void newBoundaryCalledAfterWindowClosed() { final AtomicInteger calls = new AtomicInteger(); - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject boundary = NbpPublishSubject.create(); - Supplier> boundaryFunc = new Supplier>() { + PublishProcessor source = PublishProcessor.create(); + final PublishProcessor boundary = PublishProcessor.create(); + Supplier> boundaryFunc = new Supplier>() { @Override - public NbpObservable get() { + public Flowable get() { calls.getAndIncrement(); return boundary; } }; - NbpTestSubscriber> ts = new NbpTestSubscriber>(); + TestSubscriber> ts = new TestSubscriber>(); source.window(boundaryFunc).subscribe(ts); source.onNext(1); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorWindowWithSizeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorWindowWithSizeTest.java similarity index 81% rename from src/test/java/io/reactivex/internal/operators/OperatorWindowWithSizeTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorWindowWithSizeTest.java index 4bb9200414..670e286cf3 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorWindowWithSizeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorWindowWithSizeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -24,22 +24,22 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.schedulers.Schedulers; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; public class OperatorWindowWithSizeTest { - private static List> toLists(Observable> observables) { + private static List> toLists(Flowable> observables) { final List> lists = new ArrayList>(); - Observable.concat(observables.map(new Function, Observable>>() { + Flowable.concat(observables.map(new Function, Flowable>>() { @Override - public Observable> apply(Observable xs) { + public Flowable> apply(Flowable xs) { return xs.toList(); } })) @@ -55,8 +55,8 @@ public void accept(List xs) { @Test public void testNonOverlappingWindows() { - Observable subject = Observable.just("one", "two", "three", "four", "five"); - Observable> windowed = subject.window(3); + Flowable subject = Flowable.just("one", "two", "three", "four", "five"); + Flowable> windowed = subject.window(3); List> windows = toLists(windowed); @@ -67,8 +67,8 @@ public void testNonOverlappingWindows() { @Test public void testSkipAndCountGaplessWindows() { - Observable subject = Observable.just("one", "two", "three", "four", "five"); - Observable> windowed = subject.window(3, 3); + Flowable subject = Flowable.just("one", "two", "three", "four", "five"); + Flowable> windowed = subject.window(3, 3); List> windows = toLists(windowed); @@ -79,8 +79,8 @@ public void testSkipAndCountGaplessWindows() { @Test public void testOverlappingWindows() { - Observable subject = Observable.fromArray(new String[] { "zero", "one", "two", "three", "four", "five" }); - Observable> windowed = subject.window(3, 1); + Flowable subject = Flowable.fromArray(new String[] { "zero", "one", "two", "three", "four", "five" }); + Flowable> windowed = subject.window(3, 1); List> windows = toLists(windowed); @@ -95,8 +95,8 @@ public void testOverlappingWindows() { @Test public void testSkipAndCountWindowsWithGaps() { - Observable subject = Observable.just("one", "two", "three", "four", "five"); - Observable> windowed = subject.window(2, 3); + Flowable subject = Flowable.just("one", "two", "three", "four", "five"); + Flowable> windowed = subject.window(2, 3); List> windows = toLists(windowed); @@ -109,7 +109,7 @@ public void testSkipAndCountWindowsWithGaps() { public void testWindowUnsubscribeNonOverlapping() { TestSubscriber ts = new TestSubscriber(); final AtomicInteger count = new AtomicInteger(); - Observable.merge(Observable.range(1, 10000).doOnNext(new Consumer() { + Flowable.merge(Flowable.range(1, 10000).doOnNext(new Consumer() { @Override public void accept(Integer t1) { @@ -128,7 +128,7 @@ public void accept(Integer t1) { public void testWindowUnsubscribeNonOverlappingAsyncSource() { TestSubscriber ts = new TestSubscriber(); final AtomicInteger count = new AtomicInteger(); - Observable.merge(Observable.range(1, 100000) + Flowable.merge(Flowable.range(1, 100000) .doOnNext(new Consumer() { @Override @@ -152,7 +152,7 @@ public void accept(Integer t1) { public void testWindowUnsubscribeOverlapping() { TestSubscriber ts = new TestSubscriber(); final AtomicInteger count = new AtomicInteger(); - Observable.merge(Observable.range(1, 10000).doOnNext(new Consumer() { + Flowable.merge(Flowable.range(1, 10000).doOnNext(new Consumer() { @Override public void accept(Integer t1) { @@ -171,7 +171,7 @@ public void accept(Integer t1) { public void testWindowUnsubscribeOverlappingAsyncSource() { TestSubscriber ts = new TestSubscriber(); final AtomicInteger count = new AtomicInteger(); - Observable.merge(Observable.range(1, 100000) + Flowable.merge(Flowable.range(1, 100000) .doOnNext(new Consumer() { @Override @@ -201,20 +201,20 @@ private List list(String... args) { @Test public void testBackpressureOuter() { - Observable> source = Observable.range(1, 10).window(3); + Flowable> source = Flowable.range(1, 10).window(3); final List list = new ArrayList(); final Subscriber o = TestHelper.mockSubscriber(); - source.subscribe(new Observer>() { + source.subscribe(new DefaultObserver>() { @Override public void onStart() { request(1); } @Override - public void onNext(Observable t) { - t.subscribe(new Observer() { + public void onNext(Flowable t) { + t.subscribe(new DefaultObserver() { @Override public void onNext(Integer t) { list.add(t); @@ -245,8 +245,8 @@ public void onComplete() { verify(o, times(1)).onComplete(); // 1 inner } - public static Observable hotStream() { - return Observable.create(new Publisher() { + public static Flowable hotStream() { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { BooleanSubscription bs = new BooleanSubscription(); @@ -278,9 +278,9 @@ public void testTakeFlatMapCompletes() { hotStream() .window(10) .take(2) - .flatMap(new Function, Observable>() { + .flatMap(new Function, Flowable>() { @Override - public Observable apply(Observable w) { + public Flowable apply(Flowable w) { return w.startWith(indicator); } }).subscribe(ts); @@ -295,15 +295,15 @@ public Observable apply(Observable w) { public void testBackpressureOuterInexact() { TestSubscriber> ts = new TestSubscriber>((Long)null); - Observable.range(1, 5).window(2, 1) - .map(new Function, Observable>>() { + Flowable.range(1, 5).window(2, 1) + .map(new Function, Flowable>>() { @Override - public Observable> apply(Observable t) { + public Flowable> apply(Flowable t) { return t.toList(); } - }).concatMap(new Function>, Publisher>>() { + }).concatMap(new Function>, Publisher>>() { @Override - public Publisher> apply(Observable> v) { + public Publisher> apply(Flowable> v) { return v; } }) diff --git a/src/test/java/io/reactivex/internal/operators/OperatorWindowWithStartEndObservableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorWindowWithStartEndObservableTest.java similarity index 77% rename from src/test/java/io/reactivex/internal/operators/OperatorWindowWithStartEndObservableTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorWindowWithStartEndObservableTest.java index 4e430c9172..3937d9e7d1 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorWindowWithStartEndObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorWindowWithStartEndObservableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; @@ -24,11 +24,10 @@ import io.reactivex.*; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; public class OperatorWindowWithStartEndObservableTest { @@ -46,7 +45,7 @@ public void testObservableBasedOpenerAndCloser() { final List list = new ArrayList(); final List> lists = new ArrayList>(); - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -59,7 +58,7 @@ public void subscribe(Subscriber observer) { } }); - Observable openings = Observable.create(new Publisher() { + Flowable openings = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -69,10 +68,10 @@ public void subscribe(Subscriber observer) { } }); - Function> closer = new Function>() { + Function> closer = new Function>() { @Override - public Observable apply(Object opening) { - return Observable.create(new Publisher() { + public Flowable apply(Object opening) { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -83,7 +82,7 @@ public void subscribe(Subscriber observer) { } }; - Observable> windowed = source.window(openings, closer); + Flowable> windowed = source.window(openings, closer); windowed.subscribe(observeWindow(list, lists)); scheduler.advanceTimeTo(500, TimeUnit.MILLISECONDS); @@ -97,7 +96,7 @@ public void testObservableBasedCloser() { final List list = new ArrayList(); final List> lists = new ArrayList>(); - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -110,11 +109,11 @@ public void subscribe(Subscriber observer) { } }); - Supplier> closer = new Supplier>() { + Supplier> closer = new Supplier>() { int calls; @Override - public Observable get() { - return Observable.create(new Publisher() { + public Flowable get() { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -132,7 +131,7 @@ public void subscribe(Subscriber observer) { } }; - Observable> windowed = source.window(closer); + Flowable> windowed = source.window(closer); windowed.subscribe(observeWindow(list, lists)); scheduler.advanceTimeTo(500, TimeUnit.MILLISECONDS); @@ -168,11 +167,11 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private Consumer> observeWindow(final List list, final List> lists) { - return new Consumer>() { + private Consumer> observeWindow(final List list, final List> lists) { + return new Consumer>() { @Override - public void accept(Observable stringObservable) { - stringObservable.subscribe(new Observer() { + public void accept(Flowable stringObservable) { + stringObservable.subscribe(new DefaultObserver() { @Override public void onComplete() { lists.add(new ArrayList(list)); @@ -195,16 +194,16 @@ public void onNext(String args) { @Test public void testNoUnsubscribeAndNoLeak() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - PublishSubject open = PublishSubject.create(); - final PublishSubject close = PublishSubject.create(); + PublishProcessor open = PublishProcessor.create(); + final PublishProcessor close = PublishProcessor.create(); - TestSubscriber> ts = new TestSubscriber>(); + TestSubscriber> ts = new TestSubscriber>(); - source.window(open, new Function>() { + source.window(open, new Function>() { @Override - public Observable apply(Integer t) { + public Flowable apply(Integer t) { return close; } }).unsafeSubscribe(ts); @@ -232,16 +231,16 @@ public Observable apply(Integer t) { @Test public void testUnsubscribeAll() { - PublishSubject source = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); - PublishSubject open = PublishSubject.create(); - final PublishSubject close = PublishSubject.create(); + PublishProcessor open = PublishProcessor.create(); + final PublishProcessor close = PublishProcessor.create(); - TestSubscriber> ts = new TestSubscriber>(); + TestSubscriber> ts = new TestSubscriber>(); - source.window(open, new Function>() { + source.window(open, new Function>() { @Override - public Observable apply(Integer t) { + public Flowable apply(Integer t) { return close; } }).unsafeSubscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorWindowWithTimeTest.java similarity index 87% rename from src/test/java/io/reactivex/internal/operators/OperatorWindowWithTimeTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorWindowWithTimeTest.java index 46d976992d..1579bbba11 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorWindowWithTimeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; @@ -26,9 +26,8 @@ import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.EmptySubscription; import io.reactivex.schedulers.TestScheduler; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; public class OperatorWindowWithTimeTest { @@ -47,7 +46,7 @@ public void testTimedAndCount() { final List list = new ArrayList(); final List> lists = new ArrayList>(); - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -60,7 +59,7 @@ public void subscribe(Subscriber observer) { } }); - Observable> windowed = source.window(100, TimeUnit.MILLISECONDS, scheduler, 2); + Flowable> windowed = source.window(100, TimeUnit.MILLISECONDS, scheduler, 2); windowed.subscribe(observeWindow(list, lists)); scheduler.advanceTimeTo(100, TimeUnit.MILLISECONDS); @@ -81,7 +80,7 @@ public void testTimed() { final List list = new ArrayList(); final List> lists = new ArrayList>(); - Observable source = Observable.create(new Publisher() { + Flowable source = Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { observer.onSubscribe(EmptySubscription.INSTANCE); @@ -94,7 +93,7 @@ public void subscribe(Subscriber observer) { } }); - Observable> windowed = source.window(100, TimeUnit.MILLISECONDS, scheduler); + Flowable> windowed = source.window(100, TimeUnit.MILLISECONDS, scheduler); windowed.subscribe(observeWindow(list, lists)); scheduler.advanceTimeTo(101, TimeUnit.MILLISECONDS); @@ -132,11 +131,11 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private Consumer> observeWindow(final List list, final List> lists) { - return new Consumer>() { + private Consumer> observeWindow(final List list, final List> lists) { + return new Consumer>() { @Override - public void accept(Observable stringObservable) { - stringObservable.subscribe(new Observer() { + public void accept(Flowable stringObservable) { + stringObservable.subscribe(new DefaultObserver() { @Override public void onComplete() { lists.add(new ArrayList(list)); @@ -158,7 +157,7 @@ public void onNext(T args) { } @Test public void testExactWindowSize() { - Observable> source = Observable.range(1, 10) + Flowable> source = Flowable.range(1, 10) .window(1, TimeUnit.MINUTES, scheduler, 3); final List list = new ArrayList(); @@ -194,9 +193,9 @@ public void run() { System.out.println("Main done!"); } }) - .flatMap(new Function, Observable>() { + .flatMap(new Function, Flowable>() { @Override - public Observable apply(Observable w) { + public Flowable apply(Flowable w) { return w.startWith(indicator) .doOnComplete(new Runnable() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/OperatorWithLatestFromTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorWithLatestFromTest.java similarity index 76% rename from src/test/java/io/reactivex/internal/operators/OperatorWithLatestFromTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorWithLatestFromTest.java index f5f62d2ad8..1314564d0b 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorWithLatestFromTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorWithLatestFromTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -21,10 +21,11 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.BiFunction; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; public class OperatorWithLatestFromTest { @@ -42,13 +43,13 @@ public Integer apply(Integer t1, Integer t2) { }; @Test public void testSimple() { - PublishSubject source = PublishSubject.create(); - PublishSubject other = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor other = PublishProcessor.create(); Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); - Observable result = source.withLatestFrom(other, COMBINER); + Flowable result = source.withLatestFrom(other, COMBINER); result.subscribe(o); @@ -78,10 +79,10 @@ public void testSimple() { @Test public void testEmptySource() { - PublishSubject source = PublishSubject.create(); - PublishSubject other = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor other = PublishProcessor.create(); - Observable result = source.withLatestFrom(other, COMBINER); + Flowable result = source.withLatestFrom(other, COMBINER); TestSubscriber ts = new TestSubscriber(); @@ -104,10 +105,10 @@ public void testEmptySource() { @Test public void testEmptyOther() { - PublishSubject source = PublishSubject.create(); - PublishSubject other = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor other = PublishProcessor.create(); - Observable result = source.withLatestFrom(other, COMBINER); + Flowable result = source.withLatestFrom(other, COMBINER); TestSubscriber ts = new TestSubscriber(); @@ -131,10 +132,10 @@ public void testEmptyOther() { @Test public void testUnsubscription() { - PublishSubject source = PublishSubject.create(); - PublishSubject other = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor other = PublishProcessor.create(); - Observable result = source.withLatestFrom(other, COMBINER); + Flowable result = source.withLatestFrom(other, COMBINER); TestSubscriber ts = new TestSubscriber(); @@ -158,10 +159,10 @@ public void testUnsubscription() { @Test public void testSourceThrows() { - PublishSubject source = PublishSubject.create(); - PublishSubject other = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor other = PublishProcessor.create(); - Observable result = source.withLatestFrom(other, COMBINER); + Flowable result = source.withLatestFrom(other, COMBINER); TestSubscriber ts = new TestSubscriber(); @@ -185,10 +186,10 @@ public void testSourceThrows() { } @Test public void testOtherThrows() { - PublishSubject source = PublishSubject.create(); - PublishSubject other = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor other = PublishProcessor.create(); - Observable result = source.withLatestFrom(other, COMBINER); + Flowable result = source.withLatestFrom(other, COMBINER); TestSubscriber ts = new TestSubscriber(); @@ -213,10 +214,10 @@ public void testOtherThrows() { @Test public void testFunctionThrows() { - PublishSubject source = PublishSubject.create(); - PublishSubject other = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor other = PublishProcessor.create(); - Observable result = source.withLatestFrom(other, COMBINER_ERROR); + Flowable result = source.withLatestFrom(other, COMBINER_ERROR); TestSubscriber ts = new TestSubscriber(); @@ -239,10 +240,10 @@ public void testFunctionThrows() { @Test public void testNoDownstreamUnsubscribe() { - PublishSubject source = PublishSubject.create(); - PublishSubject other = PublishSubject.create(); + PublishProcessor source = PublishProcessor.create(); + PublishProcessor other = PublishProcessor.create(); - Observable result = source.withLatestFrom(other, COMBINER); + Flowable result = source.withLatestFrom(other, COMBINER); TestSubscriber ts = new TestSubscriber(); @@ -255,10 +256,10 @@ public void testNoDownstreamUnsubscribe() { @Test public void testBackpressure() { - Observable source = Observable.range(1, 10); - PublishSubject other = PublishSubject.create(); + Flowable source = Flowable.range(1, 10); + PublishProcessor other = PublishProcessor.create(); - Observable result = source.withLatestFrom(other, COMBINER); + Flowable result = source.withLatestFrom(other, COMBINER); TestSubscriber ts = new TestSubscriber((Long)null); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorZipCompletionTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorZipCompletionTest.java similarity index 88% rename from src/test/java/io/reactivex/internal/operators/OperatorZipCompletionTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorZipCompletionTest.java index c2f74d843f..120b135da5 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorZipCompletionTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorZipCompletionTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.mockito.Mockito.*; @@ -19,9 +19,10 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.BiFunction; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.processors.PublishProcessor; /** * Systematically tests that when zipping an infinite and a finite Observable, @@ -31,9 +32,9 @@ public class OperatorZipCompletionTest { BiFunction concat2Strings; - PublishSubject s1; - PublishSubject s2; - Observable zipped; + PublishProcessor s1; + PublishProcessor s2; + Flowable zipped; Subscriber observer; InOrder inOrder; @@ -47,9 +48,9 @@ public String apply(String t1, String t2) { } }; - s1 = PublishSubject.create(); - s2 = PublishSubject.create(); - zipped = Observable.zip(s1, s2, concat2Strings); + s1 = PublishProcessor.create(); + s2 = PublishProcessor.create(); + zipped = Flowable.zip(s1, s2, concat2Strings); observer = TestHelper.mockSubscriber(); inOrder = inOrder(observer); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorZipIterableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorZipIterableTest.java similarity index 90% rename from src/test/java/io/reactivex/internal/operators/OperatorZipIterableTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorZipIterableTest.java index f2e8b407e0..ae3daf9bf1 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorZipIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorZipIterableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -24,17 +24,17 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.Observable; -import io.reactivex.TestHelper; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.processors.PublishProcessor; public class OperatorZipIterableTest { BiFunction concat2Strings; - PublishSubject s1; - PublishSubject s2; - Observable zipped; + PublishProcessor s1; + PublishProcessor s2; + Flowable zipped; Subscriber observer; InOrder inOrder; @@ -48,9 +48,9 @@ public String apply(String t1, String t2) { } }; - s1 = PublishSubject.create(); - s2 = PublishSubject.create(); - zipped = Observable.zip(s1, s2, concat2Strings); + s1 = PublishProcessor.create(); + s2 = PublishProcessor.create(); + zipped = Flowable.zip(s1, s2, concat2Strings); observer = TestHelper.mockSubscriber(); inOrder = inOrder(observer); @@ -77,7 +77,7 @@ public String apply(Object t1, Object t2, Object t3) { @Test public void testZipIterableSameSize() { - PublishSubject r1 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber o = TestHelper.mockSubscriber(); InOrder io = inOrder(o); @@ -102,7 +102,7 @@ public void testZipIterableSameSize() { @Test public void testZipIterableEmptyFirstSize() { - PublishSubject r1 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber o = TestHelper.mockSubscriber(); InOrder io = inOrder(o); @@ -122,7 +122,7 @@ public void testZipIterableEmptyFirstSize() { @Test public void testZipIterableEmptySecond() { - PublishSubject r1 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber o = TestHelper.mockSubscriber(); InOrder io = inOrder(o); @@ -144,7 +144,7 @@ public void testZipIterableEmptySecond() { @Test public void testZipIterableFirstShorter() { - PublishSubject r1 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber o = TestHelper.mockSubscriber(); InOrder io = inOrder(o); @@ -167,7 +167,7 @@ public void testZipIterableFirstShorter() { @Test public void testZipIterableSecondShorter() { - PublishSubject r1 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber o = TestHelper.mockSubscriber(); InOrder io = inOrder(o); @@ -191,7 +191,7 @@ public void testZipIterableSecondShorter() { @Test public void testZipIterableFirstThrows() { - PublishSubject r1 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber o = TestHelper.mockSubscriber(); InOrder io = inOrder(o); @@ -214,7 +214,7 @@ public void testZipIterableFirstThrows() { @Test public void testZipIterableIteratorThrows() { - PublishSubject r1 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber o = TestHelper.mockSubscriber(); InOrder io = inOrder(o); @@ -241,7 +241,7 @@ public Iterator iterator() { @Test public void testZipIterableHasNextThrows() { - PublishSubject r1 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber o = TestHelper.mockSubscriber(); InOrder io = inOrder(o); @@ -291,7 +291,7 @@ public void remove() { @Test public void testZipIterableNextThrows() { - PublishSubject r1 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber o = TestHelper.mockSubscriber(); InOrder io = inOrder(o); @@ -351,7 +351,7 @@ public String apply(Integer t1) { @Test public void testTake2() { - Observable o = Observable.just(1, 2, 3, 4, 5); + Flowable o = Flowable.just(1, 2, 3, 4, 5); Iterable it = Arrays.asList("a", "b", "c", "d", "e"); SquareStr squareStr = new SquareStr(); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorZipTest.java b/src/test/java/io/reactivex/internal/operators/flowable/OperatorZipTest.java similarity index 80% rename from src/test/java/io/reactivex/internal/operators/OperatorZipTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/OperatorZipTest.java index 660679191f..879f0d3eae 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorZipTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/OperatorZipTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -26,21 +26,21 @@ import org.reactivestreams.*; import io.reactivex.*; +import io.reactivex.Optional; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.*; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Optional; -import io.reactivex.Observable; -import io.reactivex.Observer; public class OperatorZipTest { BiFunction concat2Strings; - PublishSubject s1; - PublishSubject s2; - Observable zipped; + PublishProcessor s1; + PublishProcessor s2; + Flowable zipped; Subscriber observer; InOrder inOrder; @@ -54,9 +54,9 @@ public String apply(String t1, String t2) { } }; - s1 = PublishSubject.create(); - s2 = PublishSubject.create(); - zipped = Observable.zip(s1, s2, concat2Strings); + s1 = PublishProcessor.create(); + s2 = PublishProcessor.create(); + zipped = Flowable.zip(s1, s2, concat2Strings); observer = TestHelper.mockSubscriber(); inOrder = inOrder(observer); @@ -74,8 +74,8 @@ public void testCollectionSizeDifferentThanFunction() { Subscriber observer = TestHelper.mockSubscriber(); @SuppressWarnings("rawtypes") - Collection ws = java.util.Collections.singleton(Observable.just("one", "two")); - Observable w = Observable.zip(ws, zipr); + Collection ws = java.util.Collections.singleton(Flowable.just("one", "two")); + Flowable w = Flowable.zip(ws, zipr); w.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); @@ -91,9 +91,9 @@ public void testStartpingDifferentLengthObservableSequences1() { TestObservable w2 = new TestObservable(); TestObservable w3 = new TestObservable(); - Observable zipW = Observable.zip( - Observable.create(w1), Observable.create(w2), - Observable.create(w3), getConcat3StringsZipr()); + Flowable zipW = Flowable.zip( + Flowable.create(w1), Flowable.create(w2), + Flowable.create(w3), getConcat3StringsZipr()); zipW.subscribe(w); /* simulate sending data */ @@ -126,7 +126,7 @@ public void testStartpingDifferentLengthObservableSequences2() { TestObservable w2 = new TestObservable(); TestObservable w3 = new TestObservable(); - Observable zipW = Observable.zip(Observable.create(w1), Observable.create(w2), Observable.create(w3), getConcat3StringsZipr()); + Flowable zipW = Flowable.zip(Flowable.create(w1), Flowable.create(w2), Flowable.create(w3), getConcat3StringsZipr()); zipW.subscribe(w); /* simulate sending data */ @@ -174,12 +174,12 @@ public String apply(Object t1, Object t2, Object t3) { */ @Test public void testAggregatorSimple() { - PublishSubject r1 = PublishSubject.create(); - PublishSubject r2 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); + PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); - Observable.zip(r1, r2, zipr2).subscribe(observer); + Flowable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -209,11 +209,11 @@ public void testAggregatorSimple() { public void testAggregatorDifferentSizedResultsWithOnComplete() { /* create the aggregator which will execute the zip function when all Observables provide values */ /* define a Subscriber to receive aggregated events */ - PublishSubject r1 = PublishSubject.create(); - PublishSubject r2 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); + PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); - Observable.zip(r1, r2, zipr2).subscribe(observer); + Flowable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -236,12 +236,12 @@ public void testAggregatorDifferentSizedResultsWithOnComplete() { @Test public void testAggregateMultipleTypes() { - PublishSubject r1 = PublishSubject.create(); - PublishSubject r2 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); + PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); - Observable.zip(r1, r2, zipr2).subscribe(observer); + Flowable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -264,13 +264,13 @@ public void testAggregateMultipleTypes() { @Test public void testAggregate3Types() { - PublishSubject r1 = PublishSubject.create(); - PublishSubject r2 = PublishSubject.create(); - PublishSubject> r3 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); + PublishProcessor r2 = PublishProcessor.create(); + PublishProcessor> r3 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); - Observable.zip(r1, r2, r3, zipr3).subscribe(observer); + Flowable.zip(r1, r2, r3, zipr3).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -284,12 +284,12 @@ public void testAggregate3Types() { @Test public void testAggregatorsWithDifferentSizesAndTiming() { - PublishSubject r1 = PublishSubject.create(); - PublishSubject r2 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); + PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); - Observable.zip(r1, r2, zipr2).subscribe(observer); + Flowable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("one"); @@ -319,12 +319,12 @@ public void testAggregatorsWithDifferentSizesAndTiming() { @Test public void testAggregatorError() { - PublishSubject r1 = PublishSubject.create(); - PublishSubject r2 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); + PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); - Observable.zip(r1, r2, zipr2).subscribe(observer); + Flowable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -346,13 +346,13 @@ public void testAggregatorError() { @Test public void testAggregatorUnsubscribe() { - PublishSubject r1 = PublishSubject.create(); - PublishSubject r2 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); + PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(observer); - Observable.zip(r1, r2, zipr2).subscribe(ts); + Flowable.zip(r1, r2, zipr2).subscribe(ts); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -374,12 +374,12 @@ public void testAggregatorUnsubscribe() { @Test public void testAggregatorEarlyCompletion() { - PublishSubject r1 = PublishSubject.create(); - PublishSubject r2 = PublishSubject.create(); + PublishProcessor r1 = PublishProcessor.create(); + PublishProcessor r2 = PublishProcessor.create(); /* define a Subscriber to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); - Observable.zip(r1, r2, zipr2).subscribe(observer); + Flowable.zip(r1, r2, zipr2).subscribe(observer); /* simulate the Observables pushing data into the aggregator */ r1.onNext("one"); @@ -407,7 +407,7 @@ public void testStart2Types() { /* define a Subscriber to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); - Observable w = Observable.zip(Observable.just("one", "two"), Observable.just(2, 3, 4), zipr); + Flowable w = Flowable.zip(Flowable.just("one", "two"), Flowable.just(2, 3, 4), zipr); w.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); @@ -424,7 +424,7 @@ public void testStart3Types() { /* define a Subscriber to receive aggregated events */ Subscriber observer = TestHelper.mockSubscriber(); - Observable w = Observable.zip(Observable.just("one", "two"), Observable.just(2), Observable.just(new int[] { 4, 5, 6 }), zipr); + Flowable w = Flowable.zip(Flowable.just("one", "two"), Flowable.just(2), Flowable.just(new int[] { 4, 5, 6 }), zipr); w.subscribe(observer); verify(observer, never()).onError(any(Throwable.class)); @@ -439,7 +439,7 @@ public void testOnNextExceptionInvokesOnError() { Subscriber observer = TestHelper.mockSubscriber(); - Observable w = Observable.zip(Observable.just(10, 20, 30), Observable.just(0, 1, 2), zipr); + Flowable w = Flowable.zip(Flowable.just(10, 20, 30), Flowable.just(0, 1, 2), zipr); w.subscribe(observer); verify(observer, times(1)).onError(any(Throwable.class)); @@ -447,12 +447,12 @@ public void testOnNextExceptionInvokesOnError() { @Test public void testOnFirstCompletion() { - PublishSubject oA = PublishSubject.create(); - PublishSubject oB = PublishSubject.create(); + PublishProcessor oA = PublishProcessor.create(); + PublishProcessor oB = PublishProcessor.create(); Subscriber obs = TestHelper.mockSubscriber(); - Observable o = Observable.zip(oA, oB, getConcat2Strings()); + Flowable o = Flowable.zip(oA, oB, getConcat2Strings()); o.subscribe(obs); InOrder io = inOrder(obs); @@ -497,12 +497,12 @@ public void testOnFirstCompletion() { @Test public void testOnErrorTermination() { - PublishSubject oA = PublishSubject.create(); - PublishSubject oB = PublishSubject.create(); + PublishProcessor oA = PublishProcessor.create(); + PublishProcessor oB = PublishProcessor.create(); Subscriber obs = TestHelper.mockSubscriber(); - Observable o = Observable.zip(oA, oB, getConcat2Strings()); + Flowable o = Flowable.zip(oA, oB, getConcat2Strings()); o.subscribe(obs); InOrder io = inOrder(obs); @@ -726,13 +726,13 @@ public void testStartWithOnCompletedTwice() { // which is in the package "rx.operators". final Subscriber observer = TestHelper.mockSubscriber(); - Observable.zip(Observable.just(1), - Observable.just(1), new BiFunction() { + Flowable.zip(Flowable.just(1), + Flowable.just(1), new BiFunction() { @Override public Integer apply(Integer a, Integer b) { return a + b; } - }).subscribe(new Observer() { + }).subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -759,7 +759,7 @@ public void onNext(Integer args) { @Test public void testStart() { - Observable os = OBSERVABLE_OF_5_INTEGERS + Flowable os = OBSERVABLE_OF_5_INTEGERS .zipWith(OBSERVABLE_OF_5_INTEGERS, new BiFunction() { @Override @@ -786,7 +786,7 @@ public void accept(String s) { @Test public void testStartAsync() throws InterruptedException { - Observable os = ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(new CountDownLatch(1)).onBackpressureBuffer() + Flowable os = ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(new CountDownLatch(1)).onBackpressureBuffer() .zipWith(ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(new CountDownLatch(1)).onBackpressureBuffer(), new BiFunction() { @Override @@ -811,7 +811,7 @@ public String apply(Integer a, Integer b) { public void testStartInfiniteAndFinite() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch infiniteObservable = new CountDownLatch(1); - Observable os = OBSERVABLE_OF_5_INTEGERS + Flowable os = OBSERVABLE_OF_5_INTEGERS .zipWith(ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(infiniteObservable), new BiFunction() { @Override @@ -821,7 +821,7 @@ public String apply(Integer a, Integer b) { }); final ArrayList list = new ArrayList(); - os.subscribe(new Observer() { + os.subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -855,9 +855,9 @@ public void onNext(String s) { @Test @Ignore("Null values not allowed") public void testEmitNull() { - Observable oi = Observable.just(1, null, 3); - Observable os = Observable.just("a", "b", null); - Observable o = Observable.zip(oi, os, new BiFunction() { + Flowable oi = Flowable.just(1, null, 3); + Flowable os = Flowable.just("a", "b", null); + Flowable o = Flowable.zip(oi, os, new BiFunction() { @Override public String apply(Integer t1, String t2) { @@ -904,9 +904,9 @@ static String value(Try notification) { @Test public void testEmitMaterializedNotifications() { - Observable>> oi = Observable.just(1, 2, 3).materialize(); - Observable>> os = Observable.just("a", "b", "c").materialize(); - Observable o = Observable.zip(oi, os, new BiFunction>, Try>, String>() { + Flowable>> oi = Flowable.just(1, 2, 3).materialize(); + Flowable>> os = Flowable.just("a", "b", "c").materialize(); + Flowable o = Flowable.zip(oi, os, new BiFunction>, Try>, String>() { @Override public String apply(Try> t1, Try> t2) { @@ -935,7 +935,7 @@ public void accept(String s) { @Test public void testStartEmptyObservables() { - Observable o = Observable.zip(Observable. empty(), Observable. empty(), new BiFunction() { + Flowable o = Flowable.zip(Flowable. empty(), Flowable. empty(), new BiFunction() { @Override public String apply(Integer t1, String t2) { @@ -961,9 +961,9 @@ public void accept(String s) { public void testStartEmptyList() { final Object invoked = new Object(); - Collection> observables = Collections.emptyList(); + Collection> observables = Collections.emptyList(); - Observable o = Observable.zip(observables, new Function() { + Flowable o = Flowable.zip(observables, new Function() { @Override public Object apply(final Object[] args) { assertEquals("No argument should have been passed", 0, args.length); @@ -985,9 +985,9 @@ public Object apply(final Object[] args) { public void testStartEmptyListBlocking() { final Object invoked = new Object(); - Collection> observables = Collections.emptyList(); + Collection> observables = Collections.emptyList(); - Observable o = Observable.zip(observables, new Function() { + Flowable o = Flowable.zip(observables, new Function() { @Override public Object apply(final Object[] args) { assertEquals("No argument should have been passed", 0, args.length); @@ -1002,127 +1002,127 @@ public Object apply(final Object[] args) { public void testBackpressureSync() { AtomicInteger generatedA = new AtomicInteger(); AtomicInteger generatedB = new AtomicInteger(); - Observable o1 = createInfiniteObservable(generatedA); - Observable o2 = createInfiniteObservable(generatedB); + Flowable o1 = createInfiniteObservable(generatedA); + Flowable o2 = createInfiniteObservable(generatedB); TestSubscriber ts = new TestSubscriber(); - Observable.zip(o1, o2, new BiFunction() { + Flowable.zip(o1, o2, new BiFunction() { @Override public String apply(Integer t1, Integer t2) { return t1 + "-" + t2; } - }).take(Observable.bufferSize() * 2).subscribe(ts); + }).take(Flowable.bufferSize() * 2).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); - assertTrue(generatedA.get() < (Observable.bufferSize() * 3)); - assertTrue(generatedB.get() < (Observable.bufferSize() * 3)); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); + assertTrue(generatedA.get() < (Flowable.bufferSize() * 3)); + assertTrue(generatedB.get() < (Flowable.bufferSize() * 3)); } @Test public void testBackpressureAsync() { AtomicInteger generatedA = new AtomicInteger(); AtomicInteger generatedB = new AtomicInteger(); - Observable o1 = createInfiniteObservable(generatedA).subscribeOn(Schedulers.computation()); - Observable o2 = createInfiniteObservable(generatedB).subscribeOn(Schedulers.computation()); + Flowable o1 = createInfiniteObservable(generatedA).subscribeOn(Schedulers.computation()); + Flowable o2 = createInfiniteObservable(generatedB).subscribeOn(Schedulers.computation()); TestSubscriber ts = new TestSubscriber(); - Observable.zip(o1, o2, new BiFunction() { + Flowable.zip(o1, o2, new BiFunction() { @Override public String apply(Integer t1, Integer t2) { return t1 + "-" + t2; } - }).take(Observable.bufferSize() * 2).subscribe(ts); + }).take(Flowable.bufferSize() * 2).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); - assertTrue(generatedA.get() < (Observable.bufferSize() * 3)); - assertTrue(generatedB.get() < (Observable.bufferSize() * 3)); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); + assertTrue(generatedA.get() < (Flowable.bufferSize() * 3)); + assertTrue(generatedB.get() < (Flowable.bufferSize() * 3)); } @Test public void testDownstreamBackpressureRequestsWithFiniteSyncObservables() { AtomicInteger generatedA = new AtomicInteger(); AtomicInteger generatedB = new AtomicInteger(); - Observable o1 = createInfiniteObservable(generatedA).take(Observable.bufferSize() * 2); - Observable o2 = createInfiniteObservable(generatedB).take(Observable.bufferSize() * 2); + Flowable o1 = createInfiniteObservable(generatedA).take(Flowable.bufferSize() * 2); + Flowable o2 = createInfiniteObservable(generatedB).take(Flowable.bufferSize() * 2); TestSubscriber ts = new TestSubscriber(); - Observable.zip(o1, o2, new BiFunction() { + Flowable.zip(o1, o2, new BiFunction() { @Override public String apply(Integer t1, Integer t2) { return t1 + "-" + t2; } - }).observeOn(Schedulers.computation()).take(Observable.bufferSize() * 2).subscribe(ts); + }).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); System.out.println("Generated => A: " + generatedA.get() + " B: " + generatedB.get()); - assertTrue(generatedA.get() < (Observable.bufferSize() * 3)); - assertTrue(generatedB.get() < (Observable.bufferSize() * 3)); + assertTrue(generatedA.get() < (Flowable.bufferSize() * 3)); + assertTrue(generatedB.get() < (Flowable.bufferSize() * 3)); } @Test public void testDownstreamBackpressureRequestsWithInfiniteAsyncObservables() { AtomicInteger generatedA = new AtomicInteger(); AtomicInteger generatedB = new AtomicInteger(); - Observable o1 = createInfiniteObservable(generatedA).subscribeOn(Schedulers.computation()); - Observable o2 = createInfiniteObservable(generatedB).subscribeOn(Schedulers.computation()); + Flowable o1 = createInfiniteObservable(generatedA).subscribeOn(Schedulers.computation()); + Flowable o2 = createInfiniteObservable(generatedB).subscribeOn(Schedulers.computation()); TestSubscriber ts = new TestSubscriber(); - Observable.zip(o1, o2, new BiFunction() { + Flowable.zip(o1, o2, new BiFunction() { @Override public String apply(Integer t1, Integer t2) { return t1 + "-" + t2; } - }).observeOn(Schedulers.computation()).take(Observable.bufferSize() * 2).subscribe(ts); + }).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); System.out.println("Generated => A: " + generatedA.get() + " B: " + generatedB.get()); - assertTrue(generatedA.get() < (Observable.bufferSize() * 4)); - assertTrue(generatedB.get() < (Observable.bufferSize() * 4)); + assertTrue(generatedA.get() < (Flowable.bufferSize() * 4)); + assertTrue(generatedB.get() < (Flowable.bufferSize() * 4)); } @Test public void testDownstreamBackpressureRequestsWithInfiniteSyncObservables() { AtomicInteger generatedA = new AtomicInteger(); AtomicInteger generatedB = new AtomicInteger(); - Observable o1 = createInfiniteObservable(generatedA); - Observable o2 = createInfiniteObservable(generatedB); + Flowable o1 = createInfiniteObservable(generatedA); + Flowable o2 = createInfiniteObservable(generatedB); TestSubscriber ts = new TestSubscriber(); - Observable.zip(o1, o2, new BiFunction() { + Flowable.zip(o1, o2, new BiFunction() { @Override public String apply(Integer t1, Integer t2) { return t1 + "-" + t2; } - }).observeOn(Schedulers.computation()).take(Observable.bufferSize() * 2).subscribe(ts); + }).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); System.out.println("Generated => A: " + generatedA.get() + " B: " + generatedB.get()); - assertTrue(generatedA.get() < (Observable.bufferSize() * 4)); - assertTrue(generatedB.get() < (Observable.bufferSize() * 4)); + assertTrue(generatedA.get() < (Flowable.bufferSize() * 4)); + assertTrue(generatedB.get() < (Flowable.bufferSize() * 4)); } - private Observable createInfiniteObservable(final AtomicInteger generated) { - Observable observable = Observable.fromIterable(new Iterable() { + private Flowable createInfiniteObservable(final AtomicInteger generated) { + Flowable observable = Flowable.fromIterable(new Iterable() { @Override public Iterator iterator() { return new Iterator() { @@ -1146,10 +1146,10 @@ public boolean hasNext() { return observable; } - Observable OBSERVABLE_OF_5_INTEGERS = OBSERVABLE_OF_5_INTEGERS(new AtomicInteger()); + Flowable OBSERVABLE_OF_5_INTEGERS = OBSERVABLE_OF_5_INTEGERS(new AtomicInteger()); - Observable OBSERVABLE_OF_5_INTEGERS(final AtomicInteger numEmitted) { - return Observable.create(new Publisher() { + Flowable OBSERVABLE_OF_5_INTEGERS(final AtomicInteger numEmitted) { + return Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber o) { @@ -1169,8 +1169,8 @@ public void subscribe(final Subscriber o) { }); } - Observable ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(final CountDownLatch latch) { - return Observable.create(new Publisher() { + Flowable ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(final CountDownLatch latch) { + return Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber o) { @@ -1202,7 +1202,7 @@ public void run() { @Test(timeout = 30000) public void testIssue1812() { // https://github.com/ReactiveX/RxJava/issues/1812 - Observable zip1 = Observable.zip(Observable.range(0, 1026), Observable.range(0, 1026), + Flowable zip1 = Flowable.zip(Flowable.range(0, 1026), Flowable.range(0, 1026), new BiFunction() { @Override @@ -1210,7 +1210,7 @@ public Integer apply(Integer i1, Integer i2) { return i1 + i2; } }); - Observable zip2 = Observable.zip(zip1, Observable.range(0, 1026), + Flowable zip2 = Flowable.zip(zip1, Flowable.range(0, 1026), new BiFunction() { @Override @@ -1226,7 +1226,7 @@ public Integer apply(Integer i1, Integer i2) { } @Test public void testUnboundedDownstreamOverrequesting() { - Observable source = Observable.range(1, 2).zipWith(Observable.range(1, 2), new BiFunction() { + Flowable source = Flowable.range(1, 2).zipWith(Flowable.range(1, 2), new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + 10 * t2; @@ -1250,14 +1250,14 @@ public void onNext(Integer t) { @Test(timeout = 10000) public void testZipRace() { long startTime = System.currentTimeMillis(); - Observable src = Observable.just(1).subscribeOn(Schedulers.computation()); + Flowable src = Flowable.just(1).subscribeOn(Schedulers.computation()); // now try and generate a hang by zipping src with itself repeatedly. A // time limit of 9 seconds ( 1 second less than the test timeout) is // used so that this test will not timeout on slow machines. int i = 0; while (System.currentTimeMillis()-startTime < 9000 && i++ < 100000) { - int value = Observable.zip(src, src, new BiFunction() { + int value = Flowable.zip(src, src, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2 * 10; @@ -1273,10 +1273,10 @@ public Integer apply(Integer t1, Integer t2) { */ @Test public void testZipRequest1() { - Observable src = Observable.just(1).subscribeOn(Schedulers.computation()); + Flowable src = Flowable.just(1).subscribeOn(Schedulers.computation()); TestSubscriber ts = new TestSubscriber(1L); - Observable.zip(src, src, new BiFunction() { + Flowable.zip(src, src, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2 * 10; diff --git a/src/test/java/io/reactivex/internal/operators/PublisherDelaySubscriptionOtherTest.java b/src/test/java/io/reactivex/internal/operators/flowable/PublisherDelaySubscriptionOtherTest.java similarity index 89% rename from src/test/java/io/reactivex/internal/operators/PublisherDelaySubscriptionOtherTest.java rename to src/test/java/io/reactivex/internal/operators/flowable/PublisherDelaySubscriptionOtherTest.java index a3631ed02a..cb8b036d8b 100644 --- a/src/test/java/io/reactivex/internal/operators/PublisherDelaySubscriptionOtherTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/PublisherDelaySubscriptionOtherTest.java @@ -10,29 +10,29 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.flowable; import java.util.concurrent.atomic.AtomicInteger; import org.junit.*; import org.reactivestreams.Subscription; -import io.reactivex.Observable; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Consumer; -import io.reactivex.subjects.PublishSubject; +import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; public class PublisherDelaySubscriptionOtherTest { @Test public void testNoPrematureSubscription() { - PublishSubject other = PublishSubject.create(); + PublishProcessor other = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber(); final AtomicInteger subscribed = new AtomicInteger(); - Observable.just(1) + Flowable.just(1) .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -59,13 +59,13 @@ public void accept(Subscription s) { @Test public void testNoMultipleSubscriptions() { - PublishSubject other = PublishSubject.create(); + PublishProcessor other = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber(); final AtomicInteger subscribed = new AtomicInteger(); - Observable.just(1) + Flowable.just(1) .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -93,13 +93,13 @@ public void accept(Subscription s) { @Test public void testCompleteTriggersSubscription() { - PublishSubject other = PublishSubject.create(); + PublishProcessor other = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber(); final AtomicInteger subscribed = new AtomicInteger(); - Observable.just(1) + Flowable.just(1) .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -126,13 +126,13 @@ public void accept(Subscription s) { @Test public void testNoPrematureSubscriptionToError() { - PublishSubject other = PublishSubject.create(); + PublishProcessor other = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber(); final AtomicInteger subscribed = new AtomicInteger(); - Observable.error(new TestException()) + Flowable.error(new TestException()) .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -159,13 +159,13 @@ public void accept(Subscription s) { @Test public void testNoSubscriptionIfOtherErrors() { - PublishSubject other = PublishSubject.create(); + PublishProcessor other = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber(); final AtomicInteger subscribed = new AtomicInteger(); - Observable.error(new TestException()) + Flowable.error(new TestException()) .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { @@ -193,13 +193,13 @@ public void accept(Subscription s) { @Test public void testBackpressurePassesThrough() { - PublishSubject other = PublishSubject.create(); + PublishProcessor other = PublishProcessor.create(); TestSubscriber ts = new TestSubscriber((Long)null); final AtomicInteger subscribed = new AtomicInteger(); - Observable.just(1, 2, 3, 4, 5) + Flowable.just(1, 2, 3, 4, 5) .doOnSubscribe(new Consumer() { @Override public void accept(Subscription s) { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSequenceEqualTest.java b/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSequenceEqualTest.java deleted file mode 100644 index 725889e7db..0000000000 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSequenceEqualTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/** - * Copyright 2016 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. - */ - -package io.reactivex.internal.operators.nbp; - -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.*; - -import org.junit.*; -import org.mockito.InOrder; - -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; -import io.reactivex.exceptions.TestException; -import io.reactivex.functions.BiPredicate; - -public class NbpOperatorSequenceEqualTest { - - @Test - public void test1() { - NbpObservable o = NbpObservable.sequenceEqual( - NbpObservable.just("one", "two", "three"), - NbpObservable.just("one", "two", "three")); - verifyResult(o, true); - } - - @Test - public void test2() { - NbpObservable o = NbpObservable.sequenceEqual( - NbpObservable.just("one", "two", "three"), - NbpObservable.just("one", "two", "three", "four")); - verifyResult(o, false); - } - - @Test - public void test3() { - NbpObservable o = NbpObservable.sequenceEqual( - NbpObservable.just("one", "two", "three", "four"), - NbpObservable.just("one", "two", "three")); - verifyResult(o, false); - } - - @Test - public void testWithError1() { - NbpObservable o = NbpObservable.sequenceEqual( - NbpObservable.concat(NbpObservable.just("one"), - NbpObservable. error(new TestException())), - NbpObservable.just("one", "two", "three")); - verifyError(o); - } - - @Test - public void testWithError2() { - NbpObservable o = NbpObservable.sequenceEqual( - NbpObservable.just("one", "two", "three"), - NbpObservable.concat(NbpObservable.just("one"), - NbpObservable. error(new TestException()))); - verifyError(o); - } - - @Test - public void testWithError3() { - NbpObservable o = NbpObservable.sequenceEqual( - NbpObservable.concat(NbpObservable.just("one"), - NbpObservable. error(new TestException())), - NbpObservable.concat(NbpObservable.just("one"), - NbpObservable. error(new TestException()))); - verifyError(o); - } - - @Test - public void testWithEmpty1() { - NbpObservable o = NbpObservable.sequenceEqual( - NbpObservable. empty(), - NbpObservable.just("one", "two", "three")); - verifyResult(o, false); - } - - @Test - public void testWithEmpty2() { - NbpObservable o = NbpObservable.sequenceEqual( - NbpObservable.just("one", "two", "three"), - NbpObservable. empty()); - verifyResult(o, false); - } - - @Test - public void testWithEmpty3() { - NbpObservable o = NbpObservable.sequenceEqual( - NbpObservable. empty(), NbpObservable. empty()); - verifyResult(o, true); - } - - @Test - @Ignore("Null values not allowed") - public void testWithNull1() { - NbpObservable o = NbpObservable.sequenceEqual( - NbpObservable.just((String) null), NbpObservable.just("one")); - verifyResult(o, false); - } - - @Test - @Ignore("Null values not allowed") - public void testWithNull2() { - NbpObservable o = NbpObservable.sequenceEqual( - NbpObservable.just((String) null), NbpObservable.just((String) null)); - verifyResult(o, true); - } - - @Test - public void testWithEqualityError() { - NbpObservable o = NbpObservable.sequenceEqual( - NbpObservable.just("one"), NbpObservable.just("one"), - new BiPredicate() { - @Override - public boolean test(String t1, String t2) { - throw new TestException(); - } - }); - verifyError(o); - } - - private void verifyResult(NbpObservable o, boolean result) { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - - o.subscribe(NbpObserver); - - InOrder inOrder = inOrder(NbpObserver); - inOrder.verify(NbpObserver, times(1)).onNext(result); - inOrder.verify(NbpObserver).onComplete(); - inOrder.verifyNoMoreInteractions(); - } - - private void verifyError(NbpObservable NbpObservable) { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable.subscribe(NbpObserver); - - InOrder inOrder = inOrder(NbpObserver); - inOrder.verify(NbpObserver, times(1)).onError(isA(TestException.class)); - inOrder.verifyNoMoreInteractions(); - } -} \ No newline at end of file diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorLatestTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorLatestTest.java similarity index 80% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorLatestTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorLatestTest.java index 67b34f2d6d..bf479b49bb 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorLatestTest.java @@ -11,24 +11,24 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.*; import java.util.concurrent.TimeUnit; import org.junit.*; -import io.reactivex.NbpObservable; -import io.reactivex.observables.nbp.NbpBlockingObservable; +import io.reactivex.Observable; +import io.reactivex.observables.BlockingObservable; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpBlockingOperatorLatestTest { @Test(timeout = 1000) public void testSimple() { TestScheduler scheduler = new TestScheduler(); - NbpBlockingObservable source = NbpObservable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); + BlockingObservable source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); Iterable iter = source.latest(); @@ -52,7 +52,7 @@ public void testSimple() { public void testSameSourceMultipleIterators() { TestScheduler scheduler = new TestScheduler(); - NbpBlockingObservable source = NbpObservable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); + BlockingObservable source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); Iterable iter = source.latest(); @@ -76,7 +76,7 @@ public void testSameSourceMultipleIterators() { @Test(timeout = 1000, expected = NoSuchElementException.class) public void testEmpty() { - NbpBlockingObservable source = NbpObservable. empty().toBlocking(); + BlockingObservable source = Observable. empty().toBlocking(); Iterable iter = source.latest(); @@ -91,7 +91,7 @@ public void testEmpty() { public void testSimpleJustNext() { TestScheduler scheduler = new TestScheduler(); - NbpBlockingObservable source = NbpObservable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); + BlockingObservable source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); Iterable iter = source.latest(); @@ -110,7 +110,7 @@ public void testSimpleJustNext() { public void testHasNextThrows() { TestScheduler scheduler = new TestScheduler(); - NbpBlockingObservable source = NbpObservable. error(new RuntimeException("Forced failure!")).subscribeOn(scheduler).toBlocking(); + BlockingObservable source = Observable. error(new RuntimeException("Forced failure!")).subscribeOn(scheduler).toBlocking(); Iterable iter = source.latest(); @@ -125,7 +125,7 @@ public void testHasNextThrows() { public void testNextThrows() { TestScheduler scheduler = new TestScheduler(); - NbpBlockingObservable source = NbpObservable. error(new RuntimeException("Forced failure!")).subscribeOn(scheduler).toBlocking(); + BlockingObservable source = Observable. error(new RuntimeException("Forced failure!")).subscribeOn(scheduler).toBlocking(); Iterable iter = source.latest(); Iterator it = iter.iterator(); @@ -137,8 +137,8 @@ public void testNextThrows() { @Test(timeout = 1000) public void testFasterSource() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpBlockingObservable blocker = source.toBlocking(); + PublishSubject source = PublishSubject.create(); + BlockingObservable blocker = source.toBlocking(); Iterable iter = blocker.latest(); Iterator it = iter.iterator(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorMostRecentTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorMostRecentTest.java similarity index 80% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorMostRecentTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorMostRecentTest.java index e4d18cf4ab..f440ebc4b1 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorMostRecentTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorMostRecentTest.java @@ -11,9 +11,9 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import static io.reactivex.internal.operators.nbp.NbpBlockingOperatorMostRecent.mostRecent; +import static io.reactivex.internal.operators.observable.NbpBlockingOperatorMostRecent.mostRecent; import static org.junit.Assert.*; import java.util.Iterator; @@ -21,21 +21,21 @@ import org.junit.*; -import io.reactivex.NbpObservable; +import io.reactivex.Observable; import io.reactivex.exceptions.TestException; -import io.reactivex.observables.nbp.NbpBlockingObservable; +import io.reactivex.observables.BlockingObservable; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.*; +import io.reactivex.subjects.*; public class NbpBlockingOperatorMostRecentTest { @Test public void testMostRecentNull() { - assertEquals(null, NbpObservable.never().toBlocking().mostRecent(null).iterator().next()); + assertEquals(null, Observable.never().toBlocking().mostRecent(null).iterator().next()); } @Test public void testMostRecent() { - NbpSubject s = NbpPublishSubject.create(); + Subject s = PublishSubject.create(); Iterator it = mostRecent(s, "default").iterator(); @@ -60,7 +60,7 @@ public void testMostRecent() { @Test(expected = TestException.class) public void testMostRecentWithException() { - NbpSubject s = NbpPublishSubject.create(); + Subject s = PublishSubject.create(); Iterator it = mostRecent(s, "default").iterator(); @@ -77,7 +77,7 @@ public void testMostRecentWithException() { @Test(timeout = 1000) public void testSingleSourceManyIterators() { TestScheduler scheduler = new TestScheduler(); - NbpBlockingObservable source = NbpObservable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); + BlockingObservable source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10).toBlocking(); Iterable iter = source.mostRecent(-1L); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorNextTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorNextTest.java similarity index 83% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorNextTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorNextTest.java index 258e777de3..eefb832bde 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorNextTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorNextTest.java @@ -11,9 +11,9 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import static io.reactivex.internal.operators.nbp.NbpBlockingOperatorNext.next; +import static io.reactivex.internal.operators.observable.NbpBlockingOperatorNext.next; import static org.junit.Assert.*; import java.util.*; @@ -22,19 +22,19 @@ import org.junit.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.exceptions.TestException; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.internal.operators.nbp.NbpBlockingOperatorNext; -import io.reactivex.observables.nbp.NbpBlockingObservable; +import io.reactivex.observables.BlockingObservable; +import io.reactivex.processors.BehaviorProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.BehaviorSubject; -import io.reactivex.subjects.nbp.*; +import io.reactivex.subjects.*; public class NbpBlockingOperatorNextTest { - private void fireOnNextInNewThread(final NbpSubject o, final String value) { + private void fireOnNextInNewThread(final Subject o, final String value) { new Thread() { @Override public void run() { @@ -48,7 +48,7 @@ public void run() { }.start(); } - private void fireOnErrorInNewThread(final NbpSubject o) { + private void fireOnErrorInNewThread(final Subject o) { new Thread() { @Override public void run() { @@ -64,7 +64,7 @@ public void run() { @Test public void testNext() { - NbpSubject obs = NbpPublishSubject.create(); + Subject obs = PublishSubject.create(); Iterator it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertTrue(it.hasNext()); @@ -100,7 +100,7 @@ public void testNext() { @Test public void testNextWithError() { - NbpSubject obs = NbpPublishSubject.create(); + Subject obs = PublishSubject.create(); Iterator it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertTrue(it.hasNext()); @@ -118,7 +118,7 @@ public void testNextWithError() { @Test public void testNextWithEmpty() { - NbpObservable obs = NbpObservable. empty().observeOn(Schedulers.newThread()); + Observable obs = Observable. empty().observeOn(Schedulers.newThread()); Iterator it = next(obs).iterator(); assertFalse(it.hasNext()); @@ -139,7 +139,7 @@ public void testNextWithEmpty() { @Test public void testOnError() throws Throwable { - NbpSubject obs = NbpPublishSubject.create(); + Subject obs = PublishSubject.create(); Iterator it = next(obs).iterator(); obs.onError(new TestException()); @@ -155,7 +155,7 @@ public void testOnError() throws Throwable { @Test public void testOnErrorInNewThread() { - NbpSubject obs = NbpPublishSubject.create(); + Subject obs = PublishSubject.create(); Iterator it = next(obs).iterator(); fireOnErrorInNewThread(obs); @@ -186,7 +186,7 @@ private void assertErrorAfterObservableFail(Iterator it) { @Test public void testNextWithOnlyUsingNextMethod() { - NbpSubject obs = NbpPublishSubject.create(); + Subject obs = PublishSubject.create(); Iterator it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertEquals("one", it.next()); @@ -204,7 +204,7 @@ public void testNextWithOnlyUsingNextMethod() { @Test public void testNextWithCallingHasNextMultipleTimes() { - NbpSubject obs = NbpPublishSubject.create(); + Subject obs = PublishSubject.create(); Iterator it = next(obs).iterator(); fireOnNextInNewThread(obs, "one"); assertTrue(it.hasNext()); @@ -235,10 +235,10 @@ public void testNoBufferingOrBlockingOfSequence() throws Throwable { final CountDownLatch timeHasPassed = new CountDownLatch(COUNT); final AtomicBoolean running = new AtomicBoolean(true); final AtomicInteger count = new AtomicInteger(0); - final NbpObservable obs = NbpObservable.create(new NbpOnSubscribe() { + final Observable obs = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber o) { + public void accept(final Observer o) { o.onSubscribe(EmptyDisposable.INSTANCE); new Thread(new Runnable() { @@ -295,9 +295,9 @@ public void run() { @Test /* (timeout = 8000) */ public void testSingleSourceManyIterators() throws InterruptedException { - NbpObservable o = NbpObservable.interval(100, TimeUnit.MILLISECONDS); - NbpPublishSubject terminal = NbpPublishSubject.create(); - NbpBlockingObservable source = o.takeUntil(terminal).toBlocking(); + Observable o = Observable.interval(100, TimeUnit.MILLISECONDS); + PublishSubject terminal = PublishSubject.create(); + BlockingObservable source = o.takeUntil(terminal).toBlocking(); Iterable iter = source.next(); @@ -314,8 +314,8 @@ public void testSingleSourceManyIterators() throws InterruptedException { @Test public void testSynchronousNext() { - assertEquals(1, BehaviorSubject.createDefault(1).take(1).toBlocking().single().intValue()); - assertEquals(2, BehaviorSubject.createDefault(2).toBlocking().iterator().next().intValue()); - assertEquals(3, BehaviorSubject.createDefault(3).toBlocking().next().iterator().next().intValue()); + assertEquals(1, BehaviorProcessor.createDefault(1).take(1).toBlocking().single().intValue()); + assertEquals(2, BehaviorProcessor.createDefault(2).toBlocking().iterator().next().intValue()); + assertEquals(3, BehaviorProcessor.createDefault(3).toBlocking().next().iterator().next().intValue()); } } \ No newline at end of file diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorToIteratorTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorToIteratorTest.java similarity index 80% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorToIteratorTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorToIteratorTest.java index 020b72c4c7..f1dd02fe37 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpBlockingOperatorToIteratorTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpBlockingOperatorToIteratorTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; @@ -19,8 +19,8 @@ import org.junit.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.exceptions.TestException; import io.reactivex.internal.disposables.EmptyDisposable; @@ -28,7 +28,7 @@ public class NbpBlockingOperatorToIteratorTest { @Test public void testToIterator() { - NbpObservable obs = NbpObservable.just("one", "two", "three"); + Observable obs = Observable.just("one", "two", "three"); Iterator it = obs.toBlocking().iterator(); @@ -47,10 +47,10 @@ public void testToIterator() { @Test(expected = TestException.class) public void testToIteratorWithException() { - NbpObservable obs = NbpObservable.create(new NbpOnSubscribe() { + Observable obs = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); NbpObserver.onNext("one"); NbpObserver.onError(new TestException()); @@ -69,9 +69,9 @@ public void accept(NbpSubscriber NbpObserver) { @Ignore("subscribe() should not throw") @Test(expected = TestException.class) public void testExceptionThrownFromOnSubscribe() { - Iterable strings = NbpObservable.create(new NbpOnSubscribe() { + Iterable strings = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpSubscriber) { + public void accept(Observer NbpSubscriber) { throw new TestException("intentional"); } }).toBlocking(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpBufferUntilSubscriberTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpBufferUntilSubscriberTest.java similarity index 87% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpBufferUntilSubscriberTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpBufferUntilSubscriberTest.java index 585afa1a9f..8da44a0702 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpBufferUntilSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpBufferUntilSubscriberTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.List; import java.util.concurrent.*; @@ -19,10 +19,10 @@ import org.junit.*; -import io.reactivex.NbpObservable; +import io.reactivex.Observable; import io.reactivex.functions.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpBufferUntilSubscriberTest { @@ -36,14 +36,14 @@ public void testIssue1677() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(NITERS); for (int iters = 0; iters < NITERS; iters++) { final CountDownLatch innerLatch = new CountDownLatch(1); - final NbpPublishSubject s = NbpPublishSubject.create(); + final PublishSubject s = PublishSubject.create(); final AtomicBoolean completed = new AtomicBoolean(); - NbpObservable.fromArray(numbers) + Observable.fromArray(numbers) .takeUntil(s) .window(50) - .flatMap(new Function, NbpObservable>() { + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable integerObservable) { + public Observable apply(Observable integerObservable) { return integerObservable .subscribeOn(Schedulers.computation()) .map(new Function() { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpCachedObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpCachedObservableTest.java similarity index 78% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpCachedObservableTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpCachedObservableTest.java index b84f28bbb0..d85aee850d 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpCachedObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpCachedObservableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -22,23 +22,23 @@ import org.junit.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Consumer; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.internal.operators.nbp.NbpCachedObservable; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpCachedObservableTest { @Test public void testColdReplayNoBackpressure() { - NbpCachedObservable source = NbpCachedObservable.from(NbpObservable.range(0, 1000)); + NbpCachedObservable source = NbpCachedObservable.from(Observable.range(0, 1000)); assertFalse("Source is connected!", source.isConnected()); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); source.subscribe(ts); @@ -58,10 +58,10 @@ public void testColdReplayNoBackpressure() { @Test public void testCache() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - NbpObservable o = NbpObservable.create(new NbpOnSubscribe() { + Observable o = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); new Thread(new Runnable() { @@ -108,7 +108,7 @@ public void accept(String v) { @Test public void testUnsubscribeSource() { Runnable unsubscribe = mock(Runnable.class); - NbpObservable o = NbpObservable.just(1).doOnCancel(unsubscribe).cache(); + Observable o = Observable.just(1).doOnCancel(unsubscribe).cache(); o.subscribe(); o.subscribe(); o.subscribe(); @@ -117,9 +117,9 @@ public void testUnsubscribeSource() { @Test public void testTake() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - NbpCachedObservable cached = NbpCachedObservable.from(NbpObservable.range(1, 100)); + NbpCachedObservable cached = NbpCachedObservable.from(Observable.range(1, 100)); cached.take(10).subscribe(ts); ts.assertNoErrors(); @@ -131,9 +131,9 @@ public void testTake() { @Test public void testAsync() { - NbpObservable source = NbpObservable.range(1, 10000); + Observable source = Observable.range(1, 10000); for (int i = 0; i < 100; i++) { - NbpTestSubscriber ts1 = new NbpTestSubscriber(); + TestObserver ts1 = new TestObserver(); NbpCachedObservable cached = NbpCachedObservable.from(source); @@ -144,7 +144,7 @@ public void testAsync() { ts1.assertComplete(); assertEquals(10000, ts1.values().size()); - NbpTestSubscriber ts2 = new NbpTestSubscriber(); + TestObserver ts2 = new TestObserver(); cached.observeOn(Schedulers.computation()).subscribe(ts2); ts2.awaitTerminalEvent(2, TimeUnit.SECONDS); @@ -155,16 +155,16 @@ public void testAsync() { } @Test public void testAsyncComeAndGo() { - NbpObservable source = NbpObservable.interval(1, 1, TimeUnit.MILLISECONDS) + Observable source = Observable.interval(1, 1, TimeUnit.MILLISECONDS) .take(1000) .subscribeOn(Schedulers.io()); NbpCachedObservable cached = NbpCachedObservable.from(source); - NbpObservable output = cached.observeOn(Schedulers.computation()); + Observable output = cached.observeOn(Schedulers.computation()); - List> list = new ArrayList>(100); + List> list = new ArrayList>(100); for (int i = 0; i < 100; i++) { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); list.add(ts); output.skip(i * 10).take(10).subscribe(ts); } @@ -174,7 +174,7 @@ public void testAsyncComeAndGo() { expected.add((long)(i - 10)); } int j = 0; - for (NbpTestSubscriber ts : list) { + for (TestObserver ts : list) { ts.awaitTerminalEvent(3, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertComplete(); @@ -192,9 +192,9 @@ public void testAsyncComeAndGo() { @Test public void testNoMissingBackpressureException() { final int m = 4 * 1000 * 1000; - NbpObservable firehose = NbpObservable.create(new NbpOnSubscribe() { + Observable firehose = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber t) { + public void accept(Observer t) { t.onSubscribe(EmptyDisposable.INSTANCE); for (int i = 0; i < m; i++) { t.onNext(i); @@ -203,7 +203,7 @@ public void accept(NbpSubscriber t) { } }); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); firehose.cache().observeOn(Schedulers.computation()).takeLast(100).subscribe(ts); ts.awaitTerminalEvent(3, TimeUnit.SECONDS); @@ -215,19 +215,19 @@ public void accept(NbpSubscriber t) { @Test public void testValuesAndThenError() { - NbpObservable source = NbpObservable.range(1, 10) - .concatWith(NbpObservable.error(new TestException())) + Observable source = Observable.range(1, 10) + .concatWith(Observable.error(new TestException())) .cache(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); source.subscribe(ts); ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); ts.assertNotComplete(); ts.assertError(TestException.class); - NbpTestSubscriber ts2 = new NbpTestSubscriber(); + TestObserver ts2 = new TestObserver(); source.subscribe(ts2); ts2.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); @@ -239,7 +239,7 @@ public void testValuesAndThenError() { public void unsafeChildThrows() { final AtomicInteger count = new AtomicInteger(); - NbpObservable source = NbpObservable.range(1, 100) + Observable source = Observable.range(1, 100) .doOnNext(new Consumer() { @Override public void accept(Integer t) { @@ -248,7 +248,7 @@ public void accept(Integer t) { }) .cache(); - NbpTestSubscriber ts = new NbpTestSubscriber() { + TestObserver ts = new TestObserver() { @Override public void onNext(Integer t) { throw new TestException(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeAmbTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeAmbTest.java similarity index 74% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeAmbTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeAmbTest.java index b4b7516993..1291a308a3 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeAmbTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -24,12 +24,13 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.*; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Consumer; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subjects.PublishSubject; public class NbpOnSubscribeAmbTest { @@ -42,12 +43,12 @@ public void setUp() { innerScheduler = scheduler.createWorker(); } - private NbpObservable createObservable(final String[] values, + private Observable createObservable(final String[] values, final long interval, final Throwable e) { - return NbpObservable.create(new NbpOnSubscribe() { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber NbpSubscriber) { + public void accept(final Observer NbpSubscriber) { CompositeDisposable parentSubscription = new CompositeDisposable(); NbpSubscriber.onSubscribe(parentSubscription); @@ -79,18 +80,18 @@ public void run() { @Test public void testAmb() { - NbpObservable observable1 = createObservable(new String[] { + Observable observable1 = createObservable(new String[] { "1", "11", "111", "1111" }, 2000, null); - NbpObservable observable2 = createObservable(new String[] { + Observable observable2 = createObservable(new String[] { "2", "22", "222", "2222" }, 1000, null); - NbpObservable observable3 = createObservable(new String[] { + Observable observable3 = createObservable(new String[] { "3", "33", "333", "3333" }, 3000, null); @SuppressWarnings("unchecked") - NbpObservable o = NbpObservable.amb(observable1, + Observable o = Observable.amb(observable1, observable2, observable3); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); scheduler.advanceTimeBy(100000, TimeUnit.MILLISECONDS); @@ -108,18 +109,18 @@ public void testAmb() { public void testAmb2() { IOException expectedException = new IOException( "fake exception"); - NbpObservable observable1 = createObservable(new String[] {}, + Observable observable1 = createObservable(new String[] {}, 2000, new IOException("fake exception")); - NbpObservable observable2 = createObservable(new String[] { + Observable observable2 = createObservable(new String[] { "2", "22", "222", "2222" }, 1000, expectedException); - NbpObservable observable3 = createObservable(new String[] {}, + Observable observable3 = createObservable(new String[] {}, 3000, new IOException("fake exception")); @SuppressWarnings("unchecked") - NbpObservable o = NbpObservable.amb(observable1, + Observable o = Observable.amb(observable1, observable2, observable3); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); scheduler.advanceTimeBy(100000, TimeUnit.MILLISECONDS); @@ -135,18 +136,18 @@ public void testAmb2() { @Test public void testAmb3() { - NbpObservable observable1 = createObservable(new String[] { + Observable observable1 = createObservable(new String[] { "1" }, 2000, null); - NbpObservable observable2 = createObservable(new String[] {}, + Observable observable2 = createObservable(new String[] {}, 1000, null); - NbpObservable observable3 = createObservable(new String[] { + Observable observable3 = createObservable(new String[] { "3" }, 3000, null); @SuppressWarnings("unchecked") - NbpObservable o = NbpObservable.amb(observable1, + Observable o = Observable.amb(observable1, observable2, observable3); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); scheduler.advanceTimeBy(100000, TimeUnit.MILLISECONDS); @@ -167,13 +168,13 @@ public void accept(Disposable s) { }; //this aync stream should emit first - NbpObservable o1 = NbpObservable.just(1).doOnSubscribe(incrementer) + Observable o1 = Observable.just(1).doOnSubscribe(incrementer) .delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation()); //this stream emits second - NbpObservable o2 = NbpObservable.just(1).doOnSubscribe(incrementer) + Observable o2 = Observable.just(1).doOnSubscribe(incrementer) .delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation()); - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.amb(o1, o2).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.amb(o1, o2).subscribe(ts); ts.awaitTerminalEvent(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(2, count.get()); @@ -186,7 +187,7 @@ public void testSynchronousSources() { // then second NbpObservable does not get subscribed to before first // subscription completes hence first NbpObservable emits result through // amb - int result = NbpObservable.just(1).doOnNext(new Consumer() { + int result = Observable.just(1).doOnNext(new Consumer() { @Override public void accept(Integer t) { try { @@ -195,20 +196,20 @@ public void accept(Integer t) { // } } - }).ambWith(NbpObservable.just(2)).toBlocking().single(); + }).ambWith(Observable.just(2)).toBlocking().single(); assertEquals(1, result); } @SuppressWarnings("unchecked") @Test public void testAmbCancelsOthers() { - NbpPublishSubject source1 = NbpPublishSubject.create(); - NbpPublishSubject source2 = NbpPublishSubject.create(); - NbpPublishSubject source3 = NbpPublishSubject.create(); + PublishSubject source1 = PublishSubject.create(); + PublishSubject source2 = PublishSubject.create(); + PublishSubject source3 = PublishSubject.create(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - NbpObservable.amb(source1, source2, source3).subscribe(ts); + Observable.amb(source1, source2, source3).subscribe(ts); assertTrue("Source 1 doesn't have subscribers!", source1.hasSubscribers()); assertTrue("Source 2 doesn't have subscribers!", source2.hasSubscribers()); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeCombineLatestTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeCombineLatestTest.java similarity index 68% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeCombineLatestTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeCombineLatestTest.java index 4e6fd54f81..05ebc2eca8 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeCombineLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeCombineLatestTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,23 +25,25 @@ import org.mockito.*; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.Optional; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; +import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; -import io.reactivex.Optional; +import io.reactivex.subjects.PublishSubject; public class NbpOnSubscribeCombineLatestTest { @Test public void testCombineLatestWithFunctionThatThrowsAnException() { - NbpSubscriber w = TestHelper.mockNbpSubscriber(); + Observer w = TestHelper.mockNbpSubscriber(); - NbpPublishSubject w1 = NbpPublishSubject.create(); - NbpPublishSubject w2 = NbpPublishSubject.create(); + PublishSubject w1 = PublishSubject.create(); + PublishSubject w2 = PublishSubject.create(); - NbpObservable combined = NbpObservable.combineLatest(w1, w2, new BiFunction() { + Observable combined = Observable.combineLatest(w1, w2, new BiFunction() { @Override public String apply(String v1, String v2) { throw new RuntimeException("I don't work."); @@ -59,13 +61,13 @@ public String apply(String v1, String v2) { @Test public void testCombineLatestDifferentLengthObservableSequences1() { - NbpSubscriber w = TestHelper.mockNbpSubscriber(); + Observer w = TestHelper.mockNbpSubscriber(); - NbpPublishSubject w1 = NbpPublishSubject.create(); - NbpPublishSubject w2 = NbpPublishSubject.create(); - NbpPublishSubject w3 = NbpPublishSubject.create(); + PublishSubject w1 = PublishSubject.create(); + PublishSubject w2 = PublishSubject.create(); + PublishSubject w3 = PublishSubject.create(); - NbpObservable combineLatestW = NbpObservable.combineLatest(w1, w2, w3, + Observable combineLatestW = Observable.combineLatest(w1, w2, w3, getConcat3StringsCombineLatestFunction()); combineLatestW.subscribe(w); @@ -97,13 +99,13 @@ public void testCombineLatestDifferentLengthObservableSequences1() { @Test public void testCombineLatestDifferentLengthObservableSequences2() { - NbpSubscriber w = TestHelper.mockNbpSubscriber(); + Observer w = TestHelper.mockNbpSubscriber(); - NbpPublishSubject w1 = NbpPublishSubject.create(); - NbpPublishSubject w2 = NbpPublishSubject.create(); - NbpPublishSubject w3 = NbpPublishSubject.create(); + PublishSubject w1 = PublishSubject.create(); + PublishSubject w2 = PublishSubject.create(); + PublishSubject w3 = PublishSubject.create(); - NbpObservable combineLatestW = NbpObservable.combineLatest(w1, w2, w3, getConcat3StringsCombineLatestFunction()); + Observable combineLatestW = Observable.combineLatest(w1, w2, w3, getConcat3StringsCombineLatestFunction()); combineLatestW.subscribe(w); /* simulate sending data */ @@ -132,13 +134,13 @@ public void testCombineLatestDifferentLengthObservableSequences2() { @Test public void testCombineLatestWithInterleavingSequences() { - NbpSubscriber w = TestHelper.mockNbpSubscriber(); + Observer w = TestHelper.mockNbpSubscriber(); - NbpPublishSubject w1 = NbpPublishSubject.create(); - NbpPublishSubject w2 = NbpPublishSubject.create(); - NbpPublishSubject w3 = NbpPublishSubject.create(); + PublishSubject w1 = PublishSubject.create(); + PublishSubject w2 = PublishSubject.create(); + PublishSubject w3 = PublishSubject.create(); - NbpObservable combineLatestW = NbpObservable.combineLatest(w1, w2, w3, getConcat3StringsCombineLatestFunction()); + Observable combineLatestW = Observable.combineLatest(w1, w2, w3, getConcat3StringsCombineLatestFunction()); combineLatestW.subscribe(w); /* simulate sending data */ @@ -173,9 +175,9 @@ public void testCombineLatest2Types() { BiFunction combineLatestFunction = getConcatStringIntegerCombineLatestFunction(); /* define a NbpObserver to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable w = NbpObservable.combineLatest(NbpObservable.just("one", "two"), NbpObservable.just(2, 3, 4), combineLatestFunction); + Observable w = Observable.combineLatest(Observable.just("one", "two"), Observable.just(2, 3, 4), combineLatestFunction); w.subscribe(NbpObserver); verify(NbpObserver, never()).onError(any(Throwable.class)); @@ -190,9 +192,9 @@ public void testCombineLatest3TypesA() { Function3 combineLatestFunction = getConcatStringIntegerIntArrayCombineLatestFunction(); /* define a NbpObserver to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable w = NbpObservable.combineLatest(NbpObservable.just("one", "two"), NbpObservable.just(2), NbpObservable.just(new int[] { 4, 5, 6 }), combineLatestFunction); + Observable w = Observable.combineLatest(Observable.just("one", "two"), Observable.just(2), Observable.just(new int[] { 4, 5, 6 }), combineLatestFunction); w.subscribe(NbpObserver); verify(NbpObserver, never()).onError(any(Throwable.class)); @@ -205,9 +207,9 @@ public void testCombineLatest3TypesB() { Function3 combineLatestFunction = getConcatStringIntegerIntArrayCombineLatestFunction(); /* define a NbpObserver to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable w = NbpObservable.combineLatest(NbpObservable.just("one"), NbpObservable.just(2), NbpObservable.just(new int[] { 4, 5, 6 }, new int[] { 7, 8 }), combineLatestFunction); + Observable w = Observable.combineLatest(Observable.just("one"), Observable.just(2), Observable.just(new int[] { 4, 5, 6 }, new int[] { 7, 8 }), combineLatestFunction); w.subscribe(NbpObserver); verify(NbpObserver, never()).onError(any(Throwable.class)); @@ -275,12 +277,12 @@ public Integer apply(Integer t1, Integer t2) { @Test public void combineSimple() { - NbpPublishSubject a = NbpPublishSubject.create(); - NbpPublishSubject b = NbpPublishSubject.create(); + PublishSubject a = PublishSubject.create(); + PublishSubject b = PublishSubject.create(); - NbpObservable source = NbpObservable.combineLatest(a, b, or); + Observable source = Observable.combineLatest(a, b, or); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(NbpObserver); source.subscribe(NbpObserver); @@ -319,14 +321,14 @@ public void combineSimple() { @Test public void combineMultipleObservers() { - NbpPublishSubject a = NbpPublishSubject.create(); - NbpPublishSubject b = NbpPublishSubject.create(); + PublishSubject a = PublishSubject.create(); + PublishSubject b = PublishSubject.create(); - NbpObservable source = NbpObservable.combineLatest(a, b, or); + Observable source = Observable.combineLatest(a, b, or); - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); - NbpSubscriber observer2 = TestHelper.mockNbpSubscriber(); + Observer observer2 = TestHelper.mockNbpSubscriber(); InOrder inOrder1 = inOrder(observer1); InOrder inOrder2 = inOrder(observer2); @@ -376,12 +378,12 @@ public void combineMultipleObservers() { @Test public void testFirstNeverProduces() { - NbpPublishSubject a = NbpPublishSubject.create(); - NbpPublishSubject b = NbpPublishSubject.create(); + PublishSubject a = PublishSubject.create(); + PublishSubject b = PublishSubject.create(); - NbpObservable source = NbpObservable.combineLatest(a, b, or); + Observable source = Observable.combineLatest(a, b, or); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(NbpObserver); source.subscribe(NbpObserver); @@ -398,12 +400,12 @@ public void testFirstNeverProduces() { @Test public void testSecondNeverProduces() { - NbpPublishSubject a = NbpPublishSubject.create(); - NbpPublishSubject b = NbpPublishSubject.create(); + PublishSubject a = PublishSubject.create(); + PublishSubject b = PublishSubject.create(); - NbpObservable source = NbpObservable.combineLatest(a, b, or); + Observable source = Observable.combineLatest(a, b, or); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(NbpObserver); source.subscribe(NbpObserver); @@ -435,16 +437,16 @@ public List apply(Object[] args) { }; for (int i = 1; i <= n; i++) { System.out.println("test1ToNSources: " + i + " sources"); - List> sources = new ArrayList>(); + List> sources = new ArrayList>(); List values = new ArrayList(); for (int j = 0; j < i; j++) { - sources.add(NbpObservable.just(j)); + sources.add(Observable.just(j)); values.add(j); } - NbpObservable> result = NbpObservable.combineLatest(sources, func); + Observable> result = Observable.combineLatest(sources, func); - NbpSubscriber> o = TestHelper.mockNbpSubscriber(); + Observer> o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -466,20 +468,20 @@ public List apply(Object[] args) { }; for (int i = 1; i <= n; i++) { System.out.println("test1ToNSourcesScheduled: " + i + " sources"); - List> sources = new ArrayList>(); + List> sources = new ArrayList>(); List values = new ArrayList(); for (int j = 0; j < i; j++) { - sources.add(NbpObservable.just(j).subscribeOn(Schedulers.io())); + sources.add(Observable.just(j).subscribeOn(Schedulers.io())); values.add(j); } - NbpObservable> result = NbpObservable.combineLatest(sources, func); + Observable> result = Observable.combineLatest(sources, func); - final NbpSubscriber> o = TestHelper.mockNbpSubscriber(); + final Observer> o = TestHelper.mockNbpSubscriber(); final CountDownLatch cdl = new CountDownLatch(1); - NbpSubscriber> s = new NbpObserver>() { + Observer> s = new DefaultObserver>() { @Override public void onNext(List t) { @@ -511,10 +513,10 @@ public void onComplete() { @Test public void test2SourcesOverload() { - NbpObservable s1 = NbpObservable.just(1); - NbpObservable s2 = NbpObservable.just(2); + Observable s1 = Observable.just(1); + Observable s2 = Observable.just(2); - NbpObservable> result = NbpObservable.combineLatest(s1, s2, + Observable> result = Observable.combineLatest(s1, s2, new BiFunction>() { @Override public List apply(Integer t1, Integer t2) { @@ -522,7 +524,7 @@ public List apply(Integer t1, Integer t2) { } }); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -533,11 +535,11 @@ public List apply(Integer t1, Integer t2) { @Test public void test3SourcesOverload() { - NbpObservable s1 = NbpObservable.just(1); - NbpObservable s2 = NbpObservable.just(2); - NbpObservable s3 = NbpObservable.just(3); + Observable s1 = Observable.just(1); + Observable s2 = Observable.just(2); + Observable s3 = Observable.just(3); - NbpObservable> result = NbpObservable.combineLatest(s1, s2, s3, + Observable> result = Observable.combineLatest(s1, s2, s3, new Function3>() { @Override public List apply(Integer t1, Integer t2, Integer t3) { @@ -545,7 +547,7 @@ public List apply(Integer t1, Integer t2, Integer t3) { } }); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -556,12 +558,12 @@ public List apply(Integer t1, Integer t2, Integer t3) { @Test public void test4SourcesOverload() { - NbpObservable s1 = NbpObservable.just(1); - NbpObservable s2 = NbpObservable.just(2); - NbpObservable s3 = NbpObservable.just(3); - NbpObservable s4 = NbpObservable.just(4); + Observable s1 = Observable.just(1); + Observable s2 = Observable.just(2); + Observable s3 = Observable.just(3); + Observable s4 = Observable.just(4); - NbpObservable> result = NbpObservable.combineLatest(s1, s2, s3, s4, + Observable> result = Observable.combineLatest(s1, s2, s3, s4, new Function4>() { @Override public List apply(Integer t1, Integer t2, Integer t3, Integer t4) { @@ -569,7 +571,7 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4) { } }); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -580,13 +582,13 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4) { @Test public void test5SourcesOverload() { - NbpObservable s1 = NbpObservable.just(1); - NbpObservable s2 = NbpObservable.just(2); - NbpObservable s3 = NbpObservable.just(3); - NbpObservable s4 = NbpObservable.just(4); - NbpObservable s5 = NbpObservable.just(5); + Observable s1 = Observable.just(1); + Observable s2 = Observable.just(2); + Observable s3 = Observable.just(3); + Observable s4 = Observable.just(4); + Observable s5 = Observable.just(5); - NbpObservable> result = NbpObservable.combineLatest(s1, s2, s3, s4, s5, + Observable> result = Observable.combineLatest(s1, s2, s3, s4, s5, new Function5>() { @Override public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5) { @@ -594,7 +596,7 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ } }); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -605,14 +607,14 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ @Test public void test6SourcesOverload() { - NbpObservable s1 = NbpObservable.just(1); - NbpObservable s2 = NbpObservable.just(2); - NbpObservable s3 = NbpObservable.just(3); - NbpObservable s4 = NbpObservable.just(4); - NbpObservable s5 = NbpObservable.just(5); - NbpObservable s6 = NbpObservable.just(6); - - NbpObservable> result = NbpObservable.combineLatest(s1, s2, s3, s4, s5, s6, + Observable s1 = Observable.just(1); + Observable s2 = Observable.just(2); + Observable s3 = Observable.just(3); + Observable s4 = Observable.just(4); + Observable s5 = Observable.just(5); + Observable s6 = Observable.just(6); + + Observable> result = Observable.combineLatest(s1, s2, s3, s4, s5, s6, new Function6>() { @Override public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6) { @@ -620,7 +622,7 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ } }); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -631,15 +633,15 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ @Test public void test7SourcesOverload() { - NbpObservable s1 = NbpObservable.just(1); - NbpObservable s2 = NbpObservable.just(2); - NbpObservable s3 = NbpObservable.just(3); - NbpObservable s4 = NbpObservable.just(4); - NbpObservable s5 = NbpObservable.just(5); - NbpObservable s6 = NbpObservable.just(6); - NbpObservable s7 = NbpObservable.just(7); - - NbpObservable> result = NbpObservable.combineLatest(s1, s2, s3, s4, s5, s6, s7, + Observable s1 = Observable.just(1); + Observable s2 = Observable.just(2); + Observable s3 = Observable.just(3); + Observable s4 = Observable.just(4); + Observable s5 = Observable.just(5); + Observable s6 = Observable.just(6); + Observable s7 = Observable.just(7); + + Observable> result = Observable.combineLatest(s1, s2, s3, s4, s5, s6, s7, new Function7>() { @Override public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6, Integer t7) { @@ -647,7 +649,7 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ } }); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -658,16 +660,16 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ @Test public void test8SourcesOverload() { - NbpObservable s1 = NbpObservable.just(1); - NbpObservable s2 = NbpObservable.just(2); - NbpObservable s3 = NbpObservable.just(3); - NbpObservable s4 = NbpObservable.just(4); - NbpObservable s5 = NbpObservable.just(5); - NbpObservable s6 = NbpObservable.just(6); - NbpObservable s7 = NbpObservable.just(7); - NbpObservable s8 = NbpObservable.just(8); - - NbpObservable> result = NbpObservable.combineLatest(s1, s2, s3, s4, s5, s6, s7, s8, + Observable s1 = Observable.just(1); + Observable s2 = Observable.just(2); + Observable s3 = Observable.just(3); + Observable s4 = Observable.just(4); + Observable s5 = Observable.just(5); + Observable s6 = Observable.just(6); + Observable s7 = Observable.just(7); + Observable s8 = Observable.just(8); + + Observable> result = Observable.combineLatest(s1, s2, s3, s4, s5, s6, s7, s8, new Function8>() { @Override public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6, Integer t7, Integer t8) { @@ -675,7 +677,7 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ } }); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -686,17 +688,17 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ @Test public void test9SourcesOverload() { - NbpObservable s1 = NbpObservable.just(1); - NbpObservable s2 = NbpObservable.just(2); - NbpObservable s3 = NbpObservable.just(3); - NbpObservable s4 = NbpObservable.just(4); - NbpObservable s5 = NbpObservable.just(5); - NbpObservable s6 = NbpObservable.just(6); - NbpObservable s7 = NbpObservable.just(7); - NbpObservable s8 = NbpObservable.just(8); - NbpObservable s9 = NbpObservable.just(9); - - NbpObservable> result = NbpObservable.combineLatest(s1, s2, s3, s4, s5, s6, s7, s8, s9, + Observable s1 = Observable.just(1); + Observable s2 = Observable.just(2); + Observable s3 = Observable.just(3); + Observable s4 = Observable.just(4); + Observable s5 = Observable.just(5); + Observable s6 = Observable.just(6); + Observable s7 = Observable.just(7); + Observable s8 = Observable.just(8); + Observable s9 = Observable.just(9); + + Observable> result = Observable.combineLatest(s1, s2, s3, s4, s5, s6, s7, s8, s9, new Function9>() { @Override public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integer t5, Integer t6, Integer t7, Integer t8, Integer t9) { @@ -704,7 +706,7 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ } }); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -715,8 +717,8 @@ public List apply(Integer t1, Integer t2, Integer t3, Integer t4, Integ @Test public void testZeroSources() { - NbpObservable result = NbpObservable.combineLatest( - Collections.> emptyList(), new Function() { + Observable result = Observable.combineLatest( + Collections.> emptyList(), new Function() { @Override public Object apply(Object[] args) { @@ -725,7 +727,7 @@ public Object apply(Object[] args) { }); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -740,7 +742,7 @@ public void testWithCombineLatestIssue1717() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicInteger count = new AtomicInteger(); final int SIZE = 2000; - NbpObservable timer = NbpObservable.interval(0, 1, TimeUnit.MILLISECONDS) + Observable timer = Observable.interval(0, 1, TimeUnit.MILLISECONDS) .observeOn(Schedulers.newThread()) .doOnEach(new Consumer>>() { @Override @@ -752,9 +754,9 @@ public void accept(Try> n) { } }).take(SIZE); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - NbpObservable.combineLatest(timer, NbpObservable. never(), new BiFunction() { + Observable.combineLatest(timer, Observable. never(), new BiFunction() { @Override public Long apply(Long t1, Integer t2) { return t1; diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeDeferTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeDeferTest.java similarity index 73% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeDeferTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeDeferTest.java index 1bd59fe27c..adb6acc2c0 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeDeferTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeDeferTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -19,9 +19,10 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Supplier; +import io.reactivex.observers.DefaultObserver; @SuppressWarnings("unchecked") public class NbpOnSubscribeDeferTest { @@ -29,17 +30,17 @@ public class NbpOnSubscribeDeferTest { @Test public void testDefer() throws Throwable { - Supplier> factory = mock(Supplier.class); + Supplier> factory = mock(Supplier.class); - NbpObservable firstObservable = NbpObservable.just("one", "two"); - NbpObservable secondObservable = NbpObservable.just("three", "four"); + Observable firstObservable = Observable.just("one", "two"); + Observable secondObservable = Observable.just("three", "four"); when(factory.get()).thenReturn(firstObservable, secondObservable); - NbpObservable deferred = NbpObservable.defer(factory); + Observable deferred = Observable.defer(factory); verifyZeroInteractions(factory); - NbpSubscriber firstObserver = TestHelper.mockNbpSubscriber(); + Observer firstObserver = TestHelper.mockNbpSubscriber(); deferred.subscribe(firstObserver); verify(factory, times(1)).get(); @@ -49,7 +50,7 @@ public void testDefer() throws Throwable { verify(firstObserver, times(0)).onNext("four"); verify(firstObserver, times(1)).onComplete(); - NbpSubscriber secondObserver = TestHelper.mockNbpSubscriber(); + Observer secondObserver = TestHelper.mockNbpSubscriber(); deferred.subscribe(secondObserver); verify(factory, times(2)).get(); @@ -63,13 +64,13 @@ public void testDefer() throws Throwable { @Test public void testDeferFunctionThrows() { - Supplier> factory = mock(Supplier.class); + Supplier> factory = mock(Supplier.class); when(factory.get()).thenThrow(new TestException()); - NbpObservable result = NbpObservable.defer(factory); + Observable result = Observable.defer(factory); - NbpObserver o = mock(NbpObserver.class); + DefaultObserver o = mock(DefaultObserver.class); result.subscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeDelaySubscriptionOtherTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeDelaySubscriptionOtherTest.java similarity index 81% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeDelaySubscriptionOtherTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeDelaySubscriptionOtherTest.java index 7e633495f5..443eb00b00 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeDelaySubscriptionOtherTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeDelaySubscriptionOtherTest.java @@ -11,29 +11,29 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import java.util.concurrent.atomic.AtomicInteger; import org.junit.*; -import io.reactivex.NbpObservable; +import io.reactivex.Observable; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Consumer; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.TestObserver; +import io.reactivex.subjects.PublishSubject; public class NbpOnSubscribeDelaySubscriptionOtherTest { @Test public void testNoPrematureSubscription() { - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final AtomicInteger subscribed = new AtomicInteger(); - NbpObservable.just(1) + Observable.just(1) .doOnSubscribe(new Consumer() { @Override public void accept(Disposable d) { @@ -60,13 +60,13 @@ public void accept(Disposable d) { @Test public void testNoMultipleSubscriptions() { - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final AtomicInteger subscribed = new AtomicInteger(); - NbpObservable.just(1) + Observable.just(1) .doOnSubscribe(new Consumer() { @Override public void accept(Disposable d) { @@ -94,13 +94,13 @@ public void accept(Disposable d) { @Test public void testCompleteTriggersSubscription() { - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final AtomicInteger subscribed = new AtomicInteger(); - NbpObservable.just(1) + Observable.just(1) .doOnSubscribe(new Consumer() { @Override public void accept(Disposable d) { @@ -127,13 +127,13 @@ public void accept(Disposable d) { @Test public void testNoPrematureSubscriptionToError() { - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final AtomicInteger subscribed = new AtomicInteger(); - NbpObservable.error(new TestException()) + Observable.error(new TestException()) .doOnSubscribe(new Consumer() { @Override public void accept(Disposable d) { @@ -160,13 +160,13 @@ public void accept(Disposable d) { @Test public void testNoSubscriptionIfOtherErrors() { - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final AtomicInteger subscribed = new AtomicInteger(); - NbpObservable.error(new TestException()) + Observable.error(new TestException()) .doOnSubscribe(new Consumer() { @Override public void accept(Disposable d) { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeFromIterableTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeFromIterableTest.java similarity index 82% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeFromIterableTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeFromIterableTest.java index 6c5b9fcbaf..81633bdaab 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeFromIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeFromIterableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertFalse; import static org.mockito.Matchers.any; @@ -23,22 +23,23 @@ import org.junit.Test; import org.mockito.Mockito; -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.flowable.TestHelper; +import io.reactivex.observers.*; public class NbpOnSubscribeFromIterableTest { @Test(expected = NullPointerException.class) public void testNull() { - NbpObservable.fromIterable(null); + Observable.fromIterable(null); } @Test public void testListIterable() { - NbpObservable o = NbpObservable.fromIterable(Arrays. asList("one", "two", "three")); + Observable o = Observable.fromIterable(Arrays. asList("one", "two", "three")); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); @@ -80,9 +81,9 @@ public void remove() { } }; - NbpObservable o = NbpObservable.fromIterable(it); + Observable o = Observable.fromIterable(it); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); @@ -95,9 +96,9 @@ public void remove() { @Test public void testObservableFromIterable() { - NbpObservable o = NbpObservable.fromIterable(Arrays. asList("one", "two", "three")); + Observable o = Observable.fromIterable(Arrays. asList("one", "two", "three")); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); @@ -110,9 +111,9 @@ public void testObservableFromIterable() { @Test public void testNoBackpressure() { - NbpObservable o = NbpObservable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)); + Observable o = Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); o.subscribe(ts); @@ -122,10 +123,10 @@ public void testNoBackpressure() { @Test public void testSubscribeMultipleTimes() { - NbpObservable o = NbpObservable.fromIterable(Arrays.asList(1, 2, 3)); + Observable o = Observable.fromIterable(Arrays.asList(1, 2, 3)); for (int i = 0; i < 10; i++) { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); o.subscribe(ts); @@ -168,7 +169,7 @@ public Integer next() { }; } }; - NbpObservable.fromIterable(iterable).take(1).subscribe(); + Observable.fromIterable(iterable).take(1).subscribe(); assertFalse(called.get()); } @@ -205,7 +206,7 @@ public Integer next() { }; } }; - NbpObservable.fromIterable(iterable).subscribe(new NbpObserver() { + Observable.fromIterable(iterable).subscribe(new DefaultObserver() { @Override public void onComplete() { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRangeTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRangeTest.java similarity index 73% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRangeTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRangeTest.java index 4b4f5ed449..6b6b352ea6 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRangeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRangeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -22,17 +22,17 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Consumer; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.*; public class NbpOnSubscribeRangeTest { @Test public void testRangeStartAt2Count3() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable.range(2, 3).subscribe(NbpObserver); + Observable.range(2, 3).subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext(2); verify(NbpObserver, times(1)).onNext(3); @@ -44,11 +44,11 @@ public void testRangeStartAt2Count3() { @Test public void testRangeUnsubscribe() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); final AtomicInteger count = new AtomicInteger(); - NbpObservable.range(1, 1000).doOnNext(new Consumer() { + Observable.range(1, 1000).doOnNext(new Consumer() { @Override public void accept(Integer t1) { count.incrementAndGet(); @@ -67,39 +67,39 @@ public void accept(Integer t1) { @Test public void testRangeWithZero() { - NbpObservable.range(1, 0); + Observable.range(1, 0); } @Test public void testRangeWithOverflow2() { - NbpObservable.range(Integer.MAX_VALUE, 0); + Observable.range(Integer.MAX_VALUE, 0); } @Test public void testRangeWithOverflow3() { - NbpObservable.range(1, Integer.MAX_VALUE); + Observable.range(1, Integer.MAX_VALUE); } @Test(expected = IllegalArgumentException.class) public void testRangeWithOverflow4() { - NbpObservable.range(2, Integer.MAX_VALUE); + Observable.range(2, Integer.MAX_VALUE); } @Test public void testRangeWithOverflow5() { - assertFalse(NbpObservable.range(Integer.MIN_VALUE, 0).toBlocking().iterator().hasNext()); + assertFalse(Observable.range(Integer.MIN_VALUE, 0).toBlocking().iterator().hasNext()); } @Test public void testNoBackpressure() { - ArrayList list = new ArrayList(Observable.bufferSize() * 2); - for (int i = 1; i <= Observable.bufferSize() * 2 + 1; i++) { + ArrayList list = new ArrayList(Flowable.bufferSize() * 2); + for (int i = 1; i <= Flowable.bufferSize() * 2 + 1; i++) { list.add(i); } - NbpObservable o = NbpObservable.range(1, list.size()); + Observable o = Observable.range(1, list.size()); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); o.subscribe(ts); @@ -110,7 +110,7 @@ public void testNoBackpressure() { @Test public void testEmptyRangeSendsOnCompleteEagerlyWithRequestZero() { final AtomicBoolean completed = new AtomicBoolean(false); - NbpObservable.range(1, 0).subscribe(new NbpObserver() { + Observable.range(1, 0).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -136,8 +136,8 @@ public void onNext(Integer t) { @Test(timeout = 1000) public void testNearMaxValueWithoutBackpressure() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(Integer.MAX_VALUE - 1, 2).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.range(Integer.MAX_VALUE - 1, 2).subscribe(ts); ts.assertComplete(); ts.assertNoErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRefCountTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRefCountTest.java similarity index 84% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRefCountTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRefCountTest.java index d0c57576ec..e7686e385f 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeRefCountTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -24,14 +24,16 @@ import org.junit.Test; import org.mockito.InOrder; -import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.internal.subscribers.nbp.NbpCancelledSubscriber; +import io.reactivex.internal.subscribers.observable.NbpCancelledSubscriber; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; -import io.reactivex.subjects.nbp.NbpReplaySubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subjects.ReplaySubject; public class NbpOnSubscribeRefCountTest { @@ -39,7 +41,7 @@ public class NbpOnSubscribeRefCountTest { public void testRefCountAsync() { final AtomicInteger subscribeCount = new AtomicInteger(); final AtomicInteger nextCount = new AtomicInteger(); - NbpObservable r = NbpObservable.interval(0, 5, TimeUnit.MILLISECONDS) + Observable r = Observable.interval(0, 5, TimeUnit.MILLISECONDS) .doOnSubscribe(new Consumer() { @Override public void accept(Disposable s) { @@ -86,7 +88,7 @@ public void accept(Long l) { public void testRefCountSynchronous() { final AtomicInteger subscribeCount = new AtomicInteger(); final AtomicInteger nextCount = new AtomicInteger(); - NbpObservable r = NbpObservable.just(1, 2, 3, 4, 5, 6, 7, 8, 9) + Observable r = Observable.just(1, 2, 3, 4, 5, 6, 7, 8, 9) .doOnSubscribe(new Consumer() { @Override public void accept(Disposable s) { @@ -132,7 +134,7 @@ public void accept(Integer l) { @Test public void testRefCountSynchronousTake() { final AtomicInteger nextCount = new AtomicInteger(); - NbpObservable r = NbpObservable.just(1, 2, 3, 4, 5, 6, 7, 8, 9) + Observable r = Observable.just(1, 2, 3, 4, 5, 6, 7, 8, 9) .doOnNext(new Consumer() { @Override public void accept(Integer l) { @@ -161,7 +163,7 @@ public void accept(Integer l) { public void testRepeat() { final AtomicInteger subscribeCount = new AtomicInteger(); final AtomicInteger unsubscribeCount = new AtomicInteger(); - NbpObservable r = NbpObservable.interval(0, 1, TimeUnit.MILLISECONDS) + Observable r = Observable.interval(0, 1, TimeUnit.MILLISECONDS) .doOnSubscribe(new Consumer() { @Override public void accept(Disposable s) { @@ -181,8 +183,8 @@ public void run() { .publish().refCount(); for (int i = 0; i < 10; i++) { - NbpTestSubscriber ts1 = new NbpTestSubscriber(); - NbpTestSubscriber ts2 = new NbpTestSubscriber(); + TestObserver ts1 = new TestObserver(); + TestObserver ts2 = new TestObserver(); r.subscribe(ts1); r.subscribe(ts2); try { @@ -206,7 +208,7 @@ public void testConnectUnsubscribe() throws InterruptedException { final CountDownLatch unsubscribeLatch = new CountDownLatch(1); final CountDownLatch subscribeLatch = new CountDownLatch(1); - NbpObservable o = synchronousInterval() + Observable o = synchronousInterval() .doOnSubscribe(new Consumer() { @Override public void accept(Disposable s) { @@ -224,7 +226,7 @@ public void run() { } }); - NbpTestSubscriber s = new NbpTestSubscriber(); + TestObserver s = new TestObserver(); o.publish().refCount().subscribeOn(Schedulers.newThread()).subscribe(s); System.out.println("send unsubscribe"); // wait until connected @@ -252,7 +254,7 @@ public void testConnectUnsubscribeRaceConditionLoop() throws InterruptedExceptio @Test public void testConnectUnsubscribeRaceCondition() throws InterruptedException { final AtomicInteger subUnsubCount = new AtomicInteger(); - NbpObservable o = synchronousInterval() + Observable o = synchronousInterval() .doOnCancel(new Runnable() { @Override public void run() { @@ -269,7 +271,7 @@ public void accept(Disposable s) { } }); - NbpTestSubscriber s = new NbpTestSubscriber(); + TestObserver s = new TestObserver(); o.publish().refCount().subscribeOn(Schedulers.computation()).subscribe(s); System.out.println("send unsubscribe"); @@ -289,10 +291,10 @@ public void accept(Disposable s) { s.assertNoErrors(); } - private NbpObservable synchronousInterval() { - return NbpObservable.create(new NbpOnSubscribe() { + private Observable synchronousInterval() { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpSubscriber) { + public void accept(Observer NbpSubscriber) { final AtomicBoolean cancel = new AtomicBoolean(); NbpSubscriber.onSubscribe(new Disposable() { @Override @@ -318,9 +320,9 @@ public void dispose() { public void onlyFirstShouldSubscribeAndLastUnsubscribe() { final AtomicInteger subscriptionCount = new AtomicInteger(); final AtomicInteger unsubscriptionCount = new AtomicInteger(); - NbpObservable o = NbpObservable.create(new NbpOnSubscribe() { + Observable o = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { subscriptionCount.incrementAndGet(); NbpObserver.onSubscribe(new Disposable() { @Override @@ -330,7 +332,7 @@ public void dispose() { }); } }); - NbpObservable refCounted = o.publish().refCount(); + Observable refCounted = o.publish().refCount(); Disposable first = refCounted.subscribe(); assertEquals(1, subscriptionCount.get()); @@ -348,7 +350,7 @@ public void dispose() { @Test public void testRefCount() { TestScheduler s = new TestScheduler(); - NbpObservable interval = NbpObservable.interval(100, TimeUnit.MILLISECONDS, s).publish().refCount(); + Observable interval = Observable.interval(100, TimeUnit.MILLISECONDS, s).publish().refCount(); // subscribe list1 final List list1 = new ArrayList(); @@ -429,11 +431,11 @@ public void accept(Long t1) { @Test public void testAlreadyUnsubscribedClient() { - NbpSubscriber done = NbpCancelledSubscriber.instance(); + Observer done = NbpCancelledSubscriber.instance(); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpObservable result = NbpObservable.just(1).publish().refCount(); + Observable result = Observable.just(1).publish().refCount(); result.subscribe(done); @@ -446,14 +448,14 @@ public void testAlreadyUnsubscribedClient() { @Test public void testAlreadyUnsubscribedInterleavesWithClient() { - NbpReplaySubject source = NbpReplaySubject.create(); + ReplaySubject source = ReplaySubject.create(); - NbpSubscriber done = NbpCancelledSubscriber.instance(); + Observer done = NbpCancelledSubscriber.instance(); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); - NbpObservable result = source.publish().refCount(); + Observable result = source.publish().refCount(); result.subscribe(o); @@ -472,9 +474,9 @@ public void testAlreadyUnsubscribedInterleavesWithClient() { @Test public void testConnectDisconnectConnectAndSubjectState() { - NbpObservable o1 = NbpObservable.just(10); - NbpObservable o2 = NbpObservable.just(20); - NbpObservable combined = NbpObservable.combineLatest(o1, o2, new BiFunction() { + Observable o1 = Observable.just(10); + Observable o2 = Observable.just(20); + Observable combined = Observable.combineLatest(o1, o2, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2; @@ -482,8 +484,8 @@ public Integer apply(Integer t1, Integer t2) { }) .publish().refCount(); - NbpTestSubscriber ts1 = new NbpTestSubscriber(); - NbpTestSubscriber ts2 = new NbpTestSubscriber(); + TestObserver ts1 = new TestObserver(); + TestObserver ts2 = new TestObserver(); combined.subscribe(ts1); combined.subscribe(ts2); @@ -500,8 +502,8 @@ public Integer apply(Integer t1, Integer t2) { @Test(timeout = 10000) public void testUpstreamErrorAllowsRetry() throws InterruptedException { final AtomicInteger intervalSubscribed = new AtomicInteger(); - NbpObservable interval = - NbpObservable.interval(200,TimeUnit.MILLISECONDS) + Observable interval = + Observable.interval(200,TimeUnit.MILLISECONDS) .doOnSubscribe(new Consumer() { @Override public void accept(Disposable s) { @@ -509,21 +511,21 @@ public void accept(Disposable s) { } } ) - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public NbpObservable apply(Long t1) { - return NbpObservable.defer(new Supplier>() { + public Observable apply(Long t1) { + return Observable.defer(new Supplier>() { @Override - public NbpObservable get() { - return NbpObservable.error(new Exception("Some exception")); + public Observable get() { + return Observable.error(new Exception("Some exception")); } }); } }) - .onErrorResumeNext(new Function>() { + .onErrorResumeNext(new Function>() { @Override - public NbpObservable apply(Throwable t1) { - return NbpObservable.error(t1); + public Observable apply(Throwable t1) { + return Observable.error(t1); } }) .publish() diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeTimerTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeTimerTest.java similarity index 79% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeTimerTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeTimerTest.java index 3dd4b1761f..f555d47a89 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeTimerTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeTimerTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -22,17 +22,17 @@ import org.mockito.*; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; -import io.reactivex.observables.nbp.NbpConnectableObservable; +import io.reactivex.flowable.TestHelper; +import io.reactivex.observables.ConnectableObservable; +import io.reactivex.observers.*; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOnSubscribeTimerTest { @Mock - NbpSubscriber NbpObserver; + Observer NbpObserver; @Mock - NbpSubscriber observer2; + Observer observer2; TestScheduler scheduler; @@ -47,7 +47,7 @@ public void before() { @Test public void testTimerOnce() { - NbpObservable.timer(100, TimeUnit.MILLISECONDS, scheduler).subscribe(NbpObserver); + Observable.timer(100, TimeUnit.MILLISECONDS, scheduler).subscribe(NbpObserver); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); verify(NbpObserver, times(1)).onNext(0L); @@ -57,9 +57,9 @@ public void testTimerOnce() { @Test public void testTimerPeriodically() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - NbpObservable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler).subscribe(ts); + Observable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler).subscribe(ts); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); @@ -83,8 +83,8 @@ public void testTimerPeriodically() { } @Test public void testInterval() { - NbpObservable w = NbpObservable.interval(1, TimeUnit.SECONDS, scheduler); - NbpTestSubscriber ts = new NbpTestSubscriber(); + Observable w = Observable.interval(1, TimeUnit.SECONDS, scheduler); + TestObserver ts = new TestObserver(); w.subscribe(ts); ts.assertNoValues(); @@ -107,10 +107,10 @@ public void testInterval() { @Test public void testWithMultipleSubscribersStartingAtSameTime() { - NbpObservable w = NbpObservable.interval(1, TimeUnit.SECONDS, scheduler); + Observable w = Observable.interval(1, TimeUnit.SECONDS, scheduler); - NbpTestSubscriber ts1 = new NbpTestSubscriber(); - NbpTestSubscriber ts2 = new NbpTestSubscriber(); + TestObserver ts1 = new TestObserver(); + TestObserver ts2 = new TestObserver(); w.subscribe(ts1); w.subscribe(ts2); @@ -144,9 +144,9 @@ public void testWithMultipleSubscribersStartingAtSameTime() { @Test public void testWithMultipleStaggeredSubscribers() { - NbpObservable w = NbpObservable.interval(1, TimeUnit.SECONDS, scheduler); + Observable w = Observable.interval(1, TimeUnit.SECONDS, scheduler); - NbpTestSubscriber ts1 = new NbpTestSubscriber(); + TestObserver ts1 = new TestObserver(); w.subscribe(ts1); @@ -154,7 +154,7 @@ public void testWithMultipleStaggeredSubscribers() { scheduler.advanceTimeTo(2, TimeUnit.SECONDS); - NbpTestSubscriber ts2 = new NbpTestSubscriber(); + TestObserver ts2 = new TestObserver(); w.subscribe(ts2); @@ -184,9 +184,9 @@ public void testWithMultipleStaggeredSubscribers() { @Test public void testWithMultipleStaggeredSubscribersAndPublish() { - NbpConnectableObservable w = NbpObservable.interval(1, TimeUnit.SECONDS, scheduler).publish(); + ConnectableObservable w = Observable.interval(1, TimeUnit.SECONDS, scheduler).publish(); - NbpTestSubscriber ts1 = new NbpTestSubscriber(); + TestObserver ts1 = new TestObserver(); w.subscribe(ts1); w.connect(); @@ -195,7 +195,7 @@ public void testWithMultipleStaggeredSubscribersAndPublish() { scheduler.advanceTimeTo(2, TimeUnit.SECONDS); - NbpTestSubscriber ts2 = new NbpTestSubscriber(); + TestObserver ts2 = new TestObserver(); w.subscribe(ts2); ts1.assertValues(0L, 1L); @@ -223,9 +223,9 @@ public void testWithMultipleStaggeredSubscribersAndPublish() { } @Test public void testOnceObserverThrows() { - NbpObservable source = NbpObservable.timer(100, TimeUnit.MILLISECONDS, scheduler); + Observable source = Observable.timer(100, TimeUnit.MILLISECONDS, scheduler); - source.safeSubscribe(new NbpObserver() { + source.safeSubscribe(new DefaultObserver() { @Override public void onNext(Long t) { @@ -251,11 +251,11 @@ public void onComplete() { } @Test public void testPeriodicObserverThrows() { - NbpObservable source = NbpObservable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler); + Observable source = Observable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler); InOrder inOrder = inOrder(NbpObserver); - source.safeSubscribe(new NbpObserver() { + source.safeSubscribe(new DefaultObserver() { @Override public void onNext(Long t) { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeToObservableFutureTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeToObservableFutureTest.java similarity index 79% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeToObservableFutureTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeToObservableFutureTest.java index c67b253b48..30c4f39196 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeToObservableFutureTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeToObservableFutureTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,9 +22,9 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOnSubscribeToObservableFutureTest { @@ -35,11 +35,11 @@ public void testSuccess() throws Exception { Object value = new Object(); when(future.get()).thenReturn(value); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(o); + TestObserver ts = new TestObserver(o); - NbpObservable.fromFuture(future).subscribe(ts); + Observable.fromFuture(future).subscribe(ts); ts.dispose(); @@ -56,11 +56,11 @@ public void testFailure() throws Exception { RuntimeException e = new RuntimeException(); when(future.get()).thenThrow(e); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(o); + TestObserver ts = new TestObserver(o); - NbpObservable.fromFuture(future).subscribe(ts); + Observable.fromFuture(future).subscribe(ts); ts.dispose(); @@ -77,12 +77,12 @@ public void testCancelledBeforeSubscribe() throws Exception { CancellationException e = new CancellationException("unit test synthetic cancellation"); when(future.get()).thenThrow(e); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(o); + TestObserver ts = new TestObserver(o); ts.dispose(); - NbpObservable.fromFuture(future).subscribe(ts); + Observable.fromFuture(future).subscribe(ts); ts.assertNoErrors(); ts.assertNotComplete(); @@ -123,10 +123,10 @@ public Object get(long timeout, TimeUnit unit) throws InterruptedException, Exec } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(o); - NbpObservable futureObservable = NbpObservable.fromFuture(future); + TestObserver ts = new TestObserver(o); + Observable futureObservable = Observable.fromFuture(future); futureObservable.subscribeOn(Schedulers.computation()).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeUsingTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeUsingTest.java similarity index 74% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeUsingTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeUsingTest.java index a223107dac..b13ed4af13 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOnSubscribeUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOnSubscribeUsingTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -21,10 +21,12 @@ import org.junit.*; import org.mockito.InOrder; -import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; public class NbpOnSubscribeUsingTest { @@ -74,16 +76,16 @@ public Resource get() { } }; - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public NbpObservable apply(Resource res) { - return NbpObservable.fromArray(res.getTextFromWeb().split(" ")); + public Observable apply(Resource res) { + return Observable.fromArray(res.getTextFromWeb().split(" ")); } }; - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable o = NbpObservable.using(resourceFactory, observableFactory, + Observable o = Observable.using(resourceFactory, observableFactory, new DisposeAction(), disposeEagerly); o.subscribe(NbpObserver); @@ -134,16 +136,16 @@ public void dispose() { } }; - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public NbpObservable apply(Resource res) { - return NbpObservable.fromArray(res.getTextFromWeb().split(" ")); + public Observable apply(Resource res) { + return Observable.fromArray(res.getTextFromWeb().split(" ")); } }; - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable o = NbpObservable.using(resourceFactory, observableFactory, + Observable o = Observable.using(resourceFactory, observableFactory, new DisposeAction(), disposeEagerly); o.subscribe(NbpObserver); o.subscribe(NbpObserver); @@ -178,14 +180,14 @@ public Disposable get() { } }; - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public NbpObservable apply(Disposable s) { - return NbpObservable.empty(); + public Observable apply(Disposable s) { + return Observable.empty(); } }; - NbpObservable.using(resourceFactory, observableFactory, disposeSubscription) + Observable.using(resourceFactory, observableFactory, disposeSubscription) .toBlocking() .last(); } @@ -209,15 +211,15 @@ public Disposable get() { } }; - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public NbpObservable apply(Disposable subscription) { + public Observable apply(Disposable subscription) { throw new TestException(); } }; try { - NbpObservable.using(resourceFactory, observableFactory, disposeSubscription).toBlocking() + Observable.using(resourceFactory, observableFactory, disposeSubscription).toBlocking() .last(); fail("Should throw a TestException when the observableFactory throws it"); } catch (TestException e) { @@ -248,12 +250,12 @@ public Disposable get() { } }; - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public NbpObservable apply(Disposable subscription) { - return NbpObservable.create(new NbpOnSubscribe() { + public Observable apply(Disposable subscription) { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber t1) { + public void accept(Observer t1) { throw new TestException(); } }); @@ -261,7 +263,7 @@ public void accept(NbpSubscriber t1) { }; try { - NbpObservable + Observable .using(resourceFactory, observableFactory, disposeSubscription, disposeEagerly) .toBlocking().last(); @@ -280,16 +282,16 @@ public void testUsingDisposesEagerlyBeforeCompletion() { final Runnable completion = createOnCompletedAction(events); final Runnable unsub =createUnsubAction(events); - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public NbpObservable apply(Resource resource) { - return NbpObservable.fromArray(resource.getTextFromWeb().split(" ")); + public Observable apply(Resource resource) { + return Observable.fromArray(resource.getTextFromWeb().split(" ")); } }; - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable o = NbpObservable.using(resourceFactory, observableFactory, + Observable o = Observable.using(resourceFactory, observableFactory, new DisposeAction(), true) .doOnCancel(unsub) .doOnComplete(completion); @@ -307,16 +309,16 @@ public void testUsingDoesNotDisposesEagerlyBeforeCompletion() { final Runnable completion = createOnCompletedAction(events); final Runnable unsub = createUnsubAction(events); - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public NbpObservable apply(Resource resource) { - return NbpObservable.fromArray(resource.getTextFromWeb().split(" ")); + public Observable apply(Resource resource) { + return Observable.fromArray(resource.getTextFromWeb().split(" ")); } }; - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable o = NbpObservable.using(resourceFactory, observableFactory, + Observable o = Observable.using(resourceFactory, observableFactory, new DisposeAction(), false) .doOnCancel(unsub) .doOnComplete(completion); @@ -336,17 +338,17 @@ public void testUsingDisposesEagerlyBeforeError() { final Consumer onError = createOnErrorAction(events); final Runnable unsub = createUnsubAction(events); - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public NbpObservable apply(Resource resource) { - return NbpObservable.fromArray(resource.getTextFromWeb().split(" ")) - .concatWith(NbpObservable.error(new RuntimeException())); + public Observable apply(Resource resource) { + return Observable.fromArray(resource.getTextFromWeb().split(" ")) + .concatWith(Observable.error(new RuntimeException())); } }; - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable o = NbpObservable.using(resourceFactory, observableFactory, + Observable o = Observable.using(resourceFactory, observableFactory, new DisposeAction(), true) .doOnCancel(unsub) .doOnError(onError); @@ -364,17 +366,17 @@ public void testUsingDoesNotDisposesEagerlyBeforeError() { final Consumer onError = createOnErrorAction(events); final Runnable unsub = createUnsubAction(events); - Function> observableFactory = new Function>() { + Function> observableFactory = new Function>() { @Override - public NbpObservable apply(Resource resource) { - return NbpObservable.fromArray(resource.getTextFromWeb().split(" ")) - .concatWith(NbpObservable.error(new RuntimeException())); + public Observable apply(Resource resource) { + return Observable.fromArray(resource.getTextFromWeb().split(" ")) + .concatWith(Observable.error(new RuntimeException())); } }; - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable o = NbpObservable.using(resourceFactory, observableFactory, + Observable o = Observable.using(resourceFactory, observableFactory, new DisposeAction(), false) .doOnCancel(unsub) .doOnError(onError); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorAllTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorAllTest.java similarity index 75% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorAllTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorAllTest.java index 2a391cbf57..556e1f3692 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorAllTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorAllTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -22,18 +22,18 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.disposables.Disposable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.TestObserver; public class NbpOperatorAllTest { @Test public void testAll() { - NbpObservable obs = NbpObservable.just("one", "two", "six"); + Observable obs = Observable.just("one", "two", "six"); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); obs.all(new Predicate() { @Override @@ -51,9 +51,9 @@ public boolean test(String s) { @Test public void testNotAll() { - NbpObservable obs = NbpObservable.just("one", "two", "three", "six"); + Observable obs = Observable.just("one", "two", "three", "six"); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); obs.all(new Predicate() { @Override @@ -71,9 +71,9 @@ public boolean test(String s) { @Test public void testEmpty() { - NbpObservable obs = NbpObservable.empty(); + Observable obs = Observable.empty(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); obs.all(new Predicate() { @Override @@ -92,9 +92,9 @@ public boolean test(String s) { @Test public void testError() { Throwable error = new Throwable(); - NbpObservable obs = NbpObservable.error(error); + Observable obs = Observable.error(error); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); obs.all(new Predicate() { @Override @@ -111,8 +111,8 @@ public boolean test(String s) { @Test public void testFollowingFirst() { - NbpObservable o = NbpObservable.fromArray(1, 3, 5, 6); - NbpObservable allOdd = o.all(new Predicate() { + Observable o = Observable.fromArray(1, 3, 5, 6); + Observable allOdd = o.all(new Predicate() { @Override public boolean test(Integer i) { return i % 2 == 1; @@ -123,17 +123,17 @@ public boolean test(Integer i) { } @Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstream() { - NbpObservable source = NbpObservable.just(1) + Observable source = Observable.just(1) .all(new Predicate() { @Override public boolean test(Integer t1) { return false; } }) - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public NbpObservable apply(Boolean t1) { - return NbpObservable.just(2).delay(500, TimeUnit.MILLISECONDS); + public Observable apply(Boolean t1) { + return Observable.just(2).delay(500, TimeUnit.MILLISECONDS); } }); @@ -143,11 +143,11 @@ public NbpObservable apply(Boolean t1) { @Test public void testPredicateThrowsExceptionAndValueInCauseMessage() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final IllegalArgumentException ex = new IllegalArgumentException(); - NbpObservable.just("Boo!").all(new Predicate() { + Observable.just("Boo!").all(new Predicate() { @Override public boolean test(String v) { throw ex; diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorAnyTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorAnyTest.java similarity index 69% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorAnyTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorAnyTest.java index 0fe1aca1e3..2f49274c0b 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorAnyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorAnyTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -21,23 +21,23 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.TestObserver; public class NbpOperatorAnyTest { @Test public void testAnyWithTwoItems() { - NbpObservable w = NbpObservable.just(1, 2); - NbpObservable NbpObservable = w.any(new Predicate() { + Observable w = Observable.just(1, 2); + Observable NbpObservable = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -49,10 +49,10 @@ public boolean test(Integer v) { @Test public void testIsEmptyWithTwoItems() { - NbpObservable w = NbpObservable.just(1, 2); - NbpObservable NbpObservable = w.isEmpty(); + Observable w = Observable.just(1, 2); + Observable NbpObservable = w.isEmpty(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -64,15 +64,15 @@ public void testIsEmptyWithTwoItems() { @Test public void testAnyWithOneItem() { - NbpObservable w = NbpObservable.just(1); - NbpObservable NbpObservable = w.any(new Predicate() { + Observable w = Observable.just(1); + Observable NbpObservable = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -84,10 +84,10 @@ public boolean test(Integer v) { @Test public void testIsEmptyWithOneItem() { - NbpObservable w = NbpObservable.just(1); - NbpObservable NbpObservable = w.isEmpty(); + Observable w = Observable.just(1); + Observable NbpObservable = w.isEmpty(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -99,15 +99,15 @@ public void testIsEmptyWithOneItem() { @Test public void testAnyWithEmpty() { - NbpObservable w = NbpObservable.empty(); - NbpObservable NbpObservable = w.any(new Predicate() { + Observable w = Observable.empty(); + Observable NbpObservable = w.any(new Predicate() { @Override public boolean test(Integer v) { return true; } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -119,10 +119,10 @@ public boolean test(Integer v) { @Test public void testIsEmptyWithEmpty() { - NbpObservable w = NbpObservable.empty(); - NbpObservable NbpObservable = w.isEmpty(); + Observable w = Observable.empty(); + Observable NbpObservable = w.isEmpty(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -134,15 +134,15 @@ public void testIsEmptyWithEmpty() { @Test public void testAnyWithPredicate1() { - NbpObservable w = NbpObservable.just(1, 2, 3); - NbpObservable NbpObservable = w.any(new Predicate() { + Observable w = Observable.just(1, 2, 3); + Observable NbpObservable = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 2; } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -154,15 +154,15 @@ public boolean test(Integer t1) { @Test public void testExists1() { - NbpObservable w = NbpObservable.just(1, 2, 3); - NbpObservable NbpObservable = w.any(new Predicate() { + Observable w = Observable.just(1, 2, 3); + Observable NbpObservable = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 2; } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -174,15 +174,15 @@ public boolean test(Integer t1) { @Test public void testAnyWithPredicate2() { - NbpObservable w = NbpObservable.just(1, 2, 3); - NbpObservable NbpObservable = w.any(new Predicate() { + Observable w = Observable.just(1, 2, 3); + Observable NbpObservable = w.any(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 1; } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -195,15 +195,15 @@ public boolean test(Integer t1) { @Test public void testAnyWithEmptyAndPredicate() { // If the source is empty, always output false. - NbpObservable w = NbpObservable.empty(); - NbpObservable NbpObservable = w.any(new Predicate() { + Observable w = Observable.empty(); + Observable NbpObservable = w.any(new Predicate() { @Override public boolean test(Integer t) { return true; } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -215,8 +215,8 @@ public boolean test(Integer t) { @Test public void testWithFollowingFirst() { - NbpObservable o = NbpObservable.fromArray(1, 3, 5, 6); - NbpObservable anyEven = o.any(new Predicate() { + Observable o = Observable.fromArray(1, 3, 5, 6); + Observable anyEven = o.any(new Predicate() { @Override public boolean test(Integer i) { return i % 2 == 0; @@ -227,11 +227,11 @@ public boolean test(Integer i) { } @Test(timeout = 5000) public void testIssue1935NoUnsubscribeDownstream() { - NbpObservable source = NbpObservable.just(1).isEmpty() - .flatMap(new Function>() { + Observable source = Observable.just(1).isEmpty() + .flatMap(new Function>() { @Override - public NbpObservable apply(Boolean t1) { - return NbpObservable.just(2).delay(500, TimeUnit.MILLISECONDS); + public Observable apply(Boolean t1) { + return Observable.just(2).delay(500, TimeUnit.MILLISECONDS); } }); @@ -240,10 +240,10 @@ public NbpObservable apply(Boolean t1) { @Test public void testPredicateThrowsExceptionAndValueInCauseMessage() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final IllegalArgumentException ex = new IllegalArgumentException(); - NbpObservable.just("Boo!").any(new Predicate() { + Observable.just("Boo!").any(new Predicate() { @Override public boolean test(String v) { throw ex; diff --git a/src/test/java/io/reactivex/internal/operators/OperatorAsObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorAsObservableTest.java similarity index 86% rename from src/test/java/io/reactivex/internal/operators/OperatorAsObservableTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorAsObservableTest.java index bbc6962f3d..b9baa9c1fd 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorAsObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorAsObservableTest.java @@ -11,20 +11,20 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertFalse; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; import org.junit.Test; -import org.reactivestreams.Subscriber; import io.reactivex.*; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.subjects.PublishSubject; -public class OperatorAsObservableTest { +public class NbpOperatorAsObservableTest { @Test public void testHiding() { PublishSubject src = PublishSubject.create(); @@ -33,7 +33,7 @@ public void testHiding() { assertFalse(dst instanceof PublishSubject); - Subscriber o = TestHelper.mockSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); dst.subscribe(o); @@ -52,8 +52,7 @@ public void testHidingError() { assertFalse(dst instanceof PublishSubject); - @SuppressWarnings("unchecked") - Observer o = mock(Observer.class); + Observer o = TestHelper.mockNbpSubscriber(); dst.subscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorBufferTest.java similarity index 70% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorBufferTest.java index badd79c735..34e59a0c62 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorBufferTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertFalse; import static org.mockito.Matchers.any; @@ -23,18 +23,21 @@ import org.junit.*; import org.mockito.*; -import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; +import io.reactivex.Scheduler; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.*; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.*; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorBufferTest { - private NbpSubscriber> NbpObserver; + private Observer> NbpObserver; private TestScheduler scheduler; private Scheduler.Worker innerScheduler; @@ -47,9 +50,9 @@ public void before() { @Test public void testComplete() { - NbpObservable source = NbpObservable.empty(); + Observable source = Observable.empty(); - NbpObservable> buffered = source.buffer(3, 3); + Observable> buffered = source.buffer(3, 3); buffered.subscribe(NbpObserver); Mockito.verify(NbpObserver, Mockito.never()).onNext(Mockito.anyListOf(String.class)); @@ -59,9 +62,9 @@ public void testComplete() { @Test public void testSkipAndCountOverlappingBuffers() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); NbpObserver.onNext("one"); NbpObserver.onNext("two"); @@ -71,7 +74,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable> buffered = source.buffer(3, 1); + Observable> buffered = source.buffer(3, 1); buffered.subscribe(NbpObserver); InOrder inOrder = Mockito.inOrder(NbpObserver); @@ -85,9 +88,9 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testSkipAndCountGaplessBuffers() { - NbpObservable source = NbpObservable.just("one", "two", "three", "four", "five"); + Observable source = Observable.just("one", "two", "three", "four", "five"); - NbpObservable> buffered = source.buffer(3, 3); + Observable> buffered = source.buffer(3, 3); buffered.subscribe(NbpObserver); InOrder inOrder = Mockito.inOrder(NbpObserver); @@ -100,9 +103,9 @@ public void testSkipAndCountGaplessBuffers() { @Test public void testSkipAndCountBuffersWithGaps() { - NbpObservable source = NbpObservable.just("one", "two", "three", "four", "five"); + Observable source = Observable.just("one", "two", "three", "four", "five"); - NbpObservable> buffered = source.buffer(2, 3); + Observable> buffered = source.buffer(2, 3); buffered.subscribe(NbpObserver); InOrder inOrder = Mockito.inOrder(NbpObserver); @@ -115,9 +118,9 @@ public void testSkipAndCountBuffersWithGaps() { @Test public void testTimedAndCount() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, "one", 10); push(NbpObserver, "two", 90); @@ -128,7 +131,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable> buffered = source.buffer(100, TimeUnit.MILLISECONDS, 2, scheduler); + Observable> buffered = source.buffer(100, TimeUnit.MILLISECONDS, 2, scheduler); buffered.subscribe(NbpObserver); InOrder inOrder = Mockito.inOrder(NbpObserver); @@ -147,9 +150,9 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testTimed() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, "one", 97); push(NbpObserver, "two", 98); @@ -165,7 +168,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable> buffered = source.buffer(100, TimeUnit.MILLISECONDS, scheduler); + Observable> buffered = source.buffer(100, TimeUnit.MILLISECONDS, scheduler); buffered.subscribe(NbpObserver); InOrder inOrder = Mockito.inOrder(NbpObserver); @@ -181,9 +184,9 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testObservableBasedOpenerAndCloser() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, "one", 10); push(NbpObserver, "two", 60); @@ -194,9 +197,9 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable openings = NbpObservable.create(new NbpOnSubscribe() { + Observable openings = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, new Object(), 50); push(NbpObserver, new Object(), 200); @@ -204,12 +207,12 @@ public void accept(NbpSubscriber NbpObserver) { } }); - Function> closer = new Function>() { + Function> closer = new Function>() { @Override - public NbpObservable apply(Object opening) { - return NbpObservable.create(new NbpOnSubscribe() { + public Observable apply(Object opening) { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, new Object(), 100); complete(NbpObserver, 101); @@ -218,7 +221,7 @@ public void accept(NbpSubscriber NbpObserver) { } }; - NbpObservable> buffered = source.buffer(openings, closer); + Observable> buffered = source.buffer(openings, closer); buffered.subscribe(NbpObserver); InOrder inOrder = Mockito.inOrder(NbpObserver); @@ -232,9 +235,9 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testObservableBasedCloser() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, "one", 10); push(NbpObserver, "two", 60); @@ -245,12 +248,12 @@ public void accept(NbpSubscriber NbpObserver) { } }); - Supplier> closer = new Supplier>() { + Supplier> closer = new Supplier>() { @Override - public NbpObservable get() { - return NbpObservable.create(new NbpOnSubscribe() { + public Observable get() { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, new Object(), 100); push(NbpObserver, new Object(), 200); @@ -261,7 +264,7 @@ public void accept(NbpSubscriber NbpObserver) { } }; - NbpObservable> buffered = source.buffer(closer); + Observable> buffered = source.buffer(closer); buffered.subscribe(NbpObserver); InOrder inOrder = Mockito.inOrder(NbpObserver); @@ -278,7 +281,7 @@ public void accept(NbpSubscriber NbpObserver) { public void testLongTimeAction() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); LongTimeAction action = new LongTimeAction(latch); - NbpObservable.just(1).buffer(10, TimeUnit.MILLISECONDS, 10) + Observable.just(1).buffer(10, TimeUnit.MILLISECONDS, 10) .subscribe(action); latch.await(); assertFalse(action.fail); @@ -316,7 +319,7 @@ private List list(String... args) { return list; } - private void push(final NbpSubscriber NbpObserver, final T value, int delay) { + private void push(final Observer NbpObserver, final T value, int delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -325,7 +328,7 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private void complete(final NbpSubscriber NbpObserver, int delay) { + private void complete(final Observer NbpObserver, int delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -336,10 +339,10 @@ public void run() { @Test public void testBufferStopsWhenUnsubscribed1() { - NbpObservable source = NbpObservable.never(); + Observable source = Observable.never(); - NbpSubscriber> o = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber> ts = new NbpTestSubscriber>(o); + Observer> o = TestHelper.mockNbpSubscriber(); + TestObserver> ts = new TestObserver>(o); source.buffer(100, 200, TimeUnit.MILLISECONDS, scheduler) .doOnNext(new Consumer>() { @@ -365,10 +368,10 @@ public void accept(List pv) { @Test public void bufferWithBONormal1() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject boundary = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject boundary = PublishSubject.create(); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = Mockito.inOrder(o); source.buffer(boundary).subscribe(o); @@ -400,10 +403,10 @@ public void bufferWithBONormal1() { @Test public void bufferWithBOEmptyLastViaBoundary() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject boundary = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject boundary = PublishSubject.create(); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = Mockito.inOrder(o); source.buffer(boundary).subscribe(o); @@ -419,10 +422,10 @@ public void bufferWithBOEmptyLastViaBoundary() { @Test public void bufferWithBOEmptyLastViaSource() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject boundary = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject boundary = PublishSubject.create(); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = Mockito.inOrder(o); source.buffer(boundary).subscribe(o); @@ -438,10 +441,10 @@ public void bufferWithBOEmptyLastViaSource() { @Test public void bufferWithBOEmptyLastViaBoth() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject boundary = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject boundary = PublishSubject.create(); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = Mockito.inOrder(o); source.buffer(boundary).subscribe(o); @@ -458,10 +461,10 @@ public void bufferWithBOEmptyLastViaBoth() { @Test public void bufferWithBOSourceThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject boundary = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject boundary = PublishSubject.create(); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.buffer(boundary).subscribe(o); source.onNext(1); @@ -474,10 +477,10 @@ public void bufferWithBOSourceThrows() { @Test public void bufferWithBOBoundaryThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject boundary = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject boundary = PublishSubject.create(); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.buffer(boundary).subscribe(o); @@ -490,11 +493,11 @@ public void bufferWithBOBoundaryThrows() { } @Test(timeout = 2000) public void bufferWithSizeTake1() { - NbpObservable source = NbpObservable.just(1).repeat(); + Observable source = Observable.just(1).repeat(); - NbpObservable> result = source.buffer(2).take(1); + Observable> result = source.buffer(2).take(1); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -505,11 +508,11 @@ public void bufferWithSizeTake1() { @Test(timeout = 2000) public void bufferWithSizeSkipTake1() { - NbpObservable source = NbpObservable.just(1).repeat(); + Observable source = Observable.just(1).repeat(); - NbpObservable> result = source.buffer(2, 3).take(1); + Observable> result = source.buffer(2, 3).take(1); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -519,11 +522,11 @@ public void bufferWithSizeSkipTake1() { } @Test(timeout = 2000) public void bufferWithTimeTake1() { - NbpObservable source = NbpObservable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); + Observable source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); - NbpObservable> result = source.buffer(100, TimeUnit.MILLISECONDS, scheduler).take(1); + Observable> result = source.buffer(100, TimeUnit.MILLISECONDS, scheduler).take(1); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -535,11 +538,11 @@ public void bufferWithTimeTake1() { } @Test(timeout = 2000) public void bufferWithTimeSkipTake2() { - NbpObservable source = NbpObservable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); + Observable source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); - NbpObservable> result = source.buffer(100, 60, TimeUnit.MILLISECONDS, scheduler).take(2); + Observable> result = source.buffer(100, 60, TimeUnit.MILLISECONDS, scheduler).take(2); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); result.subscribe(o); @@ -553,12 +556,12 @@ public void bufferWithTimeSkipTake2() { } @Test(timeout = 2000) public void bufferWithBoundaryTake2() { - NbpObservable boundary = NbpObservable.interval(60, 60, TimeUnit.MILLISECONDS, scheduler); - NbpObservable source = NbpObservable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); + Observable boundary = Observable.interval(60, 60, TimeUnit.MILLISECONDS, scheduler); + Observable source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); - NbpObservable> result = source.buffer(boundary).take(2); + Observable> result = source.buffer(boundary).take(2); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); result.subscribe(o); @@ -574,19 +577,19 @@ public void bufferWithBoundaryTake2() { @Test(timeout = 2000) public void bufferWithStartEndBoundaryTake2() { - NbpObservable start = NbpObservable.interval(61, 61, TimeUnit.MILLISECONDS, scheduler); - Function> end = new Function>() { + Observable start = Observable.interval(61, 61, TimeUnit.MILLISECONDS, scheduler); + Function> end = new Function>() { @Override - public NbpObservable apply(Long t1) { - return NbpObservable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler); + public Observable apply(Long t1) { + return Observable.interval(100, 100, TimeUnit.MILLISECONDS, scheduler); } }; - NbpObservable source = NbpObservable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); + Observable source = Observable.interval(40, 40, TimeUnit.MILLISECONDS, scheduler); - NbpObservable> result = source.buffer(start, end).take(2); + Observable> result = source.buffer(start, end).take(2); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); result @@ -607,11 +610,11 @@ public void accept(List pv) { } @Test public void bufferWithSizeThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable> result = source.buffer(2); + Observable> result = source.buffer(2); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); @@ -632,11 +635,11 @@ public void bufferWithSizeThrows() { @Test public void bufferWithTimeThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable> result = source.buffer(100, TimeUnit.MILLISECONDS, scheduler); + Observable> result = source.buffer(100, TimeUnit.MILLISECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); result.subscribe(o); @@ -658,11 +661,11 @@ public void bufferWithTimeThrows() { @Test public void bufferWithTimeAndSize() { - NbpObservable source = NbpObservable.interval(30, 30, TimeUnit.MILLISECONDS, scheduler); + Observable source = Observable.interval(30, 30, TimeUnit.MILLISECONDS, scheduler); - NbpObservable> result = source.buffer(100, TimeUnit.MILLISECONDS, 2, scheduler).take(3); + Observable> result = source.buffer(100, TimeUnit.MILLISECONDS, 2, scheduler).take(3); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); result.subscribe(o); @@ -676,20 +679,20 @@ public void bufferWithTimeAndSize() { } @Test public void bufferWithStartEndStartThrows() { - NbpPublishSubject start = NbpPublishSubject.create(); + PublishSubject start = PublishSubject.create(); - Function> end = new Function>() { + Function> end = new Function>() { @Override - public NbpObservable apply(Integer t1) { - return NbpObservable.never(); + public Observable apply(Integer t1) { + return Observable.never(); } }; - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable> result = source.buffer(start, end); + Observable> result = source.buffer(start, end); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -704,20 +707,20 @@ public NbpObservable apply(Integer t1) { } @Test public void bufferWithStartEndEndFunctionThrows() { - NbpPublishSubject start = NbpPublishSubject.create(); + PublishSubject start = PublishSubject.create(); - Function> end = new Function>() { + Function> end = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { throw new TestException(); } }; - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable> result = source.buffer(start, end); + Observable> result = source.buffer(start, end); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -731,20 +734,20 @@ public NbpObservable apply(Integer t1) { } @Test public void bufferWithStartEndEndThrows() { - NbpPublishSubject start = NbpPublishSubject.create(); + PublishSubject start = PublishSubject.create(); - Function> end = new Function>() { + Function> end = new Function>() { @Override - public NbpObservable apply(Integer t1) { - return NbpObservable.error(new TestException()); + public Observable apply(Integer t1) { + return Observable.error(new TestException()); } }; - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable> result = source.buffer(start, end); + Observable> result = source.buffer(start, end); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -759,10 +762,10 @@ public NbpObservable apply(Integer t1) { @Test(timeout = 3000) public void testBufferWithTimeDoesntUnsubscribeDownstream() throws InterruptedException { - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + final Observer o = TestHelper.mockNbpSubscriber(); final CountDownLatch cdl = new CountDownLatch(1); - NbpAsyncObserver s = new NbpAsyncObserver() { + AsyncObserver s = new AsyncObserver() { @Override public void onNext(Object t) { o.onNext(t); @@ -779,7 +782,7 @@ public void onComplete() { } }; - NbpObservable.range(1, 1).delay(1, TimeUnit.SECONDS).buffer(2, TimeUnit.SECONDS).unsafeSubscribe(s); + Observable.range(1, 1).delay(1, TimeUnit.SECONDS).buffer(2, TimeUnit.SECONDS).unsafeSubscribe(s); cdl.await(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorCastTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorCastTest.java similarity index 71% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorCastTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorCastTest.java index 708b4f76bc..eb28360ea8 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorCastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorCastTest.java @@ -11,23 +11,23 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Mockito.*; import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; public class NbpOperatorCastTest { @Test public void testCast() { - NbpObservable source = NbpObservable.just(1, 2); - NbpObservable NbpObservable = source.cast(Integer.class); + Observable source = Observable.just(1, 2); + Observable NbpObservable = source.cast(Integer.class); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -40,10 +40,10 @@ public void testCast() { @Test public void testCastWithWrongType() { - NbpObservable source = NbpObservable.just(1, 2); - NbpObservable NbpObservable = source.cast(Boolean.class); + Observable source = Observable.just(1, 2); + Observable NbpObservable = source.cast(Boolean.class); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorConcatTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorConcatTest.java similarity index 77% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorConcatTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorConcatTest.java index 8581fe9dd2..f3a8ec0c37 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorConcatTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,27 +25,30 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.disposables.*; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.*; import io.reactivex.schedulers.*; -import io.reactivex.subjects.nbp.*; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subjects.*; public class NbpOperatorConcatTest { @Test public void testConcat() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); final String[] o = { "1", "3", "5", "7" }; final String[] e = { "2", "4", "6" }; - final NbpObservable odds = NbpObservable.fromArray(o); - final NbpObservable even = NbpObservable.fromArray(e); + final Observable odds = Observable.fromArray(o); + final Observable even = Observable.fromArray(e); - NbpObservable concat = NbpObservable.concat(odds, even); + Observable concat = Observable.concat(odds, even); concat.subscribe(NbpObserver); verify(NbpObserver, times(7)).onNext(anyString()); @@ -53,17 +56,17 @@ public void testConcat() { @Test public void testConcatWithList() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); final String[] o = { "1", "3", "5", "7" }; final String[] e = { "2", "4", "6" }; - final NbpObservable odds = NbpObservable.fromArray(o); - final NbpObservable even = NbpObservable.fromArray(e); - final List> list = new ArrayList>(); + final Observable odds = Observable.fromArray(o); + final Observable even = Observable.fromArray(e); + final List> list = new ArrayList>(); list.add(odds); list.add(even); - NbpObservable concat = NbpObservable.concat(NbpObservable.fromIterable(list)); + Observable concat = Observable.concat(Observable.fromIterable(list)); concat.subscribe(NbpObserver); verify(NbpObserver, times(7)).onNext(anyString()); @@ -71,18 +74,18 @@ public void testConcatWithList() { @Test public void testConcatObservableOfObservables() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); final String[] o = { "1", "3", "5", "7" }; final String[] e = { "2", "4", "6" }; - final NbpObservable odds = NbpObservable.fromArray(o); - final NbpObservable even = NbpObservable.fromArray(e); + final Observable odds = Observable.fromArray(o); + final Observable even = Observable.fromArray(e); - NbpObservable> observableOfObservables = NbpObservable.create(new NbpOnSubscribe>() { + Observable> observableOfObservables = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(NbpSubscriber> NbpObserver) { + public void accept(Observer> NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); // simulate what would happen in an NbpObservable NbpObserver.onNext(odds); @@ -91,7 +94,7 @@ public void accept(NbpSubscriber> NbpObserver) { } }); - NbpObservable concat = NbpObservable.concat(observableOfObservables); + Observable concat = Observable.concat(observableOfObservables); concat.subscribe(NbpObserver); @@ -103,12 +106,12 @@ public void accept(NbpSubscriber> NbpObserver) { */ @Test public void testSimpleAsyncConcat() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); TestObservable o1 = new TestObservable("one", "two", "three"); TestObservable o2 = new TestObservable("four", "five", "six"); - NbpObservable.concat(NbpObservable.create(o1), NbpObservable.create(o2)).subscribe(NbpObserver); + Observable.concat(Observable.create(o1), Observable.create(o2)).subscribe(NbpObserver); try { // wait for async observables to complete @@ -143,7 +146,7 @@ public void testNestedAsyncConcatLoop() throws Throwable { */ @Test public void testNestedAsyncConcat() throws InterruptedException { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); final TestObservable o1 = new TestObservable("one", "two", "three"); final TestObservable o2 = new TestObservable("four", "five", "six"); @@ -155,10 +158,10 @@ public void testNestedAsyncConcat() throws InterruptedException { final CountDownLatch parentHasFinished = new CountDownLatch(1); - NbpObservable> observableOfObservables = NbpObservable.create(new NbpOnSubscribe>() { + Observable> observableOfObservables = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(final NbpSubscriber> NbpObserver) { + public void accept(final Observer> NbpObserver) { final BooleanDisposable s = new BooleanDisposable(); NbpObserver.onSubscribe(s); parent.set(new Thread(new Runnable() { @@ -169,12 +172,12 @@ public void run() { // emit first if (!s.isDisposed()) { System.out.println("Emit o1"); - NbpObserver.onNext(NbpObservable.create(o1)); + NbpObserver.onNext(Observable.create(o1)); } // emit second if (!s.isDisposed()) { System.out.println("Emit o2"); - NbpObserver.onNext(NbpObservable.create(o2)); + NbpObserver.onNext(Observable.create(o2)); } // wait until sometime later and emit third @@ -185,7 +188,7 @@ public void run() { } if (!s.isDisposed()) { System.out.println("Emit o3"); - NbpObserver.onNext(NbpObservable.create(o3)); + NbpObserver.onNext(Observable.create(o3)); } } catch (Throwable e) { @@ -202,7 +205,7 @@ public void run() { } }); - NbpObservable.concat(observableOfObservables).subscribe(NbpObserver); + Observable.concat(observableOfObservables).subscribe(NbpObserver); // wait for parent to start parentHasStarted.await(); @@ -261,17 +264,17 @@ public void run() { @Test public void testBlockedObservableOfObservables() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); final String[] o = { "1", "3", "5", "7" }; final String[] e = { "2", "4", "6" }; - final NbpObservable odds = NbpObservable.fromArray(o); - final NbpObservable even = NbpObservable.fromArray(e); + final Observable odds = Observable.fromArray(o); + final Observable even = Observable.fromArray(e); final CountDownLatch callOnce = new CountDownLatch(1); final CountDownLatch okToContinue = new CountDownLatch(1); @SuppressWarnings("unchecked") - TestObservable> observableOfObservables = new TestObservable>(callOnce, okToContinue, odds, even); - NbpObservable concatF = NbpObservable.concat(NbpObservable.create(observableOfObservables)); + TestObservable> observableOfObservables = new TestObservable>(callOnce, okToContinue, odds, even); + Observable concatF = Observable.concat(Observable.create(observableOfObservables)); concatF.subscribe(NbpObserver); try { //Block main thread to allow observables to serve up o1. @@ -306,11 +309,11 @@ public void testConcatConcurrentWithInfinity() { //This NbpObservable will send "hello" MAX_VALUE time. final TestObservable w2 = new TestObservable("hello", Integer.MAX_VALUE); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); @SuppressWarnings("unchecked") - TestObservable> observableOfObservables = new TestObservable>(NbpObservable.create(w1), NbpObservable.create(w2)); - NbpObservable concatF = NbpObservable.concat(NbpObservable.create(observableOfObservables)); + TestObservable> observableOfObservables = new TestObservable>(Observable.create(w1), Observable.create(w2)); + Observable concatF = Observable.concat(Observable.create(observableOfObservables)); concatF.take(50).subscribe(NbpObserver); @@ -340,21 +343,21 @@ public void testConcatNonBlockingObservables() { final TestObservable w1 = new TestObservable(null, okToContinueW1, "one", "two", "three"); final TestObservable w2 = new TestObservable(null, okToContinueW2, "four", "five", "six"); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable> observableOfObservables = NbpObservable.create(new NbpOnSubscribe>() { + Observable> observableOfObservables = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(NbpSubscriber> NbpObserver) { + public void accept(Observer> NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); // simulate what would happen in an NbpObservable - NbpObserver.onNext(NbpObservable.create(w1)); - NbpObserver.onNext(NbpObservable.create(w2)); + NbpObserver.onNext(Observable.create(w1)); + NbpObserver.onNext(Observable.create(w2)); NbpObserver.onComplete(); } }); - NbpObservable concat = NbpObservable.concat(observableOfObservables); + Observable concat = Observable.concat(observableOfObservables); concat.subscribe(NbpObserver); verify(NbpObserver, times(0)).onComplete(); @@ -391,10 +394,10 @@ public void testConcatUnsubscribe() { final TestObservable w1 = new TestObservable("one", "two", "three"); final TestObservable w2 = new TestObservable(callOnce, okToContinue, "four", "five", "six"); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); - final NbpObservable concat = NbpObservable.concat(NbpObservable.create(w1), NbpObservable.create(w2)); + final Observable concat = Observable.concat(Observable.create(w1), Observable.create(w2)); try { // Subscribe @@ -433,12 +436,12 @@ public void testConcatUnsubscribeConcurrent() { final TestObservable w1 = new TestObservable("one", "two", "three"); final TestObservable w2 = new TestObservable(callOnce, okToContinue, "four", "five", "six"); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); @SuppressWarnings("unchecked") - TestObservable> observableOfObservables = new TestObservable>(NbpObservable.create(w1), NbpObservable.create(w2)); - NbpObservable concatF = NbpObservable.concat(NbpObservable.create(observableOfObservables)); + TestObservable> observableOfObservables = new TestObservable>(Observable.create(w1), Observable.create(w2)); + Observable concatF = Observable.concat(Observable.create(observableOfObservables)); concatF.subscribe(ts); @@ -507,7 +510,7 @@ public TestObservable(T seed, int size) { } @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(s); t = new Thread(new Runnable() { @@ -548,13 +551,13 @@ void waitForThreadDone() throws InterruptedException { @Test public void testMultipleObservers() { - NbpSubscriber o1 = TestHelper.mockNbpSubscriber(); - NbpSubscriber o2 = TestHelper.mockNbpSubscriber(); + Observer o1 = TestHelper.mockNbpSubscriber(); + Observer o2 = TestHelper.mockNbpSubscriber(); TestScheduler s = new TestScheduler(); - NbpObservable timer = NbpObservable.interval(500, TimeUnit.MILLISECONDS, s).take(2); - NbpObservable o = NbpObservable.concat(timer, timer); + Observable timer = Observable.interval(500, TimeUnit.MILLISECONDS, s).take(2); + Observable o = Observable.concat(timer, timer); o.subscribe(o1); o.subscribe(o2); @@ -592,16 +595,16 @@ public void testMultipleObservers() { @Test public void concatVeryLongObservableOfObservables() { final int n = 10000; - NbpObservable> source = NbpObservable.range(0, n).map(new Function>() { + Observable> source = Observable.range(0, n).map(new Function>() { @Override - public NbpObservable apply(Integer v) { - return NbpObservable.just(v); + public Observable apply(Integer v) { + return Observable.just(v); } }); - NbpObservable> result = NbpObservable.concat(source).toList(); + Observable> result = Observable.concat(source).toList(); - NbpSubscriber> o = TestHelper.mockNbpSubscriber(); + Observer> o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); result.subscribe(o); @@ -617,16 +620,16 @@ public NbpObservable apply(Integer v) { @Test public void concatVeryLongObservableOfObservablesTakeHalf() { final int n = 10000; - NbpObservable> source = NbpObservable.range(0, n).map(new Function>() { + Observable> source = Observable.range(0, n).map(new Function>() { @Override - public NbpObservable apply(Integer v) { - return NbpObservable.just(v); + public Observable apply(Integer v) { + return Observable.just(v); } }); - NbpObservable> result = NbpObservable.concat(source).take(n / 2).toList(); + Observable> result = Observable.concat(source).take(n / 2).toList(); - NbpSubscriber> o = TestHelper.mockNbpSubscriber(); + Observer> o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); result.subscribe(o); @@ -643,8 +646,8 @@ public NbpObservable apply(Integer v) { @Test public void testConcatOuterBackpressure() { assertEquals(1, - (int) NbpObservable. empty() - .concatWith(NbpObservable.just(1)) + (int) Observable. empty() + .concatWith(Observable.just(1)) .take(1) .toBlocking().single()); } @@ -652,10 +655,10 @@ public void testConcatOuterBackpressure() { // https://github.com/ReactiveX/RxJava/issues/1818 @Test public void testConcatWithNonCompliantSourceDoubleOnComplete() { - NbpObservable o = NbpObservable.create(new NbpOnSubscribe() { + Observable o = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { s.onSubscribe(EmptyDisposable.INSTANCE); s.onNext("hello"); s.onComplete(); @@ -664,8 +667,8 @@ public void accept(NbpSubscriber s) { }); - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.concat(o, o).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.concat(o, o).subscribe(ts); ts.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); ts.assertTerminated(); ts.assertNoErrors(); @@ -677,13 +680,13 @@ public void testIssue2890NoStackoverflow() throws InterruptedException { final ExecutorService executor = Executors.newFixedThreadPool(2); final Scheduler sch = Schedulers.from(executor); - Function> func = new Function>() { + Function> func = new Function>() { @Override - public NbpObservable apply(Integer t) { - NbpObservable o = NbpObservable.just(t) + public Observable apply(Integer t) { + Observable o = Observable.just(t) .subscribeOn(sch) ; - NbpSubject subject = NbpUnicastSubject.create(); + Subject subject = UnicastSubject.create(); o.subscribe(subject); return subject; } @@ -692,8 +695,8 @@ public NbpObservable apply(Integer t) { int n = 5000; final AtomicInteger counter = new AtomicInteger(); - NbpObservable.range(1, n) - .concatMap(func).subscribe(new NbpObserver() { + Observable.range(1, n) + .concatMap(func).subscribe(new DefaultObserver() { @Override public void onNext(Integer t) { // Consume after sleep for 1 ms @@ -734,12 +737,12 @@ public void concatMapRangeAsyncLoopIssue2876() { if (i % 1000 == 0) { System.out.println("concatMapRangeAsyncLoop > " + i); } - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(0, 1000) - .concatMap(new Function>() { + TestObserver ts = new TestObserver(); + Observable.range(0, 1000) + .concatMap(new Function>() { @Override - public NbpObservable apply(Integer t) { - return NbpObservable.fromIterable(Arrays.asList(t)); + public Observable apply(Integer t) { + return Observable.fromIterable(Arrays.asList(t)); } }) .observeOn(Schedulers.computation()).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDebounceTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDebounceTest.java similarity index 72% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDebounceTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDebounceTest.java index e0abb8a422..d9aeb98086 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDebounceTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -22,18 +22,19 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorDebounceTest { private TestScheduler scheduler; - private NbpSubscriber NbpObserver; + private Observer NbpObserver; private Scheduler.Worker innerScheduler; @Before @@ -45,9 +46,9 @@ public void before() { @Test public void testDebounceWithCompleted() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 100, "one"); // Should be skipped since "two" will arrive before the timeout expires. publishNext(NbpObserver, 400, "two"); // Should be published since "three" will arrive after the timeout expires. @@ -56,7 +57,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable sampled = source.debounce(400, TimeUnit.MILLISECONDS, scheduler); + Observable sampled = source.debounce(400, TimeUnit.MILLISECONDS, scheduler); sampled.subscribe(NbpObserver); scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS); @@ -71,9 +72,9 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testDebounceNeverEmits() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); // all should be skipped since they are happening faster than the 200ms timeout publishNext(NbpObserver, 100, "a"); // Should be skipped @@ -88,7 +89,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable sampled = source.debounce(200, TimeUnit.MILLISECONDS, scheduler); + Observable sampled = source.debounce(200, TimeUnit.MILLISECONDS, scheduler); sampled.subscribe(NbpObserver); scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS); @@ -101,9 +102,9 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testDebounceWithError() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); Exception error = new TestException(); publishNext(NbpObserver, 100, "one"); // Should be published since "two" will arrive after the timeout expires. @@ -112,7 +113,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable sampled = source.debounce(400, TimeUnit.MILLISECONDS, scheduler); + Observable sampled = source.debounce(400, TimeUnit.MILLISECONDS, scheduler); sampled.subscribe(NbpObserver); scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS); @@ -125,7 +126,7 @@ public void accept(NbpSubscriber NbpObserver) { inOrder.verifyNoMoreInteractions(); } - private void publishCompleted(final NbpSubscriber NbpObserver, long delay) { + private void publishCompleted(final Observer NbpObserver, long delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -134,7 +135,7 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private void publishError(final NbpSubscriber NbpObserver, long delay, final Exception error) { + private void publishError(final Observer NbpObserver, long delay, final Exception error) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -143,7 +144,7 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private void publishNext(final NbpSubscriber NbpObserver, final long delay, final T value) { + private void publishNext(final Observer NbpObserver, final long delay, final T value) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -154,17 +155,17 @@ public void run() { @Test public void debounceSelectorNormal1() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject debouncer = NbpPublishSubject.create(); - Function> debounceSel = new Function>() { + PublishSubject source = PublishSubject.create(); + final PublishSubject debouncer = PublishSubject.create(); + Function> debounceSel = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { return debouncer; } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.debounce(debounceSel).subscribe(o); @@ -191,16 +192,16 @@ public NbpObservable apply(Integer t1) { @Test public void debounceSelectorFuncThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - Function> debounceSel = new Function>() { + PublishSubject source = PublishSubject.create(); + Function> debounceSel = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { throw new TestException(); } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.debounce(debounceSel).subscribe(o); @@ -213,16 +214,16 @@ public NbpObservable apply(Integer t1) { @Test public void debounceSelectorObservableThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - Function> debounceSel = new Function>() { + PublishSubject source = PublishSubject.create(); + Function> debounceSel = new Function>() { @Override - public NbpObservable apply(Integer t1) { - return NbpObservable.error(new TestException()); + public Observable apply(Integer t1) { + return Observable.error(new TestException()); } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.debounce(debounceSel).subscribe(o); @@ -234,9 +235,9 @@ public NbpObservable apply(Integer t1) { } @Test public void debounceTimedLastIsNotLost() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.debounce(100, TimeUnit.MILLISECONDS, scheduler).subscribe(o); @@ -251,18 +252,18 @@ public void debounceTimedLastIsNotLost() { } @Test public void debounceSelectorLastIsNotLost() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject debouncer = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + final PublishSubject debouncer = PublishSubject.create(); - Function> debounceSel = new Function>() { + Function> debounceSel = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { return debouncer; } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.debounce(debounceSel).subscribe(o); @@ -279,10 +280,10 @@ public NbpObservable apply(Integer t1) { @Test public void debounceWithTimeBackpressure() throws InterruptedException { TestScheduler scheduler = new TestScheduler(); - NbpTestSubscriber NbpSubscriber = new NbpTestSubscriber(); - NbpObservable.merge( - NbpObservable.just(1), - NbpObservable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler) + TestObserver NbpSubscriber = new TestObserver(); + Observable.merge( + Observable.just(1), + Observable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler) ).debounce(20, TimeUnit.MILLISECONDS, scheduler).take(1).subscribe(NbpSubscriber); scheduler.advanceTimeBy(30, TimeUnit.MILLISECONDS); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDefaultIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDefaultIfEmptyTest.java similarity index 74% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDefaultIfEmptyTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDefaultIfEmptyTest.java index e2949eecb0..af704c745b 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDefaultIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDefaultIfEmptyTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -19,17 +19,18 @@ import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; +import io.reactivex.observers.DefaultObserver; public class NbpOperatorDefaultIfEmptyTest { @Test public void testDefaultIfEmpty() { - NbpObservable source = NbpObservable.just(1, 2, 3); - NbpObservable NbpObservable = source.defaultIfEmpty(10); + Observable source = Observable.just(1, 2, 3); + Observable NbpObservable = source.defaultIfEmpty(10); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -43,10 +44,10 @@ public void testDefaultIfEmpty() { @Test public void testDefaultIfEmptyWithEmpty() { - NbpObservable source = NbpObservable.empty(); - NbpObservable NbpObservable = source.defaultIfEmpty(10); + Observable source = Observable.empty(); + Observable NbpObservable = source.defaultIfEmpty(10); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -58,9 +59,9 @@ public void testDefaultIfEmptyWithEmpty() { @Test @Ignore("Subscribers should not throw") public void testEmptyButClientThrows() { - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + final Observer o = TestHelper.mockNbpSubscriber(); - NbpObservable.empty().defaultIfEmpty(1).subscribe(new NbpObserver() { + Observable.empty().defaultIfEmpty(1).subscribe(new DefaultObserver() { @Override public void onNext(Integer t) { throw new TestException(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDelayTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDelayTest.java similarity index 69% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDelayTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDelayTest.java index 4527b0264b..5d698b7dc7 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDelayTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.*; @@ -24,18 +24,19 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.Optional; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; -import io.reactivex.Optional; -import io.reactivex.Observable; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorDelayTest { - private NbpSubscriber NbpObserver; - private NbpSubscriber observer2; + private Observer NbpObserver; + private Observer observer2; private TestScheduler scheduler; @@ -49,8 +50,8 @@ public void before() { @Test public void testDelay() { - NbpObservable source = NbpObservable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); - NbpObservable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); + Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); + Observable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); delayed.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -89,8 +90,8 @@ public void testDelay() { @Test public void testLongDelay() { - NbpObservable source = NbpObservable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); - NbpObservable delayed = source.delay(5L, TimeUnit.SECONDS, scheduler); + Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); + Observable delayed = source.delay(5L, TimeUnit.SECONDS, scheduler); delayed.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -118,7 +119,7 @@ public void testLongDelay() { @Test public void testDelayWithError() { - NbpObservable source = NbpObservable.interval(1L, TimeUnit.SECONDS, scheduler) + Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler) .map(new Function() { @Override public Long apply(Long value) { @@ -128,7 +129,7 @@ public Long apply(Long value) { return value; } }); - NbpObservable delayed = source.delay(1L, TimeUnit.SECONDS, scheduler); + Observable delayed = source.delay(1L, TimeUnit.SECONDS, scheduler); delayed.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -151,8 +152,8 @@ public Long apply(Long value) { @Test public void testDelayWithMultipleSubscriptions() { - NbpObservable source = NbpObservable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); - NbpObservable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); + Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); + Observable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); delayed.subscribe(NbpObserver); delayed.subscribe(observer2); @@ -192,9 +193,9 @@ public void testDelayWithMultipleSubscriptions() { @Test public void testDelaySubscription() { - NbpObservable result = NbpObservable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + Observable result = Observable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); result.subscribe(o); @@ -214,10 +215,10 @@ public void testDelaySubscription() { @Test public void testDelaySubscriptionCancelBeforeTime() { - NbpObservable result = NbpObservable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); + Observable result = Observable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(o); + Observer o = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(o); result.subscribe(ts); ts.dispose(); @@ -230,22 +231,22 @@ public void testDelaySubscriptionCancelBeforeTime() { @Test public void testDelayWithObservableNormal1() { - NbpPublishSubject source = NbpPublishSubject.create(); - final List> delays = new ArrayList>(); + PublishSubject source = PublishSubject.create(); + final List> delays = new ArrayList>(); final int n = 10; for (int i = 0; i < n; i++) { - NbpPublishSubject delay = NbpPublishSubject.create(); + PublishSubject delay = PublishSubject.create(); delays.add(delay); } - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { return delays.get(t1); } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.delay(delayFunc).subscribe(o); @@ -265,17 +266,17 @@ public NbpObservable apply(Integer t1) { @Test public void testDelayWithObservableSingleSend1() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject delay = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + final PublishSubject delay = PublishSubject.create(); - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { return delay; } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.delay(delayFunc).subscribe(o); @@ -291,17 +292,17 @@ public NbpObservable apply(Integer t1) { @Test public void testDelayWithObservableSourceThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject delay = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + final PublishSubject delay = PublishSubject.create(); - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { return delay; } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.delay(delayFunc).subscribe(o); @@ -317,16 +318,16 @@ public NbpObservable apply(Integer t1) { @Test public void testDelayWithObservableDelayFunctionThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { throw new TestException(); } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.delay(delayFunc).subscribe(o); @@ -340,17 +341,17 @@ public NbpObservable apply(Integer t1) { @Test public void testDelayWithObservableDelayThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject delay = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + final PublishSubject delay = PublishSubject.create(); - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { return delay; } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.delay(delayFunc).subscribe(o); @@ -365,23 +366,23 @@ public NbpObservable apply(Integer t1) { @Test public void testDelayWithObservableSubscriptionNormal() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject delay = NbpPublishSubject.create(); - Supplier> subFunc = new Supplier>() { + PublishSubject source = PublishSubject.create(); + final PublishSubject delay = PublishSubject.create(); + Supplier> subFunc = new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return delay; } }; - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { return delay; } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.delay(subFunc, delayFunc).subscribe(o); @@ -400,23 +401,23 @@ public NbpObservable apply(Integer t1) { @Test public void testDelayWithObservableSubscriptionFunctionThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject delay = NbpPublishSubject.create(); - Supplier> subFunc = new Supplier>() { + PublishSubject source = PublishSubject.create(); + final PublishSubject delay = PublishSubject.create(); + Supplier> subFunc = new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { throw new TestException(); } }; - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { return delay; } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.delay(subFunc, delayFunc).subscribe(o); @@ -434,23 +435,23 @@ public NbpObservable apply(Integer t1) { @Test public void testDelayWithObservableSubscriptionThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject delay = NbpPublishSubject.create(); - Supplier> subFunc = new Supplier>() { + PublishSubject source = PublishSubject.create(); + final PublishSubject delay = PublishSubject.create(); + Supplier> subFunc = new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return delay; } }; - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { return delay; } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.delay(subFunc, delayFunc).subscribe(o); @@ -468,16 +469,16 @@ public NbpObservable apply(Integer t1) { @Test public void testDelayWithObservableEmptyDelayer() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { - return NbpObservable.empty(); + public Observable apply(Integer t1) { + return Observable.empty(); } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.delay(delayFunc).subscribe(o); @@ -493,24 +494,24 @@ public NbpObservable apply(Integer t1) { @Test public void testDelayWithObservableSubscriptionRunCompletion() { - NbpPublishSubject source = NbpPublishSubject.create(); - final NbpPublishSubject sdelay = NbpPublishSubject.create(); - final NbpPublishSubject delay = NbpPublishSubject.create(); - Supplier> subFunc = new Supplier>() { + PublishSubject source = PublishSubject.create(); + final PublishSubject sdelay = PublishSubject.create(); + final PublishSubject delay = PublishSubject.create(); + Supplier> subFunc = new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return sdelay; } }; - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { return delay; } }; - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.delay(subFunc, delayFunc).subscribe(o); @@ -529,18 +530,18 @@ public NbpObservable apply(Integer t1) { @Test public void testDelayWithObservableAsTimed() { - NbpObservable source = NbpObservable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); + Observable source = Observable.interval(1L, TimeUnit.SECONDS, scheduler).take(3); - final NbpObservable delayer = NbpObservable.timer(500L, TimeUnit.MILLISECONDS, scheduler); + final Observable delayer = Observable.timer(500L, TimeUnit.MILLISECONDS, scheduler); - Function> delayFunc = new Function>() { + Function> delayFunc = new Function>() { @Override - public NbpObservable apply(Long t1) { + public Observable apply(Long t1) { return delayer; } }; - NbpObservable delayed = source.delay(delayFunc); + Observable delayed = source.delay(delayFunc); delayed.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -581,21 +582,21 @@ public NbpObservable apply(Long t1) { public void testDelayWithObservableReorder() { int n = 3; - NbpPublishSubject source = NbpPublishSubject.create(); - final List> subjects = new ArrayList>(); + PublishSubject source = PublishSubject.create(); + final List> subjects = new ArrayList>(); for (int i = 0; i < n; i++) { - subjects.add(NbpPublishSubject. create()); + subjects.add(PublishSubject. create()); } - NbpObservable result = source.delay(new Function>() { + Observable result = source.delay(new Function>() { @Override - public NbpObservable apply(Integer t1) { + public Observable apply(Integer t1) { return subjects.get(t1); } }); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); result.subscribe(o); @@ -620,8 +621,8 @@ public NbpObservable apply(Integer t1) { @Test public void testDelayEmitsEverything() { - NbpObservable source = NbpObservable.range(1, 5); - NbpObservable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); + Observable source = Observable.range(1, 5); + Observable delayed = source.delay(500L, TimeUnit.MILLISECONDS, scheduler); delayed = delayed.doOnEach(new Consumer>>() { @Override @@ -630,7 +631,7 @@ public void accept(Try> t1) { } }); - NbpTestSubscriber NbpObserver = new NbpTestSubscriber(); + TestObserver NbpObserver = new TestObserver(); delayed.subscribe(NbpObserver); // all will be delivered after 500ms since range does not delay between them scheduler.advanceTimeBy(500L, TimeUnit.MILLISECONDS); @@ -639,8 +640,8 @@ public void accept(Try> t1) { @Test public void testBackpressureWithTimedDelay() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(1, Observable.bufferSize() * 2) + TestObserver ts = new TestObserver(); + Observable.range(1, Flowable.bufferSize() * 2) .delay(100, TimeUnit.MILLISECONDS) .observeOn(Schedulers.computation()) .map(new Function() { @@ -662,13 +663,13 @@ public Integer apply(Integer t) { ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); } @Test public void testBackpressureWithSubscriptionTimedDelay() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(1, Observable.bufferSize() * 2) + TestObserver ts = new TestObserver(); + Observable.range(1, Flowable.bufferSize() * 2) .delaySubscription(100, TimeUnit.MILLISECONDS) .delay(100, TimeUnit.MILLISECONDS) .observeOn(Schedulers.computation()) @@ -691,18 +692,18 @@ public Integer apply(Integer t) { ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); } @Test public void testBackpressureWithSelectorDelay() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(1, Observable.bufferSize() * 2) - .delay(new Function>() { + TestObserver ts = new TestObserver(); + Observable.range(1, Flowable.bufferSize() * 2) + .delay(new Function>() { @Override - public NbpObservable apply(Integer i) { - return NbpObservable.timer(100, TimeUnit.MILLISECONDS); + public Observable apply(Integer i) { + return Observable.timer(100, TimeUnit.MILLISECONDS); } }) @@ -726,24 +727,24 @@ public Integer apply(Integer t) { ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); } @Test public void testBackpressureWithSelectorDelayAndSubscriptionDelay() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(1, Observable.bufferSize() * 2) - .delay(new Supplier>() { + TestObserver ts = new TestObserver(); + Observable.range(1, Flowable.bufferSize() * 2) + .delay(new Supplier>() { @Override - public NbpObservable get() { - return NbpObservable.timer(500, TimeUnit.MILLISECONDS); + public Observable get() { + return Observable.timer(500, TimeUnit.MILLISECONDS); } - }, new Function>() { + }, new Function>() { @Override - public NbpObservable apply(Integer i) { - return NbpObservable.timer(100, TimeUnit.MILLISECONDS); + public Observable apply(Integer i) { + return Observable.timer(100, TimeUnit.MILLISECONDS); } }) @@ -767,16 +768,16 @@ public Integer apply(Integer t) { ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); } @Test public void testErrorRunsBeforeOnNext() { TestScheduler test = Schedulers.test(); - NbpPublishSubject ps = NbpPublishSubject.create(); + PublishSubject ps = PublishSubject.create(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); ps.delay(1, TimeUnit.SECONDS, test).subscribe(ts); @@ -794,15 +795,15 @@ public void testErrorRunsBeforeOnNext() { } public void testDelaySupplierSimple() { - final NbpPublishSubject ps = NbpPublishSubject.create(); + final PublishSubject ps = PublishSubject.create(); - NbpObservable source = NbpObservable.range(1, 5); + Observable source = Observable.range(1, 5); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - source.delaySubscription(new Supplier>() { + source.delaySubscription(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return ps; } }).subscribe(ts); @@ -820,15 +821,15 @@ public NbpObservable get() { @Test public void testDelaySupplierCompletes() { - final NbpPublishSubject ps = NbpPublishSubject.create(); + final PublishSubject ps = PublishSubject.create(); - NbpObservable source = NbpObservable.range(1, 5); + Observable source = Observable.range(1, 5); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - source.delaySubscription(new Supplier>() { + source.delaySubscription(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return ps; } }).subscribe(ts); @@ -847,15 +848,15 @@ public NbpObservable get() { @Test public void testDelaySupplierErrors() { - final NbpPublishSubject ps = NbpPublishSubject.create(); + final PublishSubject ps = PublishSubject.create(); - NbpObservable source = NbpObservable.range(1, 5); + Observable source = Observable.range(1, 5); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - source.delaySubscription(new Supplier>() { + source.delaySubscription(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return ps; } }).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDematerializeTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDematerializeTest.java similarity index 62% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDematerializeTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDematerializeTest.java index db62043d16..ab72a9ce53 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDematerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDematerializeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -19,18 +19,18 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.flowable.TestHelper; +import io.reactivex.observers.TestObserver; public class NbpOperatorDematerializeTest { @Test public void testDematerialize1() { - NbpObservable>> notifications = NbpObservable.just(1, 2).materialize(); - NbpObservable dematerialize = notifications.dematerialize(); + Observable>> notifications = Observable.just(1, 2).materialize(); + Observable dematerialize = notifications.dematerialize(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); dematerialize.subscribe(NbpObserver); @@ -43,10 +43,10 @@ public void testDematerialize1() { @Test public void testDematerialize2() { Throwable exception = new Throwable("test"); - NbpObservable o = NbpObservable.error(exception); - NbpObservable dematerialize = o.materialize().dematerialize(); + Observable o = Observable.error(exception); + Observable dematerialize = o.materialize().dematerialize(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); dematerialize.subscribe(NbpObserver); @@ -58,10 +58,10 @@ public void testDematerialize2() { @Test public void testDematerialize3() { Exception exception = new Exception("test"); - NbpObservable o = NbpObservable.error(exception); - NbpObservable dematerialize = o.materialize().dematerialize(); + Observable o = Observable.error(exception); + Observable dematerialize = o.materialize().dematerialize(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); dematerialize.subscribe(NbpObserver); @@ -73,10 +73,10 @@ public void testDematerialize3() { @Test public void testErrorPassThru() { Exception exception = new Exception("test"); - NbpObservable o = NbpObservable.error(exception); - NbpObservable dematerialize = o.dematerialize(); + Observable o = Observable.error(exception); + Observable dematerialize = o.dematerialize(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); dematerialize.subscribe(NbpObserver); @@ -87,12 +87,12 @@ public void testErrorPassThru() { @Test public void testCompletePassThru() { - NbpObservable o = NbpObservable.empty(); - NbpObservable dematerialize = o.dematerialize(); + Observable o = Observable.empty(); + Observable dematerialize = o.dematerialize(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + TestObserver ts = new TestObserver(NbpObserver); dematerialize.subscribe(ts); System.out.println(ts.errors()); @@ -104,11 +104,11 @@ public void testCompletePassThru() { @Test public void testHonorsContractWhenCompleted() { - NbpObservable source = NbpObservable.just(1); + Observable source = Observable.just(1); - NbpObservable result = source.materialize().dematerialize(); + Observable result = source.materialize().dematerialize(); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.unsafeSubscribe(o); @@ -119,11 +119,11 @@ public void testHonorsContractWhenCompleted() { @Test public void testHonorsContractWhenThrows() { - NbpObservable source = NbpObservable.error(new TestException()); + Observable source = Observable.error(new TestException()); - NbpObservable result = source.materialize().dematerialize(); + Observable result = source.materialize().dematerialize(); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.unsafeSubscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDistinctTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDistinctTest.java similarity index 86% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDistinctTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDistinctTest.java index e68a0f6ea9..ab76298dfd 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDistinctTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDistinctTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -20,12 +20,12 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; public class NbpOperatorDistinctTest { - NbpSubscriber w; + Observer w; // nulls lead to exceptions final Function TO_UPPER_WITH_EXCEPTION = new Function() { @@ -45,7 +45,7 @@ public void before() { @Test public void testDistinctOfNone() { - NbpObservable src = NbpObservable.empty(); + Observable src = Observable.empty(); src.distinct().subscribe(w); verify(w, never()).onNext(anyString()); @@ -55,7 +55,7 @@ public void testDistinctOfNone() { @Test public void testDistinctOfNoneWithKeySelector() { - NbpObservable src = NbpObservable.empty(); + Observable src = Observable.empty(); src.distinct(TO_UPPER_WITH_EXCEPTION).subscribe(w); verify(w, never()).onNext(anyString()); @@ -65,7 +65,7 @@ public void testDistinctOfNoneWithKeySelector() { @Test public void testDistinctOfNormalSource() { - NbpObservable src = NbpObservable.just("a", "b", "c", "c", "c", "b", "b", "a", "e"); + Observable src = Observable.just("a", "b", "c", "c", "c", "b", "b", "a", "e"); src.distinct().subscribe(w); InOrder inOrder = inOrder(w); @@ -80,7 +80,7 @@ public void testDistinctOfNormalSource() { @Test public void testDistinctOfNormalSourceWithKeySelector() { - NbpObservable src = NbpObservable.just("a", "B", "c", "C", "c", "B", "b", "a", "E"); + Observable src = Observable.just("a", "B", "c", "C", "c", "B", "b", "a", "E"); src.distinct(TO_UPPER_WITH_EXCEPTION).subscribe(w); InOrder inOrder = inOrder(w); @@ -96,7 +96,7 @@ public void testDistinctOfNormalSourceWithKeySelector() { @Test @Ignore("Null values no longer allowed") public void testDistinctOfSourceWithNulls() { - NbpObservable src = NbpObservable.just(null, "a", "a", null, null, "b", null); + Observable src = Observable.just(null, "a", "a", null, null, "b", null); src.distinct().subscribe(w); InOrder inOrder = inOrder(w); @@ -111,7 +111,7 @@ public void testDistinctOfSourceWithNulls() { @Test @Ignore("Null values no longer allowed") public void testDistinctOfSourceWithExceptionsFromKeySelector() { - NbpObservable src = NbpObservable.just("a", "b", null, "c"); + Observable src = Observable.just("a", "b", null, "c"); src.distinct(TO_UPPER_WITH_EXCEPTION).subscribe(w); InOrder inOrder = inOrder(w); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDistinctUntilChangedTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDistinctUntilChangedTest.java similarity index 86% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDistinctUntilChangedTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDistinctUntilChangedTest.java index 162f486769..321b7bc0ef 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDistinctUntilChangedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDistinctUntilChangedTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -20,13 +20,13 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; public class NbpOperatorDistinctUntilChangedTest { - NbpSubscriber w; - NbpSubscriber w2; + Observer w; + Observer w2; // nulls lead to exceptions final Function TO_UPPER_WITH_EXCEPTION = new Function() { @@ -47,7 +47,7 @@ public void before() { @Test public void testDistinctUntilChangedOfNone() { - NbpObservable src = NbpObservable.empty(); + Observable src = Observable.empty(); src.distinctUntilChanged().subscribe(w); verify(w, never()).onNext(anyString()); @@ -57,7 +57,7 @@ public void testDistinctUntilChangedOfNone() { @Test public void testDistinctUntilChangedOfNoneWithKeySelector() { - NbpObservable src = NbpObservable.empty(); + Observable src = Observable.empty(); src.distinctUntilChanged(TO_UPPER_WITH_EXCEPTION).subscribe(w); verify(w, never()).onNext(anyString()); @@ -67,7 +67,7 @@ public void testDistinctUntilChangedOfNoneWithKeySelector() { @Test public void testDistinctUntilChangedOfNormalSource() { - NbpObservable src = NbpObservable.just("a", "b", "c", "c", "c", "b", "b", "a", "e"); + Observable src = Observable.just("a", "b", "c", "c", "c", "b", "b", "a", "e"); src.distinctUntilChanged().subscribe(w); InOrder inOrder = inOrder(w); @@ -84,7 +84,7 @@ public void testDistinctUntilChangedOfNormalSource() { @Test public void testDistinctUntilChangedOfNormalSourceWithKeySelector() { - NbpObservable src = NbpObservable.just("a", "b", "c", "C", "c", "B", "b", "a", "e"); + Observable src = Observable.just("a", "b", "c", "C", "c", "B", "b", "a", "e"); src.distinctUntilChanged(TO_UPPER_WITH_EXCEPTION).subscribe(w); InOrder inOrder = inOrder(w); @@ -102,7 +102,7 @@ public void testDistinctUntilChangedOfNormalSourceWithKeySelector() { @Test @Ignore("Null values no longer allowed") public void testDistinctUntilChangedOfSourceWithNulls() { - NbpObservable src = NbpObservable.just(null, "a", "a", null, null, "b", null, null); + Observable src = Observable.just(null, "a", "a", null, null, "b", null, null); src.distinctUntilChanged().subscribe(w); InOrder inOrder = inOrder(w); @@ -119,7 +119,7 @@ public void testDistinctUntilChangedOfSourceWithNulls() { @Test @Ignore("Null values no longer allowed") public void testDistinctUntilChangedOfSourceWithExceptionsFromKeySelector() { - NbpObservable src = NbpObservable.just("a", "b", null, "c"); + Observable src = Observable.just("a", "b", null, "c"); src.distinctUntilChanged(TO_UPPER_WITH_EXCEPTION).subscribe(w); InOrder inOrder = inOrder(w); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDoOnEachTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDoOnEachTest.java similarity index 89% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDoOnEachTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDoOnEachTest.java index 150859106d..8731280ca6 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDoOnEachTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDoOnEachTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -23,13 +23,13 @@ import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; public class NbpOperatorDoOnEachTest { - NbpSubscriber subscribedObserver; - NbpSubscriber sideEffectObserver; + Observer subscribedObserver; + Observer sideEffectObserver; @Before public void before() { @@ -39,8 +39,8 @@ public void before() { @Test public void testDoOnEach() { - NbpObservable base = NbpObservable.just("a", "b", "c"); - NbpObservable doOnEach = base.doOnEach(sideEffectObserver); + Observable base = Observable.just("a", "b", "c"); + Observable doOnEach = base.doOnEach(sideEffectObserver); doOnEach.subscribe(subscribedObserver); @@ -61,8 +61,8 @@ public void testDoOnEach() { @Test public void testDoOnEachWithError() { - NbpObservable base = NbpObservable.just("one", "fail", "two", "three", "fail"); - NbpObservable errs = base.map(new Function() { + Observable base = Observable.just("one", "fail", "two", "three", "fail"); + Observable errs = base.map(new Function() { @Override public String apply(String s) { if ("fail".equals(s)) { @@ -72,7 +72,7 @@ public String apply(String s) { } }); - NbpObservable doOnEach = errs.doOnEach(sideEffectObserver); + Observable doOnEach = errs.doOnEach(sideEffectObserver); doOnEach.subscribe(subscribedObserver); verify(subscribedObserver, times(1)).onNext("one"); @@ -90,8 +90,8 @@ public String apply(String s) { @Test public void testDoOnEachWithErrorInCallback() { - NbpObservable base = NbpObservable.just("one", "two", "fail", "three"); - NbpObservable doOnEach = base.doOnNext(new Consumer() { + Observable base = Observable.just("one", "two", "fail", "three"); + Observable doOnEach = base.doOnNext(new Consumer() { @Override public void accept(String s) { if ("fail".equals(s)) { @@ -115,7 +115,7 @@ public void testIssue1451Case1() { final int expectedCount = 3; final AtomicInteger count = new AtomicInteger(); for (int i=0; i < expectedCount; i++) { - NbpObservable + Observable .just(Boolean.TRUE, Boolean.FALSE) .takeWhile(new Predicate() { @Override @@ -141,7 +141,7 @@ public void testIssue1451Case2() { final int expectedCount = 3; final AtomicInteger count = new AtomicInteger(); for (int i=0; i < expectedCount; i++) { - NbpObservable + Observable .just(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE) .takeWhile(new Predicate() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDoOnSubscribeTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDoOnSubscribeTest.java similarity index 83% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDoOnSubscribeTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDoOnSubscribeTest.java index 12432c66a9..511513b81c 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDoOnSubscribeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDoOnSubscribeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; @@ -19,8 +19,8 @@ import org.junit.Test; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.internal.disposables.EmptyDisposable; @@ -30,7 +30,7 @@ public class NbpOperatorDoOnSubscribeTest { @Test public void testDoOnSubscribe() throws Exception { final AtomicInteger count = new AtomicInteger(); - NbpObservable o = NbpObservable.just(1).doOnSubscribe(new Consumer() { + Observable o = Observable.just(1).doOnSubscribe(new Consumer() { @Override public void accept(Disposable s) { count.incrementAndGet(); @@ -46,7 +46,7 @@ public void accept(Disposable s) { @Test public void testDoOnSubscribe2() throws Exception { final AtomicInteger count = new AtomicInteger(); - NbpObservable o = NbpObservable.just(1).doOnSubscribe(new Consumer() { + Observable o = Observable.just(1).doOnSubscribe(new Consumer() { @Override public void accept(Disposable s) { count.incrementAndGet(); @@ -67,11 +67,11 @@ public void testDoOnUnSubscribeWorksWithRefCount() throws Exception { final AtomicInteger onSubscribed = new AtomicInteger(); final AtomicInteger countBefore = new AtomicInteger(); final AtomicInteger countAfter = new AtomicInteger(); - final AtomicReference> sref = new AtomicReference>(); - NbpObservable o = NbpObservable.create(new NbpOnSubscribe() { + final AtomicReference> sref = new AtomicReference>(); + Observable o = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { s.onSubscribe(EmptyDisposable.INSTANCE); onSubscribed.incrementAndGet(); sref.set(s); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDoOnUnsubscribeTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDoOnUnsubscribeTest.java similarity index 91% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDoOnUnsubscribeTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDoOnUnsubscribeTest.java index 20385b5b41..efdc8998c6 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorDoOnUnsubscribeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorDoOnUnsubscribeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; @@ -21,10 +21,10 @@ import org.junit.Test; -import io.reactivex.NbpObservable; +import io.reactivex.Observable; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.TestObserver; public class NbpOperatorDoOnUnsubscribeTest { @@ -37,7 +37,7 @@ public void testDoOnUnsubscribe() throws Exception { final AtomicInteger upperCount = new AtomicInteger(); final AtomicInteger lowerCount = new AtomicInteger(); - NbpObservable longs = NbpObservable + Observable longs = Observable // The stream needs to be infinite to ensure the stream does not terminate // before it is unsubscribed .interval(50, TimeUnit.MILLISECONDS) @@ -67,10 +67,10 @@ public void run() { }); List subscriptions = new ArrayList(); - List> subscribers = new ArrayList>(); + List> subscribers = new ArrayList>(); for (int i = 0; i < subCount; ++i) { - NbpTestSubscriber NbpSubscriber = new NbpTestSubscriber(); + TestObserver NbpSubscriber = new TestObserver(); subscriptions.add(NbpSubscriber); longs.subscribe(NbpSubscriber); subscribers.add(NbpSubscriber); @@ -99,7 +99,7 @@ public void testDoOnUnSubscribeWorksWithRefCount() throws Exception { final AtomicInteger upperCount = new AtomicInteger(); final AtomicInteger lowerCount = new AtomicInteger(); - NbpObservable longs = NbpObservable + Observable longs = Observable // The stream needs to be infinite to ensure the stream does not terminate // before it is unsubscribed .interval(50, TimeUnit.MILLISECONDS) @@ -130,10 +130,10 @@ public void run() { .refCount(); List subscriptions = new ArrayList(); - List> subscribers = new ArrayList>(); + List> subscribers = new ArrayList>(); for (int i = 0; i < subCount; ++i) { - NbpTestSubscriber NbpSubscriber = new NbpTestSubscriber(); + TestObserver NbpSubscriber = new TestObserver(); longs.subscribe(NbpSubscriber); subscriptions.add(NbpSubscriber); subscribers.add(NbpSubscriber); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorElementAtTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorElementAtTest.java similarity index 95% rename from src/test/java/io/reactivex/internal/operators/OperatorElementAtTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorElementAtTest.java index 9985b83cc5..7d74ab4289 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorElementAtTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorElementAtTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; @@ -19,7 +19,7 @@ import io.reactivex.Observable; -public class OperatorElementAtTest { +public class NbpOperatorElementAtTest { @Test public void testElementAt() { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorFilterTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorFilterTest.java similarity index 87% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorFilterTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorFilterTest.java index d3e931fa6b..27cf9280bb 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorFilterTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorFilterTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -20,15 +20,15 @@ import org.mockito.Mockito; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Predicate; public class NbpOperatorFilterTest { @Test public void testFilter() { - NbpObservable w = NbpObservable.just("one", "two", "three"); - NbpObservable NbpObservable = w.filter(new Predicate() { + Observable w = Observable.just("one", "two", "three"); + Observable NbpObservable = w.filter(new Predicate() { @Override public boolean test(String t1) { @@ -36,7 +36,7 @@ public boolean test(String t1) { } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorFinallyTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorFinallyTest.java similarity index 76% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorFinallyTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorFinallyTest.java index 054ad8ca3f..df63a481d9 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorFinallyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorFinallyTest.java @@ -11,19 +11,19 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Mockito.*; import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; public class NbpOperatorFinallyTest { private Runnable aAction0; - private NbpSubscriber NbpObserver; + private Observer NbpObserver; // mocking has to be unchecked, unfortunately @Before @@ -32,18 +32,18 @@ public void before() { NbpObserver = TestHelper.mockNbpSubscriber(); } - private void checkActionCalled(NbpObservable input) { + private void checkActionCalled(Observable input) { input.finallyDo(aAction0).subscribe(NbpObserver); verify(aAction0, times(1)).run(); } @Test public void testFinallyCalledOnComplete() { - checkActionCalled(NbpObservable.fromArray("1", "2", "3")); + checkActionCalled(Observable.fromArray("1", "2", "3")); } @Test public void testFinallyCalledOnError() { - checkActionCalled(NbpObservable. error(new RuntimeException("expected"))); + checkActionCalled(Observable. error(new RuntimeException("expected"))); } } \ No newline at end of file diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorFirstTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorFirstTest.java similarity index 78% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorFirstTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorFirstTest.java index 1df49e7b32..a21287b0ba 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorFirstTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorFirstTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -22,12 +22,12 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Predicate; public class NbpOperatorFirstTest { - NbpSubscriber w; + Observer w; private static final Predicate IS_D = new Predicate() { @Override @@ -43,7 +43,7 @@ public void before() { @Test public void testFirstOrElseOfNone() { - NbpObservable src = NbpObservable.empty(); + Observable src = Observable.empty(); src.first("default").subscribe(w); verify(w, times(1)).onNext(anyString()); @@ -54,7 +54,7 @@ public void testFirstOrElseOfNone() { @Test public void testFirstOrElseOfSome() { - NbpObservable src = NbpObservable.just("a", "b", "c"); + Observable src = Observable.just("a", "b", "c"); src.first("default").subscribe(w); verify(w, times(1)).onNext(anyString()); @@ -65,7 +65,7 @@ public void testFirstOrElseOfSome() { @Test public void testFirstOrElseWithPredicateOfNoneMatchingThePredicate() { - NbpObservable src = NbpObservable.just("a", "b", "c"); + Observable src = Observable.just("a", "b", "c"); src.filter(IS_D).first("default").subscribe(w); verify(w, times(1)).onNext(anyString()); @@ -76,7 +76,7 @@ public void testFirstOrElseWithPredicateOfNoneMatchingThePredicate() { @Test public void testFirstOrElseWithPredicateOfSome() { - NbpObservable src = NbpObservable.just("a", "b", "c", "d", "e", "f"); + Observable src = Observable.just("a", "b", "c", "d", "e", "f"); src.filter(IS_D).first("default").subscribe(w); verify(w, times(1)).onNext(anyString()); @@ -87,9 +87,9 @@ public void testFirstOrElseWithPredicateOfSome() { @Test public void testFirst() { - NbpObservable o = NbpObservable.just(1, 2, 3).first(); + Observable o = Observable.just(1, 2, 3).first(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -100,9 +100,9 @@ public void testFirst() { @Test public void testFirstWithOneElement() { - NbpObservable o = NbpObservable.just(1).first(); + Observable o = Observable.just(1).first(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -113,9 +113,9 @@ public void testFirstWithOneElement() { @Test public void testFirstWithEmpty() { - NbpObservable o = NbpObservable. empty().first(); + Observable o = Observable. empty().first(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -126,7 +126,7 @@ public void testFirstWithEmpty() { @Test public void testFirstWithPredicate() { - NbpObservable o = NbpObservable.just(1, 2, 3, 4, 5, 6) + Observable o = Observable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -135,7 +135,7 @@ public boolean test(Integer t1) { }) .first(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -146,7 +146,7 @@ public boolean test(Integer t1) { @Test public void testFirstWithPredicateAndOneElement() { - NbpObservable o = NbpObservable.just(1, 2) + Observable o = Observable.just(1, 2) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -155,7 +155,7 @@ public boolean test(Integer t1) { }) .first(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -166,7 +166,7 @@ public boolean test(Integer t1) { @Test public void testFirstWithPredicateAndEmpty() { - NbpObservable o = NbpObservable.just(1) + Observable o = Observable.just(1) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -175,7 +175,7 @@ public boolean test(Integer t1) { }) .first(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -186,10 +186,10 @@ public boolean test(Integer t1) { @Test public void testFirstOrDefault() { - NbpObservable o = NbpObservable.just(1, 2, 3) + Observable o = Observable.just(1, 2, 3) .first(4); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -200,9 +200,9 @@ public void testFirstOrDefault() { @Test public void testFirstOrDefaultWithOneElement() { - NbpObservable o = NbpObservable.just(1).first(2); + Observable o = Observable.just(1).first(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -213,10 +213,10 @@ public void testFirstOrDefaultWithOneElement() { @Test public void testFirstOrDefaultWithEmpty() { - NbpObservable o = NbpObservable. empty() + Observable o = Observable. empty() .first(1); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -227,7 +227,7 @@ public void testFirstOrDefaultWithEmpty() { @Test public void testFirstOrDefaultWithPredicate() { - NbpObservable o = NbpObservable.just(1, 2, 3, 4, 5, 6) + Observable o = Observable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -236,7 +236,7 @@ public boolean test(Integer t1) { }) .first(8); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -247,7 +247,7 @@ public boolean test(Integer t1) { @Test public void testFirstOrDefaultWithPredicateAndOneElement() { - NbpObservable o = NbpObservable.just(1, 2) + Observable o = Observable.just(1, 2) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -256,7 +256,7 @@ public boolean test(Integer t1) { }) .first(4); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -267,7 +267,7 @@ public boolean test(Integer t1) { @Test public void testFirstOrDefaultWithPredicateAndEmpty() { - NbpObservable o = NbpObservable.just(1) + Observable o = Observable.just(1) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -276,7 +276,7 @@ public boolean test(Integer t1) { }) .first(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorFlatMapTest.java similarity index 68% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorFlatMapTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorFlatMapTest.java index bc00b25f4a..231ed9e034 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorFlatMapTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -23,18 +23,19 @@ import org.junit.*; -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorFlatMapTest { @Test public void testNormal() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); final List list = Arrays.asList(1, 2, 3); @@ -54,7 +55,7 @@ public Integer apply(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - NbpObservable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); + Observable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); for (Integer s : source) { for (Integer v : list) { @@ -67,7 +68,7 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testCollectionFunctionThrows() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); Function> func = new Function>() { @Override @@ -85,7 +86,7 @@ public Integer apply(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - NbpObservable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); + Observable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); verify(o, never()).onComplete(); verify(o, never()).onNext(any()); @@ -94,7 +95,7 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testResultFunctionThrows() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); final List list = Arrays.asList(1, 2, 3); @@ -114,7 +115,7 @@ public Integer apply(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - NbpObservable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); + Observable.fromIterable(source).flatMapIterable(func, resFunc).subscribe(o); verify(o, never()).onComplete(); verify(o, never()).onNext(any()); @@ -123,12 +124,12 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testMergeError() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - Function> func = new Function>() { + Function> func = new Function>() { @Override - public NbpObservable apply(Integer t1) { - return NbpObservable.error(new TestException()); + public Observable apply(Integer t1) { + return Observable.error(new TestException()); } }; BiFunction resFunc = new BiFunction() { @@ -141,7 +142,7 @@ public Integer apply(Integer t1, Integer t2) { List source = Arrays.asList(16, 32, 64); - NbpObservable.fromIterable(source).flatMap(func, resFunc).subscribe(o); + Observable.fromIterable(source).flatMap(func, resFunc).subscribe(o); verify(o, never()).onComplete(); verify(o, never()).onNext(any()); @@ -170,13 +171,13 @@ public R get() { @Test public void testFlatMapTransformsNormal() { - NbpObservable onNext = NbpObservable.fromIterable(Arrays.asList(1, 2, 3)); - NbpObservable onCompleted = NbpObservable.fromIterable(Arrays.asList(4)); - NbpObservable onError = NbpObservable.fromIterable(Arrays.asList(5)); + Observable onNext = Observable.fromIterable(Arrays.asList(1, 2, 3)); + Observable onCompleted = Observable.fromIterable(Arrays.asList(4)); + Observable onError = Observable.fromIterable(Arrays.asList(5)); - NbpObservable source = NbpObservable.fromIterable(Arrays.asList(10, 20, 30)); + Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.flatMap(just(onNext), just(onError), just0(onCompleted)).subscribe(o); @@ -192,17 +193,17 @@ public void testFlatMapTransformsNormal() { @Test public void testFlatMapTransformsException() { - NbpObservable onNext = NbpObservable.fromIterable(Arrays.asList(1, 2, 3)); - NbpObservable onCompleted = NbpObservable.fromIterable(Arrays.asList(4)); - NbpObservable onError = NbpObservable.fromIterable(Arrays.asList(5)); + Observable onNext = Observable.fromIterable(Arrays.asList(1, 2, 3)); + Observable onCompleted = Observable.fromIterable(Arrays.asList(4)); + Observable onError = Observable.fromIterable(Arrays.asList(5)); - NbpObservable source = NbpObservable.concat( - NbpObservable.fromIterable(Arrays.asList(10, 20, 30)), - NbpObservable. error(new RuntimeException("Forced failure!")) + Observable source = Observable.concat( + Observable.fromIterable(Arrays.asList(10, 20, 30)), + Observable. error(new RuntimeException("Forced failure!")) ); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.flatMap(just(onNext), just(onError), just0(onCompleted)).subscribe(o); @@ -236,12 +237,12 @@ public R apply(T t) { @Test public void testFlatMapTransformsOnNextFuncThrows() { - NbpObservable onCompleted = NbpObservable.fromIterable(Arrays.asList(4)); - NbpObservable onError = NbpObservable.fromIterable(Arrays.asList(5)); + Observable onCompleted = Observable.fromIterable(Arrays.asList(4)); + Observable onError = Observable.fromIterable(Arrays.asList(5)); - NbpObservable source = NbpObservable.fromIterable(Arrays.asList(10, 20, 30)); + Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.flatMap(funcThrow(1, onError), just(onError), just0(onCompleted)).subscribe(o); @@ -252,13 +253,13 @@ public void testFlatMapTransformsOnNextFuncThrows() { @Test public void testFlatMapTransformsOnErrorFuncThrows() { - NbpObservable onNext = NbpObservable.fromIterable(Arrays.asList(1, 2, 3)); - NbpObservable onCompleted = NbpObservable.fromIterable(Arrays.asList(4)); - NbpObservable onError = NbpObservable.fromIterable(Arrays.asList(5)); + Observable onNext = Observable.fromIterable(Arrays.asList(1, 2, 3)); + Observable onCompleted = Observable.fromIterable(Arrays.asList(4)); + Observable onError = Observable.fromIterable(Arrays.asList(5)); - NbpObservable source = NbpObservable.error(new TestException()); + Observable source = Observable.error(new TestException()); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.flatMap(just(onNext), funcThrow((Throwable) null, onError), just0(onCompleted)).subscribe(o); @@ -269,13 +270,13 @@ public void testFlatMapTransformsOnErrorFuncThrows() { @Test public void testFlatMapTransformsOnCompletedFuncThrows() { - NbpObservable onNext = NbpObservable.fromIterable(Arrays.asList(1, 2, 3)); - NbpObservable onCompleted = NbpObservable.fromIterable(Arrays.asList(4)); - NbpObservable onError = NbpObservable.fromIterable(Arrays.asList(5)); + Observable onNext = Observable.fromIterable(Arrays.asList(1, 2, 3)); + Observable onCompleted = Observable.fromIterable(Arrays.asList(4)); + Observable onError = Observable.fromIterable(Arrays.asList(5)); - NbpObservable source = NbpObservable.fromIterable(Arrays. asList()); + Observable source = Observable.fromIterable(Arrays. asList()); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.flatMap(just(onNext), just(onError), funcThrow0(onCompleted)).subscribe(o); @@ -286,13 +287,13 @@ public void testFlatMapTransformsOnCompletedFuncThrows() { @Test public void testFlatMapTransformsMergeException() { - NbpObservable onNext = NbpObservable.error(new TestException()); - NbpObservable onCompleted = NbpObservable.fromIterable(Arrays.asList(4)); - NbpObservable onError = NbpObservable.fromIterable(Arrays.asList(5)); + Observable onNext = Observable.error(new TestException()); + Observable onCompleted = Observable.fromIterable(Arrays.asList(4)); + Observable onError = Observable.fromIterable(Arrays.asList(5)); - NbpObservable source = NbpObservable.fromIterable(Arrays.asList(10, 20, 30)); + Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.flatMap(just(onNext), just(onError), funcThrow0(onCompleted)).subscribe(o); @@ -301,7 +302,7 @@ public void testFlatMapTransformsMergeException() { verify(o, never()).onComplete(); } - private static NbpObservable composer(NbpObservable source, final AtomicInteger subscriptionCount, final int m) { + private static Observable composer(Observable source, final AtomicInteger subscriptionCount, final int m) { return source.doOnSubscribe(new Consumer() { @Override public void accept(Disposable s) { @@ -325,16 +326,16 @@ public void run() { public void testFlatMapMaxConcurrent() { final int m = 4; final AtomicInteger subscriptionCount = new AtomicInteger(); - NbpObservable source = NbpObservable.range(1, 10) - .flatMap(new Function>() { + Observable source = Observable.range(1, 10) + .flatMap(new Function>() { @Override - public NbpObservable apply(Integer t1) { - return composer(NbpObservable.range(t1 * 10, 2), subscriptionCount, m) + public Observable apply(Integer t1) { + return composer(Observable.range(t1 * 10, 2), subscriptionCount, m) .subscribeOn(Schedulers.computation()); } }, m); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); source.subscribe(ts); @@ -350,11 +351,11 @@ public NbpObservable apply(Integer t1) { public void testFlatMapSelectorMaxConcurrent() { final int m = 4; final AtomicInteger subscriptionCount = new AtomicInteger(); - NbpObservable source = NbpObservable.range(1, 10) - .flatMap(new Function>() { + Observable source = Observable.range(1, 10) + .flatMap(new Function>() { @Override - public NbpObservable apply(Integer t1) { - return composer(NbpObservable.range(t1 * 10, 2), subscriptionCount, m) + public Observable apply(Integer t1) { + return composer(Observable.range(t1 * 10, 2), subscriptionCount, m) .subscribeOn(Schedulers.computation()); } }, new BiFunction() { @@ -364,7 +365,7 @@ public Integer apply(Integer t1, Integer t2) { } }, m); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); source.subscribe(ts); @@ -393,26 +394,26 @@ public void testFlatMapTransformsMaxConcurrentNormalLoop() { public void testFlatMapTransformsMaxConcurrentNormal() { final int m = 2; final AtomicInteger subscriptionCount = new AtomicInteger(); - NbpObservable onNext = + Observable onNext = composer( - NbpObservable.fromIterable(Arrays.asList(1, 2, 3)) + Observable.fromIterable(Arrays.asList(1, 2, 3)) .observeOn(Schedulers.computation()) , subscriptionCount, m) .subscribeOn(Schedulers.computation()) ; - NbpObservable onCompleted = composer(NbpObservable.fromIterable(Arrays.asList(4)), subscriptionCount, m) + Observable onCompleted = composer(Observable.fromIterable(Arrays.asList(4)), subscriptionCount, m) .subscribeOn(Schedulers.computation()); - NbpObservable onError = NbpObservable.fromIterable(Arrays.asList(5)); + Observable onError = Observable.fromIterable(Arrays.asList(5)); - NbpObservable source = NbpObservable.fromIterable(Arrays.asList(10, 20, 30)); + Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(o); + Observer o = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(o); - Function> just = just(onError); + Function> just = just(onError); source.flatMap(just(onNext), just, just0(onCompleted), m).subscribe(ts); ts.awaitTerminalEvent(1, TimeUnit.SECONDS); @@ -436,12 +437,12 @@ public void flatMapRangeAsyncLoop() { if (i % 10 == 0) { System.out.println("flatMapRangeAsyncLoop > " + i); } - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(0, 1000) - .flatMap(new Function>() { + TestObserver ts = new TestObserver(); + Observable.range(0, 1000) + .flatMap(new Function>() { @Override - public NbpObservable apply(Integer t) { - return NbpObservable.just(t); + public Observable apply(Integer t) { + return Observable.just(t); } }) .observeOn(Schedulers.computation()) @@ -473,13 +474,13 @@ public void flatMapRangeMixedAsyncLoop() { if (i % 10 == 0) { System.out.println("flatMapRangeAsyncLoop > " + i); } - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(0, 1000) - .flatMap(new Function>() { + TestObserver ts = new TestObserver(); + Observable.range(0, 1000) + .flatMap(new Function>() { final Random rnd = new Random(); @Override - public NbpObservable apply(Integer t) { - NbpObservable r = NbpObservable.just(t); + public Observable apply(Integer t) { + Observable r = Observable.just(t); if (rnd.nextBoolean()) { r = r.asObservable(); } @@ -511,12 +512,12 @@ public NbpObservable apply(Integer t) { @Test public void flatMapIntPassthruAsync() { for (int i = 0;i < 1000; i++) { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - NbpObservable.range(1, 1000).flatMap(new Function>() { + Observable.range(1, 1000).flatMap(new Function>() { @Override - public NbpObservable apply(Integer t) { - return NbpObservable.just(1).subscribeOn(Schedulers.computation()); + public Observable apply(Integer t) { + return Observable.just(1).subscribeOn(Schedulers.computation()); } }).subscribe(ts); @@ -529,12 +530,12 @@ public NbpObservable apply(Integer t) { @Test public void flatMapTwoNestedSync() { for (final int n : new int[] { 1, 1000, 1000000 }) { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - NbpObservable.just(1, 2).flatMap(new Function>() { + Observable.just(1, 2).flatMap(new Function>() { @Override - public NbpObservable apply(Integer t) { - return NbpObservable.range(1, n); + public Observable apply(Integer t) { + return Observable.range(1, n); } }).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorGroupByTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorGroupByTest.java similarity index 79% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorGroupByTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorGroupByTest.java index bcbfb4878b..bdd37a8308 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorGroupByTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,15 +25,17 @@ import org.mockito.Matchers; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; +import io.reactivex.Optional; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.observables.nbp.NbpGroupedObservable; +import io.reactivex.observables.GroupedObservable; +import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; -import io.reactivex.Optional; public class NbpOperatorGroupByTest { @@ -46,8 +48,8 @@ public Integer apply(String s) { @Test public void testGroupBy() { - NbpObservable source = NbpObservable.just("one", "two", "three", "four", "five", "six"); - NbpObservable> grouped = source.groupBy(length); + Observable source = Observable.just("one", "two", "three", "four", "five", "six"); + Observable> grouped = source.groupBy(length); Map> map = toMap(grouped); @@ -59,8 +61,8 @@ public void testGroupBy() { @Test public void testGroupByWithElementSelector() { - NbpObservable source = NbpObservable.just("one", "two", "three", "four", "five", "six"); - NbpObservable> grouped = source.groupBy(length, length); + Observable source = Observable.just("one", "two", "three", "four", "five", "six"); + Observable> grouped = source.groupBy(length, length); Map> map = toMap(grouped); @@ -72,8 +74,8 @@ public void testGroupByWithElementSelector() { @Test public void testGroupByWithElementSelector2() { - NbpObservable source = NbpObservable.just("one", "two", "three", "four", "five", "six"); - NbpObservable> grouped = source.groupBy(length, length); + Observable source = Observable.just("one", "two", "three", "four", "five", "six"); + Observable> grouped = source.groupBy(length, length); Map> map = toMap(grouped); @@ -85,8 +87,8 @@ public void testGroupByWithElementSelector2() { @Test public void testEmpty() { - NbpObservable source = NbpObservable.empty(); - NbpObservable> grouped = source.groupBy(length); + Observable source = Observable.empty(); + Observable> grouped = source.groupBy(length); Map> map = toMap(grouped); @@ -95,20 +97,20 @@ public void testEmpty() { @Test public void testError() { - NbpObservable sourceStrings = NbpObservable.just("one", "two", "three", "four", "five", "six"); - NbpObservable errorSource = NbpObservable.error(new RuntimeException("forced failure")); - NbpObservable source = NbpObservable.concat(sourceStrings, errorSource); + Observable sourceStrings = Observable.just("one", "two", "three", "four", "five", "six"); + Observable errorSource = Observable.error(new RuntimeException("forced failure")); + Observable source = Observable.concat(sourceStrings, errorSource); - NbpObservable> grouped = source.groupBy(length); + Observable> grouped = source.groupBy(length); final AtomicInteger groupCounter = new AtomicInteger(); final AtomicInteger eventCounter = new AtomicInteger(); final AtomicReference error = new AtomicReference(); - grouped.flatMap(new Function, NbpObservable>() { + grouped.flatMap(new Function, Observable>() { @Override - public NbpObservable apply(final NbpGroupedObservable o) { + public Observable apply(final GroupedObservable o) { groupCounter.incrementAndGet(); return o.map(new Function() { @@ -118,7 +120,7 @@ public String apply(String v) { } }); } - }).subscribe(new NbpObserver() { + }).subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -144,14 +146,14 @@ public void onNext(String v) { assertNotNull(error.get()); } - private static Map> toMap(NbpObservable> NbpObservable) { + private static Map> toMap(Observable> NbpObservable) { final ConcurrentHashMap> result = new ConcurrentHashMap>(); - NbpObservable.toBlocking().forEach(new Consumer>() { + NbpObservable.toBlocking().forEach(new Consumer>() { @Override - public void accept(final NbpGroupedObservable o) { + public void accept(final GroupedObservable o) { result.put(o.getKey(), new ConcurrentLinkedQueue()); o.subscribe(new Consumer() { @@ -182,10 +184,10 @@ public void testGroupedEventStream() throws Throwable { final int count = 100; final int groupCount = 2; - NbpObservable es = NbpObservable.create(new NbpOnSubscribe() { + Observable es = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); System.out.println("*** Subscribing to EventStream ***"); subscribeCounter.incrementAndGet(); @@ -213,10 +215,10 @@ public void run() { public Integer apply(Event e) { return e.source; } - }).flatMap(new Function, NbpObservable>() { + }).flatMap(new Function, Observable>() { @Override - public NbpObservable apply(NbpGroupedObservable eventGroupedObservable) { + public Observable apply(GroupedObservable eventGroupedObservable) { System.out.println("NbpGroupedObservable Key: " + eventGroupedObservable.getKey()); groupCounter.incrementAndGet(); @@ -229,7 +231,7 @@ public String apply(Event event) { }); } - }).subscribe(new NbpObserver() { + }).subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -280,7 +282,7 @@ public void testUnsubscribeOnNestedTakeAndAsyncInfiniteStream() throws Interrupt assertEquals(39, sentEventCounter.get()); } - private void doTestUnsubscribeOnNestedTakeAndAsyncInfiniteStream(NbpObservable es, AtomicInteger subscribeCounter) throws InterruptedException { + private void doTestUnsubscribeOnNestedTakeAndAsyncInfiniteStream(Observable es, AtomicInteger subscribeCounter) throws InterruptedException { final AtomicInteger eventCounter = new AtomicInteger(); final AtomicInteger groupCounter = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(1); @@ -293,10 +295,10 @@ public Integer apply(Event e) { } }) .take(1) // we want only the first group - .flatMap(new Function, NbpObservable>() { + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(NbpGroupedObservable eventGroupedObservable) { + public Observable apply(GroupedObservable eventGroupedObservable) { System.out.println("testUnsubscribe => NbpGroupedObservable Key: " + eventGroupedObservable.getKey()); groupCounter.incrementAndGet(); @@ -311,7 +313,7 @@ public String apply(Event event) { }); } - }).subscribe(new NbpObserver() { + }).subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -358,10 +360,10 @@ public Integer apply(Event e) { }) // take 2 of the 4 groups .take(2) - .flatMap(new Function, NbpObservable>() { + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(NbpGroupedObservable eventGroupedObservable) { + public Observable apply(GroupedObservable eventGroupedObservable) { return eventGroupedObservable .map(new Function() { @@ -404,10 +406,10 @@ public Integer apply(Event e) { }) // take 2 of the 4 groups .take(2) - .flatMap(new Function, NbpObservable>() { + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(NbpGroupedObservable eventGroupedObservable) { + public Observable apply(GroupedObservable eventGroupedObservable) { int numToTake = 0; if (eventGroupedObservable.getKey() == 1) { numToTake = 10; @@ -445,7 +447,7 @@ public void accept(String s) { public void testStaggeredCompletion() throws InterruptedException { final AtomicInteger eventCounter = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(1); - NbpObservable.range(0, 100) + Observable.range(0, 100) .groupBy(new Function() { @Override @@ -453,10 +455,10 @@ public Integer apply(Integer i) { return i % 2; } }) - .flatMap(new Function, NbpObservable>() { + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(NbpGroupedObservable group) { + public Observable apply(GroupedObservable group) { if (group.getKey() == 0) { return group.delay(100, TimeUnit.MILLISECONDS).map(new Function() { @Override @@ -470,7 +472,7 @@ public Integer apply(Integer t) { } } }) - .subscribe(new NbpObserver() { + .subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -502,7 +504,7 @@ public void onNext(Integer s) { public void testCompletionIfInnerNotSubscribed() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicInteger eventCounter = new AtomicInteger(); - NbpObservable.range(0, 100) + Observable.range(0, 100) .groupBy(new Function() { @Override @@ -510,7 +512,7 @@ public Integer apply(Integer i) { return i % 2; } }) - .subscribe(new NbpObserver>() { + .subscribe(new DefaultObserver>() { @Override public void onComplete() { @@ -524,7 +526,7 @@ public void onError(Throwable e) { } @Override - public void onNext(NbpGroupedObservable s) { + public void onNext(GroupedObservable s) { eventCounter.incrementAndGet(); System.out.println("=> " + s); } @@ -549,11 +551,11 @@ public Integer apply(Event e) { return e.source; } }) - .flatMap(new Function, NbpObservable>() { + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(NbpGroupedObservable eventGroupedObservable) { - NbpObservable eventStream = eventGroupedObservable; + public Observable apply(GroupedObservable eventGroupedObservable) { + Observable eventStream = eventGroupedObservable; if (eventGroupedObservable.getKey() >= 2) { // filter these eventStream = eventGroupedObservable.filter(new Predicate() { @@ -594,10 +596,10 @@ public void accept(String s) { public void testFirstGroupsCompleteAndParentSlowToThenEmitFinalGroupsAndThenComplete() throws InterruptedException { final CountDownLatch first = new CountDownLatch(2); // there are two groups to first complete final ArrayList results = new ArrayList(); - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber sub) { + public void accept(Observer sub) { sub.onSubscribe(EmptyDisposable.INSTANCE); sub.onNext(1); sub.onNext(2); @@ -621,10 +623,10 @@ public Integer apply(Integer t) { return t; } - }).flatMap(new Function, NbpObservable>() { + }).flatMap(new Function, Observable>() { @Override - public NbpObservable apply(final NbpGroupedObservable group) { + public Observable apply(final GroupedObservable group) { if (group.getKey() < 3) { return group.map(new Function() { @@ -673,10 +675,10 @@ public void testFirstGroupsCompleteAndParentSlowToThenEmitFinalGroupsWhichThenSu System.err.println("----------------------------------------------------------------------------------------------"); final CountDownLatch first = new CountDownLatch(2); // there are two groups to first complete final ArrayList results = new ArrayList(); - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber sub) { + public void accept(Observer sub) { sub.onSubscribe(EmptyDisposable.INSTANCE); sub.onNext(1); sub.onNext(2); @@ -700,10 +702,10 @@ public Integer apply(Integer t) { return t; } - }).flatMap(new Function, NbpObservable>() { + }).flatMap(new Function, Observable>() { @Override - public NbpObservable apply(final NbpGroupedObservable group) { + public Observable apply(final GroupedObservable group) { if (group.getKey() < 3) { return group.map(new Function() { @@ -765,10 +767,10 @@ public void accept(String s) { public void testFirstGroupsCompleteAndParentSlowToThenEmitFinalGroupsWhichThenObservesOnAndDelaysAndThenCompletes() throws InterruptedException { final CountDownLatch first = new CountDownLatch(2); // there are two groups to first complete final ArrayList results = new ArrayList(); - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber sub) { + public void accept(Observer sub) { sub.onSubscribe(EmptyDisposable.INSTANCE); sub.onNext(1); sub.onNext(2); @@ -792,10 +794,10 @@ public Integer apply(Integer t) { return t; } - }).flatMap(new Function, NbpObservable>() { + }).flatMap(new Function, Observable>() { @Override - public NbpObservable apply(final NbpGroupedObservable group) { + public Observable apply(final GroupedObservable group) { if (group.getKey() < 3) { return group.map(new Function() { @@ -842,10 +844,10 @@ public void accept(String s) { @Test public void testGroupsWithNestedSubscribeOn() throws InterruptedException { final ArrayList results = new ArrayList(); - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber sub) { + public void accept(Observer sub) { sub.onSubscribe(EmptyDisposable.INSTANCE); sub.onNext(1); sub.onNext(2); @@ -861,10 +863,10 @@ public Integer apply(Integer t) { return t; } - }).flatMap(new Function, NbpObservable>() { + }).flatMap(new Function, Observable>() { @Override - public NbpObservable apply(final NbpGroupedObservable group) { + public Observable apply(final GroupedObservable group) { return group.subscribeOn(Schedulers.newThread()).map(new Function() { @Override @@ -899,10 +901,10 @@ public void accept(String s) { @Test public void testGroupsWithNestedObserveOn() throws InterruptedException { final ArrayList results = new ArrayList(); - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber sub) { + public void accept(Observer sub) { sub.onSubscribe(EmptyDisposable.INSTANCE); sub.onNext(1); sub.onNext(2); @@ -918,10 +920,10 @@ public Integer apply(Integer t) { return t; } - }).flatMap(new Function, NbpObservable>() { + }).flatMap(new Function, Observable>() { @Override - public NbpObservable apply(final NbpGroupedObservable group) { + public Observable apply(final GroupedObservable group) { return group.observeOn(Schedulers.newThread()).delay(400, TimeUnit.MILLISECONDS).map(new Function() { @Override @@ -955,15 +957,15 @@ public String toString() { } } - NbpObservable ASYNC_INFINITE_OBSERVABLE_OF_EVENT(final int numGroups, final AtomicInteger subscribeCounter, final AtomicInteger sentEventCounter) { + Observable ASYNC_INFINITE_OBSERVABLE_OF_EVENT(final int numGroups, final AtomicInteger subscribeCounter, final AtomicInteger sentEventCounter) { return SYNC_INFINITE_OBSERVABLE_OF_EVENT(numGroups, subscribeCounter, sentEventCounter).subscribeOn(Schedulers.newThread()); }; - NbpObservable SYNC_INFINITE_OBSERVABLE_OF_EVENT(final int numGroups, final AtomicInteger subscribeCounter, final AtomicInteger sentEventCounter) { - return NbpObservable.create(new NbpOnSubscribe() { + Observable SYNC_INFINITE_OBSERVABLE_OF_EVENT(final int numGroups, final AtomicInteger subscribeCounter, final AtomicInteger sentEventCounter) { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber op) { + public void accept(final Observer op) { BooleanDisposable bs = new BooleanDisposable(); op.onSubscribe(bs); subscribeCounter.incrementAndGet(); @@ -986,16 +988,16 @@ public void accept(final NbpSubscriber op) { public void testGroupByOnAsynchronousSourceAcceptsMultipleSubscriptions() throws InterruptedException { // choose an asynchronous source - NbpObservable source = NbpObservable.interval(10, TimeUnit.MILLISECONDS).take(1); + Observable source = Observable.interval(10, TimeUnit.MILLISECONDS).take(1); // apply groupBy to the source - NbpObservable> stream = source.groupBy(IS_EVEN); + Observable> stream = source.groupBy(IS_EVEN); // create two observers @SuppressWarnings("unchecked") - NbpObserver> o1 = mock(NbpObserver.class); + DefaultObserver> o1 = mock(DefaultObserver.class); @SuppressWarnings("unchecked") - NbpObserver> o2 = mock(NbpObserver.class); + DefaultObserver> o2 = mock(DefaultObserver.class); // subscribe with the observers stream.subscribe(o1); @@ -1025,14 +1027,14 @@ public Boolean apply(Integer n) { @Test public void testGroupByBackpressure() throws InterruptedException { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - NbpObservable.range(1, 4000) + Observable.range(1, 4000) .groupBy(IS_EVEN2) - .flatMap(new Function, NbpObservable>() { + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(final NbpGroupedObservable g) { + public Observable apply(final GroupedObservable g) { return g.observeOn(Schedulers.computation()).map(new Function() { @Override @@ -1098,7 +1100,7 @@ public Integer apply(Integer v) { @Test public void normalBehavior() { - NbpObservable source = NbpObservable.fromIterable(Arrays.asList( + Observable source = Observable.fromIterable(Arrays.asList( " foo", " FoO ", "baR ", @@ -1133,10 +1135,10 @@ public String apply(String t1) { } }; - NbpObservable m = source.groupBy(keysel, valuesel) - .flatMap(new Function, NbpObservable>() { + Observable m = source.groupBy(keysel, valuesel) + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(final NbpGroupedObservable g) { + public Observable apply(final GroupedObservable g) { System.out.println("-----------> NEXT: " + g.getKey()); return g.take(2).map(new Function() { @@ -1152,7 +1154,7 @@ public String apply(String v) { } }); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); m.subscribe(ts); ts.awaitTerminalEvent(); System.out.println("ts .get " + ts.values()); @@ -1164,11 +1166,11 @@ public String apply(String v) { @Test public void keySelectorThrows() { - NbpObservable source = NbpObservable.just(0, 1, 2, 3, 4, 5, 6); + Observable source = Observable.just(0, 1, 2, 3, 4, 5, 6); - NbpObservable m = source.groupBy(fail(0), dbl).flatMap(FLATTEN_INTEGER); + Observable m = source.groupBy(fail(0), dbl).flatMap(FLATTEN_INTEGER); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); m.subscribe(ts); ts.awaitTerminalEvent(); assertEquals(1, ts.errorCount()); @@ -1177,10 +1179,10 @@ public void keySelectorThrows() { @Test public void valueSelectorThrows() { - NbpObservable source = NbpObservable.just(0, 1, 2, 3, 4, 5, 6); + Observable source = Observable.just(0, 1, 2, 3, 4, 5, 6); - NbpObservable m = source.groupBy(identity, fail(0)).flatMap(FLATTEN_INTEGER); - NbpTestSubscriber ts = new NbpTestSubscriber(); + Observable m = source.groupBy(identity, fail(0)).flatMap(FLATTEN_INTEGER); + TestObserver ts = new TestObserver(); m.subscribe(ts); ts.awaitTerminalEvent(); assertEquals(1, ts.errorCount()); @@ -1190,11 +1192,11 @@ public void valueSelectorThrows() { @Test public void innerEscapeCompleted() { - NbpObservable source = NbpObservable.just(0); + Observable source = Observable.just(0); - NbpObservable m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); + Observable m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); m.subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); @@ -1206,15 +1208,15 @@ public void innerEscapeCompleted() { */ @Test public void testExceptionIfSubscribeToChildMoreThanOnce() { - NbpObservable source = NbpObservable.just(0); + Observable source = Observable.just(0); - final AtomicReference> inner = new AtomicReference>(); + final AtomicReference> inner = new AtomicReference>(); - NbpObservable> m = source.groupBy(identity, dbl); + Observable> m = source.groupBy(identity, dbl); - m.subscribe(new Consumer>() { + m.subscribe(new Consumer>() { @Override - public void accept(NbpGroupedObservable t1) { + public void accept(GroupedObservable t1) { inner.set(t1); } }); @@ -1222,7 +1224,7 @@ public void accept(NbpGroupedObservable t1) { inner.get().subscribe(); @SuppressWarnings("unchecked") - NbpObserver o2 = mock(NbpObserver.class); + DefaultObserver o2 = mock(DefaultObserver.class); inner.get().subscribe(o2); @@ -1233,12 +1235,12 @@ public void accept(NbpGroupedObservable t1) { @Test public void testError2() { - NbpObservable source = NbpObservable.concat(NbpObservable.just(0), - NbpObservable. error(new TestException("Forced failure"))); + Observable source = Observable.concat(Observable.just(0), + Observable. error(new TestException("Forced failure"))); - NbpObservable m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); + Observable m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); m.subscribe(ts); ts.awaitTerminalEvent(); assertEquals(1, ts.errorCount()); @@ -1247,12 +1249,12 @@ public void testError2() { @Test public void testgroupByBackpressure() throws InterruptedException { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - NbpObservable.range(1, 4000).groupBy(IS_EVEN2).flatMap(new Function, NbpObservable>() { + Observable.range(1, 4000).groupBy(IS_EVEN2).flatMap(new Function, Observable>() { @Override - public NbpObservable apply(final NbpGroupedObservable g) { + public Observable apply(final GroupedObservable g) { return g.doOnComplete(new Runnable() { @Override @@ -1304,12 +1306,12 @@ public void accept(Try> t1) { @Test public void testgroupByBackpressure2() throws InterruptedException { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - NbpObservable.range(1, 4000).groupBy(IS_EVEN2).flatMap(new Function, NbpObservable>() { + Observable.range(1, 4000).groupBy(IS_EVEN2).flatMap(new Function, Observable>() { @Override - public NbpObservable apply(final NbpGroupedObservable g) { + public Observable apply(final GroupedObservable g) { return g.take(2).observeOn(Schedulers.computation()).map(new Function() { @Override @@ -1333,10 +1335,10 @@ public String apply(Integer l) { ts.assertNoErrors(); } - static Function, NbpObservable> FLATTEN_INTEGER = new Function, NbpObservable>() { + static Function, Observable> FLATTEN_INTEGER = new Function, Observable>() { @Override - public NbpObservable apply(NbpGroupedObservable t) { + public Observable apply(GroupedObservable t) { return t; } @@ -1346,16 +1348,16 @@ public NbpObservable apply(NbpGroupedObservable t) { public void testGroupByWithNullKey() { final String[] key = new String[]{"uninitialized"}; final List values = new ArrayList(); - NbpObservable.just("a", "b", "c").groupBy(new Function() { + Observable.just("a", "b", "c").groupBy(new Function() { @Override public String apply(String value) { return null; } - }).subscribe(new Consumer>() { + }).subscribe(new Consumer>() { @Override - public void accept(NbpGroupedObservable NbpGroupedObservable) { + public void accept(GroupedObservable NbpGroupedObservable) { key[0] = NbpGroupedObservable.getKey(); NbpGroupedObservable.subscribe(new Consumer() { @@ -1373,15 +1375,15 @@ public void accept(String s) { @Test public void testGroupByUnsubscribe() { final Disposable s = mock(Disposable.class); - NbpObservable o = NbpObservable.create( + Observable o = Observable.create( new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpSubscriber) { + public void accept(Observer NbpSubscriber) { NbpSubscriber.onSubscribe(s); } } ); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); o.groupBy(new Function() { @@ -1399,11 +1401,11 @@ public Integer apply(Integer integer) { @Test public void testGroupByShouldPropagateError() { final Throwable e = new RuntimeException("Oops"); - final NbpTestSubscriber inner1 = new NbpTestSubscriber(); - final NbpTestSubscriber inner2 = new NbpTestSubscriber(); + final TestObserver inner1 = new TestObserver(); + final TestObserver inner2 = new TestObserver(); - final NbpTestSubscriber> outer - = new NbpTestSubscriber>(new NbpObserver>() { + final TestObserver> outer + = new TestObserver>(new DefaultObserver>() { @Override public void onComplete() { @@ -1414,7 +1416,7 @@ public void onError(Throwable e) { } @Override - public void onNext(NbpGroupedObservable o) { + public void onNext(GroupedObservable o) { if (o.getKey() == 0) { o.subscribe(inner1); } else { @@ -1422,10 +1424,10 @@ public void onNext(NbpGroupedObservable o) { } } }); - NbpObservable.create( + Observable.create( new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpSubscriber) { + public void accept(Observer NbpSubscriber) { NbpSubscriber.onSubscribe(EmptyDisposable.INSTANCE); NbpSubscriber.onNext(0); NbpSubscriber.onNext(1); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorIgnoreElementsTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorIgnoreElementsTest.java similarity index 76% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorIgnoreElementsTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorIgnoreElementsTest.java index 0677eeaeec..b7fa8d3a29 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorIgnoreElementsTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorIgnoreElementsTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; @@ -19,28 +19,28 @@ import org.junit.Test; -import io.reactivex.NbpObservable; +import io.reactivex.Observable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Consumer; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.TestObserver; public class NbpOperatorIgnoreElementsTest { @Test public void testWithEmpty() { - assertTrue(NbpObservable.empty().ignoreElements().isEmpty().toBlocking().single()); + assertTrue(Observable.empty().ignoreElements().isEmpty().toBlocking().single()); } @Test public void testWithNonEmpty() { - assertTrue(NbpObservable.just(1, 2, 3).ignoreElements().isEmpty().toBlocking().single()); + assertTrue(Observable.just(1, 2, 3).ignoreElements().isEmpty().toBlocking().single()); } @Test public void testUpstreamIsProcessedButIgnored() { final int num = 10; final AtomicInteger upstreamCount = new AtomicInteger(); - long count = NbpObservable.range(1, num) + long count = Observable.range(1, num) .doOnNext(new Consumer() { @Override public void accept(Integer t) { @@ -55,8 +55,8 @@ public void accept(Integer t) { @Test public void testCompletedOk() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(1, 10).ignoreElements().subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.range(1, 10).ignoreElements().subscribe(ts); ts.assertNoErrors(); ts.assertNoValues(); ts.assertTerminated(); @@ -66,9 +66,9 @@ public void testCompletedOk() { @Test public void testErrorReceived() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); TestException ex = new TestException("boo"); - NbpObservable.error(ex).ignoreElements().subscribe(ts); + Observable.error(ex).ignoreElements().subscribe(ts); ts.assertNoValues(); ts.assertTerminated(); // FIXME no longer testable @@ -80,7 +80,7 @@ public void testErrorReceived() { @Test public void testUnsubscribesFromUpstream() { final AtomicBoolean unsub = new AtomicBoolean(); - NbpObservable.range(1, 10).doOnCancel(new Runnable() { + Observable.range(1, 10).doOnCancel(new Runnable() { @Override public void run() { unsub.set(true); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorLastTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorLastTest.java similarity index 76% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorLastTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorLastTest.java index c8d199e342..0594f2f764 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorLastTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.isA; @@ -23,40 +23,40 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Predicate; public class NbpOperatorLastTest { @Test public void testLastWithElements() { - NbpObservable last = NbpObservable.just(1, 2, 3).last(); + Observable last = Observable.just(1, 2, 3).last(); assertEquals(3, last.toBlocking().single().intValue()); } @Test(expected = NoSuchElementException.class) public void testLastWithNoElements() { - NbpObservable last = NbpObservable.empty().last(); + Observable last = Observable.empty().last(); last.toBlocking().single(); } @Test public void testLastMultiSubscribe() { - NbpObservable last = NbpObservable.just(1, 2, 3).last(); + Observable last = Observable.just(1, 2, 3).last(); assertEquals(3, last.toBlocking().single().intValue()); assertEquals(3, last.toBlocking().single().intValue()); } @Test public void testLastViaObservable() { - NbpObservable.just(1, 2, 3).last(); + Observable.just(1, 2, 3).last(); } @Test public void testLast() { - NbpObservable o = NbpObservable.just(1, 2, 3).last(); + Observable o = Observable.just(1, 2, 3).last(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -67,9 +67,9 @@ public void testLast() { @Test public void testLastWithOneElement() { - NbpObservable o = NbpObservable.just(1).last(); + Observable o = Observable.just(1).last(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -80,9 +80,9 @@ public void testLastWithOneElement() { @Test public void testLastWithEmpty() { - NbpObservable o = NbpObservable. empty().last(); + Observable o = Observable. empty().last(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -93,7 +93,7 @@ public void testLastWithEmpty() { @Test public void testLastWithPredicate() { - NbpObservable o = NbpObservable.just(1, 2, 3, 4, 5, 6) + Observable o = Observable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override @@ -103,7 +103,7 @@ public boolean test(Integer t1) { }) .last(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -114,7 +114,7 @@ public boolean test(Integer t1) { @Test public void testLastWithPredicateAndOneElement() { - NbpObservable o = NbpObservable.just(1, 2) + Observable o = Observable.just(1, 2) .filter( new Predicate() { @@ -125,7 +125,7 @@ public boolean test(Integer t1) { }) .last(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -136,7 +136,7 @@ public boolean test(Integer t1) { @Test public void testLastWithPredicateAndEmpty() { - NbpObservable o = NbpObservable.just(1) + Observable o = Observable.just(1) .filter( new Predicate() { @@ -146,7 +146,7 @@ public boolean test(Integer t1) { } }).last(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -157,10 +157,10 @@ public boolean test(Integer t1) { @Test public void testLastOrDefault() { - NbpObservable o = NbpObservable.just(1, 2, 3) + Observable o = Observable.just(1, 2, 3) .last(4); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -171,9 +171,9 @@ public void testLastOrDefault() { @Test public void testLastOrDefaultWithOneElement() { - NbpObservable o = NbpObservable.just(1).last(2); + Observable o = Observable.just(1).last(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -184,10 +184,10 @@ public void testLastOrDefaultWithOneElement() { @Test public void testLastOrDefaultWithEmpty() { - NbpObservable o = NbpObservable. empty() + Observable o = Observable. empty() .last(1); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -198,7 +198,7 @@ public void testLastOrDefaultWithEmpty() { @Test public void testLastOrDefaultWithPredicate() { - NbpObservable o = NbpObservable.just(1, 2, 3, 4, 5, 6) + Observable o = Observable.just(1, 2, 3, 4, 5, 6) .filter(new Predicate() { @Override @@ -208,7 +208,7 @@ public boolean test(Integer t1) { }) .last(8); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -219,7 +219,7 @@ public boolean test(Integer t1) { @Test public void testLastOrDefaultWithPredicateAndOneElement() { - NbpObservable o = NbpObservable.just(1, 2) + Observable o = Observable.just(1, 2) .filter(new Predicate() { @Override @@ -229,7 +229,7 @@ public boolean test(Integer t1) { }) .last(4); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -240,7 +240,7 @@ public boolean test(Integer t1) { @Test public void testLastOrDefaultWithPredicateAndEmpty() { - NbpObservable o = NbpObservable.just(1) + Observable o = Observable.just(1) .filter( new Predicate() { @@ -251,7 +251,7 @@ public boolean test(Integer t1) { }) .last(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorMapNotificationTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMapNotificationTest.java similarity index 88% rename from src/test/java/io/reactivex/internal/operators/OperatorMapNotificationTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMapNotificationTest.java index e2c8f73b5b..eff6f1b16d 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorMapNotificationTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMapNotificationTest.java @@ -11,18 +11,18 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.observable; import org.junit.Test; import io.reactivex.Observable; import io.reactivex.functions.*; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.observers.TestObserver; -public class OperatorMapNotificationTest { +public class NbpOperatorMapNotificationTest { @Test public void testJust() { - TestSubscriber ts = new TestSubscriber(); + TestObserver ts = new TestObserver(); Observable.just(1) .flatMap( new Function>() { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMapTest.java similarity index 84% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMapTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMapTest.java index d7f0b0ad6b..1d17ba3832 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMapTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -20,15 +20,16 @@ import org.junit.*; -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.schedulers.Schedulers; public class NbpOperatorMapTest { - NbpSubscriber stringObserver; - NbpSubscriber stringObserver2; + Observer stringObserver; + Observer stringObserver2; final static BiFunction APPEND_INDEX = new BiFunction() { @Override @@ -47,9 +48,9 @@ public void before() { public void testMap() { Map m1 = getMap("One"); Map m2 = getMap("Two"); - NbpObservable> o = NbpObservable.just(m1, m2); + Observable> o = Observable.just(m1, m2); - NbpObservable m = o.map(new Function, String>() { + Observable m = o.map(new Function, String>() { @Override public String apply(Map map) { return map.get("firstName"); @@ -67,23 +68,23 @@ public String apply(Map map) { @Test public void testMapMany() { /* simulate a top-level async call which returns IDs */ - NbpObservable ids = NbpObservable.just(1, 2); + Observable ids = Observable.just(1, 2); /* now simulate the behavior to take those IDs and perform nested async calls based on them */ - NbpObservable m = ids.flatMap(new Function>() { + Observable m = ids.flatMap(new Function>() { @Override - public NbpObservable apply(Integer id) { + public Observable apply(Integer id) { /* simulate making a nested async call which creates another NbpObservable */ - NbpObservable> subObservable = null; + Observable> subObservable = null; if (id == 1) { Map m1 = getMap("One"); Map m2 = getMap("Two"); - subObservable = NbpObservable.just(m1, m2); + subObservable = Observable.just(m1, m2); } else { Map m3 = getMap("Three"); Map m4 = getMap("Four"); - subObservable = NbpObservable.just(m3, m4); + subObservable = Observable.just(m3, m4); } /* simulate kicking off the async call and performing a select on it to transform the data */ @@ -110,18 +111,18 @@ public String apply(Map map) { public void testMapMany2() { Map m1 = getMap("One"); Map m2 = getMap("Two"); - NbpObservable> observable1 = NbpObservable.just(m1, m2); + Observable> observable1 = Observable.just(m1, m2); Map m3 = getMap("Three"); Map m4 = getMap("Four"); - NbpObservable> observable2 = NbpObservable.just(m3, m4); + Observable> observable2 = Observable.just(m3, m4); - NbpObservable>> o = NbpObservable.just(observable1, observable2); + Observable>> o = Observable.just(observable1, observable2); - NbpObservable m = o.flatMap(new Function>, NbpObservable>() { + Observable m = o.flatMap(new Function>, Observable>() { @Override - public NbpObservable apply(NbpObservable> o) { + public Observable apply(Observable> o) { return o.map(new Function, String>() { @Override @@ -145,8 +146,8 @@ public String apply(Map map) { @Test public void testMapWithError() { - NbpObservable w = NbpObservable.just("one", "fail", "two", "three", "fail"); - NbpObservable m = w.map(new Function() { + Observable w = Observable.just("one", "fail", "two", "three", "fail"); + Observable m = w.map(new Function() { @Override public String apply(String s) { if ("fail".equals(s)) { @@ -173,7 +174,7 @@ public void accept(Throwable t1) { @Test(expected = IllegalArgumentException.class) public void testMapWithIssue417() { - NbpObservable.just(1).observeOn(Schedulers.computation()) + Observable.just(1).observeOn(Schedulers.computation()) .map(new Function() { @Override public Integer apply(Integer arg0) { @@ -187,7 +188,7 @@ public void testMapWithErrorInFuncAndThreadPoolScheduler() throws InterruptedExc // The error will throw in one of threads in the thread pool. // If map does not handle it, the error will disappear. // so map needs to handle the error by itself. - NbpObservable m = NbpObservable.just("one") + Observable m = Observable.just("one") .observeOn(Schedulers.computation()) .map(new Function() { @Override @@ -205,7 +206,7 @@ public String apply(String arg0) { */ @Test(expected = NoSuchElementException.class) public void testErrorPassesThruMap() { - NbpObservable.range(1, 0).last().map(new Function() { + Observable.range(1, 0).last().map(new Function() { @Override public Integer apply(Integer i) { @@ -220,7 +221,7 @@ public Integer apply(Integer i) { */ @Test(expected = IllegalStateException.class) public void testErrorPassesThruMap2() { - NbpObservable.error(new IllegalStateException()).map(new Function() { + Observable.error(new IllegalStateException()).map(new Function() { @Override public Object apply(Object i) { @@ -236,7 +237,7 @@ public Object apply(Object i) { */ @Test(expected = ArithmeticException.class) public void testMapWithErrorInFunc() { - NbpObservable.range(1, 1).last().map(new Function() { + Observable.range(1, 1).last().map(new Function() { @Override public Integer apply(Integer i) { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMaterializeTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMaterializeTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMaterializeTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMaterializeTest.java index 22fc568875..48d05e4300 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMaterializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMaterializeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; @@ -21,11 +21,13 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; +import io.reactivex.Optional; import io.reactivex.functions.Consumer; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; -import io.reactivex.Optional; +import io.reactivex.observers.*; public class NbpOperatorMaterializeTest { @@ -36,8 +38,8 @@ public void testMaterialize1() { final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", null, "three"); - TestObserver NbpObserver = new TestObserver(); - NbpObservable>> m = NbpObservable.create(o1).materialize(); + TestLocalObserver NbpObserver = new TestLocalObserver(); + Observable>> m = Observable.create(o1).materialize(); m.subscribe(NbpObserver); try { @@ -61,8 +63,8 @@ public void testMaterialize1() { public void testMaterialize2() { final TestAsyncErrorObservable o1 = new TestAsyncErrorObservable("one", "two", "three"); - TestObserver NbpObserver = new TestObserver(); - NbpObservable>> m = NbpObservable.create(o1).materialize(); + TestLocalObserver NbpObserver = new TestLocalObserver(); + Observable>> m = Observable.create(o1).materialize(); m.subscribe(NbpObserver); try { @@ -87,7 +89,7 @@ public void testMaterialize2() { public void testMultipleSubscribes() throws InterruptedException, ExecutionException { final TestAsyncErrorObservable o = new TestAsyncErrorObservable("one", "two", null, "three"); - NbpObservable>> m = NbpObservable.create(o).materialize(); + Observable>> m = Observable.create(o).materialize(); assertEquals(3, m.toList().toBlocking().toFuture().get().size()); assertEquals(3, m.toList().toBlocking().toFuture().get().size()); @@ -95,9 +97,9 @@ public void testMultipleSubscribes() throws InterruptedException, ExecutionExcep @Test public void testWithCompletionCausingError() { - NbpTestSubscriber>> ts = new NbpTestSubscriber>>(); + TestObserver>> ts = new TestObserver>>(); final RuntimeException ex = new RuntimeException("boo"); - NbpObservable.empty().materialize().doOnNext(new Consumer() { + Observable.empty().materialize().doOnNext(new Consumer() { @Override public void accept(Object t) { throw ex; @@ -108,7 +110,7 @@ public void accept(Object t) { ts.assertTerminated(); } - private static class TestObserver extends NbpObserver>> { + private static class TestLocalObserver extends DefaultObserver>> { boolean onCompleted = false; boolean onError = false; @@ -142,7 +144,7 @@ private static class TestAsyncErrorObservable implements NbpOnSubscribe volatile Thread t; @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); t = new Thread(new Runnable() { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMergeDelayErrorTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMergeDelayErrorTest.java similarity index 71% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMergeDelayErrorTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMergeDelayErrorTest.java index 1b9cc17d22..843dbf1be0 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMergeDelayErrorTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMergeDelayErrorTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -23,15 +23,17 @@ import org.junit.*; import org.mockito.InOrder; -import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.exceptions.*; +import io.reactivex.flowable.TestHelper; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.*; public class NbpOperatorMergeDelayErrorTest { - NbpSubscriber stringObserver; + Observer stringObserver; @Before public void before() { @@ -40,10 +42,10 @@ public void before() { @Test public void testErrorDelayed1() { - final NbpObservable o1 = NbpObservable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called - final NbpObservable o2 = NbpObservable.create(new TestErrorObservable("one", "two", "three")); + final Observable o1 = Observable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called + final Observable o2 = Observable.create(new TestErrorObservable("one", "two", "three")); - NbpObservable m = NbpObservable.mergeDelayError(o1, o2); + Observable m = Observable.mergeDelayError(o1, o2); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); @@ -61,12 +63,12 @@ public void testErrorDelayed1() { @Test public void testErrorDelayed2() { - final NbpObservable o1 = NbpObservable.create(new TestErrorObservable("one", "two", "three")); - final NbpObservable o2 = NbpObservable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called - final NbpObservable o3 = NbpObservable.create(new TestErrorObservable("seven", "eight", null)); - final NbpObservable o4 = NbpObservable.create(new TestErrorObservable("nine")); + final Observable o1 = Observable.create(new TestErrorObservable("one", "two", "three")); + final Observable o2 = Observable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called + final Observable o3 = Observable.create(new TestErrorObservable("seven", "eight", null)); + final Observable o4 = Observable.create(new TestErrorObservable("nine")); - NbpObservable m = NbpObservable.mergeDelayError(o1, o2, o3, o4); + Observable m = Observable.mergeDelayError(o1, o2, o3, o4); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); @@ -86,12 +88,12 @@ public void testErrorDelayed2() { @Test public void testErrorDelayed3() { - final NbpObservable o1 = NbpObservable.create(new TestErrorObservable("one", "two", "three")); - final NbpObservable o2 = NbpObservable.create(new TestErrorObservable("four", "five", "six")); - final NbpObservable o3 = NbpObservable.create(new TestErrorObservable("seven", "eight", null)); - final NbpObservable o4 = NbpObservable.create(new TestErrorObservable("nine")); + final Observable o1 = Observable.create(new TestErrorObservable("one", "two", "three")); + final Observable o2 = Observable.create(new TestErrorObservable("four", "five", "six")); + final Observable o3 = Observable.create(new TestErrorObservable("seven", "eight", null)); + final Observable o4 = Observable.create(new TestErrorObservable("nine")); - NbpObservable m = NbpObservable.mergeDelayError(o1, o2, o3, o4); + Observable m = Observable.mergeDelayError(o1, o2, o3, o4); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); @@ -109,12 +111,12 @@ public void testErrorDelayed3() { @Test public void testErrorDelayed4() { - final NbpObservable o1 = NbpObservable.create(new TestErrorObservable("one", "two", "three")); - final NbpObservable o2 = NbpObservable.create(new TestErrorObservable("four", "five", "six")); - final NbpObservable o3 = NbpObservable.create(new TestErrorObservable("seven", "eight")); - final NbpObservable o4 = NbpObservable.create(new TestErrorObservable("nine", null)); + final Observable o1 = Observable.create(new TestErrorObservable("one", "two", "three")); + final Observable o2 = Observable.create(new TestErrorObservable("four", "five", "six")); + final Observable o3 = Observable.create(new TestErrorObservable("seven", "eight")); + final Observable o4 = Observable.create(new TestErrorObservable("nine", null)); - NbpObservable m = NbpObservable.mergeDelayError(o1, o2, o3, o4); + Observable m = Observable.mergeDelayError(o1, o2, o3, o4); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); @@ -138,7 +140,7 @@ public void testErrorDelayed4WithThreading() { // throw the error at the very end so no onComplete will be called after it final TestAsyncErrorObservable o4 = new TestAsyncErrorObservable("nine", null); - NbpObservable m = NbpObservable.mergeDelayError(NbpObservable.create(o1), NbpObservable.create(o2), NbpObservable.create(o3), NbpObservable.create(o4)); + Observable m = Observable.mergeDelayError(Observable.create(o1), Observable.create(o2), Observable.create(o3), Observable.create(o4)); m.subscribe(stringObserver); try { @@ -165,10 +167,10 @@ public void testErrorDelayed4WithThreading() { @Test public void testCompositeErrorDelayed1() { - final NbpObservable o1 = NbpObservable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called - final NbpObservable o2 = NbpObservable.create(new TestErrorObservable("one", "two", null)); + final Observable o1 = Observable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called + final Observable o2 = Observable.create(new TestErrorObservable("one", "two", null)); - NbpObservable m = NbpObservable.mergeDelayError(o1, o2); + Observable m = Observable.mergeDelayError(o1, o2); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(Throwable.class)); @@ -185,10 +187,10 @@ public void testCompositeErrorDelayed1() { @Test public void testCompositeErrorDelayed2() { - final NbpObservable o1 = NbpObservable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called - final NbpObservable o2 = NbpObservable.create(new TestErrorObservable("one", "two", null)); + final Observable o1 = Observable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" from the source (and it should never be sent by the source since onError was called + final Observable o2 = Observable.create(new TestErrorObservable("one", "two", null)); - NbpObservable m = NbpObservable.mergeDelayError(o1, o2); + Observable m = Observable.mergeDelayError(o1, o2); CaptureObserver w = new CaptureObserver(); m.subscribe(w); @@ -211,13 +213,13 @@ public void testCompositeErrorDelayed2() { @Test public void testMergeObservableOfObservables() { - final NbpObservable o1 = NbpObservable.create(new TestSynchronousObservable()); - final NbpObservable o2 = NbpObservable.create(new TestSynchronousObservable()); + final Observable o1 = Observable.create(new TestSynchronousObservable()); + final Observable o2 = Observable.create(new TestSynchronousObservable()); - NbpObservable> observableOfObservables = NbpObservable.create(new NbpOnSubscribe>() { + Observable> observableOfObservables = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(NbpSubscriber> NbpObserver) { + public void accept(Observer> NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); // simulate what would happen in an NbpObservable NbpObserver.onNext(o1); @@ -226,7 +228,7 @@ public void accept(NbpSubscriber> NbpObserver) { } }); - NbpObservable m = NbpObservable.mergeDelayError(observableOfObservables); + Observable m = Observable.mergeDelayError(observableOfObservables); m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -236,10 +238,10 @@ public void accept(NbpSubscriber> NbpObserver) { @Test public void testMergeArray() { - final NbpObservable o1 = NbpObservable.create(new TestSynchronousObservable()); - final NbpObservable o2 = NbpObservable.create(new TestSynchronousObservable()); + final Observable o1 = Observable.create(new TestSynchronousObservable()); + final Observable o2 = Observable.create(new TestSynchronousObservable()); - NbpObservable m = NbpObservable.mergeDelayError(o1, o2); + Observable m = Observable.mergeDelayError(o1, o2); m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -249,13 +251,13 @@ public void testMergeArray() { @Test public void testMergeList() { - final NbpObservable o1 = NbpObservable.create(new TestSynchronousObservable()); - final NbpObservable o2 = NbpObservable.create(new TestSynchronousObservable()); - List> listOfObservables = new ArrayList>(); + final Observable o1 = Observable.create(new TestSynchronousObservable()); + final Observable o2 = Observable.create(new TestSynchronousObservable()); + List> listOfObservables = new ArrayList>(); listOfObservables.add(o1); listOfObservables.add(o2); - NbpObservable m = NbpObservable.mergeDelayError(NbpObservable.fromIterable(listOfObservables)); + Observable m = Observable.mergeDelayError(Observable.fromIterable(listOfObservables)); m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -268,7 +270,7 @@ public void testMergeArrayWithThreading() { final TestASynchronousObservable o1 = new TestASynchronousObservable(); final TestASynchronousObservable o2 = new TestASynchronousObservable(); - NbpObservable m = NbpObservable.mergeDelayError(NbpObservable.create(o1), NbpObservable.create(o2)); + Observable m = Observable.mergeDelayError(Observable.create(o1), Observable.create(o2)); m.subscribe(stringObserver); try { @@ -285,10 +287,10 @@ public void testMergeArrayWithThreading() { @Test(timeout = 1000L) public void testSynchronousError() { - final NbpObservable> o1 = NbpObservable.error(new RuntimeException("unit test")); + final Observable> o1 = Observable.error(new RuntimeException("unit test")); final CountDownLatch latch = new CountDownLatch(1); - NbpObservable.mergeDelayError(o1).subscribe(new NbpObserver() { + Observable.mergeDelayError(o1).subscribe(new DefaultObserver() { @Override public void onComplete() { fail("Expected onError path"); @@ -315,7 +317,7 @@ public void onNext(String s) { private static class TestSynchronousObservable implements NbpOnSubscribe { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); NbpObserver.onNext("hello"); NbpObserver.onComplete(); @@ -326,7 +328,7 @@ private static class TestASynchronousObservable implements NbpOnSubscribe NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); t = new Thread(new Runnable() { @@ -350,7 +352,7 @@ private static class TestErrorObservable implements NbpOnSubscribe { } @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); boolean errorThrown = false; for (String s : valuesToReturn) { @@ -381,7 +383,7 @@ private static class TestAsyncErrorObservable implements NbpOnSubscribe Thread t; @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); t = new Thread(new Runnable() { @@ -410,7 +412,7 @@ public void run() { } } - private static class CaptureObserver extends NbpObserver { + private static class CaptureObserver extends DefaultObserver { volatile Throwable e; @Override @@ -432,9 +434,9 @@ public void onNext(String args) { @Test @Ignore("Subscribers should not throw") public void testMergeSourceWhichDoesntPropagateExceptionBack() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber t1) { + public void accept(Observer t1) { t1.onSubscribe(EmptyDisposable.INSTANCE); try { t1.onNext(0); @@ -446,12 +448,12 @@ public void accept(NbpSubscriber t1) { } }); - NbpObservable result = NbpObservable.mergeDelayError(source, NbpObservable.just(2)); + Observable result = Observable.mergeDelayError(source, Observable.just(2)); - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + final Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); - result.unsafeSubscribe(new NbpObserver() { + result.unsafeSubscribe(new DefaultObserver() { int calls; @Override public void onNext(Integer t) { @@ -487,10 +489,10 @@ public void onComplete() { @Test public void testErrorInParentObservable() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.mergeDelayError( - NbpObservable.just(NbpObservable.just(1), NbpObservable.just(2)) - .startWith(NbpObservable. error(new RuntimeException())) + TestObserver ts = new TestObserver(); + Observable.mergeDelayError( + Observable.just(Observable.just(1), Observable.just(2)) + .startWith(Observable. error(new RuntimeException())) ).subscribe(ts); ts.awaitTerminalEvent(); ts.assertTerminated(); @@ -504,20 +506,20 @@ public void testErrorInParentObservableDelayed() throws Exception { for (int i = 0; i < 50; i++) { final TestASynchronous1sDelayedObservable o1 = new TestASynchronous1sDelayedObservable(); final TestASynchronous1sDelayedObservable o2 = new TestASynchronous1sDelayedObservable(); - NbpObservable> parentObservable = NbpObservable.create(new NbpOnSubscribe>() { + Observable> parentObservable = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(NbpSubscriber> op) { + public void accept(Observer> op) { op.onSubscribe(EmptyDisposable.INSTANCE); - op.onNext(NbpObservable.create(o1)); - op.onNext(NbpObservable.create(o2)); + op.onNext(Observable.create(o1)); + op.onNext(Observable.create(o2)); op.onError(new NullPointerException("throwing exception in parent")); } }); - NbpSubscriber stringObserver = TestHelper.mockNbpSubscriber(); + Observer stringObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(stringObserver); - NbpObservable m = NbpObservable.mergeDelayError(parentObservable); + TestObserver ts = new TestObserver(stringObserver); + Observable m = Observable.mergeDelayError(parentObservable); m.subscribe(ts); System.out.println("testErrorInParentObservableDelayed | " + i); ts.awaitTerminalEvent(2000, TimeUnit.MILLISECONDS); @@ -533,7 +535,7 @@ private static class TestASynchronous1sDelayedObservable implements NbpOnSubscri Thread t; @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); t = new Thread(new Runnable() { diff --git a/src/test/java/io/reactivex/internal/operators/OperatorMergeMaxConcurrentTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMergeMaxConcurrentTest.java similarity index 83% rename from src/test/java/io/reactivex/internal/operators/OperatorMergeMaxConcurrentTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMergeMaxConcurrentTest.java index f83024c98d..754cf7593c 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorMergeMaxConcurrentTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMergeMaxConcurrentTest.java @@ -11,31 +11,32 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import java.util.*; -import java.util.concurrent.*; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.junit.*; -import org.reactivestreams.*; import io.reactivex.Observable; -import io.reactivex.TestHelper; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; +import io.reactivex.flowable.TestHelper; +import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.schedulers.IOScheduler; -import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; -public class OperatorMergeMaxConcurrentTest { +public class NbpOperatorMergeMaxConcurrentTest { - Subscriber stringObserver; + Observer stringObserver; @Before public void before() { - stringObserver = TestHelper.mockSubscriber(); + stringObserver = TestHelper.mockNbpSubscriber(); } @Test @@ -85,7 +86,7 @@ public void testMaxConcurrent() { } } - private static class SubscriptionCheckObservable implements Publisher { + private static class SubscriptionCheckObservable implements NbpOnSubscribe { private final AtomicInteger subscriptionCount; private final int maxConcurrent; @@ -97,8 +98,8 @@ private static class SubscriptionCheckObservable implements Publisher { } @Override - public void subscribe(final Subscriber t1) { - t1.onSubscribe(EmptySubscription.INSTANCE); + public void accept(final Observer t1) { + t1.onSubscribe(EmptyDisposable.INSTANCE); new Thread(new Runnable() { @Override @@ -156,7 +157,7 @@ public void testMergeALotOfSourcesOneByOneSynchronouslyTakeHalf() { @Test public void testSimple() { for (int i = 1; i < 100; i++) { - TestSubscriber ts = new TestSubscriber(); + TestObserver ts = new TestObserver(); List> sourceList = new ArrayList>(i); List result = new ArrayList(i); for (int j = 1; j <= i; j++) { @@ -174,7 +175,7 @@ public void testSimple() { @Test public void testSimpleOneLess() { for (int i = 2; i < 100; i++) { - TestSubscriber ts = new TestSubscriber(); + TestObserver ts = new TestObserver(); List> sourceList = new ArrayList>(i); List result = new ArrayList(i); for (int j = 1; j <= i; j++) { @@ -204,7 +205,7 @@ public void testSimpleAsyncLoop() { @Test(timeout = 10000) public void testSimpleAsync() { for (int i = 1; i < 50; i++) { - TestSubscriber ts = new TestSubscriber(); + TestObserver ts = new TestObserver(); List> sourceList = new ArrayList>(i); Set expected = new HashSet(i); for (int j = 1; j <= i; j++) { @@ -234,7 +235,7 @@ public void testSimpleOneLessAsync() { if (System.currentTimeMillis() - t > TimeUnit.SECONDS.toMillis(9)) { break; } - TestSubscriber ts = new TestSubscriber(); + TestObserver ts = new TestObserver(); List> sourceList = new ArrayList>(i); Set expected = new HashSet(i); for (int j = 1; j <= i; j++) { @@ -251,36 +252,7 @@ public void testSimpleOneLessAsync() { assertEquals(expected, actual); } } - @Test(timeout = 5000) - public void testBackpressureHonored() throws Exception { - List> sourceList = new ArrayList>(3); - - sourceList.add(Observable.range(0, 100000).subscribeOn(Schedulers.io())); - sourceList.add(Observable.range(0, 100000).subscribeOn(Schedulers.io())); - sourceList.add(Observable.range(0, 100000).subscribeOn(Schedulers.io())); - - final CountDownLatch cdl = new CountDownLatch(5); - - TestSubscriber ts = new TestSubscriber((Long)null) { - @Override - public void onNext(Integer t) { - super.onNext(t); - cdl.countDown(); - } - }; - - Observable.merge(sourceList, 2).subscribe(ts); - - ts.request(5); - - cdl.await(); - - ts.assertNoErrors(); - ts.assertValueCount(5); - ts.assertNotComplete(); - - ts.dispose(); - } + @Test(timeout = 5000) public void testTake() throws Exception { List> sourceList = new ArrayList>(3); @@ -289,7 +261,7 @@ public void testTake() throws Exception { sourceList.add(Observable.range(0, 100000).subscribeOn(Schedulers.io())); sourceList.add(Observable.range(0, 100000).subscribeOn(Schedulers.io())); - TestSubscriber ts = new TestSubscriber(); + TestObserver ts = new TestObserver(); Observable.merge(sourceList, 2).take(5).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMergeTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMergeTest.java similarity index 72% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMergeTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMergeTest.java index a30b0f4492..858e079a40 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMergeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -24,18 +24,20 @@ import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.*; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.*; import io.reactivex.schedulers.*; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; -import io.reactivex.Observable; public class NbpOperatorMergeTest { - NbpSubscriber stringObserver; + Observer stringObserver; int count; @@ -70,13 +72,13 @@ public void after() { @Test public void testMergeObservableOfObservables() { - final NbpObservable o1 = NbpObservable.create(new TestSynchronousObservable()); - final NbpObservable o2 = NbpObservable.create(new TestSynchronousObservable()); + final Observable o1 = Observable.create(new TestSynchronousObservable()); + final Observable o2 = Observable.create(new TestSynchronousObservable()); - NbpObservable> observableOfObservables = NbpObservable.create(new NbpOnSubscribe>() { + Observable> observableOfObservables = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(NbpSubscriber> NbpObserver) { + public void accept(Observer> NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); // simulate what would happen in an NbpObservable NbpObserver.onNext(o1); @@ -85,7 +87,7 @@ public void accept(NbpSubscriber> NbpObserver) { } }); - NbpObservable m = NbpObservable.merge(observableOfObservables); + Observable m = Observable.merge(observableOfObservables); m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -95,10 +97,10 @@ public void accept(NbpSubscriber> NbpObserver) { @Test public void testMergeArray() { - final NbpObservable o1 = NbpObservable.create(new TestSynchronousObservable()); - final NbpObservable o2 = NbpObservable.create(new TestSynchronousObservable()); + final Observable o1 = Observable.create(new TestSynchronousObservable()); + final Observable o2 = Observable.create(new TestSynchronousObservable()); - NbpObservable m = NbpObservable.merge(o1, o2); + Observable m = Observable.merge(o1, o2); m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -108,13 +110,13 @@ public void testMergeArray() { @Test public void testMergeList() { - final NbpObservable o1 = NbpObservable.create(new TestSynchronousObservable()); - final NbpObservable o2 = NbpObservable.create(new TestSynchronousObservable()); - List> listOfObservables = new ArrayList>(); + final Observable o1 = Observable.create(new TestSynchronousObservable()); + final Observable o2 = Observable.create(new TestSynchronousObservable()); + List> listOfObservables = new ArrayList>(); listOfObservables.add(o1); listOfObservables.add(o2); - NbpObservable m = NbpObservable.merge(listOfObservables); + Observable m = Observable.merge(listOfObservables); m.subscribe(stringObserver); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -128,10 +130,10 @@ public void testUnSubscribeObservableOfObservables() throws InterruptedException final AtomicBoolean unsubscribed = new AtomicBoolean(); final CountDownLatch latch = new CountDownLatch(1); - NbpObservable> source = NbpObservable.create(new NbpOnSubscribe>() { + Observable> source = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(final NbpSubscriber> NbpObserver) { + public void accept(final Observer> NbpObserver) { // verbose on purpose so I can track the inside of it final Disposable s = new Disposable() { @Override @@ -148,7 +150,7 @@ public void dispose() { public void run() { while (!unsubscribed.get()) { - NbpObserver.onNext(NbpObservable.just(1L, 2L)); + NbpObserver.onNext(Observable.just(1L, 2L)); } System.out.println("Done looping after unsubscribe: " + unsubscribed.get()); NbpObserver.onComplete(); @@ -162,7 +164,7 @@ public void run() { }); final AtomicInteger count = new AtomicInteger(); - NbpObservable.merge(source).take(6).toBlocking().forEach(new Consumer() { + Observable.merge(source).take(6).toBlocking().forEach(new Consumer() { @Override public void accept(Long v) { @@ -188,8 +190,8 @@ public void testMergeArrayWithThreading() { final TestASynchronousObservable o1 = new TestASynchronousObservable(); final TestASynchronousObservable o2 = new TestASynchronousObservable(); - NbpObservable m = NbpObservable.merge(NbpObservable.create(o1), NbpObservable.create(o2)); - NbpTestSubscriber ts = new NbpTestSubscriber(stringObserver); + Observable m = Observable.merge(Observable.create(o1), Observable.create(o2)); + TestObserver ts = new TestObserver(stringObserver); m.subscribe(ts); ts.awaitTerminalEvent(); @@ -219,8 +221,8 @@ public void testSynchronizationOfMultipleSequences() throws Throwable { final AtomicInteger concurrentCounter = new AtomicInteger(); final AtomicInteger totalCounter = new AtomicInteger(); - NbpObservable m = NbpObservable.merge(NbpObservable.create(o1), NbpObservable.create(o2)); - m.subscribe(new NbpObserver() { + Observable m = Observable.merge(Observable.create(o1), Observable.create(o2)); + m.subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -289,10 +291,10 @@ public void onNext(String v) { @Test public void testError1() { // we are using synchronous execution to test this exactly rather than non-deterministic concurrent behavior - final NbpObservable o1 = NbpObservable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" - final NbpObservable o2 = NbpObservable.create(new TestErrorObservable("one", "two", "three")); // we expect to lose all of these since o1 is done first and fails + final Observable o1 = Observable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" + final Observable o2 = Observable.create(new TestErrorObservable("one", "two", "three")); // we expect to lose all of these since o1 is done first and fails - NbpObservable m = NbpObservable.merge(o1, o2); + Observable m = Observable.merge(o1, o2); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); @@ -311,12 +313,12 @@ public void testError1() { @Test public void testError2() { // we are using synchronous execution to test this exactly rather than non-deterministic concurrent behavior - final NbpObservable o1 = NbpObservable.create(new TestErrorObservable("one", "two", "three")); - final NbpObservable o2 = NbpObservable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" - final NbpObservable o3 = NbpObservable.create(new TestErrorObservable("seven", "eight", null));// we expect to lose all of these since o2 is done first and fails - final NbpObservable o4 = NbpObservable.create(new TestErrorObservable("nine"));// we expect to lose all of these since o2 is done first and fails + final Observable o1 = Observable.create(new TestErrorObservable("one", "two", "three")); + final Observable o2 = Observable.create(new TestErrorObservable("four", null, "six")); // we expect to lose "six" + final Observable o3 = Observable.create(new TestErrorObservable("seven", "eight", null));// we expect to lose all of these since o2 is done first and fails + final Observable o4 = Observable.create(new TestErrorObservable("nine"));// we expect to lose all of these since o2 is done first and fails - NbpObservable m = NbpObservable.merge(o1, o2, o3, o4); + Observable m = Observable.merge(o1, o2, o3, o4); m.subscribe(stringObserver); verify(stringObserver, times(1)).onError(any(NullPointerException.class)); @@ -335,17 +337,17 @@ public void testError2() { @Test @Ignore("Subscribe should not throw") public void testThrownErrorHandling() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable o1 = NbpObservable.create(new NbpOnSubscribe() { + TestObserver ts = new TestObserver(); + Observable o1 = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { throw new RuntimeException("fail"); } }); - NbpObservable.merge(o1, o1).subscribe(ts); + Observable.merge(o1, o1).subscribe(ts); ts.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); ts.assertTerminated(); System.out.println("Error: " + ts.errors()); @@ -354,7 +356,7 @@ public void accept(NbpSubscriber s) { private static class TestSynchronousObservable implements NbpOnSubscribe { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); NbpObserver.onNext("hello"); NbpObserver.onComplete(); @@ -366,7 +368,7 @@ private static class TestASynchronousObservable implements NbpOnSubscribe NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); t = new Thread(new Runnable() { @@ -397,7 +399,7 @@ private static class TestErrorObservable implements NbpOnSubscribe { } @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); for (String s : valuesToReturn) { if (s == null) { @@ -415,14 +417,14 @@ public void accept(NbpSubscriber NbpObserver) { public void testUnsubscribeAsObservablesComplete() { TestScheduler scheduler1 = Schedulers.test(); AtomicBoolean os1 = new AtomicBoolean(false); - NbpObservable o1 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler1, os1); + Observable o1 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler1, os1); TestScheduler scheduler2 = Schedulers.test(); AtomicBoolean os2 = new AtomicBoolean(false); - NbpObservable o2 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); + Observable o2 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.merge(o1, o2).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.merge(o1, o2).subscribe(ts); // we haven't incremented time so nothing should be received yet ts.assertNoValues(); @@ -457,14 +459,14 @@ public void testEarlyUnsubscribe() { for (int i = 0; i < 10; i++) { TestScheduler scheduler1 = Schedulers.test(); AtomicBoolean os1 = new AtomicBoolean(false); - NbpObservable o1 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler1, os1); + Observable o1 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler1, os1); TestScheduler scheduler2 = Schedulers.test(); AtomicBoolean os2 = new AtomicBoolean(false); - NbpObservable o2 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); + Observable o2 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.merge(o1, o2).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.merge(o1, o2).subscribe(ts); // we haven't incremented time so nothing should be received yet ts.assertNoValues(); @@ -489,14 +491,14 @@ public void testEarlyUnsubscribe() { } } - private NbpObservable createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(final Scheduler scheduler, final AtomicBoolean unsubscribed) { - return NbpObservable.create(new NbpOnSubscribe() { + private Observable createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(final Scheduler scheduler, final AtomicBoolean unsubscribed) { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber child) { - NbpObservable.interval(1, TimeUnit.SECONDS, scheduler) + public void accept(final Observer child) { + Observable.interval(1, TimeUnit.SECONDS, scheduler) .take(5) - .subscribe(new NbpSubscriber() { + .subscribe(new Observer() { @Override public void onSubscribe(final Disposable s) { child.onSubscribe(new Disposable() { @@ -532,11 +534,11 @@ public void onComplete() { @Test//(timeout = 10000) public void testConcurrency() { - NbpObservable o = NbpObservable.range(1, 10000).subscribeOn(Schedulers.newThread()); + Observable o = Observable.range(1, 10000).subscribeOn(Schedulers.newThread()); for (int i = 0; i < 10; i++) { - NbpObservable merge = NbpObservable.merge(o, o, o); - NbpTestSubscriber ts = new NbpTestSubscriber(); + Observable merge = Observable.merge(o, o, o); + TestObserver ts = new TestObserver(); merge.subscribe(ts); ts.awaitTerminalEvent(3, TimeUnit.SECONDS); @@ -552,10 +554,10 @@ public void testConcurrency() { @Test public void testConcurrencyWithSleeping() { - NbpObservable o = NbpObservable.create(new NbpOnSubscribe() { + Observable o = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber s) { + public void accept(final Observer s) { Worker inner = Schedulers.newThread().createWorker(); final CompositeDisposable as = new CompositeDisposable(); as.add(EmptyDisposable.INSTANCE); @@ -588,8 +590,8 @@ public void run() { }); for (int i = 0; i < 10; i++) { - NbpObservable merge = NbpObservable.merge(o, o, o); - NbpTestSubscriber ts = new NbpTestSubscriber(); + Observable merge = Observable.merge(o, o, o); + TestObserver ts = new TestObserver(); merge.subscribe(ts); ts.awaitTerminalEvent(); @@ -602,10 +604,10 @@ public void run() { @Test public void testConcurrencyWithBrokenOnCompleteContract() { - NbpObservable o = NbpObservable.create(new NbpOnSubscribe() { + Observable o = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber s) { + public void accept(final Observer s) { Worker inner = Schedulers.newThread().createWorker(); final CompositeDisposable as = new CompositeDisposable(); as.add(EmptyDisposable.INSTANCE); @@ -635,8 +637,8 @@ public void run() { }); for (int i = 0; i < 10; i++) { - NbpObservable merge = NbpObservable.merge(o, o, o); - NbpTestSubscriber ts = new NbpTestSubscriber(); + Observable merge = Observable.merge(o, o, o); + TestObserver ts = new TestObserver(); merge.subscribe(ts); ts.awaitTerminalEvent(); @@ -651,11 +653,11 @@ public void run() { @Test public void testBackpressureUpstream() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - NbpObservable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); + Observable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); final AtomicInteger generated2 = new AtomicInteger(); - NbpObservable o2 = createInfiniteObservable(generated2).subscribeOn(Schedulers.computation()); + Observable o2 = createInfiniteObservable(generated2).subscribeOn(Schedulers.computation()); - NbpTestSubscriber NbpTestSubscriber = new NbpTestSubscriber() { + TestObserver NbpTestSubscriber = new TestObserver() { @Override public void onNext(Integer t) { System.err.println("NbpTestSubscriber received => " + t + " on thread " + Thread.currentThread()); @@ -663,19 +665,19 @@ public void onNext(Integer t) { } }; - NbpObservable.merge(o1.take(Observable.bufferSize() * 2), o2.take(Observable.bufferSize() * 2)).subscribe(NbpTestSubscriber); + Observable.merge(o1.take(Flowable.bufferSize() * 2), o2.take(Flowable.bufferSize() * 2)).subscribe(NbpTestSubscriber); NbpTestSubscriber.awaitTerminalEvent(); if (NbpTestSubscriber.errors().size() > 0) { NbpTestSubscriber.errors().get(0).printStackTrace(); } NbpTestSubscriber.assertNoErrors(); System.err.println(NbpTestSubscriber.values()); - assertEquals(Observable.bufferSize() * 4, NbpTestSubscriber.values().size()); + assertEquals(Flowable.bufferSize() * 4, NbpTestSubscriber.values().size()); // it should be between the take num and requested batch size across the async boundary System.out.println("Generated 1: " + generated1.get()); System.out.println("Generated 2: " + generated2.get()); - assertTrue(generated1.get() >= Observable.bufferSize() * 2 - && generated1.get() <= Observable.bufferSize() * 4); + assertTrue(generated1.get() >= Flowable.bufferSize() * 2 + && generated1.get() <= Flowable.bufferSize() * 4); } @Test @@ -691,16 +693,16 @@ public void testBackpressureUpstream2InLoop() throws InterruptedException { @Test public void testBackpressureUpstream2() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - NbpObservable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); + Observable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); - NbpTestSubscriber NbpTestSubscriber = new NbpTestSubscriber() { + TestObserver NbpTestSubscriber = new TestObserver() { @Override public void onNext(Integer t) { super.onNext(t); } }; - NbpObservable.merge(o1.take(Observable.bufferSize() * 2), NbpObservable.just(-99)).subscribe(NbpTestSubscriber); + Observable.merge(o1.take(Flowable.bufferSize() * 2), Observable.just(-99)).subscribe(NbpTestSubscriber); NbpTestSubscriber.awaitTerminalEvent(); List onNextEvents = NbpTestSubscriber.values(); @@ -712,9 +714,9 @@ public void onNext(Integer t) { NbpTestSubscriber.errors().get(0).printStackTrace(); } NbpTestSubscriber.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2 + 1, onNextEvents.size()); + assertEquals(Flowable.bufferSize() * 2 + 1, onNextEvents.size()); // it should be between the take num and requested batch size across the async boundary - assertTrue(generated1.get() >= Observable.bufferSize() * 2 && generated1.get() <= Observable.bufferSize() * 3); + assertTrue(generated1.get() >= Flowable.bufferSize() * 2 && generated1.get() <= Flowable.bufferSize() * 3); } /** @@ -726,11 +728,11 @@ public void onNext(Integer t) { @Test(timeout = 10000) public void testBackpressureDownstreamWithConcurrentStreams() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - NbpObservable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); + Observable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); final AtomicInteger generated2 = new AtomicInteger(); - NbpObservable o2 = createInfiniteObservable(generated2).subscribeOn(Schedulers.computation()); + Observable o2 = createInfiniteObservable(generated2).subscribeOn(Schedulers.computation()); - NbpTestSubscriber NbpTestSubscriber = new NbpTestSubscriber() { + TestObserver NbpTestSubscriber = new TestObserver() { @Override public void onNext(Integer t) { if (t < 100) @@ -745,18 +747,18 @@ public void onNext(Integer t) { } }; - NbpObservable.merge(o1.take(Observable.bufferSize() * 2), o2.take(Observable.bufferSize() * 2)).observeOn(Schedulers.computation()).subscribe(NbpTestSubscriber); + Observable.merge(o1.take(Flowable.bufferSize() * 2), o2.take(Flowable.bufferSize() * 2)).observeOn(Schedulers.computation()).subscribe(NbpTestSubscriber); NbpTestSubscriber.awaitTerminalEvent(); if (NbpTestSubscriber.errors().size() > 0) { NbpTestSubscriber.errors().get(0).printStackTrace(); } NbpTestSubscriber.assertNoErrors(); System.err.println(NbpTestSubscriber.values()); - assertEquals(Observable.bufferSize() * 4, NbpTestSubscriber.values().size()); + assertEquals(Flowable.bufferSize() * 4, NbpTestSubscriber.values().size()); // it should be between the take num and requested batch size across the async boundary System.out.println("Generated 1: " + generated1.get()); System.out.println("Generated 2: " + generated2.get()); - assertTrue(generated1.get() >= Observable.bufferSize() * 2 && generated1.get() <= Observable.bufferSize() * 4); + assertTrue(generated1.get() >= Flowable.bufferSize() * 2 && generated1.get() <= Flowable.bufferSize() * 4); } /** @@ -774,16 +776,16 @@ public void onNext(Integer t) { @Test(timeout = 5000) public void testBackpressureBothUpstreamAndDownstreamWithRegularObservables() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); - NbpObservable> o1 = createInfiniteObservable(generated1).map(new Function>() { + Observable> o1 = createInfiniteObservable(generated1).map(new Function>() { @Override - public NbpObservable apply(Integer t1) { - return NbpObservable.just(1, 2, 3); + public Observable apply(Integer t1) { + return Observable.just(1, 2, 3); } }); - NbpTestSubscriber NbpTestSubscriber = new NbpTestSubscriber() { + TestObserver NbpTestSubscriber = new TestObserver() { int i = 0; @Override @@ -800,7 +802,7 @@ public void onNext(Integer t) { } }; - NbpObservable.merge(o1).observeOn(Schedulers.computation()).take(Observable.bufferSize() * 2).subscribe(NbpTestSubscriber); + Observable.merge(o1).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(NbpTestSubscriber); NbpTestSubscriber.awaitTerminalEvent(); if (NbpTestSubscriber.errors().size() > 0) { NbpTestSubscriber.errors().get(0).printStackTrace(); @@ -809,7 +811,7 @@ public void onNext(Integer t) { System.out.println("Generated 1: " + generated1.get()); System.err.println(NbpTestSubscriber.values()); System.out.println("done1 testBackpressureBothUpstreamAndDownstreamWithRegularObservables "); - assertEquals(Observable.bufferSize() * 2, NbpTestSubscriber.values().size()); + assertEquals(Flowable.bufferSize() * 2, NbpTestSubscriber.values().size()); System.out.println("done2 testBackpressureBothUpstreamAndDownstreamWithRegularObservables "); // we can't restrict this ... see comment above // assertTrue(generated1.get() >= Observable.bufferSize() && generated1.get() <= Observable.bufferSize() * 4); @@ -819,8 +821,8 @@ public void onNext(Integer t) { @Ignore("Null values not permitted") public void mergeWithNullValues() { System.out.println("mergeWithNullValues"); - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.merge(NbpObservable.just(null, "one"), NbpObservable.just("two", null)).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.merge(Observable.just(null, "one"), Observable.just("two", null)).subscribe(ts); ts.assertTerminated(); ts.assertNoErrors(); ts.assertValues(null, "one", "two", null); @@ -830,11 +832,11 @@ public void mergeWithNullValues() { @Ignore("Null values are no longer permitted") public void mergeWithTerminalEventAfterUnsubscribe() { System.out.println("mergeWithTerminalEventAfterUnsubscribe"); - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable bad = NbpObservable.create(new NbpOnSubscribe() { + TestObserver ts = new TestObserver(); + Observable bad = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { s.onNext("two"); // FIXME can't cancel downstream // s.unsubscribe(); @@ -842,7 +844,7 @@ public void accept(NbpSubscriber s) { } }); - NbpObservable.merge(NbpObservable.just(null, "one"), bad).subscribe(ts); + Observable.merge(Observable.just(null, "one"), bad).subscribe(ts); ts.assertNoErrors(); ts.assertValues(null, "one", "two"); } @@ -850,15 +852,15 @@ public void accept(NbpSubscriber s) { @Test @Ignore("Null values are not permitted") public void mergingNullObservable() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.merge(NbpObservable.just("one"), null).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.merge(Observable.just("one"), null).subscribe(ts); ts.assertNoErrors(); ts.assertValue("one"); } @Test public void merge1AsyncStreamOf1() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); mergeNAsyncStreamsOfN(1, 1).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); @@ -867,7 +869,7 @@ public void merge1AsyncStreamOf1() { @Test public void merge1AsyncStreamOf1000() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); mergeNAsyncStreamsOfN(1, 1000).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); @@ -876,7 +878,7 @@ public void merge1AsyncStreamOf1000() { @Test public void merge10AsyncStreamOf1000() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); mergeNAsyncStreamsOfN(10, 1000).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); @@ -885,7 +887,7 @@ public void merge10AsyncStreamOf1000() { @Test public void merge1000AsyncStreamOf1000() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); mergeNAsyncStreamsOfN(1000, 1000).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); @@ -894,7 +896,7 @@ public void merge1000AsyncStreamOf1000() { @Test public void merge2000AsyncStreamOf100() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); mergeNAsyncStreamsOfN(2000, 100).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); @@ -903,29 +905,29 @@ public void merge2000AsyncStreamOf100() { @Test public void merge100AsyncStreamOf1() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); mergeNAsyncStreamsOfN(100, 1).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); assertEquals(100, ts.values().size()); } - private NbpObservable mergeNAsyncStreamsOfN(final int outerSize, final int innerSize) { - NbpObservable> os = NbpObservable.range(1, outerSize) - .map(new Function>() { + private Observable mergeNAsyncStreamsOfN(final int outerSize, final int innerSize) { + Observable> os = Observable.range(1, outerSize) + .map(new Function>() { @Override - public NbpObservable apply(Integer i) { - return NbpObservable.range(1, innerSize).subscribeOn(Schedulers.computation()); + public Observable apply(Integer i) { + return Observable.range(1, innerSize).subscribeOn(Schedulers.computation()); } }); - return NbpObservable.merge(os); + return Observable.merge(os); } @Test public void merge1SyncStreamOf1() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); mergeNSyncStreamsOfN(1, 1).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); @@ -934,7 +936,7 @@ public void merge1SyncStreamOf1() { @Test public void merge1SyncStreamOf1000000() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); mergeNSyncStreamsOfN(1, 1000000).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); @@ -943,7 +945,7 @@ public void merge1SyncStreamOf1000000() { @Test public void merge1000SyncStreamOf1000() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); mergeNSyncStreamsOfN(1000, 1000).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); @@ -952,7 +954,7 @@ public void merge1000SyncStreamOf1000() { @Test public void merge10000SyncStreamOf10() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); mergeNSyncStreamsOfN(10000, 10).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); @@ -961,28 +963,28 @@ public void merge10000SyncStreamOf10() { @Test public void merge1000000SyncStreamOf1() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); mergeNSyncStreamsOfN(1000000, 1).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); assertEquals(1000000, ts.values().size()); } - private NbpObservable mergeNSyncStreamsOfN(final int outerSize, final int innerSize) { - NbpObservable> os = NbpObservable.range(1, outerSize) - .map(new Function>() { + private Observable mergeNSyncStreamsOfN(final int outerSize, final int innerSize) { + Observable> os = Observable.range(1, outerSize) + .map(new Function>() { @Override - public NbpObservable apply(Integer i) { - return NbpObservable.range(1, innerSize); + public Observable apply(Integer i) { + return Observable.range(1, innerSize); } }); - return NbpObservable.merge(os); + return Observable.merge(os); } - private NbpObservable createInfiniteObservable(final AtomicInteger generated) { - NbpObservable o = NbpObservable.fromIterable(new Iterable() { + private Observable createInfiniteObservable(final AtomicInteger generated) { + Observable o = Observable.fromIterable(new Iterable() { @Override public Iterator iterator() { return new Iterator() { @@ -1008,16 +1010,16 @@ public boolean hasNext() { @Test public void mergeManyAsyncSingle() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable> os = NbpObservable.range(1, 10000) - .map(new Function>() { + TestObserver ts = new TestObserver(); + Observable> os = Observable.range(1, 10000) + .map(new Function>() { @Override - public NbpObservable apply(final Integer i) { - return NbpObservable.create(new NbpOnSubscribe() { + public Observable apply(final Integer i) { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { s.onSubscribe(EmptyDisposable.INSTANCE); if (i < 500) { try { @@ -1034,33 +1036,33 @@ public void accept(NbpSubscriber s) { } }); - NbpObservable.merge(os).subscribe(ts); + Observable.merge(os).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); assertEquals(10000, ts.values().size()); } - Function> toScalar = new Function>() { + Function> toScalar = new Function>() { @Override - public NbpObservable apply(Integer v) { - return NbpObservable.just(v); + public Observable apply(Integer v) { + return Observable.just(v); } }; - Function> toHiddenScalar = new Function>() { + Function> toHiddenScalar = new Function>() { @Override - public NbpObservable apply(Integer t) { - return NbpObservable.just(t).asObservable(); + public Observable apply(Integer t) { + return Observable.just(t).asObservable(); } }; ; - void runMerge(Function> func, NbpTestSubscriber ts) { + void runMerge(Function> func, TestObserver ts) { List list = new ArrayList(); for (int i = 0; i < 1000; i++) { list.add(i); } - NbpObservable source = NbpObservable.fromIterable(list); + Observable source = Observable.fromIterable(list); source.flatMap(func).subscribe(ts); if (ts.values().size() != 1000) { @@ -1074,16 +1076,16 @@ void runMerge(Function> func, NbpTestSubscriber< @Test public void testFastMergeFullScalar() { - runMerge(toScalar, new NbpTestSubscriber()); + runMerge(toScalar, new TestObserver()); } @Test public void testFastMergeHiddenScalar() { - runMerge(toHiddenScalar, new NbpTestSubscriber()); + runMerge(toHiddenScalar, new TestObserver()); } @Test public void testSlowMergeFullScalar() { for (final int req : new int[] { 16, 32, 64, 128, 256 }) { - NbpTestSubscriber ts = new NbpTestSubscriber() { + TestObserver ts = new TestObserver() { int remaining = req; @Override @@ -1100,7 +1102,7 @@ public void onNext(Integer t) { @Test public void testSlowMergeHiddenScalar() { for (final int req : new int[] { 16, 32, 64, 128, 256 }) { - NbpTestSubscriber ts = new NbpTestSubscriber() { + TestObserver ts = new TestObserver() { int remaining = req; @Override public void onNext(Integer t) { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMulticastTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMulticastTest.java similarity index 98% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMulticastTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMulticastTest.java index eaafb17382..9049586e03 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorMulticastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorMulticastTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; public class NbpOperatorMulticastTest { // FIXME operator multicast not supported diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorObserveOnTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorObserveOnTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorObserveOnTest.java index ce71c8df07..30c47ccab1 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorObserveOnTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,11 +25,11 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; +import io.reactivex.observers.*; import io.reactivex.schedulers.*; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorObserveOnTest { @@ -40,8 +40,8 @@ public class NbpOperatorObserveOnTest { @Test @Ignore("immediate scheduler not supported") public void testObserveOn() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable.just(1, 2, 3).observeOn(Schedulers.immediate()).subscribe(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + Observable.just(1, 2, 3).observeOn(Schedulers.immediate()).subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext(1); verify(NbpObserver, times(1)).onNext(2); @@ -53,12 +53,12 @@ public void testObserveOn() { public void testOrdering() throws InterruptedException { // NbpObservable obs = NbpObservable.just("one", null, "two", "three", "four"); // FIXME null values not allowed - NbpObservable obs = NbpObservable.just("one", "null", "two", "three", "four"); + Observable obs = Observable.just("one", "null", "two", "three", "four"); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(NbpObserver); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + TestObserver ts = new TestObserver(NbpObserver); obs.observeOn(Schedulers.computation()).subscribe(ts); @@ -84,9 +84,9 @@ public void testThreadName() throws InterruptedException { System.out.println("Main Thread: " + Thread.currentThread().getName()); // FIXME null values not allowed // NbpObservable obs = NbpObservable.just("one", null, "two", "three", "four"); - NbpObservable obs = NbpObservable.just("one", "null", "two", "three", "four"); + Observable obs = Observable.just("one", "null", "two", "three", "four"); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); final String parentThreadName = Thread.currentThread().getName(); final CountDownLatch completedLatch = new CountDownLatch(1); @@ -138,13 +138,13 @@ public void run() { public void observeOnTheSameSchedulerTwice() { Scheduler scheduler = Schedulers.immediate(); - NbpObservable o = NbpObservable.just(1, 2, 3); - NbpObservable o2 = o.observeOn(scheduler); + Observable o = Observable.just(1, 2, 3); + Observable o2 = o.observeOn(scheduler); @SuppressWarnings("unchecked") - NbpObserver observer1 = mock(NbpObserver.class); + DefaultObserver observer1 = mock(DefaultObserver.class); @SuppressWarnings("unchecked") - NbpObserver observer2 = mock(NbpObserver.class); + DefaultObserver observer2 = mock(DefaultObserver.class); InOrder inOrder1 = inOrder(observer1); InOrder inOrder2 = inOrder(observer2); @@ -172,12 +172,12 @@ public void observeSameOnMultipleSchedulers() { TestScheduler scheduler1 = new TestScheduler(); TestScheduler scheduler2 = new TestScheduler(); - NbpObservable o = NbpObservable.just(1, 2, 3); - NbpObservable o1 = o.observeOn(scheduler1); - NbpObservable o2 = o.observeOn(scheduler2); + Observable o = Observable.just(1, 2, 3); + Observable o1 = o.observeOn(scheduler1); + Observable o2 = o.observeOn(scheduler2); - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); - NbpSubscriber observer2 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); + Observer observer2 = TestHelper.mockNbpSubscriber(); InOrder inOrder1 = inOrder(observer1); InOrder inOrder2 = inOrder(observer2); @@ -211,7 +211,7 @@ public void testObserveOnWithNewThreadScheduler() { final AtomicInteger count = new AtomicInteger(); final int _multiple = 99; - NbpObservable.range(1, 100000).map(new Function() { + Observable.range(1, 100000).map(new Function() { @Override public Integer apply(Integer t1) { @@ -241,7 +241,7 @@ public void testObserveOnWithThreadPoolScheduler() { final AtomicInteger count = new AtomicInteger(); final int _multiple = 99; - NbpObservable.range(1, 100000).map(new Function() { + Observable.range(1, 100000).map(new Function() { @Override public Integer apply(Integer t1) { @@ -276,7 +276,7 @@ public void testObserveOnOrderingConcurrency() { final AtomicInteger count = new AtomicInteger(); final int _multiple = 99; - NbpObservable.range(1, 10000).map(new Function() { + Observable.range(1, 10000).map(new Function() { @Override public Integer apply(Integer t1) { @@ -312,7 +312,7 @@ public void testNonBlockingOuterWhileBlockingOnNext() throws InterruptedExceptio final CountDownLatch nextLatch = new CountDownLatch(1); final AtomicLong completeTime = new AtomicLong(); // use subscribeOn to make async, observeOn to move - NbpObservable.range(1, 2).subscribeOn(Schedulers.newThread()).observeOn(Schedulers.newThread()).subscribe(new NbpObserver() { + Observable.range(1, 2).subscribeOn(Schedulers.newThread()).observeOn(Schedulers.newThread()).subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -362,10 +362,10 @@ private static int randomIntFrom0to100() { public void testDelayedErrorDeliveryWhenSafeSubscriberUnsubscribes() { TestScheduler testScheduler = new TestScheduler(); - NbpObservable source = NbpObservable.concat(NbpObservable. error(new TestException()), NbpObservable.just(1)); + Observable source = Observable.concat(Observable. error(new TestException()), Observable.just(1)); @SuppressWarnings("unchecked") - NbpObserver o = mock(NbpObserver.class); + DefaultObserver o = mock(DefaultObserver.class); InOrder inOrder = inOrder(o); source.observeOn(testScheduler).subscribe(o); @@ -383,10 +383,10 @@ public void testDelayedErrorDeliveryWhenSafeSubscriberUnsubscribes() { public void testAfterUnsubscribeCalledThenObserverOnNextNeverCalled() { final TestScheduler testScheduler = new TestScheduler(); - final NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + final Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); - NbpObservable.just(1, 2, 3) + Observable.just(1, 2, 3) .observeOn(testScheduler) .subscribe(ts); @@ -403,7 +403,7 @@ public void testAfterUnsubscribeCalledThenObserverOnNextNeverCalled() { @Test public void testBackpressureWithTakeBefore() { final AtomicInteger generated = new AtomicInteger(); - NbpObservable o = NbpObservable.fromIterable(new Iterable() { + Observable o = Observable.fromIterable(new Iterable() { @Override public Iterator iterator() { return new Iterator() { @@ -425,7 +425,7 @@ public boolean hasNext() { } }); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); o .take(7) .observeOn(Schedulers.newThread()) @@ -438,8 +438,8 @@ public boolean hasNext() { @Test public void testAsyncChild() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(0, 100000).observeOn(Schedulers.newThread()).observeOn(Schedulers.newThread()).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.range(0, 100000).observeOn(Schedulers.newThread()).observeOn(Schedulers.newThread()).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); } diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorResumeNextViaFunctionTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorResumeNextViaFunctionTest.java similarity index 73% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorResumeNextViaFunctionTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorResumeNextViaFunctionTest.java index 5003b4f988..3f7693cb2e 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorResumeNextViaFunctionTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorResumeNextViaFunctionTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -24,22 +24,23 @@ import org.reactivestreams.Subscription; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.*; import io.reactivex.disposables.Disposable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorOnErrorResumeNextViaFunctionTest { @Test public void testResumeNextWithSynchronousExecution() { final AtomicReference receivedException = new AtomicReference(); - NbpObservable w = NbpObservable.create(new NbpOnSubscribe() { + Observable w = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); NbpObserver.onNext("one"); NbpObserver.onError(new Throwable("injected failure")); @@ -48,18 +49,18 @@ public void accept(NbpSubscriber NbpObserver) { } }); - Function> resume = new Function>() { + Function> resume = new Function>() { @Override - public NbpObservable apply(Throwable t1) { + public Observable apply(Throwable t1) { receivedException.set(t1); - return NbpObservable.just("twoResume", "threeResume"); + return Observable.just("twoResume", "threeResume"); } }; - NbpObservable NbpObservable = w.onErrorResumeNext(resume); + Observable NbpObservable = w.onErrorResumeNext(resume); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -78,18 +79,18 @@ public void testResumeNextWithAsyncExecution() { final AtomicReference receivedException = new AtomicReference(); Subscription s = mock(Subscription.class); TestObservable w = new TestObservable(s, "one"); - Function> resume = new Function>() { + Function> resume = new Function>() { @Override - public NbpObservable apply(Throwable t1) { + public Observable apply(Throwable t1) { receivedException.set(t1); - return NbpObservable.just("twoResume", "threeResume"); + return Observable.just("twoResume", "threeResume"); } }; - NbpObservable o = NbpObservable.create(w).onErrorResumeNext(resume); + Observable o = Observable.create(w).onErrorResumeNext(resume); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); @@ -116,18 +117,18 @@ public NbpObservable apply(Throwable t1) { public void testFunctionThrowsError() { Subscription s = mock(Subscription.class); TestObservable w = new TestObservable(s, "one"); - Function> resume = new Function>() { + Function> resume = new Function>() { @Override - public NbpObservable apply(Throwable t1) { + public Observable apply(Throwable t1) { throw new RuntimeException("exception from function"); } }; - NbpObservable o = NbpObservable.create(w).onErrorResumeNext(resume); + Observable o = Observable.create(w).onErrorResumeNext(resume); @SuppressWarnings("unchecked") - NbpObserver NbpObserver = mock(NbpObserver.class); + DefaultObserver NbpObserver = mock(DefaultObserver.class); o.subscribe(NbpObserver); try { @@ -151,22 +152,22 @@ public NbpObservable apply(Throwable t1) { @Test @Ignore("Failed operator may leave the child NbpSubscriber in an inconsistent state which prevents further error delivery.") public void testOnErrorResumeReceivesErrorFromPreviousNonProtectedOperator() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.just(1).lift(new NbpOperator() { + TestObserver ts = new TestObserver(); + Observable.just(1).lift(new NbpOperator() { @Override - public NbpSubscriber apply(NbpSubscriber t1) { + public Observer apply(Observer t1) { throw new RuntimeException("failed"); } - }).onErrorResumeNext(new Function>() { + }).onErrorResumeNext(new Function>() { @Override - public NbpObservable apply(Throwable t1) { + public Observable apply(Throwable t1) { if (t1.getMessage().equals("failed")) { - return NbpObservable.just("success"); + return Observable.just("success"); } else { - return NbpObservable.error(t1); + return Observable.error(t1); } } @@ -184,12 +185,12 @@ public NbpObservable apply(Throwable t1) { @Test @Ignore("A crashing operator may leave the downstream in an inconsistent state and not suitable for event delivery") public void testOnErrorResumeReceivesErrorFromPreviousNonProtectedOperatorOnNext() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.just(1).lift(new NbpOperator() { + TestObserver ts = new TestObserver(); + Observable.just(1).lift(new NbpOperator() { @Override - public NbpSubscriber apply(final NbpSubscriber t1) { - return new NbpSubscriber() { + public Observer apply(final Observer t1) { + return new Observer() { @Override public void onSubscribe(Disposable s) { @@ -214,14 +215,14 @@ public void onNext(Integer t) { }; } - }).onErrorResumeNext(new Function>() { + }).onErrorResumeNext(new Function>() { @Override - public NbpObservable apply(Throwable t1) { + public Observable apply(Throwable t1) { if (t1.getMessage().equals("failed")) { - return NbpObservable.just("success"); + return Observable.just("success"); } else { - return NbpObservable.error(t1); + return Observable.error(t1); } } @@ -235,7 +236,7 @@ public NbpObservable apply(Throwable t1) { @Test public void testMapResumeAsyncNext() { // Trigger multiple failures - NbpObservable w = NbpObservable.just("one", "fail", "two", "three", "fail"); + Observable w = Observable.just("one", "fail", "two", "three", "fail"); // Introduce map function that fails intermittently (Map does not prevent this when the NbpObserver is a // rx.operator incl onErrorResumeNextViaObservable) @@ -249,19 +250,19 @@ public String apply(String s) { } }); - NbpObservable o = w.onErrorResumeNext(new Function>() { + Observable o = w.onErrorResumeNext(new Function>() { @Override - public NbpObservable apply(Throwable t1) { - return NbpObservable.just("twoResume", "threeResume").subscribeOn(Schedulers.computation()); + public Observable apply(Throwable t1) { + return Observable.just("twoResume", "threeResume").subscribeOn(Schedulers.computation()); } }); @SuppressWarnings("unchecked") - NbpObserver NbpObserver = mock(NbpObserver.class); + DefaultObserver NbpObserver = mock(DefaultObserver.class); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + TestObserver ts = new TestObserver(NbpObserver); o.subscribe(ts); ts.awaitTerminalEvent(); @@ -284,7 +285,7 @@ public TestObservable(Subscription s, String... values) { } @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { System.out.println("TestObservable subscribed to ..."); NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); t = new Thread(new Runnable() { @@ -313,13 +314,13 @@ public void run() { @Test public void testBackpressure() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(0, 100000) - .onErrorResumeNext(new Function>() { + TestObserver ts = new TestObserver(); + Observable.range(0, 100000) + .onErrorResumeNext(new Function>() { @Override - public NbpObservable apply(Throwable t1) { - return NbpObservable.just(1); + public Observable apply(Throwable t1) { + return Observable.just(1); } }) diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorResumeNextViaObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorResumeNextViaObservableTest.java similarity index 77% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorResumeNextViaObservableTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorResumeNextViaObservableTest.java index c68b728f34..9073a00e3b 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorResumeNextViaObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorResumeNextViaObservableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -21,11 +21,12 @@ import org.mockito.Mockito; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.Disposable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; +import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorOnErrorResumeNextViaObservableTest { @@ -34,11 +35,11 @@ public void testResumeNext() { Disposable s = mock(Disposable.class); // Trigger failure on second element TestObservable f = new TestObservable(s, "one", "fail", "two", "three"); - NbpObservable w = NbpObservable.create(f); - NbpObservable resume = NbpObservable.just("twoResume", "threeResume"); - NbpObservable NbpObservable = w.onErrorResumeNext(resume); + Observable w = Observable.create(f); + Observable resume = Observable.just("twoResume", "threeResume"); + Observable NbpObservable = w.onErrorResumeNext(resume); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); try { @@ -60,10 +61,10 @@ public void testResumeNext() { public void testMapResumeAsyncNext() { Disposable sr = mock(Disposable.class); // Trigger multiple failures - NbpObservable w = NbpObservable.just("one", "fail", "two", "three", "fail"); + Observable w = Observable.just("one", "fail", "two", "three", "fail"); // Resume NbpObservable is async TestObservable f = new TestObservable(sr, "twoResume", "threeResume"); - NbpObservable resume = NbpObservable.create(f); + Observable resume = Observable.create(f); // Introduce map function that fails intermittently (Map does not prevent this when the NbpObserver is a // rx.operator incl onErrorResumeNextViaObservable) @@ -77,9 +78,9 @@ public String apply(String s) { } }); - NbpObservable NbpObservable = w.onErrorResumeNext(resume); + Observable NbpObservable = w.onErrorResumeNext(resume); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); @@ -101,18 +102,18 @@ public String apply(String s) { @Test @Ignore("Publishers should not throw") public void testResumeNextWithFailureOnSubscribe() { - NbpObservable testObservable = NbpObservable.create(new NbpOnSubscribe() { + Observable testObservable = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber t1) { + public void accept(Observer t1) { throw new RuntimeException("force failure"); } }); - NbpObservable resume = NbpObservable.just("resume"); - NbpObservable NbpObservable = testObservable.onErrorResumeNext(resume); + Observable resume = Observable.just("resume"); + Observable NbpObservable = testObservable.onErrorResumeNext(resume); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); verify(NbpObserver, Mockito.never()).onError(any(Throwable.class)); @@ -123,20 +124,20 @@ public void accept(NbpSubscriber t1) { @Test @Ignore("Publishers should not throw") public void testResumeNextWithFailureOnSubscribeAsync() { - NbpObservable testObservable = NbpObservable.create(new NbpOnSubscribe() { + Observable testObservable = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber t1) { + public void accept(Observer t1) { throw new RuntimeException("force failure"); } }); - NbpObservable resume = NbpObservable.just("resume"); - NbpObservable NbpObservable = testObservable.subscribeOn(Schedulers.io()).onErrorResumeNext(resume); + Observable resume = Observable.just("resume"); + Observable NbpObservable = testObservable.subscribeOn(Schedulers.io()).onErrorResumeNext(resume); @SuppressWarnings("unchecked") - NbpObserver NbpObserver = mock(NbpObserver.class); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + DefaultObserver NbpObserver = mock(DefaultObserver.class); + TestObserver ts = new TestObserver(NbpObserver); NbpObservable.subscribe(ts); ts.awaitTerminalEvent(); @@ -158,7 +159,7 @@ public TestObservable(Disposable s, String... values) { } @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { System.out.println("TestObservable subscribed to ..."); NbpObserver.onSubscribe(s); t = new Thread(new Runnable() { @@ -190,9 +191,9 @@ public void run() { @Test public void testBackpressure() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(0, 100000) - .onErrorResumeNext(NbpObservable.just(1)) + TestObserver ts = new TestObserver(); + Observable.range(0, 100000) + .onErrorResumeNext(Observable.just(1)) .observeOn(Schedulers.computation()) .map(new Function() { int c = 0; diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorReturnTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorReturnTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorReturnTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorReturnTest.java index ed2b423f33..ccab24f61f 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorOnErrorReturnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorOnErrorReturnTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -23,21 +23,21 @@ import org.mockito.Mockito; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorOnErrorReturnTest { @Test public void testResumeNext() { TestObservable f = new TestObservable("one"); - NbpObservable w = NbpObservable.create(f); + Observable w = Observable.create(f); final AtomicReference capturedException = new AtomicReference(); - NbpObservable NbpObservable = w.onErrorReturn(new Function() { + Observable NbpObservable = w.onErrorReturn(new Function() { @Override public String apply(Throwable e) { @@ -48,7 +48,7 @@ public String apply(Throwable e) { }); @SuppressWarnings("unchecked") - NbpObserver NbpObserver = mock(NbpObserver.class); + DefaultObserver NbpObserver = mock(DefaultObserver.class); NbpObservable.subscribe(NbpObserver); try { @@ -70,10 +70,10 @@ public String apply(Throwable e) { @Test public void testFunctionThrowsError() { TestObservable f = new TestObservable("one"); - NbpObservable w = NbpObservable.create(f); + Observable w = Observable.create(f); final AtomicReference capturedException = new AtomicReference(); - NbpObservable NbpObservable = w.onErrorReturn(new Function() { + Observable NbpObservable = w.onErrorReturn(new Function() { @Override public String apply(Throwable e) { @@ -84,7 +84,7 @@ public String apply(Throwable e) { }); @SuppressWarnings("unchecked") - NbpObserver NbpObserver = mock(NbpObserver.class); + DefaultObserver NbpObserver = mock(DefaultObserver.class); NbpObservable.subscribe(NbpObserver); try { @@ -105,7 +105,7 @@ public String apply(Throwable e) { @Test public void testMapResumeAsyncNext() { // Trigger multiple failures - NbpObservable w = NbpObservable.just("one", "fail", "two", "three", "fail"); + Observable w = Observable.just("one", "fail", "two", "three", "fail"); // Introduce map function that fails intermittently (Map does not prevent this when the NbpObserver is a // rx.operator incl onErrorResumeNextViaObservable) @@ -119,7 +119,7 @@ public String apply(String s) { } }); - NbpObservable NbpObservable = w.onErrorReturn(new Function() { + Observable NbpObservable = w.onErrorReturn(new Function() { @Override public String apply(Throwable t1) { @@ -129,8 +129,8 @@ public String apply(Throwable t1) { }); @SuppressWarnings("unchecked") - NbpObserver NbpObserver = mock(NbpObserver.class); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + DefaultObserver NbpObserver = mock(DefaultObserver.class); + TestObserver ts = new TestObserver(NbpObserver); NbpObservable.subscribe(ts); ts.awaitTerminalEvent(); @@ -144,8 +144,8 @@ public String apply(Throwable t1) { @Test public void testBackpressure() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(0, 100000) + TestObserver ts = new TestObserver(); + Observable.range(0, 100000) .onErrorReturn(new Function() { @Override @@ -187,7 +187,7 @@ public TestObservable(String... values) { } @Override - public void accept(final NbpSubscriber NbpSubscriber) { + public void accept(final Observer NbpSubscriber) { NbpSubscriber.onSubscribe(EmptyDisposable.INSTANCE); System.out.println("TestObservable subscribed to ..."); t = new Thread(new Runnable() { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorOnExceptionResumeNextViaObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorOnExceptionResumeNextViaObservableTest.java similarity index 81% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorOnExceptionResumeNextViaObservableTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorOnExceptionResumeNextViaObservableTest.java index 4f95e6ac9b..f203df002f 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorOnExceptionResumeNextViaObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorOnExceptionResumeNextViaObservableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -21,12 +21,13 @@ import org.mockito.Mockito; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.Disposable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorOnExceptionResumeNextViaObservableTest { @@ -34,11 +35,11 @@ public class NbpOperatorOnExceptionResumeNextViaObservableTest { public void testResumeNextWithException() { // Trigger failure on second element TestObservable f = new TestObservable("one", "EXCEPTION", "two", "three"); - NbpObservable w = NbpObservable.create(f); - NbpObservable resume = NbpObservable.just("twoResume", "threeResume"); - NbpObservable NbpObservable = w.onExceptionResumeNext(resume); + Observable w = Observable.create(f); + Observable resume = Observable.just("twoResume", "threeResume"); + Observable NbpObservable = w.onExceptionResumeNext(resume); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); try { @@ -62,11 +63,11 @@ public void testResumeNextWithException() { public void testResumeNextWithRuntimeException() { // Trigger failure on second element TestObservable f = new TestObservable("one", "RUNTIMEEXCEPTION", "two", "three"); - NbpObservable w = NbpObservable.create(f); - NbpObservable resume = NbpObservable.just("twoResume", "threeResume"); - NbpObservable NbpObservable = w.onExceptionResumeNext(resume); + Observable w = Observable.create(f); + Observable resume = Observable.just("twoResume", "threeResume"); + Observable NbpObservable = w.onExceptionResumeNext(resume); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); try { @@ -90,11 +91,11 @@ public void testResumeNextWithRuntimeException() { public void testThrowablePassesThru() { // Trigger failure on second element TestObservable f = new TestObservable("one", "THROWABLE", "two", "three"); - NbpObservable w = NbpObservable.create(f); - NbpObservable resume = NbpObservable.just("twoResume", "threeResume"); - NbpObservable NbpObservable = w.onExceptionResumeNext(resume); + Observable w = Observable.create(f); + Observable resume = Observable.just("twoResume", "threeResume"); + Observable NbpObservable = w.onExceptionResumeNext(resume); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); try { @@ -118,11 +119,11 @@ public void testThrowablePassesThru() { public void testErrorPassesThru() { // Trigger failure on second element TestObservable f = new TestObservable("one", "ERROR", "two", "three"); - NbpObservable w = NbpObservable.create(f); - NbpObservable resume = NbpObservable.just("twoResume", "threeResume"); - NbpObservable NbpObservable = w.onExceptionResumeNext(resume); + Observable w = Observable.create(f); + Observable resume = Observable.just("twoResume", "threeResume"); + Observable NbpObservable = w.onExceptionResumeNext(resume); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); try { @@ -145,10 +146,10 @@ public void testErrorPassesThru() { @Test public void testMapResumeAsyncNext() { // Trigger multiple failures - NbpObservable w = NbpObservable.just("one", "fail", "two", "three", "fail"); + Observable w = Observable.just("one", "fail", "two", "three", "fail"); // Resume NbpObservable is async TestObservable f = new TestObservable("twoResume", "threeResume"); - NbpObservable resume = NbpObservable.create(f); + Observable resume = Observable.create(f); // Introduce map function that fails intermittently (Map does not prevent this when the NbpObserver is a // rx.operator incl onErrorResumeNextViaObservable) @@ -162,9 +163,9 @@ public String apply(String s) { } }); - NbpObservable NbpObservable = w.onExceptionResumeNext(resume); + Observable NbpObservable = w.onExceptionResumeNext(resume); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); try { @@ -188,9 +189,9 @@ public String apply(String s) { @Test public void testBackpressure() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(0, 100000) - .onExceptionResumeNext(NbpObservable.just(1)) + TestObserver ts = new TestObserver(); + Observable.range(0, 100000) + .onExceptionResumeNext(Observable.just(1)) .observeOn(Schedulers.computation()) .map(new Function() { int c = 0; @@ -225,7 +226,7 @@ public TestObservable(String... values) { } @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); System.out.println("TestObservable subscribed to ..."); t = new Thread(new Runnable() { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorPublishTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorPublishTest.java similarity index 75% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorPublishTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorPublishTest.java index f86c7e9472..d633671456 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorPublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorPublishTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; @@ -22,25 +22,25 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.internal.operators.nbp.NbpOperatorPublish; -import io.reactivex.observables.nbp.NbpConnectableObservable; +import io.reactivex.observables.ConnectableObservable; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; -import io.reactivex.Observable; public class NbpOperatorPublishTest { @Test public void testPublish() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - NbpConnectableObservable o = NbpObservable.create(new NbpOnSubscribe() { + ConnectableObservable o = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); new Thread(new Runnable() { @@ -89,8 +89,8 @@ public void accept(String v) { @Test public void testBackpressureFastSlow() { - NbpConnectableObservable is = NbpObservable.range(1, Observable.bufferSize() * 2).publish(); - NbpObservable fast = is.observeOn(Schedulers.computation()) + ConnectableObservable is = Observable.range(1, Flowable.bufferSize() * 2).publish(); + Observable fast = is.observeOn(Schedulers.computation()) .doOnComplete(new Runnable() { @Override public void run() { @@ -98,7 +98,7 @@ public void run() { } }); - NbpObservable slow = is.observeOn(Schedulers.computation()).map(new Function() { + Observable slow = is.observeOn(Schedulers.computation()).map(new Function() { int c = 0; @Override @@ -122,19 +122,19 @@ public void run() { }); - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.merge(fast, slow).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.merge(fast, slow).subscribe(ts); is.connect(); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 4, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 4, ts.valueCount()); } // use case from https://github.com/ReactiveX/RxJava/issues/1732 @Test public void testTakeUntilWithPublishedStreamUsingSelector() { final AtomicInteger emitted = new AtomicInteger(); - NbpObservable xs = NbpObservable.range(0, Observable.bufferSize() * 2).doOnNext(new Consumer() { + Observable xs = Observable.range(0, Flowable.bufferSize() * 2).doOnNext(new Consumer() { @Override public void accept(Integer t1) { @@ -142,11 +142,11 @@ public void accept(Integer t1) { } }); - NbpTestSubscriber ts = new NbpTestSubscriber(); - xs.publish(new Function, NbpObservable>() { + TestObserver ts = new TestObserver(); + xs.publish(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable xs) { + public Observable apply(Observable xs) { return xs.takeUntil(xs.skipWhile(new Predicate() { @Override @@ -168,9 +168,9 @@ public boolean test(Integer i) { // use case from https://github.com/ReactiveX/RxJava/issues/1732 @Test public void testTakeUntilWithPublishedStream() { - NbpObservable xs = NbpObservable.range(0, Observable.bufferSize() * 2); - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpConnectableObservable xsp = xs.publish(); + Observable xs = Observable.range(0, Flowable.bufferSize() * 2); + TestObserver ts = new TestObserver(); + ConnectableObservable xsp = xs.publish(); xsp.takeUntil(xsp.skipWhile(new Predicate() { @Override @@ -187,7 +187,7 @@ public boolean test(Integer i) { public void testBackpressureTwoConsumers() { final AtomicInteger sourceEmission = new AtomicInteger(); final AtomicBoolean sourceUnsubscribed = new AtomicBoolean(); - final NbpObservable source = NbpObservable.range(1, 100) + final Observable source = Observable.range(1, 100) .doOnNext(new Consumer() { @Override public void accept(Integer t1) { @@ -205,9 +205,9 @@ public void run() { final AtomicBoolean child1Unsubscribed = new AtomicBoolean(); final AtomicBoolean child2Unsubscribed = new AtomicBoolean(); - final NbpTestSubscriber ts2 = new NbpTestSubscriber(); + final TestObserver ts2 = new TestObserver(); - final NbpTestSubscriber ts1 = new NbpTestSubscriber() { + final TestObserver ts1 = new TestObserver() { @Override public void onNext(Integer t) { if (valueCount() == 2) { @@ -249,11 +249,11 @@ public void run() { @Test public void testConnectWithNoSubscriber() { TestScheduler scheduler = new TestScheduler(); - NbpConnectableObservable co = NbpObservable.interval(10, 10, TimeUnit.MILLISECONDS, scheduler).take(3).publish(); + ConnectableObservable co = Observable.interval(10, 10, TimeUnit.MILLISECONDS, scheduler).take(3).publish(); co.connect(); // Emit 0 scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); - NbpTestSubscriber NbpSubscriber = new NbpTestSubscriber(); + TestObserver NbpSubscriber = new TestObserver(); co.subscribe(NbpSubscriber); // Emit 1 and 2 scheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS); @@ -264,9 +264,9 @@ public void testConnectWithNoSubscriber() { @Test public void testSubscribeAfterDisconnectThenConnect() { - NbpConnectableObservable source = NbpObservable.just(1).publish(); + ConnectableObservable source = Observable.just(1).publish(); - NbpTestSubscriber ts1 = new NbpTestSubscriber(); + TestObserver ts1 = new TestObserver(); source.subscribe(ts1); @@ -276,7 +276,7 @@ public void testSubscribeAfterDisconnectThenConnect() { ts1.assertNoErrors(); ts1.assertTerminated(); - NbpTestSubscriber ts2 = new NbpTestSubscriber(); + TestObserver ts2 = new TestObserver(); source.subscribe(ts2); @@ -292,9 +292,9 @@ public void testSubscribeAfterDisconnectThenConnect() { @Test public void testNoSubscriberRetentionOnCompleted() { - NbpOperatorPublish source = (NbpOperatorPublish)NbpObservable.just(1).publish(); + NbpOperatorPublish source = (NbpOperatorPublish)Observable.just(1).publish(); - NbpTestSubscriber ts1 = new NbpTestSubscriber(); + TestObserver ts1 = new TestObserver(); source.unsafeSubscribe(ts1); @@ -313,7 +313,7 @@ public void testNoSubscriberRetentionOnCompleted() { @Test public void testNonNullConnection() { - NbpConnectableObservable source = NbpObservable.never().publish(); + ConnectableObservable source = Observable.never().publish(); assertNotNull(source.connect()); assertNotNull(source.connect()); @@ -321,7 +321,7 @@ public void testNonNullConnection() { @Test public void testNoDisconnectSomeoneElse() { - NbpConnectableObservable source = NbpObservable.never().publish(); + ConnectableObservable source = Observable.never().publish(); Disposable s1 = source.connect(); Disposable s2 = source.connect(); @@ -345,15 +345,15 @@ static boolean checkPublishDisposed(Disposable d) { @Test public void testConnectIsIdempotent() { final AtomicInteger calls = new AtomicInteger(); - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber t) { + public void accept(Observer t) { t.onSubscribe(EmptyDisposable.INSTANCE); calls.getAndIncrement(); } }); - NbpConnectableObservable conn = source.publish(); + ConnectableObservable conn = source.publish(); assertEquals(0, calls.get()); @@ -371,20 +371,20 @@ public void accept(NbpSubscriber t) { } @Test public void testObserveOn() { - NbpConnectableObservable co = NbpObservable.range(0, 1000).publish(); - NbpObservable obs = co.observeOn(Schedulers.computation()); + ConnectableObservable co = Observable.range(0, 1000).publish(); + Observable obs = co.observeOn(Schedulers.computation()); for (int i = 0; i < 1000; i++) { for (int j = 1; j < 6; j++) { - List> tss = new ArrayList>(); + List> tss = new ArrayList>(); for (int k = 1; k < j; k++) { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); tss.add(ts); obs.subscribe(ts); } Disposable s = co.connect(); - for (NbpTestSubscriber ts : tss) { + for (TestObserver ts : tss) { ts.awaitTerminalEvent(2, TimeUnit.SECONDS); ts.assertTerminated(); ts.assertNoErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorReduceTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorReduceTest.java similarity index 82% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorReduceTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorReduceTest.java index 057671c140..0c85c401f5 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorReduceTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorReduceTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -20,12 +20,12 @@ import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; public class NbpOperatorReduceTest { - NbpSubscriber NbpObserver; + Observer NbpObserver; @Before public void before() { @@ -42,7 +42,7 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testAggregateAsIntSum() { - NbpObservable result = NbpObservable.just(1, 2, 3, 4, 5).reduce(0, sum) + Observable result = Observable.just(1, 2, 3, 4, 5).reduce(0, sum) .map(new Function() { @Override public Integer apply(Integer v) { @@ -59,8 +59,8 @@ public Integer apply(Integer v) { @Test public void testAggregateAsIntSumSourceThrows() { - NbpObservable result = NbpObservable.concat(NbpObservable.just(1, 2, 3, 4, 5), - NbpObservable. error(new TestException())) + Observable result = Observable.concat(Observable.just(1, 2, 3, 4, 5), + Observable. error(new TestException())) .reduce(0, sum).map(new Function() { @Override public Integer apply(Integer v) { @@ -84,7 +84,7 @@ public Integer apply(Integer t1, Integer t2) { } }; - NbpObservable result = NbpObservable.just(1, 2, 3, 4, 5) + Observable result = Observable.just(1, 2, 3, 4, 5) .reduce(0, sumErr).map(new Function() { @Override public Integer apply(Integer v) { @@ -110,7 +110,7 @@ public Integer apply(Integer t1) { } }; - NbpObservable result = NbpObservable.just(1, 2, 3, 4, 5) + Observable result = Observable.just(1, 2, 3, 4, 5) .reduce(0, sum).map(error); result.subscribe(NbpObserver); @@ -122,8 +122,8 @@ public Integer apply(Integer t1) { @Test public void testBackpressureWithNoInitialValue() throws InterruptedException { - NbpObservable source = NbpObservable.just(1, 2, 3, 4, 5, 6); - NbpObservable reduced = source.reduce(sum); + Observable source = Observable.just(1, 2, 3, 4, 5, 6); + Observable reduced = source.reduce(sum); Integer r = reduced.toBlocking().first(); assertEquals(21, r.intValue()); @@ -131,8 +131,8 @@ public void testBackpressureWithNoInitialValue() throws InterruptedException { @Test public void testBackpressureWithInitialValue() throws InterruptedException { - NbpObservable source = NbpObservable.just(1, 2, 3, 4, 5, 6); - NbpObservable reduced = source.reduce(0, sum); + Observable source = Observable.just(1, 2, 3, 4, 5, 6); + Observable reduced = source.reduce(0, sum); Integer r = reduced.toBlocking().first(); assertEquals(21, r.intValue()); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorRepeatTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorRepeatTest.java similarity index 73% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorRepeatTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorRepeatTest.java index 271c76d19d..7c65042ed7 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorRepeatTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorRepeatTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -23,13 +23,15 @@ import org.junit.Test; -import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorRepeatTest { @@ -37,10 +39,10 @@ public class NbpOperatorRepeatTest { public void testRepetition() { int NUM = 10; final AtomicInteger count = new AtomicInteger(); - int value = NbpObservable.create(new NbpOnSubscribe() { + int value = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber o) { + public void accept(final Observer o) { o.onNext(count.incrementAndGet()); o.onComplete(); } @@ -52,24 +54,24 @@ public void accept(final NbpSubscriber o) { @Test(timeout = 2000) public void testRepeatTake() { - NbpObservable xs = NbpObservable.just(1, 2); + Observable xs = Observable.just(1, 2); Object[] ys = xs.repeat().subscribeOn(Schedulers.newThread()).take(4).toList().toBlocking().last().toArray(); assertArrayEquals(new Object[] { 1, 2, 1, 2 }, ys); } @Test(timeout = 20000) public void testNoStackOverFlow() { - NbpObservable.just(1).repeat().subscribeOn(Schedulers.newThread()).take(100000).toBlocking().last(); + Observable.just(1).repeat().subscribeOn(Schedulers.newThread()).take(100000).toBlocking().last(); } @Test public void testRepeatTakeWithSubscribeOn() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - NbpObservable oi = NbpObservable.create(new NbpOnSubscribe() { + Observable oi = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber sub) { + public void accept(Observer sub) { sub.onSubscribe(EmptyDisposable.INSTANCE); counter.incrementAndGet(); sub.onNext(1); @@ -98,9 +100,9 @@ public Integer apply(Integer t1) { @Test(timeout = 2000) public void testRepeatAndTake() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpObservable.just(1).repeat().take(10).subscribe(o); + Observable.just(1).repeat().take(10).subscribe(o); verify(o, times(10)).onNext(1); verify(o).onComplete(); @@ -109,9 +111,9 @@ public void testRepeatAndTake() { @Test(timeout = 2000) public void testRepeatLimited() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpObservable.just(1).repeat(10).subscribe(o); + Observable.just(1).repeat(10).subscribe(o); verify(o, times(10)).onNext(1); verify(o).onComplete(); @@ -120,9 +122,9 @@ public void testRepeatLimited() { @Test(timeout = 2000) public void testRepeatError() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpObservable.error(new TestException()).repeat(10).subscribe(o); + Observable.error(new TestException()).repeat(10).subscribe(o); verify(o).onError(any(TestException.class)); verify(o, never()).onNext(any()); @@ -132,9 +134,9 @@ public void testRepeatError() { @Test(timeout = 2000) public void testRepeatZero() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpObservable.just(1).repeat(0).subscribe(o); + Observable.just(1).repeat(0).subscribe(o); verify(o).onComplete(); verify(o, never()).onNext(any()); @@ -143,9 +145,9 @@ public void testRepeatZero() { @Test(timeout = 2000) public void testRepeatOne() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpObservable.just(1).repeat(1).subscribe(o); + Observable.just(1).repeat(1).subscribe(o); verify(o).onComplete(); verify(o, times(1)).onNext(any()); @@ -155,12 +157,12 @@ public void testRepeatOne() { /** Issue #2587. */ @Test public void testRepeatAndDistinctUnbounded() { - NbpObservable src = NbpObservable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)) + Observable src = Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)) .take(3) .repeat(3) .distinct(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); src.subscribe(ts); @@ -173,15 +175,15 @@ public void testRepeatAndDistinctUnbounded() { @Test(timeout = 3000) public void testRepeatRetarget() { final List concatBase = new ArrayList(); - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.just(1, 2) + TestObserver ts = new TestObserver(); + Observable.just(1, 2) .repeat(5) - .concatMap(new Function>() { + .concatMap(new Function>() { @Override - public NbpObservable apply(Integer x) { + public Observable apply(Integer x) { System.out.println("testRepeatRetarget -> " + x); concatBase.add(x); - return NbpObservable.empty() + return Observable.empty() .delay(200, TimeUnit.MILLISECONDS); } }) diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorReplayTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorReplayTest.java similarity index 80% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorReplayTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorReplayTest.java index e7412b1e81..4cff48ae39 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorReplayTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -24,29 +24,31 @@ import org.junit.*; import org.mockito.InOrder; -import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.internal.operators.nbp.NbpOperatorReplay.*; -import io.reactivex.observables.nbp.NbpConnectableObservable; +import io.reactivex.internal.operators.observable.NbpOperatorReplay.*; +import io.reactivex.observables.ConnectableObservable; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorReplayTest { @Test public void testBufferedReplay() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpConnectableObservable co = source.replay(3); + ConnectableObservable co = source.replay(3); co.connect(); { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -69,7 +71,7 @@ public void testBufferedReplay() { } { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -85,13 +87,13 @@ public void testBufferedReplay() { @Test public void testBufferedWindowReplay() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); TestScheduler scheduler = new TestScheduler(); - NbpConnectableObservable co = source.replay(3, 100, TimeUnit.MILLISECONDS, scheduler); + ConnectableObservable co = source.replay(3, 100, TimeUnit.MILLISECONDS, scheduler); co.connect(); { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -121,7 +123,7 @@ public void testBufferedWindowReplay() { } { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -137,13 +139,13 @@ public void testBufferedWindowReplay() { public void testWindowedReplay() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpConnectableObservable co = source.replay(100, TimeUnit.MILLISECONDS, scheduler); + ConnectableObservable co = source.replay(100, TimeUnit.MILLISECONDS, scheduler); co.connect(); { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -167,7 +169,7 @@ public void testWindowedReplay() { } { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -190,21 +192,21 @@ public Integer apply(Integer t1) { }; - Function, NbpObservable> selector = new Function, NbpObservable>() { + Function, Observable> selector = new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable t1) { + public Observable apply(Observable t1) { return t1.map(dbl); } }; - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable co = source.replay(selector); + Observable co = source.replay(selector); { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -227,7 +229,7 @@ public NbpObservable apply(NbpObservable t1) { } { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -252,21 +254,21 @@ public Integer apply(Integer t1) { }; - Function, NbpObservable> selector = new Function, NbpObservable>() { + Function, Observable> selector = new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable t1) { + public Observable apply(Observable t1) { return t1.map(dbl); } }; - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable co = source.replay(selector, 3); + Observable co = source.replay(selector, 3); { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -289,7 +291,7 @@ public NbpObservable apply(NbpObservable t1) { } { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -312,10 +314,10 @@ public Integer apply(Integer t1) { }; - Function, NbpObservable> selector = new Function, NbpObservable>() { + Function, Observable> selector = new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable t1) { + public Observable apply(Observable t1) { return t1.map(dbl); } @@ -323,12 +325,12 @@ public NbpObservable apply(NbpObservable t1) { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable co = source.replay(selector, 100, TimeUnit.MILLISECONDS, scheduler); + Observable co = source.replay(selector, 100, TimeUnit.MILLISECONDS, scheduler); { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -352,7 +354,7 @@ public NbpObservable apply(NbpObservable t1) { } { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -365,13 +367,13 @@ public NbpObservable apply(NbpObservable t1) { @Test public void testBufferedReplayError() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpConnectableObservable co = source.replay(3); + ConnectableObservable co = source.replay(3); co.connect(); { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -395,7 +397,7 @@ public void testBufferedReplayError() { } { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -413,13 +415,13 @@ public void testBufferedReplayError() { public void testWindowedReplayError() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpConnectableObservable co = source.replay(100, TimeUnit.MILLISECONDS, scheduler); + ConnectableObservable co = source.replay(100, TimeUnit.MILLISECONDS, scheduler); co.connect(); { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -443,7 +445,7 @@ public void testWindowedReplayError() { } { - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(observer1); co.subscribe(observer1); @@ -458,7 +460,7 @@ public void testWindowedReplayError() { @Test public void testSynchronousDisconnect() { final AtomicInteger effectCounter = new AtomicInteger(); - NbpObservable source = NbpObservable.just(1, 2, 3, 4) + Observable source = Observable.just(1, 2, 3, 4) .doOnNext(new Consumer() { @Override public void accept(Integer v) { @@ -467,10 +469,10 @@ public void accept(Integer v) { } }); - NbpObservable result = source.replay( - new Function, NbpObservable>() { + Observable result = source.replay( + new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable o) { + public Observable apply(Observable o) { return o.take(2); } }); @@ -513,13 +515,13 @@ public void testIssue2191_UnsubscribeSource() { Consumer sourceNext = mock(Consumer.class); Runnable sourceCompleted = mock(Runnable.class); Runnable sourceUnsubscribed = mock(Runnable.class); - NbpSubscriber spiedSubscriberBeforeConnect = TestHelper.mockNbpSubscriber(); - NbpSubscriber spiedSubscriberAfterConnect = TestHelper.mockNbpSubscriber(); + Observer spiedSubscriberBeforeConnect = TestHelper.mockNbpSubscriber(); + Observer spiedSubscriberAfterConnect = TestHelper.mockNbpSubscriber(); // NbpObservable under test - NbpObservable source = NbpObservable.just(1,2); + Observable source = Observable.just(1,2); - NbpConnectableObservable replay = source + ConnectableObservable replay = source .doOnNext(sourceNext) .doOnCancel(sourceUnsubscribed) .doOnComplete(sourceCompleted) @@ -565,11 +567,11 @@ public void testIssue2191_SchedulerUnsubscribe() throws Exception { Runnable sourceUnsubscribed = mock(Runnable.class); final TestScheduler mockScheduler = Schedulers.test(); - NbpSubscriber mockObserverBeforeConnect = TestHelper.mockNbpSubscriber(); - NbpSubscriber mockObserverAfterConnect = TestHelper.mockNbpSubscriber(); + Observer mockObserverBeforeConnect = TestHelper.mockNbpSubscriber(); + Observer mockObserverAfterConnect = TestHelper.mockNbpSubscriber(); // NbpObservable under test - NbpConnectableObservable replay = NbpObservable.just(1, 2, 3) + ConnectableObservable replay = Observable.just(1, 2, 3) .doOnNext(sourceNext) .doOnCancel(sourceUnsubscribed) .doOnComplete(sourceCompleted) @@ -618,15 +620,15 @@ public void testIssue2191_SchedulerUnsubscribeOnError() throws Exception { Consumer sourceError = mock(Consumer.class); Runnable sourceUnsubscribed = mock(Runnable.class); final TestScheduler mockScheduler = new TestScheduler(); - NbpSubscriber mockObserverBeforeConnect = TestHelper.mockNbpSubscriber(); - NbpSubscriber mockObserverAfterConnect = TestHelper.mockNbpSubscriber(); + Observer mockObserverBeforeConnect = TestHelper.mockNbpSubscriber(); + Observer mockObserverAfterConnect = TestHelper.mockNbpSubscriber(); // NbpObservable under test Function mockFunc = mock(Function.class); IllegalArgumentException illegalArgumentException = new IllegalArgumentException(); when(mockFunc.apply(1)).thenReturn(1); when(mockFunc.apply(2)).thenThrow(illegalArgumentException); - NbpConnectableObservable replay = NbpObservable.just(1, 2, 3).map(mockFunc) + ConnectableObservable replay = Observable.just(1, 2, 3).map(mockFunc) .doOnNext(sourceNext) .doOnCancel(sourceUnsubscribed) .doOnComplete(sourceCompleted) @@ -661,13 +663,13 @@ public void testIssue2191_SchedulerUnsubscribeOnError() throws Exception { verifyNoMoreInteractions(mockObserverAfterConnect); } - private static void verifyObserverMock(NbpSubscriber mock, int numSubscriptions, int numItemsExpected) { + private static void verifyObserverMock(Observer mock, int numSubscriptions, int numItemsExpected) { verify(mock, times(numItemsExpected)).onNext((Integer) notNull()); verify(mock, times(numSubscriptions)).onComplete(); verifyNoMoreInteractions(mock); } - private static void verifyObserver(NbpSubscriber mock, int numSubscriptions, int numItemsExpected, Throwable error) { + private static void verifyObserver(Observer mock, int numSubscriptions, int numItemsExpected, Throwable error) { verify(mock, times(numItemsExpected)).onNext((Integer) notNull()); verify(mock, times(numSubscriptions)).onError(error); verifyNoMoreInteractions(mock); @@ -779,9 +781,9 @@ public void testTimedAndSizedTruncation() { @Test public void testColdReplayNoBackpressure() { - NbpObservable source = NbpObservable.range(0, 1000).replay().autoConnect(); + Observable source = Observable.range(0, 1000).replay().autoConnect(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); source.subscribe(ts); @@ -798,10 +800,10 @@ public void testColdReplayNoBackpressure() { @Test public void testCache() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - NbpObservable o = NbpObservable.create(new NbpOnSubscribe() { + Observable o = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); new Thread(new Runnable() { @@ -850,7 +852,7 @@ public void accept(String v) { @Test public void testUnsubscribeSource() { Runnable unsubscribe = mock(Runnable.class); - NbpObservable o = NbpObservable.just(1).doOnCancel(unsubscribe).cache(); + Observable o = Observable.just(1).doOnCancel(unsubscribe).cache(); o.subscribe(); o.subscribe(); o.subscribe(); @@ -859,9 +861,9 @@ public void testUnsubscribeSource() { @Test public void testTake() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); - NbpObservable cached = NbpObservable.range(1, 100).replay().autoConnect(); + Observable cached = Observable.range(1, 100).replay().autoConnect(); cached.take(10).subscribe(ts); ts.assertNoErrors(); @@ -873,11 +875,11 @@ public void testTake() { @Test public void testAsync() { - NbpObservable source = NbpObservable.range(1, 10000); + Observable source = Observable.range(1, 10000); for (int i = 0; i < 100; i++) { - NbpTestSubscriber ts1 = new NbpTestSubscriber(); + TestObserver ts1 = new TestObserver(); - NbpObservable cached = source.replay().autoConnect(); + Observable cached = source.replay().autoConnect(); cached.observeOn(Schedulers.computation()).subscribe(ts1); @@ -886,7 +888,7 @@ public void testAsync() { ts1.assertTerminated(); assertEquals(10000, ts1.values().size()); - NbpTestSubscriber ts2 = new NbpTestSubscriber(); + TestObserver ts2 = new TestObserver(); cached.observeOn(Schedulers.computation()).subscribe(ts2); ts2.awaitTerminalEvent(2, TimeUnit.SECONDS); @@ -897,16 +899,16 @@ public void testAsync() { } @Test public void testAsyncComeAndGo() { - NbpObservable source = NbpObservable.interval(1, 1, TimeUnit.MILLISECONDS) + Observable source = Observable.interval(1, 1, TimeUnit.MILLISECONDS) .take(1000) .subscribeOn(Schedulers.io()); - NbpObservable cached = source.replay().autoConnect(); + Observable cached = source.replay().autoConnect(); - NbpObservable output = cached.observeOn(Schedulers.computation()); + Observable output = cached.observeOn(Schedulers.computation()); - List> list = new ArrayList>(100); + List> list = new ArrayList>(100); for (int i = 0; i < 100; i++) { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); list.add(ts); output.skip(i * 10).take(10).subscribe(ts); } @@ -916,7 +918,7 @@ public void testAsyncComeAndGo() { expected.add((long)(i - 10)); } int j = 0; - for (NbpTestSubscriber ts : list) { + for (TestObserver ts : list) { ts.awaitTerminalEvent(3, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertTerminated(); @@ -934,9 +936,9 @@ public void testAsyncComeAndGo() { @Test public void testNoMissingBackpressureException() { final int m = 4 * 1000 * 1000; - NbpObservable firehose = NbpObservable.create(new NbpOnSubscribe() { + Observable firehose = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber t) { + public void accept(Observer t) { t.onSubscribe(EmptyDisposable.INSTANCE); for (int i = 0; i < m; i++) { t.onNext(i); @@ -945,7 +947,7 @@ public void accept(NbpSubscriber t) { } }); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); firehose.replay().autoConnect().observeOn(Schedulers.computation()).takeLast(100).subscribe(ts); ts.awaitTerminalEvent(3, TimeUnit.SECONDS); @@ -957,19 +959,19 @@ public void accept(NbpSubscriber t) { @Test public void testValuesAndThenError() { - NbpObservable source = NbpObservable.range(1, 10) - .concatWith(NbpObservable.error(new TestException())) + Observable source = Observable.range(1, 10) + .concatWith(Observable.error(new TestException())) .replay().autoConnect(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); source.subscribe(ts); ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); ts.assertNotComplete(); Assert.assertEquals(1, ts.errors().size()); - NbpTestSubscriber ts2 = new NbpTestSubscriber(); + TestObserver ts2 = new TestObserver(); source.subscribe(ts2); ts2.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); @@ -981,7 +983,7 @@ public void testValuesAndThenError() { public void unsafeChildThrows() { final AtomicInteger count = new AtomicInteger(); - NbpObservable source = NbpObservable.range(1, 100) + Observable source = Observable.range(1, 100) .doOnNext(new Consumer() { @Override public void accept(Integer t) { @@ -990,7 +992,7 @@ public void accept(Integer t) { }) .replay().autoConnect(); - NbpTestSubscriber ts = new NbpTestSubscriber() { + TestObserver ts = new TestObserver() { @Override public void onNext(Integer t) { throw new TestException(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorRetryTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorRetryTest.java similarity index 79% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorRetryTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorRetryTest.java index 01e9790ed5..9dc24f90f8 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorRetryTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,30 +25,32 @@ import org.mockito.*; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.observables.nbp.NbpGroupedObservable; +import io.reactivex.observables.GroupedObservable; +import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; -import io.reactivex.Observable; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorRetryTest { @Test public void iterativeBackoff() { - NbpSubscriber consumer = TestHelper.mockNbpSubscriber(); + Observer consumer = TestHelper.mockNbpSubscriber(); - NbpObservable producer = NbpObservable.create(new NbpOnSubscribe() { + Observable producer = Observable.create(new NbpOnSubscribe() { private AtomicInteger count = new AtomicInteger(4); long last = System.currentTimeMillis(); @Override - public void accept(NbpSubscriber t1) { + public void accept(Observer t1) { t1.onSubscribe(EmptyDisposable.INSTANCE); System.out.println(count.get() + " @ " + String.valueOf(last - System.currentTimeMillis())); last = System.currentTimeMillis(); @@ -61,11 +63,11 @@ public void accept(NbpSubscriber t1) { } }); - NbpTestSubscriber ts = new NbpTestSubscriber(consumer); - producer.retryWhen(new Function, NbpObservable>() { + TestObserver ts = new TestObserver(consumer); + producer.retryWhen(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable attempts) { + public Observable apply(Observable attempts) { // Worker w = Schedulers.computation().createWorker(); return attempts .map(new Function() { @@ -78,13 +80,13 @@ public Tuple apply(Throwable n) { public Tuple apply(Tuple t, Tuple n) { return new Tuple(t.count + n.count, n.n); }}) - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public NbpObservable apply(Tuple t) { + public Observable apply(Tuple t) { System.out.println("Retry # "+t.count); return t.count > 20 ? - NbpObservable.error(t.n) : - NbpObservable.timer(t.count *1L, TimeUnit.MILLISECONDS); + Observable.error(t.n) : + Observable.timer(t.count *1L, TimeUnit.MILLISECONDS); }}).cast(Object.class); } }).subscribe(ts); @@ -111,10 +113,10 @@ public static class Tuple { @Test public void testRetryIndefinitely() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); int NUM_RETRIES = 20; - NbpObservable origin = NbpObservable.create(new FuncWithErrors(NUM_RETRIES)); - origin.retry().unsafeSubscribe(new NbpTestSubscriber(NbpObserver)); + Observable origin = Observable.create(new FuncWithErrors(NUM_RETRIES)); + origin.retry().unsafeSubscribe(new TestObserver(NbpObserver)); InOrder inOrder = inOrder(NbpObserver); // should show 3 attempts @@ -130,13 +132,13 @@ public void testRetryIndefinitely() { @Test public void testSchedulingNotificationHandler() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); int NUM_RETRIES = 2; - NbpObservable origin = NbpObservable.create(new FuncWithErrors(NUM_RETRIES)); - NbpTestSubscriber NbpSubscriber = new NbpTestSubscriber(NbpObserver); - origin.retryWhen(new Function, NbpObservable>() { + Observable origin = Observable.create(new FuncWithErrors(NUM_RETRIES)); + TestObserver NbpSubscriber = new TestObserver(NbpObserver); + origin.retryWhen(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable t1) { + public Observable apply(Observable t1) { return t1 .observeOn(Schedulers.computation()) .map(new Function() { @@ -170,12 +172,12 @@ public void accept(Throwable e) { @Test public void testOnNextFromNotificationHandler() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); int NUM_RETRIES = 2; - NbpObservable origin = NbpObservable.create(new FuncWithErrors(NUM_RETRIES)); - origin.retryWhen(new Function, NbpObservable>() { + Observable origin = Observable.create(new FuncWithErrors(NUM_RETRIES)); + origin.retryWhen(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable t1) { + public Observable apply(Observable t1) { return t1.map(new Function() { @Override @@ -200,13 +202,13 @@ public Integer apply(Throwable t1) { @Test public void testOnCompletedFromNotificationHandler() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable origin = NbpObservable.create(new FuncWithErrors(1)); - NbpTestSubscriber NbpSubscriber = new NbpTestSubscriber(NbpObserver); - origin.retryWhen(new Function, NbpObservable>() { + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + Observable origin = Observable.create(new FuncWithErrors(1)); + TestObserver NbpSubscriber = new TestObserver(NbpObserver); + origin.retryWhen(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable t1) { - return NbpObservable.empty(); + public Observable apply(Observable t1) { + return Observable.empty(); } }).subscribe(NbpSubscriber); @@ -221,12 +223,12 @@ public NbpObservable apply(NbpObservable t1) { @Test public void testOnErrorFromNotificationHandler() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable origin = NbpObservable.create(new FuncWithErrors(2)); - origin.retryWhen(new Function, NbpObservable>() { + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + Observable origin = Observable.create(new FuncWithErrors(2)); + origin.retryWhen(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable t1) { - return NbpObservable.error(new RuntimeException()); + public Observable apply(Observable t1) { + return Observable.error(new RuntimeException()); } }).subscribe(NbpObserver); @@ -244,7 +246,7 @@ public void testSingleSubscriptionOnFirst() throws Exception { final AtomicInteger inc = new AtomicInteger(0); NbpOnSubscribe onSubscribe = new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpSubscriber) { + public void accept(Observer NbpSubscriber) { NbpSubscriber.onSubscribe(EmptyDisposable.INSTANCE); final int emit = inc.incrementAndGet(); NbpSubscriber.onNext(emit); @@ -252,11 +254,11 @@ public void accept(NbpSubscriber NbpSubscriber) { } }; - int first = NbpObservable.create(onSubscribe) - .retryWhen(new Function, NbpObservable>() { + int first = Observable.create(onSubscribe) + .retryWhen(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable attempt) { - return attempt.zipWith(NbpObservable.just(1), new BiFunction() { + public Observable apply(Observable attempt) { + return attempt.zipWith(Observable.just(1), new BiFunction() { @Override public Void apply(Throwable o, Integer integer) { return null; @@ -273,8 +275,8 @@ public Void apply(Throwable o, Integer integer) { @Test public void testOriginFails() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable origin = NbpObservable.create(new FuncWithErrors(1)); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + Observable origin = Observable.create(new FuncWithErrors(1)); origin.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -288,8 +290,8 @@ public void testOriginFails() { public void testRetryFail() { int NUM_RETRIES = 1; int NUM_FAILURES = 2; - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable origin = NbpObservable.create(new FuncWithErrors(NUM_FAILURES)); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + Observable origin = Observable.create(new FuncWithErrors(NUM_FAILURES)); origin.retry(NUM_RETRIES).subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -306,8 +308,8 @@ public void testRetryFail() { @Test public void testRetrySuccess() { int NUM_FAILURES = 1; - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable origin = NbpObservable.create(new FuncWithErrors(NUM_FAILURES)); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + Observable origin = Observable.create(new FuncWithErrors(NUM_FAILURES)); origin.retry(3).subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -325,8 +327,8 @@ public void testRetrySuccess() { @Test public void testInfiniteRetry() { int NUM_FAILURES = 20; - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable origin = NbpObservable.create(new FuncWithErrors(NUM_FAILURES)); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + Observable origin = Observable.create(new FuncWithErrors(NUM_FAILURES)); origin.retry().subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -359,7 +361,7 @@ public void testRetrySubscribesAgainAfterError() { doThrow(new RuntimeException()).when(throwException).accept(Mockito.anyInt()); // create a retrying NbpObservable based on a NbpPublishSubject - NbpPublishSubject subject = NbpPublishSubject.create(); + PublishSubject subject = PublishSubject.create(); subject // record item .doOnNext(record) @@ -394,7 +396,7 @@ public static class FuncWithErrors implements NbpOnSubscribe { } @Override - public void accept(final NbpSubscriber o) { + public void accept(final Observer o) { o.onSubscribe(EmptyDisposable.INSTANCE); o.onNext("beginningEveryTime"); int i = count.getAndIncrement(); @@ -409,7 +411,7 @@ public void accept(final NbpSubscriber o) { @Test public void testUnsubscribeFromRetry() { - NbpPublishSubject subject = NbpPublishSubject.create(); + PublishSubject subject = PublishSubject.create(); final AtomicInteger count = new AtomicInteger(0); Disposable sub = subject.retry().subscribe(new Consumer() { @Override @@ -428,7 +430,7 @@ public void testRetryAllowsSubscriptionAfterAllSubscriptionsUnsubscribed() throw final AtomicInteger subsCount = new AtomicInteger(0); NbpOnSubscribe onSubscribe = new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { subsCount.incrementAndGet(); s.onSubscribe(new Disposable() { @Override @@ -439,8 +441,8 @@ public void dispose() { } }; - NbpObservable stream = NbpObservable.create(onSubscribe); - NbpObservable streamWithRetry = stream.retry(); + Observable stream = Observable.create(onSubscribe); + Observable streamWithRetry = stream.retry(); Disposable sub = streamWithRetry.subscribe(); assertEquals(1, subsCount.get()); sub.dispose(); @@ -453,11 +455,11 @@ public void dispose() { public void testSourceObservableCallsUnsubscribe() throws InterruptedException { final AtomicInteger subsCount = new AtomicInteger(0); - final NbpTestSubscriber ts = new NbpTestSubscriber(); + final TestObserver ts = new TestObserver(); NbpOnSubscribe onSubscribe = new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { BooleanSubscription bs = new BooleanSubscription(); // if isUnsubscribed is true that means we have a bug such as // https://github.com/ReactiveX/RxJava/issues/1024 @@ -476,7 +478,7 @@ public void accept(NbpSubscriber s) { } }; - NbpObservable.create(onSubscribe).retry(3).subscribe(ts); + Observable.create(onSubscribe).retry(3).subscribe(ts); assertEquals(4, subsCount.get()); // 1 + 3 retries } @@ -484,18 +486,18 @@ public void accept(NbpSubscriber s) { public void testSourceObservableRetry1() throws InterruptedException { final AtomicInteger subsCount = new AtomicInteger(0); - final NbpTestSubscriber ts = new NbpTestSubscriber(); + final TestObserver ts = new TestObserver(); NbpOnSubscribe onSubscribe = new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { s.onSubscribe(EmptyDisposable.INSTANCE); subsCount.incrementAndGet(); s.onError(new RuntimeException("failed")); } }; - NbpObservable.create(onSubscribe).retry(1).subscribe(ts); + Observable.create(onSubscribe).retry(1).subscribe(ts); assertEquals(2, subsCount.get()); } @@ -503,18 +505,18 @@ public void accept(NbpSubscriber s) { public void testSourceObservableRetry0() throws InterruptedException { final AtomicInteger subsCount = new AtomicInteger(0); - final NbpTestSubscriber ts = new NbpTestSubscriber(); + final TestObserver ts = new TestObserver(); NbpOnSubscribe onSubscribe = new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { s.onSubscribe(EmptyDisposable.INSTANCE); subsCount.incrementAndGet(); s.onError(new RuntimeException("failed")); } }; - NbpObservable.create(onSubscribe).retry(0).subscribe(ts); + Observable.create(onSubscribe).retry(0).subscribe(ts); assertEquals(1, subsCount.get()); } @@ -532,7 +534,7 @@ public SlowObservable(int emitDelay, int countNext) { } @Override - public void accept(final NbpSubscriber NbpSubscriber) { + public void accept(final Observer NbpSubscriber) { final AtomicBoolean terminate = new AtomicBoolean(false); NbpSubscriber.onSubscribe(new Disposable() { @Override @@ -566,17 +568,17 @@ public void run() { } /** NbpObserver for listener on seperate thread */ - static final class AsyncObserver extends NbpObserver { + static final class AsyncObserver extends DefaultObserver { protected CountDownLatch latch = new CountDownLatch(1); - protected NbpSubscriber target; + protected Observer target; /** * Wrap existing NbpObserver * @param target the target nbp subscriber */ - public AsyncObserver(NbpSubscriber target) { + public AsyncObserver(Observer target) { this.target = target; } @@ -612,11 +614,11 @@ public void onNext(T v) { @Test(timeout = 10000) public void testUnsubscribeAfterError() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); // NbpObservable that always fails after 100ms SlowObservable so = new SlowObservable(100, 0); - NbpObservable o = NbpObservable.create(so).retry(5); + Observable o = Observable.create(so).retry(5); AsyncObserver async = new AsyncObserver(NbpObserver); @@ -637,11 +639,11 @@ public void testUnsubscribeAfterError() { public void testTimeoutWithRetry() { @SuppressWarnings("unchecked") - NbpObserver NbpObserver = mock(NbpObserver.class); + DefaultObserver NbpObserver = mock(DefaultObserver.class); // NbpObservable that sends every 100ms (timeout fails instead) SlowObservable so = new SlowObservable(100, 10); - NbpObservable o = NbpObservable.create(so).timeout(80, TimeUnit.MILLISECONDS).retry(5); + Observable o = Observable.create(so).timeout(80, TimeUnit.MILLISECONDS).retry(5); AsyncObserver async = new AsyncObserver(NbpObserver); @@ -661,11 +663,11 @@ public void testTimeoutWithRetry() { public void testRetryWithBackpressure() throws InterruptedException { final int NUM_LOOPS = 1; for (int j=0;j NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable origin = NbpObservable.create(new FuncWithErrors(NUM_RETRIES)); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + Observable origin = Observable.create(new FuncWithErrors(NUM_RETRIES)); + TestObserver ts = new TestObserver(NbpObserver); origin.retry().observeOn(Schedulers.computation()).unsafeSubscribe(ts); ts.awaitTerminalEvent(5, TimeUnit.SECONDS); @@ -686,7 +688,7 @@ public void testRetryWithBackpressure() throws InterruptedException { @Test//(timeout = 15000) public void testRetryWithBackpressureParallel() throws InterruptedException { final int NUM_LOOPS = 1; - final int NUM_RETRIES = Observable.bufferSize() * 2; + final int NUM_RETRIES = Flowable.bufferSize() * 2; int ncpu = Runtime.getRuntime().availableProcessors(); ExecutorService exec = Executors.newFixedThreadPool(Math.max(ncpu / 2, 2)); try { @@ -707,8 +709,8 @@ public void testRetryWithBackpressureParallel() throws InterruptedException { public void run() { final AtomicInteger nexts = new AtomicInteger(); try { - NbpObservable origin = NbpObservable.create(new FuncWithErrors(NUM_RETRIES)); - NbpTestSubscriber ts = new NbpTestSubscriber(); + Observable origin = Observable.create(new FuncWithErrors(NUM_RETRIES)); + TestObserver ts = new TestObserver(); origin.retry() .observeOn(Schedulers.computation()).unsafeSubscribe(ts); ts.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS); @@ -784,11 +786,11 @@ static StringBuilder sequenceFrequency(Iterable it) { } @Test//(timeout = 3000) public void testIssue1900() throws InterruptedException { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); final int NUM_MSG = 1034; final AtomicInteger count = new AtomicInteger(); - NbpObservable origin = NbpObservable.range(0, NUM_MSG) + Observable origin = Observable.range(0, NUM_MSG) .map(new Function() { @Override public String apply(Integer t1) { @@ -803,13 +805,13 @@ public String apply(String t1) { return t1; } }) - .flatMap(new Function, NbpObservable>() { + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(NbpGroupedObservable t1) { + public Observable apply(GroupedObservable t1) { return t1.take(1); } }) - .unsafeSubscribe(new NbpTestSubscriber(NbpObserver)); + .unsafeSubscribe(new TestObserver(NbpObserver)); InOrder inOrder = inOrder(NbpObserver); // should show 3 attempts @@ -824,14 +826,14 @@ public NbpObservable apply(NbpGroupedObservable t1) { } @Test//(timeout = 3000) public void testIssue1900SourceNotSupportingBackpressure() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); final int NUM_MSG = 1034; final AtomicInteger count = new AtomicInteger(); - NbpObservable origin = NbpObservable.create(new NbpOnSubscribe() { + Observable origin = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber o) { + public void accept(Observer o) { o.onSubscribe(EmptyDisposable.INSTANCE); for(int i=0; i, NbpObservable>() { + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(NbpGroupedObservable t1) { + public Observable apply(GroupedObservable t1) { return t1.take(1); } }) - .unsafeSubscribe(new NbpTestSubscriber(NbpObserver)); + .unsafeSubscribe(new TestObserver(NbpObserver)); InOrder inOrder = inOrder(NbpObserver); // should show 3 attempts diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorRetryWithPredicateTest.java similarity index 84% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorRetryWithPredicateTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorRetryWithPredicateTest.java index 8ab79a2aaf..6a89ba6704 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorRetryWithPredicateTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -25,14 +25,16 @@ import org.junit.Test; import org.mockito.InOrder; -import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.*; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorRetryWithPredicateTest { BiPredicate retryTwice = new BiPredicate() { @@ -55,9 +57,9 @@ public boolean test(Integer t1, Throwable t2) { }; @Test public void testWithNothingToRetry() { - NbpObservable source = NbpObservable.range(0, 3); + Observable source = Observable.range(0, 3); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.retry(retryTwice).subscribe(o); @@ -70,10 +72,10 @@ public void testWithNothingToRetry() { } @Test public void testRetryTwice() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { int count; @Override - public void accept(NbpSubscriber t1) { + public void accept(Observer t1) { t1.onSubscribe(EmptyDisposable.INSTANCE); count++; t1.onNext(0); @@ -89,7 +91,7 @@ public void accept(NbpSubscriber t1) { }); @SuppressWarnings("unchecked") - NbpObserver o = mock(NbpObserver.class); + DefaultObserver o = mock(DefaultObserver.class); InOrder inOrder = inOrder(o); source.retry(retryTwice).subscribe(o); @@ -106,9 +108,9 @@ public void accept(NbpSubscriber t1) { } @Test public void testRetryTwiceAndGiveUp() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber t1) { + public void accept(Observer t1) { t1.onSubscribe(EmptyDisposable.INSTANCE); t1.onNext(0); t1.onNext(1); @@ -117,7 +119,7 @@ public void accept(NbpSubscriber t1) { }); @SuppressWarnings("unchecked") - NbpObserver o = mock(NbpObserver.class); + DefaultObserver o = mock(DefaultObserver.class); InOrder inOrder = inOrder(o); source.retry(retryTwice).subscribe(o); @@ -134,10 +136,10 @@ public void accept(NbpSubscriber t1) { } @Test public void testRetryOnSpecificException() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { int count; @Override - public void accept(NbpSubscriber t1) { + public void accept(Observer t1) { t1.onSubscribe(EmptyDisposable.INSTANCE); count++; t1.onNext(0); @@ -153,7 +155,7 @@ public void accept(NbpSubscriber t1) { }); @SuppressWarnings("unchecked") - NbpObserver o = mock(NbpObserver.class); + DefaultObserver o = mock(DefaultObserver.class); InOrder inOrder = inOrder(o); source.retry(retryOnTestException).subscribe(o); @@ -171,10 +173,10 @@ public void accept(NbpSubscriber t1) { public void testRetryOnSpecificExceptionAndNotOther() { final IOException ioe = new IOException(); final TestException te = new TestException(); - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { int count; @Override - public void accept(NbpSubscriber t1) { + public void accept(Observer t1) { t1.onSubscribe(EmptyDisposable.INSTANCE); count++; t1.onNext(0); @@ -190,7 +192,7 @@ public void accept(NbpSubscriber t1) { }); @SuppressWarnings("unchecked") - NbpObserver o = mock(NbpObserver.class); + DefaultObserver o = mock(DefaultObserver.class); InOrder inOrder = inOrder(o); source.retry(retryOnTestException).subscribe(o); @@ -208,7 +210,7 @@ public void accept(NbpSubscriber t1) { @Test public void testUnsubscribeFromRetry() { - NbpPublishSubject subject = NbpPublishSubject.create(); + PublishSubject subject = PublishSubject.create(); final AtomicInteger count = new AtomicInteger(0); Disposable sub = subject.retry(retryTwice).subscribe(new Consumer() { @Override @@ -225,11 +227,11 @@ public void accept(Integer n) { @Test(timeout = 10000) public void testUnsubscribeAfterError() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); // NbpObservable that always fails after 100ms NbpOperatorRetryTest.SlowObservable so = new NbpOperatorRetryTest.SlowObservable(100, 0); - NbpObservable o = NbpObservable + Observable o = Observable .create(so) .retry(retry5); @@ -251,11 +253,11 @@ public void testUnsubscribeAfterError() { @Test(timeout = 10000) public void testTimeoutWithRetry() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); // NbpObservable that sends every 100ms (timeout fails instead) NbpOperatorRetryTest.SlowObservable so = new NbpOperatorRetryTest.SlowObservable(100, 10); - NbpObservable o = NbpObservable + Observable o = Observable .create(so) .timeout(80, TimeUnit.MILLISECONDS) .retry(retry5); @@ -276,10 +278,10 @@ public void testTimeoutWithRetry() { @Test public void testIssue2826() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final RuntimeException e = new RuntimeException("You shall not pass"); final AtomicInteger c = new AtomicInteger(); - NbpObservable.just(1).map(new Function() { + Observable.just(1).map(new Function() { @Override public Integer apply(Integer t1) { c.incrementAndGet(); @@ -294,7 +296,7 @@ public Integer apply(Integer t1) { @Test public void testJustAndRetry() throws Exception { final AtomicBoolean throwException = new AtomicBoolean(true); - int value = NbpObservable.just(1).map(new Function() { + int value = Observable.just(1).map(new Function() { @Override public Integer apply(Integer t1) { if (throwException.compareAndSet(true, false)) { @@ -311,7 +313,7 @@ public Integer apply(Integer t1) { public void testIssue3008RetryWithPredicate() { final List list = new CopyOnWriteArrayList(); final AtomicBoolean isFirst = new AtomicBoolean(true); - NbpObservable. just(1L, 2L, 3L).map(new Function(){ + Observable. just(1L, 2L, 3L).map(new Function(){ @Override public Long apply(Long x) { System.out.println("map " + x); @@ -339,7 +341,7 @@ public void accept(Long t) { public void testIssue3008RetryInfinite() { final List list = new CopyOnWriteArrayList(); final AtomicBoolean isFirst = new AtomicBoolean(true); - NbpObservable. just(1L, 2L, 3L).map(new Function(){ + Observable. just(1L, 2L, 3L).map(new Function(){ @Override public Long apply(Long x) { System.out.println("map " + x); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSampleTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSampleTest.java similarity index 79% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSampleTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSampleTest.java index 3626ea6759..263b7e1baf 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSampleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSampleTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,17 +22,18 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.Disposable; +import io.reactivex.flowable.TestHelper; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorSampleTest { private TestScheduler scheduler; private Scheduler.Worker innerScheduler; - private NbpSubscriber NbpObserver; - private NbpSubscriber observer2; + private Observer NbpObserver; + private Observer observer2; @Before // due to mocking @@ -45,9 +46,9 @@ public void before() { @Test public void testSample() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber observer1) { + public void accept(final Observer observer1) { observer1.onSubscribe(EmptyDisposable.INSTANCE); innerScheduler.schedule(new Runnable() { @Override @@ -70,7 +71,7 @@ public void run() { } }); - NbpObservable sampled = source.sample(400L, TimeUnit.MILLISECONDS, scheduler); + Observable sampled = source.sample(400L, TimeUnit.MILLISECONDS, scheduler); sampled.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -107,10 +108,10 @@ public void run() { @Test public void sampleWithSamplerNormal() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject sampler = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject sampler = PublishSubject.create(); - NbpObservable m = source.sample(sampler); + Observable m = source.sample(sampler); m.subscribe(observer2); source.onNext(1); @@ -133,10 +134,10 @@ public void sampleWithSamplerNormal() { @Test public void sampleWithSamplerNoDuplicates() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject sampler = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject sampler = PublishSubject.create(); - NbpObservable m = source.sample(sampler); + Observable m = source.sample(sampler); m.subscribe(observer2); source.onNext(1); @@ -163,10 +164,10 @@ public void sampleWithSamplerNoDuplicates() { @Test public void sampleWithSamplerTerminatingEarly() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject sampler = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject sampler = PublishSubject.create(); - NbpObservable m = source.sample(sampler); + Observable m = source.sample(sampler); m.subscribe(observer2); source.onNext(1); @@ -187,10 +188,10 @@ public void sampleWithSamplerTerminatingEarly() { @Test public void sampleWithSamplerEmitAndTerminate() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject sampler = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject sampler = PublishSubject.create(); - NbpObservable m = source.sample(sampler); + Observable m = source.sample(sampler); m.subscribe(observer2); source.onNext(1); @@ -212,10 +213,10 @@ public void sampleWithSamplerEmitAndTerminate() { @Test public void sampleWithSamplerEmptySource() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject sampler = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject sampler = PublishSubject.create(); - NbpObservable m = source.sample(sampler); + Observable m = source.sample(sampler); m.subscribe(observer2); source.onComplete(); @@ -229,10 +230,10 @@ public void sampleWithSamplerEmptySource() { @Test public void sampleWithSamplerSourceThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject sampler = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject sampler = PublishSubject.create(); - NbpObservable m = source.sample(sampler); + Observable m = source.sample(sampler); m.subscribe(observer2); source.onNext(1); @@ -247,10 +248,10 @@ public void sampleWithSamplerSourceThrows() { @Test public void sampleWithSamplerThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject sampler = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject sampler = PublishSubject.create(); - NbpObservable m = source.sample(sampler); + Observable m = source.sample(sampler); m.subscribe(observer2); source.onNext(1); @@ -266,10 +267,10 @@ public void sampleWithSamplerThrows() { @Test public void testSampleUnsubscribe() { final Disposable s = mock(Disposable.class); - NbpObservable o = NbpObservable.create( + Observable o = Observable.create( new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpSubscriber) { + public void accept(Observer NbpSubscriber) { NbpSubscriber.onSubscribe(s); } } diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorScanTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorScanTest.java similarity index 79% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorScanTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorScanTest.java index 3e0bb925d6..47badd1847 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorScanTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorScanTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -22,21 +22,22 @@ import org.junit.Test; -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.*; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorScanTest { @Test public void testScanIntegersWithInitialValue() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable o = NbpObservable.just(1, 2, 3); + Observable o = Observable.just(1, 2, 3); - NbpObservable m = o.scan("", new BiFunction() { + Observable m = o.scan("", new BiFunction() { @Override public String apply(String s, Integer n) { @@ -58,11 +59,11 @@ public String apply(String s, Integer n) { @Test public void testScanIntegersWithoutInitialValue() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable o = NbpObservable.just(1, 2, 3); + Observable o = Observable.just(1, 2, 3); - NbpObservable m = o.scan(new BiFunction() { + Observable m = o.scan(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -84,11 +85,11 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testScanIntegersWithoutInitialValueAndOnlyOneValue() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable o = NbpObservable.just(1); + Observable o = Observable.just(1); - NbpObservable m = o.scan(new BiFunction() { + Observable m = o.scan(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -108,8 +109,8 @@ public Integer apply(Integer t1, Integer t2) { @Test public void shouldNotEmitUntilAfterSubscription() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(1, 100).scan(0, new BiFunction() { + TestObserver ts = new TestObserver(); + Observable.range(1, 100).scan(0, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -132,7 +133,7 @@ public boolean test(Integer t1) { @Test public void testNoBackpressureWithInitialValue() { final AtomicInteger count = new AtomicInteger(); - NbpObservable.range(1, 100) + Observable.range(1, 100) .scan(0, new BiFunction() { @Override @@ -141,7 +142,7 @@ public Integer apply(Integer t1, Integer t2) { } }) - .subscribe(new NbpObserver() { + .subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -170,7 +171,7 @@ public void onNext(Integer t) { */ @Test public void testSeedFactory() { - NbpObservable> o = NbpObservable.range(1, 10) + Observable> o = Observable.range(1, 10) .collect(new Supplier>() { @Override @@ -193,7 +194,7 @@ public void accept(List list, Integer t2) { @Test public void testScanWithRequestOne() { - NbpObservable o = NbpObservable.just(1, 2).scan(0, new BiFunction() { + Observable o = Observable.just(1, 2).scan(0, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -201,7 +202,7 @@ public Integer apply(Integer t1, Integer t2) { } }).take(1); - NbpTestSubscriber NbpSubscriber = new NbpTestSubscriber(); + TestObserver NbpSubscriber = new TestObserver(); o.subscribe(NbpSubscriber); NbpSubscriber.assertValue(0); NbpSubscriber.assertTerminated(); @@ -210,9 +211,9 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testInitialValueEmittedNoProducer() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); source.scan(0, new BiFunction() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/OperatorSequenceEqualTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSequenceEqualTest.java similarity index 62% rename from src/test/java/io/reactivex/internal/operators/OperatorSequenceEqualTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSequenceEqualTest.java index 6ff76ae95e..33bcdf1c2b 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorSequenceEqualTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSequenceEqualTest.java @@ -11,115 +11,115 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.*; import org.junit.*; import org.mockito.InOrder; -import org.reactivestreams.Subscriber; import io.reactivex.*; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.BiPredicate; -public class OperatorSequenceEqualTest { +public class NbpOperatorSequenceEqualTest { @Test public void test1() { - Observable observable = Observable.sequenceEqual( + Observable o = Observable.sequenceEqual( Observable.just("one", "two", "three"), Observable.just("one", "two", "three")); - verifyResult(observable, true); + verifyResult(o, true); } @Test public void test2() { - Observable observable = Observable.sequenceEqual( + Observable o = Observable.sequenceEqual( Observable.just("one", "two", "three"), Observable.just("one", "two", "three", "four")); - verifyResult(observable, false); + verifyResult(o, false); } @Test public void test3() { - Observable observable = Observable.sequenceEqual( + Observable o = Observable.sequenceEqual( Observable.just("one", "two", "three", "four"), Observable.just("one", "two", "three")); - verifyResult(observable, false); + verifyResult(o, false); } @Test public void testWithError1() { - Observable observable = Observable.sequenceEqual( + Observable o = Observable.sequenceEqual( Observable.concat(Observable.just("one"), Observable. error(new TestException())), Observable.just("one", "two", "three")); - verifyError(observable); + verifyError(o); } @Test public void testWithError2() { - Observable observable = Observable.sequenceEqual( + Observable o = Observable.sequenceEqual( Observable.just("one", "two", "three"), Observable.concat(Observable.just("one"), Observable. error(new TestException()))); - verifyError(observable); + verifyError(o); } @Test public void testWithError3() { - Observable observable = Observable.sequenceEqual( + Observable o = Observable.sequenceEqual( Observable.concat(Observable.just("one"), Observable. error(new TestException())), Observable.concat(Observable.just("one"), Observable. error(new TestException()))); - verifyError(observable); + verifyError(o); } @Test public void testWithEmpty1() { - Observable observable = Observable.sequenceEqual( + Observable o = Observable.sequenceEqual( Observable. empty(), Observable.just("one", "two", "three")); - verifyResult(observable, false); + verifyResult(o, false); } @Test public void testWithEmpty2() { - Observable observable = Observable.sequenceEqual( + Observable o = Observable.sequenceEqual( Observable.just("one", "two", "three"), Observable. empty()); - verifyResult(observable, false); + verifyResult(o, false); } @Test public void testWithEmpty3() { - Observable observable = Observable.sequenceEqual( + Observable o = Observable.sequenceEqual( Observable. empty(), Observable. empty()); - verifyResult(observable, true); + verifyResult(o, true); } @Test @Ignore("Null values not allowed") public void testWithNull1() { - Observable observable = Observable.sequenceEqual( + Observable o = Observable.sequenceEqual( Observable.just((String) null), Observable.just("one")); - verifyResult(observable, false); + verifyResult(o, false); } @Test @Ignore("Null values not allowed") public void testWithNull2() { - Observable observable = Observable.sequenceEqual( + Observable o = Observable.sequenceEqual( Observable.just((String) null), Observable.just((String) null)); - verifyResult(observable, true); + verifyResult(o, true); } @Test public void testWithEqualityError() { - Observable observable = Observable.sequenceEqual( + Observable o = Observable.sequenceEqual( Observable.just("one"), Observable.just("one"), new BiPredicate() { @Override @@ -127,26 +127,26 @@ public boolean test(String t1, String t2) { throw new TestException(); } }); - verifyError(observable); + verifyError(o); } - private void verifyResult(Observable observable, boolean result) { - Subscriber observer = TestHelper.mockSubscriber(); + private void verifyResult(Observable o, boolean result) { + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - observable.subscribe(observer); + o.subscribe(NbpObserver); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onNext(result); - inOrder.verify(observer).onComplete(); + InOrder inOrder = inOrder(NbpObserver); + inOrder.verify(NbpObserver, times(1)).onNext(result); + inOrder.verify(NbpObserver).onComplete(); inOrder.verifyNoMoreInteractions(); } - private void verifyError(Observable observable) { - Subscriber observer = TestHelper.mockSubscriber(); - observable.subscribe(observer); + private void verifyError(Observable NbpObservable) { + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + NbpObservable.subscribe(NbpObserver); - InOrder inOrder = inOrder(observer); - inOrder.verify(observer, times(1)).onError(isA(TestException.class)); + InOrder inOrder = inOrder(NbpObserver); + inOrder.verify(NbpObserver, times(1)).onError(isA(TestException.class)); inOrder.verifyNoMoreInteractions(); } } \ No newline at end of file diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSerializeTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSerializeTest.java similarity index 93% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSerializeTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSerializeTest.java index 5158644866..307bd2a225 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSerializeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -23,12 +23,14 @@ import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.flowable.TestHelper; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.DefaultObserver; public class NbpOperatorSerializeTest { - NbpSubscriber NbpObserver; + Observer NbpObserver; @Before public void before() { @@ -38,7 +40,7 @@ public void before() { @Test public void testSingleThreadedBasic() { TestSingleThreadedObservable onSubscribe = new TestSingleThreadedObservable("one", "two", "three"); - NbpObservable w = NbpObservable.create(onSubscribe); + Observable w = Observable.create(onSubscribe); w.serialize().subscribe(NbpObserver); onSubscribe.waitToFinish(); @@ -56,7 +58,7 @@ public void testSingleThreadedBasic() { @Test public void testMultiThreadedBasic() { TestMultiThreadedObservable onSubscribe = new TestMultiThreadedObservable("one", "two", "three"); - NbpObservable w = NbpObservable.create(onSubscribe); + Observable w = Observable.create(onSubscribe); BusyObserver busyobserver = new BusyObserver(); @@ -79,7 +81,7 @@ public void testMultiThreadedBasic() { @Test public void testMultiThreadedWithNPE() { TestMultiThreadedObservable onSubscribe = new TestMultiThreadedObservable("one", "two", "three", null); - NbpObservable w = NbpObservable.create(onSubscribe); + Observable w = Observable.create(onSubscribe); BusyObserver busyobserver = new BusyObserver(); @@ -110,7 +112,7 @@ public void testMultiThreadedWithNPEinMiddle() { boolean lessThan9 = false; for (int i = 0; i < 3; i++) { TestMultiThreadedObservable onSubscribe = new TestMultiThreadedObservable("one", "two", "three", null, "four", "five", "six", "seven", "eight", "nine"); - NbpObservable w = NbpObservable.create(onSubscribe); + Observable w = Observable.create(onSubscribe); BusyObserver busyobserver = new BusyObserver(); @@ -144,10 +146,10 @@ public void testMultiThreadedWithNPEinMiddle() { */ public static class OnNextThread implements Runnable { - private final NbpObserver NbpObserver; + private final DefaultObserver NbpObserver; private final int numStringsToSend; - OnNextThread(NbpObserver NbpObserver, int numStringsToSend) { + OnNextThread(DefaultObserver NbpObserver, int numStringsToSend) { this.NbpObserver = NbpObserver; this.numStringsToSend = numStringsToSend; } @@ -165,11 +167,11 @@ public void run() { */ public static class CompletionThread implements Runnable { - private final NbpObserver NbpObserver; + private final DefaultObserver NbpObserver; private final TestConcurrencyobserverEvent event; private final Future[] waitOnThese; - CompletionThread(NbpObserver NbpObserver, TestConcurrencyobserverEvent event, Future... waitOnThese) { + CompletionThread(DefaultObserver NbpObserver, TestConcurrencyobserverEvent event, Future... waitOnThese) { this.NbpObserver = NbpObserver; this.event = event; this.waitOnThese = waitOnThese; @@ -218,7 +220,7 @@ public TestSingleThreadedObservable(final String... values) { } @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); System.out.println("TestSingleThreadedObservable subscribed to ..."); t = new Thread(new Runnable() { @@ -269,7 +271,7 @@ public TestMultiThreadedObservable(String... values) { } @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); System.out.println("TestMultiThreadedObservable subscribed to ..."); final NullPointerException npe = new NullPointerException(); @@ -338,7 +340,7 @@ public void waitToFinish() { } } - private static class BusyObserver extends NbpObserver { + private static class BusyObserver extends DefaultObserver { volatile boolean onCompleted = false; volatile boolean onError = false; AtomicInteger onNextCount = new AtomicInteger(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSingleTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSingleTest.java similarity index 76% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSingleTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSingleTest.java index 2c112e4d3f..0a5506856d 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSingleTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.isA; @@ -23,16 +23,16 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; public class NbpOperatorSingleTest { @Test public void testSingle() { - NbpObservable o = NbpObservable.just(1).single(); + Observable o = Observable.just(1).single(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -43,9 +43,9 @@ public void testSingle() { @Test public void testSingleWithTooManyElements() { - NbpObservable o = NbpObservable.just(1, 2).single(); + Observable o = Observable.just(1, 2).single(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -56,9 +56,9 @@ public void testSingleWithTooManyElements() { @Test public void testSingleWithEmpty() { - NbpObservable o = NbpObservable. empty().single(); + Observable o = Observable. empty().single(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -69,7 +69,7 @@ public void testSingleWithEmpty() { @Test public void testSingleWithPredicate() { - NbpObservable o = NbpObservable.just(1, 2) + Observable o = Observable.just(1, 2) .filter( new Predicate() { @@ -80,7 +80,7 @@ public boolean test(Integer t1) { }) .single(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -91,7 +91,7 @@ public boolean test(Integer t1) { @Test public void testSingleWithPredicateAndTooManyElements() { - NbpObservable o = NbpObservable.just(1, 2, 3, 4) + Observable o = Observable.just(1, 2, 3, 4) .filter( new Predicate() { @@ -102,7 +102,7 @@ public boolean test(Integer t1) { }) .single(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -113,7 +113,7 @@ public boolean test(Integer t1) { @Test public void testSingleWithPredicateAndEmpty() { - NbpObservable o = NbpObservable.just(1) + Observable o = Observable.just(1) .filter( new Predicate() { @@ -123,7 +123,7 @@ public boolean test(Integer t1) { } }) .single(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -134,9 +134,9 @@ public boolean test(Integer t1) { @Test public void testSingleOrDefault() { - NbpObservable o = NbpObservable.just(1).single(2); + Observable o = Observable.just(1).single(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -147,9 +147,9 @@ public void testSingleOrDefault() { @Test public void testSingleOrDefaultWithTooManyElements() { - NbpObservable o = NbpObservable.just(1, 2).single(3); + Observable o = Observable.just(1, 2).single(3); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -160,10 +160,10 @@ public void testSingleOrDefaultWithTooManyElements() { @Test public void testSingleOrDefaultWithEmpty() { - NbpObservable o = NbpObservable. empty() + Observable o = Observable. empty() .single(1); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -174,7 +174,7 @@ public void testSingleOrDefaultWithEmpty() { @Test public void testSingleOrDefaultWithPredicate() { - NbpObservable o = NbpObservable.just(1, 2) + Observable o = Observable.just(1, 2) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -183,7 +183,7 @@ public boolean test(Integer t1) { }) .single(4); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -194,7 +194,7 @@ public boolean test(Integer t1) { @Test public void testSingleOrDefaultWithPredicateAndTooManyElements() { - NbpObservable o = NbpObservable.just(1, 2, 3, 4) + Observable o = Observable.just(1, 2, 3, 4) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -203,7 +203,7 @@ public boolean test(Integer t1) { }) .single(6); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -214,7 +214,7 @@ public boolean test(Integer t1) { @Test public void testSingleOrDefaultWithPredicateAndEmpty() { - NbpObservable o = NbpObservable.just(1) + Observable o = Observable.just(1) .filter(new Predicate() { @Override public boolean test(Integer t1) { @@ -223,7 +223,7 @@ public boolean test(Integer t1) { }) .single(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -235,8 +235,8 @@ public boolean test(Integer t1) { @Test(timeout = 30000) public void testIssue1527() throws InterruptedException { //https://github.com/ReactiveX/RxJava/pull/1527 - NbpObservable source = NbpObservable.just(1, 2, 3, 4, 5, 6); - NbpObservable reduced = source.reduce(new BiFunction() { + Observable source = Observable.just(1, 2, 3, 4, 5, 6); + Observable reduced = source.reduce(new BiFunction() { @Override public Integer apply(Integer i1, Integer i2) { return i1 + i2; diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipLastTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipLastTest.java similarity index 67% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipLastTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipLastTest.java index b5c4932e34..9cc5dd0723 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipLastTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -23,17 +23,17 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorSkipLastTest { @Test public void testSkipLastEmpty() { - NbpObservable o = NbpObservable. empty().skipLast(2); + Observable o = Observable. empty().skipLast(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); verify(NbpObserver, never()).onNext(any(String.class)); verify(NbpObserver, never()).onError(any(Throwable.class)); @@ -42,9 +42,9 @@ public void testSkipLastEmpty() { @Test public void testSkipLast1() { - NbpObservable o = NbpObservable.fromIterable(Arrays.asList("one", "two", "three")).skipLast(2); + Observable o = Observable.fromIterable(Arrays.asList("one", "two", "three")).skipLast(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(NbpObserver); o.subscribe(NbpObserver); inOrder.verify(NbpObserver, never()).onNext("two"); @@ -56,9 +56,9 @@ public void testSkipLast1() { @Test public void testSkipLast2() { - NbpObservable o = NbpObservable.fromIterable(Arrays.asList("one", "two")).skipLast(2); + Observable o = Observable.fromIterable(Arrays.asList("one", "two")).skipLast(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); verify(NbpObserver, never()).onNext(any(String.class)); verify(NbpObserver, never()).onError(any(Throwable.class)); @@ -67,10 +67,10 @@ public void testSkipLast2() { @Test public void testSkipLastWithZeroCount() { - NbpObservable w = NbpObservable.just("one", "two"); - NbpObservable NbpObservable = w.skipLast(0); + Observable w = Observable.just("one", "two"); + Observable NbpObservable = w.skipLast(0); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext("one"); verify(NbpObserver, times(1)).onNext("two"); @@ -81,9 +81,9 @@ public void testSkipLastWithZeroCount() { @Test @Ignore("Null values not allowed") public void testSkipLastWithNull() { - NbpObservable o = NbpObservable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1); + Observable o = Observable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); o.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext("one"); verify(NbpObserver, times(1)).onNext(null); @@ -94,18 +94,18 @@ public void testSkipLastWithNull() { @Test public void testSkipLastWithBackpressure() { - NbpObservable o = NbpObservable.range(0, Observable.bufferSize() * 2).skipLast(Observable.bufferSize() + 10); - NbpTestSubscriber ts = new NbpTestSubscriber(); + Observable o = Observable.range(0, Flowable.bufferSize() * 2).skipLast(Flowable.bufferSize() + 10); + TestObserver ts = new TestObserver(); o.observeOn(Schedulers.computation()).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals((Observable.bufferSize()) - 10, ts.valueCount()); + assertEquals((Flowable.bufferSize()) - 10, ts.valueCount()); } @Test(expected = IndexOutOfBoundsException.class) public void testSkipLastWithNegativeCount() { - NbpObservable.just("one").skipLast(-1); + Observable.just("one").skipLast(-1); } } \ No newline at end of file diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipLastTimedTest.java similarity index 77% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipLastTimedTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipLastTimedTest.java index 5670bda448..05868d78ef 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipLastTimedTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,10 +22,10 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorSkipLastTimedTest { @@ -33,12 +33,12 @@ public class NbpOperatorSkipLastTimedTest { public void testSkipLastTimed() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); // FIXME the timeunit now matters due to rounding - NbpObservable result = source.skipLast(1000, TimeUnit.MILLISECONDS, scheduler); + Observable result = source.skipLast(1000, TimeUnit.MILLISECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -72,11 +72,11 @@ public void testSkipLastTimed() { public void testSkipLastTimedErrorBeforeTime() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -97,11 +97,11 @@ public void testSkipLastTimedErrorBeforeTime() { public void testSkipLastTimedCompleteBeforeTime() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skipLast(1, TimeUnit.SECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -125,11 +125,11 @@ public void testSkipLastTimedCompleteBeforeTime() { public void testSkipLastTimedWhenAllElementsAreValid() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable result = source.skipLast(1, TimeUnit.MILLISECONDS, scheduler); + Observable result = source.skipLast(1, TimeUnit.MILLISECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipTest.java similarity index 69% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipTest.java index 78b2430cff..c049ca0ed3 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -22,17 +22,17 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.flowable.TestHelper; +import io.reactivex.observers.TestObserver; public class NbpOperatorSkipTest { @Test public void testSkipNegativeElements() { - NbpObservable skip = NbpObservable.just("one", "two", "three").skip(-99); + Observable skip = Observable.just("one", "two", "three").skip(-99); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); skip.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext("one"); verify(NbpObserver, times(1)).onNext("two"); @@ -44,9 +44,9 @@ public void testSkipNegativeElements() { @Test public void testSkipZeroElements() { - NbpObservable skip = NbpObservable.just("one", "two", "three").skip(0); + Observable skip = Observable.just("one", "two", "three").skip(0); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); skip.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext("one"); verify(NbpObserver, times(1)).onNext("two"); @@ -58,9 +58,9 @@ public void testSkipZeroElements() { @Test public void testSkipOneElement() { - NbpObservable skip = NbpObservable.just("one", "two", "three").skip(1); + Observable skip = Observable.just("one", "two", "three").skip(1); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); skip.subscribe(NbpObserver); verify(NbpObserver, never()).onNext("one"); verify(NbpObserver, times(1)).onNext("two"); @@ -72,9 +72,9 @@ public void testSkipOneElement() { @Test public void testSkipTwoElements() { - NbpObservable skip = NbpObservable.just("one", "two", "three").skip(2); + Observable skip = Observable.just("one", "two", "three").skip(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); skip.subscribe(NbpObserver); verify(NbpObserver, never()).onNext("one"); verify(NbpObserver, never()).onNext("two"); @@ -86,10 +86,10 @@ public void testSkipTwoElements() { @Test public void testSkipEmptyStream() { - NbpObservable w = NbpObservable.empty(); - NbpObservable skip = w.skip(1); + Observable w = Observable.empty(); + Observable skip = w.skip(1); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); skip.subscribe(NbpObserver); verify(NbpObserver, never()).onNext(any(String.class)); verify(NbpObserver, never()).onError(any(Throwable.class)); @@ -99,13 +99,13 @@ public void testSkipEmptyStream() { @Test public void testSkipMultipleObservers() { - NbpObservable skip = NbpObservable.just("one", "two", "three") + Observable skip = Observable.just("one", "two", "three") .skip(2); - NbpSubscriber observer1 = TestHelper.mockNbpSubscriber(); + Observer observer1 = TestHelper.mockNbpSubscriber(); skip.subscribe(observer1); - NbpSubscriber observer2 = TestHelper.mockNbpSubscriber(); + Observer observer2 = TestHelper.mockNbpSubscriber(); skip.subscribe(observer2); verify(observer1, times(1)).onNext(any(String.class)); @@ -122,12 +122,12 @@ public void testSkipError() { Exception e = new Exception(); - NbpObservable ok = NbpObservable.just("one"); - NbpObservable error = NbpObservable.error(e); + Observable ok = Observable.just("one"); + Observable error = Observable.error(e); - NbpObservable skip = NbpObservable.concat(ok, error).skip(100); + Observable skip = Observable.concat(ok, error).skip(100); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); skip.subscribe(NbpObserver); verify(NbpObserver, never()).onNext(any(String.class)); @@ -138,8 +138,8 @@ public void testSkipError() { @Test public void testRequestOverflowDoesNotOccur() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(1, 10).skip(5).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.range(1, 10).skip(5).subscribe(ts); ts.assertTerminated(); ts.assertComplete(); ts.assertNoErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipTimedTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipTimedTest.java similarity index 78% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipTimedTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipTimedTest.java index aa203a5f63..a5ad446722 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipTimedTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,10 +22,10 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorSkipTimedTest { @@ -33,11 +33,11 @@ public class NbpOperatorSkipTimedTest { public void testSkipTimed() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable result = source.skip(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skip(1, TimeUnit.SECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -70,11 +70,11 @@ public void testSkipTimed() { public void testSkipTimedFinishBeforeTime() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable result = source.skip(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skip(1, TimeUnit.SECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -97,11 +97,11 @@ public void testSkipTimedFinishBeforeTime() { public void testSkipTimedErrorBeforeTime() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable result = source.skip(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skip(1, TimeUnit.SECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -124,11 +124,11 @@ public void testSkipTimedErrorBeforeTime() { public void testSkipTimedErrorAfterTime() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable result = source.skip(1, TimeUnit.SECONDS, scheduler); + Observable result = source.skip(1, TimeUnit.SECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipUntilTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipUntilTest.java similarity index 72% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipUntilTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipUntilTest.java index 92a776acac..472b3467cc 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipUntilTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -19,11 +19,11 @@ import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.flowable.TestHelper; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorSkipUntilTest { - NbpSubscriber NbpObserver; + Observer NbpObserver; @Before public void before() { @@ -32,10 +32,10 @@ public void before() { @Test public void normal1() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpObservable m = source.skipUntil(other); + Observable m = source.skipUntil(other); m.subscribe(NbpObserver); source.onNext(0); @@ -57,9 +57,9 @@ public void normal1() { @Test public void otherNeverFires() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable m = source.skipUntil(NbpObservable.never()); + Observable m = source.skipUntil(Observable.never()); m.subscribe(NbpObserver); @@ -77,9 +77,9 @@ public void otherNeverFires() { @Test public void otherEmpty() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable m = source.skipUntil(NbpObservable.empty()); + Observable m = source.skipUntil(Observable.empty()); m.subscribe(NbpObserver); @@ -90,10 +90,10 @@ public void otherEmpty() { @Test public void otherFiresAndCompletes() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpObservable m = source.skipUntil(other); + Observable m = source.skipUntil(other); m.subscribe(NbpObserver); source.onNext(0); @@ -116,10 +116,10 @@ public void otherFiresAndCompletes() { @Test public void sourceThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpObservable m = source.skipUntil(other); + Observable m = source.skipUntil(other); m.subscribe(NbpObserver); source.onNext(0); @@ -138,10 +138,10 @@ public void sourceThrows() { @Test public void otherThrowsImmediately() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpObservable m = source.skipUntil(other); + Observable m = source.skipUntil(other); m.subscribe(NbpObserver); source.onNext(0); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipWhileTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipWhileTest.java similarity index 83% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipWhileTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipWhileTest.java index 986b015b92..afa3ab2df4 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSkipWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSkipWhileTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -20,12 +20,12 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Predicate; public class NbpOperatorSkipWhileTest { - NbpSubscriber w = TestHelper.mockNbpSubscriber(); + Observer w = TestHelper.mockNbpSubscriber(); private static final Predicate LESS_THAN_FIVE = new Predicate() { @Override @@ -46,7 +46,7 @@ public boolean test(Integer value) { @Test public void testSkipWithIndex() { - NbpObservable src = NbpObservable.just(1, 2, 3, 4, 5); + Observable src = Observable.just(1, 2, 3, 4, 5); src.skipWhile(INDEX_LESS_THAN_THREE).subscribe(w); InOrder inOrder = inOrder(w); @@ -58,7 +58,7 @@ public void testSkipWithIndex() { @Test public void testSkipEmpty() { - NbpObservable src = NbpObservable.empty(); + Observable src = Observable.empty(); src.skipWhile(LESS_THAN_FIVE).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onError(any(Throwable.class)); @@ -67,7 +67,7 @@ public void testSkipEmpty() { @Test public void testSkipEverything() { - NbpObservable src = NbpObservable.just(1, 2, 3, 4, 3, 2, 1); + Observable src = Observable.just(1, 2, 3, 4, 3, 2, 1); src.skipWhile(LESS_THAN_FIVE).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onError(any(Throwable.class)); @@ -76,7 +76,7 @@ public void testSkipEverything() { @Test public void testSkipNothing() { - NbpObservable src = NbpObservable.just(5, 3, 1); + Observable src = Observable.just(5, 3, 1); src.skipWhile(LESS_THAN_FIVE).subscribe(w); InOrder inOrder = inOrder(w); @@ -89,7 +89,7 @@ public void testSkipNothing() { @Test public void testSkipSome() { - NbpObservable src = NbpObservable.just(1, 2, 3, 4, 5, 3, 1, 5); + Observable src = Observable.just(1, 2, 3, 4, 5, 3, 1, 5); src.skipWhile(LESS_THAN_FIVE).subscribe(w); InOrder inOrder = inOrder(w); @@ -103,7 +103,7 @@ public void testSkipSome() { @Test public void testSkipError() { - NbpObservable src = NbpObservable.just(1, 2, 42, 5, 3, 1); + Observable src = Observable.just(1, 2, 42, 5, 3, 1); src.skipWhile(LESS_THAN_FIVE).subscribe(w); InOrder inOrder = inOrder(w); @@ -114,10 +114,10 @@ public void testSkipError() { @Test public void testSkipManySubscribers() { - NbpObservable src = NbpObservable.range(1, 10).skipWhile(LESS_THAN_FIVE); + Observable src = Observable.range(1, 10).skipWhile(LESS_THAN_FIVE); int n = 5; for (int i = 0; i < n; i++) { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); src.subscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSubscribeOnTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSubscribeOnTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSubscribeOnTest.java index ea04f1adb2..1ee65c2dcf 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSubscribeOnTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; @@ -21,11 +21,11 @@ import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.*; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorSubscribeOnTest { @@ -36,13 +36,13 @@ public void testIssue813() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch doneLatch = new CountDownLatch(1); - NbpTestSubscriber NbpObserver = new NbpTestSubscriber(); + TestObserver NbpObserver = new TestObserver(); - NbpObservable + Observable .create(new NbpOnSubscribe() { @Override public void accept( - final NbpSubscriber NbpSubscriber) { + final Observer NbpSubscriber) { NbpSubscriber.onSubscribe(EmptyDisposable.INSTANCE); scheduled.countDown(); try { @@ -75,11 +75,11 @@ public void accept( @Test @Ignore("NbpOnSubscribe.subscribe can't throw") public void testThrownErrorHandling() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.create(new NbpOnSubscribe() { + TestObserver ts = new TestObserver(); + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { throw new RuntimeException("fail"); } @@ -90,11 +90,11 @@ public void accept(NbpSubscriber s) { @Test public void testOnError() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.create(new NbpOnSubscribe() { + TestObserver ts = new TestObserver(); + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { s.onSubscribe(EmptyDisposable.INSTANCE); s.onError(new RuntimeException("fail")); } @@ -161,12 +161,12 @@ public Disposable schedule(final Runnable action, final long delayTime, final Ti @Test(timeout = 5000) public void testUnsubscribeInfiniteStream() throws InterruptedException { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final AtomicInteger count = new AtomicInteger(); - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber sub) { + public void accept(Observer sub) { BooleanDisposable bs = new BooleanDisposable(); sub.onSubscribe(bs); for (int i = 1; !bs.isDisposed(); i++) { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSwitchIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSwitchIfEmptyTest.java similarity index 73% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSwitchIfEmptyTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSwitchIfEmptyTest.java index e33c39d8df..9c10a2bba1 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSwitchIfEmptyTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; @@ -21,9 +21,10 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.*; import io.reactivex.functions.Consumer; +import io.reactivex.observers.DefaultObserver; public class NbpOperatorSwitchIfEmptyTest { @@ -31,8 +32,8 @@ public class NbpOperatorSwitchIfEmptyTest { @Test public void testSwitchWhenNotEmpty() throws Exception { final AtomicBoolean subscribed = new AtomicBoolean(false); - final NbpObservable o = NbpObservable.just(4) - .switchIfEmpty(NbpObservable.just(2) + final Observable o = Observable.just(4) + .switchIfEmpty(Observable.just(2) .doOnSubscribe(new Consumer() { @Override public void accept(Disposable s) { @@ -46,8 +47,8 @@ public void accept(Disposable s) { @Test public void testSwitchWhenEmpty() throws Exception { - final NbpObservable o = NbpObservable.empty() - .switchIfEmpty(NbpObservable.fromIterable(Arrays.asList(42))); + final Observable o = Observable.empty() + .switchIfEmpty(Observable.fromIterable(Arrays.asList(42))); assertEquals(42, o.toBlocking().single().intValue()); } @@ -57,20 +58,20 @@ public void testSwitchTriggerUnsubscribe() throws Exception { final BooleanDisposable bs = new BooleanDisposable(); - NbpObservable withProducer = NbpObservable.create(new NbpOnSubscribe() { + Observable withProducer = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber NbpSubscriber) { + public void accept(final Observer NbpSubscriber) { NbpSubscriber.onSubscribe(bs); NbpSubscriber.onNext(42L); } }); - NbpObservable.empty() + Observable.empty() .switchIfEmpty(withProducer) - .lift(new NbpObservable.NbpOperator() { + .lift(new Observable.NbpOperator() { @Override - public NbpSubscriber apply(final NbpSubscriber child) { - return new NbpObserver() { + public Observer apply(final Observer child) { + return new DefaultObserver() { @Override public void onComplete() { @@ -100,13 +101,13 @@ public void onNext(Long aLong) { public void testSwitchShouldTriggerUnsubscribe() { final BooleanDisposable bs = new BooleanDisposable(); - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber NbpSubscriber) { + public void accept(final Observer NbpSubscriber) { NbpSubscriber.onSubscribe(bs); NbpSubscriber.onComplete(); } - }).switchIfEmpty(NbpObservable.never()).subscribe(); + }).switchIfEmpty(Observable.never()).subscribe(); assertTrue(bs.isDisposed()); } } \ No newline at end of file diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSwitchTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSwitchTest.java similarity index 71% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSwitchTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSwitchTest.java index e51c516ee2..a06d232b22 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorSwitchTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.*; @@ -24,19 +24,20 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.BooleanDisposable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorSwitchTest { private TestScheduler scheduler; private Scheduler.Worker innerScheduler; - private NbpSubscriber NbpObserver; + private Observer NbpObserver; @Before public void before() { @@ -47,13 +48,13 @@ public void before() { @Test public void testSwitchWhenOuterCompleteBeforeInner() { - NbpObservable> source = NbpObservable.create(new NbpOnSubscribe>() { + Observable> source = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(NbpSubscriber> NbpObserver) { + public void accept(Observer> NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); - publishNext(NbpObserver, 50, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 50, Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 70, "one"); publishNext(NbpObserver, 100, "two"); @@ -64,7 +65,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable sampled = NbpObservable.switchOnNext(source); + Observable sampled = Observable.switchOnNext(source); sampled.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -76,13 +77,13 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testSwitchWhenInnerCompleteBeforeOuter() { - NbpObservable> source = NbpObservable.create(new NbpOnSubscribe>() { + Observable> source = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(NbpSubscriber> NbpObserver) { + public void accept(Observer> NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); - publishNext(NbpObserver, 10, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 10, Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 0, "one"); publishNext(NbpObserver, 10, "two"); @@ -90,9 +91,9 @@ public void accept(NbpSubscriber NbpObserver) { } })); - publishNext(NbpObserver, 100, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 100, Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 0, "three"); publishNext(NbpObserver, 10, "four"); @@ -103,7 +104,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable sampled = NbpObservable.switchOnNext(source); + Observable sampled = Observable.switchOnNext(source); sampled.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -122,22 +123,22 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testSwitchWithComplete() { - NbpObservable> source = NbpObservable.create(new NbpOnSubscribe>() { + Observable> source = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(NbpSubscriber> NbpObserver) { + public void accept(Observer> NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); - publishNext(NbpObserver, 50, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 50, Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 60, "one"); publishNext(NbpObserver, 100, "two"); } })); - publishNext(NbpObserver, 200, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 200, Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 0, "three"); publishNext(NbpObserver, 100, "four"); @@ -148,7 +149,7 @@ public void accept(final NbpSubscriber NbpObserver) { } }); - NbpObservable sampled = NbpObservable.switchOnNext(source); + Observable sampled = Observable.switchOnNext(source); sampled.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -181,22 +182,22 @@ public void accept(final NbpSubscriber NbpObserver) { @Test public void testSwitchWithError() { - NbpObservable> source = NbpObservable.create(new NbpOnSubscribe>() { + Observable> source = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(NbpSubscriber> NbpObserver) { + public void accept(Observer> NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); - publishNext(NbpObserver, 50, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 50, Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 50, "one"); publishNext(NbpObserver, 100, "two"); } })); - publishNext(NbpObserver, 200, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 200, Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 0, "three"); publishNext(NbpObserver, 100, "four"); @@ -207,7 +208,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable sampled = NbpObservable.switchOnNext(source); + Observable sampled = Observable.switchOnNext(source); sampled.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -240,30 +241,30 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testSwitchWithSubsequenceComplete() { - NbpObservable> source = NbpObservable.create(new NbpOnSubscribe>() { + Observable> source = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(NbpSubscriber> NbpObserver) { + public void accept(Observer> NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); - publishNext(NbpObserver, 50, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 50, Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 50, "one"); publishNext(NbpObserver, 100, "two"); } })); - publishNext(NbpObserver, 130, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 130, Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishCompleted(NbpObserver, 0); } })); - publishNext(NbpObserver, 150, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 150, Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 50, "three"); } @@ -271,7 +272,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable sampled = NbpObservable.switchOnNext(source); + Observable sampled = Observable.switchOnNext(source); sampled.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -294,30 +295,30 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testSwitchWithSubsequenceError() { - NbpObservable> source = NbpObservable.create(new NbpOnSubscribe>() { + Observable> source = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(NbpSubscriber> NbpObserver) { + public void accept(Observer> NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); - publishNext(NbpObserver, 50, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 50, Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 50, "one"); publishNext(NbpObserver, 100, "two"); } })); - publishNext(NbpObserver, 130, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 130, Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishError(NbpObserver, 0, new TestException()); } })); - publishNext(NbpObserver, 150, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 150, Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 50, "three"); } @@ -326,7 +327,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable sampled = NbpObservable.switchOnNext(source); + Observable sampled = Observable.switchOnNext(source); sampled.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -347,7 +348,7 @@ public void accept(NbpSubscriber NbpObserver) { verify(NbpObserver, times(1)).onError(any(TestException.class)); } - private void publishCompleted(final NbpSubscriber NbpObserver, long delay) { + private void publishCompleted(final Observer NbpObserver, long delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -356,7 +357,7 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private void publishError(final NbpSubscriber NbpObserver, long delay, final Throwable error) { + private void publishError(final Observer NbpObserver, long delay, final Throwable error) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -365,7 +366,7 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private void publishNext(final NbpSubscriber NbpObserver, long delay, final T value) { + private void publishNext(final Observer NbpObserver, long delay, final T value) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -377,13 +378,13 @@ public void run() { @Test public void testSwitchIssue737() { // https://github.com/ReactiveX/RxJava/issues/737 - NbpObservable> source = NbpObservable.create(new NbpOnSubscribe>() { + Observable> source = Observable.create(new NbpOnSubscribe>() { @Override - public void accept(NbpSubscriber> NbpObserver) { + public void accept(Observer> NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); - publishNext(NbpObserver, 0, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 0, Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 10, "1-one"); publishNext(NbpObserver, 20, "1-two"); @@ -392,9 +393,9 @@ public void accept(NbpSubscriber NbpObserver) { publishCompleted(NbpObserver, 40); } })); - publishNext(NbpObserver, 25, NbpObservable.create(new NbpOnSubscribe() { + publishNext(NbpObserver, 25, Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 10, "2-one"); publishNext(NbpObserver, 20, "2-two"); @@ -406,7 +407,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable sampled = NbpObservable.switchOnNext(source); + Observable sampled = Observable.switchOnNext(source); sampled.subscribe(NbpObserver); scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS); @@ -424,13 +425,13 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testUnsubscribe() { final AtomicBoolean isUnsubscribed = new AtomicBoolean(); - NbpObservable.switchOnNext( - NbpObservable.create(new NbpOnSubscribe>() { + Observable.switchOnNext( + Observable.create(new NbpOnSubscribe>() { @Override - public void accept(final NbpSubscriber> NbpSubscriber) { + public void accept(final Observer> NbpSubscriber) { BooleanDisposable bs = new BooleanDisposable(); NbpSubscriber.onSubscribe(bs); - NbpSubscriber.onNext(NbpObservable.just(1)); + NbpSubscriber.onNext(Observable.just(1)); isUnsubscribed.set(bs.isDisposed()); } }) @@ -440,13 +441,13 @@ public void accept(final NbpSubscriber> NbpSubscr /** The upstream producer hijacked the switch producer stopping the requests aimed at the inner observables. */ @Test public void testIssue2654() { - NbpObservable oneItem = NbpObservable.just("Hello").mergeWith(NbpObservable.never()); + Observable oneItem = Observable.just("Hello").mergeWith(Observable.never()); - NbpObservable src = oneItem.switchMap(new Function>() { + Observable src = oneItem.switchMap(new Function>() { @Override - public NbpObservable apply(final String s) { - return NbpObservable.just(s) - .mergeWith(NbpObservable.interval(10, TimeUnit.MILLISECONDS) + public Observable apply(final String s) { + return Observable.just(s) + .mergeWith(Observable.interval(10, TimeUnit.MILLISECONDS) .map(new Function() { @Override public String apply(Long i) { @@ -458,7 +459,7 @@ public String apply(Long i) { .share() ; - NbpTestSubscriber ts = new NbpTestSubscriber() { + TestObserver ts = new TestObserver() { @Override public void onNext(String t) { super.onNext(t); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastOneTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastOneTest.java similarity index 77% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastOneTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastOneTest.java index f533cfc741..a25b1856d4 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastOneTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastOneTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; @@ -19,16 +19,16 @@ import org.junit.Test; -import io.reactivex.NbpObservable; +import io.reactivex.Observable; import io.reactivex.functions.Consumer; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.TestObserver; public class NbpOperatorTakeLastOneTest { @Test public void testLastOfManyReturnsLast() { - NbpTestSubscriber s = new NbpTestSubscriber(); - NbpObservable.range(1, 10).takeLast(1).subscribe(s); + TestObserver s = new TestObserver(); + Observable.range(1, 10).takeLast(1).subscribe(s); s.assertValue(10); s.assertNoErrors(); s.assertTerminated(); @@ -38,8 +38,8 @@ public void testLastOfManyReturnsLast() { @Test public void testLastOfEmptyReturnsEmpty() { - NbpTestSubscriber s = new NbpTestSubscriber(); - NbpObservable.empty().takeLast(1).subscribe(s); + TestObserver s = new TestObserver(); + Observable.empty().takeLast(1).subscribe(s); s.assertNoValues(); s.assertNoErrors(); s.assertTerminated(); @@ -49,8 +49,8 @@ public void testLastOfEmptyReturnsEmpty() { @Test public void testLastOfOneReturnsLast() { - NbpTestSubscriber s = new NbpTestSubscriber(); - NbpObservable.just(1).takeLast(1).subscribe(s); + TestObserver s = new TestObserver(); + Observable.just(1).takeLast(1).subscribe(s); s.assertValue(1); s.assertNoErrors(); s.assertTerminated(); @@ -67,7 +67,7 @@ public void run() { unsubscribed.set(true); } }; - NbpObservable.just(1).doOnCancel(unsubscribeAction) + Observable.just(1).doOnCancel(unsubscribeAction) .takeLast(1).subscribe(); assertTrue(unsubscribed.get()); } @@ -76,7 +76,7 @@ public void run() { public void testTakeLastZeroProcessesAllItemsButIgnoresThem() { final AtomicInteger upstreamCount = new AtomicInteger(); final int num = 10; - long count = NbpObservable.range(1,num).doOnNext(new Consumer() { + long count = Observable.range(1,num).doOnNext(new Consumer() { @Override public void accept(Integer t) { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastTest.java similarity index 73% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastTest.java index caacf7b866..85816c949e 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -23,19 +23,19 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; +import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorTakeLastTest { @Test public void testTakeLastEmpty() { - NbpObservable w = NbpObservable.empty(); - NbpObservable take = w.takeLast(2); + Observable w = Observable.empty(); + Observable take = w.takeLast(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); take.subscribe(NbpObserver); verify(NbpObserver, never()).onNext(any(String.class)); verify(NbpObserver, never()).onError(any(Throwable.class)); @@ -44,10 +44,10 @@ public void testTakeLastEmpty() { @Test public void testTakeLast1() { - NbpObservable w = NbpObservable.just("one", "two", "three"); - NbpObservable take = w.takeLast(2); + Observable w = Observable.just("one", "two", "three"); + Observable take = w.takeLast(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(NbpObserver); take.subscribe(NbpObserver); inOrder.verify(NbpObserver, times(1)).onNext("two"); @@ -59,10 +59,10 @@ public void testTakeLast1() { @Test public void testTakeLast2() { - NbpObservable w = NbpObservable.just("one"); - NbpObservable take = w.takeLast(10); + Observable w = Observable.just("one"); + Observable take = w.takeLast(10); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); take.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext("one"); verify(NbpObserver, never()).onError(any(Throwable.class)); @@ -71,10 +71,10 @@ public void testTakeLast2() { @Test public void testTakeLastWithZeroCount() { - NbpObservable w = NbpObservable.just("one"); - NbpObservable take = w.takeLast(0); + Observable w = Observable.just("one"); + Observable take = w.takeLast(0); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); take.subscribe(NbpObserver); verify(NbpObserver, never()).onNext("one"); verify(NbpObserver, never()).onError(any(Throwable.class)); @@ -84,10 +84,10 @@ public void testTakeLastWithZeroCount() { @Test @Ignore("Null values no longer allowed") public void testTakeLastWithNull() { - NbpObservable w = NbpObservable.just("one", null, "three"); - NbpObservable take = w.takeLast(2); + Observable w = Observable.just("one", null, "three"); + Observable take = w.takeLast(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); take.subscribe(NbpObserver); verify(NbpObserver, never()).onNext("one"); verify(NbpObserver, times(1)).onNext(null); @@ -98,13 +98,13 @@ public void testTakeLastWithNull() { @Test(expected = IndexOutOfBoundsException.class) public void testTakeLastWithNegativeCount() { - NbpObservable.just("one").takeLast(-1); + Observable.just("one").takeLast(-1); } @Test public void testBackpressure1() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(1, 100000).takeLast(1) + TestObserver ts = new TestObserver(); + Observable.range(1, 100000).takeLast(1) .observeOn(Schedulers.newThread()) .map(newSlowProcessor()).subscribe(ts); ts.awaitTerminalEvent(); @@ -114,12 +114,12 @@ public void testBackpressure1() { @Test public void testBackpressure2() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.range(1, 100000).takeLast(Observable.bufferSize() * 4) + TestObserver ts = new TestObserver(); + Observable.range(1, 100000).takeLast(Flowable.bufferSize() * 4) .observeOn(Schedulers.newThread()).map(newSlowProcessor()).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 4, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 4, ts.valueCount()); } private Function newSlowProcessor() { @@ -143,7 +143,7 @@ public Integer apply(Integer i) { @Test public void testIssue1522() { // https://github.com/ReactiveX/RxJava/issues/1522 - assertEquals(0, NbpObservable + assertEquals(0, Observable .empty() .count() .filter(new Predicate() { @@ -159,7 +159,7 @@ public boolean test(Long v) { @Test public void testUnsubscribeTakesEffectEarlyOnFastPath() { final AtomicInteger count = new AtomicInteger(); - NbpObservable.range(0, 100000).takeLast(100000).subscribe(new NbpObserver() { + Observable.range(0, 100000).takeLast(100000).subscribe(new DefaultObserver() { @Override public void onStart() { diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastTimedTest.java similarity index 81% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastTimedTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastTimedTest.java index e3e3b6d810..1c22c44c02 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeLastTimedTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,28 +22,28 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorTakeLastTimedTest { @Test(expected = IndexOutOfBoundsException.class) public void testTakeLastTimedWithNegativeCount() { - NbpObservable.just("one").takeLast(-1, 1, TimeUnit.SECONDS); + Observable.just("one").takeLast(-1, 1, TimeUnit.SECONDS); } @Test public void takeLastTimed() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); // FIXME time unit now matters! - NbpObservable result = source.takeLast(1000, TimeUnit.MILLISECONDS, scheduler); + Observable result = source.takeLast(1000, TimeUnit.MILLISECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); @@ -74,12 +74,12 @@ public void takeLastTimed() { public void takeLastTimedDelayCompletion() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); // FIXME time unit now matters - NbpObservable result = source.takeLast(1000, TimeUnit.MILLISECONDS, scheduler); + Observable result = source.takeLast(1000, TimeUnit.MILLISECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); @@ -107,12 +107,12 @@ public void takeLastTimedDelayCompletion() { public void takeLastTimedWithCapacity() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); // FIXME time unit now matters! - NbpObservable result = source.takeLast(2, 1000, TimeUnit.MILLISECONDS, scheduler); + Observable result = source.takeLast(2, 1000, TimeUnit.MILLISECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); @@ -141,11 +141,11 @@ public void takeLastTimedWithCapacity() { public void takeLastTimedThrowingSource() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable result = source.takeLast(1, TimeUnit.SECONDS, scheduler); + Observable result = source.takeLast(1, TimeUnit.SECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); @@ -173,11 +173,11 @@ public void takeLastTimedThrowingSource() { public void takeLastTimedWithZeroCapacity() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable result = source.takeLast(0, 1, TimeUnit.SECONDS, scheduler); + Observable result = source.takeLast(0, 1, TimeUnit.SECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeTest.java similarity index 79% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeTest.java index 48e4bffd69..59b83ba603 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,23 +25,24 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorTakeTest { @Test public void testTake1() { - NbpObservable w = NbpObservable.fromIterable(Arrays.asList("one", "two", "three")); - NbpObservable take = w.take(2); + Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); + Observable take = w.take(2); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); take.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext("one"); verify(NbpObserver, times(1)).onNext("two"); @@ -52,10 +53,10 @@ public void testTake1() { @Test public void testTake2() { - NbpObservable w = NbpObservable.fromIterable(Arrays.asList("one", "two", "three")); - NbpObservable take = w.take(1); + Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); + Observable take = w.take(1); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); take.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext("one"); verify(NbpObserver, never()).onNext("two"); @@ -66,7 +67,7 @@ public void testTake2() { @Test(expected = IllegalArgumentException.class) public void testTakeWithError() { - NbpObservable.fromIterable(Arrays.asList(1, 2, 3)).take(1) + Observable.fromIterable(Arrays.asList(1, 2, 3)).take(1) .map(new Function() { @Override public Integer apply(Integer t1) { @@ -77,7 +78,7 @@ public Integer apply(Integer t1) { @Test public void testTakeWithErrorHappeningInOnNext() { - NbpObservable w = NbpObservable.fromIterable(Arrays.asList(1, 2, 3)) + Observable w = Observable.fromIterable(Arrays.asList(1, 2, 3)) .take(2).map(new Function() { @Override public Integer apply(Integer t1) { @@ -85,7 +86,7 @@ public Integer apply(Integer t1) { } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); w.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); inOrder.verify(NbpObserver, times(1)).onError(any(IllegalArgumentException.class)); @@ -94,14 +95,14 @@ public Integer apply(Integer t1) { @Test public void testTakeWithErrorHappeningInTheLastOnNext() { - NbpObservable w = NbpObservable.fromIterable(Arrays.asList(1, 2, 3)).take(1).map(new Function() { + Observable w = Observable.fromIterable(Arrays.asList(1, 2, 3)).take(1).map(new Function() { @Override public Integer apply(Integer t1) { throw new IllegalArgumentException("some error"); } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); w.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); inOrder.verify(NbpObserver, times(1)).onError(any(IllegalArgumentException.class)); @@ -110,16 +111,16 @@ public Integer apply(Integer t1) { @Test public void testTakeDoesntLeakErrors() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); NbpObserver.onNext("one"); NbpObserver.onError(new Throwable("test failed")); } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); source.take(1).subscribe(NbpObserver); @@ -136,16 +137,16 @@ public void accept(NbpSubscriber NbpObserver) { public void testTakeZeroDoesntLeakError() { final AtomicBoolean subscribed = new AtomicBoolean(false); final BooleanDisposable bs = new BooleanDisposable(); - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { subscribed.set(true); NbpObserver.onSubscribe(bs); NbpObserver.onError(new Throwable("test failed")); } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); source.take(0).subscribe(NbpObserver); assertTrue("source subscribed", subscribed.get()); @@ -161,11 +162,11 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testUnsubscribeAfterTake() { TestObservableFunc f = new TestObservableFunc("one", "two", "three"); - NbpObservable w = NbpObservable.create(f); + Observable w = Observable.create(f); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable take = w.take(1); + Observable take = w.take(1); take.subscribe(NbpObserver); // wait for the NbpObservable to complete @@ -204,10 +205,10 @@ public void accept(Long l) { @Test(timeout = 2000) public void testMultiTake() { final AtomicInteger count = new AtomicInteger(); - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { BooleanDisposable bs = new BooleanDisposable(); s.onSubscribe(bs); for (int i = 0; !bs.isDisposed(); i++) { @@ -240,7 +241,7 @@ public TestObservableFunc(String... values) { } @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); System.out.println("TestObservable subscribed to ..."); t = new Thread(new Runnable() { @@ -266,10 +267,10 @@ public void run() { } } - private static NbpObservable INFINITE_OBSERVABLE = NbpObservable.create(new NbpOnSubscribe() { + private static Observable INFINITE_OBSERVABLE = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber op) { + public void accept(Observer op) { BooleanDisposable bs = new BooleanDisposable(); op.onSubscribe(bs); long l = 1; @@ -283,8 +284,8 @@ public void accept(NbpSubscriber op) { @Test(timeout = 2000) public void testTakeObserveOn() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(o); + Observer o = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(o); INFINITE_OBSERVABLE .observeOn(Schedulers.newThread()).take(1).subscribe(ts); @@ -301,7 +302,7 @@ public void testTakeObserveOn() { public void testInterrupt() throws InterruptedException { final AtomicReference exception = new AtomicReference(); final CountDownLatch latch = new CountDownLatch(1); - NbpObservable.just(1).subscribeOn(Schedulers.computation()).take(1) + Observable.just(1).subscribeOn(Schedulers.computation()).take(1) .subscribe(new Consumer() { @Override @@ -324,9 +325,9 @@ public void accept(Integer t1) { @Test public void takeFinalValueThrows() { - NbpObservable source = NbpObservable.just(1).take(1); + Observable source = Observable.just(1).take(1); - NbpTestSubscriber ts = new NbpTestSubscriber() { + TestObserver ts = new TestObserver() { @Override public void onNext(Integer t) { throw new TestException(); @@ -342,9 +343,9 @@ public void onNext(Integer t) { @Test public void testReentrantTake() { - final NbpPublishSubject source = NbpPublishSubject.create(); + final PublishSubject source = PublishSubject.create(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); source.take(1).doOnNext(new Consumer() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeTimedTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeTimedTest.java similarity index 78% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeTimedTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeTimedTest.java index 39b0a91a89..ca53fe303e 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeTimedTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,10 +22,10 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorTakeTimedTest { @@ -33,11 +33,11 @@ public class NbpOperatorTakeTimedTest { public void testTakeTimed() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable result = source.take(1, TimeUnit.SECONDS, scheduler); + Observable result = source.take(1, TimeUnit.SECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -64,11 +64,11 @@ public void testTakeTimed() { public void testTakeTimedErrorBeforeTime() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable result = source.take(1, TimeUnit.SECONDS, scheduler); + Observable result = source.take(1, TimeUnit.SECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); @@ -96,11 +96,11 @@ public void testTakeTimedErrorBeforeTime() { public void testTakeTimedErrorAfterTime() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpObservable result = source.take(1, TimeUnit.SECONDS, scheduler); + Observable result = source.take(1, TimeUnit.SECONDS, scheduler); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); result.subscribe(o); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeUntilPredicateTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeUntilPredicateTest.java similarity index 76% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeUntilPredicateTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeUntilPredicateTest.java index 0b2b83aedb..ee6de494e3 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeUntilPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeUntilPredicateTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -19,18 +19,18 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Predicate; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.TestObserver; ; public class NbpOperatorTakeUntilPredicateTest { @Test public void takeEmpty() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpObservable.empty().takeUntil(new Predicate() { + Observable.empty().takeUntil(new Predicate() { @Override public boolean test(Object v) { return true; @@ -43,9 +43,9 @@ public boolean test(Object v) { } @Test public void takeAll() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpObservable.just(1, 2).takeUntil(new Predicate() { + Observable.just(1, 2).takeUntil(new Predicate() { @Override public boolean test(Integer v) { return false; @@ -59,9 +59,9 @@ public boolean test(Integer v) { } @Test public void takeFirst() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpObservable.just(1, 2).takeUntil(new Predicate() { + Observable.just(1, 2).takeUntil(new Predicate() { @Override public boolean test(Integer v) { return true; @@ -75,9 +75,9 @@ public boolean test(Integer v) { } @Test public void takeSome() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpObservable.just(1, 2, 3).takeUntil(new Predicate() { + Observable.just(1, 2, 3).takeUntil(new Predicate() { @Override public boolean test(Integer t1) { return t1 == 2; @@ -93,7 +93,7 @@ public boolean test(Integer t1) { } @Test public void functionThrows() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); Predicate predicate = (new Predicate() { @Override @@ -101,7 +101,7 @@ public boolean test(Integer t1) { throw new TestException("Forced failure"); } }); - NbpObservable.just(1, 2, 3).takeUntil(predicate).subscribe(o); + Observable.just(1, 2, 3).takeUntil(predicate).subscribe(o); verify(o).onNext(1); verify(o, never()).onNext(2); @@ -111,11 +111,11 @@ public boolean test(Integer t1) { } @Test public void sourceThrows() { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); - NbpObservable.just(1) - .concatWith(NbpObservable.error(new TestException())) - .concatWith(NbpObservable.just(2)) + Observable.just(1) + .concatWith(Observable.error(new TestException())) + .concatWith(Observable.just(2)) .takeUntil(new Predicate() { @Override public boolean test(Integer v) { @@ -131,7 +131,7 @@ public boolean test(Integer v) { @Test public void testErrorIncludesLastValueAsCause() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final TestException e = new TestException("Forced failure"); Predicate predicate = (new Predicate() { @Override @@ -139,7 +139,7 @@ public boolean test(String t) { throw e; } }); - NbpObservable.just("abc").takeUntil(predicate).subscribe(ts); + Observable.just("abc").takeUntil(predicate).subscribe(ts); ts.assertTerminated(); ts.assertNotComplete(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeUntilTest.java similarity index 79% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeUntilTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeUntilTest.java index 9e1ca94aca..873c1830c5 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeUntilTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Mockito.*; @@ -19,10 +19,11 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.Disposable; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.flowable.TestHelper; +import io.reactivex.observers.TestObserver; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorTakeUntilTest { @@ -33,9 +34,9 @@ public void testTakeUntil() { TestObservable source = new TestObservable(sSource); TestObservable other = new TestObservable(sOther); - NbpSubscriber result = TestHelper.mockNbpSubscriber(); - NbpObservable stringObservable = NbpObservable.create(source) - .takeUntil(NbpObservable.create(other)); + Observer result = TestHelper.mockNbpSubscriber(); + Observable stringObservable = Observable.create(source) + .takeUntil(Observable.create(other)); stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); @@ -60,8 +61,8 @@ public void testTakeUntilSourceCompleted() { TestObservable source = new TestObservable(sSource); TestObservable other = new TestObservable(sOther); - NbpSubscriber result = TestHelper.mockNbpSubscriber(); - NbpObservable stringObservable = NbpObservable.create(source).takeUntil(NbpObservable.create(other)); + Observer result = TestHelper.mockNbpSubscriber(); + Observable stringObservable = Observable.create(source).takeUntil(Observable.create(other)); stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); @@ -82,8 +83,8 @@ public void testTakeUntilSourceError() { TestObservable other = new TestObservable(sOther); Throwable error = new Throwable(); - NbpSubscriber result = TestHelper.mockNbpSubscriber(); - NbpObservable stringObservable = NbpObservable.create(source).takeUntil(NbpObservable.create(other)); + Observer result = TestHelper.mockNbpSubscriber(); + Observable stringObservable = Observable.create(source).takeUntil(Observable.create(other)); stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); @@ -107,8 +108,8 @@ public void testTakeUntilOtherError() { TestObservable other = new TestObservable(sOther); Throwable error = new Throwable(); - NbpSubscriber result = TestHelper.mockNbpSubscriber(); - NbpObservable stringObservable = NbpObservable.create(source).takeUntil(NbpObservable.create(other)); + Observer result = TestHelper.mockNbpSubscriber(); + Observable stringObservable = Observable.create(source).takeUntil(Observable.create(other)); stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); @@ -135,8 +136,8 @@ public void testTakeUntilOtherCompleted() { TestObservable source = new TestObservable(sSource); TestObservable other = new TestObservable(sOther); - NbpSubscriber result = TestHelper.mockNbpSubscriber(); - NbpObservable stringObservable = NbpObservable.create(source).takeUntil(NbpObservable.create(other)); + Observer result = TestHelper.mockNbpSubscriber(); + Observable stringObservable = Observable.create(source).takeUntil(Observable.create(other)); stringObservable.subscribe(result); source.sendOnNext("one"); source.sendOnNext("two"); @@ -154,7 +155,7 @@ public void testTakeUntilOtherCompleted() { private static class TestObservable implements NbpOnSubscribe { - NbpSubscriber NbpObserver; + Observer NbpObserver; Disposable s; public TestObservable(Disposable s) { @@ -177,7 +178,7 @@ public void sendOnError(Throwable e) { } @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { this.NbpObserver = NbpObserver; NbpObserver.onSubscribe(s); } @@ -185,10 +186,10 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testUntilFires() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject until = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject until = PublishSubject.create(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); source.takeUntil(until).unsafeSubscribe(ts); @@ -210,10 +211,10 @@ public void testUntilFires() { } @Test public void testMainCompletes() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject until = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject until = PublishSubject.create(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); source.takeUntil(until).unsafeSubscribe(ts); @@ -233,10 +234,10 @@ public void testMainCompletes() { } @Test public void testDownstreamUnsubscribes() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject until = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject until = PublishSubject.create(); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); source.takeUntil(until).take(1).unsafeSubscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeWhileTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeWhileTest.java similarity index 80% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeWhileTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeWhileTest.java index f4c55b370f..6bcd8417cf 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTakeWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTakeWhileTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.fail; import static org.mockito.Matchers.any; @@ -20,27 +20,28 @@ import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Predicate; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.subjects.nbp.*; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.TestObserver; +import io.reactivex.subjects.*; public class NbpOperatorTakeWhileTest { @Test public void testTakeWhile1() { - NbpObservable w = NbpObservable.just(1, 2, 3); - NbpObservable take = w.takeWhile(new Predicate() { + Observable w = Observable.just(1, 2, 3); + Observable take = w.takeWhile(new Predicate() { @Override public boolean test(Integer input) { return input < 3; } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); take.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext(1); verify(NbpObserver, times(1)).onNext(2); @@ -51,15 +52,15 @@ public boolean test(Integer input) { @Test public void testTakeWhileOnSubject1() { - NbpSubject s = NbpPublishSubject.create(); - NbpObservable take = s.takeWhile(new Predicate() { + Subject s = PublishSubject.create(); + Observable take = s.takeWhile(new Predicate() { @Override public boolean test(Integer input) { return input < 3; } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); take.subscribe(NbpObserver); s.onNext(1); @@ -80,8 +81,8 @@ public boolean test(Integer input) { @Test public void testTakeWhile2() { - NbpObservable w = NbpObservable.just("one", "two", "three"); - NbpObservable take = w.takeWhile(new Predicate() { + Observable w = Observable.just("one", "two", "three"); + Observable take = w.takeWhile(new Predicate() { int index = 0; @Override @@ -90,7 +91,7 @@ public boolean test(String input) { } }); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); take.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext("one"); verify(NbpObserver, times(1)).onNext("two"); @@ -101,9 +102,9 @@ public boolean test(String input) { @Test public void testTakeWhileDoesntLeakErrors() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); NbpObserver.onNext("one"); NbpObserver.onError(new Throwable("test failed")); @@ -123,8 +124,8 @@ public void testTakeWhileProtectsPredicateCall() { TestObservable source = new TestObservable(mock(Disposable.class), "one"); final RuntimeException testException = new RuntimeException("test exception"); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable take = NbpObservable.create(source) + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + Observable take = Observable.create(source) .takeWhile(new Predicate() { @Override public boolean test(String s) { @@ -150,8 +151,8 @@ public void testUnsubscribeAfterTake() { Disposable s = mock(Disposable.class); TestObservable w = new TestObservable(s, "one", "two", "three"); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable take = NbpObservable.create(w) + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + Observable take = Observable.create(w) .takeWhile(new Predicate() { int index = 0; @@ -189,7 +190,7 @@ public TestObservable(Disposable s, String... values) { } @Override - public void accept(final NbpSubscriber NbpObserver) { + public void accept(final Observer NbpObserver) { System.out.println("TestObservable subscribed to ..."); NbpObserver.onSubscribe(s); t = new Thread(new Runnable() { @@ -217,13 +218,13 @@ public void run() { @Test public void testNoUnsubscribeDownstream() { - NbpObservable source = NbpObservable.range(1, 1000).takeWhile(new Predicate() { + Observable source = Observable.range(1, 1000).takeWhile(new Predicate() { @Override public boolean test(Integer t1) { return t1 < 2; } }); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); source.unsafeSubscribe(ts); @@ -235,8 +236,8 @@ public boolean test(Integer t1) { @Test public void testErrorCauseIncludesLastValue() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.just("abc").takeWhile(new Predicate() { + TestObserver ts = new TestObserver(); + Observable.just("abc").takeWhile(new Predicate() { @Override public boolean test(String t1) { throw new TestException(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorThrottleFirstTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorThrottleFirstTest.java similarity index 81% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorThrottleFirstTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorThrottleFirstTest.java index 38115f1829..7095a66a7d 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorThrottleFirstTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorThrottleFirstTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,17 +22,18 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorThrottleFirstTest { private TestScheduler scheduler; private Scheduler.Worker innerScheduler; - private NbpSubscriber NbpObserver; + private Observer NbpObserver; @Before public void before() { @@ -43,9 +44,9 @@ public void before() { @Test public void testThrottlingWithCompleted() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); publishNext(NbpObserver, 100, "one"); // publish as it's first publishNext(NbpObserver, 300, "two"); // skip as it's last within the first 400 @@ -55,7 +56,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler); + Observable sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler); sampled.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -71,9 +72,9 @@ public void accept(NbpSubscriber NbpObserver) { @Test public void testThrottlingWithError() { - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); Exception error = new TestException(); publishNext(NbpObserver, 100, "one"); // Should be published since it is first @@ -82,7 +83,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler); + Observable sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler); sampled.subscribe(NbpObserver); InOrder inOrder = inOrder(NbpObserver); @@ -93,7 +94,7 @@ public void accept(NbpSubscriber NbpObserver) { inOrder.verifyNoMoreInteractions(); } - private void publishCompleted(final NbpSubscriber NbpObserver, long delay) { + private void publishCompleted(final Observer NbpObserver, long delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -102,7 +103,7 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private void publishError(final NbpSubscriber NbpObserver, long delay, final Exception error) { + private void publishError(final Observer NbpObserver, long delay, final Exception error) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -111,7 +112,7 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private void publishNext(final NbpSubscriber NbpObserver, long delay, final T value) { + private void publishNext(final Observer NbpObserver, long delay, final T value) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -122,9 +123,9 @@ public void run() { @Test public void testThrottle() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); TestScheduler s = new TestScheduler(); - NbpPublishSubject o = NbpPublishSubject.create(); + PublishSubject o = PublishSubject.create(); o.throttleFirst(500, TimeUnit.MILLISECONDS, s).subscribe(NbpObserver); // send events with simulated time increments diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeIntervalTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTimeIntervalTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeIntervalTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTimeIntervalTest.java index 75bc01a448..f03fb63de3 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeIntervalTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTimeIntervalTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Mockito.*; @@ -21,25 +21,25 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.schedulers.*; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorTimeIntervalTest { private static final TimeUnit TIME_UNIT = TimeUnit.MILLISECONDS; - private NbpSubscriber> NbpObserver; + private Observer> NbpObserver; private TestScheduler testScheduler; - private NbpPublishSubject subject; - private NbpObservable> NbpObservable; + private PublishSubject subject; + private Observable> NbpObservable; @Before public void setUp() { NbpObserver = TestHelper.mockNbpSubscriber(); testScheduler = new TestScheduler(); - subject = NbpPublishSubject.create(); + subject = PublishSubject.create(); NbpObservable = subject.timeInterval(testScheduler); } diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeoutTests.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTimeoutTests.java similarity index 71% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeoutTests.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTimeoutTests.java index 9dc6ba7fc9..72bb1b21e5 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTimeoutTests.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTimeoutTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.*; import static org.mockito.Mockito.*; @@ -23,32 +23,33 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.Disposable; +import io.reactivex.flowable.TestHelper; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorTimeoutTests { - private NbpPublishSubject underlyingSubject; + private PublishSubject underlyingSubject; private TestScheduler testScheduler; - private NbpObservable withTimeout; + private Observable withTimeout; private static final long TIMEOUT = 3; private static final TimeUnit TIME_UNIT = TimeUnit.SECONDS; @Before public void setUp() { - underlyingSubject = NbpPublishSubject.create(); + underlyingSubject = PublishSubject.create(); testScheduler = new TestScheduler(); withTimeout = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler); } @Test public void shouldNotTimeoutIfOnNextWithinTimeout() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); withTimeout.subscribe(ts); @@ -62,8 +63,8 @@ public void shouldNotTimeoutIfOnNextWithinTimeout() { @Test public void shouldNotTimeoutIfSecondOnNextWithinTimeout() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); withTimeout.subscribe(ts); @@ -79,8 +80,8 @@ public void shouldNotTimeoutIfSecondOnNextWithinTimeout() { @Test public void shouldTimeoutIfOnNextNotWithinTimeout() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); withTimeout.subscribe(ts); @@ -91,8 +92,8 @@ public void shouldTimeoutIfOnNextNotWithinTimeout() { @Test public void shouldTimeoutIfSecondOnNextNotWithinTimeout() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); withTimeout.subscribe(NbpObserver); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); @@ -104,8 +105,8 @@ public void shouldTimeoutIfSecondOnNextNotWithinTimeout() { @Test public void shouldCompleteIfUnderlyingComletes() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); withTimeout.subscribe(NbpObserver); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onComplete(); @@ -117,8 +118,8 @@ public void shouldCompleteIfUnderlyingComletes() { @Test public void shouldErrorIfUnderlyingErrors() { - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); withTimeout.subscribe(NbpObserver); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onError(new UnsupportedOperationException()); @@ -129,11 +130,11 @@ public void shouldErrorIfUnderlyingErrors() { @Test public void shouldSwitchToOtherIfOnNextNotWithinTimeout() { - NbpObservable other = NbpObservable.just("a", "b", "c"); - NbpObservable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); + Observable other = Observable.just("a", "b", "c"); + Observable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); source.subscribe(ts); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); @@ -152,11 +153,11 @@ public void shouldSwitchToOtherIfOnNextNotWithinTimeout() { @Test public void shouldSwitchToOtherIfOnErrorNotWithinTimeout() { - NbpObservable other = NbpObservable.just("a", "b", "c"); - NbpObservable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); + Observable other = Observable.just("a", "b", "c"); + Observable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); source.subscribe(ts); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); @@ -175,11 +176,11 @@ public void shouldSwitchToOtherIfOnErrorNotWithinTimeout() { @Test public void shouldSwitchToOtherIfOnCompletedNotWithinTimeout() { - NbpObservable other = NbpObservable.just("a", "b", "c"); - NbpObservable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); + Observable other = Observable.just("a", "b", "c"); + Observable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); source.subscribe(ts); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); @@ -198,11 +199,11 @@ public void shouldSwitchToOtherIfOnCompletedNotWithinTimeout() { @Test public void shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout() { - NbpPublishSubject other = NbpPublishSubject.create(); - NbpObservable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); + PublishSubject other = PublishSubject.create(); + Observable source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, other, testScheduler); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); source.subscribe(ts); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); @@ -232,17 +233,17 @@ public void shouldTimeoutIfSynchronizedObservableEmitFirstOnNextNotWithinTimeout final CountDownLatch exit = new CountDownLatch(1); final CountDownLatch timeoutSetuped = new CountDownLatch(1); - final NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - final NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + final Observer NbpObserver = TestHelper.mockNbpSubscriber(); + final TestObserver ts = new TestObserver(NbpObserver); new Thread(new Runnable() { @Override public void run() { - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpSubscriber) { + public void accept(Observer NbpSubscriber) { NbpSubscriber.onSubscribe(EmptyDisposable.INSTANCE); try { timeoutSetuped.countDown(); @@ -274,18 +275,18 @@ public void shouldUnsubscribeFromUnderlyingSubscriptionOnTimeout() throws Interr // From https://github.com/ReactiveX/RxJava/pull/951 final Disposable s = mock(Disposable.class); - NbpObservable never = NbpObservable.create(new NbpOnSubscribe() { + Observable never = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpSubscriber) { + public void accept(Observer NbpSubscriber) { NbpSubscriber.onSubscribe(s); } }); TestScheduler testScheduler = new TestScheduler(); - NbpObservable observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); + Observable observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); observableWithTimeout.subscribe(ts); testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS); @@ -303,20 +304,20 @@ public void shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyComplete() { // From https://github.com/ReactiveX/RxJava/pull/951 final Disposable s = mock(Disposable.class); - NbpObservable immediatelyComplete = NbpObservable.create(new NbpOnSubscribe() { + Observable immediatelyComplete = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpSubscriber) { + public void accept(Observer NbpSubscriber) { NbpSubscriber.onSubscribe(s); NbpSubscriber.onComplete(); } }); TestScheduler testScheduler = new TestScheduler(); - NbpObservable observableWithTimeout = immediatelyComplete.timeout(1000, TimeUnit.MILLISECONDS, + Observable observableWithTimeout = immediatelyComplete.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); observableWithTimeout.subscribe(ts); testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS); @@ -334,20 +335,20 @@ public void shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyErrored() th // From https://github.com/ReactiveX/RxJava/pull/951 final Disposable s = mock(Disposable.class); - NbpObservable immediatelyError = NbpObservable.create(new NbpOnSubscribe() { + Observable immediatelyError = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpSubscriber) { + public void accept(Observer NbpSubscriber) { NbpSubscriber.onSubscribe(s); NbpSubscriber.onError(new IOException("Error")); } }); TestScheduler testScheduler = new TestScheduler(); - NbpObservable observableWithTimeout = immediatelyError.timeout(1000, TimeUnit.MILLISECONDS, + Observable observableWithTimeout = immediatelyError.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); observableWithTimeout.subscribe(ts); testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorTimeoutWithSelectorTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTimeoutWithSelectorTest.java similarity index 90% rename from src/test/java/io/reactivex/internal/operators/OperatorTimeoutWithSelectorTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTimeoutWithSelectorTest.java index 0a3d30a651..8471e5fcfb 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorTimeoutWithSelectorTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTimeoutWithSelectorTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertFalse; import static org.mockito.Matchers.*; @@ -25,17 +25,19 @@ import org.mockito.InOrder; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import org.reactivestreams.*; import io.reactivex.*; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; -import io.reactivex.subscribers.TestSubscriber; -public class OperatorTimeoutWithSelectorTest { +public class NbpOperatorTimeoutWithSelectorTest { @Test(timeout = 2000) public void testTimeoutSelectorNormal1() { PublishSubject source = PublishSubject.create(); @@ -57,7 +59,7 @@ public Observable get() { Observable other = Observable.fromIterable(Arrays.asList(100)); - Subscriber o = TestHelper.mockSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); @@ -97,7 +99,7 @@ public Observable get() { Observable other = Observable.fromIterable(Arrays.asList(100)); - Subscriber o = TestHelper.mockSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); @@ -131,7 +133,7 @@ public Observable get() { Observable other = Observable.fromIterable(Arrays.asList(100)); - Subscriber o = TestHelper.mockSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); @@ -162,7 +164,7 @@ public Observable get() { Observable other = Observable.fromIterable(Arrays.asList(100)); - Subscriber o = TestHelper.mockSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); @@ -196,7 +198,7 @@ public Observable get() { Observable other = Observable.fromIterable(Arrays.asList(100)); - Subscriber o = TestHelper.mockSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); @@ -227,7 +229,7 @@ public Observable get() { Observable other = Observable.fromIterable(Arrays.asList(100)); - Subscriber o = TestHelper.mockSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.timeout(firstTimeoutFunc, timeoutFunc, other).subscribe(o); @@ -259,7 +261,7 @@ public Observable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.timeout(firstTimeoutFunc, timeoutFunc).subscribe(o); timeout.onNext(1); @@ -288,7 +290,7 @@ public Observable apply(Integer t1) { } }; - Subscriber o = TestHelper.mockSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.timeout(firstTimeoutFunc, timeoutFunc).subscribe(o); source.onNext(1); @@ -304,16 +306,16 @@ public Observable apply(Integer t1) { public void testTimeoutSelectorWithTimeoutAndOnNextRaceCondition() throws InterruptedException { // Thread 1 Thread 2 // - // observer.onNext(1) + // NbpObserver.onNext(1) // start timeout // unsubscribe timeout in thread 2 start to do some long-time work in "unsubscribe" - // observer.onNext(2) + // NbpObserver.onNext(2) // timeout.onNext(1) // "unsubscribe" done // // // In the above case, the timeout operator should ignore "timeout.onNext(1)" - // since "observer" has already seen 2. + // since "NbpObserver" has already seen 2. final CountDownLatch observerReceivedTwo = new CountDownLatch(1); final CountDownLatch timeoutEmittedOne = new CountDownLatch(1); final CountDownLatch observerCompleted = new CountDownLatch(1); @@ -325,12 +327,12 @@ public void testTimeoutSelectorWithTimeoutAndOnNextRaceCondition() throws Interr public Observable apply(Integer t1) { if (t1 == 1) { // Force "unsubscribe" run on another thread - return Observable.create(new Publisher() { + return Observable.create(new NbpOnSubscribe() { @Override - public void subscribe(Subscriber subscriber) { - subscriber.onSubscribe(EmptySubscription.INSTANCE); + public void accept(Observer NbpSubscriber) { + NbpSubscriber.onSubscribe(EmptyDisposable.INSTANCE); enteredTimeoutOne.countDown(); - // force the timeout message be sent after observer.onNext(2) + // force the timeout message be sent after NbpObserver.onNext(2) while (true) { try { if (!observerReceivedTwo.await(30, TimeUnit.SECONDS)) { @@ -344,7 +346,7 @@ public void subscribe(Subscriber subscriber) { // we ignore the interrupt signal from Scheduler. } } - subscriber.onNext(1); + NbpSubscriber.onNext(1); timeoutEmittedOne.countDown(); } }).subscribeOn(Schedulers.newThread()); @@ -354,7 +356,7 @@ public void subscribe(Subscriber subscriber) { } }; - final Subscriber o = TestHelper.mockSubscriber(); + final Observer o = TestHelper.mockNbpSubscriber(); doAnswer(new Answer() { @Override @@ -374,7 +376,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable { }).when(o).onComplete(); - final TestSubscriber ts = new TestSubscriber(o); + final TestObserver ts = new TestObserver(o); new Thread(new Runnable() { @@ -410,7 +412,7 @@ public void run() { assertFalse("CoundDownLatch timeout", latchTimeout.get()); InOrder inOrder = inOrder(o); - inOrder.verify(o).onSubscribe((Subscription)notNull()); + inOrder.verify(o).onSubscribe((Disposable)notNull()); inOrder.verify(o).onNext(1); inOrder.verify(o).onNext(2); inOrder.verify(o, never()).onNext(3); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTimestampTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTimestampTest.java similarity index 84% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTimestampTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTimestampTest.java index 750f2f7b19..b5a31acff6 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorTimestampTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorTimestampTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,12 +22,12 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.schedulers.*; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorTimestampTest { - NbpSubscriber NbpObserver; + Observer NbpObserver; @Before public void before() { @@ -38,8 +38,8 @@ public void before() { public void timestampWithScheduler() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); - NbpObservable> m = source.timestamp(scheduler); + PublishSubject source = PublishSubject.create(); + Observable> m = source.timestamp(scheduler); m.subscribe(NbpObserver); source.onNext(1); @@ -62,8 +62,8 @@ public void timestampWithScheduler() { public void timestampWithScheduler2() { TestScheduler scheduler = new TestScheduler(); - NbpPublishSubject source = NbpPublishSubject.create(); - NbpObservable> m = source.timestamp(scheduler); + PublishSubject source = PublishSubject.create(); + Observable> m = source.timestamp(scheduler); m.subscribe(NbpObserver); source.onNext(1); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorToMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorToMapTest.java similarity index 83% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorToMapTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorToMapTest.java index 54f11be314..cd8fd89581 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorToMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorToMapTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -20,12 +20,13 @@ import org.junit.*; -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; public class NbpOperatorToMapTest { - NbpSubscriber objectObserver; + Observer objectObserver; @Before public void before() { @@ -47,9 +48,9 @@ public String apply(String t1) { @Test public void testToMap() { - NbpObservable source = NbpObservable.just("a", "bb", "ccc", "dddd"); + Observable source = Observable.just("a", "bb", "ccc", "dddd"); - NbpObservable> mapped = source.toMap(lengthFunc); + Observable> mapped = source.toMap(lengthFunc); Map expected = new HashMap(); expected.put(1, "a"); @@ -66,9 +67,9 @@ public void testToMap() { @Test public void testToMapWithValueSelector() { - NbpObservable source = NbpObservable.just("a", "bb", "ccc", "dddd"); + Observable source = Observable.just("a", "bb", "ccc", "dddd"); - NbpObservable> mapped = source.toMap(lengthFunc, duplicate); + Observable> mapped = source.toMap(lengthFunc, duplicate); Map expected = new HashMap(); expected.put(1, "aa"); @@ -85,7 +86,7 @@ public void testToMapWithValueSelector() { @Test public void testToMapWithError() { - NbpObservable source = NbpObservable.just("a", "bb", "ccc", "dddd"); + Observable source = Observable.just("a", "bb", "ccc", "dddd"); Function lengthFuncErr = new Function() { @Override @@ -96,7 +97,7 @@ public Integer apply(String t1) { return t1.length(); } }; - NbpObservable> mapped = source.toMap(lengthFuncErr); + Observable> mapped = source.toMap(lengthFuncErr); Map expected = new HashMap(); expected.put(1, "a"); @@ -114,7 +115,7 @@ public Integer apply(String t1) { @Test public void testToMapWithErrorInValueSelector() { - NbpObservable source = NbpObservable.just("a", "bb", "ccc", "dddd"); + Observable source = Observable.just("a", "bb", "ccc", "dddd"); Function duplicateErr = new Function() { @Override @@ -126,7 +127,7 @@ public String apply(String t1) { } }; - NbpObservable> mapped = source.toMap(lengthFunc, duplicateErr); + Observable> mapped = source.toMap(lengthFunc, duplicateErr); Map expected = new HashMap(); expected.put(1, "aa"); @@ -144,7 +145,7 @@ public String apply(String t1) { @Test public void testToMapWithFactory() { - NbpObservable source = NbpObservable.just("a", "bb", "ccc", "dddd"); + Observable source = Observable.just("a", "bb", "ccc", "dddd"); Supplier> mapFactory = new Supplier>() { @Override @@ -167,7 +168,7 @@ public Integer apply(String t1) { return t1.length(); } }; - NbpObservable> mapped = source.toMap(lengthFunc, new Function() { + Observable> mapped = source.toMap(lengthFunc, new Function() { @Override public String apply(String v) { return v; @@ -188,7 +189,7 @@ public String apply(String v) { @Test public void testToMapWithErrorThrowingFactory() { - NbpObservable source = NbpObservable.just("a", "bb", "ccc", "dddd"); + Observable source = Observable.just("a", "bb", "ccc", "dddd"); Supplier> mapFactory = new Supplier>() { @Override @@ -203,7 +204,7 @@ public Integer apply(String t1) { return t1.length(); } }; - NbpObservable> mapped = source.toMap(lengthFunc, new Function() { + Observable> mapped = source.toMap(lengthFunc, new Function() { @Override public String apply(String v) { return v; diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorToMultimapTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorToMultimapTest.java similarity index 85% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorToMultimapTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorToMultimapTest.java index 4530788860..a8b228c029 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorToMultimapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorToMultimapTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -20,12 +20,13 @@ import org.junit.*; -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; public class NbpOperatorToMultimapTest { - NbpSubscriber objectObserver; + Observer objectObserver; @Before public void before() { @@ -47,9 +48,9 @@ public String apply(String t1) { @Test public void testToMultimap() { - NbpObservable source = NbpObservable.just("a", "b", "cc", "dd"); + Observable source = Observable.just("a", "b", "cc", "dd"); - NbpObservable>> mapped = source.toMultimap(lengthFunc); + Observable>> mapped = source.toMultimap(lengthFunc); Map> expected = new HashMap>(); expected.put(1, Arrays.asList("a", "b")); @@ -64,9 +65,9 @@ public void testToMultimap() { @Test public void testToMultimapWithValueSelector() { - NbpObservable source = NbpObservable.just("a", "b", "cc", "dd"); + Observable source = Observable.just("a", "b", "cc", "dd"); - NbpObservable>> mapped = source.toMultimap(lengthFunc, duplicate); + Observable>> mapped = source.toMultimap(lengthFunc, duplicate); Map> expected = new HashMap>(); expected.put(1, Arrays.asList("aa", "bb")); @@ -81,7 +82,7 @@ public void testToMultimapWithValueSelector() { @Test public void testToMultimapWithMapFactory() { - NbpObservable source = NbpObservable.just("a", "b", "cc", "dd", "eee", "fff"); + Observable source = Observable.just("a", "b", "cc", "dd", "eee", "fff"); Supplier>> mapFactory = new Supplier>>() { @Override @@ -105,7 +106,7 @@ public String apply(String v) { } }; - NbpObservable>> mapped = source.toMultimap( + Observable>> mapped = source.toMultimap( lengthFunc, identity, mapFactory, new Function>() { @Override @@ -127,7 +128,7 @@ public Collection apply(Integer v) { @Test public void testToMultimapWithCollectionFactory() { - NbpObservable source = NbpObservable.just("cc", "dd", "eee", "eee"); + Observable source = Observable.just("cc", "dd", "eee", "eee"); Function> collectionFactory = new Function>() { @Override @@ -153,7 +154,7 @@ public Map> get() { } }; - NbpObservable>> mapped = source + Observable>> mapped = source .toMultimap(lengthFunc, identity, mapSupplier, collectionFactory); Map> expected = new HashMap>(); @@ -169,7 +170,7 @@ public Map> get() { @Test public void testToMultimapWithError() { - NbpObservable source = NbpObservable.just("a", "b", "cc", "dd"); + Observable source = Observable.just("a", "b", "cc", "dd"); Function lengthFuncErr = new Function() { @Override @@ -181,7 +182,7 @@ public Integer apply(String t1) { } }; - NbpObservable>> mapped = source.toMultimap(lengthFuncErr); + Observable>> mapped = source.toMultimap(lengthFuncErr); Map> expected = new HashMap>(); expected.put(1, Arrays.asList("a", "b")); @@ -196,7 +197,7 @@ public Integer apply(String t1) { @Test public void testToMultimapWithErrorInValueSelector() { - NbpObservable source = NbpObservable.just("a", "b", "cc", "dd"); + Observable source = Observable.just("a", "b", "cc", "dd"); Function duplicateErr = new Function() { @Override @@ -208,7 +209,7 @@ public String apply(String t1) { } }; - NbpObservable>> mapped = source.toMultimap(lengthFunc, duplicateErr); + Observable>> mapped = source.toMultimap(lengthFunc, duplicateErr); Map> expected = new HashMap>(); expected.put(1, Arrays.asList("aa", "bb")); @@ -223,7 +224,7 @@ public String apply(String t1) { @Test public void testToMultimapWithMapThrowingFactory() { - NbpObservable source = NbpObservable.just("a", "b", "cc", "dd", "eee", "fff"); + Observable source = Observable.just("a", "b", "cc", "dd", "eee", "fff"); Supplier>> mapFactory = new Supplier>>() { @Override @@ -232,7 +233,7 @@ public Map> get() { } }; - NbpObservable>> mapped = source + Observable>> mapped = source .toMultimap(lengthFunc, new Function() { @Override public String apply(String v) { @@ -253,7 +254,7 @@ public String apply(String v) { @Test public void testToMultimapWithThrowingCollectionFactory() { - NbpObservable source = NbpObservable.just("cc", "cc", "eee", "eee"); + Observable source = Observable.just("cc", "cc", "eee", "eee"); Function> collectionFactory = new Function>() { @Override @@ -279,7 +280,7 @@ public Map> get() { } }; - NbpObservable>> mapped = source.toMultimap(lengthFunc, + Observable>> mapped = source.toMultimap(lengthFunc, identity, mapSupplier, collectionFactory); Map> expected = new HashMap>(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorToObservableListTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorToObservableListTest.java similarity index 68% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorToObservableListTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorToObservableListTest.java index cd0f8ecfc0..d6e8d609b0 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorToObservableListTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorToObservableListTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -22,17 +22,18 @@ import org.junit.*; import org.mockito.Mockito; -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.flowable.TestHelper; public class NbpOperatorToObservableListTest { @Test public void testList() { - NbpObservable w = NbpObservable.fromIterable(Arrays.asList("one", "two", "three")); - NbpObservable> NbpObservable = w.toList(); + Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); + Observable> NbpObservable = w.toList(); - NbpSubscriber> NbpObserver = TestHelper.mockNbpSubscriber(); + Observer> NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext(Arrays.asList("one", "two", "three")); verify(NbpObserver, Mockito.never()).onError(any(Throwable.class)); @@ -41,10 +42,10 @@ public void testList() { @Test public void testListViaObservable() { - NbpObservable w = NbpObservable.fromIterable(Arrays.asList("one", "two", "three")); - NbpObservable> NbpObservable = w.toList(); + Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); + Observable> NbpObservable = w.toList(); - NbpSubscriber> NbpObserver = TestHelper.mockNbpSubscriber(); + Observer> NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext(Arrays.asList("one", "two", "three")); verify(NbpObserver, Mockito.never()).onError(any(Throwable.class)); @@ -53,13 +54,13 @@ public void testListViaObservable() { @Test public void testListMultipleSubscribers() { - NbpObservable w = NbpObservable.fromIterable(Arrays.asList("one", "two", "three")); - NbpObservable> NbpObservable = w.toList(); + Observable w = Observable.fromIterable(Arrays.asList("one", "two", "three")); + Observable> NbpObservable = w.toList(); - NbpSubscriber> o1 = TestHelper.mockNbpSubscriber(); + Observer> o1 = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(o1); - NbpSubscriber> o2 = TestHelper.mockNbpSubscriber(); + Observer> o2 = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(o2); List expected = Arrays.asList("one", "two", "three"); @@ -76,10 +77,10 @@ public void testListMultipleSubscribers() { @Test @Ignore("Null values are not allowed") public void testListWithNullValue() { - NbpObservable w = NbpObservable.fromIterable(Arrays.asList("one", null, "three")); - NbpObservable> NbpObservable = w.toList(); + Observable w = Observable.fromIterable(Arrays.asList("one", null, "three")); + Observable> NbpObservable = w.toList(); - NbpSubscriber> NbpObserver = TestHelper.mockNbpSubscriber(); + Observer> NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext(Arrays.asList("one", null, "three")); verify(NbpObserver, Mockito.never()).onError(any(Throwable.class)); @@ -88,7 +89,7 @@ public void testListWithNullValue() { @Test public void testListWithBlockingFirst() { - NbpObservable o = NbpObservable.fromIterable(Arrays.asList("one", "two", "three")); + Observable o = Observable.fromIterable(Arrays.asList("one", "two", "three")); List actual = o.toList().toBlocking().first(); Assert.assertEquals(Arrays.asList("one", "two", "three"), actual); } diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorToObservableSortedListTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorToObservableSortedListTest.java similarity index 75% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorToObservableSortedListTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorToObservableSortedListTest.java index 7998113777..7613b008c1 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorToObservableSortedListTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorToObservableSortedListTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -23,17 +23,18 @@ import org.junit.Test; import org.mockito.Mockito; -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.flowable.TestHelper; public class NbpOperatorToObservableSortedListTest { @Test public void testSortedList() { - NbpObservable w = NbpObservable.just(1, 3, 2, 5, 4); - NbpObservable> NbpObservable = w.toSortedList(); + Observable w = Observable.just(1, 3, 2, 5, 4); + Observable> NbpObservable = w.toSortedList(); - NbpSubscriber> NbpObserver = TestHelper.mockNbpSubscriber(); + Observer> NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext(Arrays.asList(1, 2, 3, 4, 5)); verify(NbpObserver, Mockito.never()).onError(any(Throwable.class)); @@ -42,8 +43,8 @@ public void testSortedList() { @Test public void testSortedListWithCustomFunction() { - NbpObservable w = NbpObservable.just(1, 3, 2, 5, 4); - NbpObservable> NbpObservable = w.toSortedList(new Comparator() { + Observable w = Observable.just(1, 3, 2, 5, 4); + Observable> NbpObservable = w.toSortedList(new Comparator() { @Override public int compare(Integer t1, Integer t2) { @@ -52,7 +53,7 @@ public int compare(Integer t1, Integer t2) { }); - NbpSubscriber> NbpObserver = TestHelper.mockNbpSubscriber(); + Observer> NbpObserver = TestHelper.mockNbpSubscriber(); NbpObservable.subscribe(NbpObserver); verify(NbpObserver, times(1)).onNext(Arrays.asList(5, 4, 3, 2, 1)); verify(NbpObserver, Mockito.never()).onError(any(Throwable.class)); @@ -61,7 +62,7 @@ public int compare(Integer t1, Integer t2) { @Test public void testWithFollowingFirst() { - NbpObservable o = NbpObservable.just(1, 3, 2, 5, 4); + Observable o = Observable.just(1, 3, 2, 5, 4); assertEquals(Arrays.asList(1, 2, 3, 4, 5), o.toSortedList().toBlocking().first()); } diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorUnsubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorUnsubscribeOnTest.java similarity index 90% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorUnsubscribeOnTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorUnsubscribeOnTest.java index 5b59133dd1..5a1336e397 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorUnsubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorUnsubscribeOnTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; @@ -21,10 +21,10 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOnSubscribe; import io.reactivex.disposables.Disposable; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorUnsubscribeOnTest { @@ -34,10 +34,10 @@ public void testUnsubscribeWhenSubscribeOnAndUnsubscribeOnAreOnSameThread() thro try { final ThreadSubscription subscription = new ThreadSubscription(); final AtomicReference subscribeThread = new AtomicReference(); - NbpObservable w = NbpObservable.create(new NbpOnSubscribe() { + Observable w = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber t1) { + public void accept(Observer t1) { subscribeThread.set(Thread.currentThread()); t1.onSubscribe(subscription); t1.onNext(1); @@ -46,7 +46,7 @@ public void accept(NbpSubscriber t1) { } }); - NbpTestSubscriber NbpObserver = new NbpTestSubscriber(); + TestObserver NbpObserver = new TestObserver(); w.subscribeOn(UI_EVENT_LOOP).observeOn(Schedulers.computation()).unsubscribeOn(UI_EVENT_LOOP).subscribe(NbpObserver); NbpObserver.awaitTerminalEvent(1, TimeUnit.SECONDS); @@ -78,10 +78,10 @@ public void testUnsubscribeWhenSubscribeOnAndUnsubscribeOnAreOnDifferentThreads( try { final ThreadSubscription subscription = new ThreadSubscription(); final AtomicReference subscribeThread = new AtomicReference(); - NbpObservable w = NbpObservable.create(new NbpOnSubscribe() { + Observable w = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber t1) { + public void accept(Observer t1) { subscribeThread.set(Thread.currentThread()); t1.onSubscribe(subscription); t1.onNext(1); @@ -90,7 +90,7 @@ public void accept(NbpSubscriber t1) { } }); - NbpTestSubscriber NbpObserver = new NbpTestSubscriber(); + TestObserver NbpObserver = new TestObserver(); w.subscribeOn(Schedulers.newThread()).observeOn(Schedulers.computation()).unsubscribeOn(UI_EVENT_LOOP).subscribe(NbpObserver); NbpObserver.awaitTerminalEvent(1, TimeUnit.SECONDS); diff --git a/src/test/java/io/reactivex/internal/operators/OperatorWindowWithObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWindowWithObservableTest.java similarity index 75% rename from src/test/java/io/reactivex/internal/operators/OperatorWindowWithObservableTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWindowWithObservableTest.java index 1e3383abff..9f13482e42 100644 --- a/src/test/java/io/reactivex/internal/operators/OperatorWindowWithObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWindowWithObservableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -21,31 +21,30 @@ import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; -import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Observable; +import io.reactivex.Observer; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Supplier; +import io.reactivex.observers.*; import io.reactivex.subjects.PublishSubject; -import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; -public class OperatorWindowWithObservableTest { +public class NbpOperatorWindowWithObservableTest { @Test public void testWindowViaObservableNormal1() { PublishSubject source = PublishSubject.create(); PublishSubject boundary = PublishSubject.create(); - final Subscriber o = TestHelper.mockSubscriber(); + final Observer o = TestHelper.mockNbpSubscriber(); - final List> values = new ArrayList>(); + final List> values = new ArrayList>(); - Subscriber> wo = new Observer>() { + Observer> wo = new DefaultObserver>() { @Override public void onNext(Observable args) { - final Subscriber mo = TestHelper.mockSubscriber(); + final Observer mo = TestHelper.mockNbpSubscriber(); values.add(mo); args.subscribe(mo); @@ -79,7 +78,7 @@ public void onComplete() { assertEquals(n / 3, values.size()); int j = 0; - for (Subscriber mo : values) { + for (Observer mo : values) { verify(mo, never()).onError(any(Throwable.class)); for (int i = 0; i < 3; i++) { verify(mo).onNext(j + i); @@ -96,14 +95,14 @@ public void testWindowViaObservableBoundaryCompletes() { PublishSubject source = PublishSubject.create(); PublishSubject boundary = PublishSubject.create(); - final Subscriber o = TestHelper.mockSubscriber(); + final Observer o = TestHelper.mockNbpSubscriber(); - final List> values = new ArrayList>(); + final List> values = new ArrayList>(); - Subscriber> wo = new Observer>() { + Observer> wo = new DefaultObserver>() { @Override public void onNext(Observable args) { - final Subscriber mo = TestHelper.mockSubscriber(); + final Observer mo = TestHelper.mockNbpSubscriber(); values.add(mo); args.subscribe(mo); @@ -134,7 +133,7 @@ public void onComplete() { assertEquals(n / 3, values.size()); int j = 0; - for (Subscriber mo : values) { + for (Observer mo : values) { for (int i = 0; i < 3; i++) { verify(mo).onNext(j + i); } @@ -152,14 +151,14 @@ public void testWindowViaObservableBoundaryThrows() { PublishSubject source = PublishSubject.create(); PublishSubject boundary = PublishSubject.create(); - final Subscriber o = TestHelper.mockSubscriber(); + final Observer o = TestHelper.mockNbpSubscriber(); - final List> values = new ArrayList>(); + final List> values = new ArrayList>(); - Subscriber> wo = new Observer>() { + Observer> wo = new DefaultObserver>() { @Override public void onNext(Observable args) { - final Subscriber mo = TestHelper.mockSubscriber(); + final Observer mo = TestHelper.mockNbpSubscriber(); values.add(mo); args.subscribe(mo); @@ -186,7 +185,7 @@ public void onComplete() { assertEquals(1, values.size()); - Subscriber mo = values.get(0); + Observer mo = values.get(0); verify(mo).onNext(0); verify(mo).onNext(1); @@ -202,14 +201,14 @@ public void testWindowViaObservableSourceThrows() { PublishSubject source = PublishSubject.create(); PublishSubject boundary = PublishSubject.create(); - final Subscriber o = TestHelper.mockSubscriber(); + final Observer o = TestHelper.mockNbpSubscriber(); - final List> values = new ArrayList>(); + final List> values = new ArrayList>(); - Subscriber> wo = new Observer>() { + Observer> wo = new DefaultObserver>() { @Override public void onNext(Observable args) { - final Subscriber mo = TestHelper.mockSubscriber(); + final Observer mo = TestHelper.mockNbpSubscriber(); values.add(mo); args.subscribe(mo); @@ -236,7 +235,7 @@ public void onComplete() { assertEquals(1, values.size()); - Subscriber mo = values.get(0); + Observer mo = values.get(0); verify(mo).onNext(0); verify(mo).onNext(1); @@ -250,7 +249,7 @@ public void onComplete() { @Test public void testWindowNoDuplication() { final PublishSubject source = PublishSubject.create(); - final TestSubscriber tsw = new TestSubscriber() { + final TestObserver tsw = new TestObserver() { boolean once; @Override public void onNext(Integer t) { @@ -261,7 +260,7 @@ public void onNext(Integer t) { super.onNext(t); } }; - TestSubscriber> ts = new TestSubscriber>() { + TestObserver> ts = new TestObserver>() { @Override public void onNext(Observable t) { t.subscribe(tsw); @@ -292,7 +291,7 @@ public Observable get() { } }; - TestSubscriber> ts = new TestSubscriber>(); + TestObserver> ts = new TestObserver>(); source.window(boundary).unsafeSubscribe(ts); assertFalse(ts.isCancelled()); @@ -309,7 +308,7 @@ public Observable get() { } }; - TestSubscriber> ts = new TestSubscriber>(); + TestObserver> ts = new TestObserver>(); source.window(boundaryFunc).subscribe(ts); assertTrue(source.hasSubscribers()); @@ -335,7 +334,7 @@ public Observable get() { } }; - TestSubscriber> ts = new TestSubscriber>(); + TestObserver> ts = new TestObserver>(); source.window(boundaryFunc).subscribe(ts); assertTrue(source.hasSubscribers()); @@ -363,7 +362,7 @@ public Observable get() { } }; - TestSubscriber> ts = new TestSubscriber>(); + TestObserver> ts = new TestObserver>(); source.window(boundaryFunc).subscribe(ts); assertTrue(source.hasSubscribers()); @@ -380,42 +379,6 @@ public Observable get() { ts.assertNoErrors(); ts.assertValueCount(1); } - @Test - public void testInnerBackpressure() { - Observable source = Observable.range(1, 10); - final PublishSubject boundary = PublishSubject.create(); - Supplier> boundaryFunc = new Supplier>() { - @Override - public Observable get() { - return boundary; - } - }; - - final TestSubscriber ts = new TestSubscriber(1L); - final TestSubscriber> ts1 = new TestSubscriber>(1L) { - @Override - public void onNext(Observable t) { - super.onNext(t); - t.subscribe(ts); - } - }; - source.window(boundaryFunc) - .subscribe(ts1); - - ts1.assertNoErrors(); - ts1.assertComplete(); - ts1.assertValueCount(1); - - ts.assertNoErrors(); - ts.assertNotComplete(); - ts.assertValues(1); - - ts.request(11); - - ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); - ts.assertNoErrors(); - ts.assertComplete(); - } @Test public void newBoundaryCalledAfterWindowClosed() { @@ -430,7 +393,7 @@ public Observable get() { } }; - TestSubscriber> ts = new TestSubscriber>(); + TestObserver> ts = new TestObserver>(); source.window(boundaryFunc).subscribe(ts); source.onNext(1); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowWithSizeTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWindowWithSizeTest.java similarity index 75% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowWithSizeTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWindowWithSizeTest.java index f361c79b3e..40b4bedee3 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowWithSizeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWindowWithSizeTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; @@ -21,21 +21,22 @@ import org.junit.Test; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.disposables.BooleanDisposable; import io.reactivex.functions.*; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorWindowWithSizeTest { - private static List> toLists(NbpObservable> observables) { + private static List> toLists(Observable> observables) { final List> lists = new ArrayList>(); - NbpObservable.concat(observables.map(new Function, NbpObservable>>() { + Observable.concat(observables.map(new Function, Observable>>() { @Override - public NbpObservable> apply(NbpObservable xs) { + public Observable> apply(Observable xs) { return xs.toList(); } })) @@ -51,8 +52,8 @@ public void accept(List xs) { @Test public void testNonOverlappingWindows() { - NbpObservable subject = NbpObservable.just("one", "two", "three", "four", "five"); - NbpObservable> windowed = subject.window(3); + Observable subject = Observable.just("one", "two", "three", "four", "five"); + Observable> windowed = subject.window(3); List> windows = toLists(windowed); @@ -63,8 +64,8 @@ public void testNonOverlappingWindows() { @Test public void testSkipAndCountGaplessWindows() { - NbpObservable subject = NbpObservable.just("one", "two", "three", "four", "five"); - NbpObservable> windowed = subject.window(3, 3); + Observable subject = Observable.just("one", "two", "three", "four", "five"); + Observable> windowed = subject.window(3, 3); List> windows = toLists(windowed); @@ -75,8 +76,8 @@ public void testSkipAndCountGaplessWindows() { @Test public void testOverlappingWindows() { - NbpObservable subject = NbpObservable.fromArray(new String[] { "zero", "one", "two", "three", "four", "five" }); - NbpObservable> windowed = subject.window(3, 1); + Observable subject = Observable.fromArray(new String[] { "zero", "one", "two", "three", "four", "five" }); + Observable> windowed = subject.window(3, 1); List> windows = toLists(windowed); @@ -91,8 +92,8 @@ public void testOverlappingWindows() { @Test public void testSkipAndCountWindowsWithGaps() { - NbpObservable subject = NbpObservable.just("one", "two", "three", "four", "five"); - NbpObservable> windowed = subject.window(2, 3); + Observable subject = Observable.just("one", "two", "three", "four", "five"); + Observable> windowed = subject.window(2, 3); List> windows = toLists(windowed); @@ -103,9 +104,9 @@ public void testSkipAndCountWindowsWithGaps() { @Test public void testWindowUnsubscribeNonOverlapping() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final AtomicInteger count = new AtomicInteger(); - NbpObservable.merge(NbpObservable.range(1, 10000).doOnNext(new Consumer() { + Observable.merge(Observable.range(1, 10000).doOnNext(new Consumer() { @Override public void accept(Integer t1) { @@ -122,9 +123,9 @@ public void accept(Integer t1) { @Test public void testWindowUnsubscribeNonOverlappingAsyncSource() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final AtomicInteger count = new AtomicInteger(); - NbpObservable.merge(NbpObservable.range(1, 100000) + Observable.merge(Observable.range(1, 100000) .doOnNext(new Consumer() { @Override @@ -146,9 +147,9 @@ public void accept(Integer t1) { @Test public void testWindowUnsubscribeOverlapping() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final AtomicInteger count = new AtomicInteger(); - NbpObservable.merge(NbpObservable.range(1, 10000).doOnNext(new Consumer() { + Observable.merge(Observable.range(1, 10000).doOnNext(new Consumer() { @Override public void accept(Integer t1) { @@ -165,9 +166,9 @@ public void accept(Integer t1) { @Test public void testWindowUnsubscribeOverlappingAsyncSource() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final AtomicInteger count = new AtomicInteger(); - NbpObservable.merge(NbpObservable.range(1, 100000) + Observable.merge(Observable.range(1, 100000) .doOnNext(new Consumer() { @Override @@ -196,10 +197,10 @@ private List list(String... args) { } - public static NbpObservable hotStream() { - return NbpObservable.create(new NbpOnSubscribe() { + public static Observable hotStream() { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { BooleanDisposable bs = new BooleanDisposable(); s.onSubscribe(bs); while (!bs.isDisposed()) { @@ -222,16 +223,16 @@ public void accept(NbpSubscriber s) { @Test public void testTakeFlatMapCompletes() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final int indicator = 999999999; hotStream() .window(10) .take(2) - .flatMap(new Function, NbpObservable>() { + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable w) { + public Observable apply(Observable w) { return w.startWith(indicator); } }).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowWithStartEndObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWindowWithStartEndObservableTest.java similarity index 69% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowWithStartEndObservableTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWindowWithStartEndObservableTest.java index 80a1af0a69..244bde89ac 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowWithStartEndObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWindowWithStartEndObservableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; @@ -21,12 +21,14 @@ import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.*; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorWindowWithStartEndObservableTest { @@ -44,9 +46,9 @@ public void testObservableBasedOpenerAndCloser() { final List list = new ArrayList(); final List> lists = new ArrayList>(); - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, "one", 10); push(NbpObserver, "two", 60); @@ -57,9 +59,9 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable openings = NbpObservable.create(new NbpOnSubscribe() { + Observable openings = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, new Object(), 50); push(NbpObserver, new Object(), 200); @@ -67,12 +69,12 @@ public void accept(NbpSubscriber NbpObserver) { } }); - Function> closer = new Function>() { + Function> closer = new Function>() { @Override - public NbpObservable apply(Object opening) { - return NbpObservable.create(new NbpOnSubscribe() { + public Observable apply(Object opening) { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, new Object(), 100); complete(NbpObserver, 101); @@ -81,7 +83,7 @@ public void accept(NbpSubscriber NbpObserver) { } }; - NbpObservable> windowed = source.window(openings, closer); + Observable> windowed = source.window(openings, closer); windowed.subscribe(observeWindow(list, lists)); scheduler.advanceTimeTo(500, TimeUnit.MILLISECONDS); @@ -95,9 +97,9 @@ public void testObservableBasedCloser() { final List list = new ArrayList(); final List> lists = new ArrayList>(); - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, "one", 10); push(NbpObserver, "two", 60); @@ -108,13 +110,13 @@ public void accept(NbpSubscriber NbpObserver) { } }); - Supplier> closer = new Supplier>() { + Supplier> closer = new Supplier>() { int calls; @Override - public NbpObservable get() { - return NbpObservable.create(new NbpOnSubscribe() { + public Observable get() { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); int c = calls++; if (c == 0) { @@ -130,7 +132,7 @@ public void accept(NbpSubscriber NbpObserver) { } }; - NbpObservable> windowed = source.window(closer); + Observable> windowed = source.window(closer); windowed.subscribe(observeWindow(list, lists)); scheduler.advanceTimeTo(500, TimeUnit.MILLISECONDS); @@ -148,7 +150,7 @@ private List list(String... args) { return list; } - private void push(final NbpSubscriber NbpObserver, final T value, int delay) { + private void push(final Observer NbpObserver, final T value, int delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -157,7 +159,7 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private void complete(final NbpSubscriber NbpObserver, int delay) { + private void complete(final Observer NbpObserver, int delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -166,11 +168,11 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private Consumer> observeWindow(final List list, final List> lists) { - return new Consumer>() { + private Consumer> observeWindow(final List list, final List> lists) { + return new Consumer>() { @Override - public void accept(NbpObservable stringObservable) { - stringObservable.subscribe(new NbpObserver() { + public void accept(Observable stringObservable) { + stringObservable.subscribe(new DefaultObserver() { @Override public void onComplete() { lists.add(new ArrayList(list)); @@ -193,16 +195,16 @@ public void onNext(String args) { @Test public void testNoUnsubscribeAndNoLeak() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpPublishSubject open = NbpPublishSubject.create(); - final NbpPublishSubject close = NbpPublishSubject.create(); + PublishSubject open = PublishSubject.create(); + final PublishSubject close = PublishSubject.create(); - NbpTestSubscriber> ts = new NbpTestSubscriber>(); + TestObserver> ts = new TestObserver>(); - source.window(open, new Function>() { + source.window(open, new Function>() { @Override - public NbpObservable apply(Integer t) { + public Observable apply(Integer t) { return close; } }).unsafeSubscribe(ts); @@ -230,16 +232,16 @@ public NbpObservable apply(Integer t) { @Test public void testUnsubscribeAll() { - NbpPublishSubject source = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); - NbpPublishSubject open = NbpPublishSubject.create(); - final NbpPublishSubject close = NbpPublishSubject.create(); + PublishSubject open = PublishSubject.create(); + final PublishSubject close = PublishSubject.create(); - NbpTestSubscriber> ts = new NbpTestSubscriber>(); + TestObserver> ts = new TestObserver>(); - source.window(open, new Function>() { + source.window(open, new Function>() { @Override - public NbpObservable apply(Integer t) { + public Observable apply(Integer t) { return close; } }).unsafeSubscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWindowWithTimeTest.java similarity index 80% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowWithTimeTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWindowWithTimeTest.java index 3be973df40..6234e3535e 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWindowWithTimeTest.java @@ -11,9 +11,9 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.util.*; import java.util.concurrent.TimeUnit; @@ -22,11 +22,13 @@ import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.*; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpOperatorWindowWithTimeTest { @@ -45,9 +47,9 @@ public void testTimedAndCount() { final List list = new ArrayList(); final List> lists = new ArrayList>(); - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, "one", 10); push(NbpObserver, "two", 90); @@ -58,7 +60,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable> windowed = source.window(100, TimeUnit.MILLISECONDS, scheduler, 2); + Observable> windowed = source.window(100, TimeUnit.MILLISECONDS, scheduler, 2); windowed.subscribe(observeWindow(list, lists)); scheduler.advanceTimeTo(100, TimeUnit.MILLISECONDS); @@ -79,9 +81,9 @@ public void testTimed() { final List list = new ArrayList(); final List> lists = new ArrayList>(); - NbpObservable source = NbpObservable.create(new NbpOnSubscribe() { + Observable source = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); push(NbpObserver, "one", 98); push(NbpObserver, "two", 99); @@ -92,7 +94,7 @@ public void accept(NbpSubscriber NbpObserver) { } }); - NbpObservable> windowed = source.window(100, TimeUnit.MILLISECONDS, scheduler); + Observable> windowed = source.window(100, TimeUnit.MILLISECONDS, scheduler); windowed.subscribe(observeWindow(list, lists)); scheduler.advanceTimeTo(101, TimeUnit.MILLISECONDS); @@ -112,7 +114,7 @@ private List list(String... args) { return list; } - private void push(final NbpSubscriber NbpObserver, final T value, int delay) { + private void push(final Observer NbpObserver, final T value, int delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -121,7 +123,7 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private void complete(final NbpSubscriber NbpObserver, int delay) { + private void complete(final Observer NbpObserver, int delay) { innerScheduler.schedule(new Runnable() { @Override public void run() { @@ -130,11 +132,11 @@ public void run() { }, delay, TimeUnit.MILLISECONDS); } - private Consumer> observeWindow(final List list, final List> lists) { - return new Consumer>() { + private Consumer> observeWindow(final List list, final List> lists) { + return new Consumer>() { @Override - public void accept(NbpObservable stringObservable) { - stringObservable.subscribe(new NbpObserver() { + public void accept(Observable stringObservable) { + stringObservable.subscribe(new DefaultObserver() { @Override public void onComplete() { lists.add(new ArrayList(list)); @@ -143,7 +145,7 @@ public void onComplete() { @Override public void onError(Throwable e) { - fail(e.getMessage()); + Assert.fail(e.getMessage()); } @Override @@ -156,7 +158,7 @@ public void onNext(T args) { } @Test public void testExactWindowSize() { - NbpObservable> source = NbpObservable.range(1, 10) + Observable> source = Observable.range(1, 10) .window(1, TimeUnit.MINUTES, scheduler, 3); final List list = new ArrayList(); @@ -177,7 +179,7 @@ public void testExactWindowSize() { @Test public void testTakeFlatMapCompletes() { - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); final AtomicInteger wip = new AtomicInteger(); @@ -192,9 +194,9 @@ public void run() { System.out.println("Main done!"); } }) - .flatMap(new Function, NbpObservable>() { + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable w) { + public Observable apply(Observable w) { return w.startWith(indicator) .doOnComplete(new Runnable() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWithLatestFromTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWithLatestFromTest.java similarity index 68% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWithLatestFromTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWithLatestFromTest.java index 9053e9d063..8ba722a13c 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorWithLatestFromTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorWithLatestFromTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -21,11 +21,11 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.BiFunction; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.TestObserver; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorWithLatestFromTest { static final BiFunction COMBINER = new BiFunction() { @@ -42,13 +42,13 @@ public Integer apply(Integer t1, Integer t2) { }; @Test public void testSimple() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); - NbpObservable result = source.withLatestFrom(other, COMBINER); + Observable result = source.withLatestFrom(other, COMBINER); result.subscribe(o); @@ -78,12 +78,12 @@ public void testSimple() { @Test public void testEmptySource() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpObservable result = source.withLatestFrom(other, COMBINER); + Observable result = source.withLatestFrom(other, COMBINER); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); result.subscribe(ts); @@ -104,12 +104,12 @@ public void testEmptySource() { @Test public void testEmptyOther() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpObservable result = source.withLatestFrom(other, COMBINER); + Observable result = source.withLatestFrom(other, COMBINER); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); result.subscribe(ts); @@ -131,12 +131,12 @@ public void testEmptyOther() { @Test public void testUnsubscription() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpObservable result = source.withLatestFrom(other, COMBINER); + Observable result = source.withLatestFrom(other, COMBINER); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); result.subscribe(ts); @@ -158,12 +158,12 @@ public void testUnsubscription() { @Test public void testSourceThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpObservable result = source.withLatestFrom(other, COMBINER); + Observable result = source.withLatestFrom(other, COMBINER); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); result.subscribe(ts); @@ -185,12 +185,12 @@ public void testSourceThrows() { } @Test public void testOtherThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpObservable result = source.withLatestFrom(other, COMBINER); + Observable result = source.withLatestFrom(other, COMBINER); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); result.subscribe(ts); @@ -213,12 +213,12 @@ public void testOtherThrows() { @Test public void testFunctionThrows() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpObservable result = source.withLatestFrom(other, COMBINER_ERROR); + Observable result = source.withLatestFrom(other, COMBINER_ERROR); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); result.subscribe(ts); @@ -239,12 +239,12 @@ public void testFunctionThrows() { @Test public void testNoDownstreamUnsubscribe() { - NbpPublishSubject source = NbpPublishSubject.create(); - NbpPublishSubject other = NbpPublishSubject.create(); + PublishSubject source = PublishSubject.create(); + PublishSubject other = PublishSubject.create(); - NbpObservable result = source.withLatestFrom(other, COMBINER); + Observable result = source.withLatestFrom(other, COMBINER); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); result.unsafeSubscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorZipCompletionTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorZipCompletionTest.java similarity index 87% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorZipCompletionTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorZipCompletionTest.java index 7e201c1512..65dc75f55e 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorZipCompletionTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorZipCompletionTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.mockito.Mockito.*; @@ -19,9 +19,9 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.BiFunction; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; /** * Systematically tests that when zipping an infinite and a finite NbpObservable, @@ -31,11 +31,11 @@ public class NbpOperatorZipCompletionTest { BiFunction concat2Strings; - NbpPublishSubject s1; - NbpPublishSubject s2; - NbpObservable zipped; + PublishSubject s1; + PublishSubject s2; + Observable zipped; - NbpSubscriber NbpObserver; + Observer NbpObserver; InOrder inOrder; @Before @@ -47,9 +47,9 @@ public String apply(String t1, String t2) { } }; - s1 = NbpPublishSubject.create(); - s2 = NbpPublishSubject.create(); - zipped = NbpObservable.zip(s1, s2, concat2Strings); + s1 = PublishSubject.create(); + s2 = PublishSubject.create(); + zipped = Observable.zip(s1, s2, concat2Strings); NbpObserver = TestHelper.mockNbpSubscriber(); inOrder = inOrder(NbpObserver); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorZipIterableTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorZipIterableTest.java similarity index 83% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorZipIterableTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorZipIterableTest.java index 7fef53ded1..d523d003ea 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorZipIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorZipIterableTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; @@ -23,19 +23,20 @@ import org.junit.*; import org.mockito.InOrder; -import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorZipIterableTest { BiFunction concat2Strings; - NbpPublishSubject s1; - NbpPublishSubject s2; - NbpObservable zipped; + PublishSubject s1; + PublishSubject s2; + Observable zipped; - NbpSubscriber NbpObserver; + Observer NbpObserver; InOrder inOrder; @Before @@ -47,9 +48,9 @@ public String apply(String t1, String t2) { } }; - s1 = NbpPublishSubject.create(); - s2 = NbpPublishSubject.create(); - zipped = NbpObservable.zip(s1, s2, concat2Strings); + s1 = PublishSubject.create(); + s2 = PublishSubject.create(); + zipped = Observable.zip(s1, s2, concat2Strings); NbpObserver = TestHelper.mockNbpSubscriber(); inOrder = inOrder(NbpObserver); @@ -76,9 +77,9 @@ public String apply(Object t1, Object t2, Object t3) { @Test public void testZipIterableSameSize() { - NbpPublishSubject r1 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder io = inOrder(o); Iterable r2 = Arrays.asList("1", "2", "3"); @@ -101,9 +102,9 @@ public void testZipIterableSameSize() { @Test public void testZipIterableEmptyFirstSize() { - NbpPublishSubject r1 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder io = inOrder(o); Iterable r2 = Arrays.asList("1", "2", "3"); @@ -121,9 +122,9 @@ public void testZipIterableEmptyFirstSize() { @Test public void testZipIterableEmptySecond() { - NbpPublishSubject r1 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder io = inOrder(o); Iterable r2 = Arrays.asList(); @@ -143,9 +144,9 @@ public void testZipIterableEmptySecond() { @Test public void testZipIterableFirstShorter() { - NbpPublishSubject r1 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder io = inOrder(o); Iterable r2 = Arrays.asList("1", "2", "3"); @@ -166,9 +167,9 @@ public void testZipIterableFirstShorter() { @Test public void testZipIterableSecondShorter() { - NbpPublishSubject r1 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder io = inOrder(o); Iterable r2 = Arrays.asList("1", "2"); @@ -190,9 +191,9 @@ public void testZipIterableSecondShorter() { @Test public void testZipIterableFirstThrows() { - NbpPublishSubject r1 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder io = inOrder(o); Iterable r2 = Arrays.asList("1", "2", "3"); @@ -213,9 +214,9 @@ public void testZipIterableFirstThrows() { @Test public void testZipIterableIteratorThrows() { - NbpPublishSubject r1 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder io = inOrder(o); Iterable r2 = new Iterable() { @@ -240,9 +241,9 @@ public Iterator iterator() { @Test public void testZipIterableHasNextThrows() { - NbpPublishSubject r1 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder io = inOrder(o); Iterable r2 = new Iterable() { @@ -290,9 +291,9 @@ public void remove() { @Test public void testZipIterableNextThrows() { - NbpPublishSubject r1 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); InOrder io = inOrder(o); Iterable r2 = new Iterable() { @@ -350,7 +351,7 @@ public String apply(Integer t1) { @Test public void testTake2() { - NbpObservable o = NbpObservable.just(1, 2, 3, 4, 5); + Observable o = Observable.just(1, 2, 3, 4, 5); Iterable it = Arrays.asList("a", "b", "c", "d", "e"); SquareStr squareStr = new SquareStr(); diff --git a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorZipTest.java b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorZipTest.java similarity index 79% rename from src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorZipTest.java rename to src/test/java/io/reactivex/internal/operators/observable/NbpOperatorZipTest.java index 60b755ea42..0d515d7a0c 100644 --- a/src/test/java/io/reactivex/internal/operators/nbp/NbpOperatorZipTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/NbpOperatorZipTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.internal.operators.nbp; +package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,24 +25,26 @@ import org.mockito.InOrder; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; +import io.reactivex.Optional; import io.reactivex.disposables.BooleanDisposable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.functions.Functions; +import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; -import io.reactivex.Optional; -import io.reactivex.Observable; +import io.reactivex.subjects.PublishSubject; public class NbpOperatorZipTest { BiFunction concat2Strings; - NbpPublishSubject s1; - NbpPublishSubject s2; - NbpObservable zipped; + PublishSubject s1; + PublishSubject s2; + Observable zipped; - NbpSubscriber NbpObserver; + Observer NbpObserver; InOrder inOrder; @Before @@ -54,9 +56,9 @@ public String apply(String t1, String t2) { } }; - s1 = NbpPublishSubject.create(); - s2 = NbpPublishSubject.create(); - zipped = NbpObservable.zip(s1, s2, concat2Strings); + s1 = PublishSubject.create(); + s2 = PublishSubject.create(); + zipped = Observable.zip(s1, s2, concat2Strings); NbpObserver = TestHelper.mockNbpSubscriber(); inOrder = inOrder(NbpObserver); @@ -71,11 +73,11 @@ public void testCollectionSizeDifferentThanFunction() { //Function3 /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); @SuppressWarnings("rawtypes") - Collection ws = java.util.Collections.singleton(NbpObservable.just("one", "two")); - NbpObservable w = NbpObservable.zip(ws, zipr); + Collection ws = java.util.Collections.singleton(Observable.just("one", "two")); + Observable w = Observable.zip(ws, zipr); w.subscribe(NbpObserver); verify(NbpObserver, times(1)).onError(any(Throwable.class)); @@ -85,15 +87,15 @@ public void testCollectionSizeDifferentThanFunction() { @Test public void testStartpingDifferentLengthObservableSequences1() { - NbpSubscriber w = TestHelper.mockNbpSubscriber(); + Observer w = TestHelper.mockNbpSubscriber(); TestObservable w1 = new TestObservable(); TestObservable w2 = new TestObservable(); TestObservable w3 = new TestObservable(); - NbpObservable zipW = NbpObservable.zip( - NbpObservable.create(w1), NbpObservable.create(w2), - NbpObservable.create(w3), getConcat3StringsZipr()); + Observable zipW = Observable.zip( + Observable.create(w1), Observable.create(w2), + Observable.create(w3), getConcat3StringsZipr()); zipW.subscribe(w); /* simulate sending data */ @@ -120,13 +122,13 @@ public void testStartpingDifferentLengthObservableSequences1() { @Test public void testStartpingDifferentLengthObservableSequences2() { - NbpSubscriber w = TestHelper.mockNbpSubscriber(); + Observer w = TestHelper.mockNbpSubscriber(); TestObservable w1 = new TestObservable(); TestObservable w2 = new TestObservable(); TestObservable w3 = new TestObservable(); - NbpObservable zipW = NbpObservable.zip(NbpObservable.create(w1), NbpObservable.create(w2), NbpObservable.create(w3), getConcat3StringsZipr()); + Observable zipW = Observable.zip(Observable.create(w1), Observable.create(w2), Observable.create(w3), getConcat3StringsZipr()); zipW.subscribe(w); /* simulate sending data */ @@ -174,12 +176,12 @@ public String apply(Object t1, Object t2, Object t3) { */ @Test public void testAggregatorSimple() { - NbpPublishSubject r1 = NbpPublishSubject.create(); - NbpPublishSubject r2 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); + PublishSubject r2 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable.zip(r1, r2, zipr2).subscribe(NbpObserver); + Observable.zip(r1, r2, zipr2).subscribe(NbpObserver); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -209,11 +211,11 @@ public void testAggregatorSimple() { public void testAggregatorDifferentSizedResultsWithOnComplete() { /* create the aggregator which will execute the zip function when all Observables provide values */ /* define a NbpSubscriber to receive aggregated events */ - NbpPublishSubject r1 = NbpPublishSubject.create(); - NbpPublishSubject r2 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); + PublishSubject r2 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable.zip(r1, r2, zipr2).subscribe(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + Observable.zip(r1, r2, zipr2).subscribe(NbpObserver); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -236,12 +238,12 @@ public void testAggregatorDifferentSizedResultsWithOnComplete() { @Test public void testAggregateMultipleTypes() { - NbpPublishSubject r1 = NbpPublishSubject.create(); - NbpPublishSubject r2 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); + PublishSubject r2 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable.zip(r1, r2, zipr2).subscribe(NbpObserver); + Observable.zip(r1, r2, zipr2).subscribe(NbpObserver); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -264,13 +266,13 @@ public void testAggregateMultipleTypes() { @Test public void testAggregate3Types() { - NbpPublishSubject r1 = NbpPublishSubject.create(); - NbpPublishSubject r2 = NbpPublishSubject.create(); - NbpPublishSubject> r3 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); + PublishSubject r2 = PublishSubject.create(); + PublishSubject> r3 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable.zip(r1, r2, r3, zipr3).subscribe(NbpObserver); + Observable.zip(r1, r2, r3, zipr3).subscribe(NbpObserver); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -284,12 +286,12 @@ public void testAggregate3Types() { @Test public void testAggregatorsWithDifferentSizesAndTiming() { - NbpPublishSubject r1 = NbpPublishSubject.create(); - NbpPublishSubject r2 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); + PublishSubject r2 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable.zip(r1, r2, zipr2).subscribe(NbpObserver); + Observable.zip(r1, r2, zipr2).subscribe(NbpObserver); /* simulate the Observables pushing data into the aggregator */ r1.onNext("one"); @@ -319,12 +321,12 @@ public void testAggregatorsWithDifferentSizesAndTiming() { @Test public void testAggregatorError() { - NbpPublishSubject r1 = NbpPublishSubject.create(); - NbpPublishSubject r2 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); + PublishSubject r2 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable.zip(r1, r2, zipr2).subscribe(NbpObserver); + Observable.zip(r1, r2, zipr2).subscribe(NbpObserver); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -346,13 +348,13 @@ public void testAggregatorError() { @Test public void testAggregatorUnsubscribe() { - NbpPublishSubject r1 = NbpPublishSubject.create(); - NbpPublishSubject r2 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); + PublishSubject r2 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(NbpObserver); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(NbpObserver); - NbpObservable.zip(r1, r2, zipr2).subscribe(ts); + Observable.zip(r1, r2, zipr2).subscribe(ts); /* simulate the Observables pushing data into the aggregator */ r1.onNext("hello"); @@ -374,12 +376,12 @@ public void testAggregatorUnsubscribe() { @Test public void testAggregatorEarlyCompletion() { - NbpPublishSubject r1 = NbpPublishSubject.create(); - NbpPublishSubject r2 = NbpPublishSubject.create(); + PublishSubject r1 = PublishSubject.create(); + PublishSubject r2 = PublishSubject.create(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable.zip(r1, r2, zipr2).subscribe(NbpObserver); + Observable.zip(r1, r2, zipr2).subscribe(NbpObserver); /* simulate the Observables pushing data into the aggregator */ r1.onNext("one"); @@ -405,9 +407,9 @@ public void testStart2Types() { BiFunction zipr = getConcatStringIntegerZipr(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable w = NbpObservable.zip(NbpObservable.just("one", "two"), NbpObservable.just(2, 3, 4), zipr); + Observable w = Observable.zip(Observable.just("one", "two"), Observable.just(2, 3, 4), zipr); w.subscribe(NbpObserver); verify(NbpObserver, never()).onError(any(Throwable.class)); @@ -422,9 +424,9 @@ public void testStart3Types() { Function3 zipr = getConcatStringIntegerIntArrayZipr(); /* define a NbpSubscriber to receive aggregated events */ - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable w = NbpObservable.zip(NbpObservable.just("one", "two"), NbpObservable.just(2), NbpObservable.just(new int[] { 4, 5, 6 }), zipr); + Observable w = Observable.zip(Observable.just("one", "two"), Observable.just(2), Observable.just(new int[] { 4, 5, 6 }), zipr); w.subscribe(NbpObserver); verify(NbpObserver, never()).onError(any(Throwable.class)); @@ -437,9 +439,9 @@ public void testStart3Types() { public void testOnNextExceptionInvokesOnError() { BiFunction zipr = getDivideZipr(); - NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable w = NbpObservable.zip(NbpObservable.just(10, 20, 30), NbpObservable.just(0, 1, 2), zipr); + Observable w = Observable.zip(Observable.just(10, 20, 30), Observable.just(0, 1, 2), zipr); w.subscribe(NbpObserver); verify(NbpObserver, times(1)).onError(any(Throwable.class)); @@ -447,12 +449,12 @@ public void testOnNextExceptionInvokesOnError() { @Test public void testOnFirstCompletion() { - NbpPublishSubject oA = NbpPublishSubject.create(); - NbpPublishSubject oB = NbpPublishSubject.create(); + PublishSubject oA = PublishSubject.create(); + PublishSubject oB = PublishSubject.create(); - NbpSubscriber obs = TestHelper.mockNbpSubscriber(); + Observer obs = TestHelper.mockNbpSubscriber(); - NbpObservable o = NbpObservable.zip(oA, oB, getConcat2Strings()); + Observable o = Observable.zip(oA, oB, getConcat2Strings()); o.subscribe(obs); InOrder io = inOrder(obs); @@ -497,12 +499,12 @@ public void testOnFirstCompletion() { @Test public void testOnErrorTermination() { - NbpPublishSubject oA = NbpPublishSubject.create(); - NbpPublishSubject oB = NbpPublishSubject.create(); + PublishSubject oA = PublishSubject.create(); + PublishSubject oB = PublishSubject.create(); - NbpSubscriber obs = TestHelper.mockNbpSubscriber(); + Observer obs = TestHelper.mockNbpSubscriber(); - NbpObservable o = NbpObservable.zip(oA, oB, getConcat2Strings()); + Observable o = Observable.zip(oA, oB, getConcat2Strings()); o.subscribe(obs); InOrder io = inOrder(obs); @@ -618,10 +620,10 @@ private static String getStringValue(Object o) { private static class TestObservable implements NbpOnSubscribe { - NbpSubscriber NbpObserver; + Observer NbpObserver; @Override - public void accept(NbpSubscriber NbpObserver) { + public void accept(Observer NbpObserver) { // just store the variable where it can be accessed so we can manually trigger it this.NbpObserver = NbpObserver; NbpObserver.onSubscribe(EmptyDisposable.INSTANCE); @@ -724,15 +726,15 @@ public void testStartWithOnCompletedTwice() { // As "TestHelper.mockNbpSubscriber()" will create an instance in the package "rx", // we need to wrap "TestHelper.mockNbpSubscriber()" with an NbpObserver instance // which is in the package "rx.operators". - final NbpSubscriber NbpObserver = TestHelper.mockNbpSubscriber(); + final Observer NbpObserver = TestHelper.mockNbpSubscriber(); - NbpObservable.zip(NbpObservable.just(1), - NbpObservable.just(1), new BiFunction() { + Observable.zip(Observable.just(1), + Observable.just(1), new BiFunction() { @Override public Integer apply(Integer a, Integer b) { return a + b; } - }).subscribe(new NbpObserver() { + }).subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -759,7 +761,7 @@ public void onNext(Integer args) { @Test public void testStart() { - NbpObservable os = OBSERVABLE_OF_5_INTEGERS + Observable os = OBSERVABLE_OF_5_INTEGERS .zipWith(OBSERVABLE_OF_5_INTEGERS, new BiFunction() { @Override @@ -786,7 +788,7 @@ public void accept(String s) { @Test public void testStartAsync() throws InterruptedException { - NbpObservable os = ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(new CountDownLatch(1)) + Observable os = ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(new CountDownLatch(1)) .zipWith(ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(new CountDownLatch(1)), new BiFunction() { @Override @@ -795,7 +797,7 @@ public String apply(Integer a, Integer b) { } }).take(5); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); os.subscribe(ts); ts.awaitTerminalEvent(); @@ -811,7 +813,7 @@ public String apply(Integer a, Integer b) { public void testStartInfiniteAndFinite() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch infiniteObservable = new CountDownLatch(1); - NbpObservable os = OBSERVABLE_OF_5_INTEGERS + Observable os = OBSERVABLE_OF_5_INTEGERS .zipWith(ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(infiniteObservable), new BiFunction() { @Override @@ -821,7 +823,7 @@ public String apply(Integer a, Integer b) { }); final ArrayList list = new ArrayList(); - os.subscribe(new NbpObserver() { + os.subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -855,9 +857,9 @@ public void onNext(String s) { @Test @Ignore("Null values not allowed") public void testEmitNull() { - NbpObservable oi = NbpObservable.just(1, null, 3); - NbpObservable os = NbpObservable.just("a", "b", null); - NbpObservable o = NbpObservable.zip(oi, os, new BiFunction() { + Observable oi = Observable.just(1, null, 3); + Observable os = Observable.just("a", "b", null); + Observable o = Observable.zip(oi, os, new BiFunction() { @Override public String apply(Integer t1, String t2) { @@ -904,9 +906,9 @@ static String value(Try notification) { @Test public void testEmitMaterializedNotifications() { - NbpObservable>> oi = NbpObservable.just(1, 2, 3).materialize(); - NbpObservable>> os = NbpObservable.just("a", "b", "c").materialize(); - NbpObservable o = NbpObservable.zip(oi, os, new BiFunction>, Try>, String>() { + Observable>> oi = Observable.just(1, 2, 3).materialize(); + Observable>> os = Observable.just("a", "b", "c").materialize(); + Observable o = Observable.zip(oi, os, new BiFunction>, Try>, String>() { @Override public String apply(Try> t1, Try> t2) { @@ -935,7 +937,7 @@ public void accept(String s) { @Test public void testStartEmptyObservables() { - NbpObservable o = NbpObservable.zip(NbpObservable. empty(), NbpObservable. empty(), new BiFunction() { + Observable o = Observable.zip(Observable. empty(), Observable. empty(), new BiFunction() { @Override public String apply(Integer t1, String t2) { @@ -961,9 +963,9 @@ public void accept(String s) { public void testStartEmptyList() { final Object invoked = new Object(); - Collection> observables = Collections.emptyList(); + Collection> observables = Collections.emptyList(); - NbpObservable o = NbpObservable.zip(observables, new Function() { + Observable o = Observable.zip(observables, new Function() { @Override public Object apply(final Object[] args) { assertEquals("No argument should have been passed", 0, args.length); @@ -971,7 +973,7 @@ public Object apply(final Object[] args) { } }); - NbpTestSubscriber ts = new NbpTestSubscriber(); + TestObserver ts = new TestObserver(); o.subscribe(ts); ts.awaitTerminalEvent(200, TimeUnit.MILLISECONDS); ts.assertNoValues(); @@ -985,9 +987,9 @@ public Object apply(final Object[] args) { public void testStartEmptyListBlocking() { final Object invoked = new Object(); - Collection> observables = Collections.emptyList(); + Collection> observables = Collections.emptyList(); - NbpObservable o = NbpObservable.zip(observables, new Function() { + Observable o = Observable.zip(observables, new Function() { @Override public Object apply(final Object[] args) { assertEquals("No argument should have been passed", 0, args.length); @@ -1002,29 +1004,29 @@ public Object apply(final Object[] args) { public void testDownstreamBackpressureRequestsWithFiniteSyncObservables() { AtomicInteger generatedA = new AtomicInteger(); AtomicInteger generatedB = new AtomicInteger(); - NbpObservable o1 = createInfiniteObservable(generatedA).take(Observable.bufferSize() * 2); - NbpObservable o2 = createInfiniteObservable(generatedB).take(Observable.bufferSize() * 2); + Observable o1 = createInfiniteObservable(generatedA).take(Flowable.bufferSize() * 2); + Observable o2 = createInfiniteObservable(generatedB).take(Flowable.bufferSize() * 2); - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.zip(o1, o2, new BiFunction() { + TestObserver ts = new TestObserver(); + Observable.zip(o1, o2, new BiFunction() { @Override public String apply(Integer t1, Integer t2) { return t1 + "-" + t2; } - }).observeOn(Schedulers.computation()).take(Observable.bufferSize() * 2).subscribe(ts); + }).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); System.out.println("Generated => A: " + generatedA.get() + " B: " + generatedB.get()); - assertTrue(generatedA.get() < (Observable.bufferSize() * 3)); - assertTrue(generatedB.get() < (Observable.bufferSize() * 3)); + assertTrue(generatedA.get() < (Flowable.bufferSize() * 3)); + assertTrue(generatedB.get() < (Flowable.bufferSize() * 3)); } - private NbpObservable createInfiniteObservable(final AtomicInteger generated) { - NbpObservable o = NbpObservable.fromIterable(new Iterable() { + private Observable createInfiniteObservable(final AtomicInteger generated) { + Observable o = Observable.fromIterable(new Iterable() { @Override public Iterator iterator() { return new Iterator() { @@ -1048,13 +1050,13 @@ public boolean hasNext() { return o; } - NbpObservable OBSERVABLE_OF_5_INTEGERS = OBSERVABLE_OF_5_INTEGERS(new AtomicInteger()); + Observable OBSERVABLE_OF_5_INTEGERS = OBSERVABLE_OF_5_INTEGERS(new AtomicInteger()); - NbpObservable OBSERVABLE_OF_5_INTEGERS(final AtomicInteger numEmitted) { - return NbpObservable.create(new NbpOnSubscribe() { + Observable OBSERVABLE_OF_5_INTEGERS(final AtomicInteger numEmitted) { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber o) { + public void accept(final Observer o) { BooleanDisposable bs = new BooleanDisposable(); o.onSubscribe(bs); for (int i = 1; i <= 5; i++) { @@ -1071,11 +1073,11 @@ public void accept(final NbpSubscriber o) { }); } - NbpObservable ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(final CountDownLatch latch) { - return NbpObservable.create(new NbpOnSubscribe() { + Observable ASYNC_OBSERVABLE_OF_INFINITE_INTEGERS(final CountDownLatch latch) { + return Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber o) { + public void accept(final Observer o) { final BooleanDisposable bs = new BooleanDisposable(); o.onSubscribe(bs); Thread t = new Thread(new Runnable() { @@ -1104,7 +1106,7 @@ public void run() { @Test(timeout = 30000) public void testIssue1812() { // https://github.com/ReactiveX/RxJava/issues/1812 - NbpObservable zip1 = NbpObservable.zip(NbpObservable.range(0, 1026), NbpObservable.range(0, 1026), + Observable zip1 = Observable.zip(Observable.range(0, 1026), Observable.range(0, 1026), new BiFunction() { @Override @@ -1112,7 +1114,7 @@ public Integer apply(Integer i1, Integer i2) { return i1 + i2; } }); - NbpObservable zip2 = NbpObservable.zip(zip1, NbpObservable.range(0, 1026), + Observable zip2 = Observable.zip(zip1, Observable.range(0, 1026), new BiFunction() { @Override @@ -1130,14 +1132,14 @@ public Integer apply(Integer i1, Integer i2) { @Test(timeout = 10000) public void testZipRace() { long startTime = System.currentTimeMillis(); - NbpObservable src = NbpObservable.just(1).subscribeOn(Schedulers.computation()); + Observable src = Observable.just(1).subscribeOn(Schedulers.computation()); // now try and generate a hang by zipping src with itself repeatedly. A // time limit of 9 seconds ( 1 second less than the test timeout) is // used so that this test will not timeout on slow machines. int i = 0; while (System.currentTimeMillis()-startTime < 9000 && i++ < 100000) { - int value = NbpObservable.zip(src, src, new BiFunction() { + int value = Observable.zip(src, src, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { return t1 + t2 * 10; diff --git a/src/test/java/io/reactivex/internal/subscriptions/AsyncSubscriptionTest.java b/src/test/java/io/reactivex/internal/subscriptions/AsyncSubscriptionTest.java index b90f2d5051..78b748357b 100644 --- a/src/test/java/io/reactivex/internal/subscriptions/AsyncSubscriptionTest.java +++ b/src/test/java/io/reactivex/internal/subscriptions/AsyncSubscriptionTest.java @@ -21,7 +21,6 @@ import org.reactivestreams.Subscription; import io.reactivex.disposables.Disposable; -import io.reactivex.internal.subscriptions.AsyncSubscription; public class AsyncSubscriptionTest { @Test diff --git a/src/test/java/io/reactivex/nbp/NbpObservableTest.java b/src/test/java/io/reactivex/nbp/NbpObservableTest.java deleted file mode 100644 index 626440961e..0000000000 --- a/src/test/java/io/reactivex/nbp/NbpObservableTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright 2016 Netflix, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. - */ - -package io.reactivex.nbp; - -import java.util.*; - -import org.junit.*; - -import io.reactivex.NbpObservable; -import io.reactivex.functions.Function; - -public class NbpObservableTest { - @Test - public void testFlatMap() { - List list = NbpObservable.range(1, 5).flatMap(new Function>() { - @Override - public NbpObservable apply(Integer v) { - return NbpObservable.range(v, 2); - } - }).getList(); - - Assert.assertEquals(Arrays.asList(1, 2, 2, 3, 3, 4, 4, 5, 5, 6), list); - } -} diff --git a/src/test/java/io/reactivex/CombineLatestTests.java b/src/test/java/io/reactivex/observable/NbpCombineLatestTests.java similarity index 86% rename from src/test/java/io/reactivex/CombineLatestTests.java rename to src/test/java/io/reactivex/observable/NbpCombineLatestTests.java index a33d3b6ed9..95c5560d7e 100644 --- a/src/test/java/io/reactivex/CombineLatestTests.java +++ b/src/test/java/io/reactivex/observable/NbpCombineLatestTests.java @@ -13,19 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.reactivex; +package io.reactivex.observable; import static io.reactivex.Observable.combineLatest; -import static org.junit.Assert.assertNull; import org.junit.*; import io.reactivex.Observable; -import io.reactivex.CovarianceTest.*; import io.reactivex.functions.*; +import io.reactivex.observable.NbpCovarianceTest.*; import io.reactivex.subjects.BehaviorSubject; -public class CombineLatestTests { +public class NbpCombineLatestTests { /** * This won't compile if super/extends isn't done correctly on generics */ @@ -68,10 +67,10 @@ public void accept(ExtendedResult t1) { @Test public void testNullEmitting() throws Exception { // FIXME this is no longer allowed - Observable nullObservable = BehaviorSubject.createDefault((Boolean) null); - Observable nonNullObservable = BehaviorSubject.createDefault(true); + Observable nullNbpObservable = BehaviorSubject.createDefault((Boolean) null); + Observable nonNullNbpObservable = BehaviorSubject.createDefault(true); Observable combined = - combineLatest(nullObservable, nonNullObservable, new BiFunction() { + combineLatest(nullNbpObservable, nonNullNbpObservable, new BiFunction() { @Override public Boolean apply(Boolean bool1, Boolean bool2) { return bool1 == null ? null : bool2; @@ -80,7 +79,7 @@ public Boolean apply(Boolean bool1, Boolean bool2) { combined.subscribe(new Consumer() { @Override public void accept(Boolean aBoolean) { - assertNull(aBoolean); + Assert.assertNull(aBoolean); } }); } diff --git a/src/test/java/io/reactivex/ConcatTests.java b/src/test/java/io/reactivex/observable/NbpConcatTests.java similarity index 92% rename from src/test/java/io/reactivex/ConcatTests.java rename to src/test/java/io/reactivex/observable/NbpConcatTests.java index 529e3cb7a9..68c9261e3c 100644 --- a/src/test/java/io/reactivex/ConcatTests.java +++ b/src/test/java/io/reactivex/observable/NbpConcatTests.java @@ -10,19 +10,20 @@ * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.observable; import static org.junit.Assert.assertEquals; import java.util.*; import org.junit.Test; -import org.reactivestreams.*; import io.reactivex.Observable; -import io.reactivex.CovarianceTest.*; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; +import io.reactivex.observable.NbpCovarianceTest.*; -public class ConcatTests { +public class NbpConcatTests { @Test public void testConcatSimple() { @@ -38,7 +39,7 @@ public void testConcatSimple() { } @Test - public void testConcatWithObservableOfObservable() { + public void testConcatWithNbpObservableOfNbpObservable() { Observable o1 = Observable.just("one", "two"); Observable o2 = Observable.just("three", "four"); Observable o3 = Observable.just("five", "six"); @@ -56,7 +57,7 @@ public void testConcatWithObservableOfObservable() { } @Test - public void testConcatWithIterableOfObservable() { + public void testConcatWithIterableOfNbpObservable() { Observable o1 = Observable.just("one", "two"); Observable o2 = Observable.just("three", "four"); Observable o3 = Observable.just("five", "six"); @@ -144,9 +145,9 @@ public void testConcatCovariance4() { Media media = new Media(); HorrorMovie horrorMovie2 = new HorrorMovie(); - Observable o1 = Observable.create(new Publisher() { + Observable o1 = Observable.create(new NbpOnSubscribe() { @Override - public void subscribe(Subscriber o) { + public void accept(Observer o) { o.onNext(horrorMovie1); o.onNext(movie); // o.onNext(new Media()); // correctly doesn't compile diff --git a/src/test/java/io/reactivex/CovarianceTest.java b/src/test/java/io/reactivex/observable/NbpCovarianceTest.java similarity index 74% rename from src/test/java/io/reactivex/CovarianceTest.java rename to src/test/java/io/reactivex/observable/NbpCovarianceTest.java index 3f5ddc4df4..b61f9c6bf1 100644 --- a/src/test/java/io/reactivex/CovarianceTest.java +++ b/src/test/java/io/reactivex/observable/NbpCovarianceTest.java @@ -14,27 +14,26 @@ * limitations under the License. */ -package io.reactivex; +package io.reactivex.observable; import static org.junit.Assert.assertEquals; import java.util.*; import org.junit.Test; -import org.reactivestreams.Publisher; import io.reactivex.Observable; -import io.reactivex.Observable.Transformer; +import io.reactivex.Observable.NbpTransformer; import io.reactivex.functions.*; import io.reactivex.observables.GroupedObservable; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.observers.TestObserver; /** * Test super/extends of generics. * * See https://github.com/Netflix/RxJava/pull/331 */ -public class CovarianceTest { +public class NbpCovarianceTest { /** * This won't compile if super/extends isn't done correctly on generics @@ -43,7 +42,7 @@ public class CovarianceTest { public void testCovarianceOfFrom() { Observable. just(new HorrorMovie()); Observable. fromIterable(new ArrayList()); - // Observable.from(new Movie()); // may not compile + // NbpObservable.from(new Movie()); // may not compile } @Test @@ -67,8 +66,7 @@ public int compare(Media t1, Media t2) { @Test public void testGroupByCompose() { Observable movies = Observable.just(new HorrorMovie(), new ActionMovie(), new Movie()); - TestSubscriber ts = new TestSubscriber(); - + TestObserver ts = new TestObserver(); movies .groupBy(new Function() { @Override @@ -82,29 +80,29 @@ public void accept(GroupedObservable g) { System.out.println(g.key()); } }) - .flatMap(new Function, Publisher>() { + .flatMap(new Function, Observable>() { @Override - public Publisher apply(GroupedObservable g) { + public Observable apply(GroupedObservable g) { return g - .doOnNext(new Consumer() { - @Override - public void accept(Movie v) { - System.out.println(v); - } - }) - .compose(new Transformer() { - @Override - public Publisher apply(Observable m) { - return m.concatWith(Observable.just(new ActionMovie())); - } - } - ) - .map(new Function() { - @Override - public String apply(Object v) { - return v.toString(); - } - }); + .doOnNext(new Consumer() { + @Override + public void accept(Movie pv) { + System.out.println(pv); + } + }) + .compose(new Function, Observable>() { + @Override + public Observable apply(Observable m) { + return m.concatWith(Observable.just(new ActionMovie())); + } + } + ) + .map(new Function() { + @Override + public String apply(Movie v) { + return v.toString(); + } + }); } }) .subscribe(ts); @@ -118,9 +116,9 @@ public String apply(Object v) { @Test public void testCovarianceOfCompose() { Observable movie = Observable.just(new HorrorMovie()); - Observable movie2 = movie.compose(new Transformer() { + Observable movie2 = movie.compose(new Function, Observable>() { @Override - public Publisher apply(Observable t) { + public Observable apply(Observable t) { return Observable.just(new Movie()); } }); @@ -130,9 +128,9 @@ public Publisher apply(Observable t) { @Test public void testCovarianceOfCompose2() { Observable movie = Observable. just(new HorrorMovie()); - Observable movie2 = movie.compose(new Transformer() { + Observable movie2 = movie.compose(new Function, Observable>() { @Override - public Publisher apply(Observable t) { + public Observable apply(Observable t) { return Observable.just(new HorrorMovie()); } }); @@ -142,9 +140,9 @@ public Publisher apply(Observable t) { @Test public void testCovarianceOfCompose3() { Observable movie = Observable.just(new HorrorMovie()); - Observable movie2 = movie.compose(new Transformer() { + Observable movie2 = movie.compose(new Function, Observable>() { @Override - public Publisher apply(Observable t) { + public Observable apply(Observable t) { return Observable.just(new HorrorMovie()).map(new Function() { @Override public HorrorMovie apply(HorrorMovie v) { @@ -160,9 +158,9 @@ public HorrorMovie apply(HorrorMovie v) { @Test public void testCovarianceOfCompose4() { Observable movie = Observable.just(new HorrorMovie()); - Observable movie2 = movie.compose(new Transformer() { + Observable movie2 = movie.compose(new Function, Observable>() { @Override - public Publisher apply(Observable t1) { + public Observable apply(Observable t1) { return t1.map(new Function() { @Override public HorrorMovie apply(HorrorMovie v) { @@ -209,9 +207,9 @@ public Observable apply(List> listOfLists) { } }; - static Transformer, Movie> deltaTransformer = new Transformer, Movie>() { + static NbpTransformer, Movie> deltaTransformer = new NbpTransformer, Movie>() { @Override - public Publisher apply(Observable> movieList) { + public Observable apply(Observable> movieList) { return movieList .startWith(new ArrayList()) .buffer(2, 1) diff --git a/src/test/java/io/reactivex/nbp/NbpErrorHandlingTests.java b/src/test/java/io/reactivex/observable/NbpErrorHandlingTests.java similarity index 89% rename from src/test/java/io/reactivex/nbp/NbpErrorHandlingTests.java rename to src/test/java/io/reactivex/observable/NbpErrorHandlingTests.java index 6a095691ec..20b045462d 100644 --- a/src/test/java/io/reactivex/nbp/NbpErrorHandlingTests.java +++ b/src/test/java/io/reactivex/observable/NbpErrorHandlingTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.observable; import static org.junit.Assert.assertNotNull; @@ -21,7 +21,7 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.observers.DefaultObserver; import io.reactivex.schedulers.Schedulers; public class NbpErrorHandlingTests { @@ -34,8 +34,8 @@ public class NbpErrorHandlingTests { public void testOnNextError() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference caughtError = new AtomicReference(); - NbpObservable o = NbpObservable.interval(50, TimeUnit.MILLISECONDS); - NbpSubscriber observer = new NbpObserver() { + Observable o = Observable.interval(50, TimeUnit.MILLISECONDS); + Observer observer = new DefaultObserver() { @Override public void onComplete() { @@ -70,8 +70,8 @@ public void onNext(Long args) { public void testOnNextErrorAcrossThread() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference caughtError = new AtomicReference(); - NbpObservable o = NbpObservable.interval(50, TimeUnit.MILLISECONDS); - NbpSubscriber observer = new NbpObserver() { + Observable o = Observable.interval(50, TimeUnit.MILLISECONDS); + Observer observer = new DefaultObserver() { @Override public void onComplete() { diff --git a/src/test/java/io/reactivex/nbp/NbpEventStream.java b/src/test/java/io/reactivex/observable/NbpEventStream.java similarity index 88% rename from src/test/java/io/reactivex/nbp/NbpEventStream.java rename to src/test/java/io/reactivex/observable/NbpEventStream.java index 2515f35d33..83c676f0b0 100644 --- a/src/test/java/io/reactivex/nbp/NbpEventStream.java +++ b/src/test/java/io/reactivex/observable/NbpEventStream.java @@ -11,12 +11,12 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.observable; import java.util.*; -import io.reactivex.NbpObservable; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observable; +import io.reactivex.Observer; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; @@ -27,11 +27,11 @@ public final class NbpEventStream { private NbpEventStream() { throw new IllegalStateException("No instances!"); } - public static NbpObservable getEventStream(final String type, final int numInstances) { + public static Observable getEventStream(final String type, final int numInstances) { - return NbpObservable.generate(new Consumer>() { + return Observable.generate(new Consumer>() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { s.onNext(randomEvent(type, numInstances)); try { // slow it down somewhat diff --git a/src/test/java/io/reactivex/nbp/NbpGroupByTests.java b/src/test/java/io/reactivex/observable/NbpGroupByTests.java similarity index 81% rename from src/test/java/io/reactivex/nbp/NbpGroupByTests.java rename to src/test/java/io/reactivex/observable/NbpGroupByTests.java index 57fc9bc838..8b33d407e9 100644 --- a/src/test/java/io/reactivex/nbp/NbpGroupByTests.java +++ b/src/test/java/io/reactivex/observable/NbpGroupByTests.java @@ -11,20 +11,20 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.observable; import org.junit.Test; -import io.reactivex.NbpObservable; +import io.reactivex.Observable; import io.reactivex.functions.*; -import io.reactivex.nbp.NbpEventStream.Event; -import io.reactivex.observables.nbp.NbpGroupedObservable; +import io.reactivex.observable.NbpEventStream.Event; +import io.reactivex.observables.GroupedObservable; public class NbpGroupByTests { @Test public void testTakeUnsubscribesOnGroupBy() { - NbpObservable.merge( + Observable.merge( NbpEventStream.getEventStream("HTTP-ClusterA", 50), NbpEventStream.getEventStream("HTTP-ClusterB", 20) ) @@ -37,9 +37,9 @@ public String apply(Event event) { }) .take(1) .toBlocking() - .forEach(new Consumer>() { + .forEach(new Consumer>() { @Override - public void accept(NbpGroupedObservable v) { + public void accept(GroupedObservable v) { System.out.println(v); v.take(1).subscribe(); // FIXME groups need consumption to a certain degree to cancel upstream } @@ -50,7 +50,7 @@ public void accept(NbpGroupedObservable v) { @Test public void testTakeUnsubscribesOnFlatMapOfGroupBy() { - NbpObservable.merge( + Observable.merge( NbpEventStream.getEventStream("HTTP-ClusterA", 50), NbpEventStream.getEventStream("HTTP-ClusterB", 20) ) @@ -61,9 +61,9 @@ public String apply(Event event) { return event.type; } }) - .flatMap(new Function, NbpObservable>() { + .flatMap(new Function, Observable>() { @Override - public NbpObservable apply(NbpGroupedObservable g) { + public Observable apply(GroupedObservable g) { return g.map(new Function() { @Override public Object apply(Event event) { diff --git a/src/test/java/io/reactivex/MergeTests.java b/src/test/java/io/reactivex/observable/NbpMergeTests.java similarity index 92% rename from src/test/java/io/reactivex/MergeTests.java rename to src/test/java/io/reactivex/observable/NbpMergeTests.java index 4fcc2ec74b..b56bbec707 100644 --- a/src/test/java/io/reactivex/MergeTests.java +++ b/src/test/java/io/reactivex/observable/NbpMergeTests.java @@ -11,20 +11,19 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.observable; import static org.junit.Assert.*; import java.util.List; import org.junit.Test; -import org.reactivestreams.Publisher; import io.reactivex.Observable; -import io.reactivex.CovarianceTest.*; import io.reactivex.functions.Supplier; +import io.reactivex.observable.NbpCovarianceTest.*; -public class MergeTests { +public class NbpMergeTests { /** * This won't compile if super/extends isn't done correctly on generics @@ -76,9 +75,9 @@ public void testMergeCovariance3() { @Test public void testMergeCovariance4() { - Observable o1 = Observable.defer(new Supplier>() { + Observable o1 = Observable.defer(new Supplier>() { @Override - public Publisher get() { + public Observable get() { return Observable.just( new HorrorMovie(), new Movie() diff --git a/src/test/java/io/reactivex/nbp/NbpObservableDoOnTest.java b/src/test/java/io/reactivex/observable/NbpObservableDoOnTest.java similarity index 86% rename from src/test/java/io/reactivex/nbp/NbpObservableDoOnTest.java rename to src/test/java/io/reactivex/observable/NbpObservableDoOnTest.java index 02a5c9bf56..a3348ce012 100644 --- a/src/test/java/io/reactivex/nbp/NbpObservableDoOnTest.java +++ b/src/test/java/io/reactivex/observable/NbpObservableDoOnTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.observable; import static org.junit.Assert.*; @@ -19,7 +19,7 @@ import org.junit.Test; -import io.reactivex.NbpObservable; +import io.reactivex.Observable; import io.reactivex.functions.Consumer; public class NbpObservableDoOnTest { @@ -27,7 +27,7 @@ public class NbpObservableDoOnTest { @Test public void testDoOnEach() { final AtomicReference r = new AtomicReference(); - String output = NbpObservable.just("one").doOnNext(new Consumer() { + String output = Observable.just("one").doOnNext(new Consumer() { @Override public void accept(String v) { r.set(v); @@ -43,7 +43,7 @@ public void testDoOnError() { final AtomicReference r = new AtomicReference(); Throwable t = null; try { - NbpObservable. error(new RuntimeException("an error")) + Observable. error(new RuntimeException("an error")) .doOnError(new Consumer() { @Override public void accept(Throwable v) { @@ -62,7 +62,7 @@ public void accept(Throwable v) { @Test public void testDoOnCompleted() { final AtomicBoolean r = new AtomicBoolean(); - String output = NbpObservable.just("one").doOnComplete(new Runnable() { + String output = Observable.just("one").doOnComplete(new Runnable() { @Override public void run() { r.set(true); diff --git a/src/test/java/io/reactivex/NbpObservableNullTests.java b/src/test/java/io/reactivex/observable/NbpObservableNullTests.java similarity index 80% rename from src/test/java/io/reactivex/NbpObservableNullTests.java rename to src/test/java/io/reactivex/observable/NbpObservableNullTests.java index 0de47ca4d4..9247e2de60 100644 --- a/src/test/java/io/reactivex/NbpObservableNullTests.java +++ b/src/test/java/io/reactivex/observable/NbpObservableNullTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.observable; import java.lang.reflect.*; import java.util.*; @@ -19,20 +19,24 @@ import org.junit.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOperator; +import io.reactivex.Observer; +import io.reactivex.Optional; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; /** * Verifies the operators handle null values properly by emitting/throwing NullPointerExceptions */ public class NbpObservableNullTests { - NbpObservable just1 = NbpObservable.just(1); + Observable just1 = Observable.just(1); //*********************************************************** // Static methods @@ -40,25 +44,25 @@ public class NbpObservableNullTests { @Test(expected = NullPointerException.class) public void ambVarargsNull() { - NbpObservable.amb((NbpObservable[])null); + Observable.amb((Observable[])null); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void ambVarargsOneIsNull() { - NbpObservable.amb(NbpObservable.never(), null).toBlocking().lastOption(); + Observable.amb(Observable.never(), null).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void ambIterableNull() { - NbpObservable.amb((Iterable>)null); + Observable.amb((Iterable>)null); } @Test(expected = NullPointerException.class) public void ambIterableIteratorNull() { - NbpObservable.amb(new Iterable>() { + Observable.amb(new Iterable>() { @Override - public Iterator> iterator() { + public Iterator> iterator() { return null; } }).toBlocking().lastOption(); @@ -67,33 +71,33 @@ public Iterator> iterator() { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void ambIterableOneIsNull() { - NbpObservable.amb(Arrays.asList(NbpObservable.never(), null)).toBlocking().lastOption(); + Observable.amb(Arrays.asList(Observable.never(), null)).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void combineLatestVarargsNull() { - NbpObservable.combineLatest(new Function() { + Observable.combineLatest(new Function() { @Override public Object apply(Object[] v) { return 1; } - }, true, 128, (NbpObservable[])null); + }, true, 128, (Observable[])null); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void combineLatestVarargsOneIsNull() { - NbpObservable.combineLatest(new Function() { + Observable.combineLatest(new Function() { @Override public Object apply(Object[] v) { return 1; } - }, true, 128, NbpObservable.never(), null).toBlocking().lastOption(); + }, true, 128, Observable.never(), null).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void combineLatestIterableNull() { - NbpObservable.combineLatest((Iterable>)null, new Function() { + Observable.combineLatest((Iterable>)null, new Function() { @Override public Object apply(Object[] v) { return 1; @@ -103,9 +107,9 @@ public Object apply(Object[] v) { @Test(expected = NullPointerException.class) public void combineLatestIterableIteratorNull() { - NbpObservable.combineLatest(new Iterable>() { + Observable.combineLatest(new Iterable>() { @Override - public Iterator> iterator() { + public Iterator> iterator() { return null; } }, new Function() { @@ -119,7 +123,7 @@ public Object apply(Object[] v) { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void combineLatestIterableOneIsNull() { - NbpObservable.combineLatest(Arrays.asList(NbpObservable.never(), null), new Function() { + Observable.combineLatest(Arrays.asList(Observable.never(), null), new Function() { @Override public Object apply(Object[] v) { return 1; @@ -130,13 +134,13 @@ public Object apply(Object[] v) { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void combineLatestVarargsFunctionNull() { - NbpObservable.combineLatest(null, true, 128, NbpObservable.never()); + Observable.combineLatest(null, true, 128, Observable.never()); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void combineLatestVarargsFunctionReturnsNull() { - NbpObservable.combineLatest(new Function() { + Observable.combineLatest(new Function() { @Override public Object apply(Object[] v) { return null; @@ -147,13 +151,13 @@ public Object apply(Object[] v) { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void combineLatestIterableFunctionNull() { - NbpObservable.combineLatest(Arrays.asList(just1), null, true, 128); + Observable.combineLatest(Arrays.asList(just1), null, true, 128); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void combineLatestIterableFunctionReturnsNull() { - NbpObservable.combineLatest(Arrays.asList(just1), new Function() { + Observable.combineLatest(Arrays.asList(just1), new Function() { @Override public Object apply(Object[] v) { return null; @@ -163,14 +167,14 @@ public Object apply(Object[] v) { @Test(expected = NullPointerException.class) public void concatIterableNull() { - NbpObservable.concat((Iterable>)null); + Observable.concat((Iterable>)null); } @Test(expected = NullPointerException.class) public void concatIterableIteratorNull() { - NbpObservable.concat(new Iterable>() { + Observable.concat(new Iterable>() { @Override - public Iterator> iterator() { + public Iterator> iterator() { return null; } }).toBlocking().lastOption(); @@ -179,41 +183,41 @@ public Iterator> iterator() { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void concatIterableOneIsNull() { - NbpObservable.concat(Arrays.asList(just1, null)).toBlocking().lastOption(); + Observable.concat(Arrays.asList(just1, null)).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void concatNbpObservableNull() { - NbpObservable.concat((NbpObservable>)null); + Observable.concat((Observable>)null); } @Test(expected = NullPointerException.class) public void concatArrayNull() { - NbpObservable.concatArray((NbpObservable[])null); + Observable.concatArray((Observable[])null); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void concatArrayOneIsNull() { - NbpObservable.concatArray(just1, null).toBlocking().lastOption(); + Observable.concatArray(just1, null).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void createNull() { - NbpObservable.create(null); + Observable.create(null); } @Test(expected = NullPointerException.class) public void deferFunctionNull() { - NbpObservable.defer(null); + Observable.defer(null); } @Test(expected = NullPointerException.class) public void deferFunctionReturnsNull() { - NbpObservable.defer(new Supplier>() { + Observable.defer(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return null; } }).toBlocking().lastOption(); @@ -221,12 +225,12 @@ public NbpObservable get() { @Test(expected = NullPointerException.class) public void errorFunctionNull() { - NbpObservable.error((Supplier)null); + Observable.error((Supplier)null); } @Test(expected = NullPointerException.class) public void errorFunctionReturnsNull() { - NbpObservable.error(new Supplier() { + Observable.error(new Supplier() { @Override public Throwable get() { return null; @@ -236,27 +240,27 @@ public Throwable get() { @Test(expected = NullPointerException.class) public void errorThrowableNull() { - NbpObservable.error((Throwable)null); + Observable.error((Throwable)null); } @Test(expected = NullPointerException.class) public void fromArrayNull() { - NbpObservable.fromArray((Object[])null); + Observable.fromArray((Object[])null); } @Test(expected = NullPointerException.class) public void fromArrayOneIsNull() { - NbpObservable.fromArray(1, null).toBlocking().lastOption(); + Observable.fromArray(1, null).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void fromCallableNull() { - NbpObservable.fromCallable(null); + Observable.fromCallable(null); } @Test(expected = NullPointerException.class) public void fromCallableReturnsNull() { - NbpObservable.fromCallable(new Callable() { + Observable.fromCallable(new Callable() { @Override public Object call() throws Exception { return null; @@ -266,7 +270,7 @@ public Object call() throws Exception { @Test(expected = NullPointerException.class) public void fromFutureNull() { - NbpObservable.fromFuture(null); + Observable.fromFuture(null); } @Test @@ -274,8 +278,8 @@ public void fromFutureReturnsNull() { FutureTask f = new FutureTask(Functions.emptyRunnable(), null); f.run(); - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.fromFuture(f).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.fromFuture(f).subscribe(ts); ts.assertNoValues(); ts.assertNotComplete(); ts.assertError(NullPointerException.class); @@ -283,40 +287,40 @@ public void fromFutureReturnsNull() { @Test(expected = NullPointerException.class) public void fromFutureTimedFutureNull() { - NbpObservable.fromFuture(null, 1, TimeUnit.SECONDS); + Observable.fromFuture(null, 1, TimeUnit.SECONDS); } @Test(expected = NullPointerException.class) public void fromFutureTimedUnitNull() { - NbpObservable.fromFuture(new FutureTask(Functions.emptyRunnable(), null), 1, null); + Observable.fromFuture(new FutureTask(Functions.emptyRunnable(), null), 1, null); } @Test(expected = NullPointerException.class) public void fromFutureTimedSchedulerNull() { - NbpObservable.fromFuture(new FutureTask(Functions.emptyRunnable(), null), 1, TimeUnit.SECONDS, null); + Observable.fromFuture(new FutureTask(Functions.emptyRunnable(), null), 1, TimeUnit.SECONDS, null); } @Test(expected = NullPointerException.class) public void fromFutureTimedReturnsNull() { FutureTask f = new FutureTask(Functions.emptyRunnable(), null); f.run(); - NbpObservable.fromFuture(f, 1, TimeUnit.SECONDS).toBlocking().lastOption(); + Observable.fromFuture(f, 1, TimeUnit.SECONDS).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void fromFutureSchedulerNull() { FutureTask f = new FutureTask(Functions.emptyRunnable(), null); - NbpObservable.fromFuture(f, null); + Observable.fromFuture(f, null); } @Test(expected = NullPointerException.class) public void fromIterableNull() { - NbpObservable.fromIterable(null); + Observable.fromIterable(null); } @Test(expected = NullPointerException.class) public void fromIterableIteratorNull() { - NbpObservable.fromIterable(new Iterable() { + Observable.fromIterable(new Iterable() { @Override public Iterator iterator() { return null; @@ -326,19 +330,19 @@ public Iterator iterator() { @Test(expected = NullPointerException.class) public void fromIterableValueNull() { - NbpObservable.fromIterable(Arrays.asList(1, null)).toBlocking().lastOption(); + Observable.fromIterable(Arrays.asList(1, null)).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void generateConsumerNull() { - NbpObservable.generate(null); + Observable.generate(null); } @Test(expected = NullPointerException.class) public void generateConsumerEmitsNull() { - NbpObservable.generate(new Consumer>() { + Observable.generate(new Consumer>() { @Override - public void accept(NbpSubscriber s) { + public void accept(Observer s) { s.onNext(null); } }).toBlocking().lastOption(); @@ -346,42 +350,42 @@ public void accept(NbpSubscriber s) { @Test(expected = NullPointerException.class) public void generateStateConsumerInitialStateNull() { - BiConsumer> generator = new BiConsumer>() { + BiConsumer> generator = new BiConsumer>() { @Override - public void accept(Integer s, NbpSubscriber o) { + public void accept(Integer s, Observer o) { o.onNext(1); } }; - NbpObservable.generate(null, generator); + Observable.generate(null, generator); } @Test(expected = NullPointerException.class) public void generateStateFunctionInitialStateNull() { - NbpObservable.generate(null, new BiFunction, Object>() { + Observable.generate(null, new BiFunction, Object>() { @Override - public Object apply(Object s, NbpSubscriber o) { o.onNext(1); return s; } + public Object apply(Object s, Observer o) { o.onNext(1); return s; } }); } @Test(expected = NullPointerException.class) public void generateStateConsumerNull() { - NbpObservable.generate(new Supplier() { + Observable.generate(new Supplier() { @Override public Integer get() { return 1; } - }, (BiConsumer>)null); + }, (BiConsumer>)null); } @Test public void generateConsumerStateNullAllowed() { - BiConsumer> generator = new BiConsumer>() { + BiConsumer> generator = new BiConsumer>() { @Override - public void accept(Integer s, NbpSubscriber o) { + public void accept(Integer s, Observer o) { o.onComplete(); } }; - NbpObservable.generate(new Supplier() { + Observable.generate(new Supplier() { @Override public Integer get() { return null; @@ -391,26 +395,26 @@ public Integer get() { @Test public void generateFunctionStateNullAllowed() { - NbpObservable.generate(new Supplier() { + Observable.generate(new Supplier() { @Override public Object get() { return null; } - }, new BiFunction, Object>() { + }, new BiFunction, Object>() { @Override - public Object apply(Object s, NbpSubscriber o) { o.onComplete(); return s; } + public Object apply(Object s, Observer o) { o.onComplete(); return s; } }).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void generateConsumerDisposeNull() { - BiConsumer> generator = new BiConsumer>() { + BiConsumer> generator = new BiConsumer>() { @Override - public void accept(Integer s, NbpSubscriber o) { + public void accept(Integer s, Observer o) { o.onNext(1); } }; - NbpObservable.generate(new Supplier() { + Observable.generate(new Supplier() { @Override public Integer get() { return 1; @@ -420,50 +424,50 @@ public Integer get() { @Test(expected = NullPointerException.class) public void generateFunctionDisposeNull() { - NbpObservable.generate(new Supplier() { + Observable.generate(new Supplier() { @Override public Object get() { return 1; } - }, new BiFunction, Object>() { + }, new BiFunction, Object>() { @Override - public Object apply(Object s, NbpSubscriber o) { o.onNext(1); return s; } + public Object apply(Object s, Observer o) { o.onNext(1); return s; } }, null); } @Test(expected = NullPointerException.class) public void intervalUnitNull() { - NbpObservable.interval(1, null); + Observable.interval(1, null); } public void intervalSchedulerNull() { - NbpObservable.interval(1, TimeUnit.SECONDS, null); + Observable.interval(1, TimeUnit.SECONDS, null); } @Test(expected = NullPointerException.class) public void intervalPeriodUnitNull() { - NbpObservable.interval(1, 1, null); + Observable.interval(1, 1, null); } @Test(expected = NullPointerException.class) public void intervalPeriodSchedulerNull() { - NbpObservable.interval(1, 1, TimeUnit.SECONDS, null); + Observable.interval(1, 1, TimeUnit.SECONDS, null); } @Test(expected = NullPointerException.class) public void intervalRangeUnitNull() { - NbpObservable.intervalRange(1,1, 1, 1, null); + Observable.intervalRange(1,1, 1, 1, null); } @Test(expected = NullPointerException.class) public void intervalRangeSchedulerNull() { - NbpObservable.intervalRange(1, 1, 1, 1, TimeUnit.SECONDS, null); + Observable.intervalRange(1, 1, 1, 1, TimeUnit.SECONDS, null); } @Test public void justNull() throws Exception { @SuppressWarnings("rawtypes") - Class clazz = NbpObservable.class; + Class clazz = Observable.class; for (int argCount = 1; argCount < 10; argCount++) { for (int argNull = 1; argNull <= argCount; argNull++) { Class[] params = new Class[argCount]; @@ -489,14 +493,14 @@ public void justNull() throws Exception { @Test(expected = NullPointerException.class) public void mergeIterableNull() { - NbpObservable.merge(128, 128, (Iterable>)null); + Observable.merge(128, 128, (Iterable>)null); } @Test(expected = NullPointerException.class) public void mergeIterableIteratorNull() { - NbpObservable.merge(128, 128, new Iterable>() { + Observable.merge(128, 128, new Iterable>() { @Override - public Iterator> iterator() { + public Iterator> iterator() { return null; } }).toBlocking().lastOption(); @@ -505,30 +509,30 @@ public Iterator> iterator() { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void mergeIterableOneIsNull() { - NbpObservable.merge(128, 128, Arrays.asList(just1, null)).toBlocking().lastOption(); + Observable.merge(128, 128, Arrays.asList(just1, null)).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void mergeArrayNull() { - NbpObservable.merge(128, 128, (NbpObservable[])null); + Observable.merge(128, 128, (Observable[])null); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void mergeArrayOneIsNull() { - NbpObservable.merge(128, 128, just1, null).toBlocking().lastOption(); + Observable.merge(128, 128, just1, null).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void mergeDelayErrorIterableNull() { - NbpObservable.mergeDelayError(128, 128, (Iterable>)null); + Observable.mergeDelayError(128, 128, (Iterable>)null); } @Test(expected = NullPointerException.class) public void mergeDelayErrorIterableIteratorNull() { - NbpObservable.mergeDelayError(128, 128, new Iterable>() { + Observable.mergeDelayError(128, 128, new Iterable>() { @Override - public Iterator> iterator() { + public Iterator> iterator() { return null; } }).toBlocking().lastOption(); @@ -537,55 +541,55 @@ public Iterator> iterator() { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void mergeDelayErrorIterableOneIsNull() { - NbpObservable.mergeDelayError(128, 128, Arrays.asList(just1, null)).toBlocking().lastOption(); + Observable.mergeDelayError(128, 128, Arrays.asList(just1, null)).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void mergeDelayErrorArrayNull() { - NbpObservable.mergeDelayError(128, 128, (NbpObservable[])null); + Observable.mergeDelayError(128, 128, (Observable[])null); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void mergeDelayErrorArrayOneIsNull() { - NbpObservable.mergeDelayError(128, 128, just1, null).toBlocking().lastOption(); + Observable.mergeDelayError(128, 128, just1, null).toBlocking().lastOption(); } @Test(expected = NullPointerException.class) public void sequenceEqualFirstNull() { - NbpObservable.sequenceEqual(null, just1); + Observable.sequenceEqual(null, just1); } @Test(expected = NullPointerException.class) public void sequenceEqualSecondNull() { - NbpObservable.sequenceEqual(just1, null); + Observable.sequenceEqual(just1, null); } @Test(expected = NullPointerException.class) public void sequenceEqualComparatorNull() { - NbpObservable.sequenceEqual(just1, just1, null); + Observable.sequenceEqual(just1, just1, null); } @Test(expected = NullPointerException.class) public void switchOnNextNull() { - NbpObservable.switchOnNext(null); + Observable.switchOnNext(null); } @Test(expected = NullPointerException.class) public void timerUnitNull() { - NbpObservable.timer(1, null); + Observable.timer(1, null); } @Test(expected = NullPointerException.class) public void timerSchedulerNull() { - NbpObservable.timer(1, TimeUnit.SECONDS, null); + Observable.timer(1, TimeUnit.SECONDS, null); } @Test(expected = NullPointerException.class) public void usingResourceSupplierNull() { - NbpObservable.using(null, new Function>() { + Observable.using(null, new Function>() { @Override - public NbpObservable apply(Object d) { + public Observable apply(Object d) { return just1; } }, new Consumer() { @@ -596,7 +600,7 @@ public void accept(Object d) { } @Test(expected = NullPointerException.class) public void usingNbpObservableSupplierNull() { - NbpObservable.using(new Supplier() { + Observable.using(new Supplier() { @Override public Object get() { return 1; @@ -609,14 +613,14 @@ public void accept(Object d) { } @Test(expected = NullPointerException.class) public void usingNbpObservableSupplierReturnsNull() { - NbpObservable.using(new Supplier() { + Observable.using(new Supplier() { @Override public Object get() { return 1; } - }, new Function>() { + }, new Function>() { @Override - public NbpObservable apply(Object d) { + public Observable apply(Object d) { return null; } }, new Consumer() { @@ -627,14 +631,14 @@ public void accept(Object d) { } @Test(expected = NullPointerException.class) public void usingDisposeNull() { - NbpObservable.using(new Supplier() { + Observable.using(new Supplier() { @Override public Object get() { return 1; } - }, new Function>() { + }, new Function>() { @Override - public NbpObservable apply(Object d) { + public Observable apply(Object d) { return just1; } }, null); @@ -642,7 +646,7 @@ public NbpObservable apply(Object d) { @Test(expected = NullPointerException.class) public void zipIterableNull() { - NbpObservable.zip((Iterable>)null, new Function() { + Observable.zip((Iterable>)null, new Function() { @Override public Object apply(Object[] v) { return 1; @@ -652,9 +656,9 @@ public Object apply(Object[] v) { @Test(expected = NullPointerException.class) public void zipIterableIteratorNull() { - NbpObservable.zip(new Iterable>() { + Observable.zip(new Iterable>() { @Override - public Iterator> iterator() { + public Iterator> iterator() { return null; } }, new Function() { @@ -668,13 +672,13 @@ public Object apply(Object[] v) { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void zipIterableFunctionNull() { - NbpObservable.zip(Arrays.asList(just1, just1), null); + Observable.zip(Arrays.asList(just1, just1), null); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void zipIterableFunctionReturnsNull() { - NbpObservable.zip(Arrays.asList(just1, just1), new Function() { + Observable.zip(Arrays.asList(just1, just1), new Function() { @Override public Object apply(Object[] a) { return null; @@ -684,7 +688,7 @@ public Object apply(Object[] a) { @Test(expected = NullPointerException.class) public void zipNbpObservableNull() { - NbpObservable.zip((NbpObservable>)null, new Function() { + Observable.zip((Observable>)null, new Function() { @Override public Object apply(Object[] a) { return 1; @@ -694,12 +698,12 @@ public Object apply(Object[] a) { @Test(expected = NullPointerException.class) public void zipNbpObservableFunctionNull() { - NbpObservable.zip((NbpObservable.just(just1)), null); + Observable.zip((Observable.just(just1)), null); } @Test(expected = NullPointerException.class) public void zipNbpObservableFunctionReturnsNull() { - NbpObservable.zip((NbpObservable.just(just1)), new Function() { + Observable.zip((Observable.just(just1)), new Function() { @Override public Object apply(Object[] a) { return null; @@ -709,24 +713,24 @@ public Object apply(Object[] a) { @Test(expected = NullPointerException.class) public void zipIterable2Null() { - NbpObservable.zipIterable(new Function() { + Observable.zipIterable(new Function() { @Override public Object apply(Object[] a) { return 1; } - }, true, 128, (Iterable>)null); + }, true, 128, (Iterable>)null); } @Test(expected = NullPointerException.class) public void zipIterable2IteratorNull() { - NbpObservable.zipIterable(new Function() { + Observable.zipIterable(new Function() { @Override public Object apply(Object[] a) { return 1; } - }, true, 128, new Iterable>() { + }, true, 128, new Iterable>() { @Override - public Iterator> iterator() { + public Iterator> iterator() { return null; } }).toBlocking().lastOption(); @@ -735,13 +739,13 @@ public Iterator> iterator() { @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void zipIterable2FunctionNull() { - NbpObservable.zipIterable(null, true, 128, Arrays.asList(just1, just1)); + Observable.zipIterable(null, true, 128, Arrays.asList(just1, just1)); } @SuppressWarnings("unchecked") @Test(expected = NullPointerException.class) public void zipIterable2FunctionReturnsNull() { - NbpObservable.zipIterable(new Function() { + Observable.zipIterable(new Function() { @Override public Object apply(Object[] a) { return null; @@ -810,9 +814,9 @@ public Collection get() { @Test(expected = NullPointerException.class) public void bufferOpenCloseOpenNull() { - just1.buffer(null, new Function>() { + just1.buffer(null, new Function>() { @Override - public NbpObservable apply(Object o) { + public Observable apply(Object o) { return just1; } }); @@ -820,14 +824,14 @@ public NbpObservable apply(Object o) { @Test(expected = NullPointerException.class) public void bufferOpenCloseCloseNull() { - just1.buffer(just1, (Function>)null); + just1.buffer(just1, (Function>)null); } @Test(expected = NullPointerException.class) public void bufferOpenCloseCloseReturnsNull() { - just1.buffer(just1, new Function>() { + just1.buffer(just1, new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return null; } }).toBlocking().run(); @@ -835,7 +839,7 @@ public NbpObservable apply(Integer v) { @Test(expected = NullPointerException.class) public void bufferBoundaryNull() { - just1.buffer((NbpObservable)null); + just1.buffer((Observable)null); } @Test(expected = NullPointerException.class) @@ -855,14 +859,14 @@ public Collection get() { @Test(expected = NullPointerException.class) public void bufferBoundarySupplier2Null() { - just1.buffer((Supplier>)null); + just1.buffer((Supplier>)null); } @Test(expected = NullPointerException.class) public void bufferBoundarySupplier2ReturnsNull() { - just1.buffer(new Supplier>() { + just1.buffer(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return null; } }).toBlocking().run(); @@ -870,9 +874,9 @@ public NbpObservable get() { @Test(expected = NullPointerException.class) public void bufferBoundarySupplier2SupplierNull() { - just1.buffer(new Supplier>() { + just1.buffer(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return just1; } }, null); @@ -880,9 +884,9 @@ public NbpObservable get() { @Test(expected = NullPointerException.class) public void bufferBoundarySupplier2SupplierReturnsNull() { - just1.buffer(new Supplier>() { + just1.buffer(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return just1; } }, new Supplier>() { @@ -954,9 +958,9 @@ public void concatMapNull() { @Test(expected = NullPointerException.class) public void concatMapReturnsNull() { - just1.concatMap(new Function>() { + just1.concatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return null; } }).toBlocking().run(); @@ -1009,9 +1013,9 @@ public void debounceFunctionNull() { @Test(expected = NullPointerException.class) public void debounceFunctionReturnsNull() { - just1.debounce(new Function>() { + just1.debounce(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return null; } }).toBlocking().run(); @@ -1039,9 +1043,9 @@ public void delayWithFunctionNull() { @Test(expected = NullPointerException.class) public void delayWithFunctionReturnsNull() { - just1.delay(new Function>() { + just1.delay(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return null; } }).toBlocking().run(); @@ -1069,19 +1073,19 @@ public void delaySubscriptionTimedSchedulerNull() { @Test(expected = NullPointerException.class) public void delaySubscriptionOtherNull() { - just1.delaySubscription((NbpObservable)null); + just1.delaySubscription((Observable)null); } @Test(expected = NullPointerException.class) public void delaySubscriptionFunctionNull() { - just1.delaySubscription((Supplier>)null); + just1.delaySubscription((Supplier>)null); } @Test(expected = NullPointerException.class) public void delayBothInitialSupplierNull() { - just1.delay(null, new Function>() { + just1.delay(null, new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return just1; } }); @@ -1089,14 +1093,14 @@ public NbpObservable apply(Integer v) { @Test(expected = NullPointerException.class) public void delayBothInitialSupplierReturnsNull() { - just1.delay(new Supplier>() { + just1.delay(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return null; } - }, new Function>() { + }, new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return just1; } }).toBlocking().run(); @@ -1104,9 +1108,9 @@ public NbpObservable apply(Integer v) { @Test(expected = NullPointerException.class) public void delayBothItemSupplierNull() { - just1.delay(new Supplier>() { + just1.delay(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return just1; } }, null); @@ -1114,14 +1118,14 @@ public NbpObservable get() { @Test(expected = NullPointerException.class) public void delayBothItemSupplierReturnsNull() { - just1.delay(new Supplier>() { + just1.delay(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return just1; } - }, new Function>() { + }, new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return null; } }).toBlocking().run(); @@ -1199,7 +1203,7 @@ public void doOnEachSupplierNull() { @Test(expected = NullPointerException.class) public void doOnEachSubscriberNull() { - just1.doOnEach((NbpSubscriber)null); + just1.doOnEach((Observer)null); } @Test(expected = NullPointerException.class) @@ -1262,7 +1266,7 @@ public void endWithIterableOneIsNull() { @Test(expected = NullPointerException.class) public void endWithNbpObservableNull() { - just1.endWith((NbpObservable)null); + just1.endWith((Observable)null); } @Test(expected = NullPointerException.class) @@ -1302,9 +1306,9 @@ public void flatMapNull() { @Test(expected = NullPointerException.class) public void flatMapFunctionReturnsNull() { - just1.flatMap(new Function>() { + just1.flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return null; } }).toBlocking().run(); @@ -1312,14 +1316,14 @@ public NbpObservable apply(Integer v) { @Test(expected = NullPointerException.class) public void flatMapNotificationOnNextNull() { - just1.flatMap(null, new Function>() { + just1.flatMap(null, new Function>() { @Override - public NbpObservable apply(Throwable e) { + public Observable apply(Throwable e) { return just1; } - }, new Supplier>() { + }, new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return just1; } }); @@ -1327,19 +1331,19 @@ public NbpObservable get() { @Test(expected = NullPointerException.class) public void flatMapNotificationOnNextReturnsNull() { - just1.flatMap(new Function>() { + just1.flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return null; } - }, new Function>() { + }, new Function>() { @Override - public NbpObservable apply(Throwable e) { + public Observable apply(Throwable e) { return just1; } - }, new Supplier>() { + }, new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return just1; } }).toBlocking().run(); @@ -1347,14 +1351,14 @@ public NbpObservable get() { @Test(expected = NullPointerException.class) public void flatMapNotificationOnErrorNull() { - just1.flatMap(new Function>() { + just1.flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return just1; } - }, null, new Supplier>() { + }, null, new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return just1; } }); @@ -1362,19 +1366,19 @@ public NbpObservable get() { @Test(expected = NullPointerException.class) public void flatMapNotificationOnErrorReturnsNull() { - NbpObservable.error(new TestException()).flatMap(new Function>() { + Observable.error(new TestException()).flatMap(new Function>() { @Override - public NbpObservable apply(Object v) { + public Observable apply(Object v) { return just1; } - }, new Function>() { + }, new Function>() { @Override - public NbpObservable apply(Throwable e) { + public Observable apply(Throwable e) { return null; } - }, new Supplier>() { + }, new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return just1; } }).toBlocking().run(); @@ -1382,14 +1386,14 @@ public NbpObservable get() { @Test(expected = NullPointerException.class) public void flatMapNotificationOnCompleteNull() { - just1.flatMap(new Function>() { + just1.flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return just1; } - }, new Function>() { + }, new Function>() { @Override - public NbpObservable apply(Throwable e) { + public Observable apply(Throwable e) { return just1; } }, null); @@ -1397,19 +1401,19 @@ public NbpObservable apply(Throwable e) { @Test(expected = NullPointerException.class) public void flatMapNotificationOnCompleteReturnsNull() { - just1.flatMap(new Function>() { + just1.flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return just1; } - }, new Function>() { + }, new Function>() { @Override - public NbpObservable apply(Throwable e) { + public Observable apply(Throwable e) { return just1; } - }, new Supplier>() { + }, new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return null; } }).toBlocking().run(); @@ -1427,9 +1431,9 @@ public Object apply(Integer a, Object b) { @Test(expected = NullPointerException.class) public void flatMapCombinerMapperReturnsNull() { - just1.flatMap(new Function>() { + just1.flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return null; } }, new BiFunction() { @@ -1442,9 +1446,9 @@ public Object apply(Integer a, Object b) { @Test(expected = NullPointerException.class) public void flatMapCombinerCombinerNull() { - just1.flatMap(new Function>() { + just1.flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return just1; } }, null); @@ -1452,9 +1456,9 @@ public NbpObservable apply(Integer v) { @Test(expected = NullPointerException.class) public void flatMapCombinerCombinerReturnsNull() { - just1.flatMap(new Function>() { + just1.flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return just1; } }, new BiFunction() { @@ -1616,7 +1620,7 @@ public void liftNull() { public void liftReturnsNull() { just1.lift(new NbpOperator() { @Override - public NbpSubscriber apply(NbpSubscriber s) { + public Observer apply(Observer s) { return null; } }).toBlocking().run(); @@ -1654,14 +1658,14 @@ public void ofTypeNull() { @Test(expected = NullPointerException.class) public void onErrorResumeNextFunctionNull() { - just1.onErrorResumeNext((Function>)null); + just1.onErrorResumeNext((Function>)null); } @Test(expected = NullPointerException.class) public void onErrorResumeNextFunctionReturnsNull() { - NbpObservable.error(new TestException()).onErrorResumeNext(new Function>() { + Observable.error(new TestException()).onErrorResumeNext(new Function>() { @Override - public NbpObservable apply(Throwable e) { + public Observable apply(Throwable e) { return null; } }).toBlocking().run(); @@ -1669,7 +1673,7 @@ public NbpObservable apply(Throwable e) { @Test(expected = NullPointerException.class) public void onErrorResumeNextNbpObservableNull() { - just1.onErrorResumeNext((NbpObservable)null); + just1.onErrorResumeNext((Observable)null); } @Test(expected = NullPointerException.class) @@ -1684,7 +1688,7 @@ public void onErrorReturnValueNull() { @Test(expected = NullPointerException.class) public void onErrorReturnFunctionReturnsNull() { - NbpObservable.error(new TestException()).onErrorReturn(new Function() { + Observable.error(new TestException()).onErrorReturn(new Function() { @Override public Object apply(Throwable e) { return null; @@ -1704,9 +1708,9 @@ public void publishFunctionNull() { @Test(expected = NullPointerException.class) public void publishFunctionReturnsNull() { - just1.publish(new Function, NbpObservable>() { + just1.publish(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable v) { + public Observable apply(Observable v) { return null; } }).toBlocking().run(); @@ -1719,7 +1723,7 @@ public void reduceFunctionNull() { @Test(expected = NullPointerException.class) public void reduceFunctionReturnsNull() { - NbpObservable.just(1, 1).reduce(new BiFunction() { + Observable.just(1, 1).reduce(new BiFunction() { @Override public Integer apply(Integer a, Integer b) { return null; @@ -1789,9 +1793,9 @@ public void repeatWhenNull() { @Test(expected = NullPointerException.class) public void repeatWhenFunctionReturnsNull() { - just1.repeatWhen(new Function, NbpObservable>() { + just1.repeatWhen(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable v) { + public Observable apply(Observable v) { return null; } }).toBlocking().run(); @@ -1799,14 +1803,14 @@ public NbpObservable apply(NbpObservable v) { @Test(expected = NullPointerException.class) public void replaySelectorNull() { - just1.replay((Function, NbpObservable>)null); + just1.replay((Function, Observable>)null); } @Test(expected = NullPointerException.class) public void replaySelectorReturnsNull() { - just1.replay(new Function, NbpObservable>() { + just1.replay(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable o) { + public Observable apply(Observable o) { return null; } }).toBlocking().run(); @@ -1814,14 +1818,14 @@ public NbpObservable apply(NbpObservable o) { @Test(expected = NullPointerException.class) public void replayBoundedSelectorNull() { - just1.replay((Function, NbpObservable>)null, 1, 1, TimeUnit.SECONDS); + just1.replay((Function, Observable>)null, 1, 1, TimeUnit.SECONDS); } @Test(expected = NullPointerException.class) public void replayBoundedSelectorReturnsNull() { - just1.replay(new Function, NbpObservable>() { + just1.replay(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable v) { + public Observable apply(Observable v) { return null; } }, 1, 1, TimeUnit.SECONDS).toBlocking().run(); @@ -1834,9 +1838,9 @@ public void replaySchedulerNull() { @Test(expected = NullPointerException.class) public void replayBoundedUnitNull() { - just1.replay(new Function, NbpObservable>() { + just1.replay(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable v) { + public Observable apply(Observable v) { return v; } }, 1, 1, null).toBlocking().run(); @@ -1844,9 +1848,9 @@ public NbpObservable apply(NbpObservable v) { @Test(expected = NullPointerException.class) public void replayBoundedSchedulerNull() { - just1.replay(new Function, NbpObservable>() { + just1.replay(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable v) { + public Observable apply(Observable v) { return v; } }, 1, 1, TimeUnit.SECONDS, null).toBlocking().run(); @@ -1859,9 +1863,9 @@ public void replayTimeBoundedSelectorNull() { @Test(expected = NullPointerException.class) public void replayTimeBoundedSelectorReturnsNull() { - just1.replay(new Function, NbpObservable>() { + just1.replay(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable v) { + public Observable apply(Observable v) { return null; } }, 1, TimeUnit.SECONDS, Schedulers.single()).toBlocking().run(); @@ -1869,9 +1873,9 @@ public NbpObservable apply(NbpObservable v) { @Test(expected = NullPointerException.class) public void replaySelectorTimeBoundedUnitNull() { - just1.replay(new Function, NbpObservable>() { + just1.replay(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable v) { + public Observable apply(Observable v) { return v; } }, 1, null, Schedulers.single()); @@ -1879,9 +1883,9 @@ public NbpObservable apply(NbpObservable v) { @Test(expected = NullPointerException.class) public void replaySelectorTimeBoundedSchedulerNull() { - just1.replay(new Function, NbpObservable>() { + just1.replay(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable v) { + public Observable apply(Observable v) { return v; } }, 1, TimeUnit.SECONDS, null); @@ -1934,9 +1938,9 @@ public void retryWhenFunctionNull() { @Test(expected = NullPointerException.class) public void retryWhenFunctionReturnsNull() { - NbpObservable.error(new TestException()).retryWhen(new Function, NbpObservable>() { + Observable.error(new TestException()).retryWhen(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable f) { + public Observable apply(Observable f) { return null; } }).toBlocking().run(); @@ -1974,7 +1978,7 @@ public void scanFunctionNull() { @Test(expected = NullPointerException.class) public void scanFunctionReturnsNull() { - NbpObservable.just(1, 1).scan(new BiFunction() { + Observable.just(1, 1).scan(new BiFunction() { @Override public Integer apply(Integer a, Integer b) { return null; @@ -2119,7 +2123,7 @@ public void startWithSingleNull() { @Test(expected = NullPointerException.class) public void startWithNbpObservableNull() { - just1.startWith((NbpObservable)null); + just1.startWith((Observable)null); } @Test(expected = NullPointerException.class) @@ -2169,7 +2173,7 @@ public void accept(Throwable e) { } @Test(expected = NullPointerException.class) public void subscribeNull() { - just1.subscribe((NbpSubscriber)null); + just1.subscribe((Observer)null); } @Test(expected = NullPointerException.class) @@ -2189,9 +2193,9 @@ public void switchMapNull() { @Test(expected = NullPointerException.class) public void switchMapFunctionReturnsNull() { - just1.switchMap(new Function>() { + just1.switchMap(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return null; } }).toBlocking().run(); @@ -2259,7 +2263,7 @@ public void takeUntilPredicateNull() { @Test(expected = NullPointerException.class) public void takeUntilNbpObservableNull() { - just1.takeUntil((NbpObservable)null); + just1.takeUntil((Observable)null); } @Test(expected = NullPointerException.class) @@ -2314,9 +2318,9 @@ public void timeoutSelectorNull() { @Test(expected = NullPointerException.class) public void timeoutSelectorReturnsNull() { - just1.timeout(new Function>() { + just1.timeout(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return null; } }).toBlocking().run(); @@ -2324,9 +2328,9 @@ public NbpObservable apply(Integer v) { @Test(expected = NullPointerException.class) public void timeoutSelectorOtherNull() { - just1.timeout(new Function>() { + just1.timeout(new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return just1; } }, null); @@ -2349,9 +2353,9 @@ public void timeouSchedulerNull() { @Test(expected = NullPointerException.class) public void timeoutFirstNull() { - just1.timeout((Supplier>)null, new Function>() { + just1.timeout((Supplier>)null, new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return just1; } }); @@ -2359,14 +2363,14 @@ public NbpObservable apply(Integer v) { @Test(expected = NullPointerException.class) public void timeoutFirstReturnsNull() { - just1.timeout(new Supplier>() { + just1.timeout(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return null; } - }, new Function>() { + }, new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return just1; } }).toBlocking().run(); @@ -2374,9 +2378,9 @@ public NbpObservable apply(Integer v) { @Test(expected = NullPointerException.class) public void timeoutFirstItemNull() { - just1.timeout(new Supplier>() { + just1.timeout(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return just1; } }, null); @@ -2384,14 +2388,14 @@ public NbpObservable get() { @Test(expected = NullPointerException.class) public void timeoutFirstItemReturnsNull() { - NbpObservable.just(1, 1).timeout(new Supplier>() { + Observable.just(1, 1).timeout(new Supplier>() { @Override - public NbpObservable get() { - return NbpObservable.never(); + public Observable get() { + return Observable.never(); } - }, new Function>() { + }, new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return null; } }).toBlocking().run(); @@ -2639,14 +2643,14 @@ public void windowSizeTimedSchedulerNull() { @Test(expected = NullPointerException.class) public void windowBoundaryNull() { - just1.window((NbpObservable)null); + just1.window((Observable)null); } @Test(expected = NullPointerException.class) public void windowOpenCloseOpenNull() { - just1.window(null, new Function>() { + just1.window(null, new Function>() { @Override - public NbpObservable apply(Object v) { + public Observable apply(Object v) { return just1; } }); @@ -2659,9 +2663,9 @@ public void windowOpenCloseCloseNull() { @Test(expected = NullPointerException.class) public void windowOpenCloseCloseReturnsNull() { - NbpObservable.never().window(just1, new Function>() { + Observable.never().window(just1, new Function>() { @Override - public NbpObservable apply(Integer v) { + public Observable apply(Integer v) { return null; } }).toBlocking().run(); @@ -2669,14 +2673,14 @@ public NbpObservable apply(Integer v) { @Test(expected = NullPointerException.class) public void windowBoundarySupplierNull() { - just1.window((Supplier>)null); + just1.window((Supplier>)null); } @Test(expected = NullPointerException.class) public void windowBoundarySupplierReturnsNull() { - just1.window(new Supplier>() { + just1.window(new Supplier>() { @Override - public NbpObservable get() { + public Observable get() { return null; } }).toBlocking().run(); @@ -2749,7 +2753,7 @@ public Object apply(Integer a, Object b) { @Test(expected = NullPointerException.class) public void zipWithIterableOneIsNull() { - NbpObservable.just(1, 2).zipWith(Arrays.asList(1, null), new BiFunction() { + Observable.just(1, 2).zipWith(Arrays.asList(1, null), new BiFunction() { @Override public Object apply(Integer a, Integer b) { return 1; @@ -2759,7 +2763,7 @@ public Object apply(Integer a, Integer b) { @Test(expected = NullPointerException.class) public void zipWithNbpObservableNull() { - just1.zipWith((NbpObservable)null, new BiFunction() { + just1.zipWith((Observable)null, new BiFunction() { @Override public Object apply(Integer a, Integer b) { return 1; diff --git a/src/test/java/io/reactivex/NbpObservableTest.java b/src/test/java/io/reactivex/observable/NbpObservableTest.java similarity index 76% rename from src/test/java/io/reactivex/NbpObservableTest.java rename to src/test/java/io/reactivex/observable/NbpObservableTest.java index f0cad9c657..b1c0beda5c 100644 --- a/src/test/java/io/reactivex/NbpObservableTest.java +++ b/src/test/java/io/reactivex/observable/NbpObservableTest.java @@ -11,22 +11,22 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.observable; import java.util.*; import org.junit.*; -import io.reactivex.NbpObservable; +import io.reactivex.Observable; import io.reactivex.functions.Function; public class NbpObservableTest { @Test public void testFlatMap() { - List list = NbpObservable.range(1, 5).flatMap(new Function>() { + List list = Observable.range(1, 5).flatMap(new Function>() { @Override - public NbpObservable apply(Integer v) { - return NbpObservable.range(v, 2); + public Observable apply(Integer v) { + return Observable.range(v, 2); } }).getList(); diff --git a/src/test/java/io/reactivex/nbp/NbpObservableTests.java b/src/test/java/io/reactivex/observable/NbpObservableTests.java similarity index 81% rename from src/test/java/io/reactivex/nbp/NbpObservableTests.java rename to src/test/java/io/reactivex/observable/NbpObservableTests.java index 87889e9a02..23e01f6082 100644 --- a/src/test/java/io/reactivex/nbp/NbpObservableTests.java +++ b/src/test/java/io/reactivex/observable/NbpObservableTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.observable; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -24,19 +24,21 @@ import org.junit.*; import org.mockito.InOrder; -import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.disposables.Disposable; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.disposables.EmptyDisposable; -import io.reactivex.observables.nbp.NbpConnectableObservable; +import io.reactivex.observables.ConnectableObservable; +import io.reactivex.observers.*; import io.reactivex.schedulers.*; -import io.reactivex.subjects.nbp.*; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.subjects.*; public class NbpObservableTests { - NbpSubscriber w; + Observer w; private static final Predicate IS_EVEN = new Predicate() { @Override @@ -53,9 +55,9 @@ public void before() { @Test public void fromArray() { String[] items = new String[] { "one", "two", "three" }; - assertEquals((Long)3L, NbpObservable.fromArray(items).count().toBlocking().single()); - assertEquals("two", NbpObservable.fromArray(items).skip(1).take(1).toBlocking().single()); - assertEquals("three", NbpObservable.fromArray(items).takeLast(1).toBlocking().single()); + assertEquals((Long)3L, Observable.fromArray(items).count().toBlocking().single()); + assertEquals("two", Observable.fromArray(items).skip(1).take(1).toBlocking().single()); + assertEquals("three", Observable.fromArray(items).takeLast(1).toBlocking().single()); } @Test @@ -65,14 +67,14 @@ public void fromIterable() { items.add("two"); items.add("three"); - assertEquals((Long)3L, NbpObservable.fromIterable(items).count().toBlocking().single()); - assertEquals("two", NbpObservable.fromIterable(items).skip(1).take(1).toBlocking().single()); - assertEquals("three", NbpObservable.fromIterable(items).takeLast(1).toBlocking().single()); + assertEquals((Long)3L, Observable.fromIterable(items).count().toBlocking().single()); + assertEquals("two", Observable.fromIterable(items).skip(1).take(1).toBlocking().single()); + assertEquals("three", Observable.fromIterable(items).takeLast(1).toBlocking().single()); } @Test public void fromArityArgs3() { - NbpObservable items = NbpObservable.just("one", "two", "three"); + Observable items = Observable.just("one", "two", "three"); assertEquals((Long)3L, items.count().toBlocking().single()); assertEquals("two", items.skip(1).take(1).toBlocking().single()); @@ -81,7 +83,7 @@ public void fromArityArgs3() { @Test public void fromArityArgs1() { - NbpObservable items = NbpObservable.just("one"); + Observable items = Observable.just("one"); assertEquals((Long)1L, items.count().toBlocking().single()); assertEquals("one", items.takeLast(1).toBlocking().single()); @@ -90,9 +92,9 @@ public void fromArityArgs1() { @Test public void testCreate() { - NbpObservable o = NbpObservable.just("one", "two", "three"); + Observable o = Observable.just("one", "two", "three"); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); o.subscribe(observer); @@ -105,7 +107,7 @@ public void testCreate() { @Test public void testCountAFewItems() { - NbpObservable o = NbpObservable.just("a", "b", "c", "d"); + Observable o = Observable.just("a", "b", "c", "d"); o.count().subscribe(w); @@ -118,7 +120,7 @@ public void testCountAFewItems() { @Test public void testCountZeroItems() { - NbpObservable o = NbpObservable.empty(); + Observable o = Observable.empty(); o.count().subscribe(w); // we should be called only once verify(w, times(1)).onNext(anyLong()); @@ -129,7 +131,7 @@ public void testCountZeroItems() { @Test public void testCountError() { - NbpObservable o = NbpObservable.error(new Supplier() { + Observable o = Observable.error(new Supplier() { @Override public Throwable get() { return new RuntimeException(); @@ -143,7 +145,7 @@ public Throwable get() { } public void testTakeFirstWithPredicateOfSome() { - NbpObservable o = NbpObservable.just(1, 3, 5, 4, 6, 3); + Observable o = Observable.just(1, 3, 5, 4, 6, 3); o.takeFirst(IS_EVEN).subscribe(w); verify(w, times(1)).onNext(anyInt()); verify(w).onNext(4); @@ -153,7 +155,7 @@ public void testTakeFirstWithPredicateOfSome() { @Test public void testTakeFirstWithPredicateOfNoneMatchingThePredicate() { - NbpObservable o = NbpObservable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); + Observable o = Observable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); o.takeFirst(IS_EVEN).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, times(1)).onComplete(); @@ -162,7 +164,7 @@ public void testTakeFirstWithPredicateOfNoneMatchingThePredicate() { @Test public void testTakeFirstOfSome() { - NbpObservable o = NbpObservable.just(1, 2, 3); + Observable o = Observable.just(1, 2, 3); o.take(1).subscribe(w); verify(w, times(1)).onNext(anyInt()); verify(w).onNext(1); @@ -172,7 +174,7 @@ public void testTakeFirstOfSome() { @Test public void testTakeFirstOfNone() { - NbpObservable o = NbpObservable.empty(); + Observable o = Observable.empty(); o.take(1).subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, times(1)).onComplete(); @@ -181,7 +183,7 @@ public void testTakeFirstOfNone() { @Test public void testFirstOfNone() { - NbpObservable o = NbpObservable.empty(); + Observable o = Observable.empty(); o.first().subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onComplete(); @@ -190,7 +192,7 @@ public void testFirstOfNone() { @Test public void testFirstWithPredicateOfNoneMatchingThePredicate() { - NbpObservable o = NbpObservable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); + Observable o = Observable.just(1, 3, 5, 7, 9, 7, 5, 3, 1); o.filter(IS_EVEN).first().subscribe(w); verify(w, never()).onNext(anyInt()); verify(w, never()).onComplete(); @@ -199,7 +201,7 @@ public void testFirstWithPredicateOfNoneMatchingThePredicate() { @Test public void testReduce() { - NbpObservable o = NbpObservable.just(1, 2, 3, 4); + Observable o = Observable.just(1, 2, 3, 4); o.reduce(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -217,7 +219,7 @@ public Integer apply(Integer t1, Integer t2) { */ @Test(expected = NoSuchElementException.class) public void testReduceWithEmptyNbpObservable() { - NbpObservable o = NbpObservable.range(1, 0); + Observable o = Observable.range(1, 0); o.reduce(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -241,7 +243,7 @@ public void accept(Integer t1) { */ @Test public void testReduceWithEmptyNbpObservableAndSeed() { - NbpObservable o = NbpObservable.range(1, 0); + Observable o = Observable.range(1, 0); int value = o.reduce(1, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -255,7 +257,7 @@ public Integer apply(Integer t1, Integer t2) { @Test public void testReduceWithInitialValue() { - NbpObservable o = NbpObservable.just(1, 2, 3, 4); + Observable o = Observable.just(1, 2, 3, 4); o.reduce(50, new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -271,12 +273,12 @@ public Integer apply(Integer t1, Integer t2) { @Ignore // FIXME throwing is not allowed from the create?! @Test public void testOnSubscribeFails() { - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); final RuntimeException re = new RuntimeException("bad impl"); - NbpObservable o = NbpObservable.create(new NbpOnSubscribe() { + Observable o = Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber s) { throw re; } + public void accept(Observer s) { throw re; } }); o.subscribe(observer); @@ -287,10 +289,10 @@ public void testOnSubscribeFails() { @Test public void testMaterializeDematerializeChaining() { - NbpObservable obs = NbpObservable.just(1); - NbpObservable chained = obs.materialize().dematerialize(); + Observable obs = Observable.just(1); + Observable chained = obs.materialize().dematerialize(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); chained.subscribe(observer); @@ -314,9 +316,9 @@ public void testCustomNbpObservableWithErrorInObserverAsynchronous() throws Inte final AtomicReference error = new AtomicReference(); // FIXME custom built??? - NbpObservable.just("1", "2", "three", "4") + Observable.just("1", "2", "three", "4") .subscribeOn(Schedulers.newThread()) - .safeSubscribe(new NbpObserver() { + .safeSubscribe(new DefaultObserver() { @Override public void onComplete() { System.out.println("completed"); @@ -362,8 +364,8 @@ public void testCustomNbpObservableWithErrorInObserverSynchronous() { final AtomicReference error = new AtomicReference(); // FIXME custom built??? - NbpObservable.just("1", "2", "three", "4") - .safeSubscribe(new NbpObserver() { + Observable.just("1", "2", "three", "4") + .safeSubscribe(new DefaultObserver() { @Override public void onComplete() { @@ -404,13 +406,13 @@ public void testCustomNbpObservableWithErrorInNbpObservableSynchronous() { final AtomicInteger count = new AtomicInteger(); final AtomicReference error = new AtomicReference(); // FIXME custom built??? - NbpObservable.just("1", "2").concatWith(NbpObservable.error(new Supplier() { + Observable.just("1", "2").concatWith(Observable.error(new Supplier() { @Override public Throwable get() { return new NumberFormatException(); } })) - .subscribe(new NbpObserver() { + .subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -441,9 +443,9 @@ public void onNext(String v) { @Test public void testPublishLast() throws InterruptedException { final AtomicInteger count = new AtomicInteger(); - NbpConnectableObservable connectable = NbpObservable.create(new NbpOnSubscribe() { + ConnectableObservable connectable = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber observer) { + public void accept(final Observer observer) { observer.onSubscribe(EmptyDisposable.INSTANCE); count.incrementAndGet(); new Thread(new Runnable() { @@ -479,9 +481,9 @@ public void accept(String value) { @Test public void testReplay() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - NbpConnectableObservable o = NbpObservable.create(new NbpOnSubscribe() { + ConnectableObservable o = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber observer) { + public void accept(final Observer observer) { observer.onSubscribe(EmptyDisposable.INSTANCE); new Thread(new Runnable() { @@ -532,9 +534,9 @@ public void accept(String v) { @Test public void testCache() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - NbpObservable o = NbpObservable.create(new NbpOnSubscribe() { + Observable o = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber observer) { + public void accept(final Observer observer) { observer.onSubscribe(EmptyDisposable.INSTANCE); new Thread(new Runnable() { @Override @@ -577,9 +579,9 @@ public void accept(String v) { @Test public void testCacheWithCapacity() throws InterruptedException { final AtomicInteger counter = new AtomicInteger(); - NbpObservable o = NbpObservable.create(new NbpOnSubscribe() { + Observable o = Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber observer) { + public void accept(final Observer observer) { observer.onSubscribe(EmptyDisposable.INSTANCE); new Thread(new Runnable() { @Override @@ -632,7 +634,7 @@ public void accept(String v) { @Ignore("Subscribers can't throw") public void testErrorThrownWithoutErrorHandlerSynchronous() { try { - NbpObservable.error(new RuntimeException("failure")) + Observable.error(new RuntimeException("failure")) .subscribe(); fail("expected exception"); } catch (Throwable e) { @@ -656,9 +658,9 @@ public void testErrorThrownWithoutErrorHandlerSynchronous() { public void testErrorThrownWithoutErrorHandlerAsynchronous() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference exception = new AtomicReference(); - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(final NbpSubscriber observer) { + public void accept(final Observer observer) { new Thread(new Runnable() { @Override public void run() { @@ -683,8 +685,8 @@ public void run() { public void testTakeWithErrorInObserver() { final AtomicInteger count = new AtomicInteger(); final AtomicReference error = new AtomicReference(); - NbpObservable.just("1", "2", "three", "4").take(3) - .safeSubscribe(new NbpObserver() { + Observable.just("1", "2", "three", "4").take(3) + .safeSubscribe(new DefaultObserver() { @Override public void onComplete() { @@ -716,9 +718,9 @@ public void onNext(String v) { @Test public void testOfType() { - NbpObservable o = NbpObservable.just(1, "abc", false, 2L).ofType(String.class); + Observable o = Observable.just(1, "abc", false, 2L).ofType(String.class); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); o.subscribe(observer); @@ -739,9 +741,9 @@ public void testOfTypeWithPolymorphism() { l2.add(2); @SuppressWarnings("rawtypes") - NbpObservable o = NbpObservable. just(l1, l2, "123").ofType(List.class); + Observable o = Observable. just(l1, l2, "123").ofType(List.class); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); o.subscribe(observer); @@ -755,9 +757,9 @@ public void testOfTypeWithPolymorphism() { @Test public void testContains() { - NbpObservable o = NbpObservable.just("a", "b", "c").contains("b"); // FIXME nulls not allowed, changed to "c" + Observable o = Observable.just("a", "b", "c").contains("b"); // FIXME nulls not allowed, changed to "c" - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); o.subscribe(observer); @@ -770,9 +772,9 @@ public void testContains() { @Test public void testContainsWithInexistence() { - NbpObservable o = NbpObservable.just("a", "b").contains("c"); // FIXME null values are not allowed, removed + Observable o = Observable.just("a", "b").contains("c"); // FIXME null values are not allowed, removed - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); o.subscribe(observer); @@ -786,9 +788,9 @@ public void testContainsWithInexistence() { @Test @Ignore("null values are not allowed") public void testContainsWithNull() { - NbpObservable o = NbpObservable.just("a", "b", null).contains(null); + Observable o = Observable.just("a", "b", null).contains(null); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); o.subscribe(observer); @@ -801,9 +803,9 @@ public void testContainsWithNull() { @Test public void testContainsWithEmptyNbpObservable() { - NbpObservable o = NbpObservable. empty().contains("a"); + Observable o = Observable. empty().contains("a"); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); o.subscribe(observer); @@ -816,9 +818,9 @@ public void testContainsWithEmptyNbpObservable() { @Test public void testIgnoreElements() { - NbpObservable o = NbpObservable.just(1, 2, 3).ignoreElements(); + Observable o = Observable.just(1, 2, 3).ignoreElements(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); o.subscribe(observer); @@ -830,9 +832,9 @@ public void testIgnoreElements() { @Test public void testJustWithScheduler() { TestScheduler scheduler = new TestScheduler(); - NbpObservable o = NbpObservable.fromArray(1, 2).subscribeOn(scheduler); + Observable o = Observable.fromArray(1, 2).subscribeOn(scheduler); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); o.subscribe(observer); @@ -848,9 +850,9 @@ public void testJustWithScheduler() { @Test public void testStartWithWithScheduler() { TestScheduler scheduler = new TestScheduler(); - NbpObservable o = NbpObservable.just(3, 4).startWith(Arrays.asList(1, 2)).subscribeOn(scheduler); + Observable o = Observable.just(3, 4).startWith(Arrays.asList(1, 2)).subscribeOn(scheduler); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); o.subscribe(observer); @@ -868,9 +870,9 @@ public void testStartWithWithScheduler() { @Test public void testRangeWithScheduler() { TestScheduler scheduler = new TestScheduler(); - NbpObservable o = NbpObservable.range(3, 4).subscribeOn(scheduler); + Observable o = Observable.range(3, 4).subscribeOn(scheduler); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); o.subscribe(observer); @@ -887,7 +889,7 @@ public void testRangeWithScheduler() { @Test public void testCollectToList() { - NbpObservable> o = NbpObservable.just(1, 2, 3) + Observable> o = Observable.just(1, 2, 3) .collect(new Supplier>() { @Override public List get() { @@ -918,7 +920,7 @@ public void accept(List list, Integer v) { @Test public void testCollectToString() { - String value = NbpObservable.just(1, 2, 3).collect(new Supplier() { + String value = Observable.just(1, 2, 3).collect(new Supplier() { @Override public StringBuilder get() { return new StringBuilder(); @@ -939,22 +941,22 @@ public void accept(StringBuilder sb, Integer v) { @Test public void testMergeWith() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.just(1).mergeWith(NbpObservable.just(2)).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.just(1).mergeWith(Observable.just(2)).subscribe(ts); ts.assertValues(1, 2); } @Test public void testConcatWith() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.just(1).concatWith(NbpObservable.just(2)).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.just(1).concatWith(Observable.just(2)).subscribe(ts); ts.assertValues(1, 2); } @Test public void testAmbWith() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.just(1).ambWith(NbpObservable.just(2)).subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.just(1).ambWith(Observable.just(2)).subscribe(ts); ts.assertValue(1); } // FIXME Subscribers can't throw @@ -974,7 +976,7 @@ public void testTakeWhileToList() { final int expectedCount = 3; final AtomicInteger count = new AtomicInteger(); for (int i = 0;i < expectedCount; i++) { - NbpObservable + Observable .just(Boolean.TRUE, Boolean.FALSE) .takeWhile(new Predicate() { @Override @@ -996,10 +998,10 @@ public void accept(List booleans) { @Test public void testCompose() { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.just(1, 2, 3).compose(new Function, NbpObservable>() { + TestObserver ts = new TestObserver(); + Observable.just(1, 2, 3).compose(new Function, Observable>() { @Override - public NbpObservable apply(NbpObservable t1) { + public Observable apply(Observable t1) { return t1.map(new Function() { @Override public String apply(Integer v) { @@ -1016,9 +1018,9 @@ public String apply(Integer v) { @Test public void testErrorThrownIssue1685() { - NbpSubject subject = NbpReplaySubject.create(); + Subject subject = ReplaySubject.create(); - NbpObservable.error(new RuntimeException("oops")) + Observable.error(new RuntimeException("oops")) .materialize() .delay(1, TimeUnit.SECONDS) .dematerialize() @@ -1032,12 +1034,12 @@ public void testErrorThrownIssue1685() { @Test public void testEmptyIdentity() { - assertEquals(NbpObservable.empty(), NbpObservable.empty()); + assertEquals(Observable.empty(), Observable.empty()); } @Test public void testEmptyIsEmpty() { - NbpObservable.empty().subscribe(w); + Observable.empty().subscribe(w); verify(w).onComplete(); verify(w, never()).onNext(any(Integer.class)); @@ -1068,18 +1070,18 @@ public void testEmptyIsEmpty() { @Test(expected = NullPointerException.class) public void testForEachWithNull() { - NbpObservable.error(new Exception("boo")) + Observable.error(new Exception("boo")) // .forEach(null); } @Test public void testExtend() { - final NbpTestSubscriber subscriber = new NbpTestSubscriber(); + final TestObserver subscriber = new TestObserver(); final Object value = new Object(); - NbpObservable.just(value).to(new Function, Object>() { + Observable.just(value).to(new Function, Object>() { @Override - public Object apply(NbpObservable onSubscribe) { + public Object apply(Observable onSubscribe) { onSubscribe.subscribe(subscriber); subscriber.assertNoErrors(); subscriber.assertComplete(); diff --git a/src/test/java/io/reactivex/nbp/NbpObservableWindowTests.java b/src/test/java/io/reactivex/observable/NbpObservableWindowTests.java similarity index 81% rename from src/test/java/io/reactivex/nbp/NbpObservableWindowTests.java rename to src/test/java/io/reactivex/observable/NbpObservableWindowTests.java index cc6f09e9ba..fd9aeddf5c 100644 --- a/src/test/java/io/reactivex/nbp/NbpObservableWindowTests.java +++ b/src/test/java/io/reactivex/observable/NbpObservableWindowTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.observable; import static org.junit.Assert.*; @@ -19,7 +19,7 @@ import org.junit.Test; -import io.reactivex.NbpObservable; +import io.reactivex.Observable; import io.reactivex.functions.*; public class NbpObservableWindowTests { @@ -28,12 +28,12 @@ public class NbpObservableWindowTests { public void testWindow() { final ArrayList> lists = new ArrayList>(); - NbpObservable.concat( - NbpObservable.just(1, 2, 3, 4, 5, 6) + Observable.concat( + Observable.just(1, 2, 3, 4, 5, 6) .window(3) - .map(new Function, NbpObservable>>() { + .map(new Function, Observable>>() { @Override - public NbpObservable> apply(NbpObservable xs) { + public Observable> apply(Observable xs) { return xs.toList(); } }) diff --git a/src/test/java/io/reactivex/nbp/NbpReduceTests.java b/src/test/java/io/reactivex/observable/NbpReduceTests.java similarity index 75% rename from src/test/java/io/reactivex/nbp/NbpReduceTests.java rename to src/test/java/io/reactivex/observable/NbpReduceTests.java index b467e4e635..54bc39ce65 100644 --- a/src/test/java/io/reactivex/nbp/NbpReduceTests.java +++ b/src/test/java/io/reactivex/observable/NbpReduceTests.java @@ -11,21 +11,21 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.observable; import static org.junit.Assert.assertEquals; import org.junit.Test; -import io.reactivex.NbpObservable; +import io.reactivex.Observable; import io.reactivex.functions.BiFunction; -import io.reactivex.nbp.NbpCovarianceTest.*; +import io.reactivex.observable.NbpCovarianceTest.*; public class NbpReduceTests { @Test public void reduceInts() { - NbpObservable o = NbpObservable.just(1, 2, 3); + Observable o = Observable.just(1, 2, 3); int value = o.reduce(new BiFunction() { @Override public Integer apply(Integer t1, Integer t2) { @@ -39,16 +39,16 @@ public Integer apply(Integer t1, Integer t2) { @SuppressWarnings("unused") @Test public void reduceWithObjects() { - NbpObservable horrorMovies = NbpObservable. just(new HorrorMovie()); + Observable horrorMovies = Observable. just(new HorrorMovie()); - NbpObservable reduceResult = horrorMovies.scan(new BiFunction() { + Observable reduceResult = horrorMovies.scan(new BiFunction() { @Override public Movie apply(Movie t1, Movie t2) { return t2; } }).takeLast(1); - NbpObservable reduceResult2 = horrorMovies.reduce(new BiFunction() { + Observable reduceResult2 = horrorMovies.reduce(new BiFunction() { @Override public Movie apply(Movie t1, Movie t2) { return t2; @@ -64,9 +64,9 @@ public Movie apply(Movie t1, Movie t2) { @SuppressWarnings("unused") @Test public void reduceWithCovariantObjects() { - NbpObservable horrorMovies = NbpObservable. just(new HorrorMovie()); + Observable horrorMovies = Observable. just(new HorrorMovie()); - NbpObservable reduceResult2 = horrorMovies.reduce(new BiFunction() { + Observable reduceResult2 = horrorMovies.reduce(new BiFunction() { @Override public Movie apply(Movie t1, Movie t2) { return t2; @@ -82,14 +82,14 @@ public Movie apply(Movie t1, Movie t2) { @Test public void reduceCovariance() { // must type it to - NbpObservable horrorMovies = NbpObservable. just(new HorrorMovie()); + Observable horrorMovies = Observable. just(new HorrorMovie()); libraryFunctionActingOnMovieNbpObservables(horrorMovies); } /* * This accepts instead of since `reduce` can't handle covariants */ - public void libraryFunctionActingOnMovieNbpObservables(NbpObservable obs) { + public void libraryFunctionActingOnMovieNbpObservables(Observable obs) { obs.reduce(new BiFunction() { @Override diff --git a/src/test/java/io/reactivex/nbp/NbpScanTests.java b/src/test/java/io/reactivex/observable/NbpScanTests.java similarity index 94% rename from src/test/java/io/reactivex/nbp/NbpScanTests.java rename to src/test/java/io/reactivex/observable/NbpScanTests.java index 5192061b28..a4ecfd8af9 100644 --- a/src/test/java/io/reactivex/nbp/NbpScanTests.java +++ b/src/test/java/io/reactivex/observable/NbpScanTests.java @@ -11,14 +11,14 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.observable; import java.util.HashMap; import org.junit.Test; import io.reactivex.functions.*; -import io.reactivex.nbp.NbpEventStream.Event; +import io.reactivex.observable.NbpEventStream.Event; public class NbpScanTests { diff --git a/src/test/java/io/reactivex/nbp/NbpStartWithTests.java b/src/test/java/io/reactivex/observable/NbpStartWithTests.java similarity index 82% rename from src/test/java/io/reactivex/nbp/NbpStartWithTests.java rename to src/test/java/io/reactivex/observable/NbpStartWithTests.java index 8bdd2e3a1a..f068e1c2ee 100644 --- a/src/test/java/io/reactivex/nbp/NbpStartWithTests.java +++ b/src/test/java/io/reactivex/observable/NbpStartWithTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.observable; import static org.junit.Assert.assertEquals; @@ -19,13 +19,13 @@ import org.junit.Test; -import io.reactivex.NbpObservable; +import io.reactivex.Observable; public class NbpStartWithTests { @Test public void startWith1() { - List values = NbpObservable.just("one", "two") + List values = Observable.just("one", "two") .startWithArray("zero").toList().toBlocking().single(); assertEquals("zero", values.get(0)); @@ -37,7 +37,7 @@ public void startWithIterable() { List li = new ArrayList(); li.add("alpha"); li.add("beta"); - List values = NbpObservable.just("one", "two").startWith(li).toList().toBlocking().single(); + List values = Observable.just("one", "two").startWith(li).toList().toBlocking().single(); assertEquals("alpha", values.get(0)); assertEquals("beta", values.get(1)); @@ -50,8 +50,8 @@ public void startWithObservable() { List li = new ArrayList(); li.add("alpha"); li.add("beta"); - List values = NbpObservable.just("one", "two") - .startWith(NbpObservable.fromIterable(li)) + List values = Observable.just("one", "two") + .startWith(Observable.fromIterable(li)) .toList() .toBlocking() .single(); diff --git a/src/test/java/io/reactivex/nbp/NbpSubscriberTest.java b/src/test/java/io/reactivex/observable/NbpSubscriberTest.java similarity index 83% rename from src/test/java/io/reactivex/nbp/NbpSubscriberTest.java rename to src/test/java/io/reactivex/observable/NbpSubscriberTest.java index 024aaa38c6..696d8de35a 100644 --- a/src/test/java/io/reactivex/nbp/NbpSubscriberTest.java +++ b/src/test/java/io/reactivex/observable/NbpSubscriberTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.observable; import static org.junit.Assert.assertEquals; @@ -20,13 +20,14 @@ import org.junit.Test; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable.NbpOperator; +import io.reactivex.observers.DefaultObserver; public class NbpSubscriberTest { @Test public void testOnStartCalledOnceViaSubscribe() { final AtomicInteger c = new AtomicInteger(); - NbpObservable.just(1, 2, 3, 4).take(2).subscribe(new NbpObserver() { + Observable.just(1, 2, 3, 4).take(2).subscribe(new DefaultObserver() { @Override public void onStart() { @@ -55,7 +56,7 @@ public void onNext(Integer t) { @Test public void testOnStartCalledOnceViaUnsafeSubscribe() { final AtomicInteger c = new AtomicInteger(); - NbpObservable.just(1, 2, 3, 4).take(2).unsafeSubscribe(new NbpObserver() { + Observable.just(1, 2, 3, 4).take(2).unsafeSubscribe(new DefaultObserver() { @Override public void onStart() { @@ -84,11 +85,11 @@ public void onNext(Integer t) { @Test public void testOnStartCalledOnceViaLift() { final AtomicInteger c = new AtomicInteger(); - NbpObservable.just(1, 2, 3, 4).lift(new NbpOperator() { + Observable.just(1, 2, 3, 4).lift(new NbpOperator() { @Override - public NbpSubscriber apply(final NbpSubscriber child) { - return new NbpObserver() { + public Observer apply(final Observer child) { + return new DefaultObserver() { @Override public void onStart() { diff --git a/src/test/java/io/reactivex/nbp/NbpThrottleLastTests.java b/src/test/java/io/reactivex/observable/NbpThrottleLastTests.java similarity index 86% rename from src/test/java/io/reactivex/nbp/NbpThrottleLastTests.java rename to src/test/java/io/reactivex/observable/NbpThrottleLastTests.java index 984e7d4ddf..60fe2a2baf 100644 --- a/src/test/java/io/reactivex/nbp/NbpThrottleLastTests.java +++ b/src/test/java/io/reactivex/observable/NbpThrottleLastTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.observable; import static org.mockito.Mockito.inOrder; @@ -20,19 +20,19 @@ import org.junit.Test; import org.mockito.InOrder; -import io.reactivex.TestHelper; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; +import io.reactivex.flowable.TestHelper; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpThrottleLastTests { @Test public void testThrottle() { - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); TestScheduler s = new TestScheduler(); - NbpPublishSubject o = NbpPublishSubject.create(); + PublishSubject o = PublishSubject.create(); o.throttleLast(500, TimeUnit.MILLISECONDS, s).subscribe(observer); // send events with simulated time increments diff --git a/src/test/java/io/reactivex/nbp/NbpThrottleWithTimeoutTests.java b/src/test/java/io/reactivex/observable/NbpThrottleWithTimeoutTests.java similarity index 86% rename from src/test/java/io/reactivex/nbp/NbpThrottleWithTimeoutTests.java rename to src/test/java/io/reactivex/observable/NbpThrottleWithTimeoutTests.java index d8f1eb7eee..7d3275c2ae 100644 --- a/src/test/java/io/reactivex/nbp/NbpThrottleWithTimeoutTests.java +++ b/src/test/java/io/reactivex/observable/NbpThrottleWithTimeoutTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.nbp; +package io.reactivex.observable; import static org.mockito.Mockito.inOrder; @@ -20,19 +20,19 @@ import org.junit.Test; import org.mockito.InOrder; -import io.reactivex.TestHelper; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; +import io.reactivex.flowable.TestHelper; import io.reactivex.schedulers.TestScheduler; -import io.reactivex.subjects.nbp.NbpPublishSubject; +import io.reactivex.subjects.PublishSubject; public class NbpThrottleWithTimeoutTests { @Test public void testThrottle() { - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); TestScheduler s = new TestScheduler(); - NbpPublishSubject o = NbpPublishSubject.create(); + PublishSubject o = PublishSubject.create(); o.throttleWithTimeout(500, TimeUnit.MILLISECONDS, s) .subscribe(observer); diff --git a/src/test/java/io/reactivex/ZipTests.java b/src/test/java/io/reactivex/observable/NbpZipTests.java similarity index 78% rename from src/test/java/io/reactivex/ZipTests.java rename to src/test/java/io/reactivex/observable/NbpZipTests.java index 49b819db61..8cfb58327d 100644 --- a/src/test/java/io/reactivex/ZipTests.java +++ b/src/test/java/io/reactivex/observable/NbpZipTests.java @@ -11,26 +11,25 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.observable; -import static org.junit.Assert.*; +import static org.junit.Assert.assertSame; import java.util.*; -import org.junit.Test; -import org.reactivestreams.Publisher; +import org.junit.*; import io.reactivex.Observable; -import io.reactivex.CovarianceTest.*; -import io.reactivex.EventStream.Event; import io.reactivex.functions.*; +import io.reactivex.observable.NbpCovarianceTest.*; +import io.reactivex.observable.NbpEventStream.Event; import io.reactivex.observables.GroupedObservable; -public class ZipTests { +public class NbpZipTests { @Test - public void testZipObservableOfObservables() { - EventStream.getEventStream("HTTP-ClusterB", 20) + public void testZipNbpObservableOfNbpObservables() { + NbpEventStream.getEventStream("HTTP-ClusterB", 20) .groupBy(new Function() { @Override public String apply(Event e) { @@ -38,9 +37,9 @@ public String apply(Event e) { } }) // now we have streams of cluster+instanceId - .flatMap(new Function, Publisher>>() { + .flatMap(new Function, Observable>>() { @Override - public Publisher> apply(final GroupedObservable ge) { + public Observable> apply(final GroupedObservable ge) { return ge.scan(new HashMap(), new BiFunction, Event, HashMap>() { @Override public HashMap apply(HashMap accum, @@ -52,10 +51,10 @@ public HashMap apply(HashMap accum, } }) .take(10) - .toBlocking().forEach(new Consumer>() { + .toBlocking().forEach(new Consumer() { @Override - public void accept(HashMap v) { - System.out.println(v); + public void accept(Object pv) { + System.out.println(pv); } }); @@ -80,23 +79,23 @@ public void testCovarianceOfZip() { } /** - * Occasionally zip may be invoked with 0 observables. Test that we don't block indefinitely instead + * Occasionally zip may be invoked with 0 NbpObservables. Test that we don't block indefinitely instead * of immediately invoking zip with 0 argument. * * We now expect an NoSuchElementException since last() requires at least one value and nothing will be emitted. */ @Test(expected = NoSuchElementException.class) - public void nonBlockingObservable() { + public void nonBlockingNbpObservable() { final Object invoked = new Object(); - Collection> observables = Collections.emptyList(); + Collection> NbpObservables = Collections.emptyList(); - Observable result = Observable.zip(observables, new Function() { + Observable result = Observable.zip(NbpObservables, new Function() { @Override public Object apply(Object[] args) { System.out.println("received: " + args); - assertEquals("No argument should have been passed", 0, args.length); + Assert.assertEquals("No argument should have been passed", 0, args.length); return invoked; } }); diff --git a/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java b/src/test/java/io/reactivex/processors/AsyncSubjectTest.java similarity index 92% rename from src/test/java/io/reactivex/subjects/AsyncSubjectTest.java rename to src/test/java/io/reactivex/processors/AsyncSubjectTest.java index e0258061ed..13607057b8 100644 --- a/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java +++ b/src/test/java/io/reactivex/processors/AsyncSubjectTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects; +package io.reactivex.processors; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -24,10 +24,9 @@ import org.mockito.*; import org.reactivestreams.Subscriber; -import io.reactivex.TestHelper; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Consumer; -import io.reactivex.subjects.AsyncSubject; import io.reactivex.subscribers.TestSubscriber; public class AsyncSubjectTest { @@ -36,7 +35,7 @@ public class AsyncSubjectTest { @Test public void testNeverCompleted() { - AsyncSubject subject = AsyncSubject.create(); + AsyncProcessor subject = AsyncProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -52,7 +51,7 @@ public void testNeverCompleted() { @Test public void testCompleted() { - AsyncSubject subject = AsyncSubject.create(); + AsyncProcessor subject = AsyncProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -70,7 +69,7 @@ public void testCompleted() { @Test @Ignore("Null values not allowed") public void testNull() { - AsyncSubject subject = AsyncSubject.create(); + AsyncProcessor subject = AsyncProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -85,7 +84,7 @@ public void testNull() { @Test public void testSubscribeAfterCompleted() { - AsyncSubject subject = AsyncSubject.create(); + AsyncProcessor subject = AsyncProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); @@ -103,7 +102,7 @@ public void testSubscribeAfterCompleted() { @Test public void testSubscribeAfterError() { - AsyncSubject subject = AsyncSubject.create(); + AsyncProcessor subject = AsyncProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); @@ -123,7 +122,7 @@ public void testSubscribeAfterError() { @Test public void testError() { - AsyncSubject subject = AsyncSubject.create(); + AsyncProcessor subject = AsyncProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -143,7 +142,7 @@ public void testError() { @Test public void testUnsubscribeBeforeCompleted() { - AsyncSubject subject = AsyncSubject.create(); + AsyncProcessor subject = AsyncProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(observer); @@ -168,7 +167,7 @@ public void testUnsubscribeBeforeCompleted() { @Test public void testEmptySubjectCompleted() { - AsyncSubject subject = AsyncSubject.create(); + AsyncProcessor subject = AsyncProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -194,7 +193,7 @@ public void testSubscribeCompletionRaceCondition() { * With the synchronization code in place I can not get this to fail on my laptop. */ for (int i = 0; i < 50; i++) { - final AsyncSubject subject = AsyncSubject.create(); + final AsyncProcessor subject = AsyncProcessor.create(); final AtomicReference value1 = new AtomicReference(); subject.subscribe(new Consumer() { @@ -252,10 +251,10 @@ public void run() { private static class SubjectSubscriberThread extends Thread { - private final AsyncSubject subject; + private final AsyncProcessor subject; private final AtomicReference value = new AtomicReference(); - public SubjectSubscriberThread(AsyncSubject subject) { + public SubjectSubscriberThread(AsyncProcessor subject) { this.subject = subject; } @@ -320,7 +319,7 @@ public void run() { @Test public void testCurrentStateMethodsNormal() { - AsyncSubject as = AsyncSubject.create(); + AsyncProcessor as = AsyncProcessor.create(); assertFalse(as.hasValue()); assertFalse(as.hasThrowable()); @@ -346,7 +345,7 @@ public void testCurrentStateMethodsNormal() { @Test public void testCurrentStateMethodsEmpty() { - AsyncSubject as = AsyncSubject.create(); + AsyncProcessor as = AsyncProcessor.create(); assertFalse(as.hasValue()); assertFalse(as.hasThrowable()); @@ -364,7 +363,7 @@ public void testCurrentStateMethodsEmpty() { } @Test public void testCurrentStateMethodsError() { - AsyncSubject as = AsyncSubject.create(); + AsyncProcessor as = AsyncProcessor.create(); assertFalse(as.hasValue()); assertFalse(as.hasThrowable()); diff --git a/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java b/src/test/java/io/reactivex/processors/BehaviorSubjectTest.java similarity index 89% rename from src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java rename to src/test/java/io/reactivex/processors/BehaviorSubjectTest.java index 3f77f941f9..1dbc369ac1 100644 --- a/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java +++ b/src/test/java/io/reactivex/processors/BehaviorSubjectTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects; +package io.reactivex.processors; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -26,10 +26,10 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.BehaviorSubject; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class BehaviorSubjectTest { @@ -37,7 +37,7 @@ public class BehaviorSubjectTest { @Test public void testThatSubscriberReceivesDefaultValueAndSubsequentEvents() { - BehaviorSubject subject = BehaviorSubject.createDefault("default"); + BehaviorProcessor subject = BehaviorProcessor.createDefault("default"); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -56,7 +56,7 @@ public void testThatSubscriberReceivesDefaultValueAndSubsequentEvents() { @Test public void testThatSubscriberReceivesLatestAndThenSubsequentEvents() { - BehaviorSubject subject = BehaviorSubject.createDefault("default"); + BehaviorProcessor subject = BehaviorProcessor.createDefault("default"); subject.onNext("one"); @@ -76,7 +76,7 @@ public void testThatSubscriberReceivesLatestAndThenSubsequentEvents() { @Test public void testSubscribeThenOnComplete() { - BehaviorSubject subject = BehaviorSubject.createDefault("default"); + BehaviorProcessor subject = BehaviorProcessor.createDefault("default"); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -92,7 +92,7 @@ public void testSubscribeThenOnComplete() { @Test public void testSubscribeToCompletedOnlyEmitsOnComplete() { - BehaviorSubject subject = BehaviorSubject.createDefault("default"); + BehaviorProcessor subject = BehaviorProcessor.createDefault("default"); subject.onNext("one"); subject.onComplete(); @@ -107,7 +107,7 @@ public void testSubscribeToCompletedOnlyEmitsOnComplete() { @Test public void testSubscribeToErrorOnlyEmitsOnError() { - BehaviorSubject subject = BehaviorSubject.createDefault("default"); + BehaviorProcessor subject = BehaviorProcessor.createDefault("default"); subject.onNext("one"); RuntimeException re = new RuntimeException("test error"); subject.onError(re); @@ -123,7 +123,7 @@ public void testSubscribeToErrorOnlyEmitsOnError() { @Test public void testCompletedStopsEmittingData() { - BehaviorSubject channel = BehaviorSubject.createDefault(2013); + BehaviorProcessor channel = BehaviorProcessor.createDefault(2013); Subscriber observerA = TestHelper.mockSubscriber(); Subscriber observerB = TestHelper.mockSubscriber(); Subscriber observerC = TestHelper.mockSubscriber(); @@ -168,7 +168,7 @@ public void testCompletedStopsEmittingData() { @Test public void testCompletedAfterErrorIsNotSent() { - BehaviorSubject subject = BehaviorSubject.createDefault("default"); + BehaviorProcessor subject = BehaviorProcessor.createDefault("default"); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -187,7 +187,7 @@ public void testCompletedAfterErrorIsNotSent() { @Test public void testCompletedAfterErrorIsNotSent2() { - BehaviorSubject subject = BehaviorSubject.createDefault("default"); + BehaviorProcessor subject = BehaviorProcessor.createDefault("default"); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -212,7 +212,7 @@ public void testCompletedAfterErrorIsNotSent2() { @Test public void testCompletedAfterErrorIsNotSent3() { - BehaviorSubject subject = BehaviorSubject.createDefault("default"); + BehaviorProcessor subject = BehaviorProcessor.createDefault("default"); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -237,7 +237,7 @@ public void testCompletedAfterErrorIsNotSent3() { @Test(timeout = 1000) public void testUnsubscriptionCase() { - BehaviorSubject src = BehaviorSubject.createDefault("null"); // FIXME was plain null which is not allowed + BehaviorProcessor src = BehaviorProcessor.createDefault("null"); // FIXME was plain null which is not allowed for (int i = 0; i < 10; i++) { final Subscriber o = TestHelper.mockSubscriber(); @@ -246,14 +246,14 @@ public void testUnsubscriptionCase() { src.onNext(v); System.out.printf("Turn: %d%n", i); src.first() - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public Observable apply(String t1) { - return Observable.just(t1 + ", " + t1); + public Flowable apply(String t1) { + return Flowable.just(t1 + ", " + t1); } }) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onNext(String t) { o.onNext(t); @@ -276,7 +276,7 @@ public void onComplete() { } @Test public void testStartEmpty() { - BehaviorSubject source = BehaviorSubject.create(); + BehaviorProcessor source = BehaviorProcessor.create(); final Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); @@ -301,7 +301,7 @@ public void testStartEmpty() { } @Test public void testStartEmptyThenAddOne() { - BehaviorSubject source = BehaviorSubject.create(); + BehaviorProcessor source = BehaviorProcessor.create(); final Subscriber o = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(o); @@ -323,7 +323,7 @@ public void testStartEmptyThenAddOne() { } @Test public void testStartEmptyCompleteWithOne() { - BehaviorSubject source = BehaviorSubject.create(); + BehaviorProcessor source = BehaviorProcessor.create(); final Subscriber o = TestHelper.mockSubscriber(); source.onNext(1); @@ -340,7 +340,7 @@ public void testStartEmptyCompleteWithOne() { @Test public void testTakeOneSubscriber() { - BehaviorSubject source = BehaviorSubject.createDefault(1); + BehaviorProcessor source = BehaviorProcessor.createDefault(1); final Subscriber o = TestHelper.mockSubscriber(); source.take(1).subscribe(o); @@ -407,7 +407,7 @@ public void testEmissionSubscriptionRace() throws Exception { if (i % 1000 == 0) { System.out.println(i); } - final BehaviorSubject rs = BehaviorSubject.create(); + final BehaviorProcessor rs = BehaviorProcessor.create(); final CountDownLatch finish = new CountDownLatch(1); final CountDownLatch start = new CountDownLatch(1); @@ -427,7 +427,7 @@ public void run() { final AtomicReference o = new AtomicReference(); rs.subscribeOn(s).observeOn(Schedulers.io()) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -473,7 +473,7 @@ public void run() { @Test public void testCurrentStateMethodsNormalEmptyStart() { - BehaviorSubject as = BehaviorSubject.create(); + BehaviorProcessor as = BehaviorProcessor.create(); assertFalse(as.hasValue()); assertFalse(as.hasThrowable()); @@ -500,7 +500,7 @@ public void testCurrentStateMethodsNormalEmptyStart() { @Test public void testCurrentStateMethodsNormalSomeStart() { - BehaviorSubject as = BehaviorSubject.createDefault((Object)1); + BehaviorProcessor as = BehaviorProcessor.createDefault((Object)1); assertTrue(as.hasValue()); assertFalse(as.hasThrowable()); @@ -526,7 +526,7 @@ public void testCurrentStateMethodsNormalSomeStart() { @Test public void testCurrentStateMethodsEmpty() { - BehaviorSubject as = BehaviorSubject.create(); + BehaviorProcessor as = BehaviorProcessor.create(); assertFalse(as.hasValue()); assertFalse(as.hasThrowable()); @@ -544,7 +544,7 @@ public void testCurrentStateMethodsEmpty() { } @Test public void testCurrentStateMethodsError() { - BehaviorSubject as = BehaviorSubject.create(); + BehaviorProcessor as = BehaviorProcessor.create(); assertFalse(as.hasValue()); assertFalse(as.hasThrowable()); diff --git a/src/test/java/io/reactivex/subjects/PublishSubjectTest.java b/src/test/java/io/reactivex/processors/PublishSubjectTest.java similarity index 90% rename from src/test/java/io/reactivex/subjects/PublishSubjectTest.java rename to src/test/java/io/reactivex/processors/PublishSubjectTest.java index f7e9343d5b..79e4348d47 100644 --- a/src/test/java/io/reactivex/subjects/PublishSubjectTest.java +++ b/src/test/java/io/reactivex/processors/PublishSubjectTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects; +package io.reactivex.processors; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -24,17 +24,17 @@ import org.mockito.*; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.subjects.PublishSubject; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class PublishSubjectTest { @Test public void testCompleted() { - PublishSubject subject = PublishSubject.create(); + PublishProcessor subject = PublishProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -57,7 +57,7 @@ public void testCompleted() { @Test public void testCompletedStopsEmittingData() { - PublishSubject channel = PublishSubject.create(); + PublishProcessor channel = PublishProcessor.create(); Subscriber observerA = TestHelper.mockSubscriber(); Subscriber observerB = TestHelper.mockSubscriber(); Subscriber observerC = TestHelper.mockSubscriber(); @@ -107,7 +107,7 @@ private void assertCompletedSubscriber(Subscriber observer) { @Test public void testError() { - PublishSubject subject = PublishSubject.create(); + PublishProcessor subject = PublishProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -138,7 +138,7 @@ private void assertErrorSubscriber(Subscriber observer) { @Test public void testSubscribeMidSequence() { - PublishSubject subject = PublishSubject.create(); + PublishProcessor subject = PublishProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -168,7 +168,7 @@ private void assertCompletedStartingWithThreeSubscriber(Subscriber obser @Test public void testUnsubscribeFirstSubscriber() { - PublishSubject subject = PublishSubject.create(); + PublishProcessor subject = PublishProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(observer); @@ -200,7 +200,7 @@ private void assertObservedUntilTwo(Subscriber observer) { @Test public void testNestedSubscribe() { - final PublishSubject s = PublishSubject.create(); + final PublishProcessor s = PublishProcessor.create(); final AtomicInteger countParent = new AtomicInteger(); final AtomicInteger countChildren = new AtomicInteger(); @@ -208,10 +208,10 @@ public void testNestedSubscribe() { final ArrayList list = new ArrayList(); - s.flatMap(new Function>() { + s.flatMap(new Function>() { @Override - public Observable apply(final Integer v) { + public Flowable apply(final Integer v) { countParent.incrementAndGet(); // then subscribe to subject again (it will not receive the previous value) @@ -254,7 +254,7 @@ public void accept(String v) { */ @Test public void testReSubscribe() { - final PublishSubject ps = PublishSubject.create(); + final PublishProcessor ps = PublishProcessor.create(); Subscriber o1 = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(o1); @@ -293,7 +293,7 @@ public void testReSubscribe() { @Test(timeout = 1000) public void testUnsubscriptionCase() { - PublishSubject src = PublishSubject.create(); + PublishProcessor src = PublishProcessor.create(); for (int i = 0; i < 10; i++) { final Subscriber o = TestHelper.mockSubscriber(); @@ -301,14 +301,14 @@ public void testUnsubscriptionCase() { String v = "" + i; System.out.printf("Turn: %d%n", i); src.first() - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public Observable apply(String t1) { - return Observable.just(t1 + ", " + t1); + public Flowable apply(String t1) { + return Flowable.just(t1 + ", " + t1); } }) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onNext(String t) { o.onNext(t); @@ -380,7 +380,7 @@ public void onComplete() { // } @Test public void testCurrentStateMethodsNormal() { - PublishSubject as = PublishSubject.create(); + PublishProcessor as = PublishProcessor.create(); assertFalse(as.hasThrowable()); assertFalse(as.hasComplete()); @@ -401,7 +401,7 @@ public void testCurrentStateMethodsNormal() { @Test public void testCurrentStateMethodsEmpty() { - PublishSubject as = PublishSubject.create(); + PublishProcessor as = PublishProcessor.create(); assertFalse(as.hasThrowable()); assertFalse(as.hasComplete()); @@ -415,7 +415,7 @@ public void testCurrentStateMethodsEmpty() { } @Test public void testCurrentStateMethodsError() { - PublishSubject as = PublishSubject.create(); + PublishProcessor as = PublishProcessor.create(); assertFalse(as.hasThrowable()); assertFalse(as.hasComplete()); diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java b/src/test/java/io/reactivex/processors/ReplaySubjectBoundedConcurrencyTest.java similarity index 93% rename from src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java rename to src/test/java/io/reactivex/processors/ReplaySubjectBoundedConcurrencyTest.java index aeb728ec75..80054d1106 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java +++ b/src/test/java/io/reactivex/processors/ReplaySubjectBoundedConcurrencyTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects; +package io.reactivex.processors; import static org.junit.Assert.assertEquals; @@ -25,21 +25,19 @@ import io.reactivex.*; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.ReplaySubject; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; public class ReplaySubjectBoundedConcurrencyTest { @Test(timeout = 4000) public void testReplaySubjectConcurrentSubscribersDoingReplayDontBlockEachOther() throws InterruptedException { - final ReplaySubject replay = ReplaySubject.createUnbounded(); + final ReplayProcessor replay = ReplayProcessor.createUnbounded(); Thread source = new Thread(new Runnable() { @Override public void run() { - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber o) { @@ -64,7 +62,7 @@ public void subscribe(Subscriber o) { @Override public void run() { - Subscriber slow = new Observer() { + Subscriber slow = new DefaultObserver() { @Override public void onComplete() { @@ -105,7 +103,7 @@ public void onNext(Long args) { @Override public void run() { final CountDownLatch fastLatch = new CountDownLatch(1); - Subscriber fast = new Observer() { + Subscriber fast = new DefaultObserver() { @Override public void onComplete() { @@ -143,12 +141,12 @@ public void onNext(Long args) { @Test public void testReplaySubjectConcurrentSubscriptions() throws InterruptedException { - final ReplaySubject replay = ReplaySubject.createUnbounded(); + final ReplayProcessor replay = ReplayProcessor.createUnbounded(); Thread source = new Thread(new Runnable() { @Override public void run() { - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber o) { @@ -230,7 +228,7 @@ public void run() { @Test(timeout = 10000) public void testSubscribeCompletionRaceCondition() { for (int i = 0; i < 50; i++) { - final ReplaySubject subject = ReplaySubject.createUnbounded(); + final ReplayProcessor subject = ReplayProcessor.createUnbounded(); final AtomicReference value1 = new AtomicReference(); subject.subscribe(new Consumer() { @@ -294,7 +292,7 @@ public void testRaceForTerminalState() { final List expected = Arrays.asList(1); for (int i = 0; i < 100000; i++) { TestSubscriber ts = new TestSubscriber(); - Observable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts); + Flowable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts); ts.awaitTerminalEvent(); ts.assertValueSequence(expected); ts.assertTerminated(); @@ -303,10 +301,10 @@ public void testRaceForTerminalState() { private static class SubjectObserverThread extends Thread { - private final ReplaySubject subject; + private final ReplayProcessor subject; private final AtomicReference value = new AtomicReference(); - public SubjectObserverThread(ReplaySubject subject) { + public SubjectObserverThread(ReplayProcessor subject) { this.subject = subject; } @@ -330,7 +328,7 @@ public void testReplaySubjectEmissionSubscriptionRace() throws Exception { if (i % 1000 == 0) { System.out.println(i); } - final ReplaySubject rs = ReplaySubject.createWithSize(2); + final ReplayProcessor rs = ReplayProcessor.createWithSize(2); final CountDownLatch finish = new CountDownLatch(1); final CountDownLatch start = new CountDownLatch(1); @@ -358,7 +356,7 @@ public void run() { .subscribeOn(s) .observeOn(Schedulers.io()) // .doOnNext(e -> System.out.println(">>> " + j)) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override protected void onStart() { @@ -408,7 +406,7 @@ public void run() { } @Test(timeout = 5000) public void testConcurrentSizeAndHasAnyValue() throws InterruptedException { - final ReplaySubject rs = ReplaySubject.createUnbounded(); + final ReplayProcessor rs = ReplayProcessor.createUnbounded(); final CyclicBarrier cb = new CyclicBarrier(2); Thread t = new Thread(new Runnable() { @@ -462,7 +460,7 @@ public void run() { } @Test(timeout = 5000) public void testConcurrentSizeAndHasAnyValueBounded() throws InterruptedException { - final ReplaySubject rs = ReplaySubject.createWithSize(3); + final ReplayProcessor rs = ReplayProcessor.createWithSize(3); final CyclicBarrier cb = new CyclicBarrier(2); Thread t = new Thread(new Runnable() { @@ -505,7 +503,7 @@ public void run() { } @Test(timeout = 10000) public void testConcurrentSizeAndHasAnyValueTimeBounded() throws InterruptedException { - final ReplaySubject rs = ReplaySubject.createWithTime(1, TimeUnit.MILLISECONDS, Schedulers.computation()); + final ReplayProcessor rs = ReplayProcessor.createWithTime(1, TimeUnit.MILLISECONDS, Schedulers.computation()); final CyclicBarrier cb = new CyclicBarrier(2); Thread t = new Thread(new Runnable() { diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java b/src/test/java/io/reactivex/processors/ReplaySubjectConcurrencyTest.java similarity index 93% rename from src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java rename to src/test/java/io/reactivex/processors/ReplaySubjectConcurrencyTest.java index 316f7dff1a..d03a855f6b 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java +++ b/src/test/java/io/reactivex/processors/ReplaySubjectConcurrencyTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects; +package io.reactivex.processors; import static org.junit.Assert.assertEquals; @@ -25,21 +25,19 @@ import io.reactivex.*; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.ReplaySubject; +import io.reactivex.subscribers.DefaultObserver; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; -import io.reactivex.Observer; public class ReplaySubjectConcurrencyTest { @Test(timeout = 4000) public void testReplaySubjectConcurrentSubscribersDoingReplayDontBlockEachOther() throws InterruptedException { - final ReplaySubject replay = ReplaySubject.create(); + final ReplayProcessor replay = ReplayProcessor.create(); Thread source = new Thread(new Runnable() { @Override public void run() { - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber o) { @@ -64,7 +62,7 @@ public void subscribe(Subscriber o) { @Override public void run() { - Subscriber slow = new Observer() { + Subscriber slow = new DefaultObserver() { @Override public void onComplete() { @@ -105,7 +103,7 @@ public void onNext(Long args) { @Override public void run() { final CountDownLatch fastLatch = new CountDownLatch(1); - Subscriber fast = new Observer() { + Subscriber fast = new DefaultObserver() { @Override public void onComplete() { @@ -143,12 +141,12 @@ public void onNext(Long args) { @Test public void testReplaySubjectConcurrentSubscriptions() throws InterruptedException { - final ReplaySubject replay = ReplaySubject.create(); + final ReplayProcessor replay = ReplayProcessor.create(); Thread source = new Thread(new Runnable() { @Override public void run() { - Observable.create(new Publisher() { + Flowable.create(new Publisher() { @Override public void subscribe(Subscriber o) { @@ -230,7 +228,7 @@ public void run() { @Test(timeout = 10000) public void testSubscribeCompletionRaceCondition() { for (int i = 0; i < 50; i++) { - final ReplaySubject subject = ReplaySubject.create(); + final ReplayProcessor subject = ReplayProcessor.create(); final AtomicReference value1 = new AtomicReference(); subject.subscribe(new Consumer() { @@ -294,7 +292,7 @@ public void testRaceForTerminalState() { final List expected = Arrays.asList(1); for (int i = 0; i < 100000; i++) { TestSubscriber ts = new TestSubscriber(); - Observable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts); + Flowable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts); ts.awaitTerminalEvent(); ts.assertValueSequence(expected); ts.assertTerminated(); @@ -303,10 +301,10 @@ public void testRaceForTerminalState() { private static class SubjectObserverThread extends Thread { - private final ReplaySubject subject; + private final ReplayProcessor subject; private final AtomicReference value = new AtomicReference(); - public SubjectObserverThread(ReplaySubject subject) { + public SubjectObserverThread(ReplayProcessor subject) { this.subject = subject; } @@ -330,7 +328,7 @@ public void testReplaySubjectEmissionSubscriptionRace() throws Exception { if (i % 1000 == 0) { System.out.println(i); } - final ReplaySubject rs = ReplaySubject.create(); + final ReplayProcessor rs = ReplayProcessor.create(); final CountDownLatch finish = new CountDownLatch(1); final CountDownLatch start = new CountDownLatch(1); @@ -350,7 +348,7 @@ public void run() { final AtomicReference o = new AtomicReference(); rs.subscribeOn(s).observeOn(Schedulers.io()) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -396,7 +394,7 @@ public void run() { } @Test(timeout = 10000) public void testConcurrentSizeAndHasAnyValue() throws InterruptedException { - final ReplaySubject rs = ReplaySubject.create(); + final ReplayProcessor rs = ReplayProcessor.create(); final CyclicBarrier cb = new CyclicBarrier(2); Thread t = new Thread(new Runnable() { diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java b/src/test/java/io/reactivex/processors/ReplaySubjectTest.java similarity index 89% rename from src/test/java/io/reactivex/subjects/ReplaySubjectTest.java rename to src/test/java/io/reactivex/processors/ReplaySubjectTest.java index c57ac99509..03b43a4206 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java +++ b/src/test/java/io/reactivex/processors/ReplaySubjectTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects; +package io.reactivex.processors; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,13 +25,13 @@ import org.mockito.*; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; import io.reactivex.schedulers.*; -import io.reactivex.subjects.ReplaySubject; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.subscribers.*; public class ReplaySubjectTest { @@ -39,7 +39,7 @@ public class ReplaySubjectTest { @Test public void testCompleted() { - ReplaySubject subject = ReplaySubject.create(); + ReplayProcessor subject = ReplayProcessor.create(); Subscriber o1 = TestHelper.mockSubscriber(); subject.subscribe(o1); @@ -63,7 +63,7 @@ public void testCompleted() { @Test public void testCompletedStopsEmittingData() { - ReplaySubject channel = ReplaySubject.create(); + ReplayProcessor channel = ReplayProcessor.create(); Subscriber observerA = TestHelper.mockSubscriber(); Subscriber observerB = TestHelper.mockSubscriber(); Subscriber observerC = TestHelper.mockSubscriber(); @@ -132,7 +132,7 @@ public void testCompletedStopsEmittingData() { @Test public void testCompletedAfterError() { - ReplaySubject subject = ReplaySubject.create(); + ReplayProcessor subject = ReplayProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); @@ -162,7 +162,7 @@ private void assertCompletedSubscriber(Subscriber observer) { @Test public void testError() { - ReplaySubject subject = ReplaySubject.create(); + ReplayProcessor subject = ReplayProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -193,7 +193,7 @@ private void assertErrorSubscriber(Subscriber observer) { @Test public void testSubscribeMidSequence() { - ReplaySubject subject = ReplaySubject.create(); + ReplayProcessor subject = ReplayProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); subject.subscribe(observer); @@ -216,7 +216,7 @@ public void testSubscribeMidSequence() { @Test public void testUnsubscribeFirstSubscriber() { - ReplaySubject subject = ReplaySubject.create(); + ReplayProcessor subject = ReplayProcessor.create(); Subscriber observer = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(observer); @@ -251,7 +251,7 @@ private void assertObservedUntilTwo(Subscriber observer) { public void testNewSubscriberDoesntBlockExisting() throws InterruptedException { final AtomicReference lastValueForSubscriber1 = new AtomicReference(); - Subscriber observer1 = new Observer() { + Subscriber observer1 = new DefaultObserver() { @Override public void onComplete() { @@ -275,7 +275,7 @@ public void onNext(String v) { final CountDownLatch oneReceived = new CountDownLatch(1); final CountDownLatch makeSlow = new CountDownLatch(1); final CountDownLatch completed = new CountDownLatch(1); - Subscriber observer2 = new Observer() { + Subscriber observer2 = new DefaultObserver() { @Override public void onComplete() { @@ -304,7 +304,7 @@ public void onNext(String v) { }; - ReplaySubject subject = ReplaySubject.create(); + ReplayProcessor subject = ReplayProcessor.create(); subject.subscribe(observer1); subject.onNext("one"); assertEquals("one", lastValueForSubscriber1.get()); @@ -346,7 +346,7 @@ public void onNext(String v) { } @Test public void testSubscriptionLeak() { - ReplaySubject replaySubject = ReplaySubject.create(); + ReplayProcessor replaySubject = ReplayProcessor.create(); Disposable s = replaySubject.subscribe(); @@ -358,7 +358,7 @@ public void testSubscriptionLeak() { } @Test(timeout = 1000) public void testUnsubscriptionCase() { - ReplaySubject src = ReplaySubject.create(); + ReplayProcessor src = ReplayProcessor.create(); for (int i = 0; i < 10; i++) { final Subscriber o = TestHelper.mockSubscriber(); @@ -367,14 +367,14 @@ public void testUnsubscriptionCase() { src.onNext(v); System.out.printf("Turn: %d%n", i); src.first() - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public Observable apply(String t1) { - return Observable.just(t1 + ", " + t1); + public Flowable apply(String t1) { + return Flowable.just(t1 + ", " + t1); } }) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onNext(String t) { System.out.println(t); @@ -398,14 +398,14 @@ public void onComplete() { } @Test public void testTerminateOnce() { - ReplaySubject source = ReplaySubject.create(); + ReplayProcessor source = ReplayProcessor.create(); source.onNext(1); source.onNext(2); source.onComplete(); final Subscriber o = TestHelper.mockSubscriber(); - source.unsafeSubscribe(new Observer() { + source.unsafeSubscribe(new DefaultObserver() { @Override public void onNext(Integer t) { @@ -431,7 +431,7 @@ public void onComplete() { @Test public void testReplay1AfterTermination() { - ReplaySubject source = ReplaySubject.createWithSize(1); + ReplayProcessor source = ReplayProcessor.createWithSize(1); source.onNext(1); source.onNext(2); @@ -450,7 +450,7 @@ public void testReplay1AfterTermination() { } @Test public void testReplay1Directly() { - ReplaySubject source = ReplaySubject.createWithSize(1); + ReplayProcessor source = ReplayProcessor.createWithSize(1); Subscriber o = TestHelper.mockSubscriber(); @@ -472,7 +472,7 @@ public void testReplay1Directly() { @Test public void testReplayTimestampedAfterTermination() { TestScheduler scheduler = new TestScheduler(); - ReplaySubject source = ReplaySubject.createWithTime(1, TimeUnit.SECONDS, scheduler); + ReplayProcessor source = ReplayProcessor.createWithTime(1, TimeUnit.SECONDS, scheduler); source.onNext(1); @@ -501,7 +501,7 @@ public void testReplayTimestampedAfterTermination() { @Test public void testReplayTimestampedDirectly() { TestScheduler scheduler = new TestScheduler(); - ReplaySubject source = ReplaySubject.createWithTime(1, TimeUnit.SECONDS, scheduler); + ReplayProcessor source = ReplayProcessor.createWithTime(1, TimeUnit.SECONDS, scheduler); source.onNext(1); @@ -578,7 +578,7 @@ public void testReplayTimestampedDirectly() { @Test public void testCurrentStateMethodsNormal() { - ReplaySubject as = ReplaySubject.create(); + ReplayProcessor as = ReplayProcessor.create(); assertFalse(as.hasThrowable()); assertFalse(as.hasComplete()); @@ -599,7 +599,7 @@ public void testCurrentStateMethodsNormal() { @Test public void testCurrentStateMethodsEmpty() { - ReplaySubject as = ReplaySubject.create(); + ReplayProcessor as = ReplayProcessor.create(); assertFalse(as.hasThrowable()); assertFalse(as.hasComplete()); @@ -613,7 +613,7 @@ public void testCurrentStateMethodsEmpty() { } @Test public void testCurrentStateMethodsError() { - ReplaySubject as = ReplaySubject.create(); + ReplayProcessor as = ReplayProcessor.create(); assertFalse(as.hasThrowable()); assertFalse(as.hasComplete()); @@ -627,7 +627,7 @@ public void testCurrentStateMethodsError() { } @Test public void testSizeAndHasAnyValueUnbounded() { - ReplaySubject rs = ReplaySubject.create(); + ReplayProcessor rs = ReplayProcessor.create(); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); @@ -649,7 +649,7 @@ public void testSizeAndHasAnyValueUnbounded() { } @Test public void testSizeAndHasAnyValueEffectivelyUnbounded() { - ReplaySubject rs = ReplaySubject.createUnbounded(); + ReplayProcessor rs = ReplayProcessor.createUnbounded(); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); @@ -672,7 +672,7 @@ public void testSizeAndHasAnyValueEffectivelyUnbounded() { @Test public void testSizeAndHasAnyValueUnboundedError() { - ReplaySubject rs = ReplaySubject.create(); + ReplayProcessor rs = ReplayProcessor.create(); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); @@ -694,7 +694,7 @@ public void testSizeAndHasAnyValueUnboundedError() { } @Test public void testSizeAndHasAnyValueEffectivelyUnboundedError() { - ReplaySubject rs = ReplaySubject.createUnbounded(); + ReplayProcessor rs = ReplayProcessor.createUnbounded(); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); @@ -717,7 +717,7 @@ public void testSizeAndHasAnyValueEffectivelyUnboundedError() { @Test public void testSizeAndHasAnyValueUnboundedEmptyError() { - ReplaySubject rs = ReplaySubject.create(); + ReplayProcessor rs = ReplayProcessor.create(); rs.onError(new TestException()); @@ -726,7 +726,7 @@ public void testSizeAndHasAnyValueUnboundedEmptyError() { } @Test public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyError() { - ReplaySubject rs = ReplaySubject.createUnbounded(); + ReplayProcessor rs = ReplayProcessor.createUnbounded(); rs.onError(new TestException()); @@ -736,7 +736,7 @@ public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyError() { @Test public void testSizeAndHasAnyValueUnboundedEmptyCompleted() { - ReplaySubject rs = ReplaySubject.create(); + ReplayProcessor rs = ReplayProcessor.create(); rs.onComplete(); @@ -745,7 +745,7 @@ public void testSizeAndHasAnyValueUnboundedEmptyCompleted() { } @Test public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyCompleted() { - ReplaySubject rs = ReplaySubject.createUnbounded(); + ReplayProcessor rs = ReplayProcessor.createUnbounded(); rs.onComplete(); @@ -755,7 +755,7 @@ public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyCompleted() { @Test public void testSizeAndHasAnyValueSizeBounded() { - ReplaySubject rs = ReplaySubject.createWithSize(1); + ReplayProcessor rs = ReplayProcessor.createWithSize(1); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); @@ -776,7 +776,7 @@ public void testSizeAndHasAnyValueSizeBounded() { @Test public void testSizeAndHasAnyValueTimeBounded() { TestScheduler ts = new TestScheduler(); - ReplaySubject rs = ReplaySubject.createWithTime(1, TimeUnit.SECONDS, ts); + ReplayProcessor rs = ReplayProcessor.createWithTime(1, TimeUnit.SECONDS, ts); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); @@ -795,7 +795,7 @@ public void testSizeAndHasAnyValueTimeBounded() { } @Test public void testGetValues() { - ReplaySubject rs = ReplaySubject.create(); + ReplayProcessor rs = ReplayProcessor.create(); Object[] expected = new Object[10]; for (int i = 0; i < expected.length; i++) { expected[i] = i; @@ -809,7 +809,7 @@ public void testGetValues() { } @Test public void testGetValuesUnbounded() { - ReplaySubject rs = ReplaySubject.createUnbounded(); + ReplayProcessor rs = ReplayProcessor.createUnbounded(); Object[] expected = new Object[10]; for (int i = 0; i < expected.length; i++) { expected[i] = i; @@ -824,7 +824,7 @@ public void testGetValuesUnbounded() { @Test public void testBackpressureHonored() { - ReplaySubject rs = ReplaySubject.create(); + ReplayProcessor rs = ReplayProcessor.create(); rs.onNext(1); rs.onNext(2); rs.onNext(3); @@ -853,7 +853,7 @@ public void testBackpressureHonored() { @Test public void testBackpressureHonoredSizeBound() { - ReplaySubject rs = ReplaySubject.createWithSize(100); + ReplayProcessor rs = ReplayProcessor.createWithSize(100); rs.onNext(1); rs.onNext(2); rs.onNext(3); @@ -882,7 +882,7 @@ public void testBackpressureHonoredSizeBound() { @Test public void testBackpressureHonoredTimeBound() { - ReplaySubject rs = ReplaySubject.createWithTime(1, TimeUnit.DAYS); + ReplayProcessor rs = ReplayProcessor.createWithTime(1, TimeUnit.DAYS); rs.onNext(1); rs.onNext(2); rs.onNext(3); diff --git a/src/test/java/io/reactivex/subjects/SerializedSubjectTest.java b/src/test/java/io/reactivex/processors/SerializedSubjectTest.java similarity index 83% rename from src/test/java/io/reactivex/subjects/SerializedSubjectTest.java rename to src/test/java/io/reactivex/processors/SerializedSubjectTest.java index 9e45fadc8a..3a0caaafab 100644 --- a/src/test/java/io/reactivex/subjects/SerializedSubjectTest.java +++ b/src/test/java/io/reactivex/processors/SerializedSubjectTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects; +package io.reactivex.processors; import static org.junit.Assert.*; @@ -24,7 +24,7 @@ public class SerializedSubjectTest { @Test public void testBasic() { - SerializedSubject subject = new SerializedSubject(PublishSubject. create()); + SerializedProcessor subject = new SerializedProcessor(PublishProcessor. create()); TestSubscriber ts = new TestSubscriber(); subject.subscribe(ts); subject.onNext("hello"); @@ -35,10 +35,10 @@ public void testBasic() { @Test public void testAsyncSubjectValueRelay() { - AsyncSubject async = AsyncSubject.create(); + AsyncProcessor async = AsyncProcessor.create(); async.onNext(1); async.onComplete(); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -53,9 +53,9 @@ public void testAsyncSubjectValueRelay() { } @Test public void testAsyncSubjectValueEmpty() { - AsyncSubject async = AsyncSubject.create(); + AsyncProcessor async = AsyncProcessor.create(); async.onComplete(); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -70,10 +70,10 @@ public void testAsyncSubjectValueEmpty() { } @Test public void testAsyncSubjectValueError() { - AsyncSubject async = AsyncSubject.create(); + AsyncProcessor async = AsyncProcessor.create(); TestException te = new TestException(); async.onError(te); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -88,10 +88,10 @@ public void testAsyncSubjectValueError() { } @Test public void testPublishSubjectValueRelay() { - PublishSubject async = PublishSubject.create(); + PublishProcessor async = PublishProcessor.create(); async.onNext(1); async.onComplete(); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -108,9 +108,9 @@ public void testPublishSubjectValueRelay() { @Test public void testPublishSubjectValueEmpty() { - PublishSubject async = PublishSubject.create(); + PublishProcessor async = PublishProcessor.create(); async.onComplete(); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -125,10 +125,10 @@ public void testPublishSubjectValueEmpty() { } @Test public void testPublishSubjectValueError() { - PublishSubject async = PublishSubject.create(); + PublishProcessor async = PublishProcessor.create(); TestException te = new TestException(); async.onError(te); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -144,10 +144,10 @@ public void testPublishSubjectValueError() { @Test public void testBehaviorSubjectValueRelay() { - BehaviorSubject async = BehaviorSubject.create(); + BehaviorProcessor async = BehaviorProcessor.create(); async.onNext(1); async.onComplete(); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -162,9 +162,9 @@ public void testBehaviorSubjectValueRelay() { } @Test public void testBehaviorSubjectValueRelayIncomplete() { - BehaviorSubject async = BehaviorSubject.create(); + BehaviorProcessor async = BehaviorProcessor.create(); async.onNext(1); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -179,8 +179,8 @@ public void testBehaviorSubjectValueRelayIncomplete() { } @Test public void testBehaviorSubjectIncompleteEmpty() { - BehaviorSubject async = BehaviorSubject.create(); - Subject serial = async.toSerialized(); + BehaviorProcessor async = BehaviorProcessor.create(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -195,9 +195,9 @@ public void testBehaviorSubjectIncompleteEmpty() { } @Test public void testBehaviorSubjectEmpty() { - BehaviorSubject async = BehaviorSubject.create(); + BehaviorProcessor async = BehaviorProcessor.create(); async.onComplete(); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -212,10 +212,10 @@ public void testBehaviorSubjectEmpty() { } @Test public void testBehaviorSubjectError() { - BehaviorSubject async = BehaviorSubject.create(); + BehaviorProcessor async = BehaviorProcessor.create(); TestException te = new TestException(); async.onError(te); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -231,10 +231,10 @@ public void testBehaviorSubjectError() { @Test public void testReplaySubjectValueRelay() { - ReplaySubject async = ReplaySubject.create(); + ReplayProcessor async = ReplayProcessor.create(); async.onNext(1); async.onComplete(); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -249,9 +249,9 @@ public void testReplaySubjectValueRelay() { } @Test public void testReplaySubjectValueRelayIncomplete() { - ReplaySubject async = ReplaySubject.create(); + ReplayProcessor async = ReplayProcessor.create(); async.onNext(1); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -266,11 +266,11 @@ public void testReplaySubjectValueRelayIncomplete() { } @Test public void testReplaySubjectValueRelayBounded() { - ReplaySubject async = ReplaySubject.createWithSize(1); + ReplayProcessor async = ReplayProcessor.createWithSize(1); async.onNext(0); async.onNext(1); async.onComplete(); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -285,10 +285,10 @@ public void testReplaySubjectValueRelayBounded() { } @Test public void testReplaySubjectValueRelayBoundedIncomplete() { - ReplaySubject async = ReplaySubject.createWithSize(1); + ReplayProcessor async = ReplayProcessor.createWithSize(1); async.onNext(0); async.onNext(1); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -303,8 +303,8 @@ public void testReplaySubjectValueRelayBoundedIncomplete() { } @Test public void testReplaySubjectValueRelayBoundedEmptyIncomplete() { - ReplaySubject async = ReplaySubject.createWithSize(1); - Subject serial = async.toSerialized(); + ReplayProcessor async = ReplayProcessor.createWithSize(1); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -319,8 +319,8 @@ public void testReplaySubjectValueRelayBoundedEmptyIncomplete() { } @Test public void testReplaySubjectValueRelayEmptyIncomplete() { - ReplaySubject async = ReplaySubject.create(); - Subject serial = async.toSerialized(); + ReplayProcessor async = ReplayProcessor.create(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -336,9 +336,9 @@ public void testReplaySubjectValueRelayEmptyIncomplete() { @Test public void testReplaySubjectEmpty() { - ReplaySubject async = ReplaySubject.create(); + ReplayProcessor async = ReplayProcessor.create(); async.onComplete(); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -353,10 +353,10 @@ public void testReplaySubjectEmpty() { } @Test public void testReplaySubjectError() { - ReplaySubject async = ReplaySubject.create(); + ReplayProcessor async = ReplayProcessor.create(); TestException te = new TestException(); async.onError(te); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -372,9 +372,9 @@ public void testReplaySubjectError() { @Test public void testReplaySubjectBoundedEmpty() { - ReplaySubject async = ReplaySubject.createWithSize(1); + ReplayProcessor async = ReplayProcessor.createWithSize(1); async.onComplete(); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -389,10 +389,10 @@ public void testReplaySubjectBoundedEmpty() { } @Test public void testReplaySubjectBoundedError() { - ReplaySubject async = ReplaySubject.createWithSize(1); + ReplayProcessor async = ReplayProcessor.createWithSize(1); TestException te = new TestException(); async.onError(te); - Subject serial = async.toSerialized(); + FlowProcessor serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -408,9 +408,9 @@ public void testReplaySubjectBoundedError() { @Test public void testDontWrapSerializedSubjectAgain() { - PublishSubject s = PublishSubject.create(); - Subject s1 = s.toSerialized(); - Subject s2 = s1.toSerialized(); + PublishProcessor s = PublishProcessor.create(); + FlowProcessor s1 = s.toSerialized(); + FlowProcessor s2 = s1.toSerialized(); assertSame(s1, s2); } } \ No newline at end of file diff --git a/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java b/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java index 3b96eb32dc..539474d5a8 100644 --- a/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java +++ b/src/test/java/io/reactivex/schedulers/AbstractSchedulerConcurrencyTests.java @@ -24,7 +24,7 @@ import io.reactivex.*; import io.reactivex.Scheduler.Worker; import io.reactivex.functions.*; -import io.reactivex.subscribers.AsyncObserver; +import io.reactivex.subscribers.*; /** * Base tests for schedulers that involve threads (concurrency). @@ -45,7 +45,7 @@ public final void testUnSubscribeForScheduler() throws InterruptedException { final AtomicInteger countGenerated = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(1); - Observable.interval(50, TimeUnit.MILLISECONDS) + Flowable.interval(50, TimeUnit.MILLISECONDS) .map(new Function() { @Override public Long apply(Long aLong) { @@ -55,7 +55,7 @@ public Long apply(Long aLong) { }) .subscribeOn(getScheduler()) .observeOn(getScheduler()) - .subscribe(new Observer() { + .subscribe(new DefaultObserver() { @Override public void onComplete() { System.out.println("--- completed"); @@ -283,7 +283,7 @@ public void testRecursionAndOuterUnsubscribe() throws InterruptedException { final CountDownLatch completionLatch = new CountDownLatch(1); final Worker inner = getScheduler().createWorker(); try { - Observable obs = Observable.create(new Publisher() { + Flowable obs = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { inner.schedule(new Runnable() { @@ -317,7 +317,7 @@ public void request(long n) { final AtomicInteger count = new AtomicInteger(); final AtomicBoolean completed = new AtomicBoolean(false); - AsyncObserver s = new AsyncObserver() { + AsyncSubscriber s = new AsyncSubscriber() { @Override public void onComplete() { System.out.println("Completed"); @@ -363,7 +363,7 @@ public final void testSubscribeWithScheduler() throws InterruptedException { final AtomicInteger count = new AtomicInteger(); - Observable o1 = Observable. just(1, 2, 3, 4, 5); + Flowable o1 = Flowable. just(1, 2, 3, 4, 5); o1.subscribe(new Consumer() { diff --git a/src/test/java/io/reactivex/schedulers/AbstractSchedulerTests.java b/src/test/java/io/reactivex/schedulers/AbstractSchedulerTests.java index 1c765153cd..68840303f1 100644 --- a/src/test/java/io/reactivex/schedulers/AbstractSchedulerTests.java +++ b/src/test/java/io/reactivex/schedulers/AbstractSchedulerTests.java @@ -29,8 +29,7 @@ import io.reactivex.*; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.*; -import io.reactivex.Observable; -import io.reactivex.Observer; +import io.reactivex.subscribers.DefaultObserver; /** * Base tests for all schedulers including Immediate/Current. @@ -104,13 +103,13 @@ public void run() { @Test public final void testNestedScheduling() { - Observable ids = Observable.fromIterable(Arrays.asList(1, 2)).subscribeOn(getScheduler()); + Flowable ids = Flowable.fromIterable(Arrays.asList(1, 2)).subscribeOn(getScheduler()); - Observable m = ids.flatMap(new Function>() { + Flowable m = ids.flatMap(new Function>() { @Override - public Observable apply(Integer id) { - return Observable.fromIterable(Arrays.asList("a-" + id, "b-" + id)).subscribeOn(getScheduler()) + public Flowable apply(Integer id) { + return Flowable.fromIterable(Arrays.asList("a-" + id, "b-" + id)).subscribeOn(getScheduler()) .map(new Function() { @Override @@ -321,7 +320,7 @@ public void run() { @Test public final void testRecursiveSchedulerInObservable() { - Observable obs = Observable.create(new Publisher() { + Flowable obs = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { final Scheduler.Worker inner = getScheduler().createWorker(); @@ -365,7 +364,7 @@ public void accept(Integer v) { public final void testConcurrentOnNextFailsValidation() throws InterruptedException { final int count = 10; final CountDownLatch latch = new CountDownLatch(count); - Observable o = Observable.create(new Publisher() { + Flowable o = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber observer) { @@ -402,7 +401,7 @@ public void run() { public final void testObserveOn() throws InterruptedException { final Scheduler scheduler = getScheduler(); - Observable o = Observable.fromArray("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"); + Flowable o = Flowable.fromArray("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"); ConcurrentObserverValidator observer = new ConcurrentObserverValidator(); @@ -422,12 +421,12 @@ public final void testObserveOn() throws InterruptedException { public final void testSubscribeOnNestedConcurrency() throws InterruptedException { final Scheduler scheduler = getScheduler(); - Observable o = Observable.fromArray("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten") - .flatMap(new Function>() { + Flowable o = Flowable.fromArray("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten") + .flatMap(new Function>() { @Override - public Observable apply(final String v) { - return Observable.create(new Publisher() { + public Flowable apply(final String v) { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber observer) { @@ -458,7 +457,7 @@ public void subscribe(Subscriber observer) { * * @param */ - private static class ConcurrentObserverValidator extends Observer { + private static class ConcurrentObserverValidator extends DefaultObserver { final AtomicInteger concurrentCounter = new AtomicInteger(); final AtomicReference error = new AtomicReference(); diff --git a/src/test/java/io/reactivex/schedulers/CachedThreadSchedulerTest.java b/src/test/java/io/reactivex/schedulers/CachedThreadSchedulerTest.java index 1db6d57cb3..1f6acb2d33 100644 --- a/src/test/java/io/reactivex/schedulers/CachedThreadSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/CachedThreadSchedulerTest.java @@ -20,7 +20,6 @@ import io.reactivex.*; import io.reactivex.Scheduler.Worker; import io.reactivex.functions.*; -import io.reactivex.schedulers.Schedulers; public class CachedThreadSchedulerTest extends AbstractSchedulerConcurrencyTests { @@ -35,9 +34,9 @@ protected Scheduler getScheduler() { @Test public final void testIOScheduler() { - Observable o1 = Observable.just(1, 2, 3, 4, 5); - Observable o2 = Observable.just(6, 7, 8, 9, 10); - Observable o = Observable.merge(o1, o2).map(new Function() { + Flowable o1 = Flowable.just(1, 2, 3, 4, 5); + Flowable o2 = Flowable.just(6, 7, 8, 9, 10); + Flowable o = Flowable.merge(o1, o2).map(new Function() { @Override public String apply(Integer t) { diff --git a/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java b/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java index 1a6f780163..197c6ec368 100644 --- a/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java +++ b/src/test/java/io/reactivex/schedulers/ComputationSchedulerTests.java @@ -23,7 +23,6 @@ import io.reactivex.*; import io.reactivex.Scheduler.Worker; import io.reactivex.functions.*; -import io.reactivex.schedulers.Schedulers; public class ComputationSchedulerTests extends AbstractSchedulerConcurrencyTests { @@ -90,9 +89,9 @@ public void run() { @Test public final void testComputationThreadPool1() { - Observable o1 = Observable. just(1, 2, 3, 4, 5); - Observable o2 = Observable. just(6, 7, 8, 9, 10); - Observable o = Observable. merge(o1, o2).map(new Function() { + Flowable o1 = Flowable. just(1, 2, 3, 4, 5); + Flowable o2 = Flowable. just(6, 7, 8, 9, 10); + Flowable o = Flowable. merge(o1, o2).map(new Function() { @Override public String apply(Integer t) { @@ -116,9 +115,9 @@ public final void testMergeWithExecutorScheduler() { final String currentThreadName = Thread.currentThread().getName(); - Observable o1 = Observable. just(1, 2, 3, 4, 5); - Observable o2 = Observable. just(6, 7, 8, 9, 10); - Observable o = Observable. merge(o1, o2).subscribeOn(Schedulers.computation()).map(new Function() { + Flowable o1 = Flowable. just(1, 2, 3, 4, 5); + Flowable o2 = Flowable. just(6, 7, 8, 9, 10); + Flowable o = Flowable. merge(o1, o2).subscribeOn(Schedulers.computation()).map(new Function() { @Override public String apply(Integer t) { diff --git a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java index 10c087f873..c3a8534d83 100644 --- a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java @@ -26,7 +26,6 @@ import io.reactivex.disposables.Disposable; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.schedulers.*; -import io.reactivex.schedulers.Schedulers; public class ExecutorSchedulerTest extends AbstractSchedulerConcurrencyTests { diff --git a/src/test/java/io/reactivex/schedulers/NewThreadSchedulerTest.java b/src/test/java/io/reactivex/schedulers/NewThreadSchedulerTest.java index ed379213c6..d0964d147f 100644 --- a/src/test/java/io/reactivex/schedulers/NewThreadSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/NewThreadSchedulerTest.java @@ -16,7 +16,6 @@ import org.junit.*; import io.reactivex.Scheduler; -import io.reactivex.schedulers.Schedulers; public class NewThreadSchedulerTest extends AbstractSchedulerConcurrencyTests { diff --git a/src/test/java/io/reactivex/schedulers/SchedulerLifecycleTest.java b/src/test/java/io/reactivex/schedulers/SchedulerLifecycleTest.java index eba99ec5b1..70e23291f5 100644 --- a/src/test/java/io/reactivex/schedulers/SchedulerLifecycleTest.java +++ b/src/test/java/io/reactivex/schedulers/SchedulerLifecycleTest.java @@ -13,7 +13,7 @@ package io.reactivex.schedulers; -import static org.junit.Assert.*; +import static org.junit.Assert.fail; import java.util.*; import java.util.concurrent.*; @@ -22,7 +22,6 @@ import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.CompositeDisposable; -import io.reactivex.schedulers.Schedulers; public class SchedulerLifecycleTest { @Test diff --git a/src/test/java/io/reactivex/schedulers/SchedulerTests.java b/src/test/java/io/reactivex/schedulers/SchedulerTests.java index 972fefb0ad..7ed770588a 100644 --- a/src/test/java/io/reactivex/schedulers/SchedulerTests.java +++ b/src/test/java/io/reactivex/schedulers/SchedulerTests.java @@ -18,6 +18,7 @@ import java.util.concurrent.*; import io.reactivex.*; +import io.reactivex.subscribers.DefaultObserver; final class SchedulerTests { private SchedulerTests() { @@ -37,7 +38,7 @@ static void testUnhandledErrorIsDeliveredToThreadHandler(Scheduler scheduler) th CapturingUncaughtExceptionHandler handler = new CapturingUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(handler); IllegalStateException error = new IllegalStateException("Should be delivered to handler"); - Observable.error(error) + Flowable.error(error) .subscribeOn(scheduler) .subscribe(); @@ -72,7 +73,7 @@ static void testHandledErrorIsNotDeliveredToThreadHandler(Scheduler scheduler) t CapturingObserver observer = new CapturingObserver(); Thread.setDefaultUncaughtExceptionHandler(handler); IllegalStateException error = new IllegalStateException("Should be delivered to handler"); - Observable.error(error) + Flowable.error(error) .subscribeOn(scheduler) .subscribe(observer); @@ -109,7 +110,7 @@ public void uncaughtException(Thread t, Throwable e) { } } - private static final class CapturingObserver extends Observer { + private static final class CapturingObserver extends DefaultObserver { CountDownLatch completed = new CountDownLatch(1); int errorCount = 0; int nextCount = 0; diff --git a/src/test/java/io/reactivex/schedulers/TestSchedulerTest.java b/src/test/java/io/reactivex/schedulers/TestSchedulerTest.java index c33a847f92..acec22204d 100644 --- a/src/test/java/io/reactivex/schedulers/TestSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/TestSchedulerTest.java @@ -28,7 +28,6 @@ import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.schedulers.TestScheduler; public class TestSchedulerTest { @@ -180,8 +179,8 @@ public final void testNestedSchedule() { try { final Runnable calledOp = mock(Runnable.class); - Observable poller; - poller = Observable.create(new Publisher() { + Flowable poller; + poller = Flowable.create(new Publisher() { @Override public void subscribe(final Subscriber aSubscriber) { final BooleanSubscription bs = new BooleanSubscription(); diff --git a/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java b/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java index 8d04ec12ee..b4402b8e30 100644 --- a/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java @@ -24,11 +24,10 @@ import io.reactivex.*; import io.reactivex.Scheduler.Worker; import io.reactivex.disposables.*; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; public class TrampolineSchedulerTest extends AbstractSchedulerTests { @@ -42,9 +41,9 @@ public final void testMergeWithCurrentThreadScheduler1() { final String currentThreadName = Thread.currentThread().getName(); - Observable o1 = Observable. just(1, 2, 3, 4, 5); - Observable o2 = Observable. just(6, 7, 8, 9, 10); - Observable o = Observable. merge(o1, o2).subscribeOn(Schedulers.trampoline()).map(new Function() { + Flowable o1 = Flowable. just(1, 2, 3, 4, 5); + Flowable o2 = Flowable. just(6, 7, 8, 9, 10); + Flowable o = Flowable. merge(o1, o2).subscribeOn(Schedulers.trampoline()).map(new Function() { @Override public String apply(Integer t) { @@ -111,11 +110,11 @@ public void testTrampolineWorkerHandlesConcurrentScheduling() { final TestSubscriber ts = new TestSubscriber(observer); // Spam the trampoline with actions. - Observable.range(0, 50) + Flowable.range(0, 50) .flatMap(new Function>() { @Override public Publisher apply(Integer count) { - return Observable + return Flowable .interval(1, TimeUnit.MICROSECONDS) .map(new Function() { @Override diff --git a/src/test/java/io/reactivex/SingleNullTests.java b/src/test/java/io/reactivex/single/SingleNullTests.java similarity index 98% rename from src/test/java/io/reactivex/SingleNullTests.java rename to src/test/java/io/reactivex/single/SingleNullTests.java index 3850e5d871..7c2a4a19b7 100644 --- a/src/test/java/io/reactivex/SingleNullTests.java +++ b/src/test/java/io/reactivex/single/SingleNullTests.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.single; import java.lang.reflect.*; import java.util.*; @@ -20,6 +20,7 @@ import org.junit.*; import org.reactivestreams.*; +import io.reactivex.*; import io.reactivex.Single.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; @@ -87,7 +88,7 @@ public void concatIterableOneIsNull() { @Test(expected = NullPointerException.class) public void concatObservableNull() { - Single.concat((Observable>)null); + Single.concat((Flowable>)null); } @Test @@ -703,9 +704,9 @@ public void repeatWhenNull() { @Test(expected = NullPointerException.class) public void repeatWhenFunctionReturnsNull() { - error.repeatWhen(new Function, Publisher>() { + error.repeatWhen(new Function, Publisher>() { @Override - public Publisher apply(Observable v) { + public Publisher apply(Flowable v) { return null; } }).toBlocking().run(); @@ -733,9 +734,9 @@ public void retryWhenNull() { @Test(expected = NullPointerException.class) public void retryWhenFunctionReturnsNull() { - error.retryWhen(new Function, Publisher>() { + error.retryWhen(new Function, Publisher>() { @Override - public Publisher apply(Observable e) { + public Publisher apply(Flowable e) { return null; } }).get(); diff --git a/src/test/java/io/reactivex/SingleTest.java b/src/test/java/io/reactivex/single/SingleTest.java similarity index 99% rename from src/test/java/io/reactivex/SingleTest.java rename to src/test/java/io/reactivex/single/SingleTest.java index 68313c657a..ddaa64cfd6 100644 --- a/src/test/java/io/reactivex/SingleTest.java +++ b/src/test/java/io/reactivex/single/SingleTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.single; import static org.junit.Assert.*; @@ -21,6 +21,7 @@ import org.junit.Test; +import io.reactivex.*; import io.reactivex.Single.*; import io.reactivex.disposables.*; import io.reactivex.functions.*; @@ -443,7 +444,7 @@ public void accept(SingleSubscriber t) { @Test public void testToObservable() { - Observable a = Single.just("a").toFlowable(); + Flowable a = Single.just("a").toFlowable(); TestSubscriber ts = new TestSubscriber(); a.subscribe(ts); ts.assertValue("a"); diff --git a/src/test/java/io/reactivex/subjects/nbp/NbpAsyncSubjectTest.java b/src/test/java/io/reactivex/subjects/NbpAsyncSubjectTest.java similarity index 85% rename from src/test/java/io/reactivex/subjects/nbp/NbpAsyncSubjectTest.java rename to src/test/java/io/reactivex/subjects/NbpAsyncSubjectTest.java index c39c56cc3e..3649e7c044 100644 --- a/src/test/java/io/reactivex/subjects/nbp/NbpAsyncSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/NbpAsyncSubjectTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects.nbp; +package io.reactivex.subjects; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -23,12 +23,11 @@ import org.junit.*; import org.mockito.*; -import io.reactivex.TestHelper; -import io.reactivex.NbpObservable.NbpSubscriber; +import io.reactivex.Observer; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Consumer; -import io.reactivex.subjects.nbp.NbpAsyncSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.TestObserver; public class NbpAsyncSubjectTest { @@ -36,9 +35,9 @@ public class NbpAsyncSubjectTest { @Test public void testNeverCompleted() { - NbpAsyncSubject subject = NbpAsyncSubject.create(); + AsyncSubject subject = AsyncSubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -52,9 +51,9 @@ public void testNeverCompleted() { @Test public void testCompleted() { - NbpAsyncSubject subject = NbpAsyncSubject.create(); + AsyncSubject subject = AsyncSubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -70,9 +69,9 @@ public void testCompleted() { @Test @Ignore("Null values not allowed") public void testNull() { - NbpAsyncSubject subject = NbpAsyncSubject.create(); + AsyncSubject subject = AsyncSubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext(null); @@ -85,9 +84,9 @@ public void testNull() { @Test public void testSubscribeAfterCompleted() { - NbpAsyncSubject subject = NbpAsyncSubject.create(); + AsyncSubject subject = AsyncSubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.onNext("one"); subject.onNext("two"); @@ -103,9 +102,9 @@ public void testSubscribeAfterCompleted() { @Test public void testSubscribeAfterError() { - NbpAsyncSubject subject = NbpAsyncSubject.create(); + AsyncSubject subject = AsyncSubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.onNext("one"); subject.onNext("two"); @@ -123,9 +122,9 @@ public void testSubscribeAfterError() { @Test public void testError() { - NbpAsyncSubject subject = NbpAsyncSubject.create(); + AsyncSubject subject = AsyncSubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -143,10 +142,10 @@ public void testError() { @Test public void testUnsubscribeBeforeCompleted() { - NbpAsyncSubject subject = NbpAsyncSubject.create(); + AsyncSubject subject = AsyncSubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(observer); + Observer observer = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(observer); subject.subscribe(ts); subject.onNext("one"); @@ -168,9 +167,9 @@ public void testUnsubscribeBeforeCompleted() { @Test public void testEmptySubjectCompleted() { - NbpAsyncSubject subject = NbpAsyncSubject.create(); + AsyncSubject subject = AsyncSubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onComplete(); @@ -194,7 +193,7 @@ public void testSubscribeCompletionRaceCondition() { * With the synchronization code in place I can not get this to fail on my laptop. */ for (int i = 0; i < 50; i++) { - final NbpAsyncSubject subject = NbpAsyncSubject.create(); + final AsyncSubject subject = AsyncSubject.create(); final AtomicReference value1 = new AtomicReference(); subject.subscribe(new Consumer() { @@ -252,10 +251,10 @@ public void run() { private static class SubjectSubscriberThread extends Thread { - private final NbpAsyncSubject subject; + private final AsyncSubject subject; private final AtomicReference value = new AtomicReference(); - public SubjectSubscriberThread(NbpAsyncSubject subject) { + public SubjectSubscriberThread(AsyncSubject subject) { this.subject = subject; } @@ -320,7 +319,7 @@ public void run() { @Test public void testCurrentStateMethodsNormal() { - NbpAsyncSubject as = NbpAsyncSubject.create(); + AsyncSubject as = AsyncSubject.create(); assertFalse(as.hasValue()); assertFalse(as.hasThrowable()); @@ -346,7 +345,7 @@ public void testCurrentStateMethodsNormal() { @Test public void testCurrentStateMethodsEmpty() { - NbpAsyncSubject as = NbpAsyncSubject.create(); + AsyncSubject as = AsyncSubject.create(); assertFalse(as.hasValue()); assertFalse(as.hasThrowable()); @@ -364,7 +363,7 @@ public void testCurrentStateMethodsEmpty() { } @Test public void testCurrentStateMethodsError() { - NbpAsyncSubject as = NbpAsyncSubject.create(); + AsyncSubject as = AsyncSubject.create(); assertFalse(as.hasValue()); assertFalse(as.hasThrowable()); diff --git a/src/test/java/io/reactivex/subjects/nbp/NbpBehaviorSubjectTest.java b/src/test/java/io/reactivex/subjects/NbpBehaviorSubjectTest.java similarity index 81% rename from src/test/java/io/reactivex/subjects/nbp/NbpBehaviorSubjectTest.java rename to src/test/java/io/reactivex/subjects/NbpBehaviorSubjectTest.java index 5aa64e0b85..d33c085276 100644 --- a/src/test/java/io/reactivex/subjects/nbp/NbpBehaviorSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/NbpBehaviorSubjectTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects.nbp; +package io.reactivex.subjects; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -24,12 +24,11 @@ import org.mockito.*; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; +import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.nbp.NbpBehaviorSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpBehaviorSubjectTest { @@ -37,9 +36,9 @@ public class NbpBehaviorSubjectTest { @Test public void testThatSubscriberReceivesDefaultValueAndSubsequentEvents() { - NbpBehaviorSubject subject = NbpBehaviorSubject.createDefault("default"); + BehaviorSubject subject = BehaviorSubject.createDefault("default"); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -56,11 +55,11 @@ public void testThatSubscriberReceivesDefaultValueAndSubsequentEvents() { @Test public void testThatSubscriberReceivesLatestAndThenSubsequentEvents() { - NbpBehaviorSubject subject = NbpBehaviorSubject.createDefault("default"); + BehaviorSubject subject = BehaviorSubject.createDefault("default"); subject.onNext("one"); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("two"); @@ -76,9 +75,9 @@ public void testThatSubscriberReceivesLatestAndThenSubsequentEvents() { @Test public void testSubscribeThenOnComplete() { - NbpBehaviorSubject subject = NbpBehaviorSubject.createDefault("default"); + BehaviorSubject subject = BehaviorSubject.createDefault("default"); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -92,11 +91,11 @@ public void testSubscribeThenOnComplete() { @Test public void testSubscribeToCompletedOnlyEmitsOnComplete() { - NbpBehaviorSubject subject = NbpBehaviorSubject.createDefault("default"); + BehaviorSubject subject = BehaviorSubject.createDefault("default"); subject.onNext("one"); subject.onComplete(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); verify(observer, never()).onNext("default"); @@ -107,12 +106,12 @@ public void testSubscribeToCompletedOnlyEmitsOnComplete() { @Test public void testSubscribeToErrorOnlyEmitsOnError() { - NbpBehaviorSubject subject = NbpBehaviorSubject.createDefault("default"); + BehaviorSubject subject = BehaviorSubject.createDefault("default"); subject.onNext("one"); RuntimeException re = new RuntimeException("test error"); subject.onError(re); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); verify(observer, never()).onNext("default"); @@ -123,12 +122,12 @@ public void testSubscribeToErrorOnlyEmitsOnError() { @Test public void testCompletedStopsEmittingData() { - NbpBehaviorSubject channel = NbpBehaviorSubject.createDefault(2013); - NbpSubscriber observerA = TestHelper.mockNbpSubscriber(); - NbpSubscriber observerB = TestHelper.mockNbpSubscriber(); - NbpSubscriber observerC = TestHelper.mockNbpSubscriber(); + BehaviorSubject channel = BehaviorSubject.createDefault(2013); + Observer observerA = TestHelper.mockNbpSubscriber(); + Observer observerB = TestHelper.mockNbpSubscriber(); + Observer observerC = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(observerA); + TestObserver ts = new TestObserver(observerA); channel.subscribe(ts); channel.subscribe(observerB); @@ -168,9 +167,9 @@ public void testCompletedStopsEmittingData() { @Test public void testCompletedAfterErrorIsNotSent() { - NbpBehaviorSubject subject = NbpBehaviorSubject.createDefault("default"); + BehaviorSubject subject = BehaviorSubject.createDefault("default"); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -187,9 +186,9 @@ public void testCompletedAfterErrorIsNotSent() { @Test public void testCompletedAfterErrorIsNotSent2() { - NbpBehaviorSubject subject = NbpBehaviorSubject.createDefault("default"); + BehaviorSubject subject = BehaviorSubject.createDefault("default"); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -203,7 +202,7 @@ public void testCompletedAfterErrorIsNotSent2() { verify(observer, never()).onNext("two"); verify(observer, never()).onComplete(); - NbpSubscriber o2 = TestHelper.mockNbpSubscriber(); + Observer o2 = TestHelper.mockNbpSubscriber(); subject.subscribe(o2); verify(o2, times(1)).onError(testException); verify(o2, never()).onNext(any()); @@ -212,9 +211,9 @@ public void testCompletedAfterErrorIsNotSent2() { @Test public void testCompletedAfterErrorIsNotSent3() { - NbpBehaviorSubject subject = NbpBehaviorSubject.createDefault("default"); + BehaviorSubject subject = BehaviorSubject.createDefault("default"); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -228,7 +227,7 @@ public void testCompletedAfterErrorIsNotSent3() { verify(observer, never()).onError(any(Throwable.class)); verify(observer, never()).onNext("two"); - NbpSubscriber o2 = TestHelper.mockNbpSubscriber(); + Observer o2 = TestHelper.mockNbpSubscriber(); subject.subscribe(o2); verify(o2, times(1)).onComplete(); verify(o2, never()).onNext(any()); @@ -237,23 +236,23 @@ public void testCompletedAfterErrorIsNotSent3() { @Test(timeout = 1000) public void testUnsubscriptionCase() { - NbpBehaviorSubject src = NbpBehaviorSubject.createDefault("null"); // FIXME was plain null which is not allowed + BehaviorSubject src = BehaviorSubject.createDefault("null"); // FIXME was plain null which is not allowed for (int i = 0; i < 10; i++) { - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + final Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); String v = "" + i; src.onNext(v); System.out.printf("Turn: %d%n", i); src.first() - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public NbpObservable apply(String t1) { - return NbpObservable.just(t1 + ", " + t1); + public Observable apply(String t1) { + return Observable.just(t1 + ", " + t1); } }) - .subscribe(new NbpObserver() { + .subscribe(new DefaultObserver() { @Override public void onNext(String t) { o.onNext(t); @@ -276,8 +275,8 @@ public void onComplete() { } @Test public void testStartEmpty() { - NbpBehaviorSubject source = NbpBehaviorSubject.create(); - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + BehaviorSubject source = BehaviorSubject.create(); + final Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.subscribe(o); @@ -301,8 +300,8 @@ public void testStartEmpty() { } @Test public void testStartEmptyThenAddOne() { - NbpBehaviorSubject source = NbpBehaviorSubject.create(); - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + BehaviorSubject source = BehaviorSubject.create(); + final Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); source.onNext(1); @@ -323,8 +322,8 @@ public void testStartEmptyThenAddOne() { } @Test public void testStartEmptyCompleteWithOne() { - NbpBehaviorSubject source = NbpBehaviorSubject.create(); - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + BehaviorSubject source = BehaviorSubject.create(); + final Observer o = TestHelper.mockNbpSubscriber(); source.onNext(1); source.onComplete(); @@ -340,8 +339,8 @@ public void testStartEmptyCompleteWithOne() { @Test public void testTakeOneSubscriber() { - NbpBehaviorSubject source = NbpBehaviorSubject.createDefault(1); - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + BehaviorSubject source = BehaviorSubject.createDefault(1); + final Observer o = TestHelper.mockNbpSubscriber(); source.take(1).subscribe(o); @@ -407,7 +406,7 @@ public void testEmissionSubscriptionRace() throws Exception { if (i % 1000 == 0) { System.out.println(i); } - final NbpBehaviorSubject rs = NbpBehaviorSubject.create(); + final BehaviorSubject rs = BehaviorSubject.create(); final CountDownLatch finish = new CountDownLatch(1); final CountDownLatch start = new CountDownLatch(1); @@ -427,7 +426,7 @@ public void run() { final AtomicReference o = new AtomicReference(); rs.subscribeOn(s).observeOn(Schedulers.io()) - .subscribe(new NbpObserver() { + .subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -473,7 +472,7 @@ public void run() { @Test public void testCurrentStateMethodsNormalEmptyStart() { - NbpBehaviorSubject as = NbpBehaviorSubject.create(); + BehaviorSubject as = BehaviorSubject.create(); assertFalse(as.hasValue()); assertFalse(as.hasThrowable()); @@ -500,7 +499,7 @@ public void testCurrentStateMethodsNormalEmptyStart() { @Test public void testCurrentStateMethodsNormalSomeStart() { - NbpBehaviorSubject as = NbpBehaviorSubject.createDefault((Object)1); + BehaviorSubject as = BehaviorSubject.createDefault((Object)1); assertTrue(as.hasValue()); assertFalse(as.hasThrowable()); @@ -526,7 +525,7 @@ public void testCurrentStateMethodsNormalSomeStart() { @Test public void testCurrentStateMethodsEmpty() { - NbpBehaviorSubject as = NbpBehaviorSubject.create(); + BehaviorSubject as = BehaviorSubject.create(); assertFalse(as.hasValue()); assertFalse(as.hasThrowable()); @@ -544,7 +543,7 @@ public void testCurrentStateMethodsEmpty() { } @Test public void testCurrentStateMethodsError() { - NbpBehaviorSubject as = NbpBehaviorSubject.create(); + BehaviorSubject as = BehaviorSubject.create(); assertFalse(as.hasValue()); assertFalse(as.hasThrowable()); diff --git a/src/test/java/io/reactivex/subjects/nbp/NbpPublishSubjectTest.java b/src/test/java/io/reactivex/subjects/NbpPublishSubjectTest.java similarity index 78% rename from src/test/java/io/reactivex/subjects/nbp/NbpPublishSubjectTest.java rename to src/test/java/io/reactivex/subjects/NbpPublishSubjectTest.java index 69e0d4b2e8..bff0132214 100644 --- a/src/test/java/io/reactivex/subjects/nbp/NbpPublishSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/NbpPublishSubjectTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects.nbp; +package io.reactivex.subjects; import static org.junit.Assert.*; import static org.mockito.Matchers.any; @@ -24,20 +24,19 @@ import org.mockito.*; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.*; -import io.reactivex.subjects.PublishSubject; -import io.reactivex.subjects.nbp.NbpPublishSubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.*; +import io.reactivex.processors.PublishProcessor; public class NbpPublishSubjectTest { @Test public void testCompleted() { - NbpPublishSubject subject = NbpPublishSubject.create(); + PublishSubject subject = PublishSubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -45,7 +44,7 @@ public void testCompleted() { subject.onNext("three"); subject.onComplete(); - NbpSubscriber anotherSubscriber = TestHelper.mockNbpSubscriber(); + Observer anotherSubscriber = TestHelper.mockNbpSubscriber(); subject.subscribe(anotherSubscriber); subject.onNext("four"); @@ -58,12 +57,12 @@ public void testCompleted() { @Test public void testCompletedStopsEmittingData() { - NbpPublishSubject channel = NbpPublishSubject.create(); - NbpSubscriber observerA = TestHelper.mockNbpSubscriber(); - NbpSubscriber observerB = TestHelper.mockNbpSubscriber(); - NbpSubscriber observerC = TestHelper.mockNbpSubscriber(); + PublishSubject channel = PublishSubject.create(); + Observer observerA = TestHelper.mockNbpSubscriber(); + Observer observerB = TestHelper.mockNbpSubscriber(); + Observer observerC = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(observerA); + TestObserver ts = new TestObserver(observerA); channel.subscribe(ts); channel.subscribe(observerB); @@ -98,7 +97,7 @@ public void testCompletedStopsEmittingData() { inOrderC.verifyNoMoreInteractions(); } - private void assertCompletedSubscriber(NbpSubscriber observer) { + private void assertCompletedSubscriber(Observer observer) { verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, times(1)).onNext("three"); @@ -108,9 +107,9 @@ private void assertCompletedSubscriber(NbpSubscriber observer) { @Test public void testError() { - NbpPublishSubject subject = NbpPublishSubject.create(); + PublishSubject subject = PublishSubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -118,7 +117,7 @@ public void testError() { subject.onNext("three"); subject.onError(testException); - NbpSubscriber anotherSubscriber = TestHelper.mockNbpSubscriber(); + Observer anotherSubscriber = TestHelper.mockNbpSubscriber(); subject.subscribe(anotherSubscriber); subject.onNext("four"); @@ -129,7 +128,7 @@ public void testError() { // todo bug? assertNeverSubscriber(anotherSubscriber); } - private void assertErrorSubscriber(NbpSubscriber observer) { + private void assertErrorSubscriber(Observer observer) { verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, times(1)).onNext("three"); @@ -139,9 +138,9 @@ private void assertErrorSubscriber(NbpSubscriber observer) { @Test public void testSubscribeMidSequence() { - NbpPublishSubject subject = NbpPublishSubject.create(); + PublishSubject subject = PublishSubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -149,7 +148,7 @@ public void testSubscribeMidSequence() { assertObservedUntilTwo(observer); - NbpSubscriber anotherSubscriber = TestHelper.mockNbpSubscriber(); + Observer anotherSubscriber = TestHelper.mockNbpSubscriber(); subject.subscribe(anotherSubscriber); subject.onNext("three"); @@ -159,7 +158,7 @@ public void testSubscribeMidSequence() { assertCompletedStartingWithThreeSubscriber(anotherSubscriber); } - private void assertCompletedStartingWithThreeSubscriber(NbpSubscriber observer) { + private void assertCompletedStartingWithThreeSubscriber(Observer observer) { verify(observer, Mockito.never()).onNext("one"); verify(observer, Mockito.never()).onNext("two"); verify(observer, times(1)).onNext("three"); @@ -169,10 +168,10 @@ private void assertCompletedStartingWithThreeSubscriber(NbpSubscriber ob @Test public void testUnsubscribeFirstSubscriber() { - NbpPublishSubject subject = NbpPublishSubject.create(); + PublishSubject subject = PublishSubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(observer); + Observer observer = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(observer); subject.subscribe(ts); subject.onNext("one"); @@ -181,7 +180,7 @@ public void testUnsubscribeFirstSubscriber() { ts.dispose(); assertObservedUntilTwo(observer); - NbpSubscriber anotherSubscriber = TestHelper.mockNbpSubscriber(); + Observer anotherSubscriber = TestHelper.mockNbpSubscriber(); subject.subscribe(anotherSubscriber); subject.onNext("three"); @@ -191,7 +190,7 @@ public void testUnsubscribeFirstSubscriber() { assertCompletedStartingWithThreeSubscriber(anotherSubscriber); } - private void assertObservedUntilTwo(NbpSubscriber observer) { + private void assertObservedUntilTwo(Observer observer) { verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, Mockito.never()).onNext("three"); @@ -201,7 +200,7 @@ private void assertObservedUntilTwo(NbpSubscriber observer) { @Test public void testNestedSubscribe() { - final NbpPublishSubject s = NbpPublishSubject.create(); + final PublishSubject s = PublishSubject.create(); final AtomicInteger countParent = new AtomicInteger(); final AtomicInteger countChildren = new AtomicInteger(); @@ -209,10 +208,10 @@ public void testNestedSubscribe() { final ArrayList list = new ArrayList(); - s.flatMap(new Function>() { + s.flatMap(new Function>() { @Override - public NbpObservable apply(final Integer v) { + public Observable apply(final Integer v) { countParent.incrementAndGet(); // then subscribe to subject again (it will not receive the previous value) @@ -255,10 +254,10 @@ public void accept(String v) { */ @Test public void testReSubscribe() { - final NbpPublishSubject ps = NbpPublishSubject.create(); + final PublishSubject ps = PublishSubject.create(); - NbpSubscriber o1 = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(o1); + Observer o1 = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(o1); ps.subscribe(ts); // emit @@ -275,8 +274,8 @@ public void testReSubscribe() { // emit again but nothing will be there to receive it ps.onNext(2); - NbpSubscriber o2 = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts2 = new NbpTestSubscriber(o2); + Observer o2 = TestHelper.mockNbpSubscriber(); + TestObserver ts2 = new TestObserver(o2); ps.subscribe(ts2); // emit @@ -294,22 +293,22 @@ public void testReSubscribe() { @Test(timeout = 1000) public void testUnsubscriptionCase() { - NbpPublishSubject src = NbpPublishSubject.create(); + PublishSubject src = PublishSubject.create(); for (int i = 0; i < 10; i++) { - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + final Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); String v = "" + i; System.out.printf("Turn: %d%n", i); src.first() - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public NbpObservable apply(String t1) { - return NbpObservable.just(t1 + ", " + t1); + public Observable apply(String t1) { + return Observable.just(t1 + ", " + t1); } }) - .subscribe(new NbpObserver() { + .subscribe(new DefaultObserver() { @Override public void onNext(String t) { o.onNext(t); @@ -381,7 +380,7 @@ public void onComplete() { // } @Test public void testCurrentStateMethodsNormal() { - PublishSubject as = PublishSubject.create(); + PublishProcessor as = PublishProcessor.create(); assertFalse(as.hasThrowable()); assertFalse(as.hasComplete()); @@ -402,7 +401,7 @@ public void testCurrentStateMethodsNormal() { @Test public void testCurrentStateMethodsEmpty() { - PublishSubject as = PublishSubject.create(); + PublishProcessor as = PublishProcessor.create(); assertFalse(as.hasThrowable()); assertFalse(as.hasComplete()); @@ -416,7 +415,7 @@ public void testCurrentStateMethodsEmpty() { } @Test public void testCurrentStateMethodsError() { - PublishSubject as = PublishSubject.create(); + PublishProcessor as = PublishProcessor.create(); assertFalse(as.hasThrowable()); assertFalse(as.hasComplete()); diff --git a/src/test/java/io/reactivex/subjects/nbp/NbpReplaySubjectBoundedConcurrencyTest.java b/src/test/java/io/reactivex/subjects/NbpReplaySubjectBoundedConcurrencyTest.java similarity index 91% rename from src/test/java/io/reactivex/subjects/nbp/NbpReplaySubjectBoundedConcurrencyTest.java rename to src/test/java/io/reactivex/subjects/NbpReplaySubjectBoundedConcurrencyTest.java index 287c19851f..45fab1d855 100644 --- a/src/test/java/io/reactivex/subjects/nbp/NbpReplaySubjectBoundedConcurrencyTest.java +++ b/src/test/java/io/reactivex/subjects/NbpReplaySubjectBoundedConcurrencyTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects.nbp; +package io.reactivex.subjects; import static org.junit.Assert.assertEquals; @@ -22,26 +22,27 @@ import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.functions.Consumer; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.nbp.NbpReplaySubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpReplaySubjectBoundedConcurrencyTest { @Test(timeout = 4000) public void testReplaySubjectConcurrentSubscribersDoingReplayDontBlockEachOther() throws InterruptedException { - final NbpReplaySubject replay = NbpReplaySubject.createUnbounded(); + final ReplaySubject replay = ReplaySubject.createUnbounded(); Thread source = new Thread(new Runnable() { @Override public void run() { - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber o) { + public void accept(Observer o) { o.onSubscribe(EmptyDisposable.INSTANCE); System.out.println("********* Start Source Data ***********"); for (long l = 1; l <= 10000; l++) { @@ -64,7 +65,7 @@ public void accept(NbpSubscriber o) { @Override public void run() { - NbpSubscriber slow = new NbpObserver() { + Observer slow = new DefaultObserver() { @Override public void onComplete() { @@ -105,7 +106,7 @@ public void onNext(Long args) { @Override public void run() { final CountDownLatch fastLatch = new CountDownLatch(1); - NbpSubscriber fast = new NbpObserver() { + Observer fast = new DefaultObserver() { @Override public void onComplete() { @@ -143,15 +144,15 @@ public void onNext(Long args) { @Test public void testReplaySubjectConcurrentSubscriptions() throws InterruptedException { - final NbpReplaySubject replay = NbpReplaySubject.createUnbounded(); + final ReplaySubject replay = ReplaySubject.createUnbounded(); Thread source = new Thread(new Runnable() { @Override public void run() { - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber o) { + public void accept(Observer o) { o.onSubscribe(EmptyDisposable.INSTANCE); System.out.println("********* Start Source Data ***********"); for (long l = 1; l <= 10000; l++) { @@ -231,7 +232,7 @@ public void run() { @Test(timeout = 10000) public void testSubscribeCompletionRaceCondition() { for (int i = 0; i < 50; i++) { - final NbpReplaySubject subject = NbpReplaySubject.createUnbounded(); + final ReplaySubject subject = ReplaySubject.createUnbounded(); final AtomicReference value1 = new AtomicReference(); subject.subscribe(new Consumer() { @@ -294,8 +295,8 @@ public void run() { public void testRaceForTerminalState() { final List expected = Arrays.asList(1); for (int i = 0; i < 100000; i++) { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts); ts.awaitTerminalEvent(); ts.assertValueSequence(expected); ts.assertTerminated(); @@ -304,10 +305,10 @@ public void testRaceForTerminalState() { private static class SubjectObserverThread extends Thread { - private final NbpReplaySubject subject; + private final ReplaySubject subject; private final AtomicReference value = new AtomicReference(); - public SubjectObserverThread(NbpReplaySubject subject) { + public SubjectObserverThread(ReplaySubject subject) { this.subject = subject; } @@ -331,7 +332,7 @@ public void testReplaySubjectEmissionSubscriptionRace() throws Exception { if (i % 1000 == 0) { System.out.println(i); } - final NbpReplaySubject rs = NbpReplaySubject.createWithSize(2); + final ReplaySubject rs = ReplaySubject.createWithSize(2); final CountDownLatch finish = new CountDownLatch(1); final CountDownLatch start = new CountDownLatch(1); @@ -359,7 +360,7 @@ public void run() { .subscribeOn(s) .observeOn(Schedulers.io()) // .doOnNext(e -> System.out.println(">>> " + j)) - .subscribe(new NbpObserver() { + .subscribe(new DefaultObserver() { @Override protected void onStart() { @@ -409,7 +410,7 @@ public void run() { } @Test(timeout = 5000) public void testConcurrentSizeAndHasAnyValue() throws InterruptedException { - final NbpReplaySubject rs = NbpReplaySubject.createUnbounded(); + final ReplaySubject rs = ReplaySubject.createUnbounded(); final CyclicBarrier cb = new CyclicBarrier(2); Thread t = new Thread(new Runnable() { @@ -463,7 +464,7 @@ public void run() { } @Test(timeout = 5000) public void testConcurrentSizeAndHasAnyValueBounded() throws InterruptedException { - final NbpReplaySubject rs = NbpReplaySubject.createWithSize(3); + final ReplaySubject rs = ReplaySubject.createWithSize(3); final CyclicBarrier cb = new CyclicBarrier(2); Thread t = new Thread(new Runnable() { @@ -506,7 +507,7 @@ public void run() { } @Test(timeout = 10000) public void testConcurrentSizeAndHasAnyValueTimeBounded() throws InterruptedException { - final NbpReplaySubject rs = NbpReplaySubject.createWithTime(1, TimeUnit.MILLISECONDS, Schedulers.computation()); + final ReplaySubject rs = ReplaySubject.createWithTime(1, TimeUnit.MILLISECONDS, Schedulers.computation()); final CyclicBarrier cb = new CyclicBarrier(2); Thread t = new Thread(new Runnable() { diff --git a/src/test/java/io/reactivex/subjects/nbp/NbpReplaySubjectConcurrencyTest.java b/src/test/java/io/reactivex/subjects/NbpReplaySubjectConcurrencyTest.java similarity index 91% rename from src/test/java/io/reactivex/subjects/nbp/NbpReplaySubjectConcurrencyTest.java rename to src/test/java/io/reactivex/subjects/NbpReplaySubjectConcurrencyTest.java index 150e4a9371..70e7e6b17e 100644 --- a/src/test/java/io/reactivex/subjects/nbp/NbpReplaySubjectConcurrencyTest.java +++ b/src/test/java/io/reactivex/subjects/NbpReplaySubjectConcurrencyTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects.nbp; +package io.reactivex.subjects; import static org.junit.Assert.assertEquals; @@ -22,26 +22,27 @@ import org.junit.*; import io.reactivex.*; -import io.reactivex.NbpObservable.*; +import io.reactivex.Observable; +import io.reactivex.Observable.NbpOnSubscribe; +import io.reactivex.Observer; import io.reactivex.functions.Consumer; import io.reactivex.internal.disposables.EmptyDisposable; +import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.nbp.NbpReplaySubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpReplaySubjectConcurrencyTest { @Test(timeout = 4000) public void testNbpReplaySubjectConcurrentSubscribersDoingReplayDontBlockEachOther() throws InterruptedException { - final NbpReplaySubject replay = NbpReplaySubject.create(); + final ReplaySubject replay = ReplaySubject.create(); Thread source = new Thread(new Runnable() { @Override public void run() { - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber o) { + public void accept(Observer o) { o.onSubscribe(EmptyDisposable.INSTANCE); System.out.println("********* Start Source Data ***********"); for (long l = 1; l <= 10000; l++) { @@ -64,7 +65,7 @@ public void accept(NbpSubscriber o) { @Override public void run() { - NbpSubscriber slow = new NbpObserver() { + Observer slow = new DefaultObserver() { @Override public void onComplete() { @@ -105,7 +106,7 @@ public void onNext(Long args) { @Override public void run() { final CountDownLatch fastLatch = new CountDownLatch(1); - NbpSubscriber fast = new NbpObserver() { + Observer fast = new DefaultObserver() { @Override public void onComplete() { @@ -143,15 +144,15 @@ public void onNext(Long args) { @Test public void testNbpReplaySubjectConcurrentSubscriptions() throws InterruptedException { - final NbpReplaySubject replay = NbpReplaySubject.create(); + final ReplaySubject replay = ReplaySubject.create(); Thread source = new Thread(new Runnable() { @Override public void run() { - NbpObservable.create(new NbpOnSubscribe() { + Observable.create(new NbpOnSubscribe() { @Override - public void accept(NbpSubscriber o) { + public void accept(Observer o) { o.onSubscribe(EmptyDisposable.INSTANCE); System.out.println("********* Start Source Data ***********"); for (long l = 1; l <= 10000; l++) { @@ -231,7 +232,7 @@ public void run() { @Test(timeout = 10000) public void testSubscribeCompletionRaceCondition() { for (int i = 0; i < 50; i++) { - final NbpReplaySubject subject = NbpReplaySubject.create(); + final ReplaySubject subject = ReplaySubject.create(); final AtomicReference value1 = new AtomicReference(); subject.subscribe(new Consumer() { @@ -294,8 +295,8 @@ public void run() { public void testRaceForTerminalState() { final List expected = Arrays.asList(1); for (int i = 0; i < 100000; i++) { - NbpTestSubscriber ts = new NbpTestSubscriber(); - NbpObservable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts); + TestObserver ts = new TestObserver(); + Observable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts); ts.awaitTerminalEvent(); ts.assertValueSequence(expected); ts.assertTerminated(); @@ -304,10 +305,10 @@ public void testRaceForTerminalState() { private static class SubjectObserverThread extends Thread { - private final NbpReplaySubject subject; + private final ReplaySubject subject; private final AtomicReference value = new AtomicReference(); - public SubjectObserverThread(NbpReplaySubject subject) { + public SubjectObserverThread(ReplaySubject subject) { this.subject = subject; } @@ -331,7 +332,7 @@ public void testNbpReplaySubjectEmissionSubscriptionRace() throws Exception { if (i % 1000 == 0) { System.out.println(i); } - final NbpReplaySubject rs = NbpReplaySubject.create(); + final ReplaySubject rs = ReplaySubject.create(); final CountDownLatch finish = new CountDownLatch(1); final CountDownLatch start = new CountDownLatch(1); @@ -351,7 +352,7 @@ public void run() { final AtomicReference o = new AtomicReference(); rs.subscribeOn(s).observeOn(Schedulers.io()) - .subscribe(new NbpObserver() { + .subscribe(new DefaultObserver() { @Override public void onComplete() { @@ -397,7 +398,7 @@ public void run() { } @Test(timeout = 10000) public void testConcurrentSizeAndHasAnyValue() throws InterruptedException { - final NbpReplaySubject rs = NbpReplaySubject.create(); + final ReplaySubject rs = ReplaySubject.create(); final CyclicBarrier cb = new CyclicBarrier(2); Thread t = new Thread(new Runnable() { diff --git a/src/test/java/io/reactivex/subjects/nbp/NbpReplaySubjectTest.java b/src/test/java/io/reactivex/subjects/NbpReplaySubjectTest.java similarity index 82% rename from src/test/java/io/reactivex/subjects/nbp/NbpReplaySubjectTest.java rename to src/test/java/io/reactivex/subjects/NbpReplaySubjectTest.java index 71f84fd97f..b79bc038c6 100644 --- a/src/test/java/io/reactivex/subjects/nbp/NbpReplaySubjectTest.java +++ b/src/test/java/io/reactivex/subjects/NbpReplaySubjectTest.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects.nbp; +package io.reactivex.subjects; import static org.junit.Assert.*; import static org.mockito.Matchers.*; @@ -25,13 +25,12 @@ import org.mockito.*; import io.reactivex.*; -import io.reactivex.NbpObservable.NbpSubscriber; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Function; +import io.reactivex.observers.*; import io.reactivex.schedulers.*; -import io.reactivex.subjects.nbp.NbpReplaySubject; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; public class NbpReplaySubjectTest { @@ -39,9 +38,9 @@ public class NbpReplaySubjectTest { @Test public void testCompleted() { - NbpReplaySubject subject = NbpReplaySubject.create(); + ReplaySubject subject = ReplaySubject.create(); - NbpSubscriber o1 = TestHelper.mockNbpSubscriber(); + Observer o1 = TestHelper.mockNbpSubscriber(); subject.subscribe(o1); subject.onNext("one"); @@ -56,19 +55,19 @@ public void testCompleted() { assertCompletedSubscriber(o1); // assert that subscribing a 2nd time gets the same data - NbpSubscriber o2 = TestHelper.mockNbpSubscriber(); + Observer o2 = TestHelper.mockNbpSubscriber(); subject.subscribe(o2); assertCompletedSubscriber(o2); } @Test public void testCompletedStopsEmittingData() { - NbpReplaySubject channel = NbpReplaySubject.create(); - NbpSubscriber observerA = TestHelper.mockNbpSubscriber(); - NbpSubscriber observerB = TestHelper.mockNbpSubscriber(); - NbpSubscriber observerC = TestHelper.mockNbpSubscriber(); - NbpSubscriber observerD = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(observerA); + ReplaySubject channel = ReplaySubject.create(); + Observer observerA = TestHelper.mockNbpSubscriber(); + Observer observerB = TestHelper.mockNbpSubscriber(); + Observer observerC = TestHelper.mockNbpSubscriber(); + Observer observerD = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(observerA); channel.subscribe(ts); channel.subscribe(observerB); @@ -132,9 +131,9 @@ public void testCompletedStopsEmittingData() { @Test public void testCompletedAfterError() { - NbpReplaySubject subject = NbpReplaySubject.create(); + ReplaySubject subject = ReplaySubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.onNext("one"); subject.onError(testException); @@ -149,7 +148,7 @@ public void testCompletedAfterError() { verifyNoMoreInteractions(observer); } - private void assertCompletedSubscriber(NbpSubscriber observer) { + private void assertCompletedSubscriber(Observer observer) { InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext("one"); @@ -162,9 +161,9 @@ private void assertCompletedSubscriber(NbpSubscriber observer) { @Test public void testError() { - NbpReplaySubject subject = NbpReplaySubject.create(); + ReplaySubject subject = ReplaySubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -183,7 +182,7 @@ public void testError() { assertErrorSubscriber(observer); } - private void assertErrorSubscriber(NbpSubscriber observer) { + private void assertErrorSubscriber(Observer observer) { verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, times(1)).onNext("three"); @@ -193,9 +192,9 @@ private void assertErrorSubscriber(NbpSubscriber observer) { @Test public void testSubscribeMidSequence() { - NbpReplaySubject subject = NbpReplaySubject.create(); + ReplaySubject subject = ReplaySubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); + Observer observer = TestHelper.mockNbpSubscriber(); subject.subscribe(observer); subject.onNext("one"); @@ -203,7 +202,7 @@ public void testSubscribeMidSequence() { assertObservedUntilTwo(observer); - NbpSubscriber anotherSubscriber = TestHelper.mockNbpSubscriber(); + Observer anotherSubscriber = TestHelper.mockNbpSubscriber(); subject.subscribe(anotherSubscriber); assertObservedUntilTwo(anotherSubscriber); @@ -216,10 +215,10 @@ public void testSubscribeMidSequence() { @Test public void testUnsubscribeFirstSubscriber() { - NbpReplaySubject subject = NbpReplaySubject.create(); + ReplaySubject subject = ReplaySubject.create(); - NbpSubscriber observer = TestHelper.mockNbpSubscriber(); - NbpTestSubscriber ts = new NbpTestSubscriber(observer); + Observer observer = TestHelper.mockNbpSubscriber(); + TestObserver ts = new TestObserver(observer); subject.subscribe(ts); subject.onNext("one"); @@ -228,7 +227,7 @@ public void testUnsubscribeFirstSubscriber() { ts.dispose(); assertObservedUntilTwo(observer); - NbpSubscriber anotherSubscriber = TestHelper.mockNbpSubscriber(); + Observer anotherSubscriber = TestHelper.mockNbpSubscriber(); subject.subscribe(anotherSubscriber); assertObservedUntilTwo(anotherSubscriber); @@ -239,7 +238,7 @@ public void testUnsubscribeFirstSubscriber() { assertCompletedSubscriber(anotherSubscriber); } - private void assertObservedUntilTwo(NbpSubscriber observer) { + private void assertObservedUntilTwo(Observer observer) { verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, Mockito.never()).onNext("three"); @@ -251,7 +250,7 @@ private void assertObservedUntilTwo(NbpSubscriber observer) { public void testNewSubscriberDoesntBlockExisting() throws InterruptedException { final AtomicReference lastValueForSubscriber1 = new AtomicReference(); - NbpSubscriber observer1 = new NbpObserver() { + Observer observer1 = new DefaultObserver() { @Override public void onComplete() { @@ -275,7 +274,7 @@ public void onNext(String v) { final CountDownLatch oneReceived = new CountDownLatch(1); final CountDownLatch makeSlow = new CountDownLatch(1); final CountDownLatch completed = new CountDownLatch(1); - NbpSubscriber observer2 = new NbpObserver() { + Observer observer2 = new DefaultObserver() { @Override public void onComplete() { @@ -304,7 +303,7 @@ public void onNext(String v) { }; - NbpReplaySubject subject = NbpReplaySubject.create(); + ReplaySubject subject = ReplaySubject.create(); subject.subscribe(observer1); subject.onNext("one"); assertEquals("one", lastValueForSubscriber1.get()); @@ -346,7 +345,7 @@ public void onNext(String v) { } @Test public void testSubscriptionLeak() { - NbpReplaySubject subject = NbpReplaySubject.create(); + ReplaySubject subject = ReplaySubject.create(); Disposable s = subject.subscribe(); @@ -358,23 +357,23 @@ public void testSubscriptionLeak() { } @Test(timeout = 1000) public void testUnsubscriptionCase() { - NbpReplaySubject src = NbpReplaySubject.create(); + ReplaySubject src = ReplaySubject.create(); for (int i = 0; i < 10; i++) { - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + final Observer o = TestHelper.mockNbpSubscriber(); InOrder inOrder = inOrder(o); String v = "" + i; src.onNext(v); System.out.printf("Turn: %d%n", i); src.first() - .flatMap(new Function>() { + .flatMap(new Function>() { @Override - public NbpObservable apply(String t1) { - return NbpObservable.just(t1 + ", " + t1); + public Observable apply(String t1) { + return Observable.just(t1 + ", " + t1); } }) - .subscribe(new NbpObserver() { + .subscribe(new DefaultObserver() { @Override public void onNext(String t) { System.out.println(t); @@ -398,14 +397,14 @@ public void onComplete() { } @Test public void testTerminateOnce() { - NbpReplaySubject source = NbpReplaySubject.create(); + ReplaySubject source = ReplaySubject.create(); source.onNext(1); source.onNext(2); source.onComplete(); - final NbpSubscriber o = TestHelper.mockNbpSubscriber(); + final Observer o = TestHelper.mockNbpSubscriber(); - source.unsafeSubscribe(new NbpObserver() { + source.unsafeSubscribe(new DefaultObserver() { @Override public void onNext(Integer t) { @@ -431,14 +430,14 @@ public void onComplete() { @Test public void testReplay1AfterTermination() { - NbpReplaySubject source = NbpReplaySubject.createWithSize(1); + ReplaySubject source = ReplaySubject.createWithSize(1); source.onNext(1); source.onNext(2); source.onComplete(); for (int i = 0; i < 1; i++) { - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.subscribe(o); @@ -450,9 +449,9 @@ public void testReplay1AfterTermination() { } @Test public void testReplay1Directly() { - NbpReplaySubject source = NbpReplaySubject.createWithSize(1); + ReplaySubject source = ReplaySubject.createWithSize(1); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.onNext(1); source.onNext(2); @@ -472,7 +471,7 @@ public void testReplay1Directly() { @Test public void testReplayTimestampedAfterTermination() { TestScheduler scheduler = new TestScheduler(); - NbpReplaySubject source = NbpReplaySubject.createWithTime(1, TimeUnit.SECONDS, scheduler); + ReplaySubject source = ReplaySubject.createWithTime(1, TimeUnit.SECONDS, scheduler); source.onNext(1); @@ -487,7 +486,7 @@ public void testReplayTimestampedAfterTermination() { scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.subscribe(o); @@ -501,13 +500,13 @@ public void testReplayTimestampedAfterTermination() { @Test public void testReplayTimestampedDirectly() { TestScheduler scheduler = new TestScheduler(); - NbpReplaySubject source = NbpReplaySubject.createWithTime(1, TimeUnit.SECONDS, scheduler); + ReplaySubject source = ReplaySubject.createWithTime(1, TimeUnit.SECONDS, scheduler); source.onNext(1); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); - NbpSubscriber o = TestHelper.mockNbpSubscriber(); + Observer o = TestHelper.mockNbpSubscriber(); source.subscribe(o); @@ -578,7 +577,7 @@ public void testReplayTimestampedDirectly() { @Test public void testCurrentStateMethodsNormal() { - NbpReplaySubject as = NbpReplaySubject.create(); + ReplaySubject as = ReplaySubject.create(); assertFalse(as.hasThrowable()); assertFalse(as.hasComplete()); @@ -599,7 +598,7 @@ public void testCurrentStateMethodsNormal() { @Test public void testCurrentStateMethodsEmpty() { - NbpReplaySubject as = NbpReplaySubject.create(); + ReplaySubject as = ReplaySubject.create(); assertFalse(as.hasThrowable()); assertFalse(as.hasComplete()); @@ -613,7 +612,7 @@ public void testCurrentStateMethodsEmpty() { } @Test public void testCurrentStateMethodsError() { - NbpReplaySubject as = NbpReplaySubject.create(); + ReplaySubject as = ReplaySubject.create(); assertFalse(as.hasThrowable()); assertFalse(as.hasComplete()); @@ -627,7 +626,7 @@ public void testCurrentStateMethodsError() { } @Test public void testSizeAndHasAnyValueUnbounded() { - NbpReplaySubject rs = NbpReplaySubject.create(); + ReplaySubject rs = ReplaySubject.create(); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); @@ -649,7 +648,7 @@ public void testSizeAndHasAnyValueUnbounded() { } @Test public void testSizeAndHasAnyValueEffectivelyUnbounded() { - NbpReplaySubject rs = NbpReplaySubject.createUnbounded(); + ReplaySubject rs = ReplaySubject.createUnbounded(); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); @@ -672,7 +671,7 @@ public void testSizeAndHasAnyValueEffectivelyUnbounded() { @Test public void testSizeAndHasAnyValueUnboundedError() { - NbpReplaySubject rs = NbpReplaySubject.create(); + ReplaySubject rs = ReplaySubject.create(); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); @@ -694,7 +693,7 @@ public void testSizeAndHasAnyValueUnboundedError() { } @Test public void testSizeAndHasAnyValueEffectivelyUnboundedError() { - NbpReplaySubject rs = NbpReplaySubject.createUnbounded(); + ReplaySubject rs = ReplaySubject.createUnbounded(); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); @@ -717,7 +716,7 @@ public void testSizeAndHasAnyValueEffectivelyUnboundedError() { @Test public void testSizeAndHasAnyValueUnboundedEmptyError() { - NbpReplaySubject rs = NbpReplaySubject.create(); + ReplaySubject rs = ReplaySubject.create(); rs.onError(new TestException()); @@ -726,7 +725,7 @@ public void testSizeAndHasAnyValueUnboundedEmptyError() { } @Test public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyError() { - NbpReplaySubject rs = NbpReplaySubject.createUnbounded(); + ReplaySubject rs = ReplaySubject.createUnbounded(); rs.onError(new TestException()); @@ -736,7 +735,7 @@ public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyError() { @Test public void testSizeAndHasAnyValueUnboundedEmptyCompleted() { - NbpReplaySubject rs = NbpReplaySubject.create(); + ReplaySubject rs = ReplaySubject.create(); rs.onComplete(); @@ -745,7 +744,7 @@ public void testSizeAndHasAnyValueUnboundedEmptyCompleted() { } @Test public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyCompleted() { - NbpReplaySubject rs = NbpReplaySubject.createUnbounded(); + ReplaySubject rs = ReplaySubject.createUnbounded(); rs.onComplete(); @@ -755,7 +754,7 @@ public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyCompleted() { @Test public void testSizeAndHasAnyValueSizeBounded() { - NbpReplaySubject rs = NbpReplaySubject.createWithSize(1); + ReplaySubject rs = ReplaySubject.createWithSize(1); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); @@ -776,7 +775,7 @@ public void testSizeAndHasAnyValueSizeBounded() { @Test public void testSizeAndHasAnyValueTimeBounded() { TestScheduler ts = new TestScheduler(); - NbpReplaySubject rs = NbpReplaySubject.createWithTime(1, TimeUnit.SECONDS, ts); + ReplaySubject rs = ReplaySubject.createWithTime(1, TimeUnit.SECONDS, ts); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); @@ -795,7 +794,7 @@ public void testSizeAndHasAnyValueTimeBounded() { } @Test public void testGetValues() { - NbpReplaySubject rs = NbpReplaySubject.create(); + ReplaySubject rs = ReplaySubject.create(); Object[] expected = new Object[10]; for (int i = 0; i < expected.length; i++) { expected[i] = i; @@ -809,7 +808,7 @@ public void testGetValues() { } @Test public void testGetValuesUnbounded() { - NbpReplaySubject rs = NbpReplaySubject.createUnbounded(); + ReplaySubject rs = ReplaySubject.createUnbounded(); Object[] expected = new Object[10]; for (int i = 0; i < expected.length; i++) { expected[i] = i; diff --git a/src/test/java/io/reactivex/subjects/nbp/NbpSerializedSubjectTest.java b/src/test/java/io/reactivex/subjects/NbpSerializedSubjectTest.java similarity index 82% rename from src/test/java/io/reactivex/subjects/nbp/NbpSerializedSubjectTest.java rename to src/test/java/io/reactivex/subjects/NbpSerializedSubjectTest.java index a915349029..216c154df7 100644 --- a/src/test/java/io/reactivex/subjects/nbp/NbpSerializedSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/NbpSerializedSubjectTest.java @@ -11,21 +11,21 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex.subjects.nbp; +package io.reactivex.subjects; import static org.junit.Assert.*; import org.junit.Test; import io.reactivex.exceptions.TestException; -import io.reactivex.subscribers.nbp.NbpTestSubscriber; +import io.reactivex.observers.TestObserver; public class NbpSerializedSubjectTest { @Test public void testBasic() { - NbpSerializedSubject subject = new NbpSerializedSubject(NbpPublishSubject. create()); - NbpTestSubscriber ts = new NbpTestSubscriber(); + SerializedSubject subject = new SerializedSubject(PublishSubject. create()); + TestObserver ts = new TestObserver(); subject.subscribe(ts); subject.onNext("hello"); subject.onComplete(); @@ -35,10 +35,10 @@ public void testBasic() { @Test public void testAsyncSubjectValueRelay() { - NbpAsyncSubject async = NbpAsyncSubject.create(); + AsyncSubject async = AsyncSubject.create(); async.onNext(1); async.onComplete(); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -53,9 +53,9 @@ public void testAsyncSubjectValueRelay() { } @Test public void testAsyncSubjectValueEmpty() { - NbpAsyncSubject async = NbpAsyncSubject.create(); + AsyncSubject async = AsyncSubject.create(); async.onComplete(); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -70,10 +70,10 @@ public void testAsyncSubjectValueEmpty() { } @Test public void testAsyncSubjectValueError() { - NbpAsyncSubject async = NbpAsyncSubject.create(); + AsyncSubject async = AsyncSubject.create(); TestException te = new TestException(); async.onError(te); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -88,10 +88,10 @@ public void testAsyncSubjectValueError() { } @Test public void testPublishSubjectValueRelay() { - NbpPublishSubject async = NbpPublishSubject.create(); + PublishSubject async = PublishSubject.create(); async.onNext(1); async.onComplete(); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -108,9 +108,9 @@ public void testPublishSubjectValueRelay() { @Test public void testPublishSubjectValueEmpty() { - NbpPublishSubject async = NbpPublishSubject.create(); + PublishSubject async = PublishSubject.create(); async.onComplete(); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -125,10 +125,10 @@ public void testPublishSubjectValueEmpty() { } @Test public void testPublishSubjectValueError() { - NbpPublishSubject async = NbpPublishSubject.create(); + PublishSubject async = PublishSubject.create(); TestException te = new TestException(); async.onError(te); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -144,10 +144,10 @@ public void testPublishSubjectValueError() { @Test public void testBehaviorSubjectValueRelay() { - NbpBehaviorSubject async = NbpBehaviorSubject.create(); + BehaviorSubject async = BehaviorSubject.create(); async.onNext(1); async.onComplete(); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -162,9 +162,9 @@ public void testBehaviorSubjectValueRelay() { } @Test public void testBehaviorSubjectValueRelayIncomplete() { - NbpBehaviorSubject async = NbpBehaviorSubject.create(); + BehaviorSubject async = BehaviorSubject.create(); async.onNext(1); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -179,8 +179,8 @@ public void testBehaviorSubjectValueRelayIncomplete() { } @Test public void testBehaviorSubjectIncompleteEmpty() { - NbpBehaviorSubject async = NbpBehaviorSubject.create(); - NbpSubject serial = async.toSerialized(); + BehaviorSubject async = BehaviorSubject.create(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -195,9 +195,9 @@ public void testBehaviorSubjectIncompleteEmpty() { } @Test public void testBehaviorSubjectEmpty() { - NbpBehaviorSubject async = NbpBehaviorSubject.create(); + BehaviorSubject async = BehaviorSubject.create(); async.onComplete(); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -212,10 +212,10 @@ public void testBehaviorSubjectEmpty() { } @Test public void testBehaviorSubjectError() { - NbpBehaviorSubject async = NbpBehaviorSubject.create(); + BehaviorSubject async = BehaviorSubject.create(); TestException te = new TestException(); async.onError(te); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -231,10 +231,10 @@ public void testBehaviorSubjectError() { @Test public void testReplaySubjectValueRelay() { - NbpReplaySubject async = NbpReplaySubject.create(); + ReplaySubject async = ReplaySubject.create(); async.onNext(1); async.onComplete(); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -249,9 +249,9 @@ public void testReplaySubjectValueRelay() { } @Test public void testReplaySubjectValueRelayIncomplete() { - NbpReplaySubject async = NbpReplaySubject.create(); + ReplaySubject async = ReplaySubject.create(); async.onNext(1); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -266,11 +266,11 @@ public void testReplaySubjectValueRelayIncomplete() { } @Test public void testReplaySubjectValueRelayBounded() { - NbpReplaySubject async = NbpReplaySubject.createWithSize(1); + ReplaySubject async = ReplaySubject.createWithSize(1); async.onNext(0); async.onNext(1); async.onComplete(); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -285,10 +285,10 @@ public void testReplaySubjectValueRelayBounded() { } @Test public void testReplaySubjectValueRelayBoundedIncomplete() { - NbpReplaySubject async = NbpReplaySubject.createWithSize(1); + ReplaySubject async = ReplaySubject.createWithSize(1); async.onNext(0); async.onNext(1); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -303,8 +303,8 @@ public void testReplaySubjectValueRelayBoundedIncomplete() { } @Test public void testReplaySubjectValueRelayBoundedEmptyIncomplete() { - NbpReplaySubject async = NbpReplaySubject.createWithSize(1); - NbpSubject serial = async.toSerialized(); + ReplaySubject async = ReplaySubject.createWithSize(1); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -319,8 +319,8 @@ public void testReplaySubjectValueRelayBoundedEmptyIncomplete() { } @Test public void testReplaySubjectValueRelayEmptyIncomplete() { - NbpReplaySubject async = NbpReplaySubject.create(); - NbpSubject serial = async.toSerialized(); + ReplaySubject async = ReplaySubject.create(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -336,9 +336,9 @@ public void testReplaySubjectValueRelayEmptyIncomplete() { @Test public void testReplaySubjectEmpty() { - NbpReplaySubject async = NbpReplaySubject.create(); + ReplaySubject async = ReplaySubject.create(); async.onComplete(); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -353,10 +353,10 @@ public void testReplaySubjectEmpty() { } @Test public void testReplaySubjectError() { - NbpReplaySubject async = NbpReplaySubject.create(); + ReplaySubject async = ReplaySubject.create(); TestException te = new TestException(); async.onError(te); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -372,9 +372,9 @@ public void testReplaySubjectError() { @Test public void testReplaySubjectBoundedEmpty() { - NbpReplaySubject async = NbpReplaySubject.createWithSize(1); + ReplaySubject async = ReplaySubject.createWithSize(1); async.onComplete(); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertTrue(serial.hasComplete()); @@ -389,10 +389,10 @@ public void testReplaySubjectBoundedEmpty() { } @Test public void testReplaySubjectBoundedError() { - NbpReplaySubject async = NbpReplaySubject.createWithSize(1); + ReplaySubject async = ReplaySubject.createWithSize(1); TestException te = new TestException(); async.onError(te); - NbpSubject serial = async.toSerialized(); + Subject serial = async.toSerialized(); assertFalse(serial.hasSubscribers()); assertFalse(serial.hasComplete()); @@ -408,9 +408,9 @@ public void testReplaySubjectBoundedError() { @Test public void testDontWrapNbpSerializedSubjectAgain() { - NbpPublishSubject s = NbpPublishSubject.create(); - NbpSubject s1 = s.toSerialized(); - NbpSubject s2 = s1.toSerialized(); + PublishSubject s = PublishSubject.create(); + Subject s1 = s.toSerialized(); + Subject s2 = s1.toSerialized(); assertSame(s1, s2); } } \ No newline at end of file diff --git a/src/test/java/io/reactivex/subscribers/ObserversTest.java b/src/test/java/io/reactivex/subscribers/ObserversTest.java index 95b9051367..529768c608 100644 --- a/src/test/java/io/reactivex/subscribers/ObserversTest.java +++ b/src/test/java/io/reactivex/subscribers/ObserversTest.java @@ -24,7 +24,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Consumer; import io.reactivex.internal.functions.Functions; -import io.reactivex.subscribers.Observers; +import io.reactivex.observers.Observers; public class ObserversTest { @Test diff --git a/src/test/java/io/reactivex/subscribers/SafeObserverTest.java b/src/test/java/io/reactivex/subscribers/SafeObserverTest.java index 3d36e9c3a6..37351b7d91 100644 --- a/src/test/java/io/reactivex/subscribers/SafeObserverTest.java +++ b/src/test/java/io/reactivex/subscribers/SafeObserverTest.java @@ -21,10 +21,8 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.Observer; import io.reactivex.exceptions.*; import io.reactivex.internal.subscriptions.EmptySubscription; -import io.reactivex.subscribers.SafeSubscriber; public class SafeObserverTest { @@ -323,7 +321,7 @@ public void request(long n) { } private static Subscriber OBSERVER_SUCCESS() { - return new Observer() { + return new DefaultObserver() { @Override public void onComplete() { @@ -344,7 +342,7 @@ public void onNext(String args) { } private static Subscriber OBSERVER_SUCCESS(final AtomicReference onError) { - return new Observer() { + return new DefaultObserver() { @Override public void onComplete() { @@ -365,7 +363,7 @@ public void onNext(String args) { } private static Subscriber OBSERVER_ONNEXT_FAIL(final AtomicReference onError) { - return new Observer() { + return new DefaultObserver() { @Override public void onComplete() { @@ -386,7 +384,7 @@ public void onNext(String args) { } private static Subscriber OBSERVER_ONNEXT_ONERROR_FAIL() { - return new Observer() { + return new DefaultObserver() { @Override public void onComplete() { @@ -407,7 +405,7 @@ public void onNext(String args) { } private static Subscriber OBSERVER_ONERROR_FAIL() { - return new Observer() { + return new DefaultObserver() { @Override public void onComplete() { @@ -428,7 +426,7 @@ public void onNext(String args) { } private static Subscriber OBSERVER_ONERROR_NOTIMPLEMENTED() { - return new Observer() { + return new DefaultObserver() { @Override public void onComplete() { @@ -449,7 +447,7 @@ public void onNext(String args) { } private static Subscriber OBSERVER_ONCOMPLETED_FAIL(final AtomicReference onError) { - return new Observer() { + return new DefaultObserver() { @Override public void onComplete() { @@ -480,7 +478,7 @@ public SafeObserverTestException(String message) { @Ignore("Subscribers can't throw") public void testOnCompletedThrows() { final AtomicReference error = new AtomicReference(); - SafeSubscriber s = new SafeSubscriber(new Observer() { + SafeSubscriber s = new SafeSubscriber(new DefaultObserver() { @Override public void onNext(Integer t) { @@ -505,7 +503,7 @@ public void onComplete() { @Test public void testActual() { - Subscriber actual = new Observer() { + Subscriber actual = new DefaultObserver() { @Override public void onNext(Integer t) { } diff --git a/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java b/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java index 85b7ea4b36..6308719a45 100644 --- a/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java @@ -20,7 +20,8 @@ import org.mockito.Mockito; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; +import io.reactivex.flowable.TestHelper; public class SafeSubscriberTest { @@ -30,7 +31,7 @@ public class SafeSubscriberTest { @Test public void testOnNextAfterOnError() { TestObservable t = new TestObservable(); - Observable st = Observable.create(t); + Flowable st = Flowable.create(t); Subscriber w = TestHelper.mockSubscriber(); st.subscribe(new SafeSubscriber(new TestSubscriber(w))); @@ -50,7 +51,7 @@ public void testOnNextAfterOnError() { @Test public void testOnCompletedAfterOnError() { TestObservable t = new TestObservable(); - Observable st = Observable.create(t); + Flowable st = Flowable.create(t); Subscriber w = TestHelper.mockSubscriber(); @@ -71,7 +72,7 @@ public void testOnCompletedAfterOnError() { @Test public void testOnNextAfterOnCompleted() { TestObservable t = new TestObservable(); - Observable st = Observable.create(t); + Flowable st = Flowable.create(t); Subscriber w = TestHelper.mockSubscriber(); st.subscribe(new SafeSubscriber(new TestSubscriber(w))); @@ -92,7 +93,7 @@ public void testOnNextAfterOnCompleted() { @Test public void testOnErrorAfterOnCompleted() { TestObservable t = new TestObservable(); - Observable st = Observable.create(t); + Flowable st = Flowable.create(t); Subscriber w = TestHelper.mockSubscriber(); st.subscribe(new SafeSubscriber(new TestSubscriber(w))); diff --git a/src/test/java/io/reactivex/subscribers/SerializedObserverTest.java b/src/test/java/io/reactivex/subscribers/SerializedObserverTest.java index b24f057c15..dac12583d0 100644 --- a/src/test/java/io/reactivex/subscribers/SerializedObserverTest.java +++ b/src/test/java/io/reactivex/subscribers/SerializedObserverTest.java @@ -23,8 +23,9 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.functions.Consumer; import io.reactivex.internal.subscriptions.*; import io.reactivex.schedulers.Schedulers; @@ -45,7 +46,7 @@ private Subscriber serializedSubscriber(Subscriber o) { @Test public void testSingleThreadedBasic() { TestSingleThreadedObservable onSubscribe = new TestSingleThreadedObservable("one", "two", "three"); - Observable w = Observable.create(onSubscribe); + Flowable w = Flowable.create(onSubscribe); Subscriber aw = serializedSubscriber(observer); @@ -65,7 +66,7 @@ public void testSingleThreadedBasic() { @Test public void testMultiThreadedBasic() { TestMultiThreadedObservable onSubscribe = new TestMultiThreadedObservable("one", "two", "three"); - Observable w = Observable.create(onSubscribe); + Flowable w = Flowable.create(onSubscribe); BusySubscriber busySubscriber = new BusySubscriber(); Subscriber aw = serializedSubscriber(busySubscriber); @@ -89,7 +90,7 @@ public void testMultiThreadedBasic() { @Test(timeout = 1000) public void testMultiThreadedWithNPE() throws InterruptedException { TestMultiThreadedObservable onSubscribe = new TestMultiThreadedObservable("one", "two", "three", null); - Observable w = Observable.create(onSubscribe); + Flowable w = Flowable.create(onSubscribe); BusySubscriber busySubscriber = new BusySubscriber(); Subscriber aw = serializedSubscriber(busySubscriber); @@ -123,7 +124,7 @@ public void testMultiThreadedWithNPEinMiddle() { for (int i = 0; i < n; i++) { TestMultiThreadedObservable onSubscribe = new TestMultiThreadedObservable("one", "two", "three", null, "four", "five", "six", "seven", "eight", "nine"); - Observable w = Observable.create(onSubscribe); + Flowable w = Flowable.create(onSubscribe); BusySubscriber busySubscriber = new BusySubscriber(); Subscriber aw = serializedSubscriber(busySubscriber); @@ -267,7 +268,7 @@ public void testNotificationDelay() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch running = new CountDownLatch(2); - TestSubscriber to = new TestSubscriber(new Observer() { + TestSubscriber to = new TestSubscriber(new DefaultObserver() { @Override public void onComplete() { @@ -348,7 +349,7 @@ public void onNext(String t) { @Test public void testThreadStarvation() throws InterruptedException { - TestSubscriber to = new TestSubscriber(new Observer() { + TestSubscriber to = new TestSubscriber(new DefaultObserver() { @Override public void onComplete() { @@ -376,13 +377,13 @@ public void onNext(String t) { AtomicInteger p2 = new AtomicInteger(); o.onSubscribe(EmptySubscription.INSTANCE); - AsyncObserver as1 = Observers.createAsync(new Consumer() { + AsyncSubscriber as1 = Subscribers.createAsync(new Consumer() { @Override public void accept(String v) { o.onNext(v); } }); - AsyncObserver as2 = Observers.createAsync(new Consumer() { + AsyncSubscriber as2 = Subscribers.createAsync(new Consumer() { @Override public void accept(String v) { o.onNext(v); @@ -412,8 +413,8 @@ private static void waitOnThreads(Future... futures) { } } - private static Observable infinite(final AtomicInteger produced) { - return Observable.create(new Publisher() { + private static Flowable infinite(final AtomicInteger produced) { + return Flowable.create(new Publisher() { @Override public void subscribe(Subscriber s) { @@ -518,7 +519,7 @@ private static enum TestConcurrencySubscriberEvent { onCompleted, onError, onNext } - private static class TestConcurrencySubscriber extends Observer { + private static class TestConcurrencySubscriber extends DefaultObserver { /** * used to store the order and number of events received @@ -751,7 +752,7 @@ public void waitToFinish() { } } - private static class BusySubscriber extends Observer { + private static class BusySubscriber extends DefaultObserver { volatile boolean onCompleted = false; volatile boolean onError = false; AtomicInteger onNextCount = new AtomicInteger(); diff --git a/src/test/java/io/reactivex/subscribers/SubscribersTest.java b/src/test/java/io/reactivex/subscribers/SubscribersTest.java index d941b775a3..c872c136c6 100644 --- a/src/test/java/io/reactivex/subscribers/SubscribersTest.java +++ b/src/test/java/io/reactivex/subscribers/SubscribersTest.java @@ -24,7 +24,6 @@ import io.reactivex.exceptions.*; import io.reactivex.functions.Consumer; import io.reactivex.internal.functions.Functions; -import io.reactivex.subscribers.Subscribers; public class SubscribersTest { @Test diff --git a/src/test/java/io/reactivex/subscribers/TestObserverTest.java b/src/test/java/io/reactivex/subscribers/TestObserverTest.java index 7299f82938..50ca2faed9 100644 --- a/src/test/java/io/reactivex/subscribers/TestObserverTest.java +++ b/src/test/java/io/reactivex/subscribers/TestObserverTest.java @@ -25,10 +25,9 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; +import io.reactivex.flowable.TestHelper; import io.reactivex.internal.subscriptions.EmptySubscription; -import io.reactivex.subjects.PublishSubject; -import io.reactivex.subscribers.TestSubscriber; -import io.reactivex.Observable; +import io.reactivex.processors.PublishProcessor; public class TestObserverTest { @@ -37,7 +36,7 @@ public class TestObserverTest { @Test public void testAssert() { - Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); TestSubscriber o = new TestSubscriber(); oi.subscribe(o); @@ -48,7 +47,7 @@ public void testAssert() { @Test public void testAssertNotMatchCount() { - Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); TestSubscriber o = new TestSubscriber(); oi.subscribe(o); @@ -63,7 +62,7 @@ public void testAssertNotMatchCount() { @Test public void testAssertNotMatchValue() { - Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); TestSubscriber o = new TestSubscriber(); oi.subscribe(o); @@ -78,7 +77,7 @@ public void testAssertNotMatchValue() { @Test public void testAssertTerminalEventNotReceived() { - PublishSubject p = PublishSubject.create(); + PublishProcessor p = PublishProcessor.create(); TestSubscriber o = new TestSubscriber(); p.subscribe(o); @@ -96,7 +95,7 @@ public void testAssertTerminalEventNotReceived() { @Test public void testWrappingMock() { - Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); Subscriber mockObserver = TestHelper.mockSubscriber(); @@ -111,7 +110,7 @@ public void testWrappingMock() { @Test public void testWrappingMockWhenUnsubscribeInvolved() { - Observable oi = Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)).take(2); + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)).take(2); Subscriber mockObserver = TestHelper.mockSubscriber(); oi.subscribe(new TestSubscriber(mockObserver)); @@ -124,7 +123,7 @@ public void testWrappingMockWhenUnsubscribeInvolved() { @Test public void testErrorSwallowed() { - Observable.error(new RuntimeException()).subscribe(new TestSubscriber()); + Flowable.error(new RuntimeException()).subscribe(new TestSubscriber()); } @Test diff --git a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java index 47a705384a..d1c627aec2 100644 --- a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java @@ -25,13 +25,13 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.Scheduler.Worker; import io.reactivex.exceptions.*; +import io.reactivex.flowable.TestHelper; import io.reactivex.internal.subscriptions.EmptySubscription; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.PublishSubject; -import io.reactivex.subscribers.TestSubscriber; public class TestSubscriberTest { @@ -40,7 +40,7 @@ public class TestSubscriberTest { @Test public void testAssert() { - Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); TestSubscriber o = new TestSubscriber(); oi.subscribe(o); @@ -51,7 +51,7 @@ public void testAssert() { @Test public void testAssertNotMatchCount() { - Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); TestSubscriber o = new TestSubscriber(); oi.subscribe(o); @@ -66,7 +66,7 @@ public void testAssertNotMatchCount() { @Test public void testAssertNotMatchValue() { - Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); TestSubscriber o = new TestSubscriber(); oi.subscribe(o); @@ -82,7 +82,7 @@ public void testAssertNotMatchValue() { @Test public void testAssertTerminalEventNotReceived() { - PublishSubject p = PublishSubject.create(); + PublishProcessor p = PublishProcessor.create(); TestSubscriber o = new TestSubscriber(); p.subscribe(o); @@ -100,7 +100,7 @@ public void testAssertTerminalEventNotReceived() { @Test public void testWrappingMock() { - Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); Subscriber mockObserver = TestHelper.mockSubscriber(); oi.subscribe(new TestSubscriber(mockObserver)); @@ -114,7 +114,7 @@ public void testWrappingMock() { @Test public void testWrappingMockWhenUnsubscribeInvolved() { - Observable oi = Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)).take(2); + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)).take(2); Subscriber mockObserver = TestHelper.mockSubscriber(); oi.subscribe(new TestSubscriber(mockObserver)); @@ -129,14 +129,14 @@ public void testWrappingMockWhenUnsubscribeInvolved() { public void testAssertError() { RuntimeException e = new RuntimeException("Oops"); TestSubscriber subscriber = new TestSubscriber(); - Observable.error(e).subscribe(subscriber); + Flowable.error(e).subscribe(subscriber); subscriber.assertError(e); } @Test public void testAwaitTerminalEventWithDuration() { TestSubscriber ts = new TestSubscriber(); - Observable.just(1).subscribe(ts); + Flowable.just(1).subscribe(ts); ts.awaitTerminalEvent(1, TimeUnit.SECONDS); ts.assertTerminated(); } @@ -145,7 +145,7 @@ public void testAwaitTerminalEventWithDuration() { public void testAwaitTerminalEventWithDurationAndUnsubscribeOnTimeout() { TestSubscriber ts = new TestSubscriber(); final AtomicBoolean unsub = new AtomicBoolean(false); - Observable.just(1) + Flowable.just(1) // .doOnCancel(new Runnable() { @Override @@ -162,7 +162,7 @@ public void run() { @Test(expected = NullPointerException.class) public void testNullDelegate1() { - TestSubscriber ts = new TestSubscriber((Observer)null); + TestSubscriber ts = new TestSubscriber((DefaultObserver)null); ts.onComplete(); }